In the Arduino 1.0.5 example named listfiles there is a mistake.
Instead of
if (!SD.begin(10)) {
Serial.println("initialization failed!");
return;
}
it should be written
if (!SD.begin(4)) {
Serial.println("initialization failed!");
return;
}
because on the Ethernet/SD shield the value of CS for SD is 4
That is not the only error if you are using the ethernet shield. (add: If you have a Mega) You must disable the w5100 SPI or you will have a SPI bus contention problem.
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.
pinMode(10, OUTPUT);
// If you do not disable the w5100 SPI here, you will have a SPI bus conflict.
digitalWrite(10, HIGH);
if (!SD.begin(4)) {
Serial.println("initialization failed!");
return;
}
Serial.println("initialization done.");
Other SD shields use D8 as the slave select.