<?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>Can anybody please explain the blinky program in nrf51 examples?</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/13870/can-anybody-please-explain-the-blinky-program-in-nrf51-examples</link><description>this is the main program! 
 #include &amp;lt;stdbool.h&amp;gt;
#include &amp;lt;stdint.h&amp;gt;
#include &amp;quot;nrf_delay.h&amp;quot;
#include &amp;quot;nrf_gpio.h&amp;quot;
#include &amp;quot;boards.h&amp;quot;

const uint8_t leds_list[LEDS_NUMBER] = LEDS_LIST;

/**
 * @brief Function for application main entry.
 *</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Mon, 23 May 2016 14:25:41 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/13870/can-anybody-please-explain-the-blinky-program-in-nrf51-examples" /><item><title>RE: Can anybody please explain the blinky program in nrf51 examples?</title><link>https://devzone.nordicsemi.com/thread/52988?ContentTypeID=1</link><pubDate>Mon, 23 May 2016 14:25:41 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:82cfa0f7-9672-4a80-b0af-54f100aca9a9</guid><dc:creator>Stian R&amp;#248;ed Hafskjold</dc:creator><description>&lt;p&gt;Please click the accept button if you find any of the answers useful.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Can anybody please explain the blinky program in nrf51 examples?</title><link>https://devzone.nordicsemi.com/thread/52987?ContentTypeID=1</link><pubDate>Tue, 17 May 2016 11:40:45 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a6c4a0fb-d406-4524-bd19-3719d73a8633</guid><dc:creator>Sara</dc:creator><description>&lt;p&gt;thank you so much for the answers.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Can anybody please explain the blinky program in nrf51 examples?</title><link>https://devzone.nordicsemi.com/thread/52985?ContentTypeID=1</link><pubDate>Sun, 15 May 2016 19:30:47 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0d766a43-04c5-4536-874f-bdab3c0185c8</guid><dc:creator>Stian R&amp;#248;ed Hafskjold</dc:creator><description>&lt;p&gt;A &amp;#39;1&amp;#39; in the 32-bit number you pass to &lt;code&gt;NRF_GPIO-&amp;gt;OUTSET&lt;/code&gt; will set the corresponding bit in the &lt;code&gt;NRF_GPIO-&amp;gt;OUT&lt;/code&gt; register, a &amp;#39;0&amp;#39; will have no effect. Similarly, a &amp;#39;1&amp;#39; in the &lt;code&gt;OUTCLR&lt;/code&gt; register will clear the bit, &amp;#39;0&amp;#39; will have no effect.&lt;/p&gt;
&lt;p&gt;Let&amp;#39;s say you want to toggle &lt;code&gt;NRF_GPIO-&amp;gt;OUT[0]&lt;/code&gt; and &lt;code&gt;NRF_GPIO-&amp;gt;OUT[2]&lt;/code&gt;, and &lt;code&gt;[0]&lt;/code&gt; is &amp;#39;1&amp;#39; and &lt;code&gt;[2]&lt;/code&gt; is &amp;#39;0&amp;#39; &lt;strong&gt;(using only 4 bits to keep it simple)&lt;/strong&gt;:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;NRF_GPIO-&amp;gt;OUT: 0b0001 // initial state of the register
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;LEDS_INVERT(0b0101);  // pass the mask of the LEDs you want to invert
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;code&gt;LEDS_INVERT()&lt;/code&gt; does this:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;uint32_t gpio_state = NRF_GPIO-&amp;gt;OUT;  // Reads the state of NRF_GPIO-&amp;gt;OUT
                                      // It gets the value 0b0001

NRF_GPIO-&amp;gt;OUTSET = ((leds_mask) &amp;amp; ~gpio_state);  // 0b0101 &amp;amp; ~0b0001
                                                 // = 0b0101 &amp;amp; 0b1110 = 0b0100
                                                 // It sets NRF_GPIO-&amp;gt;OUT[2] to 1 leaving the other bits

NRF_GPIO-&amp;gt;OUTCLR = ((leds_mask) &amp;amp; gpio_state);   // 0b0101 &amp;amp; 0b0001 = 0b0001
                                                 // It clears NRF_GPIO-&amp;gt;OUT[0] to 0 leaving the other bits
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;NRF_GPIO-&amp;gt;OUT: 0b0100 // resulting state of the register
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;And the reason why this is put in a &lt;code&gt;do {...} while(0)&lt;/code&gt; statement, you can read about here: &lt;a href="http://stackoverflow.com/a/257425"&gt;stackoverflow.com/.../257425&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Can anybody please explain the blinky program in nrf51 examples?</title><link>https://devzone.nordicsemi.com/thread/52984?ContentTypeID=1</link><pubDate>Sun, 15 May 2016 19:26:56 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f11ca61a-3555-4d3d-b7f5-91590dec034e</guid><dc:creator>itssead</dc:creator><description>&lt;p&gt;(see other detailed answer - dup)
here is a nice explanation of this &amp;quot;strange&amp;quot; looking &amp;quot;do {} while (0)&amp;quot; define&lt;/p&gt;
&lt;p&gt;Answer 5:
&lt;a href="http://stackoverflow.com/questions/257418/do-while-0-what-is-it-good-for"&gt;stackoverflow.com/.../do-while-0-what-is-it-good-for&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&amp;quot;It&amp;#39;s the only construct in C that you can use to #define a multistatement operation, put a semicolon after, and still use within an if statement.&amp;quot; Greg Hewgill&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Can anybody please explain the blinky program in nrf51 examples?</title><link>https://devzone.nordicsemi.com/thread/52986?ContentTypeID=1</link><pubDate>Sun, 15 May 2016 15:59:54 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8a128163-7382-4ac6-af36-fbf3485e332e</guid><dc:creator>Christopher</dc:creator><description>&lt;p&gt;This is another way to toggle a GPIO:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;/**
 * @brief Toggle GPIO pin.
 *
 * Note that the pin must be configured as an output for this function to have any effect.
 *
 * @param pin_number specifies the pin number [0:31] to toggle.
 */
static __INLINE void nrf_gpio_pin_toggle(uint32_t pin_number)
{
    NRF_GPIO-&amp;gt;OUT ^= (1UL &amp;lt;&amp;lt; pin_number);
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Please have a look at the GPIO abstraction documentation here: &lt;a href="http://infocenter.nordicsemi.com/index.jsp?topic=%2Fcom.nordic.infocenter.sdk51.v9.0.0%2Fgroup__nrf__gpio.html&amp;amp;resultof=%22nrf_gpio%22%20"&gt;infocenter.nordicsemi.com/index.jsp&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>