SD.begin() fails if executed a second time

Piachnp

Member
Hello,

I have a project where I have created a class that sometimes might be used on its own, sometimes it might be instantiated more than once. This class makes use of read/write operations on the SD card.
The problem is that when you instantiate this class more than once, the initialization process fails, as SD.begin(BUILTIN_SDCARD) returns false when run a second time.
The obvious solution is to potentially check if SD has already been running before calling SD.begin, but there doesn't seem to be an elegant way to do this.

While investigating this I noticed that this problem has been fixed in the arduino version of the SD library such that you can call SD.begin as many times as you want. This fix is not present in the Teensyduino version of the SD library. I have tested the fix and it works fine:

Code:
boolean SDClass::begin(uint8_t csPin) {
  /*

    Performs the initialisation required by the sdfatlib library.

    Return true if initialization succeeds, false otherwise.

   */

  [COLOR="#FF0000"][B]if(root.isOpen()) root.close();[/B][/COLOR]
 
  return card.init(SPI_HALF_SPEED, csPin) &&
         volume.init(card) &&
         root.openRoot(volume);
}

Not sure where else I should post in terms of opening issues for Teensyduino libraries...
 
It may be seen here - perhaps put a note and link to this thread on the TeensyDuino 1.52 Beta 1 thread.
 
Thanks for the suggestion, I wasn't sure where to post this. I've already posted in that thread. This can be closed
 
I see that now, good. Will leave this as a placeholder for the issue. When Beta 2 releases that thread will go idle and it may not get corrected.
 
Not sure where else I should post in terms of opening issues for Teensyduino libraries...

You can find most of the included libraries in the GitHub-Account from Paul: https://github.com/PaulStoffregen
The SD Library is also there: https://github.com/PaulStoffregen/SD

If you have a fix for a problem or bug, the best is to create a pullrequest. For simple changes, you can just edit the sourcecode at github (very easy) - Paul (and others) will be informed about your edit, and maybe, after a check, he will merge it to the official code. Or not.
If you have an Issue - or found a problem, you can open an "issue" there, too.

But please don't use GitHub for questions. Please ask questions here.
 
Back
Top