ESP32-S2 SD Card Interfacing

I have been trying to get information of an SD card using the ESP32-S2-Saola-1 board, ESP32-S2-WROVER and a microSD card adapter. Every configuration that I've tried has failed to initialize. Here's the wiring that I'm currently using:
CS to IO10
MOSI to IO11
SCK to IO12
MISO to IO13
Ground to Ground
VCC to 5V
I've tried a few different example programs that others have written, but couldn't find anything specific to the ESP32-S2 boards. Below is the code meant for an ESP32-WVROOM that I would like to use for this board.

/*
  SD card test for esp32
 
  This example shows how use the utility libraries
 
  The circuit:
    SD card attached to SPI bus as follows:
        SS    = 5;
        MOSI  = 23;
        MISO  = 19;
        SCK   = 18;
 
 
   by Mischianti Renzo <https://www.mischianti.org>
  
   https://www.mischianti.org
*/
// include the SD library:
#include <SPI.h>
#include <SD.h>
 
// WeMos D1 esp8266: D8 as standard
const int chipSelect = SS;
 
void printDirectory(File dir, int numTabs);
 
void setup() {
  // Open serial communications and wait for port to open:
  Serial.begin(115200);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port 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 (!SD.begin(SS)) {
    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?");
    while (1);
  } else {
    Serial.println("Wiring is correct and a card is present.");
  }
 
  // print the type of card
  Serial.println();
  Serial.print("Card type:         ");
  switch (SD.cardType()) {
    case CARD_NONE:
      Serial.println("NONE");
      break;
    case CARD_MMC:
      Serial.println("MMC");
      break;
    case CARD_SD:
      Serial.println("SD");
      break;
    case CARD_SDHC:
      Serial.println("SDHC");
      break;
    default:
      Serial.println("Unknown");
  }
 
  // print the type and size of the first FAT-type volume
//  uint32_t volumesize;
//  Serial.print("Volume type is:    FAT");
//  Serial.println(SDFS.usefatType(), DEC);
 
  Serial.print("Card size:  ");
  Serial.println((float)SD.cardSize()/1000);
 
  Serial.print("Total bytes: ");
  Serial.println(SD.totalBytes());
 
  Serial.print("Used bytes: ");
  Serial.println(SD.usedBytes());
 
  File dir =  SD.open("/");
  printDirectory(dir, 0);
 
}
 
void loop(void) {
}
 
void printDirectory(File dir, int numTabs) {
  while (true) {
 
    File entry =  dir.openNextFile();
    if (! entry) {
      // no more files
      break;
    }
    for (uint8_t i = 0; i < numTabs; i++) {
      Serial.print('\t');
    }
    Serial.print(entry.name());
    if (entry.isDirectory()) {
      Serial.println("/");
      printDirectory(entry, numTabs + 1);
    } else {
      // files have sizes, directories do not
      Serial.print("\t\t");
      Serial.print(entry.size(), DEC);
      time_t lw = entry.getLastWrite();
      struct tm * tmstruct = localtime(&lw);
      Serial.printf("\tLAST WRITE: %d-%02d-%02d %02d:%02d:%02d\n", (tmstruct->tm_year) + 1900, (tmstruct->tm_mon) + 1, tmstruct->tm_mday, tmstruct->tm_hour, tmstruct->tm_min, tmstruct->tm_sec);
    }
    entry.close();
  }
}

Have you connected the SD card module to the correct pins on the ESP32 ?

Note the comments about pins at the start of the sketch. I would also question the use of 5V rather than 3V3

The ESP32-S2 board does not have the same IOs as what was in the example code. There is no IO23 on the ESP32-S2 board, so I can't use the same wiring.
I've tried this wiring with 5V and 3V3, but I get the same error either way.

The S2-WROVER board had some reported issues over on the official ESP32 Arduino forum:
Arduino support for ESP32-S2 chips - ESP32 Forum

Thank you for the insight. That thread mainly discusses compiling issues with the S2 boards using Arduino IDE. I don't have any issue with compiling the code and communicating with the board via serial connection, which may have been resolved by the 2.0.X packages.

According to arduino-esp32/pins_arduino.h at master · espressif/arduino-esp32 · GitHub the default ESP32-S2 SPI pins are the following.

static const uint8_t SS    = 34;
static const uint8_t MOSI  = 35;
static const uint8_t MISO  = 37;
static const uint8_t SCK   = 36;

I would try these pins. Yes, very different pins from plain old ESP32.

Thank you icebuster, these are the correct pins

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