LIS2HH12 and IIS2DLPC two's complement temp compared
Hi all,
I'm currently deploying hardware that can have either the LIS2HH12 or IIS2DLPC
According to the datasheet the LIS2HH12 stores the temperature as two's complement / 11 bit / 8 digit per degrees celcius.
So I convert it this way:
int16_t tilt_read_temp(void)
{
uint8_t temperature[2];
int32_t temp;
lis2hh12_temperature_raw_get(&dev_ctx, temperature);
temp = (temperature[1] << 8) | temperature[0];
temp = temp>>5;
temp = ((temp * 125) / 10) + 2500;
temp = temp / 10;
return temp;
}This gives me 211 my notation for 21.1 degrees
The other sensor IIS2DLPC should be 12 bits, two's complement 16 lsb per degrees celcius.
So I convert that one as:
int16_t tilt_read_temp(void)
{
uint8_t temperature[2];
int32_t temp;
iis2dlpc_temperature_raw_get(&dev_ctx, temperature);
temp = (temperature[1] << 8) | temperature[0];
temp = temp>>4;
temp = ((temp * 625) / 100) + 2500;
temp = temp / 10;
return temp;
}But this one returns 273, my notation for 27.3 degrees celcius.
Both boards are in the same room and I think 21 degrees is most likely the temperature in the room.
Am I converting the last one wrong?
BTW: I'm running both on 3.3v supply


