<?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>adc_nrfx_saadc: Channel 0 not configured, adc_read() failed with error code -22</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/103459/adc_nrfx_saadc-channel-0-not-configured-adc_read-failed-with-error-code--22</link><description>I use nRF52832 SAADC to measure battery voltage. But I encounter &amp;lt;err&amp;gt; adc_nrfx_saadc: Channel 0 not configured, adc_read() failed, ret=-22. Do you have suggestion to configure channel 0? What is meaning of error code -22? 
 
 Procedures to reproduce</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 05 Sep 2023 14:24:24 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/103459/adc_nrfx_saadc-channel-0-not-configured-adc_read-failed-with-error-code--22" /><item><title>RE: adc_nrfx_saadc: Channel 0 not configured, adc_read() failed with error code -22</title><link>https://devzone.nordicsemi.com/thread/444547?ContentTypeID=1</link><pubDate>Tue, 05 Sep 2023 14:24:24 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:7f88d10c-6c28-461b-a00d-bb9d73b99dd4</guid><dc:creator>Karl Ylvisaker</dc:creator><description>&lt;p&gt;No problem at all! :)&amp;nbsp;&lt;br /&gt;&lt;br /&gt;Good luck with your development!&lt;br /&gt;&lt;br /&gt;Best regards,&lt;br /&gt;Karl&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: adc_nrfx_saadc: Channel 0 not configured, adc_read() failed with error code -22</title><link>https://devzone.nordicsemi.com/thread/444493?ContentTypeID=1</link><pubDate>Tue, 05 Sep 2023 11:53:35 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5714e379-e462-4856-978d-38bbe8e0cb1d</guid><dc:creator>snowuyl</dc:creator><description>&lt;p&gt;Thanks for your suggestion!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: adc_nrfx_saadc: Channel 0 not configured, adc_read() failed with error code -22</title><link>https://devzone.nordicsemi.com/thread/444476?ContentTypeID=1</link><pubDate>Tue, 05 Sep 2023 11:05:39 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:faa52602-c841-4741-90f1-c0139e140d0d</guid><dc:creator>Karl Ylvisaker</dc:creator><description>[quote user="snowuyl"]Thanks for your reply! [/quote]
