cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F103 RTC calibration issue

LRegn.11
Associate II

Hi,

I'm trying to calibrate my RTC by writing on the RTCCR register on an STM32F103 MCU. However, it seems like this is not taken into account as the 512Hz signal is still slightly out.

I'm using the following code:

PWR-> CR |= PWR_CR_DBP; // Allow access to the Backup area

BKP-> RTCCR = 120; // calibrate RTC

AFIO->EVCR =0xAD; //PC13-calibration clock output enable

BKP->RTCCR &= ~BKP_RTCCR_ASOE;

BKP->RTCCR &= ~BKP_RTCCR_ASOS;

BKP->RTCCR |= BKP_RTCCR_CCO; //Setting this bit outputs the

PWR-> CR &=~ PWR_CR_DBP; // deny access to the Backup area

I'm using the MBED framework so I was wondering if something was messing with the RTC but I tried with STM32CubeIDE with nothing activated and it's still not doing anything.

Any idea? Am I missing something?

Louis

1 ACCEPTED SOLUTION

Accepted Solutions

The effect of RTCCR.CAL is not that the input RTC clock frequency changes, but that RTC won't increment upon every period of the input clock, but it will skip incrementing at each cca 1000000/CAL input pulse.

In other words, on the 512Hz calibration output, you will still see most of the periods the same as with CAL=0 (approx. 1.95ms), but every cca 136th period will be somewhat longer, approx. 1.98ms. (In fact, the 512Hz output may be derived from the RTC clock *before* the calibration-skip, so you may not see its effect on the 512Hz output at all. RM0008 does not appear to offer this piece of information.).

JW

View solution in original post

2 REPLIES 2

The effect of RTCCR.CAL is not that the input RTC clock frequency changes, but that RTC won't increment upon every period of the input clock, but it will skip incrementing at each cca 1000000/CAL input pulse.

In other words, on the 512Hz calibration output, you will still see most of the periods the same as with CAL=0 (approx. 1.95ms), but every cca 136th period will be somewhat longer, approx. 1.98ms. (In fact, the 512Hz output may be derived from the RTC clock *before* the calibration-skip, so you may not see its effect on the 512Hz output at all. RM0008 does not appear to offer this piece of information.).

JW

LRegn.11
Associate II

Makes sense, many thanks!

I'll have a look at the drift in seconds then.

Louis