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 ,,,, 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 << 16) | ((uint32_t) data << 8) | (uint32_t) data);
Can someone give an example or literature to help me understand this?
2- Also, data 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.
Thanks in advance for your time and for providing the open source code! Great work and thanks for keeping the code updated!
With best regards,