IMDTouchKnowledge BaseShop main store

Troubleshooting

Why a Modbus TCP coil write snaps back after one poll cycle

Industrial networks Published 7 min read By IMDTouch engineering team

Short answer

A coil that lights for one update cycle and then drops is a bit the panel wrote and the controller never kept. Capture the exchange on TCP port 502: a function code mismatch returns exception 01, an off-by-one address writes the neighboring coil, and a normal echo followed by a cleared read means controller logic overwrites the bit. Fix by which of those the capture shows.

On this page
  1. What the one-cycle flash tells you
  2. The three causes and the capture that decides
  3. Capture one write on port 502
  4. Worked example: decoding one captured exchange
  5. Wire address versus reference: the off-by-one
  6. Fix by cause, then prove it
  7. Questions asked

A coil that lights for one update cycle and then drops is a write the controller never kept. The panel delivered the bit — the flash proves that — and the next cyclic read replaced your value with the controller's real state. Three things cause it: the controller refuses the function code the driver uses for coil writes, the write lands on the neighboring coil through an address-base mismatch, or the controller's own program owns the bit and clears it every scan. Capture one write on TCP port 502 and read three fields: the function code, the address field and the reply type. The capture names your cause, and each cause has a one-step fix.

What the one-cycle flash tells you #

The indicator bound to the same coil address shows the HMI's local tag, not the wire. Toggle it and the tag holds the value you wrote, so the screen lights. When the next poll of that coil returns, the driver overwrites the tag with the controller's actual state and the light drops. The flash is a receipt for the panel's write; it says nothing about whether the controller accepted or kept it.

Two details narrow it further. Every other data area on the same connection reads and writes normally, so the cable, the port and the connection setup are proven — the fault is specific to the coil area. A second Modbus test tool reproduces the snap-back, which points away from one corrupted project file and toward the address mapping or the way the controller treats coil writes. Agreement between two tools is still not proof the panel is clean: both may send the same function code.

If your indicator never lights at all, that is the opposite fault — a read path or tag problem, covered in why indicators stay off over Modbus polling.

The three causes and the capture that decides #

Capture finding What it means The fix
Block write (FC15) out, exception code 01 back The controller does not implement that function on coils Switch the tag to single-coil writes, or move the bit into a register area
Normal echo, then the next read returns the bit cleared Controller logic owns the bit and rewrites it Give the HMI its own command bit that the logic latches
Address field one off the intended reference Zero-based wire address written where a one-based reference was meant Correct the tag address by one, re-test under capture
Exception code 02 back Start address or range outside the controller's coil map Match the controller's map and confirm the range is writable

The exception reply carries the request's function code with its top bit set — 0x85 for a refused single-coil write, 0x8f for a refused block write — followed by the exception code. Code 01 is illegal function: the device does not support the requested function code. Code 02 is illegal data address: the coil is not defined in the slave's map.

Capture one write on port 502 #

  1. Mirror the switch port the panel or controller uses, or insert a tap, and start a capture filtered to TCP port 502.
  2. Trigger one write by toggling the coil tag from the screen. Do that on a bench or with the machine stopped; a coil write on a running machine can start motion.
  3. Find the request. After the 7-byte MBAP header, read the function byte (05 single coil, 0f block of coils), the 16-bit address field and, for a block write, the quantity and byte count.
  4. Find the reply. A normal echo repeats the request; an exception reply has the top bit set plus the code. In a single-coil request the value ff 00 means ON and 00 00 means OFF.
  5. Find the next cyclic read of the same coil (function 01) and read its status byte — that is the value your indicator will display.
  6. Classify the exchange against the table above.

FC5 writes one coil; FC15 writes a block, with the quantity and byte count carried in the request. The Modbus application protocol lets a slave implement either one alone or both, and a device that lacks the code your driver sends answers exception 01. Some masters send FC15 for every coil write; the capture decides what your link does. A quantity or range the controller's map does not cover comes back as exception 02 — on the read side the same overreach is the trap behind coil reads that fail when the request block is too long.

Worked example: decoding one captured exchange #

Illustrative bytes, chosen to show the third cause. The panel toggles the tag; the capture shows:

  • Request, after the MBAP header: 05 00 04 ff 00
  • Reply: 05 00 04 ff 00
  • Next poll: 01 00 04 00 01, answered 01 01 00

Decode the request: function 05 is write single coil, the address field 00 04 is wire address 4, and ff 00 is ON. The reply repeats the request byte for byte, so the controller accepted the write — no exception, nothing lost on the network. Convert the address: the one-based reference is the wire address plus one, so 4 + 1 = 5 and this exchange touches coil reference 00005.

The next poll reads function 01, start address 4, quantity 1, and returns one status byte of 00: reference 00005 is OFF again within one update cycle. That is the signature of the third cause. Stop hunting the link and open the controller program instead — something in it writes that bit every scan. Rework the handshake so the HMI sets a command bit the logic latches and clears when consumed, and the same capture will then show the read-back staying ff.

