S7-1500 MODBUS Communication
MODBUS MASTER:
-
First configure the hardware, as shown below:
Then open OB1, and program, as shown below:
First call the initialized block MODBUS COMMONLOAD
Pin description:
REQ: The command starts on the rising edge (0 to 1).
PORT: After installing and configuring the CM, you can find the CM port value in the device configuration’s “Hardware ID” attribute. The symbolic port name is specified in the PLC variable table’s “System constants” tab, which is the hardware identifier mentioned earlier.
BAUD: Select the data transmission rate:
1 = 300, 2 = 600, 3= 1200, 4 = 2400, 5 = 4800, 6 = 9600, 7 = 19200, 8 = 38400, 9 = 57600, 10 =76800, 11 = 115200 bit/s. All other values are invalid.
PARITY: Select parity:
· 0 – None
· 1 – Odd
· 2 – Even
RESP_TO: Response timeout:
5 ms to 65535 ms – Modbus_Master waits for the slave’s response for this duration (in milliseconds). If the slave does not respond within this time, Modbus_Master will repeat the request, or cancel the request after a specified number of retries and prompt an error (see the RETRIES parameter below).
MB_DB: Part of the background data block of MODBUS MASTER, as shown below:
Reference to the background data block of the Modbus_Master or Modbus_Slave command. The MB_DB parameter must be replaced with the MB_DB parameter of the Modbus_Master or Modbus_Slave command (static, so it is not visible in the command).
Then call the function block of MODBUS MASTER, as shown below:
Pin description as follows:
REQ: is a pulse signal, give one pulse, send and receive once
MB_ADDR: is the slave address
MODE: Read/write mode, 0 is read, 1 is write
DATA_ADDR: Corresponding function code
LEN: Data length
DATA_PRA: The storage area for receiving or sending
The above is the correspondence between mode and function code
In addition to the above methods, it is also necessary to set one place:
Open the background data block of MODBUS COMMON LOAD, as shown below:
Set MODE to 4
The above is a summary of the master station
Next, let’s talk about the settings for the slave station:
The previous parameters are the same as the master station, just call MODBUS SLAVE and need to explain:
MB_ADDR: The slave address of MODBUS
MB_HOLD_REG: This corresponds to 40001 function code
For example 00001 function code corresponds to Q0.0
10001 ——I0.0
30001——-IW0
The rest is the same as the master station settings.
(Content source: Internet, copyright belongs to the original author)
Disclaimer: If there are copyright issues, please contact for deletion! No individual or organization assumes relevant legal responsibilities.