I am trying to understand the ADC
example using PCA10056.
In the DT file, there are two different ADCs in the device tree arduino_adc
and zephyr,user
:
adc: adc@40007000 {
compatible = "nordic,nrf-saadc";
reg = <0x40007000 0x1000>;
interrupts = <7 NRF_DEFAULT_IRQ_PRIORITY>;
status = "okay";
#io-channel-cells = <1>;
#address-cells = <1>;
#size-cells = <0>;
channel@0 {
reg = <0>;
zephyr,gain = "ADC_GAIN_1_6";
zephyr,reference = "ADC_REF_INTERNAL";
zephyr,acquisition-time = <ADC_ACQ_TIME_DEFAULT>;
zephyr,input-positive = <NRF_SAADC_AIN1>;
zephyr,resolution = <12>;
};
channel@1 {
reg = <1>;
zephyr,gain = "ADC_GAIN_1_6";
zephyr,reference = "ADC_REF_INTERNAL";
zephyr,acquisition-time = <ADC_ACQ_TIME_DEFAULT>;
zephyr,input-positive = <NRF_SAADC_VDD>;
zephyr,resolution = <14>;
zephyr,oversampling = <8>;
};
channel@7 {
reg = <7>;
zephyr,gain = "ADC_GAIN_1_5";
zephyr,reference = "ADC_REF_VDD_1_4";
zephyr,vref-mv = <750>;
zephyr,acquisition-time = <ADC_ACQ_TIME_DEFAULT>;
zephyr,input-positive = <NRF_SAADC_AIN6>;
zephyr,input-negative = <NRF_SAADC_AIN7>;
zephyr,resolution = <12>;
};
};
...
arduino_adc: analog-connector {
compatible = "arduino,uno-adc";
#io-channel-cells = <1>;
io-channel-map = <0 &adc 1>,
<1 &adc 2>,
<2 &adc 4>,
<3 &adc 5>,
<4 &adc 6>,
<5 &adc 7>;
};
zephyr,user {
io-channels = <&adc 0>, <&adc 1>, <&adc 7>;
};
I can see the following code that initializes 3 zephyr_user
channels
#if !DT_NODE_EXISTS(DT_PATH(zephyr_user)) || \
!DT_NODE_HAS_PROP(DT_PATH(zephyr_user), io_channels)
#error "No suitable devicetree overlay specified"
#endif
#define DT_SPEC_AND_COMMA(node_id, prop, idx) \
ADC_DT_SPEC_GET_BY_IDX(node_id, idx),
/* Data of ADC io-channels specified in devicetree. */
static const struct adc_dt_spec adc_channels[] = {
DT_FOREACH_PROP_ELEM(DT_PATH(zephyr_user), io_channels,
DT_SPEC_AND_COMMA)
};
I have the following questions regarding the DT and the initialization code:
- What is the difference between the
arduino_adc
vs thezephyr_user
ADC? - Based on the PCA10056 pin assignment(https://infocenter.nordicsemi.com/index.jsp?topic=%2Fps_nrf52840%2Fpin.html), AIN0 - AIN7 are analog input pins if I would like to use pins other than 0, 1, and 7. How can I initialize the other pins using the device tree?
- Can anyone helps me understand the following properties in the node
adc@40007000
?
zephyr,gain;
zephyr,reference;
zephyr,vref-mv;
zephyr,acquisition-time;
zephyr,input-positive;
zephyr,input-negative;
zephyr,oversampling = <8>; // Is this mean the result is an average of 8 sample values?
zephyr,resolution; - After I checked the pin assignment, it seems there is no analog out. I am wondering why is that or maybe I missed something.
Zephyr
tag :) \$\endgroup\$