Go Down

Topic: SD CARD INITIALIZATION FAILS (Read 9139 times) previous topic - next topic

mr7919

May 15, 2014, 10:36 am Last Edit: May 15, 2014, 10:38 am by mr7919 Reason: 1


#include <SD.h>
#include<SPI.h>

const int chipSelect = 8;  

void setup()
{
 // Open serial communications and wait for port to open:
 Serial.begin(9600);
 while (!Serial) {
   ; // wait for serial port to connect. Needed for Leonardo only
 }


 Serial.print("Initializing SD card...");

 pinMode(chipSelect, OUTPUT);


 // see if the card is present and can be initialized:
 if (!SD.begin(chipSelect)) {
   Serial.println("Card failed, or not present");
   // don't do anything more:
   return;
 }
 Serial.println("card initialized.");
}

void loop()
{


}














This is my code to check the sd card in the sd card shield
I am using the following shield but I always get the same result that card initialization failed.Please help me this is the shield

http://www.rhydolabz.com/index.php?main_page=product_info&products_id=536

johnwasser

The seller of that shield says "Also for the libraries to work pin D10 will have to be set as an output in the 'setup()' section of your sketch. "  I would try that.
Send Bitcoin tips to: 1G2qoGwMRXx8az71DVP1E81jShxtbSh5Hp

fat16lib

Quote
Also for the libraries to work pin D10 will have to be set as an output in the 'setup()' section of your sketch. "

This should not be required for the SparkFun shield unless you have a second SPI device.

Please run this program to get more info.
Code: [Select]

#include <SD.h>
#include <SPI.h>
Sd2Card card;
SdVolume vol;
SdFile root;

// Chip select pin for SD card.
const int sdCsPin = 8;

// Replace the -1 with the CS pin number of any shared SPI device.
const int sharedCsPin = -1;

void setup() {
  Serial.begin(9600);
 
  // Disable any other SPI devices
  if (sharedCsPin >= 0) {
    pinMode(sharedCsPin, OUTPUT);
    digitalWrite(sharedCsPin, HIGH);
  }
 
  // Try to initialize the SD card
  if (card.init(SPI_HALF_SPEED, sdCsPin)) {
    Serial.println("card init OK");
  } else {
    Serial.print("errorCode: ");
    Serial.println(card.errorCode(), HEX);
    Serial.print("errorData: ");
    Serial.println(card.errorData(), HEX);
    return;
  }
 
  // Try to initialize the FAT volume.
  if (vol.init(&card)) {
    Serial.println("vol init OK");
  } else {
    Serial.println("vol init failed");
    return;
  }
 
  // Try to open root
  if (root.openRoot(&vol)) {
    Serial.println("open root OK");
  } else {
    Serial.println("open root failed");
  }
}
void loop() {}

If all is well you should see this:
Quote

card init OK
vol init OK
open root OK


If there is a hardware  problem with the shield or card you will see something like this:
Quote

errorCode: 1
errorData: FF


If the card format is bad you will see something like this:
Quote

card init OK
vol init failed

Or this:
Quote

card init OK
vol init OK
open root failed


Please post the results.

mr7919

Thank you all for your response .It was my bad.There was one loose connection and thats why this was happening :smiley-mr-green:

jamaliah

hi sir...
I got error which means hardware problems or card..
I used new microSd card..How I could solve this problem..
I used Sparkfun MicroSD shield and Arduino UNO board. For the Software, I use Arduino 1.6.5..

I really hope that you may help me...

chucktodd

hi sir...
I got error which means hardware problems or card..
I used new microSd card..How I could solve this problem..
I used Sparkfun MicroSD shield and Arduino UNO board. For the Software, I use Arduino 1.6.5..

I really hope that you may help me...
You need to provide more information:
  • create a simple Arduino sketch that reproduces your problem.
  • post that sketch, with a copy of the error messages.
    so we can review you sketch for errors
  • post a drawing of your circuit.
    so we can understand how the sketch is expecting the hardware be configured.


Chuck.
Currently built mega http server, Now converting it to ESP32.

ikarisan

Hi!

I am having the same problem. I tried the "DataLogger" example and modified it in a way that it outputs the errors' code and date. The interesting thing is, that it works once after every second reset!

Code: [Select]

<<< RESET button pressed >>>

Initializing SD card...Initialization failed.
Error code: 2
Error data: FF

<<< RESET button pressed >>>

Initializing SD card...Wiring is correct and a card is present.

<<< RESET button pressed >>>

Initializing SD card...Initialization failed.
Error code: 2
Error data: FF

<<< RESET button pressed >>>

Initializing SD card...Wiring is correct and a card is present.


I am using this adapter (link to eBay)

And if the initialization has been successful I can write exactly one time to a file. After the first file.open() / file.close() it cannot be opened again. :(

vijram

This should not be required for the SparkFun shield unless you have a second SPI device.

Please run this program to get more info.
Code: [Select]

#include <SD.h>
#include <SPI.h>
Sd2Card card;
SdVolume vol;
SdFile root;

// Chip select pin for SD card.
const int sdCsPin = 8;

// Replace the -1 with the CS pin number of any shared SPI device.
const int sharedCsPin = -1;

void setup() {
  Serial.begin(9600);
 
  // Disable any other SPI devices
  if (sharedCsPin >= 0) {
    pinMode(sharedCsPin, OUTPUT);
    digitalWrite(sharedCsPin, HIGH);
  }
 
  // Try to initialize the SD card
  if (card.init(SPI_HALF_SPEED, sdCsPin)) {
    Serial.println("card init OK");
  } else {
    Serial.print("errorCode: ");
    Serial.println(card.errorCode(), HEX);
    Serial.print("errorData: ");
    Serial.println(card.errorData(), HEX);
    return;
  }
 
  // Try to initialize the FAT volume.
  if (vol.init(&card)) {
    Serial.println("vol init OK");
  } else {
    Serial.println("vol init failed");
    return;
  }
 
  // Try to open root
  if (root.openRoot(&vol)) {
    Serial.println("open root OK");
  } else {
    Serial.println("open root failed");
  }
}
void loop() {}

If all is well you should see this:
If there is a hardware  problem with the shield or card you will see something like this:
If the card format is bad you will see something like this:
Or this:
Please post the results.
hi sir.. i tried your code.. got error message as below, what does it mean??? pls help to solve  it..

errorCode: 8
errorData: 5


thanks in advance...

Go Up