cancel
Showing results forΒ 
Search instead forΒ 
Did you mean:Β 

LSM303AGR Temperature measurement??

HFuxe.1
Associate II

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

1 ACCEPTED SOLUTION

Accepted Solutions
Federica Bossi
ST Employee

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

In order to give better visibility on the answered topics, please click on 'Accept as Solution' on the reply which solved your issue or answered your question.

View solution in original post

5 REPLIES 5
HFuxe.1
Associate II

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);

}

HFuxe.1
Associate II

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

Federica Bossi
ST Employee

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

In order to give better visibility on the answered topics, please click on 'Accept as Solution' on the reply which solved your issue or answered your question.
HFuxe.1
Associate II

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

CTRL_REG4_A: 0x80

 

try this here