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(); ?
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).