Reference
This comprehensive guide delves into RS485 communication protocols and Modbus-RTU data frame formats, detailing basic communication parameters, register address functionalities, and examples for sensor data management and calibration techniques.
Communication Protocol Description
1. Basic communication parameters
| Interface | Encoding | Data bits | Parity bits | Stop bits | Error checking | Baud rate |
|---|---|---|---|---|---|---|
| RS485 | 8-bit binary | 8 | None | 1 | CRC | 1200bit/s,2400bit/s, 4800bit/s, 9600bit/s, 19200bit/s, 38400bit/s, 57600bit/s, 115200bit/s configurable, default 4800bit/s |
2. Data frame format definition
Using Modbus-RTU communication protocol, the format is as follows:
Initial structure ≥4 bytes of time
Address code = 1 byte
Function code = 1 byte
Data area = N bytes
Error check = 16-bit CRC code
End structure ≥4 bytes of time
Address code: The address of the sensor, which is unique in the communication network (factory default 0x01).
Function code: The function indication of the command sent by the host. This sensor reads the register function code 0x03/0x04 and writes the register function code 0x06/0x10
Data area: The data area is the specific communication data. Note that the high byte of 16-bit data is in front!
CRC code: A two-byte check code.
Register address
| Register Address | Content | Supported Function Codes | Definition Description |
|---|---|---|---|
| 0000H | Ammonia Nitrogen Value | 0x03/0x04 | mg/L; 16-bit unsigned integer, 100 times the actual value |
| 0001H | pH | 0x03/0x04 | 16-bit unsigned integer, 100 times the actual value |
| 0002H | Temperature | 0x03/0x04 | °C; 16-bit signed integer, 10 times the actual value |
| 0050H | Temperature Deviation Value | 0x03/0x04/0x06/0x10 | 16-bit signed integer, 10 times the actual value |
| 0051H | pH Deviation Value | 0x03/0x04/0x06/0x10 | 16-bit signed integer, 100 times the actual value |
| 0052H | Ammonia nitrogen deviation value | 0x03/0x04/0x06/0x10 | 16-bit signed integer, 100 times the actual value |
| 1200H, 1201H | Ammonia nitrogen calibration | 0x10 | Uses 2-point calibration, writing parameters to registers 0x1200 and 0x1201 via function code 0x10 for ammonia nitrogen calibration |
| 1100H, 1101H | pH calibration | 0x10 | Uses 2-point calibration, writing parameters to registers 0x1100 and 0x1101 via function code 0x10 for pH calibration |
| 07D0H | Device address | 0x03/0x04/0x06/0x10 | 1~254 (16-bit unsigned integer, factory default 1) |
| 07D1H | Device baud rate | 0x03/0x04/0x06/0x10 | 0 represents 2400, 1 represents 4800, 2 represents 9600, 3 represents 19200, 4 represents 38400, 5 represents 57600, 6 represents 115200, 7 represents 1200 |
3. Communication Protocol Examples and Explanation
3.1 Reading Ammonia Nitrogen, pH, and Temperature
Query Frame:
| Address Code | Function Code | Registry Address | Registry Length | Checksum Low Byte | Checksum High Byte |
|---|---|---|---|---|---|
| 0x01 | 0x03 | 0x00 0x00 | 0x00 0x03 | 0x05 | 0xCB |
Response Frame:
| Address Code | Function Code | Number of Valid Bytes | Registry Content | Checksum Low Byte | Checksum High Byte |
|---|---|---|---|---|---|
| 0x01 | 0x03 | 0x06 | 0x0C 0xF5 0x03 0x16 0x01 0x09 | 0x8D | 0xBA |
Ammonia nitrogen calculation: 0CF5H=3317 =>NHN=33.17mg/L
pH calculation: 0316H=790 =>pH=7.90
Temperature calculation: 0109H=265=>Temperature=26.5℃
3.2 Correcting the deviation value of ammonia nitrogen
Query frame: If the current device outputs an ammonia nitrogen value of 33.17, to increase the value by 7.25 (multiply by 100 to 725=>02D5), write 02D5 to the register content.
| Address code | Function code | Register address | Register content | Checksum low byte | Checksum high byte |
|---|---|---|---|---|---|
| 0x01 | 0x06 | 0x00 0x52 | 0x02 0xD5 | 0xE8 | 0xE4 |
Response Frame:
| Address Code | Function Code | Register Address | Register Content | Checksum Low Byte | Checksum High Byte |
|---|---|---|---|---|---|
| 0x01 | 0x06 | 0x00 0x52 | 0x02 0xD5 | 0xE8 | 0xE4 |
3.3 Ammonia Nitrogen Electrode Calibration
Calibration is performed by writing parameters to registers 0x1200 and 0x1201 using function code 0x10. This device uses two-point calibration and requires two known ammonia nitrogen standard solutions. Before each calibration point, the equipment must be thoroughly cleaned, excess water removed, and the device thoroughly shaken in the standard solution to accelerate the response. After standing for at least 15 minutes until the values stabilize, the calibration operation can proceed. For the first calibration point, write 0x0001 to register 0x1200 and 100 times the standard ammonia nitrogen value of the first point to register 0x1201. For the second calibration point, write 0x0002 to register 0x1200 and 100 times the standard ammonia nitrogen value of the second point to register 0x1201. Calibration complete.
Query frame: Select a 10 mg/L ammonia nitrogen standard solution to calibrate the first point. 10 * 100 = 1000 = 03E8H
| Address Code | Function Code | Register Address | Register Length | Byte Length | Register Content | Checksum Low Byte | Checksum High Byte |
|---|---|---|---|---|---|---|---|
| 0x01 | 0x10 | 0x12 0x00 | 0x00 0x02 | 0x04 | 0x00 0x01 0x03 0xE8 | 0x76 | 0x71 |
Response Frame:
| Address Code | Function Code | Register Address | Register Length | Checksum Low Byte | Checksum High Byte |
|---|---|---|---|---|---|
| 0x01 | 0x10 | 0x12 0x00 | 0x00 0x02 | 0x44 | 0xB0 |
Query frame: Select a 100 mg/L ammonia nitrogen standard solution to calibrate the second point. 100*100=10000=2710H
| Address Code | Function Code | Registry Address | Registry Length | Byte Length | Registry Content | Checksum Low Byte | Checksum High Byte |
|---|---|---|---|---|---|---|---|
| 0x01 | 0x10 | 0x12 0x00 | 0x00 0x02 | 0x04 | 0x00 0x02 0x27 0x10 | 0x9C | 0xF3 |
Response Frame:
| Address Code | Function Code | Registry Address | Registry Length | Checksum Low Byte | Checksum High Byte |
|---|---|---|---|---|---|
| 0x01 | 0x10 | 0x12 0x00 | 0x00 0x02 | 0x44 | 0xB0 |
3.4 pH Electrode Calibration
pH calibration is performed by writing parameters to registers 0x1100 and 0x1101 using function code 0x10. This device uses a two-point pH calibration, requiring two known pH standard solutions. For the first calibration point, write 0x0003 to register 0x1100 and 100 times the standard pH value of the first point to register 0x1101. For the second calibration point, write 0x0004 to register 0x1100 and 100 times the standard pH value of the second point to register 0x1101. Calibration complete.
Query frame: Select a pH standard solution of 4.01 to calibrate the first point. 4.01 * 100 = 401 = 0191H
| Address Code | Function Code | Register Address | Register Length | Byte Length | Register Content | Checksum Low Byte | Checksum High Byte |
|---|---|---|---|---|---|---|---|
| 0x01 | 0x10 | 0x11 0x00 | 0x00 0x02 | 0x04 | 0x00 0x03 0x01 0x91 | 0x03 | 0xC3 |
Response Frame:
| Address Code | Function Code | Register Address | Register Length | Checksum Low Byte | Checksum High Byte |
|---|---|---|---|---|---|
| 0x01 | 0x10 | 0x11 0x00 | 0x00 0x02 | 0x44 | 0xF4 |
Query frame: Select a pH standard solution of 9.18 to calibrate the second point. 9.18 * 100 = 918 = 0396H
| Address Code | Function Code | Register Address | Register Length | Byte Length | Register Content | Checksum Low Byte | Checksum High Byte |
|---|---|---|---|---|---|---|---|
| 0x01 | 0x10 | 0x11 0x00 | 0x00 0x02 | 0x04 | 0x00 0x04 0x03 0x96 | 0xF2 | 0xA0 |
Response Frame:
| Address Code | Function Code | Register Address | Register Length | Checksum Low Byte | Checksum High Byte |
|---|---|---|---|---|---|
| 0x01 | 0x10 | 0x11 0x00 | 0x00 0x02 | 0x44 | 0xF4 |
3.5 Change the current address to 0x02
Query Frame:
| Address Code | Function Code | Registry Address | Registry Content | Checksum Low Byte | Checksum High Byte |
|---|---|---|---|---|---|
| 0x01 | 0x06 | 0x07 0xD0 | 0x00 0x02 | 0x08 | 0x86 |
Response Frame:
| Address Code | Function Code | Registry Address | Registry Content | Checksum Low Byte | Checksum High Byte |
|---|---|---|---|---|---|
| 0x01 | 0x06 | 0x07 0xD0 | 0x00 0x02 | 0x08 | 0x86 |
3.6 Modify the current baud rate to 9600
Query Frame:
| Address Code | Function Code | Registry Address | Registry Content | Checksum Low Byte | Checksum High Byte |
|---|---|---|---|---|---|
| 0x01 | 0x06 | 0x07 0xD1 | 0x00 0x02 | 0x59 | 0x46 |
Response Frame:
| Address Code | Function Code | Registry Address | Registry Content | Checksum Low Byte | Checksum High Byte |
|---|---|---|---|---|---|
| 0x01 | 0x06 | 0x07 0xD1 | 0x00 0x02 | 0x59 | 0x46 |
Was this article helpful?
