RS485 Modbus RTU Interface
RS485 Modbus RTU Interface for GasLab TX/MX Boards
© 2019 GasLab, Inc. All Rights Reserved. Revision E
The information in this document is protected under applicable federal law as an unpublished work and is confidential and proprietary to GasLab Inc. Its use, disclosure, reproduction, or publication, in whole or in part, without the express prior written consent of GasLab, Inc. is prohibited.
Document History
Date |
Revision |
Description |
16 November 2018 |
A |
Initial Draft |
30 November 2018 |
A |
Updated Draft |
13 February 2019 |
B |
Firmware version 4.0 Beta. |
19 February 2019 |
C |
Detail HR and IR registers. |
10 June 2019 |
D |
MX3/TX3 REV 4.4 Addition of model number reported to IR 30009. Clarification of dual use register TX, MX, location of Temp/ RH/ Barro sensors and allocation for second probe sensor for tube cap |
19 June 2019 |
E |
MX3/TX3 S/W REV. 4.4 . Documentation of addition of limiter for 4-20mA output. HR23 20mA level is limit of ADC value to drive 20mA signal. |
Table of Contents
- Introduction
- About this Manual
- Chapter 1: Overview
- Scope
- References
- Chapter 2: Communications Interface
- General
- Physical Layer
- Framing
- Device Address
- Registers
- Chapter 3: Functions
- Function3 (0x04) Read Input Registers
- Function 4 (0x03) Read Holding Registers
- Function 6 (0x06) Write Single Hold Register
- Function16 (0x10) Write Multiple hold Registers
- Chapter 4: Device Commands
- Device Command 1 (0x0001) Error Reset
- Device Command 2 (0x0002) Factory Use
- Device Command 16 (0x0010) Save Holding Registers to Flash
- Device Command 17 (0x0011) Restore Factory Presets
- Device Command 32 (0x0020) Zero Calibration
- Device Command 33 (0x0021) Calibrate to Span
- Device Command 34 (0x0022) Calibrate to 400 PPM CO2
- Device Command 40 (0x0028) Suspend internal streaming GSS sensors only
- Device Command 41 (0x0029) resume internal streaming GSS sensors only
- Device Command 9985 (0x2701) Factory Use
- Chapter 5: Registers
- Input Registers
- Holding Registers
- Status Register (IR 30001) Bit Assignments
- Factory preset sensor parameters table
Introduction
About this Manual
This document describes the implementation of the RS485 Modbus RTU protocol on GasLab.com sensors and controllers equipped with an RS485 Modbus RTU Interface. It provides the information necessary to communicate with the sensor using this protocol. Please visit our website www.GasLab.com for information on specific products.
Chapter 1 : Overview
This document is intended to serve as a technical reference for the RS485 Modbus Protocol as implemented on GasLab.com controllers including the TX and MX4 Sensor Controllers. It is intended to be used in conjunction with the Modbus reference listed below.
Scope
This document describes the general implementation for all GasLab.com devices. The Modbus register assignments for the MX4 Sensor are described herein. Register assignments for other devices are provided in the documentation for the specific device.
References
The following documents are referenced:
Chapter 2 : Communications Interface
General
GasLab.com devices implement the RTU variant of the Modbus protocol. Modbus RTU is a packet-oriented protocol where a master device can communicate with multiple slave devices over a multi-drop line.
Physical Layer
The physical layer is a two-wire differential interface that conforms to EIA Standard RS485. This interface can operate at high speed over a single twisted pair. A common ground reference is required at each device. For cable lengths greater than about 6 feet, terminating resistors may be required at both ends of the cable.
The implementation defaults to 9600 baud, No Parity and 1 Stop Bit and is always 8 bits. The parity and stop bits can be changed in the configuration. When initially powered up, the controller will always listen with the default configuration, i.e. 9600 baud, No Parity, and 1 Stop Bit for 5 seconds. If a valid Modbus PDU is received, the controller will remain in the default configuration. If no PDU is received, the controller will switch to the programmed configuration. This is intended to ensure that the device can always be reconfigured when necessary.
Framing
Modbus RTU frames are bounded by marking intervals during which no characters are send. A frame begins with a transmitted character and ends 2.5-character times following the last transmitted character. At the end of the frame, a two-byte CRC value is checked and if not valid the frame is silently discarded. Note that there is never a response from the sensor unless a message with a valid CRC and Valid Address is received.
Device Address
Modbus uses a single byte to address slave devices. Address 0 is the broadcast address which permits a command to be set to all devices (to which no devices response).
Addresses 1 to 247 may be assigned to unique devices.
Address 254 is recognized as an any device address. This is an illegal address in the Modbus protocol and should never be used in an operational network. This device address is intended solely for configuration and test purposes where there is only a single device connected to the Modbus master.
Address 248 to 253, and 255 are always ignored.
CO2 Meter devices normally default to address 21 (0x15).
Registers
The Modbus RTU specifications define several types of registers including single bit registers (‘coils’ and ‘discrete inputs’) and 16-bit registers (‘Input Registers’ and ‘Holding Registers’).
All of these are numbered with a 16-bit value. Coils are number 01– 9999, Discrete Inputs are numbered 10001-19999, Input Registers are numbered from 30001 – 39999, and Holding Registers are numbered 40001 – 49999.
It is important to note the reference register numbers translate to ‘addresses’ in the Modbus message packets. These addresses are zero based. Register numbers 1 – 9999 translate to address 0 to 9998. Similarly, register numbers 30001 – 39999 translate to addresses 0 to 9998. The leading digit of the 5 digits in the register number is never used in the address and is implicit in the function code. For example, the read of an Input register always implies registers numbered 3XXXX.
Coils and Discrete inputs are not implemented.
Chapter 3: Functions
Modbus Functions are used to read and write registers. The following functions are implemented.
Function3 (0x04) Read Input Registers
Function 4 (0x03) Read Holding Registers
Function 6 (0x06) Write Single Hold Register
Function16 (0x10) Write Multiple hold Registers
Chapter 4: Device Commands
Holding Register 40032 (Address 0x1f) is used to initiate commands to the device for performing such functions as calibration and writing Holding Registers to FLASH. Holding Register 40031 (Address 0x1e) contains a parameter for those commands that require one.
Modbus function code 16 (0x10), Write Multiple Holding Registers, allows the parameter and command to be sent in a single PDU.
A command can only be sent to the device when it is not Busy. The Busy indication is provided as the most significant bit in the Status Register (Input Register 30001 at address 0).
If a command is not valid for a device, one of the Command Error bits will be set in the Status Register. Error bits are valid after the status returns to not busy.
Note that some commands will execute immediately. In this case, by the time the host requests status the status will return non-busy the current error status. The error status is always valid for the last command when the device status indicates not busy.
Device Command 1 (0x0001) Error Reset
This command resets all error bits in the status word. Note that certain hardware errors may cause bits to be set again.
Device Command 2 (0x0002) Factory Use
This command is reserved for factory use.
Device Command 16 (0x0010) Save Holding Registers to Flash
This command saves the holding registers to Flash.
Device Command 17 (0x0011) Restore Factory Presets
This command will restore the factory presets to the holding registers. There are 7 groups of presets numbered 0 to 6. The command parameter indicates which group should be restored. Note that the retrieved values are not automatically saved to flash. To save the registers to flash, a separate Device Command 16 is required.
Device Command 32 (0x0020) Zero Calibration
This command set the zero value for the sensor. The sensor should be shown 100% nitrogen for approximately 1 minute prior to issuing this command.
Device Command 33 (0x0021) Calibrate to Span
This command calibrates the sensor based on the known concentration provided as the command parameter. This should be expressed in 10’s of ppm. For example, for 20.9% the value should be 20900. Hold register are automatically saved upon execution.
Device Command 34 (0x0022) Calibrate to 400 PPM CO2
Calibrate CO2 sensor to 400 PPM GSS “G” Command.
Device Command 40 (0x0028) Suspend internal streaming GSS sensors only
Suspend streaming prior to calibrate CO2 sensor
Device Command 41 (0x0029) resume internal streaming GSS sensors only
Resume or start streaming operation after calibration.
Device Command 9985 (0x2701) Factory Use
This command is reserved for factory use.
Chapter 5: Registers
Input Registers
There are 32 16-bit input registers. These registers are maintained by the controller during operation and can be read at any time. The “int” type is a signed quantity. The “uint” type is unsigned. The float type is an IEEE764 formatted number. The lower numbered register contains the 16 bit word with the exponent and upper bits of the significant. The higher numbered register contains the remaining bits of the significant.
The status bits are described separately in a following section.
Table 2‑1 Input Registers (Read Only)
Reg |
Addr |
Type |
Description |
IR30001 |
0 |
int |
Busy/Error Status (see below) |
IR30002 |
1 |
int |
Reserved |
IR30003 |
2 |
int |
O2 Concentration in 10’s of ppm CO2 filter concentration. |
IR30004 |
3 |
int |
O2 Partial Pressure in millibars. CO2 Raw unfiltered unscaled |
IR30005 |
4 |
int |
O2 sensor Temperature in 10ths degree C. CO2 Sensor Temperature 10ths degree C |
IR30006 |
5 |
int |
O2 sensor Pressure in millibars. CO2 Unsigned RH in percentage |
IR30007 |
6 |
uint |
Error Status received from Sensor |
IR30008 |
7 |
uint |
Manufacturer ID Code35462 = CO2 meter |
IR30009 |
8 |
uint |
Model Number 1=TX 2=MX2 3=MX3 4=EC3 |
IR30010 |
9 |
uint |
Software Build High-revision Low-build |
IR30011 |
10 |
uint |
Controller Serial Number |
IR30012 |
11 |
uint |
TX Received PDU Count |
IR30013 |
12 |
uint |
TX Received PDU Errors |
IR30014 |
13 |
uint |
TX Transmit PDU Count |
IR30015 |
14 |
uint |
TX Count of Received Measurements from Sensor |
IR30016 |
15 |
int |
O2% Raw as received from Sensor. CO2 NA |
IR30017 |
16 |
float |
O2 % Floating Point. CO2% Filtered |
IR30018 |
17 |
||
IR30019 |
18 |
float |
O2 Floating Point Partial Pressure. CO2 unfiltered |
IR30020 |
19 |
||
IR30021 |
20 |
float |
O2 Floating Point Temperature. CO2 Temperature |
IR30022 |
21 |
||
IR30023 |
22 |
float |
O2 Floating Point Pressure. CO2 Relative humidity% |
IR30024 |
23 |
||
IR30025 |
24 |
uint |
BME1 Temp, onboard |
IR30026 |
25 |
uint |
BME1 RH |
IR30027 |
26 |
uint |
BME1 Barro |
IR30028 |
27 |
uint |
BME2 Temp , Tube cap |
IR30029 |
28 |
uint |
BME2 RH, tube cap |
IR30030 |
29 |
uint |
BME2 Barro, Tube Cap |
IR30031 |
30 |
uint |
Reserved |
IR30032 |
31 |
uint |
TX Current DAC value to current loop (0 – 4095) |
Holding Registers
There are 32 Holding Registers. The Holding Registers are read/write. They are initially loaded from non-volatile memory at power up. They may then be altered by the host.
Table 2‑2 Holding Registers (Read/Write)
Reg |
Addr |
Default |
Description |
HR40001 |
0 |
N/A |
Checksum Value for FLASH Storage |
HR40002 |
1 |
0 |
EC Output Mode Mask |
HR40003 |
2 |
0 |
EC log mask Reserved |
HR40004 |
3 |
0 |
EC Analog configuration Reserved |
HR40005 |
4 |
5 |
MX EC “!” protocol Address default 5 Reserved |
HR40006 |
5 |
0 |
EC log interval, MX stream interval 0=no log, No stream |
HR40007 |
6 |
1 |
Gas Type 1=CO2 2=O2 |
HR40008 |
7 |
0 |
Zero Value, reported in zero calibration |
HR40009 |
8 |
0 |
TX O2 K Value of calibration CONFIRM |
HR40010 |
9 |
0 |
EX/ MX Calibration Concentration, Confirm written on calibration X |
HR40011 |
10 |
0 |
EC / MX Full scale PWM Range |
HR40012 |
11 |
0 |
EC 0-3V/ MX 0-3V/ TX 4-20 mA Full Scale Analog 25000 25% O2, 10000 100% CO2 confirm use |
HR40013 |
12 |
10 |
Multiplier to get to PPM |
HR40014 |
13 |
0 |
EC Feature Configuration- Reserved |
HR40015 |
14 |
5865 |
MX PWM time base =1 second |
HR40016 |
15 |
21 |
MX/TX Modbus Address 1-247. 254 set and discovery |
HR40017 |
16 |
0 |
Comm Configuration (Stop bits and Parity) |
HR40018 |
17 |
8 |
Baud Rate (Multiple of 1200) |
HR40019 |
18 |
0 |
Reserved |
HR40020 |
19 |
0 |
TX only Loop Test (when non-zero) 4-20 mA |
HR40021 |
20 |
0 |
TX only Current Loop Scale Factor |
HR40022 |
21 |
550 |
TX only Current Loop 4ma Level |
HR40023 |
22 |
4720 |
TX only Current Loop 20ma Level and Limiter |
HR40024 |
23 |
0 |
Reserved |
HR40025 |
24 |
0 |
Reserved |
HR40026 |
25 |
0 |
Reserved |
HR40027 |
26 |
0 |
Reserved |
HR40028 |
27 |
0 |
Reserved |
HR40029 |
28 |
0 |
Reserved |
HR40030 |
29 |
0 |
Reserved |
HR40031 |
30 |
0 |
MX/TX MODBUS Command Parameter |
HR40032 |
31 |
0 |
MX/TX MODBUS Command |
Status Register (IR 30001) Bit Assignments
The Status Register indicates the current error status of the device. A 1 bit in the bit position indicates the presence of the error or condition. The bit assignments are as follows:
Bit 15 (MSB) Busy.
Bits 4-14 Reserved.
Bit 3 Command Failure.
Bit 2 Flash Error.
Bit 1 Invalid Command.
Bit 0 (LSB) Power Fail. (Set at Power Up)
All bits can be cleared by executing the “Error Reset” device command
Factory preset sensor parameters table
Sensor: |
Label |
1=CO2, 2=O2 |
Zero |
K factor |
Cal Val |
Range |
4-20 |
scaler |
Type 0: |
Luminox 25% |
2 |
0 |
32768 |
20900 |
25000 |
25000 |
10 |
Type 1: |
Luminox 50% |
2 |
0 |
32768 |
20900 |
50000 |
50000 |
10 |
Type 2: |
GSS 1-2% |
1 |
0 |
32768 |
10000 |
10000 |
1000 |
1 |
Type 3: |
GSS 5% |
1 |
0 |
32768 |
5000 |
5000 |
5000 |
10 |
Type 4: |
GSS 20% |
1 |
0 |
32768 |
10000 |
20000 |
20000 |
10 |
Type 5: |
GSS 60% |
1 |
0 |
32768 |
10000 |
60000 |
60000 |
10 |
Type 6: |
GSS 100% |
1 |
0 |
32768 |
10000 |
10000 |
10000 |
100 |