Hello,
I have a little problem with my T_3.6 + audio-shield: I want to check if a sd-card is placed into the T_3.6 and, if not, than try to check if there is one installed on the audio-shield. But if I run the following code with a sd-card inside the T_3.6, it is not found:
This results in:
Checking on-board SD (T_3.6)
Checking audio-board SD (T_3.6)
Cannot find SD card!
-1
What am I doing wrong?
Regards, Holger
I have a little problem with my T_3.6 + audio-shield: I want to check if a sd-card is placed into the T_3.6 and, if not, than try to check if there is one installed on the audio-shield. But if I run the following code with a sd-card inside the T_3.6, it is not found:
Code:
#include <SPI.h>
#include <SD.h>
#define DEBUG 1
// Teensy Audio Shield
#define SDCARD_AUDIO_CS_PIN 10
#define SDCARD_AUDIO_MOSI_PIN 7
#define SDCARD_AUDIO_SCK_PIN 14
#ifndef TEENSY4
// Teensy 3.5 & 3.6 SD card
#define SDCARD_CS_PIN 4 //BUILTIN_SDCARD
#define SDCARD_MOSI_PIN 11
#define SDCARD_SCK_PIN 13
#else
#define SDCARD_CS_PIN 10
#define SDCARD_MOSI_PIN 11
#define SDCARD_SCK_PIN 13
#endif
int8_t check_sd_cards(void)
{
int8_t ret = -1;
SPI.setMOSI(SDCARD_MOSI_PIN);
SPI.setSCK(SDCARD_SCK_PIN);
#ifdef TEENSY4
#ifdef DEBUG
Serial.println(F("Checking audio-board SD (T_4.0)"));
#endif
if (SD.begin(SDCARD_CS_PIN))
{
#ifdef DEBUG
Serial.println(F("Using SD-card on audio-board (T_4.0)"));
#endif
ret = SDCARD_CS_PIN;
}
#else // not TEENSY4
#ifdef DEBUG
Serial.println(F("Checking on-board SD (T_3.6)"));
#endif
if (SD.begin(SDCARD_CS_PIN))
{
#ifdef DEBUG
Serial.print(F("Using SD-card on Teensy (T_3.6): "));
Serial.println(SDCARD_CS_PIN, DEC);
#endif
ret = SDCARD_CS_PIN;
}
else
{
// SD Card from audio-board
#ifdef DEBUG
Serial.println(F("Checking audio-board SD (T_3.6)"));
#endif
SPI.setMOSI(SDCARD_AUDIO_MOSI_PIN);
SPI.setSCK(SDCARD_AUDIO_SCK_PIN);
if (SD.begin(SDCARD_AUDIO_CS_PIN))
{
#ifdef DEBUG
Serial.println(F("Using SD-card on audio-board (T_3.6):"));
Serial.println(SDCARD_AUDIO_CS_PIN, DEC);
#endif
ret = SDCARD_AUDIO_CS_PIN;
}
}
#endif
#ifdef DEBUG
if (ret < 0)
Serial.println(F("Cannot find SD card!"));
#endif
return (ret);
}
void setup() {
delay(500); // needed for serial console
int8_t sd = check_sd_cards();
Serial.println(sd, DEC);
}
void loop() {
;
}
This results in:
Checking on-board SD (T_3.6)
Checking audio-board SD (T_3.6)
Cannot find SD card!
-1
What am I doing wrong?
Regards, Holger