&lt;p&gt;No problem at all, I am happy to help! :)&amp;nbsp;&lt;/p&gt;
[quote user="snowuyl"]Do you suggest to use ADC_GAIN_1_6?[/quote]
&lt;p&gt;This depends on the range of the signal you will be measuring. For instance, if your signal will be in the 0 - 3.6 V range then I would suggest using the 1/6 gain, yes.&lt;br /&gt;&lt;br /&gt;Best regards,&lt;br /&gt;Karl&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: adc_nrfx_saadc: Channel 0 not configured, adc_read() failed with error code -22</title><link>https://devzone.nordicsemi.com/thread/444438?ContentTypeID=1</link><pubDate>Tue, 05 Sep 2023 09:03:38 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:526e4823-23ee-4a46-aa63-2037e30f69ea</guid><dc:creator>snowuyl</dc:creator><description>&lt;p&gt;Thanks for your reply! I am using internal reference. Do you suggest to use ADC_GAIN_1_6?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: adc_nrfx_saadc: Channel 0 not configured, adc_read() failed with error code -22</title><link>https://devzone.nordicsemi.com/thread/444434?ContentTypeID=1</link><pubDate>Tue, 05 Sep 2023 08:59:57 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f1f32a18-13b5-4e8a-8221-026dc29d05ae</guid><dc:creator>Karl Ylvisaker</dc:creator><description>&lt;p&gt;Which Reference are you using? &lt;a href="https://infocenter.nordicsemi.com/topic/com.nordic.infocenter.nrf52832.ps.v1.1/saadc.html#concept_kxz_4pp_qr"&gt;The input range is determined by the reference/gain&lt;/a&gt;, so you will get a larger range if you decrease the gain.&lt;br /&gt;&lt;br /&gt;Best regards,&lt;br /&gt;Karl&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: adc_nrfx_saadc: Channel 0 not configured, adc_read() failed with error code -22</title><link>https://devzone.nordicsemi.com/thread/444424?ContentTypeID=1</link><pubDate>Tue, 05 Sep 2023 07:48:03 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2491a2d6-4d3b-4b81-ab15-8a7be206acf8</guid><dc:creator>snowuyl</dc:creator><description>&lt;p&gt;When I set gain to ADC_GAIN_4. ADC value of battery voltage is range from 364 to 387. How can I increase ADC value of battery voltage?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: adc_nrfx_saadc: Channel 0 not configured, adc_read() failed with error code -22</title><link>https://devzone.nordicsemi.com/thread/444423?ContentTypeID=1</link><pubDate>Tue, 05 Sep 2023 07:39:16 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:16b72561-4093-469b-a38f-973a663f8760</guid><dc:creator>Karl Ylvisaker</dc:creator><description>&lt;p&gt;Hello,&lt;br /&gt;&lt;br /&gt;I am glad to read that you were able to resolve your initial issue! :)&amp;nbsp;&lt;/p&gt;
[quote user="snowuyl"]Why adc_nrfx_channel_setup() limits maximum gain to ADC_GAIN_4?[/quote]
&lt;p&gt;&lt;a href="https://infocenter.nordicsemi.com/topic/com.nordic.infocenter.nrf52832.ps.v1.1/saadc.html#register.CH-0.CONFIG"&gt;The possible gain configurations is limited by the SAADC&amp;#39;s hardware capabilities&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;Best regards,&lt;br /&gt;Karl&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: adc_nrfx_saadc: Channel 0 not configured, adc_read() failed with error code -22</title><link>https://devzone.nordicsemi.com/thread/444415?ContentTypeID=1</link><pubDate>Tue, 05 Sep 2023 06:10:50 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:faa84928-646f-482e-835c-eaee8e45a336</guid><dc:creator>snowuyl</dc:creator><description>&lt;p&gt;I found the error is because I set gain of struct adc_channel_cfg to ADC_GAIN_128. Why adc_nrfx_channel_setup() limits maximum gain to ADC_GAIN_4?&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;static int adc_nrfx_channel_setup(const struct device *dev,
				  const struct adc_channel_cfg *channel_cfg)
{
	nrf_saadc_channel_config_t config = {
		.resistor_p = NRF_SAADC_RESISTOR_DISABLED,
		.resistor_n = NRF_SAADC_RESISTOR_DISABLED,
		.burst      = NRF_SAADC_BURST_DISABLED,
	};
	uint8_t channel_id = channel_cfg-&amp;gt;channel_id;

	if (channel_id &amp;gt;= SAADC_CH_NUM) {
		return -EINVAL;
	}

	switch (channel_cfg-&amp;gt;gain) {
	case ADC_GAIN_1_6:
		config.gain = NRF_SAADC_GAIN1_6;
		break;
	case ADC_GAIN_1_5:
		config.gain = NRF_SAADC_GAIN1_5;
		break;
	case ADC_GAIN_1_4:
		config.gain = NRF_SAADC_GAIN1_4;
		break;
	case ADC_GAIN_1_3:
		config.gain = NRF_SAADC_GAIN1_3;
		break;
	case ADC_GAIN_1_2:
		config.gain = NRF_SAADC_GAIN1_2;
		break;
	case ADC_GAIN_1:
		config.gain = NRF_SAADC_GAIN1;
		break;
	case ADC_GAIN_2:
		config.gain = NRF_SAADC_GAIN2;
		break;
	case ADC_GAIN_4:
		config.gain = NRF_SAADC_GAIN4;
		break;
	default:
		LOG_ERR(&amp;quot;Selected ADC gain is not valid&amp;quot;);
		return -EINVAL;
	}

	switch (channel_cfg-&amp;gt;reference) {
	case ADC_REF_INTERNAL:
		config.reference = NRF_SAADC_REFERENCE_INTERNAL;
		break;
	case ADC_REF_VDD_1_4:
		config.reference = NRF_SAADC_REFERENCE_VDD4;
		break;
	default:
		LOG_ERR(&amp;quot;Selected ADC reference is not valid&amp;quot;);
		return -EINVAL;
	}

	switch (channel_cfg-&amp;gt;acquisition_time) {
	case ADC_ACQ_TIME(ADC_ACQ_TIME_MICROSECONDS, 3):
		config.acq_time = NRF_SAADC_ACQTIME_3US;
		break;
	case ADC_ACQ_TIME(ADC_ACQ_TIME_MICROSECONDS, 5):
		config.acq_time = NRF_SAADC_ACQTIME_5US;
		break;
	case ADC_ACQ_TIME_DEFAULT:
	case ADC_ACQ_TIME(ADC_ACQ_TIME_MICROSECONDS, 10):
		config.acq_time = NRF_SAADC_ACQTIME_10US;
		break;
	case ADC_ACQ_TIME(ADC_ACQ_TIME_MICROSECONDS, 15):
		config.acq_time = NRF_SAADC_ACQTIME_15US;
		break;
	case ADC_ACQ_TIME(ADC_ACQ_TIME_MICROSECONDS, 20):
		config.acq_time = NRF_SAADC_ACQTIME_20US;
		break;
	case ADC_ACQ_TIME(ADC_ACQ_TIME_MICROSECONDS, 40):
		config.acq_time = NRF_SAADC_ACQTIME_40US;
		break;
	default:
		LOG_ERR(&amp;quot;Selected ADC acquisition time is not valid&amp;quot;);
		return -EINVAL;
	}

	config.mode = (channel_cfg-&amp;gt;differential ?
		NRF_SAADC_MODE_DIFFERENTIAL : NRF_SAADC_MODE_SINGLE_ENDED);

	/* Keep the channel disabled in hardware (set positive input to
	 * NRF_SAADC_INPUT_DISABLED) until it is selected to be included
	 * in a sampling sequence.
	 */

	nrf_saadc_channel_init(NRF_SAADC, channel_id, &amp;amp;config);
	nrf_saadc_channel_input_set(NRF_SAADC,
				    channel_id,
				    NRF_SAADC_INPUT_DISABLED,
				    channel_cfg-&amp;gt;input_negative);

	/* Store the positive input selection in a dedicated array,
	 * to get it later when the channel is selected for a sampling
	 * and to mark the channel as configured (ready to be selected).
	 */
	m_data.positive_inputs[channel_id] = channel_cfg-&amp;gt;input_positive;

	return 0;
}&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: adc_nrfx_saadc: Channel 0 not configured, adc_read() failed with error code -22</title><link>https://devzone.nordicsemi.com/thread/444411?ContentTypeID=1</link><pubDate>Tue, 05 Sep 2023 05:30:31 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:761cd0a1-31da-4507-993c-7ab149492e7a</guid><dc:creator>snowuyl</dc:creator><description>&lt;p&gt;&lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/0537.minimal_5F00_log_5F00_battery.zip"&gt;devzone.nordicsemi.com/.../0537.minimal_5F00_log_5F00_battery.zip&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: adc_nrfx_saadc: Channel 0 not configured, adc_read() failed with error code -22</title><link>https://devzone.nordicsemi.com/thread/444410?ContentTypeID=1</link><pubDate>Tue, 05 Sep 2023 05:29:11 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ac25c183-2530-4af3-9b34-afaf435fec2d</guid><dc:creator>snowuyl</dc:creator><description>&lt;p&gt;&lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/4857.custom_5F00_nrf52832.zip"&gt;devzone.nordicsemi.com/.../4857.custom_5F00_nrf52832.zip&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>