SD-Card on Ethernet Shield refuses to initialize

Hi,

I got a basic Arduino Ethernet Shield with micro SD slot on a MEGA. It all worked fine for a couple of weeks (Ethernet and SD-Card), but now not even the "Card Info" example works.

What's surprising me is that I allways get a high (measured with voltmeter) on the "chipSelect-Pin (Pin 4)" when the card init starts. Shouldn't that be a low if I want to use the SD-Card?

Thanks for any help and a nice christmas to everybody :wink:

Slightly modified example code:

 // include the SD library:
#include <SD.h>

// set up variables using the SD utility library functions:
Sd2Card card;
SdVolume volume;
SdFile root;

// change this to match your SD shield or module;
// Arduino Ethernet shield: pin 4
// Adafruit SD shields and modules: pin 10
// Sparkfun SD shield: pin 8
const int chipSelect = 4;    

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("\nInitializing SD card...");

  pinMode(53, OUTPUT);     // change this to 53 on a mega
  digitalWrite(53, HIGH);
  pinMode(10, OUTPUT);     // change this to 53 on a mega
  digitalWrite(10, HIGH);
  
  digitalWrite(chipSelect, LOW);
  
  delay(3000);

  // we'll use the initialization code from the utility libraries
  // since we're just testing if the card is working!
  if (!card.init(SPI_HALF_SPEED, chipSelect)) {
    Serial.println("initialization failed. Things to check:");
    Serial.println("* is a card is inserted?");
    Serial.println("* Is your wiring correct?");
    Serial.println("* did you change the chipSelect pin to match your shield or module?");
    return;
  } else {
   Serial.println("Wiring is correct and a card is present."); 
  }
}
  

void loop(void) {
  
}

Leave the SD chip select HIGH. The library read/write functions will handle the slave select line. Try this code. Does the SD start ok with it?

#include <SD.h>

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
  }

  // disable w5100 SPI before starting SD
  pinMode(10, OUTPUT);
  digitalWrite(10, HIGH);

  Serial.print("Starting SD...");

  if (!SD.begin(4)) Serial.println("failed");
  else Serial.println("ok"); 
}

void loop() {
}

Thx SurferTim,

but I get the same result: "Starting SD...failed"

Have you tried reformatting the card? I had my SD lose its format while testing another user's ethernet sketch, and that code did not disable the SD card slave select. The SPI communication with the w5100 destroyed the SD format. No other device could detect the SD card had a format. I used Windows XP with FAT32 to reformat the card.

I did (twice trying FAT16 and 32) and now did it again only using your script, still no change.... Looking for another card now. But I don't think the card is broken works fine on my laptop

Update:

Now I tried two different cards and both didn't work. Maybe the shield is simply broken.

Ok, now I unplugged everything left him alone for an hour and plugged everything back in (port 22 - 53) and now its working again but I still don't know what was wrong especially because the ethernet shield isn't connected to any of this ports...

are there any buffers etc. on the mega I have to take care of?

The Ethernet Shield uses pins 50, 51, 52, and 53. These pins are either connected through the ISP connector or is SS (pin 53).

You can only use these pins with anther SPI device.