Hello,
I'm running the nRF Mesh SDK 5.0.0 with the light CTL LC server example. I have also developed an implementation of a DALI master. DALI is a manchester encoded signal which runs at 1200baud. This means that the signal has a period of 416us. A dali command consists out of 2 bytes with some start and stop bits. To implement this DALI signal I use timer3 which I initialize as follows:
nrfx_timer_config_t tx_tmr_cfg = {
.frequency = (nrf_timer_frequency_t) NRFX_TIMER_DEFAULT_CONFIG_FREQUENCY,
.mode = (nrf_timer_mode_t) NRFX_TIMER_DEFAULT_CONFIG_MODE,
.bit_width = (nrf_timer_bit_width_t) NRFX_TIMER_DEFAULT_CONFIG_BIT_WIDTH,
.interrupt_priority = 2,
.p_context = NULL
};
err_code = nrfx_timer_init(&DALI_TX_TIMER, &tx_tmr_cfg, _dali_tx_tick_handler);
if(err_code != NRF_SUCCESS) {
__LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "[DALI] Could not initialize TX timer: %d\n", err_code);
return err_code;
}
uint32_t time_ticks = nrfx_timer_us_to_ticks(&DALI_TX_TIMER, 416);
nrfx_timer_extended_compare(&DALI_TX_TIMER, NRF_TIMER_CC_CHANNEL0, time_ticks, NRF_TIMER_SHORT_COMPARE0_CLEAR_MASK, true);
The tick handler looks as follows:
static void _dali_tx_tick_handler(nrf_timer_event_t event_type, void* p_contex)
{
if(event_type != NRF_TIMER_EVENT_COMPARE0) {
return;
}
//bitbanging stuff
//when ready the timer is disabled
if(frame_complete) {
nrfx_timer_disable(&DALI_TX_TIMER);
}
}
The above code works perfectly when bluetooth is not enabled. But when Bluetooth is on and there is active mesh communication the timer interrupt is not consistent anymore. Sometimes the 416us period is only in the tens of microseconds but other times it is more than 20ms.
I think that the timer interrupt is interrupted by the softdevice. This breaks my DALI signal and the DALI drivers stop responding.
I have tried the following things:
- I tried every priority between 0 and 6.
- I tried using the app_timer (RTC based) but this was even worse.
Is there any option to solve this issue. In my head an option would be that there is an API in which we reserve a window of for example 5ms in which we know we will not be interrupted.