STM32 enter and exit sleep mode routine

Publisher:心连心意Latest update time:2018-02-13 Source: eefocusKeywords:STM32 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

    1. Design requirements

    The system is required to enter and exit sleep mode as follows: 2 seconds after the system starts, configure the RTC to generate an alarm event after 3 seconds, and then use the WFI instruction to put the system into stop mode. If you want to wake up the system to normal mode, you can press the Key button; otherwise, after 3 seconds, an RTC alarm interrupt will automatically wake up the system. Once the stop mode is exited, the system clock is configured to the previous state (in stop mode, the external high-speed oscillator HSE and PLL are unavailable). After a delay, the system will enter the stop state again, and the above operation can be repeated indefinitely.

 

    2. Hardware circuit design

    The hardware circuit uses the same hardware circuit as the application example in Section 7.1, as shown in Figure 7-10. The Key button is used to generate an external interrupt through PB9, and LED1, LED2, LED3, and LED4 are used to display the processor mode and interrupt triggering status.

    3. Software programming

    According to the task requirements, the program content mainly includes:

    (1) Configure GPIOB port, configure RTC, and configure external interrupt;

    (2) Configure the 9th pin of the PB port as an external interrupt, triggered by the falling edge; configure the RTC alarm interrupt, triggered by the rising edge;

    (3) The contents of the two interrupt service subroutines are: switching the status of LED2 and LED3;

    The entire project contains three source files: STM32F10x.s, stm32f10x_it.c and main.c, among which STM32F10x.s is the startup code.

    All interrupt service subroutines are in stm32f10x_it.c, and other functions are in main.c. The following introduces the relevant functions, and the specific program list can be found in the reference program.

    The function SYSCLKConfig_STOP is used to configure the system clock, enable HSE and PLL, and

    PLL is used as the system clock source. When the processor is in stop mode, HSE and PLL are unavailable.

    The function GPIO_Configuration is used to configure GPIO PC6, PC7, PC8, PC9 and PB9.

    The function EXTI_Configuration is used to configure external interrupt lines 9 (PB9) and 17 (RTC alarm).

    The function NV IC _Configuration configures NVIC and interrupt vector table, mainly configuring external interrupt lines 9 and 17.

    The function EXTI9_5_ IRQ Handler processes the interrupt triggered by the button Key (PB9). Its main function is to flip the state of LED2 once.

    The function RTCAlarm_IRQHandler handles the interrupt triggered by the RTC alarm. Its main function is to flip the state of LED3 once and clear the wake-up flag if it is set.

    working process:

    (1) Use Keil uVision3 to connect the experimental board through the ULINK 2 emulator, open the PWR.Uv2 routine in the PWR_TEST subdirectory of the experimental routine directory, and compile and link the project;

    (2) Select software debugging mode, click the Debug menu of MDK, select Start/Stop Debug Session or press CTR l+F5, add GPIOC_ODR.6, GPIOC_ODR.7, GPIOC_ODR.8, GPIOC_ODR.9 in the logic analyzer, and click the Run button. You can see the result as shown in Figure 7-14 in the logic analyzer. You can also use Peripherals-General Port-GPIOB to simulate the action of the KEY button;

    (3) Select the hardware debugging mode, select the Start/Stop Debug Session item or press Ctrl+F5, download the program and run it, and observe the changes in the LED light. Note that when the target system enters the shutdown mode, the emulator cannot be used for debugging;

    (4) Exit Debug mode, open Flash menu > Download, download the program to the Flash of the development board, press the RESET button to reset, and observe the status of the LED lights. The normal situation should be: when the system is in running mode, LED1 is on and LED4 is off; when the system is in shutdown mode, LED1 is off and LED4 is on; when the KEY button is pressed, the status of LED2 is reversed; when an RTC alarm occurs, the status of LED3 is reversed.


Keywords:STM32 Reference address:STM32 enter and exit sleep mode routine

Previous article:Design of power-off protection scheme based on embedded system
Next article:Transplantation and implementation of LwIP TCP/IP protocol stack on embedded real-time operating system uC/0SII

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号