Resolving MB_UNIT_ID 16#FF Error on S7-1500 CPU 1513-1 PN Modbus

David Krause12 min read
SiemensTIA PortalTroubleshooting
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
Symptom: A Modbus TCP client running on a SIMATIC S7-1500 CPU 1513-1 PN fails to read or write to a remote device. The MB_CLIENT instruction reports DONE = FALSE and a STATUS word of 16#80C8 or 16#80D2. The TCP connection itself never completes. The cause is almost always the slave identifier sent in the MBAP header: the default value 16#FF (decimal 255) shipped in the standard instance DB of MB_CLIENT is rejected by the majority of third-party Modbus TCP servers.

1. Problem Description

The failure mode reported in the field is consistent across multiple vendors (Schneider Electric PAC3200, generic Modbus simulators, Moxa gateways, ET 200MP stations with IM 155-5 MF/HF acting as Modbus devices). The MB_CLIENT block is called cyclically with REQ, the BUSY output toggles for a fraction of a second, then ERROR rises and STATUS returns an error code indicating "no response from partner" or "connection aborted". A Wireshark trace shows the CPU transmitting a SYN to port 502, the server responding with SYN-ACK, the client transmitting a Modbus request with Unit Identifier = 0xFF, and the server closing the socket with RST immediately after receiving that request.

The diagnostic sequence that confirms the root cause is straightforward:

  1. Open the MB_CLIENT instance DB (default name MB_CLIENT_DB or user-defined) in TIA Portal online.
  2. Inspect the MB_UNIT_ID input.
  3. Confirm the value is the TIA Portal default of 16#FF (255 decimal).

2. Root Cause: MB_UNIT_ID Default Value

The MB_UNIT_ID parameter of MB_CLIENT maps directly to the Unit Identifier byte (offset 6) of the Modbus Application Protocol (MBAP) header as defined by the Modbus Organization specification. According to the Modbus Messaging on TCP/IP Implementation Guide (v1.0b), this byte is used for routing on composite or serial-bridged networks. On a pure Modbus TCP network without a serial bridge, the recommended value is 0xFF when the target is a Modbus TCP device, but it is not mandatory — many devices simply hard-code 1 and ignore any other value.

The MB_CLIENT instruction in the "MODBUS TCP" library was originally developed for the ET 200S serial module and carried over to S7-1500. Its default instance DB therefore contains MB_UNIT_ID = 16#FF. The TIA Portal does not flag this default as a configuration error, which is why the symptom appears only at runtime.

2.1 Typical Server Behavior

Modbus Server Accepts 0xFF Accepts 0x01 Recommended Unit ID
Schneider PAC3200 meter No Yes 1
Generic Modbus TCP simulator (e.g. Modbus Poll, diagslave) Yes Yes 1 or 255
Moxa MGate MB3170 / MB3270 gateway Configurable Yes 1 (per port)
ET 200MP with IM 155-5 MF/HF (Modbus server mode) Yes Yes 1
WAGO 750-352/ETH EC No Yes 1
S7-1500 acting as MB_SERVER Yes Yes 255 (default)
When a Modbus TCP server is also accessible via a serial-bridged path, the Unit Identifier often carries the slave address of the RTU/ASCII device. In that case MB_UNIT_ID must be set to the actual RTU slave number (1 to 247), not to 255. For pure TCP servers, 1 is the safe default.

3. Affected Hardware and Firmware

Component Order Number Firmware Tested Modbus TCP Capable
S7-1500 CPU 1513-1 PN 6ES7513-1AM02-0AB0 V2.9 / V3.0 Yes (integrated PN)
S7-1500 CPU 1513-1 PN 6ES7513-1AL02-0AB0 V2.6 / V2.9 Yes (integrated PN)
S7-1500 CPU 1511-1 PN 6ES7511-1AK02-0AB0 V2.9 Yes (integrated PN)
S7-1500 CPU 1515-2 PN 6ES7515-2AM02-0AB0 V2.9 / V3.0 Yes (both PN ports)
ET 200MP IM 155-5 MF HF 6ES7155-5MF00-0AB0 V4.4+ Yes (Modbus server on PN)
CP 1542-1 / CP 1543-1 6GK7542-1AX00-0XE0 / 6GK7543-1AX00-0XE0 V2.2 Yes (separate FB set)

