Page 1 of 1

Problem while writing into SD card

Posted: Tue Feb 07, 2017 12:13 pm
by amalamal
Hi

I am using the SD card driver provide by esp32, it is working with normal files in one wire mode, it is creating file and writing in it,
As part of my application i am trying to store an image in sd card by creating a JPG file and writing appropriate hex values of the image, but by using the "fprintf" function in the driver it is not able to write 0x00 into file

suppose if 0xFF 0xD8 0x00 0xDE is my data till 0xD8 it will write into file, when a 0x00 comes it will assume as an ending char and stop writing.

Please anyone help me to solve this issue.

Thanks

Re: Problem while writing into SD card

Posted: Tue Feb 07, 2017 1:02 pm
by WiFive
Use fwrite

Re: Problem while writing into SD card

Posted: Wed Feb 08, 2017 2:27 am
by ESP_Sprite
Aye. The explanation is that in C, the end of a string is indicated by a zero byte. So if you feed e.g. a string containing '0x01 0x00 0x02 0x02' to fprintf, it will think it is actually a string only containing 0x01.

Re: Problem while writing into SD card

Posted: Wed Feb 08, 2017 10:00 am
by ESP_krzychb
Hi @amalamal,

Example of writing binary data to SD card using this very driver and fwrite is here.

Basically you need to replace in your code fprintf with fwrite and provide this function with:
1. pointer to your jpeg image,
2. number of bytes of the jpeg image,
3. 1 - to write one set of the "number of bytes",
4. handle to the file opened for writing.

Krzysztof

Re: Problem while writing into SD card

Posted: Thu Feb 09, 2017 7:54 am
by amalamal
Hi

Thanks for the replies, Now my problem is solved by using 'fwrite' instead of 'fprintf' .


Thanks