SD_MMC sdcard driver for datalogger iot

The Sparkfun esp32 datalogger iot board is has exactly the hardware I want for my next project, including the 4-bit SDCard interface. I am developing the software in Platformio in an Arduino framework. Unfortunately, there is no board definition for the “sparkfun_esp32_datalogger_iot” so I am using the “sparkfun_esp32_iot_redboard” which is similar except for the spi sdcard interface. All the previously developed datalogging code from the redboard came over and is working as expected. However, when I include the SD_MMC driver the code hangs in the SD_MMC.begin() function and never returns. The code to that point is:

void setup() {
  int clk = 14;
  int cmd = 15;
  int d0 = 2;
  int d1 = 4;
  int d2 = 12;
  int d3 = 13;

  Serial.begin(115200);
  SD_MMC.setPins(clk, cmd, d0, d1, d2, d3);
  if (!SD_MMC.begin()) {
    Serial.println("Card Mount Failed");
    return;
  }

I have looked through the SD_MMC code but cannot see what the problem could be. I have tried the sd_card_example_main.c code from platforms\espressif\examples\espidf-storage-sdcard\src and while it assumes an espidf environment, I compiled it anyway and it fails with the messages:

Initializing SD card
Using SDMMC peripheral
Mounting filesystem
E (53) sdmmc_common: sdmmc_init_ocr: send_op_cond (1) returned 0x107
E (54) vfs_fat_sdmmc: sdmmc_card_init failed (0x107).

I am at a loss for what to try next. Sparkfun normally provide excellent get-you-going doco for their boards but for this one it is sadly missing.

Any help would be greatly appreciated.

Ron

For the SparkFun DataLogger IoT board, the SD card pins are:

CLK: GPIO14
CMD: GPIO15
D0: GPIO2
D1: GPIO4
D2: GPIO12
D3: GPIO13

These pin assignments match exactly with what you’ve already put in your code, which is correct/good.

There are a couple of important differences between the two boards that might be causing issues:

The DataLogger IoT uses a 4-bit SDIO interface, while the IoT RedBoard ESP32 uses a standard SPI interface for the SD card.
The DataLogger IoT includes additional components for the SD card interface:
There’s a 74HC4050D level shifter (U4) between the ESP32 and the SD card slot.
Each SD card line has a 10k pull-up resistor.

Given that your pin assignments are correct, the issue likely stems from the board definition or the SD card driver configuration.

Here are some suggestions:

Ensure you’re using the latest version of the ESP32 core and SD_MMC library in PlatformIO.

Try initializing the SD card without specifying pins:

if (!SD_MMC.begin("/sdcard", true)) {  // true for 1-bit mode, false for 4-bit mode
    Serial.println("Card Mount Failed");
    return;
}

If that doesn’t work, try explicitly setting the pins and specifying 4-bit mode:

SD_MMC.setPins(14, 15, 2, 4, 12, 13);
if (!SD_MMC.begin("/sdcard", false)) {  // false for 4-bit mode
    Serial.println("Card Mount Failed");
    return;
}

Make sure you’re using a compatible SD card (FAT32 formatted, 32GB or less). If these suggestions don’t resolve the issue, you may need to dig deeper into the SD_MMC library

For the IDF error: The error you’re seeing (0x107) typically indicates a timeout during the SD card initialization process. This could be due to incorrect pin assignments, hardware issues, or incompatible SD card.

Your comment about the 74HC4040D level shifter was the fix. I made GPIO32 an output, set it high and all works beautifully. Many thanks., Ron

Wahoo!