<?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>How to detect GPIO interrupt source from deep sleep</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/87925/how-to-detect-gpio-interrupt-source-from-deep-sleep</link><description>Hi, 
 in my application I have setup the nRF52 to wake-up from deep sleep if a low value is detected on either of two GPIOs (4 and 5). What I&amp;#39;m trying to achieve, is to be able to detect upon wakeup which of the two has caused the interrupt. The issue</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 28 Jun 2022 23:56:07 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/87925/how-to-detect-gpio-interrupt-source-from-deep-sleep" /><item><title>RE: How to detect GPIO interrupt source from deep sleep</title><link>https://devzone.nordicsemi.com/thread/374639?ContentTypeID=1</link><pubDate>Tue, 28 Jun 2022 23:56:07 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:7df5f6f7-a803-486b-aa9e-02c54bb528ea</guid><dc:creator>Mike Austin (LPI)</dc:creator><description>&lt;p&gt;Not sure if you got this sorted, but I&amp;#39;ve just been through this whole process myself.&amp;nbsp; A couple of things I uncovered:&lt;/p&gt;
&lt;p&gt;1. If you are using the nRF Connect SDK, this automatically enables the LFCLK, which adds a 300-400msec delay between the GPIO triggering your device out of deep sleep and your main.c code actually firing up.&amp;nbsp; Things can happen in this time that may impact the status of the LATCH register.&amp;nbsp; You can get around this by using the SYS_INIT function and running the code you need to have run (e.g. capturing the status of the LATCH register) in one of the pre-kernel states.&amp;nbsp; Below is how I did it in my code.&lt;br /&gt;&lt;pre class="ui-code" data-mode="text"&gt;/* Grabs contents of RESETREAS and LATCH registers  */
static int detect_wakeup_latch(const struct device *dev)
{
	ARG_UNUSED(dev);

	/* Check status of RESETREAS register to determine what caused exit from System OFF */
	reset_reason = NRF_POWER-&amp;gt;RESETREAS;
	(void)NRF_TIMER0-&amp;gt;EVENTS_COMPARE[0];

	/* Record status of LATCH register to check with GPIO triggered exit from System OFF (if applicable) */
	gpio_trigger = NRF_GPIO-&amp;gt;LATCH;
	
	/* Disable inputs from affecting the DETECT signal, which should preserve LATCH and prevent spurious interrupts */
	gpio_pin_trig_disable();

	return (0);
}

SYS_INIT(detect_wakeup_latch, PRE_KERNEL_1, 0);&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;2.&amp;nbsp; If you have OTA DFU functionality enabled, then the MCUBoot can scramble your LATCH register as well.&amp;nbsp; To get around that, you need to add an mcuboot.config file in a sub-directory called {your_project}/child_image.&amp;nbsp; The mcuboot.conf file just needs to contain the following:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;CONFIG_GPIO=n&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Running the MCUBoot takes around 300-400msec, so that will then push your SYS_INIT function out by the same amount of time after the GPIO trigger.&lt;/p&gt;
&lt;p&gt;3.&amp;nbsp; Just before my device goes back to sleep, I set up the appropriate GPIO so that their PIN_CFG[n].SENSE is set appropriately.&amp;nbsp; You can do this at a register level directly, or using one of the API&amp;#39;s.&amp;nbsp; Below&amp;nbsp;is the method I use for setting one of the buttons on the nRF52-DK to be my GPIO trigger (button corresponds to P0.13).&amp;nbsp; This will trigger the device out of sleep when the GPIO input goes low&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;nrf_gpio_cfg_sense_input(sml_strike.pin, NRF_GPIO_PIN_PULLUP, NRF_GPIO_PIN_SENSE_LOW);&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;So, with everything set up as above in my code, things go like this:&lt;/p&gt;
&lt;p&gt;1. GPIO triggers deivce out of sleep&lt;/p&gt;
&lt;p&gt;2. MCUBoot validates code in memory and then passes control to that once its happy&lt;/p&gt;
&lt;p&gt;3. SYS_INIT is called and I grab the value of RESETREAS and LATCH registers&lt;/p&gt;
&lt;p&gt;4. main.c code starts running&lt;/p&gt;
&lt;p&gt;Took me about a month to get to this point!!&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Cheers,&lt;/p&gt;
&lt;p&gt;Mike&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to detect GPIO interrupt source from deep sleep</title><link>https://devzone.nordicsemi.com/thread/368183?ContentTypeID=1</link><pubDate>Wed, 18 May 2022 05:58:14 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a1193284-bc92-4945-87f1-640ab50ddd39</guid><dc:creator>Simonr</dc:creator><description>&lt;p&gt;Hi&lt;/p&gt;
&lt;p&gt;I would suggest checking out&lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/42399/understanding-how-the-detect-signal-works-and-how-to-clear-it/165223#165223"&gt; this thread&lt;/a&gt; where my colleague Håkon discuss and explains how to use the DETECT signal and LATCH register. There are no example projects specifically showcasing the LATCH registers features, but any that use the &lt;strong&gt;nrfx_gpiote&lt;/strong&gt; driver should be rather easy to implement.&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Simon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to detect GPIO interrupt source from deep sleep</title><link>https://devzone.nordicsemi.com/thread/367917?ContentTypeID=1</link><pubDate>Sat, 14 May 2022 18:18:15 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:eec553b3-d6e2-47f3-9140-15e0b6ccb2d2</guid><dc:creator>nickagian</dc:creator><description>&lt;p&gt;Hm, that&amp;#39;s a good idea! &lt;span class="emoticon" data-url="https://devzone.nordicsemi.com/cfs-file/__key/system/emoji/1f44d.svg" title="Thumbsup"&gt;&amp;#x1f44d;&lt;/span&gt;&amp;nbsp;I&amp;#39;m using nRF52832, so it seams that LATCH is supported. Do you know if there is any application example that uses this feature?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to detect GPIO interrupt source from deep sleep</title><link>https://devzone.nordicsemi.com/thread/367911?ContentTypeID=1</link><pubDate>Sat, 14 May 2022 08:57:08 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ecb8e0c7-59d9-478a-a95f-2138bb4497f5</guid><dc:creator>Turbo J</dc:creator><description>&lt;p&gt;Check if your chip supports the LATCH register in GPIO. The triggered pin should read a 1 in that register.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>