Pages: [1]   Go Down
Author Topic: SD card init failure  (Read 1713 times)
0 Members and 1 Guest are viewing this topic.
Central MN, USA
Offline Offline
Tesla Member
***
Karma: 72
Posts: 7175
Phi_prompt, phi_interfaces, phi-2 shields, phi-panels
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged


Central MN, USA
Offline Offline
Tesla Member
***
Karma: 72
Posts: 7175
Phi_prompt, phi_interfaces, phi-2 shields, phi-panels
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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


Central MN, USA
Offline Offline
Tesla Member
***
Karma: 72
Posts: 7175
Phi_prompt, phi_interfaces, phi-2 shields, phi-panels
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged


Central MN, USA
Offline Offline
Tesla Member
***
Karma: 72
Posts: 7175
Phi_prompt, phi_interfaces, phi-2 shields, phi-panels
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
Code:
/*
  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
Logged


Central MN, USA
Offline Offline
Tesla Member
***
Karma: 72
Posts: 7175
Phi_prompt, phi_interfaces, phi-2 shields, phi-panels
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged


Central MN, USA
Offline Offline
Tesla Member
***
Karma: 72
Posts: 7175
Phi_prompt, phi_interfaces, phi-2 shields, phi-panels
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged


Offline Offline
Newbie
*
Karma: 0
Posts: 1
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

*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.
Logged

Central MN, USA
Offline Offline
Tesla Member
***
Karma: 72
Posts: 7175
Phi_prompt, phi_interfaces, phi-2 shields, phi-panels
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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!)
Logged


Pages: [1]   Go Up
Jump to: