<?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>nRFX lib - Problem with interupt and timer</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/51409/nrfx-lib---problem-with-interupt-and-timer</link><description>Hi, 
 I use a mcu nRF52840 on a personal card for a project and we are stuck on interruptions: hardware pin and timer. I use the lib &amp;quot;nrfx&amp;quot; for future accounting purposes. I took the example code from the library &amp;quot;nrf&amp;quot; located at 
 *nRF5_SDK_15.3.0_59ac345</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 17 Sep 2019 16:55:15 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/51409/nrfx-lib---problem-with-interupt-and-timer" /><item><title>RE: nRFX lib - Problem with interupt and timer</title><link>https://devzone.nordicsemi.com/thread/210210?ContentTypeID=1</link><pubDate>Tue, 17 Sep 2019 16:55:15 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:903aa59f-f9e5-4519-aa1b-479d431578be</guid><dc:creator>Mikael</dc:creator><description>&lt;p&gt;Hi,&amp;nbsp;&lt;br /&gt;thank you for the answer. As you mentioned, it also works on our DK.&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRFX lib - Problem with interupt and timer</title><link>https://devzone.nordicsemi.com/thread/209477?ContentTypeID=1</link><pubDate>Thu, 12 Sep 2019 15:38:29 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:96a9d8b9-e293-4925-8759-87f190c6cf0c</guid><dc:creator>Sigurd</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;The reset_handler will call SystemInit() before jumping to main() as part of the startup, so you don&amp;#39;t have have to call it again in main().&lt;/p&gt;
&lt;p&gt;You should not read the pin status in the main while loop, it will consume alot of power. Use interrupts instead. This code here works fine when I test it on a DK.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;//----------------------------------------------------------------------------Code---------------------------------------------------
#include &amp;lt;nrfx.h&amp;gt;
#include &amp;lt;nrfx_gpiote.h&amp;gt;
#include &amp;quot;bsp.h&amp;quot;
#include &amp;quot;system_nrf52840.h&amp;quot;
#include &amp;quot;boards.h&amp;quot;

void interuptTest( nrfx_gpiote_pin_t pin, nrf_gpiote_polarity_t action );
void check_error( nrfx_err_t err_code );

void main(void)
{
  //SystemInit();
  // Configure bouton and LEDs
  // LEDs need output direction
  nrf_gpio_cfg_output( BSP_LED_0 );
  nrf_gpio_cfg_output( BSP_LED_1 );
  nrf_gpio_cfg_output( BSP_LED_2 );

  // Buttons need input direction, pull up are in hardware
  nrf_gpio_cfg_input( BSP_BUTTON_0, NRF_GPIO_PIN_PULLUP ); 
  nrf_gpio_cfg_input( BSP_BUTTON_1, NRF_GPIO_PIN_PULLUP ); 
  nrf_gpio_cfg_input( BSP_BUTTON_2, NRF_GPIO_PIN_PULLUP ); 

  // Configure the interupt on button 0
  nrfx_err_t err_code = nrfx_gpiote_init();
  check_error( err_code );
  nrfx_gpiote_in_config_t button_0_config = NRFX_GPIOTE_CONFIG_IN_SENSE_HITOLO( true );
  button_0_config.pull = NRF_GPIO_PIN_PULLUP;

  err_code = nrfx_gpiote_in_init( BSP_BUTTON_0 , &amp;amp;button_0_config, interuptTest );
  check_error( err_code );

  nrfx_gpiote_in_event_enable( BSP_BUTTON_0 , true );

  while ( true )
  {
      // Wait for an event.
    #ifdef SOFTDEVICE_PRESENT
        if (nrf_sdh_is_enabled())
        {
            ret_code_t ret_code = sd_app_evt_wait();
            ASSERT((ret_code == NRF_SUCCESS) || (ret_code == NRF_ERROR_SOFTDEVICE_NOT_ENABLED));
            UNUSED_VARIABLE(ret_code);
        }
        else
    #endif // SOFTDEVICE_PRESENT
    {
        // Wait for an event.
        __WFE();
        // Clear the internal event register.
        __SEV();
        __WFE();
    }


  }
}

void interuptTest(nrfx_gpiote_pin_t pin, nrf_gpiote_polarity_t action)
{
  nrfx_gpiote_out_toggle( BSP_LED_1 );
}
void check_error( nrfx_err_t err_code )
{
  if (NRFX_SUCCESS == err_code)
   {
     debug_printf(&amp;quot;Configuration success!\r\n&amp;quot;);
   } else 
   {
     debug_printf(&amp;quot;Error code : %i \r\n&amp;quot;, err_code);
   }
}
//--------------------------------------------------------------------------------------------------------------------------------------&lt;/pre&gt;&lt;/p&gt;
[quote userid="82830" url="~/f/nordic-q-a/51409/nrfx-lib---problem-with-interupt-and-timer/206540"] how can we include &amp;quot;app_error.h&amp;quot;?[/quote]
&lt;p&gt;Just add&amp;nbsp;this at top of main.c&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;#include &amp;quot;app_error.h&amp;quot;&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRFX lib - Problem with interupt and timer</title><link>https://devzone.nordicsemi.com/thread/206540?ContentTypeID=1</link><pubDate>Wed, 28 Aug 2019 09:02:46 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:02826b66-85ba-4328-9b82-8f3813ed35ee</guid><dc:creator>Mikael</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;Buttons were configured in bsp_init(). But to make it more clear, I moved them into this code. The result is the same. LED_2 change state when button 0 change state, we obtain 2 NRFX_SUCCESS but we never enter the interrupt.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;//----------------------------------------------------------------------------Code---------------------------------------------------
#include &amp;lt;nrfx.h&amp;gt;
#include &amp;lt;nrfx_gpiote.h&amp;gt;
#include &amp;quot;bsp.h&amp;quot;
#include &amp;quot;system_nrf52840.h&amp;quot;

