@@ -38,14 +38,32 @@ static void init(void) {
38
38
void rtc_init (void ) {
39
39
init ();
40
40
41
- //Configure the TSR. default value: 1
41
+ // Configure the TSR. default value: 1
42
42
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 ;
49
67
50
68
// enable counter
51
69
RTC -> SR |= RTC_SR_TCE_MASK ;
0 commit comments