I need twoADC channels. I tried to configure using :
CONFIG_ADC= y in prj file,
&adc{
#io-channel-cells = < 0x2 >;
}; in overlay file .. the compile error appears as shown in atteched iamge.
Gulzar Singh

I need twoADC channels. I tried to configure using :
CONFIG_ADC= y in prj file,
&adc{
#io-channel-cells = < 0x2 >;
}; in overlay file .. the compile error appears as shown in atteched iamge.
Gulzar Singh

Hello,
SAADC supports 8 channels- One cannel per single-ended input and two channels per differential input. So, If you want two single-ended inputs- you need to create two separate channel configurations; one for AIN0 and one for AIN1 for instance. It has to be defined from the main.c file. Also if you intend to do periodic sample using PPI or collect the sample as part of interrupt handling like this example I linked before https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/zephyr/reference/peripherals/adc.html?highlight=adc_channel_cfg#c.adc_channel_cfg ; you have to define this in C file.
Best Regards,
Kazi Afroza Sultana
Hi, I created an application for testng the sampling of 2 channels on AIN0 and AIN1. The files are attached. I have few doubts.
1. In the adc.h, is #define BUFFER_SIZE 2 right or wrong to sample 2 analog channels ? If in future, 3 chhannels are required, may I set #define BUFFER_SIZE 3.
2. In the main file, I adc instantiated by binding and then, set up channels using err = adc_channel_setup() .. function. Is it proper way ?
3. As, I copied the most coe from sample program, what is meaning of following ?
#if defined (CONFIG_BOARD_BMS_NRF5340_CPUAPP)
NRF_SAADC->TASKS_CALIBRATEOFFSET = 1;
4. I wrote two sample functions, as in adc.c. Is this proper way to add to sequence ? If, wrong any where, may you make changes and attache corrected code file ?
5. I called adc sampling functions in repeatitive timer. Is the result of adc from AIN0 and AIN1 be avaialble at same index or at different indices in p_sample_buffer[].


Gulzar Singh
Hi, I created an application for testng the sampling of 2 channels on AIN0 and AIN1. The files are attached. I have few doubts.
1. In the adc.h, is #define BUFFER_SIZE 2 right or wrong to sample 2 analog channels ? If in future, 3 chhannels are required, may I set #define BUFFER_SIZE 3.
2. In the main file, I adc instantiated by binding and then, set up channels using err = adc_channel_setup() .. function. Is it proper way ?
3. As, I copied the most coe from sample program, what is meaning of following ?
#if defined (CONFIG_BOARD_BMS_NRF5340_CPUAPP)
NRF_SAADC->TASKS_CALIBRATEOFFSET = 1;
4. I wrote two sample functions, as in adc.c. Is this proper way to add to sequence ? If, wrong any where, may you make changes and attache corrected code file ?
5. I called adc sampling functions in repeatitive timer. Is the result of adc from AIN0 and AIN1 be avaialble at same index or at different indices in p_sample_buffer[].


Gulzar Singh
Hello Gulzar,
I have started looking at your files. Could you please send me the whole project so I can try to reproduce it?
Best Regards,
Kazi Afroza Sultana
Hi, here is the code in attached file.

I mean the project folder which contain build file, configure file, cmakelist text file and source file. like the following screenshot:

Hi, I just need answer of three queries as shown in attached image.
Hello,
1. In the adc.h, if #define BUFFER_SIZE 2 right or wrong to sample 2 analog channels ? If in future, 3 chhannels are required, may I set #define BUFFER_SIZE 3.
The buffer size should be set to N*number of enabled channels, as SCAN mode will sample each channel subsequently and put the result in the RAM buffer as described here: https://infocenter.nordicsemi.com/topic/ps_nrf5340/saadc.html?cp=3_0_0_6_28_4_3#saadc_operationmodes_scan. If you set a buffer size that does not match the number of enabled channels, you will miss samples, or samples will be stored in the buffer in non-deterministic order.
2. In the main file, I adc instantiated by binding and then, set up channels using err = adc_channel_setup() .. function. Is it proper way ?
yes it is.
3. '' #if defined (CONFIG_BOARD_BMS_NRF5340_CPUAPP)
NRF_SAADC->TASKS_CALIBRATEOFFSET = 1''
this task will start offset auto-calibration in SAADC peripheral.
4. I wrote two sample functions, as in adc.c. Is this proper way to add to sequence ? If, wrong any where, may you make changes and attached corrected code file ?
It is ok. I have added a sample code where 2 channels are used. you can look at this as reference. 
5. I called adc sampling functions in repeatitive timer. Is the result of adc from AIN0 and AIN1 be avaialble at same index or at different indices in p_sample_buffer[]
Indexes will be different if both channels are enabled at once and scan mode are used. p_sample_buffer[] will have different values.
Regards,
Kazi Afroza Sultana