SD card became unrecognized by card readers

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(LAT/100000,7);
myFile.print(" Lon ");
myFile.println(LON/100000,7);
myFile.close();

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?

thanks!

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.

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 GUID Partition Table - Wikipedia

You can also correctly format an SD card using the SdFat SdFormatter example. SdFat is located here Google Code Archive - Long-term storage for Google Code Project Hosting..

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:

http://www.ebay.com/itm/SD-Card-Shield-Module-Memory-Read-Write-reader-Arduino-/150718852629?pt=UK_BOI_Electrical_Test_Measurement_Equipment_ET&hash=item23178b2e15#ht_2930wt_1270

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.

Mike,

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?

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 Google Code Archive - Long-term storage for Google Code Project Hosting..

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?

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.

http://code.google.com/p/sdfatlib/downloads/list

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.

http://www.ebay.com/itm/SD-Card-Reader-Module-Arduino-ARM-Read-and-Write-/200659790559?pt=LH_DefaultDomain_0&hash=item2eb8416adf

I didn't understand why you linked a different sd card reader from ebay , my sd card reader is:

http://www.ebay.com/itm/SD-Card-Shield-Module-Memory-Read-Write-reader-Arduino-/150718852629?pt=UK_BOI_Electrical_Test_Measurement_Equipment_ET&hash=item23178b2e15#ht_2930wt_1270

I connected the card reader to my arduino nano like this:

5V pin to 5V pin
GND to GND
MOSI to pin 11
SS to pin 4
SCK to pin 13
MISO to pin 12

the output of the programs you ask for: (I remind you that the SD card is probably dead)

CardInfo example from SD.h using Arduino 1.0 output:
"
Initializing SD card...initialization failed. Things to check:

  • is a card is inserted?
  • Is your wiring correct?
  • did you change the chipSelect pin to match your shield or module?
    "

QuickStart example output:
"
SD chip select is the key hardware option.
Common values are:
Arduino Ethernet shield, pin 4
Sparkfun SD shield, pin 8
Adafruit SD shields and modules, pin 10
The default chip select pin number is pin 10

Enter the chip select pin number: 4

SD initialization failed.
Do not reformat the card!
Is the card correctly inserted?
Is chipSelect set to the correct value?
Is there a wiring/soldering problem?
errorCode: 0xa, errorData: 0x1

Restarting

Enter the chip select pin number:
"

SdInfo example output
"
SD chip select is the key hardware option.
Common values are:
Arduino Ethernet shield, pin 4
Sparkfun SD shield, pin 8
Adafruit SD shields and modules, pin 10
The default chip select pin number is pin 10

Enter the chip select pin number: 4

SD initialization failed.
Do not reformat the card!
Is the card correctly inserted?
Is chipSelect set to the correct value?
Is there a wiring/soldering problem?
errorCode: 0xa, errorData: 0x1

Restarting

Enter the chip select pin number:
"

all the checks made with the same config and with arduino 1.0
I used the ruined card

I posted a link to that module because it was the same seller that sold your module and had a circuit diagram. The seller claimed that the module was for an Arduino but in fact that module should not be used with a 5V arduino. There was no circuit diagram for your module so I had no reason to believe your module is correct.

Your card fails in a strange way for an SD card. The only time I have seen error code 0x0a is for a MMC card. SD.h and SdFat do not support MMC cards.

Your card is not dead but it does not respond as expected for an SD card.

do you think I need to connect it to a 3.3 voltage although it is written 5V?

do you think the current config is ok to use with another sd card ?(i don't have an unlimited amount of it)

do you know if and how I can save this card?

Since we don't have a circuit diagram for you module, I can't be sure if it is OK. If possible measure the supply voltage as described below.

If your card is a real SD card then error code 0Xa with error data 0x1 may mean that the supply voltage to the card is out of range.

During initialization, cards operate in a safe mode and won't go ready without the correct voltage. Most SD cards work with Vcc in the range 2.7 to 3.6 volts.

Look at the diagrams in this article How to Use MMC/SDC to see which SD pin has Vcc and measure the value of Vcc.

For an SD card there should be 9 pins and Vcc is the middle pin. Pins are numbered in a strange way for historical reasons.

Edit: On your module it appears that the Vcc pin connects to the yellow cap near the regulator.

i fixed my program (made a safe remove function that closes the file)

I changed to a new card and the card reader didn't work with a 3.3V but it worked just fine with a 5V
thank you all

I will be happy if someone know's if and how I can save the corrupted card