SD Card Initialization Fail 70% Of the time.....

Hiya,

I am using Arduino Uno with Arduino Xbee + SD Shield, The card i am using is SanDisk 2GB micro SD Card, The card appears to work fine when recently formatted in PC, but if you remove it once or twice from the shield put it in computer and then put back in arduino it gets unreadable by Arduino. Dosnt matter which code i run, the default SD Library sketch SDcardinfo also dont seem to initialize the card.... What could be the problem?

exactly which SD shield/module do you use?

maybe try another sd card.

i had some error stuff when i pulled out the sd card while ardu was writing on it, maybe thats a problem too

i pulled in and out my oldschool 128 mb sd card like 20 times in the last 20min... and no problems, but i checked always on serial monitor when ardu finished writing to sd

Ive tried another card, 8GB Nokia Micro SD Card... Same problem persist!

does the sd formatter programm work properly?

if you remove it once or twice from the shield put it in computer and then put back in arduino it gets unreadable by Arduino.

r u really just putting it in and out, without doing something else?

Yes ive tried both ways, creating a txt file in the card from computer and doing nothing (i.e just insert in the computer and take it out)

i had a similar problem, but the reason was that i just have a really really cheap sd module which suxx, so i had to put some resistors into its circuit to make it work properly, but i doubt thats the case with your original shield.

does the sd formatter work, by fatlib?

once its unreadable for arduino, the computer still has no problems in reading the data?

Which library are you using? and which filesystem u use to FORMAT the card?

i am not sure whether these things could effect the initialization of the card !!

i use
sdfatlib20111205
http://code.google.com/p/sdfatlib/downloads/list

i formatted with the sd formatter
sdfatlib20111205\SdFat\examples\SdFormatter

in my current project i just use SD.h instead of SdFat, but both worked

SD.h is SdFat. SD.h is just an API translation layer for an old version of SdFat. The Adruino group wanted a "simpler API".

Does it fail you run the SdFat QuickStart or SdInfo examples? If it fails what are the error codes?

fat16lib:
SD.h is SdFat. SD.h is just an API translation layer for an old version of SdFat. The Adruino group wanted a “simpler API”.

Does it fail you run the SdFat QuickStart or SdInfo examples? If it fails what are the error codes?

How to see the error codes?

I simply see “Card Initialization Failed” in the Serial Communication Window

You need to run the QuickStart or SdInfo examples in the SdFat/examples folder. The Arduino group didn’t include these examples so you need to download SdFat here http://code.google.com/p/sdfatlib/downloads/list

QuickStart’s output looks like this with the errorCode at the end:

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: 0x2, errorData: 0xff

SdInfo’s output looks like this:

card.init failed
SD errorCode: 0X2
SD errorData: 0X20

errorCode: 0x1, errorData: 0x0

& When i use the SDFormatter example it gives

error: cardSize
SD error: 10,ff

& When i format from computer and again format using the SDFormatter it gives

Card Size: 1886 MB, (MB = 1,048,576 bytes)

Erasing
...............
All data set to 0x00
Erase done

Formatting
Blocks/Cluster: 64
FAT16
error: write MBR
SD error: 6,4

It appears that your shield uses pin 4 as SD chip select.

Are you always using pin 4 as SD chip select in begin() and init() calls?

Some SD modules/shields almost work when the wrong chip select pin is used since pin 4 may float low most of the time.

Your errors are occurring at random times, not just at initialization time. This indicates use of the wrong CS pin, noise or bad SPI bus signals or a second SPI device interfering with the SD.

It does not appear that you have any other SPI devices.

Do you have anything connected to the SPI pins 10, 11, 12, 13?

Did you edit SdFormatter and define chipselect like this?

const uint8_t chipSelect = 4;

Nothings connected to pin 10-14 as far as i know,

I am using Chip Select pin 10 !!

The wireless shield uses pin 4 for SD chip select if you are using this shield http://arduino.cc/en/Main/ArduinoWirelessShield.

See the SDCS at pin 4 on the shield.

Edit SdFormatter to use pin 4 as above and try it.

You must use pin 4 as SD chip select in all sketches.

The shield works some times because pin 4 is not initialize and floats low. The shield will fail if pin 4 floats high.

Ooops

lol such a rookie mistake, i dont know where did i got the idea of always using CS 10 !

Thanks alot for the help and support,

But how come it worked on CS 10 as well ?

You could have used almost any pin for chip select and got the same result.

When a pin is uninitialized it may float low. To enable a SPI device you pull chip select low. So your uninitialized pin 4 was mostly enabling the SD.

You are not the first have this happen and you won't be the last.