0
votes

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

I have reference the Data sheet for HTS221 , and also get the value from Sensor. But I don't how to convert the value to the actual temperature.

The value get the from the sensor is like the following:

Read HTS221 TEMP_OUT_L: 0x2a value is 0x15
Read HTS221 TEMP_OUT_H: 0x2b value is 0xFF
Read HTS221 T0_degC_x8: 0x32 value is 0xBF
Read HTS221 T1_degC_x8: 0x33 value is 0xBF
Read HTS221 T1/T0 msb: 0x35 value is 0x4
Read HTS221 T0_OUT-3C: 0x3C value is 0x0
Read HTS221 T0_OUT-3D: 0x3D value is 0x0
Read HTS221 T1_OUT-3E: 0x3E value is 0x0
Read HTS221 T1_OUT-3F: 0x3F value is 0x0

The description of temperature register is like the following picture.

enter image description here

And it give the calibration coefficients and the example of temperature conversion like the following picture , but I still understand what it mean. enter image description hereenter image description here

Does somebody can teach me how to convert the above value to the Temperature from Sensor? I have no idea about this... Thanks in advance.

1
Trying to get to it from the reverse direction, what was the temperature when you got the readings you show us?Some programmer dude

1 Answers

3
votes

You need to read the following calibration registers:

T0_degC_x8  (Calibration register 32)
T1_degC_x8  (Calibration register 33)
T1_T0msb    (Calibration register 35)
T0_OUT      (Calibration register 3C and 3D)
T1_OUT      (Calibration register 3E and 3F)

T0_degC_x8 and T1_degC_x8 are 10 bit values, so you need to get the 2 last bits from register 35.

Then it's just simple interpolation to get the measured temperature:

double T_DegC;
double T0_degC = (T0_degC_x8 + (1 << 8) * (T1_T0msb & 0x03)) / 8.0; 
double T1_degC = (T1_degC_x8 + (1 << 6) * (T1_T0msb & 0x0C)) / 8.0; // Value is in 3rd and fourth bit, so we only need to shift this value 6 more bits.
T_DegC = (T0_degC + (T_OUT - T0_OUT) * (T1_degC - T0_degC) / (T1_OUT - T0_OUT)); 

Note:

The register numbering is hexadecimal, so registers 32, 33, and 35 are actually registers 0x32, 0x33, and 0x35.