Beware that this post is related to an SDK in maintenance mode
More Info: Consider nRF Connect SDK for new designs
This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

micro second timer of nrf52832

Hi ,

 I need to generate a count data to third party library.

So I create a timer1 ,it can work well.

But I set time_us equal to 1  ,the "timer_led_event_handler" don't work.

Could I set time_us = 1 ?

below is my code,

uint64_t timer_data=0;

void timer_led_event_handler(nrf_timer_event_t event_type, void* p_context)
{
   

    switch (event_type)
    {
        case NRF_TIMER_EVENT_COMPARE0:
 
            timer_data++; 
            break;

        default:
            //Do nothing.
            break;
    }
}

void timer1_init()
{
    uint32_t time_us = 1; 
    uint32_t time_ticks;
    uint32_t err_code = NRF_SUCCESS; 
 
  //Configure TIMER_LED for generating simple light effect - leds on board will invert his state one after the other.
    nrf_drv_timer_config_t timer_cfg = NRF_DRV_TIMER_DEFAULT_CONFIG;
   timer_cfg.bit_width = NRF_TIMER_BIT_WIDTH_32;
 

 
 
    err_code = nrf_drv_timer_init(&TIMER_LED, &timer_cfg, timer_led_event_handler);
    APP_ERROR_CHECK(err_code);


   time_ticks = nrf_drv_timer_us_to_ticks(&TIMER_LED, time_us);
 

   nrf_drv_timer_extended_compare(
         &TIMER_LED, NRF_TIMER_CC_CHANNEL0, time_ticks, NRF_TIMER_SHORT_COMPARE0_CLEAR_MASK, true);
    nrf_drv_timer_enable(&TIMER_LED);
}

condition:

  • SDK16
  • ble_app_uart example

Related