SdFat: SD Card Error after running for a few weeks

First off, thanks for this amazing library!

I get an error when running a SD card for a few weeks that prevents me from opening a file for reading.

If I then reset the MCU, I cannot successfully initialize the SD card any more.

I managed to flash a test program to my ARM chip that uses the sd.errorPrint(&Serial); code.

When running the test program with a “hung” SD card, I get the following output:

SD errorCode: 0X1,0X0

after a failed call to

sd.begin(chipSelect, SPI_HALF_SPEED)

If I power cycle the SD card, it then recovers from being “hung” and functions normally as expected for a few more weeks.

I have read that SD cards operating in SPI mode are prone to “hanging” after several days of running (i guess the applet loaded onto the SD card controller is not so good at dealing with SPI implementation), and that the only way to resolve the issue is to power cycle the SD card (thereby “restarting” the applet).

Is this correct?

Is there a way to recover from this error using the SdFat library without having to schedule a site visit to power cycle the SD card?

Here is the SD portion of my design:

image

About this issue

  • Original URL
  • State: open
  • Created 6 years ago
  • Comments: 31 (11 by maintainers)

Most upvoted comments

I relocated my antenna and it seems to have worked (mostly). Let’s just say instead of having to do a field visit once per 24 hours with a fleet of 10 SD cards, I now have to send a technician out only once every month with a fleet of 40 SD cards

@macdonaldtomw Hope you solved this issue, but I had a similar experience with SdFat using the Arduino MKR GSM 1400 board. This board includes a GSM modem. In my design I was careful to make sure the SPI lines were balanced. My 16gb SanDisk microSD card worked flawlessly when the GSM modem was not transmitting, however, when the modem was active I would occasionally get corruption when writing to the card.

Turns out the problem was poor shielding and antenna proximity to the SPI lines. I used a simple 2-layer PCB and didn’t pay close attention to electromagnetic shielding. My antenna was a patch antenna, located about 2" above the circuit board and somewhat aligned with the SPI line traces. When I relocated the antenna the problems went away! A robust fix would be to ensure that all SPI lines are well shielded and that the orientation and proximity of the antenna is verified when using SPI peripherals.