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

TIMER0 instantiation failing

Hi, 

I am trying to make a micro second timer count and I am using the timer driver from the timer example. However the timer init is failing in my code and I am not sure why. Here is my code:

uint32_t hrt_time_us = 0;
const nrf_drv_timer_t HRT_TIMER_INSTANCE = NRF_DRV_TIMER_INSTANCE(0);

void hrt_timer_event_handler(nrf_timer_event_t event_type, void* p_context)
{
    switch (event_type)
    {
        case NRF_TIMER_EVENT_COMPARE0:
            hrt_time_us++;
            break;

        default:
            //Do nothing.
            break;
    }
}


void hrt_timer_init()
{
    uint32_t time_us = 1;
    nrf_drv_timer_config_t hrt_timer = NRF_DRV_TIMER_DEFAULT_CONFIG;

    NRF_LOG_INFO("init hrt");
    err_code = nrf_drv_timer_init(&HRT_TIMER_INSTANCE, &hrt_timer, hrt_timer_event_handler);

    APP_ERROR_CHECK(err_code);

    uint32_t time_ticks = nrf_drv_timer_us_to_ticks(&HRT_TIMER_INSTANCE, time_us);
    NRF_LOG_INFO("ticks: %d", time_ticks);

    nrf_drv_timer_extended_compare(&HRT_TIMER_INSTANCE,
        NRF_TIMER_CC_CHANNEL0,
        time_ticks,
        NRF_TIMER_SHORT_COMPARE0_CLEAR_MASK,
        true);

    nrf_drv_timer_enable(&HRT_TIMER_INSTANCE);

I have TIMER_ENABLED set to 1, TIMER0_ENABLED set to 1. 

The nrf_drv_timer_init function fails. Any inputs on why this may be happening? 

Parents Reply Children
No Data
Related