Teensy 4.1 SD card reader doesn't work with any library

sid8580

Well-known member
Hi,

I've tried various examples for the included SD library (within the Teensyduino application folders, SD.h), as well as the latest of Bill Greiman's SDfat-beta (2.0.0 beta 9) that has the 4.1 support added. In every case, the SD card won't initialize.

I've also tried the test sketch mentioned in this thread:
https://forum.pjrc.com/threads/61289-Question-on-the-correct-usage-of-the-SD-Card-on-Teensy-4-1

- Compilation logs have been double checked to ensure I've including what I think I'm including.
- All other SPI devices have been removed from the breadboard.
- The SD card works fine in a project built for T3.6, but just in case, I formatted it with SD Card Formatter (official from SD association)
- I've tried playing with the configuration as well as wiping it all out and just using the unmodified libraries/examples.

Is any of this supposed to work, without modification? Is there anything someone can point me to that's failsafe just so I know my board doesn't have an issue?

Thanks!
 
What is the SD card size? That same card worked on the Attached T_3.6 SD socket? That same sketch compiled for T_4.1 should work - if nothing else involved without T_4.1 support.

Given the BUILTIN SDCARD value for CSPIN it just works last tested here with a T_4.1. The Attached SD socket uses unique pins not associated with any other general BUS, SPI or otherwise - but those pins are available for general use that must not be done when used for SD - and they do not have the same pins numbers - if the sheet I just saw is up to date they are #'s 42-47 that were presented as unused bottom pads on the T_3.6.

The Greiman SDfat-beta also tested to work - it expects different Formatting IIRC based on the example used - ExFAT perhaps instead of FAT32 IIRC is what the SD.h uses on the Teensy included library.

Is anything else drawing power from the T_4.1? The SD card takes a decent amount of power - if it doesn't have enough clean power it may fail to function
 
What version of Arduino IDE and Teensyduino are you using? what is the error message that you are getting from the SD lib test? If you run the following sketch on your T4.1 with a uSD in the onboard uSD carrier, what does the serial monitor report?
Code:
 // include the SD library:
#include <SD.h>
#include <SPI.h>

// set up variables using the SD utility library functions:
Sd2Card card;
SdVolume volume;
SdFile root;

// change this to match your SD shield or module;
// Arduino Ethernet shield: pin 4
// Adafruit SD shields and modules: pin 10
// Sparkfun SD shield: pin 8
// Teensy audio board: pin 10
// Teensy 3.5 & 3.6 & 4.1 on-board: BUILTIN_SDCARD
// Wiz820+SD board: pin 4
// Teensy 2.0: pin 0
// Teensy++ 2.0: pin 20
const int chipSelect = BUILTIN_SDCARD;

void setup()
{
  //UNCOMMENT THESE TWO LINES FOR TEENSY AUDIO BOARD:
  //SPI.setMOSI(7);  // Audio shield has MOSI on pin 7
  //SPI.setSCK(14);  // Audio shield has SCK on pin 14
  
 // Open serial communications and wait for port to open:
  Serial.begin(9600);
   while (!Serial) {
    ; // wait for serial port to connect.
  }


  Serial.print("\nInitializing SD card...");


  // we'll use the initialization code from the utility libraries
  // since we're just testing if the card is working!
  if (!card.init(SPI_HALF_SPEED, chipSelect)) {
    Serial.println("initialization failed. Things to check:");
    Serial.println("* is a card inserted?");
    Serial.println("* is your wiring correct?");
    Serial.println("* did you change the chipSelect pin to match your shield or module?");
    return;
  } else {
   Serial.println("Wiring is correct and a card is present.");
  }

  // print the type of card
  Serial.print("\nCard type: ");
  switch(card.type()) {
    case SD_CARD_TYPE_SD1:
      Serial.println("SD1");
      break;
    case SD_CARD_TYPE_SD2:
      Serial.println("SD2");
      break;
    case SD_CARD_TYPE_SDHC:
      Serial.println("SDHC");
      break;
    default:
      Serial.println("Unknown");
  }

  // Now we will try to open the 'volume'/'partition' - it should be FAT16 or FAT32
  if (!volume.init(card)) {
    Serial.println("Could not find FAT16/FAT32 partition.\nMake sure you've formatted the card");
    return;
  }


  // print the type and size of the first FAT-type volume
  uint32_t volumesize;
  Serial.print("\nVolume type is FAT");
  Serial.println(volume.fatType(), DEC);
  Serial.println();
  
  volumesize = volume.blocksPerCluster();    // clusters are collections of blocks
  volumesize *= volume.clusterCount();       // we'll have a lot of clusters
  if (volumesize < 8388608ul) {
    Serial.print("Volume size (bytes): ");
    Serial.println(volumesize * 512);        // SD card blocks are always 512 bytes
  }
  Serial.print("Volume size (Kbytes): ");
  volumesize /= 2;
  Serial.println(volumesize);
  Serial.print("Volume size (Mbytes): ");
  volumesize /= 1024;
  Serial.println(volumesize);

  
  Serial.println("\nFiles found on the card (name, date and size in bytes): ");
  root.openRoot(volume);
  
  // list all files in the card with date and size
  root.ls(LS_R | LS_DATE | LS_SIZE);
}