void interuptTest( nrfx_gpiote_pin_t pin, nrf_gpiote_polarity_t action );
void check_error( nrfx_err_t err_code );

void main(void)
{
  SystemInit();
  // Configure bouton and LEDs
  // LEDs need output direction
  nrf_gpio_cfg_output( LED_0_PIN );
  nrf_gpio_cfg_output( LED_1_PIN );
  nrf_gpio_cfg_output( LED_2_PIN );

  // Buttons need input direction, pull up are in hardware
  nrf_gpio_cfg_input( BUTTON_0_PIN, NRF_GPIO_PIN_NOPULL ); 
  nrf_gpio_cfg_input( BUTTON_1_PIN, NRF_GPIO_PIN_NOPULL ); 
  nrf_gpio_cfg_input( BUTTON_2_PIN, NRF_GPIO_PIN_NOPULL ); 

  // Configure the interupt on button 0
  nrfx_err_t err_code = nrfx_gpiote_init();
  check_error( err_code );
  nrfx_gpiote_in_config_t button_0_config = NRFX_GPIOTE_CONFIG_IN_SENSE_HITOLO( true );
  err_code = nrfx_gpiote_in_init( BUTTON_0_PIN , &amp;amp;button_0_config, interuptTest );
  check_error( err_code );

  nrfx_gpiote_in_event_enable( BUTTON_0_PIN , true );

  while ( true )
  {
    // Make sure that the button is detected
    if( nrfx_gpiote_in_is_set( BUTTON_0_PIN ) )
    {
      nrfx_gpiote_out_clear( LED_2_PIN );
    } else
    {
      nrfx_gpiote_out_set( LED_2_PIN );
    }
  }
}

void interuptTest(nrfx_gpiote_pin_t pin, nrf_gpiote_polarity_t action)
{
  nrfx_gpiote_out_toggle( LED_1_PIN );
}
void check_error( nrfx_err_t err_code )
{
  if (NRFX_SUCCESS == err_code)
   {
     debug_printf(&amp;quot;Configuration success!\r\n&amp;quot;);
   } else 
   {
     debug_printf(&amp;quot;Error code : %i \r\n&amp;quot;, err_code);
   }
}
//--------------------------------------------------------------------------------------------------------------------------------------&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Regarding the APP_ERROR_CHECK(test), I&amp;#39;m aware of the practice but as we are using NRFX, how can we include &amp;quot;app_error.h&amp;quot;? I&amp;#39;m missing a step on this. However, I managed to make something functional and I received the Configuration Sucess message twice.&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRFX lib - Problem with interupt and timer</title><link>https://devzone.nordicsemi.com/thread/206442?ContentTypeID=1</link><pubDate>Tue, 27 Aug 2019 16:08:07 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b1744706-90a5-47f8-9e5e-c785a1899d1e</guid><dc:creator>Sigurd</dc:creator><description>&lt;p&gt;I then assume the buttons are not configured in bsp_init().&lt;/p&gt;
&lt;p&gt;Could you check the return values of&amp;nbsp;&lt;span&gt;nrfx_gpiote_in_init() and&amp;nbsp;nrfx_gpiote_init() ? It&amp;#39;s good practice to check the return values with&amp;nbsp;APP_ERROR_CHECK()&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;pre class="ui-code" data-mode="text"&gt;nrfx_err_t test = nrfx_gpiote_in_init( BUTTON_0_PIN , &amp;amp;button_0_config, interuptTest );
APP_ERROR_CHECK(test);&lt;/pre&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRFX lib - Problem with interupt and timer</title><link>https://devzone.nordicsemi.com/thread/206422?ContentTypeID=1</link><pubDate>Tue, 27 Aug 2019 14:03:42 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2adea935-0e84-44f4-ad57-cacb48c0346c</guid><dc:creator>Mikael</dc:creator><description>&lt;p&gt;Hi,&lt;br /&gt;thank you for answering.&lt;br /&gt;Yes, LED_1, LED_2 and buttons are configured in bsp_init().&lt;br /&gt;The problem is when the button is pressed on the PCB, the LED_2 changes state (line 22-28) but we don&amp;#39;t enter into the interrupt. Do you have any idea why the interrupt may not be active?&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRFX lib - Problem with interupt and timer</title><link>https://devzone.nordicsemi.com/thread/206301?ContentTypeID=1</link><pubDate>Tue, 27 Aug 2019 09:33:53 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e018d60b-ab33-434e-a2b8-71e14aec9a49</guid><dc:creator>Sigurd</dc:creator><description>&lt;p&gt;&lt;span&gt;Hi,&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Are you configuring any of the buttons or leds in bsp_init() ?&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;You are not configuring LED_1 as output with nrfx_gpiote_out_init(). Is it being configured in bsp_init()?&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;In SDK 15.3 nrfx is being used, there is a glue layer converting the old api to the new nrfx api. See &lt;a href="https://infocenter.nordicsemi.com/topic/com.nordic.infocenter.sdk5.v15.3.0/group__nrf__drv__gpiote.html?cp=5_1_6_9_0_12_0"&gt;this link.&lt;/a&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>