<?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>Strange behavior Button 2 and Button 3 on nRF51 DK</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/14773/strange-behavior-button-2-and-button-3-on-nrf51-dk</link><description>Updates are moved to the end of the question 
 I created a modified version of pca10028.h and boards.h and have preprocessors changed so that the following new config is loaded: 
 // Custom LEDs definitions for PCA10028
#define LEDS_NUMBER 1

//#define</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Fri, 15 Jul 2016 06:07:51 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/14773/strange-behavior-button-2-and-button-3-on-nrf51-dk" /><item><title>RE: Strange behavior Button 2 and Button 3 on nRF51 DK</title><link>https://devzone.nordicsemi.com/thread/56418?ContentTypeID=1</link><pubDate>Fri, 15 Jul 2016 06:07:51 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a63a0bf9-4046-4c64-a2fa-9d77efb2e3b8</guid><dc:creator>&amp;#216;yvind Karlsen</dc:creator><description>&lt;p&gt;You can use the port event from GPIOTE to trigger an interrupt, then handle that interrupt and evaluate current GPIO state.&lt;/p&gt;
&lt;p&gt;For the nrf_drv_gpiote_in_init I think you might be right, when I was debugging it seemed to change behaviour of the code, but it might have been a coincidence.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Strange behavior Button 2 and Button 3 on nRF51 DK</title><link>https://devzone.nordicsemi.com/thread/56419?ContentTypeID=1</link><pubDate>Fri, 15 Jul 2016 04:44:48 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:af5c2e21-ccbd-482e-89b6-6a5f2e76d521</guid><dc:creator>Hieu</dc:creator><description>&lt;p&gt;First of all, those wrong flags are exactly the problem. I kept looking elsewhere for the issue while it is such a fundamental one. Many apologies.&lt;/p&gt;
&lt;p&gt;I used GPIOTE simply because that was the only way I found to get an event upon GPIO change. I tried looking into the GPIO peripheral driver, but all I could find was setting up a GPIO as input, not setting up an interrupt for that.
I think I simply haven&amp;#39;t found the right way to do things yet. You seem to imply that there is a better way to do this. Could you point me to where I could find a better way to do this? I would be glad to learn.&lt;/p&gt;
&lt;p&gt;Finally, regarding clearing pending interrupt, to my understanding, because I am using &lt;code&gt;nrf_drv_gpiote_in_init()&lt;/code&gt; to assign a handler, the driver would automatically clear the pending interrupt before calling my handler. Could I have misunderstood this as well?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Strange behavior Button 2 and Button 3 on nRF51 DK</title><link>https://devzone.nordicsemi.com/thread/56416?ContentTypeID=1</link><pubDate>Thu, 14 Jul 2016 09:22:11 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6f59038e-45b2-488d-837d-877fdd6e75d9</guid><dc:creator>&amp;#216;yvind Karlsen</dc:creator><description>&lt;p&gt;I didn&amp;#39;t quite get why you were using GPIOTE, either way you need to clear the pending interrupt at the start of each interrupt handler. For example by calling &lt;code&gt;NVIC_ClearPendingIRQ(GPIOTE_IRQn);&lt;/code&gt;. Otherwise the interrupt will call itself again and again.&lt;/p&gt;
&lt;p&gt;You were also setting the wrong flags to false, change to the code below.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;#if DEV_CFG_USE_FLAG
        if (m_group1_input_it_flag)
        {
            nrf_gpio_pin_toggle(GROUP1_OUTPUT1_PIN);
            nrf_gpio_pin_toggle(GROUP1_OUTPUT2_PIN);
            
            m_group1_input_it_flag = false;
        }
        if (m_group2_input_it_flag)
        {
            nrf_gpio_pin_toggle(GROUP2_OUTPUT1_PIN);
            nrf_gpio_pin_toggle(GROUP2_OUTPUT2_PIN);
            
            m_group2_input_it_flag = false; //Change this
        }
        if (m_group3_input_it_flag)
        {
            nrf_gpio_pin_toggle(GROUP3_OUTPUT1_PIN);
            nrf_gpio_pin_toggle(GROUP3_OUTPUT2_PIN);
            
            m_group3_input_it_flag = false; //Change this
        }
