<?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>Setting up SAADC questions</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/81333/setting-up-saadc-questions</link><description>I&amp;#39;m trying to setup the SAADC, I do this as much as possible without examples, so I really understand what is going on. 
 Setting up: 
 
 After this I try to start an ADC task but it fails. In the function for starting: 
 
 
 There is the if statement</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Fri, 05 Nov 2021 08:37:52 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/81333/setting-up-saadc-questions" /><item><title>RE: Setting up SAADC questions</title><link>https://devzone.nordicsemi.com/thread/337623?ContentTypeID=1</link><pubDate>Fri, 05 Nov 2021 08:37:52 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c483ea59-277d-40ac-b221-eb4b09184291</guid><dc:creator>Karl Ylvisaker</dc:creator><description>[quote userid="103661" url="~/f/nordic-q-a/81333/setting-up-saadc-questions/337609#337609"]That Github repository is indeed a good resource thank you for that and the answer.[/quote]
&lt;p&gt;I am glad to hear that you found my comment useful!&lt;/p&gt;
[quote userid="103661" url="~/f/nordic-q-a/81333/setting-up-saadc-questions/337609#337609"]That radio example is also interesting, without any protocol looks like. From my time working with Microchip AVR I did almost alway&amp;#39;s the bare approach.[/quote]
&lt;p&gt;Yes, the radio peripheral may be used as any of the other peripherals - so you may use it for proprietary protocols. I would however not really recommend this, since most of this work is already done for you by the SoftDevice (for BLE or ANT) or through the Shockburst or Gazell proprietary protocols.&lt;/p&gt;
&lt;p&gt;I personally also preferred direct register manipulation when I worked with AVR in the past - so I definitely understand your approach to this -, but since changing to Nordic I have had a change of hearts in this regard - now I first and foremost make use of the provided drivers, and really only ever do the register approach to conduct specific tests of non-standard usage, for the most part.&lt;/p&gt;
[quote userid="103661" url="~/f/nordic-q-a/81333/setting-up-saadc-questions/337609#337609"]Anyway, thank you and have already a good weekend.[/quote]
&lt;p&gt;Thank you for saying that, I hope you have a great weekend as well!&lt;br /&gt;&lt;br /&gt;Best regards,&lt;br /&gt;Karl&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Setting up SAADC questions</title><link>https://devzone.nordicsemi.com/thread/337609?ContentTypeID=1</link><pubDate>Fri, 05 Nov 2021 07:41:45 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:41d8eaa1-1210-49b6-a2aa-cfafd1dabeaf</guid><dc:creator>Gatze</dc:creator><description>&lt;p&gt;That Github repository is indeed a good resource thank you for that and the answer. That radio example is also interesting, without any protocol looks like. From my time working with Microchip AVR I did almost alway&amp;#39;s the bare approach. Anyway, thank you and have already a good weekend.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Setting up SAADC questions</title><link>https://devzone.nordicsemi.com/thread/337528?ContentTypeID=1</link><pubDate>Thu, 04 Nov 2021 14:48:43 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2a8836c1-489c-48cf-a575-a42336155f95</guid><dc:creator>Karl Ylvisaker</dc:creator><description>&lt;p&gt;Hello Gatze,&lt;br /&gt;&lt;br /&gt;Thank you for your patience with this.&lt;/p&gt;
[quote user=""]&lt;p&gt;There is the if statement if (m_cb.adc_state != NRF_SAADC_STATE_BUSY) but should it not be if (m_cb.adc_state == NRF_SAADC_STATE_BUSY) ?&lt;/p&gt;
&lt;p&gt;Because if the ADC is busy then it will start an adc sampling, while you would expect when it is busy it should not and vica versa.&lt;/p&gt;[/quote]
&lt;p&gt;I concur that this might look a little off, but you will need to have provided a buffer for the SAADC before calling the nrfx_saadc_sample function, and &lt;a href="https://github.com/NordicSemiconductor/nrfx/blob/d68126c1acc9e2a7575a2c5de4a06f279d780f4f/drivers/src/nrfx_saadc.c#L491"&gt;in doing so the driver will set the state to busy&lt;/a&gt;&amp;nbsp;prior to the nrfx_saadc_sample call,&lt;/p&gt;
[quote user="Gatze"]&lt;p&gt;Never mind, I used direct register acces to setup the SAADC, for me like this is easier, than I don&amp;#39;t have to figure out how the function are working in nrf_saadc.c&lt;/p&gt;
&lt;p&gt;It is not completely finished, but an example as reference for others how I did it (partly used from the bluefruit Arduino library from Adafruit):&lt;/p&gt;[/quote]
&lt;p&gt;I am glad to hear that you got the intended functionality with the bare-metal approach.&lt;br /&gt;You might find &lt;a href="https://github.com/andenore/NordicSnippets/tree/master/examples/saadc"&gt;this github repository helpful&lt;/a&gt; if you intend to keep working with the peripherals through direct register manipulation rather than using the drivers.&lt;br /&gt;It contains some bare-metal implementations of different peripheral examples.&lt;br /&gt;&lt;br /&gt;Best regards,&lt;br /&gt;Karl&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Setting up SAADC questions</title><link>https://devzone.nordicsemi.com/thread/337296?ContentTypeID=1</link><pubDate>Wed, 03 Nov 2021 14:09:04 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:13cce14d-330c-4e0e-9963-db13d1520812</guid><dc:creator>Gatze</dc:creator><description>&lt;p&gt;Never mind, I used direct register acces to setup the SAADC, for me like this is easier, than I don&amp;#39;t have to figure out how the function are working in nrf_saadc.c&lt;/p&gt;
&lt;p&gt;It is not completely finished, but an example as reference for others how I did it (partly used from the bluefruit Arduino library from Adafruit):&lt;/p&gt;
&lt;p&gt;Initialisation:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;  NRF_SAADC-&amp;gt;OVERSAMPLE = SAADC_OVERSAMPLE_OVERSAMPLE_Over8x;
  NRF_SAADC-&amp;gt;RESOLUTION = SAADC_RESOLUTION_VAL_14bit;
  NRF_SAADC-&amp;gt;ENABLE = (SAADC_ENABLE_ENABLE_Enabled &amp;lt;&amp;lt; SAADC_ENABLE_ENABLE_Pos);

  NRF_SAADC-&amp;gt;CH[0].PSELP = SAADC_CH_PSELP_PSELP_AnalogInput3;
  NRF_SAADC-&amp;gt;CH[0].PSELN = SAADC_CH_PSELP_PSELP_NC;
  
  NRF_SAADC-&amp;gt;CH[0].CONFIG = ((SAADC_CH_CONFIG_RESP_Bypass       &amp;lt;&amp;lt; SAADC_CH_CONFIG_RESP_Pos)   &amp;amp; SAADC_CH_CONFIG_RESP_Msk)
                            | ((SAADC_CH_CONFIG_RESP_Bypass     &amp;lt;&amp;lt; SAADC_CH_CONFIG_RESN_Pos)   &amp;amp; SAADC_CH_CONFIG_RESN_Msk)
                            | ((SAADC_CH_CONFIG_GAIN_Gain1_5    &amp;lt;&amp;lt; SAADC_CH_CONFIG_GAIN_Pos)   &amp;amp; SAADC_CH_CONFIG_GAIN_Msk)
                            | ((SAADC_CH_CONFIG_REFSEL_Internal &amp;lt;&amp;lt; SAADC_CH_CONFIG_REFSEL_Pos) &amp;amp; SAADC_CH_CONFIG_REFSEL_Msk)
                            | ((SAADC_CH_CONFIG_TACQ_15us       &amp;lt;&amp;lt; SAADC_CH_CONFIG_TACQ_Pos)   &amp;amp; SAADC_CH_CONFIG_TACQ_Msk)
                            | ((SAADC_CH_CONFIG_MODE_SE         &amp;lt;&amp;lt; SAADC_CH_CONFIG_MODE_Pos)   &amp;amp; SAADC_CH_CONFIG_MODE_Msk)
                            | ((SAADC_CH_CONFIG_BURST_Enabled   &amp;lt;&amp;lt; SAADC_CH_CONFIG_BURST_Pos)   &amp;amp; SAADC_CH_CONFIG_BURST_Msk);
 
  NRF_SAADC-&amp;gt;RESULT.PTR = (uint32_t)&amp;amp;value;
  NRF_SAADC-&amp;gt;RESULT.MAXCNT = 1; // One sample

  NRF_SAADC-&amp;gt;INTENSET = (SAADC_INTENSET_STOPPED_Set &amp;lt;&amp;lt;  SAADC_INTENSET_STOPPED_Pos) &amp;amp; SAADC_INTENSET_STOPPED_Msk;
  NRF_SAADC-&amp;gt;INTENSET = (SAADC_INTENSET_STARTED_Set &amp;lt;&amp;lt;  SAADC_INTENSET_STARTED_Pos) &amp;amp; SAADC_INTENSET_STARTED_Msk;


  NRF_SAADC-&amp;gt;INTENSET = (SAADC_INTENSET_END_Set &amp;lt;&amp;lt;  SAADC_INTENSET_END_Pos) &amp;amp; SAADC_INTENSET_END_Msk;

  NRFX_IRQ_PRIORITY_SET(SAADC_IRQn, 2);
  NRFX_IRQ_ENABLE(SAADC_IRQn);

  NRF_SAADC-&amp;gt;TASKS_START = 0x01UL;&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Interrupt (not finished yet):&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;void nrfx_saadc_irq_handler(void)
{

  //saadc_temp =(void*)&amp;amp;NRF_SAADC;


  if (NRF_SAADC-&amp;gt;EVENTS_STARTED)
  {
    NRF_SAADC-&amp;gt;EVENTS_STARTED = false;
    //take one sample
     NRF_SAADC-&amp;gt;TASKS_SAMPLE = 0x01UL;

  }
  if (NRF_SAADC-&amp;gt;EVENTS_DONE)
  {
      NRF_SAADC-&amp;gt;EVENTS_DONE = false;
      NRF_LOG_DEBUG(&amp;quot;SAADC Event Done&amp;quot;);
  }
  if (NRF_SAADC-&amp;gt;EVENTS_END)
    {
        NRF_SAADC-&amp;gt;EVENTS_END = false;
        NRF_LOG_DEBUG(&amp;quot;SAADC Event End&amp;quot;);

        if(NRF_SAADC-&amp;gt;STATUS) 
        {
         NRF_LOG_DEBUG(&amp;quot;SAADC Busy&amp;quot;);
         
        }
        
        NRF_SAADC-&amp;gt;TASKS_STOP = true;  
    }

    if(NRF_SAADC-&amp;gt;EVENTS_STOPPED)
    {
      NRF_SAADC-&amp;gt;EVENTS_STOPPED = false;
      
      //start new conversion ?
      NRF_SAADC-&amp;gt;TASKS_START = 0x01UL;
    }
   
   
   
   
    //NRF_SAADC-&amp;gt;EVENTS_END = false;
    //NRF_SAADC-&amp;gt;EVENTS_STARTED = false;
   // NRF_SAADC-&amp;gt;EVENTS_STOPPED = false;
    //NRF_SAADC-&amp;gt;EVENTS_RESULTDONE = false;

}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;In the interrupt I want to change from channel to channel, I need this because I have a 74HC4051 analog multiplexer to get some extra channels, in the interrupt I will change the pins that controlling the inputs of the 47HC4051.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>