平台:SDK15.2
开发板:pca10056
开发平台:MDK5.24
1.添加文件nrfx_rtc.c
2.添加头文件的路径
const nrf_drv_rtc_t rtc = NRF_DRV_RTC_INSTANCE(0); /**< Declaring an instance of nrf_drv_rtc for RTC0. *//** @brief: Function for handling the RTC0 interrupts.* Triggered on TICK and COMPARE0 match.*/
static void rtc_handler(nrf_drv_rtc_int_type_t int_type)//rtc中断函数
{uint32_t err_code = NRF_SUCCESS;if (int_type == NRF_DRV_RTC_INT_COMPARE0){err_code = nrf_drv_rtc_cc_set(&rtc,0,COMPARE_COUNTERTIME * 8,true);//value reloadAPP_ERROR_CHECK(err_code); nrf_drv_rtc_counter_clear(&rtc);//Clear the RTC counter to start count from zeronrf_gpio_pin_toggle(COMPARE_EVENT_OUTPUT);}else if (int_type == NRF_DRV_RTC_INT_TICK){nrf_gpio_pin_toggle(TICK_EVENT_OUTPUT);}
}/** @brief Function initialization and configuration of RTC driver instance.*/
static void rtc_config(void)//rtc配置并且开启rtc
{uint32_t err_code;//Initialize RTC instancenrf_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 & interruptnrf_drv_rtc_tick_enable(&rtc,true);//Set compare channel to trigger interrupt after COMPARE_COUNTERTIME secondserr_code = nrf_drv_rtc_cc_set(&rtc,0,COMPARE_COUNTERTIME * 8,true);APP_ERROR_CHECK(err_code);//Power on RTC instancenrf_drv_rtc_enable(&rtc);
}