<?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>Change Pin from Input to Output in runtime?</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/24166/change-pin-from-input-to-output-in-runtime</link><description>Hi,
i have nrf52 and sdk13.1.
Is this possible. I get NRF_ERROR_INVALID_STATE .</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Mon, 14 Aug 2017 07:20:29 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/24166/change-pin-from-input-to-output-in-runtime" /><item><title>RE: Change Pin from Input to Output in runtime?</title><link>https://devzone.nordicsemi.com/thread/95179?ContentTypeID=1</link><pubDate>Mon, 14 Aug 2017 07:20:29 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9b412829-efd3-41f3-ae4a-fe2c925e23f9</guid><dc:creator>Boris Matešin</dc:creator><description>&lt;p&gt;Much obliged!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Change Pin from Input to Output in runtime?</title><link>https://devzone.nordicsemi.com/thread/95178?ContentTypeID=1</link><pubDate>Fri, 11 Aug 2017 11:04:39 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:3f5fdaee-9937-4652-a263-1f420a829503</guid><dc:creator>Joakim Jakobsen</dc:creator><description>&lt;p&gt;This is an answer to stealth&amp;#39;s comment above, and will hopefully help with schef&amp;#39;s original question as well.&lt;/p&gt;
&lt;p&gt;In the &lt;a href="https://infocenter.nordicsemi.com/index.jsp?topic=%2Fcom.nordic.infocenter.sdk5.v13.1.0%2Fgroup__nrf__drv__gpiote.html&amp;amp;cp=4_0_1_6_8_3_0"&gt;infocenter&lt;/a&gt; we can find that the &lt;code&gt;NRF_ERROR_INVALID_STATE&lt;/code&gt; is returned if the driver is not initialized or the pin is already used. In your case the error is returned because the pin is used.&lt;br /&gt;
When calling the function&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;err_code = nrf_drv_gpiote_in_init(BUTTON_0, &amp;amp;configInButton, my_gpio_handler);
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;the pin will be used, and therefore you should try to uninitialize the pin using the &lt;a href="https://infocenter.nordicsemi.com/topic/com.nordic.infocenter.sdk5.v13.1.0/group__nrf__drv__gpiote.html?cp=4_0_1_6_8_3_0_17#ga3baacee19f4913234327ac94f936c3d9"&gt;nrf_drv_gpiote_in_uninit()&lt;/a&gt; before you can initialize it again as an output pin.&lt;/p&gt;
&lt;p&gt;Kind regards&lt;br /&gt;
Joakim&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Change Pin from Input to Output in runtime?</title><link>https://devzone.nordicsemi.com/thread/95177?ContentTypeID=1</link><pubDate>Thu, 10 Aug 2017 14:59:54 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f9efd5e1-405f-4abc-82bd-9cc1e235f1b0</guid><dc:creator>Boris Matešin</dc:creator><description>&lt;p&gt;I have a similar case, so pardon me for hijacking the topic.
I have pin 0.08 that I wanted to have as a dual-purpose pin - first a pushbutton, then a LED. Both are tied to the pin, in parallel, then grounded&lt;/p&gt;
&lt;p&gt;My init goes smoothly:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;#define GPIO_1 8

err_code = nrf_drv_gpiote_init();
APP_ERROR_CHECK(err_code);

nrf_drv_gpiote_in_config_t configInButton = GPIOTE_CONFIG_IN_SENSE_HITOLO(true);
err_code = nrf_drv_gpiote_in_init(BUTTON_0, &amp;amp;configInButton, my_gpio_handler);
APP_ERROR_CHECK(err_code);
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;and my_gpio_handler works well. Once I&amp;#39;m done with the button I call a second method that does the following:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;nrf_drv_gpiote_out_config_t configOut = GPIOTE_CONFIG_OUT_SIMPLE(0);
err_code = nrf_drv_gpiote_out_init(GPIO_1, &amp;amp;configOut);
APP_ERROR_CHECK(err_code);
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;That last APP_ERROR_CHECK throws an NRF_ERROR_INVALID_STATE.&lt;/p&gt;
&lt;p&gt;Did I skip a step somewhere?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Change Pin from Input to Output in runtime?</title><link>https://devzone.nordicsemi.com/thread/95176?ContentTypeID=1</link><pubDate>Tue, 08 Aug 2017 12:13:03 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:759620ba-6865-4a9b-b35c-0295853c5702</guid><dc:creator>RK</dc:creator><description>&lt;p&gt;how anyone is supposed to answer that question without you even bothering to post the line of code you allegedly get NRF_ERROR_INVALID_STATE on I don&amp;#39;t know. Can you write a more complete question perhaps?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>