Hi everyone,
We have three ADC channels, two of them are implemented as a simple ADC without oversampling, the third one uses oversampling. Because one of them use oversampling the adc_uninit() method has to be called firstly when a transition is required
static void adc_uninit(void)
{
//nrf_drv_saadc_abort();
if(m_mass.adc_state == OVERSAMPLING)
{
nrf_drv_saadc_channel_uninit(LOAD_CELL_CHANNEL);
}
else if(m_mass.adc_state == NORMAL)
{
nrf_drv_saadc_channel_uninit(TEMPERATURE_CHANNEL);
nrf_drv_saadc_channel_uninit(BATTERY_CHANNEL);
}
nrf_drv_saadc_uninit();
m_mass.adc_state = NONE;
}
and after that, the saadc_oversampling_init(void) or adc_init() method is executed depends on the request inserted in the particular characteristic. After one or two switches it happens that (when oversampling_init is called) in method mass_test() function nrf_drv_saadc_sample() return 8. I know that this indicates that ADC is not busy but I do not know why this situation occurs. I will appreciate any help. The program uses Softdevice s112 and SDKv16.00. It is very interesting that the program works fine on nrf52832 but not on nrf52811.
static void saadc_oversampling_init(void)
{
if(m_mass.adc_state == NONE)
{
ret_code_t err_code = NRF_SUCCESS;
nrf_saadc_channel_config_t channel_config = NRF_DRV_SAADC_DEFAULT_CHANNEL_CONFIG_SE(NRF_SAADC_INPUT_AIN2);
channel_config.gain = NRF_SAADC_GAIN1_3;
channel_config.burst = NRF_SAADC_BURST_ENABLED;
nrfx_saadc_config_t default_config = NRFX_SAADC_DEFAULT_CONFIG;
default_config.oversample = NRF_SAADC_OVERSAMPLE_128X;
default_config.resolution = NRF_SAADC_RESOLUTION_12BIT;
default_config.interrupt_priority = APP_IRQ_PRIORITY_LOW;
err_code = nrf_drv_saadc_init(&default_config, saadc_callback)
APP_ERROR_CHECK(err_code);
err_code = nrf_drv_saadc_channel_init(LOAD_CELL_CHANNEL, &channel_config);
APP_ERROR_CHECK(err_code);
m_mass.adc_state = OVERSAMPLING;
}
}
static void adc_init(void)
{
if(m_mass.adc_state == NONE)
{
ret_code_t err_code = NRF_SUCCESS;
nrf_saadc_channel_config_t channel_config2 = NRF_DRV_SAADC_DEFAULT_CHANNEL_CONFIG_SE(NRF_SAADC_INPUT_AIN6);
channel_config2.gain = NRF_SAADC_GAIN1_3;
err_code = nrf_drv_saadc_channel_init(BATTERY_CHANNEL, &channel_config2);
APP_ERROR_CHECK(err_code);
nrf_saadc_channel_config_t channel_config3 = NRF_DRV_SAADC_DEFAULT_CHANNEL_CONFIG_SE(NRF_SAADC_INPUT_AIN3);
channel_config3.gain = NRF_SAADC_GAIN1_3;
err_code = nrf_drv_saadc_channel_init(TEMPERATURE_CHANNEL, &channel_config3);
APP_ERROR_CHECK(err_code);
nrfx_saadc_config_t default_config = NRFX_SAADC_DEFAULT_CONFIG;
default_config.resolution = NRF_SAADC_RESOLUTION_10BIT;
default_config.oversample = NRF_SAADC_OVERSAMPLE_DISABLED;
err_code = nrf_drv_saadc_init(&default_config, saadc_callback);
APP_ERROR_CHECK(err_code);
m_mass.adc_state = NORMAL;
}
}
static void mass_test()
{
uint32_t err_code;
m_mass.test_counter++;
if(m_mass.test_counter == 1)
{
adc_uninit();
saadc_oversampling_init();
err_code = app_timer_start(testing_peripheral_units_id, INTERVAL_1000MS ,NULL);
APP_ERROR_CHECK(err_code);
}
else if(m_mass.test_counter == 2)
{
err_code = nrf_drv_saadc_buffer_convert(buffer, 1);
APP_ERROR_CHECK(err_code);
err_code = nrf_drv_saadc_sample();
APP_ERROR_CHECK(err_code);
err_code = app_timer_start(testing_peripheral_units_id, INTERVAL_1000MS ,NULL);
APP_ERROR_CHECK(err_code);
}
else if(m_mass.test_counter == 3)
{
m_mass.test_counter = 1;
err_code = app_timer_start(testing_peripheral_units_id, INTERVAL_1000MS ,NULL);
APP_ERROR_CHECK(err_code);
}
}