<?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>Uart using mode 3</title><link>https://community.arm.com/developer/tools-software/tools/f/keil-forum/25482/uart-using-mode-3</link><description> 
Hellow 

 
I have a project now, using Atmel&amp;#39;s AT89C51RE2 as MCU. 
I&amp;#39;ve already checked each UART(UART0, UART1) worked alone in mode 1,
but I need 2 uarts works simultaneously. 
I heard for both uarts working, each uart configuration has different
baud</description><dc:language>en-US</dc:language><generator>Telligent Community 10</generator><item><title>RE: Uart using mode 3</title><link>https://community.arm.com/thread/146371?ContentTypeID=1</link><pubDate>Sun, 24 May 2009 19:34:12 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:505c2b8b-3117-4e57-a8d9-ac62200bc198</guid><dc:creator>dae guen kim</dc:creator><description>&lt;p&gt;&lt;p&gt;
I tried codes below, and saw both uarts(uart0/uart1) were working
concurrently.&lt;br /&gt;
I just made reset each tx interrupt flag(TI_0/TI_1) in different
place.&lt;/p&gt;

&lt;pre&gt;
#include &amp;lt;stdio.h&amp;gt;
#include &amp;lt;string.h&amp;gt;
#include &amp;quot;at89c51re2_2.h&amp;quot;
#include &amp;quot;INTRINS.H&amp;quot;

#define TRUE              1
#define FALSE             0
#define BUF_SIZE          50

typedef unsigned char       Int8;
typedef signed char         SignedInt8;
typedef unsigned short      Int16;
typedef signed short        SignedInt16;
typedef unsigned long       Int32;
typedef signed long         SignedInt32;
typedef bit                 Boolean;

Int8        serialBuf[BUF_SIZE];
Int8        serialBufPos;
Int8        serialByte;
Boolean     parseCommandFlag = FALSE;

Int8        serialBuf1[BUF_SIZE];
Int8        serialBufPos1;
Int8        serialByte1;
Boolean     parseCommandFlag1 = FALSE;

void print_Uart0(char *sBuf_0)
{
    while(*sBuf_0 != NULL)
    {
        SBUF_0 = *sBuf_0++;
    }
    SBUF_0 = 0x0D;
}

void print_Uart1(char *sBuf_1)
{
    while(*sBuf_1 != NULL)
    {
        while(!TI_1);
        TI_1 = 0;
        SBUF_1 = *sBuf_1++;
    }
    while(!TI_1);
    TI_1 = 0;
    SBUF_1 = 0x0D;
}

void ParseCommand (void)
{
    print_Uart0(&amp;quot;\n==Exciter UART0 Test==\n&amp;quot;);
    memset(serialBuf, 0x00, sizeof(Int8)*BUF_SIZE);
    serialBufPos = 0;
    parseCommandFlag = FALSE;
}

void ParseCommand1(void)
{
    print_Uart1(&amp;quot;\n==Exciter UART1 Test==\n&amp;quot;);
    memset(serialBuf1, 0x00, sizeof(Int8)*BUF_SIZE);
    serialBufPos1 = 0;
    parseCommandFlag1 = FALSE;
}

void main (void)
{
    memset(serialBuf, 0x00, sizeof(Int8)*BUF_SIZE);
    serialBufPos = 0;
    memset(serialBuf1, 0x00, sizeof(Int8)*BUF_SIZE);
    serialBufPos1 = 0;

/********* Timer Set ********/
    T2CON = 0;
    BDRCON_0 |= 0x0C; //RBCK_0 = 1, TBCK_0 = 1
    BDRCON_1 &amp;amp;= 0xF3; //RBCK_1 = 0, TBCK_1 = 0

    TMOD |= 0x20 ;         /* Timer 1 in mode 2 */

/****** UART0 ******/
    //use internal Baud Rate Generator
    SCON_0 = 0x50;    /* uart0 in mode 1 (8 bit), REN_0=1 */
    BDRCON_0 &amp;amp;=0xEC;  /* BRR_0=0; SRC_0=0; SPD_0 = 0*/
    PCON |= 0x80;     /* SMOD1_0 = 1;*/
    BRL_0 = 251;      /* set 19200, @18.432Mhz (BRL_0=251;SPD_0=1;SMOD1_0=0) */


/****** UART1 ******/
    SCON_1 = 0x50;    /* uart1 in mode 1 (8 bit), REN_1=1*/
    BDRCON_1 |= 0x80;
    TH1  = 0xFB;                 /* 19200 Bds at 18.432MHz */

    TI_0 = 1;
    TI_1 = 1;
    RI_0 = 0;
    RI_1 = 0;

    IEN1 |= 0x08;    /* Enable serial port1 interrupt   */
    ES = 1;          /* Enable serial port0 interrupt   */
    EA = 1;              /* Enable global interrupt */

    BDRCON_0 |=0x10; /* Baud rate generator run*/
    TR1 = 1;
    while(1)
    {
        if(parseCommandFlag == TRUE)
            ParseCommand();
        if(parseCommandFlag1 == TRUE)
            ParseCommand1();
    }
}

