Programmatically Enable/Disable DP Slaves with SFC12 D_ACT_DP

David Krause11 min read
ProfibusSiemensTutorial / How-to
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

Programmatically Enable/Disable DP Slaves with SFC12 D_ACT_DP on S7-300/400

This reference details how to use the SIMATIC SFC12 D_ACT_DP instruction to dynamically activate and deactivate configured PROFIBUS DP slaves from the S7 user program. It is written for engineers who must deploy a single standard program that supports many DP slaves but only commissions a fraction of them per project, and who must avoid spurious Report System Error entries when slaves are not connected at startup.

The behavior described in this document was verified on a 6ES7 315-2FH10-0AB0 CPU running firmware V2.3.3 and was cross-checked against the 6ES7 315-2FH13-0AB0 firmware V2.5.1 release notes.

1. Problem Statement

When a STEP 7 hardware configuration (SDB container) contains more DP slaves than are physically present, the CPU raises the following symptoms at startup or during operation:

  • Bus fault (BF) LED on the CPU/master
  • Report System Error entries for the missing station
  • Diagnostic interrupts (OB82) repeating each power cycle
  • WinCC alarm log flooded with slave failure messages

The objective is to mark configured slaves as logically disconnected in the S7 user program so that the diagnostic state is recognized as a deliberate operator action rather than a network fault.

2. Prerequisites

Item Specification
CPU family S7-300 (CPU 31x), S7-400 (CPU 41x)
Tested CPU (PROFIBUS side) 6ES7 315-2FH10-0AB0 firmware V2.3.3
Tested CPU (PROFINET side) 6ES7 315-2FH13-0AB0 firmware V2.5.1
STEP 7 STEP 7 V5.5 SP4 or TIA Portal V13.1+
Required SFC SFC12 D_ACT_DP (part of standard library)
Diagnostic source DP slave diagnostic address configured in HW Config
Bus terminator Active PROFIBUS terminator required at last physical station
Important: The SFC12 instruction is available in the standard SIMATIC library since STEP 7 V5.1. It is not part of the F-library and is not safety-certified for PROFIsafe applications. It must not be used to bypass safety I/O replacement.

3. SFC12 D_ACT_DP Technical Reference

The D_ACT_DP instruction is documented in the Siemens function block help and in the Siemens Support entry 105020938. The instruction signature is identical in STEP 7 Professional V13.1 onward (see Siemens Support entry 109011420):

Parameter Declaration Type Description
REQ INPUT BOOL Edge-triggered start (rising edge required)
MODE INPUT BYTE 0 = check status, 1 = deactivate, 2 = activate
LADDR INPUT WORD Logical address of the DP slave (must be WORD, in hex)
RET_VAL OUTPUT INT Return value (0 = OK, error code on fault)
BUSY OUTPUT BOOL 1 = job still in progress

3.1 MODE Byte Encoding

MODE Action Resulting BF LED Diagnostic Buffer
B#16#00 Query only (no state change) Unchanged No entry
B#16#01 Deactivate slave Stays on if slave is physically present and fails "Deactivated by user" entry
B#16#02 Activate slave Reflects new physical state "Activated by user" entry

4. LADDR Parameter Rules

Three rules govern the LADDR input. Misapplication of any of these is the dominant cause of SFC12 timeouts in field installations.

  1. Data type: The parameter must be of type WORD. Passing an INT constant (for example 100) is rejected at compile time or returns error W#16#8090 at runtime.
  2. Format: The value must be expressed in hexadecimal. A diagnostic address of 100 decimal must be entered as W#16#0064.
  3. Address selection: The address may be either:
    • The diagnostic address of the DP slave (slot 0 in HW Config), or
    • The I/O address of any module in the station.
Field note: If the diagnostic address is used, set the slave's diagnostic address to a unique value (1024..32767) to avoid collisions with process I/O. The diagnostic address is the address reported in OB82 and in the diagnostic buffer.

5. LADDR Lookup Using SFC5 (GADR_LDB)

The PROFIBUS address (1..125) is not the same as the logical address. To obtain the correct LADDR from a PROFIBUS node number, call SFC5 GADR_LDB first:

