Configuring S7-400 Modbus/TCP Communication in STEP 7 V5.5

David Krause18 min read
ModbusSiemensTutorial / 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

Configuring S7-400 Modbus/TCP Communication in STEP 7 V5.5

Overview

Modbus/TCP is the de facto standard for industrial Ethernet communication between a SIMATIC S7-400 controller and third-party PLCs, drives, SCADA nodes, and instrumentation. The protocol rides on TCP port 502, the standard Modbus/TCP port defined in the Modbus Organization's specification Modbus Application Protocol V1.1b3. The classic Modbus RTU frame is encapsulated in a 7-byte MBAP (Modbus Application) header plus a PDU (Protocol Data Unit) payload that carries the function code, starting address, quantity, and data bytes.

The S7-400 family supports Modbus/TCP through two distinct paths. The first path is the native "Modbus/TCP PN" capability that ships with PN-CPUs of the S7-300/400 generation when the firmware supports the stack and a license is present on the SIMATIC Memory Card. The second path is the SIMATIC Modbus/TCP Wizard / library bundle (catalog numbers 6AV6676-6MB10-0AX0 for H-redundancy and 6AV6676-6MB20-3AX0 for single stations) for S7-300/400 stations that need Modbus/TCP but do not have the integrated PN-CPU Modbus option, or that need redundant communication. The application note How do you configure a Modbus/TCP communication for a SIMATIC S7-300/S7-400 and where can you find further information? is the canonical Siemens reference for this configuration.

Prerequisites

Item Requirement
Engineering tool SIMATIC Manager V5.5 SP4 (or V5.5 + latest HF) on Windows 7 / Windows 10
PLC S7-400 CPU with PROFINET interface (e.g., CPU 414-5 H PN/DP, CPU 416-3 PN/DP)
Firmware PN interface firmware supporting Modbus/TCP (V6.0 or higher recommended for CPU 41x PN)
License (native PN path) "Modbus/TCP PN" option for S7-300/400, stored on the SIMATIC Memory Card and bound to the CPU serial number
Ethernet network Layer-2 switch, free IP address for the S7 CPU, IP address of the third-party device, both reachable at L3
Wizard bundle (alternative path) Order number 6AV6676-6MB20-3AX0 (single CPU) or 6AV6676-6MB10-0AX0 (redundant H-system)
Modbus reference Modbus Application Protocol V1.1b3 from the Modbus Organization
Automation License Manager Installed on the engineering station to transfer the Modbus/TCP license to the Memory Card
Network reachability check first. Confirm that the S7 CPU and the third-party device can ping each other and that no firewall, ACL, or routed path is dropping TCP/502. Modbus/TCP uses only TCP port 502; the protocol has no fallback port and no negotiation.

Modbus/TCP Frame Layout

Every Modbus/TCP frame carries the 7-byte MBAP header in front of the function code and the Modbus data. The MBAP fields are transmitted in big-endian byte order on the wire.

Offset Field Length Description
0 Transaction ID 2 bytes Echoed by the server, used to correlate request and response
2 Protocol ID 2 bytes Always 0x0000 for Modbus/TCP
4 Length 2 bytes Number of bytes following this field (unit ID + PDU)
6 Unit ID 1 byte Slave address; 0xFF or 0x00 for non-modbus-tcp-aware devices
7 Function code 1 byte Modbus function code (FC 1, FC 2, FC 3, FC 5, FC 6, FC 15, FC 16, ...)
8+ Data N bytes Starting address, quantity, payload as defined by the function code

Path 1 - Native Modbus/TCP PN on the CPU

When to Choose Native PN

If you have an S7-400 PN CPU (such as the CPU 414-5 H PN/DP) and a single S7-400 station that is not part of a redundant H-system, the native Modbus/TCP PN capability is the lowest-cost and lowest-overhead path. The CPU's PROFINET interface processes Modbus/TCP frames directly, so no additional CP module is required. Connections are configured inside STEP 7 V5.5 under the PROFINET interface properties, and the user program reads/writes Modbus registers as if they were a mirrored S7 data block area.

Firmware and License Requirements

Modbus/TCP server capability on an S7-300/400 PN CPU requires both the firmware on the PROFINET interface that supports the protocol stack (typically introduced on CPU 31x PN/DP and CPU 41x PN from firmware V6.0) and a separate license key for the "Modbus/TCP PN" feature. The license is bound to the CPU's serial number and is stored on the SIMATIC Memory Card. Without a valid license the CPU's PN interface will still accept the TCP/502 open, but the data exchange will be denied at runtime and the diagnostic buffer will record a license error. The licensing and configuration procedure is detailed in the Siemens TIA Portal documentation for the same feature, which is also valid as a reference for the STEP 7 V5.5 path: Modbus/TCP PN - Commissioning (S7-300, S7-400).

