SD Card ejection question

In the project I am working on, I need an SD card. I don't see any problems there - Touch wood!!

My question is - how do you remove a card and ensure that it is not being accessed.

Reading through the sd.h files, from the native SD library and from SD-Master from GitHub, there is obviously similarities. I see, in the SD-Master, the following, which does not appear in the native version:

//call this when a card is removed. It will allow you to inster and initialise a new card.
  void end();

Therefore I presume that I don't have to turn the Uno off to change the card. How do I ensure, though, that the card is not being accessed at the time of removal?

TIA

Fof

IamFof:
In the project I am working on, I need an SD card. I don't see any problems there - Touch wood!!

My question is - how do you remove a card and ensure that it is not being accessed.

Reading through the sd.h files, from the native SD library and from SD-Master from GitHub, there is obviously similarities. I see, in the SD-Master, the following, which does not appear in the native version:

//call this when a card is removed. It will allow you to inster and initialise a new card.

void end();




Therefore I presume that I don't have to turn the Uno off to change the card. How do I ensure, though, that the card is not being accessed at the time of removal?


TIA

Fof

I have never used an SD card with an Arduino, but I would program a LED on to tell me it was ok to remove the SD card.

Paul

My question is - how do you remove a card and ensure that it is not being accessed.

First, you have to call file.close() to physically write any pending data in the buffer to the card.
.
Second, you need to wait several hundred milliseconds after that before pulling the card, as the write can take some time.

Third, you need to block your program from writing while the card is removed. You may be able to use the card detect pad/pin on the sd module to detect if the card is in or not. You may be able to use a button to set a flag that sd writing is enabled or disabled.

As Paul suggests, you may want to be using an indicator led.

Fourth, you have to decided if you are going to use reset when the card is reinstalled and start a new file, or if you want to resume and append to the file you had. If the later case, you need to call sd.begin() when the card is reinstalled. The exact method will depend on whether or not you use SD.h or SdFat.h.

See this thread
http://forum.arduino.cc/index.php?topic=239157.msg1718831#msg1718831

@cattledog

That is just the information I was looking for. GREAT!! Thank you.

All I have to do, now, is to await the arrival of the module, and then I can start prototyping the code for it.

Fof

ps. Karma to both you and Paul