Timer interrupt priority and BLE connection

leoc7 gravatar image

asked 2018-01-12 09:31:19 +0100

Hi all,

My configuration:

  • nrf52832 microcontroller
  • Softdevice S132 V4.0.2
  • Nordic SDK 13.0

I'm using an "app_timer" in repeated mode with 10Hz frequency.

#define M_10HZ_TIMER_VALUE  APP_TIMER_TICKS(100) /* 10Hz  = 100ms */


app_timer_create(&m_10Hz_timer_id, APP_TIMER_MODE_REPEATED, m_10Hz_timer_handler);

app_timer_start(m_10Hz_timer_id, M_10HZ_TIMER_VALUE, NULL);

The timer handler (m_10Hz_timer_handler) is a function that execute a complex mathematical algorithm (no use of peripherals).

This handler function is time critical and it's necessary that its interval execution is precise and guaranteed.

In order to obtain this, I set app_timer priority high as possible:

 // <i> Priorities 0,2 (nRF51) and 0,1,4,5 (nRF52) are reserved for SoftDevice
// <0=> 0 (highest) 
// <1=> 1 
// <2=> 2 
// <3=> 3 
// <4=> 4 
// <5=> 5 
// <6=> 6 
// <7=> 7 


I tried with priority 2 and 3.

Problem: BLE connection is not stable, if I set priority 2 or 3.

How can I solve this? Is there any way to set timer with high priority and guaranteed the stability of BLE connection?


edit retag flag offensive close delete report spam

1 answer

Sort by » oldest newest most voted
ovrebekk gravatar image

answered 2018-01-12 16:03:15 +0100


What is the run time of your algorithm, and the connection interval of your BLE connection?

All the host processing in the BLE stack (everything above the link layer, such as the GAP and the GATT) will run in priorities 4 and 5, and if this processing is significantly delayed it could affect the operation of the stack.

When using the app_timer to schedule long running functions it is recommended to defer the execution to main context first (by using the app_scheduler module, or setting a flag in the timer callback that you check in the main loop).

Best regards
Torbjørn Øvrebekk

edit flag offensive delete publish link more


Many thanks for your support! :)

leoc7 ( 2018-01-12 17:26:10 +0100 )editconvert to answer

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer. Do not ask a new question or reply to an answer here.

[hide preview]

Question Tools

1 follower


Asked: 2018-01-12 09:31:19 +0100

Seen: 49 times

Last updated: jan. 12