打印

多个uart初始化,但是只有uart0可以用,我的程序有问题吗?

[复制链接]
3635|6
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
rainbow99|  楼主 | 2011-8-25 09:10 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
UART0, pi, se, TE, IO
我在uart_echo例程基础上增加了uart1,但是uart1没法使用,只有uart0可以用。以下是我的程序,看看有问题不?
    //
    // Enable the (non-GPIO) peripherals used by this example.  PinoutSet()
    // already enabled GPIO Port A.
    //
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
SysCtlPeripheralEnable(SYSCTL_PERIPH_UART1);
    //
    // Enable processor interrupts.
    //
    IntMasterEnable();
    //
    // Set GPIO A0 and A1 as UART pins.
    //
    GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);
GPIOPinTypeUART(GPIO_PORTD_BASE, GPIO_PIN_2 | GPIO_PIN_3);
    //
    // Configure the UART for 115,200, 8-N-1 operation.
    //
    UARTConfigSetExpClk(UART0_BASE, SysCtlClockGet(), 115200,
                            (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE |
                             UART_CONFIG_PAR_NONE));
UARTConfigSetExpClk(UART1_BASE, SysCtlClockGet(), 115200,
                            (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE |
                             UART_CONFIG_PAR_NONE));
    //
    // Enable the UART interrupt.
    //
    IntEnable(INT_UART0);
    UARTIntEnable(UART0_BASE, UART_INT_RX | UART_INT_RT);
IntEnable(INT_UART1);
    UARTIntEnable(UART1_BASE, UART_INT_RX | UART_INT_RT);
以上是主程序中的初始化。

以下是UART1的中断程序:
void UART1IntHandler(void)
{
    unsigned long ulStatus;
    //
    // Get the interrrupt status.
    //
    ulStatus = UARTIntStatus(UART1_BASE, true);
    //
    // Clear the asserted interrupts.
    //
    UARTIntClear(UART1_BASE, ulStatus);
    //
    // Loop while there are characters in the receive FIFO.
    //
    while(UARTCharsAvail(UART1_BASE))
    {
        //
        // Read the next character from the UART and write it back to the UART.
        //
        UARTCharPutNonBlocking(UART1_BASE,
                                   UARTCharGetNonBlocking(UART1_BASE));
    }
}

相关帖子

沙发
永远的不知| | 2011-8-25 09:11 | 只看该作者
请参考下面的程序,将PD2,PD3增加下面的两条管脚复用功能设置,由于9000等tempest系列的IO复用功能很多,所以需要配置,因为PA0和PA1默认的复用功能为uart0,所以不加这两条指令uart0可以正常使用,但其他的PD2,PD3默认复用功能并不是uart,所以必须设置。

    //
    // Configure the GPIO pin muxing for the UART function.
    // This is only necessary if your part supports GPIO pin function muxing.
    // Study the data sheet to see which functions are allocated per pin.
    // TODO: change this to select the port/pin you are using
    //
    GPIOPinConfigure(GPIO_PA0_U0RX);
    GPIOPinConfigure(GPIO_PA1_U0TX);

使用特权

评论回复
板凳
永远的不知| | 2011-8-25 09:13 | 只看该作者
GPIOPinConfigure()是设定io口的复用功能,tempest由于有多个复用功能,所以必须加这个函数;
GPIOPinTypeUART,这个函数只是起到了将IO口切换到复用功能的作用,具体是哪个复用功能,由GPIOPinConfigure决定;
这里的复用功能指的是数字部分,如果是模拟的,比如ADC,则不需要加GPIOPinConfigure,因为模拟部分功能没有复用。

使用特权

评论回复
地板
rainbow99|  楼主 | 2011-8-25 09:16 | 只看该作者
我刚试过,可以了,太感谢了,多谢不知兄指点。

使用特权

评论回复
5
永远的不知| | 2011-8-25 09:18 | 只看该作者
4# rainbow99

不客气,最好把uart0也加上该语句,这样不容易出错,可移植性更强;其他外设也一样的。

使用特权

评论回复
6
sqcumt123| | 2011-8-25 12:52 | 只看该作者
一起学习

使用特权

评论回复
7
lilihua0721| | 2011-10-9 07:13 | 只看该作者
GPIOPinConfigure()是设定io口的复用功能, 这个函数在功能复用是记得使用!

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

0

主题

54

帖子

1

粉丝