Skip to main content
Associate
January 22, 2025
Solved

Get IIS2DH data with data ready interrupt

  • January 22, 2025
  • 2 replies
  • 1547 views

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.

Best answer by danh221212

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.

2 replies

Federica Bossi
Technical Moderator
January 29, 2025

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.
danh221212AuthorBest answer
Associate
January 30, 2025

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.

Andrew Neil
Super User
January 30, 2025

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.

A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.
Associate
January 30, 2025

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.