cancel
Showing results for 
Search instead for 
Did you mean: 

Problem accessing RTC->PRLx

markaren1
Associate II
Posted on July 25, 2011 at 00:40

Hi All,

I am trying to change RTC->PRLH and RTC->PRLL.

The second WHILE hangs.

I keep re-reading the same paragraph in the STM32F101xx reference manual (UM0306, CH8), but I can't see what I am doing wrong. 

Preceding code has enabled APB1 at much more than 4x 32kHz.

Commenting out the second WHILE and reading RTC->PRLL later confirms that it has been set as expected.

Thoughts please.

-Mark

while((RTC->CRL & RTC_CRL_RTOFF) ==0);

RTC->CRL |=RTC_CRL_CNF;

RTC->PRLH =0;

RTC->PRLL =0x7FFF;

RTC->CRL &=~RTC_CRL_CNF;

while((RTC->CRL & RTC_CRL_RTOFF) == 0);

1 REPLY 1
cerdani
Associate II
Posted on July 25, 2011 at 07:43

You need to enable the RTC clock first.

Here's a sample code:

// enables the clock to Backup and power interface peripherals

RCC_APB1PeriphClockCmd(RCC_APB1Periph_BKP | RCC_APB1Periph_PWR,ENABLE);

// enables acces to BKP and RTC registers

PWR_BackupAccessCmd(ENABLE);

// enable 32.768 kHz external oscillator

RCC_LSEConfig(RCC_LSE_ON);

// provide delay to stabilize LSE

delay(5000);

// set LSE as RTC clock source

RCC_RTCCLKConfig(RCC_RTCCLKSource_LSE);

// enable RTC clock

RCC_RTCCLKCmd(ENABLE);

//RTC_WaitForLastTask();

// wait for register sync

//RTC_WaitForSynchro();

RTC_WaitForLastTask();

// set RTC prescaler

RTC_SetPrescaler(USED_RTC_XTAL_FREQ-1); 

RTC_WaitForLastTask();