Go Down

Topic: ESp32 SPI comunication on SD module (Read 259 times) previous topic - next topic

GuilhermeVolker

Jun 22, 2019, 11:47 pm Last Edit: Jun 22, 2019, 11:47 pm by GuilhermeVolker
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?  :smiley-eek:

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


the code:
Code: [Select]
#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);
 
}

Idahowalker

#1
Jun 23, 2019, 12:49 am Last Edit: Jun 23, 2019, 12:57 am by Idahowalker
Declare and define which SPI channel to use. The ESP32 has 2 SPI busses, HSPI and VSPI.
Code: [Select]
#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.

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. 

Idahowalker

#3
Jun 23, 2019, 05:17 pm Last Edit: Jun 23, 2019, 06:30 pm by Idahowalker
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 https://github.com/espressif/arduino-esp32/tree/master/libraries/SD.

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.

GuilhermeVolker


GuilhermeVolker

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

http://www.iotsharing.com/2017/05/how-to-use-arduino-esp32-to-store-data-to-sdcard.html

 :D

Go Up