STEP 5 KY Constant and Profibus-DP Diagnostics on S5-95U

David Krause13 min read
PLC HardwareSiemensTechnical Reference
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 SIMATIC S5 family (S5-95U, S5-100U, S5-115U, S5-135U, S5-155U) programs in STEP 5 using a small, fixed instruction set with explicit constant-form qualifiers. Two qualifiers appear constantly in legacy Profibus-DP (SINEC L2-DP) diagnostic blocks: KB (1-byte constant) and KY (2-byte packed constant), loaded with L and transferred to output/process words with T or to data words with T DW / T DR / T DL.

This reference decodes the instructions seen in real S5-95U and S5-135U CPU 928 diagnostic programs — specifically L KY 127, 0, L KY 127, 1, and the surrounding DB 253 MONITORING block — and explains the relationship to Profibus-DP broadcast/multicast address 127, the IM 308-B master interface, and ET200U slave diagnostics.

Document scope: Only STEP 5 syntax that is explicitly documented in the S5-95U, S5-100U, S5-115U, and S5-135U manuals is used here. Where the manuals disagree on a parameter (for example, station-number ranges for diagnostics requests), the conflicting values are shown side-by-side rather than reconciled.

Prerequisites

  • Working knowledge of STEP 5 STL (Statement List) — segments, accumulators 1 and 2, condition codes.
  • Access to the appropriate S5 programming manual for the CPU family in use. The most cited references are:
  • STEP 5 programming tool (PG 720/740/760/685/615U or PC with original STEP 5 V6.x or V7.x).
  • Configured Profibus-DP master (IM 308-B, IM 308-C, or CP 5431) and at least one DP slave (ET200U, ET200B, ET200L, ET200M, or third-party).

STEP 5 Constant Qualifiers — Reference Table

STEP 5 constants always begin with K, followed by a format letter that defines how the subsequent value is interpreted. The table below covers the qualifiers that appear in STEP 5 STL documentation across the S5 CPU families.

Qualifier Meaning Range / Encoding Typical Use
KB Constant Byte 0 to 255 (decimal) Loading a single byte (page numbers, short codes).
KC Constant Count (BCD) 0 to 999 Counter preset values.
KF Constant Fixed-point -32768 to +32767 Integer arithmetic operands.
KH Constant Hexadecimal 0000 to FFFF (max 4 digits) Bit patterns, masks, raw I/O words.
KM Constant Bit Pattern 16 binary digits, no delimiter Bit masks (e.g. KM 0000 0000 0011 1111).
KS Constant Character 2 alphanumeric characters ASCII/character constants (e.g. KS 'A1').
KT Constant Time (BCD) 0.0 to 999.3 (time base 0.1 s) Timer preset values (e.g. KT 050.0).
KY Constant (2 Bytes) Two bytes, each 0 to 255 Packed 2-byte values: node + channel, station + code, etc.

Worked example — KY 127, 1: The first byte (127) occupies the low byte of the 16-bit accumulator word; the second byte (1) occupies the high byte. The hex representation is 0x017F, with 0x7F = 127 as the LSB. This is the typical Profibus-DP encoding for "address 127, identifier 1".

The KY Constant in Practice

A KY constant loads two absolute numbers simultaneously into a single 16-bit word. Both numbers must be in the range 0 to 255, which makes KY ideal for parameters that pair a small index with a small selector, such as:

  • Profibus station number (0-127) plus diagnostic request code (0-7).
  • CP channel number (0-255) plus sub-function code (0-255).
  • Block number (0-255) plus offset (0-255).

The example program below shows the canonical "request a slave's diagnostic frame" sequence for an S5-95U used as a DP slave on a SINEC L2-DP network:

:C DB 253            
:L KB 48             
:T OY 255            
:L KY 127, 0         
:T OW 252            
:L OY 252            
:T DR 19             
:L OY 253            
:T DL 19             

Segment 2 of this block is interpreted as follows:

