SDcard in SPI mode using Loboris port?

All ESP32 boards running MicroPython.
Target audience: MicroPython users with an ESP32 board.
symac
Posts: 11
Joined: Thu Jan 04, 2018 2:01 pm

SDcard in SPI mode using Loboris port?

Post by symac » Wed Mar 21, 2018 5:22 am

Hello,
based on what I have learnt in this thread I am now trying to get my MicroSD Card Adapter to work with my ESP32 Board. The hardware I got is : I have followed the instructions and the only change I did in menuconfig was under Micropython → SD Card configuration to switch to SPI Mode, leaving the default pins numbers :
  • (14) CLK pin
  • (15) MOSI pin
  • (2) MISO pin
  • (13) CS pin
I then ran the ./BUILD.sh flash command, and can now connect to my board using ./BUILD.sh monitor. uos.uname() displays (if that can help) :

Code: Select all

(sysname='esp32_LoBo', nodename='esp32_LoBo', release='3.1.26', version='ESP32_LoBo_v3.1.26 on 2017-03-18', machine='ESP32 board with ESP32')
On my board, I have connected pins like (left SD Card adapter pin name, right ESP32 Board):
  • GND → GND
  • VCC → 3V3
  • MISO → D2
  • MOSI → D15
  • SCK → D14
  • CS → D13
When using ./BUILD.sh monitor I can connect to my board but when trying to access the sdcard it does not work. If I run directly uos.mountsd() I get the following error :

Code: Select all

E (691073) sdspi_host: sdspi_host_start_command: cmd=51 error=0x108
E (691073) sdmmc_cmd: sdmmc_card_init: send_scr (2) returned 0x108
E (691076) vfs_native: Failed to initialize SDcard: invalid response).
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
OSError: [Errno 5] EIO
And if I try, based on what I understand to be the correct way of setting it from the wiki page to run the following command:

Code: Select all

uos.sdconfig(uos.SPI)
I get an error that "'module' object has no attribute 'SPI'".

This is the first time I really use an ESP32 board so there might be various different steps where I might have done an error, so any help would be more than appreciated, as I suspect there might not be a big issue but just something I misunderstood because of my lack of knowledge of Micropython on Esp32.

OutoftheBOTS_
Posts: 679
Joined: Mon Nov 20, 2017 10:18 am

Re: SDcard in SPI mode using Loboris port?

Post by OutoftheBOTS_ » Wed Mar 21, 2018 7:24 am

I haven't used SD card in SPI mode yet.
I then ran the ./BUILD.sh flash command, and can now connect to my board using ./BUILD.sh monitor. uos.uname() displays (if that can help) :
Hopefully after you ran ./BUILD.sh menuconfig you then ran ./BUILD.sh to build firmware with the options set in menuconfig before running ./BUILS.sh flash

reading the wiki page if everything is set in the menuconfig properly you should be able to just execute to mount the SD card files system.

Code: Select all

uos.mountsd()
if you execute uos.mountsd(/sd) then it will both mount the sd card and change directory to it.

The wiki also says if the menuconfig isn't set properly then you need to use uos.sdconfig(mode [,clk, mosi, miso, cs])

loboris
Posts: 317
Joined: Fri Oct 02, 2015 6:19 pm

Re: SDcard in SPI mode using Loboris port?

Post by loboris » Wed Mar 21, 2018 9:00 am

@symac

Do you have all the needed pull-up resistors mentioned in the Wiki ?

You have sdcard connected to sdio pins, so it can be used in 1-line SD mode. You will need only pins 14, 15 & 2, no need to connect the pin 13.

Some sdcards do not work well in SPI mode.

symac
Posts: 11
Joined: Thu Jan 04, 2018 2:01 pm

Re: SDcard in SPI mode using Loboris port?

Post by symac » Wed Mar 21, 2018 10:58 am

loboris wrote:
Wed Mar 21, 2018 9:00 am
Do you have all the needed pull-up resistors mentioned in the Wiki ?
reading in the documentation that "In most cases, external pullup can be omitted and an internal pullup can be enabled using a gpio_pullup_en(GPIO_NUM_12); call. This is handled by SDCard driver." I was thinking that I had not to worry about it so my microsd card adapter is directly connected to the pins mentioned in my previous message. No external resistor has been added to my breadboard for the moment. If I understand things correctly, I should add a resistor before GPIO15?
loboris wrote:
Wed Mar 21, 2018 9:00 am
You have sdcard connected to sdio pins, so it can be used in 1-line SD mode. You will need only pins 14, 15 & 2, no need to connect the pin 13.

Some sdcards do not work well in SPI mode.
Thanks for this information, I will have a try at the 1-line mode tonight. Within this mode, is there any need to add external pull-ups or are they "software-handled"?

