Correct circuit for sd card

Saskia
Posts: 40
Joined: Mon Jun 26, 2017 11:45 am

Correct circuit for sd card

Postby Saskia » Mon Jun 26, 2017 4:49 pm

Hello,

i try to get a sd card work with my esp32. But i found different types of circuits.
This one https://github.com/espressif/esp-idf/tr ... d#hardware
looks different as this one https://github.com/espressif/arduino-es ... braries/SD

The first one says something about pull up resistors. The second one says
"Do I need any additional modules, like Arduino SD module?

No, just wire your SD card directly to ESP32."

So, do i need resistors to put datas on a sd card or not? I tried the sdcard.c example in the esp-sdk with my esp32 wroom. I used this Pinout for the esp32:
https://raw.githubusercontent.com/gojim ... pinout.png
And this for the sd card: http://elasticsheep.com/wp-content/uplo ... pinout.png

My circuit is this one

Code: Select all

/*
 * Connect the SD card to the following pins:
 *
 * SD Card | ESP32
 *    D2       -
 *    D3       SS
 *    CMD      MOSI
 *    VSS      GND
 *    VDD      3.3V
 *    CLK      SCK
 *    VSS      GND
 *    D0       MISO
 *    D1       -
 */
My sd card looks like this: http://imgur.com/wxujZeb (not pretty, but hey). Flashing the esp32 with the sd-card.c example works. But make monitor gives me this error

Code: Select all

E (1209) sdmmc_req: handle_idle_state_events unhandled: 00000004 00000000
E (1209) sdmmc_cmd: sdmmc_card_init: send_op_cond (1) returned 0x107
E (1219) example: Failed to initialize the card (263). Make sure SD card lines have pull-up resistors in place.
So my question:
Which pinout should i use?
Do i need resistors? If yes, where do i have to place them (is there a picture for the circuit out there?)?






- Saskia

ESP_igrr
Posts: 2071
Joined: Tue Dec 01, 2015 8:37 am

Re: Correct circuit for sd card

Postby ESP_igrr » Mon Jun 26, 2017 5:08 pm

If you are running ESP-IDF SD card example, please follow Readme from that example. You do need to have pullups as described in the readme.
https://github.com/espressif/esp-idf/bl ... /README.md

Saskia
Posts: 40
Joined: Mon Jun 26, 2017 11:45 am

Re: Correct circuit for sd card

Postby Saskia » Mon Jun 26, 2017 5:45 pm

I tried. Now is the error message

Code: Select all

E (1208) sdmmc_cmd: sdmmc_card_init: send_if_cond (1) returned 0x109
E (1208) example: Failed to initialize the card (265). Make sure SD card lines have pull-up resistors in place.
VSS1, VSS2 and VDD is not used on the sd card. Is this right?

- Saskia

ESP_igrr
Posts: 2071
Joined: Tue Dec 01, 2015 8:37 am

Re: Correct circuit for sd card

Postby ESP_igrr » Tue Jun 27, 2017 2:07 am

Power and ground should also be connected to the card.

Saskia
Posts: 40
Joined: Mon Jun 26, 2017 11:45 am

Re: Correct circuit for sd card

Postby Saskia » Tue Jun 27, 2017 7:29 am

I'll get a constant blue led glowing on my esp32.

The error message after flashing:

Code: Select all

$ make flash monitor
Flashing binaries to serial port COM1 (app at offset 0x10000)...
esptool.py v2.0-beta3
Connecting........_____....._____....._____....._____....._____....._____....._____....._____....._____....._____

A fatal error occurred: Failed to connect to ESP32: Timed out waiting for packet header
make: *** [/esp/components/esptool_py/Makefile.projbuild:53: flash] Fehler 2
(without a micro sd card in the adapter the messsage is still

Code: Select all

E (1208) sdmmc_req: handle_idle_state_events unhandled: 00000004 00000000
E (1208) sdmmc_cmd: sdmmc_card_init: send_op_cond (1) returned 0x107
E (1218) example: Failed to initialize the card (263). Make sure SD card lines have pull-up resistors in place.
)

I think there should be something wrong with my soldering on the sd card adapter?

Edit: I tired a complete new sd card adapter with new soldering. Still getting

Code: Select all

E (1170) sdmmc_req: handle_idle_state_events unhandled: 00000004 00000000
E (1170) sdmmc_cmd: sdmmc_card_init: send_op_cond (1) returned 0x107
E (1180) example: Failed to initialize the card (263). Make sure SD card lines have pull-up resistors in place.
but no constant blue light. I will buy an sd card shield and try everything with that.

