Showing results for 
Search instead for 
Did you mean: 

LSM303AGRTR minimun configuration as temperature sensor

Associate II

Good afternoon,

My name is Jorge. I am an firmware engineer from Sayme Corp in Spain.

I am using an LSM303AGRTR acceleration and magnetic sensor to get temperature values.

I am following the instructions from the datasheet:

"4.5 Temperature sensor The LSM303AGR is supplied with an internal temperature sensor. Temperature data can be enabled by setting the TEMP_EN[1:0] bits to ‘1’ in the TEMP_CFG_REG_A (1Fh) register. To retrieve the temperature sensor data the BDU bit in CTRL_REG4_A (23h) must be set to ‘1’. Both the OUT_TEMP_L_A (0Ch), OUT_TEMP_H_A (0Dh) registers must be read. Temperature data is stored inside OUT_TEMP_H as two’s complement data in 8-bit format left-justified. "

resources finded at:

But the temperature doesn´t change when i apply a hot air stream. It always returns 64 from OUT_TEMP_L_A and 3 from OUT_TEMP_H_A.

My algorithm is something like this:

1) check who_i_am (0Fh --> 0x33)

2) Temperature sensor enable on TEMP_CFG_REG_A (1Fh --< 0xC0)

3) BDU enabled on CTRL_REG4_A (23h --> 0x80)

4) do-while polling STATUS_REG_AUX_A while07h hasn´t 0x04

5) when out of do-while I read 0Ch and 0Fh and always I get the same values.

Now since my problem has been explained:

There is a minimun configuration to use the temperature sensor?

Can you write the conversion equation for the temperature?

Is the temperature expresed i 16 or in 8 signed bits?

ST Employee

Hi @Jorge González​ , I suggest you to check the LSM303AGR C drivers and examples on Github.

  • In the lsm303agr_read_data_polling.c example you can find the example code for the basic configuration of the LSM303AGR sensor. If you are interest in the temperature sensor only, you can consider mainly this code and to the part related to the data polling.
typedef enum {
} lsm303agr_temp_en_a_t;
 /* Enable temperature sensor */  
  lsm303agr_temperature_meas_set(&dev_ctx_xl, LSM303AGR_TEMP_ENABLE);

  • For the temperature sensor data interpretation, it depends if you are in normal mode (nm) or in low power mode (lp). You can find the code in the driver lsm303agr_reg.c.
    • For the normal mode:
float_t lsm303agr_from_lsb_nm_to_celsius(int16_t lsb)
  return ( ( (float_t)lsb / 64.0f ) / 4.0f ) + 25.0f;

  • For the low power mode:
float_t lsm303agr_from_lsb_lp_to_celsius(int16_t lsb)
  return ( ( (float_t)lsb / 256.0f ) * 1.0f ) + 25.0f;

You basically have to concatenate in MSB order the two OUT_TEMP_H_A (0Dh) + OUT_TEMP_L_A (0Ch) temperature registers, consider if you are on 10 or 8 bits, convert the binary data into decimal data through two's complement conversion and sum 25°C.