void loop(void) {
  
}

With 8GB sanDisk my T4.1 reports
Code:
Initializing SD card...Wiring is correct and a card is present.

Card type: SDHC

Volume type is FAT32

Volume size (Kbytes): 7753728
Volume size (Mbytes): 7572

Files found on the card (name, date and size in bytes): 
TST.C         2016-04-30 13:40:28 122
ODD.WAV       2017-06-22 13:51:04 276524
RNG.DAT       2000-01-01 01:00:00 1024000
TOM.TMP       2000-01-01 01:00:00 18
SDTEST1.WAV   2017-04-22 12:10:06 16787550
SDTEST2.WAV   2017-04-22 12:10:06 16425698
SDTEST3.WAV   2017-04-22 12:10:06 13617358
SDTEST4.WAV   2017-04-22 12:10:08 17173152
TOPGUN.WAV    2017-04-22 12:10:08 4233644
PARROT.BMP    2017-09-25 23:46:26 61496
 
Last edited:
Is any of this supposed to work, without modification?

One small modification is need to all of the SD library examples. You need to change the chip select to BUILTIN_SDCARD.

For example, here's some of the code from File > Examples > SD > listfiles.

// change this to match your SD shield or module;
// Arduino Ethernet shield: pin 4
// Adafruit SD shields and modules: pin 10
// Sparkfun SD shield: pin 8
// Teensy audio board: pin 10
// Teensy 3.5 & 3.6 & 4.1 on-board: BUILTIN_SDCARD

// Wiz820+SD board: pin 4
// Teensy 2.0: pin 0
// Teensy++ 2.0: pin 20
const int chipSelect = 4;

To make this work, you would change the last line to this:

Code:
const int chipSelect = BUILTIN_SDCARD;
 
What version of Arduino IDE and Teensyduino are you using? what is the error message that you are getting from the SD lib test? If you run the following sketch on your T4.1 with a uSD in the onboard uSD carrier, what does the serial monitor report?

I just did a complete refresh of the Arduino IDE so it's at 1.8.13 and Teensyduino, at 1.53.

When I run your sketch I get this:

Code:
Initializing SD card...initialization failed. Things to check:
* is a card inserted?
* is your wiring correct?
* did you change the chipSelect pin to match your shield or module?

