Вы находитесь на странице: 1из 7

22/08/12

Siemens Industry Online Support - Automation Serv ice, Automation Support, Simatic Serv ice, Simatic S

show the entry list S7-1200 communication modules -- Configuring and programming communication -- MODBUS RTU How do you establish MODBUS-RTU communication with STEP 7 (TIA Portal) V11 for the SIMATIC S7-1200? How do you establish MODBUS-RTU communication with STEP 7 (TIA Portal) V11 for the SIMATIC S71200? Display part number Description The SIMATIC S7-1200 enables point-to-point communication using the communication modules CM 1241 RS485 and CM 1241 RS232. You can add up to three communication modules to each S7-1200 controller. Using the MODBUS library integrated in STEP 7 (TIA Portal) V11 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 CM 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. Instructions 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.

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) V11 and the program code is transferred to the controllers with the switch CSM 1277. MB_COMM_LOAD The configuration block MB_COMM_LOAD is called on both sides (master and slave) for MODBUS
support.automation.siemens.com/WW/llisapi.dll?f unc=ll&objid=47755811&nodeid0=34612486&load=tree

22/08/12

Siemens Industry Online Support - Automation Serv ice, Automation Support, Simatic Serv ice, Simatic S

communication.

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) V11 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. MB_MASTER You use the MB_MASTER block to define the communication module selected with the MB_COMM_LOAD configuration block as MODBUS master.

support.automation.siemens.com/WW/llisapi.dll?f unc=ll&objid=47755811&nodeid0=34612486&load=tree

22/08/12

Siemens Industry Online Support - Automation Serv ice, Automation Support, Simatic Serv ice, Simatic S

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 REQ MB_ADDR MODE Description Enables communication. MODBUS-RTU station address. Selects the direction of transmission ("0" = read, "1" = write or additional diagnostics functions). Specifies the MODBUS data length. 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".

DATA_ADDR Specifies the MODBUS start address. DATA_LEN DATA_PTR

The "MB_MASTER" must be called in the first program cycle by activating the system marker M1.0 in the hardware settings or by a call in the Startup OB 100. MB_SLAVE You use the MB_SLAVE block to define the communication module selected with the MB_COMM_LOAD configuration block as MODBUS slave.

support.automation.siemens.com/WW/llisapi.dll?f unc=ll&objid=47755811&nodeid0=34612486&load=tree

22/08/12

Siemens Industry Online Support - Automation Serv ice, Automation Support, Simatic Serv ice, Simatic S

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 MB_ADDR Description 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 or struct that covers the specified data volume of the master (DATA_ADDR and DATA_PTR) must be transferred. The first word of this array or struct 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.

support.automation.siemens.com/WW/llisapi.dll?f unc=ll&objid=47755811&nodeid0=34612486&load=tree

22/08/12

Siemens Industry Online Support - Automation Serv ice, Automation Support, Simatic Serv ice, Simatic S

Fig. 05 1. The MB_COMM_LOAD configuration block is called in the initialization step 0. 2. In Step 1 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 made by the positive (DONE) or negative (ERROR) confirmation from the MB_MASTER. The transition resets the execution of the MB_MASTER (REQ = 0). 3. In Step 2 the communication parameters for reading from the slave (MODE = 0) are written using the MB_MASTER in the same instance data block as from Step 1 (MB_DB parameter of the MB_COMM_LOAD block). Execution and transition are the same as in Step 1. The figure below shows a step (networks 6 and 7) with transition (network 8).

support.automation.siemens.com/WW/llisapi.dll?f unc=ll&objid=47755811&nodeid0=34612486&load=tree

22/08/12

Siemens Industry Online Support - Automation Serv ice, Automation Support, Simatic Serv ice, Simatic S

Fig. 06 The MB_ADDR parameter (see Network 6) can therefore also be used to change the slave to be addressed per step, which permits data to be exchanged with up to 32 slaves. Download The compressed file "STEP7_V11_Modbus_RTU.zip" contains the sample project "MODBUS_RTU_V11 SP2.ap11" for alternating data transfer between a master and a slave. Unpack the "STEP7_V11_Modbus_RTU.zip" file and open the sample project "MODBUS_RTU_V11 SP2.ap11" with
support.automation.siemens.com/WW/llisapi.dll?f unc=ll&objid=47755811&nodeid0=34612486&load=tree

22/08/12

Siemens Industry Online Support - Automation Serv ice, Automation Support, Simatic Serv ice, Simatic S

STEP 7 (TIA Portal) V11+SP2. The firmware of the CPU modules is V2.1. Download the project folders ("Master" and "Slave") into the controllers. You can follow the data transfer in the monitoring (watch) tables.

STEP7_V11_Modbus_RTU.zip ( 1446 KB ) Note More information about MODBUS library operations is available in the SIMATIC S7-1200 Programmable Controller System Manual (Entry ID: 36932465). Entry ID:47755811 Date:2012-04-16 I regard this article.... as helpful as not helpful Copy link
Print Siemens AG 2012 - Corporate Information - Privacy Policy - Terms of Use

Suggestion for the entry

Send to a friend

support.automation.siemens.com/WW/llisapi.dll?f unc=ll&objid=47755811&nodeid0=34612486&load=tree

Вам также может понравиться