<?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>sampling two analog</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/76130/sampling-two-analog</link><description>Hello 
 
 I want to sampling two analog.. with different configuration and handler. 
 
 so I set two channels like this. 
 
 and then I call only one sample function like this. 
 
 Then error occurs. How can I change code? 
 and is there good example</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 16 Jun 2021 12:49:10 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/76130/sampling-two-analog" /><item><title>RE: sampling two analog</title><link>https://devzone.nordicsemi.com/thread/315613?ContentTypeID=1</link><pubDate>Wed, 16 Jun 2021 12:49:10 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6d5976b1-5f9d-4ba6-b1d1-ecca41283d10</guid><dc:creator>Jared</dc:creator><description>[quote user="lyrics"]So, what is role of SAADC_CH_CONFIG_GAIN_Gain1_4 and&amp;nbsp;&amp;nbsp;SAADC_CH_CONFIG_REFSEL_VDD1_4 ?[/quote]
&lt;p&gt;They are the configured Gain and Reference that is used during the sampling. Please read the &lt;a href="https://infocenter.nordicsemi.com/topic/com.nordic.infocenter.nrf52832.ps.v1.1/saadc.html?cp=4_2_0_36_7#concept_kxz_4pp_qr"&gt;product specification&lt;/a&gt; regarding this topic, and consider making a new ticket for future problems as the original problem has been solved.&lt;/p&gt;
&lt;p&gt;regards&lt;/p&gt;
&lt;p&gt;Jared&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: sampling two analog</title><link>https://devzone.nordicsemi.com/thread/315254?ContentTypeID=1</link><pubDate>Tue, 15 Jun 2021 01:21:34 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:957666f9-3ca5-452c-9d3a-8cf0be22f5ec</guid><dc:creator>lyrics</dc:creator><description>&lt;p&gt;Hi, I fixed the issue.. But another question.&lt;/p&gt;
&lt;p&gt;I reference &lt;a href="https://github.com/NordicPlayground/nRF52-ADC-examples/blob/master/ble_app_uart__saadc_timer_driven__scan_mode/main.c"&gt;this github code&lt;/a&gt;, and followed the code like this.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;    nrf_saadc_channel_config_t cds_channel_config =
    NRF_DRV_SAADC_DEFAULT_CHANNEL_CONFIG_SE(NRF_SAADC_INPUT_AIN1);

    cds_channel_config.gain = NRF_SAADC_GAIN1;

    nrf_saadc_channel_config_t co_channel_config =
    NRF_DRV_SAADC_DEFAULT_CHANNEL_CONFIG_SE(NRF_SAADC_INPUT_AIN6);

    co_channel_config.gain = NRF_SAADC_GAIN1;

    err_code = nrf_drv_saadc_init(&amp;amp;cds_saadc_config, cds_saadc_callback);
    if(err_code != NRF_SUCCESS) return 1;

    err_code = nrf_drv_saadc_channel_init(0, &amp;amp;cds_channel_config);
    APP_ERROR_CHECK(err_code);
    if(err_code != NRF_SUCCESS) return 1;

    err_code = nrf_drv_saadc_channel_init(1, &amp;amp;co_channel_config );
    APP_ERROR_CHECK(err_code);
    //if(err_code != NRF_SUCCESS) return 1;

    err_code = nrf_drv_saadc_buffer_convert(m_cds_buffer_pool[0], 1);
    APP_ERROR_CHECK(err_code);
    //if(err_code != NRF_SUCCESS) return 1;

    err_code = nrf_drv_saadc_buffer_convert(m_cds_buffer_pool[1], 1);
    APP_ERROR_CHECK(err_code);&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;and then it works well, but the result of data are not what I expected.&lt;/p&gt;
