S7-1200 Modbus TCP Client Setup with King Pigeon M340T RTD

David Krause15 min read
S7-1200SiemensTutorial / 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 an S7-1200 as a Modbus TCP Client for a King Pigeon M340T RTD Module

This reference walks through commissioning a Siemens SIMATIC S7-1200 (CPU 1212C / 1214C DC/DC/DC, firmware V4.5) as a Modbus TCP client that polls a King Pigeon M340T 8-channel RTD acquisition module acting as a Modbus TCP server. The procedure is presented for TIA Portal V17 and the MODBUS_TCP library "v6.0" delivered with the S7-1200 instruction set. Each step includes the parameter, register, or tag involved, the value to enter, and the verification method.

Engineering note: The King Pigeon M340T is unusual among Modbus TCP devices because it still expects a Slave ID byte in the Modbus ADU even though the unit address in the MBAP header is normally used by Modbus TCP. Configure a non-zero Slave ID on the M340T before commissioning.

1. System Overview and Architecture

The integration consists of two nodes on the same Ethernet subnet:

  • Modbus TCP Client (Master) — S7-1200 CPU 1212C / 1214C, PROFINET interface X1.
  • Modbus TCP Server (Slave) — King Pigeon M340T, default listen port 502.

The S7-1200 initiates a TCP connection on port 502, then issues Function Code 04 (Read Input Registers) against the 3xxxx address space of the M340T. Eight temperature values (one per RTD channel) are returned and written into an S7-1200 data block where the user program processes them.

Table 1 — Network parameters used in the reference project
Parameter S7-1200 (Client) King Pigeon M340T (Server)
IP address 192.168.0.10 192.168.0.20
Subnet mask 255.255.255.0 255.255.255.0
Default gateway 192.168.0.1 192.168.0.1
Modbus TCP port n/a (client) 502 (default)
Modbus Slave ID n/a 1 (must be non-zero)
Local TSAP 01.00 n/a
Remote TSAP 02.00 n/a

2. Prerequisites

2.1 Hardware

  • S7-1200 CPU 1214C DC/DC/DC or 1212C DC/DC/DC, firmware V4.4 or later (V4.5 used in the reference project). CPUs below V4.0 do not include the Modbus TCP v6.0 instruction set.
  • King Pigeon M340T 8-channel RTD module with PT100/PT1000/Cu50 sensors wired to channels 1–8.
  • Ethernet cable (Cat 5e or higher) connecting the CPU PROFINET port to the M340T RJ-45 port or to a managed switch on the same subnet.
  • 24 VDC power supply rated for at least 1.5 A to feed the M340T and the RTD excitation current.

2.2 Software

  • STEP 7 / TIA Portal V17 (or V16 Update 4 with the Modbus TCP V6.0 library patch).
  • MODBUS_TCP instruction library "v6.0" — installed automatically with TIA Portal V17 for S7-1200 CPU V4.4+.
  • Optional: CAS Modbus Scanner or Modbus Poll for bench verification of the M340T before involving the PLC.
Verify the library version: In TIA Portal, expand Instructions → Communications → Others → MODBUS TCP. The version block visible under the folder must read "v6.0" or later. Older libraries (v3.x / v4.x) use different MB_CLIENT input names and do not support optimized data blocks with non-optimized buffers the same way.

3. King Pigeon M340T Register Map

The M340T exposes its data through Modbus Input Registers (function code 04, address prefix 3xxxx). The Modbus Holding Register block (function code 03, 4xxxx) is reserved for configuration parameters and should not be used for polling temperature data. The register map below is reproduced from the official M340T user manual.

