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

nrf52832 rtc to timestamp

Hello,

I am using nRF52832 chip for freeRTOS project and using RTC2. I have SDK15.2. I want to have timestamp from RTC as hex format. I searched almost all forums but i have nothing.  I just found https://github.com/NordicPlayground/nrf5-calendar-example this example but i want to uptade automatically and don't want to update via bluetooth. Could you recommend me some examples or forum? 

Thanks

Parents Reply Children
  • ı implemented the calendar example to my project but i have an error when header file is like this :

    #define CAL_RTC NRF_RTC2
    #define CAL_RTC_IRQn RTC2_IRQn
    #define CAL_RTC_IRQHandler RTC2_IRQHandler
    #define CAL_RTC_IRQ_Priority 3

    Error is Output/.../....o: in function `RTC2_IRQHandler':multiple definition of `RTC2_IRQHandler';

    ...\nRF5_SDK_15.2.0_9412b96\modules\nrfx\drivers\src/nrfx_rtc.c:343: first defined here

    Then i change the header file, code just stop :

    #define CAL_RTC NRF_RTC0
    #define CAL_RTC_IRQn RTC0_IRQn
    #define CAL_RTC_IRQHandler RTC0_IRQHandler
    #define CAL_RTC_IRQ_Priority 3

    Here is my implementation :

    void NrfInit(void)
    {
    /* Select the 32 kHz crystal and start the 32 kHz clock */
    NRF_CLOCK->LFCLKSRC = CLOCK_LFCLKSRC_SRC_Xtal << CLOCK_LFCLKSRC_SRC_Pos;
    NRF_CLOCK->EVENTS_LFCLKSTARTED = 0;
    NRF_CLOCK->TASKS_LFCLKSTART = 1;
    //while(NRF_CLOCK->EVENTS_LFCLKSTARTED == 0);

    /* Configure the RTC for 1 minute wakeup (default) */
    CAL_RTC->PRESCALER = 0xFFF;
    CAL_RTC->EVTENSET = RTC_EVTENSET_COMPARE0_Msk;
    CAL_RTC->INTENSET = RTC_INTENSET_COMPARE0_Msk;
    CAL_RTC->CC[0] = m_rtc_increment * 8;
    CAL_RTC->TASKS_START = 1;
    NVIC_SetPriority(CAL_RTC_IRQn, CAL_RTC_IRQ_Priority);
    NVIC_EnableIRQ(CAL_RTC_IRQn);
    }

    void nrf_cal_set_callback(void (*callback)(void), uint32_t interval)
    {
    /* Set the calendar callback, and set the callback interval in seconds */
    cal_event_callback = callback;
    m_rtc_increment = interval;
    m_time += CAL_RTC->COUNTER / 8;
    CAL_RTC->TASKS_CLEAR = 1;
    CAL_RTC->CC[0] = interval * 8;
    }

    void CAL_RTC_IRQHandler(void)
    {
    if(CAL_RTC->EVENTS_COMPARE[0])
    {
    CAL_RTC->EVENTS_COMPARE[0] = 0;

    CAL_RTC->TASKS_CLEAR = 1;

    m_time += m_rtc_increment;
    if(cal_event_callback) cal_event_callback();
    }
    }

    Best regards

Related