The compile info is:
Code:
/Applications/Teensyduino.app/Contents/Java/arduino-builder -dump-prefs -logger=machine -hardware /Applications/Teensyduino.app/Contents/Java/hardware -hardware /Users/mos6502/Library/Arduino15/packages -hardware /Users/mos6502/Documents/Arduino/hardware -tools /Applications/Teensyduino.app/Contents/Java/tools-builder -tools /Applications/Teensyduino.app/Contents/Java/hardware/tools/avr -tools /Users/mos6502/Library/Arduino15/packages -built-in-libraries /Applications/Teensyduino.app/Contents/Java/libraries -libraries /Users/mos6502/Documents/Arduino/libraries -fqbn=teensy:avr:teensy41:usb=serial,speed=600,opt=o2std,keys=en-us -ide-version=10813 -build-path /var/folders/rw/534kw6kd6hs6chfgmjmjv79r0000gn/T/arduino_build_330008 -warnings=none -build-cache /var/folders/rw/534kw6kd6hs6chfgmjmjv79r0000gn/T/arduino_cache_6432 -verbose /Users/mos6502/Documents/Arduino/overthink.exe/LibraryTest/SD_Teensyduino/SD_Teensyduino.ino
/Applications/Teensyduino.app/Contents/Java/arduino-builder -compile -logger=machine -hardware /Applications/Teensyduino.app/Contents/Java/hardware -hardware /Users/mos6502/Library/Arduino15/packages -hardware /Users/mos6502/Documents/Arduino/hardware -tools /Applications/Teensyduino.app/Contents/Java/tools-builder -tools /Applications/Teensyduino.app/Contents/Java/hardware/tools/avr -tools /Users/mos6502/Library/Arduino15/packages -built-in-libraries /Applications/Teensyduino.app/Contents/Java/libraries -libraries /Users/mos6502/Documents/Arduino/libraries -fqbn=teensy:avr:teensy41:usb=serial,speed=600,opt=o2std,keys=en-us -ide-version=10813 -build-path /var/folders/rw/534kw6kd6hs6chfgmjmjv79r0000gn/T/arduino_build_330008 -warnings=none -build-cache /var/folders/rw/534kw6kd6hs6chfgmjmjv79r0000gn/T/arduino_cache_6432 -verbose /Users/mos6502/Documents/Arduino/overthink.exe/LibraryTest/SD_Teensyduino/SD_Teensyduino.ino
Using board 'teensy41' from platform in folder: /Applications/Teensyduino.app/Contents/Java/hardware/teensy/avr
Using core 'teensy4' from platform in folder: /Applications/Teensyduino.app/Contents/Java/hardware/teensy/avr
Detecting libraries used...
/Applications/Teensyduino.app/Contents/Java/hardware/teensy/../tools/arm/bin/arm-none-eabi-g++ -E -CC -x c++ -w -g -Wall -ffunction-sections -fdata-sections -nostdlib -std=gnu++14 -fno-exceptions -fpermissive -fno-rtti -fno-threadsafe-statics -felide-constructors -Wno-error=narrowing -mthumb -mcpu=cortex-m7 -mfloat-abi=hard -mfpu=fpv5-d16 -D__IMXRT1062__ -DTEENSYDUINO=153 -DARDUINO=10813 -DARDUINO_TEENSY41 -DF_CPU=600000000 -DUSB_SERIAL -DLAYOUT_US_ENGLISH -I/Applications/Teensyduino.app/Contents/Java/hardware/teensy/avr/cores/teensy4 /var/folders/rw/534kw6kd6hs6chfgmjmjv79r0000gn/T/arduino_build_330008/sketch/SD_Teensyduino.ino.cpp -o /dev/null -DARDUINO_LIB_DISCOVERY_PHASE
Alternatives for SD.h: [SD@1.2.4 SD@1.2.2]
ResolveLibrary(SD.h)
  -> candidates: [SD@1.2.4 SD@1.2.2]
/Applications/Teensyduino.app/Contents/Java/hardware/teensy/../tools/arm/bin/arm-none-eabi-g++ -E -CC -x c++ -w -g -Wall -ffunction-sections -fdata-sections -nostdlib -std=gnu++14 -fno-exceptions -fpermissive -fno-rtti -fno-threadsafe-statics -felide-constructors -Wno-error=narrowing -mthumb -mcpu=cortex-m7 -mfloat-abi=hard -mfpu=fpv5-d16 -D__IMXRT1062__ -DTEENSYDUINO=153 -DARDUINO=10813 -DARDUINO_TEENSY41 -DF_CPU=600000000 -DUSB_SERIAL -DLAYOUT_US_ENGLISH -I/Applications/Teensyduino.app/Contents/Java/hardware/teensy/avr/cores/teensy4 -I/Applications/Teensyduino.app/Contents/Java/hardware/teensy/avr/libraries/SD /var/folders/rw/534kw6kd6hs6chfgmjmjv79r0000gn/T/arduino_build_330008/sketch/SD_Teensyduino.ino.cpp -o /dev/null -DARDUINO_LIB_DISCOVERY_PHASE
Alternatives for SPI.h: [SPI@1.0]
ResolveLibrary(SPI.h)
  -> candidates: [SPI@1.0]
