Explainer
Why a Modbus TCP client cannot write M340 input bits
Short answer
Yes, it is normal. In Mixed topological and State RAM mode a Modicon M340 exposes %I and %IW as read only to a Modbus TCP client, and Modbus defines no function that writes discrete inputs on any server. Keep client writes on %M coils and %MW holding registers, and publish server-to-client bits in a separate, non-overlapping %M block the client reads as coils.
On this page
Yes, this is normal behavior and nothing in your project is broken. In Mixed topological and State RAM memory management, a Modicon M340 gives a Modbus TCP client read-only access to %I input bits and %IW input words, and the Modbus data model defines no function that writes discrete inputs on any server. Writes from a client belong in %M coils and %MW holding registers. The decision: keep client writes where they already are, and publish the bits the client must read in a separate, non-overlapping %M block that the client reads as coils. What follows is why the mode change broke the write, the one-offset arithmetic for your three exchange ranges, and the checks that prove the new mapping.
The Modbus data model has no write path to input bits #
The Modbus Application Protocol Specification, currently at V1.1b3, fixes the access rights of its four data tables: discrete inputs and input registers are read-only; coils and holding registers are read-write. The function codes follow from that. FC02 reads discrete inputs and FC04 reads input registers; nothing writes either table. Coils are read with FC01 and written with FC05 or FC15; holding registers are read with FC03 and written with FC06, FC16 or FC22.
| Client table | Function codes | Access | M340 object |
|---|---|---|---|
| Coils | FC01 read; FC05, FC15 write | read/write | %M |
| Discrete inputs | FC02 read | read only | %I in Mixed mode; aliased to %M in Topological mode |
| Holding registers | FC03 read; FC06, FC16, FC22 write | read/write | %MW |
| Input registers | FC04 read | read only | %IW |
So a client that cannot write %I is refused by the protocol itself, on this CPU or on any other. On other controllers the same input-word versus holding-register split decides, for example, what CODESYS %IW0 means for a Modbus TCP holding register.
Why the mode change broke the write #
From Unity Pro 6.1 with M340 firmware 2.4, the CPU can address modules through topological or State RAM addresses, and the memory-management selection picks the layout the client sees.
| Memory management | Discrete-input table resolves to | Coil table resolves to | A client write to the input-bit range |
|---|---|---|---|
| Topological | %M | %M | succeeds, because it is really a coil write |
| Mixed topological and State RAM | %I, read only | %M | never valid; no function code writes discrete inputs |
In Topological mode your client's input-bit address and its coil address were the same physical bit, so the write landed on %M and looked successful. In Mixed mode the discrete-input table becomes the real %I table, which only the input modules write. Nothing in the client changed between your two tests; the address it was writing stopped being %M. Reports differ on how well individual client drivers read the %I table in Mixed mode at all, and the design below makes that question irrelevant, because every read the client needs becomes a coil read.
Traditional and IEC addresses differ by exactly one #
Traditional Modbus numbers begin at 1; IEC addresses on the M340 begin at 0. The conversion is one rule: drop the leading type digit and subtract 1. The four bases convert as 00001 = %M0, 100001 = %I0, 300001 = %IW0 and 40001 = %MW0. Applied to your exchange: the coil block %M0 to %M8 is traditional 00001 to 00009 (0 + 1 = 1, 8 + 1 = 9), and the register block %MW0 to %MW20 is traditional 40001 to 40021 (0 + 1 = 1, 20 + 1 = 21). In the other direction, a client tag displayed as coil 00101 is 101 - 1 = 100, which is %M100, the first bit of the published block below.
Clients disagree about which convention to display: some show 1-based traditional numbers, others show 0-based protocol offsets, and the mismatch reads like an off-by-one PLC fault. Resolving the 0-based versus 1-based coil addressing offset shows how to tell which one a driver uses; for the word tables, a 0-based versus 1-based register offset reference covers the same question.
Publish server-to-client bits in a separate coil block #
Keep Mixed mode. It gives %I its real meaning, the wiring's view of the field, and it keeps the coil table clean. Then split the bit data by direction:
- Client writes: %M0 to %M8 as coils and %MW0 to %MW20 as holding registers. The application contains no assignment to any bit in that coil block.
- Server publishes: a second %M block that does not overlap the first, for example %M100 to %M119, twenty bits the client reads as traditional coils 00101 to 00120 (100 + 1 = 101, 119 + 1 = 120). Only the application writes this block. Ordinary rung assignments drive the published bits; no function block is involved.
On the wire the published read is one FC01 request, start address 100 in IEC terms, quantity 20. Every bit in the exchange then has exactly one writer, so the last-writer-wins collision cannot occur. The same single-writer discipline is what makes safe Modbus writes to PLC output registers from SCADA predictable on the word side. One safety note: a coil the client writes can drive real outputs through your logic, so interlock every client-written bit in the application and never route a safety function through Modbus-written data.
The decision for each case:
- Topological mode with one shared %M range: acceptable only when the client is the sole writer of every bit in that range. Otherwise move to Mixed mode with separated blocks.
- Mixed mode with two separate %M blocks: the default. Read and write semantics stay explicit, and no simulation is needed.
- The real %I table: reserve it for genuine field inputs, or for simulation during testing, which is the next section's subject.
When the real input table is the right answer #
If the client must see values in %I itself, for example to test a client against a PLC with no field inputs wired, the application still cannot assign %I directly: the input modules own that table. The documented route is the simulation function block WRITE_INPUT_EBOOL; its help-file entry shows the call pattern. Treat it as a commissioning and test tool. Data the application generates in production belongs in %M, where ordinary logic writes it and the client reads coils.
Rebuild, transfer and verify #
- Confirm the memory-management selection is Mixed topological and State RAM.
- Confirm the client's write list contains only coils and holding registers, and delete every write aimed at a discrete-input or input-register address.
- Confirm the two coil blocks do not overlap and that a search of the application finds no assignment into the client-written block.
- Rebuild, transfer, and confirm the CPU is in RUN.
- Write a coil from the client and watch the bit in the online data table: it sets, and it clears when the client drops it.
- Toggle a published bit from the application and read it back from the client as a coil, in both states.
With those six checks green the mapping is finished. The client writes coils and holding registers, reads the published block as coils, and the input table stays what it is: the field's view, read only to the network.
Questions asked
Does the M340 log an error when a client tries to write an input bit?
Usually there is nothing to find on the PLC side. The Modbus application layer defines no write function for discrete inputs, so a compliant client refuses the operation in its own software and the request never reaches the server. Empty PLC diagnostics are therefore consistent with correct operation. A client that writes the same numeric address as a coil does reach the PLC, and the bit it changes is %M; that difference is the whole story between your two tests.
How can the client read input words reliably in Mixed mode?
Copy them into holding registers. In the application, move each %IW the client needs into a %MW with a MOVE instruction and point the client's reads at holding registers. Input words carry the same read-only rule as input bits, and a register copy also insulates the client from drivers that handle the input-register table poorly. Copy only the words in the mapping list, and note each copy there so the next engineer can trace it.
Can one %M range carry bit data in both directions?
Only with one writer per bit. A block the client writes must have no assignments anywhere in the application, and a block the application publishes must never appear in the client's write list. When both sides write the same bit, the application's rung wins within one scan, so the client watches its own value flip back on the next read. That flip is the signature of a shared range, not of a network fault.
Does changing the memory management break client addresses that already work?
It can. Moving between Topological and Mixed changes what the client's discrete-input addresses resolve to, so a tag that formerly reached %M through the input-bit table no longer behaves the same way. After any mode change, re-test every client tag against the online data table, not only the failing one, and reissue the mapping document. Treat the mode selection as part of the interface specification, because the client experiences it as one.
Is the offset between traditional and IEC addresses a setting on the M340?
No. The PLC address is fixed; the convention lives in the client. Some drivers display 1-based traditional numbers, some display 0-based protocol offsets, and some let you choose. Verify one known tag against the PLC before trusting the rest of the list, and write the chosen convention at the top of the mapping document. The arithmetic never changes: drop the leading type digit and subtract one.