&lt;p&gt;So, what is role of SAADC_CH_CONFIG_GAIN_Gain1_4 and&amp;nbsp;&amp;nbsp;SAADC_CH_CONFIG_REFSEL_VDD1_4 ?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: sampling two analog</title><link>https://devzone.nordicsemi.com/thread/315024?ContentTypeID=1</link><pubDate>Mon, 14 Jun 2021 06:05:52 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:31906d69-69de-41f9-a579-ad5fc54aae43</guid><dc:creator>lyrics</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
[quote userid="73165" url="~/f/nordic-q-a/76130/sampling-two-analog/314864#314864"]OK, but this is a different function than earlier. What error code is returned?[/quote]
&lt;p&gt;&lt;img src="https://devzone.nordicsemi.com/resized-image/__size/320x240/__key/communityserver-discussions-components-files/4/pastedimage1623646883671v1.png" alt=" " /&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;In that case, the err_code is 0x11 (17).&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;However, if I move on to the next function with the break point, the error below occurs.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src="https://devzone.nordicsemi.com/resized-image/__size/320x240/__key/communityserver-discussions-components-files/4/pastedimage1623646992950v2.png" alt=" " /&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: sampling two analog</title><link>https://devzone.nordicsemi.com/thread/314864?ContentTypeID=1</link><pubDate>Fri, 11 Jun 2021 09:10:29 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9a190818-adfa-4d83-8c52-eec7ee2f0e21</guid><dc:creator>Jared</dc:creator><description>[quote user="lyrics"]&lt;p&gt;&lt;span&gt;But error occurs second channel init function.. (nrf_drv_saadc_channel_init)&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;[/quote]
&lt;p&gt;&amp;nbsp;OK, but this is a different function than earlier. What error code is returned?&lt;/p&gt;
&lt;p&gt;regards&lt;/p&gt;
&lt;p&gt;Jared&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: sampling two analog</title><link>https://devzone.nordicsemi.com/thread/314832?ContentTypeID=1</link><pubDate>Fri, 11 Jun 2021 07:23:25 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:069d3cc2-10c5-4a80-aabf-8dd6afe3997d</guid><dc:creator>lyrics</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
[quote userid="73165" url="~/f/nordic-q-a/76130/sampling-two-analog/314633#314633"]Maybe it would be better to just use 10 bits in both cases, [/quote]
&lt;p&gt;&lt;span&gt;First of all, I just added a channel and ran the program..&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;But error occurs second channel init function.. (nrf_drv_saadc_channel_init)&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&amp;nbsp;I hope there is reference code (example)!&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;    ret_code_t err_code;
    nrf_drv_saadc_config_t cds_saadc_config;

    cds_saadc_config.low_power_mode = false;                                  //Enable low power mode.
    cds_saadc_config.resolution = NRF_SAADC_RESOLUTION_8BIT;                  //Set SAADC resolution to 12-bit. This will make the SAADC output values from 0 (when input voltage is 0V) to 2^12=4096 (when input voltage is 3.6V for channel gain setting of 1/6).
    cds_saadc_config.oversample = NRF_SAADC_OVERSAMPLE_DISABLED;              //Set oversample to 4x. This will make the SAADC output a single averaged value when the SAMPLE task is triggered 4 times.
    cds_saadc_config.interrupt_priority = APP_IRQ_PRIORITY_LOW;               //Set SAADC interrupt to low priority.

    nrf_saadc_channel_config_t cds_channel_config =
    NRF_DRV_SAADC_DEFAULT_CHANNEL_CONFIG_SE(NRF_SAADC_INPUT_AIN1);

    err_code = nrf_drv_saadc_init(&amp;amp;cds_saadc_config, cds_saadc_callback);
    if(err_code != NRF_SUCCESS) return 1;

    err_code = nrf_drv_saadc_channel_init(0, &amp;amp;cds_channel_config);
    if(err_code != NRF_SUCCESS) return 1;

    err_code = nrf_drv_saadc_buffer_convert(m_cds_buffer_pool[0], 1);
    APP_ERROR_CHECK(err_code);
    
    err_code = nrf_drv_saadc_buffer_convert(m_cds_buffer_pool[1], 1);
    APP_ERROR_CHECK(err_code);
    
    nrf_saadc_channel_config_t co_channel_config =
    NRF_DRV_SAADC_DEFAULT_CHANNEL_CONFIG_SE(NRF_SAADC_INPUT_AIN6);

    err_code = nrf_drv_saadc_channel_init(1, &amp;amp;co_channel_config );
    APP_ERROR_CHECK(err_code);
    
    err_code = nrf_drv_saadc_buffer_convert(m_co_buffer_pool[0], 1);
    APP_ERROR_CHECK(err_code);
    
    err_code = nrf_drv_saadc_buffer_convert(m_co_buffer_pool[1], 1);
    APP_ERROR_CHECK(err_code);
    
    //CDS_F=1;
    return 0;
