【STM32F767】一、串口3的初始化及使用

1.CUBEMx配置串口的IO口

选择USART3并配置为Asynchronous 

配置IO口

设置时钟为216MHz

配置时钟

串口设置为8位数据,1位停止位


串口设置

2.生成代码,并添加串口重定向程序,以便使用printf


串口重定向

3.实验成功


实验

串口重定向代码如下

/*-----------------串口重定向 使用printf输出---------------*/

#ifdef __GNUC__

/* With GCC/RAISONANCE, small printf (option LD Linker->Libraries->Small printf

set to 'Yes') calls __io_putchar() */

#define PUTCHAR_PROTOTYPE int __io_putchar(int ch)

#else

#define PUTCHAR_PROTOTYPE int fputc(int ch, FILE *f)

#endif /* __GNUC__ */

/**

* @brief Retargets the C library printf function to the USART.

* @param None

* @retval None

*/

PUTCHAR_PROTOTYPE

{

  /* Place your implementation of fputc here */

  /* e.g. write a character to the EVAL_COM1 and Loop until the end of transmission */

  HAL_UART_Transmit(&huart3, (uint8_t *)&ch, 1, 0x0001);

  return ch;

}

/*-----------------------------------------------------------*/

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容