STEP 7 V5.5 Configuration Steps

  1. Open the SIMATIC Manager project containing your S7-400 station.
  2. Open the hardware configuration (HW Config) for the S7-400 station.
  3. Select the PROFINET interface of the CPU (X1 or X2 on the CPU 414-5 H PN/DP).
  4. Open the Properties dialog of the PROFINET interface and assign the IP address, subnet mask, and router address. The PROFINET interface must be on the same subnet as the third-party device or have a router that is reachable.
  5. Under the Modbus tab of the interface properties, click New to add a Modbus/TCP connection.
  6. Configure the partner (third-party device) IP address, leave the partner port at 502, and set the S7-400 role (Modbus/TCP server or client) and the connection ID.
  7. Map the Modbus register areas to S7 data blocks: holding registers (4xxxx) and input registers (3xxxx) to DB words, coils (0xxxx) and discrete inputs (1xxxx) to DB bits.
  8. Save and compile the hardware configuration. Download the HW Config to the CPU.
  9. Transfer the Modbus/TCP PN license to the SIMATIC Memory Card using the Automation License Manager.
  10. Insert the Memory Card into the CPU and perform a power-on to activate the license.

Program-Side Interface

The Modbus/TCP PN CPU implementation exposes the Modbus register areas as S7 data blocks. The user program reads and writes the configured DBs to exchange data with the third-party device. For program-side access from a higher-level HMI or another CPU, standard S7 PUT/GET (FB 14 / FB 15) can be used because the area is just a DB on the local CPU. The MBAP parsing, transaction ID tracking, and exception code generation are all handled inside the PN interface firmware, so the user program does not need to deal with the TCP layer at all.

Path 2 - Modbus/TCP Wizard / Library Bundle

Product Numbers and Scope

For S7-400 stations that do not have the native Modbus/TCP PN option, or that require Modbus/TCP on a non-PN CPU using a separate Industrial Ethernet CP, Siemens supplies the SIMATIC Modbus/TCP Wizard bundled with the FBs/FCs that implement the Modbus/TCP client and server roles in software.

Catalog number Scope Use case
6AV6676-6MB10-0AX0 SIMATIC Modbus/TCP Wizard for redundant S7-400H stations H-system CPU 41xH with redundant Modbus/TCP connections, see 6AV6676-6MB10-0AX0 product page
6AV6676-6MB20-3AX0 SIMATIC Modbus/TCP Wizard for single S7-300/400 stations Single S7-300 or S7-400 communicating with a third-party device, see 6AV6676-6MB20-3AX0 product page

The bundle ships with the Modbus/TCP Wizard configuration tool, the FBs/FCs (FB 100 series for the wizard blocks), and full PDF manuals. The manuals are also installed automatically when the demo or full version is installed on the engineering station.

Wizard-Supported Blocks

The wizard generates call-ready instance DBs and inserts the FBs/FCs that handle the Modbus/TCP connection, request/response framing, and data exchange. The user program simply calls the generated blocks with the configured data areas. Typical blocks include:

  • FB 100 - Modbus/TCP master (client) - read holding registers (FC 3)
  • FB 101 - Modbus/TCP master (client) - read input registers (FC 4)
  • FB 102 - Modbus/TCP master (client) - write multiple registers (FC 16)
  • FB 105 - Modbus/TCP slave (server) - register area server
  • FB 106 - Modbus/TCP slave (server) - coil/bit area server
  • UDTs for the connection and request data structures

The Modbus/TCP wizard inserts the generated code into your STEP 7 project, links the required library, and reserves the configured data block areas for Modbus register exchange.

Installation

  1. Insert the Modbus/TCP Wizard installation media (or run the downloaded setup from the Siemens support page linked to the catalog number).
  2. Follow the installer. The wizard integrates into the SIMATIC Manager menu tree and adds the FBs/FCs as a STEP 7 library.
  3. Restart SIMATIC Manager so the wizard menu items appear.
  4. License the wizard using the Automation License Manager.

Wizard Configuration Steps

  1. In SIMATIC Manager, open the S7 project that contains the S7-400 station.
  2. Launch the Modbus/TCP Wizard from the menu (Options > Modbus/TCP Wizard, or the location installed by the bundle).
  3. Select the S7 station and the CPU/CP that will handle Modbus/TCP.
  4. Define the connection: partner IP address, partner port (default 502), S7-400 role (master/slave), and connection ID.
  5. Configure the data exchange: define which Modbus register ranges (4xxxx holding, 0xxxx coils, 3xxxx input, 1xxxx discrete) are mapped to which S7 data blocks.
  6. Generate the program blocks. The wizard writes the FB calls, instance DBs, and DBs that hold the register data into the S7 program.
  7. Save and download the hardware and software to the CPU.

