Hello,
status = "okay";
};
compatible = "nordic,nrf-spim";
status = "okay";
sck-pin = <13>;
mosi-pin = <09>;
miso-pin = <40>;
};
Hello,
Hi learner,
In the NCS tutorial you can see how to add a ADC peripheral to your project.
For the .dts you could use "io-channels" as shown here.
Also here is a simple unofficial ADC sample that may be of help.
Hi Martin,
Thank you for your answer. I did go through the Tutorial Part 2 where the ADC is NOT configured via the .dts file. So, the idea of using io-channels in the .dts file is what I am interested in. I have read some of it and I am not sure I get it. So, I am going to have a go at changing the sample of the light intensity controller in Tutorial 2 and use the .dts file and see if I can get it to work. I will probably need your help at some point to get it to work.
Thank you for your support.
Hi Learner,
Sounds good. Please let me know how it goes, or if you have some additional questions that come up.
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.
I have assumed that the number 4 in the line below is the pin number P0.04 which corresponds to adc channel AIN0. Is this right?
io-channels = <&adc0 4>;