新聞中心

EEPW首頁(yè) > 嵌入式系統(tǒng) > 設(shè)計(jì)應(yīng)用 > STM32L151定時(shí)從Stop模式定時(shí)喚醒

STM32L151定時(shí)從Stop模式定時(shí)喚醒

作者: 時(shí)間:2016-11-13 來(lái)源:網(wǎng)絡(luò) 收藏

void StopRTCLSIMode(int count)

本文引用地址:http://m.butianyuan.cn/article/201611/316445.htm

{

EXTI_InitTypeDef EXTI_InitStructure;

PWR_RTCAccessCmd(ENABLE);//Allow access to RTC

RCC_LSICmd(ENABLE);//LSI Enable

while(RCC_GetFlagStatus(RCC_FLAG_LSIRDY)==RESET);//wait till LSI is ready

RCC_RTCCLKConfig(RCC_RTCCLKSource_LSI);//RTC Clock Source Selection

RCC_RTCCLKCmd(ENABLE);//Enable RTC clock

RTC_WaitForSynchro();//wait for RTC APB registers synchronisation

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);

RTC_WakeUpCmd(DISABLE);//禁止喚醒計(jì)數(shù)器

RTC_WakeUpClockConfig(RTC_WakeUpClock_RTCCLK_Div16);//喚醒時(shí)鐘16分頻

RTC_SetWakeUpCounter(count);//設(shè)置喚醒計(jì)數(shù)器

RTC_ITConfig(RTC_IT_WUT,EBANLE);//使能喚醒中斷

RTC_WakeUpCmd(ENABLE);//使能喚醒計(jì)數(shù)器

}

//喚醒中斷

void RTC_WKUP_IRQHandler(void)

{

if(RTC_GetITStatus(RTC_IT_WUT)!=RESET)

{

RTC_ClearITPendingBit(RTC_IT_WUT);

EXTI_ClearITPendingBit(EXTI_Line20);

Systeminit();

StopRTCLSIMode(2312)//~1S 再次初始化定時(shí)喚醒時(shí)間

//重新初始化外設(shè)

isWKUP = 1;

}

}

在主函數(shù)中

int main(void)

{

//TO DO

//1.初始化定時(shí)喚醒

//2.進(jìn)入低功耗模式

while(1)

{

if(isWKUP)

{

isWKUP = 0;

//TO DO 喚醒后干一些事情

StopRTCLSIMode(2312)//~1S 再次初始化定時(shí)喚醒時(shí)間

//進(jìn)入低功耗模式

}

}

}



評(píng)論


技術(shù)專區(qū)

關(guān)閉