I'm looking to do a data logging project that involves transmitting data from an FPGA to a Raspberry Pi 4 through SPI. The FPGA will transfer 250,000 bytes approximately every 7 seconds. I would like for the Pi to read this data and convert/organise it as needed. Ideally the data would be transferred within a second in order to give the Pi enough time to process the data, so I'm looking to have a SPI speed of at least 2Mbit/s. So far, I'm using an STM32 to provide dummy values and to just get the SPI working on the Pi. Because the Pi won't know when data is ready (and it HAS to be the master on the SPI bus) the slave device will generate a seperate signal on a GPIO pin just to let the Pi know that it needs access to the SPI bus. I'm using python spidev. The code:
So the code sets up the GPIO and SPI accordingly and then it sits in a loop, polling a pin waiting for the slave device (STM32F4 in this case) to be ready. The pin is set high every 3 seconds for a period of 100ms. As you can see in the code, I want to read 100 Kbytes. This code works fine if I want to just read a few bytes, but it doesn't work with larger data transfers. It seems to just read in the first few hundred bytes. Now my question: How can I get the raspberry pi to accept a larger data transfer over SPI? If I need to split the data up in to packets or smaller chunks, how can I do that in spidev? Any help would be appreciated.
Code: Select all
#a simple test for spi import spidev import time import RPi.GPIO as GPIO GPIO.setmode(GPIO.BOARD) GPIO.setup(7, GPIO.IN) #using spi0 bus = 0 #device is chip select. device = 0 #enable spi = spidev.SpiDev() #open a connection to a specific bus and device (CS pin) spi.open(bus, device) #set spi speed and mode spi.max_speed_hz = 5000000 spi.mode = 0 #msg = ["Hello! "] msg = [72, 101, 108, 108, 111, 33, 32] msgRx = 0; print ("python spi test program with STM32") #GPIO.output(7,0) time.sleep (1) while True : if GPIO.input(7) == 1: time.sleep(0.2)#needed to ensure that there aren't multiple triggers within the 100ms pulse #msgRx = spi.readbytes(100000) msgRx = spi.xfer3(100000) print ("Message received") print (msgRx)