Hi,
To decrease the load on the system I would like to periodically send some BT data (and do some SD card writing).
Since Timer 0 is used by the soft device, I am using Timer 1 as follows:
const nrf_drv_timer_t timer = NRF_DRV_TIMER_INSTANCE(1);
static void initBLE() {
uint32_t error;
nrf_clock_lf_cfg_t clock_lf_cfg = {
.source = NRF_CLOCK_LF_SRC_RC,
.rc_ctiv = 4,
.rc_temp_ctiv = 1
};
SOFTDEVICE_HANDLER_INIT(&clock_lf_cfg, NULL);
ble_enable_params_t ble_enable_params;
error = softdevice_enable_get_default_config(CENTRAL_LINK_COUNT, PERIPHERAL_LINK_COUNT, &ble_enable_params);
_error("softdevice_enable_get_default_config", error);
#if (NRF_SD_BLE_API_VERSION == 3)
ble_enable_params.gatt_enable_params.att_mtu = NRF_BLE_MAX_MTU_SIZE;
#endif
error = softdevice_enable(&ble_enable_params);
_error("softdevice_enable", error);
error = softdevice_ble_evt_handler_set(onBLE);
_error("softdevice_ble_evt_handler_set", error);
}
void onTimer(nrf_timer_event_t event_type, void *p_context) {
...
}
int main(void) {
...
nrf_drv_timer_config_t timer_cfg = NRF_DRV_TIMER_DEFAULT_CONFIG;
timer_cfg.frequency = NRF_TIMER_FREQ_31250Hz;
timer_cfg.bit_width = NRF_TIMER_BIT_WIDTH_16;
error = nrf_drv_timer_init(&timer, &timer_cfg, onTimer);
uint32_t ticks = nrf_drv_timer_ms_to_ticks(&timer, 100);
nrf_drv_timer_extended_compare(&timer, NRF_TIMER_CC_CHANNEL0, ticks, NRF_TIMER_SHORT_COMPARE0_CLEAR_MASK, true);
nrf_drv_timer_enable(&timer);
_error("nrf_drv_timer_init", error);
...
initBLE();
...
}
There is no specific error thrown, but the following things happen:
- (Usually) the timer is executed perfectly fine at an interval of 100 ms for a short period (~1 - 3 minutes)
- After some time onTimer gets executed very often (+10 x per second) and suddenly softdevice functions which get called all the time are returning errors
This of course interferes with the rest of my code and some other things may stop working properly as well (SPI, UART), but I haven't noticed.
When I disable the timer (comment out "nrf_drv_timer_enable"), all problems described are gone.
What could be the problem?
Oh, and I'm not using a 32.768 kHz crystal, but am using the 16 Mhz derived clock.