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

Can't enable timer on nRF52840 DK

The code crashes at the 3rd line (nrfx_timer.c)

void nrfx_timer_enable(nrfx_timer_t const * const p_instance)
{
    NRFX_ASSERT(m_cb[p_instance->instance_id].state == NRFX_DRV_STATE_INITIALIZED);
    nrf_timer_task_trigger(p_instance->p_reg, NRF_TIMER_TASK_START);
    m_cb[p_instance->instance_id].state = NRFX_DRV_STATE_POWERED_ON;
    NRFX_LOG_INFO("Enabled instance: %d.", p_instance->instance_id);
}

Here is my init code

static void timers_init(void)
{
    ret_code_t err_code;

    //uint32_t hesa_time_ticks = 0x0000007D; //1.6msec
    uint32_t hesa_time_ticks = nrfx_timer_us_to_ticks(&hesa_timer_instance, 1600);
    nrfx_timer_config_t hesa_timer_config = NRFX_TIMER_DEFAULT_CONFIG;
    hesa_timer_config.frequency = NRF_TIMER_FREQ_250kHz;
    hesa_timer_config.mode = NRF_TIMER_MODE_TIMER;
    hesa_timer_config.bit_width = NRF_TIMER_BIT_WIDTH_16;
    hesa_timer_config.interrupt_priority = TIMER_HESA_CONFIG_IRQ_PRIORITY;
    hesa_timer_config.p_context = NULL;
    //code taken from "timer" example
    nrfx_timer_compare(&hesa_timer_instance, NRF_TIMER_CC_CHANNEL1, hesa_time_ticks, true);
    err_code = nrfx_timer_init(&hesa_timer_instance, &hesa_timer_config, hesa_sample_timer_isr);
    APP_ERROR_CHECK(err_code);
    nrfx_timer_enable(&hesa_timer_instance);
    HESA_TIMER->TASKS_START = 1;
}

I suspect this is a config problem but I can't figure what it might be

Parents
  • Where and how is hesa_timer_instance defined and initialised?

  • further up in that same file

    #define HESA_TIMER_ID 1
    #define TIMER_HESA_CONFIG_IRQ_PRIORITY 6
    
    const nrfx_timer_t hesa_timer_instance = NRFX_TIMER_INSTANCE(HESA_TIMER_ID);

  • And I assume it is also enabled in nrfx_config.h ? 

    However, i see a strange thing, that you use the line 

    HESA_TIMER->TASKS_START = 1;

    As this would be used when setting the registers manually, but in the rest of your code, you have the SDK manage it for you. Setting the hardware in some state manually might confuse the SDK code, however, as you report the error occurs in a line before this line, this would not be the cause of the issue.

    Also, by the code crashes, you mean you're entering a HardFault? Looking at that line, getting a HardFault there would suggest you're feeding the function an invalid parameter. Can you verify if the p_instance in nrfx_timer_enable is correct? 

  • it appears that the TWIM interface is stuck here (but only after that 3rd line in nrfx_timer_enable is run):

            while (!nrf_twim_event_check(p_twim, evt_to_wait))
            {
                if (nrf_twim_event_check(p_twim, NRF_TWIM_EVENT_ERROR))
                {
                    NRFX_LOG_DEBUG("TWIM: Event: %s.", EVT_TO_STR_TWIM(NRF_TWIM_EVENT_ERROR));
                    nrf_twim_event_clear(p_twim, NRF_TWIM_EVENT_ERROR);
                    nrf_twim_task_trigger(p_twim, NRF_TWIM_TASK_RESUME);
                    nrf_twim_task_trigger(p_twim, NRF_TWIM_TASK_STOP);
                    evt_to_wait = NRF_TWIM_EVENT_STOPPED;
                }
            }
    

    should i try to get  TWIM to  use the scheduler?

Reply
  • it appears that the TWIM interface is stuck here (but only after that 3rd line in nrfx_timer_enable is run):

            while (!nrf_twim_event_check(p_twim, evt_to_wait))
            {
                if (nrf_twim_event_check(p_twim, NRF_TWIM_EVENT_ERROR))
                {
                    NRFX_LOG_DEBUG("TWIM: Event: %s.", EVT_TO_STR_TWIM(NRF_TWIM_EVENT_ERROR));
                    nrf_twim_event_clear(p_twim, NRF_TWIM_EVENT_ERROR);
                    nrf_twim_task_trigger(p_twim, NRF_TWIM_TASK_RESUME);
                    nrf_twim_task_trigger(p_twim, NRF_TWIM_TASK_STOP);
                    evt_to_wait = NRF_TWIM_EVENT_STOPPED;
                }
            }
    

    should i try to get  TWIM to  use the scheduler?

Children
Related