void serial0_IT(void) interrupt 4
{
    if (RI_0 == 1)
    {
        RI_0 = 0;

        serialByte = SBUF_0; /* Read receive data */
        if (serialByte == &amp;#39; &amp;#39;)
        {
            /* skip space */
        }
        else if (serialByte == 0x0D)    /* CR */
        {
            serialBuf [serialBufPos] = &amp;#39;\0&amp;#39;;
            parseCommandFlag = TRUE;
        }
        else
        {
            if ((serialByte &amp;gt;= &amp;#39;a&amp;#39;) &amp;amp;&amp;amp; (serialByte &amp;lt;= &amp;#39;z&amp;#39;))
            {
                serialByte -= 0x20;     /* 0x20 = &amp;#39;a&amp;#39; - &amp;#39;A&amp;#39; */
            }
            serialBuf [serialBufPos] = serialByte;
            serialBufPos++;
        }
    }
    else if (TI_0 == 1)
        TI_0 = 0;
}

void serial1_IT(void) interrupt 10
{
    if (RI_1 == 1)
    {
        RI_1 = 0;

        serialByte1 = SBUF_1; /* Read receive data */
        if (serialByte1 == &amp;#39; &amp;#39;)
        {
            /* skip space */
        }
        else if (serialByte1 == 0x0D)    /* CR */
        {
            serialBuf1[serialBufPos1] = &amp;#39;\0&amp;#39;;
            parseCommandFlag1 = TRUE;
        }
        else
        {
            if ((serialByte1 &amp;gt;= &amp;#39;a&amp;#39;) &amp;amp;&amp;amp; (serialByte1 &amp;lt;= &amp;#39;z&amp;#39;))
            {
                serialByte1 -= 0x20;     /* 0x20 = &amp;#39;a&amp;#39; - &amp;#39;A&amp;#39; */
            }
            serialBuf1[serialBufPos1] = serialByte1;
            serialBufPos1++;
        }
    }
}
&lt;/pre&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Uart using mode 3</title><link>https://community.arm.com/thread/144641?ContentTypeID=1</link><pubDate>Thu, 21 May 2009 19:07:56 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:09391f83-5503-4918-a287-3e53ea2e0a95</guid><dc:creator>dae guen kim</dc:creator><description>&lt;p&gt;&lt;p&gt;
I tried to change the codes to check Tx interrupt flag before
using serial buffer register(SFR : SBUF_0, SBUF_1).&lt;/p&gt;

&lt;p&gt;
the result is uart1 has totally no respond(uart0 still works), but
when I use uart0 after I check uart1 doesn&amp;#39;t work, I see uart1 prints
test string(&amp;quot;==Exciter Uart1 Test==&amp;quot;) just once through
hyper-terminal(I use two hyper terminal program, for uart0 and
uart1). the condition is when I use uart0 just after checking uart1
does not work, then I see this phenomenon.&lt;/p&gt;

&lt;pre&gt;
void print_Uart0(char *sBuf_0)
{
    while(*sBuf_0 != NULL)
    {
        &lt;b&gt;while(!TI_0);&lt;/b&gt;&lt;b&gt;&amp;lt;== add this&lt;/b&gt;
        &lt;b&gt;TI_0 = 0;&lt;/b&gt;  &lt;b&gt;&amp;lt;== add this&lt;/b&gt;
        SBUF_0 = *sBuf_0++;
    }
    &lt;b&gt;while(!TI_0);&lt;/b&gt;&lt;b&gt;&amp;lt;== add this&lt;/b&gt;
    &lt;b&gt;TI_0 = 0;&lt;/b&gt;&amp;gt;&lt;b&gt;&amp;lt;== add this&lt;/b&gt;
    SBUF_0 = 0x0D;
}

void print_Uart1(char *sBuf_1)
{
    while(*sBuf_1 != NULL)
    {
        &lt;b&gt;while(!TI_1);&lt;/b&gt;&lt;b&gt;&amp;lt;== add this&lt;/b&gt;
        &lt;b&gt;TI_1 = 0;&lt;/b&gt;  &lt;b&gt;&amp;lt;== add this&lt;/b&gt;
        SBUF_1 = *sBuf_1++;
    }
    &lt;b&gt;while(!TI_1);&lt;/b&gt;&lt;b&gt;&amp;lt;== add this&lt;/b&gt;
    &lt;b&gt;TI_1 = 0;&lt;/b&gt;&amp;gt;&lt;b&gt;&amp;lt;== add this&lt;/b&gt;
    SBUF_1 = 0x0D;
}
&lt;/pre&gt;

&lt;p&gt;
&lt;br /&gt;
and add this codes in initial of main function&lt;/p&gt;

&lt;pre&gt;
 &lt;b&gt;TI_0 = 1;&lt;/b&gt;
 &lt;b&gt;TI_1 = 1;&lt;/b&gt;
 &lt;b&gt;RI_0 = 0;&lt;/b&gt;
 &lt;b&gt;RI_1 = 0;&lt;/b&gt;
&lt;/pre&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Uart using mode 3</title><link>https://community.arm.com/thread/142316?ContentTypeID=1</link><pubDate>Thu, 21 May 2009 06:10:56 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:2d789a84-4c92-4f7c-88fb-40ae4fa77145</guid><dc:creator>Andy Neil</dc:creator><description>&lt;p&gt;&lt;p&gt;
Yes, it is very often the case that the &amp;quot;easy&amp;quot; option is the most
limited option - and working around those limitations can soon make
the &amp;quot;hard&amp;quot; option a lot simpler!&lt;/p&gt;

&lt;p&gt;
In this case, I don&amp;#39;t think polled &lt;i&gt;&lt;b&gt;transmission&lt;/b&gt;&lt;/i&gt;
should be difficult - reception is another thing...&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Uart using mode 3</title><link>https://community.arm.com/thread/139174?ContentTypeID=1</link><pubDate>Thu, 21 May 2009 06:01:26 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:c44bf4c7-17d8-4f15-b2c2-d5f2d1b83c32</guid><dc:creator>erik  malund</dc:creator><description>&lt;p&gt;&lt;p&gt;
&lt;i&gt;I don&amp;#39;t think that&amp;#39;s necessarily true at all&lt;/i&gt;&lt;br /&gt;
with great skill and a very short workloop you can.&lt;/p&gt;

&lt;p&gt;
The common misconception that poll is easier the interrupt driven
is totally false.&lt;/p&gt;

&lt;p&gt;
Anyhow now that the OP has posted readable code it is clear that
an (erroneous) TI will hang him.&lt;/p&gt;

&lt;p&gt;
Erik&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Uart using mode 3</title><link>https://community.arm.com/thread/135780?ContentTypeID=1</link><pubDate>Wed, 20 May 2009 23:17:57 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:4fb41b67-132c-4f76-8b92-f6d4169e114e</guid><dc:creator>Andy Neil</dc:creator><description>&lt;p&gt;&lt;p&gt;
I don&amp;#39;t think that&amp;#39;s &lt;i&gt;necessarily&lt;/i&gt; true at all.&lt;/p&gt;

&lt;p&gt;
I don&amp;#39;t see why you shouldn&amp;#39;t poll both UARTs.&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Uart using mode 3</title><link>https://community.arm.com/thread/139175?ContentTypeID=1</link><pubDate>Wed, 20 May 2009 22:44:47 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:3336285c-f4d4-4ca4-83cc-b68e6f32b2d4</guid><dc:creator>Andy Neil</dc:creator><description>&lt;p&gt;&lt;p&gt;
take a look at this tutorial: &lt;a href="http://www.8052.com/faqs/120308"&gt;www.8052.com/.../120308&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;
In fact, there&amp;#39;s a whole section on 8051/2 serial comms at
&lt;a href="http://www.8052.com/faqs"&gt;http://www.8052.com/faqs&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;
&lt;b&gt;Hint:&lt;/b&gt; When is SBUF ready to take the next character...?&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Uart using mode 3</title><link>https://community.arm.com/thread/130485?ContentTypeID=1</link><pubDate>Wed, 20 May 2009 17:53:12 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:0c08d42b-c6bb-4506-b082-412d77d55efe</guid><dc:creator>dae guen kim</dc:creator><description>&lt;p&gt;&lt;p&gt;
I appreciate your relpy.&lt;/p&gt;

&lt;p&gt;
but I&amp;#39;m not good at english.&lt;br /&gt;
I don&amp;#39;t understand &amp;#39;they must be interrupt driven&amp;#39; means.&lt;/p&gt;

&lt;p&gt;
Could you please tell me more in detail?&lt;/p&gt;

&lt;p&gt;
thank you.&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Uart using mode 3</title><link>https://community.arm.com/thread/125468?ContentTypeID=1</link><pubDate>Wed, 20 May 2009 17:45:12 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:bb2b2254-37ea-48d7-bcd7-3b74893a3484</guid><dc:creator>erik  malund</dc:creator><description>&lt;p&gt;&lt;p&gt;
if you want the two UARTs to work concurrently they must be
interrupt driven&lt;/p&gt;

&lt;p&gt;
Erik&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Uart using mode 3</title><link>https://community.arm.com/thread/114947?ContentTypeID=1</link><pubDate>Wed, 20 May 2009 17:35:29 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:de9ab26f-7d13-4e28-a731-02258dec47b3</guid><dc:creator>dae guen kim</dc:creator><description>&lt;p&gt;&lt;p&gt;
thank you for replying.&lt;/p&gt;

&lt;p&gt;
This is first time for me to use this forum, and I might be
impatient to solve my problem.&lt;br /&gt;
I missed the tips for posting messages, sorry :-)&lt;/p&gt;

&lt;p&gt;
I leave my codes again.&lt;br /&gt;
===================================================&lt;/p&gt;

&lt;pre&gt;
#include &amp;lt;stdio.h&amp;gt;
#include &amp;lt;string.h&amp;gt;
#include &amp;quot;at89c51re2_2.h&amp;quot;
#include &amp;quot;INTRINS.H&amp;quot;

#define TRUE                            1
#define FALSE                           0
#define BUF_SIZE                                                100

typedef unsigned char       Int8;
typedef signed char         SignedInt8;
typedef unsigned short      Int16;
typedef signed short        SignedInt16;
typedef unsigned long       Int32;
typedef signed long         SignedInt32;
typedef bit                 Boolean;

Int8        serialBuf[BUF_SIZE];
Int8        serialBufPos;
Int8        serialByte;
Boolean     parseCommandFlag = FALSE;

Int8        serialBuf1[BUF_SIZE];
Int8        serialBufPos1;
Int8        serialByte1;
Boolean     parseCommandFlag1 = FALSE;

void print_Uart0(char *sBuf_0)
{
    while(*sBuf_0 != NULL)
    {
        SBUF_0 = *sBuf_0++;
    }
    SBUF_0 = 0x0D;
}

void print_Uart1(char *sBuf_1)
{
    while(*sBuf_1 != NULL)
    {
        SBUF_1 = *sBuf_1++;
    }
    SBUF_1 = 0x0D;
}

void ParseCommand (void)
{
    print_Uart0(&amp;quot;\n==Exciter UART0 Test==\n&amp;quot;);
    memset(serialBuf, 0x00, sizeof(Int8)*BUF_SIZE);
    serialBufPos = 0;
    parseCommandFlag = FALSE;
}

void ParseCommand1(void)
{
    print_Uart1(&amp;quot;\n==Exciter UART1 Test==\n&amp;quot;);
    memset(serialBuf1, 0x00, sizeof(Int8)*BUF_SIZE);
    serialBufPos1 = 0;
    parseCommandFlag1 = FALSE;
}

void main (void)
{
    memset(serialBuf, 0x00, sizeof(Int8)*BUF_SIZE);
    serialBufPos = 0;
    memset(serialBuf1, 0x00, sizeof(Int8)*BUF_SIZE);
    serialBufPos1 = 0;

    /********* Timer Set ********/
    T2CON = 0;
    T2CON |= 0x30; //RCLK=1, TCLK = 1

    BDRCON_0 |= 0x0C; //RBCK_0 = 1, TBCK_0 = 1,
    BDRCON_1 &amp;amp;= 0xF3; //RBCK_1 = 0, TBCK_1 = 0,

    TH2=0xFF; /* init value */
    TL2=0xFB; /* init value */
    RCAP2H=0xFF; /* reload value, 115200 Bds at 18.432MHz */
    RCAP2L=0xFB; /* reload value, 115200 Bds at 18.432MHz */

    /****** UART0 ******/
    //use internal Baud Rate Generator
    SCON_0 = 0x50;    /* uart in mode 1 (8 bit), REN_0=1 */
    BDRCON_0 &amp;amp;=0xEC;  /* BRR_0=0; SRC_0=0; SPD_0 = 0*/
    PCON |= 0x80;     /* SMOD1_0 = 1;*/
    BDRCON_0 |=0x0C;  /* TBCK_0=1;RBCK_0=1; SPD_0=0 */
    BRL_0 = 251;      /* set 19200, @18.432Mhz */

    /****** UART1 ******/
    SCON_1 = 0x50;         /* uart1 in serial port mode 1 (8 bit), REN_1=1, */

    IEN1 |= 0x08;    /* Enable serial port1 interrupt   */
    ES = 1;          /* Enable serial port0 interrupt   */
    EA = 1;          /* Enable global interrupt */

    BDRCON_0 |=0x10; /* Baud rate generator run*/
    TR2 = 1;

    while(1)
    {
        if(parseCommandFlag == TRUE)
            ParseCommand();
        if(parseCommandFlag1 == TRUE)
            ParseCommand1();
    }
}

void serial0_IT(void) interrupt 4
{
    if (RI_0 == 1)
    {
        RI_0 = 0;

        serialByte = SBUF_0; /* Read receive data */
        if (serialByte == &amp;#39; &amp;#39;)
        {
            /* skip space */
        }
        else if (serialByte == 0x0D)    /* CR */
        {
            serialBuf [serialBufPos] = &amp;#39;\0&amp;#39;;
            parseCommandFlag = TRUE;
        }
        else
        {
            if ((serialByte &amp;gt;= &amp;#39;a&amp;#39;) &amp;amp;&amp;amp; (serialByte &amp;lt;= &amp;#39;z&amp;#39;))
            {
                serialByte -= 0x20;     /* 0x20 = &amp;#39;a&amp;#39; - &amp;#39;A&amp;#39; */
            }
            serialBuf [serialBufPos] = serialByte;
            serialBufPos++;
        }
    }
}

void serial1_IT(void) interrupt 10
{
    if (RI_1 == 1)
    {
        RI_1 = 0;

        serialByte1 = SBUF_1; /* Read receive data */
        if (serialByte1 == &amp;#39; &amp;#39;)
        {
            /* skip space */
        }
        else if (serialByte1 == 0x0D)    /* CR */
        {
            serialBuf1[serialBufPos1] = &amp;#39;\0&amp;#39;;
            parseCommandFlag1 = TRUE;
        }
        else
        {
            if ((serialByte1 &amp;gt;= &amp;#39;a&amp;#39;) &amp;amp;&amp;amp; (serialByte1 &amp;lt;= &amp;#39;z&amp;#39;))
            {
                serialByte1 -= 0x20;     /* 0x20 = &amp;#39;a&amp;#39; - &amp;#39;A&amp;#39; */
            }
            serialBuf1[serialBufPos1] = serialByte1;
            serialBufPos1++;
        }
    }
}

&lt;/pre&gt;

&lt;p&gt;
&lt;br /&gt;
===================================================&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Uart using mode 3</title><link>https://community.arm.com/thread/103125?ContentTypeID=1</link><pubDate>Wed, 20 May 2009 10:36:04 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:18d5003f-f3f0-4201-be28-013588377abd</guid><dc:creator>Andy Neil</dc:creator><description>&lt;p&gt;&lt;p&gt;
&lt;i&gt;&amp;quot; I&amp;#39;ve already checked the datasheet(AT89C51RE2), and sample
uart test codes from atmel web site&amp;quot;&lt;/i&gt;&lt;/p&gt;

&lt;p&gt;
Well, if you checked them as carefully as you studied the
instructions on how to post source code on this forum, and as
carefully as you checked your post in the &lt;b&gt;Preview&lt;/b&gt;, it wouldn&amp;#39;t
be surprising that you missed a load of important details!&lt;/p&gt;

&lt;p&gt;
See: &lt;a href="http://www.danlhenry.com/caps/keil_code.png"&gt;www.danlhenry.com/.../keil_code.png&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;
Correctly-posted source code should look something like
this:&lt;/p&gt;

&lt;pre&gt;
void print_Uart0(char *sBuf_0)
{
   while( *sBuf_0 != NULL)
   {
      SBUF_0 = *sBuf_0++;
   }
   SBUF_0 = 0x0D;
}
&lt;/pre&gt;

&lt;p&gt;
&lt;br /&gt;
and the problem should be obvious...&lt;/p&gt;

&lt;p&gt;
If it&amp;#39;s not obvious to you, take a look at this tutorial:
&lt;a href="http://www.8052.com/faqs/120308"&gt;www.8052.com/.../120308&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;
In fact, there&amp;#39;s a whole section on 8051/2 serial comms at
&lt;a href="http://www.8052.com/faqs"&gt;http://www.8052.com/faqs&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;
&lt;b&gt;Hint:&lt;/b&gt; When is SBUF ready to take the next character...?&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Uart using mode 3</title><link>https://community.arm.com/thread/103120?ContentTypeID=1</link><pubDate>Wed, 20 May 2009 06:04:21 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:975e3f63-913e-4aa9-9947-1923722215f7</guid><dc:creator>erik  malund</dc:creator><description>&lt;p&gt;&lt;p&gt;
&lt;i&gt;but, if both two uarts(uart0/uart1) operate, it happens that
uart1 is dead.&lt;br /&gt;
say again, after power on the board before using uart0, uart1 seems
to be working good, but once I using uart0 with hyper-terminal
program, uart1 doesn&amp;#39;t work any more.&lt;/i&gt;&lt;br /&gt;
nothing to do with UART mode&lt;br /&gt;
if you follow the direction above &amp;quot;Place source code source code
between .....&amp;quot; &lt;b&gt;that is properly formatted and commented&lt;/b&gt; it is
likely that someone will point you in the right direction.&lt;/p&gt;

&lt;p&gt;
Erik&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Uart using mode 3</title><link>https://community.arm.com/thread/77458?ContentTypeID=1</link><pubDate>Tue, 19 May 2009 23:11:50 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:89daf773-2323-46a0-9f15-e8e08fe197c3</guid><dc:creator>dae guen kim</dc:creator><description>&lt;p&gt;&lt;p&gt;
thanks for replying.&lt;/p&gt;

&lt;p&gt;
first of all, I&amp;#39;ve already checked the datasheet(AT89C51RE2), and
sample uart test codes from atmel web site(&lt;a href="http://www.atmel.com"&gt;http://www.atmel.com&lt;/a&gt;).&lt;/p&gt;

&lt;p&gt;
what I want is both uarts(uart0, uart1) work at the same time.&lt;/p&gt;

&lt;p&gt;
each uart operates very well by itself using different baud rate
source(timer1, timer2, internal baud rate generator), and using
different baud rate(9,600bps, 19,200bps, 11,5200bps).&lt;br /&gt;
but, if both two uarts(uart0/uart1) operate, it happens that uart1 is
dead.&lt;br /&gt;
say again, after power on the board before using uart0, uart1 seems
to be working good, but once I using uart0 with hyper-terminal
program, uart1 doesn&amp;#39;t work any more.&lt;/p&gt;

&lt;p&gt;
thank you.&lt;/p&gt;

&lt;p&gt;
Here&amp;#39;s my codes I used.&lt;br /&gt;
=========== code start =============&lt;br /&gt;
#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
#include &amp;lt;string.h&amp;gt;&lt;br /&gt;
#include &amp;quot;at89c51re2_2.h&amp;quot;&lt;br /&gt;
#include &amp;quot;INTRINS.H&amp;quot;&lt;/p&gt;

&lt;p&gt;
#define TRUE 1&lt;br /&gt;
#define FALSE 0&lt;br /&gt;
#define BUF_SIZE 100&lt;/p&gt;

&lt;p&gt;
typedef unsigned char Int8;&lt;br /&gt;
typedef signed char SignedInt8;&lt;br /&gt;
typedef unsigned short Int16;&lt;br /&gt;
typedef signed short SignedInt16;&lt;br /&gt;
typedef unsigned long Int32;&lt;br /&gt;
typedef signed long SignedInt32;&lt;br /&gt;
typedef bit Boolean;&lt;/p&gt;

&lt;p&gt;
Int8 serialBuf[BUF_SIZE];&lt;br /&gt;
Int8 serialBufPos;&lt;br /&gt;
Int8 serialByte;&lt;br /&gt;
Boolean parseCommandFlag = FALSE;&lt;/p&gt;

&lt;p&gt;
Int8 serialBuf1[BUF_SIZE];&lt;br /&gt;
Int8 serialBufPos1;&lt;br /&gt;
Int8 serialByte1;&lt;br /&gt;
Boolean parseCommandFlag1 = FALSE;&lt;/p&gt;

&lt;p&gt;
void print_Uart0(char *sBuf_0)&lt;br /&gt;
{ while(*sBuf_0 != NULL) { SBUF_0 = *sBuf_0++; } SBUF_0 = 0x0D;&lt;br /&gt;
}&lt;/p&gt;

&lt;p&gt;
void print_Uart1(char *sBuf_1)&lt;br /&gt;
{ while(*sBuf_1 != NULL) { SBUF_1 = *sBuf_1++; } SBUF_1 = 0x0D;&lt;br /&gt;
}&lt;/p&gt;

&lt;p&gt;
void ParseCommand (void)&lt;br /&gt;
{ print_Uart0(&amp;quot;\n==Exciter UART0 Test==\n&amp;quot;); memset(serialBuf, 0x00,
sizeof(Int8)*BUF_SIZE); serialBufPos = 0; parseCommandFlag =
FALSE;&lt;br /&gt;
}&lt;/p&gt;

&lt;p&gt;
void ParseCommand1(void)&lt;br /&gt;
{ print_Uart1(&amp;quot;\n==Exciter UART1 Test==\n&amp;quot;); memset(serialBuf1, 0x00,
sizeof(Int8)*BUF_SIZE); serialBufPos1 = 0; parseCommandFlag1 =
FALSE;&lt;br /&gt;
}&lt;/p&gt;

&lt;p&gt;
void main (void)&lt;br /&gt;
{ memset(serialBuf, 0x00, sizeof(Int8)*BUF_SIZE); serialBufPos = 0;
memset(serialBuf1, 0x00, sizeof(Int8)*BUF_SIZE); serialBufPos1 =
0;&lt;/p&gt;

&lt;p&gt;
/********* Timer Set ********/ T2CON = 0; T2CON |= 0x30;
//RCLK=1(use timer2 as receive clock in serial port mode 1,3), TCLK =
1 (use timer2 as receive clock in mode 1,3) BDRCON_0 |= 0x0C;
//RBCK_0 = 1, TBCK_0 = 1, Tx/Rx select internal baud rate generator
BDRCON_1 &amp;amp;= 0xF3; //RBCK_1 = 0, TBCK_1 = 0, Tx/Rx select timer1
or timer2 for baud rate generator&lt;/p&gt;

&lt;p&gt;
TH2=0xFF; /* init value */ TL2=0xFB; /* init value */ RCAP2H=0xFF;
/* reload value, 115200 Bds at 18.432MHz */ RCAP2L=0xFB; /* reload
value, 115200 Bds at 18.432MHz */&lt;/p&gt;

&lt;p&gt;
/****** UART0 ******/ //use internal Baud Rate Generator SCON_0 =
0x50; /* uart in mode 1 (8 bit), REN_0=1 */ BDRCON_0 &amp;amp;=0xEC; /*
BRR_0=0; SRC_0=0; SPD_0 = 0*/ PCON |= 0x80; /* SMOD1_0 = 1;*/
BDRCON_0 |=0x0C; /* TBCK_0=1;RBCK_0=1; SPD_0=0 use Slow internal Baud
Rate Generator*/ BRL_0 = 251; /* set 19200, @18.432Mhz
(BRL_0=251;SPD_0=1;SMOD1_0=0) */&lt;/p&gt;

&lt;p&gt;
/****** UART1 ******/ //CKCON0 = 0x7F; SCON_1 = 0x50; /* uart1 in
serial port mode 1 (8 bit), REN_1=1, enable multiprocessor comm
*/&lt;/p&gt;

&lt;p&gt;
IEN1 |= 0x08; /* Enable serial port1 interrupt */ ES = 1; /*
Enable serial port0 interrupt */ EA = 1; /* Enable global interrupt
*/&lt;/p&gt;

&lt;p&gt;
BDRCON_0 |=0x10; /* Baud rate generator run*/ TR2 = 1;&lt;/p&gt;

&lt;p&gt;
while(1) { if(parseCommandFlag == TRUE) ParseCommand();
if(parseCommandFlag1 == TRUE) ParseCommand1(); }&lt;br /&gt;
}&lt;/p&gt;

&lt;p&gt;
void serial0_IT(void) interrupt 4&lt;br /&gt;
{ if (RI_0 == 1) { RI_0 = 0;&lt;/p&gt;

&lt;p&gt;
serialByte = SBUF_0; /* Read receive data */ if (serialByte == &amp;#39;
&amp;#39;) { /* skip space */ } else if (serialByte == 0x0D) /* CR */ {
serialBuf [serialBufPos] = &amp;#39;\0&amp;#39;; parseCommandFlag = TRUE; } else { if
((serialByte &amp;gt;= &amp;#39;a&amp;#39;) &amp;amp;&amp;amp; (serialByte &amp;lt;= &amp;#39;z&amp;#39;)) {
serialByte -= 0x20; /* 0x20 = &amp;#39;a&amp;#39; - &amp;#39;A&amp;#39; */ } serialBuf [serialBufPos]
= serialByte; serialBufPos++; } }&lt;br /&gt;
}&lt;/p&gt;

&lt;p&gt;
void serial1_IT(void) interrupt 10&lt;br /&gt;
{ if (RI_1 == 1) { RI_1 = 0;&lt;/p&gt;

&lt;p&gt;
serialByte1 = SBUF_1; /* Read receive data */ if (serialByte1 == &amp;#39;
&amp;#39;) { /* skip space */ } else if (serialByte1 == 0x0D) /* CR */ {
serialBuf1[serialBufPos1] = &amp;#39;\0&amp;#39;; parseCommandFlag1 = TRUE; } else {
if ((serialByte1 &amp;gt;= &amp;#39;a&amp;#39;) &amp;amp;&amp;amp; (serialByte1 &amp;lt;= &amp;#39;z&amp;#39;)) {
serialByte1 -= 0x20; /* 0x20 = &amp;#39;a&amp;#39; - &amp;#39;A&amp;#39; */ }
serialBuf1[serialBufPos1] = serialByte1; serialBufPos1++; } }&lt;br /&gt;
}&lt;/p&gt;

&lt;p&gt;
=========== code end ===============&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Uart using mode 3</title><link>https://community.arm.com/thread/56117?ContentTypeID=1</link><pubDate>Tue, 19 May 2009 21:26:19 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:c6f2a48e-b5d5-4ad7-b5a8-e09911804195</guid><dc:creator>Andy Neil</dc:creator><description>&lt;p&gt;&lt;p&gt;
&lt;i&gt;&amp;quot;I heard&amp;quot;&lt;/i&gt;&lt;/p&gt;

&lt;p&gt;
Where did you hear it?&lt;/p&gt;

&lt;p&gt;
Don&amp;#39;t rely on hearsay - check it in the &lt;b&gt;Datasheet&lt;/b&gt;!&lt;/p&gt;

&lt;p&gt;
&lt;i&gt;&amp;quot;for both uarts working, each uart configuration has different
baud rate, and different mode, is it correct?&amp;quot;&lt;/i&gt;&lt;/p&gt;

&lt;p&gt;
It&amp;#39;s up to you to configure them how you want to!&lt;/p&gt;

&lt;p&gt;
&lt;i&gt;&amp;quot;I tried to make uart work in mode 3, but I failed.&amp;quot;&lt;/i&gt;&lt;/p&gt;

&lt;p&gt;
In what way, precisely, did you &amp;quot;fail&amp;quot;?&lt;/p&gt;

&lt;p&gt;
&lt;i&gt;&amp;quot;Could you give me any advice ?? &amp;quot;&lt;/i&gt;&lt;/p&gt;

&lt;p&gt;
You need to describe the problem properly:&lt;/p&gt;

&lt;p&gt;
What, exacly, did you try?&lt;br /&gt;
What were you expecting to happen?&lt;br /&gt;
What actually happened?&lt;br /&gt;
What &lt;b&gt;debugging&lt;/b&gt; have you done to account for the
difference?&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>