Hi, I have read all the topics relating to this issue but still cannot get it to work.
I am using an Arduino Uno R3 with the Arduino Ethernet Shield v1 to try and read a micro SDHC card. I have tried 2 different cards, 8GB and 16GB formatted to FAT32. I also tried formatting as a 4GB partition in FAT16.
#include <SPI.h>
#include <SD.h>
void setup() {
// put your setup code here, to run once:
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(4)) {
Serial.println("initialization failed!");
while (1);
}
Serial.println("initialization done.");
}
void loop() {
// put your main code here, to run repeatedly:
}
I have also tried setting pins 4 and 10 to output with pin 10 high and pin 4 low (and the reverse just to be sure). I even tried another Uno R3. No matter what, I get the error:
some SD card module handle SPI not properly and let other SPI devices not using SPI,
or, when error appear even without ethernet module, try reinsert card many times
initialization failed. Things to check:
* is a card inserted?
* is your wiring correct?
* did you change the chipSelect pin to match your shield or module?
It appears that the Ethernet Shield uses SPI to converse with the Uno, and for that D10 is used as CS. The SD card of course also uses SPI, but with D4 as CS.
Do you have a regular microSD card module that you could test with instead of the shield? It's just that when things get complicated, and things don't work, it's hard to know how to track them down. It could be something in the shield's library.
@ShermanP Unfortunately, I don't have another module except for an Ethernet Shield v2. What I don't understand is what is the point of the shield having an SD card reader, if it can't read SD cards on my Uno R3 ? Something here must not be right.
Tested with the Ethernet Shield V2, and it's working fine. So problem is somewhere with the Ethernet Shield v1.
The big ethernet chip on the shield is controlled by the Uno through SPI. That means it shares the MISO line with the SD card. I don't know how MISO is switched between the two sources, but I just wonder if the Ethernet chip has to be initialized by its library before it will leave MISO alone.
Well I'm just guessing here, and I have no experience with this shield. In theory if you specify CS for the SD card as D4, it should work. So I don't know what's wrong.
Try disabling the ethernet module before starting the SD card. Both are SPI.
void setup() {
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
// disable the ethernet
pinMode(10,OUTPUT);
digitalWrite(10,HIGH);
Serial.print("Initializing SD card...");
if (!SD.begin(4)) {
Serial.println("initialization failed!");
while (1);
}
Serial.println("initialization done.");
}
void loop() {
// put your main code here, to run repeatedly:
}
So v1 of the shield doesn't work, but v2 does? And that's just switching the shields, and not changing anything else? Well I'm sorry I can't shed any light on what might fix it.
Edit: I haven't mentioned this in a while, but a problem with some ethernet shields were solder bridges on the W5100 IC. Google "ethernet shield solder bridge" and select images.
@SurferTim Yes, I can confirm it does look like there are bridges across some of the pins compared to my shield v2. But the Ethernet connection works fine, it's just the SD card that isn't working? Also, why does my shield look different to that in the link?