<?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 Receiving characters from a UART under MQX in MQX Software Solutions</title>
    <link>https://community.nxp.com/t5/MQX-Software-Solutions/Receiving-characters-from-a-UART-under-MQX/m-p/412033#M13766</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I am trying to implement a serial (UART) interface on a K60 under MQX.&amp;nbsp; This seemed relatively straight forward, but am having no success.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I intend to have a task that that opens and receives characters on ittyx port.&amp;nbsp; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I do not know how many characters will be received.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I want to read 4 characters when available (a header) and then read additional characters based on a length value included in the first 4 bytes read.&amp;nbsp; It did not seem unreasonable to think the MQX serial drivers could support this kind of use case.&amp;nbsp; &lt;STRONG&gt;Can someone point me to example code or offer insights as to how the driver works?&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Questions:&lt;/P&gt;&lt;P&gt;Should I be using read() or fread(), I am not clear on the difference?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If in a while(1) loop I make a call to fread() and no characters are available, does this task give up the cpu allowing other tasks to run.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If, as an example, the chip has received 8 bytes and I do an fread() to read the first 4 bytes, can I then do another fread() for the remaining bytes, will I get the next 4 bytes?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 16 Nov 2015 23:51:53 GMT</pubDate>
    <dc:creator>dcooper</dc:creator>
    <dc:date>2015-11-16T23:51:53Z</dc:date>
    <item>
      <title>Receiving characters from a UART under MQX</title>
      <link>https://community.nxp.com/t5/MQX-Software-Solutions/Receiving-characters-from-a-UART-under-MQX/m-p/412033#M13766</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I am trying to implement a serial (UART) interface on a K60 under MQX.&amp;nbsp; This seemed relatively straight forward, but am having no success.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I intend to have a task that that opens and receives characters on ittyx port.&amp;nbsp; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I do not know how many characters will be received.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I want to read 4 characters when available (a header) and then read additional characters based on a length value included in the first 4 bytes read.&amp;nbsp; It did not seem unreasonable to think the MQX serial drivers could support this kind of use case.&amp;nbsp; &lt;STRONG&gt;Can someone point me to example code or offer insights as to how the driver works?&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Questions:&lt;/P&gt;&lt;P&gt;Should I be using read() or fread(), I am not clear on the difference?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If in a while(1) loop I make a call to fread() and no characters are available, does this task give up the cpu allowing other tasks to run.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If, as an example, the chip has received 8 bytes and I do an fread() to read the first 4 bytes, can I then do another fread() for the remaining bytes, will I get the next 4 bytes?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 16 Nov 2015 23:51:53 GMT</pubDate>
      <guid>https://community.nxp.com/t5/MQX-Software-Solutions/Receiving-characters-from-a-UART-under-MQX/m-p/412033#M13766</guid>
      <dc:creator>dcooper</dc:creator>
      <dc:date>2015-11-16T23:51:53Z</dc:date>
    </item>
    <item>
      <title>Re: Receiving characters from a UART under MQX</title>
      <link>https://community.nxp.com/t5/MQX-Software-Solutions/Receiving-characters-from-a-UART-under-MQX/m-p/412034#M13767</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi David,&lt;/P&gt;&lt;P&gt;Yes you can do this.&lt;/P&gt;&lt;P&gt;With UART in interrupt mode it will buffer the inputs and code can go extract as many bytes at a time as you want.&amp;nbsp; And then go back and get more.&lt;/P&gt;&lt;P&gt;If too many bytes are received before reading from the buffer, then the buffer will retain what it accumulated and drop the rest of the incoming characters.&amp;nbsp; The buffer is configurable in size in the BSP file init_sci.c.&amp;nbsp; It defaults to 64 bytes for the TX buffer and 64 bytes for the RX buffer.&lt;/P&gt;&lt;P&gt;UPDATE:&lt;/P&gt;&lt;P&gt;I created test code for the Tower TWR-K60D100M+TWR-SER using C:\Freescale\Freescale_MQX_4_2\mqx\examples\hello2 example.&lt;/P&gt;&lt;P&gt;The three key files are attached (user_config.h, twrk60d100m.h, hello.c).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Recompile the BSP/PSP and hello2 MQX application.&lt;/P&gt;&lt;P&gt;Run it and use terminal with 115200baud, 8-bit, 1-stop, no parity.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The default terminal output window will show below if you do not type any character as input:&lt;/P&gt;&lt;P&gt; Hello&lt;/P&gt;&lt;P&gt;- World &lt;/P&gt;&lt;P&gt;-------------------&lt;/P&gt;&lt;P&gt;No characters received in last 4 seconds.... --------------------&lt;/P&gt;&lt;P&gt;No characters received in last 4 seconds.... -------------------&lt;/P&gt;&lt;P&gt;No characters received in last 4 seconds.... --------------------&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The code will check the UART Rx buffer every 4 seconds to see if any characters have been received.&amp;nbsp; If not then you see the above results.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you type 1 or more characters (I typed "1234") during the 4 second interval, then you will see following:&lt;/P&gt;&lt;P&gt;No characters received in last 4 seconds.... ------------1234--------&lt;/P&gt;&lt;P&gt;Number of characters read was 5-------------------&lt;/P&gt;&lt;P&gt;No characters received in last 4 seconds.... --------------------&lt;/P&gt;&lt;P&gt;No characters received in last 4 seconds.... --------------------&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you type more then 64 characters during the 4 second interval you will see:&lt;/P&gt;&lt;P&gt;No characters received in last 4 seconds.... --------------------&lt;/P&gt;&lt;P&gt;No characters received in last 4 seconds.... --------abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ__abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ__-----------&lt;/P&gt;&lt;P&gt;RX_OVERRUNS Error...&lt;/P&gt;&lt;P&gt;-------------------&lt;/P&gt;&lt;P&gt;No characters received in last 4 seconds.... -------------------&lt;/P&gt;&lt;P&gt;No characters received in last 4 seconds.... --------------------&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You should be able to create a state machine to read your first four characters to determine what the header is telling you to do (read more, restart, other).&amp;nbsp; Assuming the header indicates how many characters you need to read, they are still in the input buffer waiting for you get them.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;David&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 20 Nov 2015 00:09:31 GMT</pubDate>
      <guid>https://community.nxp.com/t5/MQX-Software-Solutions/Receiving-characters-from-a-UART-under-MQX/m-p/412034#M13767</guid>
      <dc:creator>DavidS</dc:creator>
      <dc:date>2015-11-20T00:09:31Z</dc:date>
    </item>
  </channel>
</rss>

