Go Down

Topic: SD card init failure (Read 2 times) previous topic - next topic

liudr

I have SD card init failure with the arduino wifi shield R3 and a 4 GB SD card. The symptom is as such: After program upload (sample code ReadWrite from SD library Arduino 1.0), Arduino would repeatedly fail to init, tried other cards, same thing. I tried power down and resets and no luck. Then if I remove card, run program, it shows fail to init (as expected). Then I reinsert the SD card and reset, the card is detected. What could be causing this?

liudr

I tried a second Arduino wifi shield and the same exact problem.

liudr

If I use external power supply and unplug the USB, using the LED9 on the wifi shield as indicator, then if I initially power up the system, it fails to init SD card. If I push reset it then succeeds. I then tried to add delay but that didn't work. I sometimes get the card fail with just external power and reset won't help. I have to pull the card out, reset, wait for it to fail init, insert SD card, reset, then it works.

liudr

Code:
Code: [Select]
/*
  SD card read/write

This example shows how to read and write data to and from an SD card file
The circuit:
* SD card attached to SPI bus as follows:
** MOSI - pin 11
** MISO - pin 12
** CLK - pin 13
** CS - pin 4

created   Nov 2010
by David A. Mellis
updated 2 Dec 2010
by Tom Igoe

This example code is in the public domain.

*/

#include <SD.h>

File myFile;

void setup()
{
  Serial.begin(9600);
  Serial.println("Press a key to continue...");

  pinMode(10, OUTPUT);
  pinMode(9, OUTPUT);
  delay(2000);
//  while (!Serial.available())
//  {
//    ; // wait for serial port user input
//  }
 
//  Serial.read();
  Serial.print("Initializing SD card...");
  // On the Ethernet Shield, CS is pin 4. It's set as an output by default.
  // Note that even if it's not used as the CS pin, the hardware SS pin
  // (10 on most Arduino boards, 53 on the Mega) must be left as an output
  // or the SD library functions will not work.
   
  if (!SD.begin(4)) {
    Serial.println("initialization failed!");
    digitalWrite(9,HIGH);
    return;
  }
  Serial.println("initialization done.");
 
  // open the file. note that only one file can be open at a time,
  // so you have to close this one before opening another.
  myFile = SD.open("test.txt", FILE_WRITE);
 
  // if the file opened okay, write to it:
  if (myFile) {
    Serial.print("Writing to test.txt...");
    myFile.println("testing 1, 2, 3.");
// close the file:
    myFile.close();
    Serial.println("done.");
  } else {
    // if the file didn't open, print an error:
    Serial.println("error opening test.txt");
  }
 
  // re-open the file for reading:
  myFile = SD.open("test.txt");
  if (myFile) {
    Serial.println("test.txt:");
   
    // read from the file until there's nothing else in it:
    while (myFile.available()) {
    Serial.write(myFile.read());
    }
    // close the file:
    myFile.close();
    digitalWrite(9,HIGH);
    delay(500);
    digitalWrite(9,LOW);
    delay(500);
    digitalWrite(9,HIGH);
    delay(500);
    digitalWrite(9,LOW);
   
  } else {
  // if the file didn't open, print an error:
    Serial.println("error opening test.txt");
  }
}

void loop()
{
// nothing happens after setup
}



Using Arduino UNO and IDE 1.0

liudr

I switched to Adafruit sd logger and didn't get this problem anymore. I am using a different card though.

Tried MEGA, same result. Tried a Kingston micro sd card, new. Same result. Used microSD card adapter and on the Adafruit SD logger. Works no problem. I am lost.

liudr

Out of frustration I took out my MEGA 2560 clone and tried it. Worked with the arduino wifi shield and micro sd card, both USB and external power.

XiNNiW

*Bump* Having the same problem... really lost. Happens very inconsistently. sometimes a reset will fix it, sometimes not?! It seems to be the begin() method thats failing.

liudr

Hey,

I think I should post back. I have not had any problem since I started using MEGA2560 R3, which is the only board I use with SD card now. I don't know why earlier boards such as UNO R2 and MEGA1280 had this problem. I'm in the planning stage to include SD card in a board design with an ATMEGA328P-AU. Hope it works or I don't know what to do.

What is the board and revision of your arduino?
What is the Arduino IDE version you use?

I am going to try newer Arduino IDE versions with these older boards, when I have time.

(I hate this problem!)

UnoTotoro

I have the same problem with Seeed SD shield on Arduino Uno R3. I read on a different forum that using a different SD library can solve the problem. Will post the details here if that works out.

liudr


I have the same problem with Seeed SD shield on Arduino Uno R3. I read on a different forum that using a different SD library can solve the problem. Will post the details here if that works out.


Which library are you using? SD or SdFat?

I am using SdFat library now with MEGA2560 R3. I have not seen any problems since. I guess it may be due to the weak 3.3V supply on older boards (MEGA1280, UNO R2, Duemillanove) not able to supply enough power to the card for initialization. MEGA2560 R3 has a separate 3.3V supply. I designed a board also with a separate 3.3V supply. I have not seen any problem so far.

UnoTotoro

Thanks for the tip, I am using SD library. Will switch to SdFat and check it.

Seeed SD shield is powered from the 5V supply and converts it to 3.3V. The problem persists even if I power the boards with the USB port, without running the serial monitor.

liudr

Provide a link to the SD shield. I'll take a look at its design.

Which Arduino board and which version are you using?

UnoTotoro

Thanks a lot, that will be a great help!

This is the SD Shield:
http://www.seeedstudio.com/depot/sd-card-shield-v40-p-1381.html?cPath=132_134

The board is Arduino Uno R3:
http://arduino.cc/en/uploads/Main/ArduinoUno_R3_Front.jpg

For coding, I am using Arduino IDE 1.0

liudr

THe SD shield design looks decent. There is a 3.3V supply on board and a voltage level shifter as well. Have you tried different SD cards, say some 4GB cards? I am mainly using 4GB and 8GB cards.

UnoTotoro

Spot on! It works with a 4GB micro SD card (in a SD card housing).

I was using a 2GB Eye-Fi card. The Eye-Fi circuitry might also have caused a problem.

Thanks again for the help!

Go Up