cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F405, rtc issue

Angelo1
Associate II
Posted on September 13, 2014 at 02:22

Dear all,

i connected a 32.768Khz quartz to the external clock source (PC14, PC15), i would like to have an interrupt generated each second, for the system clock. Also, i connected a battery between VBAT and gnd, to maintain time over power off.

So for this purpose, i tried several samples found here and there, no one seems to work.

I suspect some hardware trouble on my board, anyway, i am not sure of the samples i am looking at, could anyone suggest me a sure tutorial / appnote / link for this purpose so i am sure about the software steps ?

Many thanks

Angelo

3 REPLIES 3
Posted on September 13, 2014 at 18:13

It should certainly be possible to get the RTC generating a 1 Hz interrupt, if you suspect a problem with the LSE, you should be able to check the LSE Ready signal, and time the period using TIM9, as I recall. Or expose it via one of the MCO pins.

I'll see if I can dig up or cultivate some examples on a different machine later.

There should be some in either the F4 DISCO library, or F4 DSP library
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Angelo1
Associate II
Posted on September 15, 2014 at 00:04

Many thanks. I have rtc perfectly working, except for the

RTC_WKUP_IRQHandler

that is never triggered,

i set up interrupt as:

void rtc_init(void)

{

RTC_InitTypeDef RTC_InitStructure;

NVIC_InitTypeDef NVIC_InitStructure;

EXTI_InitTypeDef EXTI_InitStructure;

RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE);

PWR_BackupAccessCmd(ENABLE);

RCC_LSEConfig(RCC_LSE_ON);

while(RCC_GetFlagStatus(RCC_FLAG_LSERDY) == RESET);

RCC_RTCCLKConfig(RCC_RTCCLKSource_LSE);

RCC_RTCCLKCmd(ENABLE);

RTC_WaitForSynchro();

if (RTC_ReadBackupRegister(RTC_BKP_DR0) != BKP_VALUE) {

/* RTC empty, first setup */

rtc_setup_time(14, 9, 14, 12, 0, 0);

}

/* Calendar Configuration */

/* ck_spre(1Hz) = RTCCLK(LSE) /(uwAsynchPrediv + 1)*(uwSynchPrediv + 1) */

RTC_InitStructure.RTC_AsynchPrediv = 127;

RTC_InitStructure.RTC_SynchPrediv = 249;

RTC_InitStructure.RTC_HourFormat = RTC_HourFormat_24;

RTC_Init(&RTC_InitStructure);

/* EXTI configuration */

EXTI_ClearITPendingBit(EXTI_Line20);

EXTI_InitStructure.EXTI_Line = EXTI_Line20;

EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;

EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising;

EXTI_InitStructure.EXTI_LineCmd = ENABLE;

EXTI_Init(&EXTI_InitStructure);

/* Enable the RTC Wakeup Interrupt */

NVIC_InitStructure.NVIC_IRQChannel = RTC_WKUP_IRQn;

NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;

NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;

NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;

NVIC_Init(&NVIC_InitStructure);

RTC_WakeUpCmd(DISABLE);

RTC_WakeUpClockConfig(RTC_WakeUpClock_CK_SPRE_16bits);

RTC_SetWakeUpCounter(0x0);

RTC_ClearITPendingBit(RTC_IT_WUT);

RTC_ITConfig(RTC_IT_WUT, ENABLE);

RTC_WakeUpCmd(ENABLE);

RTC_WakeUpCmd(ENABLE);

RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_BKPSRAM, ENABLE);

}

void RTC_WKUP_IRQHandler(void)

{

if(RTC_GetITStatus(RTC_IT_WUT) != RESET) { RTC_ClearITPendingBit(RTC_IT_WUT);

EXTI_ClearITPendingBit(EXTI_Line20);

}

}    

Over the wake up not happening i have still an additional doubt: i am actually using SysTick_Handler for the system timing, but i am wondering if to use directly the more precise 32768Khz based RTL clock is a good idea. This is my assumption, but could be that have non sense.

Posted on September 15, 2014 at 17:02

EXTI_Line20 ?? Wouldn't that need to be EXTI_Line22 ?

RM0090 ''EXTI line 22 is connected to the RTC Wakeup event''

STM32F4xx_DSP_StdPeriph_Lib_V1.3.0\Project\STM32F4xx_StdPeriph_Examples\RTC\RTC_LSI\main.c

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..