Teensy 4.1 SD card CS pin

SteveSFX

Well-known member
Am I correct in assuming the onboard SD card slot on a Teensy 4.1 is on pin 4?

If yes... damn. Had a PCB made that uses pin 4 for something else, and now it's come to light I need to use the SD card slot.

All the SPI pins are available, I just have pin 4 allocated as an I/O that I now can't change.

Didn't realise I might need the SD card.

No options I assume...
 
The T_4.1 BUILTIN onboard SD card uses direct to processor SDIO pins - it touches none of the other edge pins provided.
SDIO provides faster 4 bit I/O access and is a single device on that SDIO bus and requires no CS.
Looking in the examples there is a special value to set for the CS pin that tells it that the BUILTIN_SD device it to be used.
 
Your not the only one! Last pcb had miso and mosi switched. One before was using an esp32 and had connected up an input only as an output
 
I have literally held off having this pcb made for 2 months. I breadboarded the whole thing, made individual test boards for the Opto-isolators, DMX isolation, PSU etc. Tested every angle.

Then, 30 minutes after pressing 'GO', I get an email asking could it download all data to an SD card.

I did breakout Mosi, Miso, Sck, I2C, 1x serial pair and some spare I/O pins to a multiway header for future use.
I could always add a remote SD card if needed.
 
You've probably already seen this by now, but just in case I want to make sure your original question is answered.

Am I correct in assuming the onboard SD card slot on a Teensy 4.1 is on pin 4?

You can find the schematic on the Teensy 4.1 page under Technical Information. The page has a lot of info, so you'll probably need to scroll down.

Pin 4 isn't used. In fact, none of the ordinary pins are used, and it isn't even the 4 signal SPI connection. It's a 6 signal SDIO connection.

1703941424008.png


SDIO uses 4 bits for data, and 1 bit for command input, so it's quite different from SPI. When you write SD.begin(BUILTIN_SDCARD), the SD library uses completely different driver code to access this non-SPI hardware.


I did breakout Mosi, Miso, Sck, I2C, 1x serial pair and some spare I/O pins to a multiway header for future use.
I could always add a remote SD card if needed.

Yes, if you have pins for any of the SPI ports and any I/O to use as CS, you could add a SD card that way.
 
Is there any demo code for the SD card for the 4.1?

I am getting errors thrown up all over the shop. Is is SD.h or SdFat.h?
Neither of those compiles...
SD.h throws up:
#error "Teensy's SD library uses a custom modified copy of SdFat. Standard SdFat was mistakenly used.

SdFat.h throws up:
warning File not defined because __has_include(FS.h)

SdFat says I need to take steps to ensure it uses Teensy's special copy of SdFat?
 
Hmm

SD.begin(BUILTIN_SDCARD) throws up an error to.
So confusing.... you declare #include <SD.h>, then the errors throw up stuff about SdFat.h.
It can't find the Teensy version of SdFat.h? Want me to delete other versions..... eh? I don't want to break all my Arduino versions of SdFat.h
Where is the Teensy version of SdFat.h kept?

I wish this stuff would learn to play together.

Bin the SD card idea. Life is too short
 
@SteveFX, remove the SDFat library from your local library. latest TD (don't recall which version) integrated SDFat and made SD an interface to SDFat. Use only SD calls.
 
Well, I had alos to do frequently the decision: TD or not. Unfortunately, SDFat from TD is diverged from Bill's version in more than one point.
You can use SDFat functionality by using SD.sdfat.xxx, but most funtionality is also accessible vit SD interface. As you know, checking out the examples may help.
 
Won't that break anything I ever made before using SDfat? (that calls SDfat at the beginning)
It may or may not... I think it is reasonably compatible...
I do wish however it was named differently in TD, or alternatively that Teensy builds were of a different architecture other than AVR, that could be specified in the library properties...

Needless to say having inside of TD install, means it does not work with any other boards that are not part of TD... I find in many cases I can solve that by installing the Adafruit version of the SDFat library. The library choosing code will typically then grab the Teensyduino version for Teensy builds and the Adafruit for everything else.
 
A solution I use is to have a ZIP folder in Libraries called Hidden_Livaraies.zip.
Place the libraries you want to be temporarily hidden into this directory/zip file.
In this case SdFat.
Compile your Teensy program and all should be fine.
When done with Teensy put the SdFat library back.
 
Back
Top