主题 : mini2440串口3使用问题 复制链接 | 浏览器收藏 | 打印
积极向上
级别: 新手上路
UID: 106175
精华: 0
发帖: 3
金钱: 15 两
威望: 3 点
贡献值: 0 点
综合积分: 6 分
注册时间: 2014-07-16
最后登录: 2014-07-19
楼主  发表于: 2014-07-16 19:44

 mini2440串口3使用问题

我碰到的问题是串口3无法同外部设备通信,串口3的波特率设置为115200bps,8位数据位,1位停止位,无校验位。串口3相关寄存器的初始化程序为:
void Uart_Init(int pclk,int baud)
{
    int i;
    if(pclk == 0)
    pclk    = PCLK;
    rUFCON0 = 0x0;   //UART channel 0 FIFO control register, FIFO disable
    rUFCON1 = 0x0;   //UART channel 1 FIFO control register, FIFO disable
    rUFCON2 = 0x0;   //UART channel 2 FIFO control register, FIFO disable
    rUMCON0 = 0x0;   //UART chaneel 0 MODEM control register, AFC disable
    rUMCON1 = 0x0;   //UART chaneel 1 MODEM control register, AFC disable
//UART0
    rULCON0 = 0x3;   //Line control register : Normal,No parity,1 stop,8 bits
     //    [10]       [9]     [8]        [7]        [6]      [5]         [4]           [3:2]        [1:0]
     // Clock Sel,  Tx Int,  Rx Int, Rx Time Out, Rx err, Loop-back, Send break,  Transmit Mode, Receive Mode
     //     0          1       0    ,     0          1        0           0     ,       01          01
     //   PCLK       Level    Pulse    Disable    Generate  Normal      Normal        Interrupt or Polling
    rUCON0  = 0x245;   // Control register
    rUBRDIV0=( (int)(pclk/16./baud+0.5) -1 );   //Baud rate divisior register 0
//UART1
    rULCON1 = 0x3;
    rUCON1  = 0x245;
    rUBRDIV1=( (int)(pclk/16./baud+0.5) -1 );
//UART2
    rULCON2 = 0x3;
    rUCON2  = 0x245;
    rUBRDIV2=( (int)(pclk/16./baud+0.5) -1 );    

    for(i=0;i<100;i++);
}
接受字符的子程序为:
char Uart_Getch(void)
{
    if(whichUart==0)
    {      
        while(!(rUTRSTAT0 & 0x1)); //Receive data ready
        return RdURXH0();
    }
    else if(whichUart==1)
    {      
        while(!(rUTRSTAT1 & 0x1)); //Receive data ready
        return RdURXH1();
    }
    else if(whichUart==2)
    {
        while(!(rUTRSTAT2 & 0x1)); //Receive data ready
        return RdURXH2();
    }
    
    return 0 ;
}
发送字符的子程序为:
void Uart_SendByte(int data)
{
    if(whichUart==0)
    {
        if(data==\'\\n\')
        {
            while(!(rUTRSTAT0 & 0x2));
           // Delay(1);                 //because the slow response of hyper_terminal
            WrUTXH0(\'\\r\');
        }
        while(!(rUTRSTAT0 & 0x2));   //Wait until THR is empty.
      //  Delay(1);
        WrUTXH0(data);
    }
    else if(whichUart==1)
    {
        if(data==\'\\n\')
        {
            while(!(rUTRSTAT1 & 0x2));
            //Delay(1);                 //because the slow response of hyper_terminal
            rUTXH1 = \'\\r\';
        }
        while(!(rUTRSTAT1 & 0x2));   //Wait until THR is empty.
        //Delay(1);
        rUTXH1 = data;
    }  
    else if(whichUart==2)
    {
        if(data==\'\\n\')
        {
            while(!(rUTRSTAT2 & 0x2));
            //Delay(1);                 //because the slow response of hyper_terminal
            rUTXH2 = \'\\r\';
        }
        while(!(rUTRSTAT2 & 0x2));   //Wait until THR is empty.
        //Delay(1);
        rUTXH2 = data;
    }      
}              

我使用的测试程序为:
Uart_Init( 0,115200 );
while(1)
    {
        Uart_Select(2);
        Uart_SendByte(\'1\');
        c=Uart_Getch();
        Uart_Printf(\"%c\\n\",c);
    }

我使用USB转串口线将串口和pc相连,在pc上使用串口助手同串口通信。当我选择串口3时,串口助手无法向串口3发送数据也无法接受到来自串口3的数据。当我将串口3换成串口2时,串口2和串口助手之间可以通信。同时,我将linux系统烧进开发板,使用提供的串口助手进行调试,串口3可以正常工作,可以排除硬件的问题。我觉得有可能是寄存器初始化出现错误,查看了s3c2440的芯片手册,没有找到相关的内容,各位大神帮忙看下问题在哪?
级别: 新手上路
UID: 108372
精华: 0
发帖: 3
金钱: 15 两
威望: 3 点
贡献值: 0 点
综合积分: 6 分
注册时间: 2014-09-23
最后登录: 2015-03-31
1楼  发表于: 2014-09-23 20:44
我遇到的问题是只能使用uart0,而使用不了uart1、uart2.不知道是为什么。