Had the request instead arrived as 0f 00 04 00 01 01 ff and come back as 8f 01, the decode would name the first cause: a block write of quantity 1 that the controller refuses as an illegal function, so the tag must move to a single-coil write or into a register area.

Wire address versus reference: the off-by-one #

On the wire, the Modbus address field is zero-based: the first coil is address 0. Reference notation such as 00001 is one-based, the same convention that lies behind five-digit register references — how five-digit holding-register references decode walks through that convention for registers. A driver that passes your tag number straight to the wire turns a tag entered as 4 into wire address 4, which is reference 00005, one coil high; to hit reference 00004 the wire must carry 3.

That off-by-one moves the write onto the neighboring coil silently: the intended bit never changes, the neighbor does, and no exception is raised because both addresses are legal. Copy the working setup as your reference — an identical project on another machine that behaves correctly gives you the address offset, the slave identifier and the tag data types to match. Then take the controller's own documentation for how its coil area maps to internal bits and whether the range is enabled for writes; that mapping belongs to the controller, and the panel manual will not state it. Where a raw coil number has to line up with a named bit in the controller program, how Modbus coil addresses map to named symbols covers that mapping in depth.

Fix by cause, then prove it #

  1. Exception 01 on a block write: look in the connection's Modbus driver options in the HMI engineering tool for the single-write versus block-write choice and set the coil tags to single-coil writes. If the tool offers no choice, map the bit into a holding-register area — the register function your working data areas already prove — and unpack it in controller logic.
  2. Off-by-one: shift the tag address by one in the direction the capture shows, download the project, and re-test with the capture running. The write must land on the intended reference and nowhere else.
  3. Cleared read-back after a normal echo: remove the controller-side write to that bit or rework the handshake into a dedicated command bit the logic latches and resets. Never let two writers share one coil.
  4. Exception 02: bring the address and quantity inside the controller's defined coil map and confirm the range is enabled for writes.

Verify all four the same way:

  • The controller's online monitor shows the bit change on the write and stay changed across several update cycles.
  • The indicator on the same address stays lit after the next poll returns.
  • Toggling the bit from the controller side moves the indicator within one poll cycle, which proves the read path on its own.
  • Wire addresses one above and one below the target stay unchanged, so the fix did not simply move the problem onto a neighbor.

Run those checks and the decision is closed: the cause the capture named is fixed, the bit holds across polls in both directions, and any future snap-back on this link reads the same way — capture first, decode three fields, fix by what the wire said.

Questions asked

Can I write the bit through a holding register instead of a coil?

Yes, and it is the cleanest fallback when the capture shows a function-code refusal. Pick a register address the controller's map marks writable, write it from the panel with the same register function the link already uses for its working data areas, and unpack the bit in the controller program. That keeps the write on a function code both devices have proven, and the logic can latch the command so nothing else overwrites it.

What does exception code 02 mean on a coil write?

Illegal data address: the controller rejected the address, not the function. Usually the start coil sits outside the controller's defined coil map, the requested quantity runs past the end of it, or the range is marked read-only in the map. Compare the address field in the request against the controller's documented coil range, fix the offset or the range, and confirm the area is enabled for write access before re-testing.

Is a block write of one coil the same as a single-coil write?

On the wire, no. A single-coil write carries one address and a two-byte value; a block write carries a start address, a quantity and a byte count, and packs the bits into bytes. Some controllers accept both, some accept only one of them, and a controller that lacks the code replies with an exception. The capture tells you which your link needs; the quantity field alone never does.

How many coils can one block write carry?

The Modbus protocol caps a multiple-coil write at 1968 coils, with the byte count field sized to match, so the wire format itself is generous. The working limit on a given link is smaller: whatever the controller's coil map defines and whatever its exception replies allow. Keep operator commands to one or a few coils in a write; large block writes belong to bulk data, not to a button.

Keep reading

  • Troubleshooting

    Why a Modbus coil read fails when the request block is too long

    Exception 02 on a Read Coils exchange means the server checked every address from the start through start + quantity - 1 and found one outside its coil map, so it rejected the whole read. When a client that reads full bytes asks for 8 coils from a device that maps only 4, the first four coils in an easyE4 base unit, the valid start address still fails. Cut the quantity to fit the map; in HMI Droid that is the "Always read full bytes" setting.

    Industrial networks

  • How-to

    Getting gateway sensor data onto an HMI with a Modbus TCP bridge

    An HMI cannot poll a Node-RED application, so put the sensor values into a Modbus TCP server with a fixed register map and point the HMI's client driver at that server on TCP port 502. Run the server in the gateway's Node-RED when its runtime accepts the Modbus package; otherwise run it on a separate host. Add a heartbeat and a data-age register so the display can tell fresh values from retained ones.

    Industrial networks

  • Explainer

    How an HMI Panel Writes PLC Registers Over RS485

    RS485 and RS232 define only how electrical signals travel; they carry no data of their own. An HMI writes PLC registers over that wiring once both devices run the same protocol, usually Modbus RTU, the serial settings match at both ends, and every tag points at the documented register address with the right data type, word order and scaling.

    Industrial networks