跳到主要内容
版本:1.0.0

Communication-Protocols

MODBUS RTU Protocol Explanation

MODBUS RTU (Remote Terminal Unit) is an industrial communication protocol, which is a variant of the MODBUS protocol designed for serial communication. This protocol operates in a master-slave mode, where the master device sends a request frame, and the slave device responds.

Data Frame Structure

Each data frame includes a device address, function code, data, and a CRC checksum.

FieldDescriptionLength
Device AddressAddress of the device1 byte
Function CodeIndicates the operation (e.g., read or write)1 byte
DataContains register address and length in the request, and register address and data in the responseVariable length
CRC ChecksumError-checking data2 bytes

Device Address

Each device on the bus is uniquely identified by its address. The valid address range for slave devices is 1–247. When the master sends a data packet, only the slave device with the matching address responds.

Function Code

The function code indicates the operation to be performed, such as reading or writing registers.

CodeDescription
03Read register data
06Write register data

Data

The data packet sent by the master contains the register address and data length, and the data packet responded by the slave contains the content register address and data content. The register address in the data bit is listed in the following subsections.

The data packet sent by the master:

FieldFieldDescription
Register AddressData LengthAddress of the register and length of the data

The data packet responded by the slave:

FieldFieldDescription
Register AddressData LengthAddress of the register and length of the data

CRC Checksum

The CRC (Cyclic Redundancy Check) is a 16-bit value used to detect errors in communication. The master and slave devices calculate the CRC value from the transmitted data and compare it to the received CRC to ensure data integrity.

The calculation method involves an initial 16-bit register set to all ones (0xFFFF). Data is processed byte by byte through XOR operations and bit shifts. If the last bit of the result is 1, the register is XORed with a preset value (0xA001). This process is repeated for each byte in the frame. The final register value is the CRC checksum, with the low byte sent first during transmission.

CRC code block:

1 /** 
2   * @funcname: u16 crc16(u8 *buffer,u16 length) 
3  * @brief  CRC-16/MODBUS x16 + x15 + x2 + 1
4   * @note   The function takes each bit as the result of the XOR operation
5   * @param  buffer This parameter is used to store parameters,Directed buffer array
6   * @param  length This parameter represents the data length,To calculate the total number of bytes
7   * @return  temp result CRC-16
8   */
9 u16 crc16(u8 *buffer,u16 length)
10 {
11     u16 temp=0xffff,i,= 0;  //initial value
12     while( k < length)        //To calculate the total number of bytes
13     {
14         temp = temp ^ buffer[k];   //Enter the byte to be checked, the result of the XOR operation
15         i = 0;
16         while(< 8)            //Number of byte shifts
17         {
18             if((temp & 0x01)==0)  //Check whether the last bit of the result is zero
19             {
20                 temp = temp >> 1; //Move one to the right
21                 i++;               //counter 
22             }
23             else
24             {
25                 temp = temp >> 1;        //Move one to the right
26                 temp = temp ^ 0xa001;    //The result of the XOR operation
27                 i++;                     //counter 
28             }
29         }
30         k++;                             //Next check byte
31     }
32     return(temp);
33 }

Example of Reading and Writing Registers

Read Register Data Frame

Data frame sent when reading registers:

Device AddressFunction CodeRegister AddressData contentCRC ChecksumCRC Checksum
0~24703HRegister Address32bitHigh ByteLow Byte

Data frame responded when reading register:

Device AddressFunction CodeRegister AddressData contentCRC ChecksumCRC Checksum
0~24703HRegister Address32bitHigh ByteLow Byte

Write Register Data Frame

Data frame sent when writing registers:

Device AddressFunction CodeRegister AddressData contentCRC ChecksumCRC Checksum
0~24706HRegister Address32bitHigh ByteLow Byte

Data frame responded when writing registers:

Device AddressFunction CodeRegister AddressData contentCRC ChecksumCRC Checksum
0~24706HRegister Address32bitHigh ByteLow Byte

List of Register Addresses

