‎2023-04-13 07:40 AM
Can anyone confirm if temperature measurement is functional on the LSM303AGR? I have everything else up and working just fine with measurements over several weeks, but temperature just return 0x00 for Hi and Lo byte. This is the third generation LSM303 I'm working with, but first time I'm totally stuck!!! What to do???
I follow The data sheet from august 2022, paragraph 4.5 and have read all other developers problem on this site who are stuck the same way as I am!!
Thanx :)
Hans-Henrik
PS I have also been trying to do polling of TDA on STATUS_REG_AUX_A. TDA will never be high(1) to indicate a new value - so it will just stuck
Solved! Go to Solution.
‎2023-04-14 07:38 AM
Hi @HFuxe.1​ ,
You need to set XL ODR, you can select the data rate in CTRL_REG1_A (20h).
For any other doubts I suggest you to look at our PID.
If my reply answered your question, please click on Select as Best at the bottom of this post. This will help other users with the same issue to find the answer faster
‎2023-04-13 09:45 AM
ACC_Write_Reg(CTRL_REG4_A, 1<<BDU | 1<<SPI_ENABLE); // Enable BDU
sprintf_P(os.buffer_0, PSTR("\r\nCTRL_REG4_A: 0x%02X"), ACC_Read_Reg(CTRL_REG4_A));
uart_puts(os.buffer_0);
ACC_Write_Reg(TEMP_CFG_REG_A, 0b11<<TEMP_EN); // Enable temperature sensor
sprintf_P(os.buffer_0, PSTR("\r\nTEMP_CFG_REG_A: 0x%02X"), ACC_Read_Reg(EMP_CFG_REG_A));
uart_puts(os.buffer_0);
uint8_t temp_H;
uint8_t temp_L;
for (uint8_t i=0; i<20; i++) {
_delay_ms(500);
temp_L = ACC_Read_Reg(OUT_TEMP_L_A);
temp_H = ACC_Read_Reg(OUT_TEMP_H_A);
sprintf_P(os.buffer_0, PSTR("\r\n::LO 0x%02X HI 0x%02X"), temp_L, temp_H);
uart_puts(os.buffer_0);
}
‎2023-04-13 09:45 AM
CODE OUTPUT IS:
------------------------------------------
CTRL_REG4_A: 0x81
TEMP_CFG_REG_A: 0xC0
::LO 0x00 HI 0x00
::LO 0x00 HI 0x00
::LO 0x00 HI 0x00
::LO 0x00 HI 0x00
::LO 0x00 HI 0x00
::LO 0x00 HI 0x00
::LO 0x00 HI 0x00
::LO 0x00 HI 0x00
::LO 0x00 HI 0x00
::LO 0x00 HI 0x00
::LO 0x00 HI 0x00
::LO 0x00 HI 0x00
::LO 0x00 HI 0x00
::LO 0x00 HI 0x00
::LO 0x00 HI 0x00
::LO 0x00 HI 0x00
::LO 0x00 HI 0x00
::LO 0x00 HI 0x00
::LO 0x00 HI 0x00
::LO 0x00 HI 0x00
‎2023-04-14 07:38 AM
Hi @HFuxe.1​ ,
You need to set XL ODR, you can select the data rate in CTRL_REG1_A (20h).
For any other doubts I suggest you to look at our PID.
If my reply answered your question, please click on Select as Best at the bottom of this post. This will help other users with the same issue to find the answer faster
‎2023-04-14 09:39 AM
Thanks a lot Federica :)
It worked like a charm!!!
It should be noted in the data sheet at paragraph 4.5) that temperature measurement is coupled to the XL ODR speed. Also the TDA bit of STATUS_REG_AUX_A is worth noting!
Here is my fully working pseudo code:
// 1) Enable SPI
ACC_Write_Reg(CTRL_REG4_A, 1<<SPI_ENABLE);
sprintf_P(os.buffer_0, PSTR("\r\nCTRL_REG4_A: 0x%02X"), ACC_Read_Reg(CTRL_REG4_A));
uart_puts(os.buffer_0);
// 2) Enable BDU
ACC_Write_Reg(CTRL_REG4_A, 1<<BDU | 1<<SPI_ENABLE);
sprintf_P(os.buffer_0, PSTR("\r\nCTRL_REG4_A: 0x%02X"), ACC_Read_Reg(CTRL_REG4_A));
uart_puts(os.buffer_0);
// 3) Enable temperature sensor
ACC_Write_Reg(TEMP_CFG_REG_A, 0b11<<TEMP_EN);
sprintf_P(os.buffer_0, PSTR("\r\nTEMP_CFG_REG_A: 0x%02X"), ACC_Read_Reg(TEMP_CFG_REG_A));
uart_puts(os.buffer_0);
// 4) Set temperature measure to 10Hz (== Follows ACC measurements)
ACC_Write_Reg(CTRL_REG1_A, 0b0010<<ODR | 0<<LPen | 1<<Zen | 1<<Yen | 1<<Xen);
uint8_t temp[2];
for (uint8_t i=0; i<20; i++) {
lsm_busy_wait_inv(STATUS_REG_AUX_A, TDA); // Busy wait for valid temperature
ACC_Read_Multiple(OUT_TEMP_L_A, temp, 2);
int16_t celsius = (int8_t)temp[1] + 25; // 2's complement
// This casts to eight-bit 2's complement
sprintf_P(os.buffer_0, PSTR("\r\nHI 0x%02X C %02i"), temp[1], celsius);
uart_puts(os.buffer_0);
}
OUTPUT:
CTRL_REG4_A: 0x01
CTRL_REG4_A: 0x81
TEMP_CFG_REG_A: 0xC0
HI 0xFD C 22
HI 0xFD C 22
HI 0xFD C 22
HI 0xFC C 21
HI 0xFD C 22
HI 0xFD C 22
HI 0xFC C 21
HI 0xFC C 21
HI 0xFD C 22
HI 0xFC C 21
HI 0xFD C 22
HI 0xFD C 22
HI 0xFD C 22
HI 0xFD C 22
HI 0xFC C 21
HI 0xFC C 21
HI 0xFC C 21
HI 0xFC C 21
HI 0xFC C 21
All the best :)
Hans-Henrik Fuxelius
‎2023-06-16 11:12 PM
CTRL_REG4_A: 0x80
try this here