OB1 Call Structure

The wizard inserts the block calls into OB1 in a fixed pattern. A typical generated OB1 segment for a master read of holding registers looks like the following skeleton (the actual instance DB names are wizard-generated):

// Generated by Modbus/TCP Wizard - DO NOT EDIT MANUALLY
CALL  FB 100, DB_Modbus_Master_Read       // Modbus/TCP master - read holding registers
  REQ    := M 0.0                          // Trigger on rising edge
  CONT   := DB_Modbus_Connection           // Connection UDT (IP, port, ID)
  UNIT_ID:= 1                              // Modbus unit ID
  MB_ADDR:= 40001                          // Starting address (4xxxx range)
  QTY    := 100                            // Number of registers to read
  RD     := P#DB_Holding.WordArea          // Pointer to target DB area
  DONE   := M 10.0                         // Job complete (one-shot)
  BUSY   := M 10.1                         // Job in progress
  ERROR  := M 10.2                         // Job error
  STATUS := MW 12                          // Modbus status / exception code
  LEN    := MW 14                          // Bytes actually read

The connection UDT holds the partner IP as four bytes, the partner port (502), the connection ID, and the local TSAP / connection resource. The wizard's documentation lists the full UDT layout for the installed version.

Path 3 - Modbus/TCP via a Separate CP

For older S7-400 CPUs without an integrated PROFINET interface, or for stations that need to keep the PN interface dedicated to PROFINET I/O, an Industrial Ethernet CP (for example, CP 443-1) can carry the Modbus/TCP traffic. The CP is configured with a TCP connection in HW Config, and the wizard blocks run on the CPU. This configuration is identical in principle to Path 2, but the Modbus/TCP frames enter and leave the controller through the CP rather than the integrated PN port of the CPU. The CP must be configured to support a TCP connection on port 502 and must have free connection resources for the Modbus/TCP channel.

Port 502 - What to Know

Modbus/TCP uses TCP port 502 as defined in the Modbus Organization's specification. The port must be open in any firewall, router ACL, or NAT between the S7 station and the third-party device. The native Modbus/TCP PN capability of the S7-300/400 PN CPUs listens on this port; for the wizard bundle the connection is configured with port 502 on both sides. The S7-400 CPU supports multiple concurrent Modbus/TCP connections; the maximum number depends on the CPU type and the connection resources of the PN interface or CP. For the CPU 414-5 H PN/DP, the S7-400 manual specifies a maximum of 64 S7 connections in total, of which a subset may be Modbus/TCP connections - consult the CPU's technical data sheet for the exact figure for your specific CPU order number.

Supported Modbus Function Codes

FC Name Use Typical S7 side
FC 1 Read Coils Read 0xxxx output bits DB bit area, mapped 1:1
FC 2 Read Discrete Inputs Read 1xxxx input bits DB bit area, read-only on Modbus side
FC 3 Read Holding Registers Read 4xxxx 16-bit words DB word area, recommended for bulk reads
FC 4 Read Input Registers Read 3xxxx 16-bit words DB word area, read-only on Modbus side
FC 5 Write Single Coil Write one 0xxxx bit DB bit area, single-bit write
FC 6 Write Single Register Write one 4xxxx word DB word, single-word write
FC 15 Write Multiple Coils Write a range of 0xxxx bits DB bit area, bulk write
FC 16 Write Multiple Registers Write a range of 4xxxx words DB word area, bulk write

For high-throughput links, prefer FC 3 (read) and FC 16 (write) because they carry multiple registers in one transaction and avoid the per-request Modbus overhead. The third-party master's timeout must be set longer than the worst-case S7 scan time of the FB that handles the request; otherwise the master will see timeouts during long cycles.

Data Type Mapping

Modbus/TCP registers are 16-bit unsigned words. The S7-400 stores them as WORD, INT, or UINT inside a DB. Two Modbus registers (= four bytes) form one 32-bit REAL or DWORD. The S7 side is responsible for the byte order; the Modbus standard specifies big-endian for the 16-bit register, so on the S7 side a 32-bit value that crosses a register boundary must be byte-swapped if the rest of the program expects little-endian (the default for S7 REAL). The wizard can be configured to apply the swap automatically; verify by writing a known value (e.g., 0x40490FDB = 3.14159 as REAL) and reading it back from the third-party client.