STEP 5 Line Operation Effect on Memory
C DB 253 Open DB 253 as the active data block. Subsequent T DR / T DL target data words in DB 253.
L KB 48 Load constant byte 48. ACCU1 = 0x30.
T OY 255 Transfer ACCU1-LL to output byte 255. OB 255 := 0x30 (often a page/function selector on the CP or IM).
L KY 127, 0 Load packed constant 127, 0. ACCU1 = 0x007F (low byte 127, high byte 0).
T OW 252 Transfer ACCU1 to output word 252. OW 252 := 0x007F. This is the diagnostic-request word to the IM 308-B.
L OY 252 Load input byte 252. ACCU1-LL = first byte of the diagnostic reply from the IM.
T DR 19 Transfer ACCU1 to right data word DW 19 of DB 253. DW 19 := diagnostic reply byte 0.
L OY 253 Load input byte 253. ACCU1-LL = second byte of the diagnostic reply.
T DL 19 Transfer ACCU1-LL to left byte of DW 19. High byte of DW 19 := second diagnostic byte.

Segment 3 is structurally identical except that KY 127, 1 requests diagnostic codes 16-31 from the same station — 0 = "outline 0-15", 1 = "outline 16-31", and so on. This mirrors the request format described in the S5-95U SINEC L2-DP manual (6ES5 998-8MD21).

Why Station Address 127?

Profibus-DP reserves station address 127 for special addressing modes. The two cases documented in the S5-95U and S7 manuals are:

Address 127 Use Case Master Behavior Slave Behavior
Broadcast (master → all slaves) Send one telegram addressed to 127. All slaves consume the data; no slave transmits an acknowledgement.
Multicast (master → selected group) Send one telegram addressed to 127 with a group selector in the SAP/header. Only slaves whose DB1 has the matching receive SAP consume the data; no slave transmits.

Because address 127 never receives a response, L KY 127, 0 in a diagnostic-request context is unusual — a normal slave-diagnostic request is addressed to the slave's own station number (3 to 125 according to the S5-95U manual; 0 to 126 according to the wider DP standard, with 126 reserved for "fail-safe" slaves in some configurations). The pattern in the user's listing is therefore one of two things:

  1. A diagnostic broadcast that asks every slave simultaneously to expose its outline on input word 252 — the master then reads back responses one station at a time using individual poll telegrams.
  2. A literal 127 written by the programmer as a placeholder while commissioning, intended to be replaced with the real station number once each station's address is known.
Boundary note: The S5-95U manual (6ES5 998-8MD21) lists diagnostic-request station numbers as 3 to 125. The standard Profibus-DP address space for normal slaves is 0 to 125, with 126 reserved for some default-master configurations and 127 reserved for broadcast/multicast. The two ranges overlap and are reconciled by role, not by hard number.

DP Slave Diagnostic Request Format (S5-95U)

From the S5-95U SINEC L2-DP manual, the diagnostic request sequence is:

:L KY (station number), (code)
:T PW 252

Where:

  • station number: 3 to 125 (per 6ES5 998-8MD21). For broadcast/multicast, the source uses 127.
  • code: 0 to 7, selecting which block of device-related diagnostics is to be returned.

The IM 308-B writes the requested diagnostic data into I/O word 252 ("diagnostic address"). The CPU then loads the result with L OY 252 / L OY 253 and stores it in the application DB (DB 253 in the example).

System Architecture Used in the Example

The user's hardware is a classic S5-135U station with central I/O and a Profibus-DP master interface, talking to ET200U remote I/O over SINEC L2-DP.

Component Catalog / Order Number Role
S5-135U chassis 6ES5 135-… Central rack, slot for CPU and CPs.
CPU 928 6ES5 928-… Program execution, STEP 5 cycle.
IM 308-B 6ES5 308-3UB11 / 6ES5 308-3UC11 Profibus-DP master interface; reads/writes process image and forwards diagnostic telegrams.
ET200U slaves 6ES5 461-… / 6ES5 462-… Distributed I/O stations on the DP segment.
DB 253 "MONITORING BUS" User-defined data block Storage for diagnostic results pulled from the IM 308-B.

