Timer can not restart immediately when I call app_timer_stop() and app_timer_start() in timeout_handler.

Dear Nordic team,

I am maintain firmware on nRF51802QFAA with SDK12.3.

It starts a timer within 5 seconds interval, in timeout_handler, it will read sensor data via i2C, then save data in flash memory via SPI.

When it is connected by mobile phone, phone will request data which is stored in flash memory, device will restart timer with 100 milliseconds interval. In timeout_handler function, it will read flash data one by one and send to mobile phone quickly.

Unfortunately, almost every time, the timeout_handler can not be triggered immediately after I call app_timer_stop() and app_timer_start(). I wait for about 30 seconds or even longer time, then timeout_handler is triggered. After this, it can be triggered every 100ms correctly.

Note:

(1) I set SPI priority to 2, while timer and I2C priority is 3.  Because I found SPI transfer will be blocked if its priority is set to 3. I think it is competing for cpu resources with timer & I2C.

(2) I already tried to put app_timer_stop() and app_timer_start() in CRITICAL_REGION_ENTER() and CRITICAL_REGION_EXIT() to help timer restarting well. But it help just a little, can not make timer restart immediately every time.

Can you please figure out how to fix this problem?

Many thanks!

Bob

Parents Reply
  • I suggest that you try to comment out that line and see if you observe any difference Slight smile

    nrf_delays_us will make the CPU spin in a busy-wait loop. If called from main context then it will not block other interrupts with higher priorities, if called from interrupt context such as callback handlers, then it will most likely block other tasks.

    regards

    Jared 

Children
No Data
Related