Go Down

Topic: MicroSD not able to initialize often (Read 5 times) previous topic - next topic

SurferTim


Hopefully it will be the end of my reset-related woes!

It was for me! I've had no problems with the reset and the SD since.

I forgot to mention that on the Uno, digital pin 10 is the default slave select as well as the w5100 slave select. Since the SD.begin(4) call sets the default slave select as OUTPUT and HIGH, the w5100 is disabled in the SD setup on the Uno. But on the Mega, this is not the case. It must be disabled by your setup code.

jl-p

I see your code but is the code correct
because you mention you have to disable the W5100 chip. but you set pin 10 high before initializing the SD card.
after the initializing you set pin 10  high again.

logical i think

void setup() {
   Serial.begin(9600);

   // disable w5100 SPI while setting up SD
   pinMode(10,OUTPUT);
   digitalWrite(10,LOW);

   Serial.print("Starting SD...");
   if(!SD.begin(4)) Serial.println("failed");
   else Serial.println("ok");
   // SD.begin() returns with its SPI disabled. Good SD library!

   Serial.print("Starting w5100...");

   if(!Ethernet.begin(mac)) Serial.println("failed");
   else Serial.println("ok");

   // Ethernet.begin() returns with the SPI enabled (bug?), so disable it. Bad Ethernet library!
   digitalWrite(10,HIGH);

SurferTim

The Ethernet.begin() function is a bad puppy!  :( It returns with the w5100 SPI enabled. I think this is a bug. I did not say the functions were totally bug free. To patch the bug, you must disable it after that call.

The SD.begin(4) function returns with its SPI disabled like all SPI-based libraries should. It is a good puppy!  :)

jl-p

SurferTim, thx

added the lines like example below and it works like a charm.
I had the initialisation issue almost every boot but now only one time before it continues.
after i moved it before the while it's completly gone.


  pinMode(10,OUTPUT);
  while (!SD.begin(chipSelect)) {
  digitalWrite(10, HIGH);
  Serial.println("Card failed, or not present");}

SurferTim

#9
Oct 08, 2012, 10:52 pm Last Edit: Oct 08, 2012, 11:00 pm by SurferTim Reason: 1
Code: [Select]
 // enable w5100 SPI
 pinMode(10,OUTPUT);
 // now enable the SD SPI at the same time
 while (!SD.begin(chipSelect)) {
 // now disable the w5100 SPI after the SD fail
 digitalWrite(10, HIGH);
 Serial.println("Card failed, or not present");}

That will cause problems. You are enabling the w5100 SPI, then calling the SD.begin() function using the SPI.

I think this is what you said worked.
Code: [Select]
  pinMode(10,OUTPUT);
  digitalWrite(10, HIGH);

  while (!SD.begin(chipSelect)) {
    Serial.println("Card failed, or not present");
  }


Go Up