<?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>Button interrupt , gpiote</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/56016/button-interrupt-gpiote</link><description>HEllo; I&amp;#39;m working with nrf52832 and sdk15 , and for interrupt button i chose to work with the example &amp;quot;/nRF5_SDK_15.0.0_a53641a/examples/peripheral/pin_change_int/&amp;quot; , so my question is how we can know its pushed button(push the button two time) and long</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 23 Jan 2020 10:34:47 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/56016/button-interrupt-gpiote" /><item><title>RE: Button interrupt , gpiote</title><link>https://devzone.nordicsemi.com/thread/230551?ContentTypeID=1</link><pubDate>Thu, 23 Jan 2020 10:34:47 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c4137072-fcc8-4b7a-b900-5db2b9d907f5</guid><dc:creator>Simon</dc:creator><description>[quote user="achraf"]I think its not simple as i did[/quote]
&lt;p&gt;&amp;nbsp;I think it should be quite straightforward:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;First you call call&amp;nbsp;&lt;em&gt;timers_init()&amp;nbsp;&lt;/em&gt;and&amp;nbsp;&lt;em&gt;buttons_init()&amp;nbsp;&lt;/em&gt;in &lt;em&gt;main()&lt;/em&gt;
&lt;ul&gt;
&lt;li&gt;&lt;em&gt;timers_init()&amp;nbsp;&lt;/em&gt;will simply&amp;nbsp;initialize application timer (read more about it &lt;a href="https://devzone.nordicsemi.com/nordic/short-range-guides/b/software-development-kit/posts/application-timer-tutorial"&gt;here&lt;/a&gt;)&lt;/li&gt;
&lt;li&gt;buttons_init() will initialize&amp;nbsp;the buttons and start the timer.
&lt;ul&gt;
&lt;li&gt;It will implement a button callback that starts when button 1 is pressed&lt;/li&gt;
&lt;li&gt;It will implement a timeout handler, that will trigger&amp;nbsp;rapid and continuously after the button is pressed, that checks whether a long or short button press occurred (based on value of &lt;em&gt;cnt&lt;/em&gt;)&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;You can ignore most of the other code present (except for power management, some includes and defines)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&amp;nbsp;If anything is unclear, or if you would like me to explain anything in detail, please ask.&lt;/p&gt;
[quote user="achraf"]its based on DK other wise Im using a custom borad[/quote]
&lt;p&gt;&amp;nbsp;I think the solution should work with a custom board as well. Why do you think that matters?&lt;/p&gt;
&lt;hr /&gt;
&lt;p&gt;Some other comments about your solution:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Since you are putting the code in a loop, it is hard to know the duration of respectively a long and a short button press. In the timer-based method, you will.&lt;/li&gt;
&lt;li&gt;The solution will consume a lot of power since you are constantly polling and the CPU will always run, even when calling&amp;nbsp;&lt;em&gt;nrf_delay_ms() &lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/24632/nrf_delay_ms-consuming-too-much-power"&gt;a lot of current will be drawn&lt;/a&gt;.&lt;/em&gt;
&lt;ul&gt;
&lt;li&gt;In the timer-based method, you can put the CPU in sleep, between the increments of the counter variable &lt;em&gt;cnt&lt;/em&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Simon&lt;/p&gt;
&lt;div style="left:479px;top:350px;"&gt;
&lt;div&gt;&lt;/div&gt;
&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Button interrupt , gpiote</title><link>https://devzone.nordicsemi.com/thread/230363?ContentTypeID=1</link><pubDate>Wed, 22 Jan 2020 13:30:59 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:94f8d1f4-99ec-4943-bc5a-c7daec9c8b9a</guid><dc:creator>achraf</dc:creator><description>&lt;p&gt;Hello SImon I just want to remember you of answering me if you d like of course&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Button interrupt , gpiote</title><link>https://devzone.nordicsemi.com/thread/229966?ContentTypeID=1</link><pubDate>Mon, 20 Jan 2020 23:29:47 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4e8ee8bf-67d9-4917-981b-a285146138bb</guid><dc:creator>Simon</dc:creator><description>&lt;p&gt;I am sorry for the delay, I have been quite busy lately. I am currently looking into your problem and will provide you with an answer asap.&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: Button interrupt , gpiote</title><link>https://devzone.nordicsemi.com/thread/229091?ContentTypeID=1</link><pubDate>Tue, 14 Jan 2020 14:49:30 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:93ffa163-5438-4a58-a3f4-8b7dcd47e3f6</guid><dc:creator>achraf</dc:creator><description>[quote userid="72692" url="~/f/nordic-q-a/56016/button-interrupt-gpiote/227991"]I would like to ask why you don&amp;#39;t use the solution already provided in &lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/43506/how-to-use-bsp_button_action_push-and-bsp_button_action_long_push-on-the-same-button-with-two-different-functions"&gt;this thread&lt;/a&gt;?[/quote]
&lt;p&gt;I think its not simple as i did, and its based on DK other wise Im using a custom borad. I&amp;#39;ll use timer in my&amp;nbsp;application (based on ble_hrs example)&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Button interrupt , gpiote</title><link>https://devzone.nordicsemi.com/thread/227991?ContentTypeID=1</link><pubDate>Tue, 07 Jan 2020 19:42:19 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:67a6f395-47ad-49a2-8cd8-6ecfcd066833</guid><dc:creator>Simon</dc:creator><description>&lt;p&gt;Before continuing, I would like to ask why you don&amp;#39;t use the solution already provided in &lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/43506/how-to-use-bsp_button_action_push-and-bsp_button_action_long_push-on-the-same-button-with-two-different-functions"&gt;this thread&lt;/a&gt;? That solution is based on a timer, which makes it more accurate and energy-efficient.&amp;nbsp;&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: Button interrupt , gpiote</title><link>https://devzone.nordicsemi.com/thread/227218?ContentTypeID=1</link><pubDate>Thu, 02 Jan 2020 10:54:34 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9b00eb30-5004-47db-a5c7-fa9221e45b4e</guid><dc:creator>achraf</dc:creator><description>&lt;p&gt;Hello Simon thank you for your answer.&lt;br /&gt;I contiue working with the example (&lt;span&gt;examples/peripheral/pin_change_int&lt;/span&gt;), and I made this code :&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;
#include &amp;quot;nrf_delay.h&amp;quot;

