博客
关于我
野火MINI_STM32_CubeMX_USAT1串口_printf重定向
阅读量:155 次
发布时间:2019-02-27

本文共 802 字,大约阅读时间需要 2 分钟。

使用了串口1进行开发。我的原理图如上所示,需要将A9和A10两个PIN通过跳转器连接。

初始化和创建项目均由STM32cubeMX生成。

项目配置

RCC配置

RCC(内核配置控制器)需要进行初步配置,以便于系统运行。

系统配置

完成RCC配置后,需要进一步配置系统相关参数。

串口配置

串口配置是开发过程中非常重要的一步。以下是串口配置的具体步骤:

克洛克配置

配置系统时钟(clk)的相关参数,以确保串口通信的稳定性。

项目配置

在STM32cubeMX中完成项目配置,包括硬件板、端口、定时器等设置。

main.c函数配置

函数申明

在main函数外增加函数申明,以便于在程序中使用这些函数。

/* USER CODE BEGIN 0 */#include 
#ifdef __GNUC__#define PUTCHAR_PROTOTYPE int __io_putchar(int ch)#else#define PUTCHAR_PROTOTYPE int fputc(int ch, FILE *f)#endifPUTCHAR_PROTOTYPE{ HAL_UART_Transmit(&huart1, (uint8_t *)&ch, 1, 0xFFFF); // 阻塞方式打印 return ch;}/* USER CODE END 0 */

数据处理

在while循环中增加数据处理代码,实现对接收数据的处理和发送功能。

while (1) {    uint8_t rh = 11;    printf("\n\r welcome to www.waveshere.com !!!\n\r");    printf("%d\r\n", rh);    HAL_Delay(5000);}

接收与发送功能

完成上述配置后,系统能够正常接收数据并将数据发送回去。

转载地址:http://kytd.baihongyu.com/

你可能感兴趣的文章
npm install digital envelope routines::unsupported解决方法
查看>>
npm install 卡着不动的解决方法
查看>>
npm install 报错 ERR_SOCKET_TIMEOUT 的解决方法
查看>>
npm install 报错 no such file or directory 的解决方法
查看>>
npm install报错,证书验证失败unable to get local issuer certificate
查看>>
npm install无法生成node_modules的解决方法
查看>>
npm install的--save和--save-dev使用说明
查看>>
npm node pm2相关问题
查看>>
npm run build 失败Compiler server unexpectedly exited with code: null and signal: SIGBUS
查看>>
npm run build报Cannot find module错误的解决方法
查看>>
npm run build部署到云服务器中的Nginx(图文配置)
查看>>
npm run dev 报错PS ‘vite‘ 不是内部或外部命令,也不是可运行的程序或批处理文件。
查看>>
npm scripts 使用指南
查看>>
npm should be run outside of the node repl, in your normal shell
查看>>
npm start运行了什么
查看>>
npm WARN deprecated core-js@2.6.12 core-js@<3.3 is no longer maintained and not recommended for usa
查看>>
npm 安装依赖过程中报错:Error: Can‘t find Python executable “python“, you can set the PYTHON env variable
查看>>
npm.taobao.org 淘宝 npm 镜像证书过期?这样解决!
查看>>
npm—小记
查看>>
npm介绍以及常用命令
查看>>