新手入门
- 积分
- 19
- 金钱
- 19
- 注册时间
- 2022-9-9
- 在线时间
- 8 小时
|
#include "wkup.h"
static u8 t = 0 ;
void STANBY(void) {
RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR,ENABLE);
// PWR->CSR|=1<<8; //设置WKUP用于唤醒
PWR_WakeUpPinCmd(ENABLE); //使能WKUP唤醒引脚
PWR_EnterSTANDBYMode(); //进入待机模式
}
void EN_STANBY(void){
RCC_APB2PeriphResetCmd(0X01FC,DISABLE); //复位所有IO口
STANBY();
}
void WKUP_Init(void) {
GPIO_InitTypeDef GPIO_InitStructure;
EXTI_InitTypeDef EXTI_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_AFIO,ENABLE);
//POWER_KEY
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_EXTILineConfig(GPIO_PortSourceGPIOA,GPIO_PinSource0); //配置外部中断与GPIOA连接
EXTI_InitStructure.EXTI_Line = EXTI_Line0;
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt; //中断模式
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling; //下降沿触发
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
EXTI_Init(&EXTI_InitStructure);
NVIC_InitStructure.NVIC_IRQChannel = EXTI0_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
//if(POWER_CHECK() == 0) STANBY();
}
void EXTI0_IRQHandler(void){
EXTI_ClearITPendingBit(EXTI_Line0); //清除外部中断线0上的中断标志位
if(POWER_CHECK()) {
EN_STANBY();
}
}
u8 POWER_CHECK(void) {
while(1) {
if(power_check) {
return 0;
}
else {
// t++;
// delay_ms(30);
//
// if(t >= 100) {
//
// t = 0;
return 1;
//}
}
}
}
根据原子的demo,结合实际情况,外部PA0是接了外部上拉的,所以这里PA0外部中断设置为下降沿触发,但是这个状态待机之后,唤醒不了,还是说待机唤醒触发,只能是PA0的上升沿?
|
|