int LSIFreq=40000;
RTC_INT();
RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR,ENABLE);//open the clock
PWR_BackupAccessCmd(ENABLE);//POWER OPEN
PWR_ClearFlag(PWR_FLAG_WU);
RCC_LSICmd(ENABLE);//OPEN LSI
/* Wait till LSI is ready */
while (RCC_GetFlagStatus(RCC_FLAG_LSIRDY) == RESET)
{}
/* Check if the StandBy flag is set */
if (PWR_GetFlagStatus(PWR_FLAG_SB) != RESET)
{
/* Clear StandBy flag */
PWR_ClearFlag(PWR_FLAG_SB);
/* Check if the StandBy flag is cleared */
if (PWR_GetFlagStatus(PWR_FLAG_SB) != RESET)
{
while(1);
}
IWDG_ReloadCounter();//FEED WACHDOG
RTC_WaitForSynchro();
/* No need to configure the RTC as the RTC config(clock source, enable,
prescaler,...) are kept after wake-up from STANDBY */
}
else
{
/* RTC Configuration ******************************************************/
/* Reset Backup Domain */
RCC_BackupResetCmd(ENABLE);
RCC_BackupResetCmd(DISABLE);
/* Select the RTC Clock Source */
RCC_RTCCLKConfig(RCC_RTCCLKSource_LSI);//4000
/* Enable the RTC Clock */
RCC_RTCCLKCmd(ENABLE);
/* Wait for RTC APB registers synchronisation */
RTC_WaitForSynchro();
IWDG_ReloadCounter();//FEED WACHDOG
/* Get the LSI frequency: TIM14 is used to measure the LSI frequency */
//LSIFreq = GetLSIFrequency();
/* Set the time to 01h 00mn 00s AM */
RTC_TIMESET.RTC_H12 = RTC_H12_AM;
RTC_TIMESET.RTC_Hours = 0x02;
RTC_TIMESET.RTC_Minutes = 0x00;
RTC_TIMESET.RTC_Seconds = 0x00;
/* Clear RTC Alarm Flag */
RTC_ClearFlag(RTC_FLAG_ALRAF);
RTC_ClearFlag(RTC_FLAG_ALRAF);//alarm flag
RTC_ClearFlag(RTC_FLAG_WUTF);//WakeUp Timer flag
RTC_ClearITPendingBit(RTC_IT_TS);
RTC_ClearITPendingBit(RTC_IT_ALRA);
RTC_ClearITPendingBit(RTC_IT_TAMP1);
RTC_ClearITPendingBit(RTC_IT_TAMP2);
/* Enable RTC Alarm A Interrupt: this Interrupt will wake-up the system from
STANDBY mode (RTC Alarm IT not enabled in NVIC) */
RTC_ITConfig(RTC_IT_ALRA, ENABLE);