Hello
I have a sketch using sd.h and SerialCommand.h which I pass commands over serial to create and write to files (commands in the sketch called CSD, LSD, DSD). This works fine.
I then added a command to list all the files on the SD card (SD). This is where it gets a bit weird.
I can create, read and write files all day long, but if I then open root "/" it doesn't return any files - and then the read/write fails.
However, if I open "/" after booting it works fine. Until I then create/read and write files - then "/" won't open any more. I thought it was due to not closing "/" - but I think I am closing that correctly.
Any ideas? What am I doing wrong?
Code snippets: I've tried two methods to list the root directory structure:
//FIRST METHOD TO READ DIR
if (!card.init(SPI_HALF_SPEED, 10)) {
Serial.println("initialization failed. Things to check:");
Serial.println("* is a card is inserted?");
Serial.println("* Is your wiring correct?");
Serial.println("* did you change the chipSelect pin to match your shield or module?");
return;
} else {
Serial.println("Wiring is correct and a card is present.");
}
if (!volume.init(card)) {
Serial.println("Could not find FAT16/FAT32 partition.\n\rMake sure you've formatted the card");
}
root.openRoot(volume);
root.ls(LS_R | LS_DATE | LS_SIZE);
root.close();
AND
//SECOND METHOD TO READ DIR
myFile = SD.open("/");
if(myFile) {
printDirectory(myFile, 0);
Serial.println("done!");
}
myFile.close();
return;
Both give pretty much the same response.
Any ideas?
FIXME_SD.ino (4.31 KB)
FIXME_SD.ino (4.31 KB)