RTC issue using STM32F4 and Keil uvision 4

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);

Parents
  • If you are using the STM32F4-Discovery board, then be aware it doesn't ship with an external 32.768 KHz oscillator (LSE) or related components

    Use PRE tags when posting code.

    It doesn't not appear if you enable, or wait for LSE to come ready.

    Would suggest you use LSI, by enabling it, waiting for it to be ready, and then selecting it as the RTC. The LSI can't be run off a battery, but that probably won't be an issue with the discovery board.

Reply
  • If you are using the STM32F4-Discovery board, then be aware it doesn't ship with an external 32.768 KHz oscillator (LSE) or related components

    Use PRE tags when posting code.

    It doesn't not appear if you enable, or wait for LSE to come ready.

    Would suggest you use LSI, by enabling it, waiting for it to be ready, and then selecting it as the RTC. The LSI can't be run off a battery, but that probably won't be an issue with the discovery board.

Children
More questions in this forum