<?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>gpio button interrupt is not triggering?</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/12542/gpio-button-interrupt-is-not-triggering</link><description>Hi all, 
 I am using pca10040 board. My requirement is when i press the button led should turn on after repress the button led should turn off. 
 For that i tried below code : 
 #include &amp;lt;stdbool.h&amp;gt;
#include &amp;lt;stdint.h&amp;gt;
#include &amp;quot;pca10040.h&amp;quot;
#include</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 17 Mar 2016 16:40:14 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/12542/gpio-button-interrupt-is-not-triggering" /><item><title>RE: gpio button interrupt is not triggering?</title><link>https://devzone.nordicsemi.com/thread/47597?ContentTypeID=1</link><pubDate>Thu, 17 Mar 2016 16:40:14 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:781544e7-6414-47f9-a522-fb01e802294b</guid><dc:creator>naveen</dc:creator><description>&lt;p&gt;Thank you, Have a joyful day.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: gpio button interrupt is not triggering?</title><link>https://devzone.nordicsemi.com/thread/47596?ContentTypeID=1</link><pubDate>Thu, 17 Mar 2016 15:26:53 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:fffecebb-4826-4681-ae52-20c247c470cd</guid><dc:creator>Ole Bauck</dc:creator><description>&lt;p&gt;Just answered similar question &lt;a href="https://devzone.nordicsemi.com/question/72108/maximum-gpio-interrupts-nrf52/"&gt;here&lt;/a&gt;. With PORT event you can have interrupt on all pins, with IN event you can only have on 8 pins.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: gpio button interrupt is not triggering?</title><link>https://devzone.nordicsemi.com/thread/47595?ContentTypeID=1</link><pubDate>Thu, 17 Mar 2016 14:51:07 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b25b9e02-82e3-4f2d-bfbe-049d30f542ea</guid><dc:creator>naveen</dc:creator><description>&lt;p&gt;Hi Ole Bauck,
Thank you for your responses.
Whatever you above mentioned thats fine. I&amp;#39;m using GPIOTE, with that we can able to set upto 8 interrupts only right? if wrong means please correct me.
Actually i need more than 8 interrupts, I dont know how to use remaining pins a interrupt pins and how to set priorities about those pins.&lt;/p&gt;
&lt;p&gt;Can you guide me on this please?&lt;/p&gt;
&lt;p&gt;Thanks Again.. :)&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: gpio button interrupt is not triggering?</title><link>https://devzone.nordicsemi.com/thread/47594?ContentTypeID=1</link><pubDate>Thu, 17 Mar 2016 09:38:08 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:95442d80-1751-4272-8649-5e6775efeeec</guid><dc:creator>Ole Bauck</dc:creator><description>&lt;p&gt;App_button uses PORT event which is only limited to number of pins, so you can technically have buttons on all pins if you want. You have to change GPIOTE_CONFIG_NUM_OF_LOW_POWER_EVENTS in nrf_drv_config.h to be high enough though. You can use two priority level when using SoftDevice: APP_PRIORITY_LOW and APP_PRIORITY_HIGH. If not using SoftDevice you have 4 interrupt levels. Did this answer your question?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: gpio button interrupt is not triggering?</title><link>https://devzone.nordicsemi.com/thread/47593?ContentTypeID=1</link><pubDate>Wed, 16 Mar 2016 17:24:24 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5608a3a9-8fca-449b-a6e7-733616c7c48f</guid><dc:creator>naveen</dc:creator><description>&lt;p&gt;yeah thats fine.
How many interrupts we can able to generate and setting priorities using gpio?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: gpio button interrupt is not triggering?</title><link>https://devzone.nordicsemi.com/thread/47592?ContentTypeID=1</link><pubDate>Wed, 16 Mar 2016 10:28:19 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d2d90b3e-066b-4041-a4cf-7e5958380b1a</guid><dc:creator>Ole Bauck</dc:creator><description>&lt;p&gt;The gpiote interrupt priority is defined by GPIOTE_CONFIG_IRQ_PRIORITY in nrf_drv_config.h.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: gpio button interrupt is not triggering?</title><link>https://devzone.nordicsemi.com/thread/47591?ContentTypeID=1</link><pubDate>Wed, 16 Mar 2016 06:19:43 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8e4e8388-22f5-4786-bc25-d44e144d0a0d</guid><dc:creator>naveen</dc:creator><description>&lt;p&gt;Hi Ole Bauck,
Thanks for your awesome responses, Its really helpful for us.
And may i know how to set the priority of gpio interrupts?
Thank you,&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: gpio button interrupt is not triggering?</title><link>https://devzone.nordicsemi.com/thread/47590?ContentTypeID=1</link><pubDate>Tue, 15 Mar 2016 16:16:01 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:12892528-6bd5-4850-89be-18f05e43529b</guid><dc:creator>Ole Bauck</dc:creator><description>&lt;p&gt;You need to define &lt;code&gt;app_button_cfg_t p_button[] = {{BUTTON_1, false, BUTTON_PULL, button_handler}}&lt;/code&gt; as static or move it outside of main(). Or else it will be placed on the stack and removed when it is not used anymore. You are also toggling the led twice inside button_handler, remove one of the toggle functions.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: gpio button interrupt is not triggering?</title><link>https://devzone.nordicsemi.com/thread/47589?ContentTypeID=1</link><pubDate>Tue, 15 Mar 2016 06:44:09 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:121e946e-146b-45b1-a735-be4214ed5df5</guid><dc:creator>naveen</dc:creator><description>&lt;p&gt;Hi Ole Bauck,
Thanks for your support,
After adding &lt;code&gt;nrf_drv_clock_lfclk_request()&lt;/code&gt; the above program is handling fine.&lt;/p&gt;
&lt;p&gt;That same code i had implemented in FreeRTOS. There i created 3 tasks , those tasks are running parallely but there my button handler is not handling.
Code is below :&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;#include &amp;lt;stdbool.h&amp;gt;
#include &amp;lt;stdint.h&amp;gt;
#include &amp;quot;FreeRTOS.h&amp;quot;
#include &amp;quot;task.h&amp;quot;
#include &amp;quot;timers.h&amp;quot;
#include &amp;quot;bsp.h&amp;quot;
#include &amp;quot;nordic_common.h&amp;quot;
#include &amp;quot;nrf_gpio.h&amp;quot;
#include &amp;quot;nrf_drv_clock.h&amp;quot;
#include &amp;quot;sdk_errors.h&amp;quot;
#include &amp;quot;app_error.h&amp;quot;
#include &amp;quot;app_uart.h&amp;quot;
#include &amp;quot;app_fifo.h&amp;quot;
#include &amp;quot;pca10040.h&amp;quot;
#include &amp;quot;app_button.h&amp;quot;
#include &amp;quot;app_timer.h&amp;quot;
#include &amp;quot;nrf_delay.h&amp;quot;
#include &amp;quot;nrf_error.h&amp;quot;