/Applications/Teensyduino.app/Contents/Java/hardware/teensy/../tools/arm/bin/arm-none-eabi-g++ -E -CC -x c++ -w -g -Wall -ffunction-sections -fdata-sections -nostdlib -std=gnu++14 -fno-exceptions -fpermissive -fno-rtti -fno-threadsafe-statics -felide-constructors -Wno-error=narrowing -mthumb -mcpu=cortex-m7 -mfloat-abi=hard -mfpu=fpv5-d16 -D__IMXRT1062__ -DTEENSYDUINO=153 -DARDUINO=10813 -DARDUINO_TEENSY41 -DF_CPU=600000000 -DUSB_SERIAL -DLAYOUT_US_ENGLISH -I/Applications/Teensyduino.app/Contents/Java/hardware/teensy/avr/cores/teensy4 -I/Applications/Teensyduino.app/Contents/Java/hardware/teensy/avr/libraries/SD -I/Applications/Teensyduino.app/Contents/Java/hardware/teensy/avr/libraries/SPI /var/folders/rw/534kw6kd6hs6chfgmjmjv79r0000gn/T/arduino_build_330008/sketch/SD_Teensyduino.ino.cpp -o /dev/null -DARDUINO_LIB_DISCOVERY_PHASE
Using cached library dependencies for file: /Applications/Teensyduino.app/Contents/Java/hardware/teensy/avr/libraries/SD/File.cpp
Using cached library dependencies for file: /Applications/Teensyduino.app/Contents/Java/hardware/teensy/avr/libraries/SD/SD.cpp
Using cached library dependencies for file: /Applications/Teensyduino.app/Contents/Java/hardware/teensy/avr/libraries/SD/cache_t3.cpp
Using cached library dependencies for file: /Applications/Teensyduino.app/Contents/Java/hardware/teensy/avr/libraries/SD/card_t3.cpp
Using cached library dependencies for file: /Applications/Teensyduino.app/Contents/Java/hardware/teensy/avr/libraries/SD/dir_t3.cpp
Using cached library dependencies for file: /Applications/Teensyduino.app/Contents/Java/hardware/teensy/avr/libraries/SD/fat_t3.cpp
Using cached library dependencies for file: /Applications/Teensyduino.app/Contents/Java/hardware/teensy/avr/libraries/SD/file_t3.cpp
Using cached library dependencies for file: /Applications/Teensyduino.app/Contents/Java/hardware/teensy/avr/libraries/SD/init_t3.cpp
Using cached library dependencies for file: /Applications/Teensyduino.app/Contents/Java/hardware/teensy/avr/libraries/SD/utility/NXP_SDHC.cpp
Using cached library dependencies for file: /Applications/Teensyduino.app/Contents/Java/hardware/teensy/avr/libraries/SD/utility/Sd2Card.cpp
Using cached library dependencies for file: /Applications/Teensyduino.app/Contents/Java/hardware/teensy/avr/libraries/SD/utility/SdFile.cpp
Using cached library dependencies for file: /Applications/Teensyduino.app/Contents/Java/hardware/teensy/avr/libraries/SD/utility/SdVolume.cpp
Using cached library dependencies for file: /Applications/Teensyduino.app/Contents/Java/hardware/teensy/avr/libraries/SPI/SPI.cpp
Generating function prototypes...
/Applications/Teensyduino.app/Contents/Java/hardware/teensy/../tools/arm/bin/arm-none-eabi-g++ -E -CC -x c++ -w -g -Wall -ffunction-sections -fdata-sections -nostdlib -std=gnu++14 -fno-exceptions -fpermissive -fno-rtti -fno-threadsafe-statics -felide-constructors -Wno-error=narrowing -mthumb -mcpu=cortex-m7 -mfloat-abi=hard -mfpu=fpv5-d16 -D__IMXRT1062__ -DTEENSYDUINO=153 -DARDUINO=10813 -DARDUINO_TEENSY41 -DF_CPU=600000000 -DUSB_SERIAL -DLAYOUT_US_ENGLISH -I/Applications/Teensyduino.app/Contents/Java/hardware/teensy/avr/cores/teensy4 -I/Applications/Teensyduino.app/Contents/Java/hardware/teensy/avr/libraries/SD -I/Applications/Teensyduino.app/Contents/Java/hardware/teensy/avr/libraries/SPI /var/folders/rw/534kw6kd6hs6chfgmjmjv79r0000gn/T/arduino_build_330008/sketch/SD_Teensyduino.ino.cpp -o /var/folders/rw/534kw6kd6hs6chfgmjmjv79r0000gn/T/arduino_build_330008/preproc/ctags_target_for_gcc_minus_e.cpp -DARDUINO_LIB_DISCOVERY_PHASE
/Applications/Teensyduino.app/Contents/Java/tools-builder/ctags/5.8-arduino11/ctags -u --language-force=c++ -f - --c++-kinds=svpf --fields=KSTtzns --line-directives /var/folders/rw/534kw6kd6hs6chfgmjmjv79r0000gn/T/arduino_build_330008/preproc/ctags_target_for_gcc_minus_e.cpp
Compiling sketch...
/Applications/Teensyduino.app/Contents/Java/hardware/teensy/../tools/precompile_helper /Applications/Teensyduino.app/Contents/Java/hardware/teensy/avr/cores/teensy4 /var/folders/rw/534kw6kd6hs6chfgmjmjv79r0000gn/T/arduino_build_330008 /Applications/Teensyduino.app/Contents/Java/hardware/teensy/../tools/arm/bin/arm-none-eabi-g++ -x c++-header -O2 -g -Wall -ffunction-sections -fdata-sections -nostdlib -MMD -std=gnu++14 -fno-exceptions -fpermissive -fno-rtti -fno-threadsafe-statics -felide-constructors -Wno-error=narrowing -mthumb -mcpu=cortex-m7 -mfloat-abi=hard -mfpu=fpv5-d16 -D__IMXRT1062__ -DTEENSYDUINO=153 -DARDUINO=10813 -DARDUINO_TEENSY41 -DF_CPU=600000000 -DUSB_SERIAL -DLAYOUT_US_ENGLISH -I/Applications/Teensyduino.app/Contents/Java/hardware/teensy/avr/cores/teensy4 /var/folders/rw/534kw6kd6hs6chfgmjmjv79r0000gn/T/arduino_build_330008/pch/Arduino.h -o /var/folders/rw/534kw6kd6hs6chfgmjmjv79r0000gn/T/arduino_build_330008/pch/Arduino.h.gch
Using previously compiled file: /var/folders/rw/534kw6kd6hs6chfgmjmjv79r0000gn/T/arduino_build_330008/pch/Arduino.h.gch
/Applications/Teensyduino.app/Contents/Java/hardware/teensy/../tools/arm/bin/arm-none-eabi-g++ -c -O2 -g -Wall -ffunction-sections -fdata-sections -nostdlib -MMD -std=gnu++14 -fno-exceptions -fpermissive -fno-rtti -fno-threadsafe-statics -felide-constructors -Wno-error=narrowing -mthumb -mcpu=cortex-m7 -mfloat-abi=hard -mfpu=fpv5-d16 -D__IMXRT1062__ -DTEENSYDUINO=153 -DARDUINO=10813 -DARDUINO_TEENSY41 -DF_CPU=600000000 -DUSB_SERIAL -DLAYOUT_US_ENGLISH -I/var/folders/rw/534kw6kd6hs6chfgmjmjv79r0000gn/T/arduino_build_330008/pch -I/Applications/Teensyduino.app/Contents/Java/hardware/teensy/avr/cores/teensy4 -I/Applications/Teensyduino.app/Contents/Java/hardware/teensy/avr/libraries/SD -I/Applications/Teensyduino.app/Contents/Java/hardware/teensy/avr/libraries/SPI /var/folders/rw/534kw6kd6hs6chfgmjmjv79r0000gn/T/arduino_build_330008/sketch/SD_Teensyduino.ino.cpp -o /var/folders/rw/534kw6kd6hs6chfgmjmjv79r0000gn/T/arduino_build_330008/sketch/SD_Teensyduino.ino.cpp.o
Compiling libraries...
Compiling library "SD"
Using previously compiled file: /var/folders/rw/534kw6kd6hs6chfgmjmjv79r0000gn/T/arduino_build_330008/libraries/SD/dir_t3.cpp.o
Using previously compiled file: /var/folders/rw/534kw6kd6hs6chfgmjmjv79r0000gn/T/arduino_build_330008/libraries/SD/cache_t3.cpp.o
Using previously compiled file: /var/folders/rw/534kw6kd6hs6chfgmjmjv79r0000gn/T/arduino_build_330008/libraries/SD/fat_t3.cpp.o
Using previously compiled file: /var/folders/rw/534kw6kd6hs6chfgmjmjv79r0000gn/T/arduino_build_330008/libraries/SD/SD.cpp.o
Using previously compiled file: /var/folders/rw/534kw6kd6hs6chfgmjmjv79r0000gn/T/arduino_build_330008/libraries/SD/File.cpp.o
Using previously compiled file: /var/folders/rw/534kw6kd6hs6chfgmjmjv79r0000gn/T/arduino_build_330008/libraries/SD/init_t3.cpp.o
Using previously compiled file: /var/folders/rw/534kw6kd6hs6chfgmjmjv79r0000gn/T/arduino_build_330008/libraries/SD/file_t3.cpp.o
Using previously compiled file: /var/folders/rw/534kw6kd6hs6chfgmjmjv79r0000gn/T/arduino_build_330008/libraries/SD/card_t3.cpp.o
Using previously compiled file: /var/folders/rw/534kw6kd6hs6chfgmjmjv79r0000gn/T/arduino_build_330008/libraries/SD/utility/NXP_SDHC.cpp.o
Using previously compiled file: /var/folders/rw/534kw6kd6hs6chfgmjmjv79r0000gn/T/arduino_build_330008/libraries/SD/utility/Sd2Card.cpp.o
Using previously compiled file: /var/folders/rw/534kw6kd6hs6chfgmjmjv79r0000gn/T/arduino_build_330008/libraries/SD/utility/SdFile.cpp.o
Using previously compiled file: /var/folders/rw/534kw6kd6hs6chfgmjmjv79r0000gn/T/arduino_build_330008/libraries/SD/utility/SdVolume.cpp.o
Compiling library "SPI"
Using previously compiled file: /var/folders/rw/534kw6kd6hs6chfgmjmjv79r0000gn/T/arduino_build_330008/libraries/SPI/SPI.cpp.o
Compiling core...
Using precompiled core: /var/folders/rw/534kw6kd6hs6chfgmjmjv79r0000gn/T/arduino_cache_6432/core/core_5a344d82694cbc94f2b0e86b18501051.a
Linking everything together...
/Applications/Teensyduino.app/Contents/Java/hardware/teensy/../tools/arm/bin/arm-none-eabi-gcc -O2 -Wl,--gc-sections,--relax -T/Applications/Teensyduino.app/Contents/Java/hardware/teensy/avr/cores/teensy4/imxrt1062_t41.ld -mthumb -mcpu=cortex-m7 -mfloat-abi=hard -mfpu=fpv5-d16 -o /var/folders/rw/534kw6kd6hs6chfgmjmjv79r0000gn/T/arduino_build_330008/SD_Teensyduino.ino.elf /var/folders/rw/534kw6kd6hs6chfgmjmjv79r0000gn/T/arduino_build_330008/sketch/SD_Teensyduino.ino.cpp.o /var/folders/rw/534kw6kd6hs6chfgmjmjv79r0000gn/T/arduino_build_330008/libraries/SD/File.cpp.o /var/folders/rw/534kw6kd6hs6chfgmjmjv79r0000gn/T/arduino_build_330008/libraries/SD/SD.cpp.o /var/folders/rw/534kw6kd6hs6chfgmjmjv79r0000gn/T/arduino_build_330008/libraries/SD/cache_t3.cpp.o /var/folders/rw/534kw6kd6hs6chfgmjmjv79r0000gn/T/arduino_build_330008/libraries/SD/card_t3.cpp.o /var/folders/rw/534kw6kd6hs6chfgmjmjv79r0000gn/T/arduino_build_330008/libraries/SD/dir_t3.cpp.o /var/folders/rw/534kw6kd6hs6chfgmjmjv79r0000gn/T/arduino_build_330008/libraries/SD/fat_t3.cpp.o /var/folders/rw/534kw6kd6hs6chfgmjmjv79r0000gn/T/arduino_build_330008/libraries/SD/file_t3.cpp.o /var/folders/rw/534kw6kd6hs6chfgmjmjv79r0000gn/T/arduino_build_330008/libraries/SD/init_t3.cpp.o /var/folders/rw/534kw6kd6hs6chfgmjmjv79r0000gn/T/arduino_build_330008/libraries/SD/utility/NXP_SDHC.cpp.o /var/folders/rw/534kw6kd6hs6chfgmjmjv79r0000gn/T/arduino_build_330008/libraries/SD/utility/Sd2Card.cpp.o /var/folders/rw/534kw6kd6hs6chfgmjmjv79r0000gn/T/arduino_build_330008/libraries/SD/utility/SdFile.cpp.o /var/folders/rw/534kw6kd6hs6chfgmjmjv79r0000gn/T/arduino_build_330008/libraries/SD/utility/SdVolume.cpp.o /var/folders/rw/534kw6kd6hs6chfgmjmjv79r0000gn/T/arduino_build_330008/libraries/SPI/SPI.cpp.o /var/folders/rw/534kw6kd6hs6chfgmjmjv79r0000gn/T/arduino_build_330008/../arduino_cache_6432/core/core_5a344d82694cbc94f2b0e86b18501051.a -L/var/folders/rw/534kw6kd6hs6chfgmjmjv79r0000gn/T/arduino_build_330008 -larm_cortexM7lfsp_math -lm -lstdc++
/Applications/Teensyduino.app/Contents/Java/hardware/teensy/../tools/arm/bin/arm-none-eabi-objcopy -O ihex -j .eeprom --set-section-flags=.eeprom=alloc,load --no-change-warnings --change-section-lma .eeprom=0 /var/folders/rw/534kw6kd6hs6chfgmjmjv79r0000gn/T/arduino_build_330008/SD_Teensyduino.ino.elf /var/folders/rw/534kw6kd6hs6chfgmjmjv79r0000gn/T/arduino_build_330008/SD_Teensyduino.ino.eep
/Applications/Teensyduino.app/Contents/Java/hardware/teensy/../tools/arm/bin/arm-none-eabi-objcopy -O ihex -R .eeprom /var/folders/rw/534kw6kd6hs6chfgmjmjv79r0000gn/T/arduino_build_330008/SD_Teensyduino.ino.elf /var/folders/rw/534kw6kd6hs6chfgmjmjv79r0000gn/T/arduino_build_330008/SD_Teensyduino.ino.hex
/Applications/Teensyduino.app/Contents/Java/hardware/teensy/../tools/stdout_redirect /var/folders/rw/534kw6kd6hs6chfgmjmjv79r0000gn/T/arduino_build_330008/SD_Teensyduino.ino.lst /Applications/Teensyduino.app/Contents/Java/hardware/teensy/../tools/arm/bin/arm-none-eabi-objdump -d -S -C /var/folders/rw/534kw6kd6hs6chfgmjmjv79r0000gn/T/arduino_build_330008/SD_Teensyduino.ino.elf
/Applications/Teensyduino.app/Contents/Java/hardware/teensy/../tools/stdout_redirect /var/folders/rw/534kw6kd6hs6chfgmjmjv79r0000gn/T/arduino_build_330008/SD_Teensyduino.ino.sym /Applications/Teensyduino.app/Contents/Java/hardware/teensy/../tools/arm/bin/arm-none-eabi-objdump -t -C /var/folders/rw/534kw6kd6hs6chfgmjmjv79r0000gn/T/arduino_build_330008/SD_Teensyduino.ino.elf
/Applications/Teensyduino.app/Contents/Java/hardware/teensy/../tools/teensy_post_compile -file=SD_Teensyduino.ino -path=/var/folders/rw/534kw6kd6hs6chfgmjmjv79r0000gn/T/arduino_build_330008 -tools=/Applications/Teensyduino.app/Contents/Java/hardware/teensy/../tools/ -board=TEENSY41
Multiple libraries were found for "SD.h"
 Used: /Applications/Teensyduino.app/Contents/Java/hardware/teensy/avr/libraries/SD
 Not used: /Applications/Teensyduino.app/Contents/Java/libraries/SD
