Reference

The article provides an in-depth explanation of communication protocols for CO2 sensors, emphasizing RS485 and Modbus-RTU, detailing data frames, error checking with CRC, and sensor calibration methods.

Communication Protocol Description

1. Basic communication parameters

Interface Encoding Data bit Parity bit Stop bit Error check Baud rate
RS485 8-bit binary 8 None 1 CRC 2400bit/s, 4800bit/s, 9600 bit/s,19200bit/s,38400bit/s, 115200bit/s can be set, default is 9600bit/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 and writes the register function code 0x06

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.

Host inquiry frame structure:

Address code Function code Register start address Register length Check code low bit Check code high bit
1byte 1byte 2byte 2byte 1byte 1byte

Slave response frame structure:

Address code Function code Number of valid bytes Data area 1 Data area 2 Nth data area Check code
1byte 1byte 1byte 2byte 2byte 2byte 2byte

Register address

Register address PLC or configuration address Content Supported function code Definition description
0000H 40001 CO2 value 0x03 Actual value
006BH CO2 correction value 0x03/0x06 The modifiable range is ±1000, that is, the value range is 0-1000 or 64535-65535
0066H 40103 Device address 0x03/0x06 1~249 (factory default 1)
0067H 40104 Device baud rate 0x03/0x06 1 represents 2400, 2 represents 4800, 3 represents 9600, 4 represents 19200, 5 represents 38400, 6 represents 115200

3. Communication protocol example and explanation

3.1. Read carbon dioxide value

Inquiry frame: Read value function code 0x03

Address code Function code Register start address Register length Check code low bit Check code high bit
0x01 0x03 0x00 0x00 0x00 0x01 0x84 0x0A

Response frame:

Address code Function code Return valid bytes Carbon dioxide value Check code low bit Check code high bit
0x01 0x03 0x02 0x02 0xFC 0xB9 0x65

CO2 value:

02FC (hexadecimal) = 764=> CO2 value = 764ppm

3.2, Read the current CO2 correction value (factory default is 0)

Inquiry frame:

Address code Function code Register start address Register length Check code low position Check code high position
0x01 0x03 0x00 0x6B 0x00 0x01 0xF5 0xD6

Response frame:

Address code Function code Return valid bytes Correction value Check code low position Check code high position
0x01 0x03 0x02 0x00 0x64 0xB9 0xAF

Calibration value:

0064 (hexadecimal) = 100=> Calibration value = 100ppm

3.3. Modify the CO2 calibration value

When the data is different from the reference standard, we can reduce the display error by adjusting the "calibration value". The calibration difference can be modified in the range of ±1000, that is, the value range is 0-1000 or 64535-65535. For example, when the displayed value is 100 less, we can correct it by adding 100. In the command, 100 is hexadecimal 0x64; if you need to reduce it, you can set a negative value, such as -100, which is calculated as FFFF-64+1=FF9C, which is hexadecimal 0xFF 9C

Inquiry frame:

Address code Function code Register start address Modify value Check code low position Check code high position
0x01 0x06 0x00 0x6B 0x00 0x64 0xF9 0xFD

Response frame:

Address code Function code Register address Correction value Check code low position Check code high position
0x01 0x06 0x00 0x6B 0x00 0x64 0xF9 0xFD

Correction value:

0064 (hexadecimal) = 100=> correction value = 100ppm

3.4, Modify the current address

Inquiry frame: (modify the current address to 0x02)

Address code Function code Register address Modify value Check code low bit Check code high bit
0x01 0x06 0x00 0x66 0x00 0x02 0xE8 0x14

Response frame:

Address code Function code Register address Modify value Check code low bit Check code high bit
0x02 0x06 0x00 0x66 0x00 0x02 0xE8 0x27

3.5, Modify current baud rate

Inquiry frame: (Modify current baud rate to 38400)

Address code Function code Register address Modify value Check code low bit Check code high bit
0x01 0x06 0x00 0x67 0x00 0x05 0xF8 0x16

Response frame:

Address code Function code Register address Modify value Check code low bit Check code high bit
0x01 0x06 0x00 0x67 0x00 0x05 0xF8 0x16

3.6, Query current address, baud rate

Inquiry frame:

Address code Function code Register address Data length Check code low bit Check code high bit
0xFA 0x03 0x00 0x66 0x00 0x02 0x31 0x9F

Response frame:

Address code Function code Return valid bytes Address Baud rate Check code low bit Check code high bit
0x01 0x03 0x04 0x00 0x01 0x00 0x03 0xEB 0xF2

The real address of the device read is 01, and the baud rate is 0x03, which is 9600.

Principle

This infrared carbon dioxide sensor uses the principle of non-dispersive infrared (NDIR technology) to detect CO2 in the air.

Was this article helpful?

TOP