Connection Diagnostics

Once the program is downloaded and the connection is established, the wizard blocks and the native PN option both expose status and error information in their instance DBs. Use STEP 7 V5.5's Monitor/Modify or a watch table to inspect the status word, error code, and connection state. The Modbus/TCP wizard documentation lists the full set of return values; typical values include:

Status Meaning
0x0000 Connection established, no error
0x8x22 Modbus exception 0x02 - illegal data address
0x8x23 Modbus exception 0x03 - illegal data value
0x8x2A Modbus exception 0x0A - gateway path unavailable
0x80C4 TCP connection error (timeout, partner unreachable)
0x80B0 Connection busy / re-init in progress
0x80A1 Connection aborted by partner (TCP RST/FIN received)

The status of the underlying S7 connection is visible in the standard S7 connection diagnostics (CPU > Connection Information in SIMATIC Manager). For a quick read of the diagnostic buffer, open the online view of the CPU in SIMATIC Manager and select CPU > Diagnostic Buffer.

Verification

  1. In the CPU's online diagnostic buffer, confirm no connection establishment errors. Look for entries such as "Modbus connection established" or "Connection aborted by partner."
  2. In the watch table, force a known value into a Modbus holding register DB on the S7 side and confirm the third-party client reads the same value. Likewise, write a value from the third-party client and confirm the S7 DB updates.
  3. Use Wireshark on a mirror port to capture the TCP stream on port 502 and confirm the MBAP header (transaction ID, protocol ID 0, length, unit ID) and the function code match the configured Modbus request.
  4. For redundant H-systems running the 6AV6676-6MB10-0AX0 bundle, perform a link-switch test and confirm the standby CPU takes over the Modbus/TCP connection without an external timeout.
  5. Stress test by reading 100+ registers in a single transaction (FC 3) and confirm the response time stays within the partner's timeout.

Troubleshooting Matrix

Symptom Likely cause Action
Third-party client cannot open TCP/502 to the S7 Firewall or ACL blocking port 502; wrong IP; CPU in STOP Verify ping, telnet to 502, check CPU operating mode, trace the SYN at the switch
TCP connects but Modbus exception 02 (illegal data address) Register range outside configured DB area Re-run wizard or reconfigure Modbus PN mapping; verify FC code and start address against the configured DB offset
TCP connects but Modbus exception 03 (illegal data value) Quantity or value out of range Verify FC quantity parameter and PLC data types, especially for FC 16 word-count and FC 15 byte-count
Connection drops after a few seconds Keep-alive not honored; partner timeout too short Adjust TCP keep-alive on the S7 connection properties; check partner timeout; verify no NAT session timer on a firewall is killing idle TCP
Intermittent timeouts under load CPU scan time too long; too many simultaneous Modbus requests Reduce Modbus request rate; use multi-register FC 3/16 instead of single-register FCs; raise the OB1 priority for the FB call
Wizard FBs return 0x80C4 / 0x80B0 CP/CPU connection busy or resource exhausted Reduce number of active connections; check CP/CPU connection resources in HW Config; verify the partner is not exceeding the configured number of parallel connections
H-system link switch kills Modbus/TCP Redundancy bundle not licensed or incorrectly configured Confirm 6AV6676-6MB10-0AX0 license is present on the Memory Card and that the wizard was run in redundant mode with the H-system CPU
License missing at runtime Modbus/TCP PN option not transferred to Memory Card Use Automation License Manager to transfer the license; perform a power-on of the CPU with the new card
Read returns 0xFFFF for all words Byte-swap issue on 16-bit boundary Verify the word-endian setting on the third-party master; check whether the wizard is configured to swap bytes
Successful first read, then all subsequent reads timeout Partner's TCP keep-alive is too aggressive for the S7 idle time Configure the S7 Modbus connection with the recommended keep-alive interval; verify the partner respects TCP keep-alive

Cycle Time and Performance

Each Modbus/TCP transaction costs roughly one OB1 cycle of the FB plus the TCP round-trip. For a CPU 414-5 H PN/DP with a 50 ms OB1 cycle, a single FC 3 read of 100 registers from a partner on the same subnet typically completes in well under 100 ms. Bulk transfers of 1000+ registers in one FC 3 read are supported by both the native PN option and the wizard, but the OB1 cycle time grows with the number of registers processed per call. If the application requires a high polling rate, raise the priority of the OB that calls the wizard FB to OB 30 - OB 38 and limit the number of registers per call to 125 (the Modbus spec maximum for FC 3).

Security and Network Considerations

