SFB52 RDREC for SCALANCE PROFINET Diagnostics: Parameter Guide

David Krause11 min read
HMI ProgrammingSiemensTutorial / 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

Overview

The system function block SFB52 "RDREC" (Read Record) is the standard Siemens mechanism for reading acyclic PROFINET IO records from any PROFINET device on the network, including the SCALANCE X family of managed switches. Because SCALANCE X-200, XB-200, XC-200, XR-200 and XM-400 switches expose their port, link, neighbor and diagnostic state through PROFINET records rather than cyclic I/O, RDREC is the only way to retrieve that data from an S7-300/400/1500 controller without third-party tools.

This guide covers the SFB52 interface, the correct population of the ID, INDEX, MLEN and RECORD parameters, the most useful record indices for SCALANCE diagnostics, how to read link/neighbor topology data, and the root-cause analysis of the typical BF (Bus Fault) LED symptom that appears immediately after a faulty RDREC call is downloaded to the CPU.

Prerequisites

  • SIMATIC S7-300 (CPU 31x-2 PN/DP), S7-400 (CPU 41x-3 PN/DP), or S7-1200/1500 controller on the same PROFINET subnet as the SCALANCE device.
  • SCALANCE X switch with PROFINET diagnostics enabled (X-200, XC-200, XB-200, XM-400, XR-500 families). The switch must appear as a PROFINET IO device in the STEP 7 / TIA Portal project.
  • The GSDML file of the SCALANCE imported into the hardware catalog (e.g. GSDML-Vx.x-Siemens-SCALANCE-XC200-...xml).
  • The diagnostic address assigned to the SCALANCE in HW Config / device configuration. This is the ID input for RDREC.
  • STEP 7 V5.5 / TIA Portal V13+ with the SFB52 instance library (FB52 on S7-1500) installed.
  • Familiarity with the Siemens support entry Reading out the topology data of a PROFINET IO system, which is the canonical SFB52-with-SCALANCE reference.

SFB52 Interface and Parameter Map

SFB52 RDREC reads an acyclic record from a PROFINET IO device. Its formal interface is identical for S7-300 and S7-1500 (where it is provided as FB52 RDREC in the "PROFINET IO" instructions library). The block has the following input and output parameters:

Parameter Direction Type Meaning
REQ IN BOOL Level-triggered start. Set to 1 to initiate one read; the block reads once on the rising edge of internal processing.
ID IN DWORD / HW_IO PROFINET IO identifier of the device = the diagnostic address configured in HW Config for the SCALANCE. For S7-300: DW#16#7FA style; for S7-1500: HW-IO handle from the system constants.
INDEX IN INT Data record number. Determines which PROFINET record is read (e.g. 0x8000-series for port statistics, 0x802A for neighbor/port data, 0xF80C for LLDP-MIB style topology).
MLEN IN INT Maximum length in bytes of the record to be read. Must be ≥ the actual record length; otherwise STATUS = 0x80B1.
VALID OUT BOOL 1 = new record received and valid.
BUSY OUT BOOL 1 = read operation still in progress.
ERROR OUT BOOL 1 = read error; evaluate STATUS.
STATUS OUT DWORD Error/status code (see STATUS Code Decoding below).
LEN OUT INT Actual length of returned record in bytes.
RECORD OUT VARIANT / ANY Destination data area. Pointer form on S7-300: P#DBx.DBXy.z BYTE n; on S7-1500: tag of BYTE/Word/DWord array.
Important: On S7-300/400 RDREC is multi-instance capable and must be called from OB1 (or OB82 for diagnostic interrupt-driven reads). On S7-1500, use FB52 in the "PROFINET IO" instructions; the parameter ID accepts a HW-IO system constant from the device table.

Step-by-Step: Implementing SFB52 in STEP 7

  1. Open HW Config and assign a diagnostic address. Double-click the SCALANCE X device; in Properties > PROFINET interface > Diagnostics set a unique diagnostic address (e.g. 2042 decimal = 0x7FA). Note this number; it becomes your ID.
  2. Create an instance DB. Insert SFB52 from the standard library and assign a new DB (e.g. DB52). This DB stores the RDREC instance data.
  3. Create a destination DB. Build DB2 with at least 256 bytes reserved for the response. Larger values (512-2048) are needed for port-statistics records. Use the RECORD ANY pointer to mark the start.
  4. Drive REQ from a clock or trigger. To prevent bus overload, pulse REQ from a 1-second timer or from OB82 (diagnostic interrupt) when the SCALANCE reports a state change.
  5. Evaluate VALID and ERROR. On a rising edge of VALID, the data at RECORD is fresh. On ERROR = 1, read STATUS and branch to a fault handler.

Reference: SCALANCE Record Indices

The record indices listed below are the ones most often used for SCALANCE X diagnostics. All values are 0-based, decimal or hex as shown; pass them to RDREC as the INDEX input.