ESP_igrr
Posts: 2071
Joined: Tue Dec 01, 2015 8:37 am

Re: Correct circuit for sd card

Postby ESP_igrr » Tue Jun 27, 2017 10:47 am

send_op_cond is the first command sent to the card. If it returns ESP_ERR_TIMEOUT (0x107), this means that card did not respond even using just CMD line (data lines are not used at this point). Make sure that D3 line of the card is high (has a pullup; not pulled low by any circuit). If it is low during cmd_go_idle_state, the card will enter SPI mode instead of SD mode.

I recommend capturing the handshake using a logic analyzer. This will probably let you figure out the problem very quickly.

Saskia
Posts: 40
Joined: Mon Jun 26, 2017 11:45 am

Re: Correct circuit for sd card

Postby Saskia » Wed Jun 28, 2017 2:18 pm

I tried the sd card shield. This works with the SD_CARD example in the Arduino IDE. But the error messages with the esp-sdk are the same. Of course, when i try to use the Arduino IDE example in the esp-sdk i'll get some messages like
"can't find #include "FS.h" #include "SD.h" #include "SPI.h"". Si i'm asking to myself: Is it possible to use this ibrarys in the esp sdk? Or is a script out there, which can handle the sd card shield?

Dig Kleppe
Posts: 26
Joined: Wed Jun 28, 2017 5:03 pm

Re: Correct circuit for sd card

Postby Dig Kleppe » Wed Jun 28, 2017 5:28 pm

Hi,
I am also connecting an SDcard.
The SDK uses SD/MMC interface 2 . It has some pins common with the JTAG interface. I don't want to loose this.
The arduino lib uses the plain SPI slow 1 bit mode.
Is there an easy way of connecting the SDK FatFs with SPI , or better SD/MMC interface 1? Is there a reason why interface 1 is not used?
The alternative would be using a separate FatFS.
Dig

User avatar
rudi ;-)
Posts: 1727
Joined: Fri Nov 13, 2015 3:25 pm

Re: Correct circuit for sd card

Postby rudi ;-) » Wed Jun 28, 2017 11:26 pm

Saskia wrote: Of course, when i try to use the Arduino IDE example in the esp-sdk i'll get some messages like
"can't find #include "FS.h" #include "SD.h" #include "SPI.h"". Si i'm asking to myself: Is it possible to use this ibrarys in the esp sdk? Or is a script out there, which can handle the sd card shield?
hi

@ESP_igrr wrote, SD SPI driver is almost ready! Hope to release it soon so i think this comes asap in the ESP-IDF.

in the meantime you can sure use the arduino IDE example and it works in arduino ide and also in the esp-idf , example in eclipse without mistake.
SD-SPI_ESP-IDF.jpg
SD-SPI_ESP-IDF.jpg (322.93 KiB) Viewed 64580 times
have a note how the wire must be done

btw:
cause it is SPI,
you can setup your SPI like you want use your PINS and must then change the wire too on this steps if you want a difference setup.

edit: if you wounder how, check your board example by look up here , then you see example in the ESP32 board (DevKitC board) the used pins for SPI. you can change there - or you can use the SPI.begin with parameters, look example here


and last but not least:

cause you use the "SD Component" (lib) be sure you have arduino as component in your ESP-IDF path or
took this to the project folder. btw - you can use the SD lib as component too.
edit: ( this solve your problem: "can't find #include "FS.h" #include "SD.h" #include "SPI.h"". )

i change to my project the things little like you see and named it SPISD.
also i sort out header to an include folder.

cause you have then arduino as "component" you can setup in menuconfig what you want to do in the main file
use auto setup() and loop() then you need no main_app
or not - then you need the main_app
compo_arduino.jpg
compo_arduino.jpg (43.23 KiB) Viewed 64580 times
if you wounder, where this steps are documented..

RTFM
:mrgreen:

hope this helps

best wishes
rudi ;-)
-------------------------------------
love it, change it or leave it.
-------------------------------------
問候飛出去的朋友遍全球魯迪

Saskia
Posts: 40
Joined: Mon Jun 26, 2017 11:45 am

Re: Correct circuit for sd card

Postby Saskia » Thu Jun 29, 2017 10:25 am

Great workaround, thanks for your help! Works perfectly.

Who is online

Users browsing this forum: Google [Bot] and 116 guests