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

Problem with Timer Interrupt and SoftDevice

Hello,

I have troubles with the timer interrupt. The code work fine until the timer hit the compare value and then stop. 

This is my function for the timer init:

void timer_init(uint32_t periode_ms){

  uint32_t time_ticks;
  // config timer
  nrfx_timer_config_t timer_cfg = {
      .frequency	= NRF_TIMER_FREQ_500kHz ,
      .mode		= NRF_TIMER_MODE_TIMER,
      .bit_width	= NRF_TIMER_BIT_WIDTH_32,
      .interrupt_priority	= NRFX_TIMER_DEFAULT_CONFIG_IRQ_PRIORITY,
      .p_context	= NULL
  };
  // init timer
  APP_ERROR_CHECK(nrfx_timer_init(&TIMER_LED, &timer_cfg,timer_led_handler));
  //transform ms in system ticks
  time_ticks = nrfx_timer_ms_to_ticks(&TIMER_LED, periode_ms);
  // config timer periode
  nrfx_timer_extended_compare(&TIMER_LED, NRF_TIMER_CC_CHANNEL1, time_ticks, NRF_TIMER_SHORT_COMPARE1_CLEAR_MASK, true);
  // start timer
  nrfx_timer_disable(&TIMER_LED);
  nrfx_timer_clear(&TIMER_LED);
  nrfx_timer_enable(&TIMER_LED);

}

Here is the handler function:

void timer_led_handler(nrf_timer_event_t ev_type, void* p_context){
  bsp_board_led_on(1);
}

In the main function, i have a rudimentary loop to blink another led

int main(void){

  log_init();
  
  bsp_board_init(BSP_INIT_LEDS | BSP_INIT_BUTTONS);

  gpio_init();

  timer_init(1000);

  /* Toggle LEDs. */
  while (true)
  {
      nrf_delay_ms(200);
      bsp_board_led_invert(0);

  }
}

The led 0 blink during approx. 1s and then remains off and the led 1 never turn on.

I'm using the SDK 15.3.0 59ac345 on a nRF52832 on a custom board and developping with ECLIPSE/GCC.

  • Hi,

    The led 0 blink during approx. 1s and then remains off and the led 1 never turn on.

    Since this happens in the main loop, LED 0 should always blink. Since it does not, it seems likely that your application is stuck in an event handler (directly or indirectly) somewhere. Have you tried to debug? If you halt the execution, where do you end up (remember to test with a debug build with optimization turned off when doing this)?

  • Hi,

    Thank you for your time. Meanwhile I've managed to get the app working but without the SoftDevice installed and the app located at 0x0000000 in the Flash. Also I get the the Timer to work with the ble_app_template with the SoftDevice (the app is located after the SoftDevice).

    Now if i put the Softdevice (S132) in the Flash and the app at 0x26000 (In the same conditions i was when i posted) then halt the system when no LEDs are blinking, I end up with this in the console

    Debugger requested to halt target...
    ...Target halted (PC = 0x00000A6E)
    Reading all registers
    Read 1 bytes @ address 0x00000000 (Data = 0x00)
    Reading register (PSP = 0x       0)
    Reading register (PRIMASK = 0x       0)

    I also set a breakpoint in the timer_led_handler() but it never reach it.

  • Hi,

    There is not much to go on, but clearly something happens. Can you start by building with DEBUG defined as well as logging enabled, and see if perhaps an error has been detected and the device is in the error handler? 

Related