This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

How to configure the adc periheral in the Device Tree file *.dts

Hello,

I am trying to figure out a way to configure the adc node using the .dts Device Tree file in a similar way to what is done for other nodes such as &spi and &i2c.
Unfortunately, all the examples I have seen so far only set the status property for the adc node. I would like to add GPIO pin numbers, resolution, etc ...
Any suggestions?
&adc {
status = "okay";
};
&spi1 {
compatible = "nordic,nrf-spim";
status = "okay";
sck-pin = <13>;
mosi-pin = <09>;
miso-pin = <40>;
};
Thank you.
Parents Reply
  • Hi Martin,

    In NCS Tutorial Part 2- the light intensity controller, there is this section of #defines for the ADC.

    /*ADC definitions and includes*/
    #include <hal/nrf_saadc.h>
    #define ADC_DEVICE_NAME DT_LABEL(DT_INST(0, nordic_nrf_saadc))
    #define ADC_RESOLUTION 10
    #define ADC_GAIN ADC_GAIN_1_6
    #define ADC_REFERENCE ADC_REF_INTERNAL
    #define ADC_ACQUISITION_TIME ADC_ACQ_TIME(ADC_ACQ_TIME_MICROSECONDS, 10)
    #define ADC_1ST_CHANNEL_ID                     0
    #define ADC_1ST_CHANNEL_INPUT              NRF_SAADC_INPUT_AIN0

    Since I am configuring the adc channels using the .overlay with io-channels as you suggested file as follows,

    adc0: adc@4000E000 {
           label = "ADC_0";
    };

    n: node {
           io-channels = <&adc0 4>;
           io-channel-names = "AIN_0"";
    };

    I think these two lines are not needed anymore, am I right?

    #define ADC_1ST_CHANNEL_ID                    0
    #define ADC_1ST_CHANNEL_INPUT             NRF_SAADC_INPUT_AIN0

    But I am not sure how the information in the .overlay file will get used by the C code. 

    Could you please advise on what changes I need to make to the C code to make it use the new info in the overlay file.

    Thank you.

Children
Related