0

I am trying to get data over SPI from the AEAT9922 angular Sensor (HEDS-9922EV Evaluation Board) using a Raspberry Pi 3b+. Later we will move to a jetson nano or xavier nx. With the Code given we are getting garbage Data which i cant interpret. My best guess is that we are misinterpreting the Datasheet or a general misunderstandig of SPI Communication.

Edit: for the Angular Data its always Returning: 00000000 10000000 00000000 00000000

Link to Datasheet: here

Setup:

    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

Method for Angle:

    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

Finally two screenshots from the Datasheet with the (hopefully) most important information.

[Position Read: (https://i.stack.imgur.com/xnN6y.png)]

[Command and Data Frame: (https://i.stack.imgur.com/3Y55z.png)]

What we tried:

  1. Testing the SPI communication with spidev_test -> Working.
  2. Measuring with Osziloscope if signals are send correctly -> working.
  3. Adapting the script, given is the last iteration. We tried it with just 2 bytes. The Sensor is supposed to work in 16 Bit mode but as the datasheet states returns only 8 Bits.
DerFilip
  • 1
  • 1

0 Answers0