cancel
Showing results for 
Search instead for 
Did you mean: 

RTC Cannot Set New Time

emsing007
Associate
Posted on November 24, 2014 at 13:35

Hello.

I have a problem with set time. When I config time on program start, time is ok, but after, I can not set new time.

This is a code:

void RTC_Config(void)

{

RTC_InitTypeDef RTC_InitStructure;

RTC_TimeTypeDef RTC_TimeStructure;

RTC_DateTypeDef RTC_DateStructure;

/* Enable the PWR clock */

RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE);

/* Allow access to RTC */

PWR_BackupAccessCmd(ENABLE);

/* LSI used as RTC source clock */

/* The RTC Clock may varies due to LSI frequency dispersion. */

/* Enable the LSI OSC */

RCC_LSICmd(ENABLE);

/* Wait till LSI is ready */

while(RCC_GetFlagStatus(RCC_FLAG_LSIRDY) == RESET)

{

}

/* Select the RTC Clock Source */

RCC_RTCCLKConfig(RCC_RTCCLKSource_LSI);

/* Enable the RTC Clock */

RCC_RTCCLKCmd(ENABLE);

/* Wait for RTC APB registers synchronisation */

RTC_WaitForSynchro();

/* Calendar Configuration with LSI supposed at 32KHz */

RTC_InitStructure.RTC_AsynchPrediv = 0x7F;

RTC_InitStructure.RTC_SynchPrediv =  0xFF; /* (32KHz / 128) - 1 = 0xFF*/

RTC_InitStructure.RTC_HourFormat = RTC_HourFormat_24;

RTC_Init(&RTC_InitStructure);

RTC_TimeStructure.RTC_Seconds = 0;

RTC_TimeStructure.RTC_Minutes = 5;

RTC_TimeStructure.RTC_Hours = 14;

RTC_SetTime(RTC_Format_BIN, &RTC_TimeStructure);

RTC_DateStructure.RTC_Date = 19;

RTC_DateStructure.RTC_Month = 11;

RTC_DateStructure.RTC_WeekDay= RTC_Weekday_Wednesday;

RTC_DateStructure.RTC_Year = 14;

RTC_SetDate(RTC_Format_BIN, &RTC_DateStructure);

}

Code for new time:

RTC_TimeStructure.RTC_Seconds = 0;

RTC_TimeStructure.RTC_Minutes = 1;

RTC_TimeStructure.RTC_Hours = 11;

RTC_SetTime(RTC_Format_BIN, &RTC_TimeStructure);

RTC_DateStructure.RTC_Date = 11;

RTC_DateStructure.RTC_Month = 12;

RTC_DateStructure.RTC_WeekDay= RTC_Weekday_Wednesday;

RTC_DateStructure.RTC_Year = 12;

RTC_SetDate(RTC_Format_BIN, &RTC_DateStructure);

#lsi #date #rtc #time
1 REPLY 1
jagadeesh
Associate II
Posted on October 01, 2015 at 09:58

Hi 

I am also facing the same problem.How can I solve this.Is there any solution available for this issue.Can any one Guide me please.