External Interrupts
EXTI Lines
0..15 | EXTI lines 0..15 correspond to the GPIO pins 0..15 |
16 | PVD interrupt |
17 | RTC Alarm A & B interrupt |
18 | USB OTG FS interrupt |
19 | Ethernet wakeup |
20 | USB OTG HS interrupt |
21 | Tamper & time stamp interrupt |
22 | RTC wakeup interrupt |
Configuration Register
SYSCFG_EXTICR1 - External interrupt configuration register 1
SYSCFG_EXTICR2 - External interrupt configuration register 2
SYSCFG_EXTICR3 - External interrupt configuration register 3
SYSCFG_EXTICR4 - External interrupt configuration register 4
Select the source input for EXTI
EXTIx | 0000 | GPIOA pin x (reset state) |
0001 | GPIOB pin x | |
… | ||
1010 | GPIOK pin x |
EXTI_RTSR / EXTI_FTSR - Rising / falling trigger selection register
EXTI_IMR - Interrupt mask register
MRx | 0 | Interrupt request for EXTI line x masked (reset state) |
1 | Interrupt request for EXTI line x unmasked |
EXTI_PR - Pending register
PRx* | 0 | No trigger request occurred |
1 | Selected trigger request occured |
* This bit is set when the selected edge event arrives on the external interrupt line x. This bis is cleared by programming it to '1'
Programming Example
Setup Peripheral (e.g. GPIOA Pin 5)
#include "reg_stm32f4xx.h" RCC->AHB1ENR |= (0x1 << 0u); /* Enable GPIOA clock */ /* Configure GPIO pin A.5 as input. */ GPIOA->MODER &= ~(0x3 << 10u); /* Clear existing mode bits 10 and 11. */ GPIOA->PUPDR &= ~(0x3 << 10u); /* Clear existing pull-up/-down bits 10 and 11. */ GPIOA->PUPDR |= (0x1 << 10u); /* Set pin 5 to pull-up mode. */
Setup SYSCFG
To choose which GPIO peripheral should trigger EXTI line 5 you have to configure the SYSCFG register.
#include "reg_stm32f4xx.h" SYSCFG->EXTICR2 |= (0u << 4u); /* Set EXTI5 to GPIOA. */
Setup EXTI
#include "reg_stm32f4xx.h" EXTI->RTSR |= (0x1 << 5u); /* Trigger on rising edge. */ EXTI->IMR |= (0x1 << 5u); /* Unmask interrupt line. */
Setup NVIC
#include "reg_stm32f4xx.h" NVIC->ISER0 |= (0x1 << 23u); /* Enable EXTI5 interrupt. */