IMDHMIControls LibraryShop main store

How-to

Using a PLC as a Modbus RTU to Profibus gateway

Industrial networks Published 9 min read

Short answer

Keep the regulator and let one PLC carry both buses. Poll the regulator over Modbus RTU on a fixed cyclic interval, map every register to a defined PROFIBUS DP location with documented scaling, and hand the BMS a data-valid flag instead of stale values. Terminate each bus at its own two ends; never join RS-485 and PROFIBUS into one network.

On this page
  1. Two separate buses, one translator
  2. What goes in the cabinet
  3. Wire the Modbus RTU side
  4. Wire the PROFIBUS DP side
  5. Configure the bridge in this order
  6. Timing one 16-register poll at 19200 baud
  7. Failure behavior the BMS can trust
  8. The decision for each case
  9. Questions asked

Yes, one PLC can be the gateway. Give it a serial port for the Modbus RTU regulator and a PROFIBUS DP interface for the BMS, poll the regulator on a fixed cyclic interval, and hand the BMS a mapped, scaled and validity-flagged image of its registers. This is a data-model translation job, not a network splice: the RS-485 segment and the DP segment stay two separate buses, each terminated at its own two ends. On an S7-1200-class controller the fit is a CB1241 RS-485 board for the regulator plus the PROFIBUS module whose DP role matches the BMS. The sections below walk the build in order: bus roles, wiring each side, the register map, the polling-cycle arithmetic, and the failure behavior the BMS engineer needs before go-live.

Two separate buses, one translator #

The PLC plays two roles at once. On the regulator side it is the Modbus RTU master: it sends the requests and the regulator answers as a slave — confirm that role in the regulator manual rather than assuming it. On the BMS side the usual arrangement is the reverse: the BMS runs the DP segment as master and the PLC sits on it as a DP slave. The role each side needs is what decides the PROFIBUS hardware, and a role mismatch blocks communication even with perfect wiring.

What the PLC must never do is join the two electrically or logically. Modbus RTU and PROFIBUS DP share RS-485-style differential electronics as a family, but their frames, speeds and termination practice differ, and neither protocol understands the other. The translation happens in the PLC program, between a Modbus receive buffer and a DP image. Two segments, two terminations, one program in the middle.

What goes in the cabinet #

For one regulator per cabinet with local I/O to spare, the build that keeps coming out ahead is a first-generation S7-1200 CPU such as the 1212C, the CB1241 RS-485 communication board for the Modbus RTU link, and the PROFIBUS module that matches the BMS role: the CM1242-5 when the BMS is the DP master and the PLC is a slave — the common BMS case — or the CM1243-5 when this PLC must run the DP segment itself. Treat those two modules as alternatives chosen by role, not a pair to install together, and verify module-and-CPU firmware compatibility with your engineering software version against the module manuals before ordering anything. The PLC also carries the cabinet's local I/O duties, which is exactly what a dedicated protocol gateway cannot do.

Wire the Modbus RTU side #

The wiring rules live in two places: the TIA/EIA-485 electrical standard and the Modbus over Serial Line specification, V1.02, which fixes the practice for Modbus RTU specifically. Run a single twisted pair in a daisy chain from device to device — no stubs, no star branches — with the shield carried through and drained per the device manuals. Keep the A and B lines named the same way at every device: polarity is critical on RS-485, and a bus that never answers although every serial setting checks out is almost always swapped A/B at one end. The cable's characteristic impedance is 120 Ω, and termination belongs only at the two physical ends of the segment, matched to that impedance — not at every device.

The serial settings — baud rate, parity, stop bits — come from the regulator manual and must match at both ends. In the PLC program, the Modbus_Comm_Load instruction configures the communication module for Modbus RTU: it sets the port, baud rate and parity once at startup, and the polling logic then runs against that loaded configuration.

Wire the PROFIBUS DP side #

PROFIBUS DP is standardized in IEC 61158 and brings its own cabling rules even though the electronics are again differential RS-485. Use the dedicated DP cable, run the devices in a line, and engage termination at exactly the two ends. The switch on a DP connector inserts the terminator network — 220 Ω across the pair with 390 Ω bias resistors to the connector's 5 V supply — so a terminating device that loses power takes the whole segment down with it; power the end devices accordingly. At 1.5 Mbit/s, the rate most BMS integrations run, the documented maximum segment length is 200 m.

