Application Description 04/2013 Master-Slave Communication .

Transcription

Application description 04/2013Master-Slave Communicationwith Modbus RTU Protocol forS7-300 and ET 200S SystemsS7-300, CP 341, ET 200S 09474714

Warranty and liabilityWarranty and liabilityNoteThe Application Examples are not binding and do not claim to be completeregarding the circuits shown, equipping and any eventuality. The ApplicationExamples do not represent customer-specific solutions. They are only intendedto provide support for typical applications. You are responsible for ensuring thatthe described products are used correctly. These application examples do notrelieve you of the responsibility to use safe practices in application, installation,operation and maintenance. When using these Application Examples, yourecognize that we cannot be made liable for any damage/claims beyond theliability clause described. We reserve the right to make changes to theseApplication Examples at any time without prior notice.If there are any deviations between the recommendations provided in theseapplication examples and other Siemens publications – e.g. Catalogs – thecontents of the other documents have priority.We do not accept any liability for the information contained in this document. Siemens AG 2013 All rights reservedAny claims against us – based on whatever legal reason – resulting from the use ofthe examples, information, programs, engineering and performance data etc.,described in this Application Example shall be excluded. Such an exclusion shallnot apply in the case of mandatory liability, e.g. under the German Product LiabilityAct (“Produkthaftungsgesetz”), in case of intent, gross negligence, or injury of life,body or health, guarantee for the quality of a product, fraudulent concealment of adeficiency or breach of a condition which goes to the root of the contract(“wesentliche Vertragspflichten”). The damages for a breach of a substantialcontractual obligation are, however, limited to the foreseeable damage, typical forthe type of contract, except in the event of intent or gross negligence or injury tolife, body or health. The above provisions do not imply a change of the burden ofproof to your detriment.Any form of duplication or distribution of these Application Examples or excerptshereof is prohibited without the expressed consent of the Siemens AG.SecurityinformationSiemens provides products and solutions with industrial security functions thatsupport the secure operation of plants, solutions, machines, equipment and/ornetworks. They are important components in a holistic industrial securityconcept. With this in mind, Siemens’ products and solutions undergo continuousdevelopment. Siemens recommends strongly that you regularly check forproduct updates.For the secure operation of Siemens products and solutions, it is necessary totake suitable preventive action (e.g. cell protection concept) and integrate eachcomponent into a holistic, state-of-the-art industrial security concept. Third-partyproducts that may be in use should also be considered. For more informationabout industrial security, visit http://www.siemens.com/industrialsecurity.To stay informed about product updates as they occur, sign up for a productspecific newsletter. For more information, visithttp://support.industry.siemens.com.Entry-ID: 109474714,V 1.0,04/20132

Table of contentsTable of contentsWarranty and liability. 21Task . 42Solution. 52.12.23Solution overview . 5Required hardware and software components . 6Basics of the Modbus RTU protocol. 83.13.23.2.13.2.2 Siemens AG 2013 All rights reserved4Description of the STEP 7 program . are configuration . 35Hardware configuration in STEP 7 V5.5 . 37Retrieving and downloading the project in STEP 7 V5.5 . 38Hardware configuration in STEP 7 V12 . 40Retrieving and downloading the project in STEP 7 V12 . 42Operation of the application . 447.17.28Modifying communication settings . 28Modifying existing communication jobs . 28Adding further communication jobs . 30Procedure for Modbus master . 31Procedure for Modbus slave . 32Adjusting the receive buffers . 34Startup of the application . 356.16.26.36.46.57Overview. 15Function mechanisms of the FB Modbus Master (FB5) . 17Calling the FB Modbus Master . 17Initialization . 19Cyclic processing of the communication jobs . 20The UDT Data for Master . 23Function mechanisms of the Modbus slave . 24Calling the FB S MODB (FB81) . 24Blocks . 25The DB Master Data. 27Configuration . 285.15.25.35.3.15.3.25.46Function mechanisms of Modbus RTU . 8Configuration in STEP 7 V5.5 . 10Configuration of the CP 341 as Modbus master . 11Configuration of the ET 200S 1SI as Modbus slave . 13Monitoring . 44Data reading from Modbus slave to Modbus master . 45Related literature . 46Internet links . 469History. 46Entry-ID: 109474714,V 1.0,04/20133

1 Task2.1 Solution overview1TaskIntroductionThis application demonstrates how to deal with the Modbus RTU protocol in theautomation environment of an S7-300 station. It demonstrates the programming ofa Modbus master via CP 341 as well as the programming of a Modbus slave viaET 200S 1SI in an S7-300 CPU.Overview of the automation taskThe figure below provides an overview of the automation task.Figure 1-1Copyright Siemens AG 2013 All rights reservedS7-300Automation systemS7-300controller:parameterization, datastorageCommunicationinterfaceDistributed I/ORS485(CP 341)Modbusslaves(ET 200S 1SI)Description of the automation taskThe application is to demonstrate the following: Configuration of the CP 341 and ET 200S 1SI for Modbus RTU. Creation of a flexible Modbus master/slave program in the S7-300.Entry-ID: 109474714,V 1.0,04/20134

2 Solution2.1 Solution overview2Solution2.1Solution overviewObjective of the applicationThis application demonstrates the following: Basics of the Modbus RTU protocol Parameterization of a serial communication processor (CP 341, ET 200S 1SI)for communication with Modbus RTU Flexible programming of an S7-300 CPU with a CP 341 as Modbus master forcommunication with several slaves Programming of an S7-300 CPU as Modbus slave for communication with amaster via an ET200S 1SI moduleIn the sample project, the CP 341 as Modbus master alternatingly reads two datawords each from the two slaves (ET 200S 1SI).Copyright Siemens AG 2013 All rights reservedThe user program of the master and slaves designed for the application of thefunction codes 3 and 16 is located in the S7-300 CPU.The exact function mechanisms of the program are described in Chapter 4.DisplayThe following figure displays the most important components of the solution:Figure 2-1Engineering stationSTEt7 V5.5S7-300 CPU:program forModbus master &Modbus slaves1SI1SI(RTU(RTUslaveSlave1)1)CP 341(RTUmaster)1SI(RTUslave 2)ET 200SRS485Entry-ID: 109474714,V 1.0,04/20135

