Go Down

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

jl-p

I have several mega's and WL5100 ethernet shields and sd cards.
but the have all the same issue.
when i upload my code the SD card isn't working any more.
when i disconnect it from my laptop and connect it again. it usualy works after sd card failed message.
but sometimes i need to power off and on several time before it start up.

if it works and i dont restart my arduino it keeps working without any problem.
but if i disconnect the power and power it on the issue is back.

any idea whats wrong

SurferTim

Try this. It disables the w5100 SPI while you are setting up the SD.
Code: [Select]
#include <SD.h>

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

  // disable w5100 SPI wile setting up SD
  pinMode(10,OUTPUT);
  digitalWrite(10,HIGH);

  Serial.print("Starting SD...");
  if(!SD.begin(4)) Serial.println("failed");
  else Serial.println("ok");
}

void loop() {
}


tails_naf

I think I am experiencing a similar issue using the Latest HW for Ethernet shield and Mega 2560 -

I had intermittent failures, where the SD card would init and I could list all files on the card - but not read any file contents. Sometimes a re-start could cause the card init to fail.

I think it is related (in part) to the SPI IO.

At the time, I was setting pin 10 as an output, and high.
The mistake I was making was that I thought 'SS' (pin 53), was the SD chip_select, and I was passing SS to the sd.init function.

It seemed when I did this the operation was flaky at best - though it did work in part.

Does anyone have a definitive description of what the following pins do:
Pin 4         = CS_SD   ?
Pin 10       = CS_Ethernet ?
Pin 53 (SS) = Must be set as an output, and preferably pulled high ?

I plan on trying to trace the PCB scheamtics, but if anyone has that done, it would be great.

SurferTim

Digital pin 4 is the SD slave select.
Digital pin 10 is the w5100 slave select.
Digital pin 53 is the default slave select.

The SD.begin(4) will set the default slave select as OUTPUT and HIGH.

If you are using a Mega, you must disable the w5100 slave select before initializing the SD. If you don't, the w5100 will trash up the SPI, and chances are the setup will fail.

The SPI data lines are on the ICSP pins as well as on pins 50-52 on the Mega and pins 11-13 on the Uno. The ICSP connector is how the ethernet shield gets those SPI lines from either model, not the digital pins.

This post has code that I use to initialize both devices if I want to use them together.
http://arduino.cc/forum/index.php/topic,125359.msg943368.html#msg943368

tails_naf

Thanks SurferTim, I'll give that a shot.
Hopefully it will be the end of my reset-related woes!


Go Up