cancel
Showing results for 
Search instead for 
Did you mean: 

[SOLVED] Reading temperature sensor on LIS2DE12 via I2C

davide239955_st
Associate II

I have implemented in our product a LIS2DE12 sensor. I would like to read the temperature register via I2C.

In order to do this I setup the following register:

at start-up:

-check WHO_AM_ I register (0x0Fh) which correctly reports 0x33h (so I2C bus and LI2DE12 is alive).

-register CTRL_REG0 (0x1Eh) to 0x90h (i.e. SDO/SA0 disconnected from pull-up because it is connected to GND on the PCB).

-register TEMP_CTRL_REG (0x1Fh) to 0xC0h (i.e. enabling the temperature sensor reading).

-register CTRL_REG1 (0x20h) to 0x18h (i.e. ODR set to 1Hz and Lpen bit set '1' as stated in datasheet).

at run-time:

-read STATUS_REG_AUX(0x07h) and check TOR bit is '0' and TDA bit is '1'.

-if it is OK, read OUT_TEMP_L (0x0Ch) register.

However STATUS_REG_AUX always reports 0x44h (i.e. temperature data overrun occured). Even if I discard checking the TOR and TDA bit, the register OUT_TEMP_L is always 0x00.

Is there a different procedure to read the temperature sensor?

Thanks

8 REPLIES 8
Winfred LU
ST Employee

Hi Davide,

Please try to set BDU bit 1 in CTRL_REG4 (23h).

Please note that both OUT_TEMP_L (0Ch) and OUT_TEMP_H (0Dh) have to be read.

Best Regards,

Winfred

davide239955_st
Associate II

Hello Winfred,

Thank you for reply. I have modified my code as below

at start-up:

-check WHO_AM_ I register (0x0Fh) which correctly reports 0x33h (so I2C bus and LI2DE12 is alive).

-register CTRL_REG0 (0x1Eh) to 0x90h (i.e. SDO/SA0 disconnected from pull-up because it is connected to GND on the PCB).

-register TEMP_CTRL_REG (0x1Fh) to 0xC0h (i.e. enabling the temperature sensor reading).

-register CTRL_REG1 (0x20h) to 0x18h (i.e. ODR set to 1Hz and Lpen bit set '1' as stated in datasheet).

-registrer CTRL_REG4(0x23h) to 0x80h (i.e. BDU bit set, Selftest disable, FSR to +/-2g, SIM bit to 0)

at run-time:

(only for debug)

-read back registrer CTRL_REG4(0x23h): checked that it is 0x80h (i.e. BDU bit set)

-read back registrer CTRL_CFG_REG(0x1Fh): checked that it is 0xC0h (i.e. Temp sensor is enabled)

(end only for debug)

-read STATUS_REG_AUX(0x07h): checked TOR bit is '0' and TDA bit is '1'.

-read OUT_TEMP_L (0x0Ch) and OUT_TEMP_H (0x0Dh) register.

I still get STATUS_REG_AUX = 0xFF and OUT_TEMP_L = 0x00, OUT_TEMP_H = 0x00 (which seems weird because the two register should be in 2's complement each other).

Should I enable acceleromter features to read sensor temperature or is it allowed to read only the temperature?

Thanks again

Hi Davide,

> Should I enable acceleromter features to read sensor temperature or is it allowed to read only the temperature?

 Yes, please try to also enable accelerometer.

If the accelrometer sensor is in power-down mode, the temperature sensor is off and is showing the last value measured.

Thank you.

Best Regards,

Winfred

davide239955_st
Associate II

Hello Winfred,

Following your suggestion, I have modified the code has below

at start-up:

-check WHO_AM_ I register (0x0Fh) which correctly reports 0x33h (so I2C bus and LI2DE12 is alive).

-set register CTRL_REG0 (0x1Eh) to 0x90h (i.e. SDO/SA0 disconnected from pull-up because it is connected to GND on the PCB).

-set register TEMP_CTRL_REG (0x1Fh) to 0xC0h (i.e. enabling the temperature sensor reading).

-set register CTRL_REG1 (0x20h) to 0x1Fh (i.e. ODR set to 1Hz ,Lpen bit set '1' as stated in datasheet, Zen,Yen,Xen enabled).

-set registrer CTRL_REG4 (0x23h) to 0x80h (i.e. BDU bit set, Selftest disable, FSR to +/-2g, SIM bit to 0)

at run-time:

(only for debug)

-read back registrer CTRL_REG4(0x23h): checked that it is 0x80h (i.e. BDU bit set)

-read back registrer CTRL_CFG_REG(0x1Fh): checked that it is 0xC0h (i.e. Temp sensor is enabled)

-read back registrer STATUS_REG(0x27h): it replies 0xFF (i.e. data are available but there is overrun on all axis..not good)

(end only for debug)

-read STATUS_REG_AUX(0x07h): checked TOR bit is '0' and TDA bit is '1'.

-read OUT_TEMP_L (0x0Ch) and OUT_TEMP_H (0x0Dh) register.

At this point, I think I'm doing something incorrect in the configuration phase. I expected at least to find status_reg not "overruned".

The good news is that I2C bus is wokring and LIS2DE12TR is repling with expected value when the configured registers are red.

Could you please write me the correct sequence of command to enable the accellerometer (and possibly temperature sensor)?

Thanks for support.

Best regards,

Davide

Winfred LU
ST Employee

Hi Davide,

The sequence is OK.

It would be fine to see 0xFF for STATUS_REG, since you didn't read accelerometer data out.

Actually, there is no need to check STATUS_REG (27h) for your application.

Please just check STATUS_REG_AUX (07h), and when temperature data is available read the temperature data both from OUT_TEMP_L and OUT_TEMP_H,

as the last 2 steps:

-read STATUS_REG_AUX(0x07h): checked TOR bit is '0' and TDA bit is '1'.

-read OUT_TEMP_L (0x0Ch) and OUT_TEMP_H (0x0Dh) register.

Thank you.

Best Regards,

Winfred

davide239955_st
Associate II

Hello Winfred,

Thank you for confirmation that sequence is OK. However, it doesn't solve my issue because STATUS_REG_AUX(0x27h) register is always equal to 0xFF.

Unless I need to read out the accelerometer data out (OUT_X_H, OUT_Y_H and OUT_Z_H registers ) in order to "unlock" the STATUS_REG_AUX value.

I will try to read the accelerometer output registers to see if it can help.

May the ODR (in my case 1Hz) affect the behaviour? Do you suggest to increase it?

Thanks and regards,

Davide

Hi Davide,

It is strange, since in my test i don't have to read accelerometer data.

The scenario would simply be: whenever TDA bit in STATUS_REG_AUX is set, read OUT_TEMP_L and OUT_TEMP_H.

During the test, STATUS_REG_AUX value was either 0xBF when data available or 0xBB when data not available.

ODR shall not matter for its behavior.

Anyway, for your case

i think if you also read accelerometer data out to clean STATUS_REG, before checking STATUS_REG_AUX, it will help.

Best Regards,

Winfred

davide239955_st
Associate II

Dear Winfred,

I think I have solved my problem. Configuration registers are OK.

Problem was related to the reading part of the code. To read multiple register (in my case temperature register 0x0C and 0x0D) the MSB of the SUB byte must be '1'.

Now It seems i get some value from temperature. Now i have to understand to convert from data byte to celsius degree.

I have discovered this "driver" from STM github

https://github.com/STMicroelectronics/STMems_Standard_C_drivers/tree/master/lis2de12_STdC

and I think I will find there the solution.

Thanks for support.

Regards,

Davide