Table 2 — M340T Input Register map (Function Code 04)
Address (1-based, 3xxxx) Address (0-based, %MW) Symbol Description Unit
30001 0 AIN1RTD1 Channel 1 RTD raw ADC value counts
30002 1 AIN1RTD2 Channel 2 RTD raw ADC value counts
30003 2 AIN1RTD3 Channel 3 RTD raw ADC value counts
30004 3 AIN1RTD4 Channel 4 RTD raw ADC value counts
30005 4 AIN1RTD5 Channel 5 RTD raw ADC value counts
30006 5 AIN1RTD6 Channel 6 RTD raw ADC value counts
30007 6 AIN1RTD7 Channel 7 RTD raw ADC value counts
30008 7 AIN1RTD8 Channel 8 RTD raw ADC value counts
30009 8 RTD1_TEMP Channel 1 temperature, post-scaling and calibration °C × 10
30010 9 RTD2_TEMP Channel 2 temperature °C × 10
30011 10 RTD3_TEMP Channel 3 temperature °C × 10
30012 11 RTD4_TEMP Channel 4 temperature °C × 10
30013 12 RTD5_TEMP Channel 5 temperature °C × 10
30014 13 RTD6_TEMP Channel 6 temperature °C × 10
30015 14 RTD7_TEMP Channel 7 temperature °C × 10
30016 15 RTD8_TEMP Channel 8 temperature °C × 10
Units: The eight "TEMP" registers at 30009–30016 store the temperature value as a signed 16-bit integer that represents °C multiplied by 10. Divide by 10.0 in the user program to obtain engineering units. For example, a register value of 253 means +25.3 °C; a value of -150 means -15.0 °C.

4. Engineering the MB_CLIENT Request

The MB_CLIENT instruction in the v6.0 library is configured with the following fixed parameters for this application:

Table 3 — MB_CLIENT static inputs
Input Type Value Notes
REQ BOOL edge-triggered Rising edge initiates a single transaction.
DISCONNECT BOOL FALSE Hold the TCP connection open.
MB_MODE USINT 0 0 = Read, 1 = Write.
MB_DATA_ADDR UINT 9 Modbus start address (0-based). 9 = register 30010 (30009 + 1 offset).
MB_DATA_LEN UINT 8 Read eight registers (30010 through 30017 in 1-based numbering).
MB_DATA_PTR VARIANT DB buffer Pointer to ARRAY[0..7] of WORD.
CONNECT VARIANT TCON_IP_v4 DB Connection description.
TIMEOUT TIME T#2s Response timeout; raises 16#80C8 if exceeded.
Address offset rule: Modbus function codes reference registers in 1-based notation (30001 = first input register). MB_CLIENT on the S7-1200 expects a 0-based address. To read registers 30009 through 30016, enter MB_DATA_ADDR = 8 (the first register address minus one) and MB_DATA_LEN = 8. The buffer then holds eight words corresponding to channels 1–8.

5. Step-by-Step TIA Portal Configuration

  1. Create the project and add the CPU. Launch TIA Portal V17, create a new project, then Add new device → Controllers → SIMATIC S7-1200 → CPU → CPU 1214C DC/DC/DC (or 1212C). Confirm firmware V4.4 or later in the order number suffix.
  2. Configure the PROFINET interface. Open Device view → CPU → PROFINET interface → Ethernet addresses. Set IP 192.168.0.10, subnet 255.255.255.0, and disable the PROFINET device name (leave empty) since the S7-1200 is acting only as a Modbus TCP client.
  3. Insert MB_CLIENT. In the program block (OB1 or a dedicated cyclic OB), drag Instructions → Communications → Others → MODBUS TCP v6.0 → MB_CLIENT onto the network. Place a single instance DB (the wizard creates it automatically) named MB_CLIENT_DB.
  4. Create the connection data block. In a new global DB, declare a tag TCON_IP_v4 with the structure type TCON_IP_v4 (found under PLC data types → Communications → Others). Populate the fields:
Table 4 — TCON_IP_v4 parameter population
Field Value Comment
InterfaceId 64 (default for PROFINET X1) Hardware identifier of the local PROFINET interface.
ID 1 Connection ID, must be unique within the project (range 1–4095).
ConnectionType 16#0B (TCP) Required for Modbus TCP.
ActiveEstablished TRUE S7-1200 initiates the connection (active).
LocalDeviceId 0 Leave at default for direct Ethernet.
LocalTsapId 16#0100 Local TSAP = 01.00 (S7-1200 convention).
RemoteDeviceId 0 Leave at default.
RemoteTsapId 16#0200 Remote TSAP = 02.00 (M340T partner port).
NextStaddr 192.168.0.20 M340T IP address (must be a STRING of the form '192.168.0.20').
RemotePort 502 Modbus TCP port (decimal).
  1. Create the data buffer DB. Add a second global DB (for example RTD_Data) and uncheck "Optimized block access" in the DB properties. Without this step, MB_CLIENT cannot resolve MB_DATA_PTR at compile time and reports 16#80C3 or a build warning. Inside, declare:
