'STM32F4 interrupt

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);  
    SYSCFG->EXTICR[4] |=(1<<5);    
    EXTI->IMR |=(1<<13);  
    EXTI->FTSR |=(1<<13); 
    EXTI->PR =(1<<13);  
    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();



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source