External SD card connection on teensy 3.5

Status
Not open for further replies.
I am a newbie to use the teensy board, so please forgive me if I ask some stupid questions.

I moved my project from Arduino Mega to Teensy 3.5. Because of the design limitation, I cannot use the built-in SD card slot. I would like to use external SD card adaptor to connect with Teensy 3.5 via SPI connection. The problem is when I use SD.h or SDFAT.h libarary for the card info sketch, I cannot even access to the card, always ask me if the wiring is correct. The card works fine on build-in SD card slot with Teensy 3.5 and works fine on Arduino Mega or Teensy 3.2 with SPI connection.

I think I need to change something on Sdfat or SD library to make it work. How can I change the library to make the SD card working with SPI connection on Teensy 3.5?

Any advices will be helpful, thanks!
 
To used the builtin card takes that special BUILTIN_SDCARD flag for chipSelect - that uses direct wired interface pins to the adapter.

To use a standard SPI SD card - then it should work when wired to the usual SPI pins like for T_3.2 where CS pin is a real valid pin number.
 
Hi charles
I had same problem but with internal sd reader
if you use arduino IDE, may be it is an library problem
fisrt point:
ide search sd librairy in many folders, an first it use sd lib in user/xx/document/arduino.....
after only it use in tennsy folder
second point:
if you use tennsy lib's sd master, it use an internal connexion for Cs pin named "BUILTIN_SDCARD"
const int chipSelect = BUILTIN_SDCARD;
...
if (!card.init(SPI_HALF_SPEED, chipSelect))

I think that if you want to use an external card reader you must change CS signal to your cs pin
 
To used the builtin card takes that special BUILTIN_SDCARD flag for chipSelect - that uses direct wired interface pins to the adapter.

To use a standard SPI SD card - then it should work when wired to the usual SPI pins like for T_3.2 where CS pin is a real valid pin number.

Thanks for your reply. It does not work on Teensy 3.5 when using the standard SPI connecting to external SD card. I have tested on two Teensy 3.5 board and IDEs on different computers. It works great on Teensy 3.2 and Arduino Mega. Therefore, I really suspect that the problem is the libraries.

My wirings are also simple, just from pin 10 -13. Pin 10 - CS, PIN 13 - CLK. I have moved around the CS pins to 15,21,20, none of them works.
 
In that case you should post what version of the IDE is installed as well as TeensyDuino. Ideally running the latest to test against.

Also indicate the sketch involved if an included example - or post it if not - and the wiring used - and perhaps what SD adapter so anyone looking can see a problem or recreate to your situation and work toward a fix if it is a problem.

Is this just with the SD adapter on SPI - or is there other hardware attached or in use?
 
Thanks for your reply. It does not work on Teensy 3.5 when using the standard SPI connecting to external SD card. I have tested on two Teensy 3.5 board and IDEs on different computers. It works great on Teensy 3.2 and Arduino Mega. Therefore, I really suspect that the problem is the libraries.

My wirings are also simple, just from pin 10 -13. Pin 10 - CS, PIN 13 - CLK. I have moved around the CS pins to 15,21,20, none of them works.

provide code to reproduce issue.
 
Hi charles
I had same problem but with internal sd reader
if you use arduino IDE, may be it is an library problem
fisrt point:
ide search sd librairy in many folders, an first it use sd lib in user/xx/document/arduino.....
after only it use in tennsy folder
second point:
if you use tennsy lib's sd master, it use an internal connexion for Cs pin named "BUILTIN_SDCARD"
const int chipSelect = BUILTIN_SDCARD;
...
if (!card.init(SPI_HALF_SPEED, chipSelect))

I think that if you want to use an external card reader you must change CS signal to your cs pin

Thanks for your advice. Good to know that the order of library searching. My SD card works with the built-in slot when CS pin is "BUILTIN_SDCARD". And I did change the CS pins when i move them around.
 
I have tested on IDE 1.8.5 and 1.8.6. TeensyDuino is 1.45. I am testing the functionalities of Teensy 3.5 one by one. So I only have MicroSD card adapter on SPI.

Here is my code, it's pretty standard card info skecth. The CS pin is 10, CLK is 13. And MISO MOSI are 11 and 12. Adapter is powered up by Vin and ground of Teensy 3.5.
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 on-board: BUILTIN_SDCARD
// Wiz820+SD board: pin 4
// Teensy 2.0: pin 0
// Teensy++ 2.0: pin 20
const int chipSelect = 10;    

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. Needed for Leonardo only
  }


  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) {
  
}
 
