博客
关于我
野火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/

你可能感兴趣的文章
np.arange()和np.linspace()绘制logistic回归图像时得到不同的结果?
查看>>
np.power的使用
查看>>
NPM 2FA双重认证的设置方法
查看>>
npm build报错Cannot find module ‘webpack/lib/rules/BasicEffectRulePlugin‘解决方法
查看>>
npm build报错Cannot find module ‘webpack‘解决方法
查看>>
npm ERR! ERESOLVE could not resolve报错
查看>>
npm ERR! fatal: unable to connect to github.com:
查看>>
npm ERR! Unexpected end of JSON input while parsing near '...on":"0.10.3","direc to'
查看>>
npm ERR! Unexpected end of JSON input while parsing near ‘...“:“^1.2.0“,“vue-html-‘ npm ERR! A comp
查看>>
npm error Missing script: “server“npm errornpm error Did you mean this?npm error npm run serve
查看>>
npm error MSB3428: 未能加载 Visual C++ 组件“VCBuild.exe”。要解决此问题,1) 安装
查看>>
npm install CERT_HAS_EXPIRED解决方法
查看>>
npm install digital envelope routines::unsupported解决方法
查看>>
npm install 卡着不动的解决方法
查看>>
npm install 报错 EEXIST File exists 的解决方法
查看>>
npm install 报错 ERR_SOCKET_TIMEOUT 的解决方法
查看>>
npm install 报错 Failed to connect to github.com port 443 的解决方法
查看>>
npm install 报错 fatal: unable to connect to github.com 的解决方法
查看>>
npm install 报错 no such file or directory 的解决方法
查看>>
npm install 权限问题
查看>>