<?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>Switching GPIO pin between input and output mode</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/93658/switching-gpio-pin-between-input-and-output-mode</link><description>Hi, 
 Could help me please? 
 What I need? 
 1) set GPIO pin as input with internal pulldown and set IRQ for Rising Edge. 
 In .overlay I add my pin like that: 
 
 Then in code I set pin as INPUT and enabled IRQ 
 
 
 2) In code I need sometimes to set</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Sat, 19 Nov 2022 13:13:49 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/93658/switching-gpio-pin-between-input-and-output-mode" /><item><title>RE: Switching GPIO pin between input and output mode</title><link>https://devzone.nordicsemi.com/thread/396500?ContentTypeID=1</link><pubDate>Sat, 19 Nov 2022 13:13:49 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d2dc8a3a-8fc6-4c4a-ad2a-0ae597fd5b3d</guid><dc:creator>witc</dc:creator><description>&lt;p&gt;Thank you very much!&lt;/p&gt;
&lt;p&gt;Unbelievable how helpful this forum is :-)&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Switching GPIO pin between input and output mode</title><link>https://devzone.nordicsemi.com/thread/394957?ContentTypeID=1</link><pubDate>Wed, 09 Nov 2022 15:12:00 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f87070ff-6e00-4ac3-b4f9-0e60f9b61cd9</guid><dc:creator>Naeem Maroof</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;Thank you for your patience.&lt;/p&gt;
&lt;p&gt;So basically your query is regarding configuring GPIO pin as input and output.&lt;/p&gt;
&lt;p&gt;As per your provided information, I created a sample project and added the overlay.&lt;/p&gt;
&lt;p&gt;I was able to configure a pin (in my case &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;P0.26&lt;/span&gt;) as an input pin, set an interrupt on it, disable the interrupt and configure it as an output port.&lt;/p&gt;
&lt;p&gt;I am attaching my setup (&lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;main.c&lt;/span&gt; and &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;overlay&lt;/span&gt;) here.&lt;/p&gt;
&lt;p&gt;I can read the status of GPIO pins using nrfjprog command-line tool.&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;GPIO0&lt;/span&gt; base address is &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;0x50000000&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;And the offset of DIR (direction either input or output) register of GPIO is &lt;span style="font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;0x514&lt;/span&gt;.&lt;/p&gt;
&lt;p&gt;&lt;img style="max-height:240px;max-width:320px;" src="https://devzone.nordicsemi.com/resized-image/__size/640x480/__key/communityserver-discussions-components-files/4/pastedimage1668006135031v1.png" alt=" " /&gt;&lt;/p&gt;
&lt;p&gt;You can see here in the attached image that I am reading once from the DIR register when the pin is configured as INPUT, and the next time when the pin is configured as OUTPUT.&lt;/p&gt;
&lt;p&gt;After checking the values read, you can see that our pin (P0.26) direction bit values are changing from 0 to 1, which means first it was configured as input, and now (at the later stage of code) as output.&lt;/p&gt;
&lt;p&gt;Snapshot attached for clarification:&lt;/p&gt;
&lt;p&gt;&lt;img style="max-height:240px;max-width:320px;" src="https://devzone.nordicsemi.com/resized-image/__size/640x480/__key/communityserver-discussions-components-files/4/pastedimage1668006471550v2.png" alt=" " /&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Source file:&amp;nbsp;&lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/66434.main.c"&gt;devzone.nordicsemi.com/.../66434.main.c&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Overlay:&amp;nbsp;&lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/3755.nrf52840dk_5F00_nrf52840.overlay"&gt;devzone.nordicsemi.com/.../3755.nrf52840dk_5F00_nrf52840.overlay&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Hope it helps,&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Regards,&lt;/p&gt;
&lt;p&gt;Naeem&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Switching GPIO pin between input and output mode</title><link>https://devzone.nordicsemi.com/thread/394775?ContentTypeID=1</link><pubDate>Tue, 08 Nov 2022 15:53:00 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5b2a467e-4031-4508-8c94-a13307a2c581</guid><dc:creator>Naeem Maroof</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;Thank you for contacting DevZone at NordicSemi.&lt;/p&gt;
&lt;p&gt;This ticket has been assigned to me, and I will look into this case and update you accordingly.&lt;/p&gt;
&lt;p&gt;Regards,&lt;/p&gt;
&lt;p&gt;Naeem&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>