Using library SD at version 1.2.2 in folder: /Applications/Teensyduino.app/Contents/Java/hardware/teensy/avr/libraries/SD 
Using library SPI at version 1.0 in folder: /Applications/Teensyduino.app/Contents/Java/hardware/teensy/avr/libraries/SPI 
/Applications/Teensyduino.app/Contents/Java/hardware/teensy/../tools/arm/bin/arm-none-eabi-size -A /var/folders/rw/534kw6kd6hs6chfgmjmjv79r0000gn/T/arduino_build_330008/SD_Teensyduino.ino.elf
Sketch uses 23856 bytes (0%) of program storage space. Maximum is 8126464 bytes.
Global variables use 45756 bytes (8%) of dynamic memory, leaving 478532 bytes for local variables. Maximum is 524288 bytes.
Invalid library found in /Users/mos6502/Documents/Arduino/libraries/i2cdevlib-master: no headers files (.h) found in /Users/mos6502/Documents/Arduino/libraries/i2cdevlib-master
Invalid library found in /Users/mos6502/Documents/Arduino/libraries/Adafruit_nRF52_Arduino-master: no headers files (.h) found in /Users/mos6502/Documents/Arduino/libraries/Adafruit_nRF52_Arduino-master

Not sure what to make of it. I haven't modified anything at this point in the software, to keep things clean...