Modbus/TCP has no authentication, no encryption, and no integrity check. The MBAP header has a 16-bit transaction identifier and a 16-bit length field, and the function code is in the clear. Place the S7 station and the third-party device on a private, layer-2 segmented network, ideally a VLAN with no path to the corporate network. If the network must traverse an untrusted segment, terminate it with a stateful firewall that allows only port 502 between the specific Modbus endpoints. Consider wrapping Modbus/TCP in a VPN tunnel for cross-site links. For S7-400 stations that need to expose Modbus/TCP to a higher-trust network, use the CP 443-1's security features (firewall, IP ACL) to restrict access to the CPU's IP and to the port 502 listener.

Firmware and CPU Compatibility

CPU Required firmware for native Modbus/TCP PN
CPU 412-2 PN V6.0 or higher
CPU 414-3 PN/DP V6.0 or higher
CPU 414-5 H PN/DP V6.0 or higher
CPU 416-3 PN/DP V6.0 or higher
CPU 417-4 PN V6.0 or higher

For older firmware revisions or for non-PN CPUs (e.g., CPU 412-1, CPU 414-2 DP, CPU 416-2), the wizard bundle (6AV6676-6MB20-3AX0) running on a CP 443-1 is the supported path.

Migration to TIA Portal

The Modbus/TCP PN option is also exposed in TIA Portal V16 and higher for S7-300/400 projects that have been migrated. The legacy wizard bundle (6AV6676-6MB10-0AX0 / 6AV6676-6MB20-3AX0) is still the supported path for older STEP 7 V5.5 SP4 projects. If the project will be moved to TIA Portal, plan to relicense the Modbus/TCP PN option for the TIA Portal project because the legacy license is bound to the STEP 7 V5.5 project environment. The commissioning procedure for the TIA Portal path is described in the Siemens documentation at Modbus/TCP PN - Commissioning (S7-300, S7-400) and follows the same pattern as the STEP 7 V5.5 setup.

Summary

For a single S7-400 station with a PN CPU running SIMATIC Manager V5.5 SP4, use the native Modbus/TCP PN capability on the CPU's PROFINET interface, license it on the SIMATIC Memory Card, and expose the holding/input/coil/discrete input areas as S7 data blocks. For redundant H-systems, license the 6AV6676-6MB10-0AX0 bundle and use the wizard to configure the redundant connection. For non-PN CPUs or for stations that need Modbus/TCP on a separate CP, license 6AV6676-6MB20-3AX0 and configure the connection through the Modbus/TCP Wizard. In all cases, the protocol runs on TCP port 502, status is monitored through the wizard's instance DBs and the S7 connection diagnostics, and the application is verified end-to-end with a known-value round-trip test and a Wireshark capture on the LAN segment.

How many Modbus/TCP connections does a CPU 414-5 H PN/DP support?

The CPU 414-5 H PN/DP supports up to 64 S7 connections in total, of which a subset can be configured as Modbus/TCP. The exact number depends on the connection resource budget; consult the CPU's technical data sheet for the precise maximum for your specific order number.

What TCP port does Modbus/TCP use?

Modbus/TCP uses TCP port 502 as defined by the Modbus Organization. This is the only port supported by both the native Modbus/TCP PN capability and the Modbus/TCP wizard bundle; there is no fallback port.

Can the S7-400 act as a Modbus/TCP client (master) with the wizard bundle?

Yes. The 6AV6676-6MB20-3AX0 wizard bundle includes FB 100 / FB 101 / FB 102 for client (master) operation, and FB 105 / FB 106 for server (slave) operation. The wizard inserts the correct FB based on the role you select in the wizard dialog.

Do I need a separate license for the native Modbus/TCP PN capability?

Yes. The "Modbus/TCP PN" option for S7-300/400 is a separate license that is bound to the CPU's serial number and stored on the SIMATIC Memory Card. Without a valid license the Modbus/TCP data exchange is denied at runtime even if the configuration is otherwise correct.

Which catalog number is correct for an S7-400H redundant system?

Use 6AV6676-6MB10-0AX0 for S7-400H redundant Modbus/TCP communication. For non-redundant S7-300/400 stations, use 6AV6676-6MB20-3AX0. The two bundles have different FBs/FCs and different licensing scopes and are not interchangeable.

Can I keep SIMATIC Manager V5.5 SP4 and still configure Modbus/TCP?

Yes. SIMATIC Manager V5.5 SP4 supports the Modbus/TCP PN option on PN CPUs and supports the legacy wizard bundle. The wizard FBs/FCs are inserted into the STEP 7 V5.5 project and downloaded to the CPU alongside the standard user program; no TIA Portal migration is required for the legacy path.

Back to blog