Hi I'm struggling to get an RTC time to increment it just stays at the initial values, any help appreciated, I've reduced my code to below. Its now basically a while loop that calls a function to display the current date and time, the RTC is set up just before the while loop. I display the time to an LCD and the seconds don't increment and in debug they don't either.
int main(void) { volatile uint32_t dlycnt; int ch;
ADC3_CH12_DMA_Config(); ADC_SoftwareStartConv(ADC3); STM32f4_Discovery_LCD_Init();
/* wait the power stable */ for (dlycnt = 0; dlycnt < 10000000; dlycnt++);
RTC_config();
while (1) { RTC_TimeStampShow(); } }
void RTC_config(void) { /* Enable the PWR clock */ RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE); /* Allow access to RTC */ PWR_BackupAccessCmd(ENABLE); /* Select the RTC Clock Source */ RCC_RTCCLKConfig(RCC_RTCCLKSource_LSE); RCC_RTCCLKCmd(ENABLE); RTC_StructInit(&RTC_InitStruct);
RTC_TimeStruct.RTC_Hours = 16; RTC_TimeStruct.RTC_Minutes = 30; RTC_TimeStruct.RTC_Seconds = 5; RTC_SetTime(RTC_Format_BCD,&RTC_TimeStruct);
RTC_DateStruct.RTC_WeekDay = RTC_Weekday_Thursday; RTC_DateStruct.RTC_Date = 14; RTC_DateStruct.RTC_Month = RTC_Month_March; RTC_DateStruct.RTC_Year = 13; RTC_SetDate(RTC_Format_BCD,&RTC_DateStruct); }
void RTC_TimeStampShow(void)
{ /*RTC_GetTime(RTC_Format_BCD, &RTC_TimeStruct);*/ if I uncomment this line the time is all zeros?? sprintf((char*)time_display,"Time = %0.2d:%0.2d:%0.2d", RTC_TimeStruct.RTC_Hours, RTC_TimeStruct.RTC_Minutes,RTC_TimeStruct.RTC_Seconds); LCD_DisplayStringLine(LINE(8),0,(unsigned char*)time_display);
/*RTC_GetDate(RTC_Format_BCD, &RTC_DateStruct);*/ if I uncomment the date is always 01/01/00 sprintf((char*)date_display,"Date = %0.2d/%0.2d/%0.2d", RTC_DateStruct.RTC_Date, RTC_DateStruct.RTC_Month,RTC_DateStruct.RTC_Year); LCD_DisplayStringLine(LINE(9),0,(unsigned char*)date_display);
Thanks for your reply Clive I hadn't noticed that an LSE oscillator was not on board all makes sense now, sorry about the 'tags' its the first post I've made with code but its good to get some constructive advice. Its been a couple of years since I've done any embedded programming and I'm just finishing a 5 year part time degree whilst working full time and having a family so your (non judgemental) post has gone a long way, thanks again.