基于BLE下使用NRF sdk中SAADC多通道扫描时,会发现在高速扫描下(比如4通道8k/s扫描),开启蓝牙时很快就会发现通道数据紊乱,经本人实测,ADC采样并没有错,只是缓存数组里的数据错位了。这个问题产生的根本原因和解决办法参考官方论坛
https://devzone.nordicsemi.com/f/nordic-q-a/63074/buffer-order-swap-of-saadc-used-with-nrf-mesh;https://github.com/crownstone/bluenet/blob/6ad42e77e06d675ff63fdff8f8fab2484d656ea1/docs/ADC.md;https://devzone.nordicsemi.com/f/nordic-q-a/20291/offset-in-saadc-samples-with-easy-dma-and-ble;
解决办法:
就是在saadc_sampling_event_init();//PPI联结函数里,末尾再添加一个PPI联结,同时,屏蔽nrfx_saadc.c第128行
126: if (!m_cb.low_power_mode)
127: {
128: //nrf_saadc_task_trigger(NRF_SAADC_TASK_START);
129: };
PPI联结代码:
void saadc_sampling_event_init(void)
{
ret_code_t err_code;
err_code = nrf_drv_ppi_init();
APP_ERROR_CHECK(err_code);
nrf_drv_timer_config_t timer_cfg = NRF_DRV_TIMER_DEFAULT_CONFIG;
timer_cfg.bit_width = NRF_TIMER_BIT_WIDTH_32;
timer_cfg.frequency = NRF_TIMER_FREQ_16MHz;
err_code = nrf_drv_timer_init(&m_timer, &timer_cfg, timer_handler);
APP_ERROR_CHECK(err_code);
/* setup m_timer for compare event every 50 us */
uint32_t ticks = nrf_drv_timer_us_to_ticks(&m_timer, 50);
nrf_drv_timer_extended_compare(&m_timer,
NRF_TIMER_CC_CHANNEL1,
ticks,
NRF_TIMER_SHORT_COMPARE1_CLEAR_MASK,
false);
nrf_drv_timer_enable(&m_timer);
uint32_t timer_compare_event_addr = nrf_drv_timer_compare_event_address_get(&m_timer,
NRF_TIMER_CC_CHANNEL1);
uint32_t saadc_sample_task_addr = nrf_drv_saadc_sample_task_get();
/* setup ppi channel so that timer compare event is triggering sample task in SAADC */
err_code = nrf_drv_ppi_channel_alloc(&m_ppi_channel);
APP_ERROR_CHECK(err_code);
err_code = nrf_drv_ppi_channel_assign(m_ppi_channel,
timer_compare_event_addr,
saadc_sample_task_addr);
APP_ERROR_CHECK(err_code);
/////////////////////////////////////添加PPI联结SAADC END和START事件//////////////////////////////////////////
nrf_ppi_channel_t saadc_buffer_swap_ppi_channel;
nrf_drv_ppi_channel_alloc(&saadc_buffer_swap_ppi_channel);
nrf_drv_ppi_channel_assign(saadc_buffer_swap_ppi_channel,
(uint32_t)&NRF_SAADC->EVENTS_END,
(uint32_t)&NRF_SAADC->TASKS_START);
nrf_drv_ppi_channel_enable(saadc_buffer_swap_ppi_channel);
}
目前没有再出现通道串位