I was trying to build off of the example of Lesson 6, exercise 3 from the Intermediate course on DevAcademy.
In this example, the AN0 is sampled the amount of times set by SAADC_BUFFER_SIZE (8000).
In my application, I am trying to sample on more than 1 pin. Is it possible to do scan multiple pins with the PPI?
Ideally, I would like to monitor, AN2 and AN3. In some circumstances, I want to monitor AN2, AN3, AN5, and AN6.
I tried to modify the example as such but it reports 0bad0004
/* STEP 4.6 - Declare the struct to hold the configuration for the SAADC channel used to sample the battery voltage */
nrfx_saadc_channel_t channel_2 = NRFX_SAADC_DEFAULT_CHANNEL_SE(NRF_SAADC_INPUT_AIN2, 0);
nrfx_saadc_channel_t channel_3 = NRFX_SAADC_DEFAULT_CHANNEL_SE(NRF_SAADC_INPUT_AIN3, 0);
/* STEP 4.7 - Change gain config in default config and apply channel configuration */
channel_2.channel_config.gain = NRF_SAADC_GAIN1_6;
err = nrfx_saadc_channels_config(&channel_2, 0);
if(err != NRFX_SUCCESS)
{
printk("nrfx_saadc_channels_config error\r\n");
// LOG_ERR("nrfx_saadc_channels_config error: %08x", err);
return;
}
channel_3.channel_config.gain = NRF_SAADC_GAIN1_6;
err = nrfx_saadc_channels_config(&channel_3, 1);
if(err != NRFX_SUCCESS)
{
printk("nrfx_saadc_channels_config error\r\n");
// LOG_ERR("nrfx_saadc_channels_config error: %08x", err);
return;
}
/* STEP 4.8 - Configure channel 0 in advanced mode with event handler (non-blocking mode) */
nrfx_saadc_adv_config_t saadc_adv_config = NRFX_SAADC_DEFAULT_ADV_CONFIG;
err = nrfx_saadc_advanced_mode_set(BIT(2)|BIT(3),
NRF_SAADC_RESOLUTION_12BIT,
&saadc_adv_config,
saadc_event_handler);
if(err != NRFX_SUCCESS)
{
printk("nrfx_saadc_advanced_mode_set error %08x\r\n", err);
// LOG_ERR("nrfx_saadc_advanced_mode_set error: %08x", err);
return;
}
Any advice?