Problem to use SD card module on pin 12 (MISO)

Hello people.

I'm trying to build the ESP_8_BIT fork (GitHub - CornN64/esp_8_bit: Atari 8 bit computers, NES and SMS game consoles on your TV with nothing more than a ESP32 and a sense of nostalgia), almost everything runs fine, but when I try to use a SD card module following the read.me instructions, I've got problems.

15 |------------> SD card CS
13 |------------> SD card MOSI
14 |------------> SD card SCLK
12 |------------> SD card MISO
   |     3.3v <-> SD card Vcc
   |      gnd <-> SD card GND

Firstly I can not upload the code if the pin 12 is in use:

A fatal error occurred: Timed out waiting for packet content

If I take off the pin connection, the code goes, than I reconnect the pin after, but it can not read the micro sd card as well:

rst:0x1 (POWERON_RESET),boot:0x33 (SPI_FAST_FLASH_BOOT)
flash read err, 1000
ets_main.c 371

Some tip?

If I were to take a SWAG I would guess the MOSI and MISO are reversed. Please post a schematic as to how you have wired it showing all connections, power and ground. Also include links to technical information on the hardware modules.

Avoid pin 12, its the voltage select pin for the FLASH, and using it can cause FLASH read errors.

Pin 12 can be used but be sure its left floating during programming or reset.

Thank you.

Follow the schematic.

My ESP32 is the WROOM32:
https://www.mouser.com/datasheet/2/891/esp-wroom-32_datasheet_en-1223836.pdf

Yes, I've tried to change in the code the pin 12 to another, but the sd card can not load.

I know a possible way around the problem. I had the same issue using the HSPI bus, as pointed out the MISO pin can cause problems, specially during boot. I came up with a simple solution that didn't require any software changes and allowed me to use the default HSPI pins. I just connected a small PNP transistor in the MISO line. The base is connected via a resistor to the CS pin. When the communication starts the CS line is pulled low first, thus turning on the transistor. This way the MISO line is only active during communication and won't interfere during boot or with any other devices in the same bus.

2 Likes

Nice idea, if you want post a schematic showing the circuit.

When the master initiates the communication, the first signal sent to the slave is a LOW to the cs pin, connected to the GPIO 15 on the ESP32. This activates the PNP transistor enabling the communication through the MISO line connected to the GPIO 12 on the ESP32. When the master wants to end the communication it holds the CS pin HIGH. This makes the PNP transistor to cease conducting, cutting off the SD card reader MISO line from the ESP32 while its not being used. This in turn prevents the problems with the GPIO 12 remaining HIGH on boot and could possibly help solving conflicts with other devices that communicate on the same HSPI bus.

2 Likes

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.