2024-03-20 08:32 AM
Hi everybody,
I'm using a LSM303AGR and I got some difficulties to read the temperature.
My I2c functions, because I can read "who am I" registers, and I tried to write then to read some registers.
I did the following steps :
LSM303_IO_Write_one_byte(ACC_I2C_ADDRESS,LSM303AGR_CTRL_REG4_A,0x80);
for (idx = 0;idx < 50000; idx++) {}
LSM303_IO_Write_one_byte(ACC_I2C_ADDRESS,LSM303AGR_TEMP_CFG_REG_A,0xC0);
for (idx = 0;idx < 50000; idx++) {}
LSM303_IO_Write_one_byte(ACC_I2C_ADDRESS,LSM303AGR_CTRL_REG1_A,0x27);
First, I set BDU, then I set TEMP_EN[1.0], and I configure (HR / normal / low power mode (10Hz)
To read the register, I'm waiting for change on TDA bit :
if((LSM303_IO_Read_one_byte(ACC_I2C_ADDRESS,LSM303AGR_STATUS_REG_AUX_A) & 0x04) == 0x04) {
LSM303_IO_Read_multiple_bytes(ACC_I2C_ADDRESS,LSM303AGR_OUT_TEMP_L_A,2,(uint8_t *)data_temp);
temp = (int8_t)data_temp[1] + 25;
}
But I've always 0.
When I display the I2C signals, it seems to be correct :
If you have some suggestions, I'll be very happy.
Thank you.
2024-03-21 03:26 AM
Hi @fab04 ,
Did you set the TEMP_EN[1:0] bits to 1 in the TEMP_CFG_REG_A (1Fh) register?
You could also take a look at our PID examples on Github.
You will find how to read the temperature sensor output and how to implement it: