The firmware implements a simple MODBUS RTU master mode. You can read holding and input registers and write to holding registers. The example below reads two values from one device from different memory addresses.
Note: If your MODBUS device uses the RS485 or RS232 interface, you need the corresponding converter from UART (TTL) to RS232 or UART (TTL) to RS485. UART uses P02 and P03 pins (3.3V). Therefore you should use the P02 pin in the configuration.
The MODBUS sensor mode supports several common data types with the “Little-Endian” and “Big-endian” byte order (wiki).
- UART – UART communication parameters. The list contains all possible supported combinations of a baud rate, a number of data bits, parity, stop bits.
- Device address (decimal) – it is the MODBUS address of a connected MODBUS device.
- Function – you can select the MODBUS function number for input and holding registers.
- Memory offset (decimal) – it is a zero-based memory offset in your MODBUS device. If your address looks like 40001, it may mean the holding register with the memory offset 0. Or 30002 – the input register with offset 1.
- Data type – it is a data type of a value in MODBUS memory. Some data types occupy two MODBUS registers. The firmware converts all received values to a single-precision float number (32 bit).
- The number of values – this number defines how much data the firmware reads from MODBUS memory. The firmware automatically calculates the necessary number of registers uses this number and the data type. If you configured the reading of multiple values, the firmware outputs all data to one endpoint (channel) but adds a value index to a description.
Writing MODBUS data
The firmware accepts the “write” command from a coordinator on a configured output and can write a single value back to a MODBUS device.
The firmware automatically converts a source value to a target data type and uses the “Write single register” (0x06) or “Write multiple registers” (0x10) MODBUS commands.
write – writes a values to a MODBUS device.
Channel: l1, l2, l3 … l8
Payload: any valid float value.