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
#define APP_TIMER_CONFIG_IRQ_PRIORITY 2
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?
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).
Many thanks for your support! :)