STM8 IO external interrupt setting problem (using library function)
STM8, fall into the pit:
In the program, first enable the general interrupt, enableInterrupts(); // Enable the general interrupt
In the subsequent program, set the IO port external interrupt to open and set the trigger level. The code is as follows: (The pit is here, pay attention!!!)
GPIO_Init(PORT_BLE_STA, PIN_BLE_STA, GPIO_Mode_In_PU_IT); //Pull up, open interrupt
EXTI_SetPinSensitivity(EXTI_PIN_BLE_STA, EXTI_Trigger_Falling); //Falling edge interrupt
Then the tragedy happened. Once a falling edge occurred at the IO port, the program died immediately and the watchdog was reset.
After locating, it was found that the interrupt was triggered continuously. But why was the interrupt triggered continuously? Wasn't it set to the falling edge interrupt?
reason:
Because the general interrupt has been turned on when setting the trigger level, the setting is invalid!!! This means that the falling edge trigger is not set at all!!! Then the default value is used, which is low level trigger. When the IO port is pulled low, the interrupt will be triggered continuously.
Solution: Be sure to set the level trigger when the general interrupt is turned off.
If you don't need interrupts at the beginning, you can disable IO port interrupts, but you need to set the trigger level first. When you need interrupts later, just turn on the interrupts, and you don't need to set the trigger level again.
example:
1. No interrupt is needed at the beginning, IO interrupt is disabled, but the trigger level must be set
GPIO_Init(PORT_BLE_STA, PIN_BLE_STA, GPIO_Mode_In_PU_No_IT);
EXTI_SetPinSensitivity(EXTI_PIN_BLE_STA, EXTI_Trigger_Falling); //When setting the trigger mode, be sure to turn off the total interrupt, otherwise it will fail
2. In the subsequent programs, you need to enable interrupts. Just turn on the IO interrupts. There is no need to set the trigger level here.
GPIO_Init(PORT_BLE_STA, PIN_BLE_STA, GPIO_Mode_In_PU_IT);
Previous article:stm8 GPIO button input
Next article:STM8 STM8S208MB registers
Recommended ReadingLatest update time:2024-11-16 13:27
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
- Gizwits ESP8266 controls the lifting of rolling shutter doors
- How to connect unused op amps in the same package?
- Help analyze this small wind power generation circuit
- Lessons learned from transplanting LwIP on C6414
- Lichee RV 86 PANEL Review (7) - Deploy a personal blog on Lichee
- [NXP Rapid IoT Review] Bluetooth Control RGB
- [National Technology N32G457 Review] Comparison between development board N32G457 and AB32VG1
- I2C pull-up levels
- It’s the middle of the year, how are your 2021 plans/goals going?
- [TI recommended course] #Optimizing system-level design through industrial Ethernet#