[demo程序] NV32F100FL64E之UART环回模式测试代码

[复制链接]
 楼主| 詹求实 发表于 2020-6-27 10:51 | 显示全部楼层 |阅读模式
  1. #include "common.h"
  2. #include "rtc.h"
  3. #include "uart.h"
  4. #include "uart_app.h"
  5. #include "sysinit.h"

  6. #define SEND_BUF_LEN    1
  7. #define RECEIVE_BUF_LEN 1

  8. uint8_t send_buf[SEND_BUF_LEN] = {'L'};
  9. uint8_t receive_buf[RECEIVE_BUF_LEN] = {0};

  10. /******************************************************************************/
  11. int main (void)
  12. {       
  13.     UART_ConfigType sConfig;

  14.     /*执行系统初始化*/
  15.     sysinit();
  16.     sConfig.u32SysClkHz = BUS_CLK_HZ;//选择系统时钟
  17.     sConfig.u32Baudrate = 115200;//配置波特率为115200

  18.     LED0_Init();//初始化 LED
  19.     printf("\nRunning the UART_Loopback_demo project.\r\n");  
  20.     printf("\nEnter any character to echo...\r\n");
  21.     UART_WaitTxComplete(UART1);//等待串口1发送完成
  22.    
  23.     UART_Init(UART3,&sConfig);//初始化串口3
  24.     UART_EnableLoopback(UART3);//开启串口3环回,设定UART3为循环模式
  25.     UART_SetCallback(UART_HandleInt);       

  26.     /* 禁用串口 1 收发中断 */
  27.     UART_DisableInterrupt(TERM_PORT, UART_RxBuffFullInt);
  28.     UART_DisableInterrupt(TERM_PORT, UART_TxBuffEmptyInt);
  29.     /* 使能串口 1 接收溢出中断 */
  30.     UART_EnableInterrupt(UART1, UART_RxOverrunInt);
  31.     NVIC_EnableIRQ(UART1_IRQn);//打开串口1中断
  32.      
  33.     while (1)
  34.     {
  35.         send_buf[0] = UART_GetChar(TERM_PORT); //获取串口1上的字符,存放到发送缓冲区
  36.         UART_SendWait(UART3, send_buf, 1);  //发送缓冲区字符到UART3口
  37.         UART_ReceiveWait(UART3, receive_buf, 1);//把UART3的内容放入接收缓冲区中
  38.         UART_PutChar(TERM_PORT, receive_buf[0]);//接收缓冲区的数据放入 UART1 口的数据寄存器   
  39.     }
  40. }



coshi 发表于 2020-7-6 17:27 | 显示全部楼层
非常感谢楼主分享
zljiu 发表于 2020-7-6 17:28 | 显示全部楼层
环回模式是什么模式呀
wiba 发表于 2020-7-6 17:28 | 显示全部楼层
最少需要多少延时
您需要登录后才可以回帖 登录 | 注册

本版积分规则

13

主题

135

帖子

0

粉丝
快速回复 在线客服 返回列表 返回顶部

13

主题

135

帖子

0

粉丝
快速回复 在线客服 返回列表 返回顶部