<?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>SAADC Offset Calibration not working?</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/64428/saadc-offset-calibration-not-working</link><description>Hello, 
 
 I am using the nRF52832 on a custom board, with SDK 15.2 and SD132 v6.1. My BLE application uses the SAADC to measure VCC voltage every 6 hours. I am using an app timer to initialize SAADC, kick off either an offset calibration or an ADC conversion</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 11 Aug 2020 07:24:47 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/64428/saadc-offset-calibration-not-working" /><item><title>RE: SAADC Offset Calibration not working?</title><link>https://devzone.nordicsemi.com/thread/263938?ContentTypeID=1</link><pubDate>Tue, 11 Aug 2020 07:24:47 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2fac2ff5-1aef-4c3e-8d14-08438b22106e</guid><dc:creator>aeozyalcin</dc:creator><description>&lt;p&gt;Thank you for the suggestion. It seems that my issue was calling&amp;nbsp;&lt;span&gt;nrf_drv_saadc_buffer_convert before calling the calibrate function. It looks like after calling&amp;nbsp;nrf_drv_saadc_buffer_convert, SAADC expects me to start a conversion instead of calibration.&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SAADC Offset Calibration not working?</title><link>https://devzone.nordicsemi.com/thread/263766?ContentTypeID=1</link><pubDate>Mon, 10 Aug 2020 08:49:44 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ead3fcc1-25f1-47c3-b938-8f91222819fd</guid><dc:creator>haakonsh</dc:creator><description>&lt;p&gt;You can try to wait for the&amp;nbsp;&lt;a title="nrfx_saadc_is_busy" href="https://infocenter.nordicsemi.com/topic/sdk_nrf5_v17.0.0/group__nrfx__saadc.html?cp=7_1_6_8_0_30_1_18#gada73390989901a284e9d52621639763e"&gt;nrfx_saadc_is_busy&lt;/a&gt;&amp;nbsp;flag&amp;nbsp;with a &amp;#39;while&amp;#39; loop.&amp;nbsp;&lt;br /&gt;while(!&lt;a title="nrfx_saadc_is_busy" href="https://infocenter.nordicsemi.com/topic/sdk_nrf5_v17.0.0/group__nrfx__saadc.html?cp=7_1_6_8_0_30_1_18#gada73390989901a284e9d52621639763e"&gt;nrfx_saadc_is_busy&lt;/a&gt;&lt;span&gt;&amp;nbsp;()&lt;/span&gt;)&lt;br /&gt;{&lt;br /&gt;&amp;nbsp; &amp;nbsp; // Calibrate offset&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p&gt;I also suggest that you calibrate the offset before the first time you call&amp;nbsp;nrf_drv_saadc_buffer_convert (in your init function).&lt;br /&gt;&lt;br /&gt;A third option is to use the new&amp;nbsp;&lt;a title="SAADC v2 driver" href="https://infocenter.nordicsemi.com/topic/sdk_nrf5_v17.0.0/group__nrfx__saadc__v2.html?cp=7_1_6_8_0_30_2"&gt;SAADC v2 driver&lt;/a&gt;&amp;nbsp;in nRF5 SDK7.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SAADC Offset Calibration not working?</title><link>https://devzone.nordicsemi.com/thread/263728?ContentTypeID=1</link><pubDate>Sun, 09 Aug 2020 00:55:48 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:21b616cf-b163-419b-841e-f8b57e47ca84</guid><dc:creator>aeozyalcin</dc:creator><description>&lt;p&gt;Thanks for the suggestions.&amp;nbsp;I tried a few things based on your last comment:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;I tried calling abort after initializing SAADC, and then calling calibration afterwards. However, calibration call still returns&amp;nbsp;&lt;span&gt;NRFX_ERROR_BUSY&amp;nbsp;when called after the abort. I even tried adding some delays in between and no luck. I also tried calling&amp;nbsp;&lt;a title="nrfx_saadc_buffer_convert" href="https://infocenter.nordicsemi.com/topic/sdk_nrf5_v17.0.0/group__nrfx__saadc.html?cp=7_1_6_8_0_30_1_13#ga94a7376973f1726b22a5debc090763eb"&gt;nrfx_saadc_buffer_convert&lt;/a&gt;&amp;nbsp;between the abort and the calibration call, but no go here either. Didn&amp;#39;t make a difference.&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;Calling abort does not create an&amp;nbsp;NRF_DRV_SAADC_EVT_DONE&amp;nbsp;event, since there was already no conversion taking place when I called it. I am calling abort right after initializing the SAADC so I wouldn&amp;#39;t expect there to be conversions taking place anyway.&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span&gt;&lt;span&gt;When I omit the calibration call altogether, and just call abort after initializing SAADC, and then try to kick off a conversion 1 second after calling abort,&amp;nbsp;&lt;/span&gt;&lt;/span&gt;nrf_drv_saadc_sample returns NRFX_ERROR_INVALID_STATE. This happens regardless of whether I call&amp;nbsp;&lt;a title="nrfx_saadc_buffer_convert" href="https://infocenter.nordicsemi.com/topic/sdk_nrf5_v17.0.0/group__nrfx__saadc.html?cp=7_1_6_8_0_30_1_13#ga94a7376973f1726b22a5debc090763eb"&gt;nrfx_saadc_buffer_convert&lt;/a&gt;&amp;nbsp;between the abort and the&amp;nbsp;&lt;span&gt;nrf_drv_saadc_sample&amp;nbsp;functions.&lt;/span&gt;&amp;nbsp;Somehow, using the abort function puts the SAADC in a bad state that I can&amp;#39;t seem to recover from.&lt;/li&gt;
