Skip to main content
Explorer
November 30, 2020
Solved

LIS2DH12 value of temperature?

  • November 30, 2020
  • 3 replies
  • 3340 views

I'm using sensor LIS2DH12, acceleration data I get looks OK. But I'm bit confused about temperature data.

CTRL_REG4.BDU is set to 1

CTRL_REG4.FS is set to 0 (= 2g scale)

CTRL_REG1.LPEN is set to 0

CTRL_REG4.HR is set to 0 (= 10bit normal mode)

CTRL_REG1.ODR is set 0x04 (50Hz)

TEMP_CFG_REG.TEMP_EN is set to 1 (enable temperature sensor)

I left measuring for 10 minutes, once every second, and I get these values (99% of time):

OUT_TEMP_H = 0b01111011 (7Bh = 123)

OUT_TEMP_L = 0

rarely I get value like 6Fh, 7Fh, 73h, 77h, 79h, 6Bh (I take those as some fluctuations).

Ambient temperature is around 23C.

How to interpret those values? They look too high to me.

UPDATE:

In normal mode (10bit) I get:

OUT_TEMP_H = 0b01111011 (7Bh = 123)

OUT_TEMP_L = 0

In low-power mode (8bit) I get:

OUT_TEMP_H = 0b01101111 (6Fh = 111)

OUT_TEMP_L = 0

This doesn't seem right.

    This topic has been closed for replies.
    Best answer by Chupacabras

    I have changed the IC and now it looks like working.

    I'm getting values like:

    OUT_TEMP_H = 0b00000100 (04h = 4)

    OUT_TEMP_L = 0b11000000 (C0h = 192)

    that translates to 29.75C. This looks like reasonable value. Not sure whether this measuring is useful or not, but at least I got a reasonable value.

    That means the problem was in defective IC. Case closed, I guess.

    3 replies

    Explorer
    November 30, 2020

    The datasheet only specifies a rate (1 digit per °C at 8 bit), but no fixed relation.

    I understand this as the customer's responsibility to calibrate it.

    Have you tried to vary the ambient temperature, and do the sensor values follow ?

    Explorer
    November 30, 2020

    I'm not writing about calibration.

    How to interpret those values? Because they seem to be too high.

    OUT_TEMP_H contains two's complement value. So it can go from -128 to +127.

    At room temperature I'm getting values like +123.

    Explorer
    November 30, 2020

    > OUT_TEMP_H contains two's complement value. So it can go from -128 to +127.

    You set it to 10 bit, didn't you ?

    > CTRL_REG4.HR is set to 0 (= 10bit normal mode)

    ST Employee
    November 30, 2020

    Hi @Chupacabras​ ,

    on top of Ozone's suggestions, please consider the following formula for the LSB to physical units temperature conversion for LIS2DH12  (source Github lis2dh12:(

    • Normal mode
    float_t lis2dh12_from_lsb_nm_to_celsius(int16_t lsb)
    {
     return ( ( (float_t)lsb / 64.0f ) / 4.0f ) + 25.0f;
    }

    • Low power mode:
    float_t lis2dh12_from_lsb_lp_to_celsius(int16_t lsb)
    {
     return ( ( (float_t)lsb / 256.0f ) * 1.0f ) + 25.0f;
    }

    Decoding your value, it looks like you have actually 123 (+25°C) degrees... since the temperature you want to measure is less than 25°C, you should have a negative value, i.e. a MSB value starting with "1" bit. Is the bit endianess of your temperature data correct?

    -Eleon

    Explorer
    November 30, 2020

    I assume endianess is correct, because readings of acceleration data is correct. Data from temperature sensor is handled the same way.

    I actually use exactly that driver from github. And exactly that function you mentioned (lis2dh12_from_lsb_nm_to_celsius).

    When

    OUT_TEMP_H = 0b01111011 (7Bh = 123)

    OUT_TEMP_L = 0

    then

    lsb value that goes to that function is  0b0111101100000000

    so lis2dh12_from_lsb_nm_to_celsius returns 148.0

    1. that looks very wrong
    2. ambient temperature is 25C, and this value is already right on the upper edge. Imagine ambient temperature rises to 40C. The value would be off scale...

    Explorer
    December 1, 2020

    > ambient temperature is 25C, and this value is already right on the upper edge. Imagine ambient temperature rises to 40C. The value would be off scale...

    I would do that. I mean, measure at two other points. Say, 40°C and 0°C.

    The presented output looks strange, so much is true.

    I have always used the LIS2DH12 as accelerometer only.

    ST Employee
    December 1, 2020

    Hi @Chupacabras​ , @Ozone​ ,

    then there could be something not working well...

    >> I already contacted official ST support to ask about this problem. Waiting for response.

    This is of course a good approach (going though the OLS / Representatives). Did you also open a report on Github (which is maintained by ST employees, as you correctly guessed)?

    -Eleon

    Explorer
    December 1, 2020

    Nope. I did not contact anybody on github so far.

    My approach is generally to ask on public forum first.

    I might misunderstood something silly, somebody could give me some easy answer.

    Then contact official support. There are actually 2 problems. The device is working weirdly. There are missing information about this in datasheet.

    ST Employee
    December 1, 2020

    Hi @Chupacabras​ ,

    well, the datasheet is not so clear and I'll report it internally, even if one can find the info to decode data in p.12 (maybe except from the 25°C "zero point"). Did you have the possibility to try a different LIS2DH12 sample?

    -Eleon