Sparkfun SAMD51 Thin PLus: SDCard + SPI #14347
-
Hello everybody, I was doing some acquisition tests, real-time audio processing and saving the resulting files (raw and processed data) As for the SPI protocol, I'm having a lot of difficulty on the Sparkfun Samd51 Thing Plus microcontroller, as I'm not able to mount the SPI. This was the code that I'm using with Samd51 Thing Plus (only working with SoftSPI, didn't work with SPI): from machine import Pin, SoftSPI
def MountSD():
# Configure the pins -- 3.3V(OUT) red / GND black
SD_MOSI = Pin('D11', Pin.OUT) # yellow
SD_SCK = Pin('D13', Pin.OUT) # green
SD_CS = Pin('D10', Pin.OUT) # blue
SD_MISO = Pin('D12', Pin.IN) # white
# Start SPI bus - only SoftSPI worked
spi = SoftSPI(baudrate=500_000, polarity=1, phase=0, sck=SD_SCK, mosi=SD_MOSI, miso=SD_MISO)
# Configuration of the CS (Chip Select) pin for the SD card
cs = SD_CS
# Mount SD card
sd = sdcard.SDCard(spi, cs)
vfs = os.VfsFat(sd)
os.mount(vfs, '/sd') What surprised me was the time it took to save the array on the micro SDCard, using SPI. From my tests, it took 7s to save twelve ".npy" arrays, being in total 23.2kb, being far from the speed of the Class 10 SDCard (10Mb/s). SPI in Teensy 4.1: spi = SPI(0,
baudrate=10_000_000,
polarity=0,
phase=0,
bits=8,
firstbit=SPI.MSB) From what I saw the SoftSPI method would be limiting the baudrate to 500_000, while the SPI could be possible to save at 10_000_000 for a Class 10 card or up to the limit of 24_000_000. (SPI protocol in Teensy 4.1 also not reaching the expected speed?) Question 1, how should I made the SPI protocol correctly? Question 2: would these speeds in the order of Mb/s be possible with the SDCard + SPI or would I need another protocol and wiring to reach these speeds? Question 3: would even higher speeds be possible? Using a V90 card? Like 90 to 300Mb/s for writing? Question 4 I Thank to anyone who can clarify a little more about this subject. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 6 replies
-
With the selected pins for MOSI/MISO/SCK, Hard SPI device 1 works. The MIMXRT port has built-in SD card support. So no need to use the Python SD card driver. When the SD card is inserted, it mounts the SD card on boot. Depending on the block size and card type, I get transfer rates up to 10 MByte/s. Using sdcard.py and SPI bus, the speed will stay limited. Question 3: Possibly no Question 4: That seems to be related to the FAT file system on not the respective ports. How did you inspect the files? Which block size has the file system on the card you use? With FAT, each file allocates at least one block. |
Beta Was this translation helpful? Give feedback.
-
This little script works here with a Sparkfun SAMD51 Things Plus and a simple SD card breakout. You do not have to initialize the Pin objects or the baud rate, because that will be done by sdcard.py. So you can as well write: You can however specify a baudrate in the SDCARD constructor, which will be used by the driver. The highest value you can use with SAMD51 is 24MHz. I achieved a data rate of up to 0.5 MByte/s with 50k data blocks.
The Sparkfun SAMD51 Thing Plus has as well three pins labeled MOSI, MISO, and SCK between D0 and A4 . The labels are somewhat hard to read. For these the SPI object can be created with: |
Beta Was this translation helpful? Give feedback.
This little script works here with a Sparkfun SAMD51 Things Plus and a simple SD card breakout. You do not have to initialize the Pin objects or the baud rate, because that will be done by sdcard.py. So you can as well write:
spi = SPI(1, sck="D13", mosi="D11", miso="D12")
. Only cs must be provided as Pin object, but will be set up by the driver.You can however specify a baudrate in the SDCARD constructor, which will be used by the driver. The highest value you can use with SAMD51 is 24MHz. I achieved a data rate of up to 0.5 MByte/s with 50k data blocks.