Reference topology (S5-135U / IM 308-B / ET200U)

S5-135U CPU 928 (STEP 5 cycle) IM 308-B (DP master) DB 253 MONITORING DB 254..n (other DBs) RS-485 Terminator on / off ET200U (slave 3) addr 3, 4…7 ET200U (slave 4) addr 4, 8…11 ET200U (slave 5) addr 5, 12…15 Profibus L2

Step-by-Step: Decoding and Rebuilding the Diagnostic Block

  1. Identify the active DB. The first line of each segment (C DB 253) opens DB 253 so all subsequent T DR / T DL operations target data words in that block.
  2. Identify the page selector. L KB 48 / T OY 255 writes 48 to the byte-level output process image at byte 255. On an S5-95U with integrated DP, byte 255 is the "page" or function index for the integrated L2 interface. The exact meaning depends on the CPU variant.
  3. Build the diagnostic-request word. L KY 127, 0 packs (0, 127) into a single 16-bit value and writes it to OW 252, which is the input/output word used as the "diagnostic address" of the IM 308-B.
  4. Read the response. The IM 308-B returns the slave's diagnostic frame in I/O word 252. The CPU pulls the low and high bytes separately with L OY 252 and L OY 253.
  5. Store the result. T DR 19 overwrites the right (low) byte of DW 19; T DL 19 overwrites the left (high) byte. The next segment reuses the same pattern with a different request code to read the next 16 bits of diagnostic data.
  6. Repeat per request code. Codes 0, 1, 2, … each retrieve 16 bits of the device-related diagnostic frame, so a complete read of a standard DP slave diagnostic frame requires 6-8 segments in the same DB.
Sanity check: The first byte of every DP slave diagnostic frame is the station status byte (0x00 = no fault, 0x0C = fault present). If you read 0x00 from a slave that you know is faulted, the request word is not reaching the IM 308-B correctly — verify the byte order of OW 252 on the specific IM firmware revision in use.

STEP 5 Segments — Reference Block

A complete diagnostic-fetch block for an ET200U station typically looks like this. Replace the placeholder station number with the real address once the segment is verified.

FB 100
NAME : DIAG_FETCH
:C DB 253                   
:L KB 48                    
:T OY 255                   
:L KY 3, 0                  
:T OW 252                   
:L OY 252                   
:T DR 19                    
:L OY 253                   
:T DL 19                    
:L KY 3, 1                  
:T OW 252                   
:L OY 252                   
:T DR 20                    
:L OY 253                   
:T DL 20                    
:L KY 3, 2                  
:T OW 252                   
:L OY 252                   
:T DR 21                    
:L OY 253                   
:T DL 21                    
:BE

Diagnostic codes 0 through 7 cover:

Code Content Size
0 Station status (1 byte) + reserved / device-related outline 0-15 2 bytes
1 Device-related diagnostic, bytes 16-31 2 bytes
2 Module status, bytes 32-47 2 bytes
3 Module status, bytes 48-63 2 bytes
4..7 Channel-specific diagnostic, 16 bytes total 2 bytes each

Verification Procedure

  1. Force a known fault. Disconnect one ET200U terminal block on a non-production station. The slave should pull its status byte to a non-zero value within one DP cycle.
  2. Single-step the FB in PG online mode. Watch DR 19 in DB 253. With station 3, code 0, you should see the station status in the low byte of DW 19 within one PLC cycle of writing OW 252.
  3. Check byte order. If DR 19 contains 0x0000 and the slave is known to be present, swap OY 252 and OY 253 in the read sequence — some IM 308-B firmware revisions return the high byte first.
  4. Cross-check the SAP list. In COM PROFIBUS, open the master configuration and verify that the slave's diagnostic SAP (default 0x3C) is enabled. If it is not, no diagnostic frame will be returned to OW 252.

Common Pitfalls and Diagnostic Matrix

