Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
8 years, 8 months ago.
A weird problem with mbed SPI SD Card
Hi everybody, After hours and hours of developing an application based on mbed platform, I got a horror problem with SD card. When I was testing, I found that while logging some measured data in files everything goes well until the 13th file is created, and weirdly after I fopen the 13th file as writing (surely I won't forget fclose!) whole FAT and local file system won't work. (and remains not working)
here is the code: (inside main loop):
LLD_FAT_writeFile(const char * adr, const char * data) is a function that writes the data inside the given address and checks if the new file is made. (just checks the existence of the file)
here is the definition of this function:
when I run the code on micro, I get this: 0,1
1,1
2,1
. .
12,1
13,0
14,0
. .
19,0
20,0
Reveals that from the 13th file the problem occurs and remains.
Have you tried inserting some sort of wait or delay between calls to write to the SD card. I start having problems if I repeatedly slam the SD card with data over and over again like this. Why? I don't know, but slowing down the calls helped. Also at the end of the Write function you seem to open the file again without closing it. Stack exchange seems to suggest this is a problem: http://stackoverflow.com/questions/3353214/fopen-without-fclose-in-c
I will give this a try, if you posted the full code, or at least a pared down version that showed the problem.
posted by Graham S. 07 Mar 2017Thanks for your answer. Actually I inserted the wait and delay, and the problem remained. However I'll try closing the file at the end of reading test.
posted by Abolfazl Danayi 09 Mar 2017