SFC5 Parameter Direction Type Meaning
IOID INPUT BYTE B#16#00 = input area
LADDR INPUT WORD Base address of the slave's I/O (WORD)
AREA INPUT BYTE B#16#00 = process I/O
RET_VAL OUTPUT INT Return code
BUSY OUTPUT BOOL 1 = still in progress
DPADRR OUTPUT BYTE PROFIBUS address (1..125)

Use SFC5 to translate a station's slot-0 diagnostic address into a PROFIBUS address when building an HMI-driven selection list, or in reverse when commissioning a station from its physical PROFIBUS node number.

6. SCL Implementation Example

The following SCL (Structured Control Language) block wraps SFC12 with a state machine, idempotency, and Report System Error suppression:

FUNCTION_BLOCK FB1000 "DP_Slave_Control"
VAR_INPUT
    i_Enable  : BOOL;        // 1 = activate, 0 = deactivate
    i_LADDR   : WORD;        // W#16#nnnn (hex)
    i_Req     : BOOL;        // rising edge to execute
END_VAR
VAR_OUTPUT
    o_RetVal  : INT;         // SFC12 return value
    o_Busy    : BOOL;        // SFC12 BUSY
    o_Status  : BYTE;        // 0=inactive, 1=active, 2=unknown
    o_Error   : BOOL;        // 1 = last call returned error
END_VAR
VAR
    sfc12_BUSY : BOOL;
    sfc12_RET  : INT;
    mode_set   : BYTE;
END_VAR
BEGIN
    o_Error := FALSE;

    IF i_Req THEN
        IF i_Enable THEN
            mode_set := B#16#02;  // activate
        ELSE
            mode_set := B#16#01;  // deactivate
        END_IF;

        // Only one SFC12 job per slave at a time
        IF NOT sfc12_BUSY THEN
            D_ACT_DP(
                REQ    := TRUE,
                MODE   := mode_set,
                LADDR  := i_LADDR,
                RET_VAL:= sfc12_RET,
                BUSY   := sfc12_BUSY
            );
            o_RetVal := sfc12_RET;
            o_Busy   := sfc12_BUSY;
            o_Status := BYTE#0;  // pending confirmation

            IF sfc12_RET <> 0 AND NOT sfc12_BUSY THEN
                o_Error := TRUE;
            END_IF;
        END_IF;
    ELSE
        // Status query path (MODE=0)
        D_ACT_DP(
            REQ    := FALSE,
            MODE   := B#16#00,
            LADDR  := i_LADDR,
            RET_VAL:= sfc12_RET,
            BUSY   := sfc12_BUSY
        );
        o_RetVal := sfc12_RET;
        o_Busy   := sfc12_BUSY;
        IF sfc12_RET = 0 AND NOT sfc12_BUSY THEN
            o_Status := BYTE#1;  // active
        END_IF;
    END_IF;
END_FUNCTION_BLOCK

7. Ladder Logic Equivalent

For engineers who prefer ladder:

Network 1: Rising edge of i_Req
 A   i_Req
 FP  M 10.0     // local edge memory
 =   #tempEdge

Network 2: Mode selection
 AN  i_Enable
 L   B#16#01
 T   #mode

Network 3: Activate path
 A   i_Enable
 L   B#16#02
 T   #mode

Network 4: SFC12 call (must be a separate network)
 A   #tempEdge
 AN  sfc12_busy
 CALL D_ACT_DP
   REQ    := #tempEdge
   MODE   := #mode
   LADDR  := i_LADDR
   RET_VAL:= sfc12_ret
   BUSY   := sfc12_busy

8. SFC12 Return Value Reference

RET_VAL (hex) Meaning Recommended Action
W#16#0000 Job completed without error None
W#16#7000 No job active None
W#16#7001 First call, job running Wait, call again until BUSY=0
W#16#7002 Follow-up call, job still running Wait
W#16#8090 Wrong or invalid LADDR / MODE Verify LADDR is WORD and configured
W#16#8093 Logical address not assigned to a configured slave Check HW Config for that address
W#16#80A1 Negative acknowledgement from DP master (slave does not exist) Confirm slave present; check PROFIBUS address
W#16#80A2 DP master is in clear/operate state conflict Retry after CPU RUN/RUN
W#16#80A3 PROFINET CBA: device locked by another application Release device, retry
W#16#80C3 Resource bottleneck, internal SFC12 error Retry; check CPU OB35/OB82 load
W#16#80C4 Communication error to DP master Check bus, terminators, topology

