<?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>topic Re: Correct syntax/method for setting IOCON bits in LPC Microcontrollers</title>
    <link>https://community.nxp.com/t5/LPC-Microcontrollers/Correct-syntax-method-for-setting-IOCON-bits/m-p/526130#M8763</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by deevee on Wed Oct 02 15:15:52 MST 2013&lt;/STRONG&gt;&lt;BR /&gt;&lt;SPAN&gt;Just to clarify something with that register config...&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This register starts up as 00011010000 (0xD0)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;With this value you get StandardGPIO/Reserved/AD-Digital/Reserved/NoHysteresis/Pull&lt;/SPAN&gt;&lt;STRONG&gt;UP&lt;/STRONG&gt;&lt;SPAN&gt;enabled/FuncReserved &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The value you mentioned the register should have was (0x9C) which comes out as 00011001001&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Which sets things up as StandardGPIO/Reserved/AD-Digital/Reserved/NoHysteresis/Pull&lt;/SPAN&gt;&lt;STRONG&gt;DOWN&lt;/STRONG&gt;&lt;SPAN&gt;enabled/DigitalIO&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;This value has the IO resistor set up the wrong way round for my application.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;As you say, for this register, I only want to flip a single bit, to set the pin function which gives 00011010001 (0xD1) &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;StandardGPIO/Reserved/AD-Digital/Reserved/NoHysteresis/Pull&lt;/SPAN&gt;&lt;STRONG&gt;UP&lt;/STRONG&gt;&lt;SPAN&gt;enabled/DigitalIO&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;So - is 0xD1 correct or have I mis-read something somewhere and actually (0x9C) is correct. I'm looking at the UM10398 data sheet at table 134 on page 125.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Let me know what you think&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Best&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;D&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 15 Jun 2016 17:01:33 GMT</pubDate>
    <dc:creator>lpcware</dc:creator>
    <dc:date>2016-06-15T17:01:33Z</dc:date>
    <item>
      <title>Correct syntax/method for setting IOCON bits</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/Correct-syntax-method-for-setting-IOCON-bits/m-p/526127#M8760</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by deevee on Thu Sep 26 14:55:02 MST 2013&lt;/STRONG&gt;&lt;BR /&gt;&lt;SPAN&gt;Evening - hoping that someone can shed a little light on something I read in another post (&lt;/SPAN&gt;&lt;A href="http://http://www.lpcware.com/content/forum/unable-configure-gpio045-etc-input" rel="nofollow noopener noreferrer" target="_blank"&gt;http://www.lpcware.com/content/forum/unable-configure-gpio045-etc-input&lt;/A&gt;&lt;SPAN&gt;)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;With reference to setting bits in a GPIO's IOCON, NXP_Paul mentions: &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;HR /&gt;&lt;SPAN style="color: #0000ff;"&gt;&lt;STRONG&gt;Quote: &lt;/STRONG&gt;&lt;BR /&gt;So the configuration to get this working is minimal:&lt;BR /&gt;LPC_IOCON-&amp;gt;PIO0_4 &amp;amp;= ~(1&amp;lt;&amp;lt;4); // disable internal pull-up&lt;BR /&gt;Make sure you don't set IOCON using:&lt;BR /&gt;LPC_IOCON-&amp;gt;PIO0_4 = 0;&lt;BR /&gt;or else this bit will always read back as a '0' when reading the PIN register (reserved bit 7 must remain 1).&lt;/SPAN&gt;&lt;HR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Please can someone explain why the top method is 'better' than the bottom method? Is it actually 'better', is there a convention?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I see that the first version of that line specifically clear bit 4 of that register, where as the second sets its value, in total, to 0. I understand that by clearing a single bit you leave bit 7 alone, as it has to set to one for the stuff that was being discussed there to work.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;In the project I am working on, for example, I have an active low input, connected to Port1 Bit0 of my LPCXpresso LPC1114 - which is IOCON_R_PIO1_0&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;From the data sheet:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This is a 32bit register which initialises as xxxxxxxxxxxxxxxxxxxxx00011010000&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;bits 11 thru 31 are reserved, so we don't care about them&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;bits 0 thru 2 set the function, a value of 0x1 here is digital I/O : 001b&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;bits 3 thru 4 set the mode, this is an active low switch so we need the pull up to be enabled (0x2) : 10b&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;bit 5 sets the Hysteresis, the opto switch as a Schmitt trigger on it so we don't need it (0) : 0b&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;bit 7 sets A or D mode, its a switch so let's have D (1) : 1b&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;bits 8 thru 9 are reserved : 00b&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;bit 10 sets the open-drain mode, its an input so we don't care, lets leave it as a standard GPIO (0) : 0b&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;config bits thus are 0001010001 which is 0x0051&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;From here I seem to have a number of options of setting those bits.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I could:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD bgcolor="#cacaca"&gt; &lt;PRE&gt;LPC_IOCON-&amp;gt;R_PIO1_0 = 0x51;&amp;nbsp; //simple enough, right? But will it mess with other things?&lt;/PRE&gt; &lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;or:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD bgcolor="#cacaca"&gt; &lt;PRE&gt;
