A year or so back i created a device that uses a Mega 2560 and an Ethernet Shield 2.
I now need to create more of these devices and plan to replace the Ethernet Shield 2 with a W5500 Ethernet Shield.
The W5500 Ethernet Shield looks like it should replace the Ethernet Shield 2 with no hardware or software modifications (i was expecting too much lol!) but i have been unable to get the W5500 Ethernet Shield ethernet or sd card features to work on a Mega 2560.
Let me list what works and what does not work:
Mega 2560 + Ethernet Shield 2 = both ethernet and sdcard WORK
Mega 2560 + W5500 Ethernet Shield = both ethernet and sdcard FAIL
Uno + W5500 Ethernet Shield = both ethernet and sdcard WORK
By FAIL i mean:
The Ethernet2 library examples all fail to return from the call to Ethernet.begin(mac):
Serial.println("Before Ethernet.begin"); int result = Ethernet.begin(mac); Serial.print("After Ethernet.begin, result="); Serial.println(result);
The serial console shows the 'before' message but not the 'after' message.
A google search suggests that DHCP is failing and that if i leave the sketch a minute or two then the call will return 0 indicating DHCP failure.
I've left the sketch for many minutes and this call never returns.
The SdFat library examples all fail with error code 0x20.
A search of the SdFat library files doesn't tell me what this error code means, and neither does a google search.
I spent all of yesterday trying to find a solution but got nowhere, so am asking if anyone can suggest how to debug the problem.
Why do both SPI devices on the W5500 Ethernet Shield fail to initialize on a Mega 2560 but work fine on a Uno?
(The ethernet and sdcard features are both SPI features).
Note that in the library examples for both features i added code to set the (unused) Mega 2560 SS pin (pin 53) as an OUTPUT as recommended in various documentation.
I also added code to the Ethernet2 example to disable sdcard on CS 4:
// set mega 2560 SS pin to output mode pinMode(SS, OUTPUT); // disable sd card pinMode(4, OUTPUT); digitalWrite(4, HIGH);
The SdFat example already contains code to disable any secondary SPI device:
* Set DISABLE_CHIP_SELECT to disable a second SPI device. * For example, with the Ethernet shield, set DISABLE_CHIP_SELECT * to 10 to disable the Ethernet controller. */ const int8_t DISABLE_CHIP_SELECT = 10;
I can post the exact sketches that fail on the Mega 2560 but work on the Uno if required.