0 x03:read holding registers
0 x04:read input registers
0 x06:write a single holding register
0 x10:write multiple hold registers
the host sends a data frame:
the slave address |
function Code |
register Address the high byte |
register Address the low byte |
number of registers the high byte |
number of registers the low byte |
CRC the high byte |
CRC the low byte |
|
|
|
|
|
|
|
|
slave response data frame:
the slave address |
in response to the function code |
the number of bytes |
register1data the high byte |
register1data the low byte |
registerNdata the high byte |
registerNdata the low byte |
CRC the high byte |
CRC the low byte |
|
|
|
|
|
|
|
|
|
MODBUSthe command frame
the slave address |
function Code |
register Address the high byte |
register Address the low byte |
number of registers the high byte |
number of registers the low byte |
CRC the high byte |
CRC the low byte |
0x01 |
0x04 |
0x00 |
0x01 |
0x00 |
0x01 |
0x60 |
0x0a |
slave response data frame:
the slave address |
function Code |
the number of bytes |
temperature the high byte |
temperature the low byte |
CRC the high byte |
CRC the low byte |
0x01 |
0x04 |
0x02 |
0x01 |
0x31 |
0x79 |
0x74 |
the temperature value= 0 x131,to decimal conversion305actual temperature value= 305 / 10=30.5℃
note: temperature is marked16decimal number, temperature value= 0 xFF33,to decimal conversion-205the actual temperature= -20.5℃;
host reads humidity command frames(0 x04):
the slave address |
function Code |
register Address the high byte |
register Address the low byte |
number of registers the high byte |
number of registers the low byte |
CRC the high byte |
CRC the low byte |
0x01 |
0x04 |
0x00 |
0x02 |
0x00 |
0x01 |
0xC1 |
0xCA |
slave response data frame:
the slave address |
function Code |
the number of bytes |
humidity the high byte |
humidity the low byte |
CRC the high byte |
CRC the low byte |
0x01 |
0x04 |
0x02 |
0x02 |
0x22 |
0xD1 |
0xBA |
humidity value= 0 x222,to decimal conversion546actual humidity value= 546 / 10 = 54.6%;
continuously read temperature and humidity command frames(0 x04):
the slave address |
function Code |
register Address the high byte |
register Address the low byte |
number of registers the high byte |
number of registers the low byte |
CRC the high byte |
CRC the low byte |
0x01 |
0x04 |
0x00 |
0x01 |
0x00 |
0x02 |
0x20 |
0x0B |
slave response data frame:
the slave address |
function Code |
the number of bytes |
temperature the high byte |
temperature the low byte |
humidity the high byte |
humidity the low byte |
CRC the high byte |
CRC the low byte |
0x01 |
0x04 |
0x04 |
0x01 |
0x31 |
0x02 |
0x22 |
0x2A |
0xCE |
read the content of the maintenance register(0 x03):
take reading the slave address as an example:
the slave address |
function Code |
register Address the high byte |
register Address the low byte |
number of registers the high byte |
number of registers the low byte |
CRC the high byte |
CRC the low byte |
0x01 |
0x03 |
0x01 |
0x01 |
0x00 |
0x01 |
0xD4 |
0x0F |
PARAMinstructions:
TC:0.0,HC:0.0,BR:9600,HZ:1->temperature correction0.0humidity correction value0.0the baud rate9600report rate1Hz
SLAVE_ADD:1->MODBUSthe slave address0x01