Go Down

Topic: What is the proper procedure to mount/unmount SD card with SD library? (Read 1 time) previous topic - next topic

liudr

I am having some doubts that I did mount/unmount of SD card correctly. I often get errors when using Sd cards on adafruit data logger shield, such as not able to begin.

I suspect that just inserting the SD card and pulling it out is not the proper procedure.

Before I can unmount an SD card, do I need to call any function to stop it?
If I insert the card again, do I need to start it before reading from it?
If I have opened a file to write on the SD card and then remove the SD card, when I insert the card again, will I be able to just continue to write on the same file or do I need to reopen it?

I wish someone has answered my question about the whereabout of the SD library manual.

PaulS

Quote
Before I can unmount an SD card, do I need to call any function to stop it?

You need to close any open files.

Quote
If I insert the card again, do I need to start it before reading from it?

No. The device has no way of knowing that the card has been inserted/removed.

Quote
If I have opened a file to write on the SD card and then remove the SD card, when I insert the card again, will I be able to just continue to write on the same file or do I need to reopen it?

Neither. Removing the card without closing the file corrupted it.

Quote
I wish someone has answered my question about the whereabout of the SD library manual.

There are a number of variations of "the SD library". You weren't specific enough.

In any case, nothing that the library does differs in any radical way from reading/writing files on a PC, except that the media is removable.

liudr

Thank you Paul. I will make some changes to my code to see if closing and reopening the file will eliminate all the errors.

I am using this library from adafruit:

https://github.com/adafruit/SD

I looked "everywhere" but can't find a documentation. Hope someone can point me to it.

liudr

Something I got from adafruit forum:

Quote
Once you remove the card the serial connection is broken / severed and you must re initialize the connection.


Documentation: http://arduino.cc/en/Reference/SD

Go Up