SoftSPI and sdcard on M5Stack Core2 #9184
-
Hi sdcard is formatted with FAT32. Does anyone see an obvious problem with my code? from machine import SoftSPI,Pin
import sdcard
import uos
'''
micdroSDCard Pins on M5Stack
mosi = GPIO23
miso = GPIO38
sck = GPIO18
cs = GPIO4
'''
cs = Pin(4)
spi =SoftSPI(baudrate=100000,
polarity=1,
phase=0,
sck=Pin(18),
mosi=Pin(23),
miso=Pin(38))
sd = sdcard.SDCard(spi,cs)
uos.mount(sd,"/sd")
uos.listdir('/sd')
file = open("/sd/data.txt", "w")
file.write("Test Test Test")
file.close() |
Beta Was this translation helpful? Give feedback.
Replies: 6 comments 9 replies
-
This is similar to https://forum.micropython.org/viewtopic.php?f=15&t=12988 ?
I'm not quite sure I follow... the ESP32 allows you to use any pins with a given hardware SPI. |
Beta Was this translation helpful? Give feedback.
-
Yes, it is the same. I was unsure where to post...
Thanks for this information. It was not clear to me when reading the documentation. I am new to the ESP32, coming from the AVR processor Family.... It is a bit confusing that you can change pins on a hardware SPI. Must have skipped this information:-( I imported the newest sdcard.py file, but an older sdcard.py file compiled into the firmware was used when calling sdcard functions. The firmware version seems to be outdated too... I will try it with the newest sdcard file and hardware SPI. |
Beta Was this translation helpful? Give feedback.
-
Isn't the old version a problem when using the machine module?
I have never compiled a firmware for an esp32... Currently, with the newest sdcard.py file, the output is:
I will try it with the machine module. |
Beta Was this translation helpful? Give feedback.
-
Version with the machine module. '''
micdroSDCard Pins on M5Stack
mosi = GPIO23
miso = GPIO38
sck = GPIO18
cs = GPIO4
'''
import machine, os
sd = machine.SDCard(slot=2,sck=machine.Pin(18),miso=machine.Pin(38),mosi=machine.Pin(23),cs=machine.Pin(4))
os.mount(sd, '/sd') # mount
os.listdir('/sd')
file = open("/sd/data.txt", 'w')
file.write("Test Test Test")
file.close()
os.umount('/sd') First run after inserting card and hw reset gives:
Continuous runs give:
(Edit by @jimmo to add code formatting) |
Beta Was this translation helpful? Give feedback.
-
Thanks for the hint, I will do so... Lowering the frequency did not change it, still sd = machine.SDCard(slot=2,freq=1_000_000, sck=machine.Pin(18),miso=machine.Pin(38),mosi=machine.Pin(23),cs=machine.Pin(4)) |
Beta Was this translation helpful? Give feedback.
-
@rgroener I managed to track down an SD adaptor. I have tested sdcard.py on an ESP32 using hardware SPI(1), SPI(2) and SoftSPI.
Changing to
works fine for software SPI. I have also tested with
Unfortunately I don't have an ESP32 board that exposes pin 38 so can't try your exact configuration. So... not sure. Does the M5 Stack have some additional requirement like turning on power to the SDCard? (Many boards have something like this). |
Beta Was this translation helpful? Give feedback.
@rgroener I managed to track down an SD adaptor.
I have tested sdcard.py on an ESP32 using hardware SPI(1), SPI(2) and SoftSPI.
Changing to
works fine for software SPI.
I have also tested with
machine.SDCard
, and that seems fine too.