先看看uart特性:1. 全双工,标准非归零格式
2. 支持DMA传输数据
3. 可编程8或9位数据长度,1或2位停止位,硬件自动生成奇偶校验位
4. 可选择传输器输出和接收器输入极性
5. 支持硬件流控制
6. 支持传输器输出和接收器输入极性
7. 轮询或中断方式查询状态
8. 可生成13位分隔符,可选10或11位LIN功能分隔符检测
9. 支持RS485自动控制方向
对应的初始化代码:
- void InitDebug(void)
- {
- #ifdef ITM_DEBUG_OUT
- #else
- GPIO_SetFunc(49, 1);
- GPIO_SetFunc(50, 1);
- CKGEN_Enable(DEBUG_UART_CLK, 1);
- CKGEN_SoftReset(DEBUG_UART_SRST, 1);
- UART_SetDivisor(DEBUG_UART, APB_BUS_FREQ / 16.0 / 115200); //apbbus: 48M
- UART_SetDataBits(DEBUG_UART, 8);
- UART_SetStopBit(DEBUG_UART, 1);
- UART_EnableTX(DEBUG_UART, 1);
- UART_EnableRX(DEBUG_UART, 1);
- UART_Set2ByteFIFO(DEBUG_UART, 1);
- UART_SetIntEn(DEBUG_UART, 9);
- #endif
- s_debugInit = 1;
- }
如果要使用printf函数,则需要重定向串口:
- /**
- * @param[in] f: file pointer for the std input
- * @param[in] ch: the char to put
- * [url=home.php?mod=space&uid=266161]@return[/url] return the char of be put
- *
- * [url=home.php?mod=space&uid=247401]@brief[/url] put a char to UART
- */
- int fputc(int ch, FILE *f)
- {
- if (s_debugInit)
- {
- UART_SendData(DEBUG_UART, ch);
- }
- return ch;
- }
很简单,主循环中闪灯和打印字符串即可:
完美!
|