Ethernet shield never TX

Hello everyone,

Here is my problem : I stacked an Arduino Ethernet shield on a ATMega2560 (no jumpers added). I succeeded in reading/writing to SD card over SPI bus via ICSP headers but impossible to make the Ethernet work.

My code is :

#include "SPI.h"
#include "Ethernet.h"

byte mac[6] = { 0x90, 0xA2, 0xDA, 0x0D, 0xFA, 0xDE };

void setup() {
	Ethernet.begin(mac, IPAddress(192,168,1,72));
	pinMode(53, OUTPUT);
	delay(500);
}

void loop() {
	float ip[4];
	for (byte thisByte = 0; thisByte < 4; thisByte++) {
		ip[thisByte] = Ethernet.localIP()[thisByte];
	}
}

I also tried the complete Webserver example from Arduino IDE. And also tried to add more manual control of SS pins with for example :

pinMode(4, OUTPUT); // SD SS
digitalWrite(4, HIGH); // SD disable
pinMode(10, OUTPUT); // Ethernet SS
digitalWrite(10, LOW); // Ethernet enable

But normally the Ethernet library should manage this…

I wired the whole thing with an ethernet cable to my wifi box, but I can’t even Ping the arduino… It worked with my arduino UNO.

The ping request keeps returning “Host unreachable”. But the RX pin of the shield seems to receive the packets (blinking), but the TX pin never awakes…

Does anyone have an idea to solve my problem? Is it a network issue?

Thanks a lot.

It is a setup issue. The Mega uses different SPI pins that the Uno.

On the Uno, if you start the SD card first, it sets the default SPI slave select (D10) as OUTPUT and HIGH to set the SPI as master mode. This disables the w5100 by accident (a good thing for you).

On the Mega, it sets the default slave select (D53) to OUTPUT and HIGH, but leaves the w5100 SPI (D10) active. This will cause fails in the SD card startup.

Also, Ethernet.begin() leaves the w5100 slave select LOW. If you try to use the SD before any other w5100 functions, the SD access will fail. So after the Ethernet.begin() call, you must make another ethernet access call, or set D10 HIGH.

Here is the setup I use on my Mega.

void setup() {
   Serial.begin(9600);

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

   Serial.print(F("Starting SD.."));
   if(!SD.begin(4)) Serial.println(F("failed"));
   else Serial.println(F("ok"));

   Serial.print(F("Starting w5100.."));
   Ethernet.begin(mac,ip);
   digitalWrite(10,HIGH);

   // rest of your setup
}

Wow incredible!

I spent my whole day on this and you just saved me… But I am completely lost…

Setting a SS pin HIGH (like in your last line with pin 10) isn’t supposed to DISABLE the slave?

Your explanation seems intelligible but I think I do not really understand SD and Ethernet interactions… Furthermore, I tried the simplest code possible (like in my first post), so no interaction with SD, but it did not work… :roll_eyes:

A little enlightment would be an graal :sweat_smile:

memel182: Setting a SS pin HIGH (like in your last line with pin 10) isn't supposed to DISABLE the slave?

Yes, that is the point. All SPI slaves must have the slave select HIGH while not in a SPI device library call. Once the setup on the devices are complete, the library's low level read/write functions will handle the slave select for that device. You never need to change those again. The SD SS (D4) and the w5100 SS (D10) should always be HIGH, unless in a SD or Ethernet function call.

The Ethernet.begin() call is the exception to that rule. I consider the fact it leaves the w5100 SS LOW as a bug, but I have gotten used to dealing with it.

edit: Does the SD.begin(4) call work? It should display "Starting SD..ok" on the serial montor.

Ok I got it. You got the key, and your explanation is very clear. Quite a mysterious behavior nevertheless...

I did not try in details the SD card in this example, but will try a more complex code tomorrow, and keep you in touch with the results.

BTW, great thanks for this nice SPI course!

Glad I could help. Let me know if you need more info. Hopefully I can help you avoid all the trouble and pitfalls I went through. :)

Back again,

But I just wanted to confirm that my application seems to work like I wanted! Ethernet and SD cooperate and I can request a web page almost at the same time that data is written on SD! Hourra ;)

And another great thank to you!

You are very welcome. Glad I could get you started with the ethernet shield. Very good product.

Whoops, maybe a little too optimistic...

It seems that I have burned out the SD card... Can't even format it in Windows.

Will describe my problem in an another thread.

I thought that too. I messed up the format on my SanDisk 4GB card testing a user sketch. I played with it for a while, and I can't remember exactly what I did, but was able to reformat it with Windows XP pro with the format FAT32.

Thank you to continue to support me :)

Ok I will try to revive my SD card with some tools, but my problem is that I want to be able to avoid these burns... I opened a new thread "Ethernet shield and SD burned out" if you prefer to continue discussion there.

If you experimented this too, I would love some advices...