How to convert the value from the temperature sensor?


I am working on ST Temperature sensor( hts221 ) , I use I2C command communication with sensor.

I see from the document like the following text.

enter code here Temperature data are expressed as TEMP_OUT_H & TEMP_OUT_L as 2’s complement numbers.

And the following picture is the description from document.

And the Temperature data read from the sensor is like the following

TEMP_OUT_L is 0xA8

How to convert the value of TEMP_OUT_L and TEMP_OUT_H to the Temperature data ?

Thanks in advance ?

By concatenating the bits in the two values, to form a single 16-bit value:

const temp_h = i2c_read_byte(TEMP_OUT_H);
const temp_l = i2c_read_byte(TEMP_OUT_L);
const uint16_t temp = (temp_h << 8) | temp_l;

This just assumes you have a function uint8_t i2c_read_byte(uint8_t address); that can be used to read out the two registers.

Of course, the next step would be to convert this raw binary number into an actual temperature in some proper unit (like degrees Celsius, or Kelvin). To do that, you need more information from the data sheet.