IMDHMIControls LibraryShop main store

Troubleshooting

Why S7-300 PROFIBUS RTD byte conversion reads wrong

Industrial networks Published 8 min read By IMDHMI controls team

Short answer

The PROFIBUS transfer is not the fault. Keep the receive buffer in bytes, assemble each RTD channel's two bytes with the high-order byte at the lower address, decode the complete 16-bit word as signed two's complement, and only then scale. A standard PT100 range carries ten counts per degree, so 50 °C must read 500; a measured 5066 means the channel is in a different configured range — calibrate with two points or fix the configuration.

On this page
  1. Symptoms and what each one points to
  2. Why the BYTE buffer is correct and the WORD change was not
  3. Locate the channel's two bytes and assemble them high-byte first
  4. Decode the complete word as signed two's complement
  5. Worked example: a negative setpoint and the measured positive point
  6. Match the scale to the configured range
  7. Checks that prove the conversion
  8. Questions asked

Your PROFIBUS link is working; the conversion is not. When DP_RECV delivers an ET-200 analog channel into a DB as bytes, a temperature goes wrong for three stacked reasons: the byte pair is read in the wrong order or only half of it is read, the 16-bit word is decoded unsigned so negative temperatures disappear, and a scale is applied that the channel configuration never promised. Assemble the two bytes with the high-order byte at the lower address, decode the complete word as signed two's complement, then apply a scale verified against the configured measuring range. A standard PT100 temperature range carries ten counts per degree, so the raw word must rise ten counts for every degree the simulator adds. The test behind this article measured 5066 counts at a simulated 50 °C — a different scale — and the worked example below converts both that measurement and the negative case.

Symptoms and what each one points to #

Each fault observed in this kind of setup maps to one cause and one first move:

  • Bytes change when you simulate, but no arithmetic makes a temperature. You are watching a single byte or the wrong pair. Every analog channel occupies two adjacent bytes in the receive buffer; locate that pair before any math.
  • Changing the DB entry between BYTE and WORD changed nothing. The declaration renames the same bytes; it cannot set byte order, signedness or scale. Keep the buffer in bytes and assemble the pair deliberately.
  • The value sits far above what the assumed scale predicts. Either a byte is missing from the word, or the configured range does not carry the tenths-of-a-degree scale you assumed.
  • A negative simulation never shows a minus. The word is being read unsigned, or the bytes are complemented one at a time; both destroy the sign. Decode the complete word instead.
  • The word stays at a constant large value whatever the simulator does. That is a substituted overflow or fault code, not measurement — the failure family behind a PROFIBUS analog input stuck at 32735.
  • Monitoring the channel address online shows nothing. With DP_SEND and DP_RECV the slave data never enters the CPU's process image; watch the receive DB, not a peripheral address.

Why the BYTE buffer is correct and the WORD change was not #

DP_SEND and DP_RECV belong to the CP-based PROFIBUS master setup on an S7-300. The communications processor collects the slave's data and hands it to the program as one block that you declare yourself — hence a DB of byte entries — instead of peripheral addresses in the process image. That is also why the online monitor found nothing at the channel address: there is no channel address to watch, only the receive DB.

Byte entries are the right declaration for such a buffer. Each received octet keeps its identity, and you assemble words where you control the order. Changing the entry type to WORD only changes how you name the same two bytes; it cannot decide which byte is high-order, whether the pattern is signed, or what scale the channel produces. Those three live in the assembly, the decode and the configured measuring range.

Consistency is handled by the transfer itself. Siemens documents SFC 14 DPRD_DAT for a standard slave on the CPU's own DP interface whenever more than four bytes, or exactly three, must stay consistent over the whole transfer; DP_RECV does the equivalent job on the CP side by moving the entire block into the DB in one call. Either way a two-byte analog value arrives as a pair you can treat as one word.

Locate the channel's two bytes and assemble them high-byte first #

The offsets come from the slave's configured module layout, not from arithmetic: digital modules consume whole bytes first, then every analog channel occupies two adjacent bytes in configuration order. Read the configured layout in the hardware configuration and write down the two buffer offsets for the channel under test — the same mechanism that maps PROFIBUS DP byte offsets to controller input addresses.

Then isolate. Disable every channel except the one under test, as the reported test did, and confirm that exactly two bytes in the receive DB move when the simulator changes. If more than two move, another channel is still live; if none move, the offsets are wrong.

S7 words are big-endian: the byte at the lower address is the high-order byte. For a pair at DBB10 and DBB11 the word is 256 × DBB10 + DBB11. A SIMATIC analog module transmits its channel value in that order; for a third-party slave, take the order from its module data before assembling.

Decode the complete word as signed two's complement #

Treat the assembled word as unsigned first. Below 32768 it already is the signed value; at 32768 or more the value is negative and equals the word minus 65536. That is the same conversion covered in converting an unsigned 16-bit Modbus word to a signed integer.

Complementing each byte separately does not do this. Inverting both bytes inverts all sixteen bits of the word, and the bitwise NOT of a two's-complement number equals its negation minus one, so a negative reading comes back as its magnitude less one count — positive, sign gone. That is exactly the "absolute temperature" effect the reported test saw. Make the sign decision on the complete word, before any conversion to DINT or REAL.

The pipeline is fixed: assemble the pair, decode the word as signed, move it to a DINT or REAL, then scale. Never complement individual bytes on the way.

Worked example: a negative setpoint and the measured positive point #

Take a channel configured in a standard PT100 temperature range, simulator at -20.0 °C. The documented scale gives -20.0 °C × 10 counts per degree = -200 counts.

As a 16-bit two's-complement word, -200 is 65536 - 200 = 65336, written FF38 in hex: byte FF at the lower address, 38 above it.