#endif // #if DEV_CFG_USE_FLAG
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Be aware that there is a limit on the maximum low power resources, this can be changed in the file nrf_drv_config, found in &lt;code&gt;ble_app_uart\config&lt;/code&gt;.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Strange behavior Button 2 and Button 3 on nRF51 DK</title><link>https://devzone.nordicsemi.com/thread/56417?ContentTypeID=1</link><pubDate>Thu, 14 Jul 2016 02:50:13 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:7c29fdc3-8272-4bf2-91cb-6aefe54bc19e</guid><dc:creator>Hieu</dc:creator><description>&lt;p&gt;I thought I replied last week already but it turns out I didn&amp;#39;t. I probably forgot to hit the add comment button or something. Sorry about this.
The reason is because I often need to run a fair amount of work at a GPIO event, not just a couple of GPIO toggling like this. Meanwhile, I believe I should avoid running large amount of code in the interrupt context (unless there is some difference thanks to nRF&amp;#39;s PPI system?). That is why I often use the flag raising strategy, sacrificing a little response time for safety. Therefore I would like to find the root of the problem to avoid issues in the future.&lt;/p&gt;
&lt;p&gt;But you are right that for my current particular case, I could just run the simple GPIO toggling in the handler.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Strange behavior Button 2 and Button 3 on nRF51 DK</title><link>https://devzone.nordicsemi.com/thread/56415?ContentTypeID=1</link><pubDate>Tue, 05 Jul 2016 06:58:04 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:78c60280-f98c-4ddf-b7e2-08d1d9700417</guid><dc:creator>&amp;#216;yvind Karlsen</dc:creator><description>&lt;p&gt;If its working without the flag implementation, why not stick with that?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Strange behavior Button 2 and Button 3 on nRF51 DK</title><link>https://devzone.nordicsemi.com/thread/56414?ContentTypeID=1</link><pubDate>Thu, 30 Jun 2016 10:06:08 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:514ddf24-a030-4050-b3ee-661aa2ab1c4f</guid><dc:creator>Hieu</dc:creator><description>&lt;p&gt;Just updated the question with a better edited main.c and the modified pca10028.h I used for your convenience.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Strange behavior Button 2 and Button 3 on nRF51 DK</title><link>https://devzone.nordicsemi.com/thread/56413?ContentTypeID=1</link><pubDate>Thu, 30 Jun 2016 09:36:05 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2d230fd4-df2c-4b11-b407-eec0b12edb22</guid><dc:creator>Hieu</dc:creator><description>&lt;p&gt;Sorry Øyvind, I missed those when I trimmed out the unrelevant part.
Another thing I forgot is enable the flag macro. If you change &lt;code&gt;DEV_CFG_USE_FLAG&lt;/code&gt; to 1 it should enable using flag instead of using handler directly. &lt;code&gt;DEV_CFG_USE_BSP&lt;/code&gt; on the other hand enable and disable BSP feature&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Strange behavior Button 2 and Button 3 on nRF51 DK</title><link>https://devzone.nordicsemi.com/thread/56412?ContentTypeID=1</link><pubDate>Thu, 30 Jun 2016 09:19:04 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a7329754-60ea-4d68-a5b2-54a47513a080</guid><dc:creator>&amp;#216;yvind Karlsen</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;Had to include some .h files and comment out ir_raw.h. When I compiled and ran it LED 1, 2 and 3 on the DK lit up, and these become unlit when I hold Button 1, 2 and 3 respectively. I am also able to connect to it using master control panel on a android device. None of the LEDs are blinking by themselves in either connected or advertising mode.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Strange behavior Button 2 and Button 3 on nRF51 DK</title><link>https://devzone.nordicsemi.com/thread/56411?ContentTypeID=1</link><pubDate>Thu, 30 Jun 2016 08:26:05 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:41503de4-88e8-43ae-b417-dc595f8c574c</guid><dc:creator>Hieu</dc:creator><description>&lt;p&gt;Øyvind,
I think my problem is a little different. What I am seeing is that after pressing button 2 or 3, pressing any button (1, 2 or 3) will cause button 2 or 3&amp;#39;s flagged routine to run. For example, after pressing button 2, when I pressed button 1 I will see both LED 1 and 2 blink.&lt;/p&gt;
&lt;p&gt;You could check that out with my attached main.c. It should work by just replacing it into an ble_app_uart example of SDK v10.&lt;/p&gt;
&lt;p&gt;I would like to understand the root of this problem a little better for future use of GPIO interrupt and flags, since I foresee a need to run a heavy workload at an GPIO event.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Strange behavior Button 2 and Button 3 on nRF51 DK</title><link>https://devzone.nordicsemi.com/thread/56410?ContentTypeID=1</link><pubDate>Tue, 28 Jun 2016 07:54:17 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:61cc409d-1a37-4588-b221-82b0d2fb9f02</guid><dc:creator>&amp;#216;yvind Karlsen</dc:creator><description>&lt;p&gt;Setting the LEDs in main might get tangled up in interrupts that occur at the same time. Since it works in the handler and not in main I guess this is what you are seeing.&lt;/p&gt;
&lt;p&gt;If what you want to do is to toggle LEDs every time you press a button you can follow the &lt;a href="https://devzone.nordicsemi.com/tutorials/13/"&gt;BSP tutorial&lt;/a&gt;, as it implements this.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Strange behavior Button 2 and Button 3 on nRF51 DK</title><link>https://devzone.nordicsemi.com/thread/56409?ContentTypeID=1</link><pubDate>Tue, 28 Jun 2016 07:41:31 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a6870bc9-9953-4037-906e-abc3dc8b5098</guid><dc:creator>Hieu</dc:creator><description>&lt;p&gt;Øyvind,&lt;/p&gt;
&lt;p&gt;I tried a little more without BSP, and has observed that even without BSP, using nRF51 Button 2 and 3 along with flag raising still cause events to be tangled up with each other. Do you have any guess what is going on?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Strange behavior Button 2 and Button 3 on nRF51 DK</title><link>https://devzone.nordicsemi.com/thread/56408?ContentTypeID=1</link><pubDate>Mon, 27 Jun 2016 09:05:42 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:3eafe3eb-57a3-423f-a2fe-97ffb36046bf</guid><dc:creator>&amp;#216;yvind Karlsen</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;I&amp;#39;ve also had trouble with unexpected behavior when running BSP and BLE simultaneously. What happens is that the function bsp_led_indication() in bsp.c will turn off all LEDs and then blink LED1.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;LEDS_OFF(LEDS_MASK &amp;amp; ~BSP_LED_0_MASK &amp;amp; ~m_alert_mask);

// in advertising blink LED_0
if (LED_IS_ON(BSP_LED_0_MASK))
{
    LEDS_OFF(BSP_LED_0_MASK);
    next_delay = indicate == BSP_INDICATE_ADVERTISING ? ADVERTISING_LED_OFF_INTERVAL : ADVERTISING_SLOW_LED_OFF_INTERVAL;
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;You can comment out the line LEDS_OFF line. For me the BSP is too much of an abstraction and I prefer to implement buttons and LEDs myself to have full control over what is happening.&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Øyvind&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>