Reading Siemens S7-300F CPU Status and Diagnostics at Runtime
Overview
Engineers who have programmed a Mitsubishi MELSEC Q-series, iQ-R, or A-series controller rely on a well-known set of special relay (SM) bits, special registers (SD), and link relays for real-time visibility into PLC health, scan timing, and error state. The Siemens SIMATIC S7-300 / S7-300F family, including the fail-safe CPU 315F-2PN/DP, exposes equivalent information through a different but equally deterministic mechanism: error and diagnostic organization blocks (OBs), the system function SFC51 "RDSYSST" for reading system state lists (SSLs), the data-record system function SFC59 "RD_REC" / SFB52 "RDREC" for module diagnostics, the diagnostic buffer, and the status word (STW) of the CPU. This reference consolidates the runtime status sources, the SFCs/SFBs that surface them, and the standard approach used to forward the information to WinCC flexible, WinCC, or a plant SCADA system. Field-proven configurations, common pitfalls, and concrete STL/SCL call examples are included.
Siemens S7-300F Diagnostic Architecture
CPU and module status in an S7-300/400 is not concentrated in a single memory area. Instead, it is distributed across three layers that the user program can sample at runtime:
- Event-driven: Organization Blocks (OBs). The operating system calls a specific OB when a defined fault, interrupt, or restart event occurs. Local variables declared in the OB's interface give the event timestamp, the logical base address, the channel, and the error code.
-
Polled: System state lists via SFC51 "RDSYSST". A long list of static or slowly-changing data (LED states, communication status, module identification, diagnostic buffer) is read on demand by passing the corresponding
SSL_IDto the call. - Process-image level: Status word (STW), accumulator flags, and F-channel passivation bits. These are read with normal bit/byte logic just like any input or memory bit.
For monitoring only, SFC51 covers most requirements. For guaranteed capture of a transient diagnostic event, an OB is mandatory - by the time the user program polls for the event, it may already have been cleared by the operating system.
Diagnostic Organization Blocks (OBs)
The S7-300 operating system invokes the following OBs automatically. If the OB is not present in the project and a triggering event occurs, the CPU transitions to STOP unless a default OB (e.g., OB 121/122) is allowed. Always load every diagnostic OB you might need, even if the body is empty, so that the system event is logged and execution continues.
| OB | Name | Trigger | Key local variables | Why it matters |
|---|---|---|---|---|
| OB 1 | Main cyclic | Free cycle, low priority | OB1_PREV_CYCLE, OB1_MIN_CYCLE, OB1_MAX_CYCLE, OB1_DATE_TIME | Direct scan-time read in DINT ms. |
| OB 10 | Time-of-day | Configured TOD interrupt | OB10_DATE_TIME | Time-stamped action. |
| OB 35 | Cyclic interrupt | Default 100 ms | OB35_PHASE_OFFSET | Jitter-free periodic task. |
| OB 40 | Hardware interrupt | DI/AI threshold, count | OB40_MDL_ID, OB40_POINT_ADDR, OB40_FLT_ID | Per-channel fault capture. |
| OB 55 | Status interrupt | PROFIBUS/PROFINET status | OB55_MDL_ID, OB55_FLT_ID | DP/PN slave diagnostics. |
| OB 56 | Update interrupt | Slot update event | OB56_MDL_ID, OB56_FLT_ID | PROFINET slot update. |
| OB 57 | Vendor interrupt | Vendor-specific | OB57_MDL_ID, OB57_FLT_ID | Optional 3rd-party diagnostics. |
| OB 80 | Time error | Scan-time overrun, OB overflow | OB80_FLT_ID, OB80_ERROR_INFO, OB80_DURATION | Detects cycle overrun; causes STOP if not loaded. |
| OB 82 | Diagnostic interrupt | Channel error on DI/DO/AI/AO | OB82_MDL_ADDR, OB82_FLT_ID, OB82_IO_FLAG, OB82_LEN, OB82_DIAG[0..7] | Most common source of per-channel diagnostics. |
| OB 83 | Insert/Remove | Module pull/plug in RUN | OB83_MDL_ID, OB83_FLT_ID | Confirms hot-swap events. |
| OB 84 | CPU hardware fault | MPI/PN interface error, MMC fault | OB84_MDL_ID, OB84_FLT_ID, OB84_DIAG[0..3] | MMC error or interface fault. |
| OB 85 | Program execution | Unloaded OB call, image update fail | OB85_FLT_ID, OB85_DIAG[0..3] | Often raised when a programmed OB is missing. |
| OB 86 | Rack/Station failure | PROFIBUS slave / PROFINET device loss | OB86_MDL_ADDR, OB86_FLT_ID, OB86_DIAG[0..3] | Detects down DP slaves/PN devices. |
| OB 87 | Communication error | GD/PN frame error | OB87_FLT_ID, OB87_DIAG[0..3] | Time-sync / PN frame errors. |
| OB 100 | Warm restart | Power-up, mode selector MRES | OB100_STOP, OB100_STRT_INFO | Run-up routines. |
| OB 101 | Hot restart | OB 101 only on S7-400 | n/a on S7-300 | Not supported on CPU 315F-2PN/DP. |
| OB 102 | Cold restart | Power-up with cold-restart request | OB102_STOP, OB102_STRT_INFO | Reinitialise non-retentive. |
| OB 121 | Programming error | BCD conversion, range, type errors | OB121_FLT_ID, OB121_SW_FLT, OB121_BLK_TYPE, OB121_BLK_NUM, OB121_PRG_ADDR, OB121_OPCODE | Source line-level error capture. |
| OB 122 | I/O access error | Direct I/O read/write on missing module | OB122_FLT_ID, OB122_SW_FLT, OB122_BLK_TYPE, OB122_BLK_NUM, OB122_IO_ADDR, OB122_POINT_ADDR | Periphery access errors. |
| OB 123 | Failure F-CPU (F-only) | Internal F-runtime error | OB123_FLT_ID | Used by F-library runtime. |
STL skeleton for an OB 82 diagnostic handler (ladder / FBD is also accepted by Step 7):
FUNCTION_BLOCK FB_DiagInt
VAR_TEMP
t_info : DATE_AND_TIME;
w_flt : WORD;
w_mdl : WORD;
b_io : BOOL;
i_len : INT;
ad : ARRAY[0..7] OF BYTE;
END_VAR
BEGIN
t_info := OB82_DATE_TIME; // 8 bytes BCD - feed to DTL conversion
w_flt := OB82_FLT_ID; // Identifies incoming vs outgoing fault
w_mdl := OB82_MDL_ADDR; // Logical base address of the module
b_io := OB82_IO_FLAG; // 0 = input, 1 = output
i_len := OB82_LEN; // Length of diagnostic data in bytes
ad := OB82_DIAG; // Up to 8 bytes of channel-specific diag
// Forward to a global status DB and to WinCC flexible tag list
"dbStatus".diagFlg := TRUE;
"dbStatus".lastOB82FltId := w_flt;
"dbStatus".lastOB82Mdl := w_mdl;
// Set the global "report to SCADA" marker
"dbStatus".newDiagPending := TRUE;
END_FUNCTION_BLOCK
OB82_DIAG (or 16-byte OB82_DIAG as returned on some modules) into a global DB. Splicing the channel-by-channel error requires the module's channel structure manual, which is referenced in the Siemens Industry Online Support entry for each article number. Truncating the diagnostic array to one or two bytes discards the actual fault reason.SFC51 "RDSYSST" - System State Lists
SFC51 is the single most powerful diagnostic call on the S7-300. It returns partial system state lists (SSLs) that the user program can poll at any time. The call signature in STL is:
CALL SFC 51
REQ := TRUE // or a rising edge for one-shot reads
SSL_ID := W#16#0019 // requested SSL
INDEX := W#16#0000 // element index within the SSL
RET_VAL:= MW 200 // error code
BUSY := M 201.0
SSL_HEADER := DB_Hdr // STRUCT: DWORD length, WORD SSL_ID
DR := P#DB_List.DBX0.0 BYTE 40 // destination area
NOP 0
The DR (destination) area must be at least as long as the SSL entry plus the 6-byte SSL header. Always size the destination DB to the maximum entry length reported for your CPU; if too small, SFC51 returns W#16#8544 (destination area too small) without writing the data.
Common SSL_IDs for Runtime Status
| SSL_ID | Name | Returned info (per element) | Typical use |
|---|---|---|---|
| W#16#0000 | List of all available SSLs | WORD SSL_ID, DWORD length | Discover which SSLs the CPU supports. |
| W#16#0011 | Module identification | BYTE rack, BYTE slot, BYTE submodule, DWORD article no., BCD version | Confirm installed article numbers. |
| W#16#0012 | CPU characteristics | MC7 capabilities, OB list supported | Discover runtime capability set. |
| W#16#0013 | User memory areas | Code/data/M-bit/Timer/Counter sizes | Map process to remaining memory. |
| W#16#0014 | System areas | Process image, communications byte count | Map periphery boundaries. |
| W#16#0015 | Block types | Type code, count of blocks per type | List FB/FC/DB inventory. |
| W#16#0019 | Status of all LEDs (CPU) | 1 byte per LED state, 1 byte per LED colour | Mirror SF / BF1 / BF2 / RUN / STOP / FRCE / MSTR / REDF. |
| W#16#001C | Component identification | Vendor, family, type, serial | Asset tracking. |
| W#16#0022 | Interrupt status | BOOL flags per interrupt class | Track which interrupts are pending or lost. |
| W#16#0024 | Communication status data | State of PN/DP/MPI interfaces | Detect partial network outages. |
| W#16#0031 / 0131 | Status of all module LEDs | Per-module LED state + colour | Whole-station LED mirror. |
| W#16#0092 | Diagnostic buffer | 20-byte events (timestamp, event ID, event info) | Sequenced fault log. |
| W#16#00A0 | Diagnostic buffer (S7-400 alt.) | Same structure as 0x0092 | Used on S7-400 only. |
| W#16#00B1 / 0x0F31 | Module status info | WORD status, WORD slot | Identify faulty modules. |
| W#16#00B2 | Diagnostic data of a module (DS0/DS1) | Module-specific diagnostic record | Channel-level detail. |
| W#16#00B4 | Diagnostic data of a DP slave | Per slave, DS0/DS1 | DP slave channel info. |
| W#16#0132 | Communication status PN | PN port state, link, speed | PROFINET port status. |
| W#16#0174 | Time of day, 8-byte BCD | DTL equivalent | Read CPU clock without SFC1. |
Notes on the LED SSL (W#16#0019): the returned data is six bytes per CPU: the first two bytes encode state (0 = LED off, 1 = LED on, 2 = LED flash slow, 3 = LED flash fast), the second two bytes encode colour (0 = green, 1 = yellow, 2 = red, 3 = white, 4 to 6 = vendor-specific). For the 315F-2PN/DP the relevant LEDs are SF (group fault), BF1 (PROFIBUS DP), BF2 (PROFINET 1), BF3 (PROFINET 2 on two-port CPUs), RUN, STOP, FRCE (force active), MSTR (master on PN ring), and REDF (PROFIsafe / F-error). The reference PDF for decoding these into the HMI was the entry referenced in the original task - see Siemens Industry Online Support entry 22727527 and 9985721 for the S7-300 / S7-400 mapping tables.
SFC51 RET_VAL error codes
| RET_VAL (hex) | Meaning | Recommended action |
|---|---|---|
| 0000 | Function executed without error | Process DR contents. |
| 80A1 | SSL_ID not valid for this CPU | Replace with another SSL_ID; 0x0000 lists valid IDs. |
| 80A2 | INDEX not valid | Re-issue with INDEX = 0; for indexed SSLs, check range. |
| 80A3 | SSL_ID not supported in this operating state | Wait for RUN; some SSLs unavailable in STOP. |
| 80A4 | SSL_ID is read-protected | Enable read protection, or skip this SSL. |
| 80B1 | Module does not exist / wrong slot | Check rack/slot in INDEX. |
| 80C1 | No diagnostic data available | Module has not raised a diagnostic event yet. |
| 8542 | BUSY = FALSE too early; retry | Call again; only sample when BUSY = FALSE. |
| 8544 | Destination area too small | Enlarge DB; 6-byte header + max entry length. |
| 8090 | CPU in STOP, no data | Buffer call; release when RUN returns. |
Reading the Diagnostic Buffer (SSL 0x0092)
The diagnostic buffer is the most valuable runtime snapshot for post-incident analysis. It is a ring of up to 100 (CPU 315F-2PN/DP) or 200 (CPU 317 / 319) entries; each entry is 20 bytes:
- Bytes 0-7: 8-byte BCD timestamp (year/month/day/hour/minute/second/millisecond)
- Bytes 8-9: WORD event ID
- Bytes 10-11: WORD event class (OB number, error class, etc.)
- Bytes 12-15: DWORD event information 1 (e.g., logical address)
- Bytes 16-19: DWORD event information 2 (e.g., channel code)
Use SSL_ID = W#16#0092, INDEX = W#16#0001 for "all events of oldest first" or higher indexes for newer entries. RET_VAL indicates the number of bytes returned. Common event IDs that surface in production:
| Event ID (hex) | Meaning |
|---|---|
| 0x2520 | CPU STOP due to OB80 (time error) |
| 0x2521 | CPU STOP due to priority class error |
| 0x2522 | CPU STOP due to OB85 (program execution error) |
| 0x2523 | CPU STOP due to OB122 (I/O access error) |
| 0x2540 | Battery exhausted (F-CPU with battery-buffered RTC) |
| 0x2541 | Backup battery voltage low |
| 0x3576 | PROFINET IO device failure |
| 0x3582 | DP slave failure |
| 0x39A1 | Diagnostic interrupt incoming (OB82) |
| 0x39A2 | Diagnostic interrupt outgoing (OB82) |
| 0x3F32 | Operating state change to RUN |
| 0x3F33 | Operating state change to STOP |
| 0x4A11 | MMC/MCC card removed (if hot-swap capable) |
| 0x4A12 | MMC/MCC card write-protected |
| 0x4A18 | MMC/MCC card read error (often: card damaged) |
| 0x4E10 | F-runtime group error (F-CPU specific) |
| 0x4E11 | PROFIsafe channel passivated (F-CPU specific) |
On a 315F-2PN/DP, the absence of an MMC card is reported as event 0x4A18 when the card is unreadable. Note that the operating system cannot fully load the project into work memory without a working MMC, so once the card fails the user code is not executing. Therefore polling for "MMC error" is mostly useful for capturing the last diagnostic-buffer entry before the CPU goes to STOP, or for early warning if the card begins to return intermittent read errors (visible as OB84 plus event 0x4A12 / 0x4A18).
Reading Scan Cycle Time
The current, minimum, and maximum scan time are available without any SFC call - they are exposed as local variables in OB 1 (the main cyclic OB):
// Inside OB 1
L OB1_PREV_CYCLE // Last cycle time, in milliseconds (DINT)
T "dbStatus".currCycleMs
L OB1_MIN_CYCLE // Shortest since last STOP-RUN
T "dbStatus".minCycleMs
L OB1_MAX_CYCLE // Longest since last STOP-RUN
T "dbStatus".maxCycleMs
Step 7 / TIA Portal also reports the cycle time in the online > module information dialog. Programmatic extraction via OB1 is preferred when the value must be reported to a higher-level system, because the HMI/SCADA can read the value as a regular tag without needing the engineering tool.
OB80_CYCLE_TIME inside OB 80. Always set the maximum to 3 to 5 times the typical scan to absorb transient overruns without forcing a STOP.Status Word (STW) and Bit-Level Status
The S7-300 / S7-400 status word is a 9-bit field accessible as bits in the local STW structure. It is read by the OB as it is entered, and it is the same field that drives the LED indicators for the conditional BR memory area:
| Bit | Symbol | Meaning | When to use it |
|---|---|---|---|
| 0 | /FC | First check (negated) - first operation after a block boundary | Detecting edge conditions on first instruction in a block. |
| 1 | RLO | Result of logic operation | Cascading boolean conditions. |
| 2 | /STA | Status of addressed bit (negated) | Reflects addressed input/output. |
| 3 | /OR | OR of the AND stack (negated) | Used by FBD / LAD compiler for nested OR. |
| 4 | OS | Overflow stored (latched) | Persist math error across blocks. |
| 5 | OV | Overflow | Detect a single math error in the current block. |
| 6 | A0 | AND result bit 0 | Carry-out for word arithmetic. |
| 7 | A1 | AND result bit 1 | Result class for compare / math. |
| 8 | BIE | Binary result | Branch on the BR memory to gate FB/FC calls. |
The /ER (error) and VKE (RLO) bits are the legacy S7-200 / S7-300 names; in the 9-bit STW the equivalent encoding is at bits 5 (OV) and 1 (RLO). Sample read of OV at the end of a math block:
// At the end of a calculation block
A OV // bit from STW: bit 5
JCN NO_OV
S "dbStatus".mathOverflow // latched
L 0
T "dbStatus".mathResult // invalidate
NO_OV: NOP 0
LED Status Indicators on the CPU 315F-2PN/DP
The front of the CPU carries SF, BF, RUN, STOP, FRCE, and (on firmware V3.x) MSTR, REDF. The mapping between the live LED and the equivalent SSL_ID W#16#0019 byte is documented in the Siemens support PDF "Getting the Status for the CPU LED Indicators", entry ID 22727527 (S7-300), 9985721 (S7-400), and 24248266 (PROFINET IO extension). Each LED byte returns two sub-bytes (state, colour) that the HMI script can decode to the visual colour seen on the panel.
| LED | Indication when ON | Action in user program |
|---|---|---|
| SF | Group fault (hardware or diagnostic interrupt active) | Read OB82, set "unacknowledged fault" tag. |
| BF1 | PROFIBUS DP bus fault | Read OB86; check slave list. |
| BF2 | PROFINET 1 bus fault | Read OB86 and PROFINET SSL 0x0132. |
| BF3 | PROFINET 2 bus fault (two-port CPU) | Same as BF2 for the second port. |
| RUN | CPU in RUN | Mirror as "system running" bit. |
| STOP | CPU in STOP | Alarm escalation; do not write to outputs. |
| FRCE | Force active | Block operator actions on forced I/O. |
| MSTR | PN ring master (MRP) is active | Used by ring diagnostics only. |
| REDF | PROFIsafe / F-error on at least one F-channel | Read F-host DB; passivation active. |
F-CPU Specific Status Information (315F-2PN/DP)
The 315F-2PN/DP runs the F-library blocks (F-CPU, F-Safety, F-I/O). The runtime status of the safety layer is exposed through:
- F-host block FB 215 / FB 219 (F-runtime group). Inputs and outputs include a "PASS_ON" flag (passivation triggered), "QBAD" (substitute value active), "ACK_REQ" (operator acknowledgement required), and "IPAR_EN" (i-parameter assignment enabled).
- F-channel data block. Each F-module exchanges process values plus a per-channel quality byte. Bits in the quality byte (0x00 = valid, 0x40 = substitute, 0x80 = passivated, 0xC0 = invalid) are mirrored to WinCC flexible tags.
- Diagnostic events 0x4E10 and 0x4E11 in the diagnostic buffer. Capture them by SFC51 SSL 0x0092 and surface the F-event class to the SCADA.
The minimum and maximum PROFIsafe monitoring time must be respected. For the 315F-2PN/DP the default is 150 ms; reducing it below 50 ms risks spurious passivation on noisy networks, while raising it above 6000 ms delays fault detection. Siemens enforces a hard minimum of 1 ms and a hard maximum of 6000 ms for the F-monitoring time setting.
PROFINET IO and PROFIBUS DP Diagnostics
For per-channel diagnostics on a PROFINET device or PROFIBUS slave, the pattern is to call SFC 51 with SSL 0x00B2 (DP slave) or 0x00B4 (DP slave) for the diagnostic record, or to use the higher-level SFBs:
| SFC/SFB | Number | Purpose | Called from |
|---|---|---|---|
| SFC 13 "DPNRM_DG" | 13 | Read complete diagnostic record of a DP slave | OB1, OB82, OB86 |
| SFC 51 "RDSYSST" SSL 0x00B2 | 51 | Read DS0/DS1 of an I/O module | OB82, OB1 |
| SFB 52 "RDREC" | 52 | Read data record from a module or PN device | OB82, OB86, OB1 |
| SFB 53 "WRREC" | 53 | Write data record (e.g., to ACK PROFINET alarms) | OB82 (after fix) |
| SFB 54 "RALRM" | 54 | Read the latest PROFINET interrupt record | OB40, OB55-OB57 |
| SFC 59 "RD_REC" | 59 | Legacy read data record (S7-300 / 400 compatible) | OB82, OB1 |
STL pattern for OB 82 to read PROFINET channel diagnostics using SFB 52:
// In OB 82
CALL SFB 52, DB52Inst
REQ := TRUE
IOID := OB82_IO_FLAG // 0 = input, 1 = output, 2 = mixed (PN device)
LADDR := OB82_MDL_ADDR // Logical base address of the device
RECNUM := B#16#00 // 0 = DS0 standard diagnostics
RET_VAL := MW210
BUSY := M211.0
RDREC := P#DB_DiagBuf.DBX0.0 BYTE 240
NOP 0
The complete DS0 record is six bytes (channel status flag byte, channel number byte, channel error byte, channel error info byte, interrupt status byte, sequence number byte). DS1 is the manufacturer-specific extended diagnostics. The decoding tables are in the manual for the relevant I/O module - search the article number (e.g., 6ES7321-1BH02-0AA0) in Siemens Industry Online Support and select "Diagnostics" in the product tree.
WinCC flexible and WinCC Integration
There are three common ways to display the runtime status on a WinCC flexible panel or in WinCC:
-
HMI tags connected to the status DB. Create a WinCC flexible tag list and link each bit/byte in
dbStatusto an HMI tag with the standard acquisition cycle (default 1 s). The OB handlers in OB 80, 82, 84, 86 set the bits; WinCC flexible displays them. The reference entry is the FAQ "How can you have system error messages from a SIMATIC S7-300/400 displayed in WinCC flexible?" in Siemens support. - WinCC "Alarm Logging" via SFC 17/18 "ALARM_SQ" and "ALARM_DQ". These send a defined event text to the HMI alarm log. The user program passes the event ID and an associated value list; WinCC formats the message with the configured text. Use this for unbounded error texts that depend on the OB arguments.
- Area pointer "Coordination" and "Job mailbox". The WinCC area pointer "Coordination" carries 1 byte that reflects the PLC life sign, mode selector, and connection state. The "Job mailbox" pointer is used for screen selection rather than status, but is often configured together with status tags.
Concrete recipe for "system error message to WinCC flexible":
- Create a global FB "FB_DiagDispatcher" with input
i_eventClass(BYTE) andi_eventID(WORD). - Inside the FB, call
SFC 17 "ALARM_SQ"withEV_ID := 1,SD := local event data. The HMI will receive the alarm. The corresponding text in WinCC flexible / WinCC Alarm Logging referencesEV_ID 1with up to 10 associated values. - Inside WinCC flexible, configure an alarm message "@Event Class 0x10 / 0x11" and map the associated values to the OB arguments (logical address, channel, error code).
- On the HMI screen, place an AlarmView control bound to the alarm log. Configure the message classes so that unacknowledged alarms flash red and acknowledged alarms become steady.
CPU_DIAGNOSE tag onto the screen.Mapping the Status to a Plant SCADA
For integration with WinCC, PCS 7, TIA Portal HMI, or a third-party SCADA, the recommended pattern is a small "PLC status FB" that fills a fixed-layout status DB. The SCADA tag list is then generated from the status DB, and the HMI script decodes the fields. A typical layout:
| Offset | Name | Type | Source |
|---|---|---|---|
| DBB 0 | cpuState | BYTE | SFC51 SSL 0x0019 (LED state) |
| DBB 1 | cpuLedColor | BYTE | SFC51 SSL 0x0019 (LED colour) |
| DBW 2 | currCycleMs | INT | OB1_PREV_CYCLE |
| DBW 4 | minCycleMs | INT | OB1_MIN_CYCLE |
| DBW 6 | maxCycleMs | INT | OB1_MAX_CYCLE |
| DBW 8 | ovfFlag | INT | STW.OV (1 = overflow) |
| DBW 10 | osFlag | INT | STW.OS (1 = latched overflow) |
| DBB 12 | lastOB82Flt | BYTE | OB82_FLT_ID |
| DBB 13 | lastOB82Io | BYTE | OB82_IO_FLAG |
| DBW 14 | lastOB82Addr | WORD | OB82_MDL_ADDR |
| DBB 16..23 | lastOB82Diag | 8 BYTE | OB82_DIAG[0..7] |
| DBB 24 | lastOB86Flt | BYTE | OB86_FLT_ID |
| DBW 26 | lastOB86Addr | WORD | OB86_MDL_ADDR |
| DBB 28 | lastOB84Flt | BYTE | OB84_FLT_ID |
| DBB 29 | newDiagPending | BOOL | Set by any OB handler |
| DBB 30 | forceActive | BOOL | SFC51 SSL 0x0019 / FRCE LED |
| DBB 31 | redfActive | BOOL | SFC51 SSL 0x0019 / REDF LED |
| DBD 32 | lastErrorTime | DTL | OB82_DATE_TIME etc. |
Stamp the time using SFC 0 "SET_CLK" synchronisation, or read the time with SFC 1 "READ_CLK" for an 8-byte BCD and convert to DTL in the SCADA. The DTL structure was added in firmware V3.0 of the S7-300, and is the recommended field for any new project.
Comparison with Mitsubishi MELSEC Special Relays
Engineers coming from Mitsubishi will be used to a flat list of special relays (SM) and special registers (SD) that the CPU updates on its own. The Siemens approach is event-driven via OBs rather than polled via a memory map, but the information is comparable. The mapping is approximate:
| Mitsubishi (Q / iQ-R / A) | Meaning | Siemens S7-300/400 equivalent |
|---|---|---|
| SM0 / SM400 (always ON) | Always-1 bit | TRUE constant or OB1 infinite loop |
| SM53 / SM53A (AC fail) | Momentary power loss | OB81 (power error); not implemented on 315F-2PN/DP |
| SM100..SM199 (scan timing) | Scan time, low/high-speed counters | OB1_PREV_CYCLE / OB1_MIN_CYCLE / OB1_MAX_CYCLE |
| SM200..SM299 (clock) | Year, month, day, hour, minute, second | SFC1 "READ_CLK" / SFC0 "SET_CLK" |
| SM400..SM499 (error flags) | Annunciator, fuse blown, battery low | OB82 (diagnostic interrupt), OB84 (hardware fault), OB86 (rack/DP), diagnostic buffer 0x0092 |
| SD0..SD199 (registers) | Scan time, error code, clock | Status DB built by SFC51, OB1, OBs |
| SM0 (initial pulse) | First scan | OB100 / OB101 / OB102 startup bits |
| M8000 (RUN) | RUN mode | SFC51 SSL 0x0019 (RUN LED), or OB1 is being executed |
| SD8030..SD8037 (current error) | Error code registers | SSL 0x0092 diagnostic buffer event ID + event info |
Best Practices and Field-Proven Caveats
- Load all OBs you might need - even empty OBs. An unprogrammed OB 82 keeps the CPU in RUN on a diagnostic interrupt; a missing OB 82 takes the CPU to STOP. The empty-OB pattern is standard on F-CPU installations.
-
Always capture the entire diagnostic array. Splicing
OB82_DIAGto one byte destroys channel resolution and makes root-cause analysis impossible. - Use the diagnostic buffer as ground truth. When an error log from a third-party HMI disagrees with the SCADA, the buffer entry is the source of record. It survives power-cycles and is the official event log.
- Set OB80 cycle time to 3-5x the typical scan. The default of 150 ms on the 315F-2PN/DP is conservative; on a fast 20 ms cycle, a 100 ms maximum still gives a 5x safety factor while preserving short fault response.
- Don't poll SFC51 at 100 ms. SFC51 is not free; calling it on a 100 ms cycle adds 1-2% of CPU load. Use a 1 s scan or call on operator request.
- Watch the F-monitoring time. Reduce it only if the network is clean; the PROFIsafe V2 protocol tolerates a worst-case jitter up to the F-monitoring time minus the F-WD-time of the module.
- Mirror the LED bytes, not just the LED colour. A flashing yellow SF and a steady red SF have different states in SSL 0x0019; treat them as distinct alarms.
- Document the SSL_IDs you use. Some IDs are CPU-family-specific (0x00A0 is S7-400 only). Use the SSL 0x0000 list at project start to discover which ones are supported.
- Synchronise the clock to a network time source. The 315F-2PN/DP supports NTP via the "Time of Day" interface. Without sync, the diagnostic buffer timestamps are useless across shifts.
-
Force a STOP on critical F-events. When a safety-relevant event occurs (F-channel passivated, OB123 triggered), consider routing the application to a controlled stop using
SFC 46 "STP"only after the safety group is in a defined state; do not stop mid F-cycle.
Troubleshooting Matrix
| Symptom | Most likely cause | First place to look |
|---|---|---|
| SF LED steady on, BF off | Channel-level diagnostic on an I/O module | OB82 entry; SSL 0x0092 last 5 entries |
| BF1 LED flashing | PROFIBUS DP slave lost or wiring fault | OB86 event ID 0x38xx; SSL 0x00B4 |
| BF2 / BF3 LED on | PROFINET device loss or port down | OB86 event ID 0x35xx; SSL 0x0132 |
| REDF LED on, F-channel flags set | PROFIsafe channel passivation | Diagnostic buffer 0x4E11; F-host DB PASS_ON |
| CPU in STOP, no SF | Programmed but missing OB | OB85 entry; check OB80/82/84/86/87 |
| Diagnostic buffer shows 0x4A18 | MMC card read error or removed | Power-cycle with valid MMC; card may be corrupt |
| OB1_MAX_CYCLE keeps rising | Communication stack overload | Check PN load, no. of SFB calls, cyclic OB period |
| WinCC flexible shows status with 1 s delay | Acquisition cycle too long | Set WinCC flexible acquisition to 100 ms for fast tags |
| SFC51 returns 0x8544 | Destination DB too small | Enlarge DR area; include 6-byte header + max entry |
| SFC51 returns 0x80A1 | SSL_ID not supported on this CPU | Use SSL 0x0000 first to enumerate supported IDs |
Frequently Asked Questions
What is the simplest way to read the current scan time of a CPU 315F-2PN/DP?
Read the temporary variable OB1_PREV_CYCLE at the start of OB 1. The value is a DINT in milliseconds. For minimum and maximum, use OB1_MIN_CYCLE and OB1_MAX_CYCLE. These reset on STOP -> RUN.
How do I detect a missing or faulty MMC card from the user program?
The CPU cannot fully run user code without a working MMC, so the only practical check is via the diagnostic buffer. Read SFC 51 with SSL_ID = W#16#0092 and look for event ID 0x4A18 (MMC read error) or 0x4A11 (card removed). OB 84 also fires on CPU hardware faults and contains a FLT_ID of 0x1000 to 0x10FF for MMC errors.
Which OBs are mandatory for a 315F-2PN/DP system with both F and standard I/O?
At minimum, load OB 82 (diagnostic interrupt), OB 84 (CPU hardware fault), OB 85 (program execution), OB 86 (rack / station failure), OB 87 (communication error), OB 100 (warm restart), OB 121 (programming error), and OB 122 (I/O access error). For F-signals, leave the F-library OBs as the F-library generates them automatically; the user program does not need to write any F-specific OBs.
Can I read the LED state of the CPU from the user program?
Yes - call SFC 51 "RDSYSST" with SSL_ID = W#16#0019. The returned data contains two bytes per LED: state (0 = off, 1 = on, 2 = flash slow, 3 = flash fast) and colour (0 = green, 1 = yellow, 2 = red). The reference PDF for the LED mapping is entry 22727527 (S7-300) or 9985721 (S7-400) in Siemens Industry Online Support.
Why does the CPU go to STOP on a module diagnostic when I have not yet downloaded OB 82?
S7-300/400 OBs that are not loaded but are required by an event cause the CPU to enter STOP. This is intentional - it prevents an unhandled error from being silently ignored. Always download every diagnostic OB (even with an empty body) for all events that can occur in your plant.
How can I see the diagnostic buffer from WinCC flexible without writing extra user code?
In WinCC flexible / WinCC Comfort, the area pointer "Coordination" and the predefined tag @CPU_diagnose surface a subset of the diagnostic buffer automatically. Enable the diagnostic session on the connection, and WinCC flexible will display the LED status and the last diagnostic-buffer entry as standard HMI objects. For full access to all 100 entries, call SFC 51 in the user program and forward the data into a status DB that the HMI reads.
What is the F-monitoring time and how do I configure it on the 315F-2PN/DP?
The F-monitoring time is the maximum interval between two valid PROFIsafe telegrams. Default is 150 ms; minimum 1 ms; maximum 6000 ms. Configure in HW Config under the F-host properties. A value lower than the worst-case network latency will cause spurious passivation. The actual current value is available inside the F-host DB for SCADA visibility.