<?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>Porting Project from SDK12.2 to SDK14.1, SAADC issue</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/27291/porting-project-from-sdk12-2-to-sdk14-1-saadc-issue</link><description>I had the following setup, two app_timers triggering blocking SAADC reads in the callback functions 
 app_timer 1000ms triggering 1 Blocking SAADC read (For battery service, default Bluetooth SIG battery service) 
 ret_code_t err_code;
nrf_saadc_value_t</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Mon, 20 Nov 2017 20:29:45 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/27291/porting-project-from-sdk12-2-to-sdk14-1-saadc-issue" /><item><title>RE: Porting Project from SDK12.2 to SDK14.1, SAADC issue</title><link>https://devzone.nordicsemi.com/thread/107821?ContentTypeID=1</link><pubDate>Mon, 20 Nov 2017 20:29:45 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:54b8e4ee-ea4d-4295-9aac-399826c506df</guid><dc:creator>rms</dc:creator><description>&lt;p&gt;I think I figured it out. I was using the GPIOTE peripheral to handle the power off button.
I turned the log for the GPIOTE peripheral on, and saw that as soon as I initialized it would detect the power button event right away. My PWR_OFF line on the device has a capacitor that keeps the unit on for a 6+ seconds, this was probably keeping my unit alive and the SAADC acting strange.&lt;/p&gt;
&lt;p&gt;This was my original code&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;nrf_drv_gpiote_in_config_t in_config = GPIOTE_CONFIG_IN_SENSE_LOTOHI(false);
in_config.pull = NRF_GPIO_PIN_PULLUP;

err_code = nrf_drv_gpiote_in_init(PWR_SW, &amp;amp;in_config, power_button_interrupt_handler);
APP_ERROR_CHECK(err_code);

nrf_drv_gpiote_in_event_enable(PWR_SW, true);
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;I set the GPIOTE to high accuracy and it stopped registering the power button event at initialization.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;nrf_drv_gpiote_in_config_t in_config = GPIOTE_CONFIG_IN_SENSE_LOTOHI(true);
in_config.pull = NRF_GPIO_PIN_PULLUP;

err_code = nrf_drv_gpiote_in_init(PWR_SW, &amp;amp;in_config, power_button_interrupt_handler);
APP_ERROR_CHECK(err_code);

nrf_drv_gpiote_in_event_enable(PWR_SW, true);
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This is my &lt;code&gt;power_button_interrupt_handler&lt;/code&gt;, I also started calling the sd_power_system_off from here after setting the PWR_OFF line which wasn&amp;#39;t done before&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;void power_button_interrupt_handler(nrf_drv_gpiote_pin_t pin, nrf_gpiote_polarity_t action)
{
greenLED_blink_stop();
NRF_LOG_INFO(&amp;quot;POWER_BUTTON_HANDLER&amp;quot;);
nrf_gpio_pin_write(LED_RED,LED_ON);
NRF_LOG_FINAL_FLUSH();
nrf_drv_gpiote_out_set(PWR_OFF);

ret_code_t err_code;
// Go to system-off mode (this function will not return; wakeup will cause a reset).
err_code = sd_power_system_off();
APP_ERROR_CHECK(err_code);
}
&lt;/code&gt;&lt;/pre&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Porting Project from SDK12.2 to SDK14.1, SAADC issue</title><link>https://devzone.nordicsemi.com/thread/107820?ContentTypeID=1</link><pubDate>Mon, 20 Nov 2017 16:40:44 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1a97461b-9080-404d-87b4-626868d7d8cb</guid><dc:creator>rms</dc:creator><description>&lt;p&gt;A note on the SAADC conversion value, with &lt;code&gt;-O3&lt;/code&gt; after flashing the program it will give the expected value but after one reset it gives a wrong value&lt;/p&gt;
&lt;p&gt;** After -O3 Flash (right after flashing it runs fine), value around 400ish&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;Triggering battery level update...
&amp;lt;info&amp;gt; saadc: Function: nrf_drv_saadc_init, error code: NRF_SUCCESS.
&amp;lt;info&amp;gt; saadc: Channel initialized: 0.
&amp;lt;info&amp;gt; saadc: Function: nrf_drv_saadc_channel_init, error code: NRF_SUCCESS.
&amp;lt;info&amp;gt; saadc: Conversion value: 437, channel: 0.
&amp;lt;warning&amp;gt; saadc: Function: nrf_drv_saadc_sample_convert, error code: NRF_SUCCESS.
&amp;lt;info&amp;gt; saadc: Channel denitialized: 0.
&amp;lt;info&amp;gt; saadc: Function: nrf_drv_saadc_channel_uninit, error code: NRF_SUCCESS.
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;*** After reset of -03 Flash (after resetting once, the SAADC conversion values stay like this), value around 8ish or 65530ish&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;Triggering battery level update...
&amp;lt;info&amp;gt; saadc: Function: nrf_drv_saadc_init, error code: NRF_SUCCESS.
&amp;lt;info&amp;gt; saadc: Channel initialized: 0.
&amp;lt;info&amp;gt; saadc: Function: nrf_drv_saadc_channel_init, error code: NRF_SUCCESS.
&amp;lt;info&amp;gt; saadc: Conversion value: 8, channel: 0.
&amp;lt;warning&amp;gt; saadc: Function: nrf_drv_saadc_sample_convert, error code: NRF_SUCCESS.
&amp;lt;info&amp;gt; saadc: Channel denitialized: 0.
&amp;lt;info&amp;gt; saadc: Function: nrf_drv_saadc_channel_uninit, error code: NRF_SUCCESS.