#define TASK_DELAY 1000
#define MAX_TEST_DATA_BYTES     (15U)                /**&amp;lt; max number of test bytes to be used for tx and rx. */
#define UART_TX_BUF_SIZE 256                         /**&amp;lt; UART TX buffer size. */
#define UART_RX_BUF_SIZE 1                           /**&amp;lt; UART RX buffer size. */

#define APP_TIMER_PRESCALER 0
#define  APP_TIMER_OP_QUEUE_SIZE 6
#define BUTTON_DETECTION_DELAY        APP_TIMER_TICKS(500u, APP_TIMER_PRESCALER)

static void vLed0Function (void *pvParameter)
{
    UNUSED_PARAMETER(pvParameter);
    for( ;; )
    {
                printf(&amp;quot;LED 1 Toggle \r\n&amp;quot;);
                nrf_gpio_pin_toggle(BSP_LED_0);
                vTaskDelay(TASK_DELAY); // Delay a task for a given number of ticks
    }
}

static void vLed1Function (void *pvParameter)
{
    UNUSED_PARAMETER(pvParameter);
    for( ;; )
    {
                printf(&amp;quot;LED 2 Toggle \r\n&amp;quot;);
                nrf_gpio_pin_toggle(BSP_LED_1);
                vTaskDelay(TASK_DELAY); // Delay a task for a given number of ticks
    }
}

static void vLed2Function (void *pvParameter)
{
    UNUSED_PARAMETER(pvParameter);
    for( ;; )
    {
                printf(&amp;quot;LED 3 Toggle \r\n&amp;quot;);
                nrf_gpio_pin_toggle(BSP_LED_2);
                vTaskDelay(TASK_DELAY); // Delay a task for a given number of ticks
    }
}

static void leds_init(void)
{
    printf(&amp;quot;LEDS Initialized \r\n&amp;quot;);
    // Configure LED-pins as outputs
    nrf_gpio_cfg_output(BSP_LED_0);
    nrf_gpio_cfg_output(BSP_LED_1);
    nrf_gpio_cfg_output(BSP_LED_2);
    nrf_gpio_cfg_output(BSP_LED_3);
    nrf_gpio_pin_set(BSP_LED_0);
    nrf_gpio_pin_set(BSP_LED_1);
    nrf_gpio_pin_set(BSP_LED_2);
    nrf_gpio_pin_set(BSP_LED_3);
}

static void uart_error_handle(app_uart_evt_t * p_event)
{
    if (p_event-&amp;gt;evt_type == APP_UART_COMMUNICATION_ERROR)
    {
        APP_ERROR_HANDLER(p_event-&amp;gt;data.error_communication);
    }
    else if (p_event-&amp;gt;evt_type == APP_UART_FIFO_ERROR)
    {
        APP_ERROR_HANDLER(p_event-&amp;gt;data.error_code);
    }
}

