cancel
Showing results for 
Search instead for 
Did you mean: 

LSM303AGR can't enable temperature sensor

MHuk
Associate II

I am having a problem when initializing temperature sensor on LSM303AGR. To simplify everything for a test I am using direct commands. Writing 0xC0 to register 0x1F and then reading back register 0x1F results in 0x00 reply instead of 0xC0. Why is it behaving in this way? Writing and reading from another registers works fine.

I don't need to measure temperature, but I want to have temperature compensation working. So I am also writing 1 to COMP_TEMP_EN. Is it enough to turn on temperature compensation?

#define LSM303AGR_MAG_TEMP_CFG_REG_A 0x1F

 u8_t value = 0xC0;

 u8_t value1;

 LSM303AGR_MAG_WriteReg(0, LSM303AGR_MAG_TEMP_CFG_REG_A, &value, 1);

 LSM303AGR_MAG_ReadReg(0, LSM303AGR_MAG_TEMP_CFG_REG_A, &value1, 1);

1 ACCEPTED SOLUTION

Accepted Solutions
MHuk
Associate II

Ok, I've found the problem myself. This register 0x1F is accessible only when addressing accelerometer part of the LSM303AGR. So use 0x32 instead of 0x3C as an I2C address. It is not stated clearly anywhere in documentation which ****** me off a bit. I realized it only when saw that temperature sensor description is under accelerometer section.

However, temperature compensation is still not working as I expect. When heating device from room temperature to 50-60 degrees Celsius in 3 minutes magnetometer values are changing a lot.

I have 100Hz ODR, high-precision mode, temperature sensor and temperature compensation enabled, offset cancelation disabled.

Anyone having an idea what else should I set up? What is the normal (delta C / minute) which sensor can work with and compensating properly?

View solution in original post

1 REPLY 1
MHuk
Associate II

Ok, I've found the problem myself. This register 0x1F is accessible only when addressing accelerometer part of the LSM303AGR. So use 0x32 instead of 0x3C as an I2C address. It is not stated clearly anywhere in documentation which ****** me off a bit. I realized it only when saw that temperature sensor description is under accelerometer section.

However, temperature compensation is still not working as I expect. When heating device from room temperature to 50-60 degrees Celsius in 3 minutes magnetometer values are changing a lot.

I have 100Hz ODR, high-precision mode, temperature sensor and temperature compensation enabled, offset cancelation disabled.

Anyone having an idea what else should I set up? What is the normal (delta C / minute) which sensor can work with and compensating properly?