1. Experimental Purpose
1) Understand the knowledge related to STM32 external interrupts;
2) Use STM32 external interrupt to turn on and off two LEDs;
2. Introduction to STM32 external interrupts
1) The STM32F103 series has 60 maskable interrupts and supports 19 external interrupt/event requests. Each interrupt has a status bit, and each interrupt/event has independent trigger and mask settings.
The 19 external interrupts of STM32F103 are:
Line 0~15: corresponds to the input interrupt of the external IO port.
Line 16: Connect to PVD output.
Line 17: Connected to the RTC alarm event.
Line 18: Connected to USB wakeup event.
The interrupt line corresponds to:
2) External interrupt function:
EXPORT EXTI0_IRQHandler
EXPORT EXTI2_IRQHandler
EXPORT EXTI4_IRQHandler
EXPORT EXTI15_10_IRQHandler
EXPORT EXTI9_5_IRQHandler
EXPORT EXTI1_IRQHandler
EXPORT EXTI3_IRQHandler
Interrupt lines 0-4 each correspond 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.
When writing interrupt service functions, two functions are often used. The first function is to determine whether an interrupt occurs on a certain interrupt line (whether the flag bit is set):
ITStatus EXTI_GetITStatus(uint32_t EXTI_Line);
This function is generally used at the beginning of the interrupt service function to determine whether an interrupt has occurred. Another function is to clear the interrupt flag on a certain interrupt line:
void EXTI_ClearITPendingBit(uint32_t EXTI_Line);
This function is generally used to clear the interrupt flag before the end of the interrupt service function.
3) General steps in IO port external
1) Initialize the IO port as input.
2) Enable the IO port multiplexing 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.
3. Hardware Design
LED lights, buttons.
4. Software Design
exti.c is mainly involved in the implementation of initialization and interrupt functions
//External interrupt 0 service routine
void EXTIX_Init(void)
{
EXTI_InitTypeDef EXTI_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
KEY_Init(); //Key port initialization
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO,ENABLE); //Enable multiplexing function clock
//GPIOE.2 interrupt line and interrupt initialization configuration falling edge trigger
GPIO_EXTILineConfig(GPIO_PortSourceGPIOE,GPIO_PinSource2);
EXTI_InitStructure.EXTI_Line=EXTI_Line2; //KEY2
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
EXTI_Init(&EXTI_InitStructure); //Initialize the peripheral EXTI register according to the parameters specified in EXTI_InitStruct
NVIC_InitStructure.NVIC_IRQChannel = EXTI0_IRQn; // Enable the external interrupt channel where the WK_UP button is located
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x02; //Preemption priority 2,
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x03; //Subpriority 3
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //Enable external interrupt channel
NVIC_Init(&NVIC_InitStructure); //Enable external interrupt channel
NVIC_Init(&NVIC_InitStructure); //Initialize peripheral NVIC registers according to the parameters specified in NVIC_InitStruct
}
Interrupt function implementation: The implementation of functions is also mainly implemented in the interrupt function
void EXTI0_IRQHandler(void)
{
delay_ms(10); //debounce
if(KEY3==1) //key KEY3
{
LED0=!LED0;
}
EXTI_ClearITPendingBit(EXTI_Line0); //Clear the interrupt flag on LINE0
}
V. Experimental Results
success!
Previous article:[Experiment 4] Independent watchdog experiment
Next article:【Experiment 2】Serial port experiment
- Popular Resources
- Popular amplifiers
- Learn ARM development(16)
- Learn ARM development(17)
- Learn ARM development(18)
- Embedded system debugging simulation tool
- A small question that has been bothering me recently has finally been solved~~
- Learn ARM development (1)
- Learn ARM development (2)
- Learn ARM development (4)
- Learn ARM development (6)
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
- 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
- From probes to power supplies, Tektronix is leading the way in comprehensive innovation in power electronics testing
- From probes to power supplies, Tektronix is leading the way in comprehensive innovation in power electronics testing
- Sn-doped CuO nanostructure-based ethanol gas sensor for real-time drunk driving detection in vehicles
- Design considerations for automotive battery wiring harness
- Do you know all the various motors commonly used in automotive electronics?
- What are the functions of the Internet of Vehicles? What are the uses and benefits of the Internet of Vehicles?
- Power Inverter - A critical safety system for electric vehicles
- Analysis of the information security mechanism of AUTOSAR, the automotive embedded software framework
- Summary of the use of polarity and phase of MSP430 SPI
- How Designers Achieve Tri-Band Gigabit Speeds and High Throughput in Wi-Fi
- 【Development Kit for nRF52840】+ Evaluation of four Bluetooth serial port transparent transmission
- TMS320VC5502+ISP1581 USB2.0 high-speed data acquisition solution
- CH549EVT development board test - SPI test
- Find an IC IG00151 with pictures
- Designing with MSP430 MCU and Segment LCD
- FPGA technology introduction and FPGA application fields
- What is a recording digital pressure gauge? In what fields is it used?
- Basic learning of programming