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.
RTC
- marina.petrovic
- Posts: 2986
- Joined: 18 Apr 2013 08:11
Re: RTC
Hi,
Please, can you explain me a little bit more where the problem occurs?
Which hardware you use?
Best regards,
Marina
Please, can you explain me a little bit more where the problem occurs?
Which hardware you use?
Best regards,
Marina
Re: RTC
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
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 (217.4 KiB) Viewed 4329 times
- marina.petrovic
- Posts: 2986
- Joined: 18 Apr 2013 08:11
Re: RTC
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
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
Re: RTC
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
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
- marina.petrovic
- Posts: 2986
- Joined: 18 Apr 2013 08:11
Re: RTC
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
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