Index (hex) Index (dec) Record content Typical MLEN
0x0000-0x7FFF 0-32767 Manufacturer-specific records as defined in the SCALANCE GSDML. device-specific
0x8000 32768 Port statistics (per-port counters: discards, errors, CRC, collisions) for the queried port. 64
0x8002 32770 Port description / port name list (8-byte header + ASCII port names). 256
0x802A 32810 Neighbor (LLDP) record for one port. The first 4 bytes of the request specify the port number (1-based). 128
0x802B 32811 All neighbors at once: contains an array of LLDP records, one per port that has detected a neighbor. 512
0x8050 32848 Interface description (MIB-II ifDescr equivalent). 128
0xF80C 63500 LLDP management address / topology block used by STEP 7 topology editor. 256
0xF841 63553 PD Port Data Real (PDPortDataReal) – live link/speed/duplex/auto-neg per port. 64
The actual port-specific request layout is not implicit in the index. For 0x8000 / 0x802A you must place the 1-based port number in the first 4 bytes of the RECORD area before calling RDREC. The block copies these bytes into the request, and the device returns the corresponding port record in the same buffer.

Sample Ladder Logic (S7-300, STEP 7 V5.5)

The snippet below reads the live link state of Port 5 on a SCALANCE X208. The pattern follows the Siemens reference PDF 38566021_NET_topology_SFB52_e.pdf.

// ---- DB2 layout: target buffer for the SCALANCE record ----
// DB2.DBX0.0  DWORD  : Port selector (1-based) – loaded before CALL
// DB2.DBX4.0  BYTE x : Record response from device
//
// ---- Marker area (MW100, M110, MD112, MW116) ----

NETWORK 1   // load record index 0x802A (32810 dec)
L  32810
T  MW 100

NETWORK 2   // prepare port selector (Port 5)
L  5
T  DB2.DBD 0

NETWORK 3   // call RDREC
CALL  "RDREC" , DB52
REQ    := M0.5          // 1-second pulse from timer
ID     := DW#16#7FA     // diagnostic address of SCALANCE
INDEX  := MW100         // 0x802A = 32810
MLEN   := 128           // large enough for one LLDP neighbor
VALID  := M110.0
BUSY   := M110.1
ERROR  := M110.2
STATUS := MD112
LEN    := MW116
RECORD := P#DB2.DBX4.0 BYTE 128

STATUS Code Decoding

RDREC returns a four-byte STATUS word whose upper two bytes (DWORD bits 16-31) identify the source (PROFINET IO stack = 0x80) and whose lower two bytes are the actual code. Use the table below as a first triage before consulting the S7 system manual.

STATUS (hex) Meaning Field action
0000_0000 Read finished, data valid. None – consume RECORD.
7000_0000 First call / BUSY = 1, no error yet. Wait for BUSY = 0.
80A0_xxxx Negative acknowledge from the IO device (record index unknown, access denied). Check GSDML for valid INDEX values.
80A1_xxxx Device rejected the read (e.g. wrong port selector). Verify the 4-byte request header.
80A2_xxxx Resource error on the device. Retry; investigate device load.
80A7_xxxx Busy, the device cannot process right now. Delay next REQ.
80A9_xxxx Vendor error – see the lower 16 bits. Cross-check with SCALANCE WBM diagnostic buffer.
80B1_xxxx User-supplied MLEN shorter than the record's actual length. Increase MLEN and RECORD size.
80C0_xxxx Read conflict, the same record is being written (by WRREC) on the device. Serialize with any SFB53 writes.
80C3_xxxx CPU resource bottleneck on acyclic RPC frames. Throttle the calling rate.
80F0_xxxx Device not reachable / disconnected. Check the BF LED, cable, ring redundancy.

Root Cause: BF LED After Download

The symptom reported in the field — "the BF LED turns on when the program is downloaded, but goes away when the program is removed" — almost always traces to one of three causes:

  1. Wrong ID value. The ID must be the diagnostic address, not the PROFINET device number and not the cyclic IO address base. In the sample above, DW#16#7FA is the diagnostic address assigned in HW Config. Using a value from the process-image range will return STATUS = 0x80F0 and the CPU flags the device as not reachable, lighting the BF LED.
  2. Bad RECORD ANY pointer. A malformed ANY such as P#DB2.DBX0.0 BYTE 0 or one whose DB number does not exist at runtime produces an internal RDREC error. STEP 7's online block-consistency check normally catches this, but a DB downloaded in a later change can mask the fault until RDREC actually executes.
  3. Truncated MLEN combined with a long record. If the chosen INDEX returns, say, 220 bytes but MLEN = 2, the device treats the request as ill-formed (STATUS = 0x80B1) and may momentarily mark the slot as disturbed. The BF LED will blink rather than stay on, but many SCALANCE firmware revisions also surface a transient PROFINET alarm that the CPU records as a bus fault.
