2020-03-12 04:07 PM
Hi
I am using STM32F205RCT6 to try periodical wakeup from standby mode. I choose RTC_WakeUpClock_RTCCLK_Div16 and set wakup counter 0x9000, that is about 18 Seconds @32768hz LSE. In main function,first print wakeup counter and RTC_CR, then every 1 sec print the wakeup counter and realtime . I found that: 1. the RTC_CR looks correct, 0x4400 means WUTE is set and WUTIE is set as well 2. the wakeup counter did not counter down, 3. the MCU can wakeup only once from standby mode on time.
Here is code:
void RTC_Initialization(void)
{ EXTI_InitTypeDef EXTI_InitStructure;
if (RTC_ReadBackupRegister(RTC_BKP_DR0) != 0x32F1)
{
/* RTC configuration */
RTC_Config();
/* Configure the RTC data register and RTC prescaler */
//RTC_InitStructure.RTC_AsynchPrediv = AsynchPrediv;
//RTC_InitStructure.RTC_SynchPrediv = SynchPrediv;
RTC_InitStructure.RTC_HourFormat = RTC_HourFormat_24;
RTC_Init(&RTC_InitStructure);
EXTI_ClearITPendingBit(EXTI_Line22);
EXTI_InitStructure.EXTI_Line = EXTI_Line22;
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising;
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
EXTI_Init(&EXTI_InitStructure);
/* Check on RTC init */
if (RTC_Init(&RTC_InitStructure) == ERROR)
{
printf("\n\r /!\\***** RTC Prescaler Config failed ********/!\\ \n\r");
}
RTC_WakeUP_Init(30720,RTC_WakeUpClock_RTCCLK_Div16);
RTC_NVIC_Config();
/* Configure the time register */
printf("\n\r regulate time \n\r");
RTC_WriteBackupRegister(RTC_BKP_DR0, 0x32F1);
}
else
{
/* Enable the PWR clock */
RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE);
/* Allow access to RTC */
PWR_BackupAccessCmd(ENABLE);
/* Wait for RTC APB registers synchronisation */
RTC_WaitForSynchro();
/* Clear the RTC Alarm Flag */
RTC_ClearFlag(RTC_FLAG_ALRAF);
}
}
void RTC_WakeUP_Init(u16 WakeUpPeriod,u16 RTC_WakeUpClock )
{ ErrorStatus err;
err= RTC_WakeUpCmd(DISABLE);
//if (err == !ERROR)
RTC_WakeUpClockConfig(RTC_WakeUpClock);
RTC_SetWakeUpCounter(WakeUpPeriod);
printf("wakeup counter= %x\n\r", RTC_GetWakeUpCounter());
RTC->WPR = 0xCA;
RTC->WPR = 0x53;
RTC_ITConfig(RTC_IT_WUT, ENABLE);
RTC_WakeUpCmd(ENABLE);
RTC->WPR = 0XFF;
printf("rtc_cr= %x\n\r",RTC->CR);
printf("setup RTC WAKEUP completed");
}
RTC wakeup interrupt IRQ clear the flag, not sure why just wake up once.