Configuring Siemens FC125 for PROFIBUS DP Diagnostics
Application context. FC125 (and its companion FB125 DP_DIA) is the legacy SIMATIC S7-300 / S7-400 block for reading PROFIBUS DP slave diagnostic data from a DP master system. It is supplied as part of the STEP 7 optional package and is intended to be called cyclically from OB1, with the activation flag driven from OB82, OB86, and OB100. This reference resolves the most common parameter confusion (specifically DP_MASTERSYSTEM) and documents the input/output contract, integration pattern, visualization block (FB126), and the migration path to PNIODiag for PROFINET systems.
1. Block Identification and Package Layout
| Block | Type | Function | Call location |
|---|---|---|---|
| FC125 | Function (no instance DB) | Reads DP slave diagnostics into a byte field | OB1, OB82, OB86, OB100 |
| FB125 (DP_DIA) | Function block | Pre-processed form of FC125 with instance DB | OB1 |
| FB126 | Function block | Formats FC125 output for HMI / visualization | OB1 or OB35 |
| DB125 (typical) | Data block | Receives diagnostic data from FC125 | Allocated by user |
The two blocks (FC125 and FB125) are functionally equivalent in their I/O contract. FB125 simply adds an instance DB so that the diagnostic data is retained across calls; FC125 returns the data in a target area pointed to by DATA_FIELD. Newer STEP 7 V5.x service packs prefer FC125 because it has no instance-DB overhead and integrates cleanly with the global diagnostic DB that almost every STEP 7 PROFIBUS project already owns.
2. Formal Interface Contract
| Parameter | Declaration | Data type | Direction | Meaning |
|---|---|---|---|---|
CHECK_ACTIV |
INPUT | BOOL | IN | Activates evaluation of the configured DP master system. Drive from OB82 / OB86 / OB100 for event-driven evaluation; set TRUE cyclically in OB1 for polling. |
EXTERNAL_DP_INTERFACE |
INPUT | BOOL | IN | FALSE = the DP master is an integral interface of the CPU (e.g., CPU 315-2 DP). TRUE = the DP master is an external CP or IM (e.g., CP 342-5, CP 443-5, IM 467). |
DP_MASTERSYSTEM |
INPUT | INT | IN | The internal index of the DP master system assigned by STEP 7 HW Config. It is not the PROFIBUS station address of the master and it is not the number of masters on the network. |
DATA_FIELD |
INPUT | ANY | IN/OUT | Pointer to a working area of at least 50 bytes. The pointed-to data type must be BYTE; alignment to byte 0 of the target DB is recommended. |
RET_VAL |
OUTPUT | INT | OUT | Return code: 0 = no error / data refreshed; non-zero = see Section 8 error matrix. |
3. Resolving DP_MASTERSYSTEM in HW Config
Three reliable ways to read the index you must pass to DP_MASTERSYSTEM:
-
HW Config property dialog. Right-click the PROFIBUS subnet line (the orange rail) and open Properties > General. The first tab shows the configured name and the internal number used by STEP 7 for this DP master system. This number is the value to load into
DP_MASTERSYSTEM. - NetPro subnet list. In NetPro select the PROFIBUS subnet; the bottom status bar displays the configured Subnet number which matches the HW Config value for the same subnet.
- System data block (SDB) inspection. Open PLC > Module Information > System Data on a live online connection and read the DP master system row of the diagnostic buffer; SDBs are tagged with the same index.
DP_MASTERSYSTEM. This returns RET_VAL = 8090 ("DP master system not configured") because the SFC lookup uses the internal index, not the station address. Always read the value from HW Config, never from the DP address table.4. EXTERNAL_DP_INTERFACE Decision Logic
The boolean simply tells FC125 whether to query SFCs that target the local CPU's integrated DP port or SFCs that target an external CP/IM module in the rack. The matrix is:
| Hardware topology | EXTERNAL_DP_INTERFACE | SFC family invoked |
|---|---|---|
| CPU 31x-2 DP (integrated) | FALSE | SFC 13 / SFC 49 (CPU-local) |
| CPU 41x-2 DP (integrated) | FALSE | SFC 13 / SFC 49 (CPU-local) |
| CP 342-5 in ET 200M / S7-300 | TRUE | SFC 13 / SFC 49 with LADDR of CP |
| CP 443-5 Extended in S7-400 | TRUE | SFC 13 / SFC 49 with LADDR of CP |
| IM 467 in S7-400 | TRUE | SFC 13 / SFC 49 with LADDR of IM |
Setting EXTERNAL_DP_INTERFACE = FALSE when a CP is actually the master causes the CPU to look at its own integrated interface (which in a CP-only rack does not exist) and returns RET_VAL = 8092. Setting it TRUE for an integrated CPU returns the same error because FC125 then tries to read a CP slot that is empty.
5. DATA_FIELD Sizing and Layout
The diagnostic data block must be at least 50 bytes. The minimum layout that FC125 expects is:
// DB125 - PROFIBUS DP diagnostic target
DATA_BLOCK DB125
STRUCT
STATE : BYTE; // Byte 0 - overall state (0=OK, <>0=fault)
SLAVE_ADDR : BYTE; // Byte 1 - failing slave PROFIBUS address
RESERVED : ARRAY[2..5] OF BYTE;
IDENT : WORD; // Byte 6/7 - DP ident (0x0000 = DP)
LEN_DIAG : BYTE; // Byte 8 - length of standardized diag
DIAG_DATA : ARRAY[9..49] OF BYTE; // up to 41 bytes diag payload
END_STRUCT;
END_DATA_BLOCK
DATA_FIELD := P#DB125.DBX0.0 BYTE 50. The area length must be ≥ 50; values of 48 or less are rejected with RET_VAL = 8091. The first byte offset must be 0.0 to keep the internal index consistent with FB126's offset expectation.6. Wiring FC125 into OB1, OB82, OB86 and OB100
The classic integration pattern from the STEP 7 online help for the diagnostic functions for PROFIBUS is event-driven with a polled refresh:
// OB1 - cyclic refresh
CALL FC 125
CHECK_ACTIV := M 100.0 // latched TRUE
EXTERNAL_DP_INTERFACE := FALSE // CPU 315-2 DP
DP_MASTERSYSTEM := 1 // index from HW Config
DATA_FIELD := P#DB125.DBX0.0 BYTE 50
RET_VAL := MW 102
// OB82 - diagnostic interrupt (slave diagnostic change)
SET
S M 100.0 // activate FC125 evaluation
// OB86 - rack/IO fault
SET
S M 100.0
// OB100 - warm restart
SET
S M 100.0
R M 100.0 // single-shot, will clear in OB1
Why three OBs? OB82 fires when a slave changes its diagnostic state (channel fault, module pull, hot-swap on IM 153-1). OB86 fires on rack failure, which for a DP master includes loss of an entire DP segment. OB100 ensures that after a restart the diagnostics are rebuilt from scratch. OB1 then evaluates RET_VAL and the first byte of DATA_FIELD to drive HMI tags.
7. Visualization with FB126
FB126 was added to the same diagnostic package so that the raw byte array returned by FC125 can be rendered in WinCC flexible / ProTool without writing custom parsing code. FB126 takes the same DATA_FIELD pointer and produces a structured UDT with one element per known slave:
// FB126 - visualization driver
CALL FB 126, DB126
DP_MASTERSYSTEM := 1
DATA_FIELD := P#DB125.DBX0.0 BYTE 50
SLAVE_TABLE := P#DB126.DBX0.0 BYTE 200 // pre-allocated 200 B
RET_VAL := MW 110
Each entry in SLAVE_TABLE is a fixed 20-byte slot: bytes 0…1 = PROFIBUS address, byte 2 = state, byte 3 = ident byte 1, bytes 4…19 = diagnostic text. WinCC reads the table via raw area pointer and displays it in a status screen.
8. Return Codes and Troubleshooting Matrix
| RET_VAL (hex) | RET_VAL (dec) | Meaning | Most likely cause | Correction |
|---|---|---|---|---|
| 0000 | 0 | OK, data refreshed | - | - |
| 8090 | 32912 | DP master system not configured / not found | Wrong value in DP_MASTERSYSTEM
|
Read index from HW Config |
| 8091 | 32913 | Length of DATA_FIELD too small | < 50 bytes allocated | Resize target DB |
| 8092 | 32914 | DP interface (integrated or external) not available | Wrong EXTERNAL_DP_INTERFACE setting or wrong CP slot | Verify rack and slot in HW Config |
| 8093 | 32915 | SFC access error (CP/IM not in RUN) | External CP stopped or not configured | Check CP diagnostic buffer |
| 80A1 | 32929 | Diagnostic data inconsistent | Slaves still coming up after restart | Retry from OB100 after a delay |
| 80A2 | 32930 | No slaves on the master system | Empty segment or address mismatch | Check HW Config assignment list |
| 80B1 | 32945 | Internal SFC parameter error | Firmware bug on very old CPUs | Apply CPU firmware update |
| 80C0 | 32960 | Communication error to CP | CP faulted or removed | Check CP SF LED |
9. Diagnostic Data Flow (Inline Diagram)
10. Commissioning Checklist
- Install the STEP 7 optional package that contains FC125 / FB125 / FB126. Without it the blocks are not in the standard library and Blocks folder will be empty.
- Compile HW Config and download SDBs so that the master system has its internal index written to the CPU.
- Insert DB125 (or your chosen diagnostic DB) with at least 50 bytes of
BYTEstorage at offset 0.0. - Open OB1 and insert a call to FC125 with the parameter values from Sections 3 and 4.
- Insert
SET+Sinstructions in OB82, OB86 and OB100 that flipCHECK_ACTIVto TRUE. - Download all blocks to the CPU and place it in RUN. Force
CHECK_ACTIV = TRUEand verifyRET_VAL = 0. - Pull a slave connector and confirm that OB86 fires and that
DB125.DBX0becomes non-zero within two OB1 cycles. - Insert FB126 if WinCC visualization is required, then rebuild the WinCC tags that point at
SLAVE_TABLE. - Save the project with the optional package version stamped in the project properties for reproducibility.
11. Migration to PNIODiag for PROFINET
FB125 / FC125 and the FB126 visualization were retired for new PROFINET IO projects. Siemens recommends the PNIODiag package, which exposes equivalent diagnostics over the standard PROFINET record reads and integrates with TIA Portal. For mixed PROFIBUS / PROFINET cells, keep FC125 on the PROFIBUS master system and run PNIODiag on the PROFINET IO controller side; the two coexist and their diagnostic DBs are independent.
12. Frequently Asked Questions
Is DP_MASTERSYSTEM the PROFIBUS station address of the CPU?
No. DP_MASTERSYSTEM is the internal index that STEP 7 assigns to the DP master system in HW Config (typically 1 for a single-master CPU 315-2 DP). The PROFIBUS station address (often 2) is a different value and is set in the CPU properties. Always read the master system index from the HW Config subnet properties.
Is DP_MASTERSYSTEM the number of DP masters on the network?
No. It is the ordinal index of the master system inside the S7 project, not a count of masters. A single CPU 315-2 DP with 32 IM 153-1 slaves still has DP_MASTERSYSTEM = 1; the number of slaves is irrelevant to this parameter.
What is the minimum size of the DATA_FIELD area?
50 bytes, pointed at byte 0.0 of the target DB. Anything smaller is rejected with RET_VAL = 8091. A typical engineering choice is 200 bytes so that FB126 can also be called without resizing the DB.
When should EXTERNAL_DP_INTERFACE be TRUE?
Only when the DP master is an external CP or IM module (CP 342-5, CP 443-5, IM 467). For a CPU with an integrated DP port (CPU 31x-2 DP / CPU 41x-2 DP) it must be FALSE. Wrong polarity returns RET_VAL = 8092.
Can FC125 be replaced by PNIODiag on a PROFIBUS system?
No. PNIODiag targets PROFINET IO diagnostics. For PROFIBUS DP the FC125 / FB125 pair remains the supported mechanism. In mixed cells the two packages run side by side, each addressing its own master system.