<?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 BSP long push event to enter system off mode</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/44863/using-bsp-long-push-event-to-enter-system-off-mode</link><description>Hi, 
 I am trying to use BSP button event to take the system into sleep mode. A long push turns off IO and calls power management shutdown and the same button is configured for wakeup. However the system immediately restarts after entering system off</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 14 Mar 2019 11:06:10 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/44863/using-bsp-long-push-event-to-enter-system-off-mode" /><item><title>RE: Using BSP long push event to enter system off mode</title><link>https://devzone.nordicsemi.com/thread/176146?ContentTypeID=1</link><pubDate>Thu, 14 Mar 2019 11:06:10 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2d68864f-5820-442d-a978-c5ca3695edac</guid><dc:creator>Jimmy Wong</dc:creator><description>&lt;p&gt;HI,&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;You can do this code. Create 2 app_timer as below.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;        err_code = app_timer_create(&amp;amp;m_app_shutdown_timer_id,
                                    APP_TIMER_MODE_SINGLE_SHOT,
                                    long_press_button_shutdown_timeout_handler);
        APP_ERROR_CHECK(err_code);
        
        err_code = app_timer_create(&amp;amp;m_button_long_press_timer_id,
                                    APP_TIMER_MODE_REPEATED,
                                    button_timer_handler);
        APP_ERROR_CHECK(err_code);
        
static void long_press_button_shutdown_timeout_handler(void *unused)
{
        uint32_t err_code;
        UNUSED_PARAMETER(unused);

        drv_ssd1306_power_off();

        err_code = app_timer_stop_all();
        APP_ERROR_CHECK(err_code);

        delay_ms(10);

        nrf_gpio_cfg_sense_input(CINETIC_BUTTON_PIN, NRF_GPIO_PIN_PULLUP, NRF_GPIO_PIN_SENSE_LOW);

        nrf_pwr_mgmt_shutdown(NRF_PWR_MGMT_SHUTDOWN_GOTO_SYSOFF);
}

static void button_timer_handler(void * p_context)
{
        uint32_t err_code;

        UNUSED_PARAMETER(p_context);
        NRF_LOG_INFO(&amp;quot;Long Press button count %d&amp;quot;, m_button_ticks_count);
        m_button_ticks_count++;

        if (m_button_ticks_count &amp;gt; LONG_PRESS_BUTTON_COUNT)
        {
                m_shutdown_is_request = true;

                app_button_disable();
                err_code = app_timer_stop(m_button_long_press_timer_id);
                APP_ERROR_CHECK(err_code);

                NRF_LOG_INFO(&amp;quot;Prepare to shutdown the device&amp;quot;);
                err_code = app_timer_start(m_app_shutdown_timer_id, LONG_PRESS_BUTTON_SHUTDOWN_TIMER_INTERVAL, NULL);
                APP_ERROR_CHECK(err_code);
        }
}

static void button_evt_handler(uint8_t pin_no, uint8_t button_action)
{
        uint32_t err_code;
        static uint8_t current_long_push_pin_no;

        switch (pin_no) {
        case KEY_BUTTON_PIN:
        {
                switch (button_action)
                {
                case APP_BUTTON_PUSH:
                        m_press_is_button = true;
                        if (m_button_ticks_count == 0)
                        {
                                err_code = app_timer_start(m_button_long_press_timer_id, LONG_PRESS_BUTTON_TIMER_INTERVAL, NULL);
                                APP_ERROR_CHECK(err_code);
                                m_button_ticks_count++;
                        }
&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>