-
Notifications
You must be signed in to change notification settings - Fork 46
Closed
Description
It seems that it is possible to use SdFat (with teensy 4.1)
But defining PREFER_SDFAT_LIBRARY seems not to work because of type of File
Can you provide a simple example please?
thanks
Here the code I use, no instantiation for the moment, just #include <IniFile.h>
#include <SPI.h>
#define PREFER_SDFAT_LIBRARY
#include <IPAddress.h>
#include <IniFile.h>
#define SD_FAT_TYPE 3
// SDCARD_SS_PIN is defined for the built-in SD on some boards.
#ifndef SDCARD_SS_PIN
const uint8_t SD_CS_PIN = SS;
#else // SDCARD_SS_PIN
// Assume built-in SD is used.
const uint8_t SD_CS_PIN = SDCARD_SS_PIN;
#endif // SDCARD_SS_PIN
// Try to select the best SD card configuration.
#if HAS_SDIO_CLASS
#define SD_CONFIG SdioConfig(FIFO_SDIO)
#elif ENABLE_DEDICATED_SPI
#define SD_CONFIG SdSpiConfig(SD_CS_PIN, DEDICATED_SPI)
#else // HAS_SDIO_CLASS
#define SD_CONFIG SdSpiConfig(SD_CS_PIN, SHARED_SPI)
#endif // HAS_SDIO_CLASS
#if SD_FAT_TYPE == 0
SdFat sd;
File file;
File configFile;
#elif SD_FAT_TYPE == 1
SdFat32 sd;
File32 file;
File32 configFile;
#elif SD_FAT_TYPE == 2
SdExFat sd;
ExFile file;
ExFile configFile;
#elif SD_FAT_TYPE == 3
SdFs sd;
FsFile file;
FsFile configFile;
#else // SD_FAT_TYPE
#error Invalid SD_FAT_TYPE
#endif // SD_FAT_TYPE
void setup() {
Serial.begin(112500);
while (!Serial) {}
Serial.println(F("\nType any character to begin."));
while (!Serial.available()) {
yield();
}
Serial.print("Initializing SD card...");
if (!SD.begin(SD_CONFIG)) {
Serial.println("initialization failed!");
return;
}
Serial.println("initialization done.");
// open the file.
file = SD.open("test.txt", FILE_WRITE);
// if the file opened okay, write to it:
if (file) {
Serial.print("Writing to test.txt...");
file.println("testing 1, 2, 3.");
// close the file:
file.close();
Serial.println("done.");
} else {
// if the file didn't open, print an error:
Serial.println("error opening test.txt");
}
// re-open the file for reading:
file = SD.open("test.txt");
if (file) {
Serial.println("test.txt:");
// read from the file until there's nothing else in it:
while (file.available()) {
Serial.write(file.read());
}
// close the file:
file.close();
} else {
// if the file didn't open, print an error:
Serial.println("error opening test.txt");
}
}
void loop() {
// nothing happens after setup
}
Metadata
Metadata
Assignees
Labels
No labels