File tree Expand file tree Collapse file tree 2 files changed +15
-9
lines changed Expand file tree Collapse file tree 2 files changed +15
-9
lines changed Original file line number Diff line number Diff line change @@ -52,15 +52,7 @@ void RTCZero::begin(bool resetTime)
52
52
}
53
53
54
54
// Setup clock GCLK2 with OSC32K divided by 32
55
- GCLK->GENDIV .reg = GCLK_GENDIV_ID (2 )|GCLK_GENDIV_DIV (4 );
56
- while (GCLK->STATUS .reg & GCLK_STATUS_SYNCBUSY)
57
- ;
58
- GCLK->GENCTRL .reg = (GCLK_GENCTRL_GENEN | GCLK_GENCTRL_SRC_XOSC32K | GCLK_GENCTRL_ID (2 ) | GCLK_GENCTRL_DIVSEL );
59
- while (GCLK->STATUS .reg & GCLK_STATUS_SYNCBUSY)
60
- ;
61
- GCLK->CLKCTRL .reg = (uint32_t )((GCLK_CLKCTRL_CLKEN | GCLK_CLKCTRL_GEN_GCLK2 | (RTC_GCLK_ID << GCLK_CLKCTRL_ID_Pos)));
62
- while (GCLK->STATUS .bit .SYNCBUSY )
63
- ;
55
+ configureClock ();
64
56
65
57
RTCdisable ();
66
58
@@ -419,6 +411,19 @@ void RTCZero::setY2kEpoch(uint32_t ts)
419
411
}
420
412
}
421
413
414
+ /* Attach peripheral clock to 32k oscillator */
415
+ void RTCZero::configureClock () {
416
+ GCLK->GENDIV .reg = GCLK_GENDIV_ID (2 )|GCLK_GENDIV_DIV (4 );
417
+ while (GCLK->STATUS .reg & GCLK_STATUS_SYNCBUSY)
418
+ ;
419
+ GCLK->GENCTRL .reg = (GCLK_GENCTRL_GENEN | GCLK_GENCTRL_SRC_XOSC32K | GCLK_GENCTRL_ID (2 ) | GCLK_GENCTRL_DIVSEL );
420
+ while (GCLK->STATUS .reg & GCLK_STATUS_SYNCBUSY)
421
+ ;
422
+ GCLK->CLKCTRL .reg = (uint32_t )((GCLK_CLKCTRL_CLKEN | GCLK_CLKCTRL_GEN_GCLK2 | (RTC_GCLK_ID << GCLK_CLKCTRL_ID_Pos)));
423
+ while (GCLK->STATUS .bit .SYNCBUSY )
424
+ ;
425
+ }
426
+
422
427
/*
423
428
* Private Utility Functions
424
429
*/
Original file line number Diff line number Diff line change @@ -100,6 +100,7 @@ class RTCZero {
100
100
bool _configured;
101
101
102
102
void config32kOSC (void );
103
+ void configureClock (void );
103
104
void RTCreadRequest ();
104
105
bool RTCisSyncing (void );
105
106
void RTCdisable ();
You can’t perform that action at this time.
0 commit comments