Register AddressParameter NameRead/WriteData RangeDescription
00 00Version InformationR/W0/1Returns version info on power-up (0: No return, 1: Return, default: Return)
00 01Baud RateR/W1~5Baud rates: 1=19200, 2=57600, 3=115200, 4=2250000, 5=4500000bps (default: 19200)
00 02Device AddressR/W0~247Device address
00 03Motor TemperatureR-40°C~75°CRead motor temperature
00 04BrakeR/W0/1Brake/Release brake (only for models with brakes)
00 10Servo StateR/W0/1Servo state (0: Off, 1: On).
00 13Encoder Position 1R±67108864Read cumulative position of encoder 1, cleared when powered off.
00 14Motor SpeedR±3000 rpmRead current motor speed (in rpm).
00 15Encoder Position 2R0~32767Read single-turn absolute position of output shaft encoder 2.
00 19Drive CurrentR0~5000Read drive current (in milliamps).
00 1AOperating StateR0/1Read motor operating state.
00 1BFault CodeR/W0~3Fault code (0: Normal, 1: Under-voltage, 2: Over-temperature, 3: Overload).
00 1EUpper Limit of Motor CurrentR/W10~3500Set upper limit of motor current (in mA).
00 20Position Control Proportional Coefficient (Kp1)R/W1~32000Higher value indicates stronger stiffness.
00 21Position Control Integral Coefficient (Ki1)R/W1~32000Used to eliminate steady-state error.
00 22Position Control Derivative Coefficient (Kd1)R/W1~32000Damping to prevent oscillation.
00 27Acceleration TimeR/W100~1000 msSet motor acceleration time (in milliseconds).
00 28Deceleration TimeR/W100~1000 msSet motor deceleration time (in milliseconds).
00 2DSave ParametersW1Save configuration parameters.
00 2ETarget SpeedR/W1~3000 rpmSet motor running speed (in rpm).
00 2FSpeed ModeR/W±3000 rpmSpeed mode (in rpm).
00 30Current ModeR/W±2000 mAModify PWM parameters in current mode.
00 31Set Home PositionW1Set the current position as the home position.
00 32Return to Home PositionW1Return the output shaft to the home position.
00 33Stop Motor OperationW1Stop motor operation.
00 81Position ModeW±134217728Run to target position (without acceleration or deceleration, no return information).
00 82Position ModeW±134217728Run to target position (with target speed setting).
提示

If the communication baud rate or device address is modified, the parameters need to be saved and the device needs to be powered off and restarted for the changes to take effect.

提示

It is recommended that the target position and current position difference be less than 1000 when sending a new target position. If the difference is too large, the lack of acceleration/deceleration may cause motor vibrations.

提示

Encoder 1 resolution varies as follows:

  • 15 bits for models without brakes
  • 18 bits for brake-equipped joint modules of models 08 and 11
  • 19 bits for brake-equipped joint modules of models 14 and 17

Application Examples

Read Motor Position

The master send:

Device AddressFunction CodeRegister AddressData content 32bitCRC Checksum
010300 1300 00 00 02C5 B6

The slave response:

Device AddressFunction CodeRegister AddressData content 32bitCRC Checksum
010300 1300 01 86 A0C5 B6

Read Servo Status

The master send:

Device AddressFunction CodeRegister AddressData content 32bitCRC Checksum
010300 1000 00 00 02C5 F2

The slave response:

Device AddressFunction CodeRegister AddressData content 32bitCRC Checksum
010300 1000 00 00 0004 73

Write Servo Status

The master send:

Device AddressFunction CodeRegister AddressData content 32bitCRC Checksum
010600 1000 00 00 01C4 E7

The slave response:

Device AddressFunction CodeRegister AddressData content 32bitCRC Checksum
010600 1000 00 00 01C4 E7

Write Target Speed: 1000 rpm

The master send:

Device AddressFunction CodeRegister AddressData content 32bitCRC Checksum
010600 2E00 00 03 E87F 0F

The slave response:

Device AddressFunction CodeRegister AddressData content 32bitCRC Checksum
010600 2E00 00 03 E87F 0F

Write Target Position: 20000

The master send:

Device AddressFunction CodeRegister AddressData content 32bitCRC Checksum
010600 8200 00 4E 20A1 AB

The slave response:

Device AddressFunction CodeRegister AddressData content 32bitCRC Checksum
010600 8200 00 4E 20A1 AB

Write Target Position: -20000

The master send:

Device AddressFunction CodeRegister AddressData content 32bitCRC Checksum
010600 82FF FF B1 DF35 AA

The slave response:

Device AddressFunction CodeRegister AddressData content 32bitCRC Checksum
010600 82FF FF B1 DF35 AA