<?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>Ensure GPIO initializes to default low</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/73223/ensure-gpio-initializes-to-default-low</link><description>Using: NRF52840, SDK 14.2, S140 
 My GPIO initialization code is as follows. This is the first thing that happens in main.c. 
 
 Here are logic analyzer traces of 2 GPIOs (I can also scope them soon). Top one (P1.0) should be initialized low, bottom one</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 08 Apr 2021 07:46:15 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/73223/ensure-gpio-initializes-to-default-low" /><item><title>RE: Ensure GPIO initializes to default low</title><link>https://devzone.nordicsemi.com/thread/303653?ContentTypeID=1</link><pubDate>Thu, 08 Apr 2021 07:46:15 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f4234663-f481-45b9-bf25-cb21c3ed4897</guid><dc:creator>Dmitry</dc:creator><description>&lt;p&gt;Softdevice is not initialized until you call sd_softdevice_enable(). If your configuration includes a bootloader, there is some delay in bootloader that is&amp;nbsp;much shorter than 4 ms.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Ensure GPIO initializes to default low</title><link>https://devzone.nordicsemi.com/thread/303610?ContentTypeID=1</link><pubDate>Wed, 07 Apr 2021 21:25:52 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1046ea45-88f4-42e7-9e12-0c9caab11865</guid><dc:creator>nordev</dc:creator><description>&lt;p&gt;How long does the softdevice take to initialize, and is it possible to initialize GPIO before the softdevice?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Ensure GPIO initializes to default low</title><link>https://devzone.nordicsemi.com/thread/302904?ContentTypeID=1</link><pubDate>Fri, 02 Apr 2021 20:15:40 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5052b898-bf4c-4cc6-b497-b88d2e4e8103</guid><dc:creator>Dmitry</dc:creator><description>&lt;p&gt;Sorry I missed that mention. 4ms is within the device specification, see&amp;nbsp;5.3.8.3 Device startup times - up to 10 ms is allowed in case of&amp;nbsp;10us&amp;nbsp;VDD rise time. But it shouldn&amp;#39;t matter anyway (unless your device is powered from an energy harvester, in this case you probably have to look for alternative solution). The pin is floating until it&amp;#39;s initialized - if this is unacceptable, there should be a pull-up/pull-down on that pin.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Ensure GPIO initializes to default low</title><link>https://devzone.nordicsemi.com/thread/302902?ContentTypeID=1</link><pubDate>Fri, 02 Apr 2021 18:38:59 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:44b5f23d-64f7-44b2-9760-d80235aab1e5</guid><dc:creator>nordev</dc:creator><description>&lt;p&gt;@dmitry, as mentioned above, the initialization code is basically the first thing that happens in main():&lt;/p&gt;
&lt;p&gt;&lt;img src="https://devzone.nordicsemi.com/resized-image/__size/320x240/__key/communityserver-discussions-components-files/4/pastedimage1617389647559v2.png" alt=" " /&gt;&lt;/p&gt;
&lt;p&gt;(the initialization are inside gpio_init).&lt;/p&gt;
&lt;p&gt;&lt;a href="https://devzone.nordicsemi.com/members/hmolesworth"&gt;hmolesworth&lt;/a&gt;, thanks for the note. I changed the order of my initializations, and it took care of part of the problem (things that should be initialized high getting first initialized low).&amp;nbsp;&lt;/p&gt;
&lt;p&gt;But the 4ms high blip still shows up for the pins that should be initialized low. I tested with an oscilloscope, and it shows P1.0 is low consistently. I will note that when the scope is not connected to anything, it reads low, and when the logic analyzer is not connected to anything, it reads high. &lt;strong&gt;So it seems like the pins are floating for 4ms upon startup. This is a long time. Why might this be happening?&amp;nbsp;&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;As another example: P0.6 and P1.0 both are supposed to go low. There is 50 us between when P0.6 goes low and P1.0 goes low. There are 25 pins initialized in between them, so this seems about right. It also supports the hypothesis that the pins are all floating until they are initialized.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;img src="https://devzone.nordicsemi.com/resized-image/__size/320x240/__key/communityserver-discussions-components-files/4/pastedimage1617389246710v1.png" alt=" " /&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Ensure GPIO initializes to default low</title><link>https://devzone.nordicsemi.com/thread/302004?ContentTypeID=1</link><pubDate>Thu, 25 Mar 2021 17:29:45 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:aed1e915-6efe-4f2d-bef0-600e3e5253b0</guid><dc:creator>hmolesworth</dc:creator><description>&lt;p&gt;In general the initialisation order shown above is incorrect, choose the pin high or low level before driving it as an output when the pin was previously not configured.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;nrf_gpio_pin_clear(NRF_GPIO_PIN_MAP(1, 0)); // Drives low as soon as configured as output
nrf_gpio_cfg_output(NRF_GPIO_PIN_MAP(1, 0));

nrf_gpio_pin_set(NRF_GPIO_PIN_MAP(1, 14)); // Drives high as soon as configured as output
nrf_gpio_cfg_output(NRF_GPIO_PIN_MAP(1, 14));&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;On power off - assuming Vdd collapses from 3 volts-ish towards 0 volts - any external item connected to the pin will back-drive the pin through the internal schottky protection diode if the external item either has a power source or has any significant capacitance (which acts like a power source). If the signal is as clean as shown in the trace (often not the case depending on the logic analyzer instrument, scope is preferred) then something else is afoot ..&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Ensure GPIO initializes to default low</title><link>https://devzone.nordicsemi.com/thread/301815?ContentTypeID=1</link><pubDate>Thu, 25 Mar 2021 08:29:33 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f3d11b31-0f7c-460e-9de8-99c8b56090c8</guid><dc:creator>Dmitry</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;how close is your initialization code to the start of main()?&amp;nbsp;&amp;nbsp;As soon as your GPIO initialization is executed, the pins are set to the right state&amp;nbsp;immediately, without any delay. As for powering off, you cannot contol pin state at this time with software. If your pins have some load that should be in known state while CPU is powering-on/powering-off/browned-out, you need hardware pull-up or pull-down resistors on that pins.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>