Closed AmedeeBulle closed 3 years ago
formula: x = (x >> 11) == 0 ? x : -1 ^ 0xFFF | x;
PS: Checked all my BME280's (4), but all calibrated with small positive dig_H4 and dig_H5.
This code was taken directly from the Bosch example code.
Have you seen adverse affects due to it?
I am not sure which Bosch example code you are referring to, but in all the Bosch code I have seen, dig_H4 and dig_H5 are taken as signed integers on 12 bits.
On the sensors I have, dig_H4 and dig_H5 are positive so it doesn't make a difference, but it would if they were negative.
Don't they cast it to signed? dig_H4_msb = (int16_t)(int8_t)reg_data[3] * 16;
Yes they do, and this is what I am proposing in #103
According to the datasheet, dig_H4 and dig_H5 are signed integers on 12 bits
The following code handles these as pure 16bits signed, which will never be negative...
https://github.com/finitespace/BME280/blob/7a211f03aa3ac5567b14e2cbc12ac21e185b6e0b/src/BME280.cpp#L277-L278
The datasheet is ambiguous as it refers to these 12 bits values as
signed short
, but the BoschSensortec reference code definitely handles the values as 12 bits signed integer -- the(int8_t)
cast on the msb together with a multiplication instead of a shift ensure the sign is propagated properly to theint16_t