uart1里前面不知道为什么会多出一个,代码使用的是如下
1. Define HAL_UART=TRUE, HAL_UART_ISR=1, and HAL_UART_DMA=2 in compile options.
2. Initialize and use UART0 (P0_2 as RX/P0_3 as TX) as the followings: void initUart0(halUARTCBack_t pf)
{
halUARTCfg_t uartConfig;
uartConfig.configured = TRUE;
uartConfig.baudRate = HAL_UART_BR_115200;
uartConfig.flowControl = FALSE;
uartConfig.flowControlThreshold = 48;
uartConfig.rx.maxBufSize = 128;
uartConfig.tx.maxBufSize = 128;
uartConfig.idleTimeout = 6; uartConfig.intEnable = TRUE; uartConfig.callBackFunc = pf;
HalUARTOpen (HAL_UART_PORT_0, &uartConfig);
}
void uart0RxCb( uint8 port, uint8 event )
{
uint8 ch;
while (Hal_UART_RxBufLen(port))
{
// Read one byte from UART to ch
HalUARTRead (port, &ch, 1);
}
}
initUart0(uart0RxCb);
//Output "UART0 output test" to P0.3
HalUARTWrite( HAL_UART_PORT_0, "UART0 output test", (byte)osal_strlen("UART0 output test"));
3. Initialize and use UART1 (P1_6 as TX/P1_7 as RX) as the followings: void initUart1(halUARTCBack_t pf)
{
halUARTCfg_t uartConfig;
uartConfig.configured = TRUE;
uartConfig.baudRate = HAL_UART_BR_115200;
uartConfig.flowControl = FALSE;
uartConfig.flowControlThreshold = 48;
uartConfig.rx.maxBufSize = 128;
uartConfig.tx.maxBufSize = 128;
uartConfig.idleTimeout = 6; uartConfig.intEnable = TRUE; uartConfig.callBackFunc = pf;
HalUARTOpen (HAL_UART_PORT_1, &uartConfig);
}
void uart1RxCb( uint8 port, uint8 event )
{
uint8 ch;
while (Hal_UART_RxBufLen(port))
{
// Read one byte from UART to ch
HalUARTRead (port, &ch, 1);
}
}
initUart1(uart0RxCb);
//Output "UART1 output test" to P1.6
HalUARTWrite( HAL_UART_PORT_1, "UART1 output test", (byte)osal_strlen("UART1 output test"));
user5358070:
Viki Shi:
请参考这边的类似贴,给出了代码:e2echina.ti.com/…/526637