Interpreting HEX return values MODBUS

Slaves of RTU Master have following register map

42101 to 42102 voltage normal R phase

I am using the code to read as below

result_mtr_vals = node.readHoldingRegisters(2100,2);

        lcd.print("R PHASE VOLTAGE");
        lcd.setCursor(0,1);
        lcd.print(node.getResponseBuffer(0),HEX);//2101
        lcd.print(node.getResponseBuffer(1),HEX);//2102

The results are 2B22 4278

The meter is showing around 60.5 volt

The Data type of holding register is 32 bits FP.

How can I reach to this value(around 60V)

webscada, realise that the data is stored as unsigned integer, not as hexadecimal.
You are printing to the LCD it as hexadecimal only.

You wrote:

The Data type of holding register is 32 bits FP

No it is not. You should now now that it is unsigned integer, 16 bits, or uint16_t. Always.

So, as all Modbus data in holding registers are transacted as unsigned integer, more concisely, uint16_t, then this is the datatype you need to work with.

So, with a little looking online I am sure you will find many examples of obtaining floating point data from two unit16_t values.
For example, the following code is one method:

float num;
unsigned long temp = (unsigned long)regs[0] << 16 | regs[1];
num = *(float*)&temp;

You need to know the register order of the two registers, in terms of which is the significant register.
If the data result is not correct, you can swap the order of the two registers.


Paul - VK7KPA

Thanks Sir,It worked.