Forums Technical Articles Developer Docs 中文区 UART Decoder Module Database Models Quotes & Orders EN · 中文 · 日本語 · DE · ES

How to decode an LR1200E2 reply frame and verify the checksum (55 AA 88 ...)

Viewed 0

Frequently asked by integrators; answered by ERDI Engineering.

I send 55 AA 88 FF FF FF FF 84 to an LR1200E2 at 115200 8N1 and get back 55 AA 88 01 FF 04 D2 5D. How do I turn this into metres, and how is the checksum calculated? My parser rejects some frames and I do not know whether it is the module or my code.

1 Answers

The LR1200E2 uses the family A command/response protocol: every frame is 8 bytes, header 55 AA, all values hexadecimal.

Reply layout: 55 AA 88 STA FF DIS_H DIS_L SUM

  • Byte 3 STA: 1 means the measurement succeeded. Any other value means it failed, and the distance bytes must be ignored.
  • Bytes 6-7: distance, high byte first. The module reports the actual value x 10.
  • Last byte: low 8 bits of the sum of bytes 1 to 7 of the reply (header included).

Your frame: STA = 0x01 is a valid measurement. DIS = 0x04D2 = 1234, divided by 10 gives 123.4 m. Checksum: 0x55 + 0xAA + 0x88 + 0x01 + 0xFF + 0x04 + 0xD2 = 0x35D, low 8 bits 0x5D, which matches.

Note the asymmetry that trips many parsers: the request checksum covers only the function code and the four data bytes (bytes 3 to 7), so 0x88 + 4 x 0xFF gives 0x484, low 8 bits 0x84, and that is the final byte of 55 AA 88 FF FF FF FF 84. The reply checksum covers bytes 1 to 7. Using the request rule on replies is the most common reason for rejected frames.

def parse_reply(f):
    if len(f) != 8 or f[0] != 0x55 or f[1] != 0xAA:
        return None
    if sum(f[0:7]) & 0xFF != f[7]:
        return None            # checksum fail
    if f[3] != 1:
        return None            # STA != 1: measurement failed
    return ((f[5] << 8) | f[6]) / 10.0   # metres

Continuous ranging is 55 AA 89 FF FF FF FF 85 and stop is 55 AA 8E FF FF FF FF 8A. A maintained reference implementation is in https://github.com/ErdiTech/erdi-lrf-drivers ; capture at least 20 raw frames before blaming the module.

Sources:

ERDI Verified Answer — checked against the datasheet by ERDI Engineering.

ERDI Engineering Community is run by ERDI TECH LTD (Chengdu, China) · erdilrf.com · GitHub · Civil applications only · Questions about modules from any brand are welcome.