a) Purpose: Similar to serial port input, IO input without interrupts is also inefficient, and button events can be inserted through EXTI. This section is related to EXTI interrupts.
b) Initialization function definition:
void EXTI_Configuration(void); //Define IO interrupt initialization function
c) Initialization function call:
EXTI_Configuration(); //IO interrupt initialization function call Simple application:
d) Initialization function:
void EXTI_Configuration(void)
{
EXTI_InitTypeDef EXTI_InitStructure; //EXTI initialization structure definition
EXTI_ClearITPendingBit(EXTI_LINE_KEY_BUTTON); //Clear interrupt flag
GPIO_EXTILineConfig(GPIO_PortSourceGPIOA, GPIO_PinSource3); //Pin selection
GPIO_EXTILineConfig(GPIO_PortSourceGPIOA, GPIO_PinSource4);
GPIO_EXTILineConfig(GPIO_PortSourceGPIOA, GPIO_PinSource5);
GPIO_EXTILineConfig(GPIO_PortSourceGPIOA, GPIO_PinSource6);
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt; //Event selection
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling; //Trigger mode
EXTI_InitStructure.EXTI_Line = EXTI_Line3 | EXTI_Line4; //Line selection
EXTI_InitStructure.EXTI_LineCmd = ENABLE; //Start interrupt
EXTI_Init(&EXTI_InitStructure); //Initialization
}
e) Turn on the I/O clock in the RCC initialization function
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA , ENABLE);
Define the input I/O pins in the GPIO initialization function.
//IO input, GPIOA's 4-pin input
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; //Pull-up input
GPIO_Init(GPIOA, &GPIO_InitStructure); //Initialization
f) Add the following code in the NVIC initialization function to enable related interrupts:
NVIC_InitStructure.NVIC_IRQChannel = EXTI9_5_IRQChannel; //Channel
NVIC_InitStructure.NVIC_IRQChannelPreemptionPrio rity = 0;//Priority level
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; //Response level
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //Start
NVIC_Init(&NVIC_InitStructure); //Initialization
g) Find the void USART1_IRQHandler function in the stm32f10x_it.c file and add the execution code to it. Generally, there are at least three steps: first use the if statement to determine which interrupt occurred, then clear the interrupt flag, and finally assign a value to the string, or do other things.
if(EXTI_GetITStatus(EXTI_Line3) != RESET) //Judge the source of the interrupt
{ EXTI_ClearITPendingBit(EXTI_Line3); //Clear the interrupt flag
USART_SendData(USART1, 0x41); //Send the character "a"
GPIO_WriteBit(GPIOB, GPIO_Pin_2, (BitAction)(1-GPIO_ReadOutputDataBit(GPIOB, GPIO_Pin_2))); //LED alternates between light and dark
h
) Interrupt precautions:
The interrupt bit must be cleared after the interrupt occurs, otherwise the interrupt will occur in an endless loop. Then the interrupt type needs to be determined before executing the code.
To use the EXTI I/O interrupt, three things need to be done after completing the RCC and GPIO hardware settings: initialize EXTI, enable NVIC interrupts, and write interrupt execution code.
Keywords:STM32
Reference address:Application of STM32 external (IO) interrupt EXTI
b)
void
c)
EXTI_Configuration(); //IO interrupt initialization function call Simple application:
d)
void
{
EXTI_ClearITPendingBit(EXTI_LINE_KEY_BUTTON); //Clear interrupt flag
}
e)
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA
Define the input I/O pins in the GPIO initialization function.
//IO input, GPIOA's 4-pin input
f)
g)
h
)
The interrupt bit must be cleared after the interrupt occurs, otherwise the interrupt will occur in an endless loop. Then the interrupt type needs to be determined before executing the code.
To use the EXTI I/O interrupt, three things need to be done after completing the RCC and GPIO hardware settings: initialize EXTI, enable NVIC interrupts, and write interrupt execution code.
Previous article:About dynamically changing the STM32 PWM duty cycle
Next article:STM32 PWM output
- Popular Resources
- Popular amplifiers
Recommended Content
Latest Microcontroller Articles
He Limin Column
Microcontroller and Embedded Systems Bible
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
MoreSelected Circuit Diagrams
MorePopular Articles
- 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
MoreDaily News
- Keysight Technologies Helps Samsung Electronics Successfully Validate FiRa® 2.0 Safe Distance Measurement Test Case
- Innovation is not limited to Meizhi, Welling will appear at the 2024 China Home Appliance Technology Conference
- Innovation is not limited to Meizhi, Welling will appear at the 2024 China Home Appliance Technology Conference
- 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)
Guess you like
- Xunwei iTOP-i.MX6ULL development board-network communication-socket UDP
- Power supply "core" trend, low power consumption
- Question about programmable frequency divider based on shift register
- AD20 Select PCB Components cannot be used?
- Newly purchased MicroPython development board
- STM32F 7508DK I2C BH1570 driver development and I2C usage
- C2000 MCU, Vienna Rectifier-Based Three-Phase Power Factor Correction Reference Design
- The 5G era has arrived. This is a rare opportunity. What ideas do you have to share?
- General method of displaying pictures and texts on TFT color screen
- Ultra-low standby power consumption DC-DC controller chip