&lt;li&gt;Finally, everything works fine if I just give up on calibration. I can init the SAADC every minute, then call&amp;nbsp;&lt;a title="nrfx_saadc_buffer_convert" href="https://infocenter.nordicsemi.com/topic/sdk_nrf5_v17.0.0/group__nrfx__saadc.html?cp=7_1_6_8_0_30_1_13#ga94a7376973f1726b22a5debc090763eb"&gt;nrfx_saadc_buffer_convert&lt;/a&gt;, and then deinit SAADC and go back to sleep without any issues. It&amp;#39;s when I try to do calibration and abort functions when things go wrong.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Could I ask that you take another look at my SAADC initialization function I shared in my original post, and let me know if you see anything wrong that I am doing?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SAADC Offset Calibration not working?</title><link>https://devzone.nordicsemi.com/thread/263401?ContentTypeID=1</link><pubDate>Thu, 06 Aug 2020 11:00:27 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:35b0da57-8e46-4558-96fc-92b6a0aa092f</guid><dc:creator>haakonsh</dc:creator><description>&lt;ol&gt;
&lt;li&gt;Stop the SAADC before you start a calibration. Use&amp;nbsp;&lt;a title="nrfx_saadc_abort" href="https://infocenter.nordicsemi.com/topic/sdk_nrf5_v17.0.0/group__nrfx__saadc.html?cp=7_1_6_8_0_30_1_12#ga480525496e0676a598b828789104fdf6"&gt;nrfx_saadc_abort.&lt;/a&gt;&amp;nbsp;After the calibration is complete you need to set-up the buffers before you start sampling again, with&amp;nbsp;&lt;a title="nrfx_saadc_buffer_convert" href="https://infocenter.nordicsemi.com/topic/sdk_nrf5_v17.0.0/group__nrfx__saadc.html?cp=7_1_6_8_0_30_1_13#ga94a7376973f1726b22a5debc090763eb"&gt;nrfx_saadc_buffer_convert&lt;/a&gt;.&amp;nbsp;&lt;br /&gt;&lt;br /&gt;&lt;/li&gt;
&lt;li&gt;If you take one sample with 32x oversampling your can count the number of times the&amp;nbsp;&lt;span&gt;NRF_DRV_SAADC_EVT_DONE has&amp;nbsp;fired.&lt;/span&gt;&lt;/li&gt;
&lt;/ol&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SAADC Offset Calibration not working?</title><link>https://devzone.nordicsemi.com/thread/263329?ContentTypeID=1</link><pubDate>Thu, 06 Aug 2020 05:10:33 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:de439291-bcfc-4357-9f31-c9928829225b</guid><dc:creator>aeozyalcin</dc:creator><description>&lt;p&gt;Thanks for the reply and the suggestions!&lt;/p&gt;
&lt;p&gt;&lt;span&gt;1. The call to&amp;nbsp;&lt;a title="nrf_drv_saadc_calibrate_offset" href="https://infocenter.nordicsemi.com/topic/sdk_nrf5_v17.0.0/group__nrf__drv__saadc.html?cp=7_1_6_8_0_30_0_3#ga75bfde8a2350eb3ccc8892e725a9fb39"&gt;nrf_drv_saadc_calibrate_offset&lt;/a&gt;&amp;nbsp;is returning NRFX_ERROR_BUSY as you may have suspected, which explains why there is no SAADC event triggering the SAADC callback function. I even tried waiting until the function returns a success (like what I have below), but I don&amp;#39;t think it ever returns success. My program gets stuck in the while loop.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;while(nrf_drv_saadc_calibrate_offset() != NRF_SUCCESS);&lt;/pre&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;You can see that I call the calibrate function right after initializing the SAADC. Is there an SAADC call in my init function that doesn&amp;#39;t block, but needs time to finish that I am missing?&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;2. I am not sure I understand your reply here. Let me rephrase my question: Does SAADC write the value to my supplied buffer only after it has finished taking all the &amp;quot;oversample&amp;quot; samples, and averaged them?&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Thanks&lt;/span&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><item><title>RE: SAADC Offset Calibration not working?</title><link>https://devzone.nordicsemi.com/thread/263016?ContentTypeID=1</link><pubDate>Tue, 04 Aug 2020 13:12:49 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:3255b93e-0b56-4b4b-a9c4-289ebffca620</guid><dc:creator>haakonsh</dc:creator><description>&lt;ol&gt;
&lt;li&gt;I suggest you catch the error codes that our API&amp;#39;s use, specifically the one that &lt;a title="nrf_drv_saadc_calibrate_offset" href="https://infocenter.nordicsemi.com/topic/sdk_nrf5_v17.0.0/group__nrf__drv__saadc.html?cp=7_1_6_8_0_30_0_3#ga75bfde8a2350eb3ccc8892e725a9fb39"&gt;nrf_drv_saadc_calibrate_offset&lt;/a&gt;&amp;nbsp;returns.&amp;nbsp;&lt;br /&gt;&lt;br /&gt;&lt;/li&gt;
&lt;li&gt;I don&amp;#39;t know the definition of a conversion vs sample with regards to oversampling. I guess you can write a test and see whether it is true or not.&amp;nbsp;&lt;/li&gt;
&lt;/ol&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>