Triggering battery level update...
&amp;lt;info&amp;gt; saadc: Function: nrf_drv_saadc_init, error code: NRF_SUCCESS.
&amp;lt;info&amp;gt; saadc: Channel initialized: 0.
&amp;lt;info&amp;gt; saadc: Function: nrf_drv_saadc_channel_init, error code: NRF_SUCCESS.
&amp;lt;info&amp;gt; saadc: Conversion value: 65530, channel: 0.
&amp;lt;warning&amp;gt; saadc: Function: nrf_drv_saadc_sample_convert, error code: NRF_SUCCESS.
&amp;lt;info&amp;gt; saadc: Channel denitialized: 0.
&amp;lt;info&amp;gt; saadc: Function: nrf_drv_saadc_channel_uninit, error code: NRF_SUCCESS.
&lt;/code&gt;&lt;/pre&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Porting Project from SDK12.2 to SDK14.1, SAADC issue</title><link>https://devzone.nordicsemi.com/thread/107819?ContentTypeID=1</link><pubDate>Fri, 17 Nov 2017 01:16:54 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a35e3d17-af0c-43cc-ae28-2622a4ffeea8</guid><dc:creator>rms</dc:creator><description>&lt;p&gt;I tried with the &lt;code&gt;DEBUG&lt;/code&gt; compiler flag with &lt;code&gt;-03&lt;/code&gt; but it still resets with any info, as soon as I start IR sensors notification. this is what I see&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;Triggering battery level update...
&amp;lt;info&amp;gt; saadc: Function: nrf_drv_saadc_init, error code: NRF_SUCCESS.
&amp;lt;info&amp;gt; saadc: Channel initialized: 1.
&amp;lt;info&amp;gt; saadc: Function: nrf_drv_saadc_channel_init, error code: NRF_SUCCESS.
&amp;lt;info&amp;gt; saadc: Conversion value: 7, channel: 1.
&amp;lt;warning&amp;gt; saadc: Function: nrf_drv_saadc_sample_convert, error code: NRF_SUCCESS.
&amp;lt;info&amp;gt; saadc: Channel denitialized: 1.
&amp;lt;info&amp;gt; saadc: Function: nrf_drv_saadc_channel_uninit, error code: NRF_SUCCESS.
&amp;lt;info&amp;gt; app: Connected.
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;2nd run without connecting&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;RAM Start: 20002140
BLE init
&amp;lt;info&amp;gt; app: Fast advertising.
After init
Triggering battery level update...
&amp;lt;info&amp;gt; saadc: Function: nrf_drv_saadc_init, error code: NRF_SUCCESS.
&amp;lt;info&amp;gt; saadc: Channel ini▒
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;After I connect and start notifications it resets with no info after these lines. If I just let it run without connecting it resets on its own after a small time. By the way the conversion value is very small its normally around 400ish for the battery when it is working correctly&lt;/p&gt;
&lt;p&gt;SAADC module disabled, all SAADC code commented out, &lt;code&gt;-O0 DEBUG&lt;/code&gt; &amp;amp; &lt;code&gt;-O3&lt;/code&gt; ok&lt;/p&gt;
&lt;p&gt;SAADC module enabled, but all SAADC code commented out, &lt;code&gt;-O0 DEBUG&lt;/code&gt; &amp;amp; &lt;code&gt;-O3&lt;/code&gt; ok&lt;/p&gt;
&lt;p&gt;SAADC module enabled, only battery SAADC code un-commented , &lt;code&gt;-O0 DEBUG&lt;/code&gt; Ok, &lt;code&gt;-O3&lt;/code&gt; reset forever&lt;/p&gt;
&lt;p&gt;I will try to use non-blocking instead to see what happends&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Porting Project from SDK12.2 to SDK14.1, SAADC issue</title><link>https://devzone.nordicsemi.com/thread/107818?ContentTypeID=1</link><pubDate>Thu, 16 Nov 2017 20:30:11 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2dba2d40-c431-4fcd-97da-e206a5948d39</guid><dc:creator>rms</dc:creator><description>&lt;p&gt;I just noticed something &lt;code&gt;APP_TIMER_CONFIG_OP_QUEUE_SIZE&lt;/code&gt; was 20 in my last project it was changed to 10 when I changed my SDK. I changed it back to 20 and now it seems working and also put some protection to see if SAADC is already in use. I have other timers didnt mention it above which dont use the SAADC.&lt;/p&gt;
&lt;p&gt;Now it runs fine in &lt;code&gt;-O0 DEBUG&lt;/code&gt; with the debugger attached. If I try to run &lt;code&gt;-O0 DEBUG&lt;/code&gt; without the debugger attached I get this&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;&amp;lt;error&amp;gt; app: ERROR 3735928559 [Unknown error code] at ../../nRF5_SDK_14.1.0_1dda907/components/drivers_nrf/pwm/nrf_drv_pwm.c:375
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;I am using the PWM to blink an LED, which indicates if it is shutting down or powered on&lt;/p&gt;
&lt;p&gt;With &lt;code&gt;-O3&lt;/code&gt; it still exhibits the reset behavior&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Porting Project from SDK12.2 to SDK14.1, SAADC issue</title><link>https://devzone.nordicsemi.com/thread/107816?ContentTypeID=1</link><pubDate>Thu, 16 Nov 2017 15:27:55 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9c11a095-6632-44a0-9c58-ea0d09025017</guid><dc:creator>rms</dc:creator><description>&lt;p&gt;Hey Jørgen, I have NRF_LOG enabled with DEBUG, and have SAADC log enabled. I never get error returns from the SAADC log. The weird thing that happens is before the reset problem happens, the SAADC will return really high or really low reading before the reset. Like a reading of 15.&lt;/p&gt;
&lt;p&gt;And no I do not have a way of knowing if the the SAADC is already initialized, should I use a mutex or similar to protect the SAADC as a resource?&lt;/p&gt;
&lt;p&gt;Another weird thing is this exact setup gave me no problems with previous SDKs&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Porting Project from SDK12.2 to SDK14.1, SAADC issue</title><link>https://devzone.nordicsemi.com/thread/107817?ContentTypeID=1</link><pubDate>Thu, 16 Nov 2017 15:15:29 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:fa226bad-bb43-47dc-ab37-90372e648422</guid><dc:creator>J&amp;#248;rgen Holmefjord</dc:creator><description>&lt;p&gt;Are you pausing the always-running timer when you do the on-demand sampling of the SAADC, or make sure that the other timer handler does not try to initialize the SAADC when it is already initialized by the other? If the chip restarts, it have ended up in the error handler, where the default recovery is to reset the chip. If you enable NRF_LOG and defined the preprocessor symbol &lt;code&gt;DEBUG&lt;/code&gt;, the error handler in SDK 14.1 should print the error code and info about that caused the function, if you are not able to reproduce it while debugging.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>