Study Materials
Li Xiang stm32 video tutorial 49 episodes http://pan.baidu.com/s/1kTyt03P STM32 interrupts (upper, middle and lower) external interrupts (registers, library functions)
STM32 function description (Chinese).pdf http://download.csdn.net/detail/leytton/7630851
Interrupt management function.pdf http://wenku.baidu.com/view/b90e5b82360cba1aa811dad3.html
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; //取读是那个引脚的中断
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.
Previous article:STM32 MCU (3) Serial port interrupt communication
Next article:STM32 MCU (1) Summary of learning materials + reference manual + LED light
- 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
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- Compile QT5.6.0
- How to consider and design ESD of RF modules?
- There seems to be something wrong with microPython's regular expression library ure. The matching result of the "*" wildcard is incorrect.
- Regarding IIC communication PCB routing, do I need differential routing? I am currently routing in a dispersed manner? Maximum frequency of 400K
- Decoupling Basics
- Communicate with device over wifi (Android)
- 【RPi Pico】Install MicroPython
- Can anyone recommend the DATASHEE for ATMLU308? I have searched on Baidu but couldn't find it. Thank you.
- MSP430 serial port receiving program (using interruption)
- Starting tomorrow: Follow the experts and challenge yourself to learn FreeRTOS in 21 days ~ win gifts + cash