Get IIS2DH data with data ready interrupt
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2025-01-22 3:44 AM
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.
Solved! Go to Solution.
- Labels:
-
Accelerometers
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2025-01-30 3:22 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2025-01-29 1:37 AM
Hi @danh221212 ,
Have a look at this official example on Github and let me know if it helps you :)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2025-01-30 3:22 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2025-01-30 3:27 AM
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 designed from scratch never works and cannot be patched up to make it work.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2025-01-30 1:17 PM
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.
