From e5a4d000e226435f1562918ee9dc108e3484d4d5 Mon Sep 17 00:00:00 2001 From: austin1611 Date: Mon, 30 Jan 2017 10:42:36 -0600 Subject: [PATCH 1/4] Fix counter overflow (part 1) change a bit shifting operation to reflect the fact the RTC is 24 bits, not 32. --- cores/nRF5/delay.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cores/nRF5/delay.c b/cores/nRF5/delay.c index 6c6dfc85..c2b1f4e6 100644 --- a/cores/nRF5/delay.c +++ b/cores/nRF5/delay.c @@ -29,14 +29,14 @@ static volatile uint32_t overflows = 0; uint32_t millis( void ) { - uint64_t ticks = (uint64_t)((uint64_t)overflows << (uint64_t)32) | (uint64_t)(NRF_RTC1->COUNTER); + uint64_t ticks = (uint64_t)((uint64_t)overflows << (uint64_t)24) | (uint64_t)(NRF_RTC1->COUNTER); return (ticks * 1000) / 32768; } uint32_t micros( void ) { - uint64_t ticks = (uint64_t)((uint64_t)overflows << (uint64_t)32) | (uint64_t)(NRF_RTC1->COUNTER); + uint64_t ticks = (uint64_t)((uint64_t)overflows << (uint64_t)24) | (uint64_t)(NRF_RTC1->COUNTER); return (ticks * 1000000) / 32768; } From 1ab68852cc2c8eda31a34016b82a596876e416e5 Mon Sep 17 00:00:00 2001 From: austin1611 Date: Mon, 30 Jan 2017 10:44:04 -0600 Subject: [PATCH 2/4] Fix RTC issue (part 2) enable the overflow interrupt --- cores/nRF5/wiring.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cores/nRF5/wiring.c b/cores/nRF5/wiring.c index e9efa719..fc7d6b25 100644 --- a/cores/nRF5/wiring.c +++ b/cores/nRF5/wiring.c @@ -34,6 +34,7 @@ void init( void ) NRF_CLOCK->LFCLKSRC = (uint32_t)((CLOCK_LFCLKSRC_SRC_RC << CLOCK_LFCLKSRC_SRC_Pos) & CLOCK_LFCLKSRC_SRC_Msk); NRF_CLOCK->TASKS_LFCLKSTART = 1UL; + NRF_RTC1->INTENSET = 2; NRF_RTC1->PRESCALER = 0; NRF_RTC1->EVTENSET = offsetof(NRF_RTC_Type, EVENTS_OVRFLW); NRF_RTC1->INTENSET = offsetof(NRF_RTC_Type, EVENTS_OVRFLW); @@ -42,4 +43,4 @@ void init( void ) #ifdef __cplusplus } -#endif \ No newline at end of file +#endif From c22cce14db10dc80393aca57c1510abce8db0937 Mon Sep 17 00:00:00 2001 From: austin1611 Date: Mon, 6 Feb 2017 08:04:22 -0600 Subject: [PATCH 3/4] Update wiring.c updated to use the RTC_INTENSET_OVRFLW_Msk mask instead of the number 2. --- cores/nRF5/wiring.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cores/nRF5/wiring.c b/cores/nRF5/wiring.c index fc7d6b25..4ef69cf1 100644 --- a/cores/nRF5/wiring.c +++ b/cores/nRF5/wiring.c @@ -34,7 +34,7 @@ void init( void ) NRF_CLOCK->LFCLKSRC = (uint32_t)((CLOCK_LFCLKSRC_SRC_RC << CLOCK_LFCLKSRC_SRC_Pos) & CLOCK_LFCLKSRC_SRC_Msk); NRF_CLOCK->TASKS_LFCLKSTART = 1UL; - NRF_RTC1->INTENSET = 2; + NRF_RTC1->INTENSET = RTC_INTENSET_OVRFLW_Msk; NRF_RTC1->PRESCALER = 0; NRF_RTC1->EVTENSET = offsetof(NRF_RTC_Type, EVENTS_OVRFLW); NRF_RTC1->INTENSET = offsetof(NRF_RTC_Type, EVENTS_OVRFLW); From 9942031c4b68b9ef9a563c9c8a3824b2083db53a Mon Sep 17 00:00:00 2001 From: austin1611 Date: Mon, 6 Feb 2017 19:34:19 -0600 Subject: [PATCH 4/4] Update wiring.c --- cores/nRF5/wiring.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/cores/nRF5/wiring.c b/cores/nRF5/wiring.c index 4ef69cf1..652bfd11 100644 --- a/cores/nRF5/wiring.c +++ b/cores/nRF5/wiring.c @@ -34,10 +34,9 @@ void init( void ) NRF_CLOCK->LFCLKSRC = (uint32_t)((CLOCK_LFCLKSRC_SRC_RC << CLOCK_LFCLKSRC_SRC_Pos) & CLOCK_LFCLKSRC_SRC_Msk); NRF_CLOCK->TASKS_LFCLKSTART = 1UL; - NRF_RTC1->INTENSET = RTC_INTENSET_OVRFLW_Msk; NRF_RTC1->PRESCALER = 0; - NRF_RTC1->EVTENSET = offsetof(NRF_RTC_Type, EVENTS_OVRFLW); - NRF_RTC1->INTENSET = offsetof(NRF_RTC_Type, EVENTS_OVRFLW); + NRF_RTC1->EVTENSET = RTC_INTENSET_OVRFLW_Msk; + NRF_RTC1->INTENSET = RTC_EVTEN_OVRFLW_Msk; NRF_RTC1->TASKS_START = 1; }