S7-1200 OB40 Not Triggering on PROFINET Disconnect: Use OB82

David Krause10 min read
S7-1200SiemensTroubleshooting
Licensed PE Working through this on a live machine? A Maine-licensed engineer can take it from here — included with IMD hardware, by the hour for everything else. Book an engineer

S7-1200 OB40 Not Triggering on PROFINET Disconnect: Use OB82

Symptom: An OB40 (hardware interrupt OB) is created in TIA Portal V14 for an S7-1200 CPU 1212C DC/DC/DC (6ES7 212-1BD30-0XB0) to detect the unplugging of a PROFINET IO device, but the OB body never executes when the device is removed from the network. The MOVE instruction placed inside the OB remains inactive and no program scan ever reaches the OB. The fault persists even though the project is downloaded without errors and the PROFINET device is configured and online.

Engineering Conclusion: OB40 is the wrong organization block for PROFINET device diagnostics on an S7-1200. OB40 services hardware interrupts from local digital inputs (rising edge, falling edge, HSC threshold events). PROFINET device removal generates a diagnostic error interrupt, which on S7-1200 is handled by OB82 only.

1. Affected Hardware, Firmware and Software

Item Value Notes
CPU SIMATIC S7-1200 CPU 1212C DC/DC/DC MLFB 6ES7 212-1BD30-0XB0
Firmware (typical) V4.0 / V4.1 / V4.2 OB82 available from FW V4.0 onward
Work memory 50 KB Loadable + work memory, integrated
Bit memory (M) 4096 bytes Retainable area configurable
I/O address area 1 KB I / 1 KB Q Process image limits
PROFINET interface 1 × RJ45, 2-port switch Single PN interface, IO controller
Max. PN IO devices 16 (FW V4.x) Per PROFINET interface
Engineering TIA Portal V14 (V14.0.0.0+) Same fix applies to V13, V15, V16, V17, V18
Documentation S7-1200 System Manual, edition 2017-09 Article ID 109772940

Reference: S7-1200 Programmable Controller System Manual (Siemens Support, 109772940).

2. Why OB40 Is Incorrect for PROFINET Diagnostics

The S7-1200 OB40 is the hardware interrupt OB. Per the TIA Portal documentation for hardware interrupt OBs 40–47, hardware interrupts are generated by:

  • Rising-edge events on local digital inputs (DI).
  • Falling-edge events on local digital inputs.
  • High-Speed Counter (HSC) threshold-value CV = RV events.
  • Comparators on the onboard analog inputs (CPU 1214C / 1215C / 1217C only).
  • PTO (Pulse Train Output) finished events on FW V4.1+.

A PROFINET device disappearing from the network is none of these. It is an I/O subsystem-level fault (an IO device going to station failure or diagnosis from station). For S7-1200 / S7-1500 this triggers a diagnostic interrupt, dispatched through OB82 on the CPU. On S7-300/400 the same class of fault would also reach OB86 (rack / IO-device failure OB); however, S7-1200 only supports OB82 and does not provide OB86.

On TIA Portal V14 with an S7-1200, the "Add new organization block" dialog will offer OB82 (Diagnostic error interrupt) but will not offer OB86. If you only see OB82 in the list, that is expected — OB86 is not implemented on this CPU family.

3. Root Cause Analysis

When the field engineer unplugs a PROFINET IO device, the IO controller observes the link-down event and raises a PROFINET alarm. The CPU converts that alarm into an OB call based on the alarm class:

Alarm class (PROFINET) Trigger condition Called OB on S7-1200
Diagnosis (incoming / outgoing) Channel fault or module diagnostic on an IO device OB82 (Diagnostic error interrupt)
Station failure Whole IO device unreachable / removed OB82 (S7-1200 does not differentiate OB86)
Process alarm Vendor-specific event from IO device No native OB on S7-1200 — poll via SFB54 RALRM
Hardware interrupt (rising / falling edge) Local DI edge or HSC event OB40 (hardware interrupt OB)

Because the engineer placed the detection logic in OB40, and OB40 is not bound to any PROFINET alarm source, the OB is never scheduled. The MOVE inside the OB therefore never runs.

4. Required Configuration of OB82

OB82 is supported on every S7-1200 CPU whose firmware is V3.0 or newer. The OB is generated through the project tree:

  1. Project tree → PLC_1 → Program blocks → Add new block → Organization block → Diagnostic error interrupt (OB82).
  2. Open the OB82 editor; the local temp variables LADDR, IOSTS, Channel, MultiError, EventClass, FaultId, EvId are pre-declared.
  3. Implement the required MOVE (or function call) in the OB body.
  4. In every called function block (FB/FC) used inside OB82: open Block properties → Attributes and deselect "Handle errors within the block" (Handle errors locally = OFF). If "Local error handling" is enabled for an FB called by OB82, the diagnostic call chain stops at that block and OB82 is not re-entered.
  5. Compile and download the project to the CPU in STOP, then switch back to RUN.

