cancel
Showing results for 
Search instead for 
Did you mean: 

stm32f4 external interrupt problem

EPora.1
Associate II

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

17 REPLIES 17

that is the handler implementation.

0693W00000FChi0QAD.pngdoes it seem fine?

C++?

JW

not sure what you mean but I am using C++

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() {
  ...
}
 
}

If you feel a post has answered your question, please click "Accept as Solution".

OK thanks.

the whole main file is cpp. does it still matter?

It works now! thank you very much

I'm not sure what you're asking, does what still matter?
Generally, that's the main gotcha. If you have other IRQ handlers in there, or functions that are called from C source files, those also need to have extern "C".
If you feel a post has answered your question, please click "Accept as Solution".

ok now I get it thanks!