STM8S MCU external interrupt wake-up

Publisher:chaochenLatest update time:2020-08-12 Source: elecfansKeywords: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

STM8S MCU external interrupt wake-up

STM8S MCU external interrupt wake-up

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.

STM8S MCU external interrupt wake-up

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.

STM8S MCU external interrupt wake-up

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:

STM8S MCU external interrupt wake-up

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.

STM8S MCU external interrupt wake-up

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.

STM8S MCU external interrupt wake-up

STM8S MCU external interrupt wake-up

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.

Keywords:STM8S Reference address:STM8S MCU external interrupt wake-up

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

Design of digital constant temperature control system for electric heating based on 80C52 single chip microcomputer
1. Control scheme design The temperature field is a gradient field, and the rise or fall of temperature changes slowly over time. The temperature control process of an electric heating furnace can be described by three sub-processes: natural cooling, programmed heating, and constant temperature mainten
[Power Management]
Design of digital constant temperature control system for electric heating based on 80C52 single chip microcomputer
Detailed explanation of design failure mode and effects analysis (DFMEA) for automotive MCU
Failure Mode and Effects Analysis (DFMEA) plays a very important role in the automotive industry. In the process of automotive design and manufacturing, DFMEA is widely used to identify and manage potential design failure modes, as well as to evaluate the impact of these failure modes on automotive performance, safe
[Embedded]
Detailed explanation of design failure mode and effects analysis (DFMEA) for automotive MCU
SL11R MCU External Memory Expansion
SL11R is a 16-bit RISC microcontroller with a USB interface produced by Scanlogic. Its core processing speed reaches 48MIPS. It has rich hardware resources and 32-bit programmable I/O ports, and can flexibly expand peripheral chips. This article mainly discusses the expansion of its external memory. 1 SL11R
[Microcontroller]
SL11R MCU External Memory Expansion
Is the 51 microcontroller still suitable as a microcontroller for beginners?
For many beginners, it is a headache to consider whether to start with the 51 microcontroller. After all, many companies no longer use 51 microcontrollers to make products. But the 51 microcontroller has been popular for so long, it must be a very classic product. I also started learning at 51. My personal suggestio
[Microcontroller]
51 MCU startup code: STARTUP.A51
When building a project using the Keil compiler, Keil will prompt you whether to add the STARTUP.A51 file to the project. This file is the 51 microcontroller startup code. After the 51 MCU is reset, the startup code in the STARTUP.A51 file is executed immediately. The following operations are performed in sequence acc
[Microcontroller]
51 driver circuits for commonly used devices in microcontrollers
1. Introduction to IO The 51 microcontroller has a total of 40 pins, but only 32 of them can be used as IO, and every 8 pins are divided into one group, for a total of 4 groups. In order to achieve predetermined functions, the microcontroller must use various IO ports to complete various functions, including lighting
[Microcontroller]
51 driver circuits for commonly used devices in microcontrollers
Design of smart IC card gas meter electronic control system based on PIC microcontroller
    Abstract: The design of a smart IC card gas meter electronic control system with PIC microcontroller as the core is given. The control mode of the system, the hardware circuit composition of the electronic control system, the system software design and its practical application are introduced. Keywords: PIC mic
[Test Measurement]
Design of digital controlled current source based on single chip microcomputer PIC16F877A
1 Introduction Power supply technology, especially digital control power supply technology, is a very practical engineering technology, involving many disciplines such as electrical, electronic, system integration, control theory, and materials. The development of computer and communication technology has p
[Microcontroller]
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号