I'm trying to do an ADC measurement on AIN6 on an nRF52832. This is how I have things set up:
proj.conf:
#ADC/Comparator CONFIG_ADC=y CONFIG_NRFX_COMP=y
Overlay file:
/ { zephyr,user { io-channels = <&adc 6>; }; &adc { #address-cells = <1>; #size-cells = <0>; channel@6 { reg = <6>; zephyr,gain = "ADC_GAIN_1_6"; zephyr,reference = "ADC_REF_INTERNAL"; zephyr,acquisition-time = <ADC_ACQ_TIME_DEFAULT>; zephyr,input-positive = <NRF_SAADC_AIN6>; /* P0.30 */ zephyr,resolution = <12>; zephyr,oversampling = <4>; }; };
ADC initialisation (this gets called on power up of the chip)
void adc_init (void) { int8_t ret; if (!device_is_ready(adc_chan6.dev)) { LOG_ERR("ADC device not found"); return; } // Setup ADC ret = adc_channel_setup_dt(&adc_chan6); if (ret < 0) { LOG_ERR("ADC channel set up failed"); return; } ret = adc_sequence_init_dt(&adc_chan6, &sequence); if (ret < 0) { LOG_ERR("ADC channel sequence init failed"); return; } }
And firmware:
const struct adc_dt_spec adc_chan6 = ADC_DT_SPEC_GET_BY_IDX(DT_PATH(zephyr_user), 0); struct adc_sequence sequence = { .buffer = &sample_buffer, .buffer_size = sizeof(sample_buffer), }; void counter_callback(const struct device *dev, void *user_data) { if (sample_count < MAX_NUM_SAMPLES) { err = adc_read(adc_chan6.dev, &sequence); if (err < 0) { LOG_ERR("Could not read (%d)", err); } adc_samples[sample_count] = sample_buffer; sample_count++; } else { sampling_complete = true; } }
I've got a counter set up to trigger an ADC read every ~ 300usec, and I take 32 samples. Problem I am having is that the ADC read is returning error -11. According to errno.h, this equates to EAGAIN, and there isn't any explanation on what that actually means, so I'm not exactly sure what I need to be doing to fix it.
Can anyone explain what this error is indicating? And is there anything in my ADC setup that would indicate why I'm gettting this error?
Cheers,
Mike