<?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>Use 1 button to exit/enter system off mode</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/77810/use-1-button-to-exit-enter-system-off-mode</link><description>Hi, I&amp;#39;m learning the nrf51-powerdown-example &amp;lt;system_off_wakeup_on_gpiote&amp;gt; from github. 
 
 My understanding of the code is: 
 1) When button 0 (Power down) button is pressed (high to low), in_pin_handler() starts 
 2) We firstly turn off LED, uninitialize</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 11 Feb 2025 23:54:11 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/77810/use-1-button-to-exit-enter-system-off-mode" /><item><title>RE: Use 1 button to exit/enter system off mode</title><link>https://devzone.nordicsemi.com/thread/522541?ContentTypeID=1</link><pubDate>Tue, 11 Feb 2025 23:54:11 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1a93522a-f387-4f8e-998b-dcde21654600</guid><dc:creator>okay_-_computer</dc:creator><description>&lt;p&gt;Did you resolve this?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Use 1 button to exit/enter system off mode</title><link>https://devzone.nordicsemi.com/thread/484815?ContentTypeID=1</link><pubDate>Fri, 17 May 2024 10:57:40 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a728421b-fb7e-4c0c-a4c0-976b3e5c9fbb</guid><dc:creator>srinivasa m</dc:creator><description>&lt;p&gt;Hi StevenW807,&lt;/p&gt;
&lt;p&gt;the solution you made for system ON/OFF using single button is working fine. but I integrated this code with BLE peripheral code and started working with device. turn ON/OFF functions are working only if BLE IS not pairing with other device but if i perform device turn OFF after it is connected with BLE device it is not turning OFF. if I reset the device then only the device is working.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;kindly help me on this issue&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;thank&amp;amp;regards&lt;/p&gt;
&lt;p&gt;Srinivasa m&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Use 1 button to exit/enter system off mode</title><link>https://devzone.nordicsemi.com/thread/323628?ContentTypeID=1</link><pubDate>Fri, 06 Aug 2021 04:09:44 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ddce4c22-e800-491b-95f2-13d280e6f61a</guid><dc:creator>StevenW807</dc:creator><description>&lt;p&gt;Problem solved. Here is my code of &amp;quot;&lt;strong&gt;using 1 button to turn on/off the system&lt;/strong&gt;&amp;quot;. Happy to share/use the code if you&amp;#39;re interested.&lt;/p&gt;
&lt;p&gt;You may connect your nRF52 DK with PuTTY. Press button 0 to see that the system has been turned on/off.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;
#include &amp;lt;stdbool.h&amp;gt;
#include &amp;lt;stdint.h&amp;gt;
#include &amp;quot;boards.h&amp;quot;
#include &amp;quot;bsp.h&amp;quot;
#include &amp;quot;bsp_nfc.h&amp;quot;
#include &amp;quot;app_timer.h&amp;quot;
#include &amp;quot;nordic_common.h&amp;quot;
#include &amp;quot;app_error.h&amp;quot;
#include &amp;quot;nrf_drv_clock.h&amp;quot;
#include &amp;quot;nrf_pwr_mgmt.h&amp;quot;

#include &amp;quot;nrf_log.h&amp;quot;
#include &amp;quot;nrf_log_ctrl.h&amp;quot;
#include &amp;quot;nrf_log_default_backends.h&amp;quot;

#if NRF_PWR_MGMT_CONFIG_USE_SCHEDULER
#include &amp;quot;app_scheduler.h&amp;quot;
#define APP_SCHED_MAX_EVENT_SIZE    0   /**&amp;lt; Maximum size of scheduler events. */
#define APP_SCHED_QUEUE_SIZE        4   /**&amp;lt; Maximum number of events in the scheduler queue. */
#endif // NRF_PWR_MGMT_CONFIG_USE_SCHEDULER

#define BTN_ID                0


/**@brief Handler for shutdown preparation.
 */
bool shutdown_handler(nrf_pwr_mgmt_evt_t event)
{

    uint32_t err_code;

    switch (event)
    {
        case NRF_PWR_MGMT_EVT_PREPARE_WAKEUP:
            NRF_LOG_INFO(&amp;quot;NRF_PWR_MGMT_EVT_PREPARE_WAKEUP&amp;quot;);
            err_code = bsp_buttons_disable();
            // Suppress NRF_ERROR_NOT_SUPPORTED return code.
            UNUSED_VARIABLE(err_code);

            err_code = bsp_wakeup_button_enable(BTN_ID);
            // Suppress NRF_ERROR_NOT_SUPPORTED return code.
            UNUSED_VARIABLE(err_code);

            break;
    }

    err_code = app_timer_stop_all();
    APP_ERROR_CHECK(err_code);

    return true;
}





