# PROFIBUS Communication with Siemens S7-1500 PLC: Implementation Guide ## 1. Introduction This document serves as a technical reference for configuring and programming a Siemens S7-1500 PLC to communicate with PROFIBUS devices, with a specific focus on devices using a GSD file configured with 4 blocks of 32 bytes each for input and output data transfer. The document assumes the reader has basic knowledge of TIA Portal and PLC programming. ## 2. PROFIBUS Configuration Overview ### 2.1 GSD Configuration The GSD (General Station Description) file for this implementation is configured with: - 4 blocks of 32 bytes each for input (total 128 bytes) - 4 blocks of 32 bytes each for output (total 128 bytes) This configuration allows consistent data exchange between the S7-1500 PLC (master) and the PROFIBUS device (slave). ### 2.2 Hardware Requirements - Siemens S7-1500 PLC with CM 1542-5 or CP 1542-5 PROFIBUS interface - TIA Portal V16 or later - GSD file for the PROFIBUS device - PROFIBUS cable and connectors ## 3. TIA Portal Configuration ### 3.1 Importing the GSD File 1. Open TIA Portal and your project 2. Navigate to "Options" → "Manage general station description files (GSD)" 3. Click "Install" and select the GSD file for your device 4. Click "Install" and close the dialog ### 3.2 Hardware Configuration 1. Open the device configuration view 2. Add your S7-1500 CPU to the project if not already present 3. From the hardware catalog, select "PROFIBUS DP" → "Additional Field Devices" → find your device 4. Add the PROFIBUS device to the PROFIBUS network 5. Configure the PROFIBUS address (must be unique on the network) 6. Select the proper I/O configuration (4 blocks x 32 bytes for inputs and outputs) 7. Compile and download the hardware configuration ### 3.3 Setting PROFIBUS Parameters 1. Select the PROFIBUS interface of your S7-1500 PLC 2. Set the PROFIBUS address (typically 2, as 0 is reserved for programming devices and 1 often for master devices) 3. Configure the operating mode as "DP master" 4. Set the transmission rate (usually 1.5 Mbps, but ensure it matches all devices) 5. Set the highest station address (HSA) to cover all planned device addresses ## 4. Data Structure Organization ### 4.1 Input Data Structure (Device to PLC) The 128 bytes of input data is organized in 4 blocks of 32 bytes each. Based on the provided documentation, a typical structure might be: #### Block 1 (Bytes 0-31) ``` Byte 0: Status mPDS 5 (0=Initialization, 1=OK, 2=Warning, 4=Error) Byte 1: Not used Byte 2-3: Production line status Byte 4-5: Product number (0-65535) Byte 6-7: Product type number Byte 8-11: Requested parameter 1 (Real) Byte 12-15: Requested parameter 2 (Real) Byte 16-19: Requested parameter 3 (Real) Byte 20-23: Requested parameter 4 (Real) Byte 24-27: Measurement value 1 (Real) Byte 28-31: Measurement value 2 (Real) ``` #### Block 2 (Bytes 32-63) ``` Byte 32-35: Measurement value 3 (Real) Byte 36-39: Measurement value 4 (Real) Byte 40-43: Measurement value 5 (Real) Byte 44-47: Measurement value 6 (Real) Byte 48-51: Measurement value 7 (Real) Byte 52-55: Measurement value 8 (Real) Byte 56-59: Measurement value 9 (Real) Byte 60-63: Measurement value 10 (Real) ``` #### Block 3 (Bytes 64-95) ``` Byte 64-67: Measurement value 11 (Real) Byte 68-71: Measurement value 12 (Real) Byte 72-75: Measurement value 13 (Real) Byte 76-79: Measurement value 14 (Real) Byte 80-83: Measurement value 15 (Real) Byte 84-87: Measurement value 16 (Real) Byte 88-91: Measurement value 17 (Real) Byte 92-95: Measurement value 18 (Real) ``` #### Block 4 (Bytes 96-127) ``` Byte 96-99: Measurement value 19 (Real) Byte 100-103: Measurement value 20 (Real) Byte 104-107: Measurement value 21 (Real) Byte 108-111: Measurement value 22 (Real) Byte 112-115: Measurement value 23 (Real) Byte 116-119: Measurement value 24 (Real) Byte 120-123: Measurement value 25 (Real) Byte 124-127: Measurement value 26 (Real) ``` ### 4.2 Output Data Structure (PLC to Device) The 128 bytes of output data is also organized in 4 blocks of 32 bytes each: #### Block 1 (Bytes 0-31) ``` Byte 0-1: Product number (Word) Byte 2-3: DI1-DI16 from PLC (16 bits) Byte 4: Type of requested parameter 1 Byte 5: Index of requested parameter 1 Byte 6: Type of requested parameter 2 Byte 7: Index of requested parameter 2 Byte 8: Type of requested parameter 3 Byte 9: Index of requested parameter 3 Byte 10: Type of requested parameter 4 Byte 11: Index of requested parameter 4 Byte 12-13: "Enter" command for requested parameters Byte 14-17: Measurement value 1 from PLC (Real) - Optional Byte 18-21: Measurement value 2 from PLC (Real) - Optional Byte 22-25: Measurement value 3 from PLC (Real) - Optional Byte 26-29: Measurement value 4 from PLC (Real) - Optional Byte 30-31: Type and index of parameter 1 to transfer ``` #### Block 2 (Bytes 32-63) ``` Byte 32-35: Value of parameter 1 to transfer (Real) Byte 36-37: Type and index of parameter 2 to transfer Byte 38-41: Value of parameter 2 to transfer (Real) Byte 42-43: Type and index of parameter 3 to transfer Byte 44-47: Value of parameter 3 to transfer (Real) Byte 48-49: Type and index of parameter 4 to transfer Byte 50-53: Value of parameter 4 to transfer (Real) Byte 54-55: Type and index of parameter 5 to transfer Byte 56-59: Value of parameter 5 to transfer (Real) Byte 60-63: Type and index of parameter 6 to transfer ``` #### Block 3 (Bytes 64-95) ``` Byte 64-67: Value of parameter 6 to transfer (Real) Byte 68-69: Type and index of parameter 7 to transfer Byte 70-73: Value of parameter 7 to transfer (Real) Byte 74-75: Type and index of parameter 8 to transfer Byte 76-79: Value of parameter 8 to transfer (Real) Byte 80-81: Type and index of parameter 9 to transfer Byte 82-85: Value of parameter 9 to transfer (Real) Byte 86-87: Type and index of parameter 10 to transfer Byte 88-91: Value of parameter 10 to transfer (Real) Byte 92-93: Type and index of parameter 11 to transfer Byte 94-95: Beginning of value of parameter 11 ``` #### Block 4 (Bytes 96-127) ``` Byte 96-97: Remaining bytes of parameter 11 value Byte 98-99: Type and index of parameter 12 to transfer Byte 100-103: Value of parameter 12 to transfer Byte 104-105: Type and index of parameter 13 to transfer Byte 106-109: Value of parameter 13 to transfer Byte 110-111: Type and index of parameter 14 to transfer Byte 112-115: Value of parameter 14 to transfer Byte 116-117: Type and index of parameter 15 to transfer Byte 118-121: Value of parameter 15 to transfer Byte 122-125: Type and index of parameter 16 to transfer Byte 126-127: "Enter" command for parameters to be transferred ``` ## 5. TIA Portal Implementation ### 5.1 Creating Data Blocks For better organization, create the following data blocks (DBs): 1. **DB_PROFIBUS_Config**: For configuration parameters 2. **DB_PROFIBUS_Input**: For storing input data from the device 3. **DB_PROFIBUS_Output**: For preparing output data to the device 4. **DB_PROFIBUS_Parameters**: For parameter management #### Sample DB_PROFIBUS_Input Structure ``` // Block 1 "Status_mPDS" : Byte // Status byte "NotUsed" : Byte // Not used "ProductionLineStatus" : Word // Status of production line "ProductNumber" : Word // Current product number "ProductTypeNumber" : Word // Product type number "RequestedParam1" : Real // Requested parameter 1 "RequestedParam2" : Real // Requested parameter 2 "RequestedParam3" : Real // Requested parameter 3 "RequestedParam4" : Real // Requested parameter 4 "MeasValue1" : Real // Measurement value 1 "MeasValue2" : Real // Measurement value 2 // Continue for all measurement values through Block 4 ``` #### Sample DB_PROFIBUS_Output Structure ``` // Block 1 "ProductNumber" : Word // Product number to set "DigitalInputs" : Word // DI1-DI16 from PLC "ReqParamType1" : Byte // Type of requested parameter 1 "ReqParamIndex1" : Byte // Index of requested parameter 1 "ReqParamType2" : Byte // Type of requested parameter 2 "ReqParamIndex2" : Byte // Index of requested parameter 2 "ReqParamType3" : Byte // Type of requested parameter 3 "ReqParamIndex3" : Byte // Index of requested parameter 3 "ReqParamType4" : Byte // Type of requested parameter 4 "ReqParamIndex4" : Byte // Index of requested parameter 4 "EnterCommand" : Word // "Enter" command for requested parameters "PLCMeasValue1" : Real // Measurement value 1 from PLC "PLCMeasValue2" : Real // Measurement value 2 from PLC "PLCMeasValue3" : Real // Measurement value 3 from PLC "PLCMeasValue4" : Real // Measurement value 4 from PLC "ParamTypeIndex1" : Word // Type and index of parameter 1 to transfer // Continue for all parameters through Block 4 ``` ### 5.2 Hardware Addressing In the device properties, you'll see I/O addresses assigned to the device. Note these addresses as they'll be used for data exchange. For example: - Input address: %IB0 to %IB127 (for 128 bytes of input data) - Output address: %QB0 to %QB127 (for 128 bytes of output data) ### 5.3 Programming for Data Exchange #### Reading Input Data (OB Cyclic Interrupt) ``` // Create a cyclic interrupt OB (e.g., OB30) that executes every 100ms // Read block 1 (bytes 0-31) MOVE %IB0 #DB_PROFIBUS_Input.Status_mPDS MOVE %IB1 #DB_PROFIBUS_Input.NotUsed MOVE %IW2 #DB_PROFIBUS_Input.ProductionLineStatus MOVE %IW4 #DB_PROFIBUS_Input.ProductNumber MOVE %IW6 #DB_PROFIBUS_Input.ProductTypeNumber MOVE %ID8 #DB_PROFIBUS_Input.RequestedParam1 MOVE %ID12 #DB_PROFIBUS_Input.RequestedParam2 MOVE %ID16 #DB_PROFIBUS_Input.RequestedParam3 MOVE %ID20 #DB_PROFIBUS_Input.RequestedParam4 MOVE %ID24 #DB_PROFIBUS_Input.MeasValue1 MOVE %ID28 #DB_PROFIBUS_Input.MeasValue2 // Continue for all blocks ``` For SCL programming, you can use a more efficient approach with UDTs and AT constructs: ```SCL // In OB30 (cyclic interrupt) // Map the entire input area to the DB structure DB_PROFIBUS_Input.InputData := %IB0; ``` #### Writing Output Data (FC or FB) ``` // Create a function (FC) or function block (FB) for writing data // Set product number MOVE #DB_PROFIBUS_Output.ProductNumber %QW0 // Set digital inputs MOVE #DB_PROFIBUS_Output.DigitalInputs %QW2 // Set request parameters MOVE #DB_PROFIBUS_Output.ReqParamType1 %QB4 MOVE #DB_PROFIBUS_Output.ReqParamIndex1 %QB5 MOVE #DB_PROFIBUS_Output.ReqParamType2 %QB6 MOVE #DB_PROFIBUS_Output.ReqParamIndex2 %QB7 MOVE #DB_PROFIBUS_Output.ReqParamType3 %QB8 MOVE #DB_PROFIBUS_Output.ReqParamIndex3 %QB9 MOVE #DB_PROFIBUS_Output.ReqParamType4 %QB10 MOVE #DB_PROFIBUS_Output.ReqParamIndex4 %QB11 // Set "Enter" command MOVE #DB_PROFIBUS_Output.EnterCommand %QW12 // Continue for all blocks ``` For SCL programming: ```SCL // In a function block %QB0 := DB_PROFIBUS_Output.OutputData; ``` ## 6. Programming Examples ### 6.1 Example: Reading CO2 Measurement ```SCL // Assuming MeasValue1 contains CO2 concentration in g/L // Read the value and check for alarm conditions #CO2_Concentration := "DB_PROFIBUS_Input".MeasValue1; // Check for alarm condition IF #CO2_Concentration > #CO2_HighLimit THEN #AlarmHighCO2 := TRUE; ELSE #AlarmHighCO2 := FALSE; END_IF; IF #CO2_Concentration < #CO2_LowLimit THEN #AlarmLowCO2 := TRUE; ELSE #AlarmLowCO2 := FALSE; END_IF; ``` ### 6.2 Example: Changing a Parameter ```SCL // Change the offset parameter for Original Extract measurement // Assuming parameter type 3 = Offset and index 2 = Original Extract // Prepare data "DB_PROFIBUS_Output".ParamTypeIndex1.%B0 := 3; // Type: Offset "DB_PROFIBUS_Output".ParamTypeIndex1.%B1 := 2; // Index: Original Extract "DB_PROFIBUS_Output".ParamValue1 := 0.15; // New offset value: 0.15 // Generate Enter command trigger (change the value) IF "DB_LastEnterCommand" = 0 THEN "DB_PROFIBUS_Output".EnterCommandParams := 1; ELSE "DB_PROFIBUS_Output".EnterCommandParams := 0; END_IF; "DB_LastEnterCommand" := "DB_PROFIBUS_Output".EnterCommandParams; // Wait for 2 seconds before next parameter change (using a timer) ``` ### 6.3 Example: Setting a Product ```SCL // Set product number 12 "DB_PROFIBUS_Output".ProductNumber := 12; // Verify the product was set correctly by checking input data IF "DB_PROFIBUS_Input".ProductNumber = 12 THEN "ProductSetCorrectly" := TRUE; ELSE "ProductSetCorrectly" := FALSE; END_IF; ``` ## 7. Working with PROFIBUS Data Types ### 7.1 Data Types Reference |Data Type|Size|Description| |---|---|---| |Byte|8 bits|Single byte value (0-255)| |Word|16 bits|Two-byte value (0-65535, binary coded)| |Real|32 bits|Floating point value, MSB,...,LSB format| |Bit|1 bit|Single binary value (0 or 1) for digital I/O| ### 7.2 Byte Order Considerations The device uses the MSB (Most Significant Byte) first order for multi-byte values. In the S7-1500, all data is stored in little-endian format. This is handled automatically by the PLC for standard data types, but should be considered when working with custom byte manipulations. For 32-bit Real values, the byte order is: - MSB (Most Significant Byte) first in PROFIBUS transmission - The S7-1500 automatically handles the conversion when using REAL data types ### 7.3 Accessing Individual Bits To access individual bits in the digital inputs/outputs: ```SCL // Check if digital input 1 is active IF "DB_PROFIBUS_Input".ProductionLineStatus.%X0 THEN // DI1 is active END_IF; // Activate digital output 3 "DB_PROFIBUS_Output".DigitalInputs.%X2 := TRUE; ``` ## 8. Diagnostics and Troubleshooting ### 8.1 PROFIBUS Diagnostics 1. In TIA Portal, go to the device view 2. Right-click on the PROFIBUS device and select "Online & Diagnostics" 3. Check "PROFIBUS Interface" for general communication status 4. Check "I/O Addresses" for address assignment 5. Check "Module information" for module status ### 8.2 Common Error Codes |Error|Description|Solution| |---|---|---| |Error #1|Valve error (Gas pressure too high)|Check valves, ensure proper line pressure| |Error #2|Concentration out of range|Check measurement conditions| |Error #4|Pressure Gas out of range|Check pressure sensor, ensure proper range| |Error #8|Temperature out of range|Check temperature sensor| |Error #16|Line pressure out of range|Check line pressure sensor| |Error #64|Degassing error|Check impeller/oscillator| |Error #128|Air in measuring chamber|Ensure proper liquid flow, purge air| ### 8.3 Status Monitoring Create a status monitoring view in your HMI application with: - Communication status indicators - Error code display and interpretation - Parameter request status - Parameter change status ### 8.4 Testing Communication Use the "Force table" in TIA Portal to: 1. Force input values to test PLC reactions 2. Force output values to test device reactions 3. Monitor data exchange in real-time ## 9. Best Practices 1. **Consistent Data Handling**: Ensure you maintain data consistency by not interrupting parameter writes 2. **Buffer Time**: Wait 2 seconds after sending the "Enter" command before sending new parameters 3. **Validation**: Always validate data received from the device before using it in calculations 4. **Error Handling**: Implement proper error handling and status monitoring 5. **Documentation**: Document the meaning and purpose of each data point in your application 6. **Periodic Testing**: Periodically test the communication during normal operation ## 10. Appendix ### 10.1 Parameter Types Reference (Type values used in data exchange) |Type|Description| |---|---| |3|Offset| |4|Adjustment factor| |5|Hi limit| |6|HiHi limit| |7|Lo limit| |8|LoLo limit| |9|Product parameter| |10|Target value| ### 10.2 Sample Configuration Data Block ```SCL // DB_PROFIBUS_Config DATA_BLOCK "DB_PROFIBUS_Config" { S7_Optimized_Access := 'TRUE' } VERSION : 0.1 NON_RETAIN STRUCT DeviceAddress : USInt := 3; // PROFIBUS address of the device UpdateRate : Time := T#100MS; // Update rate for data exchange WaitTimeAfterEnter : Time := T#2S; // Wait time after Enter command MaxProductNumber : UInt := 65535; // Maximum product number // Parameter limits MaxParameters : USInt := 16; // Maximum number of parameters MaxParamIndex : USInt := 255; // Maximum parameter index // Communication status CommStatus : Bool; // TRUE if communication is OK LastErrorCode : Word; // Last error code ErrorCount : UDInt; // Error counter END_STRUCT; END_DATA_BLOCK ``` ### 10.3 Further Resources - Siemens Industry Online Support (SIOS): [https://support.industry.siemens.com](https://support.industry.siemens.com/) - TIA Portal documentation - PROFIBUS PA System Description - S7-1500 Programming Manual