SoftSPI on ESP32

Discussion about programs, libraries and tools that work with MicroPython. Mostly these are provided by a third party.
Target audience: All users and developers of MicroPython.
Post Reply
eskimo
Posts: 2
Joined: Mon May 16, 2022 12:20 pm

SoftSPI on ESP32

Post by eskimo » Fri Sep 02, 2022 8:26 am

Hi
I try to run a sdcard on my M5Stack Core2 (esp32).
I have to use the SoftSPI, due to the given cardreader connection on the M5Stack Core2.
Pins are checked with the documentation of the core2. https://docs.m5stack.com/en/core/core2
Card is formatted with FAT32 and I tried different micro-SD cards with the same result.

The most I got was a very long waiting time and the following error on the REPL.

Code: Select all

>>> %Run -c $EDITOR_CONTENT
Traceback (most recent call last):
  File "<stdin>", line 11, in <module>
  File "sdcard.py", line 54, in __init__
  File "sdcard.py", line 87, in init_card
  File "sdcard.py", line 135, in init_card_v2
OSError: timeout waiting for v2 card
Here is my code.... Does anybody see the problem with it or has an advise on how to fix the problem?
Thanks in advance

Code: Select all

import machine
import sys
import time
from machine import SoftSPI,Pin
import sdcard
import uos

spi =SoftSPI(baudrate=100000,polarity=1,phase=0,sck=Pin(18),mosi=Pin(23),miso=Pin(38))
cs = Pin(4, Pin.OUT, Pin.PULL_UP)
sd = sdcard.SDCard(spi,cs)
time.sleep_ms(10)
uos.mount(sd,"/sd")
time.sleep_ms(10)
file = open("/sd/data.txt", 'w')
file.write("Test Test Test")
file.close()

User avatar
jimmo
Posts: 2754
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia
Contact:

Re: SoftSPI on ESP32

Post by jimmo » Fri Sep 02, 2022 11:36 am

eskimo wrote:
Fri Sep 02, 2022 8:26 am
I have to use the SoftSPI, due to the given cardreader connection on the M5Stack Core2.
Can you elaborate on why that is?

I don't think this is likely the problem, but does it work if you try a higher baud rate?

Are you using the latest version of sdcard.py? There were some recent fixes. https://github.com/micropython/micropyt ... /sdcard.py

I notice that your stacktrace says line 135 is where the timeout is raised, but that doesn't match the current version.

eskimo
Posts: 2
Joined: Mon May 16, 2022 12:20 pm

Re: SoftSPI on ESP32

Post by eskimo » Tue Sep 06, 2022 8:12 am


Post Reply