Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 18 of 18

Thread: Teensy 3.6 hangs if SD card present

  1. #1

    Teensy 3.6 hangs if SD card present

    I have a Teensy 3.6 that will hang if there is an SD card in the slot. I have tried three different SD cards and the outcome is the same. All three SD cards work OK in another Teensy 3.6, so the issue seems to be with one Teensy.

    The issue is easy to replicate with the following code:

    Code:
    #include <SPI.h>
    #include <SD.h>
    
    // Teensy 3.5 & 3.6 SD card
    #define SDCARD_CS_PIN    BUILTIN_SDCARD
    #define SDCARD_MOSI_PIN  11
    #define SDCARD_SCK_PIN   13
    
    int16_t check_sd_cards(void)
    {
      int16_t ret = -1;
      SPI.setMOSI(SDCARD_MOSI_PIN);
      SPI.setSCK(SDCARD_SCK_PIN);
      Serial.println(F("Checking on-board SD (T_3.6)"));
      if (SD.begin(SDCARD_CS_PIN))
      {
        Serial.print(F("Using SD-card on Teensy (T_3.6): "));
        Serial.println(SDCARD_CS_PIN, DEC);
        ret = SDCARD_CS_PIN;
      }
      if (ret < 0)
      {
        Serial.println(F("Cannot find SD card!"));
      }
      return (ret);
    }
    
    void setup() {
      while(!Serial);
      delay(500); // needed for serial console
      int16_t sd = check_sd_cards();
      Serial.println(sd, DEC);
    }
    
    void loop() {
      ;
    }
    With no SD inserted this is the serial output:

    Code:
    07:47:11.476 -> Checking on-board SD (T_3.6)
    07:47:11.509 -> Checking audio-board SD (T_3.6)
    07:47:13.504 -> Cannot find SD card!
    07:47:13.504 -> -1
    With SD card inserted it hangs at SD.begin:

    Code:
    07:54:19.559 -> Checking on-board SD (T_3.6)
    These are the libraries being used:

    Code:
    Using library SPI at version 1.0 in folder: /home/adrian/arduino-1.8.13/hardware/teensy/avr/libraries/SPI 
    Using library SD at version 1.2.2 in folder: /home/adrian/arduino-1.8.13/hardware/teensy/avr/libraries/SD
    Is this a hardware issue? Is there any workaround or known issue that can be resolved?

    Many thanks,

    Adrian

  2. #2
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    15,268
    Not sure why the spi pin games? Not sure it relates to the issue at hand ...
    Code:
    #define SDCARD_CS_PIN    BUILTIN_SDCARD
    #define SDCARD_MOSI_PIN  11
    #define SDCARD_SCK_PIN   13
    
    int16_t check_sd_cards(void)
    {
      int16_t ret = -1;
      SPI.setMOSI(SDCARD_MOSI_PIN);
      SPI.setSCK(SDCARD_SCK_PIN);
    When the onboard "BUILTIN_SDCARD" - it uses SDIO bit bit SPI not in any way related to standard SPI pins. The SDIO pins for data and control are unique to that SD socket and not connected to anything but the MCU - with no option to change them.

    If using an SPI SD card then it has a CS_PIN that cannot use the one on the BUILTIN_SDCARD - which uses a hard coded pin and BUILTIN_SDCARD is an out of pin range value used as a flag.

  3. #3
    Senior Member CorBee's Avatar
    Join Date
    Jun 2018
    Location
    Netherlands
    Posts
    507
    The code is from https://forum.pjrc.com/threads/60074...r-audio-shield

    Indeed the SPI has no function since we are using the builtin_SD. But this code does work to test the functionality of the SD-card on the T3.6 board itself. The main question is, how can one debug a possible hardware issue.

    cheers
    cor

  4. #4
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    15,268
    Was wondering why SerMon output showed AUDIO when the code snippet did not.

    But 11 and 13 are the T_3.6 default functions for those pins - so those lines are not useful - unless moving SCK to #14 with audio adapter.

    Look on the MICROMOD thread - I just posted 'NewPinTest'

    Put that on the T_3.6 with no SD card and with a wire as appropriate ( GND or 3.3V depending on test ) carefully touch the appropriate soldered points on the PCB's SD END.

    Using this as a guide it will show active pin numbers ( they may not match this T_4.1 drawing )
    Click image for larger version. 

Name:	teensy41_sdcard_pinout.png 
Views:	24 
Size:	150.1 KB 
ID:	24272

    Pin Numbers may differ on SerMon - but the function is the same - RE carefully :: avoid the GND and 3.3V

    If the startup doesn't show problems on those pins then they should not be shorted - and if they report change when touched they are usably functional for digital I/O?

    If that 'rings out' properly - then check PCB for a missing component? Maybe try a 'harmless' 15 second Restore?

  5. #5
    Senior Member CorBee's Avatar
    Join Date
    Jun 2018
    Location
    Netherlands
    Posts
    507
    Which message # in the micromod thread should this be, I dont see code marked NewPinTest ?

  6. #6
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    15,268
    thread search found it for me - #34 :: MicroMod-Beta-Testing

    I did edit a BOLD label with advanced on it just now.

  7. #7
    Senior Member CorBee's Avatar
    Join Date
    Jun 2018
    Location
    Netherlands
    Posts
    507
    Thanks, I got tricked by your "I just posted" , the forum states yesterday

    I hope that Adrian can test this out, that way we might save a T3.6 he is using in our bat-detector project.

    regards
    Cor

  8. #8
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    15,268
    I saw 'just' written after I posted and started to edit - but never know if posts are read before I can edit ... but the MMod JUST arrived

    That test was created - with two of them special - when @loglow was making his Teensy 4.0 breakout and picking up the SD pins to it - those pins were getting messed with ...

    Other than that I've not seen T_4.1 SD problems like there

  9. #9
    I have tried to compile the 'NewPinTest' sketch and get the error: 'GPIO8_GDIR' was not declared in this scope.

  10. #10
    Senior Member CorBee's Avatar
    Join Date
    Jun 2018
    Location
    Netherlands
    Posts
    507
    Hi,

    I see thats a variable declared in https://github.com/PaulStoffregen/co...y4/core_pins.h but your request is for a T3.6.
    @defragster: which include should be used for this ?

    regards
    Cor

  11. #11
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    15,268

    NewPinTest

    Opps - that was updated for use on a T_4.0 and 4.1 - not properly #ifdef'd it seems ... I wondered about that ... I'll give it a look ...

    Here is a quick edit to pull out the 1062 specific code Paul wrote to test that was included. It just nullifies that function with : #ifdef GPIO8_GDIR
    Code:
    uint32_t xx = 3; // pick TEST inloop() :: 0,1,2 >> change this before compile - or add query in setup() to set
    
    void setup() {
      Serial.begin(115200);
      while (!Serial && millis() < 4000 );
      Serial.println("Compile Time:: " __FILE__ " " __DATE__ " " __TIME__);
      analogReadRes(12);
      analogWriteRes(12);
    
      Serial.print("This Teensy Digital Pin Count :: ");
      Serial.println(NUM_DIGITAL_PINS);
      HelpMe();
    }
    
    uint32_t cnt = 0;
    void loop() {
      cnt++;
    
      if ( xx == 0 ) {
        // array pinsSDIO[] requires PINS JUMPERED:  34>37, 35>38, 36>39
        sdioTestPWM( cnt );
      }
      else if ( xx == 1 ) {
        // This code changes Voltage seen on each pin
        // Freq changes in pin pairs: 34/35, 36/37, 38/39
        sdioTestVolts( cnt );
      }
      else if ( xx == 2 )
      {
        // Paul's code changes FREQ to each pin
        // uint32_t xx = 2; // change this before compile - or add query in setup() to set
        loopPaulHz();
      }
      else if ( xx == 3 ) {
        allPinTest( cnt );
      }
      else if ( xx == 4 ) {
        aLogPinTest( cnt );
      }
      int xxQ = tellMe( 0 );
      if (xxQ < 10 ) xx = xxQ;
    }
    
    
    elapsedMillis emiWait;
    uint32_t emWaitM;
    uint32_t pinsSDIO[9] = { 34, 35, 36, 37, 38, 39, 34, 35, 36 }; //note first three repeat duplicates
    //uint32_t pinsSDIO[9] = { 34, 35, 36, 37, 39, 38, 34, 35, 36 };
    FASTRUN void sdioTestPWM( uint32_t cnt) {
      int ii, mm, nn;
      if ( cnt % 2 ) mm = 0;
      else mm = 3;
      for ( ii = mm; ii < mm + 3; ii++ ) {
        nn = ii + 3;
        //    pinMode( pinsSDIO[ii], INPUT_DISABLE); // Not required - pin state set on analogWrite
        pinMode( pinsSDIO[nn], INPUT);
      }
    
      for ( ii = mm; ii < mm + 3; ii++ ) {
        nn = ii + 3;
        //analogWriteFrequency( pinsSDIO[ii], (nn + (cnt % 4)) * 1000000 ); // Similar results on changing or other frequencies
        analogWriteFrequency( pinsSDIO[ii], 16664000 );
        analogWrite( pinsSDIO[ii], 128 );
        delayMicroseconds( 4);
        uint32_t pCnt = 0, Cnt0 = 0, Cnt1 = 0;
        while ( 0 == digitalReadFast( pinsSDIO[nn] ) );
        while ( digitalReadFast( pinsSDIO[nn] ) );
        emiWait = 0;
        emWaitM = millis() + 500;
        while ( emiWait < 500 ) {
          //    while ( emWaitM >millis() ) {
          while ( 0 == digitalReadFast( pinsSDIO[nn] ) ) Cnt0++;
          while ( digitalReadFast( pinsSDIO[nn] ) ) Cnt1++;
          pCnt++;
        }
        Serial.print(ii);
        Serial.print(" Cnt=");
        Serial.print(pCnt * 2);
        Serial.print(" PWM out =");
        Serial.print(pinsSDIO[ii]);
        Serial.print(" Dig Read =");
        Serial.print(pinsSDIO[nn]);
        Serial.print(" Cnt0's=");
        Serial.print(Cnt0);
        Serial.print(" Cnt1's=");
        Serial.print(Cnt1);
        Serial.println();
      }
      Serial.println();
    }
    
    
    FASTRUN void sdioTestVolts( uint32_t cnt) {
      int ii, nn;
      for ( ii = 0; ii < 6; ii++ ) {
        nn = 1 + ii;
        analogWriteFrequency( pinsSDIO[ii], nn * 1000 );
        analogWrite( pinsSDIO[ii], nn * 32 );
      }
      while (1) {
      }
    }
    
    uint32_t n = 0;
    
    void loopPaulHz()
    {
    #ifdef GPIO8_GDIR
      GPIO8_GDIR |= (0x3F << 12);
      n++;
      GPIO8_DR = (GPIO8_DR & ~(0x3F << 12)) | ((n & 0x3F) << 12);
      delayMicroseconds(50);
    #endif
    }
    
    uint32_t pinLast[NUM_DIGITAL_PINS];
    void allPinTest( uint32_t cnt ) {
      uint32_t ii, SET;
      Serial.print("PULLDOWN Start Vals:\n  ");
      SET = 0;
      Serial.print("PULLDOWN :: TEST to 3.3V\n  ");
      for ( ii = 0; ii < NUM_DIGITAL_PINS; ii++) {
        pinMode( ii, INPUT_PULLDOWN );
        delayMicroseconds( 5 );
        pinLast[ii] = digitalReadFast( ii );
        if (pinLast[ii]) {
          Serial.print("\nd#=");
          Serial.print( ii );
          Serial.print( " val=" );
        }
        Serial.print( pinLast[ii] );
        Serial.print(',');
      }
      Serial.println();
      Serial.println();
      while ( 1 ) {
        uint32_t jj, dd = 0, cc = 0;
        cc = 0;
        for ( ii = 0; ii < NUM_DIGITAL_PINS; ii++) {
          jj = digitalReadFast( ii );
          if ( jj != pinLast[ii] ) {
            dd = 1;
            cc++;
            pinLast[ii] = jj;
            Serial.print("d#=");
            Serial.print( ii );
            if ( pinLast[ii] ) Serial.print( "\t" );
            Serial.print( " val=" );
            Serial.print( pinLast[ii] );
            Serial.print(',');
          }
          if ( cc > 1 ) {
            Serial.println(">>>");
          }
          if ( Serial.available() ) {
            while ( Serial.available() ) Serial.read();
            if ( 0 == SET ) {
              SET = 1;
              Serial.print("PULLUP :: TEST TO GND\n  ");
            }
            else {
              SET = 0;
              Serial.print("PULLDOWN :: TEST to 3.3V\n  ");
            }
            for ( ii = 0; ii < NUM_DIGITAL_PINS; ii++) {
              if ( 0 == SET )
                pinMode( ii, INPUT_PULLDOWN );
              else
                pinMode( ii, INPUT_PULLUP );
              delayMicroseconds( 20 );
              pinLast[ii] = digitalReadFast( ii );
              if (SET != pinLast[ii]) {
                Serial.print("d#=");
                Serial.print( ii );
                Serial.print( " val=" );
                Serial.println( pinLast[ii] );
              }
            }
          }
        }
        if ( dd ) {
          dd = 0;
          Serial.println();
          delay( 50 );
        }
      }
    }
    
    PROGMEM char showText [][48] = {
      "Enter # below for test choice\t ver0.1\n",
      "\t0: test 34,35,36 crossed to 36,37,38\n",
      "\t1: change voltage on 34-39\n",
      "\t2: change Freq on 34-39\n",
      "\t3: All Pins Test digital\n",
      "\t4: Test Analog A0-A13 \n",
      ""
    };
    
    int tellMe( int whatNow ) {
      int retVal = 0;
      if ( 0 == whatNow )
        if ( Serial.available() ) while ( Serial.available() ) Serial.read();
        else return 100;
      HelpMe();
      while ( Serial.available() ) {
        char chi = Serial.read();
        if ( chi >= '0' && chi <= '9' ) retVal = chi - '0';
      }
      return retVal;
    }
    
    void HelpMe() {
      uint32_t ii = 0;
      while ( 0 != showText[ii][0] ) {
        Serial.print( showText[ii] );
        ii++;
      }
    }
    
    
    uint32_t pinAlog[ 14 ] = {A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13}; // FAKE NUM_ANALOG_INPUTS==14 t4 p#14-#27
    void aLogPinTest( uint32_t cnt ) {
      uint32_t ii, SET;
      Serial.print("PULLDOWN Start Vals:\n  ");
      SET = 0;
      Serial.print("PULLDOWN :: TEST to 3.3V\n  ");
      for ( ii = 0; ii < NUM_DIGITAL_PINS; ii++) {
        pinMode( ii, INPUT_PULLDOWN );
        delayMicroseconds( 5 );
        pinLast[ii] = digitalReadFast( ii );
        if (pinLast[ii]) {
          Serial.print("\nd#=");
          Serial.print( ii );
          Serial.print( " val=" );
        }
        Serial.print( pinLast[ii] );
        Serial.print(',');
      }
      Serial.println();
      Serial.println();
      while ( 1 ) {
        uint32_t jj, dd = 0, cc = 0;
        cc = 0;
        for ( ii = 0; ii < NUM_DIGITAL_PINS; ii++) {
          jj = digitalReadFast( ii );
          if ( jj != pinLast[ii] ) {
            dd = 1;
            cc++;
            pinLast[ii] = jj;
            Serial.print("d#=");
            Serial.print( ii );
            if ( pinLast[ii] ) Serial.print( "\t" );
            Serial.print( " val=" );
            Serial.print( pinLast[ii] );
            Serial.print(',');
          }
          if ( cc > 1 ) {
            Serial.println(">>>");
          }
          if ( Serial.available() ) {
            while ( Serial.available() ) Serial.read();
            if ( 0 == SET ) {
              SET = 1;
              Serial.print("PULLUP :: TEST TO GND\n  ");
            }
            else {
              SET = 0;
              Serial.print("PULLDOWN :: TEST to 3.3V\n  ");
            }
            for ( ii = 0; ii < NUM_DIGITAL_PINS; ii++) {
              if ( 0 == SET )
                pinMode( ii, INPUT_PULLDOWN );
              else
                pinMode( ii, INPUT_PULLUP );
              delayMicroseconds( 20 );
              pinLast[ii] = digitalReadFast( ii );
              if (SET != pinLast[ii]) {
                Serial.print("d#=");
                Serial.print( ii );
                Serial.print( " val=" );
                Serial.println( pinLast[ii] );
              }
            }
          }
        }
        if ( dd ) {
          dd = 0;
          Serial.println();
          delay( 50 );
        }
      }
    }
    Directions for USE:
    Code:
    It gives a static reading of the pins in Pull Up or Pull Down when that 'test mode' is entered.
    
    Ideally with nothing connected all pins should show 0 on PULL DOWN and 1 on PULL UP, when things are connected, or there are issues they will print the pin number for unexpected values.
    
    The SerMon displayed notes: "PULLDOWN :: TEST to 3.3V" and "PULLUP :: TEST TO GND"
    Are for dynamic testing as noted use a WIRE either at 3.3V or GND and carefully touch the other 'testable' pins and they will show a change by number.
    Touching a Single pin as indicated should only change a single pin (otherwise it is a short to any other changing pins) and a single pin change should be as expected transitioning 0>1 or 1>0 depending on the test.
    Last edited by defragster; 04-03-2021 at 09:32 AM. Reason: opps - fixed again - it had PINLIST not included

  12. #12
    Thanks for the updated code. Here's the output as run with no changes, no SD card, and no connection/wire to any pins:

    Code:
    09:12:18.717 -> Compile Time:: /home/adrian/Arduino/sketch_apr03a/sketch_apr03a.ino Apr  3 2021 09:07:13
    09:12:18.717 -> 
    09:12:18.717 -> This Teensy Digital Pin Count :: 64
    09:12:18.717 -> 
    09:12:18.717 -> Enter # below for test choice	 ver0.1
    09:12:18.717 -> 0: test 34,35,36 crossed to 36,37,38
    09:12:18.717 -> 1: change voltage on 34-39
    09:12:18.717 -> 2: change Freq on 34-39 { 1062 MCU's only )
    09:12:18.717 -> 3: All Pins Test digital
    09:12:18.717 -> 4: Test Analog A0-A13 
    09:12:18.717 -> PULLDOWN Start Vals:
    09:12:18.717 ->   PULLDOWN :: TEST to 3.3V
    09:12:18.717 ->   0,0,0,0,0,0,
    09:12:18.717 -> d#=6 val=1,0,0,0,
    09:12:18.717 -> d#=10 val=1,0,0,0,0,0,0,0,
    09:12:18.717 -> d#=18 val=1,
    09:12:18.717 -> d#=19 val=1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
    09:12:18.717 -> 
    09:12:18.717 -> 
    09:12:18.717 -> 
    09:12:18.717 -> PULLUP :: TEST TO GND
    09:12:18.717 ->   d#=13 val=0
    09:12:18.717 -> d#=15 val=0
    09:12:18.717 -> PULLDOWN :: TEST to 3.3V
    09:12:18.717 ->   d#=6 val=1
    09:12:18.717 -> d#=10 val=1
    09:12:18.717 -> d#=18 val=1
    09:12:18.717 -> d#=19 val=1
    09:12:18.717 -> PULLUP :: TEST TO GND
    09:12:18.717 ->   d#=13 val=0
    09:12:18.717 -> d#=15 val=0
    09:12:18.717 -> PULLDOWN :: TEST to 3.3V
    09:12:18.717 ->   d#=6 val=1
    09:12:18.717 -> d#=10 val=1
    09:12:18.717 -> d#=18 val=1
    09:12:18.717 -> d#=19 val=1

  13. #13
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    15,268
    That is a static reading of the pins in Pull Up or Pull Down when that 'test mode' is entered.

    Ideally with nothing connected all pins should show 0 on PULL DOWN and 1 on PULL UP, when things are connected, or there are issues they will print the pin number for unexpected values.

    In Pull Up it shows: pins 13 and 15 are grounded to 0 when they should be 1.

    In Pull Down it shows: 6,10,18,19 are externally pulled high to 1 when they should be 0.
    > 18,19 are likely i2c pullups?
    > not sure about connections to 6,10

    The SerMon displayed notes: "PULLDOWN :: TEST to 3.3V" and "PULLUP :: TEST TO GND"
    Are for dynamic testing as noted use a WIRE either at 3.3V or GND and carefully touch the other 'testable' pins and they will show a change by number.
    Touching a Single pin as indicated should only change a single pin (otherwise it is a short to any other changing pins) and a single pin change should be as expected transitioning 0>1 or 1>0 depending on the test.

  14. #14
    As my Teensy is soldered to a PCB and everything functions OK except for the SD card, I have ordered a micro SD card sniffer to make pull-up and pull-down testing less risky. Unsoldering the Teensy from the PCB will be very tricky if I manage to damage it.

    Click image for larger version. 

Name:	Screenshot from 2021-04-03 09-46-19.png 
Views:	48 
Size:	121.3 KB 
ID:	24291

    Depending on how brave I feel later today I may give further testing a go, but otherwise it will be a few days before the sniffer arrives, so I'll post back then.

    Many thanks for all the help so far @defragster and @CorBee

  15. #15
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    15,268
    The sniffer looks like fun - I ordered one but never used it yet.

    Those solder points are tiny targets - but it can work - as long as the 3.3V probe avoids the GND and the GND probe avoids the 3.3V.

    The #ifdef'd code Paul wrote for the T_4.0 cycles power on and off across the SDIO pins in a way that results in a unique freq for each pin to test with a DMM and see the freq. If the port were properly changed for the pins on the T_3.5 and 3.6 boards it should work there as well.

  16. #16
    Senior Member+ KurtE's Avatar
    Join Date
    Jan 2014
    Posts
    9,734
    I have used adapters like that (https://www.sparkfun.com/products/9419) and in fact have made my own breakout boards.

    When I get hangs/crashes like this I often add in Serial.flush() statements to force output. As often times the crash may be several prints later, which have not been output over USB and you end up barking at the wrong tree
    Also I add more prints... Also maybe blink led if it gets to loop

    Things like:

    Code:
    #include <SPI.h>
    #include <SD.h>
    
    // Teensy 3.5 & 3.6 SD card
    #define SDCARD_CS_PIN    BUILTIN_SDCARD
    #define SDCARD_MOSI_PIN  11
    #define SDCARD_SCK_PIN   13
    
    int16_t check_sd_cards(void)
    {
      int16_t ret = -1;
      SPI.setMOSI(SDCARD_MOSI_PIN);
      SPI.setSCK(SDCARD_SCK_PIN);
      Serial.println(F("Checking on-board SD (T_3.6)")); Serial.flush();
      if (SD.begin(SDCARD_CS_PIN))
      {
        Serial.print(F("Using SD-card on Teensy (T_3.6): ")); 
        Serial.println(SDCARD_CS_PIN, DEC);
        Serial.flus();
        ret = SDCARD_CS_PIN;
      }
      Serial.println("After SD.Being"); Serial.flush();
      if (ret < 0)
      {
        Serial.println(F("Cannot find SD card!"));
        Serial.flush();
      }
      Serial.println("End of check_sd_card"); Serial.flush();
      return (ret);
    }
    
    void setup() {
      while(!Serial);
       pinMode(13, OUTPUT);
      delay(500); // needed for serial console
      int16_t sd = check_sd_cards();
      Serial.println(sd, DEC);
    }
    
    void loop() {
      digitalToggleFast(13);
      delay(250);
    }
    Again typed in on the fly... But hopefully it makes sense. As I have often looked at the wrong place

  17. #17
    Quote Originally Posted by KurtE View Post
    I have used adapters like that (https://www.sparkfun.com/products/9419) and in fact have made my own breakout boards.

    When I get hangs/crashes like this I often add in Serial.flush() statements to force output. As often times the crash may be several prints later, which have not been output over USB and you end up barking at the wrong tree
    Also I add more prints... Also maybe blink led if it gets to loop

    Things like:

    Code:
    #include <SPI.h>
    #include <SD.h>
    
    // Teensy 3.5 & 3.6 SD card
    #define SDCARD_CS_PIN    BUILTIN_SDCARD
    #define SDCARD_MOSI_PIN  11
    #define SDCARD_SCK_PIN   13
    
    int16_t check_sd_cards(void)
    {
      int16_t ret = -1;
      SPI.setMOSI(SDCARD_MOSI_PIN);
      SPI.setSCK(SDCARD_SCK_PIN);
      Serial.println(F("Checking on-board SD (T_3.6)")); Serial.flush();
      if (SD.begin(SDCARD_CS_PIN))
      {
        Serial.print(F("Using SD-card on Teensy (T_3.6): ")); 
        Serial.println(SDCARD_CS_PIN, DEC);
        Serial.flus();
        ret = SDCARD_CS_PIN;
      }
      Serial.println("After SD.Being"); Serial.flush();
      if (ret < 0)
      {
        Serial.println(F("Cannot find SD card!"));
        Serial.flush();
      }
      Serial.println("End of check_sd_card"); Serial.flush();
      return (ret);
    }
    
    void setup() {
      while(!Serial);
       pinMode(13, OUTPUT);
      delay(500); // needed for serial console
      int16_t sd = check_sd_cards();
      Serial.println(sd, DEC);
    }
    
    void loop() {
      digitalToggleFast(13);
      delay(250);
    }
    Again typed in on the fly... But hopefully it makes sense. As I have often looked at the wrong place
    Many thanks for the Serial.flush() tip - I have noticed that sometimes I don't get the full serial output that I am expecting.

  18. #18
    I have now tested the SD card pins using the pullup/pulldown sketch. For reference, I have determined the pin numbering for the Teensy 3.6 SD card to be as shown below.

    Click image for larger version. 

Name:	teensy36_sdcard_pinout.png 
Views:	22 
Size:	182.9 KB 
ID:	24356

    The results of the test show that I can not get pin 59 to change state during the PULLUP :: TEST TO GND test:
    Code:
    PULLUP :: TEST TO GND
    d#=58 val=0,
    d#=58	 val=1,
    d#=60 val=0,
    d#=60	 val=1,
    d#=61 val=0,
    d#=61	 val=1,
    d#=62 val=0,
    d#=62	 val=1,
    d#=63 val=0,
    d#=63	 val=1,
    PULLDOWN :: TEST to 3.3V
    d#=58	 val=1,
    d#=58 val=0,
    d#=59	 val=1,
    d#=59 val=0,
    d#=60	 val=1,
    d#=60 val=0,
    d#=61	 val=1,
    d#=61 val=0,
    d#=62	 val=1,
    d#=62 val=0,
    d#=63	 val=1,
    d#=63 val=0
    Now I have to work out why. Pin 59 behaves correctly during the PULLDOWN :: TEST to 3.3V test.

    It's also worth noting that this Teensy was working OK last time I used it (October/November last year). I have also tried 4GB, 8GB, 16GB, 32GB and 64GB SD Cards, formatted with the sdcard.org formatter, and none of these work.

    The CardInfo SD card test that tests the SD.h library shows that
    Code:
    !card.init(SPI_HALF_SPEED, chipSelect)
    initilises OK, and the card type can then be determined (SDHC), but the Teensy freezes at
    Code:
    !volume.init(card)
    Any further help with this issue will be appreciated.

    EDIT During the PULLUP test, pin 59 reads 0.7V (other pins are 3.3V), which probably explains why it doesn't change state when connected to GND.
    Last edited by Hystrix; 04-07-2021 at 02:59 PM. Reason: add more information

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •