STM32 porting FreeModbus RTU tutorial 3 (actual verification after FreeModbus porting)

Download the project to the development board and connect to the PC through the USB to 485 communication line

After opening the project and compiling, connect the development board through the stlink or Jlink burner and burn the program.
insert image description here
insert image description here
PC connects and communicates with the development board

insert image description here

Communication verification through modbus debugging assistant

insert image description here
Find the COM port corresponding to the USB to 485 communication line and open the serial port for communication verification

03H 04H 06H 10H function code verification

  1. Verification of 03H function code
    insert image description here
    Open the demo.c file in the project, we can see the number of holding registers we initially defined and the initial storage value. Next we read the communication.
    Read the data in the first two registers:
    insert image description here
    the slave address defined in our project is 0x01, and the returned data corresponds to the data in the data.
    Our register data index in the project = number of registers - start address. The index corresponding to the No. 1 register is 0
    ** Send and read registers exceeding the defined 8, then return an error message with the corresponding error code
    insert image description here
  2. Verification of the 04H function code
    insert image description here
    The definition of the input register is as follows to read the data of the 3 registers,
    insert image description here
    and the return data is as defined.
  3. 06H Verification of writing a single holding register function code
    1 Send 0x06 function code to write the first register data, rewrite 0x0000 to 0x120F
    2 Send 0x03 function code to read the rewritten value of the first register
    insert image description here
    Pass the return data, explain the function of 06 single register The code was written successfully.
  4. 10H Verification of writing multiple holding register function codes
    1 Send 0x10 function code to write the first two register data, rewrite 0x0000 to 0x120F, rewrite 0x5678 to 0x1345
    2 Send 0x03 function code to read the rewritten values ​​of the first two registers
    insert image description here
    according to the return Data verification 10H function rewriting is successful.
    So far, the commonly used function codes of 03H 04H 06H 10H have passed the actual verification, and the communication is normal.
    Attached below is
    the link of the debugging assistant connection and the completed project that has been debugged: Modbus debugging assistant .
    Link: debugged verification project .

Guess you like

Origin blog.csdn.net/weixin_42634914/article/details/106469395