1: EXTI (external interrupt) description
===========================================dividing line==========================================
The external interrupt/event controller consists of 19 edge detectors that generate event/interrupt requests. Each input line can be independently configured
Input type (pulse or pending) and corresponding trigger event (rising edge or falling edge or both edges). Each input line can be independently
The Pending Register holds the interrupt request for the Status Line.
===========================================dividing line==========================================
The 19 interrupts are as follows:
17 - EXTI line 16 connected to PVD output
18 - EXTI line 17 connected to the RTC alarm event
19 - EXTI line 18 connected to USB wake-up event
Note: From the above figure, we can see that the pins connected to EXTI0 are PA0, PB0, PC0, PD0, PE0, PF0, PG0, and other external interrupts EXTI1——
EXTI15 is similar. So when using, try to configure the required external interrupts on different EXTIx.
For example, if three external interrupts are needed, we can configure them to PA0, PB4, and PG3. At this time, each interrupt has its own interrupt handler.
If PA0, PB0, and PC1 are configured, PA0 and PB0 will share an interrupt program segment.
It can be designed like this.
===========================================dividing line==========================================
Configuration usage:
Initialize the corresponding GPIO pins
Configure external interrupt sources and connect interrupt sources to GPIO
Write the interrupt handler for the corresponding interrupt source
===========================================dividing line==========================================
code
Initialize the corresponding GPIO pins
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOE, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0|GPIO_Pin_1;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOE, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8|GPIO_Pin_9;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOB, &GPIO_InitStructure);
Note: GPIO multiplexing function must be turned on, as shown in the red part
Configure external interrupt sources and connect interrupt sources to GPIO
GPIO_EXTILineConfig(GPIO_PortSourceGPIOE, GPIO_PinSource0);
GPIO_EXTILineConfig(GPIO_PortSourceGPIOE, GPIO_PinSource1);
GPIO_EXTILineConfig(GPIO_PortSourceGPIOB, GPIO_PinSource8);
GPIO_EXTILineConfig(GPIO_PortSourceGPIOB, GPIO_PinSource9);
EXTI_InitStructure.EXTI_Line = EXTI_Line0|EXTI_Line1|EXTI_Line8|EXTI_Line9;
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
EXTI_Init(&EXTI_InitStructure);
Write the interrupt handler for the corresponding interrupt source
void EXTI0_IRQHandler(void)
{
if(Sys_Status > MIN_STATUS)
{
Sys_Status --;
}
EXTI_ClearITPendingBit(EXTI_Line0);
}
void EXTI1_IRQHandler(void)
{
PEout(2) = ~PEout(2);
EXTI_ClearITPendingBit(EXTI_Line1);
}
#define Exti_From_Pin8 0x00000100
#define Exti_From_Pin9 0x00000200
void EXTI9_5_IRQHandler(void)
{
u32 Temp = 0x00;
PEout(2) = ~PEout(2);
Temp = EXTI->PR; //Read the interrupt pin
switch(Temp)
{
case Exti_From_Pin8:
EXTI_ClearITPendingBit(EXTI_Line8);
break;
case Exti_From_Pin9:
if(Sys_Status < MAX_STATUS)
{
Sys_Status ++;
}
EXTI_ClearITPendingBit(EXTI_Line9);
break;
default:break;
}
}
===========================================dividing line==========================================
Interrupt handler description: Since external interrupts EXTI5-EXTI9 share an interrupt (EXTI10-EXTI15 are similar),
Differentiating different interrupt sources requires corresponding judgment. As shown in EXTI9_5_IRQHandler above, the judgment is made by reading the EXTI->PR register.
The source of the interrupt.
Hardware: Using PA11 pin
It should be clear that the PxN pins share the external interrupt line EXTIN and the external interrupt vector EXTIN_IRQn and the interrupt service routine entry EXTIN_IRQHandler, but it should be noted that [9...5] share EXTI9_5_IRQn and EXTI9_5_IRQHandler, and [15...10] share EXTI15_10_IRQn and EXTI15_10_IRQHandler
2: Use of Stm32 external interrupt EXTI
Basic process:
1. Set the clock
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_AFIO, ENABLE);
Note that you need to turn on the AFIO clock
2. Configure GPIO
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);
Use floating input method
3. Connect the GPIO pin to the external interrupt line
GPIO_EXTILineConfig(GPIO_PortSourceGPIOA, GPIO_PinSource11);
Quite important
4. Configure EXTI
EXTI_InitStructure.EXTI_Line = EXTI_Line11;
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
EXTI_Init(&EXTI_InitStructure);
Including triggering methods, etc.
6. Configure NVIC
NVIC_InitTypeDef NVIC_InitStructure;
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0);
NVIC_InitStructure.NVIC_IRQChannel = EXTI15_10_IRQn; //PPP external interrupt line
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
7. Write interrupt service routine
void EXTI15_10_IRQHandler(void)
{
if (EXTI_GetITStatus(EXTI_Line11) != RESET)
{
EXTI_ClearITPendingBit(EXTI_Line11);//Clear flag
...
}
}
Previous article:Relationship between EXTI and NVIC in STM32
Next article:Reading and writing data on the I2C bus in STM32.
- Popular Resources
- Popular amplifiers
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- Huawei's Strategic Department Director Gai Gang: The cumulative installed base of open source Euler operating system exceeds 10 million sets
- Download from the Internet--ARM Getting Started Notes
- Learn ARM development(22)
- Learn ARM development(21)
- Learn ARM development(20)
- Learn ARM development(19)
- Learn ARM development(14)
- Learn ARM development(15)
- Analysis of the application of several common contact parts in high-voltage connectors of new energy vehicles
- Wiring harness durability test and contact voltage drop test method
- Implementation of Interface between DSP and Slow Devices
- The output voltage of the transimpedance amplifier drifts upward
- Is there a suitable chip/solution for converting 24V to positive and negative 15V?
- CircuitPython Duck Computer cyberDuCK
- Design of high-speed and equal-precision frequency measurement system based on FPGA.rar
- [SC8905 EVM Evaluation] + MCU I2C Communication Experiment
- Hikvision responds to US ban: All components used have alternatives
- How to implement BLUENRG1/2 Bluetooth MESH and BLE REMOTE at the same time?
- Using ESP's rtc memory in mpy
- Comprehensive electrical skills from entry level to mastery