IMDHMIControls LibraryShop main store

Troubleshooting

Why a Modicon M340 REAL reads zero over Modbus TCP

SCADA and data logging Published 6 min read By IMDHMI controls team

Short answer

An HR2628 read returns one 16-bit register, not the two-register REAL at %MW2628, and even an HRF read returns zero when the driver assembles the words in the wrong order. Point the tag at HRF2628, enable Reverse Word Order on the device connection, and prove each step with a non-round test value.

On this page
  1. Prove the transport with an integer first
  2. What an HR address actually reads from a REAL
  3. Switch the address to HRF
  4. Enable Reverse Word Order on the device connection
  5. A swapped 50.0 decodes to 2.4e-41
  6. Create the tag with a full item path
  7. End-to-end check of the REAL read path
  8. Questions asked

Your M340 REAL reads zero for two stacked reasons: the HR address reads only one of the two words the REAL occupies, and once you fix that with an HRF address, the two words arrive in the opposite order to what the driver expects. A round value such as 50.0 with swapped words decodes to a denormal near 2.4e-41, which displays as a clean zero, so the fault hides itself. The fix is an HRF float address plus Reverse Word Order on the device connection, proven step by step with a non-round value. The same zero pattern appears on other platforms when a float spans two registers; the even-word requirement behind it is covered in the article on why a BRX PLC needs an even first word to read a Modbus Float32.

Prove the transport with an integer first #

An integer at %MW1003 reads and writes correctly through the HR1003 address with the connection set to zero-based addressing. That result proves three things at once: the transport works, the unit ID is right, and the offset between the %MW number and the holding-register number is right. Do not touch the addressing mode again while chasing the REAL problem.

Before moving on, pass this gate in both directions:

  • Write a value from the gateway and see it appear in the animation table in the PLC programming software.
  • Change the value in the PLC and see it change in the gateway within one poll cycle.

Only after that gate passes do you touch the REAL, because every later check depends on the transport being proven.

What an HR address actually reads from a REAL #

A REAL in the M340 occupies two consecutive %MW words. A REAL at %MW2628 lives in %MW2628 and %MW2629. The HR address is a 16-bit integer address, so it requests one register and returns one word of that pair:

  • HR2628: one register, decoded as a 16-bit integer, and on this M340 the half that arrives reads as 0.
  • Changing the tag data type from float to double changes nothing, because the data type does not change how many registers the address requests.

Also check in the PLC that no other variable is mapped over %MW2629. An overlapping variable corrupts the high or low word of the REAL and produces garbage regardless of the driver settings. Write a known, non-round test value into the REAL, something with several fractional digits such as 123.456, and record the animation-table value. That recorded number is the reference for every later check; a round value like 50.0 hides word-order errors, as the worked example below shows.

Switch the address to HRF #

Point the tag at the float-typed holding-register address instead: HRF2628 in place of HR2628. The F prefix tells the driver to request two registers and decode them as one 32-bit float. After the change:

  • The tag quality must go Good, with no bad or unsupported-address status.
  • A value of 0 at this stage is expected if the word order is wrong. Leave the address alone now and go to the word-order setting; changing the address again cannot help.

Enable Reverse Word Order on the device connection #

The M340 sends the two words of the float in the opposite order to the one the driver expects. With the default order, the driver assembles the 32-bit float with its high and low words exchanged, and a round value decodes near zero. Enable the Reverse Word Order setting in the Modbus device configuration, save, wait for the device to reconnect, and compare the tag value with the reference recorded from the animation table. They must match to the displayed precision.

Order of operations matters here. Reverse Word Order tested against the plain HR address changes nothing useful, because a single-register integer read never combines two words; there is nothing to swap. Test the swap only after the address is HRF. This is exactly why the fix appeared to fail when it was tried before the address change.

A swapped 50.0 decodes to 2.4e-41 #

Inputs, all from the thread and the IEEE 754 single-precision format:

  • PLC value written to the REAL: 50.0, read from the animation table.
  • 50.0 as a 32-bit float: 0x42480000, high word 0x4248, low word 0x0000.
  • Denormal minimum on this format: 2 to the power of minus 149, about 1.4e-45 per unit of the integer mantissa.

Rule in words: when the two 16-bit words are swapped, the driver builds the 32-bit pattern low-word-first, so the bit pattern becomes 0x00004248. Because the high word is 0x0000, the result is a denormal, valued as mantissa times 2 to the power of minus 149.

Arithmetic:

  • 0x4248 as an integer: 4 x 4096 + 2 x 256 + 4 x 16 + 8 = 16968.
  • 16968 x 1.4e-45 is about 2.4e-41.

