<?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: FRDM-KE04Z Software bit banging in Kinetis Microcontrollers</title>
    <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/FRDM-KE04Z-Software-bit-banging/m-p/736746#M44978</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Since the KE02 has 3 UARTs, I am assuming that this is a school exercise in bit-banging since it otherwise doesn't make much sense to do it like this.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;However, if you need a fast solution just take the Open Source uTasker FRDM-KE02Z project at the links below and replace the following in your code:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;1. Initialise the pins with&lt;BR /&gt;#define UART_RX&amp;nbsp;&amp;nbsp; KE_PORTA_BIT3&lt;BR /&gt;#define UART_TX&amp;nbsp;&amp;nbsp; KE_PORTA_BIT2&lt;BR /&gt;_CONFIG_PORT_INPUT(A, (UART_RX), PORT_PS_UP_ENABLE);&lt;BR /&gt;_CONFIG_DRIVE_PORT_OUTPUT_VALUE(A, (UART_TX), (UART_TX), (PORT_SRE_SLOW | PORT_DSE_HIGH)); // initialise driving '1'&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;2. For the delay use&lt;BR /&gt;fnDelayLoop(2);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;3. To read the input pin state use&lt;BR /&gt;if (_READ_PORT_MASK(A, UART_RX) != 0) {&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; // input is '1'&lt;BR /&gt;}&lt;BR /&gt;else {&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; // input is '0'&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;4. To set the UART_TX low use&lt;BR /&gt;_CLEARBITS(A, UART_TX);&lt;BR /&gt;and to set it high use&lt;BR /&gt;_SETBITS(A, UART_TX);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;SPAN&gt;You can find all port macros described at &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%2Fforum%2Findex.php%3Ftopic%3D1875.0" rel="nofollow" target="_blank"&gt;http://www.utasker.com/forum/index.php?topic=1875.0&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&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;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Kinetis: &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;Kinetis KE:&lt;BR /&gt;&lt;SPAN&gt;- &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%2FFRDM-KE02Z.html" rel="nofollow" target="_blank"&gt;http://www.utasker.com/kinetis/FRDM-KE02Z.html&lt;/A&gt;&lt;BR /&gt;&lt;SPAN&gt;- &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%2FFRDM-KE02Z40M.html" rel="nofollow" target="_blank"&gt;http://www.utasker.com/kinetis/FRDM-KE02Z40M.html&lt;/A&gt;&lt;BR /&gt;&lt;SPAN&gt;- &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%2FFRDM-KE04Z.html" rel="nofollow" target="_blank"&gt;http://www.utasker.com/kinetis/FRDM-KE04Z.html&lt;/A&gt;&lt;BR /&gt;&lt;SPAN&gt;- &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%2FFRDM-KE06Z.html" rel="nofollow" target="_blank"&gt;http://www.utasker.com/kinetis/FRDM-KE06Z.html&lt;/A&gt;&lt;BR /&gt;&lt;SPAN&gt;- &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%2FFRDM-KE15Z.html" rel="nofollow" target="_blank"&gt;http://www.utasker.com/kinetis/FRDM-KE15Z.html&lt;/A&gt;&lt;BR /&gt;&lt;SPAN&gt;HW Timers: &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%2Fdocs%2FuTasker%2FuTaskerHWTimers.PDF" rel="nofollow" target="_blank"&gt;http://www.utasker.com/docs/uTasker/uTaskerHWTimers.PDF&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Free Open Source solution: &lt;/SPAN&gt;&lt;A class="jive-link-external-small" href="https://community.nxp.com/external-link.jspa?url=https%3A%2F%2Fgithub.com%2FuTasker%2FuTasker-Kinetis" rel="nofollow" target="_blank"&gt;https://github.com/uTasker/uTasker-Kinetis&lt;/A&gt;&lt;BR /&gt;&lt;SPAN&gt;Working project in 15 minutes video: &lt;/SPAN&gt;&lt;A class="jive-link-external-small" href="https://community.nxp.com/external-link.jspa?url=https%3A%2F%2Fyoutu.be%2FK8ScSgpgQ6M" rel="nofollow" target="_blank"&gt;https://youtu.be/K8ScSgpgQ6M&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;For better, faster, cheaper product developments consider the uTasker developer's version, professional Kinetis support, one-on-one training and complete fast-track project solutions to set you apart from the herd : &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%2Fsupport.html" rel="nofollow" target="_blank"&gt;http://www.utasker.com/support.html&lt;/A&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 16 Apr 2018 14:29:48 GMT</pubDate>
    <dc:creator>mjbcswitzerland</dc:creator>
    <dc:date>2018-04-16T14:29:48Z</dc:date>
    <item>
      <title>FRDM-KE04Z Software bit banging</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/FRDM-KE04Z-Software-bit-banging/m-p/736745#M44977</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I am using&amp;nbsp;&lt;STRONG&gt;FRDM-KE04Z dev board with onboard MKE04Z8VFK4 MCU&lt;/STRONG&gt;, I an=m trying to implement bit banging on this board using 2 GPIO pins one for RX and one for TX. During implementation am unuseful with&amp;nbsp;&lt;SPAN&gt;FRDM-KE04Z. Someone can help me with implementing software UART on this board. As am new to this platform and am unable to configure properly.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Note: The below code has been tested and working on microchip boards. I am to port the same code to&amp;nbsp;FRDM-KE04Z dev board.&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;My code.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;#include "common.h"&lt;BR /&gt;#include "ics.h"&lt;BR /&gt;#include "gpio.h"&lt;BR /&gt;#include "sysinit.h"&lt;BR /&gt;#include "start.h"&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;int main (void);&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;* Global functions&lt;BR /&gt;******************************************************************************/&lt;BR /&gt;unsigned char UART_Receive(void);&lt;BR /&gt;void UART_Transmit(const char DataValue);&lt;BR /&gt;void DelayUs(unsigned int cnt);&lt;BR /&gt;#define UART_RX&amp;nbsp; &amp;nbsp; GPIO_PTA3 // UART RX pin&lt;BR /&gt;#define UART_TX&amp;nbsp; &amp;nbsp; &amp;nbsp;GPIO_PTA2 // UART TX pin&lt;BR /&gt;#define DataBitCount&amp;nbsp; &amp;nbsp;8 // no parity, no flow control&lt;BR /&gt;#define OneBitDelay&amp;nbsp; &amp;nbsp; 2 //(1000000/1200) // microseconds&lt;BR /&gt;//#define GPIOA ((GPIO_Type *)GPIOA_BASE)&lt;/P&gt;&lt;P&gt;/********************************************************************/&lt;BR /&gt;int main (void)&lt;BR /&gt;{&lt;BR /&gt;/* Perform processor initialization */&lt;BR /&gt;sysinit();&lt;BR /&gt;cpu_identify();&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;/* way 2. GPIO initialize single pin name */&lt;/P&gt;&lt;P&gt;GPIO_PinInit(GPIO_PTA2, GPIO_PinOutput);&lt;BR /&gt;GPIO_PinInit(GPIO_PTA3, GPIO_PinInput);&lt;/P&gt;&lt;P&gt;unsigned char ch = 0; // Variable to store Rx character&lt;BR /&gt;GPIO_PinSet(UART_TX);&amp;nbsp; / /TX pin is high in idle state&lt;BR /&gt;while (1)&lt;BR /&gt;{&lt;BR /&gt;ch = UART_Receive(); // Receive a character from UART&lt;BR /&gt;UART_Transmit(ch); // Echo back that character&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;unsigned char UART_Receive(void)&lt;BR /&gt;{&lt;BR /&gt;unsigned char DataValue = 0;&lt;BR /&gt;uint32_t data;&lt;/P&gt;&lt;P&gt;//wait for start bit&lt;BR /&gt;while(UART_RX==1);&lt;/P&gt;&lt;P&gt;DelayUs(OneBitDelay);&lt;BR /&gt;DelayUs(OneBitDelay/2); // Take sample value in the mid of bit duration&lt;/P&gt;&lt;P&gt;for ( unsigned char i = 0; i &amp;lt; DataBitCount; i++ )&lt;BR /&gt;{&lt;BR /&gt;if ( UART_RX == 1 ) //if received bit is high&lt;BR /&gt;{&lt;BR /&gt;DataValue += (1&amp;lt;&amp;lt;i);&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;DelayUs(OneBitDelay);&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;// Check for stop bit&lt;BR /&gt;if ( UART_RX == 1 ) //Stop bit should be high&lt;BR /&gt;{&lt;BR /&gt;DelayUs(OneBitDelay/2);&lt;BR /&gt;return DataValue;&lt;BR /&gt;}&lt;BR /&gt;else //some error occurred !&lt;BR /&gt;{&lt;BR /&gt;DelayUs(OneBitDelay/2);&lt;BR /&gt;return 0x000;&lt;BR /&gt;}&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;void UART_Transmit(const char DataValue)&lt;BR /&gt;{&lt;BR /&gt;/* Basic Logic&lt;/P&gt;&lt;P&gt;TX pin is usually high. A high to low bit is the starting bit and&lt;BR /&gt;a low to high bit is the ending bit. No parity bit. No flow control.&lt;BR /&gt;BitCount is the number of bits to transmit. Data is transmitted LSB first.&lt;/P&gt;&lt;P&gt;*/&lt;/P&gt;&lt;P&gt;// Send Start Bit&lt;BR /&gt;GPIO_PinClear(UART_TX);&lt;BR /&gt;DelayUs(OneBitDelay);&lt;/P&gt;&lt;P&gt;for ( unsigned char i = 0; i &amp;lt; DataBitCount; i++ )&lt;BR /&gt;{&lt;BR /&gt;//Set Data pin according to the DataValue&lt;BR /&gt;if( ((DataValue&amp;gt;&amp;gt;i)&amp;amp;0x1) == 0x1 ) //if Bit is high&lt;BR /&gt;{&lt;BR /&gt;GPIO_PinSet(UART_TX);&lt;BR /&gt;}&lt;BR /&gt;else //if Bit is low&lt;BR /&gt;{&lt;BR /&gt;GPIO_PinClear(UART_TX);&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;DelayUs(OneBitDelay);&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;//Send Stop Bit&lt;BR /&gt;GPIO_PinSet(UART_TX);&lt;BR /&gt;DelayUs(OneBitDelay);&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;void DelayUs(unsigned int cnt)&lt;BR /&gt;{&lt;BR /&gt;while (--cnt != 0)continue;&lt;BR /&gt;}&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 16 Apr 2018 10:43:01 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/FRDM-KE04Z-Software-bit-banging/m-p/736745#M44977</guid>
      <dc:creator>vikranthnk</dc:creator>
      <dc:date>2018-04-16T10:43:01Z</dc:date>
    </item>
    <item>
      <title>Re: FRDM-KE04Z Software bit banging</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/FRDM-KE04Z-Software-bit-banging/m-p/736746#M44978</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Since the KE02 has 3 UARTs, I am assuming that this is a school exercise in bit-banging since it otherwise doesn't make much sense to do it like this.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;However, if you need a fast solution just take the Open Source uTasker FRDM-KE02Z project at the links below and replace the following in your code:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;1. Initialise the pins with&lt;BR /&gt;#define UART_RX&amp;nbsp;&amp;nbsp; KE_PORTA_BIT3&lt;BR /&gt;#define UART_TX&amp;nbsp;&amp;nbsp; KE_PORTA_BIT2&lt;BR /&gt;_CONFIG_PORT_INPUT(A, (UART_RX), PORT_PS_UP_ENABLE);&lt;BR /&gt;_CONFIG_DRIVE_PORT_OUTPUT_VALUE(A, (UART_TX), (UART_TX), (PORT_SRE_SLOW | PORT_DSE_HIGH)); // initialise driving '1'&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;2. For the delay use&lt;BR /&gt;fnDelayLoop(2);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;3. To read the input pin state use&lt;BR /&gt;if (_READ_PORT_MASK(A, UART_RX) != 0) {&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; // input is '1'&lt;BR /&gt;}&lt;BR /&gt;else {&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; // input is '0'&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;4. To set the UART_TX low use&lt;BR /&gt;_CLEARBITS(A, UART_TX);&lt;BR /&gt;and to set it high use&lt;BR /&gt;_SETBITS(A, UART_TX);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;SPAN&gt;You can find all port macros described at &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%2Fforum%2Findex.php%3Ftopic%3D1875.0" rel="nofollow" target="_blank"&gt;http://www.utasker.com/forum/index.php?topic=1875.0&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&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;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Kinetis: &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;Kinetis KE:&lt;BR /&gt;&lt;SPAN&gt;- &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%2FFRDM-KE02Z.html" rel="nofollow" target="_blank"&gt;http://www.utasker.com/kinetis/FRDM-KE02Z.html&lt;/A&gt;&lt;BR /&gt;&lt;SPAN&gt;- &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%2FFRDM-KE02Z40M.html" rel="nofollow" target="_blank"&gt;http://www.utasker.com/kinetis/FRDM-KE02Z40M.html&lt;/A&gt;&lt;BR /&gt;&lt;SPAN&gt;- &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%2FFRDM-KE04Z.html" rel="nofollow" target="_blank"&gt;http://www.utasker.com/kinetis/FRDM-KE04Z.html&lt;/A&gt;&lt;BR /&gt;&lt;SPAN&gt;- &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%2FFRDM-KE06Z.html" rel="nofollow" target="_blank"&gt;http://www.utasker.com/kinetis/FRDM-KE06Z.html&lt;/A&gt;&lt;BR /&gt;&lt;SPAN&gt;- &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%2FFRDM-KE15Z.html" rel="nofollow" target="_blank"&gt;http://www.utasker.com/kinetis/FRDM-KE15Z.html&lt;/A&gt;&lt;BR /&gt;&lt;SPAN&gt;HW Timers: &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%2Fdocs%2FuTasker%2FuTaskerHWTimers.PDF" rel="nofollow" target="_blank"&gt;http://www.utasker.com/docs/uTasker/uTaskerHWTimers.PDF&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Free Open Source solution: &lt;/SPAN&gt;&lt;A class="jive-link-external-small" href="https://community.nxp.com/external-link.jspa?url=https%3A%2F%2Fgithub.com%2FuTasker%2FuTasker-Kinetis" rel="nofollow" target="_blank"&gt;https://github.com/uTasker/uTasker-Kinetis&lt;/A&gt;&lt;BR /&gt;&lt;SPAN&gt;Working project in 15 minutes video: &lt;/SPAN&gt;&lt;A class="jive-link-external-small" href="https://community.nxp.com/external-link.jspa?url=https%3A%2F%2Fyoutu.be%2FK8ScSgpgQ6M" rel="nofollow" target="_blank"&gt;https://youtu.be/K8ScSgpgQ6M&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;For better, faster, cheaper product developments consider the uTasker developer's version, professional Kinetis support, one-on-one training and complete fast-track project solutions to set you apart from the herd : &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%2Fsupport.html" rel="nofollow" target="_blank"&gt;http://www.utasker.com/support.html&lt;/A&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 16 Apr 2018 14:29:48 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/FRDM-KE04Z-Software-bit-banging/m-p/736746#M44978</guid>
      <dc:creator>mjbcswitzerland</dc:creator>
      <dc:date>2018-04-16T14:29:48Z</dc:date>
    </item>
  </channel>
</rss>

