Hello, I am preparing a driver for the SAADC of nRF52832; I have to acquire data from five channels; consequently - in a scanning mode.
However, what I observed is that when having up to two channels enabled I can get data of them without a problem.
If I enable the third (or more than three) channels I am not able to get the data of the second channel.
What I am getting is perhaps the data of another channel, but I didn't investigate which one. I have seen a number of discussions in the dev zone referring to problems with data acquisition, swapping channel data, etc. in scanning mode.
I wonder whether my problem is also related to swapping data, and would appreciate any advice how to figure it out.
Additional information:
Rev.: QFAAB0
#define SAMPLES_IN_BUFFER 2
static nrf_saadc_value_t m_buffer_pool[SAMPLES_IN_BUFFER];
void saadc_init(void)
{
ret_code_t err_code;
nrf_drv_saadc_config_t saadc_config; // ADC general settings
nrf_saadc_channel_config_t channel_config; // individual ADC channel settings
//Configure SAADC
saadc_config.resolution = NRF_SAADC_RESOLUTION_12BIT; //Set SAADC resolution to 12-bit. This will make the SAADC output values from 0 (when input voltage is 0V) to 2^12=2048 (when input voltage is 3.6V for channel gain setting of 1/6).
saadc_config.oversample = NRF_SAADC_OVERSAMPLE_DISABLED; //Set oversample to 4x. This will make the SAADC output a single averaged value when the SAMPLE task is triggered 4 times.
saadc_config.interrupt_priority = APP_IRQ_PRIORITY_HIGH; //Set SAADC interrupt to low priority.
//Initialize SAADC
err_code = nrf_drv_saadc_init(&saadc_config, saadc_callback); //Initialize the SAADC with configuration and callback function. The application must then implement the saadc_callback function, which will be called when SAADC interrupt is triggered
APP_ERROR_CHECK(err_code);
//I. Configure SAADC channel - for the OA output
channel_config.reference = NRF_SAADC_REFERENCE_INTERNAL; // Set internal reference of fixed 0.6 volts
channel_config.gain = NRF_SAADC_GAIN1_6; // Set input gain to 1/6. The maximum SAADC input voltage is then 0.6V/(1/6)=3.6V. The single ended input range is then 0V-3.6V
channel_config.acq_time = NRF_SAADC_ACQTIME_40US; // Set acquisition time. Set low acquisition time to enable maximum sampling frequency of 200kHz. Set high acquisition time to allow maximum source resistance up to 800 kohm, see the SAADC electrical specification in the PS.
channel_config.mode = NRF_SAADC_MODE_SINGLE_ENDED; // Set SAADC as single ended. This means it will only have the positive pin as input, and the negative pin is shorted to ground (0V) internally.
channel_config.pin_p = NRF_SAADC_INPUT_AIN0; // Select the input pin for the channel. AIN0 pin maps to physical pin P0.02.
channel_config.pin_n = NRF_SAADC_INPUT_DISABLED; // Since the SAADC is single ended, the negative pin is disabled. The negative pin is shorted to ground internally.
channel_config.resistor_p = NRF_SAADC_RESISTOR_DISABLED; // Disable pullup resistor on the input pin
channel_config.resistor_n = NRF_SAADC_RESISTOR_DISABLED; // Disable pulldown resistor on the input pin
err_code = nrf_drv_saadc_channel_init(0, &channel_config); //Initialize SAADC channel 0 with the channel configuration
APP_ERROR_CHECK(err_code);
channel_config.pin_p = NRF_SAADC_INPUT_AIN1;
err_code = nrf_drv_saadc_channel_init(1, &channel_config); //Initialize SAADC channel 1 with the channel configuration
APP_ERROR_CHECK(err_code);
//channel_config.pin_p = NRF_SAADC_INPUT_AIN2;
//err_code = nrf_drv_saadc_channel_init(2, &channel_config); //Initialize SAADC channel 2 with the channel configuration
//APP_ERROR_CHECK(err_code);
//channel_config.pin_p = NRF_SAADC_INPUT_AIN4;
//err_code = nrf_drv_saadc_channel_init(3, &channel_config); //Initialize SAADC channel 4 with the channel configuration
//APP_ERROR_CHECK(err_code);
//channel_config.pin_p = NRF_SAADC_INPUT_AIN5;
//err_code = nrf_drv_saadc_channel_init(4, &channel_config); //Initialize SAADC channel 5 with the channel configuration
//APP_ERROR_CHECK(err_code);
err_code = nrf_drv_saadc_buffer_convert(m_buffer_pool,SAMPLES_IN_BUFFER); //Set SAADC buffer 1. The SAADC will start to write to this buffer
APP_ERROR_CHECK(err_code);
}
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;
int i;
printf("val: %d\r\n", p_event->data.done.p_buffer[1]);
.........
err_code = nrf_drv_saadc_buffer_convert(p_event->data.done.p_buffer, SAMPLES_IN_BUFFER);
APP_ERROR_CHECK(err_code);
}
}