static void uart_init(void)
{
    ret_code_t err_code;
    const app_uart_comm_params_t comm_params =
    {
        RX_PIN_NUMBER,
        TX_PIN_NUMBER,
        RTS_PIN_NUMBER,
        CTS_PIN_NUMBER,
        APP_UART_FLOW_CONTROL_ENABLED,
        false,
        UART_BAUDRATE_BAUDRATE_Baud38400
    };

    APP_UART_FIFO_INIT(&amp;amp;comm_params,
                       UART_RX_BUF_SIZE,
                       UART_TX_BUF_SIZE,
                       uart_error_handle,
                       APP_IRQ_PRIORITY_LOW,
                       err_code);

    APP_ERROR_CHECK(err_code);

    UNUSED_VARIABLE(puts(&amp;quot; UART Initialized \r\n&amp;quot;));
}

void button_handler(uint8_t pin_no, uint8_t button_action)
{
    UNUSED_VARIABLE(puts(&amp;quot;Enter \r\n&amp;quot;));
    nrf_gpio_pin_toggle(BSP_LED_3);
    if (button_action == APP_BUTTON_PUSH)
    {
        switch (pin_no)
        {
            case BSP_BUTTON_0:
                    UNUSED_VARIABLE(puts(&amp;quot;Buttons 0 \r\n&amp;quot;));
                    nrf_gpio_pin_toggle(BSP_LED_3);
                break;
          }
     }
}
int main(void)
{
    uart_init();
    leds_init();

    ret_code_t err_code;
    err_code = nrf_drv_clock_init();
    APP_ERROR_CHECK(err_code);
    nrf_drv_clock_lfclk_request(NULL);

        UNUSED_VARIABLE(puts(&amp;quot; Buttons Initialized \r\n&amp;quot;));
        app_button_cfg_t p_button[] = {{BUTTON_1, false, BUTTON_PULL, button_handler}};
        APP_TIMER_INIT(APP_TIMER_PRESCALER, APP_TIMER_OP_QUEUE_SIZE, NULL);
        // Initializing the buttons.
        err_code = app_button_init(p_button,1, BUTTON_DETECTION_DELAY);
        APP_ERROR_CHECK(err_code);
        // Enabling the buttons.
        err_code = app_button_enable();
        APP_ERROR_CHECK(err_code);

    TaskHandle_t  xLed0Handle;       /**&amp;lt; Reference to LED0 toggling FreeRTOS task. */
    TaskHandle_t  xLed1Handle;       /**&amp;lt; Reference to LED1 toggling FreeRTOS task. */
    TaskHandle_t  xLed2Handle;       /**&amp;lt; Reference to LED2 toggling FreeRTOS task. */

    UNUSED_VARIABLE(xTaskCreate( vLed0Function, &amp;quot;L0&amp;quot;, configMINIMAL_STACK_SIZE + 50, NULL, 1, &amp;amp;xLed0Handle ));    // LED0 task creation
    UNUSED_VARIABLE(xTaskCreate( vLed1Function, &amp;quot;L1&amp;quot;, configMINIMAL_STACK_SIZE + 50, NULL, 2, &amp;amp;xLed1Handle ));    // LED1 task creation
    UNUSED_VARIABLE(xTaskCreate( vLed2Function, &amp;quot;L2&amp;quot;, configMINIMAL_STACK_SIZE + 50, NULL, 0, &amp;amp;xLed2Handle ));    // LED2 task creation
    /* Activate deep sleep mode */
    SCB-&amp;gt;SCR |= SCB_SCR_SLEEPDEEP_Msk;

uint8_t ch;
while(app_uart_get(&amp;amp;ch) != NRF_SUCCESS);
    // Start FreeRTOS scheduler.
    vTaskStartScheduler();

    while (true)
    {
        // FreeRTOS should not be here...
    }
}

/* Used in debug mode for assertions */
void assert_nrf_callback(uint16_t line_num, const uint8_t *file_name)
{
  while(1)
  {
    /* Loop forever */
  }
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Is there anything we need to enable or disable for using FreeRTOS,&lt;/p&gt;
&lt;p&gt;Can you please guide me on this?&lt;/p&gt;
&lt;p&gt;Thank you&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: gpio button interrupt is not triggering?</title><link>https://devzone.nordicsemi.com/thread/47587?ContentTypeID=1</link><pubDate>Mon, 14 Mar 2016 15:16:11 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:24f7390f-a37c-4cfd-9c88-a7dd84590099</guid><dc:creator>naveen</dc:creator><description>&lt;p&gt;How to use the same code in FreeRTOS?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: gpio button interrupt is not triggering?</title><link>https://devzone.nordicsemi.com/thread/47588?ContentTypeID=1</link><pubDate>Mon, 14 Mar 2016 14:50:22 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:592c0ac2-1256-475b-8042-b67a264dcb32</guid><dc:creator>Ole Bauck</dc:creator><description>&lt;p&gt;You need to start the LFCLK with &lt;code&gt;nrf_drv_clock_lfclk_request()&lt;/code&gt; or else app_timer will not work (which app_button depends on). &lt;a href="https://devzone.nordicsemi.com/question/60033/button-interrupt-problem-when-booting/?answer=60480#post-id-60480"&gt;Here&lt;/a&gt; is a similar example that uses app_button.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>