SDCard not working for me on Slot3

All ESP32 boards running MicroPython.
Target audience: MicroPython users with an ESP32 board.
Post Reply
mikeabuilder
Posts: 3
Joined: Tue Mar 09, 2021 12:49 am

SDCard not working for me on Slot3

Post by mikeabuilder » Sun Jul 17, 2022 10:14 pm

I'm trying to get a microSD card adapter working on the HSPI bus and not getting anywhere after several days of trying and reading various posts on this forum. I'm hoping someone can help get me set straight.

I've got my adapter connected to the HSPI bus, but using Pin(32) for CS.

Here's the whole of my code:

Code: Select all

''' SD card test'''
import os
import machine


my_sd = machine.SDCard(slot=3, width=1, cd=None, wp=None, sck=machine.Pin(14), miso=machine.Pin(12), mosi=machine.Pin(13), cs=machine.Pin(32), freq = 10000000)
#my_sd = machine.SDCard(slot=3)
print("Print(my_sd) returns: ",my_sd)

os.mount(my_sd, "/sd")
The terminal output is this:

Code: Select all

Print(my_sd) returns:  <SDCard>
E (1373) sdmmc_sd: sdmmc_init_sd_if_cond: send_if_cond (1) returned 0x108
Traceback (most recent call last):
  File "main.py", line 10, in <module>
OSError: 16
MicroPython v1.18 on 2022-01-17; ESP32 module with ESP32
I've run the code with the commented out my_sd= line used in place of the one that explicitly names the pins. The result is the same.

I thought maybe something was wrong with the specific microSD card I'm using, but I get the same error with no card connected.

I thought maybe my microSD adapter is bad, so I tried with it unplugged. Same error.

I thought maybe the board wiring was bad, so I unplugged the ESP32 board and am runnign with nothing connected. Same error message.

I thought maybe my Pin32 CS is causing a problem, so I just used my_sd = machine.SDCard(slot=3). Same error message.

I tried "slot=2", Same error message

I tried my_sd = machine.SDCard() # all defaults. Now I get a different error message:

Code: Select all

E (959) sdmmc_common: sdmmc_init_ocr: send_op_cond (1) returned 0x107
I'm starting to question my sanity. I hope someone can point out something I'm obviously missing.

quiltyja
Posts: 7
Joined: Sun Jul 10, 2022 12:10 pm

Re: SDCard not working for me on Slot3

Post by quiltyja » Mon Jul 18, 2022 2:15 am

I'm not sure that the sck, miso, mosi, etc. options take machine.Pin() values. What works for us on MicroPython 1.14 (see my recent post) is to just pass the logical GPIO numbers. In your configuration this would be:

Code: Select all

my_sd = SDCard(slot=3, sck=14, miso=12, mosi=13, cs=32)
Our experience is that non-recommended pin configurations throw errors when the SDCard() class is instantiated on MicroPython versions 1.16 and later.

I'm not sure if your experience will be the same, but you might like to try v1.14 before you question your sanity :)

Post Reply