ADC

hello

I try to make work the ADC on the NRF52840DK

I would like to use any of the 6 channels on the ARDUINO connector (p0.3, p0.4, p0.28-p0.31)

I am simply not able to make the code work. The only channel that works is channel 1. The project can be found here:

https://drive.switch.ch/index.php/s/NXyb6rleEa9Mcc2

It is an entire workspace. You may open the project through the workspace file.

Any help is apreciated.

/medard

Parents
  • If you are using NCS, you would have to use Zephyr's devicetree overlay to set the pin number. Here's one that I have tested myself

    / {
    	zephyr,user {
    		io-channels = <&adc 0>;
    	};
    };

    Here, you can use <&adc 0>; replacing 0 with whatever pin number you want.

    In your code file, you can use these defines

    #define ADC_CHANNEL          DT_IO_CHANNELS_INPUT_BY_IDX(DT_PATH(zephyr_user), 0)
    #define ADC_NODE		     DT_PHANDLE(DT_PATH(zephyr_user), io_channels)
    #define ADC_NUM_CHANNELS	 DT_PROP_LEN(DT_PATH(zephyr_user), io_channels)

    You can use the ADC example provided in NCS for the rest, as I used the same code on my side. 

    Hope this helps Slight smile

Reply
  • If you are using NCS, you would have to use Zephyr's devicetree overlay to set the pin number. Here's one that I have tested myself

    / {
    	zephyr,user {
    		io-channels = <&adc 0>;
    	};
    };

    Here, you can use <&adc 0>; replacing 0 with whatever pin number you want.

    In your code file, you can use these defines

    #define ADC_CHANNEL          DT_IO_CHANNELS_INPUT_BY_IDX(DT_PATH(zephyr_user), 0)
    #define ADC_NODE		     DT_PHANDLE(DT_PATH(zephyr_user), io_channels)
    #define ADC_NUM_CHANNELS	 DT_PROP_LEN(DT_PATH(zephyr_user), io_channels)

    You can use the ADC example provided in NCS for the rest, as I used the same code on my side. 

    Hope this helps Slight smile

Children
No Data
Related