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

app_timer_handler not running (triggering)

I'm running SDK 15.3 with SD 132 and SES 4.30. 

I am working with the ble_app_uart_c as the base code and adding other functions. I've gone through the app_timer tutorial and other blogs but can't get the timer to trigger the app_timer_handler function.  I've attached a screenshot showing the system running with a break point set in the handler.  It never triggers.  I've enabled the RTC, RTC1 and RTC2 in sdk_config.

I am also integrating the saadc example code which uses a timer function (originally using timer 0 which I changed to timer 1 because of SD) and GPIOTE for the ADC function.  Could this timer code be affecting the RTC function?

I've attached my code: 

/*****************************************************************************************
                Set up timers for our general use
******************************************************************************************/

void perf_shwr_timer_handler(nrf_timer_event_t event_type, void* p_context) 
{
  perf_shwr_timer_counter++;
  printf("Perf_Shwr Timer Triggered!");
  perfect_shower_main();
}

void timer_init(void)
{
    ret_code_t err_code = app_timer_init();               // initialize library
    APP_ERROR_CHECK(err_code);

    APP_TIMER_DEF(perf_shwr_timer); 
 
    // create a main system timer to run perfect_shower_main every 1 sec.
    err_code = app_timer_create(&perf_shwr_timer, APP_TIMER_TICKS(1000000), perf_shwr_timer_handler);

//}
//void timers_start(void)
//{
       err_code = app_timer_start(perf_shwr_timer, APP_TIMER_TICKS(1000000), NULL); //1000000 uS=1 sec
       APP_ERROR_CHECK(err_code);
}
/*
/

Note:  I was getting an error: 'perf_shwr_timer' undeclared (first use in this function); did you mean 'perf_shwr_timer_handler'?  When the start_timers() function was standalone.  I had to move the function into the timer_init() function where the timer is defined to eliminate this error.  Why isn't the linker finding the predefined timer? 

Parents
  • 1) app_timer_create's second parameter is 'mode'. If its not set to "APP_TIMER_MODE_REPEATED" it will default to "APP_TIMER_MODE_SINGLE_SHOT". So it will only trigger once.

    2) APP_TIMER_TICKS converts ms to ticks. Your timeout is set to 1000000ms.

    So this timer is going to take over 15 minutes to trigger, and it will only trigger once.

    The reason for the undeclared error is because line 7 is the variable definition for perf_shwr_timer. If you want to reference the variable outside of timer_init, move it outside of the method.

Reply
  • 1) app_timer_create's second parameter is 'mode'. If its not set to "APP_TIMER_MODE_REPEATED" it will default to "APP_TIMER_MODE_SINGLE_SHOT". So it will only trigger once.

    2) APP_TIMER_TICKS converts ms to ticks. Your timeout is set to 1000000ms.

    So this timer is going to take over 15 minutes to trigger, and it will only trigger once.

    The reason for the undeclared error is because line 7 is the variable definition for perf_shwr_timer. If you want to reference the variable outside of timer_init, move it outside of the method.

Children
Related