1. Explanation of STM32 low power mode
Some devices, such as wearable devices, have very high requirements for power consumption. For example, a watch needs to run normally when I check the time or get data.
But sometimes, such as at night or when we don’t need to use it, we don’t need to shut it down. We can use the low power mode to save power and extend its usage time.
1. Sleep mode: The core stops, but its peripherals such as interrupt management NVIC and system clock Systick are still running.
2. Stop mode: Lower power consumption than sleep mode, all clocks are stopped, but the 1.8V core power supply is still working, but other clocks such as PLL, HIS and HSE RC oscillator functions are all disabled.
The contents of registers and SRAM are retained.
3. Standby mode: Lower power consumption, the core 1.8V power supply is turned off, and only the backup registers and standby circuits maintain power supply.
All register and SRAM contents are lost, achieving the lowest power consumption.
In some scenarios, we still need the system to run normally. If we want to reduce power consumption, we can take the following measures:
1. Lower the system clock
2. Turn off the clocks of unused peripherals on the APB and AHB buses.
Three low power modes of STM32
To enter or exit these three low power modes:
1. Sleep mode: How to enter: (1) Execute the WFI instruction or the WFE instruction. You only need to call a function.
Wake-up method: For WFI entry: Any interrupt
For WFE entry: Wake-up event
2. Stop mode: How to enter: Both PDDS and LPDS bits + SLEEPDEEP bits need to be set, and then use the WFI or WFE instruction.
Wake-up method: Any external interrupt can be used (set in the external interrupt register)
3. Standby mode: How to enter: Set the PDDS bit + SLEEPDEEP bit, clear the WUF bit, and then use the WFI or WFE instruction to enter
Wake-up method: through the rising edge of the WKUP pin (PA0 pin), or RTC alarm event, or external reset on the NRST pin, independent watchdog IWDG reset. Commonly used are alarm events or external WKUP pin.
The experimental program is woken up by the WKUP pin (PA0).
The experiment adopts standby mode:
In standby mode, most pins are in high impedance state.
In standby mode, the F1 only requires 2uA of current, which is very low.
2. Register and library function configuration
1. PWR_CR power control register
Bit 1: PDDS, set to 1 when entering standby mode
SLEEPDEEP is set to 1 in the system control register SCB.
Clear the WUF bit in the PWR_CSR register.
2. PWR_CSR Power Control/Status Register
There are several ways to exit standby mode. How to configure it if you want to use the WKUP pin to wake up?
PWR_CSR register bit 8, EWUP enables the WKUP pin.
Low power operation functions in the firmware library
Call void PWR_EnterSTANDBYMode(void); //Enter standby mode
Four operations are performed in this function: 1. PDDS position 1
2. SLEEPDEEP position 1
3. Clear the WUF bit
4. Execute the WFI() instruction. Of course, you can also execute the WFE() instruction.
Configuration steps for wake-up from standby
3. Experimental Procedure
The experimental procedure is relatively complicated. It is mainly to press and hold the same WKUP pin (PA0) for 3 seconds to enter the standby mode, and in the standby mode, press and hold for 3 seconds to wake up from the standby mode.
Program design ideas reminder:
1. Write a standby wake-up test first
Press a button to enter standby mode
(1) Add PWR related firmware library .c and .h files under FWLlib
(2) Program design: After the program is reset, the LCD screen is lit up and displays some content. Then, press KEY0 to enter the standby mode. Press the WKUP key in the standby mode to exit the standby mode. The program is equivalent to resetting and starting from the beginning, and the LCD screen displays the content again.
int main(void)
{
x=0;
u8 lcd_id[12]; //Store LCD ID string
delay_init(); //delay function initialization
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2); //Set NVIC interrupt group 2: 2-bit preemption priority, 2-bit response priority
uart_init(115200); //Serial port initialized to 115200
LED_Init(); //LED port initialization
LCD_Init();
KEY_Init();
POINT_COLOR=RED;
LCD_ShowString(30,40,210,24,24,"WarShip STM32 ^_^"); //The LCD screen displays some content
LCD_ShowString(30,70,200,16,16,"TFTLCD TEST");
LCD_ShowString(30,90,200,16,16,"ATOM@ALIENTEK");
while(1)
{
if(KEY_Scan(0) == KEY0_PRES)
{
RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR,ENABLE); //Enable PWR clock on APB1 bus
PWR_WakeUpPinCmd(ENABLE); //Enable the WKUP wake-up pin so that pressing the WKUP key in standby mode can exit standby mode
PWR_EnterSTANDBYMode(); //Enter standby mode
}
delay_ms(10);
}
}
Experimental phenomenon: The program starts running, and the LCD screen displays three lines of text. When the KEY0 key is pressed, it enters standby mode and the LCD screen turns off. When the WKUP key is pressed, the LCD screen displays the content again.
2. Experimental Procedure
Press and hold the same WKUP pin (PA0) for 3 seconds to enter standby mode. In standby mode, press and hold for 3 seconds to wake up from standby.
wkup.c File
//PA0 WKUP wake-up initialization
void WKUP_Init(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
EXTI_InitTypeDef EXTI_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_AFIO, ENABLE); //Enable GPIOA and multiplexing function clock, because the PA0 pin will be configured as an external interrupt later, so the multiplexing function must be enabled.
GPIO_InitStructure.GPIO_Pin =GPIO_Pin_0; //PA.0
GPIO_InitStructure.GPIO_Mode =GPIO_Mode_IPD; //Pull-up input
GPIO_Init(GPIOA, &GPIO_InitStructure); //Initialize IO
//Use external interrupt mode to configure the interrupt line
GPIO_EXTILineConfig(GPIO_PortSourceGPIOA, GPIO_PinSource0); //Interrupt line 0 connects to GPIOA.0
EXTI_InitStructure.EXTI_Line = EXTI_Line0; //Set all external lines of the button
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt; //Set external interrupt mode: EXTI line is interrupt request
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising; //Rising edge trigger
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
EXTI_Init(&EXTI_InitStructure); // Initialize external interrupt
NVIC_InitStructure.NVIC_IRQChannel = EXTI0_IRQn; // Enable the external interrupt channel where the button is located
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 2; //Preemption priority level 2
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2; //From priority level 2
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //Enable external interrupt channel
NVIC_Init(&NVIC_InitStructure); //Initialize peripheral NVIC registers according to the parameters specified in NVIC_InitStruct
if(Check_WKUP()==0) Sys_Standby(); //After powering on, if the WKUP pin is not pressed continuously for 3 seconds, the computer will enter standby mode. Only when the WKUP key is pressed continuously for 3 seconds when powering on, the program can be executed normally.
}
//Detect the signal of WKUP pin
//Return value 1: Press continuously for more than 3 seconds
// 0: wrong trigger
u8 Check_WKUP(void) //Check the level of the WKUP pin. If it is pressed continuously within 3 seconds, it returns 1.
{
u8 t=0; //Record the time of pressing
LED0=0; //light up DS0
while(1)
{
if(WKUP_KD)
{
t++; //has been pressed
delay_ms(30);
if(t>=100) //press for more than 3 seconds, t+1 every 30 milliseconds, t counts to 100, indicating 3 seconds have passed
{
LED0=0; //light up DS0
return 1; //Press for more than 3s, return 1
}
}else
{
LED0=1;
return 0; //If the press is less than 3 seconds, return 0
}
}
}
void Sys_Standby(void)
{
RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE); //Enable PWR peripheral clock
PWR_WakeUpPinCmd(ENABLE); //Enable wake-up pin function
PWR_EnterSTANDBYMode(); //Enter STANDBY mode, enter standby mode
}
main.c file
int main(void)
{
delay_init(); //delay function initialization
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2); //Set the interrupt priority group to group 2: 2-bit preemption priority, 2-bit response priority
uart_init(115200); //Serial port initialized to 115200
LED_Init(); //LED port initialization
WKUP_Init(); //Standby wake-up initialization
LCD_Init(); //LCD initialization
POINT_COLOR=RED;
LCD_ShowString(30,50,200,16,16,"Warship STM32");
LCD_ShowString(30,70,200,16,16,"WKUP TEST");
LCD_ShowString(30,90,200,16,16,"ATOM@ALIENTEK");
LCD_ShowString(30,110,200,16,16,"2014/1/14");
while(1)
{
LED0=!LED0;
delay_ms(250);
}
}
//External interrupt, a rising edge of PA0 pin is detected.
//Interrupt detection on interrupt line 0
void EXTI0_IRQHandler(void)
{
EXTI_ClearITPendingBit(EXTI_Line0); // Clear the interrupt flag on LINE10
if(Check_WKUP()) //Check if the WKUP key is pressed for 3 seconds, and then enter standby mode
{
Sys_Enter_Standby(); //If it is pressed continuously for 3 seconds, it will enter the standby wake-up mode
}
}
//The system enters standby mode
void Sys_Enter_Standby(void)
{
RCC_APB2PeriphResetCmd(0X01FC,DISABLE); //Reset all IO ports
Sys_Standby();
}
When the program runs normally, several lines of text are displayed and LED0 flashes crosswise.
In the WKUP_Init function, if you do not press it for 3 seconds, it will enter standby mode.
If the WKUP key is pressed continuously for 3 seconds, it will execute normally. In the case of normal execution, because we set an external interrupt for WKUP, we enter the external interrupt function.
Experimental phenomena:
The program starts to execute and determines whether WKUP is pressed. If not, it will enter standby mode for 3 seconds.
Because WKUP was not pressed at the beginning, it entered standby mode and the LCD screen did not light up.
Then press WKUP continuously for 3 seconds to wake up, the LCD screen displays a few lines of text, and LED0 starts flashing.
Because, as soon as WKUP is pressed, it is awakened and the main function is executed.
if(Check_WKUP()==0) Sys_Standby(); //Not booting, entering standby mode
Because we pressed the button for 3 seconds, the test will not pass and the device will not enter standby mode. The program will execute directly, the LCD screen will display, and LED0 will flash.
Next, press and hold WKUP for 3 seconds to enter standby mode. Because we set WKUP as an external interrupt when the program is running normally, pressing PA0 will enter the external interrupt service function. In the interrupt service function, we will determine whether WKUP is pressed for more than 3 seconds. If it is pressed for more than 3 seconds, it will enter standby mode. If it is pressed for less than 3 seconds, it will not enter standby mode and the LCD screen will still display normally.
Previous article:51.Internal temperature sensor experiment
Next article:49. RTC Experiment Explanation
- Popular Resources
- Popular amplifiers
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- 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
- consult
- MSP430 timer is set to 1S
- Wi-Fi in 2025: It might be watching your every move
- Please tell me about low noise broadband op amp
- Keil development environment construction
- MSP430 MCU GPIO Demonstration Program
- Which teacher would like to talk about CPL?
- Live review: Infineon BMS solutions protect electric vehicles and energy storage systems!
- Why is the ADS software constantly being updated, but each version of the model is not supported?
- How does MSP430FR6972 achieve the lowest power consumption for LCD driving?