SdFat lib inhibits LED_BUILTIN in SPI mode? (Micromod)

ninja2

Well-known member
When I run this sketch the LED blinks twice during setup, but doesn't flash in loop().
However, if I comment out the if-else SD initialisation, the LED flashes as expected.
Looks like an issue for SdFat lib, but I don't know where to look?
Code:
#include "Streaming.h"

#include "SdFat.h"

#ifdef ARDUINO_TEENSY_MICROMOD
  const uint8_t SD_CS_PIN = 44;
  #define SPI_CLOCK SD_SCK_MHZ(50)            // maximum. Reduce if errors ...
  #define SD_CONFIG SdSpiConfig(SD_CS_PIN, DEDICATED_SPI, SPI_CLOCK)
#else
  #define SD_CONFIG SdioConfig(FIFO_SDIO)     // inbuilt SD on T3,T4
#endif

SdFs sd;

void setup() {
  pinMode(LED_BUILTIN, OUTPUT);
  flashLED(2);
  while (!Serial && millis() < 1000);
  Serial << "\n\n------ TEST.b -----\n";
  if (!sd.begin(SD_CONFIG)) { sd.initErrorHalt(&Serial); }
  else { Serial << F("SD begin OK\n");}
  Serial << "---- setup done ---\n";
  }

void loop() {
  flashLED(1);
  delay(1000);
  }

void flashLED(int flashes){
  for (int i=0; i<flashes; i++){
    digitalWrite(LED_BUILTIN,HIGH); delay(100);
    digitalWrite(LED_BUILTIN,LOW);  delay(100);
    }
  }
 
I haven't used a micromod but it appears to use the same pinouts as the T4.0 and T4.1.
The SD SCK signal is on Teensy pin 13. This is the same pin as that used for the LED.
So, if you are using the SD, you can't use pin 13 for the LED output.
You'll have to work around it by connecting a LED and resistor to another pin and use that instead.

Pete
 
Yes - with your #if code, if you are building for the MICROMOD, you are using this setup:
Code:
const uint8_t SD_CS_PIN = 44;
  #define SPI_CLOCK SD_SCK_MHZ(50)            // maximum. Reduce if errors ...
  #define SD_CONFIG SdSpiConfig(SD_CS_PIN, DEDICATED_SPI, SPI_CLOCK)
This is saying, to use the SD in SPI mode, Dedicated which implies that sets the Chip select pin to LOW assuming there is
no other SPI devices on your SPI bus, And as mentioned pin 13 is the SLK clock pin for SPI, so the pin is set into SPI mode.
So your digital writes will not do anything. However if you actually used the SD, the led will flash as the clock pin goes high and low.

Your else clause says, to use SDIO not SPI for SD. Which can work on T3.5, T3.6, and all of the T4.x including Micromod.
T4 psds are on the bottom, MMOD they are exported as well
3466FPE1SD_B0_033.15Serial5(8) RTSSPI2(1) MISOPWM1_B1IO-07DATA1
3564SD_B0_023.14Serial5(8) CTSSPI2(1) MOSIPWM1_A1IO-06DATA0
3660*SD_B0_013.13Wire2(3) SDASPI2(1) CS0PWM1_B0IO-05CLK
3762*SD_B0_003.12Wire2(3) SCLSPI2(1) SCKPWM1_A0IO-04CMD
3868FPE0SD_B0_043.16Serial5(8) TXFLEXSPI B_SSO_BPWM1_A2IO-08DATA2
3970FNCS1SD_B0_053.17Serial5(8) RXFLEXSPI B_DQSPWM1_B2IO-09DATA3

However there are very few of the Sparkfun Adapters that are setup for SDIO. The ones that I have made, have SDIO setup.
 
Doh! Of course it's SCK. Many thanks

FWIW I should have mnentioned: When I previously ran the code above on my stock T4.1 the LED flashes work fine, since it uses SDIO

You'll have to work around it by connecting a LED and resistor to another pin and use that instead.
AFAIK there such pins aren't broken out on the Micromod boards, so not so easy. I could maybe do something over I2C?
It's not the end of the world, just a bit annoying.
 
Back
Top