HX711 2's complement and saturation values

Hi all,

I am an electrical engineer student (newbie) trying to implement a circuit using HX711 Board. During my research I found bogde’s code, but since I am trying to implement my own code (to also learn during the process) I am using bodge’s code as a guideline to understand how to implement the serial interface communication. However, I have some doubts and I would like to kindly ask if anyone could help me:

1 - During the 24 bit conversion are you/how are you calculating the 2’s complement? I saw that you read the 24 bits by shifting one byte at the time and after reading [1],[2],[3],[4],[5] I saw that the conversion is performed in one single line (stated below), but I don’t understand how shifting the bytes to a 32 unsigned integer is comparable to performing the 2’s complement

return (((uint32_t) data[2] << 16) | ((uint32_t) data[1] << 8) | (uint32_t) data[0]);

Can someone give an example or literature to help me understand this?

2- Also, data[2] is compared with 0x80 but 24 bits are not compared with 07FFFFFh (the maximum value as stated in the datasheet). Shouldn’t it be? I am just trying to correlate the code with the HX711’s datasheet to check if something is missing.
image

Thanks in advance for your time and for providing the open source code! Great work and thanks for keeping the code updated!

[1] #23
[2] #38
[3] #47

[4] queuetue/Q2-HX711-Arduino-Library#1
[5] queuetue/Q2-HX711-Arduino-Library#5

With best regards,
Miguel

1 Like