can i use 2 sd cards at the same time with teensy 4.1?

i am currently using teensy 4.1 with its built in sd_card read led animation frames and drive them to leds.
i want to add the audio adapter and use its sd card to play music simultaneously in sync with led animation that had been pre recorded with the music.

is it possible to manage 2 sd card in the same time if i seperate the spi pins?

i couldn't find what pins is the build in sd card using ( if any) i saw in the example of the audio library that it said:

// Use these with the Teensy 3.5 & 3.6 SD card
// #define SDCARD_CS_PIN BUILTIN_SDCARD
// #define SDCARD_MOSI_PIN 11 // not actually used
// #define SDCARD_SCK_PIN 13 // not actually used

if this means that pins 11 and 13 are not used for the built in sd card that is good because the rev d of the audio board uses pins 11 and 13,

has anyone tried this before?
also will managing 2 files on the same card will maybe be fast enough ?

thanks in advance
 
The audio adapter's SD card uses completely separate pins than the built-in SD card, and they are on separate SPI buses.

I would expect the built-in SD card to be faster than the audio adapter, since the built-in SD card can transmit 4 bits at a time, compared to the audio adapter 1 bit.

On the Teensy 4.x audio adapter (revision D or D2), pins 6, 10, 11, 12, and 13 are used for SPI. Pin 6 is the CS pin for the flash memory that you can solder to the adapter, and pin 10 is the CS pin for the SD card. Pins 11, 12, 13 are the SPI control pins used for both flash memory and the audio adapter's SD card (plus any other SPI devices using the first SPI bus).

Revisions A-C of the audio adapter for Teensy 3.x used pins 11 and 13 for the I2S audio stream, and you had to use the alternate SPI pins (7 and 14) on the Teensy 3.x boards. Note, the Teensy 4.x boards no longer support alternate SPI pins for the first SPI bus.
 
has anyone tried this before?

Yes, it's been done before and confirmed to work. It was discussed here on the forum. Maybe you can find that old conversation with crafty searching?

Briefly, for the 2nd card you'll need create another instance of SDClass and give it a distinctive name of your choosing. Then run begin() on that instance, and of course SD.begin() for the 1st card. If you want it to use a different SPI port, use the syntax shown in the SdFat_Usage example rather than ordinary begin().

I should also mention only 1 card is possible if using the old SD library we had in Teensyduino 1.53 and earlier. You need 1.54 or newer for multiple cards.

also will managing 2 files on the same card will maybe be fast enough ?

It really depends on the card. It also depends heavily on the data sizes your code uses. Almost all cards do better if you read and write in multiples of 512 byte sectors. For many cards, you get diminishing returns around 4096 or 8192 bytes... until you get to very large sizes which are unrealistic on a microcontroller with limited RAM.

If buying a new card, look for the A1 or A2 mark. Those mean the card will have decent performance for 4096 byte access (if the card is actually a reputable brand and not a counterfeit... the memory card market is flooded with cheap counterfeits so buyer beware). The SD / SdFat library only uses the A1 feature, so A2 is no better than A1 and many people have returned certain better quality A1 cards outperform others with A2 rating.

Also perhaps worth mentioning is the dedicated SPI option. If each card is on a different SPI port (or 1 is on Teensy 4.1's built in SDIO and other is on a SPI port) and you have no other SPI chips connected, you might get better performance if you use the special begin syntax for dedicated SPI.
 
I believe people who have previously reported success used separate buses for each SD card. But I don't have a link handy to those old conversations, so I'm just going from memory.

Use of the same SPI bus should probably work. If you use the special SdFat begin syntax, of course you must use the shared SPI option, which is the default when using the simple SD.begin() syntax.

The SDIO bus can't be shared. It only supports a single card.

You don't (or shouldn't) need to do anything special to manage which port is used. That is all handled by creating extra SDClass instances. Each will access the bus and CS pin you specify with its begin() function.
 
If you do connect 2 or more SD cards to the same SPI bus, be careful about wire lengths and ground connections. SPI is a high speed bus which isn't designed for long wires.

Just a couple days ago on this forum we had a conversation where someone made a PCB with 5 chips on the SPI bus and a connector to add a ribbon cable for expansion. When they plugged in a ribbon cable with nothing connected, just a cable of 10-12 inches length, the signal quality problems of trying to drive the long cable caused the 5 chips to no longer communicate properly.

Also be wary of SPI breakout boards with a 5V-3V buffer chip. Those buffer chips add delay. Many of them only work with older Arduino Uno that runs at only 16 MHz and has a max SPI clock of only 8 MHz. We regularly get people reporting problems with those cheap SD boards. The SdFat_Usage example shows how to configure slow clock because those low quality products are widespread. If possible, buy or build SD hardware that directly connects the card to the bus signals.
 
i tried setting up 2 different sd card with different instances , both seemed to initialize but then faild to read. also im unsure regarding the usage of

// SD card setup for Teensy Audio Shield
#define SDCARD_CS_PIN 10
#define SDCARD_MOSI_PIN 7
#define SDCARD_SCK_PIN 14

i mean yes each sd instance was initialized with it own cs pin, but what about the, mosi and sck defenitions assuming im using a rev c audio board with my teensy 4.1 ?
does it interfere with the built in sd cards comunication?
also, i saw that in the audio library inside it also uses the default sd instance, so do i need to change the internal library function to match ?
thanks in advace
 
ah i see, ok it also seems that my audio board is actually rev d,
any thoughts on the internal audio lib using the regular sd.open ?
 
Back
Top