I'll try another card if I can find one, even though the one I have works in the 3.6.

Thanks for everyone's input so far.
 
Try using the following sketch:

Code:
#include "SdFat.h"

SdFat SD;

void setup() {
  Serial.begin(9600);
  while (!Serial){;}
  
  Serial.print("Initializing SDIO card...");
  if (!SD.begin(SdioConfig(FIFO_SDIO))) {
      Serial.println("failed!");
    return;
  }
  Serial.println("OK!");
}
void loop(){}

What model of microSD card are you using?
 
What is the SD card size? That same card worked on the Attached T_3.6 SD socket? That same sketch compiled for T_4.1 should work - if nothing else involved without T_4.1 support.

---

The Greiman SDfat-beta also tested to work - it expects different Formatting IIRC based on the example used - ExFAT perhaps instead of FAT32 IIRC is what the SD.h uses on the Teensy included library.

Is anything else drawing power from the T_4.1? The SD card takes a decent amount of power - if it doesn't have enough clean power it may fail to function

The same card works on the attached 3.6 socket, yes.

I had been previously using SDfat-beta with the T3.6, with a 512mb card formatted FAT16. I was initializing the cardreader with:

Code:
  if (!SD.begin(SdioConfig(FIFO_SDIO)))
  {
    Serial.println("SDb9 initialization failed!");
    return;
  }
  Serial.println("SD initialization done.");

