User Guide

User Guide
©2008-2020 Seeed Technology Co., Ltd. All rights reserved. solution.seeedstudio.com
11 / 21
4.4 Example
In the following instructions, data beginning with 0x or ending with H is hexadecimal. The Modbus protocol
has two common register types:
(1) keep the register, the storage data is not lost power, is readable and writable. Normally read with
function number 3 (0x03) and write with function number 6 (0x06) or 16 (0x10).
(2) input register, used to store some read-only physical quantities, such as temperature value, is read-
only. Normally read with function number 4 (0x04).
4.4.1 Example of Function Code 3
Request command: AA 03 RRRR NNNN CCCC
AA
03
RRRR
NNNN
CCCC
1 Byte
1 Byte
2 Bytes
2 Bytes
2 Bytes
Slave address,
range 0-247
Function Code is 3
Start register
address, high byte
first
The number of
registers to read,
high byte first
CRC check
Response: AA 03 MM VV0 VV1 VV2 VV3… CCCC
AA
03
MM
VV0
VV2
CCCC
1 Byte
1 Byte
1 Bytes
2 Bytes
2 Bytes
2 Bytes
Slave address,
range 0-247
Function
Code is 3
Returns the
number of
data bytes of
the register
value
The first
register value
returned
The second
register
value
returned
The N
register
value
returned
(N=MM/2)
CRC check
For example: Read registers 0x0000 ~ 0x0007 to read the measured values of air temperature and
humidity, barometric pressure and light intensity.
Request: 01 03 0000 0008 440C
01
03
0000
0008
440C
1 Byte
1 Byte
2 Bytes
2 Bytes
2 Bytes
Slave address 0x01
Function Code is 3
Start register
address: 0x00
Read 8 registers
CRC check
Response: 01 03 10 0AE7 1CF1 0001 882F 0000 5FA0 0004 0A0A 8B07
01
03
10
0AE7
1CF1
0001
882F
0000
5FA0
0004
0A0A
8B07
1 Byte
1 Byte
1 Bytes
2 Bytes
2 Bytes
2 Bytes
2 Bytes
2 Bytes
2 Bytes
2 Bytes
2 Bytes
2 Bytes