<?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 k60f120m toggle led with onboard button in Kinetis Microcontrollers</title>
    <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/k60f120m-toggle-led-with-onboard-button/m-p/632560#M38076</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I wanted a easy start in the development with the evalutationboard. So i started to turn leds on , toggle them ....&lt;/P&gt;&lt;P&gt;But i can't find a simple way to toggle a onboard LED with sw1 or sw2 of of the board.&lt;/P&gt;&lt;P&gt;I set the systemclock&lt;/P&gt;&lt;P&gt;SIM_SCGC5 |= SIM_SCGC5_PORTA_MASK ;&lt;/P&gt;&lt;P&gt;set the sw1 as gpio&lt;/P&gt;&lt;P&gt;PORTA_PCR19 |= (PORT_PCR_MUX(1));&lt;/P&gt;&lt;P&gt;and set the resistors&lt;/P&gt;&lt;P&gt;PORTA_PCR19 |= PORT_PCR_PE_MASK;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If i press the button nothing happens and the GPIO_PDIR_PDI (19) don't have a high state&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;tmp=(GPIOA_PDIR &amp;amp; GPIO_PDIR_PDI(1&amp;lt;&amp;lt;19));&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 29 Nov 2016 08:39:02 GMT</pubDate>
    <dc:creator>philippadolph</dc:creator>
    <dc:date>2016-11-29T08:39:02Z</dc:date>
    <item>
      <title>k60f120m toggle led with onboard button</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/k60f120m-toggle-led-with-onboard-button/m-p/632560#M38076</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I wanted a easy start in the development with the evalutationboard. So i started to turn leds on , toggle them ....&lt;/P&gt;&lt;P&gt;But i can't find a simple way to toggle a onboard LED with sw1 or sw2 of of the board.&lt;/P&gt;&lt;P&gt;I set the systemclock&lt;/P&gt;&lt;P&gt;SIM_SCGC5 |= SIM_SCGC5_PORTA_MASK ;&lt;/P&gt;&lt;P&gt;set the sw1 as gpio&lt;/P&gt;&lt;P&gt;PORTA_PCR19 |= (PORT_PCR_MUX(1));&lt;/P&gt;&lt;P&gt;and set the resistors&lt;/P&gt;&lt;P&gt;PORTA_PCR19 |= PORT_PCR_PE_MASK;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If i press the button nothing happens and the GPIO_PDIR_PDI (19) don't have a high state&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;tmp=(GPIOA_PDIR &amp;amp; GPIO_PDIR_PDI(1&amp;lt;&amp;lt;19));&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 29 Nov 2016 08:39:02 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/k60f120m-toggle-led-with-onboard-button/m-p/632560#M38076</guid>
      <dc:creator>philippadolph</dc:creator>
      <dc:date>2016-11-29T08:39:02Z</dc:date>
    </item>
    <item>
      <title>Re: k60f120m toggle led with onboard button</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/k60f120m-toggle-led-with-onboard-button/m-p/632561#M38077</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Philipp&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I didn't see an "error" with the code but I think that you may need to add a delay between configuring the input and reading it. Don't forget that PTA19 (SW1) on the TWR board has no external pull-up resistor and the pin defaults to a XTAL output at reset. If you change its function and add a pull-up it may take a short amount of time before the input charges to '1'; if your code immediately reads the input it may always read '0', whether the button is pressed or not.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In case you want a simple start with your board see the link below since it gives you everything you may need (including industrial quality USB and Ethernet) and allows you to simulate the board in (approx.) real-time to avoid HW complications.&lt;BR /&gt;To do what you want in this case, the code would be (it handles all details that beginners may get wrong but gives most powerful learning and analysis capabilities at the same time)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;#define SWITCH_SW1&amp;nbsp;&amp;nbsp;&amp;nbsp; PORTA_BIT19&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;_CONFIG_PORT_INPUT(A, (SWITCH_SW1), PORT_PS_UP_ENABLE); // configure the input (including clocking and characteristics)&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;if (_READ_PORT_MASK(A, SWITCH_SW1) == 0) { // read the state of the input&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; // SW1 pressed&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;}&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;else {&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; // SW1 not pressed&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;}&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;Note that there is one thing in your code that may have caused failure:&lt;/EM&gt;&lt;BR /&gt;&lt;STRONG&gt;&lt;EM&gt;PORTA_PCR19 |= (PORT_PCR_MUX(1)); // risky but works for this pin&lt;/EM&gt;&lt;/STRONG&gt;&lt;BR /&gt;&lt;EM&gt;This works since the default peripheral function is ALT 0 (XTAL) but may fail if it weren't.&lt;/EM&gt;&lt;BR /&gt;&lt;STRONG&gt;&lt;EM&gt;PORTA_PCR19 = (PORT_PCR_MUX(1)); // no risk&lt;/EM&gt;&lt;/STRONG&gt;&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;SPAN&gt;Kinetis for Professionals: &lt;/SPAN&gt;&lt;A class="jive-link-external-small" href="https://community.nxp.com/external-link.jspa?url=http%3A%2F%2Fwww.utasker.com%2Fkinetis.html" rel="nofollow" target="_blank"&gt;http://www.utasker.com/kinetis.html&lt;/A&gt;&lt;BR /&gt;&lt;SPAN&gt;K60F120: &lt;/SPAN&gt;&lt;A class="jive-link-external-small" href="https://community.nxp.com/external-link.jspa?url=http%3A%2F%2Fwww.utasker.com%2Fkinetis%2FTWR-K60F120M.html" rel="nofollow" target="_blank"&gt;http://www.utasker.com/kinetis/TWR-K60F120M.html&lt;/A&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 29 Nov 2016 12:01:40 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/k60f120m-toggle-led-with-onboard-button/m-p/632561#M38077</guid>
      <dc:creator>mjbcswitzerland</dc:creator>
      <dc:date>2016-11-29T12:01:40Z</dc:date>
    </item>
  </channel>
</rss>

