The explanation (in this case) I discovered at http://blog.startingelectronics.com/dis ... et-shield/
As both the Ethernet library (and hardware) and the SD library (and hardware) use the SPI bus they must be carefully protected from each other during the initialization process. Whichever package is initialized last must be "hardware deselected" during the initialization of the package being done first. In my case the SD was done first so the Ethernet package must be disabled. Before the statement SD.begin(4); I need the statements
Code: Select all
// Now setup and test the microSD card
// The Ethernet chip is not yet initialized so we have to prevent it responding to the SD commands
pinMode(10,OUTPUT);
digitalWrite(10,HIGH); // Disable the Ethernet chip temporarily while we use the SPI bus to initialize the SD.
This results in (so far) total success 100% of the time and seems logical (and obvious when you think about it).
As this appears to be absolutely necessary for reliable function I think it should be included in the documentation for these cards (and probably for the Etherten and various ethernet shields etc.)