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

你可能感兴趣的文章
NO 157 去掉禅道访问地址中的zentao
查看>>
No Datastore Session bound to thread, and configuration does not allow creation of non-transactional
查看>>
No fallbackFactory instance of type class com.ruoyi---SpringCloud Alibaba_若依微服务框架改造---工作笔记005
查看>>
No Feign Client for loadBalancing defined. Did you forget to include spring-cloud-starter-loadbalanc
查看>>
No mapping found for HTTP request with URI [/...] in DispatcherServlet with name ...的解决方法
查看>>
No module named 'crispy_forms'等使用pycharm开发
查看>>
No module named cv2
查看>>
No module named tensorboard.main在安装tensorboardX的时候遇到的问题
查看>>
No module named ‘MySQLdb‘错误解决No module named ‘MySQLdb‘错误解决
查看>>
No new migrations found. Your system is up-to-date.
查看>>
No qualifying bean of type XXX found for dependency XXX.
查看>>
No resource identifier found for attribute 'srcCompat' in package的解决办法
查看>>
no session found for current thread
查看>>
No toolchains found in the NDK toolchains folder for ABI with prefix: mips64el-linux-android
查看>>
NO.23 ZenTaoPHP目录结构
查看>>
NO32 网络层次及OSI7层模型--TCP三次握手四次断开--子网划分
查看>>
NoClassDefFoundError: org/springframework/boot/context/properties/ConfigurationBeanFactoryMetadata
查看>>
Node JS: < 一> 初识Node JS
查看>>
Node-RED中使用JSON数据建立web网站
查看>>
Node-RED中使用json节点解析JSON数据
查看>>