IMDHMIControls LibraryShop main store

Troubleshooting

Fix ABB IRC5 PROFINET word values with a byte swap

Industrial networks Published 6 min read

Short answer

A word of 100 written from an S7-300 arrives at an ABB IRC5 Group Input as 25600: the PLC stores words big-endian, the Group Input reads the first byte as the low byte. Swap the two bytes in exactly one place, preferably an SCL block in the PLC, and the robot reads 100.

On this page
  1. Why the word arrives reversed
  2. What the byte-split test already proved
  3. Sending 100 from an S7-300 into Group Input 0-15: the arithmetic
  4. Rule out a mapping fault first
  5. Do the swap in the PLC
  6. When to swap in RAPID instead
  7. Wider values and negative numbers
  8. Prove the whole path
  9. Questions asked

An S7-300 word of 100 written to the robot arrives at the IRC5 Group Input as 25600, because the two bytes of the word are read in opposite orders: the S7-300 stores 16-bit values big-endian, high byte at the lower address, and the Group Input takes the first byte as bits 0-7. The link itself is healthy — digital signals and single-byte writes already work — so leave the GSD, the device name and the IP address alone. Fix the data representation with a byte swap in exactly one place, preferably an SCL block in the PLC, and prove it with the value table at the end.

Why the word arrives reversed #

Byte order belongs to the CPU, not to PROFINET. The S7-300 stores 16-bit values big-endian: the byte holding the most significant bits sits at the lower address. The PROFINET I/O image carries both bytes onto the wire exactly as stored, with no reordering, so the device receives the same byte sequence the controller wrote. The IRC5 Group Input then reads the first byte as bits 0-7 and the second as bits 8-15, a little-endian interpretation. Both sides are internally consistent; the two conventions simply disagree, and only multi-byte values expose it. For the underlying pattern, endianness in automation: big-endian versus little-endian lays out both orders with the same failure mode. The trap is not PROFINET-specific either: the RTDE header length field is big-endian, not little-endian, which surprises integrators who assumed one order everywhere.

Confirm the layout on your own controller with a watch table: write 16#0102 to MW0 and read MB0 and MB1. MB0 = 16#01 with MB1 = 16#02 is the big-endian layout. Byte order follows the CPU family, so repeat this two-minute test whenever the controller changes.

What the byte-split test already proved #

The behavior in this fault, with the robot reading a Group Input covering bits 0-15:

