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

App_timer only executes timeout_handler once.

I am integrating app_timer with no softdevice..

Code compiles and runs correctly at the begining but it only executes the timeout_handler function once after the app_timer_start() is run.

Already tried creating the timer with APP_TIMER_MODE_REPEAT and APP_TIMER_MODE_SINGLE_SHOT. (on the second case call app_timer_start() from timeout_handler().

I think that maybe something is being missed , but cannot find what.

Here is the code.

#include <stdbool.h>
#include <stdint.h>

#include "nrf.h"
#include "nordic_common.h"
#include "boards.h"

#include "nrf_log.h"
#include "nrf_log_ctrl.h"
#include "nrf_log_default_backends.h"

#include "app_timer.h"
#include "nrf_drv_clock.h"


/* ------ timer ------*/

#define ANALOG_READ_INTERVAL     APP_TIMER_TICKS(2000)

APP_TIMER_DEF(my_timer_id);

static void lfclk_request(void)
{
    uint32_t err_code = nrf_drv_clock_init();
    APP_ERROR_CHECK(err_code);

    nrf_drv_clock_lfclk_request(NULL);
}

static void timeout_handler(void * p_context){
    ret_code_t err_code;
    
    NRF_LOG_INFO("[tmr] execute");


    err_code = app_timer_start(my_timer_id,APP_TIMER_TICKS(2000), NULL);
    APP_ERROR_CHECK(err_code);

    NRF_LOG_FLUSH();


}


static void timers_init(){
    ret_code_t err_code = app_timer_init();
    APP_ERROR_CHECK(err_code);

    err_code = app_timer_create(&my_timer_id, APP_TIMER_MODE_SINGLE_SHOT , timeout_handler);
    APP_ERROR_CHECK(err_code);


}

/* ----- logs -----*/
static void logs_init(void){
    uint32_t err_code = NRF_LOG_INIT(NULL);
    APP_ERROR_CHECK(err_code);

    NRF_LOG_DEFAULT_BACKENDS_INIT();


}

/**
 * @brief Function for application main entry.
 */
int main(void)
{
    ret_code_t err_code;
    lfclk_request();
    logs_init();
    timers_init();

    NRF_LOG_INFO("APP_TEMPLATE");
    NRF_LOG_FLUSH();

    err_code = app_timer_start(my_timer_id, APP_TIMER_TICKS(2000), NULL);
    APP_ERROR_CHECK(err_code);



    while (true)
    {
        // Do nothing.
    }
}

Parents Reply Children
No Data
Related