2021-01-18 08:10 PM
Hi, i am new to stm32 i need to write negative values (signed integers or float) in my modbus and transmit it to my PC. But i am not able to write negative values it shows some other values if i transmit negative values . can anyone help me with it please if you know the answer.
Thank you
2021-01-18 11:34 PM
The modbus spec only knows bits (called single coils) and registers, which are just 16-bit values.
https://modbus.org/docs/Modbus_Application_Protocol_V1_1b3.pdf
Any interpretation (signed/unsigned) happens in the receiver.
> But i am not able to write negative values it shows some other values if i transmit negative values
You could be more specific why do you think that.
What do you observe ?
What do you expect, and what do you see ?
2021-01-19 01:55 AM
if i write -800 in modbus and transmit it to my pc . i am going to receive 64736. but i need to get -800.
Should i need to write any line of code to modify the value coming from my modbus.
Thank you
2021-01-19 02:03 PM
That is the correct (-800) value, just cast it to the desired 16-bit signed integer type. :)
2021-01-19 08:33 PM
if(Target_Pos1[0] > 32767 && Target_Pos1[0] < 65535)
{
Target_Pos1[0] = 65536 - Target_Pos1[0] ;
}
i did like this is it correct and my Target_Pos1[0] is my buffer where my modbus value -800 is storing.
2021-01-19 08:33 PM
Thank you