9. PROFIsafe Interaction

On a CPU 6ES7 315-2FH10-0AB0 with firmware V2.3.3, SFC12 was used to deactivate a PROFIBUS DP slave that contained F-I/O. The following behavior was observed and matched against the F-CPU documentation:

  • No SF or BF LED on the F-CPU was lit while SFC12 executed.
  • All F-I/O on the target slave was automatically passivated by the F-library.
  • The passivation is normal and required: removing the slave from cyclic exchange trips the F-host watchdog and the F-library sets the affected channels to safe state.
Safety implication: SFC12 must not be used to mask a real PROFIsafe fault. If the slave is critical to the safety function, deactivating it brings the F-system into the configured fault state. Operators must be informed through a separate alarm channel.

10. PROFINET Behavior on F-CPU

On the same 6ES7 315-2FH10-0AB0 V2.3.3 F-CPU, SFC12 did not affect a PROFINET IO device with F-I/O. No change in the BF LED or the device state was observed. Firmware V2.3.4 release notes did not list a fix, indicating the limitation was architectural in the V2.3.x line.

The replacement CPU 6ES7 315-2FH13-0AB0 with firmware V2.5.1 includes updated SFC12 PROFINET support. The firmware download is documented in Siemens entry 23877553. Before deploying PROFINET deactivation, verify on the target CPU that:

  1. The PROFINET device is configured with a valid device name and IP.
  2. The device's diagnostic address is assigned and not zero.
  3. The PROFINET interface is not shared with an IRT configuration that locks devices.

11. Bus Termination Pitfall (End-of-Line)

Disabling the last physical slave on a PROFIBUS segment removes the segment's bus terminator. Observed symptoms:

  • BF LED on the CPU/IM turns on immediately after deactivation.
  • Diagnostic buffer records "DP master: bus fault, end of line lost."
  • Reactivating the slave clears the BF.

Solutions, in order of preference:

  1. Install an active PROFIBUS terminator (for example 6ES7 972-0DA00-0AA0) on a free DP connector. Active terminators are powered from the bus and remain effective regardless of station state.
  2. Reorder the topology so that the last physical node is a slave that is always active.
  3. Use a DP repeater (6ES7 972-0AA02-0XA0) with its own terminating resistor at the segment end.

12. Integrating with Report System Error

Report System Error (RSE) is enabled in HW Config on the CPU. RSE uses OB82, OB83, OB86, OB122 to populate the WinCC alarm log. The combination of SFC12 + RSE produces the following desired behavior:

Slave State SFC12 Action OB86 Triggered RSE Message
Configured, present, healthy None No None
Configured, missing at startup SFC12 MODE=1 (deactivate) after CPU RUN Yes (once), then suppressed by SFC12 "DP slave failure" then "Deactivated by user"
Configured, present, then removed SFC12 MODE=1 (deactivate) on operator command No (slave is logically removed before failure) "Deactivated by user"
Re-added by operator SFC12 MODE=2 (activate) OB83 (module restart) if physical "Activated by user"

To prevent the initial OB86 from generating a flood, call SFC12 in OB100 (warm restart) or in the first scan of OB1 with a known HMI-confirmed list of "intentionally absent" slaves.

13. Verification Procedure

  1. Build a small test rack with one configured PROFIBUS DP slave whose diagnostic address is W#16#03E8 (1000 decimal).
  2. Disconnect the slave and bring the CPU to RUN.
  3. Confirm the BF LED on the CPU is lit and OB86 has run.
  4. Trigger the FB1000 instance with i_LADDR := W#16#03E8 and i_Enable := FALSE.
  5. Read the return value via VAT: DB1000.DBX0.0 = 0 (no error) and o_Busy = 0 within 5 seconds.
  6. Open the diagnostic buffer (online > diagnostic buffer). Confirm an entry of the form "DP slave: station deactivated."
  7. Reconnect the slave and call FB1000 with i_Enable := TRUE. Confirm OB83 "Module reinserted" is logged and process I/O updates resume.

