sdfat lib init problem

Hi,

with the following:

  • seeeduino MEGA 1280
  • gravitech board
  • sdfatlib20101010.zip
  • SDFatInfo.pde from sdfat example
  • lexar 2G

I have the following behavior:

when I load the sketch and the SD card is already in, it does NOT
detect the SD card no problem. Eject SD Card and reinsert without
cutting power, it does work:

init time: 6

Card type: SD2

Manufacturer ID: 1B
OEM ID: SM
Product: 00000
Version: 1.0
Serial number: 2433431162
Manufacturing date: 4/2010

cardSize: 3964928 (512 byte blocks)
flashEraseSize: 128 blocks
eraseSingleBlock: true

if I remove power on the arduino and power back, I get:

card.init failed
SD error
errorCode: 1
errorData: FF

if I eject and re-insert without cutting power, the card.init works again....

so basically, I have to eject/re-insert the SD card every time power is applied to the mega. Anyone might know what is happening?

thanx a lot

Mart

Sounds like a race condition between the Arduino code at reset and the SDcard power-on-reset. Ensure the SD library is initialized immediately on sketch start-up so that the SPI bus isn't floating. You might want to add a pull-up resistor on the Slave-Select line and a pull-down on the SCLK.

SD library is initialized? You mean an card.init()? It might not have an SD card in at startup...

I have added the following in setup():

// microSD Init
pinMode(PIN_CARD_DETECT, INPUT);
digitalWrite(PIN_CARD_DETECT, HIGH);

pinMode(PIN_CHIP_SELECT, OUTPUT); // set the SS pin as an output (necessary!)
digitalWrite(PIN_CHIP_SELECT, HIGH);

pinMode(PIN_MOSI, OUTPUT);
digitalWrite(PIN_MOSI, HIGH);

pinMode(PIN_MISO, OUTPUT);
digitalWrite(PIN_MISO, HIGH);

pinMode(PIN_SPI_CLOCK, OUTPUT);
digitalWrite(PIN_SPI_CLOCK, HIGH);

I will try with a digitalWrite(PIN_SPI_CLOCK, LOW);

Make sense?

Mart

Well it might make a difference...

I have tried:
digitalWrite(PIN_SPI_CLOCK, LOW);

with no success :frowning:

Mart

You don't need any of the pinMode and digitalWrite stuff. SdFat handles it in card.init() or sd.init().