hit counter script
Table of Contents

Advertisement

FAQ  02/2014
CP340/CP341/CP440/CP441
Communication and
Programming
SIMATIC S7
http://support.automation.siemens.com/WW/view/en/ID 88867653

Advertisement

Table of Contents
loading

Summary of Contents for Siemens SIMATIC S7 CP340

  • Page 1 FAQ  02/2014 CP340/CP341/CP440/CP441 Communication and Programming SIMATIC S7 http://support.automation.siemens.com/WW/view/en/ID 88867653...
  • Page 2 This entry is from the Siemens Industry Online Support. The general terms of use (http://www.siemens.com/terms_of_use) apply. Security Siemens provides products and solutions with industrial security functions that informa- support the secure operation of plants, solutions, machines, equipment and/or tion networks. They are important components in a holistic industrial security concept.
  • Page 3 The author of the program will not assume any liability for any functionality or compatibility, and users shall assume the related risks. Siemens will not provide error correction of this program example or hotline support. It is suggested that users...
  • Page 4 1 Overview should read the related module operation manuals carefully to use them in a better way. CP340/CP341/CP440/CP441 Communication and Programming Entry-ID: 88867653, V1.0, 02/2014...
  • Page 5 STEP7 STEP7 programming software is used to write PLC program, and it shall be purchased from Siemens. All procedure codes in this document are written with STEP7 V5.4 SP4. PtP drive software package PtP Param V5.1 is the drive software package for CP340/CP341/CP440/CP441,...
  • Page 6 "Start-> SIMATIC-> Documentation - > English”, or they may be found directly from the folder of STEP7 installation path“… Program files-> Siemens -> Step7 -> S7MANUAL -> S7PtP_Cp”. Fig. 1: Module manual path diagram...
  • Page 7 The following examples are used to introduce the ASCII protocol communication of Siemens serial communication modules CP340, CP341, CP440 and CP441. ASCII protocol communication of CP340 4.1.1 Hardware catalog...
  • Page 8 4 ASCII protocol communication Fig. 3: Insert S7-300 station 3. Double-click Hardware to enter the hardware configuration interface and insert RACK, CPU315-2DP and CP340. Fig. 4: Configuration hardware CP340/CP341/CP440/CP441 Communication and Programming Entry-ID: 88867653, V1.0, 02/2014...
  • Page 9 4 ASCII protocol communication 4. Double-click CP340 module, and click Parameter... to configure CP340 parameters. Fig. 5: CP340 Properties dialog box 5. Select ASCII from Protocol options. Fig. 6: Protocol selection CP340/CP341/CP440/CP441 Communication and Programming Entry-ID: 88867653, V1.0, 02/2014...
  • Page 10 4 ASCII protocol communication 6. Double-click the envelop icon under Protocol to configure ASCII communication parameters. The set communication parameters shall be the same as those of the communication partner. Communication Baud rate: 9600bps,Data bit: 8 bits, Stop bit: 1 bit, Parity: none, Character delay time: 4ms, Other parameters shall be in default settings.
  • Page 11 4 ASCII protocol communication R(A)0V/R(B)5V R(A)5V/R(B)0V Fig. 9: Wiring of receiver at interface RS485/422 8. After the parameters are configured, click button to save and compile the hardware configurations. After it is confirmed that no error exists, download the hardware configurations to CPU to complete the whole hardware configuration process.
  • Page 12 4 ASCII protocol communication Fig. 12: Send Data block DB1 3. Invoke Send Function block The parameters of the send function block FB3 P_SEND of CP340 are set as in the table below: LADDR Start logic address in hardware configuration, which is 256 in this example DB_NO Send Data block number, which is 1(DB1) in this example DBB_NO...
  • Page 13 4 ASCII protocol communication 5. Create receive data block DB10. Fig. 14: Receive data block DB10 6. Invoke receive function block The parameters of the receive function block FB2 P_RCV of CP340 are set as in the table below: LADDR Start logic address in hardware configuration, which is 256 in this example DB_NO Send Data block number, which is 10(DB10) in this example...
  • Page 14 4 ASCII protocol communication 4.1.4 Equipment connection Use standard RS232C cable to connect serial ports of CP340 and computer. The detailed cable connecting method may be seen in CP340 Manual - Chapter B: Connecting cables. ASCII protocol communication of CP341 4.2.1 Hardware catalog PS 307...
  • Page 15 4 ASCII protocol communication Fig. 20: Configuration hardware 3. Double-click CP341 module, and click Parameter... to configure CP341 parameters. Fig. 21: CP341 Properties dialog box 4. Select ASCII protocol from Protocol options. CP340/CP341/CP440/CP441 Communication and Programming Entry-ID: 88867653, V1.0, 02/2014...
  • Page 16 4 ASCII protocol communication Fig. 22: Protocol selection 5. Double-click the envelop icon under Protocol to configure ASCII communication parameters. The set communication parameters shall be the same as those of the communication partner. Communication Baud rate:9600bps,Data bit: 8 bits, Stop bit: 1 bit, Parity: none, Character delay time:4ms,Other parameters shall be in default settings.
  • Page 17 4 ASCII protocol communication Fig. 24: Configuration interface parameters 7. After completing configuration, user may click button to save and compile the hardware configuration and download it to CPU after confirming that no error exists. The whole hardware configuration process is completed by now. Fig.
  • Page 18 4 ASCII protocol communication Fig. 27: Send Data block DB1 3. Invoke Send Function block The parameters of the send function block FB8 P_SND_RK of CP341 are set as in the table below: LADDR Start logic address in hardware configuration, which is 256 in this example DB_NO Send Data block number, which is 1(DB1) in this example DBB_NO...
  • Page 19 4 ASCII protocol communication 4. Invoke Receive Function Block FB7 P_RCV_RK from Libraries -> CP PtP -> CP341 and distribute instance data block DB7 to it. Set LADDR as the start logic address 256 in hardware configuration. 5. Create receive data block DB10 Fig.
  • Page 20 4 ASCII protocol communication Fig. 30: Invoke FB7 P_RCV_RK from OB1 4.2.4 Equipment connection Use standard RS232C cable to connect serial ports of CP341 and computer. The detailed cable connecting method may be seen in CP341 Manual - Chapter B: Connecting cables.
  • Page 21 4 ASCII protocol communication Fig. 34: Insert S7-400 station 2. Double-click Hardware to enter the hardware configuration screen and insert RACK-400,PS407,CPU414-3DP and CP440. Fig. 35: Configuration hardware 3. Double-click CP440 module and click Parameter to configure CP440 parameters, and select ASCII protocol in Protocol options. CP340/CP341/CP440/CP441 Communication and Programming Entry-ID: 88867653, V1.0,...
  • Page 22 4 ASCII protocol communication Fig. 36: Protocol selection 4. Double-click the envelop icon in Protocol to configure the performance parameters in it. The set communication parameters must match those of the communication partner. Baud rate: 9600bps,Data bit: 8 bits,,Stop bit: 1 bit, Parity: none, Character delay time:4ms,other parameters may use default data.
  • Page 23 4 ASCII protocol communication Fig. 38: Configuration interface parameters 6. After configuration completes, compile and save the hardware configuration, and download it after it is confirmed correct. 4.3.3 Write communication program 1. Double-click OB1 to open programming screen. Invoke Send Function Block FB10 SEND_400 from Libraries->CP PtP->CP440 and distribute instance data block DB10 to it.
  • Page 24 4 ASCII protocol communication type Send Data trigger bit, rising edge BOOL trigger, which is M0.0 in this example Cancel send, discontinue BOOL communication Module start logic address in LADDR hardware configuration, which is 512 in this example Send Data block number, which DB_NO is 1(DB1) in this example Start address of Send Data,...
  • Page 25 4 ASCII protocol communication Fig. 41: Invoke FB10 SEND_440 from OB1 4. Invoke receive function block FB9 RECV_440 from the same folder in the library and distribute instance data block DB9 to it, and set LADDR as input start logic address 512 in hardware configuration.
  • Page 26 4 ASCII protocol communication 4.3.4 Equipment connection CP440 module only provides one 15-pin RS422/485 serial port. Select RS422 or RS485 interface according to the wiring mode. Only one interface is valid. RS422 is 4-wire and in full-duplex mode while RS485 is 2-wire and in half-duplex mode. The detailed cable connecting method may be seen in CP440 Manual - Appendix B: Connecting cables.
  • Page 27 4 ASCII protocol communication 4.4.2 Configuration 1. Open the project ptp that has been created, and insert a new SIMATIC 400 Station to change the station name to CP441 ASCII. Double-click Hardware to enter the hardware configuration screen, and insert the related module in steps stated above.
  • Page 28 4 ASCII protocol communication Fig. 44: Setting of basic interface parameters 3. Click Parameter, and configure CP441-2 parameters. Fig. 45: Protocol selection 4. Double-click the envelop icon under Protocol to configure ASCII communication parameters. The set communication parameters shall be the same as those of the communication partner, and the others shall be in default values.
  • Page 29 4 ASCII protocol communication Fig. 46: Create new PtP network PtP 1 interface is in connection status at this moment. PtP 2 has the same configuration, which is not introduced for it is not used in this example. Fig. 47: Interface status after PtP is connected 6.
  • Page 30 4 ASCII protocol communication Fig. 48: Insert a new connection 7. Select "Unspecified" as the connection object. This option is used for connection with third-party devices and the devices without communication bus, including S7-CP PtP (CP340,CP341), S5-CP PtP and Printer, etc. If the communication partner is CP441, it shall be confirmed that it has been connected to a same PtP subnet and selected directly as the connection object.
  • Page 31 4 ASCII protocol communication 8. After completing configuration, click OK to confirm. PtP connection properties screen will pop up at this moment. Fig. 50: Configuration connection  One parameter Local ID (Hex) in this screen shall be noted for it will be used when programming to invoke system function block.
  • Page 32 4 ASCII protocol communication 4.4.3 Write communication program 1. Double-click OB1 to open the programming screen. Invoke SFB12 BSEND from Libraries-> Standard library-> System function blocks, and distribute instance data block DB12 to it and create send data block DB1. Fig.
  • Page 33 4 ASCII protocol communication Fig. 53: Invoke SFB12 BSEND from OB1 3. At the same time, invoke SFB13 BRCV to receive data, and distribute instance data block DB13, and create a new DB block DB2 to receive data. Fig. 54: Receive data block DB2 Name Data type comments...
  • Page 34 4 ASCII protocol communication Fig. 55: Invoke SFB13 BRCV from OB1 4.4.4 Equipment connection Use standard RS232C cable to connect serial ports of CP441-2 interface1 and computer. The detailed cable connecting method may be seen in CP441 Manual - Appendix B: Connecting cables. CP340/CP341/CP440/CP441 Communication and Programming Entry-ID: 88867653, V1.0,...
  • Page 35 5 MODBUS RTU Protocol communication MODBUS RTU Protocol communication MODBUS RTU communication protocol is in master-slave mode. In the transmission process, the master sends a request telegram actively to the slave, and the slave returns an answer telegram. For details of MODBUS RTU protocol, please refer to related MODBUS RTU files or manuals.
  • Page 36 5 MODBUS RTU Protocol communication 5.1.2 Configuration 1. Open the project ptp created above, and right-click the project name, select Insert New Object->SIMATIC 300 Station to change the station name to CP341 Modbus-S. Fig. 58: Insert S7-300 station 2. Double-click Hardware to enter the hardware configuration interface and insert RACK, CPU315-2DP and CP341.
  • Page 37 5 MODBUS RTU Protocol communication Fig. 60: Selecting communication protocol 4. Double-click the envelop icon under Protocol to configure MODBUS Slave parameter, and click MODBUS-Slave button. Step 1 Step 2 Fig. 61: Configure MODBUS Slave communication parameter Step 1: set MODBUS Slave address, which is set as 2 in this example Step 2: set parameters of MODBUS Slave, such as Baud rate, stop bit and check bit, etc.
  • Page 38 Siemens data area is M0.0-M12.4. 101 to 200 match the MODBUS Address area 00102 to 00201, and the corresponding Siemens data area is Q0.0 to Q12.3. The slave addresses 201 to 300 and 301 to 400 match the Modbus address areas 00202 to 00301 and 00302 to 00401, and the corresponding Siemens data area is Timer, Counter.
  • Page 39 5 MODBUS RTU Protocol communication Fig. 65: Distribution of MODBUS Slave addresses 9. Setting limit values for writing parameters Fig. 66: Write parameter limit values for MODBUS Slave 10. If CP341 in RS422/485 interface is selected, the interface type shall also be set as shown in the Fig.
  • Page 40 5 MODBUS RTU Protocol communication Fig. 68: Dialog box prompting loading driver 12. At this moment it must be connected to the actual PLC. Click Yes to load the driver. The CPU must be in STOP mode when in loading. After the driver is loaded, STEP7 will prompt "Driver already exists"...
  • Page 41 5 MODBUS RTU Protocol communication Fig. 70: Logic address of CP341 3. Invoke MODBUS Slave function block Start logic address in hardware configuration, LADDR which is 256 in this example timeout initialization timer, which is T1 in this START_TIME example timeout initialization time value, which is 1s in START_TIME this example...
  • Page 42 5 MODBUS RTU Protocol communication Fig. 71: Invoke FB80 from OB1 4. Create FC03,06,16 function code communication data block DB1. Fig. 72: Communication data block DB1 5. Create FC04 function code communication data block DB2. Fig. 73: Communication data block DB2 5.1.4 Equipment connection Use standard RS232C cable to connect serial ports of CP341 and computer.
  • Page 43 5 MODBUS RTU Protocol communication Fig. 74: Open Modscan32 software 2. Click Connection->Connect in Modscan32, as shown in the screen below. Select COM port COM1 connecting the computer with CP341, and set the Baud rate, data bit, stop bit and check mode, as shown in the Fig. below: Fig.
  • Page 44 5 MODBUS RTU Protocol communication Modbus slave address Set data display method Modbus initial Type of data accessed by address and length Modbus Data display area Fig. 76: Modscan32 operation interface 4. The 10 address data of the data display area correspond to the numeric values (1-10 for DBW0 - DBW10 respectively)of the first 10 words of DB1 in CPU, as shown in the Fig.
  • Page 45 5 MODBUS RTU Protocol communication Fig. 78: Floating point number data processing At this moment, the floating point number 40001 displayed in Modscan32 corresponds to the floating point number value of MD200, but MODBUS address corresponds to DB1.DBD0. Fig. 79: Floating point number data exchange If CP341 module with RS422/RS485 interface is used, RS422/485 converter shall be used when using computer serial port debugging program.
  • Page 46 5 MODBUS RTU Protocol communication Fig. 80: Before and after inserting Dongle 5.2.2 Configuration 1. Open the project ptp created above, and right-click the project name, select Insert New Object->SIMATIC 300 Station to change the station name to CP341 Modbus-M. Fig.
  • Page 47 5 MODBUS RTU Protocol communication Fig. 82: Configuration hardware 3. Double-click CP341 module, and click Parameter... to configure CP341 parameters. Select MODBUS Master from Protocol options. Fig. 83: Selecting communication protocol 4. Double-click the envelop icon under Protocol to configure Modbus Master parameter, and click Modbus-Master button to set communication Baud rate, etc.
  • Page 48 5 MODBUS RTU Protocol communication Fig. 84: Configure MODBUS Master communication parameter 5. After configuration completes, a prompt will ask you whether you load the driver before it is saved. Fig. 85: Dialog box prompting loading driver 6. At this moment, it must be connected to the actual PLC. Click Yes to load the driver or click Load Drivers.
  • Page 49 5 MODBUS RTU Protocol communication Fig. 87: Compile and save hardware configuration 5.2.3 Write communication program 1. Double-click OB1 to open OB1 programming screen. Invoke send program block FB8 P_SND_RK from Libraries -> CP PtP -> CP341 and distribute instance data block DB8 to it.
  • Page 50 5 MODBUS RTU Protocol communication example trigger bit of Send Data, rising edge trigger, which is M0.0 in this example DB_NO Send Data block number, which is 1(DB1) in this example DBB_NO Start address of Send Data, which is 0(DB1.DBB0) in this example Length of send data, which is 6 in this example R_TYP "X"...
  • Page 51 5 MODBUS RTU Protocol communication Fig. 91: Logic address of CP341 5. Create receive data block DB2 Fig. 92:Receive data block DB2 6. Invoke receive function block The FB7 P_RCV_RK parameter setting may be seen in the table below: Start logic address in hardware configuration, which is 256 in this LADDR example DB_NO...
  • Page 52 5 MODBUS RTU Protocol communication Fig. 93: Invoke FB7 P_RCV_RK from OB1 5.2.4 Equipment connection Use standard RS232C cable to connect serial ports of CP341 and computer. The detailed cable connecting method may be seen in CP341 Manual - Chapter B: Connecting cables.
  • Page 53 5 MODBUS RTU Protocol communication Fig. 94: Open Modbus Slave test software 2. Click the button Register Later. This software may be used for 30 days without registration, but each time it may only be used for 15min. The software downloaded from the Internet has no registration code.
  • Page 54 5 MODBUS RTU Protocol communication Fig. 96: Setting communication parameters 4. Then set the address 1 to 4 as 111 to 444 respectively, set M0.3 as TRUE in Step7 Variable table to enable receiving. Then set M0.0 as TRUE ( rising edge trigger.
  • Page 55 5 MODBUS RTU Protocol communication Fig. 99: Monitoring of receive data3 MODBUS Master protocol communication of CP441-2 5.3.1 Hardware catalog RACK-400 6ES7400-1JA01-0AA0 PS407 6ES7407-0KA02-0AA0 CPU414-3 6ES7414-3XJ04-0AB0 CP441-2 6ES7441-2AA03-0AE0 Dongle 6ES7870-1AA01-0YA0 Dongle is installed in the same positions as S7-300 and CP341, and both are behind the module.
  • Page 56 5 MODBUS RTU Protocol communication Fig. 100: Selecting communication protocol 3. Double-click the envelop icon under Protocol to configure Modbus Master parameter, and click Modbus-master button to set the basic parameters such as communication rate and message details, etc., and other parameters may be in default settings.
  • Page 57 5 MODBUS RTU Protocol communication Fig. 102: Configuration connection 5. Click to save and compile the configuration information. If there is no error, select CPU to download the configuration information as a whole, and to check the connection status online till the displayed icon of "connection status"...
  • Page 58 5 MODBUS RTU Protocol communication Set “Monitoring Time for”  “Transfer of parameters to modules(100ms)” to a value as small as 3000 (=300s), by which an adequately long time may be guaranteed to download the used load protocol driver into the CP card. 5.3.3 Write communication program 1.
  • Page 59 5 MODBUS RTU Protocol communication Function Length code (in bytes) >6 >6 4. The instance data block of FB13 is DB13, and the receive data DB block DB2 is created. Fig. 106: Receive data block DB2 5. Invoke receive function block Fig.
  • Page 60 5 MODBUS RTU Protocol communication 5.3.4 Equipment connection Use standard RS232C cable to connect serial ports of CP441-2 interface1 and computer. The detailed cable connecting method may be seen in CP441 Manual - Appendix B: Connecting cables. 5.3.5 Communication test 1.
  • Page 61 5 MODBUS RTU Protocol communication 3. When testing different function codes, just modify the data request telegram sent by the master. Fig. 110: Create send data frame Fig. 111: Invoke SFB13 in OB1 MODBUS Slave protocol communication of CP441-2 5.4.1 Hardware catalog RACK-400 6ES7400-1JA01-0AA0...
  • Page 62 5 MODBUS RTU Protocol communication 5.4.2 Configuration 1. Open the project ptp that has been created, insert a new SIMATIC 400 Station, and change the station name to CP441-2 modbus Slave. 2. Double-click Hardware to enter the hardware configuration interface, and insert RACK, PS, CPU, and CP441-2.
  • Page 63 Q2.7.Slave addresses 48 to 79 and 80 to 111 match the Modbus address areas 00049 to 00080 and 00081 to 00112, and the corresponding Siemens data area is Timer, Counter. FC02 reads input data status, and the address matching is as stated above.
  • Page 64 5 MODBUS RTU Protocol communication Fig. 116: Distribution of MODBUS Slave addresses 8. FC04 configuration output register data area also corresponds to Siemens data area DB block. Fig. 117: Distribution of MODBUS Slave addresses 9. Set write parameter limit values of FC05,06,15,16 : Fig.
  • Page 65 5 MODBUS RTU Protocol communication 10. After completing configuration, click OK and save it, and close the dialog box. Just like ASCII-2 as stated above, create PtP connection for the used interface, and record the Local ID (Hex) connection number. Fig.
  • Page 66 5 MODBUS RTU Protocol communication Set “Monitoring Time for”  “Transfer of parameters to modules(100ms)” to a value as small as 1000 (=100s), by which an adequately long time may be guaranteed to download the used load protocol driver into the CP card during the parameter assignment process.
  • Page 67 5 MODBUS RTU Protocol communication 2. The FB180 parameter setting is shown in the table below: Name Data type comments Local ID number, which is obtained from the INPUT/INT PtP connection properties and is hexadecimal. Initialization timeout timer, which is T5 in START_TIMER INPUT/TIMER this example...
  • Page 68 5 MODBUS RTU Protocol communication 3. Invoke FB180 function block . Fig. 122: Invoke FB180 function block 5.4.4 Equipment connection Use standard RS232C cable to connect serial ports of CP341 and computer. The detailed cable connecting method may be seen in CP341 Manual - Chapter B: Connecting cables.
  • Page 69 5 MODBUS RTU Protocol communication Fig. 123: Distribute communication parameters Modbus slave address Modbus initial Type of data accessed by address and Modbus, viz. selecting length function code to be used Fig. 124: Communication monitor interface CP340/CP341/CP440/CP441 Communication and Programming Entry-ID: 88867653, V1.0, 02/2014...
  • Page 70 5 MODBUS RTU Protocol communication Shown in the Fig. below is the corresponding communication monitor screen when the function code FC04 is used. To read other data, just change the related access data type. For floating point number display, refer to the read method for Modbus Slave communication of CP341 as stated above.

This manual is also suitable for:

Simatic s7 cp341Simatic s7 cp441Simatic s7 cp440

Table of Contents