0
votes

I am trying to read and write data to SD card but at the beginnig of code I am taking the error Card Failed or not presented.I changed the pins from the example code which is written for Arduino Uno but still gave the same error.I am using Arduino Mega 2560.How can I solve this problem?My code is here :

#include <SD.h>

// On the Ethernet Shield, CS is pin 4. Note that even if it's not
// used as the CS pin, the hardware CS pin (10 on most Arduino boards,
// 53 on the Mega) must be left as an output or the SD library
// functions will not work.
const int chipSelect = 53;

void setup()
{
 Serial.begin(9600);
 Serial.print("Initializing SD card...");
 // make sure that the default chip select pin is set to
 // output, even if you don't use it:
 pinMode(53, 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()
 {

 }
1

1 Answers

0
votes

Please add this:

digitalWrite(53, HIGH);

If it's low, the Wiznet chip corrupts the SPI bus. (More details)