-
hi I'm testing the spi sdcard driver with the following example on a ESP32 S3 and it works great, however it only works once. If I try to run it a second time using thonny I get "OSError: no SD card", even after machine.reset() I get the same error but if I unplug the USB cable and plug it again the example works, not really sure what is going on maybe Its a issue with SDCard object already existing? import sdcard, os
from machine import Pin,SPI,SoftSPI,I2S,I2C,UART
spi = SPI(2, sck=Pin(13), mosi=Pin(11), miso=Pin(12))
spi.init(baudrate=4000000, polarity=0, phase=0)
sd = sdcard.SDCard(spi, Pin(4))
vfs = os.VfsFat(sd)
os.mount(vfs, "/sd")
with open("/sd/twolines.txt", "w") as f:
n = f.write("this is the first line\n this is the second") # one block
print(n, "bytes writen")
with open("/sd/twolines.txt", "r") as f:
result = f.read()
print(result)
os.umount('/sd') another issue is that os.listdir() is broken with this driver, I always get the following error:
|
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 3 replies
-
Could you please try my update to the SDcard code, in PR765, micropython/micropython-lib#765 |
Beta Was this translation helpful? Give feedback.
-
Have you tried a lower baud rate, to make sure that there isn't something that cannot run at 24 MHz? That should be legal for any SD card, but maybe there is something wrong. Have you tried s different SD card? Can you test it by putting the code in main.py, and doing a bunch of operations without Thonny involved, just in case it is somehow breaking the SPI? I like Thonny, but its REPL interface does sometimes get in the way. |
Beta Was this translation helpful? Give feedback.
-
How is the SD card attached? |
Beta Was this translation helpful? Give feedback.
-
I fixed the issue by changing the wiring to (sck = 39, miso=21, mosi = 42, cs =15), i think the problem was because i had a LCD on the same SPI as the sdcard, I have them separeted now and both drivers work |
Beta Was this translation helpful? Give feedback.
I fixed the issue by changing the wiring to (sck = 39, miso=21, mosi = 42, cs =15), i think the problem was because i had a LCD on the same SPI as the sdcard, I have them separeted now and both drivers work