一、前言
正点原子源码中使用usb将飞机上的各种传感器数据发送到上位机上,但是飞机在飞行调试过程中,很难一遍连接数据线一边飞行,本篇文章记录了如何修改源码,使其使用usart串口发出数据;如此,在串口上挂接一个蓝牙HC-05,就可以在飞行的过程中查看飞机的各项数据并且保存查看了;
二、软件修改
1、usart.c和usart.h修改
(1)usart.h的修改
增加两个函数,一个是提供串口1的字符串发送;一个是增加字节数据处理; 其中usart1GetDataWithTimout 函数主要是等待消息队列,该消息队列里的数据来自串口1中断,一旦串口中断收到数据,就把数据发送到消息队列中;只有消息队列中有数据,就拿到上层的任务中做处理; 
(2)usart.c的修改
增加串口1 中断服务函数; 增加串口1字节数据提供函数;  修改fputc函数,将原来的printf使用usb发送改为usart串口发送; 增加usart字符串发送函数; 
2、uart.c修改
把这里的串口中断函数注释掉,否则编译出现报错; 
3、system.c修改
此处加入usart1的初始化,这里波特率设置为460800;同时蓝牙hc-05的波特率也需要设置成460800; 注意:usart1的初始化必须加在使用printf的函数的前面,否则程序会异常; 
4、usblink.c的修改
最后是修改usblink驱动修改,主要就是两点,一个是input,修改成串口1等待消息队列里的字节数据; 另一个就是output,将原来使用usb发送改成串口1的字符串发送函数; 
5、源码记录

git@gitee.com:ggxxd/wukong_dronefly.git
三、硬件连接

四、上位机连接

|