English
English
简体中文
日本語
UART / Protocol reference
PDF

Chain Key UART Control Protocol (Documentation V1)


1. Basic Information

Item Description
Communication method UART / serial port asynchronous communication
Device Chain Key
SKU U206
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
0xE0 chain device presses, actively sends Device-initiated report Device-initiated report Index_id (device index ID) Status (key trigger status) 5.5
0xE1 Query button status 0x0003 0x0004 Index_id (device index ID) Status 5.6
0xE2 Set key data interval 0x0005 0x0004 Index_id (device index ID), Double (double-click time interval), Long (long press time interval) Operation_status 5.7
0xE3 Get key data interval 0x0003 0x0005 Index_id (device index ID) Double、Long 5.8
0xE4 Set button mode 0x0004 0x0004 Index_id (device index ID), Mode (key mode) Operation_status 5.9
0xE5 Get key mode 0x0003 0x0004 Index_id (device index ID) Mode 5.10
0xF8 Query device unique UID 0x0004 0x0004+4/12 Index_id (device index ID), UID_Type Operation_status、UID 5.11
0xF9 Query the upgrade program version number 0x0003 0x0004 Index_id (device index ID) Bootloader_version 5.12
0xFA Query the device software version number 0x0003 0x0004 Index_id (device index ID) Firmware_version 5.13
0xFB Query device type 0x0003 0x0005 Index_id (device index ID) Device_type 5.14
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.15
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.16
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.17

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

  1. Operation_status operation status
    • 0: Operation failed
    • 1: Operation successful
  2. Index is the starting coordinate of the RGB light, starting from 0. The Key device has two RGB lights. By definition, the two RGB lights are of the same color, 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

  1. Operation_status operation status
    • 0: Operation failed
    • 1: Operation successful
  2. Index is the starting coordinate of the RGB light, starting from 0. The Key device has two RGB lights. By definition, the two RGB lights are of the same color, so Index = 0, Num = 1
  3. 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

  1. Operation_status operation status
    • 0: Operation failed
    • 1: Operation successful
  2. Save_to_flash Whether to save internal Flash
    • 0: Do not save
    • 1:Save
  3. Successful setting takes effect immediately
  4. 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 chain device presses, actively sends - Cmd 0xE0

Request data

Input parameter: Index_id (device index ID)

Request Frame:
  Device-initiated report,No host request frame

Response Data

Return parameters: Status (key trigger status)

Response Frame:
  Device-initiated report,No response frame

Things to note

  1. Status button status
    • 0: click
    • 1: Double click
    • 2: long press
  2. This packet is only sent in active reporting mode. After the data packet is sent, the RGB light will superimpose the effect on the light effect set by the user: • Click on Overlay Green (G) • Double click to overlay blue (B) • Long press to overlay red (R) The color channel value of each overlay is 255, and gradually decays with a 10ms cycle within 1 second. The final overlay value drops to 0 and returns to the color effect set by the user. Example: The user sets the RGB light to purple (R=128, G=0, B=128) and the brightness to 50%. After brightness compression, the actual display is: R=64, G=0, B=64. • When the user clicks, the G channel stacks 255: Displayed as R=64, G=255, B=64, the stacked G value gradually decays to 0 over 1 second, and eventually returns to R=64, G=0, B=64. • When the user double-clicks, the B channel superimposes 255: original B=64. After superposition, the value exceeding 255 is processed as 255. After superposition, it is displayed as R=64, G=0, B=255. The superimposed B value gradually decays to 0 within 1 second, and finally returns to R=64, G=0, B=64. • When the user presses and hold, the R channel superimposes 255: original R=64. After superposition, the value exceeding 255 is processed as 255. After superposition, it is displayed as R=255, G=0, B=64. The superimposed R value gradually decays to 0 within 1 second, and finally returns to R=64, G=0, B=64.

5.6 Query button status - Cmd 0xE1

Request data

Input parameter: Index_id (device index ID)

Request Frame:
  AA 55 | 0x03 | 0x00 | Index_id | E1 | CRC | 55 AA

Response Data

Return parameters: Status

Response Frame:
  AA 55 | 0x04 | 0x00 | Index_id | E1 | Status | CRC | 55 AA

Things to note

  1. Status button status
    • 0: Not pressed
    • 1: Press

5.7 Set key data interval - Cmd 0xE2

Request data

Input parameters: Index_id (device index ID), Double (double-click time interval), Long (long press time interval)

Request Frame:
  AA 55 | 0x05 | 0x00 | Index_id | E2 | Double | Long | CRC | 55 AA

Response Data

Return parameters: Operation_status

Response Frame:
  AA 55 | 0x04 | 0x00 | Index_id | E2 | Operation_status | CRC | 55 AA

Things to note

  1. Double: Double-click time interval (default 1) (Double+1)*100ms 0~9(100ms~1000ms)
  2. Long long press time interval (default 0) (Long+3)*1s 0~7(3s~10s)
  3. Operation_status operation status
    • 0: Operation failed
    • 1: Operation successful

5.8 Get key data interval - Cmd 0xE3

Request data

Input parameter: Index_id (device index ID)

Request Frame:
  AA 55 | 0x03 | 0x00 | Index_id | E3 | CRC | 55 AA

Response Data

Return parameters: Double, Long

Response Frame:
  AA 55 | 0x05 | 0x00 | Index_id | E3 | Double | Long | CRC | 55 AA

Things to note

  1. Double double-click time interval 0~9 (100ms~100ms)
  2. Long long press time interval 0~7(3s~10S)

5.9 Set button mode - Cmd 0xE4

Request data

Input parameters: Index_id (device index ID), Mode (key mode)

Request Frame:
  AA 55 | 0x04 | 0x00 | Index_id | E4 | Mode | CRC | 55 AA

Response Data

Return parameters: Operation_status

Response Frame:
  AA 55 | 0x04 | 0x00 | Index_id | E4 | Operation_status | CRC | 55 AA

Things to note

  1. Mode (default 1)
    • 0: Non-active reporting
    • 1: Take the initiative to report
  2. Operation_status operation status
    • 0: Operation failed
    • 1: Operation successful

5.10 Get key mode - Cmd 0xE5

Request data

Input parameter: Index_id (device index ID)

Request Frame:
  AA 55 | 0x03 | 0x00 | Index_id | E5 | CRC | 55 AA

Response Data

Return parameters: Mode

Response Frame:
  AA 55 | 0x04 | 0x00 | Index_id | E5 | Mode | CRC | 55 AA

Things to note

  1. Mode (default 1)
    • 0: Non-active reporting
    • 1: Take the initiative to report

5.11 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

  1. Operation_status operation status
    • 0: Operation failed
    • 1: Operation successful
  2. UID_Type UID type
    • 0:4byte UID
    • 1:12byte UID

5.12 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.13 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.14 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

  1. Device_type = (uint16_t)((Device_type_high << 8) | Device_type_low)
  2. The device type code of Key is 0x0003

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.16 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 connection - 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.17 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-8-6 Organized according to the official Chain Key protocol