PaulStoffregen / SD

70 stars 41 forks source link

Access 2 SD cards simultaneously #19

Open mariocaptain opened 5 years ago

mariocaptain commented 5 years ago

I need to play background audio while accessing the SD card for data logging at the same time on Teensy 3.5.

Since the SD instance can't read two files at the same time, I decided to use an additional micro SD card module, so 1 SD is for audio and the other is for data. Doesn't work either.

I would prefer to have to use only the onboard SD card. For audio, I am using the Teensy audio lib, while for data logging, I am using the EDB library which also includes this library (I deleted the standard Arduino SD lib to not be confused).

Using 1 card for both seems to be working as I see that the library allows multiple SD.open's , but when I use that as per EDB example, the audio is distorted and log data is corrupt.

Is there a way to mod this lib to enable proper multi-file or multi-card access?

UPDATE: Turn out there is also a conflict beenween Audio.h and SD.h. As long as I include Audio.h, SD.open used in EDB library will result in a deadlock.

Dave

cfeied commented 2 years ago

More than 2 years after the OP: multicard access along with audio does not require modifications to this library. I think this issue could be closed. For those who may see this in the future:

I have done this exact same thing successfully (simultaneously managing audio output from one drive and recording to another) using SdFat for the two SD cards and SerialFlash.h for the spi flash on the audioboard. IIRC the key is to set up SPI correctly:

1) Remap to use the correct MISO/MOSI/SCK pins based on what's required by other modules like the audio module. 2) Define all the correct CS pins for the various SPI interfaces and ensure you're using the right one for each drive definition.

This was before Paul released the new SD wrapper, but the exact same thing can be done using calls to SD.sdfs instead of SdFat directly. Here's the SPI definition / configuration block from my project ("WS6", which uses audio.h) in case it helps someone:

// ---------------------------------------
// WS V6 board SPI pins
#define SPI_MOSI_WS6 7
#define SPI_MISO_WS6 12
#define SPI_SCLK_WS6 14
#define SPI_CS_WIFI_WS6 16
#define SPI_CS_SD_AUDIOBOARD_WS6 10
#define SPI_CS_FLASHMEM_AUDIOBOARD_WS6 6
// -------------------------------------------
void DrivesClass::ConfigureSPI()
{
// Make sure none of the CS pins that may be connected to the SPI bus are floating.
// SPI pulls a CS pin low to activate the selected bus device.
pinMode(SPI_CS_WIFI_WS6, OUTPUT);
pinMode(SPI_CS_SD_AUDIOBOARD_WS6, OUTPUT);
pinMode(SPI_CS_FLASHMEM_AUDIOBOARD_WS6, OUTPUT);
digitalWriteFast(SPI_CS_WIFI_WS6, HIGH);
digitalWriteFast(SPI_CS_SD_AUDIOBOARD_WS6, HIGH);
digitalWriteFast(SPI_CS_FLASHMEM_AUDIOBOARD_WS6, HIGH);

// Ensure that the correct (potentially remapped) pins are being used for the primary SPI instance.
// For the WSV6 board these are defined in the config.h file.
SPI.setMISO(SPI_MISO_WS6);
SPI.setMOSI(SPI_MOSI_WS6);
SPI.setSCK(SPI_SCLK_WS6);
}