I want to implement digital clock AND CALENDER in nRF51422 using internal RTC. iF ANYONE HAVE ANY IDEA THEN PLEASE SHARE WITH ME. [email protected]
I want to implement digital clock AND CALENDER in nRF51422 using internal RTC. iF ANYONE HAVE ANY IDEA THEN PLEASE SHARE WITH ME. [email protected]
// Internal 32kHz RC
NRF_CLOCK->LFCLKSRC = CLOCK_LFCLKSRC_SRC_Xtal << CLOCK_LFCLKSRC_SRC_Pos;
// Start the 32 kHz clock, and wait for the start up to complete
NRF_CLOCK->EVENTS_LFCLKSTARTED = 0;
NRF_CLOCK->TASKS_LFCLKSTART = 1;
while(NRF_CLOCK->EVENTS_LFCLKSTARTED == 0);
// Configure the RTC to run at 1 second intervals, and make sure COMPARE0 generates an interrupt (this will be the wakeup source)
NRF_RTC0->PRESCALER = 0;
NRF_RTC0->EVTENSET = RTC_EVTEN_COMPARE0_Msk;
NRF_RTC0->INTENSET = RTC_INTENSET_COMPARE0_Msk;
// NORDIC: Count to 32767, and not 32768
NRF_RTC0->CC[0] = 1*32767;
NVIC_EnableIRQ(RTC0_IRQn);
// NORDIC: SET IRQ PRIORITY
NVIC_SetPriority(RTC0_IRQn, 0);
NRF_RTC0->TASKS_START = 1;
//--------------------------------------------------------------------------------------------------
void RTC0_IRQHandler(void)
{
// NORDIC: CLEAR TASK AS QUICKLY AS POSSIBLE
NRF_RTC0->TASKS_CLEAR = 1;
// This handler will be run after wakeup from system ON (RTC wakeup)
if(NRF_RTC0->EVENTS_COMPARE[0])
{
NRF_RTC0->EVENTS_COMPARE[0] = 0;
info.tm_sec++;
}
}
//--------------------------------------------------------------------------------------------------
// Internal 32kHz RC
NRF_CLOCK->LFCLKSRC = CLOCK_LFCLKSRC_SRC_Xtal << CLOCK_LFCLKSRC_SRC_Pos;
// Start the 32 kHz clock, and wait for the start up to complete
NRF_CLOCK->EVENTS_LFCLKSTARTED = 0;
NRF_CLOCK->TASKS_LFCLKSTART = 1;
while(NRF_CLOCK->EVENTS_LFCLKSTARTED == 0);
// Configure the RTC to run at 1 second intervals, and make sure COMPARE0 generates an interrupt (this will be the wakeup source)
NRF_RTC0->PRESCALER = 0;
NRF_RTC0->EVTENSET = RTC_EVTEN_COMPARE0_Msk;
NRF_RTC0->INTENSET = RTC_INTENSET_COMPARE0_Msk;
// NORDIC: Count to 32767, and not 32768
NRF_RTC0->CC[0] = 1*32767;
NVIC_EnableIRQ(RTC0_IRQn);
// NORDIC: SET IRQ PRIORITY
NVIC_SetPriority(RTC0_IRQn, 0);
NRF_RTC0->TASKS_START = 1;
//--------------------------------------------------------------------------------------------------
void RTC0_IRQHandler(void)
{
// NORDIC: CLEAR TASK AS QUICKLY AS POSSIBLE
NRF_RTC0->TASKS_CLEAR = 1;
// This handler will be run after wakeup from system ON (RTC wakeup)
if(NRF_RTC0->EVENTS_COMPARE[0])
{
NRF_RTC0->EVENTS_COMPARE[0] = 0;
info.tm_sec++;
}
}
//--------------------------------------------------------------------------------------------------