Chain ToF UART Control Protocol (Documentation V1)
1. Basic Information
| Item | Description |
|---|---|
| Communication method | UART / serial port asynchronous communication |
| Device | Chain ToF |
| SKU | U209 |
| Baud Rate | 115200 bps |
| Data Bits | 8 bit |
| Stop bit | 1 bit |
| Parity | None |
| Flow Control | None |
| Document version | V1 |
2. Data Frame Format
All packets start with 0xAA 0x55 and end with 0x55 0xAA. Multi-byte length fields are entered low byte first.
2.1 Request Frame Format
| Field | length | Description |
|---|---|---|
| Header | 2 | Fixed to 0xAA 0x55 |
| Length | 2 | Number of bytes from Index to CRC, low byte first |
| Index | 1 | The index ID of the device in the Chain link |
| Cmd | 1 | request command code |
| Req Data | n | Request parameters; if there are no parameters, the length is 0 |
| CRC | 1 | See "3. Verification Instructions" |
| Tail | 2 | Fixed to 0x55 0xAA |
Request Frame:
AA 55 <Length_low> <Length_high> <Index> <Cmd> <Req Data...> <CRC> 55 AA 2.2 Response Frame Format
| Field | length | Description |
|---|---|---|
| Header | 2 | Fixed to 0xAA 0x55 |
| Length | 2 | Number of bytes from Index to CRC, low byte first |
| Index | 1 | The index ID of the device in the Chain link |
| Cmd | 1 | Consistent with request Cmd |
| Resp Data | n | Response data, the structure is defined by the corresponding command |
| CRC | 1 | See "3. Verification Instructions" |
| Tail | 2 | Fixed to 0x55 0xAA |
Response Frame:
AA 55 <Length_low> <Length_high> <Index> <Cmd> <Resp Data...> <CRC> 55 AA 2.3 Response Data Convention
| situation | response rules |
|---|---|
| Reply with status code | Operation_status = 0 means the operation failed, Operation_status = 1 means the operation was successful |
| Reply without status code | The judgment method of success or failure shall be based on the "Notes" of the corresponding instruction. |
3. Checksum
| Item | rules |
|---|---|
| Check field | CRC |
| Checksum range | Starting from Index, accumulate to the last byte of Data |
| Checksum algorithm | Excluding the packet header, packet trailer, Length and CRC, the remaining bytes are accumulated and the lower 8-bits are taken. |
| Empty Data | CRC = (Index + Cmd) & 0xFF |
| Checksum failure | discard the frame |
CRC = (Index + Cmd + Data[0] + ... + Data[n]) & 0xFF 3.1 Checksum Example
#include <stddef.h>
#include <stdint.h>
uint8_t chain_calc_crc(uint8_t index, uint8_t cmd,
const uint8_t *data, size_t data_len)
{
uint16_t sum = index + cmd;
for (size_t i = 0; i < data_len; i++) {
sum += data[i];
}
return (uint8_t)(sum & 0xFF);
} 4. Quick overview of commands
| Cmd | Command name | Request Length | Reply Length | Request clarification | Response description | Details |
|---|---|---|---|---|---|---|
0x20 | Set RGB values | 0x0005+Num*3 | 0x0004 | Index_id (device index ID), Index (starting coordinates of the RGB lamp), Num (number of RGB to be set), RGB value | Operation_status | 5.1 |
0x21 | Get RGB value | 0x0005 | 0x0004+Num*3/0x04 | Index_id (device index ID), Index (starting coordinates of RGB lights), Num (number of RGB lights to be read) | RGB value | 5.2 |
0x22 | Set RGB light brightness | 0x0005 | 0x0004 | Index_id (device index ID), Light (RGB brightness, 0~100, default 40), Save_to_flash (whether to save to internal Flash) | Operation_status | 5.3 |
0x23 | Get RGB light brightness | 0x0003 | 0x0004 | Index_id (device index ID) | Light (RGB brightness) | 5.4 |
0x50 | Get ToF measurement distance | 0x0003 | 0x0004 | Index_id (device index ID) | Measure_distance | 5.5 |
0x51 | Set measurement time | 0x0004 | 0x0004 | Index_id (device index ID), Time | Operation_status | 5.6 |
0x52 | Get measurement mode | 0x0003 | 0x0004 | Index_id (device index ID) | Mode | 5.7 |
0x53 | Set measurement mode | 0x0004 | 0x0004 | Index_id (device index ID), Mode | Operation_status | 5.8 |
0x54 | Get measurement mode | 0x0003 | 0x0004 | Index_id (device index ID) | Mode | 5.9 |
0x55 | Set measurement status | 0x0004 | 0x0004 | Index_id (device index ID), Status (measurement status) | Operation_status | 5.10 |
0x56 | Get measurement status | 0x0003 | 0x0004 | Index_id (device index ID) | Status (measurement status) | 5.11 |
0x57 | Get measurement completion flag | 0x0003 | 0x0004 | Index_id (device index ID) | Flag (completion flag) | 5.12 |
0xF8 | Query device unique UID | 0x0004 | 0x0004+4/12 | Index_id (device index ID), UID_Type | Operation_status、UID | 5.13 |
0xF9 | Query the upgrade program version number | 0x0003 | 0x0004 | Index_id (device index ID) | Bootloader_version | 5.14 |
0xFA | Query the device software version number | 0x0003 | 0x0004 | Index_id (device index ID) | Firmware_version | 5.15 |
0xFB | Query device type | 0x0003 | 0x0005 | Index_id (device index ID) | Device_type | 5.16 |
0xFC | Enumeration request, sent by the chain link change end device, and when the device is powered on, notifying the host to update the link device status | Device-initiated report | Device-initiated report | none | none | 5.17 |
0xFD | Heartbeat packets, regular communication between chain devices, can self-discover whether they are end devices, and the host can also use heartbeat packets to determine whether there is a chain device connected. | 0x0003 | 0x0003 | none | none | 5.18 |
0xFE | Enumerate to obtain the number of cascaded devices | 0x0004 | 0x0004 | Send_num (default 0, used to record the number of devices) | Receive_num (the value represents the number of devices) | 5.19 |
5. Command Details
5.1 Set RGB value - Cmd 0x20
Request data
Input parameters: Index_id (device index ID), Index (starting coordinates of the RGB lamp), Num (number of RGB to be set), RGB value
Request Frame:
AA 55 | 0x05+Num*3 | 0x00 | Index_id | 0x20 | Index | Num | R | G | B | ... | CRC | 55 AA Response Data
Return parameters: Operation_status
Response Frame:
AA 55 | 0x04 | 0x00 | Index_id | 0x20 | Operation_status | CRC | 55 AA Things to note
- Operation_status operation status
0: Operation failed1: Operation successful
- Index is the starting coordinate of the RGB light, starting from 0. The TOF device has only one RGB light, so Index = 0, Num = 1
5.2 Get RGB value - Cmd 0x21
Request data
Input parameters: Index_id (device index ID), Index (starting coordinates of RGB lights), Num (number of RGB lights to be read)
Request Frame:
AA 55 | 0x05 | 0x00 | Index_id | 0x21 | Index | Num | CRC | 55 AA Response Data
Return parameter: RGB value
Response Frame:
AA 55 | 0x04+Num*3/0x04 | 0x00 | Index_id | 0x21 | Operation_status | R | G | B | ... | CRC | 55 AA Things to note
- Operation_status operation status
0: Operation failed1: Operation successful
- Index is the starting coordinate of the RGB light, starting from 0. The TOF device has only one RGB light, so Index = 0, Num = 1
- The operation failed and the returned data packet did not contain RGB values.
5.3 Set RGB light brightness - Cmd 0x22
Request data
Input parameters: Index_id (device index ID), Light (RGB brightness, 0~100, default 40), Save_to_flash (whether to save to internal Flash)
Request Frame:
AA 55 | 0x05 | 0x00 | Index_id | 0x22 | Light | Save_to_flash | CRC | 55 AA Response Data
Return parameters: Operation_status
Response Frame:
AA 55 | 0x04 | 0x00 | Index_id | 0x22 | Operation_status | CRC | 55 AA Things to note
- Operation_status operation status
0: Operation failed1: Operation successful
- Save_to_flash Whether to save internal Flash
0: Do not save1:Save
- Successful setting takes effect immediately
- Saving to the internal Flash requires erasing the page, which is a time-consuming process (about 20ms). During this period, the serial port interrupt will be turned off, and frequent operations will affect the life of the device. If you need to adjust the brightness frequently, please avoid saving to the internal Flash every time.
5.4 Get RGB light brightness - Cmd 0x23
Request data
Input parameter: Index_id (device index ID)
Request Frame:
AA 55 | 0x03 | 0x00 | Index_id | 0x23 | CRC | 55 AA Response Data
Return parameters: Light (RGB brightness)
Response Frame:
AA 55 | 0x04 | 0x00 | Index_id | 0x23 | Light | CRC | 55 AA Things to note
5.5 Get ToF measurement distance - Cmd 0x50
Request data
Input parameter: Index_id (device index ID)
Request Frame:
AA 55 | 0x03 | 0x00 | Index_id | 0x50 | CRC | 55 AA Response Data
Return parameters: Measure_distance
Response Frame:
AA 55 | 0x04 | 0x00 | Index_id | 0x50 | Measure_distance_low | Measure_distance_high | CRC | 55 AA Things to note
- Measure_distance = (uint16_t)(Measure_distance_high <<8) | Measure_distance_low (unit: mm)
5.6 Set measurement time - Cmd 0x51
Request data
Input parameters: Index_id (device index ID), Time
Request Frame:
AA 55 | 0x04 | 0x00 | Index_id | 0x51 | Time | CRC | 55 AA Response Data
Return parameters: Operation_status
Response Frame:
AA 55 | 0x04 | 0x00 | Index_id | 0x51 | Operation_status | CRC | 55 AA Things to note
- Operation_status operation status
0: Operation failed1: Operation successful
- Time measurement time (the longer the measurement time, the higher the accuracy) Value:20~200ms Default:33ms
- This instruction requires changing the configuration of VL53L0X, which is time-consuming.
5.7 Get measurement mode - Cmd 0x52
Request data
Input parameter: Index_id (device index ID)
Request Frame:
AA 55 | 0x03 | 0x00 | Index_id | 0x52 | CRC | 55 AA Response Data
Return parameters: Mode
Response Frame:
AA 55 | 0x04 | 0x00 | Index_id | 0x52 | Time | CRC | 55 AA Things to note
- Time measurement time (the longer the measurement time, the higher the accuracy) Value:20~200ms Default:33ms
5.8 Set measurement mode - Cmd 0x53
Request data
Input parameters: Index_id (device index ID), Mode
Request Frame:
AA 55 | 0x04 | 0x00 | Index_id | 0x53 | Mode | CRC | 55 AA Response Data
Return parameters: Operation_status
Response Frame:
AA 55 | 0x04 | 0x00 | Index_id | 0x53 | Operation_status | CRC | 55 AA Things to note
- Operation_status operation status
0: Operation failed1: Operation successful
- Mode measurement mode
0: Stop mode (stop measurement, lowest power consumption)1: Single-shot mode (no active sampling by default, manual triggering is required, power consumption is proportional to the trigger frequency)2: Continuous mode (default active sampling, automatic cycle sampling, maximum power consumption) Default:2
5.9 Get measurement mode - Cmd 0x54
Request data
Input parameter: Index_id (device index ID)
Request Frame:
AA 55 | 0x03 | 0x00 | Index_id | 0x54 | CRC | 55 AA Response Data
Return parameters: Mode
Response Frame:
AA 55 | 0x04 | 0x00 | Index_id | 0x54 | Mode | CRC | 55 AA Things to note
- Mode measurement mode
0: Stop mode (stop measurement, lowest power consumption)1: Single-shot mode (no active sampling by default, manual triggering is required, power consumption is proportional to the trigger frequency)2: Continuous mode (default active sampling, automatic cycle sampling, maximum power consumption) Default:2
5.10 Set measurement status - Cmd 0x55
Request data
Input parameters: Index_id (device index ID), Status (measurement status)
Request Frame:
AA 55 | 0x04 | 0x00 | Index_id | 0x55 | Status | CRC | 55 AA Response Data
Return parameters: Operation_status
Response Frame:
AA 55 | 0x04 | 0x00 | Index_id | 0x55 | Operation_status | CRC | 55 AA Things to note
- Operation_status operation status
0: Operation failed1: Operation successful
- Status measurement status
0: No measurement (stop mode is always 0)1: Measurement (continuous mode is always 1)
- It is not allowed to change the status to 1 in stop mode, and it is not allowed to change the status to 0 in continuous mode. Illegal settings will return failure.
- When the measurement in single mode is completed and other modes are converted to single mode, the flag bit will be actively set to 0.
- When other modes are converted to stop mode, the flag bit will be automatically set to 0.
- When other modes are converted to continuous mode, the flag bit will be automatically set to 1.
5.11 Get measurement status - Cmd 0x56
Request data
Input parameter: Index_id (device index ID)
Request Frame:
AA 55 | 0x03 | 0x00 | Index_id | 0x56 | CRC | 55 AA Response Data
Return parameters: Status (measurement status)
Response Frame:
AA 55 | 0x04 | 0x00 | Index_id | 0x56 | Status | CRC | 55 AA Things to note
- Status measurement mode
0: No measurement (stop mode is always 0)1: Measurement (continuous mode is always 1)
5.12 Get the measurement completion flag - Cmd 0x57
Request data
Input parameter: Index_id (device index ID)
Request Frame:
AA 55 | 0x03 | 0x00 | Index_id | 0x57 | CRC | 55 AA Response Data
Return parameters: Flag (completion flag)
Response Frame:
AA 55 | 0x04 | 0x00 | Index_id | 0x57 | Flag | CRC | 55 AA Things to note
- Flag measurement flag
0: Measurement not completed1: Measurement completed
- Read the measurement result (instruction code: 0x50), this flag will be set to 0, and the flag will be set to 1 once the collection is completed.
5.13 Query the unique UID of the device - Cmd 0xF8
Request data
Input parameters: Index_id (device index ID), UID_Type
Request Frame:
AA 55 | 0x04 | 0x00 | Index_id | 0xF8 | UID_Type | CRC | 55 AA Response Data
Return parameters: Operation_status, UID
Response Frame:
AA 55 | 0x04+4/12 | 0x00 | Index_id | 0xF8 | Operation_status | UID (multi-byte) | CRC | 55 AA Things to note
- Operation_status operation status
0: Operation failed1: Operation successful
- UID_Type UID type
0:4byte UID1:12byte UID
5.14 Query the upgrade program version number - Cmd 0xF9
Request data
Input parameter: Index_id (device index ID)
Request Frame:
AA 55 | 0x03 | 0x00 | Index_id | 0xF9 | CRC | 55 AA Response Data
Return parameters: Bootloader_version
Response Frame:
AA 55 | 0x04 | 0x00 | Index_id | 0xF9 | Bootloader_version | CRC | 55 AA Things to note
5.15 Query the device software version number - Cmd 0xFA
Request data
Input parameter: Index_id (device index ID)
Request Frame:
AA 55 | 0x03 | 0x00 | Index_id | 0xFA | CRC | 55 AA Response Data
Return parameters: Firmware_version
Response Frame:
AA 55 | 0x04 | 0x00 | Index_id | 0xFA | Firmware_version | CRC | 55 AA Things to note
5.16 Query device type - Cmd 0xFB
Request data
Input parameter: Index_id (device index ID)
Request Frame:
AA 55 | 0x03 | 0x00 | Index_id | 0xFB | CRC | 55 AA Response Data
Return parameters: Device_type
Response Frame:
AA 55 | 0x05 | 0x00 | Index_id | 0xFB | Device_type_low | Device_type_high | CRC | 55 AA Things to note
- Device_type = (uint16_t)((Device_type_high << 8) | Device_type_low)
- The device type code of ToF is 0x0005
5.17 Enumeration request, sent by the end device of chain link change, and sent by the device when it is powered on, notifying the host to update the link device status - Cmd 0xFC
Request data
Input parameters: none
Request Frame:
Device-initiated report,No host request frame Response Data
Return parameters: none
Response Frame:
Device-initiated report,No response frame Things to note
None.
5.18 Heartbeat packet, regular communication between chain devices, you can self-discover whether it is an end device, and the host can also use the heartbeat packet to determine whether there is a chain device connected - Cmd 0xFD
Request data
Input parameters: none
Request Frame:
AA 55 | 0x03 | 0x00 | 0xFF | 0xFD | CRC | 55 AA Response Data
Return parameters: none
Response Frame:
AA 55 | 0x03 | 0x00 | 0xFF | 0xFD | CRC | 55 AA Things to note
5.19 Enumerate to obtain the number of cascaded devices - Cmd 0xFE
Request data
Input parameter: Send_num (default 0, used to record the number of devices)
Request Frame:
AA 55 | 0x04 | 0x00 | 0xFF | 0xFE | Send_num | CRC | 55 AA Response Data
Return parameter: Receive_num (the value represents the number of devices)
Response Frame:
AA 55 | 0x04 | 0x00 | 0xFF | 0xFE | Receive_num | CRC | 55 AA Things to note
None.
6. Status code/enumeration value
6.1 Operating status
| value | Name | Description |
|---|---|---|
0 | Failure | Operation failed |
1 | Success | Operation successful |
Other modes, ranges, and event enumeration values are defined in the "Notes" of the corresponding instructions.
7. Version records
| Document version | Date | Description |
|---|---|---|
V1 | 2025-10-22 | Organized according to the official Chain ToF protocol |