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.
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
- 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
- Part-time job - Embedded Linux + Android related product development
- Knowledge about the pressure taking method of throttling device
- Please recommend a development board
- Dr. MC is available for viewing. Can be discussed openly
- The new forum homepage is online! Do you think it is necessary to keep the old homepage entrance?
- How to quickly write the output logic expression of CMOS logic gate circuit
- Recommendations for components encountered in peak sampling circuit design
- Follow and comment to win gifts! Micron 2022 Taipei International Computer Show Keynote Speech Highlights: Data Center Special
- Prize-winning quiz | How much do you know about Fujitsu's Ferroelectric Random Access Memory FRAM?
- Want to make an embedded machine learning wearable system