DATA_BLOCK "RTD_Data"
{ S7_Optimized_Access := 'FALSE' }
VERSION : 0.1
NON_RETAIN
  STRUCT
    Temperatures : ARRAY[0..15] OF WORD;   // 16 words; first 8 used
    RawCounts    : ARRAY[0..7]  OF WORD;   // optional raw ADC buffer
  END_STRUCT;
END_DATA_BLOCK
  1. Wire the MB_CLIENT inputs in OB1. Drive REQ with a clock-bit or a periodic task (see Section 7). Pass "RTD_Data".Temperatures as MB_DATA_PTR. Pass the connection structure by reference (AT notation or symbol). The complete call in Structured Text (SCL) for an FB:
// Polling block: OB1 calls this every 200 ms via cyclic interrupt
IF NOT %DB_MB_CLIENT_DB.Busy AND NOT %DB_MB_CLIENT_DB.Error THEN
    "MB_CLIENT_DB"(REQ := TRUE,
                  DISCONNECT := FALSE,
                  MB_MODE := 0,
                  MB_DATA_ADDR := 8,       // 0-based: register 30009
                  MB_DATA_LEN := 8,
                  MB_DATA_PTR := "RTD_Data".Temperatures,
                  CONNECT := "Conn_DB".TCON_IP_v4,
                  TIMEOUT := T#2s);
END_IF;

6. Slave ID and the MBAP Header

Modbus TCP normally does not use the Slave ID byte (Unit Identifier, UID), but the King Pigeon M340T expects a non-zero value, otherwise it discards the request. The UID is not an MB_CLIENT input; it must be hard-coded inside the M340T's own configuration web page.

  1. Open a browser and navigate to http://192.168.0.20 (default M340T web interface).
  2. Log in with the factory credentials and open Modbus Settings.
  3. Set Modbus Slave ID = 1. Any non-zero value in the range 1–247 is acceptable, but both ends of the link must agree.
  4. Confirm the listen port is still 502 unless the network policy mandates a non-standard port.
Common commissioning pitfall: A Slave ID of 0 is silently accepted by many slaves but causes the M340T to ignore every read request. Symptoms include MB_CLIENT receiving no response and timing out with 16#80C8, even though Wireshark shows a valid TCP three-way handshake and outgoing Modbus ADU.

7. Polling Cadence and Timing

The MB_CLIENT is edge-triggered: a single rising edge of REQ issues exactly one transaction. If REQ stays high, the block internally re-triggers as soon as the previous transaction completes, but this prevents user code from reacting to errors. The recommended pattern is:

  • Drive REQ from a cyclic interrupt OB (OB30) at a configurable interval. RTD temperatures typically change slowly; 250–500 ms is sufficient.
  • Check MB_CLIENT_DB.Done on the next scan after the trigger to read the freshly updated buffer.
  • Latch MB_CLIENT_DB.Error into a sticky bit and capture the static STATUS word for diagnostics.
Table 5 — Recommended OB30 cycle time vs. process dynamics
Cycle time Suitable for Comment
100 ms Fast reacting loops Risk of saturating the M340T queue.
250 ms HVAC, ambient monitoring Default for this reference project.
500 ms Bearing or motor temperature Balanced load.
1 s Slow oven / tank Maximizes network headroom.

8. Error Code Reference

MB_CLIENT surfaces all errors through the STATUS output word. Some of the codes most frequently seen on a King Pigeon M340T integration are listed below.

Table 6 — Common MB_CLIENT STATUS codes
STATUS (hex) Meaning Typical cause Corrective action
16#0000 No error
16#7000 No job active REQ not yet seen Verify REQ is being pulsed.
16#7001 First execution Block initializing Wait one cycle.
16#7002 Subsequent execution Job in progress Wait for DONE.
16#80C3 Invalid MB_DATA_PTR Optimized DB or wrong length Disable optimized access on buffer DB; confirm array length ≥ MB_DATA_LEN.
16#80C4 Modbus exception from server Illegal function / data address Verify register number, FC (04 for 3xxxx), and Slave ID on M340T.
16#80C8 Response timeout M340T not responding within TIMEOUT Increase TIMEOUT; ping M340T; check Slave ID ≠ 0; verify MB_DATA_ADDR (0-based).
16#80D1 Connection request rejected Remote TSAP, port, or IP wrong Confirm port 502 open and TSAP = 02.00 at the partner.
16#80D2 Connection aborted by partner M340T power cycled or wrong Slave ID Reset M340T; re-check UID byte.
16#8380 Modbus connection not established CONNECTION_DB misconfigured Re-check TCON_IP_v4 fields.
16#8381 Modbus exception code 02 (illegal data address) Reading beyond end of map Reduce MB_DATA_LEN or lower start address.
16#8382 Modbus exception code 03 (illegal data value) Writing illegal value For read-only operation, ensure MB_MODE = 0.
16#8383 Modbus exception code 04 (slave device failure) Internal M340T fault Cycle power; check RTD wiring.

9. Troubleshooting Matrix

Table 7 — Symptom → cause → remedy
Symptom Likely cause First action
MB_CLIENT reports 16#80C8 immediately Slave ID = 0 on M340T Set M340T Slave ID to 1, cycle power.
MB_CLIENT reports 16#80D1 Wrong port or firewall Telnet to 192.168.0.20:502 from PC.
Wireshark shows TCP SYNs but no Modbus ADU MB_CLIENT never receives REQ Monitor REQ bit in online watch table.
ADU transmitted, no reply M340T in Modbus RTU master mode (RS-485) Switch M340T to Modbus TCP server mode.
Temperatures read as 65535 (0xFFFF) Channel open or RTD out of range Check wiring and sensor type configuration.
All values read as -32768 Buffer DB optimized Disable optimized block access.
Values appear correct but with one-register offset 1-based vs 0-based address error Subtract 1 from MB_DATA_ADDR.
DONE never goes TRUE; BUSY stuck Same MB_Client used for two slaves simultaneously One MB_CLIENT instance per remote device.

10. Verification and Commissioning Procedure

  1. Bench-test the M340T independently. With the S7-1200 disconnected, point CAS Modbus Scanner at 192.168.0.20:502 with Slave ID 1 and Function 04 starting at 30009. Confirm eight integer values appear and respond to physical changes (heat the PT100 with your hand and watch register 30010 climb).
  2. Compile and download to the S7-1200. Use TIA Portal's Compile → Download to device. Open the online watch table and add the buffer DB RTD_Data.Temperatures[0..7] plus MB_CLIENT_DB.Done, MB_CLIENT_DB.Busy, MB_CLIENT_DB.Error, MB_CLIENT_DB.STATUS.
  3. Force REQ once. Manually set REQ from the watch table. The block should pulse BUSY for one cycle, then DONE = TRUE, and Temperatures[0..7] should populate.
  4. Cross-check values. Compare the values to those seen in CAS Modbus Scanner. They must match exactly; any deviation indicates an address offset.
  5. Convert to engineering units. Apply Temp_C[ch] := INT_TO_REAL("RTD_Data".Temperatures[ch]) / 10.0; in a separate FB to obtain degrees Celsius.
  6. Verify error handling. Disconnect the Ethernet cable, confirm STATUS rises to 16#80C8 within TIMEOUT, and the sticky error bit latches. Reconnect, confirm STATUS clears within one or two cycles.
  7. Stress-test cyclic interrupt. Drop OB30 cycle time to 100 ms for one minute. STATUS must remain 16#0000 throughout; Done must toggle at the requested cadence.
Tip for unattended sites: Many S7-1200 programmers wrap MB_CLIENT in a "watchdog" — a TON timer that resets the connection (RECONNECT or full RESTART of the MB_CLIENT instance) if STATUS has been non-zero for more than 10 s. The M340T occasionally stops responding after power dips and needs a fresh TCP session.

11. Scaling and Out-of-Range Handling

The M340T reports negative temperatures in two's-complement signed 16-bit integers. When the buffer is declared as WORD (unsigned), values below 0 °C appear as 16#8000 through 16#FFFF. Three options are available to the programmer:

  1. Declare the buffer as ARRAY[0..7] OF INT instead of WORD. MB_CLIENT will move signed values directly.
  2. Keep WORD but apply WordToInt to each element before scaling.
  3. Test for 16#7FFF (positive overflow) or 16#8000 (negative overflow / open sensor) before scaling.
// SCL scaling routine
FOR i := 0 TO 7 DO
    IF "RTD_Data".Temperatures[i] = 16#7FFF THEN
        "Process".TempStatus[i] := 16#0001;  // sensor open
    ELSIF "RTD_Data".Temperatures[i] = 16#8000 THEN
        "Process".TempStatus[i] := 16#0002;  // out-of-range high
    ELSE
        "Process".TempC[i]    := INT_TO_REAL(WORD_TO_INT("RTD_Data".Temperatures[i])) / 10.0;
        "Process".TempStatus[i] := 16#0000;  // valid
    END_IF;
END_FOR;

12. Optional: Reading Raw ADC Counts

If you need access to the un-scaled ADC counts at 30001–30008 (for custom linearization, for example), issue a second MB_CLIENT call with MB_DATA_ADDR = 0 and MB_DATA_LEN = 8. The M340T returns the raw 16-bit A/D counts that have not been multiplied by 10 or had any calibration offset applied. The conversion to resistance uses the Steinhart-Hart equation or the PT100 lookup table in IEC 60751. Confirm the wiring for the calibration offset in the M340T web interface before mixing raw and scaled data in the same buffer.

13. Edge Cases and Field Notes

  • Mixing MB_CLIENT and MB_SERVER on the same CPU. A single S7-1200 can simultaneously host one MB_SERVER (e.g., for an HMI) and several MB_CLIENT connections. Each MB_CLIENT must use a unique connection ID and a unique instance DB. Sharing the buffer DB between an MB_SERVER read and an MB_CLIENT write is undefined behavior.
  • Multiple M340T devices on one CPU. Add one MB_CLIENT instance per M340T. Stagger their REQ triggers by at least one OB30 cycle to avoid overlapping responses on a shared Ethernet segment.
  • Firmware V4.5 vs V4.6 differences. CPU firmware V4.6 added extended STATUS codes (16#80C9 for partner-initiated reset) that V4.5 maps to the older 16#80D2 code. Either firmware works for this integration; the codes documented in Section 8 cover both.
  • Watchdog reset on network loss. If STATUS has been 16#80C8 or 16#80D2 for longer than 30 s, drop DISCONNECT for one second, then re-establish. Use a separate counter DB to track consecutive failures before triggering a reconnect.
  • King Pigeon Modbus RTU master function. The M340T also exposes an RS-485 Modbus RTU master capable of reading external slaves. If this feature is enabled in the M340T web UI, it can collide with the TCP server if both try to write the same internal register. Use the TCP server exclusively unless the Modbus RTU master has been disabled in configuration.

14. Quick-Reference JSON Snippet for the Connection DB

For projects using TIA Portal's Openness API, the connection description can be exported as JSON:

{
  "InterfaceId": 64,
  "ID": 1,
  "ConnectionType": 11,
  "ActiveEstablished": true,
  "LocalDeviceId": 0,
  "LocalTsapId": "01.00",
  "RemoteDeviceId": 0,
  "RemoteTsapId": "02.00",
  "NextStaddr": "192.168.0.20",
  "RemotePort": 502
}

15. Frequently Asked Questions

Why does MB_CLIENT time out (16#80C8) even though the M340T responds to a Modbus scanner?

The most common reason is that the M340T Slave ID is set to 0 in its web configuration. The M340T silently discards Modbus/TCP requests when the Unit Identifier (UID) in the MBAP header does not match its configured Slave ID. Set Slave ID to a non-zero value (typically 1) and confirm the MB_CLIENT TIMEOUT input is at least T#2s.

Should I use MB_CLIENT or MB_SERVER in TIA Portal for this integration?

Use MB_CLIENT. The S7-1200 must be the Modbus master/client that initiates requests to the King Pigeon M340T, which acts as the server/slave. MB_SERVER is only needed when another Modbus master (such as an HMI or SCADA) needs to read or write tags inside the S7-1200.

What is the correct MB_DATA_ADDR for reading temperatures from channels 1–8?

MB_CLIENT expects a 0-based address. To read the scaled temperature registers 30009–30016 (channels 1–8 in °C × 10), enter MB_DATA_ADDR = 8 (the first register number minus one) and MB_DATA_LEN = 8. The eight returned words are placed into your buffer DB in order.

Do I need to disable optimized block access on the data buffer DB?

Yes. MB_CLIENT requires a non-optimized (standard) DB so that the absolute memory addresses can be resolved at compile time. Open the DB properties and uncheck "Optimized block access"; otherwise MB_CLIENT will report 16#80C3 or fail to compile cleanly.

Can I poll more than one M340T from a single S7-1200?

Yes. Add one MB_CLIENT instance per M340T, each with its own instance DB and connection description (unique ID). Stagger the REQ pulses using separate cyclic interrupt OBs or offsets so that two responses do not arrive in the same PLC scan. The M340T default listen port 502 can remain unchanged on every device since the IP address differentiates them.

Back to blog