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

anyone having problem with the APP_TIMER in SDK14

When using the APP_TIMER in SDK14 I am having a problem with the application stopping. I was using the APP_TIMER to flash LEDs and watch for timeouts in SDK13. when porting the code to SDK14 I am having a problem with the timer functions stopping. I have cut the functions down to the minimum for testing am still having the problem with both the APP_TIMER_MODE_REPEATED and APP_TIMER_MODE_SINGLE_SHOT.

I started with a repeated timer but changed to a single shot for testing. I increased the timer interval from 150 to 2000. I am also using the timer to trigger sensor a reading so the use of soft_led will not solve the issue.

I have been using the timer in SDK14 to watch for loss of signal while doing range testing and have had no problem using the timer in single mode and constantly resetting it, but there were very few timeout events.

on dev board: nrf52840-Preview-DK softdevice s140_nrf52840_6.0.0-6.alpha_softdevice.hex

setting up the timer

define LED_FLASH_TIME 2000

static void timers_init(void) {

ret_code_t err_code = app_timer_init();

APP_ERROR_CHECK(err_code);
err_code = app_timer_create(&low_gate_led_timer_id, APP_TIMER_MODE_SINGLE_SHOT,
		&low_led_timer);
APP_ERROR_CHECK(err_code);

}

and the timer service routine

void low_led_timer(void * p_context) {

UNUSED_PARAMETER(p_context);
nrf_gpio_pin_toggle(GATE_DOWN_LED);
ret_code_t err_code = app_timer_start(low_gate_led_timer_id,LED_FLASH_TIME,NULL);  

}

Parents
  • hello

    yes I have problems with my app_timers in SDK14.2 (migration from 12),

    I well noticed that the prototypes of the functions create and start changed from sdk12.

    	// create timer
    	static app_timer_t timer_data = { {0} };
    	m_timer_id = &timer_data;
    	err_code = app_timer_create(&m_timer_id, APP_TIMER_MODE_REPEATED, cbk_measure);
    	APP_ERROR_CHECK(err_code);

    this works well

    ret_code_t err_code;
    
    	err_code = app_timer_start(m_timer_id, APP_TIMER_TICKS(m_probing_interval_ms), (void *) this);
    
    	NRF_LOG_DEBUG("FIXME: app_timer_start returns %d", err_code);
    	//	APP_ERROR_CHECK(err_code);

    but the start returns error code 8 (invalid param if i remember correctly) and I dotn understand why.

    BTW my timer_ids are C++ class members. I cannot simply use the APP-TIMER_DEF macro. but it was already the case ion SDK12 and worked AFAIK

    thx,

    yacine

Reply
  • hello

    yes I have problems with my app_timers in SDK14.2 (migration from 12),

    I well noticed that the prototypes of the functions create and start changed from sdk12.

    	// create timer
    	static app_timer_t timer_data = { {0} };
    	m_timer_id = &timer_data;
    	err_code = app_timer_create(&m_timer_id, APP_TIMER_MODE_REPEATED, cbk_measure);
    	APP_ERROR_CHECK(err_code);

    this works well

    ret_code_t err_code;
    
    	err_code = app_timer_start(m_timer_id, APP_TIMER_TICKS(m_probing_interval_ms), (void *) this);
    
    	NRF_LOG_DEBUG("FIXME: app_timer_start returns %d", err_code);
    	//	APP_ERROR_CHECK(err_code);

    but the start returns error code 8 (invalid param if i remember correctly) and I dotn understand why.

    BTW my timer_ids are C++ class members. I cannot simply use the APP-TIMER_DEF macro. but it was already the case ion SDK12 and worked AFAIK

    thx,

    yacine

Children
  • Hi yacine,

    Error code 8 is NRF_ERROR_INVALID_STATE. You will get this error code if have not initialized the timer module(app_timer_init()). You could also get this error code if your timer_id is 0, or if the timeout_handler function is NULL.

  • Hello Sigurd, 

    Thanks for your reply. I verified: app_timer_create is called, the timer _id is not 0, the callback is not NULL.

    I discovered the following with more tests: 

    1) this code works only if the temporary variable timer_data is declared static (just like in APP_TIMER_DEF macro. is not static app-timer_create returns SUCCESS, but app_timer_start will return  NRF_ERROR_INVALID_STATE. see below ths code:

    ret_code_t err_code;
    static app_timer_t timer_data = { {0} };
    m_timer_id = &timer_data;
    err_code = app_timer_create(&m_timer_id, APP_TIMER_MODE_REPEATED, cbk_measure);
    
    (...)
    ret_code_t err_code;
    err_code = app_timer_start(m_timer_id, APP_TIMER_TICKS(m_probing_interval_ms), (void *) this);
    
    

    2) now the problem is that m_timer_id is a member of my c++ class and my code breaks when I create a second instance of this class and try to call app_timer_create. it seems like app_timer_create returns NRF_ERROR_INVALID_STATE when the timer_id is already used by another app_timerActually the timed_id generated in the second instance constructor has the same value of the previous instance and this leads to app_timer create returning 

    see below the logs:

    // first instance
    <debug> FIXME: m_timer_id (before app_timer_create)= 536884956
    <debug> FIXME: app_timer_create returns 0
    <debug> FIXME: m_timer_id (before app_timer_start) = 536884956
    <debug> FIXME: app_timer_start returns 0
    
    // second instance
    <debug> FIXME: m_timer_id (before app_timer_create)= 536884956
    <debug> FIXME: app_timer_create returns 8
    
    

    I need to geenerate a different m_timer_id for each class instance. how can I do ?!?!

Related