31
8. Modbus protocol
8. 9. Read/Write Multiple Registers (23 = 16#17)
Request:
Response:
Example: This example combines the two examples for functions 3 and 16. With function 23, the line is less busy than with these two
functions. However, the number of words that can be read and written is restricted.
• Write the values 20 (16#14) and 30 (16#1E) respectively to the 2 logic address words 9001 and 9002 on slave 2.
• Read the 4 logic address words 3102 to 3105 on the same slave (values read = 16#0028, 16#0258, 16#01F4, and 16#0000).
Request:
Response:
Slave no. 17 No. of 1
st
word to be
read
Number of words to be
read
No. of 1
st
word to be
written
Number of words to be
written
---
Hi Lo Hi Lo Hi Lo Hi Lo ---
1byte 1byte 2bytes 2bytes 2bytes 2bytes
--- Number of bytes to be
written
Value of 1
st
word to be
written
Value of last word to be written CRC16
--- Hi Lo ----------------------------- Hi Lo Lo Hi
1 byte 2 bytes 2 bytes 2 bytes
Slave no. 17 Number of bytes
read
Value of 1
st
word read Value of last word read CRC16
Hi Lo -------------- Hi Lo Lo Hi
1 byte 1 byte 1 byte 2 bytes 2 bytes 2 bytes
Slave no. Request code No. of 1
st
word to be
read
No. of words to be
read
No. of 1
st
word to be
written
No. of words to be
written
---
Hi Lo Hi Lo Hi Lo Hi Lo ---
02 17 0C 1E 00 04 23 29 00 02 ---
--- No. of bytes to be written Value of 1
st
word to be written Value of 2
nd
word to be written CRC CRC
--- HiLoHiLoLoHi
--- 04 00 14 00 1E D2 F5
Slave no. Response code No. of bytes
read
Value of 1
st
word read
Value of 2
nd
word read
Value of 3
rd
word read
Value of 4
th
word read
CRC CRC
Hi Lo Hi Lo Hi Lo Hi Lo Lo Hi
02 17 08 00 28 02 58 01 F4 00 00 12 F0