Skip to content

Commit d465cb5

Browse files
committed
Merge pull request #1506 from star297/master
Update rtc_api.c
2 parents 22f2084 + d9d5e97 commit d465cb5

File tree

1 file changed

+25
-7
lines changed
  • libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KLXX

1 file changed

+25
-7
lines changed

libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KLXX/rtc_api.c

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,32 @@ static void init(void) {
3838
void rtc_init(void) {
3939
init();
4040

41-
//Configure the TSR. default value: 1
41+
// Configure the TSR. default value: 1
4242
RTC->TSR = 1;
43-
44-
if (PinMap_RTC[0].pin == NC) { //Use OSC32K
45-
RTC->CR |= RTC_CR_OSCE_MASK;
46-
//delay for OSCE stabilization
47-
for(int i=0; i<0x1000; i++) __NOP();
48-
}
43+
44+
// Configure Time Compensation Register to calibrate RTC accuracy
45+
46+
// dissable LRL lock
47+
RTC->LR &= ~RTC_LR_LRL_MASK;
48+
// RTC->TCR: RTC_TCR_CIR_MASK,RTC_TCR_CIR(x)=0,RTC_TCR_TCR(x)=0 Default no correction
49+
RTC->TCR = RTC_TCR_CIR(0) | RTC_TCR_TCR(0);
50+
/*
51+
RTC_TCR_CIR(x) sets the compensation interval in seconds from 1 to 256.
52+
0x05 will apply the compensation once every 4 seconds.
53+
54+
RTC_TCR_TCR(x) sets the Register Overflow
55+
0x80 Time Prescaler Register overflows every 32896 clock cycles. (+128)
56+
... ... RTC runs slower
57+
0xFF Time Prescaler Register overflows every 32769 clock cycles.
58+
0x00 Time Prescaler Register overflows every 32768 clock cycles, Default.
59+
0x01 Time Prescaler Register overflows every 32767 clock cycles.
60+
... ... RTC runs faster
61+
0x7F Time Prescaler Register overflows every 32641 clock cycles. (-128)
62+
*/
63+
// enable TCL lock
64+
RTC->LR |= RTC_LR_TCL_MASK;
65+
// enable LRL lock
66+
RTC->LR |= RTC_LR_LRL_MASK;
4967

5068
// enable counter
5169
RTC->SR |= RTC_SR_TCE_MASK;

0 commit comments

Comments
 (0)