A BF LED that only appears during the first scan after a download and then extinguishes within one PROFINET update cycle is almost always caused by the third case. The CPU has issued a malformed acyclic RPC and the slot state recovers automatically once the device rejects the frame and the CPU clears the internal "read pending" flag.

Reading Topology Data from a SCALANCE X208 (Worked Example)

This is the canonical use case from Siemens FAQ 38566021. Goal: discover which PROFINET neighbor is connected to Port 5 of a SCALANCE X208.

  1. In HW Config, the SCALANCE X208 is at diagnostic address 2046 (0x7FE).
  2. DB100 contains 256 bytes of buffer; DB100.DBD0 = port selector (1-based); the response starts at DB100.DBD4.
  3. Set DB100.DBD0 = 5 (Port 5).
  4. Call RDREC with INDEX = 32810 (0x802A), MLEN = 128, ID = DW#16#7FE.
  5. When VALID = 1, decode the response:
    • Bytes 0-1: port number echo.
    • Bytes 2-3: chassis-id length.
    • Bytes 4-9: chassis-id (MAC of neighbor).
    • Bytes 10+: port-id of the neighbor's perspective and LLDP TLV list.

The same procedure with INDEX = 32811 (0x802B) and a 512-byte buffer returns all neighbor records in a single call, which is the pattern used by STEP 7's own topology scanner.

Verification and Commissioning

  1. Open STEP 7 online > Monitor/Modify. Force REQ and watch VALID rise within 1-2 PROFINET update cycles (default 1 ms).
  2. In the Diagnostic Buffer of the CPU, confirm no entry with ID 80F0 (device unreachable) or 80A0 (negative ack) appears after the call.
  3. On the SCALANCE WBM (Web Based Management), open Information > PROFINET Diagnostics and compare the port status reported there with the data returned in RECORD. Any divergence points to a buffer-size mismatch.
  4. If a topology viewer is open in STEP 7 (Target topology / Actual topology), the scanned neighbors should match the LLDP entries decoded from 0x802B.

Troubleshooting Matrix

Symptom Likely STATUS Likely cause Fix
BF LED on, ERROR = 1 0x80F0 Wrong ID or device not online Re-check diagnostic address in HW Config; ping the switch's PROFINET IP.
VALID never set, BUSY = 0, ERROR = 1 0x80A0 Unknown record index Cross-check with the GSDML; try 0x8000 as a sanity check.
Returns zeros 0x0000 + LEN = 0 Port selector = 0 or unsupported port SCALANCE port numbers are 1-based; load 1..8 (XC208) or 1..24 (XM416).
BF LED blinks on first scan only 0x80B1 MLEN too small Raise MLEN and RECORD size to the full record length.
Random 0x80A9 Vendor code in low word SCALANCE-specific rejection Map low word via SCALANCE WBM Events log.

Notes on S7-1500 and TIA Portal

On S7-1500, drop the equivalent RDREC instruction from Instructions > Communication > PROFINET IO. The interface is identical, but two practical changes apply:

  • ID is supplied as a system constant of type HW_Interface or HW_Device. Right-click the SCALANCE in the device tree and select PROFINET IO diagnostics address to bind it.
  • The RECORD input expects a tag of the same data type as the record. For SCALANCE port records, declare a Byte array (e.g. Array[0..255] of Byte) and use a slice for the port-selector header.

FAQ

What value goes into the ID input of SFB52?

The PROFINET IO identifier, which is the diagnostic address assigned to the SCALANCE in HW Config / device properties. For an S7-300 it is a hex constant such as DW#16#7FA. For an S7-1500 it is an HW-IO system constant from the device table.

Why does the BF LED light the moment I download the program with an SFB52 call?

Three causes account for nearly every case: (1) ID is the wrong address (use the diagnostic address, not a process-image base); (2) the RECORD ANY pointer is malformed; (3) MLEN is shorter than the actual record length, producing STATUS = 0x80B1 and a transient slot disturbance. Correct any of these and the BF LED will stay off.

How do I read the LLDP neighbor of a specific SCALANCE port?

Load the 1-based port number into the first four bytes of the RECORD buffer, then call RDREC with INDEX = 0x802A and an MLEN of at least 128. To read all neighbors in one call use INDEX = 0x802B with a 512-byte buffer, as documented in Siemens FAQ 38566021.

Is SFB52 the same as FB52 on S7-1500?

Yes. On S7-300/400 the read-record block is the system function block SFB52 "RDREC". On S7-1200/1500 it is the standard FB52 "RDREC" from the PROFINET IO instructions library. The parameter set, the STATUS codes, and the record-index conventions are identical.

How can I tell if an 80A9 vendor error came from the SCALANCE and not the CPU?

Open the SCALANCE WBM (https://<switch-ip>) and look in Information > Events. The low 16 bits of the STATUS word correspond to the event ID shown there. Common SCALANCE codes include 0x0010 (port not present) and 0x0025 (function not supported in current operating mode).

Back to blog