[活动专区] 【AutoChips MCU评测报告】+Hello,AutoChips!

[复制链接]
789|1
 楼主| caizhiwei 发表于 2020-5-31 15:55 | 显示全部楼层 |阅读模式
先看看uart特性:1.        全双工,标准非归零格式
2.        支持DMA传输数据
3.        可编程8或9位数据长度,1或2位停止位,硬件自动生成奇偶校验位
4.        可选择传输器输出和接收器输入极性
5.        支持硬件流控制
6.        支持传输器输出和接收器输入极性
7.        轮询或中断方式查询状态
8.        可生成13位分隔符,可选10或11位LIN功能分隔符检测
9.        支持RS485自动控制方向


对应的初始化代码:
  1. void InitDebug(void)
  2. {
  3. #ifdef ITM_DEBUG_OUT
  4. #else

  5.     GPIO_SetFunc(49, 1);
  6.     GPIO_SetFunc(50, 1);
  7.     CKGEN_Enable(DEBUG_UART_CLK, 1);
  8.     CKGEN_SoftReset(DEBUG_UART_SRST, 1);

  9.     UART_SetDivisor(DEBUG_UART, APB_BUS_FREQ / 16.0 / 115200); //apbbus: 48M

  10.     UART_SetDataBits(DEBUG_UART, 8);
  11.     UART_SetStopBit(DEBUG_UART, 1);
  12.     UART_EnableTX(DEBUG_UART, 1);
  13.     UART_EnableRX(DEBUG_UART, 1);
  14.     UART_Set2ByteFIFO(DEBUG_UART, 1);

  15.     UART_SetIntEn(DEBUG_UART, 9);
  16. #endif

  17.     s_debugInit = 1;
  18. }
如果要使用printf函数,则需要重定向串口:
  1. /**
  2. * @param[in]  f:  file pointer for the std input
  3. * @param[in]  ch: the char to put
  4. * [url=home.php?mod=space&uid=266161]@return[/url] return the char of be put
  5. *
  6. * [url=home.php?mod=space&uid=247401]@brief[/url]  put a char to UART
  7. */
  8. int fputc(int ch, FILE *f)
  9. {
  10.     if (s_debugInit)
  11.     {
  12.         UART_SendData(DEBUG_UART, ch);
  13.     }
  14.     return ch;
  15. }
很简单,主循环中闪灯和打印字符串即可:
auto获.PNG
完美!

 楼主| caizhiwei 发表于 2020-5-31 16:19 | 显示全部楼层
demo.rar (46.23 KB, 下载次数: 2)
附上工程代码,方便有需要的人。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

100

主题

856

帖子

16

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