Page 1 of 2
Issues when using SPI SD card
Posted: Thu Nov 12, 2020 11:31 pm
by jjamjohnson
Hello, I am trying to setup SD CARD on ESP32 DevKit V1 board using esp-idf for some time but without success.
When I use Arduino IDE, the card works without issues (SD_Test example sketch).
When using esp-idf example sd_card, i get the following error message:
Code: Select all
I (347) example: Initializing SD card
I (347) example: Using SPI peripheral
I (357) gpio: GPIO[5]| InputEn: 0| OutputEn: 1| OpenDrain: 0| Pullup: 0| Pulldown: 0| Intr:0
I (407) sdspi_transaction: cmd=5, R1 response: command not supported
E (427) sdmmc_common: sdmmc_init_ocr: send_op_cond (1) returned 0x107
E (427) vfs_fat_sdmmc: sdmmc_card_init failed (0x107).
I (427) gpio: GPIO[5]| InputEn: 1| OutputEn: 0| OpenDrain: 0| Pullup: 0| Pulldown: 0| Intr:0
E (437) example: Failed to initialize the card (ESP_ERR_TIMEOUT). Make sure SD card lines have pull-up resistors in place.
I have set the define:
and configured pins as following.
Code: Select all
#define PIN_NUM_MISO 19
#define PIN_NUM_MOSI 23
#define PIN_NUM_CLK 18
#define PIN_NUM_CS 5
Can someone help me out with this please?
This image shows how I connected the shield:

- Setup image (1)
- 20201113_000600.jpg (2.37 MiB) Viewed 21004 times

- Setup image (2)
- 20201113_000327.jpg (2.02 MiB) Viewed 21004 times
Re: Issues when using SPI SD card
Posted: Fri Nov 13, 2020 4:49 pm
by PeterR
Try a really, really slow SPI speed. Like 1MHz. This will help show that the issue is not hardware.
Re: Issues when using SPI SD card
Posted: Fri Nov 13, 2020 7:27 pm
by chegewara
This is 5V SD card adapter.
Re: Issues when using SPI SD card
Posted: Sat Nov 14, 2020 9:08 pm
by jjamjohnson
Try a really, really slow SPI speed. Like 1MHz. This will help show that the issue is not hardware.
Thanks! Once I decreased frequency it started working. I get max write speed (1024 to 4096 bytes chunks) at 41KBps. This seams low, any hints on how to improve?
This is 5V SD card adapter.
It seams that this is not the issue.
Re: Issues when using SPI SD card
Posted: Sat Nov 14, 2020 10:23 pm
by PeterR
This is 5V SD card adapter.
lol, that would do it!
He says that this works under arduino. Why do you think that the switch of OS helps/hinders? Random life stuff?
Re: Issues when using SPI SD card
Posted: Wed Dec 09, 2020 12:11 am
by jjamjohnson
Try a really, really slow SPI speed. Like 1MHz. This will help show that the issue is not hardware.
Thanks! Once I decreased frequency it started working. I get max write speed (1024 to 4096 bytes chunks) at 41KBps. This seams low, any hints on how to improve?
This is 5V SD card adapter.
It seams that this is not the issue.
I have an issue with robustness of this solution to sometimes fail mounting or writing to the card. I solved this by reducing as much as possible wires between esp32 and SD module and so far have not experienced issues.
Re: Issues when using SPI SD card
Posted: Wed Dec 09, 2020 12:48 am
by PeterR
Tell me that you have checked the 3V / 5V comment?
That's an easy datasheet check.
You can get voltage level issues to 'work' when reducing MHz but you don't/should not use empirical results ahead of something as simple as a datasheet check (I'm not doing that check for you).
41Kbps is stupidly slow.
I have run SD on ESP at 4MHz using dupont held on with sticky tape & positive thinking ...
Re: Issues when using SPI SD card
Posted: Thu Dec 10, 2020 8:48 pm
by jjamjohnson
Tell me that you have checked the 3V / 5V comment?
That's an easy datasheet check.
You can get voltage level issues to 'work' when reducing MHz but you don't/should not use empirical results ahead of something as simple as a datasheet check (I'm not doing that check for you).
41Kbps is stupidly slow.
I have run SD on ESP at 4MHz using dupont held on with sticky tape & positive thinking ...
I did check and I am not sure -
http://datalogger.pbworks.com/w/file/fe ... asheet.pdf:
Code: Select all
Power supply is 4.5V ~ 5.5V, 3.3V voltage regulator circuit board
Re: Issues when using SPI SD card
Posted: Wed Dec 23, 2020 4:32 pm
by PeterR
Well the datasheet says that it has a level convertor but does not show you how to use 3.3V.
I would hunt for a tutorial.
If you run 5V into an ESP pin then the ESP won't love you for long.
Re: Issues when using SPI SD card
Posted: Sat Dec 26, 2020 3:28 pm
by chegewara
The reason i mentioned about 5V for this sd card module is because i am using exactly the same module and it was the issue i had with it. I found the same answer on arduino-esp32 github. Im not saying it is/was the issue in your case, but i thought its worth to mention.
This module is using AMS1117 which characteristics says that Vin >= Vout + 1,5V.