PWC — 待机 + WKUP 引脚唤醒
固件库: AT32F403A_407_Firmware_Library V2.2.2
芯片: AT32
源文件: AT32/AT32F403A_407_Firmware_Library_V2.2.2/project/at_start_f403a/examples/pwc/standby_wakeup_pin/src/main.c
功能简介
本示例演示待机(Standby)最低功耗模式。几乎所有电路断电,只保留 RTC 和唤醒引脚。唤醒后相当于复位重启。
完整代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
#include "at32f403a_407_board.h"
#include "at32f403a_407_clock.h"
int main(void)
{
__IO uint32_t index = 0;
/* congfig the system clock */
system_clock_config();
/* init at start board */
at32_board_init();
/* config priority group */
nvic_priority_group_config(NVIC_PRIORITY_GROUP_4);
/* turn on the led light */
at32_led_off(LED2);
at32_led_off(LED3);
at32_led_off(LED4);
/* enable pwc clock */
crm_periph_clock_enable(CRM_PWC_PERIPH_CLOCK, TRUE);
if(pwc_flag_get(PWC_STANDBY_FLAG) != RESET)
{
/* wakeup from standby */
pwc_flag_clear(PWC_STANDBY_FLAG);
at32_led_on(LED2);
}
if(pwc_flag_get(PWC_WAKEUP_FLAG) != RESET)
{
/* wakeup event occurs */
pwc_flag_clear(PWC_WAKEUP_FLAG);
at32_led_on(LED3);
}
at32_led_on(LED4);
/*delay to check led status*/
delay_ms(1000);
/* enable wakeup pin */
pwc_wakeup_pin_enable(PWC_WAKEUP_PIN_1, TRUE);
/* enter standby mode */
pwc_standby_mode_enter();
while(1)
{
}
}
|
代码讲解
系统时钟初始化:配置 MCU 的主频和时钟树。不同芯片的时钟配置不同,一般由工具生成。
板级初始化:初始化开发板上的 LED、按键等基础外设。
中断优先级配置:NVIC 设置中断的抢占优先级和子优先级。数字越小优先级越高。
延时:使用系统延时函数控制 LED 翻转间隔。