Troubleshooting
Why a Modbuspn initialization makes a PLC go to STOP
Short answer
Read the earliest diagnostic-buffer event before changing anything. A MODBUSPN initialization that stops the CPU comes from one of two faults: a cycle-time overrun, when a program loop waits inside one scan for communication, or write errors into the instance DB, when Modbus blocks are missing or carry conflicting numbers. The buffer names the fault; each fault has its own fix.

On this page
- Which diagnostic-buffer event do you read first?
- Why does setting Init online stop a program that ran fine?
- How does a communication wait loop overrun the scan cycle?
- What causes write errors into the instance DB?
- Which blocks and block numbers does the project actually need?
- How do you reload the corrected project without a second STOP?
- What result proves the fix matched the fault?
- Questions asked
A MODBUSPN block that runs in a small test project and then stops the CPU the moment Init is set in a large application has one of two faults, and the diagnostic buffer names which one: a time error from a program loop that waits inside one scan for communication to finish, or write errors into the instance DB from Modbus blocks that are missing or carry conflicting numbers. Read the earliest event in the buffer before you change anything, because the two faults have different fixes. The test project passed for honest reasons: it has neither a busy scan nor a crowded block list, and the production program supplies both, so only the full project exposes the fault.
Which diagnostic-buffer event do you read first? #
Read the oldest event that still belongs to the failure rather than the newest: the latest entries usually record the consequences of the STOP, while the fault that started it sits just above the transition from RUN to STOP. The buffer is chronological, and the vendor documents that when the CPU changes to STOP you evaluate the events leading up to that transition to find the cause. Work upward from the RUN-to-STOP entry and look for one of two signatures:
- A time error tied to cycle-time monitoring. That points at the wait-loop fault described below.
- Repeated write errors into the instance DB. That points at missing or conflicting Modbus blocks, also described below.
Record the CPU order, the block location named in the event, and the data area it references, and take the exact wording from the CPU itself. Treating every RUN-to-STOP as a communication timeout is how the wrong block gets replaced first.
Why does setting Init online stop a program that ran fine? #
The online modification is only a trigger: changing Init changes one value the block reads, and the CPU then executes the call path your program already had, so the STOP comes from that path and not from the click itself. In the test project, the same value walked through a short sequence in an otherwise idle scan. In the production program, it enters a longer call structure already loaded with other work, and initialization is heavier than a steady-state pass because it sets up the connection and the block's buffers inside that same scan. That is why the STOP lands on the first Init in the big project and never in the small one.
Two checks belong here. Check the block documentation for whether Init is level-controlled or transition-controlled; the two behaviors are not interchangeable, and holding the request TRUE repeatedly or clearing it early disrupts the sequence the block expects. Then trace the logic that consumes Init, because that call path is where either fault shows itself. The routine way to initialize is to drive Init from program logic under a controlled condition, not to keep modifying the value online.
How does a communication wait loop overrun the scan cycle? #
A CPU leaves RUN when one scan runs longer than its cycle monitoring time, and on an S7-300 or S7-400 with no time-error organization block in the project that time error goes straight to STOP. Each pass of the scan is supposed to return, which what the PLC scan cycle does in each pass walks through step by step. A loop that waits inside one scan for the block's communication work to finish breaks that contract, because the work completes only when the partner's transaction arrives, and the master paces those transactions. With the PLC answering as a slave, a synchronous wait can hold one scan for nearly a full polling interval; the pacing effect is the same one that makes drive polling crawl on a shared serial link, as covered in why Modbus RTU drive polling on one serial port is slow.
Work the numbers for an example set before trusting the diagnosis. Take an example monitoring limit of 150 ms, read from your CPU's cycle-time monitoring setting in the hardware configuration; an example steady program scan of 30 ms; and an example master that polls the PLC once per 1000 ms:
Monitoring limit (example): 150 ms
Steady scan without the wait (example): 30 ms
Master polling interval (example): 1000 ms
Worst case: 30 ms + (1000 ms - 30 ms) = 1000 ms -> 850 ms over the limit
Average case: 30 ms + (1000 ms - 30 ms) / 2 = 515 ms -> 365 ms over the limit
On this example set the limit is exceeded on nearly every poll, not only in the worst case, so the time error fires the first time Init drives the block through its handshake. The fix is structural: remove the synchronous wait, call the block cyclically, and take its status, done and error outputs once per pass, letting the handshake span as many passes as it needs.
What causes write errors into the instance DB? #
Write errors into the instance DB mean the data area behind the call does not match the block that is calling for it, which in practice happens when a Modbus block the FB calls internally is missing or carries the wrong number. An instance DB exists so that the state of one call has a home of its own; the same principle, that function block state belongs to each instance, is spelled out for CODESYS in why function block state belongs to each instance, and the instance DB plays exactly that role here.
The usual origins, in the order they occur: a Modbus block that the communication FB calls internally never made it into the project; the block exists but unrelated application logic already holds the number the library expects, so an internal call resolves to the wrong code; or the instance DB was not generated from the function block that calls it, so the layouts disagree. Application code that writes into the instance DB for storage, or an external client mapped over its addresses, produces the same errors, because internal communication state is not general-purpose storage. If the event names an offset, use that offset to find the conflicting access instead of replacing blocks at random.
Which blocks and block numbers does the project actually need? #
Insert the complete Modbus/TCP block set with the numbers the library assigns, parameterize its parameter DB, and generate the instance DB from the function block itself, because an existing DB that happens to have a free number is not automatically the right one. Open the properties of the MODBUSPN block in the working test project: the internally called blocks are listed there, and the production project must contain every one of them. Then work the list:
- List the communication block and every internally called block, with numbers, from the block properties in the test project.
- Search the production project for each of those numbers; where unrelated logic already holds one, renumber per the library's documented requirements before inserting anything.
- Insert the entire set from one version of the library; the documentation separates a V1 and a V2 of the instruction for these CPUs, and mixing versions leaves interfaces that do not match.
- Parameterize the associated parameter DB for the block, as the vendor's configuration entry for Modbus/TCP on these CPUs requires.
- Generate each instance DB from the function block that calls it, and regenerate it whenever that block changes.
- Search the project for direct writes into those instance DBs and remove them.
The tie between a Modbus block and its instance data is not a quirk of this library; multi-instance Modbus blocks and MB_DB links in an S7-1200 shows the same discipline on current controllers.
How do you reload the corrected project without a second STOP? #
Capture the diagnostic record and a project backup first, then make the block changes offline and download the whole corrected set in one maintenance window, with the machine in an approved state and nobody relying on a communication-dependent function while you transfer. The buffer is a finite record, so save the events around the transition to a file before you go offline, and keep both projects on hand; the test project is your reference for what a correct set looks like. Run the editor's consistency check on the whole project and download the coordinated set in one transfer rather than block by block, because a half-updated set produces exactly the mismatch you are fixing.
Bring the machine back the same way every time: drive Init from program logic once the set is running, and test initialization on its own, before sustained traffic, so that any new event in the buffer maps to one stage and one fault. Expect the connection to establish and the first transaction to complete with no new entries in the buffer.
What result proves the fix matched the fault? #
Reconnect after the restart and check only the event your buffer named: a fresh time error means the wait loop is still active, while fresh instance-DB write errors mean a block or number from the set is still missing, so you fix exactly that one fault. For the time-error case, the proof is a measured scan: after replacing the wait loop with per-pass status handling, watch the CPU's measured cycle time through initialization and confirm it stays under the monitoring limit; for example, a scan around 35 ms against the example 150 ms limit leaves room even while the block sets up its connection. For the instance-DB case, the proof is a clean buffer: drive Init from logic, let the first transactions complete, and confirm no new write errors appear, because every fresh write error names a block or data area that is still mismatched.
The decision, per case: if the earliest buffer event is a time error, restructure the call so no pass waits for communication, and verify the scan time in the CPU diagnostics. If the earliest events are write errors into the instance DB, complete the block set with its internal calls under correct numbers, regenerate the instance DBs from their function blocks, and remove foreign writes. Both faults are fully recoverable offline, and neither requires replacing hardware.
Questions asked
When does MODBUSCP apply instead of MODBUSPN?
MODBUSPN communicates through the integrated PROFINET interface of the S7-300 or S7-400 CPU itself. MODBUSCP does the same Modbus/TCP job when the physical path runs through a CP 343-1 or CP 443-1 communication processor instead. Pick the instruction that matches your hardware path, and keep the block set, parameter DB and instance DB handling consistent with whichever one your project uses.
If a time-error OB is present, does the wait loop still matter?
Yes. With the time-error organization block in the project, the CPU logs the overrun and stays in RUN instead of stopping, but the overrun scan still delays every I/O and communication update for its full length, and the error repeats on each transaction. Installing the OB is a diagnostic aid, not a fix for the loop itself.
How do I keep the diagnostic buffer from being overwritten before I read it?
Save it as soon as you are online. The buffer is a fixed-size ring, so new events push the oldest ones out, and reconnecting or letting the fault repeat can remove the entries you need. Open the buffer view, read the events around the RUN-to-STOP transition, and export or copy them into your project documentation before you change anything.
Where can I find sample projects that show the block set set up correctly?
The Siemens support portal keeps a configuration entry for Modbus/TCP between S7-300 or S7-400 controllers and partner devices, document ID 22660304, which includes application samples and demo projects. Compare your integrated project against one of those: the samples show the complete block set, its parameter DB and the block numbering in a working arrangement.