2 Solution2.2 Required hardware and software componentsAdvantagesThis application offers you the following advantages: Fast introduction to the subject of Modbus RTU with SIMATIC S7-300 You get encapsulated functions for programming either a Modbus slave or aModbus master Software versions from STEP 7 V5.5 SP3 on SIMATIC S7-300 CPUs CP 341, ET 200S 1SIValidityDelimitationThis application does not include an introduction to the subject of SCLprogramming.Copyright Siemens AG 2013 All rights reservedBasic knowledge of that is assumed.2.2Required hardware and software componentsThe application in STEP 7 V5.5 was generated with the following components:Hardware componentsTable 2-1ComponentNoteNo.Order numberNotePS 307 5A16ES7 307-1EA01-0AA0CPU 315-2 PN/DP16ES7 315-2EH14-0AB0Alternatively, otherCPUs from the S7300 spectrum canalso be used.CP 341-RS422/48516ES7 341-1CH02-0AE0The module with theRS232 interface is notsuitable for a busconfiguration.ET 200S16ES7 151-3AA23-0AB0PM-E DC24V16ES7 138-4CA00-0AA0ET 200S 1SI26ES7 138-4DF11-0BA0BaseUnit26ES7 193-4CC20-0AA0BaseUnit16ES7 193-4CB20-0AA0If hardware different from that in the sample project is used, the hardwareconfiguration has to be modified correspondingly!Entry-ID: 109474714,V 1.0,04/20136

2 Solution2.2 Required hardware and software componentsStandard software componentsTable 2-2ComponentNoteNo.Order numberNoteSTEP 7 V5.5 SP2 HF516ES7810-4CC10-0YA5S7-SCL V5.316ES7811-1CC05-0YA5Modbus Master f.CP341/CP441-216ES7870-1AA00-0YA0STEP 7 V1216ES7822-1AE02-0YA5The STEP 7 V5.5project was migrated toSTEP 7 V12.Only Chapter 6 "Startup of the application" goes into the differences betweenSTEP 7 V5.5 and STEP 7 V12. This application is focused on STEP 7 V5.5.Copyright Siemens AG 2013 All rights reservedSample files and projectsThe following list includes all files and projects that are used in this example.Table 2-3ComponentNote109474714 classic S7300 ModbusRTU CODE V10.zipThis zip file includes the archivedSTEP 7 V5.5 project.109474714 TIA S7300 ModbusRTU CODE V10.zipThis file includes the archivedSTEP 7 V12 project.109474714 S7-300 ModbusRTUDOKU V10 d.pdfThis document.For further documentation, for example on the distributed I/O ET 200S, please referChapter 8 References.Entry-ID: 109474714,V 1.0,04/20137

3 Basics of the Modbus RTU protocol3.1 Function mechanisms of Modbus RTU3Basics of the Modbus RTU protocol3.1Function mechanisms of Modbus RTUOverviewModbus RTU (Remote Terminal Unit) is a standard protocol for serialcommunication between master and slave.Other protocols of the Modbus specification such as Modbus ASCII are notsupported by the serial SIMATIC S7-300 CPs.Master-slave relationModbus RTU utilizes a master-slave relation in which the entire communication iseffected from one single master unit. The slaves only respond to the requests fromthe master. The master sends a request to a slave address and only the slave withthis slave address responds to the command.Copyright Siemens AG 2013 All rights reservedSpecial case: If Modbus slave address 0 is used, the master communicationmodule sends a broadcast telegram to all slaves (without receiving a slaveresponse).Communication procedureThe communication procedure with Modbus RTU is as follows:1. The Modbus master sends a request to a Modbus slave in the network.2. The slave responds with a response telegram in which - if data were requested- the data are already contained or3. if the slave cannot process the request of the master, it responds with an errortelegram.As an example, the following table shows the structure of a telegram if data are tobe read from a or several holding register(s) of the Modbus slave (Modbusstandard).Table 3-1TelegramByte 0Byte 1RequestSlaveaddressFunctioncodeValid responseSlaveaddressFunctioncodeLengthRegister dataError messageSlaveaddress0x83Errorcode---Entry-ID: 109474714,V 1.0,04/2013Byte 2Byte 3Start address (fromwhich holding registeron it is to be read)Byte 4Byte 5No. of registers ---8

3 Basics of the Modbus RTU protocol3.1 Function mechanisms of Modbus RTUThe function code tells the slave which function to execute. Table 3-2 lists thefunction codes that can be used with the CP 341:Table 3-2Copyright Siemens AG 2013 All rights reservedFunction codeFunction01Read output bit02Read input bit03Read holding register04Read input words05Write one output bit06Write one holding register15Write one or several output bit(s)16Write one or several holding register(s)07Read event bit08Check slave status via data diagnosis code /Reset slave event counter via data diagnosis code11Re

Special case: If Modbus slave address 0 is used, the master communication module sends a broadcast telegram to all slaves (without receiving a slave response). Communication procedure The communication procedure with Modbus RTU is as follows: 1. The Modbus master sends a request to a Modbus slave in the network. 2. The slave responds with a response telegram in which - if data were File Size: 902KBPage Count: 46