SD Intermittent Initialization Failure

Combining the power of the ATmega2560 MCU with onboard Ethernet, a microSD card slot, an efficient switchmode power supply, and a small prototyping area. [Product page]
Post Reply
skiphod
Posts: 5
Joined: Sun Apr 26, 2015 6:45 am

SD Intermittent Initialization Failure

Post by skiphod » Sun Aug 07, 2016 10:52 pm

There are a number of posts about intermittent SD initialization on cards or shields that contain both Ethernet chips (W5100) and SD features. Many suggestions are proposed including low capacity power sources (USB) needing external DC power, careful attention to correct CS pins, proper pull-ups on data lines etc. etc. I had this problem too with EtherMega cards, about 25% of the time the SD initialization step SD.begin(4); would fail and retrying under program control would never succeed. The intermittent nature of the problem sounds very "hardware"; but not so.

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.
There is no need to undo this operation as the subsequent initialization of the Ethernet will take care of that.

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.)

danieldewaard
Freetronics Staff
Freetronics Staff
Posts: 33
Joined: Thu Jul 14, 2016 2:41 am

Re: SD Intermittent Initialization Failure

Post by danieldewaard » Sat Aug 13, 2016 7:35 am

Hi skiphod,

Thanks for the useful post. I'll have a closer look at the link and we will possibly include it in the appropriate sections on our website :)

Daniel

Post Reply