Troubleshooting
Modbus exception 02 when a read crosses a register map gap
Short answer
The exception is correct: a Modbus block read requests consecutive registers, so a span from 754 through 788 includes the undefined 764-767 gap and the meter rejects it with exception 02, illegal data address. Read the 754-763 setup block at startup and after configuration changes, keep continuous reads inside the 768+ measurement area, and publish the last fully accepted set to your calculation logic.
On this page
The exception is the meter behaving correctly. A Modbus read requests consecutive registers, and one request covering 754 through 788 also requests 764 to 767, which the meter's map does not define, so the whole request is rejected with exception 02, illegal data address. Split the reads around the gap: read the 754-763 setup block (multiplying factors, model data) once at startup and again after configuration changes, and read the 768-and-up measurement block every cycle into the MELSEC-Q. Stage both responses and hand the calculation logic the last complete accepted set in one program step. That delivers a consistent data set; nothing you do at the PLC makes the meter sample two areas at the same instant.
Why one request cannot cross the gap #
Read function codes 03 and 04 carry a start address and a register count, and together they define one contiguous span. The meter validates every address in that span, and a single undefined address returns exception 02 rather than partial data. Code 02 is the documented illegal-data-address rejection — the same code a server returns for any address outside its map, seen from the server side in Fixing CODESYS Modbus TCP server exception 0x0002. It is an address fault, not a timing or transport fault.
In the reported ME96SS-series map (an ME96SSHA-MB meter here), 754-763 holds setup data such as multiplying factors and model information, the measurements run from 768 upward (reported through 788 and beyond), and 764-767 is not defined. Any request whose span touches those four addresses fails, no matter how much useful data it also contains. Modbus has no way to skip addresses inside a request: there is no address list, only a start and a count.
First checks on the failing request #
- Record the start address and count of the failing request. The gap enters only when the span covers 764-767; two requests that each stay inside one area should both succeed.
- Capture the exception code, not just the failure. Code 02 points at the address span. A timeout means no response arrived and points at the link, the slave address, or the connection — a different repair.
- Confirm the documented ranges for your exact model and version in the meter's Modbus interface specification. Maps move between models and firmware; the ranges here are the reported case, not a family-wide constant.
- Check the numbering convention. If the meter document numbers registers one-based while the PLC communication instruction addresses zero-based, every value shifts by one register: plausible numbers, wrong quantities. Test one known register before scaling anything.
- List the operands the calculation needs and mark which can change during operation. That list decides the grouping in the sequence below.
Sizing the split reads for a 754 to 788 span #
Inputs:
- Setup area 754-763 (multiplying factors, model data) — reported meter map.
- Measurement area 768-788 — reported meter map.
- Undefined gap 764-767 — reported meter map.
- Read function 03 or 04, limit 125 registers per request — Modbus protocol limit.
Rule in words: a block's register count is the last address minus the first address plus one, and the block is valid only if every address inside it is defined and the count is 125 or fewer.
The arithmetic:
- One combined request: 788 - 754 + 1 = 35 registers. Inside that span sit 767 - 764 + 1 = 4 undefined addresses, so the meter answers with exception 02. The count of 35 is far below the limit of 125, which proves the rejection is about which addresses are requested, not how many.
- Setup block: 763 - 754 + 1 = 10 registers with first address 754.
- Measurement block: 788 - 768 + 1 = 21 registers with first address 768.
- Check: 10 + 4 + 21 = 35. The split covers every address the combined request did, minus exactly the four that caused the rejection.
Decision: any block that stays inside one continuous area succeeds; any block that crosses 764-767 fails. Read 10 registers at 754 at startup and after configuration changes, read 21 registers at 768 every cycle, and extend the measurement block upward from 768 as far as it stays continuous and under 125.
One block read is not one measurement set #
Three properties get confused here, and only the first comes free:
| Property | What it means | Who provides it | How you get it |
|---|---|---|---|
| Register continuity | Every address in one request is defined | The meter's map | Split reads around the gap |
| Sampling coherence | All quantities come from one internal measurement update | The meter's update cycle | Only the meter's documented behavior |
| One-set consistency | The calculation consumes one complete accepted set | Your program | Stage, then publish in one program step |
A valid block gives you continuity only. A successful response does not prove its values were sampled at the same instant: the meter refreshes registers on its own internal cycle, and only its manual states what one update covers. On the PLC side, consistency is guaranteed per access — a word, a defined structure — never across two separate communication transactions. Issuing both requests in one scan orders them; it does not synchronize them. So the coherence work belongs to your program: communications write into staging storage, and one defined program sequence copies the completed set into calculation data after every required read has succeeded.
How to treat the multiplying factors #
The factors sit in the setup area, but that alone does not make them startup-only data. Decide by how the factor can change:
- Configuration-only factor: read it at startup, and re-read after any configuration write and after a reconnect. Polling it every cycle adds a transaction and improves nothing.
- Fixed factor set per layer: read the set once, then select the right factor per the documented mapping, driven by the layer-selection value.
- Layer selection that changes during operation: read the selection value with every measurement cycle, and void any data set in which the selection changed between that cycle's reads.
Before any of that matters, confirm the representation of both operands: signedness, word order for 32-bit values, and the documented scaling operation. A factor from the wrong layer produces a plausible number that is quietly wrong. If the meter offers a documented snapshot or capture facility, use it for pairing; if it does not, no polling sequence can guarantee pairing across a layer change — command the layer, let it settle, then acquire.
The read sequence, transaction by transaction #
- At startup, read the 10-register setup block at 754 into staging storage; decode the factors and model data once.
- At the start of each measurement cycle, clear the cycle-complete state.
- Read the measurement block from 768 (21 registers in the reported case) into staging. If the layer selection is dynamic, read the selection value in the same cycle.
- Check completion and error status of every transaction in the cycle. Any failure, or a detected selection change, voids the set.
- On full success, copy the staged set into the calculation data area in one program sequence that finishes before the calculation executes.
- On failure, keep the previous accepted set serving the calculation, and expose freshness and error status to everything downstream.
That is two requests per cycle instead of one. Over TCP the cost is negligible; over RTU it adds a transaction to the poll list — the same trade discussed in Why Modbus RTU drive polling on one serial port is slow.
What will not fix it #
- Switching between RTU and TCP. The undefined addresses live in the meter's map; both transports carry the same span and both get exception 02.
- Reading the gap to fill the span. Those four addresses are undefined; a request touching them is the request that already fails.
- Scanning faster or aligning scans. The exception is an address problem, and sampling simultaneity is decided inside the meter, not by your scan timing.
Questions asked
Can Modbus skip the undefined registers inside one request?
No. Function codes 03 and 04 define a span by start address and register count, and every address in that span must exist in the server's map. There is no address list and no skip field in a read request. The only way past a hole in a map is a second request that starts after it.
Will moving from Modbus RTU to Modbus TCP remove the exception?
No. The undefined addresses are a property of the meter's register map, not of the transport. RTU and TCP carry the same start address and count, so a span covering 764-767 is rejected on both. Change transport for wiring or topology reasons, never to fix a map gap.
Does issuing both reads in the same PLC scan make the values simultaneous?
No. Each request is its own transaction and completes on its own schedule, and the meter refreshes its measurements on an internal cycle regardless of your scan. Issuing reads in one scan only orders them. Stage the responses and publish one accepted set; that is the consistency you can actually control.
How often should the setup block at 754 be re-read?
Read it at startup, then after any configuration write, a reconnect, or anything that restores or reloads the meter's parameters. The factors change only when the configuration changes, so polling them every cycle adds a transaction and no accuracy. A layer that changes at runtime is different: poll the selection value each cycle, not the whole block.
Is the meter returning an exception or dropping the request?
An exception response means the meter received the request and refused it; code 02 specifically means the address span is not available, so you fix the request. A timeout means nothing came back, which points at the wiring, the slave address, or the connection, so you fix the link. The two repairs are unrelated.