(一)串口通信介绍
串行接口是一种可以将接收来自CPU的并行数据字符转换为连续的串行数据流发送出去,同时可将接收的串行数据流转换为并行的数据字符供给CPU的器件。一般完成这种功能的电路,我们称为串行接口电路。
串口通信(Serial Communications)的概念非常简单,串口按位(bit)发送和接收字节的通信方式。
(二)使用CubeMX进行配置
打开STM32CubeMX,选择新建项目
芯片这里选择STM32F103C8T6
创建后对SYS进行配置,选择Serial Wire
对RCC进行配置,选择Crydtal/Ceramic Resonator
对USART进行配置,选择Asynchronous
设置NVIC
创建项目
(三)编写代码(发送“hello world”)
打开keil5软件,将刚刚创建的项目主函数改成下面代码
#include "main.h"
#include "usart.h"
#include "gpio.h"
#include <string.h>
void SystemClock_Config(void);
char c;//指令 0:停止 1:开始
char message[]="hello Windows\n";//输出信息
char tips[]="CommandError\n";//提示1
char tips1[]="Start.....\n";//提示2
char tips2[