How to write multiple registers in Modbus RTU? Little White Tutorial

freeFree Technical Resource

This content is free to read, suitable for basic learning and search traffic.

How to write multiple registers in Modbus RTU? Little White Tutorial缩略图

Detailed explanation of writing multiple registers in Modbus RTU

How to write multiple registers in Modbus RTU? Little White Tutorial插图

1. Protocol Overview

Modbus RTU is a serial communication protocol used for inter device communication in industrial automation. The main characteristics are simplicity and stability. In this mode, data is transmitted in binary form.

2. Write multiple registers

When we need to modify multiple parameters on a device (such as a motor driver or sensor), we can use the "write multiple registers" function.

3. Request format

A standard Modbus RTU request to write multiple registers includes the following parts:

  • Device address1 byte, identifying the target device to be communicated with.
  • function code1 byte, write the function code for multiple registers as0x10
  • Starting register address: 2 bytes, specifying the address of the first register to be written.
  • number of registers: 2 bytes, specifying the total number of registers to be written.
  • Byte count1 byte represents the total number of bytes of data to be written in the future.
  • dataAccording to the number of registers that need to be written, each register is 2 bytes.
  • CRC check2 bytes, used to verify the integrity of the message.

4. Examples

Assuming we need to address0x01Write to the device from the register address0x3000Start with four consecutive registers. The data we need to write is:0x1234, 0x5678, 0x9ABC, 0xDEF0

The constructed message is:

01       (设备地址)
10       (功能码)
30 00    (起始寄存器地址)
00 04    (寄存器数量)
08       (字节计数,4寄存器*2字节/寄存器)
12 34 56 78 9A BC DE F0 (数据)
?? ??    (CRC校验, 实际值需要使用crc16-modbus来计算)

Please note that the CRC check value is calculated based on the entire message (excluding the CRC). You need to use the CRC algorithm of Modbus RTU to obtain this value and add it to the end of the message.

5. Send and wait

After completing the message, send it through an appropriate serial communication interface (such as RS-485) and wait for a response from the slave device. The response format is similar to the request, but does not include byte counting and data parts.

Put this resource to use in a real project?

Go to the Tool Center for message parsing, CRC verification and device debugging, or submit your requirements for selection and integration advice.

Engineer Membership

Turn this article into actionable debugging resources

After activation, you can use advanced message parsing, resource pack downloads, code examples, engineering cases and priority technical support, suitable for real project delivery.

Unlimited Advanced Tools
Resource & Code Packs
Complete Engineering Case Library
Priority Technical Support

《 “How to write multiple registers in Modbus RTU? Little White Tutorial” 》 有 2 条Comments

Leave a Reply

Your email address will not be published. Required fields are marked *.