Hello,
Just though I would share a solution to a problem I had using the W5100 Shield on a Mega, (original and clones tried)
I have a big bespoke energy management system, Arduino Mega based, have a few out there in the field, all good. Trying to get some Internet connectivity for Log file uploads, mqqt etc and the best way forward was the W5100 Shield since that manages the CS of the SD and Ethernet signals properly to allow other SPI devices: I am also using a SPI CAN Interface and had all three working happily on another project,
So upgrading an existing system with the W5100 Shield (which I mount on a daughter board), the SD Card would not initialize with my code. But it would test okay with the SD examples / test sketches.
The lengthy fault finding involved commenting out blocks of my project code, comparing to the example which worked, until I got a result, which was the final line of 22k lines of code.
I did dig deep on the Interwebs, none of the hail Mary's worked.
What was the problem?
Briefly:
#include <SPI.h> // SD Card
#include <SD.h> // SD Card
#include <Ethernet.h>
#define SD_ChipSelect 4 // SD Chip Select
#define Eth_ChipSelect 11 // Ethernet CS
void setup()
{
pinMode(SD_ChipSelect, OUTPUT);
pinMode(Eth_ChipSelect, OUTPUT);
All looks good right? No.
Until I commented out this, which was not defined in the example but I thought wtf surely it can't be the issue. It was.
// pinMode(Eth_ChipSelect, OUTPUT);
The SD Card would not initialize.
To clarify that is defining the pin for the Ethernet CS as an output. Not the CS for the SD. I did try different pins as well but that setup has worked elsewhere. I obviously did not define the CS for the Eth before in previous projects.
Defies logic but that what made the SD card work.
This might save someone else a few days of fault finding, and a few sleepless nights.
Any thoughts? Cheers.