<?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>Using one button How to enter into Deep sleep mode and wake up the device</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/114999/using-one-button-how-to-enter-into-deep-sleep-mode-and-wake-up-the-device</link><description>Hello! I am using nRF Connect SDK 2.6.0v. I want to enter the device into deep sleep mode when i press the button 2 sec When Next time I press the button 2 sec, wake up from deep sleep mode I tried but its not working as expected I want to use GPIO pin</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 25 Sep 2024 09:06:39 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/114999/using-one-button-how-to-enter-into-deep-sleep-mode-and-wake-up-the-device" /><item><title>RE: Using one button How to enter into Deep sleep mode and wake up the device</title><link>https://devzone.nordicsemi.com/thread/503693?ContentTypeID=1</link><pubDate>Wed, 25 Sep 2024 09:06:39 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2eb12b2a-5b25-4a7d-878f-146bfd139f9f</guid><dc:creator>Madhu Mohan Reddy</dc:creator><description>&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;void button_pressed(const struct device *dev, struct gpio_callback *cb, uint32_t pins)
{
	if(BIT(button.pin) &amp;amp; pins)
	{
		if(gpio_pin_get_dt(&amp;amp;button))
		{
			k_timer_start(&amp;amp;mytimer, K_SECONDS(2), K_NO_WAIT);
			printk(&amp;quot;Button pressed at %&amp;quot; PRIu32 &amp;quot;\n&amp;quot;, k_cycle_get_32());

		}
		else
		{
		    k_timer_stop(&amp;amp;mytimer);
		}
		
	}
	
}
/*Define a variable of type static struct gpio_callback */
static struct gpio_callback button_cb_data;

struct k_work ads_work;
/* timer call back function */
static void my_timer(struct k_timer *dummy)
{
	if(gpio_pin_get_dt(&amp;amp;button))
	{
		printk(&amp;quot;work in timer&amp;quot;);
		k_work_submit(&amp;amp;ads_work);
	}

}
struct k_timer mytimer;


static void ads_work_cb(struct k_work *work)
{
		printk(&amp;quot;Button presssed to off the device partially\n&amp;quot;);
		gpio_pin_set_dt(&amp;amp;led, 1);
		sys_poweroff();
		//nrf_power_system_off(NRF_POWER);
		//NVIC_SystemReset();
	
			
		
	
	
}

in main()
	ret = gpio_pin_configure_dt(&amp;amp;button, GPIO_INPUT);
	if (ret &amp;lt; 0) {
		return -1;
	}
	/* STEP 3 - Configure the interrupt on the button&amp;#39;s pin */
	ret = gpio_pin_interrupt_configure_dt(&amp;amp;button, GPIO_INT_LEVEL_ACTIVE);

	/* STEP 6 - Initialize the static struct gpio_callback variable   */
    gpio_init_callback(&amp;amp;button_cb_data, button_pressed, BIT(button.pin)); 	
	
	/* STEP 7 - Add the callback function by calling gpio_add_callback()   */
	gpio_add_callback(button.port, &amp;amp;button_cb_data);
	k_work_init(&amp;amp;ads_work, ads_work_cb);&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;
[quote userid="131149" url="~/f/nordic-q-a/114999/using-one-button-how-to-enter-into-deep-sleep-mode-and-wake-up-the-device"]&lt;span&gt;I want to enter the device into deep sleep mode when i press the button 2 sec&lt;/span&gt;&lt;br /&gt;&lt;span&gt;When Next time I press the button 2 sec, wake up from deep sleep mode&amp;nbsp;&lt;/span&gt;[/quote]
&lt;p&gt;I am expecting like this&lt;/p&gt;
[quote userid="131149" url="~/f/nordic-q-a/114999/using-one-button-how-to-enter-into-deep-sleep-mode-and-wake-up-the-device"]I&amp;nbsp; want to use GPIO pin to power off and power on the device&amp;nbsp;[/quote]
&lt;p&gt;using button to power off and power on the device using GPIO&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Using one button How to enter into Deep sleep mode and wake up the device</title><link>https://devzone.nordicsemi.com/thread/503688?ContentTypeID=1</link><pubDate>Wed, 25 Sep 2024 08:59:26 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:3fa99871-20df-4bcd-818f-c0e89e0d7195</guid><dc:creator>Susheel Nuguru</dc:creator><description>&lt;p&gt;You should&amp;nbsp;give&amp;nbsp;a bit more on information like what does it mean by &amp;quot;not working as expected&amp;quot;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;code snippets of the power on power off&lt;/li&gt;
&lt;li&gt;code snippets for configuring gpio for power off and wakeup configuration.&lt;/li&gt;
&lt;li&gt;What steps you followed&amp;nbsp;&lt;/li&gt;
&lt;li&gt;and finally what steps you tried to debug.&lt;/li&gt;
&lt;/ol&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>