<?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>Zephyr GPIO Interrupt</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/90232/zephyr-gpio-interrupt</link><description>I am porting my code from Nordic SDK16 to Zephyr and NRF Connect SDK 2.0. I am working on putting a chip into sleep mode and set up a wake up on a press of the button. Everything seems to be working ok on the first run but after the chip wakes up, the</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Fri, 10 Jan 2025 08:08:56 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/90232/zephyr-gpio-interrupt" /><item><title>RE: Zephyr GPIO Interrupt</title><link>https://devzone.nordicsemi.com/thread/517867?ContentTypeID=1</link><pubDate>Fri, 10 Jan 2025 08:08:56 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:bcb05208-0b95-4fce-8e5b-5f0ab0b01369</guid><dc:creator>Andrea Verdecchia</dc:creator><description>&lt;p&gt;I&amp;#39;ve the same problem. Did you solve it?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Zephyr GPIO Interrupt</title><link>https://devzone.nordicsemi.com/thread/393758?ContentTypeID=1</link><pubDate>Wed, 02 Nov 2022 22:28:26 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d1485694-7c25-4ac7-8bc0-fac6dad74eb9</guid><dc:creator>skim</dc:creator><description>&lt;p&gt;At your code line 49:&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;gpio_pin_interrupt_configure_dt(&amp;amp;button, GPIO_INT_EDGE_BOTH);&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Instead of&amp;nbsp;&lt;span&gt;&lt;strong&gt;GPIO_INT_EDGE_BOTH&lt;/strong&gt;, try using others: e.g.&amp;nbsp;&lt;a title="GPIO_INT_EDGE_TO_ACTIVE" href="https://docs.zephyrproject.org/latest/hardware/peripherals/gpio.html#c.GPIO_INT_EDGE_TO_ACTIVE" rel="noopener noreferrer" target="_blank"&gt;GPIO_INT_EDGE_TO_ACTIVE&lt;/a&gt;,&amp;nbsp;&lt;a title="GPIO_INT_LEVEL_INACTIVE" href="https://docs.zephyrproject.org/latest/hardware/peripherals/gpio.html#c.GPIO_INT_LEVEL_INACTIVE" rel="noopener noreferrer" target="_blank"&gt;GPIO_INT_LEVEL_INACTIVE&lt;/a&gt;, or any other &lt;strong&gt;&lt;/strong&gt;interrupt config flags.&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;You can find other interrupt config flags at Zephyr GPIO document page, under&amp;nbsp;&lt;strong&gt;GPIO interrupt configuration flags&lt;/strong&gt;. (&lt;a title="GPIO-Zephyr" href="https://docs.zephyrproject.org/latest/hardware/peripherals/gpio.html" rel="noopener noreferrer" target="_blank"&gt;GPIO-Zephyr&lt;/a&gt;)&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Zephyr GPIO Interrupt</title><link>https://devzone.nordicsemi.com/thread/378532?ContentTypeID=1</link><pubDate>Mon, 25 Jul 2022 11:56:12 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:12722a88-3ea2-4d37-96ce-f277140182ed</guid><dc:creator>Susheel Nuguru</dc:creator><description>&lt;p&gt;I can reproduce this, but do not know why it behaves like this. I need to investigate the nrfx driver behaviour&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Zephyr GPIO Interrupt</title><link>https://devzone.nordicsemi.com/thread/378445?ContentTypeID=1</link><pubDate>Sun, 24 Jul 2022 18:42:06 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0c789aaa-2bdc-433d-980d-852a6932cb44</guid><dc:creator>akaun</dc:creator><description>&lt;p&gt;OK here is log, first I press and release button, it goes to sleep. Then i press to wake up, it wakes up. Then I press and release again and you can see call back is fired twice. I added a time stamp inside callback before if statement &lt;span&gt;printk&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;&amp;quot;Button pressed at %&amp;quot;&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;PRIu32&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;\n&lt;/span&gt;&lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;, &lt;/span&gt;&lt;span&gt;k_cycle_get_32&lt;/span&gt;&lt;span&gt;());&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;*** Booting Zephyr OS build v3.0.99-ncs1 ***&lt;br /&gt;Set up button at GPIO_0 pin 11&lt;br /&gt;Button pressed at 176252&lt;br /&gt;Button pressed...&lt;br /&gt;Button pressed at 210136&lt;br /&gt;Button released...&lt;br /&gt;Preparing wake up&lt;br /&gt;�*** Booting Zephyr OS build v3.0.99-ncs1 ***&lt;br /&gt;Set up button at GPIO_0 pin 11&lt;br /&gt;Button pressed at 246061&lt;br /&gt;Button pressed...&lt;br /&gt;Button pressed at 246189&lt;br /&gt;Button pressed...&lt;br /&gt;Button pressed at 283049&lt;br /&gt;Button released...&lt;br /&gt;Preparing wake up&lt;br /&gt;Power down&lt;br /&gt;Button pressed at 283276&lt;br /&gt;Button released...&lt;br /&gt;Preparing wake up&lt;br /&gt;�ower down&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Zephyr GPIO Interrupt</title><link>https://devzone.nordicsemi.com/thread/378444?ContentTypeID=1</link><pubDate>Sun, 24 Jul 2022 17:42:25 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e0ff9209-af70-4902-85fe-eb0fafeee615</guid><dc:creator>Susheel Nuguru</dc:creator><description>&lt;p&gt;Single press most likely is not firing the interrupt twice, it is the way you are printing the logs.&lt;/p&gt;
&lt;p&gt;Can you add another log just after entereing&amp;nbsp;button_pressed() but before the if condition and show me the logs again.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Zephyr GPIO Interrupt</title><link>https://devzone.nordicsemi.com/thread/378336?ContentTypeID=1</link><pubDate>Fri, 22 Jul 2022 13:38:40 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:355bdc2f-4b57-4d19-8091-48c25cd550d8</guid><dc:creator>akaun</dc:creator><description>&lt;p&gt;This is a simplified code, where in reality the button needs to be help for half a second for power down to begin. That shouldn&amp;#39;t really solve the problem as to why the gpio callback gets fired twice on &amp;quot;SINGLE&amp;quot; press of the button and then release.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Zephyr GPIO Interrupt</title><link>https://devzone.nordicsemi.com/thread/378204?ContentTypeID=1</link><pubDate>Fri, 22 Jul 2022 04:41:15 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:51c03721-4ac4-4bd0-a311-817cca213f60</guid><dc:creator>Susheel Nuguru</dc:creator><description>&lt;p&gt;The logic in your code seems to have a bug.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;static void button_pressed(const struct device *dev, struct gpio_callback *cb, uint32_t pins)
{
    if (gpio_pin_get(button.port, button.pin)) {
        printk(&amp;quot;Button pressed...\r\n&amp;quot;);
    } else {
        printk(&amp;quot;Button released...\r\n&amp;quot;);
        prepare_wake_up();
        power_down();
    }
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Inside the button_pressed callback&amp;nbsp;reading the gpio pin status after wakeup might read that the button is released if you pressed and released the button fast. Instead do something like below&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;static void button_interrupt(const struct device *dev,
			     struct gpio_callback *cb,
			     uint32_t pins)
{
static bool pressed = false;

	pressed = !pressed;
	printk(&amp;quot;Button %s\n&amp;quot;, pressed ? &amp;quot;pressed&amp;quot; : &amp;quot;released&amp;quot;);

	if (pressed) {
        ...
	}
    else {
        ...
    }
    ...
}&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>