cancel
Showing results for 
Search instead for 
Did you mean: 

RTC Prescaler wont work

p_
Associate II
Posted on July 23, 2009 at 05:08

RTC Prescaler wont work

4 REPLIES 4
p_
Associate II
Posted on May 17, 2011 at 13:18

Hello,

i have a Problem configuring the RTC prescaler.

This is my code:

// -----------------------------

// Real Time Clock konfiguration

// -----------------------------

void RTC_Configuration (void)

{

RCC_APB1PeriphClockCmd(RCC_APB1Periph_BKP | RCC_APB1Periph_PWR, ENABLE); // Enable PWR and BKP clocks

PWR_BackupAccessCmd(ENABLE); // Allow access to Backup Registers

BKP_DeInit(); // Reset Backup Domain

RCC_LSEConfig(RCC_LSE_ON);

while (RCC_GetFlagStatus(RCC_FLAG_LSERDY) == RESET); // Wait till LSE is ready

RCC_RTCCLKConfig(RCC_RTCCLKSource_LSE); // Select LSE as RTC Clock Source

RCC_RTCCLKCmd(ENABLE); // Enable RTC Clock

RTC_WaitForSynchro(); // Wait for RTC registers synchronization

RTC_WaitForLastTask(); // Wait until last write operation on RTC registers has finished

RTC_ITConfig(RTC_IT_SEC, ENABLE); // Enable the RTC Second

RTC_WaitForLastTask(); // Wait until last write operation on RTC registers has finishe

// Set RTC prescaler: set RTC period to 1sec

RTC_SetPrescaler(32767); // RTC period = RTCCLK/RTC_PR = (32.768 KHz)/(32767+1)

RTC_WaitForLastTask(); // Wait until last write operation on RTC registers has finished

}

It doesnt matter which value i give the RTC_SetPrescaler function (32767 or 2 oder 16000) the Interrupt period is allways 1.6ms.

I am using an external 32,768kHz Quartz.

What am i doing wrong or is there missing something?

Thanks

domen2
Associate III
Posted on May 17, 2011 at 13:18

Try enabling RTC second interrupt after setting the prescaler.

Also, I have

RTC_WaitForLastTask();

RTC_SetCounter(0);

after set prescaler, the rest is the same.

p_
Associate II
Posted on May 17, 2011 at 13:18

Thanks,

but i didnt help.

p_
Associate II
Posted on May 17, 2011 at 13:18

I found my mistake.

I forgot to clear the RTC Second Flag in the RTC Interrupt.