&lt;/pre&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: sampling two analog</title><link>https://devzone.nordicsemi.com/thread/314633?ContentTypeID=1</link><pubDate>Thu, 10 Jun 2021 08:57:34 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:54399a53-ab25-4b78-b99c-140a11d23529</guid><dc:creator>Jared</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
[quote user="lyrics"]&lt;p&gt;Because I set different resolution value. cds is 8Bit , and co is 10Bit.&amp;nbsp;&amp;nbsp;&lt;span&gt;Also, I tried to handle each value&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;[/quote]
&lt;p&gt;&amp;nbsp;Then you need to:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Initialize the SAADC with 8 bit resolution.&lt;/li&gt;
&lt;li&gt;Sample&amp;nbsp;&lt;/li&gt;
&lt;li&gt;Un initialize the SAADC&lt;/li&gt;
&lt;li&gt;Initialize the SAADC with 10 bit resolution&lt;/li&gt;
&lt;li&gt;Sample&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Maybe it would be better to just use 10 bits in both cases, that way you wouldn&amp;#39;t need to reinitialize the SAADC peripheral between each sample. You can truncate the 10 bit result to 8 bit in your application instead.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
[quote user="lyrics"]Is there a way to separate two channels in one handler?&amp;nbsp;[/quote]
&lt;p&gt;The samples are taken sequential starting from the lowest channel number. You can print the number of the sample to keep track of which channel it comes from. For example, if you&amp;#39;re using two channels then you know that odd numbered samples are from the first channel, and even numbered samples are from the second channel.&lt;/p&gt;
&lt;p&gt;regards&lt;/p&gt;
&lt;p&gt;Jared&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: sampling two analog</title><link>https://devzone.nordicsemi.com/thread/314572?ContentTypeID=1</link><pubDate>Thu, 10 Jun 2021 00:17:06 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e37a958b-73d8-41ae-955a-d59858fea943</guid><dc:creator>lyrics</dc:creator><description>[quote userid="73165" url="~/f/nordic-q-a/76130/sampling-two-analog/314413#314413"]But do they require a different configuration of the SAADC peripheral? If yes, exactly what needs to be different?&amp;nbsp;[/quote]
&lt;p&gt;Because I set different resolution value. cds is 8Bit , and co is 10Bit.&amp;nbsp;&amp;nbsp;&lt;span&gt;Also, I tried to handle each value&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt; with a handler. (cds_handler and co_handler)&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;I don&amp;#39;t know the ads functions well, so I just divided them into two.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Is there a way to separate two channels in one handler?&amp;nbsp;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: sampling two analog</title><link>https://devzone.nordicsemi.com/thread/314413?ContentTypeID=1</link><pubDate>Wed, 09 Jun 2021 09:35:26 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9b3aebea-fc42-4c1d-bf2e-1bf6fe6647b9</guid><dc:creator>Jared</dc:creator><description>&lt;p&gt;But do they require a different configuration of the SAADC peripheral? If yes, exactly what needs to be different?&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
[quote user="lyrics"]it returns 0x08 error , second initializing[/quote]
&lt;p&gt;&amp;nbsp;Yes, as I suspected, the issue is that you try to initialize the driver after it has already been initialized. You need to un initialize it in between if you want to use a different config for the SAADC driver.&lt;/p&gt;
&lt;p&gt;&lt;a href="https://infocenter.nordicsemi.com/topic/sdk_nrf5_v17.0.2/group__nrf__drv__saadc.html#gace15be014bfbc23fd1b3b8ac252f875b"&gt;Error 0x08 = &lt;span&gt;NRF_ERROR_INVALID_STATE&lt;/span&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src="https://devzone.nordicsemi.com/resized-image/__size/320x240/__key/communityserver-discussions-components-files/4/pastedimage1623231299939v1.png" alt=" " /&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: sampling two analog</title><link>https://devzone.nordicsemi.com/thread/314393?ContentTypeID=1</link><pubDate>Wed, 09 Jun 2021 08:50:53 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:fb2a9c37-1ccb-487f-8347-5271ec6bd29c</guid><dc:creator>lyrics</dc:creator><description>[quote userid="73165" url="~/f/nordic-q-a/76130/sampling-two-analog/314385#314385"]Exactly what error occurs?[/quote]
&lt;p&gt;&lt;img src="https://devzone.nordicsemi.com/resized-image/__size/320x240/__key/communityserver-discussions-components-files/4/pastedimage1623228584688v1.png" alt=" " /&gt;&lt;/p&gt;
&lt;p&gt;it returns 0x08 error , second initializing.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt; err_code = nrf_drv_saadc_init(&amp;amp;co_saadc_config, co_saadc_callback);&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
[quote userid="73165" url="~/f/nordic-q-a/76130/sampling-two-analog/314385#314385"] Is there any difference between&amp;nbsp;cds_saadc_config and&amp;nbsp;co_saadc_config?&amp;nbsp;[/quote]
&lt;p&gt;they are different sensor, so each sensor value needs to sampling.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: sampling two analog</title><link>https://devzone.nordicsemi.com/thread/314385?ContentTypeID=1</link><pubDate>Wed, 09 Jun 2021 08:33:32 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a86c8512-ee68-44de-bbd9-db76d38ad347</guid><dc:creator>Jared</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;Exactly what error occurs?&lt;/p&gt;
&lt;p&gt;The SAADC periperhal should only be initialized once with the same&amp;nbsp;nrfx_saadc_config_t configuration.&lt;/p&gt;
&lt;p&gt;You can un-initialize it and then re-initialize with a new configuration. Is there any difference between&amp;nbsp;cds_saadc_config and&amp;nbsp;co_saadc_config?&amp;nbsp;&lt;/p&gt;
&lt;p&gt;The channels can be configured differently so this shouldn&amp;#39;t be a problem.&lt;/p&gt;
&lt;p&gt;regards&lt;/p&gt;
&lt;p&gt;Jared&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>