<?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>SDK 1.6.1 Zephyr,  How Read nRF52832 AIN7 and configure prj.conf and overlay file.</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/79642/sdk-1-6-1-zephyr-how-read-nrf52832-ain7-and-configure-prj-conf-and-overlay-file</link><description>Hello, how do I configure the prj.conf file and the overlay file and how do I read the AIN7 analog input (P0.31) of the nRF52832. It is the first time that I use the micro to read an analog voltage. I did various research on DevZone, but I couldn&amp;#39;t figure</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Fri, 24 Sep 2021 10:06:41 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/79642/sdk-1-6-1-zephyr-how-read-nrf52832-ain7-and-configure-prj-conf-and-overlay-file" /><item><title>RE: SDK 1.6.1 Zephyr,  How Read nRF52832 AIN7 and configure prj.conf and overlay file.</title><link>https://devzone.nordicsemi.com/thread/331024?ContentTypeID=1</link><pubDate>Fri, 24 Sep 2021 10:06:41 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:fe7fab55-784f-458f-bd3d-b8f3005e0211</guid><dc:creator>Fb62</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;OK, work now.&lt;/p&gt;
&lt;p&gt;Best Regards&lt;/p&gt;
&lt;p&gt;Fausto&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SDK 1.6.1 Zephyr,  How Read nRF52832 AIN7 and configure prj.conf and overlay file.</title><link>https://devzone.nordicsemi.com/thread/331008?ContentTypeID=1</link><pubDate>Fri, 24 Sep 2021 09:27:50 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c62b4fb0-25c3-42e7-892f-5b9a667dd8f8</guid><dc:creator>Heidi</dc:creator><description>&lt;p&gt;Hi!&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Try&amp;nbsp;setting the gain to ADC_GAIN_1_6 to get a range of 0V - 3.6V.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SDK 1.6.1 Zephyr,  How Read nRF52832 AIN7 and configure prj.conf and overlay file.</title><link>https://devzone.nordicsemi.com/thread/330848?ContentTypeID=1</link><pubDate>Thu, 23 Sep 2021 12:31:17 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8b835a12-c726-4a77-9e0b-1953eb8d843f</guid><dc:creator>Fb62</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;I compiled the last adc_sample code, but I get&lt;/p&gt;
&lt;p&gt;*** Booting Zephyr OS build v2.6.0-rc1-ncs1 ***&lt;br /&gt;ADC raw 4095 =&amp;gt; 599 mV&lt;br /&gt;ADC raw 4095 =&amp;gt; 599 mV&lt;br /&gt;ADC raw 4095 =&amp;gt; 599 mV&lt;br /&gt;ADC raw 4095 =&amp;gt; 599 mV&lt;br /&gt;ADC raw 4095 =&amp;gt; 599 mV&lt;br /&gt;ADC raw 4095 =&amp;gt; 599 mV&lt;/p&gt;
&lt;p&gt;In input of AN7 I have 1.7 Volt but the ADC&amp;nbsp;reaches full scale with only 0.6 volts&lt;/p&gt;
&lt;p&gt;Is there any other settings to be made?&lt;br /&gt;My hardware is the pine watch which has a resistive divider which halves the battery voltage which is about 3.7Volt&lt;/p&gt;
&lt;p&gt;Best Regards&lt;/p&gt;
&lt;p&gt;Fausto&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SDK 1.6.1 Zephyr,  How Read nRF52832 AIN7 and configure prj.conf and overlay file.</title><link>https://devzone.nordicsemi.com/thread/330703?ContentTypeID=1</link><pubDate>Wed, 22 Sep 2021 14:04:26 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:958ab335-4698-410c-84e3-8fa67056c881</guid><dc:creator>Heidi</dc:creator><description>&lt;p&gt;Hi!&lt;/p&gt;
&lt;p&gt;You can add the following code snippet to convert the raw ADC reading to millivolts.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;mV = (int16_t)adc_raw;
err = adc_raw_to_millivolts(adc_ref_internal(dev_adc), channel_cfg.gain,
			   sequence.resolution, &amp;amp;mV);
