<?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>hardfault about the saadc channel init</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/68834/hardfault-about-the-saadc-channel-init</link><description>Hi, 
 I meet a hard fault handler issue when initialize the saadc channel. The code is as followed. 
 
 When I set the breakpoint at line 22, the debugging process can work well, but when I move the breakpoint to line 24, the debugging process will jump</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 03 Dec 2020 09:35:24 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/68834/hardfault-about-the-saadc-channel-init" /><item><title>RE: hardfault about the saadc channel init</title><link>https://devzone.nordicsemi.com/thread/283011?ContentTypeID=1</link><pubDate>Thu, 03 Dec 2020 09:35:24 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f12f1029-94e5-4302-a26e-181c3509bf7f</guid><dc:creator>haakonsh</dc:creator><description>&lt;p&gt;I&amp;#39;ll try to set it up&amp;nbsp;on my end.&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;Have you disabled ASSERTs for that project? What SDK are you using for these two projects?&lt;br /&gt;&lt;br /&gt;All instances of the&amp;nbsp;nrf_drv_saadc_channel_init in the nRF5 SDK 12.3 and upwards contain the following check:&lt;/p&gt;
&lt;div&gt;&lt;span&gt;ASSERT&lt;/span&gt;&lt;span&gt;((&lt;/span&gt;&lt;span&gt;p_config&lt;/span&gt;&lt;span&gt;-&amp;gt;&lt;/span&gt;&lt;span&gt;pin_p&lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;lt;=&amp;nbsp;NRF_SAADC_INPUT_VDD)&amp;nbsp;&amp;amp;&amp;amp;&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;p_config&lt;/span&gt;&lt;span&gt;-&amp;gt;&lt;/span&gt;&lt;span&gt;pin_p&lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;gt;&amp;nbsp;NRF_SAADC_INPUT_DISABLED));&lt;br /&gt;&lt;br /&gt;Where&amp;nbsp;NRF_SAADC_INPUT_VDD = 0x9 and&amp;nbsp;NRF_SAADC_INPUT_DISABLED = 0x0.&amp;nbsp;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: hardfault about the saadc channel init</title><link>https://devzone.nordicsemi.com/thread/282930?ContentTypeID=1</link><pubDate>Wed, 02 Dec 2020 16:29:05 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5b83e4d8-1fa0-4558-ab15-35e0df24a683</guid><dc:creator>Leogean</dc:creator><description>&lt;p&gt;Thanks for your reply. I extract the saadc part from my project. The terminal output and the register setting are the same as the pictures before. It should print three sample values in the terminal. Please have a try.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Thanks a lot.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;#include &amp;lt;stdio.h&amp;gt;
#include &amp;lt;stdlib.h&amp;gt;
#include &amp;lt;sys/time.h&amp;gt;
#include &amp;lt;stdbool.h&amp;gt;
#include &amp;lt;stdbool.h&amp;gt;
#include &amp;lt;stdint.h&amp;gt;
#include &amp;lt;ble_gap.h&amp;gt;
#include &amp;quot;nrf.h&amp;quot;
#include &amp;quot;app_util_platform.h&amp;quot;
#include &amp;quot;nrf_delay.h&amp;quot;
#include &amp;quot;app_timer.h&amp;quot;
#include &amp;quot;app_error.h&amp;quot;
#include &amp;quot;nrf_delay.h&amp;quot;
#include &amp;quot;nrf_log.h&amp;quot;
#include &amp;quot;boards.h&amp;quot;
#include &amp;quot;pca10056.h&amp;quot;
#include &amp;quot;nrf_gpio.h&amp;quot;
#include &amp;quot;nrf_drv_timer.h&amp;quot;
#include &amp;quot;nrfx_gpiote.h&amp;quot;
#include &amp;quot;nrf_drv_gpiote.h&amp;quot;
#include &amp;quot;nrf_drv_ppi.h&amp;quot;
#include &amp;quot;nrf_drv_rtc.h&amp;quot;
#include &amp;quot;nrf_drv_clock.h&amp;quot;
#include &amp;quot;nrf_drv_lpcomp.h&amp;quot;
#include &amp;quot;nrf_drv_saadc.h&amp;quot;
#include &amp;quot;nrf_drv_twi.h&amp;quot;
#include &amp;quot;nrf_libuarte_async.h&amp;quot;
#include &amp;quot;app_pwm.h&amp;quot;

#define SAADC_SAMPLES_IN_BUFFER 3

nrf_saadc_channel_config_t channel[3]; //saadc channel
nrf_drv_saadc_config_t saadc_config;  //saadc
static nrf_saadc_value_t buffer[2][SAADC_SAMPLES_IN_BUFFER];  //buffer for saadc
int adcData[3];

/*saadc data read*/
void saadc_callback(nrf_drv_saadc_evt_t const * p_event)
{
    if (p_event-&amp;gt;type == NRF_DRV_SAADC_EVT_DONE)
    {
        ret_code_t err_code;

        err_code = nrf_drv_saadc_buffer_convert(p_event-&amp;gt;data.done.p_buffer, SAADC_SAMPLES_IN_BUFFER);

        for (int i = 0; i &amp;lt; SAADC_SAMPLES_IN_BUFFER; i++)
        {
            adcData[i] = p_event-&amp;gt;data.done.p_buffer[i];
        }
    }
}

