I can't initialize the SD card module with Teensy4.0.

Emirhan Aydın

New member
I've been working on this for weeks but still I'couldn't any solution. I'm working on a flight control board. Its purpose is to send sensor data to a computer via the LoRa module and write the data read during flight to a microSD card. This allows me to compare the accuracy of the data sent and read. However, I can't initialize the SD card module in my system. The microSD card is formatted in FAT32, I'm using the SPI pins, and the module is powered by an external 5V power supply. I've reviewed many forum threads about SD card initialization issues, but I still haven't been able to resolve the issue. I can't even run a simple SD card initialization code. I've checked the hardware and software repeatedly, but I can't find any problems. Could you review my PCB schematic and code here and help me identify the problem? I must be missing something. (I've defined the Teensy SDFat library in the software section.)

Code:
#include <BufferedPrint.h>
#include <FreeStack.h>
#include <MinimumSerial.h>
#include <RingBuf.h>
#include <SdFat.h>
#include <SdFatConfig.h>
#include <sdios.h>
#include <SPI.h>

SdFat SD;
const uint8_t SD_CS_PIN = 7;

void setup() {
  Serial.begin(115200);
  while (!Serial) {}

  SPI.begin();

  // SD kart başlat
  if (!SD.begin(SD_CS_PIN, SD_SCK_MHZ(10))) {
    Serial.println("SD Kart failed to initialize!");
    return;
  }
  Serial.println("SD Kart initialized.");

  // Dosya oluşturma ve yazma
  FsFile file = SD.open("test.txt", O_WRITE | O_CREAT);
  if (file) {
    file.println("hello Teensy 4.0!");
    file.close();
    Serial.println("file written.");
  } else {
    Serial.println("file could not be opened !");
  }
}

void loop() {
}
Schematic_sivasspor-aviyonik_copy.png
Ekran görüntüsü 2025-08-31 134947.png
 
What is this SD card module? SD cards are powered by 3.3V, if it is converting the MISO signal to 5V you are risking damaging your Teensy. There may also be issues if the module is expecting 5V signals going to the SD card.
 
What is this SD card module? SD cards are powered by 3.3V, if it is converting the MISO signal to 5V you are risking damaging your Teensy. There may also be issues if the module is expecting 5V signals going to the SD card.
micro SD card module Here is the SD card module I use. I'm connecting the power supply to the VCC pin of the SD card module via the regulator, independently of the Teensy. I'm connecting the SPI pins to the Teensy as usual. There's a logic converter on the SD card module, so there's no risk of any damage. I even remember trying to power it with 3.3V before (with an Arduino UNO), but I couldn't get it to work. That's why I never tried connecting 3.3V to the VCC pin on the Teensy.
 
We're heard many people report problems with this type of SD card adapter. Your best path would be the get a simple one that has no electronics (just plain wires between the SD card and Teensy) and power it with 3.3V from Teensy. But if you really want to make this one work, the known problems fall into 2 categories.

1: Power - most of these require 5V power and create 3.3V for the SD card. Some claim to have a very low dropout regulator which can still power the card if you use 3.3V power, but we've seen that fail over and over on this forum.

2: Clock Speed - the buffer chip may only work at slow 8 MHz speed used by 8 bit Arduino. You can configure for slower clock. To see how, in Arduino IDE (with Teensy selected, as Arduino's menus update based on the selected board) click File > Examples > SD > SdFat_Usage. Look for the comment "Very slow SPI frequency".
 
We're heard many people report problems with this type of SD card adapter. Your best path would be the get a simple one that has no electronics (just plain wires between the SD card and Teensy) and power it with 3.3V from Teensy. But if you really want to make this one work, the known problems fall into 2 categories.

1: Power - most of these require 5V power and create 3.3V for the SD card. Some claim to have a very low dropout regulator which can still power the card if you use 3.3V power, but we've seen that fail over and over on this forum.

2: Clock Speed - the buffer chip may only work at slow 8 MHz speed used by 8 bit Arduino. You can configure for slower clock. To see how, in Arduino IDE (with Teensy selected, as Arduino's menus update based on the selected board) click File > Examples > SD > SdFat_Usage. Look for the comment "Very slow SPI frequency".
I removed the existing SD card module and tried a different one, but still couldn't get it to work. I think the problem is related to the SPI pins. I wrote SPI scanner code for this. However, the CS pin isn't visible on the SD card module. When I try this with a LoRa module that works with the SPI protocol, that module's CS pin is detected by the SPI scanner. According to your suggestion, there might be problems with the modules. To do this, I just need to solder a cable to the SD card and power it with 3.3V via the Teensy. Did I understand correctly?
 
Back
Top