1.使用LPC1765芯片.
2.串口使用代码如下:
- //UART1配置
- void UART1_Config(void)
- {
- UART_CFG_Type UARTConfigStruct; // UART配置结构变量
- UART_FIFO_CFG_Type UARTFIFOConfigStruct;// UART FIFO配置结构变量
- PINSEL_CFG_Type PinCfg; // UART2 引脚配置
-
- //初始化UART1 引脚
- //p2.0:TXD1, p2.1:RXD1
- PinCfg.Funcnum = 2;
- PinCfg.OpenDrain = 0;
- PinCfg.Pinmode = 0;
- PinCfg.Pinnum = 0;
- PinCfg.Portnum = 2;
- PINSEL_ConfigPin(&PinCfg);
- PinCfg.Pinnum = 1;
- PINSEL_ConfigPin(&PinCfg);
-
- /* UART2 配置参数:
- * Baudrate = 9600bps
- * 8 data bit
- * 1 Stop bit
- * None parity
- */
- UART_ConfigStructInit(&UARTConfigStruct);
- UART_Init(TEST_UART, &UARTConfigStruct);
- //初始化UART2并设置相应的参数
- /* 初始化FIFOConfigStruct默认状态:
- * - FIFO_DMAMode = DISABLE
- * - FIFO_Level = UART_FIFO_TRGLEV0
- * - FIFO_ResetRxBuf = ENABLE
- * - FIFO_ResetTxBuf = ENABLE
- * - FIFO_State = ENABLE
- */
- UART_FIFOConfigStructInit(&UARTFIFOConfigStruct);
- UART_FIFOConfig(TEST_UART, &UARTFIFOConfigStruct); //初始化UART2 FIFO并设置相应的参数
-
- // 使能串口发送
- UART_TxCmd(TEST_UART, ENABLE);
- }
- int main(void)
- {
- UART1_Config(); //配置串口1
- while (1)
- {
- UART_Send(TEST_UART, testStr1, sizeof(testStr1), BLOCKING); //阻塞的方式,发送测试字符串口,
- //Delay(100); //延迟100ms
- UART_Send(TEST_UART, testStr2, sizeof(testStr2), BLOCKING);
- Delay(1000); //延迟1秒
- }
- }
打印输出:
Hello NXP Semiconductors
UART hardware flow control mode demo
Hello NXP Semiconductors
ART hardware flow control mode demo
Hello NXP Semiconductors
ART hardware flow control mode demo
看到在输出第二句字符:'UART hardware flow control mode demo ',会丢失字符'U'。
我尝试给其一个延时发现能够解决问题,但是为什么不加延时它会丢失字符呢??
UART_Send()我特意选择使用阻塞方式发送的,为什么还会这样。
|