I'm using a Teensy 4.1 microcontroller for a project that involves saving some data to a series of SD cards.
I'm programming my Teensy 4.1 with the Arduino IDE v2.3.8 and Teensyduino v1.60.
While I am able to use the basic "SD.h" Teensyduino library in order to open & save data to an SD card in the in-built SD card reader onboard the Teensy 4.1, I am curious whether it is possible to de-initialize an SD card once it's been initialized with "SD.begin". I'm looking specifically for something that would disable the SPI bus the SD card uses.
It appears to me that Teensyduino's SD library is a wrapper for SdFat. In that library, there is an end function, which should effectively de-initialize a previously-initialized SD card.
However, it appears that using the lower-level classes that the Teensyduino SD library implements from SdFat doesn't quite work with a Teensy 4.1.
For instance, attempting to run the following basic example code that uses the `SdFat` and `FsFile` classes:
Just fails to initialize any SD card I put in the in-built SD card slot. If I try to use the SdFat library from the Arduino library manager, I get errors stating that I should only be using the Teensyduino SD library exclusively. I've tried formatting my SD cards to the "Fat32" and "ExFat" formats, to no avail.
Is there a way to programatically de-initialize an SD card on a Teensy 4.1 microcontroller, with the Teensyduino SD library? Has this ever been attempted before? Assuming it's possible, is it also possible to subsequently re-initialize the same or a different SD card with the same SD class?
If not, is there a way I could use the base SdFat class on a Teensy 4.1 instead of the Teensyduino SD library?
Thanks for your time, any guidance is appreciated.
I'm programming my Teensy 4.1 with the Arduino IDE v2.3.8 and Teensyduino v1.60.
While I am able to use the basic "SD.h" Teensyduino library in order to open & save data to an SD card in the in-built SD card reader onboard the Teensy 4.1, I am curious whether it is possible to de-initialize an SD card once it's been initialized with "SD.begin". I'm looking specifically for something that would disable the SPI bus the SD card uses.
It appears to me that Teensyduino's SD library is a wrapper for SdFat. In that library, there is an end function, which should effectively de-initialize a previously-initialized SD card.
However, it appears that using the lower-level classes that the Teensyduino SD library implements from SdFat doesn't quite work with a Teensy 4.1.
For instance, attempting to run the following basic example code that uses the `SdFat` and `FsFile` classes:
C++:
#include <SD.h>
SdFat sd;
FsFile file;
void setup()
{
Serial.begin(9600);
while (!sd.begin(BUILTIN_SDCARD))
{
Serial.println("unable to find SD card!");
delay(500);
}
}
void loop()
{
file = sd.open("test.txt", FILE_WRITE);
file.println("test");
file.flush();
file.close();
sd.end();
while (true)
{
delay(500);
Serial.println("done");
}
}
Just fails to initialize any SD card I put in the in-built SD card slot. If I try to use the SdFat library from the Arduino library manager, I get errors stating that I should only be using the Teensyduino SD library exclusively. I've tried formatting my SD cards to the "Fat32" and "ExFat" formats, to no avail.
Is there a way to programatically de-initialize an SD card on a Teensy 4.1 microcontroller, with the Teensyduino SD library? Has this ever been attempted before? Assuming it's possible, is it also possible to subsequently re-initialize the same or a different SD card with the same SD class?
If not, is there a way I could use the base SdFat class on a Teensy 4.1 instead of the Teensyduino SD library?
Thanks for your time, any guidance is appreciated.
Last edited: