RTC

Please check the frequently asked questions before posting to the forum.
Post Reply
Author
Message
mklau
Posts: 34
Joined: 19 Aug 2013 03:41

RTC

#1 Post by mklau » 13 Feb 2014 18:08

Hi,

I am trying to use the RTC clock (using 32.768KHz crystal) on STM32R102R6 MCU. Below are the sample codes to set the clock control and backup registers:

RCC_APB1ENR.PWREN = 1; //enable the power and backup interface clocks
RCC_APB1ENR.BKPEN = 1; //enable the power and backup interface clocks
PWR_CR.DBP = 1; //enable access to the Backup registers and RTC
RCC_BDCR.LSEON = 1; //enable 32.768Kzh oscillator
RTC_CRL.CNF = 1; //set rtc into configuration mode
RTC_CRL.RTOFF = 1; //allow write operation
RTC_PRLL = 0x7FFF; //load rtc prescaler with 32768 to set 1 sec counter
RCC_BDCR.RTCEN = 1; // RTC clock enable
RTC_CRL.CNF = 0; //exit rtc configuration mode

Those registers can be set only in software debug mode but not in the hardware J-Link debugger.

Any clue on that?

Thanks a lot.

User avatar
marina.petrovic
Posts: 2986
Joined: 18 Apr 2013 08:11

Re: RTC

#2 Post by marina.petrovic » 14 Feb 2014 17:00

Hi,

Please, can you explain me a little bit more where the problem occurs?
Which hardware you use?

Best regards,
Marina

mklau
Posts: 34
Joined: 19 Aug 2013 03:41

Re: RTC

#3 Post by mklau » 20 Feb 2014 06:31

Hi Marina,

Referring to the attached picture, both RCC_CR and RCC_CRGR have value of no-zero as shown on the configuration registers under the project edit manual. But when we run it in hardware debugg mode, their values and other RCC and RTC registers are zero as shown on the variables of the Debug Windows. The code works fine in software debug mode. We are using J-Link debugger and we changed to another J-Link debugger but have the same problem.

Any clue on that?

Many thanks,

Henry
Attachments
MiKroC Project Setup.JPG
MiKroC Project Setup.JPG (217.4 KiB) Viewed 4329 times

User avatar
marina.petrovic
Posts: 2986
Joined: 18 Apr 2013 08:11

Re: RTC

#4 Post by marina.petrovic » 20 Feb 2014 17:17

Hi,

Please, can you send me your project so I can test it on my system and try to find source of the problem?

Best regards,
Marina

mklau
Posts: 34
Joined: 19 Aug 2013 03:41

Re: RTC

#5 Post by mklau » 23 Feb 2014 17:01

Hi Marina,

The compiler was re-installed and the problem goes away. It may be related to the compiler in some ways.

Now, I am trying to work on Timer 2 and have some problems:

1. The compiler cannot recognize TIM2_CR1.DIR valuable as it cannot take this command:

TIM2_CR1.DIR=0;

2. I tried to use this command to enable the update interrupt:

TIM2_DIER.UIE = 1; //Update interrupt enabled.

But the valuable remains 0 after program execution.

Could you help on it as well?

Thanks a lot,

Henry

mklau
Posts: 34
Joined: 19 Aug 2013 03:41

Re: RTC

#6 Post by mklau » 25 Feb 2014 01:13

Hi Marina,

TIM2_DIER.UIE = 1

does set the UIE bit to 1 as I spent more time on debugging it and realized that it was cleared by another command.

Henry

User avatar
marina.petrovic
Posts: 2986
Joined: 18 Apr 2013 08:11

Re: RTC

#7 Post by marina.petrovic » 25 Feb 2014 16:04

Hi,

Did you try Timer Calculator from LibStock Website?
http://www.libstock.com/projects/view/3 ... calculator

Timer Calculator is a free software development tool used for easier calculation of timer interrupts
and maybe it can help you with the project that you have.

Best regards,
Marina

Post Reply

Return to “mikroPascal FAQ”