<?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>How to get second FX2 serial port to work?</title><link>https://community.arm.com/developer/tools-software/tools/f/keil-forum/20554/how-to-get-second-fx2-serial-port-to-work</link><description> 
Hello, 

 
I have read all the info regarding how to get the 2nd serial port
to work with putchar (printf). I have updated the &amp;#39;PUTCHAR.C&amp;#39; file
like recommended by Keil: 

 
char putchar (char c) {
 while (!TI1);
 TI1 = 0;
 return (SBUF1 = c);
}
 
</description><dc:language>en-US</dc:language><generator>Telligent Community 10</generator><item><title>RE: How to get second FX2 serial port to work?</title><link>https://community.arm.com/thread/99174?ContentTypeID=1</link><pubDate>Tue, 01 May 2007 12:31:15 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:c565fc6b-2c93-488f-b42c-6907eb367c6a</guid><dc:creator>John Gulbrandsen</dc:creator><description>&lt;p&gt;&lt;p&gt;
The problem has now been sorted out. I this morning realized that
the MON51 connection is using SIO-1 and that the STDIO is using
SIO-0. This means that the Keil putchar routine should not be changed
(already uses the first serial port). The only thing that needs to be
done (not mentioned anywhere) is to set up the baudrate source for
the first UART to be timer 1 and to clear the TI and RI bits. My code
snipped below shows the working solution, i hope this can help
others.&lt;/p&gt;

&lt;p&gt;
NOTE that timer 1 should not be initialized when loading the
application into the FX2 board via Mon51 because the monitor already
initializes the timer.&lt;/p&gt;

&lt;pre&gt;
void main()
{
        unsigned long ul;

        // FX2 Serial port initialization:
        // Set up the first serial port so we can use it for the STDIO functions
        // (printf, putchar etc). NOTE that the second serial port (SIO-1) is
        // used by the Mon51 connection on the FX2 board while we use the first
        // serial port (SIO-0) for STDIO. Also note that if the monitor is in use
        // we don&amp;#39;t have to initialize timer 1 because it has already been done by
        // the monitor. All we have to do is to set up the first serial port to
        // use timer 1.
#ifndef MONITOR51
    TMOD |= 0x20;               /* TMOD: timer 1, mode 2, 8-bit reload        */
    TH1   = 236;                /* TH1:  reload value for 38400 baud @ 48MHz   */
    TR1   = 1;                  /* TR1:  timer 1 run                          */
#endif
    SCON0  = 0x53;                      /* SCON0: mode 1, 8-bit UART, enable rcvr, Clr TI, RI */

        while(1)
        {
                for(ul=0; ul&amp;lt;0xffff; ul++)
                {
                        printf(&amp;quot;Testing...&amp;quot;);
                }
        }
}
&lt;/pre&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to get second FX2 serial port to work?</title><link>https://community.arm.com/thread/75055?ContentTypeID=1</link><pubDate>Tue, 01 May 2007 11:16:27 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:0b887f90-a4eb-404f-8e2c-edf628cd6fe4</guid><dc:creator>John Gulbrandsen</dc:creator><description>&lt;p&gt;&lt;p&gt;
&amp;quot;But all your setup code for the 2nd UART is within a #ifndef
MONITOR51...&amp;quot;&lt;/p&gt;

&lt;p&gt;
No it is not. The second UART uses the same timer 1 for its
baudrate generation so it doesn&amp;#39;t need to be initialized again.
MONITOR51 is defined in the preprocessor so that snippet of code is
never executed.&lt;/p&gt;

&lt;p&gt;
The second UART shares timer 1 with the first UART. The MON51
monitor initializes timer 1 for the first UART so that a baudrate of
38400 N81 is being used. This works fine since i can connect and
debug with uVision3.&lt;/p&gt;

&lt;p&gt;
The assignment of SCON and TI1 IS however executed so the second
UART should work but does not. Something in the system causes TI1 to
always be cleared (even when explicitly set) and since i don&amp;#39;t have
the source code for MON51 i&amp;#39;m suspecting that MON51 somehow touches
the second serial port too!&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to get second FX2 serial port to work?</title><link>https://community.arm.com/thread/50683?ContentTypeID=1</link><pubDate>Tue, 01 May 2007 02:41:11 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:e88f7831-af1c-4f18-8eb9-89eaa6b6cf98</guid><dc:creator>Andy Neil</dc:creator><description>&lt;p&gt;&lt;p&gt;
&lt;i&gt;&amp;quot;i&amp;#39;m using Mon51&amp;quot;&lt;/i&gt;&lt;/p&gt;

&lt;p&gt;
But all your setup code for the 2nd UART is within a &lt;b&gt;#ifndef
MONITOR51&lt;/b&gt;...&lt;/p&gt;

&lt;pre&gt;
#ifndef MONITOR51 &lt;b&gt;// The following code is &lt;i&gt;disabled&lt;/i&gt; when MONITOR51 is defined!!&lt;/b&gt;
    SCON  = 0x50; /* SCON: mode 1, 8-bit UART, enable rcvr      */
    TMOD |= 0x20; /* TMOD: timer 1, mode 2, 8-bit reload        */
    TH1   = 221;  /* TH1:  reload value for 1200 baud @ 16MHz   */
    TR1   = 1;    /* TR1:  timer 1 run                          */
    TI    = 1;    /* TI:   set TI to send first char of UART    */
#endif
&lt;/pre&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>