Zephyr adc init in device tree versus runtime

I'm using the version 2.3.0 Zephyr toolchain. The chip is the nRF52832 and I'm setting up an ADC channel in the device tree overlay like so:

	channel@2 {
		reg = <2>;
		zephyr,gain = "ADC_GAIN_1_6";
		zephyr,reference = "ADC_REF_INTERNAL";
		zephyr,vref-mv = <750>;
		zephyr,acquisition-time = <ADC_ACQ_TIME_DEFAULT>;
		zephyr,input-positive = <NRF_SAADC_AIN2>;
		zephyr,resolution = <12>;
	};
	

At runtime, I get the device using this call:

    struct device * adc_dev = DEVICE_DT_GET(DT_NODELABEL(adc));
Which comes back non-NULL and ready.
Then I use the device in adc_read like so:
    uint16_t sample_buf[1] = {0};
    const struct adc_sequence seq = {
        .buffer = sample_buf,
        .buffer_size = buf_size,
        .channels = channel_mask,
        .resolution = 12,
    };
    int adc_result = adc_read( adc_dev , &seq );
    *result = sample_buf[0];
    if( adc_result == 0 ) {
        return MESSAGE_OK;
    } else {
        printk("ADC read error: %d\n",adc_result);
        return ADC_READ_ERROR;
    }
    
The error code coming back is -22 and the message is this:
<err> adc_nrfx_saadc: start_read: Channel 2 not configured
Now, I thought everything I need to configure for the channel is present in the device tree and I'm getting that device from DEVICE_DT_GET. But it seems that something is still not configured. What am I missing?
Parents Reply Children
No Data
Related