How-to
Connect an S7-200 to a Modbus RTU sensor and read its register
Short answer
Confirm the exact S7-200 CPU and Micro/WIN library first, then call MBUS_CTRL once on every scan to initialize the Modbus RTU master and MBUS_MSG to read the sensor's holding register with matching serial settings (example: 9600 baud, even parity). Decode the returned 16-bit word with the sensor's documented scale, and use a gateway if the library is unavailable.
On this page
The direct path is a Micro/WIN Modbus RTU master library on the S7-200: call MBUS_CTRL on every scan to initialize the master, then MBUS_MSG with the sensor's slave address and holding-register number, and decode the returned word with the sensor's own scale. If your CPU will not take the library, put a serial gateway between the PLC and the sensor instead of forcing the port. This article walks through verifying the CPU, matching the serial settings, writing the two calls, and decoding the register.
Confirm the CPU and the library before wiring #
The S7-200 does not speak Modbus RTU out of the box; the master instructions come from the Siemens Standard Instruction Library add-on in STEP 7-Micro/WIN. Check three things before you write a line of logic: the exact CPU part number, the firmware version on that CPU, and the Micro/WIN version you will program it with, because the library only installs into the matching software version.
If the library cannot be loaded on your installed base, stop here and plan a gateway: the sensor stays Modbus RTU, the PLC keeps its own protocol, and the gateway translates. That is a supported architecture, not a workaround.
Collect the sensor's documented values #
The sensor is a lab device on a C8051F350 system-on-chip, so its register map is whatever its documentation defines, not a standard product table. From the sensor documentation you need five values before programming:
- Slave address on the RS-485 segment
- Serial framing: baud rate, data bits, parity, stop bits
- Holding register number that carries the temperature
- Data type, byte order and signedness of that register
- Scale from raw word to degrees C
Do not assume the returned word is already temperature in tenths of a degree. Lab sensors commonly expose counts or an offset-scaled value; substituting an assumed scale is the most common way to get a healthy Modbus exchange and a wrong number.
Wire the RS-485 segment #
Connect the sensor's RS-485 A and B lines to the S7-200 communication port through an RS-485 converter or the port's own lines, matching A to A and B to B, and terminate both ends of the segment. The S7-200 port is a freeport-capable serial interface; the library drives it, so no separate communication module is needed for RTU on the classic CPUs. Ground the shield at one end only.
Write the master program #
The library adds two folders of instructions to Micro/WIN. For a master you use MBUS_CTRL and MBUS_MSG:
- Call MBUS_CTRL once on every scan, enabled by SM0.0 (ALWAYS_ON), so the master stays initialized and its function control runs continuously. Set the baud rate, parity, port number and timeout to match the sensor's serial framing. Restarting initialization conditionally is a common cause of intermittent faults; call it unconditionally.
- Call MBUS_MSG with the slave address, the read function for holding registers, the register number, the word count, and a data pointer in V memory. Edge the First input so the call fires once per polling cycle, not on every scan.
- One MBUS_MSG call performs one transaction. For several registers on one sensor, increase the word count in the same call; for several sensors on one segment, use one MBUS_MSG call per slave address and interleave them so each completes before the next starts.
- Check the status output of each call every scan. A nonzero code means the transaction failed; zero means the V memory now holds fresh data.
Set the serial parameters from the sensor's sheet, not from habit. A typical environmental sensor reads 9600 baud, 8 data bits, even parity, 1 stop bit; with even parity each character carries 11 bits on the wire, and both ends must agree bit for bit or nothing answers.
Example: timing one temperature read at 9600 baud #
Inputs: an 8-byte read request and a 7-byte response for one holding register (from the Modbus RTU frame layout), an 11-bit character frame (8 data bits plus start, parity and stop from the sensor sheet's even-parity setting), 9600 bits per second, an assumed slave turnaround of 10 ms before it replies, and the 3.5-character silent interval that separates frames.
The rule in words: poll time equals wire time for both frames, plus the slave turnaround, plus the inter-frame silence.
Arithmetic: 15 bytes total on the wire at 11 bits each is 165 bits; at 9600 bits per second that is 165 / 9600 = 17.2 ms. The silent interval is 3.5 characters, or 3.5 x 11 / 9600 = 3.99 ms, applied twice around the exchange, about 8 ms. Adding the 10 ms turnaround gives 17.2 + 8 + 10 = 35.2 ms per poll.
Result: one complete temperature read takes roughly 35 ms at these settings.
Decision: a 35 ms poll updates the temperature about 28 times a second, far beyond what environmental monitoring needs, so the serial port is never the bottleneck for one sensor. When the number instead climbs into the hundreds of milliseconds, look first at the timeout parameter in MBUS_CTRL and at retries from a framing mismatch, not at the wire.
When data arrives but the temperature is wrong #
Separate transport from decoding. If MBUS_MSG returns zero, the frames are clean and the problem is in how you read the word:
- Confirm the register number points at the temperature and not a status or configuration register; a read that strays onto an unimplemented address returns an exception or stale data, the failure behind Modbus exception 02 when a read crosses a register map gap.
- Check signedness: a temperature below 0 degrees C arrives as a two's-complement negative word and reads as about 65,000 if treated as unsigned.
- Check byte order if the sensor documentation specifies word swap.
- Apply the documented scale and offset, then verify against a physical reference: hold the sensor at ice water and confirm the decoded value lands at 0 degrees C.
If MBUS_MSG returns an error instead, move to the wiring and settings list: A/B swap, termination, parity and baud mismatch, or the sensor expecting an RS-232 level where you delivered RS-485.
One safety note: this communication path is for monitoring only. Do not route anything that can start or stop equipment through an unvalidated Modbus write from SCADA or the sensor segment.
The decision, in short #
With the library installed, wire the segment, call MBUS_CTRL every scan, poll the sensor's holding register with MBUS_MSG, and scale the word as documented; one read costs about 35 ms at 9600 baud, so a single sensor is trivially served. Without the library, plan a gateway rather than hand-rolling freeport framing. Either way, treat a wrong temperature with clean communication as a decoding problem and fix the scale, not the wire.
Questions asked
Does every S7-200 CPU support the Modbus RTU master library?
The Siemens Standard Instruction Library is a Micro/WIN add-on, and not every CPU and firmware revision carries the memory and library support it needs. Before writing code, confirm the exact CPU part number and firmware, and get the matching Micro/WIN version from the manufacturer's own channels. If your CPU cannot load the library, a serial protocol gateway that speaks Modbus RTU to the sensor and the PLC's own protocol to the S7-200 is the supported alternative.
Why does my read return valid data but a wrong temperature?
That is a decoding fault, not a serial fault. The register returns a raw 16-bit word; the temperature depends on the sensor's documented scale and signedness. Check the register map entry for data type and byte order, apply the scale, then hold the sensor at a known reference, such as ice water at 0 degrees C, and verify the decoded value moves to that point. Compare raw word, decoded value, and PLC value so they track together.
Can I read several sensors from one S7-200 port?
Yes, if they share the same serial settings and sit on the same RS-485 segment at different slave addresses. Call MBUS_MSG once per device per pass, since one call handles one transaction. Total update time is roughly the per-poll time times the device count; at about 31 ms per poll, ten sensors still update inside half a second, which is fast enough for environmental temperature.