Go Down

Topic: Reset when using the SD library (Read 1 time) previous topic - next topic

emc

I spent a while trying to to track down a repeating reset and eventually tracked it down to the following that is not the original code but simply to demonstrate the problem.

Code: [Select]


#include <SD.h>

#define SD_SELECT 4

String filename = "file1.txt";

void setup() {

}

void loop() {

    if (!SD.begin(SD_SELECT)) {

        while (1) {

            File logfile;


            logfile= SD.open(filename , FILE_WRITE);


            logfile.println("Some Date for the file");

            // At this point I test the current size of logfile and if to large create a new filename
            if (logfile.size() > 10000) {

                filename = "nextfilename.txt"; // iterate file name in some way...
            }

            logfile.close();
        }       
    }
}



I didn't find any mention of the issue or requirement to not do this in the reference but it looks like changing the variable 'filename' used to open the file before it is closed will cause a reset (crash).


Go Up