2020-07-13 05:32 AM
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: https://www.st.com/resource/en/datasheet/lsm303agr.pdf
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?
2020-07-13 08:16 AM
Hi @Jorge González , I suggest you to check the LSM303AGR C drivers and examples on Github.
typedef enum {
LSM303AGR_TEMP_DISABLE = 0,
LSM303AGR_TEMP_ENABLE = 3,
} lsm303agr_temp_en_a_t;
/* Enable temperature sensor */
lsm303agr_temperature_meas_set(&dev_ctx_xl, LSM303AGR_TEMP_ENABLE);
float_t lsm303agr_from_lsb_nm_to_celsius(int16_t lsb)
{
return ( ( (float_t)lsb / 64.0f ) / 4.0f ) + 25.0f;
}
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.
Regards