This is very different in external interrupts. STM8S automatically clears external interrupts, while STM8L requires software to clear them. The register that clears the flag bit varies depending on the setting, as explained below.
The following takes the STM8L external interrupt PB1 as an example to illustrate the operation of the external interrupt register
There are several steps to set up external interrupts:
The first step is to set the IO port as interrupt input by setting (PB_DDR = 0X00; PB_CR1 = 0X02; PB_CR2 = 0X02;)
Step 2: Set the interrupt trigger mode (00: Falling edge and low level; 01: Rising edge only; 10: Falling edge only; 11: Rising and falling edge)
Step 3: Change the interrupt vector table (in the stm8_interrupt_vector.c file)
Step 4: Write an interrupt handling function and remember to clear the interrupt in the function
Step 1: Set the IO port as interrupt input
PB_DDR = 0X00; // Input
PB_CR1 = 0X02; // 0_0010
PB_CR2 = 0X02; // 0_0010 CR1 and CR2 are combined to determine the pull-up external interrupt input
Step 2: Set the interrupt trigger mode. The PB and PD ports in STM8L are special and can have two trigger modes.
EXTI_CONF = 0x00;
These two trigger modes are set through the register EXTI_CONF
The first method is the same as port A and C. The trigger mode is set by the following two registers. Set register EXTI_CONF[0] to 0, indicating that port B[3:0] uses the first method (which I call the normal method here).
EXTI_CR1 register sets the 3, 2, 1, 0 pins of Port A, B, C and/or D external interrupts
EXTI_CR2 register sets the 7, 6, 5, 4 pins of Port A, B, C and/or D external interrupts
The second method is to set the trigger mode EXTI_CONF[0] to 1 through the EXTI_CR3 register, indicating that Port B[3:0] uses the second method (I named it the special method here)
Bits [3:2] of the EXTI_CR3 register set the trigger mode of port D.
Bits [1:0] of the EXTI_CR3 register set the trigger mode of port B.
Step 3: Change the interrupt vector table
{0x82, KEY_Interrupt}, /* irq9 */
The PB1 normal mode interrupt vector number is 9, where KEY_Interrupt can be named according to actual needs as long as it is consistent with the interrupt function name written later.
Why choose 9? Look at the picture below to know.
Step 4: Write an interrupt handling function
@far @interrupt void KEY_Interrupt(void)
{
LED1 = !LED1;
//EXTI_SR2 = 0x01; // If set to special mode, clear the interrupt flag through this register
EXTI_SR1 =0x02; // If set to normal mode, clear the interrupt flag through this register
}
There are two points to note in this step:
1. If the interrupt execution function does not want to be written in the stm8_interrupt_vector.c file, you need to add such a function in the stm8_interrupt_vector.c file
@far @interrupt void KEY_Interrupt(void);
2. EXTI_SR2 = 0x01; // If set to special mode, clear the interrupt flag through this register
EXTI_SR1 = 0x02; // If set to normal mode, clear the interrupt flag through this register
Interrupt vector level:
From the first table below, we can see that if we use normal interrupt mode, the interrupt of port B1 belongs to EXTI1 (if it is PB2, it belongs to EXTI2), and the interrupt of special mode port B belongs to EXTIB and EXTID,
After knowing this, we can combine it with the interrupt vector table in the manual to know where we should write the interrupt entry function name.
Previous article:Microcontroller learning notes external interrupt, timer, serial port interrupt
Next article:STC11F04 MCU timer simulation multi-tasking program
Recommended ReadingLatest update time:2024-11-16 22:24
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- 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
- Application Note - Optimizing Capacitance and AC Impedance Measurements Using the 4200A-SCS Parameter Analyzer
- SPI interface driver based on TI-RTOS and separate control of CS pin
- Prize live broadcast: TI low-power MCU products and Zigbee wireless solutions are now open for registration~
- FPGA_100 Days Journey_VGA Design
- CCS Basics Tutorial
- 2021 ST Industrial Summit Tour starts to reserve seats: "Motor Drive, Power Supply, Industrial Automation" + "New Products, Courses, Training"
- Happy Dragon Boat Festival, salty rice dumplings, sweet rice dumplings, which kind do you like?
- [Topmicro Intelligent Display Module Review] 5. Development Board NUCLEO-F746ZG Communication with Intelligent Display Module
- TI MCU has launched a new product! August live broadcast reveals new features video replay summary!
- Please restore the number of invitees to 8. Thank you. Thank you. I invited 8 people before, but there are already 6 people in the list.