LPC_IOCON_R_PIO1_0 &amp;amp;= ~(0xff);&amp;nbsp;&amp;nbsp; //clear the bits we are about to set, we don't know what they were, best start with zeros. Bitwise AND-equals NOT (~) the bits you want to clear
LPC_IOCON_R_PIO1_0 |= 0x51 &amp;amp; 0xff; //ANDing the value with the mask from above means we don't accidentally set any of the wrong bits
//this seems like the safest way to do this, but its a bit long winded&lt;/PRE&gt; &lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;or:&lt;/SPAN&gt;&lt;BR /&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD bgcolor="#cacaca"&gt; &lt;PRE&gt;LPC_IOCON_R_PIO1_0 &amp;amp;= ~(0xff) | (0x51&amp;lt;&amp;lt;8)&amp;nbsp; //if I've understood the bitmasking thing properly, this should shift 0x51 into the bottom 8bits of the register without touching anything else&lt;/PRE&gt; &lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;So - which method of setting those bits is the 'most correct'/best practice/follows convention? Is my bit mask okay, and, is it actually any more succinct than the two line clear and OR method above?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;For reference, I'm extremely new to LPCXpresso/programming for ARM etc. I'm coming from a background of writing ASM for PICs and prototyping with Arduinos (so C 'programming short cuts' will be lost on me a little). Please let me know if you need any further information, to help you help me.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks folks!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Jun 2016 17:01:31 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/Correct-syntax-method-for-setting-IOCON-bits/m-p/526127#M8760</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-15T17:01:31Z</dc:date>
    </item>
    <item>
      <title>Re: Correct syntax/method for setting IOCON bits</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/Correct-syntax-method-for-setting-IOCON-bits/m-p/526128#M8761</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by NXP_Paul on Mon Sep 30 12:33:31 MST 2013&lt;/STRONG&gt;&lt;BR /&gt;&lt;SPAN&gt;The problem with the first solution is that it does not leave reserved bit 6 set to 1.&amp;nbsp; Also, the mode bits [4:3] are 01, so you should use 0xC9 rather than 0x51:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;LPC_IOCON-&amp;gt;R_PIO1_0 = 0xC9;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I do not see a problem using this method to configure the IOCON register, as long as the value is calculated correctly.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The second method is okay, but again, don't clear the reserved bit 6.&amp;nbsp; The ANDing shouldn't be necessary.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;LPC_IOCON_R_PIO1_0 &amp;amp;= ~(0xbf);&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;LPC_IOCON_R_PIO1_0 |= 0x89 &amp;amp; 0xff;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Since your example only requires changing the FUNC bits [2:0], it would probably be best to only change these 3 bits, minimizing the chance of an error:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;LPC_IOCON_R_PIO1_0 &amp;amp;= ~0x07;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;LPC_IOCON_R_PIO1_0 |= 0x01;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The third method is okay but you don't need to shift the value by 8 bits.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Most of the NXP example code uses the second method.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Jun 2016 17:01:32 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/Correct-syntax-method-for-setting-IOCON-bits/m-p/526128#M8761</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-15T17:01:32Z</dc:date>
    </item>
    <item>
      <title>Re: Correct syntax/method for setting IOCON bits</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/Correct-syntax-method-for-setting-IOCON-bits/m-p/526129#M8762</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by deevee on Tue Oct 01 07:05:39 MST 2013&lt;/STRONG&gt;&lt;BR /&gt;&lt;SPAN&gt;That's great, thanks Paul!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Jun 2016 17:01:32 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/Correct-syntax-method-for-setting-IOCON-bits/m-p/526129#M8762</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-15T17:01:32Z</dc:date>
    </item>
    <item>
      <title>Re: Correct syntax/method for setting IOCON bits</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/Correct-syntax-method-for-setting-IOCON-bits/m-p/526130#M8763</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by deevee on Wed Oct 02 15:15:52 MST 2013&lt;/STRONG&gt;&lt;BR /&gt;&lt;SPAN&gt;Just to clarify something with that register config...&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This register starts up as 00011010000 (0xD0)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;With this value you get StandardGPIO/Reserved/AD-Digital/Reserved/NoHysteresis/Pull&lt;/SPAN&gt;&lt;STRONG&gt;UP&lt;/STRONG&gt;&lt;SPAN&gt;enabled/FuncReserved &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The value you mentioned the register should have was (0x9C) which comes out as 00011001001&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Which sets things up as StandardGPIO/Reserved/AD-Digital/Reserved/NoHysteresis/Pull&lt;/SPAN&gt;&lt;STRONG&gt;DOWN&lt;/STRONG&gt;&lt;SPAN&gt;enabled/DigitalIO&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;This value has the IO resistor set up the wrong way round for my application.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;As you say, for this register, I only want to flip a single bit, to set the pin function which gives 00011010001 (0xD1) &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;StandardGPIO/Reserved/AD-Digital/Reserved/NoHysteresis/Pull&lt;/SPAN&gt;&lt;STRONG&gt;UP&lt;/STRONG&gt;&lt;SPAN&gt;enabled/DigitalIO&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;So - is 0xD1 correct or have I mis-read something somewhere and actually (0x9C) is correct. I'm looking at the UM10398 data sheet at table 134 on page 125.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Let me know what you think&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Best&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;D&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Jun 2016 17:01:33 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/Correct-syntax-method-for-setting-IOCON-bits/m-p/526130#M8763</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-15T17:01:33Z</dc:date>
    </item>
    <item>
      <title>Re: Correct syntax/method for setting IOCON bits</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/Correct-syntax-method-for-setting-IOCON-bits/m-p/526131#M8764</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by NXP_Paul on Thu Oct 03 07:07:31 MST 2013&lt;/STRONG&gt;&lt;BR /&gt;&lt;SPAN&gt;My apologies.&amp;nbsp; You're correct.&amp;nbsp; I was looking at pull-down rather than pull-up.&amp;nbsp; The value should be 0xD1.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Jun 2016 17:01:34 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/Correct-syntax-method-for-setting-IOCON-bits/m-p/526131#M8764</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-15T17:01:34Z</dc:date>
    </item>
    <item>
      <title>Re: Correct syntax/method for setting IOCON bits</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/Correct-syntax-method-for-setting-IOCON-bits/m-p/526132#M8765</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by deevee on Thu Oct 03 08:03:58 MST 2013&lt;/STRONG&gt;&lt;BR /&gt;&lt;SPAN&gt;OK cool, thought I was going crazy there for a moment...&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks again&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;D&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Jun 2016 17:01:34 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/Correct-syntax-method-for-setting-IOCON-bits/m-p/526132#M8765</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-15T17:01:34Z</dc:date>
    </item>
  </channel>
</rss>