Sorry what might sound like stupid questions, I promise to write a detailed report when I get things working so that other newbies don't have to ask the same questions ;)

loboris
Posts: 317
Joined: Fri Oct 02, 2015 6:19 pm

Re: SDcard in SPI mode using Loboris port?

Post by loboris » Wed Mar 21, 2018 4:22 pm

@symac
All sdcard pins requires pullups.
The driver sets the internal pullups, but they may not be enough (they have higher resistance than recommended 10 K) , depending on sdcard used.

If using 1-line SD mode, the unused sdcard pin D3 must also have a pullup resistor.

As I mentioned, some sdcards do not work well in SPI mode. I have couple of Kingmax cards that do not work in SPI mode at all. All SanDisk cards I have, work well.

When using wires to connect the sdcard (connector) make them as short as possible.

symac
Posts: 11
Joined: Thu Jan 04, 2018 2:01 pm

Re: SDcard in SPI mode using Loboris port?

Post by symac » Fri Mar 23, 2018 5:15 am

symac wrote:
Wed Mar 21, 2018 10:58 am
Thanks for this information, I will have a try at the 1-line mode tonight. Within this mode, is there any need to add external pull-ups or are they "software-handled"?
Some updates on this. I am still unable to access the sd card so I will give more explanation about what I have done so far, hoping someone will find the explanation. I have run the following commands on my host computer :

Code: Select all

./BUILD.sh menuconfig
# change sd setting to 1-line
./BUILD.sh
./BUILD.sh flash
./BUILD.sh monitor
My circuit is currently looking like that :

Image
higher resolution

Image
higher resolution

I believe I followed all the explanations from the wiki now that the pullup resistors have been added. I have tried two different card adapters and two different microSd cards (1x philips; 1x SanDisk).

Thanks in advance for any pointer.

User avatar
liudr
Posts: 147
Joined: Tue Oct 17, 2017 5:18 am

Re: SDcard in SPI mode using Loboris port?

Post by liudr » Fri Mar 23, 2018 5:49 am

I believe that I have the same sd card adapter and it didn't work. I tried to supply it 5V and 3.3 and pullup/no pullup (the module seems to have 4 pullup resistors on board). Killed a card in the process (reversed power pins). I gave up. I took an sd-microsd adapter and soldered pins to it. Finally I got it to work after making some mistakes. My mistake was using the wrong pin for CS. My dev board's pin markings confused me.

So for you, can I recommend using 5V on the sd card adapter's VCC since it needs 5V to generate 3.3V with its on board regulator? Be careful though, use a cheap low-capacity card.

OutoftheBOTS_
Posts: 679
Joined: Mon Nov 20, 2017 10:18 am

Re: SDcard in SPI mode using Loboris port?

Post by OutoftheBOTS_ » Fri Mar 23, 2018 6:59 am

I got an SD card to work using an external adapter in SPI mode.
MicroPython ESP32_LoBo_v3.1.24 - 2017-03-16 on ESP32 board with ESP32
Type "help()" for more information.
>>> import uos
>>> import os
>>> uos.sdconfig(uos.SDMODE_SPI, clk=14, mosi=15, miso=2, cs=13)
>>> os.mountsd(True)
---------------------
Mode: SPI
Name: SD16G
Type: SDHC/SDXC
Speed: default speed (25 MHz)
Size: 14784 MB
CSD: ver=1, sector_size=512, capacity=30277632 read_bl_len=9
SCR: sd_spec=2, bus_width=5

>>> os.listdir()
['System Volume Information', 'JPG', 'VIDEO', 'bots.jpg', 'bots.bmp', 'text.txt']
>>>
20180323_165619.jpg
20180323_165619.jpg (32.48 KiB) Viewed 2610 times
Last edited by OutoftheBOTS_ on Sat Mar 24, 2018 8:36 pm, edited 1 time in total.

User avatar
liudr
Posts: 147
Joined: Tue Oct 17, 2017 5:18 am

Re: SDcard in SPI mode using Loboris port?

Post by liudr » Fri Mar 23, 2018 7:59 pm

Soldered pins to an sd-microsd card adapter and added 10K pullup resistors:

Image

Works like a charm! :lol: The pads are exactly 0.1 inches apart so all I did was lining up the pins and the pads and solder. I then removed the plastic spacer from the pins so I could plug it into a breadboard.

OutoftheBOTS_
Posts: 679
Joined: Mon Nov 20, 2017 10:18 am

Re: SDcard in SPI mode using Loboris port?

Post by OutoftheBOTS_ » Fri Mar 23, 2018 9:41 pm

Now that is cleaver. where there is a will there is a way.

Mind it does surprise me that on such a simple circuit manufactures can be selling BOBs that don't work :(

Post Reply