Hi,
I’m trying to send a 16-bit value over SPI to a slave device, but when I use a logic analyzer to look at the data that is being sent, the first half of the transmission is just zeros. However, the second half directly mirrors what the binary for the value should be (for example, I was testing with the value 4064 in decimal which is 0000111111100000 in binary, and the 11100000 half sends fine). I’m fairly new to SPI and logic analyzers, so I’ve had some trouble narrowing down where this problem is stemming from. Attached below is the code I’m using in the OpenMV IDE. Is there an issue with the code here that would be causing it? I’ve made sure to set bits=16 when I initialize SPI, and I’ve looked through the SPI documentation to see if there was anything else I was missing.
import sensor, image, time, pyb
from pyb import Pin, SPI
cs = Pin("P3", Pin.OUT_OD)
rst = Pin("P7", Pin.OUT_PP)
rs = Pin("P8", Pin.OUT_PP)
# The hardware SPI bus for your OpenMV Cam is always SPI bus 2.
# NOTE: The SPI clock frequency will not always be the requested frequency. The hardware only supports
# frequencies that are the bus frequency divided by a prescaler (which can be 2, 4, 8, 16, 32, 64, 128 or 256).
spi = SPI(2, SPI.MASTER, baudrate=625000, polarity=0, phase=0, bits=16, firstbit=SPI.MSB)
print(spi)
def write_command_byte(c):
cs.low()
rs.low()
spi.send(c)
cs.high()
def write_data_byte(c):
cs.low()
rs.high()
spi.send(c)
cs.high()
def write_command(c, *data):
write_command_byte(c)
if data:
for d in data: write_data_byte(d)
def write_image(img):
cs.low()
rs.high()
spi.send(img)
cs.high()
sensor.reset() # Initialize the camera sensor.
sensor.set_pixformat(sensor.RGB565) # must be this
sensor.set_framesize(sensor.QQVGA2) # must be this
sensor.skip_frames(time = 2000) # Let new settings take affect.
clock = time.clock() # Tracks FPS.
while(True):
clock.tick()
#img = sensor.snapshot()
def c420mat_set_i_out(value_dac):
write_data_byte(value_dac)
#print("Sending SPI Value!")
c420mat_set_i_out(4064) #can be anything between 800 and 4095 (not inclusive)
#print(clock.fps())
Also attached is an image from the logic analyzer
Thank you for your help!