Hello, I am using the nRF connect SDK and am currently running into some issues with using the on board ADC. My issue relates to the adc_channel_setup function which returns an error 22 (Invalid Argument). Despite this I can't find the source of this error. My config struct can be seen below as well as how I am getting the device:
#include <zephyr.h>
#include <device.h>
#include <drivers/gpio.h>
#include <drivers/adc.h>
#define ADC_DEVICE_NAME DT_LABEL(DT_ALIAS(adcctrl))
#define DEFAULT_ACQ_TIME ADC_ACQ_TIME(ADC_ACQ_TIME_MICROSECONDS, 30)
static const struct device *adc_device;
static int16_t buffer[8];
const static struct adc_channel_cfg adc_config = {
.gain = ADC_GAIN_1_6,
.reference = ADC_REF_INTERNAL,
.acquisition_time = DEFAULT_ACQ_TIME,
.channel_id = 0,
.differential = 0,
#if CONFIG_ADC_CONFIGURABLE_INPUTS
.input_positive = 1,
#endif
};
uint8_t adc_setup() {
adc_device = device_get_binding(ADC_DEVICE_NAME);
if (!adc_device) {
printk("Failed to get ADC Device\n\r");
}
int8_t error_code = adc_channel_setup(adc_device, &adc_config);
...
}
For reference I am using an nRF52810 DK with the following config file:
CONFIG_I2C=y CONFIG_ADC=y CONFIG_ADC_ASYNC=y CONFIG_SPI=y
Does anything stand out as to what may be going wrong/what I have entered that is incorrect?