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

timer handler never called

I'm trying to get a simple, single shot timer working. The debugger never stops at a breakpoint set in my handler function, and an LED turned on in that function never lights. In main.c, adapted from the BLE proximity sample app:

#define TEST_TIMEOUT APP_TIMER_TICKS(5000, 0)

static app_timer_id_t m_test_timeout_timer_id;
static uint8_t m_test_timed_out = 0;

void timeout_handler(void * p_context)
{
    UNUSED_PARAMETER(p_context);
    m_test_timed_out = 1;
    nrf_gpio_pin_set(LED_0);
}

int main(void)
{
    uint32_t err_code;
    
    leds_init();
    timers_init();
    
    m_test_timed_out = 0;
    err_code = app_timer_create(&m_test_timeout_timer_id, APP_TIMER_MODE_SINGLE_SHOT, timeout_handler);
    APP_ERROR_CHECK(err_code);
    err_code = app_timer_start(m_test_timeout_timer_id, TEST_TIMEOUT, NULL);
    APP_ERROR_CHECK(err_code);
    
    for (;;)
    {
        power_manage();
    }
}

What am I doing wrong here? This is using Soft Device 6.0.0.

Parents
  • This isn't very obvious, but when not using the softdevice, you have to start the LFCLK manually, to make the RTC run at all. You can refer to the RTC example for an example of how to do so, which uses a snippet like this:

    
    static void lfclk_config(void)
    {
        NRF_CLOCK->LFCLKSRC             = (CLOCK_LFCLKSRC_SRC_Xtal << CLOCK_LFCLKSRC_SRC_Pos);
        NRF_CLOCK->EVENTS_LFCLKSTARTED  = 0;
        NRF_CLOCK->TASKS_LFCLKSTART     = 1;
        while (NRF_CLOCK->EVENTS_LFCLKSTARTED == 0)
        {
            //Do nothing.
        }
        NRF_CLOCK->EVENTS_LFCLKSTARTED = 0;
    }
    
    
Reply
  • This isn't very obvious, but when not using the softdevice, you have to start the LFCLK manually, to make the RTC run at all. You can refer to the RTC example for an example of how to do so, which uses a snippet like this:

    
    static void lfclk_config(void)
    {
        NRF_CLOCK->LFCLKSRC             = (CLOCK_LFCLKSRC_SRC_Xtal << CLOCK_LFCLKSRC_SRC_Pos);
        NRF_CLOCK->EVENTS_LFCLKSTARTED  = 0;
        NRF_CLOCK->TASKS_LFCLKSTART     = 1;
        while (NRF_CLOCK->EVENTS_LFCLKSTARTED == 0)
        {
            //Do nothing.
        }
        NRF_CLOCK->EVENTS_LFCLKSTARTED = 0;
    }
    
    
Children
No Data
Related