The three wrong reads: the low byte alone shows 38 = 56; the pair read as an unsigned word shows 65336; complementing each byte gives 00 and C7, a word of 00C7 = 199, which converts to +19.9 °C — positive and one count off.

The correct decode: 65336 is at or above 32768, so the signed value is 65336 - 65536 = -200 counts, and -200 counts × 0.1 °C per count = -20.0 °C.

Now the measured point from the reported test: a simulated 50 °C produced the combined word 5066 counts, not the 500 a standard range would give. 5066 / 50 = 101.32 counts per degree, and dividing by 100 gives 50.66 — which is why the tester divided by one hundred and then applied an adjustment. A word of that size on a channel set up for tenths of a degree proves the configured range is not a standard temperature range; the correction belongs in the configuration or the scale, not the PROFIBUS link.

Match the scale to the configured range #

The S7 analog format gives a channel a nominal range that tops out at 27648 counts, with overflow and substituted codes above it — the convention behind why an S7-300 analog input reads 0 to 27648 counts. Temperature is the documented exception to raw full-scale counts: the S7-300 module data specifies tenths of a degree for standard RTD ranges, so 50.0 °C arrives as 500 counts.

Decide per case:

  • Channel configured in a standard PT100 temperature range. Expect the signed word to rise ten counts per degree and convert by dividing it by ten after the signed decode. The worked example above closes that loop.
  • Signed word at a known setpoint is not ten counts per degree (the measured case). The channel sits in a different configured range. Reconfigure it to a standard temperature range in the hardware configuration and expect the documented tenths, or keep the configuration and calibrate it.
  • Calibration, if the configuration stays. Read the signed word at two known setpoints. Slope = (raw2 - raw1) / (T2 - T1) counts per degree, offset = raw1 - slope × T1, temperature = (raw - offset) / slope, where raw1 and raw2 are the signed words at setpoints T1 and T2. For the measured point — 50 °C with 5066 counts — a zero reading at 0 °C gives a slope of 101.32 counts per degree and an offset of zero; if the zero point does not read zero, the two-point formula absorbs it into the offset.

A word parked just above 27648 while the simulator changes is a substituted code, not a temperature: fix wiring or channel configuration, not arithmetic.

Checks that prove the conversion #

  • With only the test channel enabled, exactly two bytes move in the receive DB when the simulator changes — the same two, every time.
  • At 0 °C the signed word reads zero, within a few counts of drift.
  • On a standard range, the signed word at any positive setpoint equals the setpoint in degrees times ten counts per degree.
  • At a negative setpoint the signed word is negative and the display tracks the simulator; the unsigned view of that same word equals the signed value plus 65536, which confirms the assembly and byte order.
  • Returning the simulator to a previous setpoint reproduces the previous word exactly, byte for byte.

Questions asked

Can I read the two buffer bytes directly as a signed integer?

Yes. Absolute word access reads two adjacent byte fields as one value without changing the declaration: an address in the form DB20.DBW10 takes DBB10 as the high byte and DBB11 as the low byte. Move that word into a variable of type INT and you already have the signed 16-bit number, so the manual two's-complement step disappears. Confirm the word address matches the channel's configured offset first.

Why does a negative temperature appear as a large positive number?

The byte pair was read as an unsigned word. With the standard tenth-degree scale, minus twenty degrees arrives as minus 200 counts, stored as hexadecimal FF38, which shows as 65336 when the sign is ignored. Apply the signed rule to the assembled word instead: a word of 32768 or more is negative, and this one decodes to minus 200 counts, that is minus twenty degrees.

When is SFC 14 DPRD_DAT required instead of DP_RECV?

For a standard DP slave connected to the CPU's own DP interface, Siemens documents SFC 14 DPRD_DAT whenever more than four bytes, or exactly three bytes, must stay consistent across the whole transfer. DP_SEND and DP_RECV are the counterpart instructions for a PROFIBUS communications processor: they move the entire slave block into the DB in one consistent operation, which keeps each two-byte analog value intact.

What scale turns the signed word into degrees Celsius?

For a channel configured in a standard RTD temperature range, the S7-300 module data specifies tenths of a degree: 50 degrees reads 500 counts and you divide by ten. The reported test instead measured about 101 counts per degree at its simulated point, which means the channel sat in a different configured range; measure two known setpoints and divide the count difference by the temperature difference.

Why disable the other analog channels during the test?

Each analog channel owns its own two-byte pair, and several live channels change several pairs at once. With only the tested channel enabled, exactly one pair moves when the simulator changes, which proves the buffer offsets before any arithmetic is built on them. Re-enable the other channels afterwards and check that each pair still tracks its own channel.

Keep reading

  • Troubleshooting

    Converting an unsigned 16-bit Modbus word to a signed integer

    The module is sending offset-binary counts for a bipolar input, and the controller reads them as two's complement, so every count from 32768 up arrives negative. Subtract 65536 from any count at or above 32768, or set the channel to a unipolar range so the wrap disappears entirely.

    Industrial networks

  • Troubleshooting

    Fix ABB IRC5 PROFINET word values with a byte swap

    A word of 100 written from an S7-300 arrives at an ABB IRC5 Group Input as 25600: the PLC stores words big-endian, the Group Input reads the first byte as the low byte. Swap the two bytes in exactly one place, preferably an SCL block in the PLC, and the robot reads 100.

    Industrial networks

  • Troubleshooting

    Why a Modbus 32-bit float reads wrong after a CPW copy

    A wrong float after a CPW copy means the two 16-bit Modbus words sit in the wrong order, not that communications failed. Capture the raw pair at two different meter readings, swap the words in integer storage, copy the ordered pair into the float destination, and confirm the value tracks the meter. Test byte order only as a separate last step.

    Industrial networks

Read PROFINET device status on an S7-400 with SFC 51 SSL 0x0194