ESp32 SPI comunication on SD module

I'am having problem with the SD module on Esp32 Dev kit v1 with 30pins. I already have try many things but nothing seens to work. I try diferents pins for the spi and diferent codes, as the one on the exemples and the code bellow (and the SD card had been formated to the correct format). Is there anything that i'am missing? :astonished:

pins conections as the data sheet shows:
MOSI - gpio23
MISO - gpio 19
CLK - gpio 18
CS - gpio 5

the code:

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

void setup(){
  Serial.begin(9600);
  Serial.println("Inicializing SD...");
    
  // verify the SD 
  if (!SD.begin()) {
    Serial.println("Falha, verifique se o cartão está presente.");
    //end
    return;
  }
   
  Serial.println("success.");
 
}
void loop() {
 
  File dataFile = SD.open("LOG.txt", FILE_WRITE);

  if (dataFile) {
    Serial.println("file open!");
  
      dataFile.print("teste do arquivo");
      dataFile.print(" | ");
      dataFile.println("gravacao");
 
      
      dataFile.close();
  }

  else {
    Serial.println("fail to open LOG.txt");
  }
 
  delay(2000);
 
}

Declare and define which SPI channel to use. The ESP32 has 2 SPI busses, HSPI and VSPI.

#include "SPI.h"
SPIClass SPI1(HSPI);
MPU9250FIFO IMU( SPI1, 15);

HSPI and VSPI pins can be redefined or defaults used.

I like using HSPI.

The default pins for SPI on the ESP32.
HSPI
MOSI = GPIO13
MISO = GPIO12
CLK = GPIO14
CD = GPIO15

VSPI
MOSI = GPIO23
MISO = GPIO19
CLK/SCK = GPIO18
CS/SS = GPIO5

If you use HSPI and you receive reboots or Guru Meditation errors, then your SPI device is sending out information during the boot process. GPIO13 cannot change states during the boot process. If that the case use VSPI.

If your library does not receive a SPI device as an input initialization parameter, you will need to change or edit the library. The other option is to use the ESP32 SPI API, feature rich; such as duplexing, multitasking, and fast.

1 Like

i'd try on HSPI and i haven't received any mensage, does it mens that the librarie is incorrect? I change for the espressif SPI librarie but i had the same result. I guess the only option would be the ESP32 SPI API.

GuilhermeVolker:
i'd try on HSPI and i haven't received any mensage, does it mens that the librarie is incorrect? I change for the espressif SPI librarie but i had the same result. I guess the only option would be the ESP32 SPI API.

I found, for the ESP32, when searching for a library add the term "ESP32" to your search, such as "esp32 SD library". Which would get you to this site/page arduino-esp32/libraries/SD at master · espressif/arduino-esp32 · GitHub.

On that page you can navigate to see that the ESP32 has support for the SD card that is declared differently from the Arduino SD declaration and you will see an example of the libraries use.

Thanks a lot for the help! ;D

After a lot of search on the internet i found this site providing a library and a code for test. It works!

:smiley: