App Timer does not trigger his handle function

Hi,

I'm trying to implement a timer that will trigger each 10ms (for example) an handler function and do something inside it. So, I came with the idea to implement an App Timer as follow :

#define OSCILLATION_INTERVAL APP_TIMER_TICKS(10)
  
APP_TIMER_DEF(m_app_timer_id);

static void app_timer_handler(void *p_context)
{
  NRF_LOG_INFO("YES");
}

static void timer_init(void)
{
    ret_code_t err_code;

    err_code = app_timer_create(&m_app_timer_id, APP_TIMER_MODE_REPEATED, app_timer_handler);
    APP_ERROR_CHECK(err_code);
}

static void idle_state_handle(void)
{
    if (NRF_LOG_PROCESS() == false)
    {
        nrf_pwr_mgmt_run();
    }
}

int main(void)
{
    bool erase_bonds;
    ret_code_t err_code;
    
    // Initialize.
    log_init();
    app_timer_init();
    NRF_LOG_INFO("START");
    timer_init();
    // Enter main loop. 
    err_code = app_timer_start(m_app_timer_id, OSCILLATION_INTERVAL, NULL);
    APP_ERROR_CHECK(err_code);
    for (;;)
    {   
        idle_state_handle();
    }
}

My issue is that I don't read the "Yes" charachter in the debug terminal, so I guees that my timer is not working correctly.
I tried to find the solution, but didn't find where my error is...

Thanks for helping !

Chris

Parents Reply Children
  • Christos.Bou said:
    Thanks for your advice about the DEBUG !

    No problem at all - it is a very helpful configuration - I am happy to hear that you found my advice helpful!

    Christos.Bou said:
    The issue was that I was not initializing lfclk at the start.
    Even if I have a SoftDevice, if I do not initialize the SoftDevice I need to intialize lfclk I guess

    I am not sure I have understood you fully here. With a SoftDevice present the clock peripherals will be restricted access, meaning that all clock related calls should be triggered through the SoftDevice API.
    However, in an application without the SoftDevice present you will not need to manually start and stop the LFCLK in order to use the app_timer API - it will be done as part of the app_timer initialization and usage. Could you elaborate on what you meant here?

    Best regards,
    Karl

Related