SD Eject & re-insertion?

I have a data logging thing running. I shut it off. Files closed etc. Pop out my SD card, read the files on the computer. Pop it back in and.. I can't make it restart without rebooting.

Is there a way of resetting the SD stuff without a reboot and re-calling SD.begin(); ?

Thanks!

-jim lee

Yes you can.
See Nick Gammon’s code here

See the code for “Atmega_Hex_Uploader_Fixed_Filename”

It looks to me like he's calling SD.begin() over and over 'till he sees an SD card. Is that an OK thing to do?

-jim lee

Ralph Bacon had a video on this subject. Apparently there is, or was, a problem with the SD library not having an SDend(). The video goes back aways, and I’m not sure it’s relevant anymore, but he illustrates the problem of card removal and reinsertion.

By the way, the module he’s using should not be used with 5V Arduinos. SD cards are 3.3V devices, and that module has no level shifters.

jimLee:
It looks to me like he's calling SD.begin() over and over 'till he sees an SD card. Is that an OK thing to do?

-jim lee

Well if Nick was doing it and got away with it, I suspect it's ok. That said, I know the SD library does use dynamic memory allocation when you open a file, so it might be worth checking the library to see what it does when you invoke SD.begin, but I'll guess it doesn't malloc anything or Nick's program would have crashed when he tested it.

jimLee:
Is there a way of resetting the SD stuff without a reboot and re-calling SD.begin(); ?

Without a reset: yes
Without re-calling SD.begin(): no

SD.end() does exist, so you should call it before any "hot" removal or swap attempt (close all opened files/folders beforehand though).
This is because otherwise there would be inconsistencies if the running program doesn't realize when the card was changed (for instance: assuming there's still an 8 GB card when you already switched to a 2 GB one); also SD cards exit from SPI mode after a power loss anyway.

By the way, to be even safer, remove the card when it enters in the standby state; which happens one second after the last access (issued command).

I'm running v1.8.8 of the IDE, and I don't see SD.end in the included SD library. Is there a preferred alternate SD library that includes it?

ShermanP:
I'm running v1.8.8 of the IDE, and I don't see SD.end in the included SD library.

Did they changed that in just a single revision? Really?

At 1.8.7, there is an end() function inside the SDClass (aka SD) class. Take a look at the sources ("SD.h" and "SD.cpp").

What happens is that it's not documented here ("deprecated", redundant, or why?), so obviously it's pretty unknown.

You're right. It's there. I guess I messed up the search.