The BMS engineer needs one file from you: the GSD file describing the PLC's DP interface. The BMS-side DP master project imports it, after which that project assigns the PLC's slot and cyclic data addresses; it is also where the slave watchdog time is set. Build the bridge so the cyclic input area holds regulator values and the cyclic output area holds the BMS command set — nothing else crosses.

Configure the bridge in this order #

  1. Draw the register map before any code. For every point, record the Modbus register address and function code, the data type, the scale and units, the PLC tag it lands in, and the DP-facing offset and direction. Keep regulator addresses and BMS offsets as separate columns so neither end is ever guessed from the other.
  2. Fix the value representation. Check the byte and word order of any multi-register value against a known value observed on the wire, and check whether the BMS consumes floating point at all; if it does not, agree a scaled integer with the BMS engineer and document the scale at both ends.
  3. Bring the serial link up and group the reads. After Modbus_Comm_Load loads the port, read the mapped registers in as few requests as the regulator allows — one block read of consecutive registers beats one request per point.
  4. Poll on a fixed cyclic interval. Every cycle: send the read request or requests, refresh the internal image, count consecutive timeouts. Fixed-cycle polling is easier to diagnose than event-driven tricks and, at these data sizes, costs only single-digit milliseconds of extra age.
  5. Scale and copy in one place. All regulator-to-BMS values pass through one scaling routine into the DP image; nothing else writes that image.
  6. Pass BMS writes through on change only. Compare the commanded value with the last value sent to the regulator and transmit only on a difference, and only for the mapped writable set. Map no point the BMS is not permitted to command: protection and local control stay in the regulator and the PLC, and the BMS gets setpoints and enables, nothing more.
  7. Prove it before the BMS goes live. Check one mapped value whose engineering units you can verify independently at the regulator display, confirm the DP diagnostics show the PLC healthy, and watch the timeout counter over an hour of running. If the Modbus master stops after its first request, the causes are walked through in Modbus communication that terminates after the first poll — port configuration bits are the usual suspects.

Timing one 16-register poll at 19200 baud #

This is the case to work once, then reuse: one regulator whose mapped block fits one read request.

Inputs. 16 consecutive holding registers read with function code 03 — this example's case, a typical setpoint-and-feedback block for one regulator. Port at 19200 bit/s, 8 data bits, even parity, 1 stop bit — the example's settings, the kind Modbus_Comm_Load loads; the regulator manual is the authority for your device. The RTU frame structure fixes the sizes: the request is 1 byte address + 1 byte function + 2 bytes start + 2 bytes count + 2 bytes CRC = 8 bytes; the response is 1 + 1 + 1 byte count + 2 × 16 data bytes + 2 bytes CRC = 37 bytes. RTU also demands a 3.5-character silent gap around each frame, and at these settings one character is 11 bits on the wire — start, 8 data, parity, stop.

The rule in words: wire time per exchange equals request bytes plus response bytes plus silence character-times, all multiplied by bits per byte and divided by the baud rate.

Arithmetic. Payload: 8 + 37 = 45 bytes, so 45 × 11 = 495 bits. Silence: 2 × 3.5 = 7 character times × 11 = 77 bits. Total: 495 + 77 = 572 bits. Time: 572 ÷ 19200 bit/s = 29.8 ms, call it 30 ms.

Result and decision. One full poll of this block costs about 30 ms on the wire. Keep one slave's exchange under a quarter of its polling period; the remaining three quarters absorb the regulator's own response time, one retry after a CRC error, and scan jitter. Thirty milliseconds therefore sets the fastest sensible period at about 120 ms. Start at a 250 ms polling period, which loads the bus at 30 ÷ 250 = 12%, and shorten toward 120 ms only if the process proves it needs fresher data. Adding slaves multiplies this arithmetic — exactly the effect behind why Modbus RTU polling on one serial port is slow.

Failure behavior the BMS can trust #

