modbus_rtu_server#
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 Server Example Start!
Use the modbus client simulator to read holding registers(0x3) to test modbus function
Supported Boards#
MIMXRT1180-EVK
Hardware requirements
Mini/micro USB cable
MIMXRT1180-EVK board
USB to TTL tool
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 USB to TTL tool to the pins of the board
J44-20(RX)----USB to TTL tool(TX) J44-18(TX)----USB to TTL tool(RX) J44-17(GND)---USB to TTL tool(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.
IMX943-EVK
Hardware requirements
Mini/micro USB cable
IMX943-EVK board
USB to TTL tool
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 USB to TTL tool to the pins of the board
J48-2(RX)----USB to TTL tool(TX) J48-4(TX)----USB to TTL tool(RX) J47-14(GND)---USB to TTL tool(GND)
Open a serial terminal with the following settings:
115200 baud rate
8 data bits
No parity
One stop bit
No flow control
Download the program to the target 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.