This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

How to Write to SD Card at high rate ?

Hi All,

I have just started working on interfacing SD card with nrf52 using SDK 12.0. I have to write to SD card at a rate of 84 packets per second and each packet consists of 20 bytes. I am taking fatfs example in sdk 12.0 as reference.

I am sampling the SAADC at 1 ksps and storing these samples in SD card.Here I amwriting to SD card based on GPIO interrupt For each write operation I am using following steps: 1)open directory 2)open file 3)write bytes to file 4)close the file.

While writing continuously I am facing following issues :

  1. Code gets restarted automatically after writing some kb's into SD card.

  2. I am wring only in one file. Still additional files are generated in SD card.

  3. while writing to file somewhere in the middle I am getting massage as Unable to open or create file: ank.TXT.

I am using 8 GB SD card for this operation. IAR version 7.4 and SDK 12.0. Does any one has any idea why I am getting these issues?

I am attaching my code and some images for the reference. modified1.c image description image description image description

image1: when issue no. 3 occurred image2: when code gets restarted image3: when multiple files gets created in SD card

I have to write to SD card whole data at longer duration without restarting the code.

Parents
  • You should check why your code is restarting. Most of the time it is because an error condition was met, see here.

    Maybe you get the Unable to open or create file: ank.TXT because you try to open the file while it is not closed yet.

    Can you try to use f_sync(...) as described here to minimize the critical sections? If you use f_sync(..) you can leave the file open instead of closing it after every write, suitable for datalogging, see here. Then you can close it before you remove the SD card or when the logging is done.

Reply
  • You should check why your code is restarting. Most of the time it is because an error condition was met, see here.

    Maybe you get the Unable to open or create file: ank.TXT because you try to open the file while it is not closed yet.

    Can you try to use f_sync(...) as described here to minimize the critical sections? If you use f_sync(..) you can leave the file open instead of closing it after every write, suitable for datalogging, see here. Then you can close it before you remove the SD card or when the logging is done.

Children
No Data
Related