<?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>getting an interrupt when any of multiple GPIO pins change</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/20195/getting-an-interrupt-when-any-of-multiple-gpio-pins-change</link><description>I am trying to setup an interrupt to fire whenever any of 6 GPIO pins change value using an nRF51822 with soft device. I found the example that uses GPIOTE to get an interrupt call when a single pin changes and that works fine (the pin change int example</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 07 Mar 2017 01:09:49 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/20195/getting-an-interrupt-when-any-of-multiple-gpio-pins-change" /><item><title>RE: getting an interrupt when any of multiple GPIO pins change</title><link>https://devzone.nordicsemi.com/thread/78674?ContentTypeID=1</link><pubDate>Tue, 07 Mar 2017 01:09:49 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ae193b89-ae2c-4c58-b675-ecff6b4b0593</guid><dc:creator>David</dc:creator><description>&lt;p&gt;Thank you very much Jørn for the thorough answer.  Very helpful!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: getting an interrupt when any of multiple GPIO pins change</title><link>https://devzone.nordicsemi.com/thread/78673?ContentTypeID=1</link><pubDate>Mon, 06 Mar 2017 13:47:10 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:775f1420-4399-46c2-b3e1-66a26164ed77</guid><dc:creator>J&amp;#248;rn</dc:creator><description>&lt;p&gt;Hello David&lt;/p&gt;
&lt;p&gt;The pin_change_int example uses high accuracy sensing to sense change in the pin. When using high accuracy you can detect high-speed changes in several pins simultaneously, but in nRF51822 there are only 4 GPIOTE channels which means you can only detect changes in up to 4 pins. It also requires the use of a high frequency clock which increases power consumption.&lt;/p&gt;
&lt;p&gt;If low accuracy (Port event) is used you can detect changes in up to 32 pins, but you cannot detect high-speed changes as it uses a low frequency timer. In addition to this it can only detect change in one pin at a time. If changes in two pins happen simultaneously only one change will be sensed.
A combination between high and low accuracy can be used by changing the value of&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;in_config.hi_accuracy
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;from true to false between gpiote_in_inits.&lt;/p&gt;
&lt;p&gt;Remember to change the &amp;quot;GPIOTE_CONFIG_NUM_OF_LOW_POWER_EVENTS&amp;quot; in sdk_config.h to the correct number of events you need. If you try to create more low power events than is defined here you will get a NO_MEM error.&lt;/p&gt;
&lt;p&gt;The following code is a modification of the pin_change_int example, and uses high accuracy for 4 inputs, and low accuracy for additional two inputs. GPIOTE_CONFIG_NUM_OF_LOW_POWER_EVENTS in sdk_config.h is here set to 2.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;#ifdef BSP_BUTTON_0
    #define PIN_IN BSP_BUTTON_0
#endif
#ifdef BSP_BUTTON_1
    #define PIN_IN2 BSP_BUTTON_1
#endif
#ifdef BSP_BUTTON_2
    #define PIN_IN3 BSP_BUTTON_2
#endif
#ifdef BSP_BUTTON_3
    #define PIN_IN4 BSP_BUTTON_3
#endif

#define PIN_IN5 16 //pin P0.16
#define PIN_IN6 15 //pin P0.15

#ifndef PIN_IN
    #error &amp;quot;Please indicate input pin&amp;quot;
#endif

#ifdef BSP_LED_0
    #define PIN_OUT BSP_LED_0
#endif
#ifdef BSP_LED_1
    #define PIN_OUT2 BSP_LED_1
#endif
#ifdef BSP_LED_2
    #define PIN_OUT3 BSP_LED_2
#endif
#ifdef BSP_LED_3
    #define PIN_OUT4 BSP_LED_3
#endif
#ifndef PIN_OUT
    #error &amp;quot;Please indicate output pin&amp;quot;
#endif

void in_pin_handler(nrf_drv_gpiote_pin_t pin, nrf_gpiote_polarity_t action)
{
	switch(pin)
	{
		case PIN_IN:
			nrf_drv_gpiote_out_toggle(PIN_OUT);
			break;
		case PIN_IN2:
			nrf_drv_gpiote_out_toggle(PIN_OUT2);
			break;
		case PIN_IN3:
			nrf_drv_gpiote_out_toggle(PIN_OUT3);
			break;
		case PIN_IN4:
			nrf_drv_gpiote_out_toggle(PIN_OUT4);
			break;
		case PIN_IN5:
			nrf_drv_gpiote_out_toggle(PIN_OUT);
			nrf_drv_gpiote_out_toggle(PIN_OUT3);
			break;
		case PIN_IN6:
			nrf_drv_gpiote_out_toggle(PIN_OUT2);
			nrf_drv_gpiote_out_toggle(PIN_OUT4);
			break;
		default:

			break;
	}
}

/**
 * @brief Function for configuring: PIN_IN pin for input, PIN_OUT pin for output,
 * and configures GPIOTE to give an interrupt on pin change.
 */
static void gpio_init(void)
{
    ret_code_t err_code;

    err_code = nrf_drv_gpiote_init();
    APP_ERROR_CHECK(err_code);

    nrf_drv_gpiote_out_config_t out_config = GPIOTE_CONFIG_OUT_SIMPLE(false);

    err_code = nrf_drv_gpiote_out_init(PIN_OUT, &amp;amp;out_config);
    APP_ERROR_CHECK(err_code);
    err_code = nrf_drv_gpiote_out_init(PIN_OUT2, &amp;amp;out_config);
    APP_ERROR_CHECK(err_code);
    err_code = nrf_drv_gpiote_out_init(PIN_OUT3, &amp;amp;out_config);
    APP_ERROR_CHECK(err_code);
    err_code = nrf_drv_gpiote_out_init(PIN_OUT4, &amp;amp;out_config);
    APP_ERROR_CHECK(err_code);
		
		//configure pins for high accuracy
    nrf_drv_gpiote_in_config_t in_config = GPIOTE_CONFIG_IN_SENSE_HITOLO(true); 
    in_config.pull = NRF_GPIO_PIN_PULLUP;
		
    err_code = nrf_drv_gpiote_in_init(PIN_IN, &amp;amp;in_config, in_pin_handler);
    APP_ERROR_CHECK(err_code);
    err_code = nrf_drv_gpiote_in_init(PIN_IN2, &amp;amp;in_config, in_pin_handler);
    APP_ERROR_CHECK(err_code);
    err_code = nrf_drv_gpiote_in_init(PIN_IN3, &amp;amp;in_config, in_pin_handler);
    APP_ERROR_CHECK(err_code);
    err_code = nrf_drv_gpiote_in_init(PIN_IN4, &amp;amp;in_config, in_pin_handler);
    APP_ERROR_CHECK(err_code);
		
	//Configure low accuracy for the remaining 2 pins
	in_config.hi_accuracy=false; 
		
    err_code = nrf_drv_gpiote_in_init(PIN_IN5, &amp;amp;in_config, in_pin_handler);
    APP_ERROR_CHECK(err_code);
    err_code = nrf_drv_gpiote_in_init(PIN_IN6, &amp;amp;in_config, in_pin_handler);
    APP_ERROR_CHECK(err_code);

	//Enable pin events, interrupt is specifically enabled for high accuracy pins to function.
	//For low accuracy interrupt is always enabled.
    nrf_drv_gpiote_in_event_enable(PIN_IN, true);
    nrf_drv_gpiote_in_event_enable(PIN_IN2, true);
    nrf_drv_gpiote_in_event_enable(PIN_IN3, true);
    nrf_drv_gpiote_in_event_enable(PIN_IN4, true);
	nrf_drv_gpiote_in_event_enable(PIN_IN5, true);
	nrf_drv_gpiote_in_event_enable(PIN_IN6, true);
}



/**
 * @brief Function for application main entry.
 */
int main(void)
{
    gpio_init();

    while (true)
    {
        // Do nothing.
    }
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Best regards&lt;/p&gt;
&lt;p&gt;Jørn Frøysa&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>