初级会员

- 积分
- 76
- 金钱
- 76
- 注册时间
- 2020-10-6
- 在线时间
- 10 小时
|
20金钱
最近在搞lora低功耗通信,卡到stm32L151c8t6低功耗了。。。。
下面的程序可以进行睡眠,但是无法唤醒,进不去中断服务函数。。。。给位大佬帮帮忙
int main(void)
{
uint8_t i,a;
RTC_Config();
GPIO_Configuration();
USART1_Config();
while(1)
{
printf("111");
/*控制CPU进入stop模式 */
PWR_EnterSTOPMode(PWR_Regulator_LowPower, PWR_STOPEntry_WFI);
printf("222");
/* CPU唤醒后,先停止自动唤醒功能 */
RTC_WakeUpCmd(DISABLE);
printf("333");
}
}
void RTC_Config(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
EXTI_InitTypeDef EXTI_InitStructure;
static RTC_InitTypeDef RTC_InitStructure;
static RTC_TimeTypeDef RTC_TimeStructure;
static RTC_DateTypeDef RTC_DateStruct;
static RTC_AlarmTypeDef RTC_AlarmStruct;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE);
//allow access to rtc
PWR_RTCAccessCmd(ENABLE); //启用访问功能
//RESET RTC Domain
RCC_RTCResetCmd(ENABLE);
RCC_RTCResetCmd(DISABLE);
//LSE enable 32.768k
RCC_LSEConfig(RCC_LSE_ON);
//wait till LSE is ready
while(RCC_GetFlagStatus(RCC_FLAG_LSERDY) == RESET)
{}
//rtc clock select
RCC_RTCCLKConfig(RCC_RTCCLKSource_LSE);
//enable rtc clock
RCC_RTCCLKCmd(ENABLE);
// wait for rtc APB registers synchronisation
RTC_WaitForSynchro();
// RTC_InitStructure.RTC_AsynchPrediv = 0x7F;
// RTC_InitStructure.RTC_SynchPrediv = 0xFF;
// RTC_InitStructure.RTC_HourFormat = RTC_HourFormat_24;
// RTC_Init(&RTC_InitStructure);
//EXIT Config
EXTI_ClearITPendingBit(EXTI_Line20);
EXTI_InitStructure.EXTI_Line = EXTI_Line20;
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising;
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
EXTI_Init(&EXTI_InitStructure);
//enable the rtc wakeup interrupt
NVIC_InitStructure.NVIC_IRQChannel = RTC_WKUP_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
// RTC_AlarmCmd(RTC_Alarm_A,ENABLE);
//rtc wakeup interrupt generation:clock source:RTCDiv_16,
//wakeup time base:4s
RTC_WakeUpCmd(DISABLE); //禁止唤醒计数器
RTC_WakeUpClockConfig(RTC_WakeUpClock_CK_SPRE_16bits);
RTC_SetWakeUpCounter(5); //设置唤醒计数器
RTC_ClearFlag(RTC_FLAG_WUTF);
RTC_ClearITPendingBit(RTC_IT_WUT);
//enable the wakeup interrupt
RTC_ITConfig(RTC_IT_WUT, ENABLE); //使能唤醒中断
RTC_WakeUpCmd(ENABLE); //使能唤醒计数器
}
void RTC_WKUP_IRQHandler(void)
{
//printf("frtrtrt");
if(RTC_GetITStatus(RTC_IT_WUT) != RESET)
{
RTC_ClearITPendingBit(RTC_IT_WUT);
EXTI_ClearITPendingBit(EXTI_Line20);
//printf("asdf");
}
}
|
|