7 interrupt channels are used in NVRC
7 interrupt service functions EXPORT EXTI9_5_IRQHandler
22 interrupt lines
The interrupt source is any GPIO you want to connect, use that to connect SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOA, EXTI_PinSource0);
Configure NVRC—Configure GPIO (turn on SYSCFG clock)—Connect interrupt source to GPIO—Configure interrupt EXTI—Write interrupt service function
details as follows
Each IO of STM32F4 can be used as an interrupt input port for external interrupts, which is also the strength of STM32F4. The interrupt controller of STM32F407 supports 22 external interrupt/event requests. Each interrupt has a status bit, and each interrupt/event has independent trigger and mask settings. The 22 external interrupts of STM32F407 are:
EXTI lines 0~15: correspond to input interrupts of external IO ports.
EXTI line 16: Connect to PVD output.
EXTI line 17: connected to the RTC alarm event.
EXTI line 18: connected to USB OTG FS wake-up event.
EXTI line 19: Connected to Ethernet wake-up event.
EXTI line 20: connected to USB OTG HS (configured in FS) wake-up event.
EXTI line 21: Connected to RTC intrusion and timestamp events.
EXTI line 22: connected to RTC wake-up event.
Mapping diagram of GPIO and interrupt lines:
Steps for library function to configure external interrupts:
1) Enable the IO port clock and initialize the IO port as input
GPIO_InitTypeDef GPIO_InitStructure;
RCC_AHB1PeriphClockCmd(KEY1_INT_GPIO_CLK|KEY2_INT_GPIO_CLK ,ENABLE);
GPIO_InitStructure.GPIO_Pin = KEY1_INT_GPIO_PIN;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_Init(KEY1_INT_GPIO_PORT, &GPIO_InitStructure);
2) Turn on the SYSCFG clock and set the mapping relationship between the IO port and the interrupt line.
/*SYSCFG clock must be enabled when using GPIO external interrupt*/
RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);
Configure the mapping relationship between GPIO and interrupt lines (connect interrupt sources to GPIO pins)
SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOA, EXTI_PinSource0);
Mapping interrupt line 0 to GPIOA, it is obvious that GPIOA.0 is connected to the EXTI0 interrupt line.
3) Initialize online interrupts, set trigger conditions, etc.
EXTI_InitTypeDef EXTI_InitStructure;
EXTI_InitStructure.EXTI_Line=EXTI_Line4; (电影手机源)(EXTI_Line0~EXTI_Line15)
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt; (interrupt mode) (divided into interrupt and event)
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling; (Falling edge trigger) (Rising edge triggers Rising, any level triggers Rising_Fallingr)
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
EXTI_Init(&EXTI_InitStructure); //Initialize the peripheral EXTI register
The above example sets the interrupt on interrupt line 4 to be falling edge triggered.
4) Configure the interrupt group (NVIC) and enable interrupts.
Set the interrupt priority of interrupt line 2. In the WildFire routine, set NVRC to a function static void NVIC_Configuration(void) called in void EXTI_Key_Config(void).
NVIC_InitTypeDef NVIC_InitStructure;
NVIC_InitStructure.NVIC_IRQChannel = EXTI2_IRQn; // Enable the external interrupt channel of the key. Interrupt lines 0-4 each correspond to one channel, interrupt lines 5-9 share EXTI9_5_IRQ, and interrupt lines 10-15 share EXTI15_10_IRQ
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x02; //Preemption priority 2,
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x02; //Response priority 2
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //Enable external interrupt channel
NVIC_Init(&NVIC_InitStructure); //Interrupt priority group initialization
5) Write the interrupt service function.
The names of the interrupt service functions are pre-defined in MDK. It should be noted here that the STM32F4 IO port has only 7 external interrupt functions, namely:
EXPORT EXTI0_IRQHandler
EXPORT EXTI1_IRQHandler
EXPORT EXTI2_IRQHandler
EXPORT EXTI3_IRQHandler
EXPORT EXTI4_IRQHandler
EXPORT EXTI9_5_IRQHandler
EXPORT EXTI15_10_IRQHandler
Each interrupt line 0-4 corresponds to an interrupt function, interrupt lines 5-9 share the interrupt function EXTI9_5_IRQHandler, and interrupt lines 10-15 share the interrupt function EXTI15_10_IRQHandler.
The commonly used interrupt service function format is:
void EXTI3_IRQHandler(void)
{
if(EXTI_GetITStatus(EXTI_Line3)!=RESET)//Judge whether an interruption on a line occurs
{ ...interrupt logic...
EXTI_ClearITPendingBit(EXTI_Line3); //Clear the interrupt flag on LINE
}
}
Summarize the general steps of using IO port external interrupts:
1) Enable the IO port clock and initialize the IO port as input.
2) Enable the SYSCFG clock and set the mapping relationship between the IO port and the interrupt line.
3) Initialize online interrupts, set trigger conditions, etc.
4) Configure the interrupt group (NVIC) and enable interrupts.
5) Write the interrupt service function.
The simple routine is as follows
#include "stm32f4xx.h"
#include "stm32f4xx_exti.h"
#include "stm32f4xx_rcc.h"
#include "stm32f4xx_gpio.h"
#include "stm32f4xx_syscfg.h"
void main(void)
{
config(); // Initialization
while(1);
}
void config(void)
{
//Interrupt IO port initialization
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE); //
RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
//GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_Init(GPIOD, &GPIO_InitStructure);
//Interrupt initialization
EXTI_InitTypeDef EXTI_InitStructure;
SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOD, EXTI_PinSource13);
EXTI_ClearITPendingBit(EXTI_Line13);
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising_Falling;
EXTI_InitStructure.EXTI_Line = EXTI_Line13;
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
EXTI_Init(&EXTI_InitStructure);
//Interrupt configuration initialization
/* Configures the nested vectored interrupt controller. */
NVIC_InitTypeDef NVIC_InitStructure;
/* Enable the USARTx Interrupt */
NVIC_InitStructure.NVIC_IRQChannel = EXTI15_10_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
//Interrupt function
void EXTI15_10_IRQHandler(void)
{
if ( EXTI_GetITStatus(EXTI_Line13) != RESET )
{
EXTI_ClearITPendingBit(EXTI_Line13);//清电影
}
}
Previous article:STM32F4XX interrupt number definition
Next article:A collection of problems encountered during the use of STM
- Popular Resources
- Popular amplifiers
- Naxin Micro and Xinxian jointly launched the NS800RT series of real-time control MCUs
- How to learn embedded systems based on ARM platform
- Summary of jffs2_scan_eraseblock issues
- Application of SPCOMM Control in Serial Communication of Delphi7.0
- Using TComm component to realize serial communication in Delphi environment
- Bar chart code for embedded development practices
- Embedded Development Learning (10)
- Embedded Development Learning (8)
- Embedded Development Learning (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Intel promotes AI with multi-dimensional efforts in technology, application, and ecology
- ChinaJoy Qualcomm Snapdragon Theme Pavilion takes you to experience the new changes in digital entertainment in the 5G era
- Infineon's latest generation IGBT technology platform enables precise control of speed and position
- Two test methods for LED lighting life
- Don't Let Lightning Induced Surges Scare You
- Application of brushless motor controller ML4425/4426
- Easy identification of LED power supply quality
- World's first integrated photovoltaic solar system completed in Israel
- Sliding window mean filter for avr microcontroller AD conversion
- What does call mean in the detailed explanation of ABB robot programming instructions?
- STMicroelectronics discloses its 2027-2028 financial model and path to achieve its 2030 goals
- 2024 China Automotive Charging and Battery Swapping Ecosystem Conference held in Taiyuan
- State-owned enterprises team up to invest in solid-state battery giant
- The evolution of electronic and electrical architecture is accelerating
- The first! National Automotive Chip Quality Inspection Center established
- BYD releases self-developed automotive chip using 4nm process, with a running score of up to 1.15 million
- GEODNET launches GEO-PULSE, a car GPS navigation device
- Should Chinese car companies develop their own high-computing chips?
- Infineon and Siemens combine embedded automotive software platform with microcontrollers to provide the necessary functions for next-generation SDVs
- Continental launches invisible biometric sensor display to monitor passengers' vital signs
- Swedish car dealer Holmgrens Bil achieves great success with RFID
- 【Small Home Weather Station】Work Submission
- Simulation failed with no results
- Problems with rectangular wave generating circuit
- Principle of Dialogue Communication
- Detailed summary! Help you pass the customs with the basic knowledge and selection of power supply topology solutions
- Voltage jump problem
- Commonly used semiconductor devices
- 【Silicon Labs Development Kit Review】1-Introduction to Main Components
- MCU Basics: Detailed explanation of button single click, double click, and long press