Hey,
I have a project I am moving to the Due and am trying to get what used to work on the Mega 2560 working on the Due. Specifically I have a Ethernet Shield R3 and am trying to use both the SD card and Ethernet interface in one sketch.
Unfortunately I am having some problems getting the ethernet to work after initializing the SD card. If I use the stock SD library (not SdFat) it seems to be able to initialize both, I used to use the stock SD library but switched to SdFat as I needed some of the extra functionality plus I know the SD library uses (or used to use for avr) SdFat internally so i'm not sure why now SD works and SdFat doesn't (to be fair SdFat for Due is in beta, I am using the version from the 12/3/2012).
Let me show you some code (not full sketches):
SdFat sd;
// disable w5100 SPI while setting up SD
pinMode(10,OUTPUT);
digitalWrite(10,HIGH);
if (!sd.begin(4, SPI_HALF_SPEED))
{
sd.initErrorHalt();
Serial.println("Failed to init SD card");
return;
}
else
Serial.println("SD init done");
// now disable SD card CS and enable ethernet CS
digitalWrite(4, HIGH);
digitalWrite(10, LOW);
if (Ethernet.begin(mac) == 0)
{
Serial.println("Failed to configure Ethernet using DHCP");
return;
}
As you can see I enable the SD card CS and disable the ethernet one before initializing the SD card and then reverse the procedure for initializing the ethernet (ala Arduino Mega 2560 ethernet/sd shield issue. - #2 by SurferTim - Networking, Protocols, and Devices - Arduino Forum).
When it gets to initializing the ethernet interface the code hangs and this point and the "Failed to configure" line is not printed.
If I omit the digitalWrite statements, SD inits ok and the ethernet fails and returns immediately. I'm pretty sure I have my pin numbers correct for the two CS lines, they seem to be the same as the mega (Arduino Forum).
The following code using the stock SD library works:
if (!SD.begin(4)) {
Serial.println("SD initialization failed!");
return;
}
Serial.println("SD initialization done.");
// start the Ethernet connection:
if (Ethernet.begin(mac) == 0) {
Serial.println("Failed to configure Ethernet using DHCP");
return;
}
If anyone has gotten this working (SD card using SdFat AND Ethernet) please let me know, or if anyone has any ideas as to what I'm doing or not doing wrong
If fat16lib or any of the other SdFat guys have any ideas that would be great. Happy to help debugging the problem given SdFat for Due is beta.
Cheers,
JayCee