1. STM8S external interrupt wake-up
First understand the interrupt resources of STM8S
Let's look at the interrupt management of STM8S. STM8S uses software priority and hardware priority to control the response of an interrupt. The software priority is compared first, and the hardware priority is compared only when the software priority is consistent. Since the hardware priority is unique, it ensures that only one interrupt will be processed at a certain time.
To use external interrupts, simply configure the EXTI_CR1 register and set the software priority of the main program to 0. By default, the software priority of the main program is set to 3 since reset, which is the highest software priority. Only TRAP, TLI, and RESET interrupts can interrupt, and the rest of the interrupts will not be responded to.
In order to prevent the interruption process from being interrupted by other high-priority interrupts, the current priority can be set to the highest level 3.
code show as below:
main.c code
//EXTI_CR1|=EXTI_CR1_PBIS_R; //PB5TRINT high level trigger
EXTI_CR1|=EXTI_CR1_PCIS_R; //PC3 rising edge trigger
//#defineEXTI_CR1_PCIS_R(1《《4)
RIM; //Open global interrupt, this sentence is required, otherwise only non-maskable interrupts will be responded
//#defineHALT_asm(“halt”)
//#defineRIM_asm(“rim”)
//#defineSIM_asm(“sim”)
GPIO_Init (GPIOC, TRINT, GPIO_MODE_IN_PU_IT); // Enable the corresponding IO port interrupt
stm8s_it.c code
//Transmit and receive interrupt (PC3) BJ8F101
@far@interruptvoidEXTI_PORTC_IRQHandler(void)
{
//Used as a receive interrupt, please note that PSB_D and TRRDY_U will generate an interrupt and TRINT will be pulled high
if(cur_mode==RX_MODE)
{
//To exclude the first time, you can check whether PSB is high, which means it is ActiveMode
if(PB_ODR&PSB)
{
ss=1;
}
}else
{
}
return;
}
In fact, the rim command only reduces the software priority of the main program to 0 so that it can be interrupted. Naturally, the sim command is suitable for raising the software priority to level 3.
Also, please note that if there are several different interrupts on a port (interrupts occur on PC3, PC4, and PC5), you can only determine which IO port is interrupted based on some other flags. In fact, this chip does not have an interrupt flag.
Another problem is that the system cannot jump out after entering the interrupt. It is likely that the instruction execution order is incorrect. For example, the rim instruction is executed first, and then the GPIO port interrupt is enabled. The corresponding IO port is set to the rising edge trigger. It is found that the system cannot jump out after entering the interrupt. The reason is that the IO port may be in an uncertain state after reset, and it will be responded immediately after executing rim. By default, both the rising and falling edges of the IO port will trigger the interrupt.
External interrupts can wake up the system, such as:
That is to say, after the halt instruction is executed in the main function, the MCU enters the halt mode (without enabling AWU), and the external interrupt can wake up the MCU from the halt mode. You can use the emulator to set breakpoints for verification, or you can use the LED light.
2. AWU automatic wakeup
In addition to the wait mode and stop mode, STM8S also provides an active stop mode. To use the active stop mode, you only need to enable AWU.
#ifdefENABLE_AWU
voidInit_AWU(void)
{
CLK_PCKENR2=CLK_PCKENR2_AWU; //Enable AWU clock
//#defineAWU_AWUTB_1S0x0C/*500ms~1s*/
//#defineAWU_AWUTB_2S0x0D/*1s~2s*/
AWU_TBR=AWU_AWUTB_1S;//AWU_AWUTB_2S;//1~2s
AWU_APR=0x3E; //Frequency division
AWU_ CSR |=0x10; //AWU enable
#ifdefPOWER_LEVEL_1 //Power consumption 1, the most power-saving
CLK_ICKR|=CLK_ICKR_REGAH; //In active shutdown mode (AWU enabled), turn off the voltage regulator to save power
FLASH_CR1|=FLASH_CR1_AHALT; // Flash is powered off in active halt mode. By default, it is powered off only in halt mode, but the wake-up time is increased to microseconds
#endif/*ENABLEPOWER_LEVEL_1*/
}
#endif/*ENDENABLE_AWU*/
Then after the halt instruction is executed in the main function, the MCU will continue to run until the AWU wakes up. In addition, the AWU timed wake-up of STM8S provides a maximum delay of about 30 seconds.
3. Window Watchdog
STM8S provides two types of watchdogs. I personally feel that the window watchdog can solve the contradiction between the stop mode and the use of the watchdog, so I am only interested in the window watchdog.
code show as below:
#ifdefENABLE_WWDG
voidInit_WWDG(void) //Initialize window watchdog
{
//The window watchdog resets when the count value drops to 0x3F, and the watchdog cannot be fed when it is greater than the window value, otherwise it will reset
WWDG_WR=0x60; //Watchdog window value, the window value must be above 0x3F, but must be less than the count value, otherwise the watchdog cannot be fed
WWDG_CR=0x7F; //watchdog count value
WWDG_CR|=0x80; //Enable window watchdog
//4Mhz main frequency, the maximum extension time of the count value 0x7F is (64*(12288/4000000)) = 196ms
}
voidFree_WWDG(void)
{
if((WWDG_CR&0x7F)
WWDG_CR|=0x7F; //Re-feed the dog
}
#endif/*ENDENABLE_WWDG*/
The timer cannot be used to feed the watchdog regularly. After the MCU hangs up, the timer circuit may still be working, so the watchdog loses its meaning.
The independent watchdog is not affected by the MCU stop mode or other modes. Its clock is independent, so entering the stop mode will cause a system reset.
Summarize:
1. When using interrupts, you need to pay attention to the priority setting and the corresponding IO port enable trigger conditions.
2. The use of AWU is relatively simple, you just need to make sure the clock is turned on.
3. Pay attention to feeding the window watchdog and setting the delay. The specific delay time can be calculated using step = 12288 / fclk_wwdg_ck.
Previous article:Development Solution for STM8AF5286 Automotive 8-bit Microcontroller
Next article:Serial printf output based on STM8L15x microcontroller
Recommended ReadingLatest update time:2024-11-16 21:32
- Popular Resources
- Popular amplifiers
- Wireless Sensor Network Technology and Applications (Edited by Mou Si, Yin Hong, and Su Xing)
- Modern Electronic Technology Training Course (Edited by Yao Youfeng)
- Modern arc welding power supply and its control
- Small AC Servo Motor Control Circuit Design (by Masaru Ishijima; translated by Xue Liang and Zhu Jianjun, by Masaru Ishijima, Xue Liang, and Zhu Jianjun)
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
- After reading this article, do you have the urge to make some modifications? Let's take a look at the design of an outdoor camera with a temperature switch.
- Have fun! Teach you how to make a different kind of "face-slapping" tool!
- EEWORLD University Hall--Follow Grant Imahara to Japan and explore the Nagasaki Robot Hotel
- There is a small signal DC gain function TF in PsPice. Does anyone have any information about this?
- Knowledge not found in 100 books: How to determine the inductance of wide range buck and boost
- High-precision, smallest-size MEMS three-axis accelerometer
- I need a driver for the segment code LCD, please help, thank you!
- TFT LCD screen power supply problem
- IAR EWARM link warning: How to resolve Warning [Lt009] Inconsistent wchar_t size
- Ultrasonic Measurement Using the MEMS Microphone MP23ABS1