a MODBUS-RTU communication with PLC SIEMENS SIMATIC S7-1200?

PLC Siemens umumnya mengalami kesulitan dalam koneksi modbus, khusunya ke peralatan dengan modbus serial seperti power meter, protection relay dan lainnya. sebenarnya dari versi sebelumnya bisa dilakukan tetapi semuanya tidak free, sekarang di plc siemens S7-1200 sudah bisa langsung dilakukan

berikut kutipan yang di ambil dari web resmi support siemens

The PLC Siemens SIMATIC S7-1200 enables point-to-point communication via the CPU extension with the interfaces RS485 und RS232. You can add up to three communication modules (+ one RS485 communications board) to each PLC Siemens S7-1200 controller. Using the MODBUS library integrated in STEP 7 (TIA Portal) you can define each communication module as a MODBUS master or slave. If you select MODBUS Master, you can communicate

  • With only one slave using the CM 1241 RS232 (physical limitation).
  • With up to 32 slaves one after the other using the RS485 (via CM or CB 1241 RS485).

We will take a sample project to describe the configuration procedure in STEP 7 (TIA Portal) V11 for communication with multiple slaves using the CM 1241 RS485.

We have taken the example of MODBUS communication between a master and a slave. There is alternate writing to the holding register of the slave (function code 16) and reading from the holding register of the slave (function code 03). Since the RS485 has a two-wire interface (half-duplex), writing and reading must be conducted consecutively. By the same principle, the address of the slave to be addressed can be changed between two actions (here writing and reading), thus making it possible to exchange data with multiple slaves.

modbus page 1

Fig. 01

The CM 1241 RS485 communication modules are linked to each other using a PROFIBUS cable. You can continue with the PROFIBUS cable to connect up to 31 additional MODBUS slaves to the master. The configuration is made in STEP 7 (TIA Portal) and the program code is transferred to the controllers with the switch CSM 1277.

The configuration block MB_COMM_LOAD is called on both sides (master and slave) for MODBUS communication.

modbus page 2
Fig. 02

The MB_COMM_LOAD block is used to select the communication module, set the communication parameters and parameterize the connection with the master or slave parameters. The MB_COMM_LOAD block must be called in the first program cycle (by activating the system marker M1.0 in the hardware settings or by a call in Startup OB 100). After inserting the communication module in the hardware configuration you can select the symbolic name of the communication module at the PORT parameter. The communication parameters BAUD (transmission rate) and PARITY (parity) must be identical for all nodes. The port configuration of the RS485 interface in the STEP 7 (TIA Portal) device view is irrelevant here. The instance data block of the master or slave block is transferred at the MB_DB parameter and thus defines the communication module (PORT parameter) as MODBUS master or slave.

You use the MB_MASTER block to define the communication module selected with the MB_COMM_LOAD configuration block as MODBUS master.

modbus page 3
Fig. 03

The MB_MASTER block is used to select the MODBUS slave to be addressed, select the function code and define the local data storage area. The table below explains the parameters.

Parameter Description
REQ Enables communication.
MB_ADDR MODBUS-RTU station address.
MODE Selects the direction of transmission (“0” = read, “1” = write or additional diagnostics functions).
DATA_ADDR Specifies the MODBUS start address.
DATA_LEN Specifies the MODBUS data length.
DATA_PTR Defines the local receive and send data areas of the master. The DATA_PTR parameter must refer to a global data block created with the disabled option “Symbolic access only”.

The “MB_MASTER” is called cyclically (in OB1, for example).

You use the MB_SLAVE block to define the communication module selected with the MB_COMM_LOAD configuration block as MODBUS slave.

modbus page 4
Fig. 04

The MB_SLAVE block is used to define the MODBUS-RTU station address and specify the local data storage area for the holding register data transfer.

Parameter Description
MB_ADDR Transfers the MODBUS-RTU station address.
MB_HOLD_REG Holding register of the slave. The MB_HOLD_REG parameter must refer to a global data block created with the disabled option “Symbolic access only”.

When multiple registers (words) are to be transferred, with the “MB_HOLD_REG” parameter the symbolic name of an array, struct or PLC data type that covers the specified data volume of the master (DATA_ADDR and DATA_PTR) must be transferred. The first word of this array, struct or PLC data type corresponds to the MODBUS holding register start address 40001.

The parameters can be switched with the inputs and outputs of the blocks or by accessing the instance data block concerned.

Sample project
In the master project, the alternate writing to / reading from the holding register of the slave is done using a sequencer.

modbus page 5
Fig. 05

  1. The MB_COMM_LOAD configuration block is called in the initialization step 0.
  2. In Step 1, the data to be written is copied into the DATA_PTR and the MB_Master with the communication parameters for writing to the slave (MODE = 1) is called and executed (REQ = 1).
    • The transition to Step 2 is done by the execution feedback (BUSY) of the MB_MASTER.
    • The transition to Step 3 is done by the successful feedback (DONE) of the MB_MASTER.
    • The transition resets the execution of the MB_MASTER (REQ = 0).
  3. In Step 3 the communication parameter for reading out of the slave (MODE = 0) is transferred to the MB_MASTER.
    • Execution and transition to Step 4 are the same as in Step 1.
    • After successful feedback (DONE) of the MB_MASTER, the data read from the DATA_PTR must be saved (copied).

The execution of an action (here the reading of the data out of the slave with storage) is shown in the figure below.

modbus page 6
Fig. 06

By changing the MB_ADDR parameter (in Network 7) you could also address another slave.

If an error occurs (ERROR) the STATUS is stored in the ERROR_STATUS tag.
Additional information about the STATUS evaluation is available in the TIA Portal Online Help via F1.


Leave a Comment (0) ↓