Go Down

Topic: SD card became unrecognized by card readers (Read 19330 times) previous topic - next topic


hi guys,

I've tried to make a data logger for a gps receiver and used this code:

  myFile = SD.open("POS.txt", FILE_WRITE);
  myFile.print("Satellites in view: ");
  myFile.println(gps.satsinview(), DEC);
  myFile.print("Lat : ");
  myFile.print(" Lon ");

this code section is in the loop function so it repeats it self endlessly
I haven't made any safe remove function in the code .

after using this code once, my sd card became unrecognized in any card reading devices (arduino card reader, my laptop card reader, my camera)
because of that I can't format it or use it.

does someone knows how to fix it? and\or avoiding this problem in the future?



after using this code once,

How long for.?
Opening the same file and writing to it over and over seems to me a good way of wearing out your SD card.


I used it for about 20 seconds before I shut it off. (it needed to access the file about 20 times)
so you say that in this case I need to open and close the file only once? (opening the file in the setup and making a safe remove function to close it)

do you know if I can save the card and make it work again?


I used it for about 20 seconds before I shut it off.

20 seconds should not have damaged your card. Of course, we can't actually see how many times you wrote to the card in that 20 seconds, but I can't imagine having written more times than the card can be written to in just 20 seconds.
The art of getting good answers lies in asking good questions.


It might have left something part written or you I terrupted something critical. However if you are not able to format it then I assume it is dead.
Have you tried a low level format using your disc utilities?


I don't understand what made it died.
is opening and closing file for a few dozen times  can kill a SD card?
is shutting the power of a SD card in the middle of a write process can kill it? (I can't and don't know in which part of the program I shut it off)

what is low level format? (I can't get any device to recognize the card - my laptop nor my camera - so I can't  format it)   


You can't wear out an SD card by writing with an Arduino.  The card's controller has wear leveling.  When the SD library writes to a file, it writes an entire block.  The card's SD controller does a physical to logical mapping to prevent any block from being written too many times.

The controller also handles bad blocks by only mapping good blocks.

Interrupting power during write will at most cause data in that block to be bad.  The card should still be OK.

You could kill the card by putting 5V on its pins.  SD card are 3.3V devices.

Also don't format the card with your format utility.  PCs and especially Macs don't format SD cards according to the SD standard.  If possible use the SD associations format utility https://www.sdcard.org/downloads/formatter_3/.

A Mac may format a card with GPT format instead of MBR format.  Since GPT is not part of the SD standard, many devices don't recognize GPT formatted  SD cards.  Here is an article about GPT http://en.wikipedia.org/wiki/GUID_Partition_Table

You can also correctly format an SD card using the SdFat SdFormatter example.  SdFat is located here http://code.google.com/p/sdfatlib/.

The Arduino SD.h library is based on an old version of SdFat.


indeed I connected the SD controller to a 5V source but as you can see:


this is the controller I used and it says explicitly 5V

and I tried the example programs a few times with a 5V config and it worked just fine..
the program I wrote killed the card after only one no safe remove use


The card's controller has wear leveling.

It might on the file's contents but the same block will be written to for the file's information. As the same name was being used maybe it used the same place and re wrote the new block.
Anyway for 20 seconds it was more than a few dozen times, several hundred to say the least.
That card reader is a poor design because it does not use logic, level translations only resistors.

A Mac may format a card with GPT format instead of MBR format.

A Mac will format it to what ever standard you set it to. It's not a PC you know.



The flash controller in an SD card is a very sophisticated device with a powerful micro-controller.  It doesn't work in the simple way you describe.

The same block is not rewritten.  The SD card's flash controller maintains a pool of erased blocks. when you write a block of data it uses an new block.

The Mac is not a PC so it is not that good at FAT file systems with MBR partition tables. 

I wrote SdFat, the base library for SD.h and get a lot of e-mail about problems the Mac causes.  Once an SD is formatted GPT, even a PC won't restore it to MBR.

That is why I wrote the SdFat SdFormat program.  So you can recover a GPT formatted SD.

There are other problems with OS format utilities.  Flash in SD cards have very large, 128KB or more, erase groups so file structures should be aligned on these for best performance.  PC and MAC generic format utilities don't do this.

Here is a quote from the SD Assoication:
The SD Formatter was created specifically for memory cards using the SD/SDHC/SDXC standards. It is strongly recommended to use the SD Formatter instead of formatting utilities provided with operating systems that format various types of storage media. Using generic formatting utilities may result in less than optimal performance for your memory cards.


The flash controller in an SD card is a very sophisticated device with a powerful micro-controller.  It doesn't work in the simple way you describe.

OK so why did he kill his card?


Jan 16, 2012, 06:14 pm Last Edit: Jan 16, 2012, 06:17 pm by fat16lib Reason: 1
About the only way to harm an SD card is to put too much voltage on a pin.

We should be asking about the user's hardware setup.

Also it would be good to have output from a program like CardInfo from the Arduino 1.0 SD.h library.

Another option is output from QuickStart or SdInfo from my SdFat library http://code.google.com/p/sdfatlib/downloads/list.


We should be asking about the user's hardware setup.

We did, he showed a link to the board he used, I commented on it. You can see it contains a voltage regulator.


I connected the 5V pin in the controller directly to the 5V output pin in my arduino.

if what you say is true and the only reason for the card malfunction is high voltage than what do I do wrong? (are you positive that no software problem can cause a card malfunction?!)

do i need to put a capacitor in the 5V pin of the controller to stabilize the input?
is the voltage that the arduino board generate is no stable?


Jan 16, 2012, 08:03 pm Last Edit: Jan 16, 2012, 08:21 pm by fat16lib Reason: 1
Exactly how is the SD module connected to the Arduino?  Which pins on the module to which pins on the Arduino.

Post the output from running the CardInfo example from SD.h using Arduino 1.0.

If possible download SdFat and run the examples QuickStart and SdInfo.   Post the output from each program.


Edit: I just noticed that the module pictured on ebay has resistor level shifters.  Some SD cards don't work well with resistor level shifters since newer cards require very fast rise times on the SPI signals.  Many newer cards use edge detectors for the SPI signals.

Using resistor level shifters instead of semiconductor level shifters won't hurt the SD card but may cause I/O errors at higher SPI speeds.

It looks like the regulator has a cap on the 3.3V that it supplies to the card.

Edit again:  Looks like some of the modules do not have resistor level shifters, just pullups to 3.3V.  The signal pins are connected straight to the Adduino which could ruin an SD.


Go Up