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

Use of timer in beacon example.

I am using SDK15 , nRF52832 custom board , keil uVISION 5 , ble_app_beacon example.

I am adding timer to the example.

In below code, when I comment out update_vbatt()  & advertising_init() LED toggles perfectly means timer is working. but with those functions in handler, LED does not toggle means code is working properly.(mostly the handler part)

#include....
.
.
.
void advdata_update_timer_timeout_handler(void * p_context)
{
	update_vbatt();
	advertising_init();
	nrf_gpio_pin_toggle(LED_1);
}


/**@brief Function for initializing timers. */
static void timers_init(void)
{
    ret_code_t err_code = app_timer_init();
    APP_ERROR_CHECK(err_code);
	
		err_code = app_timer_create(&m_advdata_update_timer, APP_TIMER_MODE_REPEATED, advdata_update_timer_timeout_handler);
    APP_ERROR_CHECK(err_code);
}


static void timers_start(void)
{
    ret_code_t err_code;
		err_code = app_timer_start(m_advdata_update_timer, APP_TIMER_TICKS(2000), NULL);
    APP_ERROR_CHECK(err_code);
}
.
.
.
int main(void)
{   log_init();
    leds_init();
    power_management_init();
    ble_stack_init();
	timers_init();
	update_vbatt();
    advertising_init();
	timers_start();
    NRF_LOG_INFO("Beacon example started.");
    advertising_start();
	nrf_gpio_pin_toggle(LED_2);
	
    for (;;)
    {
        idle_state_handle();
    }
}

After reading much on devzone to solve this, I got additional doubts...

  • Softdevice itself uses one timer and I am adding 1 more. There are timer0,timer1,....,timer4. Which one does SD use and which one should I enable(changes in sdk_config.h)?
  • If there is existing timer in code, which one it is? (Am I right if I assume that they are enabled automatically in sequence as we do app_timer_create())
  • How do I debug it in keil? I mean how can I create time out for timer in keil debugger to check if handler function is working properly or not. Or what is the error in it?
  • What is the flow of code due to timer? Does, after time out, it comes to timers_start() again in main()? I mean once there is time out, handler is called and function in it are performed. How does the code flow after that?
Parents
  • Hi,

    1) You can know what peripherals softdevice is reserving here. You can see that softdevice is using Timer0 and  hence applications does not have access to this when softdevice is enabled.

    2) Softdevice also uses RTC0, and app_timer library (which is application code) uses RTC1

    2) Normally timers_start in examples initializes application timers RTC1 and TIMER1 (in some cases) based on the use case. Please read the documentation on this in infocenter, I think this topic is very well covered here in the forum also.

    About your problem having issues with timer after using update_vbatt() function. Either it is touching the app_timer registers (RTC1) or disabling its interrupt or maybe there is a hardfault or system reset in this function. I think you should be able to debug this once your run your code in debug mode and stepping through update_vbatt function.

Reply
  • Hi,

    1) You can know what peripherals softdevice is reserving here. You can see that softdevice is using Timer0 and  hence applications does not have access to this when softdevice is enabled.

    2) Softdevice also uses RTC0, and app_timer library (which is application code) uses RTC1

    2) Normally timers_start in examples initializes application timers RTC1 and TIMER1 (in some cases) based on the use case. Please read the documentation on this in infocenter, I think this topic is very well covered here in the forum also.

    About your problem having issues with timer after using update_vbatt() function. Either it is touching the app_timer registers (RTC1) or disabling its interrupt or maybe there is a hardfault or system reset in this function. I think you should be able to debug this once your run your code in debug mode and stepping through update_vbatt function.

Children
No Data
Related