ESP32 C3 mini/pico: can't get SD card to work

daledj
Posts: 3
Joined: Sat Jul 29, 2023 2:03 am

ESP32 C3 mini/pico: can't get SD card to work

Postby daledj » Wed Sep 06, 2023 9:15 pm

I'm unable to get sd.begin to start successfully on a C3 pico when connected to an SD card shield. The same shield works when connected to a D1 pro processor, so I know the SD card shield is working. From my studies I think I've specified the pins correctly in this sketch. Any suggestions for how to get this working would be appreciated. Sketch is from the esp32/sd example with the file system tests removed and the pin info for the C3 added. It always fails with "Card Mount Failed".

Code: Select all

/*
 * Connect the SD card to the following pins:
 *
 * SD Card | ESP32 (Lolin C3 pico pins)
 *    D2       -
 *    D3       SS aka CS (IO5)
 *    CMD      MOSI (IO4)
 *    VSS      GND
 *    VDD      3.3V
 *    CLK      SCK (IO1)
 *    VSS      GND
 *    D0       MISO (IO0)
 *    D1       -
 */
#include "FS.h"
#include "SD.h"
#include "SPI.h"

// PINS for C3 mini or C3 pico
#define SCK 1
#define MISO 0
#define MOSI 4
#define SS 5

SPIClass spi = SPIClass();



void setup(){
    Serial.begin(115200);
    spi.begin(SCK, MISO, MOSI, SS);

    if(!SD.begin(SS,spi)){
        Serial.println("Card Mount Failed");
        return;
    }
    uint8_t cardType = SD.cardType();

    if(cardType == CARD_NONE){
        Serial.println("No SD card attached");
        return;
    }

    Serial.print("SD Card Type: ");
    if(cardType == CARD_MMC){
        Serial.println("MMC");
    } else if(cardType == CARD_SD){
        Serial.println("SDSC");
    } else if(cardType == CARD_SDHC){
        Serial.println("SDHC");
    } else {
        Serial.println("UNKNOWN");
    }

    uint64_t cardSize = SD.cardSize() / (1024 * 1024);
    Serial.printf("SD Card Size: %lluMB\n", cardSize);
}

void loop(){

}


lbernstone
Posts: 826
Joined: Mon Jul 22, 2019 3:20 pm

Re: ESP32 C3 mini/pico: can't get SD card to work

Postby lbernstone » Thu Sep 07, 2023 6:43 pm

Hmm. That is a bug. It should alias HSPI (the default) to FSPI on C3. Change your definition to SPIClass spi(FSPI); and it should work. Note that you can skip all that completely and use the default SPI if you call SD.begin(SS).

daledj
Posts: 3
Joined: Sat Jul 29, 2023 2:03 am

Re: ESP32 C3 mini/pico: can't get SD card to work

Postby daledj » Fri Sep 08, 2023 1:34 pm

I found this: https://github.com/espressif/arduino-esp32/issues/8457 that talked about the bug. I'm unable to use the defaults on a Lolin C3 Pico because they are incorrect. However, as described in the article above, I was able to get it to work on my C3 Pico using this code snippet:

Code: Select all

SPI.begin(SCK,MISO,MOSI,SS);
    if (!SD.begin(SS)) {

Who is online

Users browsing this forum: No registered users and 89 guests