5. Reading PROFINET Diagnostic Data with SFB54 (RALRM)

To identify which device failed, read the diagnostic record from inside OB82 with the RALRM instruction (SFB54 on S7-1200 / S7-1500, identical interface):

// ST inside OB82
// Inputs
#RALRM_ID := 0;          // 0 = call from OB, 1..n = handle from previous call
#MODE := 1;              // 1 = read all output parameters
#F_ID := 0;              // not used when called from OB
#MLEN := 100;            // max length of diagnostic buffer
#NEW_PTR := FALSE;       // not used when called from OB
#TINFO := #tInfo;        // 34 bytes of task info
#AINFO := #aInfo;        // 34 bytes of ACK info
#LEN := #iLen;           // actual length returned
#STATUS := #wStatus;     // status word

IF #STATUS = 0 THEN
    // #tInfo.IO_STATE / #tInfo.IO_TYPE / #tInfo.LEN give channel info
    // #aInfo[0..3] is slot, #aInfo[4..5] is submodule ID, #aInfo[6..7] is alarm specifier
    // Evaluate #iLen bytes for the raw channel diagnostic record
    // AINFO[0] = ChannelNumber
    // AINFO[1..2] = ChannelProperties (bit 0..15)
    // AINFO[3..4] = ChannelErrorType
END_IF;
Call SFB54 with MODE = 0 inside OB82 (no parameter F_ID). MODE = 1 is only valid when called from a user program with a valid F_ID handle obtained from a prior MODE = 0 call. Returning MODE = 2 lets you reject the alarm (only available on S7-1500; on S7-1200 the alarm is always acknowledged automatically).

6. Hardware Interrupt OBs 40–47 — When They Are Right

If the requirement is genuinely a hardware interrupt (not a PROFINET diagnostic), then OB40 on S7-1200 is configured through the device view of the DI module, not through OB82.

Step Action Where
1 Open the CPU or SB/SM in the device view Devices & networks → PLC → DI module
2 Select the channel (I0.0 .. In.x) Properties → Inputs → Channel template
3 Enable "Hardware interrupt" on rising edge / falling edge Properties → Inputs → Interrupt settings
4 Create OB40 (Program blocks → Add new block → Organization block → Hardware interrupt) Program blocks
5 Attach the OB40 to the event with ATTACH / DETACH or via the HW identifier Implicit by configuration in TIA V14+

From the TIA Portal help for hardware interrupt OBs, the available instructions for runtime control of OB40–OB47 are:

Instruction (S7-300/400) S7-1200 equivalent Purpose
DIS_IRT (SFC 30) EN/DIS via system clock word or ATTACH/DETACH Disable all hardware interrupt OBs from being called
EN_IRT (SFC 31) EN_IRT (FW V4.2+) Re-enable all hardware interrupt OBs
DIS_AIRT (SFC 32) DIS_AIRT (FW V4.2+) Delay higher-priority OBs / interrupts
EN_AIRT (SFC 33) EN_AIRT (FW V4.2+) Re-enable higher-priority interrupts

The runtime instruction set is identical on S7-1200 FW V4.2 and later. For earlier FW V4.0/V4.1, hardware interrupts are enabled by default; an SFC 30–33 call returns an "Instruction not supported" error and can be ignored.

7. Step-by-Step Conversion: OB40 → OB82

  1. Open the project in TIA Portal V14.
  2. Right-click Program blocks → Add new block → Organization block → Diagnostic error interrupt → confirm OB82.
  3. Cut the MOVE (or call to a function) from the original OB40 and paste it into OB82.
  4. Delete the obsolete OB40 from the project tree (right-click → Delete → confirm).
  5. Open each FB/FC that the OB now calls. In Properties → Attributes uncheck "Handle errors within the block". Save and rebuild.
  6. Place a watch-table tag of type Bool that you set inside OB82 (e.g. "PN_Fault_Active" := TRUE) so you can verify in online mode that the OB has been called.
  7. Compile the project (Project → Compile all). Resolve any errors flagged in the messages window.
  8. Download to the S7-1200 in STOP, switch to RUN.
  9. In online & diagnostics, expand Online & Diagnostics → PROFINET interface → Diagnostics to see the live device list.