Symptom Likely Cause Fix
DR 19 always reads 0x0000 with no fault Station number in KY does not match the configured slave address. Use COM PROFIBUS to confirm the slave's Profibus address and substitute it into the KY.
DR 19 reads 0xFF / 0xFF on every cycle IM 308-B has no answer because the diagnostic SAP is disabled or the slave is in address 127 broadcast mode. Confirm SAP 0x3C is enabled; do not use address 127 for unicast reads.
Only the low byte is updated Program uses T DR 19 twice and skips T DL 19. Insert the missing T DL 19 instruction between the two L OY operations.
Page number 48 has no effect CPU is an S5-100U (no integrated L2); OY 255 routes to the wrong interface. Use the slot-aware output address of the IM 308-B instead of OY 255.
Compile error: invalid operand for KY One of the two numbers is outside 0-255. Split into L KB / L KB + OW combination, or use L KH if both are 0x00-0xFF.
Diagnostic frame returns wrong station Multiple slaves configured with overlapping addresses. Run COM PROFIBUS → Check Bus and re-number the offending slave.

Related STEP 5 Constant Patterns

Other KY patterns seen in real S5 communications blocks:

Instruction Hex Typical Meaning
L KY 0, 0 0x0000 No-op / clear request word.
L KY 0, 1 0x0100 "Read parameter" to local station.
L KY 126, 0 0x007E Address 126 — sometimes used as "default master" in some S5-95U configurations.
L KY 127, 0 0x007F Address 127 — broadcast/multicast.
L KY 3, 7 0x0703 Read channel-specific diagnostic, code 7, of station 3.

Where to Read More

For the S5-95U Profibus interface and DP slave behavior, the canonical Siemens document is the S5-95U SINEC L2-DP manual (order number 6ES5 998-8MD21). For the S7 side of the same multicast behavior (which the legacy code is reusing) the Siemens Knowledge Base entry ID 20987711 covers FDL multicast via Profibus CPs. Older but still valid explanations of broadcast address 127 appear in the S5-95U manual and in the Siemens Knowledge Base entry 1091429. The full set of STEP 5 constant formats is in the S5-100U manual (6ES5 998-0UB23) and S5-115U manual (6ES5 998-0UF23). STEP 5 itself is documented in the S5 programming manual for the relevant CPU family.

What does the K in KY, KB, KF mean in STEP 5?

K stands for Konstante (German for "constant"). The letter after K is the format specifier. KY means a 2-byte packed constant of two numbers 0-255; KB means a single byte 0-255; KF means a signed 16-bit fixed-point; KH means hex; KM means a 16-bit binary pattern; KS means two ASCII characters; KT means a BCD time; KC means a BCD count.

Why does the program use L KY 127, 0 instead of the slave's real station number?

Address 127 is the Profibus-DP broadcast/multicast address. Slaves do not acknowledge broadcast telegrams, so writing it to OW 252 is a request that every slave on the segment consume but not respond to. The real station-by-station poll then happens with the slave's actual address (3 to 125 per the S5-95U manual). If the segment is not intended as a broadcast, 127 in this context is almost certainly a commissioning placeholder.

What is the diagnostic address on the IM 308-B?

It is I/O word 252 on the IM 308-B's process image. The CPU writes a request formed by L KY (station), (code) followed by T OW 252, and reads the result back with L OY 252 and L OY 253. The IM 308-B manual specifies this address and the request format.

How is a KY constant different from two consecutive KB loads?

Two KB loads combined with an OW transfer use two byte-level operations. A single KY load and OW transfer is one STEP 5 line and one bus cycle on the internal S5 backplane. For comm processors that poll a parameter word, the single-line KY form is preferred because it is atomic from the CP's point of view.

What range of station numbers is valid for a DP diagnostic request on S5-95U?

Per the S5-95U SINEC L2-DP manual (6ES5 998-8MD21), normal diagnostic requests use station numbers 3 to 125 with codes 0 to 7. The standard Profibus-DP address space is 0 to 125 for normal slaves, 126 reserved for some default-master roles, and 127 reserved for broadcast and multicast.

Back to blog