SD card errors after reinsertion

I have a project where I would like to be able to remove and reinstall the SD card without resetting (rebooting) the Arduino. Currently if I can remove the SD card without issue, but once it is reinserted I have to reset the Arduino to be able to access the card again. Is it possible to insert a SD card while a program is running and be able to access it? What has to be done to be able to remove an reinsert an SD card with a running program?

I think you have to use the SD.begin () after the reinsertion because it initializes the SD library and the card.

Hello.
Do you have a data logger shield??
if yes , there are 2 point that named , CD and WP .
if sd card remove from shield , CD go to HIGH logic and when SD card is insert it go to GND .
also you can use the library function to check SD card is inserted or not.

At the end , i am sorry for my bad English writing .

Vahid

If you hot-unplug the SD card (remove while the system is running), then you should have an indicator to know when it's actually safe to do so. Removing it at the most inopportune moment, could lead to data corruption (that chkdsk most likely will detect).

Two conditions must be met in order to remove the SD card safely:

  • All opened files and directories must be closed. Otherwise, inconsistency may occur in the library (any file operation will fail, or potentially corrupt the filesystem if the reinserted card has a totally different content and somehow it's already initialized to the SPI mode); and some data might be lost (512 bytes at most).
  • One second must be elapsed since the last interaction with the card; this way you are guaranteed that any sent data is actually written into the physical medium.

Understood, Lucario448. I have plans to provide an indication when the card can be removed. In testing, the read/write is initiated by user action (currently a pushbutton) so this is not the issue. I have not had the time to try the suggestion to connect SD.begin() to the CD signal.

adwsystems:
I have not had the time to try the suggestion to connect SD.begin() to the CD signal.

But you have to.

SD cards default to their native SDIO protocol; so everytime it's inserted, you have to change it to SPI mode (with SD.begin() of course).

Side question to see if somebody can answer: will in the future the SD cards still support this mode?
SPI is like the "legacy mode" because it provides compatibility with the old MMC standard; and modern card readers for PC don't even support MMC (don't use SPI) anymore.

Or maybe this support is removed since SDXC? Does anybody managed to intialize a 64 GB or larger SD card with an Arduino?

Lucario448:
But you have to.

SD cards default to their native SDIO protocol; so everytime it's inserted, you have to change it to SPI mode (with SD.begin() of course).

I know. The point was that I haven't had a chance to circle back to that aspect of the project and test it. (winter's coming quick in these parts and there's other projects to be finished be she arrives)