8. Commissioning Verification

  1. Go online with the CPU (Online → Go online).
  2. Open the watch table that monitors PN_Fault_Active.
  3. Unplug the PROFINET device from the switch / cable. Within ≤ 200 ms the IO controller raises the diagnostic alarm.
  4. Verify that PN_Fault_Active transitions to TRUE and that the yellow SF (system fault) LED on the CPU lights.
  5. Reconnect the device. The alarm goes out, the SF LED clears, and OB82 is called a second time with the "incoming → outgoing" transition.
  6. If PN_Fault_Active remains FALSE after a 2-second wait, see the troubleshooting matrix in section 10.

9. Fault Code Reference (PROFINET Diagnostic Alarms)

ChannelErrorType (hex) ChannelErrorType (decimal) Meaning
0x0000 0 No error / data exchange normal
0x0010 16 Short circuit
0x0011 17 Undervoltage (sensor supply)
0x0012 18 Overvoltage (sensor supply)
0x0013 19 Overload
0x0014 20 Over-temperature
0x0015 21 Wire break
0x0016 22 Upper limit exceeded
0x0017 23 Lower limit undershot
0x0018 24 Error
0x0100 256 Communication error / station failure (whole device)
0x8000 32768 Manufacturer-specific diagnostic (refer to GSD file)

When a PROFINET device is unplugged, OB82 receives ChannelErrorType = 0x0100 with the slot / channel that maps to the IO device's interface submodule (slot 0, subslot 1 for the head module).

10. Troubleshooting Matrix

Symptom Likely cause Remedy
OB82 still not called after PN unplug Block property "Handle errors locally" enabled on a called FB Uncheck in each called FB/FC, recompile, re-download
OB82 called once only on plug, never on unplug Alarm OB queue overflowed by spam of a faulty device Reduce diagnostic alarm density in device; check for ground faults
CPU SF LED on, OB82 not called No OB82 downloaded (CPU in STOP did not get new OB) Download in STOP → RUN; verify block exists in online view
OB82 called but MOVE shows wrong value Indirect addressing on RALRM AINFO not byte-aligned Use AT-view or symbolic access; verify #iLen > 0
SF LED blinks 3-times pause 3-times pattern Distributed I/O fault with no error OB present Install OB82 (or OB86 on S7-1500)
IO device still reports "OK" after unplug Topology port is in ring / MRP and partner is forwarding frames Check PROFINET topology editor and disable MRP if not needed
OB82 called only for some devices Per-device "Report diagnostic interrupts" not enabled Open each IO device → Properties → Diagnostics → enable "Report diagnostic interrupts"

11. Standards and Documentation References

12. Safety and Design Considerations

Fail-safe applications: If the IO device is part of a PROFIsafe group, use OB82 only for logging. The actual PROFIsafe reaction is driven by the F-runtime and the F-CPU's safety program; do not implement safety actions in a standard OB82. See the S7-1200F System Manual for F-OB scheduling.

The OB82 priority is set in Properties → Attributes → Priority. Default priority 9 on S7-1200 is sufficient for diagnostic handling; raising it above the cyclic OB1 priority (1) does not interfere with PROFIsafe execution. Keep OB82 short — typically < 1 ms — to avoid jitter on time-critical alarms. If heavy processing is required, set a flag and process the diagnostic payload inside OB1.

Frequently Asked Questions

Why does OB40 not fire when I unplug a PROFINET device on S7-1200?

OB40 is the hardware interrupt OB and is bound to local DI edges or HSC threshold events only. A PROFINET device unplugging generates a diagnostic alarm serviced by OB82 (Diagnostic error interrupt) on the S7-1200. OB40 will never receive a PROFINET station-failure event.

Can I add OB86 (Rack/IO-device failure) to an S7-1200?

No. The S7-1200 CPU family does not support OB86 — TIA Portal's "Add new organization block" dialog does not offer it for S7-1200. Use OB82, which on S7-1200 covers both the diagnostic interrupt and the station-failure class of alarms.

What does "Handle errors within the block" mean for OB82?

When the attribute is enabled on a block called by OB82, that block intercepts any incoming error event and stops the diagnostic call chain at its boundary, so OB82 is not re-entered and the system-fault LED remains latched. Disable the attribute on every block involved in OB82 processing to keep the call chain intact.

How do I identify which PROFINET device triggered OB82?

Inside OB82 call SFB54 RALRM with MODE = 0 (from OB) and MLEN ≥ 34. Read the AINFO structure: bytes 0 = slot number, bytes 3–4 = channel, bytes 6–7 = alarm specifier, and the LADDR tag's high byte holds the logical base address of the IO device head module. Combine LADDR with the device list to identify the failed device.

Does OB82 run automatically with OB40?

No. OB82 and OB40 are independent OBs that are called only when their corresponding event class occurs. Adding OB40 does not invoke OB82, and adding OB82 does not invoke OB40. You must explicitly add the OB whose event matches your use case and download it to the CPU.

Back to blog