ESP32-S3 SPI SD Card Won't Initialize (All Pins & Wiring Verified)

Hi everyone,

I'm using an ESP32-S3 dev board and trying to connect a standard microSD card via SPI. I'm not using SDMMC, only SPI mode.

Hardware setup:

  • CS: GPIO13
  • MOSI: GPIO20
  • MISO: GPIO19
  • SCK: GPIO18
  • All lines have 4.7k pull-up resistors to 3.3V
  • SD card is formatted with SD Card Formatter (tested with 2GB FAT and 16GB FAT32)
  • Supply voltage is steady 3.34V
  • No TFT or other devices sharing these pins

What happens:

  • I consistently get SD Card Mount Failed or Card initialization failed
  • The SPI test returns 0xFF responses (at least showing MISO is reading)
  • Tried both the Arduino SD library and SdFat with custom SPI instances
  • I tested with multiple SD cards, verified wiring multiple times, tried with different CS and SCK pins
  • ESP32 works fine otherwise, just SD via SPI won’t initialize

Has anyone had success with ESP32-S3 and SD over SPI mode?

Any help, working pin configurations or example code is highly appreciated. Thanks!

Please read the pinned post re 'How to get the most from the forum'

1 Like

Try without them.

Which SD card module. There are 3.3volt and 5volt variants.
I2C needs pull up resistors, SPI not.
Leo..

Why not post the code you are using ?

Tank for your answer, the resistors are integrated in a board ILI9448 tft 4"

Sorry, you said in the first post;

"No TFT or other devices sharing these pins"

?

The 4" tft module have only four SPI indipendent pins. Two SD cards, one is a micro sd 16GB with adapter and the secon is a 2GB Thoshiba.

#include <SPI.h>
#include <SD.h>

#define CS_SD   13
#define MOSI_SD 20
#define MISO_SD 19
#define SCK_SD  18  // also tried 14

SPIClass SPI_SD(VSPI);

void setup() {
  Serial.begin(115200);
  delay(1000);

  Serial.println("========== DEBUG SPI SD ==========");
  Serial.printf("CS: %d\nMOSI: %d\nMISO: %d\nSCK: %d\n", CS_SD, MOSI_SD, MISO_SD, SCK_SD);

  Serial.println(">> Initializing SPI with custom pins...");
  SPI_SD.begin(SCK_SD, MISO_SD, MOSI_SD, CS_SD);

  Serial.println(">> Checking pin states:");
  Serial.printf("MOSI: %d\n", digitalRead(MOSI_SD));
  Serial.printf("MISO: %d\n", digitalRead(MISO_SD));
  Serial.printf("SCK: %d\n",  digitalRead(SCK_SD));
  Serial.printf("CS: %d\n",   digitalRead(CS_SD));

  Serial.println(">> Testing SPI: sending dummy 0xFF commands...");
  for (int i = 0; i < 10; i++) {
    uint8_t response = SPI_SD.transfer(0xFF);
    Serial.printf("SPI response: 0x%02X\n", response);
  }

  Serial.println(">> Attempting SD.begin()...");
  if (!SD.begin(CS_SD, SPI_SD)) {
    Serial.println("!!! SD initialization failed (check wiring and card)");
  } else {
    Serial.println("SD card successfully initialized!");
  }
}

void loop() {
  delay(5000);
}

Now is all ok using this code `#include <SPI.h>
#include <SD.h>

#define SD_CS 13
#define SD_SCK 18
#define SD_MOSI 19
#define SD_MISO 20

SPIClass sdSPI(FSPI); // Usa FSPI per SD (corrisponde alla SPI principale su molti S3)

void setup() {
Serial.begin(115200);
delay(1000);

// Inizializza SPI con i tuoi pin
sdSPI.begin(SD_SCK, SD_MISO, SD_MOSI, SD_CS);

// Inizializza la SD con SPI personalizzata
if (!SD.begin(SD_CS, sdSPI)) {
Serial.println("SD card initialization failed!");
return;
}

Serial.println("SD card initialized successfully!");
File file = SD.open("/test.txt", FILE_WRITE);
if (file) {
file.println("Ciao dal futuro!");
file.close();
Serial.println("Scrittura completata.");
} else {
Serial.println("Impossibile scrivere sul file.");
}
}

void loop() {}
`

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.