cancel
Showing results for 
Search instead for 
Did you mean: 

Get IIS2DH data with data ready interrupt

danh221212
Associate II

Hello everyone,

I'm using the II2SDH accelerometer and want to collect the data whenever the Data Ready Interrupt is fired. I'm using the INT1 pin for that and this is my configuration:

    SPI_WriteByte(CTRL_REG1, 0x9f); // Low power mode, 5.376Hz data rate, XYZ Axis enable
    SPI_WriteByte(CTRL_REG2, 0x00);
    SPI_WriteByte(CTRL_REG3, 0x10);	// INT1 on data ready
    SPI_WriteByte(CTRL_REG4, 0x00);
    SPI_WriteByte(CTRL_REG5, 0x00); 
    SPI_WriteByte(CTRL_REG6, 0x00);

The INT1 pin is configured as external interrupt mode on STM32, but the interrupt won't triggered. Is there any other ways to collect the data correctly? Otherwise my FFT calculation is incorrect.

Any ideas how to fix the problem will be appreciated. Thanks.

1 ACCEPTED SOLUTION

Accepted Solutions
danh221212
Associate II

Hi, thanks for the reply.
The code you propose actually not using interrupt. I've found out the problem in my code and it work now.

View solution in original post

4 REPLIES 4
Federica Bossi
ST Employee

Hi @danh221212 ,

Have a look at this official example on Github and let me know if it helps you :)

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.
danh221212
Associate II

Hi, thanks for the reply.
The code you propose actually not using interrupt. I've found out the problem in my code and it work now.

For the benefit of future readers, who may find this looking for solutions to the same problem, it would be helpful if you would describe what was the problem, and how you fixed it.

i want to collect 2048 data of the accelerometer and apply FFT. If not sample correctly, the FFT result will be wrong. That's why i want to use data ready interrupt. My code was first look like this

while(1){
   if(sampleIndex >= 2047){
       performFFT()
       sampleIndex = 0;
       collectData(); // this is to clear the status register and reactivate the interrupt
   }
}
....
void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
{
  if(GPIO_Pin == INT1_Pin) {
      collectData();
  } else {
      __NOP();
  }
}

This however make the interrupt unstable. I read again the requirement and add a timer interrupt to reset the sampleIndex every 3 second. And it work fine.