/**@brief Register application shutdown handler with priority 0. */
NRF_PWR_MGMT_HANDLER_REGISTER(shutdown_handler, 0);






/**@brief Function for handling BSP events.
 */
static void bsp_evt_handler(bsp_event_t evt)
{
#if NRF_PWR_MGMT_CONFIG_STANDBY_TIMEOUT_ENABLED
    nrf_pwr_mgmt_feed();
    NRF_LOG_INFO(&amp;quot;Power management fed&amp;quot;);
#endif // NRF_PWR_MGMT_CONFIG_STANDBY_TIMEOUT_ENABLED

    switch (evt)
    {
        
        case BSP_EVENT_DEFAULT:

            break;

        case BSP_EVENT_SYSOFF:

                // Application will prepare the wakeup mechanism: NRF_PWR_MGMT_EVT_PREPARE_WAKEUP
                /**@brief Function for shutting down the system.
                 * @param[in] shutdown_type     Type of operation.
                 * @details All callbacks will be executed prior to shutdown.
                 */
                nrf_pwr_mgmt_shutdown(NRF_PWR_MGMT_SHUTDOWN_GOTO_SYSOFF);
                // NRF_LOG_INFO(&amp;quot;2) System OFF is entered\r\n&amp;quot;);
                // NRF_POWER-&amp;gt;SYSTEMOFF = 1;
            
            break;


        default:
            return; // no implementation needed
    }
}








/**@brief Function for initializing low-frequency clock.
 */
static void lfclk_config(void)
{
    ret_code_t err_code = nrf_drv_clock_init();
    APP_ERROR_CHECK(err_code);

    nrf_drv_clock_lfclk_request(NULL);
}






/**@brief Function for initializing the BSP module.
 */
static void bsp_configuration()
{
    uint32_t err_code;

    err_code = bsp_init(BSP_INIT_BUTTONS, bsp_evt_handler);
    APP_ERROR_CHECK(err_code);

    err_code = bsp_event_to_button_action_assign(BTN_ID,
                                                 BSP_BUTTON_ACTION_LONG_PUSH,
                                                 BSP_EVENT_DEFAULT);
    APP_ERROR_CHECK(err_code);

    err_code = bsp_event_to_button_action_assign(BTN_ID,
                                                 BSP_BUTTON_ACTION_RELEASE,
                                                 BSP_EVENT_SYSOFF);
    APP_ERROR_CHECK(err_code);

}






/**
 * @brief Function for application main entry.
 */
int main(void)
{
    
    APP_ERROR_CHECK(NRF_LOG_INIT(NULL));
    NRF_LOG_DEFAULT_BACKENDS_INIT();

    NRF_LOG_INFO(&amp;quot;Power Management example&amp;quot;);

    lfclk_config();

    uint32_t err_code = app_timer_init();
    APP_ERROR_CHECK(err_code);

#if NRF_PWR_MGMT_CONFIG_USE_SCHEDULER
    APP_SCHED_INIT(APP_SCHED_MAX_EVENT_SIZE, APP_SCHED_QUEUE_SIZE);
#endif // NRF_PWR_MGMT_CONFIG_USE_SCHEDULER
    bsp_configuration();

    ret_code_t ret_code = nrf_pwr_mgmt_init();
    APP_ERROR_CHECK(ret_code);

    while (true)
    {
#if NRF_PWR_MGMT_CONFIG_USE_SCHEDULER
        app_sched_execute();
#endif // NRF_PWR_MGMT_CONFIG_USE_SCHEDULER

        if (NRF_LOG_PROCESS() == false)
        {
            nrf_pwr_mgmt_run();
        }
    }
}











