STM32F4 interrupt summary

  • Each IO port of STM32F4 can be used as an external interrupt input;

     

  • The external interrupt line EXTI only has 0~15 corresponding to the input interrupt of the external IO port (the corresponding relationship is that GPIOX.0 is mapped to EXTI0, for example: GPIOF.0 is mapped to EXTI0), and EXTI lines 16~22 are connected to other unique events;

     

  • For each interrupt line, we can set the corresponding trigger mode: rising edge, falling edge, edge trigger, and can set the enable of each interrupt line;

     

  • General configuration steps for external interrupts:
  1. Enable the SYSCFG clock ( as long as we use external interrupts, we must turn on the SYSCFG clock , because we need to use related registers such as configuring the mapping relationship between GPIO and interrupt lines); (on APB2)
  2. Set the mapping relationship between IO port and interrupt line, SYSCFG_EXTILineConfig();
  3. Initialize online interrupts, set trigger conditions, etc., EXTI_Init();
  4. Configure interrupt grouping (NVIC), and enable interrupt, NVIC_Init();
  5. Write the interrupt service function, EXTIX_IRQHandler() (STM32 can only use 7 interrupt service functions, 0~4 are separate interrupt service functions such as EXTI3_IRQHandler(), and 5~9 share an interrupt service function, 10~15 share one such as EXTI15_10_IRQHandler(), the names of all STM32 interrupt service functions have been defined in startup_stm32f40_41xx.s )
  • Other common functions of external interrupt

        EXTI_GetITStatus(); Determine the interrupt status of the interrupt line, whether it occurs

        EXTI_ClearITPendingBit(); Clear the interrupt flag bit on the interrupt line

  • Generally, the corresponding GPIO initialization and clock enable have been written in the function that triggers the interrupt, so it is not configured in the interrupt configuration, just write the encapsulated trigger function into the interrupt configuration, if the button is used to trigger the interrupt, all buttons The relevant functions are written in key(), and then key() is introduced in the interrupt configuration

  • Commonly used interrupt service function format

 void EXTI3_IRQHandler(void)

{

if(EXTI_GetITStatus(EXTI_Line3)!=RESET) //Determine whether an interrupt on a certain line occurs

{

interrupt logic

}

EXTI_ClearITPendingBit(EXTI_Line3);//Clear the interrupt flag on Line

}

Guess you like

Origin blog.csdn.net/qq_41379312/article/details/82937934