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?