Reading Temperature sensor data from LIS2DH12 IC


I am using the dwm-simple example from new firmware release to add more functionalities such as reading accelerometer and temperature sensor data from LIS2DH12. As per the datasheet of LIS2DH12, there is inbuilt temperature sensor . The value of temperature sensor can be read from two output registers OUT_TEMP_L, OUT_TEMP_H.

I am using following configurations to initialize LIS2DH12 registers:

  1. Write 57h into CTRL_REG1 // Turn on the sensor and enable X, Y, and Z, ODR = 100 Hz
  2. Write 00h into CTRL_REG2 // High-pass filter disabled
  3. Write 40h into CTRL_REG3 // Interrupt activity 1 driven to INT1 pad
  4. Write 80h into CTRL_REG4 // FS = ±2 g, enable BDU
  5. Write 08h into CTRL_REG5 // Interrupt 1 pin latched
  6. Write 10h into INT1_THS // Threshold = 250 mg
  7. Write 00h into INT1_DURATION // Duration = 0
  8. Write 2Ah into INT1_CFG
  9. Write C0h into TEMP_CFG_REG

If there is new data arrival i.e TDA bit is high in STATUS_REG_AUX, my code reads output temperature registers, I use the following method to convert raw temperature reading to Celsius.

temp_in_celsius = ((OUT_TEMP_H / 64) / 4) + 25;

The problem is I am only getting same value i.e 25. I used soldering iron to test the variations in temperature but nothing has changed the raw data output of both registers OUT_TEMP_H, OUT_TEMP_L.

I would really appreciate any help.

1 Like

hi maniot,

where did you take that formula from?
i do:
write C0h into TEMP_CFG_REG
write 80h into CTRL_REG4
check STATUS_REG_AUX (always reads FFh for me)
read OUT_TEMP_H (0Dh) and OUT_TEMP_L (0Ch)

OUT_TEMP_H holds the degrees in Celsius (with an offset)
OUT_TEMP_L holds fractions of degrees depending on the resolution setting in CTRL_REG1 (20h)
its two’s complement, so OUT_TEMP_H (0Dh) flips somewhere in the range from 0 “down” to 255.

the sensor is intended to show changes in temperature, not absolute values, so there is no information about the offset.


with your formula, if you heat up your chip 100°C, the “temp_in_celsius” rises about 0.4

hope it helps,
greetings horst

Thanks Horst.

I found this formula being used to calibrate the temperature sensor’s absolute values to a reference temperature of 25 in Celsius.

Thank you for the clarification of this concept that the output registers are storing the change in temperature.