Skip to main content
Lchal.1
Associate III
January 19, 2021
Question

Regarding modbus to write negative values.

  • January 19, 2021
  • 1 reply
  • 2224 views

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

    This topic has been closed for replies.

    1 reply

    Ozone
    Principal
    January 19, 2021

    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 ?

    Lchal.1
    Lchal.1Author
    Associate III
    January 19, 2021

    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

    Piranha
    Principal III
    January 19, 2021

    That is the correct (-800) value, just cast it to the desired 16-bit signed integer type. :)