STM8S interrupt wake-up, timer wake-up, window watchdog

Publisher:Yuexin888Latest update time:2017-02-17 Source: eefocusKeywords:STM8S Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

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:


  1. main.c code  

  2.     //EXTI_CR1|=EXTI_CR1_PBIS_R; //PB5 TRINT high level trigger  

  3.     EXTI_CR1|=EXTI_CR1_PCIS_R; //PC3 rising edge trigger  

  4. //#define EXTI_CR1_PCIS_R (1<<4)  

  5.   

  6.         RIM; //Open global interrupt, this sentence is required, otherwise it will only respond to non-maskable interrupts  

  7. //#define HALT _asm("halt")  

  8. //#define RIM _asm("rim")  

  9. //#define SIM _asm("sim")   

  10.   

  11.         GPIO_Init(GPIOC,TRINT,GPIO_MODE_IN_PU_IT); //Enable the corresponding IO port interrupt  

  12.   

  13. stm8s_it.c code  

  14. //Transmit and receive interrupt (PC3) BJ8F101  

  15. @far @interrupt void EXTI_PORTC_IRQHandler(void)  

  16. {  

  17.     //Used as a receive interrupt, please note that PSB_D, TRRDY_U will generate an interrupt, TRINT will be pulled high  

  18.     if(cur_mode==RX_MODE)  

  19.     {  

  20.         //To exclude the first time, you can check whether PSB is high, high means it is Active Mode  

  21.         if(PB_ODR&PSB)  

  22.         {  

  23.             ss=1;  

  24.         }  

  25.     }else  

  26.     {  

  27.     }  

  28.     return;  

  29. }  

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.

  1. #ifdef ENABLE_AWU  

  2. void Init_AWU(void)  

  3. {  

  4.         CLK_PCKENR2=CLK_PCKENR2_AWU; //Enable AWU clock  

  5.   

  6. //#define AWU_AWUTB_1S 0x0C /*500ms ~ 1s*/  

  7. //#define AWU_AWUTB_2S 0x0D /*1s ~ 2s*/  

  8.         AWU_TBR=AWU_AWUTB_1S; //AWU_AWUTB_2S; //1~2s  

  9.     AWU_APR=0x3E; //Frequency division  

  10.     AWU_CSR|=0x10; //AWU enable  

  11.   

  12. #ifdef POWER_LEVEL_1 //Power consumption 1, most power-saving  

  13.     CLK_ICKR|=CLK_ICKR_REGAH; //In active shutdown mode (AWU enabled), turn off the voltage regulator to save power  

  14.     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.  

  15. #endif /*ENABLE POWER_LEVEL_1*/  

  16. }  

  17. #endif /*END ENABLE_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:

  1. #ifdef ENABLE_WWDG  

  2. void Init_WWDG(void) //Initialize window watchdog  

  3. {  

  4.     //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  

  5.     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  

  6.     WWDG_CR = 0x7F; //Watchdog count value  

  7.     WWDG_CR |= 0x80; //Enable window watchdog  

  8.       

  9.     //4Mhz main frequency, count value 0x7F, maximum extension time is (64 * (12288 / 4000000)) = 196ms  

  10. }  

  11.   

  12. void Free_WWDG(void)  

  13. {  

  14.     if ((WWDG_CR & 0x7F) < WWDG_WR) //The dog can be fed only if it is less than the window value  

  15.         WWDG_CR |= 0x7F; //Re-feed the dog  

  16. }  

  17. #endif /*END ENABLE_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.


Keywords:STM8S Reference address:STM8S interrupt wake-up, timer wake-up, window watchdog

Previous article:STM8S103 independent button detection
Next article:STM8S operates internal EEPROM

Recommended ReadingLatest update time:2024-11-16 04:23

STM8S (105K4) usage notes - basic configuration of window watchdog WWDG
0. Use of window watchdog The window watchdog runs based on the CPU clock fCPU and is implemented based on a down counter. If the fCPU runs normally, when an error occurs in the main program, the watchdog counter cannot be reset, and the window watchdog will generate a reset flag and restart. Since the window watc
[Microcontroller]
STM8S (105K4) usage notes - basic configuration of window watchdog WWDG
STM8S serial port interrupt stuck debugging record
The project uses the STM8S003 microcontroller. When the data transmission rate is slow, everything works fine. When the rate is fast, the system freezes. Specifically, the interrupt service program keeps running and the content in while (1) cannot be executed. Debug Logging I started to suspect that it was respondin
[Microcontroller]
STM8S serial port interrupt stuck debugging record
STM8s(3) GPIO pin function settings
// Initialization of PXn pin // Output configuration void GPIO_Init(void) {     PX_DDR |= 1 n; // 1 -- output; 0 -- input     PX_CR1 |= 1 n; // 1 -- push completed; 0 -- open drain     PX_CR2 |= 1 n; // 1 -- high speed; 0 -- low speed          PX_ODR // Output register } // Input configuration void GPIO_Init(void)
[Microcontroller]
STM8S awu and watchdog IWDG WWDG application
Application of AWU (completed using library functions) //Remember to enable interrupts and clear interrupts in the interrupt function AWU_GetFlagStatus(); void AWU_SET(void) {     CLK_PeripheralClockConfig(CLK_PERIPHERAL_AWU, ENABLE);     AWU_Init(AWU_TIMEBASE_12S); } #ifdef _COSMIC_ @far @interrupt void AWU_IRQH
[Microcontroller]
STM8S independent watchdog configuration and use
//The clock source of the independent gatekeeper is the internal low-speed clock 128khz divided by 2, which is 64khz //Select IWDG_Prescaler_128 //64/128 = 0.5 khz 2ms period #define IWDG_500MS_REST (uint8) 250 #define IWDG_400MS_REST (uint8) 200 #define IWDG_300MS_REST (uint8) 150 #define IWDG_250MS_REST (uint8) 1
[Microcontroller]
stm8s ADC single mode
Because the STM8s analog input io defaults to floating input, I did not configure the io, but directly configured the ADC. In short, the ADC single-shot mode only collects the signal once and then no longer collects it. The ADC single-shot mode configuration method is as follows:      ADC_CR1_ADON = 0; //turn off AD
[Microcontroller]
STM8S main clock switching (using HSE clock source)
The clock switching method used is manual switching. The clock switching is performed in the interrupt, and then the switched main clock is output to the CLK_CCO port. Clock switching flow chart (manual switching flow chart): Clock Tree: Register version: unsigned char i=255;  PD_DDR_DDR0=1; //Configure PD0 to o
[Microcontroller]
STM8S main clock switching (using HSE clock source)
About STM8S low power management
I have received some questions about STM8S low power consumption in the background. Today I will write about low power consumption. 1STM8S power consumption source STM8S power consumption is divided into static power consumption and dynamic power consumption. Static power consumption: mainly generated by the bias cu
[Microcontroller]
About STM8S low power management
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号