This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

HW control for RTC

Dears,

Just one question for RTC. In SDK9.0, it's possible to control of time to use HW RTC block?? If possible, please let me know how to use it..

Thank you.

  • There is an RTC example in SDK 9.0.0, see this. Are you using a SoftDevice?

  • If I understand you correctly, you want to use the RTC directly instead of using the timer library which is documented here infocenter.nordicsemi.com/index.jsp ?

    If you use a softdevice, you need to check which RTC instance is available in the SoftDevice Specification. Good chances are that the RTC1 is available.

    Here's an example of how to set the RTC up for a compare interrupt using only bare metal registers:

        NRF_RTC1->PRESCALER = 327;
    	NRF_RTC1->INTENSET = (RTC_INTENSET_TICK_Enabled << RTC_INTENSET_TICK_Pos);
    	NRF_RTC1->EVTENSET = (RTC_EVTENSET_TICK_Enabled << RTC_EVTENSET_TICK_Pos);
    	
    	NRF_RTC1->INTENSET = 
        (RTC_INTENSET_COMPARE0_Enabled << RTC_INTENSET_COMPARE0_Pos);
    	NRF_RTC0->EVTENSET = 
        (RTC_EVTENSET_COMPARE0_Enabled << RTC_EVTENSET_COMPARE0_Pos);
    	
        NVIC_SetPriority(RTC1_IRQn,3);
    	NVIC_ClearPendingIRQ(RTC1_IRQn);
    	NVIC_EnableIRQ(RTC1_IRQn);
    	
    	NRF_RTC1->TASKS_START = 1;
    	
    	NRF_RTC1->CC[0] = NRF_RTC1->COUNTER + 5;
    

    Then just implement interrupt handler:

    void RTC0_IRQHandler(void)
    {
    	
    	if(NRF_RTC0->EVENTS_TICK )
    	{
    		...
         }
    		NRF_RTC0->EVENTS_TICK = 0;
    	}
    	else if(NRF_RTC0->EVENTS_COMPARE[0])
    	{
               ...
    		
    		NRF_RTC0->CC[0] = NRF_RTC0->COUNTER + 5;
    		NRF_RTC0->EVENTS_COMPARE[0] = 0;
    	}
    }
    
Related