/** @brief Function initialization and configuration of RTC driver instance. */ static void rtc_config(void) { uint32_t err_code; //Initialize RTC instance err_code = nrf_drv_rtc_init(&rtc1, NULL, rtc1_handler); APP_ERROR_CHECK(err_code); //Disable tick event & interrupt nrf_drv_rtc_tick_enable(&rtc1,false); /* |----| |----| | | | | ____| |______________________..._____| |____... 1s 1s 8s 1s 1s */ //Set compare channel 0 to trigger interrupt after RTC1_CC_VALUE*125ms err_code = nrf_drv_rtc_cc_set(&rtc1,0,RTC1_CC_VALUE,true); APP_ERROR_CHECK(err_code); //Set compare channel 1 to trigger interrupt after RTC1_CC_VALUE*125ms*2 err_code = nrf_drv_rtc_cc_set(&rtc1,1,RTC1_CC_VALUE*2,true); APP_ERROR_CHECK(err_code); //Set compare channel 2 to trigger interrupt after RTC1_CC_VALUE*125ms*9 err_code = nrf_drv_rtc_cc_set(&rtc1,2,RTC1_CC_VALUE*10,true); APP_ERROR_CHECK(err_code); //Power on RTC instance nrf_drv_rtc_enable(&rtc1); }
static void rtc_handler(nrf_drv_rtc_int_type_t int_type) { uint32_t err_code; if (int_type == NRF_DRV_RTC_INT_COMPARE0) { nrf_drv_saadc_sample(); //Trigger the SAADC SAMPLE task LEDS_INVERT(BSP_LED_0_MASK); //Toggle LED1 to indicate SAADC sampling start err_code = nrf_drv_rtc_cc_set(&rtc,0,RTC_CC_VALUE,true); //Set RTC compare value. This needs to be done every time as the nrf_drv_rtc clears the compare register on every compare match APP_ERROR_CHECK(err_code); nrf_drv_rtc_counter_clear(&rtc); //Clear the RTC counter to start count from zero } }
static void rtc_config(void) { uint32_t err_code; //Initialize RTC instance nrf_drv_rtc_config_t rtc_config; rtc_config.prescaler = RTC_FREQ_TO_PRESCALER(RTC_FREQUENCY); err_code = nrf_drv_rtc_init(&rtc, &rtc_config, rtc_handler); //Initialize the RTC with callback function rtc_handler. The rtc_handler must be implemented in this applicaiton. Passing NULL here for RTC configuration means that configuration will be taken from the sdk_config.h file. APP_ERROR_CHECK(err_code); err_code = nrf_drv_rtc_cc_set(&rtc,0,RTC_CC_VALUE,true); //Set RTC compare value to trigger interrupt. Configure the interrupt frequency by adjust RTC_CC_VALUE and RTC_FREQUENCY constant in top of main.c APP_ERROR_CHECK(err_code); //Power on RTC instance nrf_drv_rtc_enable(&rtc); //Enable RTC }
/** @brief Function initialization and configuration of RTC driver instance. */ static void rtc_config(void) { uint32_t err_code; //Initialize RTC instance nrf_drv_rtc_config_t config = NRF_DRV_RTC_DEFAULT_CONFIG; config.prescaler = 4095; err_code = nrf_drv_rtc_init(&rtc, &config, rtc_handler); APP_ERROR_CHECK(err_code); //Enable tick event & interrupt nrf_drv_rtc_tick_enable(&rtc,true); //Set compare channel to trigger interrupt after COMPARE_COUNTERTIME seconds err_code = nrf_drv_rtc_cc_set(&rtc,0,COMPARE_COUNTERTIME * 8,true); APP_ERROR_CHECK(err_code); //Power on RTC instance nrf_drv_rtc_enable(&rtc); }
static inline void rtc_cc_schedule(unsigned chan, unsigned time) { ret_code_t err_code = nrf_drv_rtc_cc_set(&g_rtc, chan, rtc_current() + time, true); APP_ERROR_CHECK(err_code); }