void saadc_init()
{
    nrf_drv_saadc_init(&amp;amp;saadc_config, saadc_callback); //initial the saadc with the callback function
    saadc_config.resolution = 2; //res = 12?

    channel[0].reference = NRF_SAADC_REFERENCE_VDD4; //reference vvd
    channel[0].gain = NRF_SAADC_GAIN1_4; //gain 1/4
    channel[0].acq_time = NRF_SAADC_ACQTIME_3US; //tacq=3
    channel[0].pin_p = 31; //D31? positive pin?
    nrf_drv_saadc_channel_init(0, &amp;amp;channel[0]);

    channel[1].reference = NRF_SAADC_REFERENCE_INTERNAL; //refvvd false
    channel[1].gain = NRF_SAADC_GAIN1_6;
    channel[1].acq_time = NRF_SAADC_ACQTIME_3US;
    channel[1].pin_p = 28;
    nrf_drv_saadc_channel_init(1, &amp;amp;channel[1]);

    channel[2].reference = NRF_SAADC_REFERENCE_VDD4;
    channel[2].gain = NRF_SAADC_GAIN1_6;
    channel[2].acq_time = NRF_SAADC_ACQTIME_3US;
    channel[2].pin_p = 30;
    nrf_drv_saadc_channel_init(2, &amp;amp;channel[2]);

    nrf_drv_saadc_buffer_convert(buffer[0], SAADC_SAMPLES_IN_BUFFER); //read sample from saadc to buffer?
    nrf_drv_saadc_buffer_convert(buffer[1], SAADC_SAMPLES_IN_BUFFER);
}

void updateADC()
{
        for(int i=0; i&amp;lt;3; i++)
        {
            nrf_drv_saadc_sample();
            printf(&amp;quot;%d \n&amp;quot;, i);
        }
}

int main(void)
{
    printf(&amp;quot;hello\n&amp;quot;);
    saadc_init();
    updateADC();
    printf(&amp;quot;%d, %d, %d \n&amp;quot;, adcData[0], adcData[1], adcData[2]);

}&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: hardfault about the saadc channel init</title><link>https://devzone.nordicsemi.com/thread/282827?ContentTypeID=1</link><pubDate>Wed, 02 Dec 2020 09:31:04 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:38993095-4999-4309-83cf-06aee948abf3</guid><dc:creator>haakonsh</dc:creator><description>&lt;p&gt;Have you read the definition of&amp;nbsp;nrf_drv_saadc_channel_init/nrfx_saadc_channel_init?&lt;/p&gt;
[quote user="Leogean"]the register can set properly and I can get the sample value.&amp;nbsp;[/quote]
&lt;p&gt;Are you sure? Can you share that code?&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: hardfault about the saadc channel init</title><link>https://devzone.nordicsemi.com/thread/282753?ContentTypeID=1</link><pubDate>Tue, 01 Dec 2020 19:01:18 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:73a5bf90-323e-490f-a740-3618f2b0b1ad</guid><dc:creator>Leogean</dc:creator><description>&lt;p&gt;Thanks for your response. I try to change yp to 6 which is AIN2, but it still jump to the hardfault handler. after initialize the channel Also, in another project, I am using pin 28, 30 and 31 as the positive input and you can see from the picture, the register can set properly and I can get the sample value.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;img alt=" " src="https://devzone.nordicsemi.com/resized-image/__size/320x240/__key/communityserver-discussions-components-files/4/6406.PNG" /&gt;&lt;/p&gt;
&lt;p&gt;By the way, could you please tell me what will cause the hard fault issue?&lt;/p&gt;
&lt;p&gt;Thanks very much for your help:)&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: hardfault about the saadc channel init</title><link>https://devzone.nordicsemi.com/thread/282638?ContentTypeID=1</link><pubDate>Tue, 01 Dec 2020 11:28:26 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:73c7c16a-f486-4970-8914-26d5a7ec9ad7</guid><dc:creator>haakonsh</dc:creator><description>&lt;p&gt;28 is not a valid input.&lt;br /&gt;&lt;br /&gt;See&amp;nbsp;&lt;a title="nrfx_saadc_channel_init" href="https://infocenter.nordicsemi.com/topic/sdk_nrf5_v17.0.2/group__nrfx__saadc.html?cp=7_1_6_8_0_30_1_15#gab74892a83a2f842436fac5f1462eca6a"&gt;nrfx_saadc_channel_init&lt;/a&gt;,&amp;nbsp;&lt;a href="https://infocenter.nordicsemi.com/topic/sdk_nrf5_v17.0.2/structnrf__saadc__channel__config__t.html"&gt;nrf_saadc_channel_config_t&lt;/a&gt;, and&amp;nbsp;&lt;a title="nrf_saadc_input_t" href="https://infocenter.nordicsemi.com/topic/sdk_nrf5_v17.0.2/group__nrf__saadc__hal.html?cp=7_1_6_8_0_30_3_8#ga4adceebeae2b334a695d4aecb640fe35"&gt;nrf_saadc_input_t&lt;/a&gt;.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: hardfault about the saadc channel init</title><link>https://devzone.nordicsemi.com/thread/282317?ContentTypeID=1</link><pubDate>Fri, 27 Nov 2020 16:09:43 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:028a7dc5-470b-4bcd-8b0c-8ee374736531</guid><dc:creator>Leogean</dc:creator><description>&lt;p&gt;Ah sorry, xp is 5 and yp is 28&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: hardfault about the saadc channel init</title><link>https://devzone.nordicsemi.com/thread/282227?ContentTypeID=1</link><pubDate>Fri, 27 Nov 2020 10:12:05 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6494206b-e457-47ab-b5ea-6ff105a32ae8</guid><dc:creator>haakonsh</dc:creator><description>&lt;p&gt;What is yp?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>