Troubleshooting
Why calling CP341 FB7 and FB8 twice causes Modbus errors
Short answer
FB7 and FB8 are asynchronous and a CP341 running the Modbus master driver holds one job at a time. Calling the pair for a second and third Modbus area while the first job still runs overlaps jobs on the CP and returns STATUS errors and lost responses. Trigger each new call only after the previous one finishes - DONE on the send, NDR or ERROR on the receive - and stagger the areas with a 0.5 s clock tick and a counter preset of 3.

On this page
- Symptoms that point to overlapping FB7 and FB8 calls
- Why the CP341 takes one Modbus job at a time
- Which flag ends each job
- Staggering FC04, FC02 and FC05 with a 0.5 s tick and a counter preset of 3
- Building the sequencer in the CPU
- Hand off on DONE and NDR when a transaction outruns its slot
- Reading STATUS and ERROR when the sequencing is right
- The fix, assembled
- Questions asked
A CP341 Modbus master that runs cleanly with the example program and turns erratic the moment the second and third FB7/FB8 calls are added has a sequencing problem, not a wiring problem. FB7 (P_SND_RK) and FB8 (P_RCV_RK) are asynchronous blocks, and the CP341 executes one serial job at a time. When the call for the next Modbus area fires while the previous transaction is still on the port, the jobs collide and the link answers with STATUS values, ERROR bits and lost responses. The fix has two parts: let every job finish on its completion flag before the next REQ edge, and spread the areas across a sequencer driven from the CPU's clock memory.
Symptoms that point to overlapping FB7 and FB8 calls #
The failure has a recognizable shape. Look for this combination:
- The link runs without trouble while the example program polls its single Modbus area, and degrades as soon as calls for further areas are added.
- Errors are sporadic rather than constant: one transaction succeeds, the next returns an error, the third works again.
- Responses arrive late, short or not at all, and the receive block raises ERROR without a consistent pattern.
- Wiring, slave configuration and port parameters all check out, because the same setup was clean with one call per cycle.
The data-side twin of this timing fault is described in CP 341 FB7 and FB8 multiple-call data corruption fix; the two failures share one cause, the overlap.
Why the CP341 takes one Modbus job at a time #
FB7 and FB8 do not complete inside the block call. An edge at the REQ input of FB7 hands the job to the CP341, and control returns to OB1 at once; the query frame, the slave's turnaround and the response then travel over many OB1 cycles. Until the completion flags arrive, the job is still active.
Three rules follow from the way the driver works:
- The CP341 holds exactly one serial job and does not queue the jobs the program triggers, so a second trigger while a job is active collides with it.
- FB7 and FB8 are asynchronous: the call starts a job whose result appears several scans later.
- Overlapping jobs are themselves the fault: the CP is asked to run a new transaction on a port that is still busy, and the errors in the log are that collision being reported.
This is why the example program, which triggers one FB7/FB8 pair for one area, behaves, while three unconditional calls for three areas do not.
Which flag ends each job #
Gate every new trigger on the flags, not on elapsed time alone:
- FB7, P_SND_RK: fired by an edge at REQ. DONE reports that the send job has finished, and STATUS carries the job's result.
- FB8, P_RCV_RK: NDR reports that the request completed without errors and all data was read; ERROR reports that an error occurred.
- A transaction is over only when the send has raised DONE and the receive has raised NDR or ERROR. Only then may the next REQ edge fire.
Keep the receive block enabled in every OB1 pass so a response is caught whenever it lands. A clean job never raises ERROR, so gating on ERROR alone stalls the sequencer after every good read; gate on NDR or ERROR together. The receive-side handshake itself, with the acknowledge taken on NDR, is walked through in the CP341 ASCII protocol FB7/FB8 receive and ACK on NDR page; the mechanic is the same for a Modbus master.
Staggering FC04, FC02 and FC05 with a 0.5 s tick and a counter preset of 3 #
The case to size is the one that breaks: three Modbus areas on one CP341. The inputs, and where each comes from:
- Areas: input registers at 30001+ read with FC04, discrete inputs at 10001+ read with FC02, one coil at 00001+ written with FC05.
- Tick: 0.5 s, taken from a bit of the clock byte assigned in the CPU properties.
- Steps: a circular counter with a preset of 3, one step per area.
The rule in words: a circular sequencer's cycle time is the tick period multiplied by the number of steps, and each step triggers exactly one FB7/FB8 transaction, so every job owns the port alone for one tick period.
The arithmetic: 0.5 s × 3 steps = 1.5 s per full cycle. Each of the three areas is served once every 1.5 s, and each transaction has one full tick of quiet port ahead of it before the next job is triggered.
The decision: for this three-area case, set the tick to 0.5 s and the counter preset to 3, and keep every transaction short enough to finish inside its slot. When the slowest slave needs longer than one slot to answer - long frames, radio or modem links, slow devices - stop widening the tick and hand off on the completion flags as the next section shows. The tick is the one setting this sequencer asks you to tune, so prove it against the slaves' response behavior in tests. If the FC05 coil drives field equipment, commission the sequenced write with the load in a safe state.
Building the sequencer in the CPU #
- In the hardware configuration, open the CPU properties and enable clock memory; assign the clock byte.
- Pick the tick bit: the CPU's operating instructions list the period of each bit of the clock byte; take the bit with the 0.5 s period.
- Detect the rising edge of that bit with a dedicated edge-flag bit and count edges into a step word that runs 0, 1, 2 and wraps to 0 on the next edge; the comparison against the preset makes it circular.
- Compare the step word once per area: step 0 triggers the FB7/FB8 pair for the FC04 read, step 1 the pair for the FC02 read, step 2 the pair for the FC05 write. Each pair lives in its own instance data block, so each area keeps its own request frame and its own receive buffer.
- Tie each pair's REQ to its step's trigger and interlock that trigger with the completion flags of the previous step, so the port is free before a job fires.
Clock memory runs asynchronously to the CPU cycle, so the tick keeps its rhythm even when a long scan would swallow a software timer, which is one reason a clock bit rather than a timer drives this sequencer. When the same scheduling problem spans several slaves rather than several areas of one device, how to poll many Modbus RTU slaves from one serial master covers the scheduler side in full.
Hand off on DONE and NDR when a transaction outruns its slot #
The tick sets the rhythm; the flags make it safe. Chain the steps so that step 1's REQ is enabled only after step 0's DONE has arrived and its FB8 has raised NDR or ERROR, and so on around the circle. The handoff guarantees that at most one job is ever active, which is the constraint the CP imposes; the tick then acts as extra spacing for the slaves' benefit rather than as the only protection against overlap.
With the handoff in place, the cycle time stops being a fixed number and becomes the sum of the three actual transaction times, so a slow answer delays the next area instead of colliding with it. Where the per-transaction time goes - frame lengths, turnarounds, port speed - is laid out in why Modbus RTU drive polling on one serial port is slow.
Reading STATUS and ERROR when the sequencing is right #
Once every job finishes before the next one triggers, whatever remains in STATUS and ERROR is a configuration or link problem, and the driver documentation lists each code in its error message area. Read the code instead of guessing it. One documented entry shows the style: status 0E41 directs you to check the connection configuration and the CP-CPU interface, and to reload the Modbus communication instruction if that interface does not check out. For a code that carries a specific meaning on this hardware, why a CP 341 Modbus master returns status W#16#1E0D traces one such diagnostic from the CP's state to the driver's expectation on the PLC side.
The fix, assembled #
End state, in five lines:
- Three FB7/FB8 pairs, one per Modbus area, each in its own instance data block.
- One job on the port at a time, enforced by the DONE and NDR/ERROR handoff.
- The areas stepped by a clock-memory sequencer at the tick and preset from the worked example.
- STATUS and ERROR read only after the sequencing is in place, against the documented error message area.
- The tick tuned once, by test, against the slaves' response times.
The erratic errors go away not because a hidden parameter was found, but because the CP finally receives one job at a time.
Questions asked
Does the same one-job rule apply to the CP441-2?
Yes. The staggered trigger sequence built from clock memory bits and a counter is used on the CP441-2 serial master for the same reason: the FB7 and FB8 pair is asynchronous and the port runs one job at a time. Carry the same pattern over, tune the tick against the slaves' response times in tests, and gate every step on the previous job's completion flags.
Why does each Modbus area need its own FB7 and FB8 instances?
One FB7/FB8 pair drives one request frame and one receive buffer. With a separate instance data block per area, the FC04 read, the FC02 read and the FC05 write each keep their own function code, start address and response data, so a discrete-input response cannot land in the input-register buffer. A single shared instance would rewrite the request while the previous response is still being consumed, which is a quieter version of the same overlap fault.
Do clock memory bits hold their period when the OB1 scan runs long?
Yes. Clock memory runs asynchronously to the CPU cycle, and its state can change several times inside one long scan. The tick therefore keeps its period under scan-time load, but a long scan can swallow a tick: detect the rising edge with a dedicated edge-flag bit rather than testing the bit level, or the sequencer can skip a step and leave an area unpolled for a full extra cycle.
What limits how fast the CP341 can poll the three areas?
The serial link does. Each transaction costs a query frame, the slave's processing time, a response frame and the line turnarounds, and the frame length grows with the number of registers read, so reading fewer registers per poll shortens every cycle. If the refresh an application needs is faster than the link delivers, add a second serial port rather than tightening the sequencer; tightening it only recreates the overlap and the errors.


