Beware that this post is related to an SDK in maintenance mode
More Info: Consider nRF Connect SDK for new designs
This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

nRF52832 SDK14.2 How to retrigger RTC Compare0

Hi All,

Based on nRF52832 SDK14.2 rtc example, I want to change it to retrigger RTC Compare0, let the LED1 also toggle every 3s, instead of keeping LED1 on. I tried to add NRF_RTC0->CC[0]=0, and then nrf_drv_rtc_cc_set() in rtc_handler, however, it seems still can not work. I also can't find any example. Would you please give any suggestion? Thanks a lot.

BR,

XiaoYa

Parents
  • Hey Lian,

    If you use the RTC driver with interrupts (callback) then you need to set the CC register in the callback because it will be cleared, you will also need to start the RTC again. 

    Another option is to not use the callback(do not enable interrupt), but instead fork your PPI channel to the RTCs CLEAR task. That way the RTC will reset automatically when you hit the CC value, and the CC value will remain intact. You will also need to change the GPIOTE task from 'set'/'clear' to 'toggle'. 

    Cheers,

    Håkon.

  • Hakon,

    Thanks a lot for your reply. I use RTC drive with callback, and i refer to "blinky_rtc_freeRTOS" example, and add below code in rtc_handler callback, and it works as expected.

    For Option2, which with PPI, is there any code example that I can refer to? Thanks a lot.

    err_code = nrf_drv_rtc_cc_set(
    &m_rtc,
    BLINK_RTC_CC,
    (nrf_rtc_cc_get(m_rtc.p_reg, BLINK_RTC_CC) + BLINK_RTC_TICKS) & RTC_COUNTER_COUNTER_Msk,
    true);
    APP_ERROR_CHECK(err_code);

    BR,

    XiaoYa

Reply
  • Hakon,

    Thanks a lot for your reply. I use RTC drive with callback, and i refer to "blinky_rtc_freeRTOS" example, and add below code in rtc_handler callback, and it works as expected.

    For Option2, which with PPI, is there any code example that I can refer to? Thanks a lot.

    err_code = nrf_drv_rtc_cc_set(
    &m_rtc,
    BLINK_RTC_CC,
    (nrf_rtc_cc_get(m_rtc.p_reg, BLINK_RTC_CC) + BLINK_RTC_TICKS) & RTC_COUNTER_COUNTER_Msk,
    true);
    APP_ERROR_CHECK(err_code);

    BR,

    XiaoYa

Children
Related