SPI-4:带角度旋转传感器 (AEAT 9922) 和 Raspberry Pi 3b+ 的垃圾数据

问题描述 投票:0回答:0

我正在尝试使用 Raspberry Pi 3b+ 通过 SPI 从 AEAT9922 角度传感器(HEDS-9922EV 评估板)获取数据。稍后我们将转移到 jetson nano 或 xavier nx。 使用给出的代码,我们得到了我无法解释的垃圾数据。我最好的猜测是我们误解了数据表或对 SPI 通信的普遍误解。

编辑:对于 Angular 数据,它总是返回:00000000 10000000 00000000 00000000

数据表链接:这里

设置:

    def __init__(self, bus, device):
        self.spi = spidev.SpiDev()
        self.spi.open(bus, device)
        self.spi.max_speed_hz = 5_000_000
        self.spi.mode = 1

角度方法:

    def read_angle(self):
        # SPI4 read command for position data (address 0x3F)
        address = 0x3F
        read_flag = 0x4000  # Bit 14
        read_cmd = address | read_flag
        read_cmd |= self.compute_parity(read_cmd) << 15

        # Split the 16-bit command into two 8-bit chunks
        cmd_msb = (read_cmd >> 8) & 0xFF  # Most significant byte
        cmd_lsb = read_cmd & 0xFF  # Least significant byte

        # Send the command and receive the response
        resp = self.spi.xfer2([cmd_msb, cmd_lsb, 0, 0])  # sending 4 bytes in total for receiving 18 bits

        # Combine the two bytes into a single 32-bit value
        angle = (resp[0] << 24) + (resp[1] << 16) + (resp[2] << 8) + resp[3]  # assuming big-endian byte order

        # Extract the parity bit
        parity = (angle >> 31) & 0x01

        # Extract the error flag
        ef = (angle >> 30) & 0x01
        if ef:
            print("Warning: Error flag set in angle reading.")

        # Extract the position data
        data = (angle >> 12) & 0x3FFFF  # assuming 18-bit position

        # Check the parity bit
        if parity != self.compute_parity(data):
            raise Exception("Parity error in SPI response")

        return data

最后是数据表中的两个屏幕截图,其中包含(希望)最重要的信息。

[位置读取:(https://i.stack.imgur.com/xnN6y.png)]

[命令和数据帧:(https://i.stack.imgur.com/3Y55z.png)]

我们尝试了什么:

  1. 使用 spidev_test 测试 SPI 通信 -> 工作。
  2. 用示波器测量信号是否正确发送 -> 工作。
  3. 适配脚本,给出的是最后一次迭代。我们只用了 2 个字节就试过了。传感器应该在 16 位模式下工作,但正如数据表所述,仅返回 8 位。
python-3.x spi spidev
© www.soinside.com 2019 - 2024. All rights reserved.