<?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>NCS: How to configure gpio input pins?</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/82207/ncs-how-to-configure-gpio-input-pins</link><description>Dear NCS experts, can you please lend a hand at configuring gpio input pins at nRF Connect SDK (1.7.1)? Here&amp;#39;s a short code snippet that configures pin 3 as input: This is basically working. When pushing or releasing the button wired to pin 3 button_callback</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 01 Dec 2021 16:46:44 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/82207/ncs-how-to-configure-gpio-input-pins" /><item><title>RE: NCS: How to configure gpio input pins?</title><link>https://devzone.nordicsemi.com/thread/341581?ContentTypeID=1</link><pubDate>Wed, 01 Dec 2021 16:46:44 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:17516beb-33ec-42f2-95d1-e1466d1a821a</guid><dc:creator>&amp;#216;ivind</dc:creator><description>&lt;p&gt;In your code, could you try to replicate how it is done in zephyr/samples/basic/button?&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;static const struct gpio_dt_spec button = GPIO_DT_SPEC_GET_OR(DT_NODELABEL(buttonred), gpios,
							      {0});
							      
gpio_pin_configure_dt(&amp;amp;button, GPIO_INPUT | GPIO_INT_DEBOUNCE);

gpio_pin_interrupt_configure_dt(&amp;amp;button, GPIO_INT_EDGE_BOTH);
					      
gpio_init_callback(&amp;amp;gpio_button_callback, button_callback, BIT(button.pin));

gpio_add_callback(button.port, &amp;amp;gpio_button_callback);

