2021-10-14 11:40 PM
Hello,
I'm using an stm32f411ce with an lsm6ds3 IMU and I want to trigger a read from the IMU with an EXTI. I've set it all in the code below and activated the interrupt on the IMU. the interrupt is set in PR register but handler is never called.
Thanks,
Eyal
void EXTIsetup(void)
{
//PB3 ---- IMU INT1 gyro
//PB12 --- IMU INT2 accel
//PB0 ---- BAR INT
//1. Enable the SYSCFG/AFIO bit in RCC register
//2. Configure the EXTI configuration Register in the SYSCFG/AFIO
//3. Disable the EXTI Mask using Interrupt Mask Register (IMR)
//4. Configure the Rising Edge / Falling Edge Trigger
//5. Set the Interrupt Priority
//6. Enable the interrupt
RCC ->AHB1ENR |= (1 << 1); //enable the GPIOB bus clock
//set the moder values
//GPIOB ->MODER &= ~(3 << 0);
GPIOB ->MODER &= ~(3 << 6);
//GPIOB ->MODER &= ~(3 << 24);
//set pull down on all three pins
//GPIOB ->PUPDR |= (1 << 1);
GPIOB ->PUPDR |= (1 << 7);
//GPIOB ->PUPDR |= (1 << 25);
RCC ->APB2ENR |= (1 << 14); //enable SYSCNFG
//SYSCFG ->EXTICR[0] |= (1 << 0); //EXTI0 --> PB PB0
SYSCFG ->EXTICR[0] |= (1 << 12); //EXTI3 --> PB PB3
//SYSCFG ->EXTICR[3] |= (1 << 0); //EXTI12 --> PB PB12
//EXTI ->IMR |= (1 << 0); //dsb mask MR0
EXTI ->IMR |= (1 << 3); //dsb mask MR3
//EXTI ->IMR |= (1 << 12); //dsb mask MR12
//EXTI ->RTSR |= (1 << 0); //enable rising edge on line 0
EXTI ->RTSR |= (1 << 3); //enable rising edge on line 3
//EXTI ->RTSR |= (1 << 12); //enable rising edge on line 12
//EXTI ->FTSR &= ~(1 << 0); //disable falling edge on line 0
EXTI ->FTSR &= ~(1 << 3); //disable falling edge on line 3
//EXTI ->FTSR &= ~(1 << 12); //disable falling edge on line 12
//setting the priority of the interrupts
NVIC_SetPriority(EXTI3_IRQn, 1);
//NVIC_SetPriority (EXTI4_IRQn, 1);
//enable the interrupts
NVIC_EnableIRQ(EXTI3_IRQn);
//NVIC_EnableIRQ(EXTI4_IRQn);
}
Solved! Go to Solution.
2021-10-15 12:23 PM
So it has C++ linkage, not C linkage, which means the linker doesn't see it as EXTI3_IRQHandler.
To fix, surround it in extern "C" braces.
extern "C" {
void EXTI3_IRQHandler() {
...
}
}
2021-10-15 07:14 AM
Looks like you're doing the right things. Are interrupts globally enabled? Can you look in peripheral view and verify that all relevant register settings are correct? Particularly, SYSCFG, which may need a delay after setting the clock before modifying values.
2021-10-15 07:21 AM
Thanks for your response!
What do you mean by interrupts are globally enabled? all of the registers are seem to set correctly using an st-link.
2021-10-15 07:26 AM
__enable_irq();
They should be enabled by default.
2021-10-15 07:26 AM
> interrupt is set in PR register but handler is never called
How do you check that?
Check, if the handler's address is correctly inserted in the vector table. This is best to be seen in disassembly view.
Make sure you are not stuck in an ISR with higher priority.
Some interrupt-related remarks here.
JW
2021-10-15 07:42 AM
I'll check that
2021-10-15 07:45 AM
I'm using the Keil IDE pre generated startup and core files so I guess it should be correct. but also I've checked the vector table and it says that
EXTI3_IRQn = 9,
so that should be correct.
I didn't set any other interrupt and the priority is 1, from what I understood it's the lowest
2021-10-15 07:53 AM
You did not answer my question, how do you check that the handler is not executed.
> I'm using the Keil IDE pre generated startup and core files so I guess it should be correct.
Don't guess, check it.
> EXTI3_IRQn = 9,
No that's not the vector table; the vector table is in the startup code, located normally at the beginning of FLASH, unless you've changed the VTOR register.
Nonetheless, if interrupts are enabled - both EXTI3 and globally - and if respective bit in EXTI's pending register is set, then some ISR must be executed - so, in debugger, where is the program counter?
JW
2021-10-15 10:53 AM
In the int handler I have added an LED toggle and turned off the bit 3 in the PR register by writing 1 to it. this never happens and the bit 3 is active on.
the vector table is as default.
This is what I see in the NVIC window and also in the code I just have a while loop after the EXTI and IMU initialization and whenever I stop the code with the debugger it goes to the brakepointed line
2021-10-15 11:14 AM
VECTACTIVE = 0x19, which means the processor is currently within the EXTI3_IRQ interrupt. So the interrupt is firing just fine.
Likely you just don't have the function implemented in your program anywhere so it defaults to the default handler. Check that the function you want it to call matches exactly with the name in the vector table (EXTI3_IRQHandler) and that it has C linkage. The output from the linker should tell you where EXTI3_IRQHandler is pointing.