Mega Ethernet W5100 shield with SD Card problems

Hi guys,

I'm having trouble with my Mega 2560 with a W5100 Ethernet shield with SD Card.

A lot of SD card are not working with the shield. Is that normal? I have tested 5 cards all under 32GB and 3 of them are not working. I have tested with the Cardinfo example.

I have other problems, but I'll keep that for another thread.

Is there something I should know about exploiting both the Ethernet and SD card in a project?

Thank you

Can you split out the SD code and verify if they work without the enet shield hw? Then can you get the enet shield running w/o the sd hw? That should make it easier to combine & debug knowing the hw is solid standalone.

This is the example code ReadWrite which comes with Arduino IDE. Like I said some SD works and other don't, but on the PC all the sd cards work. I have used SD Card formatter software.


#include <SPI.h>
#include <SD.h>

File myFile;

void setup() {
  // Open serial communications and wait for port to open:
  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.");

  myFile = SD.open("test.txt", FILE_WRITE);

  // if the file opened okay, write to it:
  if (myFile) {
    Serial.print("Writing to test.txt...");
    myFile.println("testing 1, 2, 3.");
    // close the file:
    myFile.close();
    Serial.println("done.");
  } else {
    // if the file didn't open, print an error:
    Serial.println("error opening test.txt");
  }

  // re-open the file for reading:
  myFile = SD.open("test.txt");
  if (myFile) {
    Serial.println("test.txt:");

    // read from the file until there's nothing else in it:
    while (myFile.available()) {
      Serial.write(myFile.read());
    }
    // close the file:
    myFile.close();
  } else {
    // if the file didn't open, print an error:
    Serial.println("error opening test.txt");
  }
}

void loop() {
  // nothing happens after setup
}

Concerning the double usage of the shield, this is what I read from Mouser.com

Do NOT use the OS to format the sd cards. They can only use DOS 8.3 FAT directories.
Are you having trouble with different chips in the same hardware, or are you changing the readers?

I’m using different cards with the same hardware. Later I’ll try on another identical shield if I have the same trouble.

How should I format the SD card? I’m using the official SD card formatter tool that you can download for Windows.

Don't format them at all. Just use them as they come out of the package. They're default formatted for the lowest common denominator - DOS 8.3 FAT

begin(4) the SD card as first.
use the right CS pins 4 for SD and 10 for Ethernet.
if it doesn't help, set pin 10 HIGH before SD.begin.

Just a note that might help.

I had a power outage this weekend. The SD card wasn't detected anymore. I tried many solutions without success until I removed the volume name and then "voilà"! It worked. I really don't like this kind of magic, but it seemed to have fixed my problem.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.