Closed davidkleng closed 2 years ago
@P-R-O-C-H-Y PTAL, thanks!
Hi @davidkleng,
when using custom pins for Sd card, you need to init the SPI first with custom pins before calling SD.begin(SD_CS);
Add this line before calling SD.begin:
SPI.begin(SD_SCK, SD_MISO, SD_MOSI, SD_CS);
@P-R-O-C-H-Y , thanks for your help.
I tried that, problem persists. Also, the SD.begin() function does SPI.begin()
Hello @davidkleng, seems it could be problem with PlatformIO set up of your environment. Please take a look on this issue #6021, it can be relevant.
Try
#define SCLK_PIN 18
#define MISO_PIN 38
#define MOSI_PIN 23
#define SS_PIN 4
SPIClass * hspi = NULL;
hspi = new SPIClass(SPI);
hspi->begin(SCLK_PIN, MISO_PIN, MOSI_PIN, SS_PIN);
SD.begin(SS_PIN, *hspi *, 10000000);
or simply try
SD.begin(SS_PIN, SPI, 10000000);
It works with @bhupiister code
Try
#define SCLK_PIN 18 #define MISO_PIN 38 #define MOSI_PIN 23 #define SS_PIN 4 SPIClass * hspi = NULL; hspi = new SPIClass(SPI); hspi->begin(SCLK_PIN, MISO_PIN, MOSI_PIN, SS_PIN); SD.begin(SS_PIN, *hspi *, 10000000);
or simply try
SD.begin(SS_PIN, SPI, 10000000);
Hi @davidkleng, when using custom pins for Sd card, you need to init the SPI first with custom pins before calling
SD.begin(SD_CS);
Add this line before calling SD.begin:
SPI.begin(SD_SCK, SD_MISO, SD_MOSI, SD_CS);
EDIT: For Future Reference:
I had the following errors using the SparkFun Thing Plus C using VS Code and PlatformIO:
[ 1336][E][sd_diskio.cpp:199] sdCommand(): Card Failed! cmd: 0x00
[ 1337][E][sd_diskio.cpp:802] sdcard_mount(): f_mount failed: (3) The physical drive cannot work
[ 1643][E][sd_diskio.cpp:199] sdCommand(): Card Failed! cmd: 0x00
Card Mount Failed
General Code Structure:
#define SD_CS 5
#define SD_SCK 18
#define SD_MISO 19
#define SD_MOSI 2
.....
void setup()
{
Serial.begin(115200);
SPI.begin(SD_SCK, SD_MISO, SD_MOSI, SD_CS);
.....
SD.begin(SD_CS);
.....
}
.....
Many Thanks!!
Hardware:
Board: ESP32-WROOM-32U Core Installation version: platformio/framework-arduinoespressif32 @ https://github.com/espressif/arduino-esp32.git IDE name: Platform.io Flash Frequency: 40Mhz Upload Speed: 115200 Computer OS: Windows 11 ESP sdk version: v4.4-dev-3703-gddc44956bf
Description:
Im trying to initialize a SD card in SPI port.
Sketch:
platformio.ini file:
The code I wrote:
also, i tried with no luck to start the spi first.
The serial output of the code is: