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
Problem while writing into SD card
Re: Problem while writing into SD card
Use fwrite
-
- Posts: 9833
- Joined: Thu Nov 26, 2015 4:08 am
Re: Problem while writing into SD card
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.
- ESP_krzychb
- Posts: 402
- Joined: Sat Oct 01, 2016 9:05 am
- Contact:
Re: Problem while writing into SD card
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
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
Hi
Thanks for the replies, Now my problem is solved by using 'fwrite' instead of 'fprintf' .
Thanks
Thanks for the replies, Now my problem is solved by using 'fwrite' instead of 'fprintf' .
Thanks
Who is online
Users browsing this forum: Bing [Bot], MicroController and 134 guests