Now we develop a SPI Loopback app.
Firstly, we open OpenMV IDE and create Python file. We send 4 bytes to SPI and the listen incoming message. The following is complete code.
from pyb import SPI import time print('demo spi') spi = SPI(2, SPI.MASTER, baudrate=600000, polarity=1, phase=0, crc=0x7) b1 = 50 b2 = 55 b3 = 60 b4 = 65 while 1: tx = chr(b1)+chr(b2)+chr(b3)+chr(b4) rx = bytearray(4) spi.send_recv(tx,rx) print('tx: ' + str(tx)) print('rx: ' + str(rx)) b1 += 5 b2 += 5 b3 += 5 b4 += 5 if b1>80: b1 = 50 if b2>80: b2 = 55 if b3>80: b3 = 60 if b4>80: b4 = 65 time.sleep(1500)
Save this code as spidemo.py.