I am trying to do very simple interrupt code in STM32F401RE where I press the button and LED2 should turn on based on external interrupt triggered by the button.
I am using the user button(blue button) in nucleo board F401 which corresponds to PC13 according to the board datasheet pinout. I tried different options but LED2 is still off, here is the code i am using:
void Interrupt_config(void)
{
RCC->APB2ENR |=(1<<14); // for clock config
SYSCFG->EXTICR[4] |=(1<<5);
EXTI->IMR |=(1<<13); //disable the mask
EXTI->FTSR |=(1<<13);
EXTI->PR =(1<<13); //clear pending interrrupt
NVIC_SetPriority(EXTI4_IRQn,0);
NVIC_EnableIRQ(EXTI4_IRQn);
}
int main(void)
{
sysconfig();
Interrupt_config();
while(1)
{
if(flag)
{
GPIOA->ODR |= (1<<5);
}
}
}
I used polling method (without interrupt) and the LED2 turns on fine when the button is pressed using only LED_initialize(); Button_init();
CodePudding user response:
Haven't checked your IRQ setup code, but the handler you need for PC13 is EXTI15_10_IRQHandler
.
Edit:
Another issue: EXTICR is 4 words long. This is incorrect: SYSCFG->EXTICR[4] |=(1<<5);
.