Hi Charles
1 - your card reader is on 5v??
2 - what spi pin's you use?. In tennsy3.5 card reader is connecter directly on chip, not on spi pin's, maybe you must define your spi pins
 
That adapter seems to specify ~5V power - though refers to 3.3V … onboard?

This page shows the use of a PJRC adapter designed to work with adjustment (bottom trace) to the 3.3V levels of a Teensy: Teensy-3-MicroSD-guide

This PJRC product is designed to pin directly to Teensy LC, 3.0, 3.1, 3.2, 3.5 and 3.6 : pjrc.com/store/wiz820_sd_adaptor.html

SD cards don't need 5V. For 3.3V Teensy the logic interface must support 3.3V logic levels - and with a 5V only device the 3.3V signals may not meet the bar for proper function. Given it works with T_3.2 that may or may not explain it - both are 5V tolerant at least on all pins with digital I/O function as noted on the card. The only SD socket I have I trust to work is on the PJRC Audio board - and if I connected that (properly :) )I'm sure it would work as it is commonly used - but the T_3.5 I have at hand has had the VIN<>VUSB trace cut and my 5V jumper wire to VIN for power is in the way of socketing the adapter easily …

<edit per post #12> SD cards use 3.2V.
 
Last edited:
SD cards use 3.2V. Newer cards support lower voltages, too, but Teensy uses their 3.2V mode only.
On Arduino-adapters are often levelshifters . These are not good for Teensy and cause problems, because they are too slow. You need to use an adapter without these levelshifters or remove/short them with wires.
 
I have tested on IDE 1.8.5 and 1.8.6. TeensyDuino is 1.45. I am testing the functionalities of Teensy 3.5 one by one. So I only have MicroSD card adapter on SPI.

Here is my code, it's pretty standard card info skecth. The CS pin is 10, CLK is 13. And MISO MOSI are 11 and 12. Adapter is powered up by Vin and ground of Teensy 3.5.
In your code you never set CLK,MISO,MOSI, so you are relying on the default settings that may not be as you expect.
So, I would explicit set the three line similar to the suggested lines for the AudioAdapter
 
Hi Charles
1 - your card reader is on 5v??
2 - what spi pin's you use?. In tennsy3.5 card reader is connecter directly on chip, not on spi pin's, maybe you must define your spi pins

Hi goc,

I have tried to define my spi pins, still no luck.
SPI.setMOSI(11); // Audio shield has MOSI on pin 7
SPI.setSCK(13); // Audio shield has SCK on pin 14
SPI.setMISO(12);
 
That adapter seems to specify ~5V power - though refers to 3.3V … onboard?

This page shows the use of a PJRC adapter designed to work with adjustment (bottom trace) to the 3.3V levels of a Teensy: Teensy-3-MicroSD-guide

This PJRC product is designed to pin directly to Teensy LC, 3.0, 3.1, 3.2, 3.5 and 3.6 : pjrc.com/store/wiz820_sd_adaptor.html

SD cards don't need 5V. For 3.3V Teensy the logic interface must support 3.3V logic levels - and with a 5V only device the 3.3V signals may not meet the bar for proper function. Given it works with T_3.2 that may or may not explain it - both are 5V tolerant at least on all pins with digital I/O function as noted on the card. The only SD socket I have I trust to work is on the PJRC Audio board - and if I connected that (properly :) )I'm sure it would work as it is commonly used - but the T_3.5 I have at hand has had the VIN<>VUSB trace cut and my 5V jumper wire to VIN for power is in the way of socketing the adapter easily …

<edit per post #12> SD cards use 3.2V.

Hi defragster,

I also tried use 3.3V to power up the adapter, no luck. I really do no think it is the power issue. Because I also use 5 V to power it up on Mega and Teensy 3.2
 
Do we need SPI.begin? I think it is included in the SD.h head files. Because I have never added them when working on other board.
also,
what type of error messages you get?
what microSD you are using (size)?
what type of formatting?
did you check content on PC?
how did you set-up Arduino IDE (tools tab)?
 
Thanks to everyone. The issue has been solved. It is because the adaptor gradually die. It was working on Teensy 3.2 and Mega yesterday, but when testing the codes today, the first time I got error on FAT16/32 formatting error, and later on it lost connection completely, but still working on Mega board. I do not know why. After switching to a new adaptor, it works well on all 3 boards.
 
Status
Not open for further replies.
Back
Top