<?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>GPIO pin reading wrong value</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/29133/gpio-pin-reading-wrong-value</link><description>There seems to be an issue when reading GPIO pins returning false readings. I am using two pins for I2C communication, 26 and 27, I am configuring them with the required configuration for using I2C and then setting them high. However, when I go to read</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Mon, 15 Jan 2018 15:23:12 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/29133/gpio-pin-reading-wrong-value" /><item><title>RE: GPIO pin reading wrong value</title><link>https://devzone.nordicsemi.com/thread/115743?ContentTypeID=1</link><pubDate>Mon, 15 Jan 2018 15:23:12 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:3c907160-220b-45f9-a019-0c2cb361215d</guid><dc:creator>MartinBL</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;After further investigation I&amp;#39;m not sure that I&amp;#39;m able to reproduce what your are seeing afterall, and all I can see is expected behaviour. Let us start with this:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;However, when I go to read the inputs
of these pins (which are floating, the
only thing attached to them is an
oscilloscope) they are falsely read as
high when they are low (verified on
the scope)&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;I used your pin configuration, tied the pin to GND with a wire, and toggled the pin in software like this:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;NRF_GPIO-&amp;gt;OUTCLR = 1 &amp;lt;&amp;lt; PIN;
val = NRF_GPIO-&amp;gt;IN &amp;amp; (1 &amp;lt;&amp;lt; PIN);

