<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Setting up multiple ADC channels in the device tree</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/89015/setting-up-multiple-adc-channels-in-the-device-tree</link><description>Hi, 
 
 I am working on setting up multiple ADC channels in the device tree. My starting point is here , which seemed to be an unofficial ADC example that many ADC-related posts referred to. 
 I can make it work for a single-ended mode as well as a differential</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 21 Jul 2022 13:56:50 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/89015/setting-up-multiple-adc-channels-in-the-device-tree" /><item><title>RE: Setting up multiple ADC channels in the device tree</title><link>https://devzone.nordicsemi.com/thread/378135?ContentTypeID=1</link><pubDate>Thu, 21 Jul 2022 13:56:50 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:06717380-d99e-43f8-b325-fa2307ee9237</guid><dc:creator>Ted H</dc:creator><description>&lt;p&gt;Hi Carl,&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Thank you for the reply. In fact, I used the DT macro to enable the GPIO pins but was unsuccessful with the ADC stuff. The only relevant part was:&lt;/p&gt;
&lt;div&gt;
&lt;div&gt;&lt;span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;pre class="ui-code" data-mode="d"&gt;&amp;amp;adc {
    // compatible = &amp;quot;nordic_nrf_saadc&amp;quot;; // only used to instantiate the NRF_SAADC-peripheral on the chip
    status = &amp;quot;okay&amp;quot;;
    // io-channels = &amp;lt;&amp;amp;adc 0&amp;gt;, &amp;lt;&amp;amp;adc 1&amp;gt;, &amp;lt;&amp;amp;adc 2&amp;gt;, &amp;lt;&amp;amp;adc 3&amp;gt;, &amp;lt;&amp;amp;adc 4&amp;gt;, &amp;lt;&amp;amp;adc 5&amp;gt;, &amp;lt;&amp;amp;adc 6&amp;gt;, &amp;lt;&amp;amp;adc 7&amp;gt;;
    // io-channel-names = &amp;quot;VCM2&amp;quot;, &amp;quot;READ2_MCU&amp;quot;, &amp;quot;READ3_MCU&amp;quot;, &amp;quot;VCM3&amp;quot;, &amp;quot;VCM1&amp;quot;, &amp;quot;READ1_MCU&amp;quot;, &amp;quot;VCM4&amp;quot;, &amp;quot;READ4_MCU&amp;quot;;
};&lt;/pre&gt;
&lt;div&gt;&lt;span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;Please note that it didn&amp;#39;t need the io-channels to be specified in the overlay file, but those&amp;nbsp;were configured in the source code side instead and it worked fine:&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;div&gt;
&lt;div&gt;&lt;span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;pre class="ui-code" data-mode="text"&gt;#define ADC_DEVICE_NAME &amp;quot;ADC_0&amp;quot;
#define ADC_RESOLUTION 10
#define ADC_GAIN ADC_GAIN_1_4
#define ADC_REFERENCE ADC_REF_VDD_1_4
#define ADC_ACQUISITION_TIME ADC_ACQ_TIME(ADC_ACQ_TIME_MICROSECONDS, 10)

// READ4 Channel
#define AIN6_VCM_CHANNEL_ID 6
#define AIN6_VCM_CHANNEL_INPUT NRF_SAADC_INPUT_AIN6
#define AIN7_READ4_MCU_CHANNEL_ID 7
#define AIN7_READ4_MCU_CHANNEL_INPUT NRF_SAADC_INPUT_AIN7

static const struct adc_channel_cfg m_read4_channel_cfg = {
    .gain = ADC_GAIN,
    .reference = ADC_REFERENCE,
    .acquisition_time = ADC_ACQUISITION_TIME,
    .channel_id = AIN7_READ4_MCU_CHANNEL_ID,
    .differential = 1,
#if defined(CONFIG_ADC_CONFIGURABLE_INPUTS)
    .input_positive = AIN7_READ4_MCU_CHANNEL_INPUT,
    .input_negative = AIN6_VCM_CHANNEL_INPUT,
#endif
};

err = adc_channel_setup(adc_dev, &amp;amp;m_read4_channel_cfg);
if (err) {
    printk(&amp;quot;Error in setting up the READ4_MCU: %d\n&amp;quot;, err);
}&lt;/pre&gt;
&lt;div&gt;
&lt;div&gt;
&lt;div&gt;&lt;span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;&lt;/div&gt;
&lt;div&gt;So my question is, what are the benefits of instantiating these ADC channels in the device tree rather than doing it in the source code?&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Setting up multiple ADC channels in the device tree</title><link>https://devzone.nordicsemi.com/thread/373315?ContentTypeID=1</link><pubDate>Mon, 20 Jun 2022 17:14:55 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b1d8ea3a-23d6-4cf9-a0d8-9aa7b6da8f9e</guid><dc:creator>Carl Richard</dc:creator><description>&lt;p&gt;Hello, Ted!&lt;br /&gt;&lt;br /&gt;Have you had a look at the Device Tree API documentation for &lt;a href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/zephyr/build/dts/api/api.html?highlight=dt_io_channels_ctlr_by_idx#io-channels"&gt;IO Channels&lt;/a&gt;? Specifically the&amp;nbsp;&lt;a href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/zephyr/build/dts/api/api.html?highlight=dt_io_channels_ctlr_by_idx#c.DT_IO_CHANNELS_INPUT_BY_NAME"&gt;&lt;span&gt;DT_IO_CHANNELS_INPUT_BY_NAME&lt;/span&gt;&lt;/a&gt;&amp;nbsp;macro. I haven&amp;#39;t tried these myself, but from what I can see they fit your requirements.&lt;br /&gt;&lt;br /&gt;Regarding your second question I believe you can instantiate all the channels in a single node like they have done in the example code in the documentation.&lt;br /&gt;&lt;br /&gt;Best regards,&lt;br /&gt;Carl Richard&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>