Page 1 of 1
machine.SDCard(slot=3) defaults
Posted: Thu Dec 17, 2020 9:53 am
by RobH
I'm trying to access an SD card to an ESP32 (nodemcu, currently with firmware 1.13-254) with the following code:
Code: Select all
import machine
sd = machine.SDCard(slot=2)
print(sd.info())
This works fine, no need to specify pins when using the defaults.
However to get this working for slot=3 I need to specify mosi, miso and cs, even when using the default pins (13, 12, 15 as documented in the table of
https://docs.micropython.org/en/latest/ ... DCard.html).
Without miso I get: OSError: (-264, 'ESP_ERR_INVALID_RESPONSE')
Without mosi I get: OSError: (110, 'ESP_ERR_TIMEOUT')
Strangely enough the sck pin needs not be specified.
It looks to me that machine.SDCard does not have implemented the (correct) defaults for slot=3 (except for sck).
Re: machine.SDCard(slot=3) defaults
Posted: Sun Jan 10, 2021 11:40 pm
by jimmo
I think the defaults used for slot=3 are
#define SDSPI_SLOT_CONFIG_DEFAULT() {\
.gpio_miso = GPIO_NUM_2, \
.gpio_mosi = GPIO_NUM_15, \
.gpio_sck = GPIO_NUM_14, \
.gpio_cs = GPIO_NUM_13, \
.gpio_cd = SDSPI_SLOT_NO_CD, \
.gpio_wp = SDSPI_SLOT_NO_WP, \
.gpio_int = GPIO_NUM_NC, \
.dma_channel = 1 \
}
RobH wrote: ↑Thu Dec 17, 2020 9:53 am
It looks to me that machine.SDCard does not have implemented the (correct) defaults for slot=3 (except for sck).
Looks like there's a typo in the documentation -- miso should be 2, not 12.
Re: machine.SDCard(slot=3) defaults
Posted: Sun Jan 10, 2021 11:42 pm
by jimmo
Re: machine.SDCard(slot=3) defaults
Posted: Mon Jan 11, 2021 10:56 am
by RobH
@Jimmo,
Confirmed! Just received a new ESP module with onboard micro SD card connector (TTGO-T8 V1.7). Its pinout picture shows the same numbers for its SPI interface as you mention above. And indeed I can access the SD card by just specifying:
Thanks
Re: machine.SDCard(slot=3) defaults
Posted: Tue Jan 12, 2021 3:06 pm
by RobH
@jimmo: May I conclude that the default pins for the Hardware SPI bus, esp. for HSPI (id=1) as documented in the Quick Reference for ESP32 are incorrect too?
Re: machine.SDCard(slot=3) defaults
Posted: Tue Jan 12, 2021 11:08 pm
by jimmo
RobH wrote: ↑Tue Jan 12, 2021 3:06 pm
@jimmo: May I conclude that the default pins for the Hardware SPI bus, esp. for HSPI (id=1) as documented in the Quick Reference for ESP32 are incorrect too?
from spi_caps.h in ESP-IDF
Code: Select all
#define HSPI_IOMUX_PIN_NUM_MISO 12
#define HSPI_IOMUX_PIN_NUM_MOSI 13
#define HSPI_IOMUX_PIN_NUM_CLK 14
#define HSPI_IOMUX_PIN_NUM_CS 15
#define HSPI_IOMUX_PIN_NUM_WP 2
#define HSPI_IOMUX_PIN_NUM_HD 4
#define VSPI_IOMUX_PIN_NUM_MISO 19
#define VSPI_IOMUX_PIN_NUM_MOSI 23
#define VSPI_IOMUX_PIN_NUM_CLK 18
#define VSPI_IOMUX_PIN_NUM_CS 5
#define VSPI_IOMUX_PIN_NUM_WP 22
#define VSPI_IOMUX_PIN_NUM_HD 21
Seems fine to me? What are you seeing?
Re: machine.SDCard(slot=3) defaults
Posted: Wed Jan 13, 2021 9:13 am
by RobH
@jimmo
Well, this pins seems to match the quick ref and the datasheet Table 1 of the ESP32. I'm surprised/confused/would-like-to-understand why machine.SDCard(slot=3) uses different default pins for mosi and miso than machine.SPI(id=1). I expected that these would use the same SPI hardware (HSPI). I'm probably missing knowledge of the ESP32 architecture.