1

So I need to transfer a byte on the spi interface on raspberry pi. Here's my code in python

import spidev
import time
import binimp

fhandle=open("white.txt")

initial=binimp.extract(fhandle,'192','28')
final=binimp.metdat(initial,'192','28')

spi = spidev.SpiDev() #create spi object
spi.open(0, 1) #open spi port 0, device (CS) 1
spi.max_speed_hz = 976000

try:
 while True:
     for i in final:
         resp = spi.xfer2([ord(i)])
except KeyboardInterrupt: # Ctrl+C pressed, so…
    spi.close() # … close the port before exit

Basically I'm just sending a byte one by one to the SPI (ignore the newbinimp functions, they're basically generating a sequence of characters). The issue is that there is a lot of time in between each consecutive byte transfer as shown in the imageSPI on logic analayzer. I'm using a logic analyzer to see the bytes being transferred. As you can see there is a 61.4 micro second wait before each byte is transferred. Is there any way to reduce this time? Thank you so much**Python code made easier to read**

bumped to the homepage by Community 2 days ago

This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.

1

Why don't you send multiple bytes in one transfer?

If you have to send byte by byte I suggest you use C instead of Python.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.