/* SET */ 
NRF_GPIO-&amp;gt;OUTSET = 1 &amp;lt;&amp;lt; PIN;
val = NRF_GPIO-&amp;gt;IN &amp;amp; (1 &amp;lt;&amp;lt; PIN);
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;At no point did I read the pin as high.&lt;/p&gt;
&lt;p&gt;Furthermore, considering your configuration:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;NRF_GPIO-&amp;gt;PIN_CNF[pin] = 
    (GPIO_PIN_CNF_SENSE_Disabled &amp;lt;&amp;lt; GPIO_PIN_CNF_SENSE_Pos)
  | (GPIO_PIN_CNF_DRIVE_S0D1     &amp;lt;&amp;lt; GPIO_PIN_CNF_DRIVE_Pos)
  | (GPIO_PIN_CNF_PULL_Disabled  &amp;lt;&amp;lt; GPIO_PIN_CNF_PULL_Pos)
  | (GPIO_PIN_CNF_INPUT_Connect  &amp;lt;&amp;lt; GPIO_PIN_CNF_INPUT_Pos)
  | (GPIO_PIN_CNF_DIR_Output     &amp;lt;&amp;lt; GPIO_PIN_CNF_DIR_Pos);   
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;It sounds like you may know this, but this configuration disables both the pull up and the pull down resistor. Equally important though, it also disconnects the GPIO output from the pad whenever the pin is set high (S0D1 = Standard drive low, and disconnect high). This means that if you try to set the pin high with e.g. nrf_gpio_pin_set() the pin is actually left floating, while if you set it low it is firmly tied down. As you probably know, a floating pin is left to the mercy of the elements and if you try to read the state of such a pin you will not get reliable results.&lt;/p&gt;
&lt;p&gt;If you want to get correct readings you can either:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Enable the pull up resistor. This will pull the pin high even though it is disconnected when you set the pin with nrf_gpio_pin_set().&lt;/li&gt;
&lt;li&gt;Use S0S1 or S0H1. These settings will ensure that the GPIO output is not disconnected when you set the pin high.&lt;/li&gt;
&lt;/ol&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: GPIO pin reading wrong value</title><link>https://devzone.nordicsemi.com/thread/115742?ContentTypeID=1</link><pubDate>Mon, 15 Jan 2018 07:59:16 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:88ec9aaf-6f9a-4d47-a754-29296eb25b38</guid><dc:creator>jm_laird</dc:creator><description>&lt;p&gt;I haven&amp;#39;t tested over pins as we only allow I2C on one set of pins which isn&amp;#39;t configurable. Will there be a fix for this issue in an updated SDK or is it not possible to fix via software?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: GPIO pin reading wrong value</title><link>https://devzone.nordicsemi.com/thread/115741?ContentTypeID=1</link><pubDate>Thu, 04 Jan 2018 16:23:18 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1ee96cd0-24e0-40a1-b71a-5274b9c5d662</guid><dc:creator>MartinBL</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;Have you tested other pins? In your GDB log you read pin 1 for example. In my tests it seems to behave similarly on all pins.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: GPIO pin reading wrong value</title><link>https://devzone.nordicsemi.com/thread/115740?ContentTypeID=1</link><pubDate>Mon, 18 Dec 2017 15:08:49 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:7ce022b0-9d94-46ce-815b-87b7b21e363d</guid><dc:creator>MartinBL</dc:creator><description>&lt;p&gt;I have managed to recreate the behaviour on my desk. I&amp;#39;ll ask around and figure out if this is expected or not. It is holiday season in Norway now, so I can&amp;#39;t promise any answers before after new year.&lt;/p&gt;
&lt;p&gt;In the meantime, it seems to work as one would expect if you just enable the pullup resistor. Pulldown doesn&amp;#39;t work of some reason.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: GPIO pin reading wrong value</title><link>https://devzone.nordicsemi.com/thread/115739?ContentTypeID=1</link><pubDate>Fri, 15 Dec 2017 08:39:54 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:11ff16ca-643a-46d5-a3fd-56486aa28fec</guid><dc:creator>jm_laird</dc:creator><description>&lt;ol&gt;
&lt;li&gt;There is nothing connected to the pins, no I2C slave devices, either nothing is connected or the scope is connected.&lt;/li&gt;
&lt;li&gt;I&amp;#39;ve used it in triggering mode and in non-triggering mode, when it wrongly reads that the pin status is high I can see on the scope that it is low&lt;/li&gt;
&lt;li&gt;I&amp;#39;ll have to play more with the code and see if I can get a sample project showing the issue when I get time.&lt;/li&gt;
&lt;/ol&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: GPIO pin reading wrong value</title><link>https://devzone.nordicsemi.com/thread/115737?ContentTypeID=1</link><pubDate>Tue, 12 Dec 2017 15:58:26 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6b97207a-f332-4014-a97c-5ea47e0f8be9</guid><dc:creator>MartinBL</dc:creator><description>&lt;ol&gt;
&lt;li&gt;Do you have anything connected to the pins that can be messing with the voltage levels? Logic low is not the default state of a TWI bus so I imagine that if you have a TWI slave connected it may be manipulating the logic levels under certain conditions.&lt;/li&gt;
&lt;li&gt;How do you use the Scope? Are you triggering on positive edges or something? Are you sure are capturing every event that might drive the pins high for short periods of time?&lt;/li&gt;
&lt;li&gt;Can you upload more of your code?&lt;/li&gt;
&lt;/ol&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: GPIO pin reading wrong value</title><link>https://devzone.nordicsemi.com/thread/115738?ContentTypeID=1</link><pubDate>Mon, 11 Dec 2017 08:43:51 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9ae30d47-0ef9-4860-b60b-05ab36fb9403</guid><dc:creator>jm_laird</dc:creator><description>&lt;ol&gt;
&lt;li&gt;That seems to &lt;em&gt;somewhat&lt;/em&gt; resolve it - for a short period of time. With a delay of 3ms it now works fine if I run the code as many times as I want in a row, if however I leave the module alone idle and then run it again after about 10 seconds, it goes back to the old behavior of wrongly detecting the pins as high.&lt;/li&gt;
&lt;li&gt;No reset at all, we have a command line interface for running parts of code, when no command is entered the system is idle.&lt;/li&gt;
&lt;li&gt;Both pins wrongly read high.&lt;/li&gt;
&lt;/ol&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: GPIO pin reading wrong value</title><link>https://devzone.nordicsemi.com/thread/115736?ContentTypeID=1</link><pubDate>Thu, 07 Dec 2017 11:46:18 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5ddf31d1-1a0a-4dac-9772-6aacaa43b05b</guid><dc:creator>MartinBL</dc:creator><description>&lt;p&gt;Strange. Maybe the GPIO logic needs some time to stabilize after a power on reset.&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;What happens if you try to put a small delay before you read the pins?&lt;/li&gt;
&lt;li&gt;As I understand it you do not power off the device between the first faulty, and the second correct reading? Only a pin or softreset?&lt;/li&gt;
&lt;li&gt;You notice that one or both of the pins reads low at the line &lt;code&gt;if( SDAVal &amp;amp;&amp;amp; SCLVal )&lt;/code&gt;?&lt;/li&gt;
&lt;/ol&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>