I've never tried formatting the card exFAT, should I? With the T3.6 /SDfat-beta library I had been using SdFat32 and File32, which exclude exFAT support. Having just reformatted this SD card though with the SD association's formatter I doubt that is the issue but I will try anything at this stage.

The T4.1 is pulling power over USB from a computer. There are a few other small breakouts connected to the power rails on the breadboard (nothing connected to the Teensy pins directly though), but this is not even the full compliment I'll be connecting once this is all done and normally this project runs from a LiPo battery (for a long time) on the T3.6.

Thanks.
 
Paul, already tried changing to BUILTIN_SDCARD, but at least now I know that it's all that is required - I can rule out the code most likely.

TFTLCDCyg, I've tried initializing it exactly how you described and no go (with SDfat-beta rather than SD).

The card is Nokia brand 512mb, and is SD and not SDHC or one of the other fancier types (per the SD Formatter).

Thanks.
 
Go if that microSD is small !. If I'm not mistaken, those microSD tend to fail, if not formatted correctly. The best thing is to format them directly in windows.

8hhea3qp8ngs2o8zg.jpg
 
Good news - I was able to finally hunt down 2 other microSD cards. Problem instantly solved.

Both use FAT16 like the first, one was 2GB and the other only 128MB but yeah... the both worked right away without any fiddling. I'm at a loss as to why the original card doesn't get along with the T4.1, yet it works with T3.6 and all of my computers just fine and didn't come up with any errors during a full (all sector) format.

Thanks everyone, I figured it had to be something I was doing wrong so the sanity checks really helped :)
 
I'm using the SdFat library ver. 1.1.4 with the Teensy 3.6. Now I'm testing the Teensy 4.1 and I found that I have to use the SdFat 2 beta library. In addition to that I found that a lot of code I wrote for the Teensy 3.6 should be entirely rewritten.
Before doing a lot of coding I wish to know if in the near future the two libraries will be merged.

Thank you
 
Hi Paul
I have a Teensy 4.1, is it possible to open two .txt files both in write mode at the same time? like can I do
Code:
File dataFile_1 = SD.open("temperature.txt", FILE_WRITE);
File dataFile_2 = SD.open("pressure.txt", FILE_WRITE);
or do I have to close one file before opening the next?
Thanks
 
Back
Top