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

TIMER INTERRUPT CALL BACK NOT CALLED AFTER FIRST TIME EXECUTION.

Hi,

I am woking on NRF52840.

OS  : Windows 

SDK version : 15.0

Dev : Keil IDE.

I am using Timer -2, Compare value method to obtain an interrupt.

The interrupt is being generated every time but the call back is executed only on the first interrupt.

Here is a small Snippet of my code.

nrf_ppi_channel_t m_ppi_channel;

const nrfx_timer_t m_timer2 = NRF_DRV_TIMER_INSTANCE(2);

/* Timer Init */

nrf_drv_timer_config_t timer_cfg = NRF_DRV_TIMER_DEFAULT_CONFIG;
err_code = nrf_drv_timer_init( &m_timer2, &timer_cfg, event_handler);
APP_ERROR_CHECK( err_code );

/* PPI Init */

// Configuring the PPI used for automating the data streaming
err_code = nrf_drv_ppi_channel_alloc( &m_ppi_channel );
APP_ERROR_CHECK( err_code );

// Set up PPI Chn0 for triggering of SPIM start when DR pin event occurs (set up for falling edge event)
err_code = nrf_drv_ppi_channel_assign( m_ppi_channel,
nrf_drv_gpiote_in_event_addr_get( AFE_DR_PIN ),
nrf_spim_task_address_get( nrfbusHandle->busIdentifier.u.spim.p_reg, NRF_SPIM_TASK_START ) );
APP_ERROR_CHECK( err_code );

// Fork PPI to also trigger count on timer2 to keep track of number of samples.
err_code = nrf_drv_ppi_channel_fork_assign( m_ppi_channel,
nrf_drv_timer_task_address_get( &m_timer2, NRF_TIMER_TASK_COUNT ) );
APP_ERROR_CHECK( err_code );

/* Waiting for INT */

nrf_drv_timer_extended_compare( &m_timer2, NRF_TIMER_CC_CHANNEL1,Count, NRF_TIMER_SHORT_COMPARE1_STOP_MASK, true ); //Tried with clear mask also

err_code = nrf_drv_ppi_channel_enable( m_ppi_channel );
APP_ERROR_CHECK( err_code );

nrf_drv_timer_enable( &m_timer2 );

My code is hung.

I tried debugging and I found out that the Interrupts are Generated and not cleared. My timer is counting and restarting the count when i try the second time.

It's just that my Interrupt Handler :  event_handler is not called the second time.

I even tried increasing the Timer Interrupt Priority.

Is there anything I have missed out or I have misunderstood? 

Thanks in advance.

:-) Tejaswini 

  • Just to add a little more to this, 

    The Timer IRQ itself is not firing after the first time

  • Using NRF_TIMER_SHORT_COMPARE1_STOP_MASK stops your timer after the compare event so that won't work. You should rather use NRF_TIMER_SHORT_COMPARE1_CLEAR_MASK. 

    I copied your code, commented out the GPIOTE and SPIM stuff, and used _CLEAR_MASK instead of _STOP_MASK and it seems to work like intended. Maybe you should try that too and focus on getting the timer to work before you include the other peripherals. If it doesn't work, can you upload your project files?

    static void event_handler(nrf_timer_event_t event_type, void * p_context)
    {
        //
    }
    
    void test(void)
    {
        nrf_ppi_channel_t m_ppi_channel;
        uint32_t err_code;
    
        const nrfx_timer_t m_timer2 = NRF_DRV_TIMER_INSTANCE(2);
    
        /* Timer Init */
    
        nrf_drv_timer_config_t timer_cfg = NRF_DRV_TIMER_DEFAULT_CONFIG;
        err_code = nrf_drv_timer_init( &m_timer2, &timer_cfg, event_handler);
        APP_ERROR_CHECK( err_code );
    
        /* PPI Init */
    
        // Configuring the PPI used for automating the data streaming
        err_code = nrf_drv_ppi_channel_alloc( &m_ppi_channel );
        APP_ERROR_CHECK( err_code );
    
        // Set up PPI Chn0 for triggering of SPIM start when DR pin event occurs (set up for falling edge event)
    //    err_code = nrf_drv_ppi_channel_assign( m_ppi_channel,
    //    nrf_drv_gpiote_in_event_addr_get( AFE_DR_PIN ),
    //    nrf_spim_task_address_get( nrfbusHandle->busIdentifier.u.spim.p_reg, NRF_SPIM_TASK_START ) );
    //    APP_ERROR_CHECK( err_code );
    
        // Fork PPI to also trigger count on timer2 to keep track of number of samples.
        err_code = nrf_drv_ppi_channel_fork_assign( m_ppi_channel, nrf_drv_timer_task_address_get( &m_timer2, NRF_TIMER_TASK_COUNT ) );
        APP_ERROR_CHECK( err_code );
    
        /* Waiting for INT */
    
        nrf_drv_timer_extended_compare( &m_timer2, NRF_TIMER_CC_CHANNEL1,1000, NRF_TIMER_SHORT_COMPARE1_CLEAR_MASK, true ); //Tried with clear mask also
    
        err_code = nrf_drv_ppi_channel_enable( m_ppi_channel );
        APP_ERROR_CHECK( err_code );
    
        nrf_drv_timer_enable( &m_timer2 );
    }

Related