在使用nRF的多通道AD转换时,p_event->data.done.p_buffer里的值对应的通道有时正确有时不正确,p_buffer[0]和p_buffer[1]里的值有时刚好和两个通道反过来了,是什么原因?
#define SAMPLES_IN_BUFFER 2
static nrf_saadc_value_t m_buffer_pool[2][SAMPLES_IN_BUFFER];
void saadc_callback(nrf_drv_saadc_evt_t const * p_event)
{
if (p_event->type == NRF_DRV_SAADC_EVT_DONE)
{
ret_code_t err_code;
err_code = nrf_drv_saadc_buffer_convert(p_event->data.done.p_buffer, SAMPLES_IN_BUFFER);
APP_ERROR_CHECK(err_code);
NRF_LOG_DEBUG("ADC event number: %d", (int)m_adc_evt_counter);
NRF_LOG_DEBUG("AIN1:%d AIN2:%d",p_event->data.done.p_buffer[0],p_event->data.done.p_buffer[1]);
m_adc_evt_counter++;
}
}
void saadc_init(void)
{
ret_code_t err_code;
nrf_saadc_channel_config_t channel_config_1 =
NRF_DRV_SAADC_DEFAULT_CHANNEL_CONFIG_SE(NRF_SAADC_INPUT_AIN1);
nrf_saadc_channel_config_t channel_config_2 =
NRF_DRV_SAADC_DEFAULT_CHANNEL_CONFIG_SE(NRF_SAADC_INPUT_AIN2);
err_code = nrf_drv_saadc_init(NULL, saadc_callback);
APP_ERROR_CHECK(err_code);
err_code = nrf_drv_saadc_channel_init(0, &channel_config_1);
APP_ERROR_CHECK(err_code);
err_code = nrf_drv_saadc_channel_init(1, &channel_config_2);
APP_ERROR_CHECK(err_code);
err_code = nrf_drv_saadc_buffer_convert(m_buffer_pool[0], SAMPLES_IN_BUFFER);
APP_ERROR_CHECK(err_code);
err_code = nrf_drv_saadc_buffer_convert(m_buffer_pool[1], SAMPLES_IN_BUFFER);
APP_ERROR_CHECK(err_code);
}