0
\$\begingroup\$

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:

  1. What is the difference between the arduino_adc vs the zephyr_user ADC?
  2. 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?
  3. 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;
  4. After I checked the pin assignment, it seems there is no analog out. I am wondering why is that or maybe I missed something.
\$\endgroup\$
3
  • \$\begingroup\$ I am surprised that there is no Zephyr tag :) \$\endgroup\$
    – r0n9
    Commented Oct 18, 2022 at 20:14
  • \$\begingroup\$ I suggest asking this at Nordic’s forum instead, devzone.nordicsemi.com . They support that SDK there. \$\endgroup\$ Commented Oct 19, 2022 at 4:50
  • \$\begingroup\$ @MarkLeavitt Thanks for your suggestion. And yes, I did ask in the Nordic DevZone before I post this question here. Just give it a try here. \$\endgroup\$
    – r0n9
    Commented Oct 19, 2022 at 22:03

1 Answer 1

1
\$\begingroup\$

How can I initialize the other pins using the device tree?

Duplicate what you already have for adc_0 or 1 or 7, then make the reg = <1> and the channel@1 lines match the other channel numbers you want to use (valid range 0-7)

I would suggest you get the nrf52840 "product spec" pdf from the Nordic website, and read the chapter on the SAADC peripheral.... then nearly all of the named labels will make sense to you (gain, positive and negative input etc)

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.