<?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>BAS with SAADC - How to read ADC value periodically</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/22457/bas-with-saadc---how-to-read-adc-value-periodically</link><description>Hi, I&amp;#39;m testing my custom PCB that uses nRF52832-QFAA and a single cell Li-Ion battery (3 ~ 4.2V). 
 Additionally, I use 
 
 
 SDK 12.1 
 
 
 SoftDevice S132 v3 
 
 
 HRS example and SAADC example 
 
 
 
 void saadc_init(void) {
ret_code_t</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 01 Jun 2017 07:12:36 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/22457/bas-with-saadc---how-to-read-adc-value-periodically" /><item><title>RE: BAS with SAADC - How to read ADC value periodically</title><link>https://devzone.nordicsemi.com/thread/88294?ContentTypeID=1</link><pubDate>Thu, 01 Jun 2017 07:12:36 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:58cb1179-55cf-4925-8984-70d2a7c1c14c</guid><dc:creator>J&amp;#248;rgen Holmefjord</dc:creator><description>&lt;p&gt;There should not be any difference in using &lt;code&gt;nrf_drv_saadc_gpio_to_ain(4)&lt;/code&gt; or &lt;code&gt;NRF_SAADC_INPUT_AIN2&lt;/code&gt; directly. The gpio_to_ain function only returns the correct index of the &lt;code&gt;nrf_saadc_input_t&lt;/code&gt; enum, to get corresponding NRF_SAADC_INPUT_AINx value. Note that this reflects the &lt;strong&gt;Analog input&lt;/strong&gt;, not the GPIO pin number, i.e., AIN2 = GPIO P0.04.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: BAS with SAADC - How to read ADC value periodically</title><link>https://devzone.nordicsemi.com/thread/88293?ContentTypeID=1</link><pubDate>Thu, 01 Jun 2017 00:52:27 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c9bff06b-554f-4f15-ade8-018ca6d1c1c1</guid><dc:creator>MANGO</dc:creator><description>&lt;p&gt;Pardon me, Jørgen.&lt;/p&gt;
&lt;p&gt;In the &lt;a href="https://infocenter.nordicsemi.com/index.jsp?topic=%2Fcom.nordic.infocenter.sdk5.v12.0.0%2Fnrf_dev_saadc_example.html&amp;amp;cp=4_0_3_4_5_27"&gt;SDK 12.1 infocenter&amp;#39;s explanation&lt;/a&gt;, it says &lt;code&gt;configures one channel to sample analog input 0 (GPIO pin 2).&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;The original code was&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;channel_config = NRF_DRV_SAADC_DEFAULT_CHANNEL_CONFIG_SE(nrf_drv_saadc_gpio_to_ain(2));
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;whereas the &lt;code&gt;nrf_saadc_input_t&lt;/code&gt; enums uses a different value.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;#define SAADC_CH_PSELP_PSELP_AnalogInput0 (1UL) /*!&amp;lt; AIN0 */
#define SAADC_CH_PSELP_PSELP_AnalogInput2 (3UL) /*!&amp;lt; AIN2 */
typedef enum {
NRF_SAADC_INPUT_AIN0     = SAADC_CH_PSELP_PSELP_AnalogInput0, ///&amp;lt; (AIN0).
NRF_SAADC_INPUT_AIN2     = SAADC_CH_PSELP_PSELP_AnalogInput2, ///&amp;lt; (AIN2).
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Should I use &lt;code&gt;NRF_SAADC_INPUT_AIN2 + 1&lt;/code&gt;? This looks quite weird. I added a photo to the original question.&lt;/p&gt;
&lt;p&gt;-Best Regards&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: BAS with SAADC - How to read ADC value periodically</title><link>https://devzone.nordicsemi.com/thread/88292?ContentTypeID=1</link><pubDate>Wed, 31 May 2017 11:07:15 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c420b029-175c-4cc8-a6f3-c4eae7784485</guid><dc:creator>J&amp;#248;rgen Holmefjord</dc:creator><description>&lt;p&gt;Blocking/non-blocking mode is described in the &lt;a href="http://infocenter.nordicsemi.com/topic/com.nordic.infocenter.sdk5.v12.0.0/hardware_driver_saadc.html?cp=4_0_3_2_13_1#saadc_using"&gt;SAADC documentation&lt;/a&gt;. Blocking mode will simply wait for the function to finish, before continuing the program. In non-blocking mode, you start a task, allowing the CPU to continue other work/sleep. When the task is completed, a interrupt or event will be generated, allowing the CPU to process the result.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: BAS with SAADC - How to read ADC value periodically</title><link>https://devzone.nordicsemi.com/thread/88291?ContentTypeID=1</link><pubDate>Wed, 31 May 2017 10:59:33 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2ca6e04e-6617-4f6f-93c5-2d32b7ddadf4</guid><dc:creator>MANGO</dc:creator><description>&lt;p&gt;Hi, Jørgen. Thanks for your quick reply! Can I ask you about the technical term?&lt;/p&gt;
&lt;p&gt;I always wondered the &amp;quot;blocking / non-blocking&amp;quot; mode.&lt;/p&gt;
&lt;p&gt;Is this similar to the ARM&amp;#39;s thumb mode? Or is this a mode defined by Nordic?&lt;/p&gt;
&lt;p&gt;I couldn&amp;#39;t find that term at the product spec or the Nordic&amp;#39;s infocenter.&lt;/p&gt;
&lt;p&gt;-Best regards&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: BAS with SAADC - How to read ADC value periodically</title><link>https://devzone.nordicsemi.com/thread/88290?ContentTypeID=1</link><pubDate>Wed, 31 May 2017 09:23:42 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f39b1b8e-05f7-4133-8dcf-12121aaff483</guid><dc:creator>J&amp;#248;rgen Holmefjord</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;If you want to get a single sample from the SAADC, you can use blocking mode with the function &lt;a href="http://infocenter.nordicsemi.com/topic/com.nordic.infocenter.sdk5.v12.0.0/group__nrf__drv__saadc.html#ga8ae9523c91a94d4f865125b189273f63"&gt;&lt;code&gt;nrf_drv_saadc_sample_convert()&lt;/code&gt;&lt;/a&gt;. This can be called in your timer callback, and you can use the sample value to update the BAS characteristics.&lt;/p&gt;
&lt;p&gt;I still think it is a better solution to use non-blocking sampling and trigger the sample task from the timer callback (or connect the timer event directly to the sample task using PPI), if you will be doing regular sampling. You can set the buffer size to 1 to get a callback after each sample.&lt;/p&gt;
&lt;p&gt;Your channel setup looks correct, but if you only use one SAADC channel, you can use channel 0. It is also possible to use the AIN2 define from &lt;em&gt;nrf_adc.h&lt;/em&gt; as an input directly, this depends on what you think is more easily readable:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;NRF_DRV_SAADC_DEFAULT_CHANNEL_CONFIG_SE(NRF_SAADC_INPUT_AIN2);
err_code = nrf_drv_saadc_channel_init(0, &amp;amp;channel_config);
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Jørgen&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>