Initializing SD Card Failed ?

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:

Initializing SD card...initialization failed!

I am out of ideas at this point.

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

run the CardInfo example. it is a diagnostics tool

@Juraj I did try that. I get the same error

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.

Do v1 and v2 use different libraries?

no. it is the SD library

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.

Edit: Did you look at this thread?

https://forum.arduino.cc/t/ethernet-sd-wont-recognize/83580/14

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:
}

^^^

@SurferTim I already tried that with no luck.

@ShermanP I did look at that thread before posting here. The solution to toggle the device that is active did not work for me.

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.

Ethernet shield V1 does work. I have one. No problem with the SD card. I have a web server docs on the SD card. Is this it?
https://docs.arduino.cc/retired/shields/arduino-ethernet-shield-without-poe-module/

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 Mine looks slightly different:

My IC:

the IC is the W5100 Ethernet chip

The pic isn't clear enough, but it appears that IC has solder bridges, 3 on the right and 2 on the bottom..

@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?

Do you have a voltmeter or o-scope?