NRF Timer doesn't start

Hi,

In my application I need an interrupt every 8us that I use as basetime, so I add a nrf timer to my code in the following way:

in the prj.conf

CONFIG_NRFX_TIMER1=y
CONFIG_NRFX_TIMER2=y

In the application:

#include <nrfx_timer.h>
#include <irq.h>

static const nrfx_timer_t mIrTimer = NRFX_TIMER_INSTANCE(2);
static volatile uint64_t mIrTimerCounter = 0;

static void irTimerHandler (nrf_timer_event_t event_type, void *p_context) 
{
    mIrTimerCounter += 8;
}

static bool startIrTimer (void) 
{
    nrfx_err_t errCode;

    nrfx_timer_config_t tmrConfig = NRFX_TIMER_DEFAULT_CONFIG;
    tmrConfig.frequency           = NRF_TIMER_FREQ_125kHz;
    tmrConfig.mode                = NRF_TIMER_MODE_TIMER;
    tmrConfig.bit_width           = NRF_TIMER_BIT_WIDTH_32;
    //tmrConfig.interrupt_priority  = NRFX_TIMER_DEFAULT_CONFIG_IRQ_PRIORITY;

    errCode = nrfx_timer_init(&mIrTimer,&tmrConfig,irTimerHandler);
    if (errCode != NRFX_SUCCESS) 
    {
		return false;
	}

    // Interrupt every 10us
    //nrfx_timer_extended_compare(&mIrTimer,NRF_TIMER_CC_CHANNEL1,10,NRF_TIMER_SHORT_COMPARE1_CLEAR_MASK, true);

	IRQ_CONNECT(TIMER2_IRQn,2,nrfx_timer_2_irq_handler, NULL,0);

    nrfx_timer_clear(&mIrTimer);
    nrfx_timer_enable(&mIrTimer);

    return true;
}

I call the function startIrTimer() and the function return without any error, but the callback is never called. Where is it the problem?

Best

Marco

  • It seems like something else is masking your interrupt sometimes for a small period of time. It would be better if you enable tracing and use the systemview to get the overall timings of all contexts traced.

    Other than some other higher interrupt masking your timer interrupt sometimes, I do not see a valid explanation for this behavior. Once you understand which interrupt is doing this you will have better control on your timer. If you have BLE or any other RADIO protocol activity in parallel, then it makes sense that the protocol high priority activity is masking your application interrupt. Are you using BLE or any other radio protocol in parallel with your timer? If so, test the behavior of timer latencies without any other protocols to double confirm on the cause of this behavior.

Related