The MB_CLIENT instruction requires TIA Portal V14 SP1 or later. The current TIA Portal V18 (released 2023) ships the latest revision of the MODBUS TCP library under Instructions → Communication → MODBUS TCP. Refer to the TIA Portal Modbus TCP documentation for the master reference on supported function codes and address ranges.

4. MB_CLIENT Parameter Reference

The block is configured through a single instance DB and through a connection description of type TCON_IP_V4. The full input/output set is listed below.

Parameter Direction Type Description Typical Value
REQ Input Bool Request trigger (rising edge) Toggled from a clock generator or user logic
DISCONNECT Input Bool 0 = connect & stay, 1 = terminate FALSE
MB_MODE Input USInt 0 = Read, 1 = Write 0 for read, 1 for write
MB_DATA_ADDR Input UInt Modbus starting address (0-based for FC 1/2/3/4/5/6, 1-based for FC 15/16/23) 0, 1, 40001, etc.
MB_DATA_LEN Input UInt Number of bits or registers 1 to 125 (regs), 1 to 2000 (coils)
MB_UNIT_ID Input Byte Slave / unit identifier 1 (NOT 16#FF)
DATA_PTR InOut Variant Pointer to data buffer (DB or bit-memory area) P#DB100.DBX0.0 BYTE 100
CONNECT InOut TCON_IP_V4 Connection description See section 5
DONE Output Bool Request completed without error Monitor for 1 cycle
BUSY Output Bool Request in progress TRUE while active
ERROR Output Bool Error flag TRUE if STATUS <> 0
STATUS Output Word Detailed error / status code 16#0000 = OK

5. Connection Description: TCON_IP_V4

The CONNECT input of MB_CLIENT is a structure of type TCON_IP_V4. The fields that the integrator must populate manually are shown below.

Field Type Value (typical) Comment
InterfaceId HW_ANY 64 (default X1 of CPU 1513-1 PN) Hardware identifier of PROFINET interface
ID CONN_OUC 1 Local connection identifier, 1..4095, must be unique per CPU
ConnectionType Byte 16#0B 11 = TCP/IP native
ActiveEstablished Bool TRUE MB_CLIENT is always the active partner
RemoteAddress ARRAY[1..4] of Byte {192,168,0,241} Server IP address
RemotePort UInt 502 IANA-registered Modbus TCP port
LocalPort UInt 0 0 = any free local port assigned by CPU
Port 502: The IANA-assigned port for Modbus TCP is 502/TCP. Some integrators change this to 2000, 2001, or 5000 to traverse NAT, but doing so breaks compliance with the Modbus Messaging on TCP/IP Implementation Guide v1.0b and is rejected by some firewalls. Always use 502 unless the target device explicitly requires another port.

6. Step-by-Step Resolution Procedure

The corrective action takes about 60 seconds once the offending parameter is identified.

6.1 Prerequisites

  • Project is loaded on the CPU 1513-1 PN with read/write access from TIA Portal (online → Go online).
  • MB_CLIENT block exists in the project, with its instance DB compiled and downloaded.
  • The PC station is reachable from the CPU (e.g. PC 192.168.0.241, PLC 192.168.0.2, subnet mask 255.255.255.0).

6.2 Procedure

  1. In the project tree, open Program blocks → System blocks → MB_CLIENT_DB (or the user-defined instance DB).
  2. Switch to the Data view (Monitor/Modify view offline).
  3. Locate the static tag MB_UNIT_ID of type Byte.
  4. Change the initial value from 16#FF to 1 (decimal) for a pure Modbus TCP server, or to the RTU slave address if the server is bridging to a serial network.
  5. Recompile the block (right-click → Compile → Software).
  6. Download to the CPU (online → Download to device).
  7. Trigger REQ and monitor DONE / ERROR / STATUS.

6.3 Verify the Connect Path in DB5

If the project uses an external connection DB (a common practice in TIA Portal V14/V15), open that DB and confirm:

  • RemoteAddress matches the IP of the slave device.
  • RemotePort = 502.
  • ConnectionType = 16#0B.
  • LocalPort = 0 (auto-assign).

7. Verification

Confirm communication is established by any of the following methods.

7.1 Online STATUS = 16#0000

When DONE pulses TRUE for one scan and STATUS returns 16#0000, the request was successful. The MB_CLIENT block retains its connection after the first successful call, so subsequent calls with the same ID and CONNECT do not re-establish the TCP session.

7.2 Wireshark Capture

Filter on the slave IP and inspect the Modbus/TCP stream. The Unit Identifier byte at offset 6 of the MBAP header should now read 0x01 instead of 0xFF:

Modbus/TCP → Transaction Identifier: 0x0001 → Protocol Identifier: 0x0000 → Length: 0x0006 → Unit Identifier: 0x01

7.3 Read Coils / Holding Registers Test

Issue a Function Code 03 read against a known address (for instance, register 40001 on a PAC3200 returns the line-to-line voltage V_LL in tenths of a volt). Confirm the value returned matches the simulator or the meter's display.

8. STATUS and Error Code Reference

MB_CLIENT STATUS values for the most common Modbus TCP errors. Refer to the TIA Portal online help for the complete table.

STATUS (hex) Meaning Likely Cause Remediation
16#0000 OK — —
16#7001 Job accepted, waiting for completion Normal during first scan Continue polling
16#7002 Job active BUSY = TRUE Wait for DONE
16#80C8 Partner not reachable / timeout Wrong IP, firewall, wrong port Ping server, check port, check VLAN
16#80D2 No response from partner Wrong Unit ID, server rejected frame Set MB_UNIT_ID = 1
16#8186 Invalid ID CONNECT.ID out of range Use 1..4095, unique per CPU
16#8380 Reserved function code MB_MODE / MB_DATA_ADDR combination unsupported Check FC support, see FC table
16#8381 Address out of range Address + length exceeds server limits Reduce length, check server register map
16#80A1 Connection ID in use Duplicate CONNECT.ID Use a unique ID per MB_CLIENT instance

9. Troubleshooting Matrix

Symptom STATUS Root Cause Fix
BUSY never clears, no ERROR 16#7002 forever REQ is held TRUE; no edge Generate a rising edge for REQ
ERROR pulses, STATUS = 16#80C8 16#80C8 Wrong port, IP, or firewall blocks 502/TCP Use port 502, fix IP, open firewall
ERROR pulses, STATUS = 16#80D2 16#80D2 Wrong Unit ID Set MB_UNIT_ID = 1
ERROR pulses, STATUS = 16#8186 16#8186 Connection ID collision Use a unique ID per MB_CLIENT
DATA_PTR error 16#8323 DATA_PTR not byte-aligned or wrong length Use byte-aligned P# pointer matching MB_DATA_LEN
Read returns zeros 16#0000 DATA_PTR maps to wrong DB, or MB_DATA_ADDR off by one Check addressing convention (0-based for FC 3/4)
Connection drops after a few minutes 16#80C8 Keep-alive not configured on switch Enable TCP keep-alive on managed switch

10. Best Practices and Field-Proven Notes

  • Always set MB_UNIT_ID = 1 for a pure Modbus TCP server. The 16#FF default is a heritage from the ET 200S serial era and is rejected by a majority of third-party slaves.
  • Allocate a unique CONNECT.ID per MB_CLIENT instance. Reusing IDs across instances causes 16#80A1 at runtime, not at compile time.
  • Use a single global MB_CLIENT_DB shared by all calls when polling multiple registers on the same device. The Siemens FAQ on this topic is explicit: a single MB_CLIENT can perform multiple function codes by re-triggering REQ; multiple MB_CLIENT instances targeting the same server should be consolidated to avoid wasted connections.
  • Address convention differs by function code. FC 1/2/3/4 use 0-based coil/register numbers in MB_DATA_ADDR; FC 5/6/15/16/23 use 1-based. Mapping a holding register of address 40001 requires MB_DATA_ADDR = 0 (or 40001 depending on the documentation; cross-check with the device's register map).
  • Disable any third-party firewall on the engineering PC during commissioning. Windows Defender silently drops outgoing TCP to port 502 on some patch levels.
  • Document the slave device's required Unit ID in the project comments. MB_UNIT_ID is not visible in the project tree, only in the instance DB. Without an explicit comment, a future maintainer will reset it to the default.

11. Related Configuration: CPU Side

The CPU 1513-1 PN uses its first PROFINET interface (X1) for Modbus TCP. Configuration steps on the device side:

  1. Device view → CPU 1513-1 PN → PROFINET interface [X1] → Properties → Ethernet addresses.
  2. Set IP address (e.g. 192.168.0.2), subnet mask (255.255.255.0), and ensure no router is configured for a flat network.
  3. Under Connection resources, verify the CPU is configured for S7 connections, TCP connections, and ISO-on-TCP as required. The default allows all three.
  4. Under Security → Connection mechanisms, ensure the Permit access with PUT/GET option is enabled if you also need S7 communication, although this is independent of Modbus TCP.

12. Quick Reference Card

Item Value
Default MB_UNIT_ID (shipped) 16#FF (255)
Recommended MB_UNIT_ID (pure TCP server) 16#01 (1)
Recommended MB_UNIT_ID (serial bridge) 1..247 (RTU slave address)
Standard Modbus TCP port 502/TCP
ConnectionType 16#0B
ActiveEstablished (client) TRUE
Maximum MB_DATA_LEN for FC 3/4 125 registers
Maximum MB_DATA_LEN for FC 1/2 2000 bits
MB_CLIENT location in TIA Portal Instructions → Communication → MODBUS TCP
Minimum TIA Portal version V14 SP1

What is the MB_UNIT_ID parameter in Modbus TCP on a S7-1500 CPU?

MB_UNIT_ID is the slave identifier transmitted in byte 6 of the Modbus Application Protocol (MBAP) header. On a pure Modbus TCP network it must match the value expected by the server — typically 1. The TIA Portal default is 16#FF (255), which a majority of third-party Modbus TCP servers (Schneider PAC3200, WAGO 750-352, Moxa gateways) silently reject, causing STATUS = 16#80D2.

Why does the default MB_UNIT_ID in TIA Portal ship as 16#FF?

The MB_CLIENT instruction was originally developed for the ET 200S serial gateway and carried over to the S7-1500 platform. The default 16#FF is the value recommended by the Modbus Messaging on TCP/IP Implementation Guide v1.0b for legacy interoperation with serial-bridged networks. TIA Portal does not flag the default as an error at compile time, so the mismatch is only visible at runtime when the partner device closes the socket.

Which port must be configured for Modbus TCP on the S7-1500?

Use 502/TCP. This is the IANA-assigned port for Modbus TCP. Set RemotePort = 502 in the TCON_IP_V4 connection description of the MB_CLIENT block. Avoid non-standard ports (e.g. 2000, 5000) unless the target device explicitly requires them.

How do I find the right MB_UNIT_ID for a specific Modbus TCP server?

Consult the device's user manual under "Modbus TCP" or "Communication". Most pure Modbus TCP servers expect 1. Serial-bridged gateways (Moxa, Digi) often require the Unit ID to equal the RTU slave address of the downstream device, in the range 1..247. If the value is unknown, start with 1 and verify with a Wireshark capture: the server's response will not arrive if the Unit ID is wrong.

What STATUS code indicates the MB_UNIT_ID is wrong?

STATUS = 16#80D2 ("No response from partner") is the typical signature. The CPU transmits the Modbus request with the wrong Unit Identifier, the server discards the frame and closes the TCP connection, and MB_CLIENT reports the timeout. STATUS = 16#80C8 ("Partner not reachable") can also appear if the server resets the socket fast enough to be treated as a connection failure. The two are often confused — both can be resolved by setting MB_UNIT_ID = 1 and re-establishing the connection.

Can a single MB_CLIENT instance poll multiple registers on the same Modbus TCP server?

Yes. A single MB_CLIENT instance handles one request at a time, but by re-triggering REQ with new MB_MODE / MB_DATA_ADDR / MB_DATA_LEN parameters it can sequentially poll as many registers as needed without closing the TCP connection. Using one instance per register wastes connection resources and is the most common cause of 16#80A1 ("Connection ID in use") errors on S7-1500 CPUs.

Back to blog