50. Standby wake-up experiment

Publisher:ohp991养生的香菇Latest update time:2018-10-17 Source: eefocusKeywords:Standby Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

1. Explanation of STM32 low power mode

50. Standby wake-up experiment

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.

50. Standby wake-up experiment
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:

50. Standby wake-up experiment
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:

50. Standby wake-up experiment
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

50. Standby wake-up experiment

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

50. Standby wake-up experiment

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

50. Standby wake-up experiment
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

50. Standby wake-up experiment

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:

50. Standby wake-up experiment

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.


Keywords:Standby Reference address:50. Standby wake-up experiment

Previous article:51.Internal temperature sensor experiment
Next article:49. RTC Experiment Explanation

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号