#define PIN_IN 30
#define PIN_OUT 26
bool HL_state;
bool LH_state;
bool First_state;
bool up_state;
int HL_counter=0;
int LH_counter=0;
int count ;
int push_counter;
int up_counter;


void in_pin_handlerHL(nrf_drv_gpiote_pin_t pin, nrf_gpiote_polarity_t action)
{
    //nrf_drv_gpiote_out_toggle(PIN_OUT);
    NRF_GPIOTE-&amp;gt;EVENTS_IN[0] = 0;


        if (nrf_gpio_pin_read(30)==0)
        {
            HL_counter ++;
            HL_state=true;
            LH_state=false;
            LH_counter=0;
        }else{
            LH_counter ++;
            LH_state=true;
            HL_state=false;
            HL_counter=0;
        }

}
// void in_pin_handlerLH(nrf_drv_gpiote_pin_t pin, nrf_gpiote_polarity_t action)
// {
//     //nrf_drv_gpiote_out_toggle(PIN_OUT);
//     NRF_GPIOTE-&amp;gt;EVENTS_IN[0] = 0;
//     LH_counter ++;

//         if (nrf_gpio_pin_read(30)==1)
//         {
//             LH_state=true;
//             HL_state=false;
//             HL_counter=0;
//         }else{
//             LH_state=false;
//         }
// }
/**
 * @brief Function for configuring: PIN_IN pin for input, PIN_OUT pin for output,
 * and configures GPIOTE to give an interrupt on pin change.
 */
static void gpio_init(void)
{
    ret_code_t err_code;


    if (!nrf_drv_gpiote_is_init())
    {
        err_code = nrf_drv_gpiote_init();
        APP_ERROR_CHECK(err_code);
    }

    nrf_drv_gpiote_out_config_t out_config = GPIOTE_CONFIG_OUT_SIMPLE(false);

    // err_code = nrf_drv_gpiote_out_init(PIN_OUT, &amp;amp;out_config);
    // APP_ERROR_CHECK(err_code);

    nrf_drv_gpiote_in_config_t in_configHL = GPIOTE_CONFIG_IN_SENSE_TOGGLE(false);
    // nrf_drv_gpiote_in_config_t in_config = GPIOTE_CONFIG_IN_SENSE_TOGGLE(true);
    in_configHL.pull = NRF_GPIO_PIN_PULLUP;

    nrf_drv_gpiote_in_config_t in_configLH = GPIOTE_CONFIG_IN_SENSE_LOTOHI(true);
    in_configLH.pull = NRF_GPIO_PIN_PULLUP;

    err_code = nrf_drv_gpiote_in_init(PIN_IN, &amp;amp;in_configHL, in_pin_handlerHL);
    APP_ERROR_CHECK(err_code);

    // err_code = nrf_drv_gpiote_in_init(PIN_IN, &amp;amp;in_configLH, in_pin_handlerLH);
    // APP_ERROR_CHECK(err_code);

    nrf_drv_gpiote_in_event_enable(PIN_IN, true);
}

/**
 * @brief Function for application main entry.
 */