&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src="https://devzone.nordicsemi.com/resized-image/__size/320x240/__key/communityserver-discussions-components-files/4/pastedimage1628223129816v1.png" alt=" " /&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Use 1 button to exit/enter system off mode</title><link>https://devzone.nordicsemi.com/thread/322523?ContentTypeID=1</link><pubDate>Thu, 29 Jul 2021 15:32:34 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:bc04a1a0-e232-497f-937a-3311b3af36c0</guid><dc:creator>J&amp;#248;rgen Holmefjord</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;There is no HW debounce functionality in the chip. You can use the&amp;nbsp;&lt;a title="Button handling library" href="https://infocenter.nordicsemi.com/topic/sdk_nrf5_v17.0.2/lib_button.html?cp=8_1_3_7"&gt;Button handling library&lt;/a&gt;, which implements timers for button detection delay.&lt;/p&gt;
&lt;p&gt;Wakeup from system OFF will always cause a reset, and hence execution from main(). If you want to perform a different task when waking from System OFF than from Power-On-Reset, you can check the&amp;nbsp;&lt;a href="https://infocenter.nordicsemi.com/topic/com.nordic.infocenter.nrf52832.ps.v1.1/power.html#register.RESETREAS"&gt;RESETREAS register&lt;/a&gt;&lt;span&gt;&amp;nbsp;to decide what to do in start of main().&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Best regards,&lt;br /&gt;Jørgen&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Use 1 button to exit/enter system off mode</title><link>https://devzone.nordicsemi.com/thread/321821?ContentTypeID=1</link><pubDate>Mon, 26 Jul 2021 12:45:32 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d588c8be-4002-4b82-88cd-99509788cc42</guid><dc:creator>StevenW807</dc:creator><description>&lt;p&gt;Thanks for your reply, Jorgen. I modified the code. I want to:&amp;nbsp;&lt;/p&gt;
&lt;p&gt;1) When I press the button, turn on the system.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;2) Press the same button again, enter the system off state.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;3) Press again, wake up from the system off state.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Here is my code.&lt;strong&gt;&amp;nbsp;&lt;/strong&gt;Because I used HITOLO for both gpio_init() and in_pin_handler(), so &lt;strong&gt;the system always restarts at main().&lt;/strong&gt;&amp;nbsp;&lt;strong&gt;How to modify the code (i.e. what&amp;#39;s the the logic), please? Does the nRF52805 have an internal debouncing hardware circuit? If no, is there any button debouncing software example code from Nordic?&amp;nbsp;&lt;/strong&gt;Thank you very much!&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;#include &amp;lt;stdbool.h&amp;gt;
#include &amp;quot;nrf.h&amp;quot;
#include &amp;quot;nrf_drv_gpiote.h&amp;quot;
#include &amp;quot;app_error.h&amp;quot;
#include &amp;quot;boards.h&amp;quot;




#define SWITCH_PIN          BSP_BUTTON_0
#define LED_PIN_OUT         BSP_LED_0


/**
 * @brief Interrupt handler for wakeup pins
 */
void in_pin_handler(nrf_drv_gpiote_pin_t pin, nrf_gpiote_polarity_t action)
{
    ret_code_t err_code;
    printf(&amp;quot;in_pin_handler() entered\r\n&amp;quot;);
    if (pin == SWITCH_PIN)
    {
        //Turn off LED to indicate the nRF5x is in System-off mode
        //NRF_LOG_INFO(&amp;quot;Turn off LED to indicate the nRF5x is in System-off mode&amp;quot;);
        nrf_drv_gpiote_out_set(LED_PIN_OUT);
        
        //Disable power-down button to prevent System-off wakeup
        //NRF_LOG_INFO(&amp;quot;Disable power-down button to prevent System-off wakeup&amp;quot;);
        nrf_drv_gpiote_in_uninit(SWITCH_PIN);           
        nrf_drv_gpiote_in_event_disable(SWITCH_PIN);
        
        //Configure wake-up button
        nrf_drv_gpiote_in_config_t in_config = GPIOTE_CONFIG_IN_SENSE_HITOLO(false);     //Configure to generate interrupt and wakeup on pin signal low. &amp;quot;false&amp;quot; means that gpiote will use the PORT event, which is low power, i.e. does not add any noticable current consumption (&amp;lt;&amp;lt;1uA). Setting this to &amp;quot;true&amp;quot; will make the gpiote module use GPIOTE-&amp;gt;IN events which add ~8uA for nRF52 and ~1mA for nRF51.
        in_config.pull = NRF_GPIO_PIN_PULLUP;                                            //Configure pullup for input pin to prevent it from floting. Pin is pulled down when button is pressed on nRF5x-DK boards, see figure two in http://infocenter.nordicsemi.com/topic/com.nordic.infocenter.nrf52/dita/nrf52/development/dev_kit_v1.1.0/hw_btns_leds.html?cp=2_0_0_1_4
        err_code = nrf_drv_gpiote_in_init(SWITCH_PIN, &amp;amp;in_config, NULL);             //Initialize the wake-up pin
        APP_ERROR_CHECK(err_code);                                                       //Check error code returned
        nrf_drv_gpiote_in_event_enable(SWITCH_PIN, true);                            //Enable event and interrupt for the wakeup pin
        printf(&amp;quot;Configured switch to wake-up\r\n&amp;quot;);

        //Enter System-off
        printf(&amp;quot;Enter System-off\r\n\r\n&amp;quot;);
        NRF_POWER-&amp;gt;SYSTEMOFF = 1;
        
    }
}




/**
 * @brief Function for configuring: SWITCH_PIN (BUTTON_1) to enter System-off, 
 * SWITCH_PIN pin (BUTTON_2) to wake up from System-off, and LED_PIN_OUT pin for LED_1 output
 */
static void gpio_init(void)
{
    ret_code_t err_code;

    //Initialize gpiote module
    err_code = nrf_drv_gpiote_init();
    APP_ERROR_CHECK(err_code);
    
    //Initialize output pin, and Turn on LED 4
    nrf_drv_gpiote_out_config_t out_config = GPIOTE_CONFIG_OUT_SIMPLE(false);        	//Configure output button
    err_code = nrf_drv_gpiote_out_init(LED_PIN_OUT, &amp;amp;out_config);                        	//Initialize output button
    APP_ERROR_CHECK(err_code);                                                     	//Check potential error
    nrf_drv_gpiote_out_clear(LED_PIN_OUT);                                               	//Turn on LED to indicate that nRF5x is not in System-off mode

    //Configure sense input pin to enable wakeup and interrupt on button press.
    nrf_drv_gpiote_in_config_t in_config = GPIOTE_CONFIG_IN_SENSE_HITOLO(false);        //Configure to generate interrupt and go to system_off on pin signal high. &amp;quot;false&amp;quot; means that gpiote will use the PORT event, which is low power, i.e. does not add any noticable current consumption (&amp;lt;&amp;lt;1uA). Setting this to &amp;quot;true&amp;quot; will make the gpiote module use GPIOTE-&amp;gt;IN events which add ~8uA for nRF52 and ~1mA for nRF51.
    in_config.pull = NRF_GPIO_PIN_PULLUP;                                             	//Configure pullup for input pin to prevent it from floting. Pin is pulled down when button is pressed on nRF5x-DK boards, see figure two in http://infocenter.nordicsemi.com/topic/com.nordic.infocenter.nrf52/dita/nrf52/development/dev_kit_v1.1.0/hw_btns_leds.html?cp=2_0_0_1_4		
    err_code = nrf_drv_gpiote_in_init(SWITCH_PIN, &amp;amp;in_config, in_pin_handler);   //Initialize the pin with interrupt handler in_pin_handler
    APP_ERROR_CHECK(err_code);                                                          //Check potential error
    nrf_drv_gpiote_in_event_enable(SWITCH_PIN, true);
    
    printf(&amp;quot;gpio_init() completed\r\n&amp;quot;);
}




/**@brief Function for application main entry.
 */
int main(void)
{
    printf(&amp;quot;Enter main()\r\n&amp;quot;);
    gpio_init();

    while (true)
    {
        //Enter System-on idle mode
        __WFE();
        __SEV();
        __WFE();	
    }
}&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Use 1 button to exit/enter system off mode</title><link>https://devzone.nordicsemi.com/thread/321601?ContentTypeID=1</link><pubDate>Fri, 23 Jul 2021 14:31:55 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:39f72ecd-3826-4b5a-8dd8-a4e1491784e6</guid><dc:creator>J&amp;#248;rgen Holmefjord</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Wakeup from &lt;a href="https://infocenter.nordicsemi.com/topic/com.nordic.infocenter.nrf52832.ps.v1.1/power.html#unique_1707892264"&gt;System OFF&lt;/a&gt; is a pure HW feature. The GPIO is configured to sense the state of the pin. If the pin state changes, this will generate a HW signal inside the chip to start the wakeup procedure. Note that wakeup from System OFF will always cause a chip reset, it will not continue executing code from where you put it to sleep. You can use the &lt;a href="https://infocenter.nordicsemi.com/topic/com.nordic.infocenter.nrf52832.ps.v1.1/power.html#register.RESETREAS"&gt;RESETREAS register&lt;/a&gt; to check if the startup was from a System OFF event or a reset.&lt;/li&gt;
&lt;li&gt;Yes, there should be no issues with using the same pin for power-down/power-up. Once you have entered the&amp;nbsp;in_pin_handler to power down, you can reconfigure the same pin as wakeup source from System OFF before entering this state.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Best regards,&lt;br /&gt;Jørgen&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>