Initializing SD card...initialization failed!

I cannot get my card to initialize. I have read 10 different posts and tried many different things.

I am using the ReadWrite example (Arduino 1.6.9) Here is the code in case you don't have easy access.

/*
  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 I think Mega 50
 ** MISO - pin 12 I think Mega 51
 ** CLK - pin 13  I think Mega 52
 ** CS - pin 4    I have been using 53

 created   Nov 2010
 by David A. Mellis
 modified 9 Apr 2012
 by Tom Igoe

 This example code is in the public domain.

 */

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

File myFile;

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

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

  if (!SD.begin(53)) {
    Serial.println("initialization failed!");
    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();
  } else {
    // if the file didn't open, print an error:
    Serial.println("error opening test.txt");
  }
}

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

I am using this sparkfun breakout board.

I am also using a MEGA 2560

Finally to get the right voltages I am using something similar to this
http://garagelab.com/profiles/blogs/tutorial-how-to-use-sd-card-with-arduino with exception that I am using pins 50-53 on the MEGA.

My output is saying that my initialization is failing but I wanted to know what is happening. I put a scope up to the clock line and saw that my clock was working. I then put it on the MOSI line and a little ripple but not what I would consider a true data output. Why?

As suggested on a couple forum posts I tried setting my chip select as an output but that still didn't work.

pinMode(53,OUTPUT);
  digitalWrite(53, HIGH);

I would really appreciate some help with this. Thanks in advance!

jacob84401:
I cannot get my card to initialize. I have read 10 different posts and tried many different things.

I am using the ReadWrite example (Arduino 1.6.9) Here is the code in case you don't have easy access.

/*

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 I think Mega 50
    ** MISO - pin 12 I think Mega 51
    ** CLK - pin 13  I think Mega 52
    ** CS - pin 4    I have been using 53

created  Nov 2010
by David A. Mellis
modified 9 Apr 2012
by Tom Igoe

This example code is in the public domain.

*/

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

File myFile;

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

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

if (!SD.begin(53)) {
    Serial.println("initialization failed!");
    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();
  } else {
    // if the file didn't open, print an error:
    Serial.println("error opening test.txt");
  }
}

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




I am using this sparkfun breakout board. 
https://www.sparkfun.com/products/544

I am also using a MEGA 2560

Finally to get the right voltages I am using something similar to this 
http://garagelab.com/profiles/blogs/tutorial-how-to-use-sd-card-with-arduino with exception that I am using pins 50-53 on the MEGA.

My output is saying that my initialization is failing but I wanted to know what is happening. I put a scope up to the clock line and saw that my clock was working. I then put it on the MOSI line and a little ripple but not what I would consider a true data output. Why?

As suggested on a couple forum posts I tried setting my chip select as an output but that still didn't work.



pinMode(53,OUTPUT);
  digitalWrite(53, HIGH);




I would really appreciate some help with this. Thanks in advance!

The SPI interface on the MEGA is:
MISO: pin 50
MOSI: pin 51
SCK : pin 52
SS : pin 53

It looks like you have MISO and MOSI reversed. DO on the SD card should connect to MISO.

Also, the 3.3v output is only rated for 50ma, The SD card spec allows a card to use 200ma. Depending on your exact SDCard, the card could be browning out when it is trying to boot.

Chuck.

I'm having the problem now.
sd.begin never returns.
Not sure why that would be in this instance, the SD Card is the first thing I'm trying to initialise.

We might be able to offer more assistance if you posted your code. Read the sticky 'How to use this forum'.