int main(void)
{
    gpio_init();

    //printf(&amp;quot;HL_state%d\n&amp;quot;, HL_state );
    //printf(&amp;quot;LH_state%d\n&amp;quot;, LH_state );
       // printf(&amp;quot;start&amp;quot;);
    while (true)
    {

        if (HL_state==true)
        {
            //printf(&amp;quot;yes\n&amp;quot;);
            First_state=true;
            count=0;

            push_counter ++;
        }else
        {
            count ++;
            //printf(&amp;quot;counter : %d\n&amp;quot;, count);
            push_counter=0;
            up_counter ++;
        }

        if (1&amp;lt;count &amp;amp;&amp;amp; count &amp;lt;5 &amp;amp;&amp;amp; First_state==true )
        {
            printf(&amp;quot;UP\n&amp;quot;);
            up_state=true;
            First_state=false;
            up_counter=0;

        }else{
            up_state==false;

        }

        if (HL_state==true &amp;amp;&amp;amp; up_state==true &amp;amp;&amp;amp; up_counter &amp;lt; 10)
        {
            printf(&amp;quot;double\n&amp;quot;);
            up_state=false;
            First_state=false;
            count=0;
            up_counter=0;

        }else{

        }

        if(20&amp;lt;push_counter &amp;amp;&amp;amp; push_counter&amp;lt;50 &amp;amp;&amp;amp; HL_state==true){

            printf(&amp;quot;hold_press\n&amp;quot;);
            up_state=false;
            First_state=false;


        }else if(push_counter&amp;gt;50 &amp;amp;&amp;amp; HL_state==true){
            printf(&amp;quot;long_press\n&amp;quot;);
            up_state=false;
            First_state=false;
            push_counter=0;

        }else{

        }

        nrf_delay_ms(100);

    }

}


/** @} */
&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;is it right ? , my question is can we do the high to lo and lo to high configuration as i commented in my code , cause it dosnt work for me , but for the moment i made it , I think it&amp;#39;s right, please give me your feed back about my code. and i hope it will not consume a lot of energy&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Button interrupt , gpiote</title><link>https://devzone.nordicsemi.com/thread/227138?ContentTypeID=1</link><pubDate>Tue, 31 Dec 2019 13:46:14 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:176282a6-2fca-4034-b1bd-ccd5539aec0c</guid><dc:creator>Simon</dc:creator><description>[quote user=""]so my question is how we can know its pushed button(push the button two time)[/quote]
&lt;p&gt;&amp;nbsp;In the pin change int example, you know that button 1 is pushed (a transition happens) when a GPIOTE event is triggered. In the pin_change_int example, the function&amp;nbsp;&lt;em&gt;in_pin_handler() &lt;/em&gt;will run in response to this event.&lt;/p&gt;
[quote user=""]and&amp;nbsp;long press[/quote]
&lt;p&gt;&amp;nbsp;Check out &lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/43506/how-to-use-bsp_button_action_push-and-bsp_button_action_long_push-on-the-same-button-with-two-different-functions"&gt;this ticket&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
[quote user=""]and how we can add : three configuration&amp;nbsp;nrf_drv_gpiote_in_config_t in_config = GPIOTE_CONFIG_IN_SENSE_HITOLO(true);/and LOTOHI and toggle , all together[/quote]
&lt;p&gt;&amp;nbsp;I am not sure if I understand what you are asking about here, can you explain it in more details?&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
[quote user=""]and what about consume of the energy is it better to work wirh&amp;nbsp;nrf_gpio_pin_read(30) or this methode of interupt[/quote]
&lt;p&gt;&amp;nbsp;It depends on how you use &lt;em&gt;nrf_gpio_pin_read(). &lt;/em&gt;If you put it in a while(1) it will definitely use more power than the method using GPIOTE events and interrupt.&lt;/p&gt;
&lt;p&gt;However, if you create a timer that will trigger an interrupt handler periodically and run &lt;em&gt;nrf_gpio_pin_read() &lt;/em&gt;in the handler, then the current consumption will be low. The drawback of this method is that it will most definitely loose some pin transitions. I think&amp;nbsp;the initial method is the best one.&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Simon&lt;/p&gt;
&lt;div style="left:649px;top:320px;"&gt;
&lt;div&gt;&lt;/div&gt;
&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Button interrupt , gpiote</title><link>https://devzone.nordicsemi.com/thread/227085?ContentTypeID=1</link><pubDate>Mon, 30 Dec 2019 14:16:49 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b9fbf26a-55ee-4272-88c2-ee8ca4334312</guid><dc:creator>achraf</dc:creator><description>&lt;p&gt;Okey no probleme ; I&amp;#39;ll be waiting for the reply , happy vacation for all&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Button interrupt , gpiote</title><link>https://devzone.nordicsemi.com/thread/227071?ContentTypeID=1</link><pubDate>Mon, 30 Dec 2019 13:06:41 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:3c10ba41-19f2-4bbc-978a-a3d40c2b51f0</guid><dc:creator>Simon</dc:creator><description>&lt;p&gt;A huge portion of the support team is currently on Christmas vacation and you may experience delayed answers. Most of the staff will be back 6 of January 2020 and you can&amp;nbsp;be sure to get an answer shortly after that.&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></channel></rss>