I have a sensor named LSM303DLHC ,it have 2 temp register but I can't figure it out how to convert it to degrees Celsius. 2 Reg is:
TEMP_OUT_H_M register // high reg
TEMP11 | TEMP10 | TEMP9 | TEMP8 | TEMP7 | TEMP6 | TEMP5 | TEMP4
TEMP_OUT_L_M register //low reg
TEMP3 | TEMP2 | TEMP1 | TEMP0 | 0 | 0 | 0 | 0
In datasheet say: "TEMP[11:0] Temperature data (8 LSB/deg - 12-bit resolution)" My current code is
uint8_t hig_reg = read(TEMP_OUT_H_M) // value = 0x03
uint8_t low_reg = read(TEMP_OUT_L_M) // value = 0x40
int16_t temp = ((uint16_t)hig_reg << 8) | (uint16_t)low_reg; // temp = 0x0340 = 832
float mTemp = temp/256; // = 3.25
mTemp = mTemp +20 ; // =23.25 (°C) i add 20 more
But I don't understand where the 20 °C offset comes from? Datasheet never mentions it.