1 介绍
大家从标题中来看呢,大家可能会有些困惑,MPU6050只输出加速度、陀螺仪。没有角度。这个也是我今天想和大家说的。最近我做了一个倾角项目。老板基于成本考虑希望我能用MPU6050去算出来角度。说实话自己没接触这个东西,去搞的时候才知道挺难的,很地方看不懂。然后我去看过了正电原子的MPU6050的解算。但是那个角度的结果和我想要精度有点差别。无意中呢在淘宝上搜到了一个维特智能的JY61模块。这个模块的内置的就是MPU6050模块。这个商家说它的静态角度的精度为0.05度、动态0.1度。这个精度是很符合我的需求。给大家看下这个模块
这个模块体积很小巧就15×15×2mm大小。串口通讯用单片机去获取数据很简单,相比起直接去获取MPU6050简单不知道多少倍了。下面和大家说说我是怎么去用STM32F103读取JY62陀螺仪、加速度、角度的数据。
2 开发准备
讲程序之前呢,和大家简单的说说一些硬件、软件准备和JY61怎么和STM32F103接线的。
2.1硬件、软件准备
硬件:JY61模块、USB-TTL、STM32F103开发板、杜邦线。
软件 :https://pan.baidu.com/s/1SEWmixu4jtUL2HH_3Hcn2g 提取码:zryo
这个是我的写的一个 示例代码大家有兴趣的可以看下:https://pan.baidu.com/s/1sXnlT89FTTs5tONLiaPihw
2.2 接线方式
1、使用USB-TTL将STM32F103C8T6与电脑连接通信
2、JY61与STM32F103C8T6使用杜邦线连接。具体接线如下图所示:
具体接线方式如下:
USB-TTL---------------STM32F103C8T6---------------JY61
VCC-------------- VCC -------------------------VCC
TX-------------------RX1(PA10),PA3---------------------------TX
RX-------------------TX1(PA9),PA2----------------------------RX
GND------------------GND, GND----------------------------GND
3 程序讲解
3.1程序思路讲解
好了到大家最关心的地方了。在这里呢。我先和大家说下。我的整体思路是什么。我直接把我们的main.c函数放在下面给大家看下。
[backcolor=inherit !important]#[backcolor=inherit !important]include[backcolor=inherit !important] [backcolor=inherit !important]<string.h>[backcolor=inherit !important]#[backcolor=inherit !important]include[backcolor=inherit !important] [backcolor=inherit !important]<stdio.h>[backcolor=inherit !important]#[backcolor=inherit !important]include[backcolor=inherit !important] [backcolor=inherit !important]"Main.h"[backcolor=inherit !important]#[backcolor=inherit !important]include[backcolor=inherit !important] [backcolor=inherit !important]"UART1.h"[backcolor=inherit !important]#[backcolor=inherit !important]include[backcolor=inherit !important] [backcolor=inherit !important]"UART2.h"[backcolor=inherit !important]#[backcolor=inherit !important]include[backcolor=inherit !important] [backcolor=inherit !important]"delay.h"[backcolor=inherit !important]#[backcolor=inherit !important]include[backcolor=inherit !important] [backcolor=inherit !important]"JY61.h"[backcolor=inherit !important]#[backcolor=inherit !important]include[backcolor=inherit !important] [backcolor=inherit !important]"DIO.h"[backcolor=inherit !important]struct [backcolor=inherit !important]SAcc stcAcc[backcolor=inherit !important];[backcolor=inherit !important]struct [backcolor=inherit !important]SGyro stcGyro[backcolor=inherit !important];[backcolor=inherit !important]struct [backcolor=inherit !important]SAngle stcAngle[backcolor=inherit !important];[backcolor=inherit !important]//CopeSerialData为串口2中断调用函数,串口每收到一个数据,调用一次这个函数。[backcolor=inherit !important]void [backcolor=inherit !important]CopeSerial2Data[backcolor=inherit !important]([backcolor=inherit !important]unsigned [backcolor=inherit !important]char ucData[backcolor=inherit !important])[backcolor=inherit !important]{ [backcolor=inherit !important]static [backcolor=inherit !important]unsigned [backcolor=inherit !important]char ucRxBuffer[backcolor=inherit !important][[backcolor=inherit !important]250[backcolor=inherit !important]][backcolor=inherit !important]; [backcolor=inherit !important]static [backcolor=inherit !important]unsigned [backcolor=inherit !important]char ucRxCnt = [backcolor=inherit !important]0[backcolor=inherit !important]; [backcolor=inherit !important]LED_REVERSE[backcolor=inherit !important]([backcolor=inherit !important])[backcolor=inherit !important]; [backcolor=inherit !important]//接收到数据,LED灯闪烁一下 ucRxBuffer[backcolor=inherit !important][ucRxCnt++[backcolor=inherit !important]]=ucData[backcolor=inherit !important]; [backcolor=inherit !important]//将收到的数据存入缓冲区中 [backcolor=inherit !important]if [backcolor=inherit !important](ucRxBuffer[backcolor=inherit !important][[backcolor=inherit !important]0[backcolor=inherit !important]]!=[backcolor=inherit !important]0x55[backcolor=inherit !important]) [backcolor=inherit !important]//数据头不对,则重新开始寻找0x55数据头 [backcolor=inherit !important]{ ucRxCnt=[backcolor=inherit !important]0[backcolor=inherit !important]; [backcolor=inherit !important]return[backcolor=inherit !important]; [backcolor=inherit !important]} [backcolor=inherit !important]if [backcolor=inherit !important](ucRxCnt<[backcolor=inherit !important]11[backcolor=inherit !important]) [backcolor=inherit !important]{[backcolor=inherit !important]return[backcolor=inherit !important];[backcolor=inherit !important]}[backcolor=inherit !important]//数据不满11个,则返回 [backcolor=inherit !important]else [backcolor=inherit !important]{ [backcolor=inherit !important]switch[backcolor=inherit !important](ucRxBuffer[backcolor=inherit !important][[backcolor=inherit !important]1[backcolor=inherit !important]][backcolor=inherit !important])[backcolor=inherit !important]//判断数据是哪种数据,然后将其拷贝到对应的结构体中,有些数据包需要通过上位机打开对应的输出后,才能接收到这个数据包的数据 [backcolor=inherit !important]{ [backcolor=inherit !important]//memcpy为编译器自带的内存拷贝函数,需引用"string.h",将接收缓冲区的字符拷贝到数据结构体里面,从而实现数据的解析。 [backcolor=inherit !important]case [backcolor=inherit !important]0x51: [backcolor=inherit !important]memcpy[backcolor=inherit !important](&stcAcc[backcolor=inherit !important],&ucRxBuffer[backcolor=inherit !important][[backcolor=inherit !important]2[backcolor=inherit !important]][backcolor=inherit !important],[backcolor=inherit !important]8[backcolor=inherit !important])[backcolor=inherit !important];[backcolor=inherit !important]break[backcolor=inherit !important]; [backcolor=inherit !important]case [backcolor=inherit !important]0x52: [backcolor=inherit !important]memcpy[backcolor=inherit !important](&stcGyro[backcolor=inherit !important],&ucRxBuffer[backcolor=inherit !important][[backcolor=inherit !important]2[backcolor=inherit !important]][backcolor=inherit !important],[backcolor=inherit !important]8[backcolor=inherit !important])[backcolor=inherit !important];[backcolor=inherit !important]break[backcolor=inherit !important]; [backcolor=inherit !important]case [backcolor=inherit !important]0x53: [backcolor=inherit !important]memcpy[backcolor=inherit !important](&stcAngle[backcolor=inherit !important],&ucRxBuffer[backcolor=inherit !important][[backcolor=inherit !important]2[backcolor=inherit !important]][backcolor=inherit !important],[backcolor=inherit !important]8[backcolor=inherit !important])[backcolor=inherit !important];[backcolor=inherit !important]break[backcolor=inherit !important]; [backcolor=inherit !important]} ucRxCnt=[backcolor=inherit !important]0[backcolor=inherit !important];[backcolor=inherit !important]//清空缓存区 [backcolor=inherit !important]}[backcolor=inherit !important]}[backcolor=inherit !important]void [backcolor=inherit !important]CopeSerial1Data[backcolor=inherit !important]([backcolor=inherit !important]unsigned [backcolor=inherit !important]char ucData[backcolor=inherit !important])[backcolor=inherit !important]{ [backcolor=inherit !important]UART2_Put_Char[backcolor=inherit !important](ucData[backcolor=inherit !important])[backcolor=inherit !important];[backcolor=inherit !important]//转发串口1收到的数据给串口2(JY模块)[backcolor=inherit !important]}[backcolor=inherit !important]int [backcolor=inherit !important]main[backcolor=inherit !important]([backcolor=inherit !important]void[backcolor=inherit !important])[backcolor=inherit !important]{ [backcolor=inherit !important]unsigned [backcolor=inherit !important]char i = [backcolor=inherit !important]0[backcolor=inherit !important]; [backcolor=inherit !important]SysTick_init[backcolor=inherit !important]([backcolor=inherit !important]72[backcolor=inherit !important],[backcolor=inherit !important]10[backcolor=inherit !important])[backcolor=inherit !important];[backcolor=inherit !important]//设置时钟频率 [backcolor=inherit !important]Initial_UART1[backcolor=inherit !important]([backcolor=inherit !important]9600[backcolor=inherit !important])[backcolor=inherit !important];[backcolor=inherit !important]//接PC的串口 [backcolor=inherit !important]Initial_UART2[backcolor=inherit !important]([backcolor=inherit !important]115200[backcolor=inherit !important])[backcolor=inherit !important];[backcolor=inherit !important]//接JY61模块的串口 [backcolor=inherit !important]LED_ON[backcolor=inherit !important]([backcolor=inherit !important])[backcolor=inherit !important]; [backcolor=inherit !important]delay_ms[backcolor=inherit !important]([backcolor=inherit !important]1000[backcolor=inherit !important])[backcolor=inherit !important];[backcolor=inherit !important]delay_ms[backcolor=inherit !important]([backcolor=inherit !important]1000[backcolor=inherit !important])[backcolor=inherit !important];[backcolor=inherit !important]//等等JY61初始化完成 [backcolor=inherit !important]while[backcolor=inherit !important]([backcolor=inherit !important]1[backcolor=inherit !important]) [backcolor=inherit !important]{ [backcolor=inherit !important]delay_ms[backcolor=inherit !important]([backcolor=inherit !important]1000[backcolor=inherit !important])[backcolor=inherit !important]; [backcolor=inherit !important]//串口接受到的数据已经拷贝到对应的结构体的变量中了,根据说明书的协议,以加速度为例 stcAcc.a[0]/32768*16就是X轴的加速度, [backcolor=inherit !important]printf[backcolor=inherit !important]([backcolor=inherit !important]"Acc:%.3f %.3f %.3f\r\n"[backcolor=inherit !important],[backcolor=inherit !important]([backcolor=inherit !important]float[backcolor=inherit !important])stcAcc[backcolor=inherit !important].a[backcolor=inherit !important][[backcolor=inherit !important]0[backcolor=inherit !important]]/[backcolor=inherit !important]32768*[backcolor=inherit !important]16[backcolor=inherit !important],[backcolor=inherit !important]([backcolor=inherit !important]float[backcolor=inherit !important])stcAcc[backcolor=inherit !important].a[backcolor=inherit !important][[backcolor=inherit !important]1[backcolor=inherit !important]]/[backcolor=inherit !important]32768*[backcolor=inherit !important]16[backcolor=inherit !important],[backcolor=inherit !important]([backcolor=inherit !important]float[backcolor=inherit !important])stcAcc[backcolor=inherit !important].a[backcolor=inherit !important][[backcolor=inherit !important]2[backcolor=inherit !important]]/[backcolor=inherit !important]32768*[backcolor=inherit !important]16[backcolor=inherit !important])[backcolor=inherit !important]; [backcolor=inherit !important]delay_ms[backcolor=inherit !important]([backcolor=inherit !important]10[backcolor=inherit !important])[backcolor=inherit !important]; [backcolor=inherit !important]//输出角速度 [backcolor=inherit !important]printf[backcolor=inherit !important]([backcolor=inherit !important]"Gyro:%.3f %.3f %.3f\r\n"[backcolor=inherit !important],[backcolor=inherit !important]([backcolor=inherit !important]float[backcolor=inherit !important])stcGyro[backcolor=inherit !important].w[backcolor=inherit !important][[backcolor=inherit !important]0[backcolor=inherit !important]]/[backcolor=inherit !important]32768*[backcolor=inherit !important]2000[backcolor=inherit !important],[backcolor=inherit !important]([backcolor=inherit !important]float[backcolor=inherit !important])stcGyro[backcolor=inherit !important].w[backcolor=inherit !important][[backcolor=inherit !important]1[backcolor=inherit !important]]/[backcolor=inherit !important]32768*[backcolor=inherit !important]2000[backcolor=inherit !important],[backcolor=inherit !important]([backcolor=inherit !important]float[backcolor=inherit !important])stcGyro[backcolor=inherit !important].w[backcolor=inherit !important][[backcolor=inherit !important]2[backcolor=inherit !important]]/[backcolor=inherit !important]32768*[backcolor=inherit !important]2000[backcolor=inherit !important])[backcolor=inherit !important]; [backcolor=inherit !important]delay_ms[backcolor=inherit !important]([backcolor=inherit !important]10[backcolor=inherit !important])[backcolor=inherit !important]; [backcolor=inherit !important]//输出角度 [backcolor=inherit !important]printf[backcolor=inherit !important]([backcolor=inherit !important]"Angle:%.3f %.3f %.3f\r\n"[backcolor=inherit !important],[backcolor=inherit !important]([backcolor=inherit !important]float[backcolor=inherit !important])stcAngle[backcolor=inherit !important].Angle[backcolor=inherit !important][[backcolor=inherit !important]0[backcolor=inherit !important]]/[backcolor=inherit !important]32768*[backcolor=inherit !important]180[backcolor=inherit !important],[backcolor=inherit !important]([backcolor=inherit !important]float[backcolor=inherit !important])stcAngle[backcolor=inherit !important].Angle[backcolor=inherit !important][[backcolor=inherit !important]1[backcolor=inherit !important]]/[backcolor=inherit !important]32768*[backcolor=inherit !important]180[backcolor=inherit !important],[backcolor=inherit !important]([backcolor=inherit !important]float[backcolor=inherit !important])stcAngle[backcolor=inherit !important].Angle[backcolor=inherit !important][[backcolor=inherit !important]2[backcolor=inherit !important]]/[backcolor=inherit !important]32768*[backcolor=inherit !important]180[backcolor=inherit !important])[backcolor=inherit !important]; [backcolor=inherit !important]delay_ms[backcolor=inherit !important]([backcolor=inherit !important]10[backcolor=inherit !important])[backcolor=inherit !important];[backcolor=inherit !important]//等待传输完成 [backcolor=inherit !important]}[backcolor=inherit !important]//主循环[backcolor=inherit !important]}
其实一共就分为三个部分。
第一部分,为串口2中断调用函数CopeSerialData,串口每收到一个数据,调用一次这个函数。把串口2获取到的数据存在ucRxBuffer这个数组里。然后根据JY61的通讯协议(如下图所示)去做一个数据检验判断。判断完后呢,就到了一个memcpy这个复制函数。不懂这个函数的可以看这个链接:运动传感:STM32中的memcpy函数的使用 我和大家说个结果。比如说加速度,memcpy函数就是把ucRxBuffer的数据复制到stcAcc这个结构体里了,剩下的以此类推。到这里这里的第一部分就结束了。
JY61的通讯协议
第二部分,CopeSerial1Data。很简单的就是转发串口1收到的数据给串口2(JY模块)。
第三部分,就是数据处理部分了。以加速度为例子。
[backcolor=inherit !important]printf[backcolor=inherit !important]([backcolor=inherit !important]"Acc:%.3f %.3f %.3f\r\n"[backcolor=inherit !important],[backcolor=inherit !important]([backcolor=inherit !important]float[backcolor=inherit !important])stcAcc[backcolor=inherit !important].a[backcolor=inherit !important][[backcolor=inherit !important]0[backcolor=inherit !important]]/[backcolor=inherit !important]32768*[backcolor=inherit !important]16[backcolor=inherit !important],[backcolor=inherit !important]([backcolor=inherit !important]float[backcolor=inherit !important])stcAcc[backcolor=inherit !important].a[backcolor=inherit !important][[backcolor=inherit !important]1[backcolor=inherit !important]]/[backcolor=inherit !important]32768*[backcolor=inherit !important]16[backcolor=inherit !important],[backcolor=inherit !important]([backcolor=inherit !important]float[backcolor=inherit !important])stcAcc[backcolor=inherit !important].a[backcolor=inherit !important][[backcolor=inherit !important]2[backcolor=inherit !important]]/[backcolor=inherit !important]32768*[backcolor=inherit !important]16[backcolor=inherit !important])[backcolor=inherit !important]; [backcolor=inherit !important]delay_ms[backcolor=inherit !important]([backcolor=inherit !important]10[backcolor=inherit !important])[backcolor=inherit !important];
stcAcc这个前面讲了就是复制结束的结果。根据上面的JY61的通讯协议。/32768*16这些都是为了把JY61输出的16进制的原始数据转成成有符号的10进制的数据。然后把得到的结果输出到串口1。
以上三个部分呢,就是我的主要编程思路了。下面给大家讲讲一些细节方面的函数。
3.2 关键底层函数说
从上面的接线可以看出呢。一共用了32单片机的两个UART引脚。一个是UART1这个是把处理过的数据发送到PC端。一个是UART2这个是用来接收JY61传过来的数据。UART2也是使用中断来接收到数据。这些都是在初始化UART2的时候来配置的。前面那部分都是默认的串口配置。设置波特率、数据位8位、停止位1、无奇偶检验、配置串口模式。最后再初始化USART2。一般都是固定的。后面的USART_ITConfig。就是开启串口中断。
[backcolor=inherit !important]void [backcolor=inherit !important]Initial_UART2[backcolor=inherit !important]([backcolor=inherit !important]unsigned [backcolor=inherit !important]long baudrate[backcolor=inherit !important])[backcolor=inherit !important]{ GPIO_InitTypeDef GPIO_InitStructure[backcolor=inherit !important]; USART_InitTypeDef USART_InitStructure[backcolor=inherit !important]; NVIC_InitTypeDef NVIC_InitStructure[backcolor=inherit !important]; [backcolor=inherit !important]RCC_APB1PeriphClockCmd[backcolor=inherit !important](RCC_APB1Periph_USART2 | RCC_APB2Periph_GPIOA[backcolor=inherit !important], ENABLE[backcolor=inherit !important])[backcolor=inherit !important]; GPIO_InitStructure[backcolor=inherit !important].GPIO_Pin = GPIO_Pin_2[backcolor=inherit !important]; GPIO_InitStructure[backcolor=inherit !important].GPIO_Mode = GPIO_Mode_AF_PP[backcolor=inherit !important]; GPIO_InitStructure[backcolor=inherit !important].GPIO_Speed = GPIO_Speed_50MHz[backcolor=inherit !important]; [backcolor=inherit !important]GPIO_Init[backcolor=inherit !important](GPIOA[backcolor=inherit !important], &GPIO_InitStructure[backcolor=inherit !important])[backcolor=inherit !important]; GPIO_InitStructure[backcolor=inherit !important].GPIO_Pin = GPIO_Pin_3[backcolor=inherit !important]; GPIO_InitStructure[backcolor=inherit !important].GPIO_Mode = GPIO_Mode_IN_FLOATING[backcolor=inherit !important]; [backcolor=inherit !important]GPIO_Init[backcolor=inherit !important](GPIOA[backcolor=inherit !important], &GPIO_InitStructure[backcolor=inherit !important])[backcolor=inherit !important]; USART_InitStructure[backcolor=inherit !important].USART_BaudRate = baudrate[backcolor=inherit !important]; USART_InitStructure[backcolor=inherit !important].USART_WordLength = USART_WordLength_8b[backcolor=inherit !important]; USART_InitStructure[backcolor=inherit !important].USART_StopBits = USART_StopBits_1[backcolor=inherit !important]; USART_InitStructure[backcolor=inherit !important].USART_Parity = USART_Parity_No [backcolor=inherit !important]; USART_InitStructure[backcolor=inherit !important].USART_HardwareFlowControl = USART_HardwareFlowControl_None[backcolor=inherit !important]; USART_InitStructure[backcolor=inherit !important].USART_Mode = USART_Mode_Rx | USART_Mode_Tx[backcolor=inherit !important]; [backcolor=inherit !important]USART_Init[backcolor=inherit !important](USART2[backcolor=inherit !important], &USART_InitStructure[backcolor=inherit !important])[backcolor=inherit !important]; [backcolor=inherit !important]USART_ITConfig[backcolor=inherit !important](USART2[backcolor=inherit !important], USART_IT_TXE[backcolor=inherit !important], DISABLE[backcolor=inherit !important])[backcolor=inherit !important]; [backcolor=inherit !important]//串口2的发送端TX是不使能的 [backcolor=inherit !important]USART_ITConfig[backcolor=inherit !important](USART2[backcolor=inherit !important], USART_IT_RXNE[backcolor=inherit !important], ENABLE[backcolor=inherit !important])[backcolor=inherit !important];[backcolor=inherit !important]//串口2的接收端的RX使能 [backcolor=inherit !important]USART_ClearFlag[backcolor=inherit !important](USART2[backcolor=inherit !important],USART_FLAG_TC[backcolor=inherit !important])[backcolor=inherit !important]; [backcolor=inherit !important]USART_Cmd[backcolor=inherit !important](USART2[backcolor=inherit !important], ENABLE[backcolor=inherit !important])[backcolor=inherit !important]; NVIC_InitStructure[backcolor=inherit !important].NVIC_IRQChannel = USART2_IRQn[backcolor=inherit !important]; NVIC_InitStructure[backcolor=inherit !important].NVIC_IRQChannelPreemptionPriority = [backcolor=inherit !important]1[backcolor=inherit !important]; NVIC_InitStructure[backcolor=inherit !important].NVIC_IRQChannelSubPriority = [backcolor=inherit !important]8[backcolor=inherit !important]; NVIC_InitStructure[backcolor=inherit !important].NVIC_IRQChannelCmd = ENABLE[backcolor=inherit !important]; [backcolor=inherit !important]NVIC_Init[backcolor=inherit !important](&NVIC_InitStructure[backcolor=inherit !important])[backcolor=inherit !important];[backcolor=inherit !important]}
使能串口中断后呢。UART2的数据都会一个个字节的往DR寄存器里面写。就是第一部分调用的那个中断函数CopeSerial2Data。整体来就是给大家介绍下数据是怎么来的。底层中断函数说明
[backcolor=inherit !important]void [backcolor=inherit !important]USART2_IRQHandler[backcolor=inherit !important]([backcolor=inherit !important]void[backcolor=inherit !important])[backcolor=inherit !important]{ [backcolor=inherit !important]if[backcolor=inherit !important]([backcolor=inherit !important]USART_GetITStatus[backcolor=inherit !important](USART2[backcolor=inherit !important], USART_IT_TXE[backcolor=inherit !important]) != RESET[backcolor=inherit !important])[backcolor=inherit !important]//由于TX中断被禁止了所以这个if是不会进入的。 [backcolor=inherit !important]{ [backcolor=inherit !important]USART_SendData[backcolor=inherit !important](USART2[backcolor=inherit !important], TxBuffer[backcolor=inherit !important][TxCounter++[backcolor=inherit !important]][backcolor=inherit !important])[backcolor=inherit !important]; [backcolor=inherit !important]USART_ClearITPendingBit[backcolor=inherit !important](USART2[backcolor=inherit !important], USART_IT_TXE[backcolor=inherit !important])[backcolor=inherit !important]; [backcolor=inherit !important]if[backcolor=inherit !important](TxCounter == count[backcolor=inherit !important]) [backcolor=inherit !important]USART_ITConfig[backcolor=inherit !important](USART2[backcolor=inherit !important], USART_IT_TXE[backcolor=inherit !important], DISABLE[backcolor=inherit !important])[backcolor=inherit !important]; [backcolor=inherit !important]} [backcolor=inherit !important]else [backcolor=inherit !important]if[backcolor=inherit !important]([backcolor=inherit !important]USART_GetITStatus[backcolor=inherit !important](USART2[backcolor=inherit !important], USART_IT_RXNE[backcolor=inherit !important]) != RESET[backcolor=inherit !important])[backcolor=inherit !important]//直接进入RX的这个中断 [backcolor=inherit !important]{ [backcolor=inherit !important]CopeSerial2Data[backcolor=inherit !important]([backcolor=inherit !important]([backcolor=inherit !important]unsigned [backcolor=inherit !important]char[backcolor=inherit !important])USART2->DR[backcolor=inherit !important])[backcolor=inherit !important];[backcolor=inherit !important]//把UART2的数据给到DR寄存器后呢,再由这个CopeSerial2Data函数把数据给到给出去了 [backcolor=inherit !important]USART_ClearITPendingBit[backcolor=inherit !important](USART2[backcolor=inherit !important], USART_IT_RXNE[backcolor=inherit !important])[backcolor=inherit !important]; [backcolor=inherit !important]} [backcolor=inherit !important]USART_ClearITPendingBit[backcolor=inherit !important](USART2[backcolor=inherit !important],USART_IT_ORE[backcolor=inherit !important])[backcolor=inherit !important];[backcolor=inherit !important]}
## 6 输出结果显示
在电脑上正确连接好板子,首先打开串口调试助手,找到相应的端口,然后打开串口,注意这里波特率设置为9600,然后就可以观察到左边的窗口有数据输出了。如图所示:
|