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

Can't make app_timer work

I have following code which should start the app_timer and blink the LED_1.


#include "config.h"

#include "nrf_pwr_mgmt.h"

#include "boards.h"
#include "bsp.h"
#include "app_error.h"
#include "app_timer.h"

#include "nrf_log.h"
#include "nrf_log_ctrl.h"
#include "nrf_log_default_backends.h"

static uint16_t leds_timer_counter = 0;

static void leds_tick_handler(void * p_context) {
  NRF_LOG_INFO("timer.");
  if (leds_timer_counter++ % 8 == 0) bsp_board_led_invert(BSP_BOARD_LED_1);
}

int main(void) {
  APP_ERROR_CHECK(NRF_LOG_INIT(NULL));
  NRF_LOG_DEFAULT_BACKENDS_INIT();

  APP_ERROR_CHECK(app_timer_init());
  APP_TIMER_DEF(m_leds_tick_timer);
  APP_ERROR_CHECK(app_timer_create(&m_leds_tick_timer, APP_TIMER_MODE_REPEATED, leds_tick_handler));
  APP_ERROR_CHECK(app_timer_start(m_leds_tick_timer, APP_TIMER_TICKS(500), NULL));
  
  APP_ERROR_CHECK(nrf_pwr_mgmt_init());

  bsp_board_leds_init();
  bsp_board_led_on(BSP_BOARD_LED_0);

  NRF_LOG_INFO("Started.");
  
  while (1) { 
    NRF_LOG_FLUSH();
    nrf_pwr_mgmt_run();
  }
}

When flashed, the LED_0 turns on and I can see the "Started." log. But the LED_1 is not blinking and I can't see the "timer." log.

Any idea what's wrong with the code?

Thanks.

Parents Reply Children
No Data
Related