STM32 Guide: Interrupts

Prerequisites

This is tutorial is not intended to be a guide for learning C language or about the STM32 platform. It’s primary target is to provide developers a concise guide about integrating peripheral modules and features into active applications.

If you are a beginner, I would recommend you look into an STM32 Project Setup guide like this one.

https://medium.com/vicara-hardware-university/smt32-project-setup-with-cubeide-947974baf713

Interrupts

Interrupts in microcontroller are inputs for external sources or internal processes, which when triggered can stop the currently executing task and run a different sequence of tasks.

The applications range from making real-time response systems to reducing power consumption and it is used in a wide variety of embedded systems.

Interrupts are essentially signals and can arrive at the GPIO pin in one of the following 3 methods

  • Rising Edge
  • Falling Edge
  • Toggle (Rising and Falling)

EXTI in STM32

STM32F4 has 7 interrupts

Image for post

Setting Up Interrupt Handler



void EXTI0_IRQHandler(void) {
  /* Make sure that interrupt flag is set */
  if (EXTI_GetITStatus(EXTI_Line0) != RESET) {
     /* Do your stuff when EXTI0 is changed */      /* Clear interrupt flag */
     EXTI_ClearITPendingBit(EXTI_Line0)}   }
  /* Handle IRQ10-15 interrupt */
  void EXTI15_10_IRQHandler(void) {
     /* Make sure that interrupt flag is set */
     if (EXTI_GetITStatus(EXTI_Line12) != RESET) {
     /* Do your stuff when EXTI is changed */
     
     /* Clear interrupt flag */
     EXTI_ClearITPendingBit(EXTI_Line12);
  }
}

Conclusion

In this tutorial, we discussed the methods for using External Interrupts (EXTI)

Sources