gpio_pin_get_dt(&amp;amp;button);&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NCS: How to configure gpio input pins?</title><link>https://devzone.nordicsemi.com/thread/341576?ContentTypeID=1</link><pubDate>Wed, 01 Dec 2021 16:11:14 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b212a4c3-0706-459b-b7d9-113b1c8deebc</guid><dc:creator>BlueMike</dc:creator><description>&lt;p&gt;So the device tree overlay now looks like this:&lt;/p&gt;
&lt;p&gt;&lt;span style="background-color:#fafafa;color:#000080;font-family:courier new, courier;"&gt;/ {&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color:#fafafa;color:#000080;font-family:courier new, courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; buttons {&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color:#fafafa;color:#000080;font-family:courier new, courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; compatible = &amp;quot;gpio-keys&amp;quot;;&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color:#fafafa;color:#000080;font-family:courier new, courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; buttonred: button_red {&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color:#fafafa;color:#000080;font-family:courier new, courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; gpios = &amp;lt;&amp;amp;gpio0 0x5 0x11&amp;gt;;&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color:#fafafa;color:#000080;font-family:courier new, courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; label = &amp;quot;Button red.&amp;quot;;&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color:#fafafa;color:#000080;font-family:courier new, courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; };&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color:#fafafa;color:#000080;font-family:courier new, courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; };&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color:#fafafa;color:#000080;font-family:courier new, courier;"&gt;};&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="background-color:#fafafa;color:#000080;font-family:courier new, courier;"&gt;&amp;amp;uart0 {&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color:#fafafa;color:#000080;font-family:courier new, courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; /delete-property/rts-pin;&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color:#fafafa;color:#000080;font-family:courier new, courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; /delete-property/status;&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color:#fafafa;color:#000080;font-family:courier new, courier;"&gt;};&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;Please note:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;gpio pin 5 has been unassigned as uart0 rts-pin.&lt;/li&gt;
&lt;li&gt;a new button has been added for pin 5 instead.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Still the same behavior: Calling &lt;span style="font-family:courier new, courier;"&gt;gpio_pin_get(5)&lt;/span&gt; at the isr crashes the firmware...&lt;/p&gt;
&lt;p&gt;Any ideas why it crashes and how to fix it are welcome.&lt;/p&gt;
&lt;p&gt;Thank you,&lt;br /&gt;Michael.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NCS: How to configure gpio input pins?</title><link>https://devzone.nordicsemi.com/thread/341522?ContentTypeID=1</link><pubDate>Wed, 01 Dec 2021 13:17:13 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:3b2b1b65-aaa4-458c-88bd-472508b642eb</guid><dc:creator>&amp;#216;ivind</dc:creator><description>&lt;p&gt;Ah, I&amp;#39;m sorry, I was mixing up a bit with another api. You need the pin in the device tree. You can add it to the overlay, like how buttons are added in the board files.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NCS: How to configure gpio input pins?</title><link>https://devzone.nordicsemi.com/thread/341493?ContentTypeID=1</link><pubDate>Wed, 01 Dec 2021 12:06:04 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:afc883f0-4d38-48af-b2bd-4c1cf1bb44c8</guid><dc:creator>BlueMike</dc:creator><description>&lt;p&gt;gpio_pin_configure(), gpio_add_callback() and gpio_pin_interrupt_configure() all return zero. The interrupt happens and the callback is executed, however, calling &lt;span style="font-family:courier new, courier;"&gt;gpio_pin_get(5)&lt;span style="font-family:arial, helvetica, sans-serif;"&gt; from inside the callback crashes the application.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family:courier new, courier;"&gt;&lt;span style="font-family:arial, helvetica, sans-serif;"&gt;Maybe I should just handle the interrupt in a thread outside the isr, would be no effort, however, I&amp;#39;m having a bad feeling workarounding a crash without knowing the reason for the crash....&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NCS: How to configure gpio input pins?</title><link>https://devzone.nordicsemi.com/thread/341480?ContentTypeID=1</link><pubDate>Wed, 01 Dec 2021 11:07:37 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9370d7ce-ba66-40d2-a59e-972950125c0e</guid><dc:creator>&amp;#216;ivind</dc:creator><description>&lt;p&gt;gpio_pin_configure(), gpio_add_callback() and gpio_pin_interrupt_configure() all return 0 if they are successful, and a negative error code on failure. Could you check if any of them return error codes?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NCS: How to configure gpio input pins?</title><link>https://devzone.nordicsemi.com/thread/341398?ContentTypeID=1</link><pubDate>Tue, 30 Nov 2021 20:56:36 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8f5965d0-ed2f-424b-9c47-0c333aa2a779</guid><dc:creator>BlueMike</dc:creator><description>&lt;p&gt;Hi &amp;Oslash;ivind,&lt;/p&gt;
&lt;p&gt;Thanks for your help!&lt;/p&gt;
&lt;p&gt;Outside the isr, &lt;span style="font-family:courier new, courier;"&gt;gpio_pin_get(3)&lt;/span&gt; returns 0 - thanks for pointing in that direction! Would be nice to have it return zero from inside the isr as well, but that&amp;#39;s easy to workaround.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Yes, I&amp;#39;m building for nrf52dk_nrf52832 with the default board files. I&amp;#39;ve first tried to remove &lt;span style="font-family:courier new, courier;"&gt;rts-pin&lt;/span&gt; by adding the following to the overlay:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;&amp;amp;uart0 {
    /delete-property/rts-pin;
};
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;This successfully removes &lt;span style="font-family:courier new, courier;"&gt;rts-pin&lt;/span&gt; from &lt;span style="font-family:courier new, courier;"&gt;uart0&lt;/span&gt;, however the app still crashes when calling &lt;span style="font-family:courier new, courier;"&gt;gpio_pin_get(5)&lt;/span&gt;. So I&amp;#39;ve tried to remove the complete &lt;span style="font-family:courier new, courier;"&gt;uart0&lt;/span&gt;:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;/ {   
   chosen {
        /delete-property/zephyr,console;
        /delete-property/zephyr,shell-uart;
        /delete-property/zephyr,uart-mcumgr;
        /delete-property/zephyr,bt-mon-uart;
        /delete-property/zephyr,bt-c2h-uart;
    };
    /delete-node/arduino_serial; 
    /delete-node/uart0;
};
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Unfortunately this didn&amp;#39;t work: &lt;span style="font-family:courier new, courier;"&gt;uart0&lt;/span&gt; is still in the device tree, and calling &lt;span style="font-family:courier new, courier;"&gt;gpio_pin_get(5)&lt;/span&gt; still crashes. Do you have any other ideas how to fix the crash?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NCS: How to configure gpio input pins?</title><link>https://devzone.nordicsemi.com/thread/341386?ContentTypeID=1</link><pubDate>Tue, 30 Nov 2021 19:12:03 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9355ee20-36d6-4668-9b98-0da11de79d52</guid><dc:creator>&amp;#216;ivind</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;It would be useful to have a little more information about your application.&lt;/p&gt;
&lt;p&gt;Are you able to get 0 from gpio_pin_get() at other times, for example if you call it outside of the callback?&lt;/p&gt;
&lt;p&gt;Are you building for nrf52dk_nrf52832 with the default board files? By default pin 5 is set as the RTS pin for uart0.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>