Problem while writing into SD card

amalamal
Posts: 23
Joined: Mon Dec 12, 2016 7:07 am

Problem while writing into SD card

Postby amalamal » Tue Feb 07, 2017 12:13 pm

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

WiFive
Posts: 3529
Joined: Tue Dec 01, 2015 7:35 am

Re: Problem while writing into SD card

Postby WiFive » Tue Feb 07, 2017 1:02 pm

Use fwrite

ESP_Sprite
Posts: 9014
Joined: Thu Nov 26, 2015 4:08 am

Re: Problem while writing into SD card

Postby ESP_Sprite » Wed Feb 08, 2017 2:27 am

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.

User avatar
ESP_krzychb
Posts: 394
Joined: Sat Oct 01, 2016 9:05 am
Contact:

Re: Problem while writing into SD card

Postby ESP_krzychb » Wed Feb 08, 2017 10:00 am

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

amalamal
Posts: 23
Joined: Mon Dec 12, 2016 7:07 am

Re: Problem while writing into SD card

Postby amalamal » Thu Feb 09, 2017 7:54 am

Hi

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


Thanks

Who is online

Users browsing this forum: LSitar and 88 guests