logo

[ESP32] could not find any example in Arduino framework

2020-04-17 21:00
M
wal2
#include <Arduino.h>
#include <SPI.h>
#include <SD.h>

SPIClass spiSD(VSPI);
#define SD_CS 15

void setup()
{
	Serial.begin(115200);

	SPI.end();
	spiSD.begin(18, 19, 23, SD_CS);

	pinMode(39, INPUT);
	if (digitalRead(39) == LOW)
	{
		log_i("SDCard attached!");
	}
	else
	{
		log_i("SDCard detached!");
	}

	if (!SD.begin(SD_CS, spiSD))
	{
		Serial.println("initialization failed!");
		return;
	}
}

void loop()
{
}

https://singtown.com/learn/48770/

I try to follow this tutorial to convert the code into Arduino but I could not connect to the Sdcard.

I also change the other pin but failed too

	spiSD.begin(12, 13, 14, 15); //try 1
	spiSD.begin(12, 13, 14, 5);  //try 2

console log:

clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0018,len:4
load:0x3fff001c,len:1216
ho 0 tail 12 room 4
load:0x40078000,len:9720
ho 0 tail 12 room 4
load:0x40080400,len:6352
entry 0x400806b8
[I][main.cpp:18] setup(): SDCard attached!
[E][sd_diskio.cpp:739] sdcard_mount(): f_mount failed 0x(d)
initialization failed!

update 1:

I also try micro python but it not work too

import time
import machine, sdcard, os
from machine import SPI, Pin

ledValue = 0
led=Pin(12, Pin.OUT)
led.value(1)
time.sleep(1)

try:
  sd = sdcard.SDCard(SPI(2, sck=Pin(18), mosi=Pin(23), miso=Pin(19)), Pin(15))
  os.mount(sd, '/sd')
  ledValue = 1
except:
  sd = None
  ledValue = 0
  
if(sd):
  ledValue = 1

led.value(ledValue)  #Led turn off due too sd initialize failed+