Using SD Fat on Teensy 4.1

tedm

Active member
I'm starting a project that uses the SD card slot on the Teensy 4.1. Can anyone please provide:

1. An example of code that's written to use the SD Fat code on a Teensy 4.1 and using the SD slot on the Teensy 4.1 running QSPI?
2. Where are the recommended SD Fat drivers for use with a Teensy 4.1 located?
3. Where can I find the documentation that describes the functions available in that library?

Thanks in advance,

Ted
 
Simplest answer: Install the latest version of Teensyduino. Either 56 or 57 beta 3...

The install will install both the SD library as well as SDFat. Note: with the more recent versions of Teensyduino, SD is a thin wrapper on SDFat.
Note: you should verify that it builds with these versions and not with other versions of these libraries that might be contained in (sketches folder)/libraries

Maybe easiest to start of the examples. For example SD->listfiles

Which has stuff like:
Code:
#include <SD.h>

// change this to match your SD shield or module;
// Teensy 2.0: pin 0
// Teensy++ 2.0: pin 20
// Wiz820+SD board: pin 4
// Teensy audio board: pin 10
// Teensy 3.5 & 3.6 & 4.1 on-board: BUILTIN_SDCARD
const int chipSelect = 10;

void setup()
{
  //Uncomment these lines for Teensy 3.x Audio Shield (Rev C)
  //SPI.setMOSI(7);  // Audio shield has MOSI on pin 7
  //SPI.setSCK(14);  // Audio shield has SCK on pin 14  
  
  // Open serial communications and wait for port to open:
  Serial.begin(9600);
   while (!Serial) {
    ; // wait for serial port to connect.
  }

  Serial.print("Initializing SD card...");

  if (!SD.begin(chipSelect)) {
    Serial.println("initialization failed!");
    return;
  }
  Serial.println("initialization done.");
...
So for 4.1 you would want to use BUILTIN_SDCARD
Which will build using the qspi support.

As for reference. Not sure... There is some documention for SDFat up on github
 
Just to help anyone following in my footsteps...

To get documentation on SDFAT, go to this github page, download the zip file and expand it to a location of your choice, then look for the file index.html and open it in your browser (just double click in file explorer).
 
Back
Top