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 EXIT
Reference address:STM32 Note 9: Interrupt it to do things for me, EXIT (external I/O interrupt) application
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:STM32 Notes 8: Say hello to the PC, basic serial communication
Next article:sw's STM32 Notes 10: Work, PWM output
- Popular Resources
- Popular amplifiers
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
- 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
Guess you like
- Please help to explain how the two reed switches in the water meter transmit information.
- MSP430 MCU Tetris Game Programming
- MicroPython-Ctl, a TypeScript library for communicating with MicroPython devices
- Thank you for being my first leader
- [Analog Electronics Elective Test] + Operational Amplifier Noise
- Cadence, the new CIS schematic is overwritten by the old schematic with the same name. Can it be restored?
- In late summer and early autumn, play with EE core points, earn and spend + gift exchange spoilers
- What is the difference between SOP package and DIP package!
- Which is more effective in eliminating the back EMF of inductive loads, TVS or varistor?
- The chip cannot be removed