Decide the failure behavior while you write the map, not after the first fault. Every mapped block carries a data-valid flag the PLC program owns: on a Modbus timeout, hold the last good values and clear the flag. Do not write zeros — a regulator feedback that drops to zero on a comms fault looks like a real process excursion to BMS alarms. Suspend BMS writes for the duration of the fault. Add one counter or heartbeat value that changes on every successful poll, so BMS logic can tell fresh data from a frozen image — the same trick as a PLC-5 heartbeat that monitors communication without the PLC-5 sending messages, and it costs one DP byte.

When the failure points the other way and the BMS stops cycling, the DP watchdog detects it at the slave, and your program takes whatever local action you have written. Two failure paths — name both in the map.

The decision for each case #

  • One regulator per cabinet, BMS is DP master, PLC also runs local I/O: the first-generation S7-1200 build — CPU 1212C, CB1241, CM1242-5 — with cyclic polling at the example's 250 ms period and BMS writes on change. One device replaces the gateway-plus-PLC pair: one configuration, one spare, one watchdog chain, and the cabinet's other I/O comes along free.
  • The PLC must run the DP segment itself, because the BMS is a DP slave or other DP devices share the segment: the same build with the CM1243-5 in place of the CM1242-5. The regulator side does not change.
  • More Modbus devices or a heavier mapped set: re-run the timing example per port. Up to 32 unit loads share one RS-485 segment; past that, or when the cycle time collapses, a second serial port is the next move, not a faster polling loop.
  • Keep the regulator: keep it. The PLC reads its defined registers and writes its mapped command set and nothing else. Only a scope change from the owner justifies removing it, and that is a different project.

Questions asked

How many devices can share the regulator's RS-485 segment?

The Modbus serial line specification allows 32 unit loads on one RS-485 segment without a repeater, with slave addresses 1 through 247 across the system. The PLC port and the regulator each count against that 32. Past it, add an RS-485 repeater or move new devices to a second port, then re-run the cycle arithmetic for the extended bus, because every added slave multiplies the wire time you calculated for one.

Can the regulator be wired straight into the BMS Profibus connector?

No. The two protocols share differential RS-485-style electronics as a family and nothing else: different frame formats, different allowed speeds, different termination practice, and no translation between the data models. Connecting them directly produces no communication and can load the segment badly. The translation must happen in a device that speaks both protocols, which is the role the PLC takes in this build.

How old is the value the BMS finally sees?

Add three delays: the polling interval, one PLC scan, and the DP cycle. With the 250 ms polling period from the worked example, a scan in the single-digit milliseconds, and a DP cycle of a few milliseconds, steady-state data age is roughly 0.3 s. After a dropped reply the next good poll is one full period later, so the worst case is a bit over half a second before the valid flag clears.

What happens if the BMS stops communicating with the PLC?

The DP master project sets a watchdog time for each slave. If the BMS stops exchanging data for longer than that time, the PLC's DP interface exits data exchange and raises a diagnostic, and your program can then run whatever local fallback you have written: hold outputs, drop to local control, or alarm. The regulator is not affected and keeps running on its own settings either way.

Keep reading

  • How-to

    How a PLC runs two Modbus networks at the same time

    Yes. Each serial port is its own independent link: the HMI polls the PLC on one port while the PLC acts as master, or slave, on a separate RS-485 Modbus RTU network. The two links share no settings — only their endpoints must match — and PLC copy logic moves any data between them.

    Industrial networks

  • Troubleshooting

    Fixing CODESYS Modbus TCP server exception 0x0002

    Exception 0x0002 means the CODESYS Modbus TCP server holds no point at the address the client requested. The Data Model start-address fields are offsets within each data type's standard range, so entering 10001 for Discrete Inputs pushes the first bit to reference 20002. Set each start address to 0, confirm the client's notation, then prove one point with a scanner.

    Industrial networks

  • How-to

    How to build a virtual PLC test bench for protocol practice

    One laptop runs the whole bench: a Modbus TCP server simulator, a master test client, a Node-RED OPC UA server and a SCADA trial connect over loopback, so you can practice addressing, sessions, scaling, alarms and fault diagnosis without a PLC. Work through three bounded projects and finish with seven pass criteria you can defend.

    Industrial networks