Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 5 of 5

Thread: SD.begin() fails if executed a second time

  1. #1
    Junior Member
    Join Date
    May 2018
    Location
    NYC
    Posts
    16

    SD.begin() fails if executed a second time

    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.
    
       */
    
      if(root.isOpen()) root.close();
     
      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...

  2. #2
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    11,764
    It may be seen here - perhaps put a note and link to this thread on the TeensyDuino 1.52 Beta 1 thread.

  3. #3
    Junior Member
    Join Date
    May 2018
    Location
    NYC
    Posts
    16
    Thanks for the suggestion, I wasn't sure where to post this. I've already posted in that thread. This can be closed

  4. #4
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    11,764
    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.

  5. #5
    Senior Member+ Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany NRW
    Posts
    6,906
    Quote Originally Posted by Piachnp View Post
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •