The SD examples work with the new Ethernet shield on Duemilanove and Uno boards, but not with Mega boards.
In the init() functions there is the following statement:
// make sure that the default chip select pin is set to
// output, even if you don't use it:
The Ethernet shield uses Arduino Pin 10 as the Wiznet chip select.
That statement is redundant for '328 boards, since the card.init()
function in the SD library sets the SS_PIN high, and the SS_PIN is Arduino pin 10 for these MCUs. This is a slight modification of (and an improvement over) the original SdFat card.init()
function, which did not set SS_PIN high.
However, for Mega boards, SS_PIN is not pin 10, a digitalWrite statement to make Pin 10 go HIGH is required (somewhere) in order to disable the Wiznet chip.
I suggest the following:
Putting a digitalWrite(10, HIGH);
statement after the pinMode
statement in setup()
of each of the example sketches makes them work with Mega boards as well as the '328 boards. You could even use a conditional directive so that the two statements are only compiled for '1280 and '2560 boards.
Note that my tests were with Duemilanove, Uno, and Mega1280 boards. I do not have a Mega2560, but I believe the issues are the same (assuming that everything else
works on a '2560 board).
This confusion between SS_PIN and the device chip select has been the source of much frustration on the part of users with whom I have interacted. In addition to adding the digitalWrite
statement, a more informative comment might be in order.