if (err) {
	printk(&amp;quot;ADC conversion failed: %d\n&amp;quot;, err);
	return;
}
printf(&amp;quot;ADC raw %d =&amp;gt; %d mV\n&amp;quot;, (int16_t)adc_raw, mV);					   &lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;I attached a zip file of the application below.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/adc_5F00_sample.7z"&gt;devzone.nordicsemi.com/.../adc_5F00_sample.7z&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SDK 1.6.1 Zephyr,  How Read nRF52832 AIN7 and configure prj.conf and overlay file.</title><link>https://devzone.nordicsemi.com/thread/330506?ContentTypeID=1</link><pubDate>Tue, 21 Sep 2021 13:35:13 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:eef0d5f2-ccd3-4806-bc52-85640a09dbed</guid><dc:creator>Fb62</dc:creator><description>&lt;p&gt;Hello Heidi,&lt;/p&gt;
&lt;p&gt;I tested the code sample, but whit 0.5V in input I have 3430 of adc_raw data, it&amp;#39;s normal,&lt;/p&gt;
&lt;p&gt;What is the input voltage range of AN7 (P0.31)?&lt;/p&gt;
&lt;p&gt;Best regards&lt;/p&gt;
&lt;p&gt;Fausto&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SDK 1.6.1 Zephyr,  How Read nRF52832 AIN7 and configure prj.conf and overlay file.</title><link>https://devzone.nordicsemi.com/thread/330485?ContentTypeID=1</link><pubDate>Tue, 21 Sep 2021 12:23:04 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:88b313e8-8946-4670-841a-9ba9beaefac4</guid><dc:creator>Fb62</dc:creator><description>&lt;p&gt;Hello Heidi,&lt;/p&gt;
&lt;p&gt;can you share your test code project.&lt;/p&gt;
&lt;p&gt;Thanks&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Fausto&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SDK 1.6.1 Zephyr,  How Read nRF52832 AIN7 and configure prj.conf and overlay file.</title><link>https://devzone.nordicsemi.com/thread/330478?ContentTypeID=1</link><pubDate>Tue, 21 Sep 2021 12:02:33 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c35db7b3-eaa3-4ba9-8da7-fa6d633a7d0e</guid><dc:creator>Heidi</dc:creator><description>&lt;p&gt;Great! I was able to test it now, and it seems to work. I modified the main.c just now, so try that one instead.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SDK 1.6.1 Zephyr,  How Read nRF52832 AIN7 and configure prj.conf and overlay file.</title><link>https://devzone.nordicsemi.com/thread/330471?ContentTypeID=1</link><pubDate>Tue, 21 Sep 2021 11:43:28 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2eace1f1-3f4c-4b85-8573-82bbc7a81a9f</guid><dc:creator>Fb62</dc:creator><description>&lt;p&gt;Hello Heidi,&lt;/p&gt;
&lt;p&gt;I test it,&lt;/p&gt;
&lt;p&gt;Thanks&lt;/p&gt;
&lt;p&gt;Fausto&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SDK 1.6.1 Zephyr,  How Read nRF52832 AIN7 and configure prj.conf and overlay file.</title><link>https://devzone.nordicsemi.com/thread/330458?ContentTypeID=1</link><pubDate>Tue, 21 Sep 2021 11:01:06 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6df37e47-7473-42a3-ad1a-5b163718477d</guid><dc:creator>Heidi</dc:creator><description>&lt;p&gt;Hi!&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;I&amp;#39;m having some trouble flashing the application to the board to actually test this, but I will provide the basics here to start with.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;In the prj.conf file, you will need to enable&amp;nbsp;CONFIG_ADC=y.&lt;/p&gt;
&lt;p&gt;Then we need an overlay file to enable the adc and to create a node and set the correct io-channel:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;&amp;amp;adc {
	status = &amp;quot;okay&amp;quot;;
};


/ {
	n: node {
		io-channels = &amp;lt;&amp;amp;adc 31&amp;gt;;
		io-channel-names = &amp;quot;AIN7&amp;quot;;
	};
};&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;The main will look something like below.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;/*
 * Copyright (c) 2020 Nordic Semiconuctor ASA
 * SPDX-License-Identifier: Apache-2.0
 */

#include &amp;lt;stdio.h&amp;gt;
#include &amp;lt;zephyr.h&amp;gt;
#include &amp;lt;sys/printk.h&amp;gt;
#include &amp;lt;drivers/adc.h&amp;gt;


#define ADC_RESOLUTION			12
#define ADC_GAIN				ADC_GAIN_1
#define ADC_REFERENCE			ADC_REF_INTERNAL
#define ADC_ACQUISITION_TIME	ADC_ACQ_TIME_DEFAULT

#define ADC_CHANNEL_ID		7

static uint16_t adc_raw;
static const struct device * dev_adc;

struct adc_channel_cfg channel_cfg = {
	.gain 				= ADC_GAIN,
	.reference 			= ADC_REFERENCE,
	.acquisition_time 	= ADC_ACQUISITION_TIME,
	.differential 		= 0,
	.channel_id			= ADC_CHANNEL_ID,
	.input_positive 	= SAADC_CH_PSELP_PSELP_AnalogInput7,
};


void main(void)
{
	int err;
	dev_adc = device_get_binding(&amp;quot;ADC_0&amp;quot;);
	if (!device_is_ready(dev_adc)) {
		printk(&amp;quot;ADC device not found\n&amp;quot;);
		return;
	}
	err = adc_channel_setup(dev_adc, &amp;amp;channel_cfg);
	if (err) {
		printk(&amp;quot;adc_channel_setup() failed with error: %d\n&amp;quot;, err);
	}
	struct adc_sequence sequence = {
		.channels    = BIT(channel_cfg.channel_id),
		.buffer      = &amp;amp;adc_raw,
		.buffer_size = sizeof(adc_raw),
		.resolution  = ADC_RESOLUTION,
	};

	while (true) {
		err = adc_read(dev_adc, &amp;amp;sequence);
		if (err != 0) {
			printk(&amp;quot;ADC reading failed with error %d.\n&amp;quot;, err);
			return;
		}
		printk(&amp;quot;ADC reading: %d\n&amp;quot;, (int16_t)adc_raw);
		k_sleep(K_MSEC(1000));
	}
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt; &lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>