14. Troubleshooting Matrix

Symptom Likely Cause Fix
SFC12 returns W#16#8090 LADDR not WORD, or slave not in SDB Use W#16# prefix, verify HW Config
SFC12 returns W#16#80A1 Slave physically missing on PROFIBUS Check bus, terminator, PROFIBUS address
RET_VAL = W#16#7002 forever Multiple SFC12 jobs in parallel for same LADDR Serialize calls, gate by BUSY
BF LED stays on after deactivate Last station on segment, end-of-line lost Install active terminator 6ES7 972-0DA00-0AA0
No effect on PROFINET device F-CPU FW < 2.5.1 limitation Upgrade to 6ES7 315-2FH13-0AB0 FW 2.5.1
OB86 flood at startup SFC12 not called early enough Call SFC12 in OB100 with HMI-confirmed absent list
F-I/O not passivated after deactivation F-library not linked Install F-library, recompile
Diagnostic buffer empty after SFC12 Diagnostic address not assigned to slot 0 Open HW Config, set slot 0 diagnostic address

15. Memory and Scan-Time Budget

SFC12 is a synchronous system call. It blocks OB1 execution for the duration of the activation/deactivation handshake with the DP master. The time scales with the number of configured slaves on the segment. Typical figures from a 6ES7 315-2FH10-0AB0 at V2.3.3:

Segment load SFC12 cycle time
1..8 slaves 10..80 ms
9..32 slaves 80..250 ms
33..64 slaves 250..600 ms
65..125 slaves 600..1500 ms

Call SFC12 only on operator request, never in a high-priority cyclic OB (OB35) without time-budget review. For projects that change slave states at high frequency, use OB35 at 100 ms and gate at most one SFC12 call per cycle.

16. Alternative: HW Config Group Suppression

If the slave list is fixed at commissioning time, the simpler approach is to use STEP 7's "Station not present" option in HW Config on a per-slave basis (DP slave properties > Parameters > "Station not present in configuration"). This avoids SFC12 entirely but is not HMI-driven.

17. Frequently Asked Questions

What data type must the LADDR input of SFC12 D_ACT_DP be?

LADDR must be of type WORD with hexadecimal literal syntax, e.g. W#16#0064 for decimal 100. Passing a plain integer constant will return RET_VAL W#16#8090.

Can SFC12 deactivate a DP slave that is physically missing on the bus?

Yes, but only after the CPU has detected the missing slave via the standard PROFIBUS polling. SFC12 with MODE=1 then writes a "logically disconnected" state to the DP master, suppressing the OB86 message until the slave is reactivated.

Does SFC12 work on PROFINET IO devices on the S7-300F CPU 6ES7 315-2FH10-0AB0?

No. On firmware V2.3.3 SFC12 has no effect on PROFINET devices. Upgrade to the 6ES7 315-2FH13-0AB0 with firmware V2.5.1 (Siemens entry 23877553) to obtain PROFINET deactivation support.

Why does the BF LED light up when I deactivate the last slave on a segment?

Deactivating the last physical station removes the segment's terminating resistor. Install an active PROFIBUS terminator (6ES7 972-0DA00-0AA0) on a free DP connector so the segment stays terminated regardless of station state.

What happens to PROFIsafe I/O when the F-host deactivates a slave with SFC12?

The F-library automatically passivates all F-I/O on the target slave. No SF or BF LED is lit on the F-CPU, but the safety function is no longer executed by the affected channels until the slave is reactivated. SFC12 must not be used to mask a genuine safety fault.

How do I prevent Report System Error from logging an alarm for a known-absent slave?

Call SFC12 with MODE=1 in OB100 (warm restart) or in the first OB1 scan using a list of slaves the operator has confirmed as intentionally absent. The DP master then records "station deactivated" instead of "station failure," and OB86 no longer fires.

Back to blog