endail / hx711-pico-c

Implementation of single and multiple HX711 use via RP2040's state machine
https://endail.github.io/hx711-pico-c/
MIT License
35 stars 7 forks source link

32-bit signed conversion #33

Closed hubiscode closed 2 years ago

hubiscode commented 2 years ago

I get incorrect values for negative numbers. The following function for the conversion from 24-bit to 32-bit works correctly for me.

static inline int32_t hx711_get_twos_comp(const uint32_t raw) {

    int32_t val = raw;
    if (val & 0x800000) {
      val -= 0x1000000;
    }
    assert(val >= HX711_MIN_VALUE && val <= HX711_MAX_VALUE);

    return val;
}
endail commented 2 years ago

This should be fixed now. Can you check if it's working for you?

hubiscode commented 2 years ago

Works great, thank you.