Serial Communication Protocol

Last Updated on : 2024-05-09 08:49:36download

The Tuya-defined serial communication protocol specifies how the MCU and network module talk to each other, and applies to all standard network modules that are compatible with Tuya. It supports various wireless protocols, including Wi-Fi, Wi-Fi and Bluetooth combo, Bluetooth, Bluetooth mesh, Zigbee, NB-IoT, and LTE Cat.1.

Connection mode

The MCU standard protocol supports two connection modes: standard power consumption and low power consumption, as shown below.

Standard power consumption

ModuleMCUTX -> RXRX <- TXModuleMCU

Low power consumption

ModuleMCUTX -> RXRX <- TXControl I/O1Control I/O2ModuleMCU
  • You can learn how the control I/O works in low power mode from the low power section of the serial communication protocol for a specific wireless technology.
  • The serial port on the network module connected to the MCU only supports 3.3V.
    When connecting the network module to a 5V-powered MCU, ensure that the MCU is compatible with a 3.3V serial port. If not, voltage level translation will be necessary.

Serial communication convention

Parameter Description
Baud (bit/s)
  • Wi-Fi or Wi-Fi and Bluetooth combo: 9600/115200
  • Bluetooth: 9600/115200
  • Bluetooth mesh: 9600/19200/115200
  • Zigbee: 9600/115200
  • NB-IoT: 9600/115200
  • LTE Cat.1: 9600/115200/460800/921600
Data bit 8
Parity None
Stop bit 1
Data flow control None

For more information about auto-baud detection, see the serial communication protocol for a specific wireless technology.

Frame format

Standard protocol

The following wireless technologies use the standard protocol for integration:

  • Wi-Fi or Wi-Fi and Bluetooth combo
  • Bluetooth
  • Bluetooth mesh
  • NB-IoT
  • LTE Cat.1
Field Bytes Description
Header 2 It is fixed to 0x55aa.
Version 1 It is used for updates and extensions.
Command 1 The frame type.
Data length 2 Big-endian format.
Data N The payload.
Checksum 1 Start from the header, add up all the bytes, and then divide the sum by 256 to get the remainder.

Extended protocol

The Zigbee technology uses the extended protocol for integration:

Field Bytes Description
Header 2 It is fixed to 0x55aa.
Version 1 It is used for updates and extensions.
Packet ID 2 The sequence number of a packet, ranging from 0 to 0xFFF0. When it reaches 0xFFF0, it resets to 0.
Command 1 The frame type.
Data length 2 Big-endian format.
Data N The payload.
Checksum 1 Start from the header, add up all the bytes, and then divide the sum by 256 to get the remainder.
  • All data greater than one byte is transmitted in big-endian format.
  • All sample data in the protocol is in hexadecimal format.
  • The version field is used for extended features.

Serial communication mode

Command transmission

One command is sent by one party and received by the other party synchronously. That is, one party sends a command and waits for a response from the other party.

MCUModuleSend command NRespond to command NMCUModule

If the sender does not receive a correct response within a specified time period, it will resend the packet after a timeout.

See the Protocol List for the commands applying to a specific wireless technology.

Command sending and status reporting

Both command sending and status reporting use asynchronous transmission. For example, the network module sends a command X and the MCU reports a command Y. Data transmission is performed as shown below.

  • The module sends a control command:

    ModuleMCUSend a control command XReport status YModuleMCU

    Assume that the module sends a command X and the MCU reports a command Y.

    • The command sending process:
      1. The module sends a DP command to the MCU through 0x04.
      2. The MCU acknowledges the receipt of the 0x04 packet.
      3. The MCU returns the result of the command execution through 0x05.
      4. Check if the sequence number of the 0x05 packet matches the one of the 0x04 packet.
  • The MCU reports status:

    The MCU reports status to the module in an asynchronous manner. The MCU reports status either proactively or passively.

    • Passive reporting: The MCU responds to the status request from the module.
    ModuleMCUSend a control commandExecute the commandReport statusModuleMCU
    • Proactive reporting: The MCU proactively reports the current status to the module when the device status is changed such as after operations on physical hardware or a restart. After status reporting, if the MCU does not receive a response within the timeout period, or receives a failure result, it will attempt reporting again.
    MCUModuleStatus changeReport statusMCUModule

DP format

Field Length (byte) Description
dpid 1 The identifier of a DP (DP ID).
type 1 The data type of DP, identified by a value.
Type Value Length (byte) Description
Raw 0x00 N Represents a DP of raw data type.
Boolean 0x01 1 Represents a DP of Boolean data type. Valid values include 0x00 and 0x01.
Value 0x02 4 Represents a DP of integer data type, in big-endian format.
String 0x03 N Represents a DP of string data type.
Enum 0x04 1 Represents a DP of enum data type, ranging from 0 to 255.
Bitmap 0x05 1/2/4 Data greater than one byte is transmitted in big-endian format.
len 2 The length is the number of bytes of a value.
Value 1/2/4/N Represented in hexadecimal format. Data greater than one byte is transmitted in big-endian format.