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

Bluetooth Alarm Clock

Hi,

I want to use nrf51 development board as a bluetooth alarm clock using internal RTC . How can I generate timestamps to determine current date and time. Can the timer library be used for this purpose?

Parents
  • Digital clock and calendar along with nrf51422 and nrf51822 RTC's setting. BHAGYESH D BHAVASAR

    // 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++;
       
    		}
    }
    //--------------------------------------------------------------------------------------------------
    
Reply
  • Digital clock and calendar along with nrf51422 and nrf51822 RTC's setting. BHAGYESH D BHAVASAR

    // 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++;
       
    		}
    }
    //--------------------------------------------------------------------------------------------------
    
Children
No Data
Related