Flir Lepton 3.5,带转接板v2.0和Raspberry Pi SPI通信

2024-05-17 06:23:39 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在使用Lepton 3.5模块和带有Raspberry Pi 3B的突破板v2.0。目标是在启用遥测的情况下获得RAW14视频输出。现在,我正在尝试使用Python3.7和spidev库进行SPI通信,但我面临一些问题。我正在使用Flir轻子工程数据表203来指导我

附件是我的代码,最初SPI端口打开,我一次读取164字节,因为视频格式是RAW14,禁用了遥测功能,但我从SPI获得的原始值似乎不正确,附件是一些输出图像。通过检查报头ID中的数据包编号和ttt值,我得到了SPI速度为2.2MHz时35%左右的有效帧,但当我检查数据包编号20处的分段值时,我几乎没有得到有效的分段值。当我切换到20MHz的SPI速度时,我接收到大约9%的有效帧

接收到的某些“有效”数据包的标头仅为零。您能否帮助我了解从SPI端口接收正确数据所需的一些后续步骤或信息?我一次获取164字节的方法正确吗?如何确保数据包不会失去同步

我的代码:

import spidev
import time

spi = spidev.SpiDev()
spi.open(0, 0)
spi.max_speed_hz = 2200000
spi.mode = 0b01 # mode = 3

segmentation=[]
discard = 0
valid = 0
counter = 0
counter2 = 0
for i in range(1000):
#while True:
    data = spi.readbytes(164)
    print("Packet:", data)

    header = data[:4]
    h1 = format(header[0], '08b')
    h2 = format(header[1], '08b')
    h3 = format(header[2], '08b')
    h4 = format(header[3], '08b')
    
    header_bits = h1 + h2 + h3 + h4
    id_field = h1 + h2
    crc = h3 + h4

    first = id_field[0]
    ttt = id_field[1:4]
    packet_number = id_field[4:16]
    print("first: {}, TTT: {}, packet number: {}, CRC: {}". format(first, ttt, packet_number, crc))

    if packet_number == '000000010100':
        segmentation.append(ttt)

    if first != '0':
        print("Priemrio Bit diferente de 0. Repeticoes: {}", counter)
        counter2 = counter2 + 1
        
    elif packet_number[0:4] == '1111':
        print("------------- Discard Package ------------------\n")
        discard = discard + 1
        
    else:
        print("------------- Valid Package --------------------\n")
        valid = valid + 1

    counter = counter + 1
    #break        
print("Valid: {}, Errors: {}".format(valid, discard))    
print("Valid percentage: {:.2f}%".format(valid/(discard+valid+counter2) * 100))
print(counter2)
print("Segmentation: ", segmentation)

“有效”帧的输出:(SPI端口的164字节红色)

Packet: [0, 0, 0, 0, 0, 0, 0, 0, 245, 155, 251, 193, 52, 17, 160, 225, 128, 64, 128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 15, 255, 255, 255, 192, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
first: 0, TTT: 000, packet number: 000000000000, CRC: 0000000000000000
------------- Valid Package --------------------

的输出无效:

Packet: [63, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 214, 113, 113, 130, 128, 121, 29, 36, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
first: 0, TTT: 011, packet number: 111111111111, CRC: 1111111111111111
------------- Discard Package ------------------

1000包的简历:

Valid: 321, Errors: 646
Valid percentage: 32.10%

Tags: spiformatnumberpacketcounter数据包discardheader