What the PLC writes Group Input reads Meaning
Digital bits Correct values Link, device and signal mapping are alive
Word 100 (16#0064) 25600 Word read as 16#6400: bytes reversed
Byte 100 at IB0 100 First byte lands in bits 0-7
Byte 100 at IB1 25600 Second byte lands in bits 8-15: 100 × 256

IW0, IB0 and IB1 are the addresses in this fault; use whichever addresses your hardware configuration maps to the robot's I/O area, on the side and in the direction that belong to the robot device. If your digital signals do not transfer either, stop here: that is a connection fault, not endianness — work through fixing PROFINET connect errors between a controller and an S7-1200 and return once bits flow both ways.

Sending 100 from an S7-300 into Group Input 0-15: the arithmetic #

Inputs:

  • Sent value: 100 (INT, decimal), the test setpoint in the PLC program.
  • S7-300 word layout: big-endian — high byte at the lower address, a CPU property confirmed by the MW0 watch-table test.
  • IRC5 Group Input 0-15: first byte read as bits 0-7, second as bits 8-15, proven by the IB0 and IB1 rows above.

Rule in words: the robot's reading is the second byte times 256 plus the first byte. The word you must send is the sent value with its two bytes exchanged.

The arithmetic:

  1. 100 decimal = 16#0064, so high byte 16#00 and low byte 16#64.
  2. PLC memory: byte 0 = 16#00, byte 1 = 16#64.
  3. Robot reading = byte 1 × 256 + byte 0 = 100 × 256 + 0 = 25600 = 16#6400.
  4. Swapped word to send: 16#6400, giving byte 0 = 16#64 and byte 1 = 16#00.
  5. Robot reading after the swap = 0 × 256 + 100 = 100.

Result: with the swap writing 16#6400 to the output word, the Group Input reads 100.

Decision: before any fix, the pendant must show exactly the sent value × 256 — 25600 ÷ 256 = 100 here. A near miss of a few hundred means the sent value was not what you thought; retype it. A reading that fails that division outright is a mapping fault, so do the next section before swapping anything.

Rule out a mapping fault first #

Confirm the Group Input covers two consecutive bytes before touching data. In the IRC5 signal configuration, the signal must span bits 0-15 of the device mapping with no gap. Then:

  1. Write 1 to the first byte and 0 to the second: the Group Input must read 1.
  2. Write 0 to the first byte and 1 to the second: it must read 256.
  3. Write 16#FF to both bytes: it must read 65535.

Step 2 returning 256 proves the mapping is contiguous and leaves byte order as the only defect. Any other pattern means the start bit or width is wrong — fix that in the IRC5 signal configuration first, because no swap repairs a mis-mapped signal.

Do the swap in the PLC #

The PLC is the default place: the robot configuration stays untouched, and every consumer of the signal, including the FlexPendant I/O view, sees the engineering value. The fix that resolved this fault was a small SCL function; SwapW and In below are illustrative names, while SHL and SHR are the SCL shift operators:

FUNCTION SwapW : WORD
VAR_INPUT
 In : WORD := 16#0000;
END_VAR
 SwapW := SHL(In := In, N := 8) OR SHR(In := In, N := 8);
END_FUNCTION

Test it in isolation: SwapW with In := 16#0064 must return 16#6400, and In := 16#0102 must return 16#0201. Compile-check the shift syntax on your STEP 7 version. In STL, TAW does the same job in one instruction by swapping the two bytes of the low word of accumulator 1. A published byte-swap library block is equally fine; if you use one, do not wrap it in another swap. Assign the return value to the output word mapped to the robot and force the setpoint: 100 in, 100 on the Group Input.

When to swap in RAPID instead #

Option Where Use when
SCL, STL or library block PLC program Default: one place, and the robot signals stay meaningful on the pendant
MOD/DIV expression RAPID program The PLC program is locked, or other devices sharing those outputs expect the S7 byte order

The RAPID form, with v and result as illustrative names:

VAR num v := 0; ! raw Group Input reading
VAR num result := 0; ! value for robot logic
result := (v MOD 256) * 256 + (v DIV 256);

Run it in your head on the raw reading from the worked example: it returns 100. The price is the FlexPendant I/O list, which shows the raw swapped number, so an operator watching the signal sees a meaningless value until a RAPID variable carries the converted one. Never fit both swaps: two swaps cancel and the fault returns.

Wider values and negative numbers #

  • A negative INT crosses as its two's-complement bit pattern, which the Group Input reads as an unsigned number; recover the sign on the robot side if the logic needs it.
  • A DINT or REAL is 32 bits: reversing only two bytes is wrong. Reverse all four bytes and map the Group Input 32 bits wide.
  • With several words, swap each word individually. A byte swap does not reorder words, so the word sequence stays exactly as you designed it.

Prove the whole path #

With the swap active, write these values from the PLC and read the Group Input each time:

PLC value (INT) PLC word Reads without swap Must read with swap
1 16#0001 256 1
100 16#0064 25600 100
255 16#00FF 65280 255
258 16#0102 513 258
1000 16#03E8 59395 1000

Every row in the last column must match exactly. Then read the value inside a RAPID routine, because that variable is the number the motion logic consumes. The same reversed-word trap appears wherever a Siemens controller feeds integer setpoints to another vendor's device — apply the same one-swap discipline when you control a PROFINET servo drive with cyclic telegram data.

Questions asked

Can I predict the wrong number before sending anything?

Yes. Write the value as four hex digits and swap the two pairs. 100 is 16#0064, so the robot reads 16#6400, which is 25600; 258 is 16#0102, so it reads 16#0201, which is 513. When the pendant shows exactly the predicted number, byte order is the only fault and one swap fixes it. A reading that misses the prediction points at the mapping instead.

Can I avoid the swap entirely for small values?

Yes, for values 0 to 255. Write the value to the first byte of the pair and zero to the second, and the Group Input reads it unchanged, because a single byte has no byte order. That is a legitimate workaround for one-byte quantities, but it wastes half the signal and collapses the moment you need 256 or more, so use the swap for anything 16-bit.

What happens to negative integers?

The PLC sends two's-complement bits and the Group Input reads them unsigned, so minus 1 arrives as 65535 and minus 100 as 65436 even after the swap. If the robot logic needs signed values, recover the sign on the robot: subtract 65536 from any reading above 32767. Positive setpoints in the 0 to 32767 range need nothing extra.

Can the swap be done in the device configuration instead of the program?

No. The GSD-based device configuration maps each byte of the telegram one-to-one into the I/O area; it does not convert integer byte order. There is no setting on either side that reorders the two bytes of a Group Input, so the swap has to live in executable code: an SCL or STL block in the PLC, or the MOD and DIV expression in RAPID, in exactly one of the two.

Why did the value turn wrong again after I added a second swap?

Two byte swaps cancel and restore the original order, so the robot sees the original reversed number again. The usual cause is a swap in the PLC plus another one in RAPID, or your own block wrapped around a published swap library block. Search the path once, end to end, and keep exactly one swap in it; tag the swapped block so the next programmer does not add a third.

Keep reading

  • How-to

    Control a PROFINET servo drive with cyclic telegram data

    No motion library is needed when a PLC only exchanges cyclic process data with a PROFINET servo drive: import the device description, attach the drive, select the same telegram the drive is configured for, and map the words. Standard telegram 1, PZD 2/2, is two 16-bit words each way — four bytes per direction — and the PLC logic sequences control word STW1 and reads status word ZSW1.

    Drives and motion

  • Troubleshooting

    Fix CODESYS PROFINET IP-change error on an S7-1200 link

    The station shows in the scan because DCP discovery answers, but the connection fails because the CODESYS runtime refuses the IP address the controller assigns. Enable the IP-address update for the bound Ethernet interface in the runtime's .cfg configuration and restart the runtime; the error names the fix itself. If you would rather not enable it, set matching fixed addresses on both sides.

    Industrial networks

  • Troubleshooting

    Fix PROFINET connect errors between a controller and an S7-1200

    Separate the engineering port and the PROFINET port onto different IP layers on different physical ports, connect the controller to the S7-1200 directly or through a PROFINET-capable switch, make the device name and address match the project, and run the PROFINET IO task at priority 1 or 0. A scan that finds the S7-1200 proves discovery only; the connect stage is where DB814006 appears.

    Industrial networks