深度睡眠模式例程:
int main(void)
{
/******** 本实验测试单片机深度睡眠模式 *********/
/* 功能:深度睡眠模式需要EXTI的任何中断来唤醒 唤醒后闪灯 闪烁5次 进入深度睡眠模式
本测试设置PE3外部中断 下降沿触发 唤醒MCU
*/
int FlashingCount =0;
//init uart3
Modbus2_Init(9600);
//init led
gd_eval_led_init(LED2); //run light
//init PE3
init_PE3();
while(1){
my_delay(1000);
//取反
gd_eval_led_toggle(LED2);
FlashingCount ++;
if(FlashingCount >= 10){
FlashingCount = 0;
gd_eval_led_off(LED2);
//进入停止模式
rcu_periph_clock_enable(RCU_PMU);
pmu_to_deepsleepmode(PMU_LDO_LOWPOWER, WFI_CMD);
//notice:WFI need EXTI interrupt wakeup
//恢复HSE时钟
SYSCLKConfig_STOP();
}
}
}
void init_PE3(void)
{
//enable clock
rcu_periph_clock_enable(RCU_GPIOE);
rcu_periph_clock_enable(RCU_AF);
//init pe3 io
gpio_init(GPIOE, GPIO_MODE_IPU, GPIO_OSPEED_50MHZ, GPIO_PIN_3);
//set interrut
/* enable and set key EXTI interrupt to the lowest priority */
nvic_irq_enable(EXTI3_IRQn, 2U, 0U);
/* connect key EXTI line to key GPIO pin */
gpio_exti_source_select(GPIO_PORT_SOURCE_GPIOE, GPIO_PIN_SOURCE_3);
/* configure key EXTI line */
exti_init(EXTI_3, EXTI_INTERRUPT, EXTI_TRIG_FALLING);
exti_interrupt_flag_clear(EXTI_3);
}
void EXTI3_IRQHandler(void)
{
if(RESET != exti_interrupt_flag_get(EXTI_3)){
gd_eval_led_toggle(LED2);
}
exti_interrupt_flag_clear(EXTI_3);
}
|