how to create a timer ms on nRF Connect SDK ?

Hi,

as follow is nRF5 SDK code to  create a timer ms.

how to create a timer ms on nRF Connect SDK ?

APP_TIMER_DEF(m_timer_speed_1ms);
int timer_lms=0;

static void timer_1ms_handler(void * p_context)
{
  timer_lms++;

}

void main()

{

   ret_code_t err_code = app_timer_create(&m_timer_speed_1ms, APP_TIMER_MODE_REPEATED, timer_1ms_handler);
   APP_ERROR_CHECK(app_timer_start(m_timer_speed_1ms, APP_TIMER_TICKS(1),NULL));

  for (;;){idle_state_handle();}

}

thank  a lot

Parents Reply
  • Oh, sorry. I didn't catch that you were doing this in NCS. 

    The app_timer is not present in the nRF Connect SDK (NCS). You can look into the k_timer documentation which in many ways is the equivalent of app_timer in NCS.

    I can recommend the section Using a Timer Expiry Function, as this also shows you how to implement the k_work. It may not be needed in your case, but if you have some interrupt dependent work you need to do in your app_timer, you can use this.

    Based on your snippet above, you shouldn't need the k_work, but you can increment the ms_timer directly in your "my_timer_handler()" interrupt.

    Best regards,

    Edvin

Children
No Data
Related