modbus_rtu_client#
Overview#
This example demonstrates how to use Modbus RTU protocol to communication.
FreeModbus supports bellow feature:
Read coil(0x01)
Read discrete inputs(0x02)
Read holding registers(0x03)
Read input registers(0x04)
Write single coil(0x05)
Write single holding register(0x06)
Write board LED status(0x0d)
Read board LED status(0x0e)
Write multiple coils(0x0f)
Write multiple holding registers(0x10)
Running the demo#
If the test passes, serial port output:
Modbus RTU Client Example Start!
Use the MIMXRT1180-EVK board as modbus Server simulator, write board LED status(0x0d) to control LED(D6, D7) light
Supported Boards#
MIMXRT1180-EVK
Hardware requirements
Mini/micro USB cable
MIMXRT1180-EVK board
Personal Computer
Board settings
No special settings are required.
Prepare the Demo
Connect a USB cable between the host PC and the OpenSDA USB port on the target board.
Use Dupont wire to connect the pin of the two MIMXRT1180-EVK boards
J44-18(TX)----J44-20(RX) J44-20(RX)----J44-18(TX) J44-17(GND)---J44-17(GND)
Open a serial terminal with the following settings:
115200 baud rate
8 data bits
No parity
One stop bit
No flow control
Write the program to the flash of the target board.
Press the reset button on your board to start the demo. Note: The serial terminal of both boards must be opened.
IMX943-EVK
Hardware requirements
Mini/micro USB cable
IMX943-EVK board
MIMXRT1180-EVK board
Personal Computer
Board settings
No special settings are required.
Prepare the Demo
Connect a USB cable between the host PC and the OpenSDA USB port on the target board.
Connect IMX943-EVK board and MIMXRT1180-EVK board with Dupont wire
IMX943-EVK J48-2(RX)----J44-18(TX) MIMXRT1180-EVK IMX943-EVK J48-4(TX)----J44-20(RX) MIMXRT1180-EVK IMX943-EVK J47-14(GND)---J44-17(GND) MIMXRT1180-EVK
Open a serial terminal with the following settings:
115200 baud rate
8 data bits
No parity
One stop bit
No flow control
Download the modbus_rtu_client program to IMX943-EVK board.
Download the modbus_rtu_server program to MIMXRT1180-EVK board.
Either re-power up your board or launch the debugger in your IDE to begin running the example.
Note: MODBUS_RTU uses LPUART11, which is cm7_core0 core default serial port, please make sure that there is no output on the serial port of cm7_0 image to avoid affecting the modbus function.