Result: the swapped decoding of 50.0 is a denormal near 2.4e-41, which every display rounds to 0.

Decision: any round PLC value whose low word is 0x0000 or 0x8000, such as 50.0, 1.0, 100.0 or 0.5, will show as a clean zero or a tiny denormal under a swapped word order, not as garbage. That is why the test value must be non-round: 123.456 swapped decodes to a large, obviously wrong number that cannot be mistaken for a working tag. If your HRF tag reads a suspiciously exact zero, suspect the word order before suspecting the address.

Create the tag with a full item path #

The tag editor can leave the OPC server field blank after you pick the server and commit, because a Modbus device resolves its address from the item path itself, not from addresses pre-built on the device page. Build the path directly:

  • Create the tag and set its OPC server to the server that hosts the Modbus connection; if the picker leaves the field blank after commit, enter that server name into the property by hand.
  • Enter the item path as the device connection name in square brackets plus the address, for example the connection named with the Modbus device followed by HRF2628.
  • Compare against a working tag's path to match the exact prefix format the gateway uses.

Gate: the tag shows Good quality and the reference value before you replicate it. For bulk creation, export one working tag, edit its item paths, and import.

End-to-end check of the REAL read path #

Run the whole chain once, in order:

  1. Confirm the integer tag at the %MW1003 address still matches the PLC.
  2. Confirm the HRF tag matches the non-round reference value recorded from the animation table.
  3. Change the PLC value to a second non-round value, including a negative one, and confirm the tag follows within one poll cycle.
  4. Set the value to 0.0 and confirm the tag reads 0 for the right reason: it now tracks the PLC as it moves off zero.
  5. Repeat for one more REAL at a different %MW address, to confirm the word-order setting applies across the whole connection.
  6. Write a non-round value from the gateway and confirm the same number in the animation table.

If step 6 lands in the PLC as a different number, the write path is word-swapped too, which points back at the same device setting. A read that returns zero while the integer reference works is an address-type and word-order fault, not a network fault; keep the two fixes in the order given and the zero disappears. For the integer half of similar faults, the article on converting an unsigned 16-bit Modbus word to a signed integer covers the decoding side of single-register values.

Questions asked

Why does changing the tag data type from float to double not fix the zero?

Changing the data type in the tag editor does not change how many registers the address requests. HR2628 still asks for one 16-bit register, so there is no second word to combine and no float to decode. Only an HRF address makes the driver request both registers of the REAL and decode them as one 32-bit value.

Can Reverse Word Order break other tags on the same connection?

It applies to the whole device connection, but it only affects multi-register types: HRF floats, and 32-bit integer or double-word reads. Single-register HR and IR integer reads combine no words, so they are untouched. After enabling it, re-check any other HRF tag and any 32-bit integer tag on that connection, and leave HR integer tags alone.

How do I write a REAL back to the M340 once reads work?

Write through the same HRF address, not the HR address, and write a non-round test value first. Enter a value such as 123.456 in the gateway, then confirm the animation table in the PLC shows the same number. If the write lands but the PLC shows a different number, the word order of the write path is swapped, which points back at the same device setting.

Where does the register number for an HRF address come from?

From the %MW number of the REAL itself. Modicon addressing maps the %MW space onto holding registers, so a REAL at %MW2628 is read at HRF2628 and occupies %MW2628 and %MW2629. You do not add an offset on top of the %MW number once the connection is set to zero-based addressing and that mapping is confirmed with the integer test.

Keep reading

  • How-to

    How Geo SCADA writes to an M340 PLC over Modbus TCP

    A Geo SCADA write to an M340 over Modbus TCP needs a write function code, a writable target and PLC logic that leaves the target alone. Point function 05 or 15 at %M bits and function 06 or 16 at %MW words, prove both on scratch addresses, and confirm the offset convention by writing 1234 and reading the same word back in the animation table.

    SCADA and data logging

  • Troubleshooting

    Why a Modicon M221 bit stays fixed in Kepware over Modbus TCP

    A Modbus TCP tag at 00001 that never changes usually reads the wrong Modbus object, not a broken link. The M221 does not expose its %I inputs to a read request, so match the controller's documented coil mapping, then correct Kepware's zero-based addressing option before blaming the network.

    SCADA and data logging

  • Troubleshooting

    Fixing junk Modbus TCP REAL writes from Citect SCADA

    The junk is the two 16-bit halves of your 32-bit REAL, assembled in the wrong order. Give each REAL two consecutive holding registers and set the [MODNET]FloatMode parameter - values 0 to 3, default 0, byte order 1 0 3 2 - until the PLC reads back the entered value. The address is usually right; ModScan already matched the PLC arrangement.

    SCADA and data logging