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

Using app_timer callback

Hello, I'm trying to do a millisecond counter using app_timer but the callback is never called. I think I have missunderstood how it works. I've tried using the app_timer with or without softdevice, in debug mode and without debug mode, but still the timeout handler is not called.

What am I doing wrong?

Thank you.

My code is as follows:


static void timeout_handler(void * p_context)
{
    //UNUSED_PARAMETER(p_context);
    //battery_start();

    simple_uart_putstring((const uint8_t *)"time!\n\r");
    millis+=20;
}

int main(void)
{
simple_uart_config(RTS_PIN_NUMBER, TX_PIN_NUMBER, CTS_PIN_NUMBER, RX_PIN_NUMBER, HWFC);
simple_uart_putstring((const uint8_t *)"Start using device \n\r");

APP_TIMER_INIT(0, 4, 5, false);

  NRF_CLOCK->TASKS_LFCLKSTART = 1;

    	while (NRF_CLOCK->EVENTS_LFCLKSTARTED == 0);
    	NRF_CLOCK->EVENTS_LFCLKSTARTED = 0;

      
      NRF_CLOCK->TASKS_LFCLKSTART = 1;

      while (NRF_CLOCK->EVENTS_LFCLKSTARTED == 0);

        // Create timer
      err_code = app_timer_create(&test_timer_id, APP_TIMER_MODE_REPEATED, timeout_handler);
      APP_ERROR_CHECK(err_code);

      err_code =app_timer_start(test_timer_id, 100, NULL);
      APP_ERROR_CHECK(err_code);

uint8_t sd_is_enabled;
while (true)
{

	    (void)sd_softdevice_is_enabled(&sd_is_enabled);
	    if (sd_is_enabled)
	    {
	        uint32_t err_code = sd_app_event_wait();
	        APP_ERROR_CHECK(err_code);
	    }
	    else
	        __WFI()
}

}


Parents Reply Children
Related