STM32L151中RTC_WakeUpCmd()函數(shù)帶來(lái)了系統(tǒng)延時(shí)
掃描二維碼
隨時(shí)隨地手機(jī)看文章
ErrorStatus RTC_WakeUpCmd(FunctionalState NewState)
{
__IO uint32_t wutcounter = 0x00;
uint32_t wutwfstatus = 0x00;
ErrorStatus status = ERROR;
assert_param(IS_FUNCTIONAL_STATE(NewState));
RTC->WPR = 0xCA;
RTC->WPR = 0x53;
if (NewState != DISABLE)
{
RTC->CR |= (uint32_t)RTC_CR_WUTE;
status = SUCCESS;
}
else
{
RTC->CR &= (uint32_t)~RTC_CR_WUTE;
do
{
wutwfstatus = RTC->ISR & RTC_ISR_WUTWF;
wutcounter++;
} while((wutcounter != INITMODE_TIMEOUT) && (wutwfstatus == 0x00));
if ((RTC->ISR & RTC_ISR_WUTWF) == RESET)
{
status = ERROR;
}
else
{
status = SUCCESS;
}
}
RTC->WPR = 0xFF;
return status;
}
上邊時(shí)RTC喚醒的打開(kāi)和關(guān)閉,在使用時(shí),發(fā)現(xiàn)就RTC_WakeUpCmd(DISABLE)這個(gè)函數(shù)就要占據(jù)8ms(可怕)系統(tǒng)延時(shí),這對(duì)于低功耗產(chǎn)品來(lái)說(shuō),不能頻繁地使用此函數(shù),否則帶來(lái)不必要的浪費(fèi)。
原因:在關(guān)閉時(shí)函數(shù)內(nèi)部下面幾句話
do
{
wutwfstatus = RTC->ISR & RTC_ISR_WUTWF;
wutcounter++;
} while((wutcounter != INITMODE_TIMEOUT) && (wutwfstatus == 0x00));
在這里要等待,可能等待時(shí)間與RTC喚醒設(shè)定的值有關(guān)系。就沒(méi)有再詳細(xì)的跟蹤測(cè)試。