<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>Kinetis Microcontrollers中的主题 Re: GPIO.h input/output configuration correct ?</title>
    <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/GPIO-h-input-output-configuration-correct/m-p/372511#M19409</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Kas&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The macro looks to be incorrect - as you point out it can't set an input once it has been an output, &lt;EM&gt;but it is also is necessary to clear the corresponding bit in the GPIOx_PIDR register to be able to read anything other than a zero&lt;/EM&gt;.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Below are the macros that I use (from the uTasker project):&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;#define _CONFIG_PORT_OUTPUT(ref, pins, chars) GPIO##ref##_PIDR &amp;amp;= ~(pins); fnConnectGPIO(PORT##ref, pins, chars); GPIO##ref##_PDDR |= (pins)&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;#define _CONFIG_PORT_INPUT(ref, pins, chars) GPIO##ref##_PIDR &amp;amp;= ~(pins); fnConnectGPIO(PORT##ref, pins, chars); GPIO##ref##_PDDR &amp;amp;= ~(pins)&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;#define _CONFIG_DRIVE_PORT_OUTPUT_VALUE(ref, pins, value, chars) GPIO##ref##_PIDR &amp;amp;= ~(pins); GPIO##ref##_PDOR = ((GPIO##ref##_PDOR &amp;amp; ~(pins)) | (value)); GPIO##ref##_PDDR |= (pins);&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;These allow multiple bits to be configured at the same time and also the output state to be defined when setting an output. The &lt;STRONG&gt;fnConnetGPIO()&lt;/STRONG&gt; part is optional (and I haven't shown its code here) but it allows pull-ups to be defined on inputs and drive strengths to be defined on outputs, which are set the same for each of the pins reference in the call.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;What is a bit strange about the KE and KEA devices is that the ports are in fact basically the same as those in K and KL parts - they use the same 32 bit registers to control them but they are named as if they were 8 bit registers. (One 32 bit register packs in 4 of the 8 bit ports).&lt;/P&gt;&lt;P&gt;I suspect that this is a naming conventon that has its roots in older 8 bit devices but it does make for some compatibility complications due to the naming:&lt;/P&gt;&lt;P&gt;- if there were two ports A an B then everything would be simple&lt;/P&gt;&lt;P&gt;- having 8 pseudo 8 bit ports packed into the 2 real 32 bit ports makes referencing unnecessarily complicated&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;With a few tricks one can live with it but it doesn't keep things as simple as they could have been....&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Mark&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="http://www.utasker.com/kinetis.html" title="http://www.utasker.com/kinetis.html"&gt;http://www.utasker.com/kinetis.html&lt;/A&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 24 Dec 2014 00:30:06 GMT</pubDate>
    <dc:creator>mjbcswitzerland</dc:creator>
    <dc:date>2014-12-24T00:30:06Z</dc:date>
    <item>
      <title>GPIO.h input/output configuration correct ?</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/GPIO-h-input-output-configuration-correct/m-p/372509#M19407</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I was looking in the GPIO.h file for the KEA family and I saw the below code to set input/output for the ports, but something does not look correct to me.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;#define CONFIG_PIN_AS_GPIO(port,register_number,mode)&amp;nbsp;&amp;nbsp;&amp;nbsp; XCONFIG_PIN_AS_GPIO(port,register_number,mode)&lt;/P&gt;&lt;P&gt;#define XCONFIG_PIN_AS_GPIO(port,register_number,mode)&amp;nbsp;&amp;nbsp; (mode == 0) ? (GPIO##port##_PDDR |= 0 &amp;lt;&amp;lt; register_number) : (GPIO##port##_PDDR |= 1 &amp;lt;&amp;lt; register_number)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The first option in the conditional statement (second line) looks incorrect. If the port was previously set as an output (mode = 1) and then you try set the port as an input, you would be doing 1 | 0 which we know is equal to 1 -&amp;gt; output. Should the correct code not be&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;#define XCONFIG_PIN_AS_GPIO(port,register_number,mode)&amp;nbsp;&amp;nbsp; (mode == 0) ? (GPIO##port##_PDDR &amp;amp;= ~(1 &amp;lt;&amp;lt; register_number)) : (GPIO##port##_PDDR |= 1 &amp;lt;&amp;lt; register_number)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;please let me know if I am understanding this incorrectly or if this really is an issue.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;Kas&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 23 Dec 2014 19:52:27 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/GPIO-h-input-output-configuration-correct/m-p/372509#M19407</guid>
      <dc:creator>kaslewis</dc:creator>
      <dc:date>2014-12-23T19:52:27Z</dc:date>
    </item>
    <item>
      <title>Re: GPIO.h input/output configuration correct ?</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/GPIO-h-input-output-configuration-correct/m-p/372510#M19408</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Kas,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I agree you. However, I'm not responsible for the issue and cannot confirm it because I'm not a Freescale person.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Best regards,&lt;/P&gt;&lt;P&gt;Yasuhiko Koumoto.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 23 Dec 2014 21:15:57 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/GPIO-h-input-output-configuration-correct/m-p/372510#M19408</guid>
      <dc:creator>yasuhikokoumoto</dc:creator>
      <dc:date>2014-12-23T21:15:57Z</dc:date>
    </item>
    <item>
      <title>Re: GPIO.h input/output configuration correct ?</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/GPIO-h-input-output-configuration-correct/m-p/372511#M19409</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Kas&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The macro looks to be incorrect - as you point out it can't set an input once it has been an output, &lt;EM&gt;but it is also is necessary to clear the corresponding bit in the GPIOx_PIDR register to be able to read anything other than a zero&lt;/EM&gt;.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Below are the macros that I use (from the uTasker project):&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;#define _CONFIG_PORT_OUTPUT(ref, pins, chars) GPIO##ref##_PIDR &amp;amp;= ~(pins); fnConnectGPIO(PORT##ref, pins, chars); GPIO##ref##_PDDR |= (pins)&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;#define _CONFIG_PORT_INPUT(ref, pins, chars) GPIO##ref##_PIDR &amp;amp;= ~(pins); fnConnectGPIO(PORT##ref, pins, chars); GPIO##ref##_PDDR &amp;amp;= ~(pins)&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;#define _CONFIG_DRIVE_PORT_OUTPUT_VALUE(ref, pins, value, chars) GPIO##ref##_PIDR &amp;amp;= ~(pins); GPIO##ref##_PDOR = ((GPIO##ref##_PDOR &amp;amp; ~(pins)) | (value)); GPIO##ref##_PDDR |= (pins);&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;These allow multiple bits to be configured at the same time and also the output state to be defined when setting an output. The &lt;STRONG&gt;fnConnetGPIO()&lt;/STRONG&gt; part is optional (and I haven't shown its code here) but it allows pull-ups to be defined on inputs and drive strengths to be defined on outputs, which are set the same for each of the pins reference in the call.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;What is a bit strange about the KE and KEA devices is that the ports are in fact basically the same as those in K and KL parts - they use the same 32 bit registers to control them but they are named as if they were 8 bit registers. (One 32 bit register packs in 4 of the 8 bit ports).&lt;/P&gt;&lt;P&gt;I suspect that this is a naming conventon that has its roots in older 8 bit devices but it does make for some compatibility complications due to the naming:&lt;/P&gt;&lt;P&gt;- if there were two ports A an B then everything would be simple&lt;/P&gt;&lt;P&gt;- having 8 pseudo 8 bit ports packed into the 2 real 32 bit ports makes referencing unnecessarily complicated&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;With a few tricks one can live with it but it doesn't keep things as simple as they could have been....&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Mark&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="http://www.utasker.com/kinetis.html" title="http://www.utasker.com/kinetis.html"&gt;http://www.utasker.com/kinetis.html&lt;/A&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 24 Dec 2014 00:30:06 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/GPIO-h-input-output-configuration-correct/m-p/372511#M19409</guid>
      <dc:creator>mjbcswitzerland</dc:creator>
      <dc:date>2014-12-24T00:30:06Z</dc:date>
    </item>
    <item>
      <title>Re: GPIO.h input/output configuration correct ?</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/GPIO-h-input-output-configuration-correct/m-p/372512#M19410</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Looking through the other macros there appears to be other issues. As a general rule simple code like this I try not use other peoples code without checking it first and if possible I write the code myself so as not to be bitten by someone elses bad code.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you for confirming my thoughts&lt;/P&gt;&lt;P&gt;Kas&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 24 Dec 2014 06:12:50 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/GPIO-h-input-output-configuration-correct/m-p/372512#M19410</guid>
      <dc:creator>kaslewis</dc:creator>
      <dc:date>2014-12-24T06:12:50Z</dc:date>
    </item>
    <item>
      <title>Re: GPIO.h input/output configuration correct ?</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/GPIO-h-input-output-configuration-correct/m-p/372513#M19411</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you for confirming my thoughts&lt;/P&gt;&lt;P&gt;Kas&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 24 Dec 2014 06:12:57 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/GPIO-h-input-output-configuration-correct/m-p/372513#M19411</guid>
      <dc:creator>kaslewis</dc:creator>
      <dc:date>2014-12-24T06:12:57Z</dc:date>
    </item>
  </channel>
</rss>

