<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://community.arm.com/utility/feedstylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>What is wrong the sio.c?</title><link>https://community.arm.com/developer/tools-software/tools/f/keil-forum/19278/what-is-wrong-the-sio-c</link><description> I download intsio.zip and only changed some word in main.c as following: 
 
void main (void)
{
com_initialize (); /* initialize interrupt driven serial I/O */
com_baudrate (38400); /* setup for 38400 baud */

printf (&amp;quot;Interrupt-driver Serial I/O Example</description><dc:language>en-US</dc:language><generator>Telligent Community 10</generator><item><title>RE: What is wrong the sio.c?</title><link>https://community.arm.com/thread/111670?ContentTypeID=1</link><pubDate>Fri, 23 Sep 2005 10:14:05 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:dd4153bd-c08e-494f-8ab3-7084446434ea</guid><dc:creator>Jon Ward</dc:creator><description>&lt;p&gt;Well, the _getkey routine is included in the main.c file as follows:&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;
/*------------------------------------------------------------------------------
_getkey waits until a character is received from the serial port.  This may not
be the exact desired operation (for example if the buffer is empty, this
function hangs waiting for a character to be received).
------------------------------------------------------------------------------*/
char _getkey (void)
{
int k;

do
  {
  k = com_getchar ();
  }
while (k == -1);

return ((unsigned char) k);
}
&lt;/pre&gt;
&lt;br /&gt;
The SIO.C file includes routines to test the length of the serial buffer BEFORE you try to get a character using _getkey.  Alternatively, you can use com_getchar (also in SIO.C) that returns a -1 if there are no characters in the buffer.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Jon&lt;/b&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: What is wrong the sio.c?</title><link>https://community.arm.com/thread/122954?ContentTypeID=1</link><pubDate>Fri, 23 Sep 2005 04:15:47 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:a294da87-b895-4f5c-84be-a7de936edfa3</guid><dc:creator>Andy Neil</dc:creator><description>&lt;p&gt;&lt;i&gt;&amp;quot;it&amp;#39;s just doing what it says on the tin!&amp;quot;&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
See: &lt;a href="http://www.keil.com/support/man/docs/c51/c51__getkey.htm"&gt;http://www.keil.com/support/man/docs/c51/c51__getkey.htm&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
Which is consistent with Keil&amp;#39;s other products:&lt;br /&gt;
&lt;a href="http://www.keil.com/support/man/docs/ca/ca__getkey.htm"&gt;http://www.keil.com/support/man/docs/ca/ca__getkey.htm&lt;/a&gt;&lt;br /&gt;
&lt;a href="http://www.keil.com/support/man/docs/c166/c166__getkey.htm"&gt;http://www.keil.com/support/man/docs/c166/c166__getkey.htm&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: What is wrong the sio.c?</title><link>https://community.arm.com/thread/111669?ContentTypeID=1</link><pubDate>Fri, 23 Sep 2005 03:41:21 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:735065fc-26b4-4044-9c29-ffe18a549fab</guid><dc:creator>Andy Neil</dc:creator><description>&lt;p&gt;&lt;i&gt;&amp;quot;the main_loop would stop excuting when program runing in _getkey() while UART hadn&amp;#39;t income data&amp;quot;&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
That&amp;#39;s the way the SIO example works - it&amp;#39;s just doing what it says on the tin!&lt;br /&gt;
&lt;br /&gt;
If this is not the behaviour you require, you will have to change it to your requirements.&lt;br /&gt;
&lt;br /&gt;
Me, I created a &lt;b&gt;rx_available()&lt;/b&gt; function to check if any received character(s) are available, then I call getchar() only if there&amp;#39;s something to get.&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;&amp;quot;the program would poll RI untill the data coming &amp;quot;&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
Not if you&amp;#39;re doing interrupt-driven serial IO!&lt;br /&gt;
If your program really is doing this, it might explain your problem...&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;&amp;quot;If i want communicating with ISR_driven and running others program when serial has no incoming data,how can i do?&amp;quot;&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
See above.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: What is wrong the sio.c?</title><link>https://community.arm.com/thread/97480?ContentTypeID=1</link><pubDate>Thu, 22 Sep 2005 23:33:11 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:429aa75e-8175-43bd-9068-04acf6db9784</guid><dc:creator>Nantian Gumo</dc:creator><description>&lt;p&gt;Now,I found that the main_loop would stop excuting when program runing in &lt;b&gt;_getkey() &lt;/b&gt; while UART hadn&amp;#39;t income data, in others words,the program would poll &lt;b&gt;RI&lt;/b&gt; untill the data coming . If i want communicating with &lt;b&gt;ISR_driven&lt;/b&gt; and running others program when serial has no incoming data,how can i do?&lt;br /&gt;
&lt;br /&gt;
Thanks a lot!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: What is wrong the sio.c?</title><link>https://community.arm.com/thread/73486?ContentTypeID=1</link><pubDate>Sun, 18 Sep 2005 11:11:24 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:10ad96d2-b843-4248-bf32-146f956e8eb2</guid><dc:creator>Nantian Gumo</dc:creator><description>&lt;p&gt;The ring buffer is ,256 bytes for transmitting while 256 bytes for receiving,and others to variables.I try changing &lt;b&gt;getchar()&lt;/b&gt; to &lt;b&gt;_getkey()&lt;/b&gt;,after first transmitting (prefix+234bytes),pc could receive some of prefix(&amp;#39;@&amp;#39;,&amp;#39;cCmd&amp;#39;) and 234bytes&amp;#39; message ,and the second time just received 6 bytes&amp;#39; prefix(&amp;#39;AA&amp;#39;,&amp;#39;55&amp;#39;,&amp;#39;@&amp;#39;,&amp;#39;cCmd&amp;#39;,&amp;#39;cCmdComplex&amp;#39;,&amp;#39;cCmdLen&amp;#39;);the thirst time&amp;#39;s just like the first&amp;#39;s,and the fourth&amp;#39;s likes the second&amp;#39;s ,such revolve.But everytime just transmit the same thing ,prefix + 234 bytes&amp;#39; message.&lt;br /&gt;
I long for that you teach me how to  resolve data in the ring buffer like these.&lt;br /&gt;
Thank you very much.&lt;br /&gt;
Best regards,&lt;br /&gt;
Nantiangumo.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: What is wrong the sio.c?</title><link>https://community.arm.com/thread/97478?ContentTypeID=1</link><pubDate>Sat, 17 Sep 2005 16:56:36 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:c9543ce8-e039-485a-8d98-0d50b6d60d33</guid><dc:creator>Andy Neil</dc:creator><description>&lt;p&gt;&lt;i&gt;&amp;quot;Buffer: xdata (p89lv51rd2 ram_on_chip&amp;#39;s xdata is 768 bytes, and xdata used 517bytes)&amp;quot;&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
So your ring buffers are in XDATA.&lt;br /&gt;
What size are they?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: What is wrong the sio.c?</title><link>https://community.arm.com/thread/122956?ContentTypeID=1</link><pubDate>Sat, 17 Sep 2005 16:52:48 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:e899c90d-fc14-4e72-967c-4dddc5afec20</guid><dc:creator>Andy Neil</dc:creator><description>&lt;p&gt;&lt;i&gt;&amp;quot;It seems like you expect getchar() to echo the received character.&amp;quot;&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
Yes, that is the documented behaviour of the standard Keil C51 implementation:&lt;br /&gt;
&lt;a href="http://www.keil.com/support/man/docs/c51/c51_getchar.htm"&gt;http://www.keil.com/support/man/docs/c51/c51_getchar.htm&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: What is wrong the sio.c?</title><link>https://community.arm.com/thread/44691?ContentTypeID=1</link><pubDate>Sat, 17 Sep 2005 16:37:03 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:5cb70227-7583-47e8-8e16-b533513aa958</guid><dc:creator>Jon Ward</dc:creator><description>&lt;p&gt;Were you able to get the serial I/O example working without making any changes?  I have used that code for more than 10 years without failure.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Jon&lt;/b&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: What is wrong the sio.c?</title><link>https://community.arm.com/thread/111664?ContentTypeID=1</link><pubDate>Sat, 17 Sep 2005 12:00:04 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:6b124062-8695-4783-bba6-5b4695d9487a</guid><dc:creator>Drew Davis</dc:creator><description>&lt;p&gt;It seems like you expect getchar() to echo the received character.  (If not, the command prefix AA 55 40 etc would not appear.)&lt;br /&gt;
&lt;br /&gt;
In the command body, you also echo characters with printf().  (I&amp;#39;d suggest putchar() for less overhead.)  This would cause the characters to be echoed of the command body to be output twice, once by getchar and once by printf.&lt;br /&gt;
&lt;br /&gt;
Is your serial output buffered, or at least synchronized with a delay loop watching TI?  What if printf() writes to the SBUF before the byte written by the getchar() character has finished transmitting?  Since both routines are writing the same value, you might see only one appear.&lt;br /&gt;
&lt;br /&gt;
I don&amp;#39;t understand why the prefix to the command should ever be doubly echoed.  You say this is correct, but I wouldn&amp;#39;t expect that from the posted code.  Only the bytes after the command length should be doubled.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: What is wrong the sio.c?</title><link>https://community.arm.com/thread/97479?ContentTypeID=1</link><pubDate>Sat, 17 Sep 2005 11:33:59 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:591cafc0-2392-44ec-a09a-f07c87b63139</guid><dc:creator>Nantian Gumo</dc:creator><description>&lt;p&gt;Additionally,just doubly transmit and never miss bytes.&lt;br /&gt;
&lt;br /&gt;
Thanks.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: What is wrong the sio.c?</title><link>https://community.arm.com/thread/73485?ContentTypeID=1</link><pubDate>Sat, 17 Sep 2005 11:31:30 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:c24d3972-a27c-40c9-bfc9-e611564d10dc</guid><dc:creator>Nantian Gumo</dc:creator><description>&lt;p&gt;Processor:P89LV51RD2&lt;br /&gt;
Clock:11.0592MHz&lt;br /&gt;
Buffer:xdata(p89lv51rd2 ram_on_chip&amp;#39;s xdata is 768 bytes,and xdata used 517bytes)&lt;br /&gt;
Platform:\win2000\program\addition\communication\supperClient&lt;br /&gt;
&lt;br /&gt;
When baudrate been changed to 9600 or 4800,the same thing happened.&lt;br /&gt;
sio.c never been changed,and main loop just shew as up.&lt;br /&gt;
&lt;br /&gt;
Best regards,&lt;br /&gt;
Nantiangumo&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: What is wrong the sio.c?</title><link>https://community.arm.com/thread/44688?ContentTypeID=1</link><pubDate>Sat, 17 Sep 2005 05:34:22 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:9e94f62a-0531-445f-be2a-a63c992d0570</guid><dc:creator>Andy Neil</dc:creator><description>&lt;p&gt;What processor are you using, and what clock speed?&lt;br /&gt;
Where are your ring buffers - xdata? data? or what?&lt;br /&gt;
&lt;br /&gt;
Are you sure that your system has sufficient performance to guarantee that you will never miss a character?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>