Hello,
I am trying to connect an SD card to an ESP32 Feather.
ESP32 : ESP32-S2 Feather - 2 Mo PSRAM et Stemma QT/Qwiic Adafruit 5000
SD card :
Here's the code
#include <SPI.h>
#include <SD.h>
#include <Arduino.h>
#define CS_SD 10
SPIClass spiSD = SPIClass(SPI);
void setup() {
Serial.begin(115200);
while (!Serial);
delay(1000);
Serial.println("🔹 Début du programme...");
// Initialisation SPI
spiSD.begin(36, 37, 35, CS_SD); // SCK, MISO, MOSI, CS
pinMode(CS_SD, OUTPUT);
digitalWrite(CS_SD, HIGH);
Serial.println("🟡 Initialisation de la carte SD...");
digitalWrite(CS_SD, LOW);
if (!SD.begin(CS_SD, spiSD)) {
Serial.println("❌ Erreur : Impossible d'initialiser la carte SD !");
} else {
Serial.println("✅ Carte SD détectée et initialisée !");
}
}
void loop() {
}
Could you help me?
Thank you.
SPI is the object which is defined in SPI.cpp as follows:
#if CONFIG_IDF_TARGET_ESP32
SPIClass SPI(VSPI);
#else
SPIClass SPI(FSPI);
#endif
So you cannot pass SPI to the constructor of SPIClass.
And you don't need this line:
baptgauthier:
// Initialisation SPI
spiSD.begin(36, 37, 35, CS_SD); // SCK, MISO, MOSI, CS
36, 37, 35 are already defined as SCK, MISO, and MOSI. See pins_arduino.h of your board:
static const uint8_t SS = 42;
static const uint8_t MOSI = 35;
static const uint8_t SCK = 36;
static const uint8_t MISO = 37;
Also I think those are assigned to SPI by default. So the following line
could be OK as:
if (!SD.begin(CS_SD)) {
Note:
FSPI, HSPI or VSPI are just the symbols defined in esp32-hal-spi.h
#ifdef CONFIG_IDF_TARGET_ESP32S2
#define FSPI 1 //SPI 1 bus. ESP32S2: for external memory only (can use the same data lines but different SS)
#define HSPI 2 //SPI 2 bus. ESP32S2: external memory or device - it can be matrixed to any pins
#define SPI2 2 // Another name for ESP32S2 SPI 2
#define SPI3 3 //SPI 3 bus. ESP32S2: device only - it can be matrixed to any pins
#elif CONFIG_IDF_TARGET_ESP32
#define FSPI 1 //SPI 1 bus attached to the flash (can use the same data lines but different SS)
#define HSPI 2 //SPI 2 bus normally mapped to pins 12 - 15, but can be matrixed to any pins
#define VSPI 3 //SPI 3 bus normally attached to pins 5, 18, 19 and 23, but can be matrixed to any pins
#else
#define FSPI 0
#define HSPI 1
#endif
Be careful as those can be confused with the global object SPI
jim-p
March 6, 2025, 2:25pm
4
Did you try the SD_Test example?
Files->Examples->SD->SD_Test
Thanks to your reply, i try a start with the basic example but its fails.
that's why i tried to redefine the SPI
Thank for the link : arduino-esp32/variants/adafruit_feather_esp32s2/pins_arduino.h at master · espressif/arduino-esp32 · GitHub
i retry
Thank
jim-p
March 7, 2025, 9:44am
6
Then there is something wrong with your wiring,
Do you have the module connected to 5V or 3.3V?
3.3V, i dont have 5V on my chip
Thanks
jim-p
March 7, 2025, 4:59pm
8
Your feather has a pin marked USB, that is 5V.
Your SD card has a pin labeled VCC.
Connect VCC pin to USB pin
Then try the example code.
jim-p:
our feather has a pin marked USB, that is 5V.
Your SD card has a pin labeled VCC.
Connect VCC pin to USB pin
Then try the example code.
It's OK with 5V and simplify code !
Thanks
jim-p
March 10, 2025, 9:31am
10
baptgauthier:
Thanks
So 5V was the problem and not the code?
I go back to my initial code and 5V and all worked !
Thank
jim-p
March 10, 2025, 4:08pm
12
Yeah, some of those modules claim they can work on 3.3V or 5V but really need 5V, that is why I asked.
Glad it worked
Have a nice day!
system
Closed
September 6, 2025, 4:08pm
13
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.