class="hljs-ln-code"> class="hljs-ln-line">void UART1_Init(uint32_t ulBaudrate); class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="3"> class="hljs-ln-code"> class="hljs-ln-line"> class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="4"> class="hljs-ln-code"> class="hljs-ln-line">void UART1_SendString(const char *pcString, ...); class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="5"> class="hljs-ln-code"> class="hljs-ln-line">uint8_t UART1_SendAT(char *pcAT, char *pcAckString, uint16_t usTimeOutMs); class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="6"> class="hljs-ln-code"> class="hljs-ln-line">void UART1_SendData(uint8_t *puData, uint16_t usNum); class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="7"> class="hljs-ln-code"> class="hljs-ln-line"> class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="8"> class="hljs-ln-code"> class="hljs-ln-line">uint16_t UART1_GetRxNum(void); class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="9"> class="hljs-ln-code"> class="hljs-ln-line">uint8_t* UART1_GetRxData(void); class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="10"> class="hljs-ln-code"> class="hljs-ln-line">void UART1_ClearRx(void); class="hljs-button signin active" data-title="登录复制" data-report-click="{"spm":"1001.2101.3001.4334"}" onclick="hljs.signin(event)">
二、文件移植
1、新建 bsp_UART.c 和 bsp_UART.h这两个文件
- 如果已有魔女开发板的示例网盘,打开随便一个示例的 BSP 文件夹,把其下UART文件夹,复制到你的目标工程中即可,不用另行新建文件。
- 如果没有,就到文章末处,复制 bsp_UART.c 和 bsp_UART.h 的代码,在目标工程的文件夹中,新建bsp_UART.c 和 bsp_UART.h 这两个文件,对应粘贴进去即可。
2、工程添加 bsp_UART.c 文件
- 双击keil左侧的目标文件夹,添加bsp_UART.c到工程中。
- 也可以点击工具栏的 组管理 按钮进行添加; 操作如下图:

3、添加头文件路径;
刚才添加了 c文件到工程,还需要添加头文件的路径,编译器才能知道 h 文件的存放位置 。
操作如下:


4、添加文件引用
在需要UART功能的文件中,添加:#include "bsp_UART.h"
如,main.c 中想使用UART,就在它的头部位置添加。
操作如下:

好了,移植就是这么简单,至此,你的工程中已经可以正常使用UART功能了。
三、初始化、引脚使用
以使用UART1为例,其它几个UART的初始化方法相同。
调用:UART1_Init (115200) ; // 参数:波特率
操作如下:

此函数将会执行:引脚PA9+PA10的初始化、UART1初始化、中断初始化、进入接收状态。
初始化仅需调用这个函数即可。不用修改代码,不用管其它的。
各个UART在初始化时,将默认使用以下引脚:
这些都是STM32不同系列通用的 UART引脚,不管F1还是F4,都可以使用以下引脚,无需修改。
class="table-box">串口端口 | 发送引脚 (TX) | 接收引脚 (RX) |
---|
UART1 | PA9 | PA10 |
UART2 | PA2 | PA3 |
UART3 | PB10 | PB11 |
UART4 | PC10 | PC11 |
UART5 | PC12 | PD2 |
UART6 | PC6 | PC7 |
四、发送
各个UART的发送,都提供了 3个函数。
灵活选择,能实现不同场景数据的发送, 如:float、int、数组、字符串、AT指令、结构体,等等。
发送机制:发送中断+环形队列。当然,这些底层不用管、不用修改,只管调用函数。
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1"> class="hljs-ln-code"> class="hljs-ln-line">void UART1_SendString(const char *pcString, ...);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="2"> class="hljs-ln-code"> class="hljs-ln-line">void UART1_SendData(uint8_t *puData, uint16_t usNum);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="3"> class="hljs-ln-code"> class="hljs-ln-line">uint8_t UART1_SendAT(char *pcAT, char *pcAckString, uint16_t usTimeOutMs);
class="hljs-button signin active" data-title="登录复制" data-report-click="{"spm":"1001.2101.3001.4334"}" onclick="hljs.signin(event)">
函数解释:
① 发送字符串,用:UART1_SendString (char *string,...)
使用方法如同 printf,相当灵活,具体可以百度一下printf的格式化如何使用,操作是一样的。
使用示范:
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1"> class="hljs-ln-code"> class="hljs-ln-line">UART1_SendString("\r 你好吗? \r");
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="2"> class="hljs-ln-code"> class="hljs-ln-line">UART1_SendString("字节数:%d 字节\r", rxNum);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="3"> class="hljs-ln-code"> class="hljs-ln-line">UART1_SendString("数据 (ASCII): %s\r", (char *)rxData);
class="hljs-button signin active" data-title="登录复制" data-report-click="{"spm":"1001.2101.3001.4334"}" onclick="hljs.signin(event)">
② 发送指定长度的数据,用:UART1_SendData (*data, num)
参数:缓存地址、字节数
可用于发送数组、结构体、字符串 等任意数据。
使用示范:
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="2"> class="hljs-ln-code"> class="hljs-ln-line">UART1_SendData((uint8_t*)"你好吗", 6);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="3"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="4"> class="hljs-ln-code"> class="hljs-ln-line">uint8_t myArray[50] = {0xAA, 0xBB, 0xCC, 0xDD};
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="5"> class="hljs-ln-code"> class="hljs-ln-line">UART1_SendData(myArray, 8);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="6"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="7"> class="hljs-ln-code"> class="hljs-ln-line">float myFloat = 520.1314;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="8"> class="hljs-ln-code"> class="hljs-ln-line">UART1_SendData(&myFloat, sizeof(float));
class="hljs-button signin active" data-title="登录复制" data-report-click="{"spm":"1001.2101.3001.4334"}" onclick="hljs.signin(event)">
③ 发送AT指令:UART1_SendAT(char *pcAT, char *pcAckString, uint16_t usTimeOutMs);
参数:AT指令字符串、期待返回信息字符串、等待超时ms;
返回:0-执行失败、1-执行成功
本函数能很方便地与ESP8266、蓝牙模块等进行通过。
用于发送AT指令后,等待执行反馈;
使用示范:
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1"> class="hljs-ln-code"> class="hljs-ln-line">UART1_SendAT("AT+RESTORE\r\n", "ready", 3000) ? printf("恢复出厂设置: 成功\r\n") : printf("恢复出厂设置: 失败\r\n");
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="2"> class="hljs-ln-code"> class="hljs-ln-line">UART1_SendAT("AT+CWMODE=1\r\n", "OK", 3000) ? printf("配置 STA模式: 成功\r\n") : printf("配置 STA模式: 失败\r\n");
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="3"> class="hljs-ln-code"> class="hljs-ln-line">UART1_SendAT("AT+RST\r\n", "ready", 3000) ? printf("重启 ESP8266: 成功\r\n") : printf("重启 ESP8266: 失败\r\n");
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="4"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="5"> class="hljs-ln-code"> class="hljs-ln-line">char strTemp[100] = {0};
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="6"> class="hljs-ln-code"> class="hljs-ln-line">sprintf(strTemp, "AT+CWJAP=\"%s\",\"%s\"\r\n", "wifiName", "wifiPassWord");
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="7"> class="hljs-ln-code"> class="hljs-ln-line">if(UART1_SendAT(strTemp, "OK\r\n", 6000) )
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="8"> class="hljs-ln-code"> class="hljs-ln-line"> printf("连接WiFi网络 成功\r\n");
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="9"> class="hljs-ln-code"> class="hljs-ln-line">else
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="10"> class="hljs-ln-code"> class="hljs-ln-line"> printf("连接WiFi网络 失败\r\n");
class="hljs-button signin active" data-title="登录复制" data-report-click="{"spm":"1001.2101.3001.4334"}" onclick="hljs.signin(event)">
printf
很多人习惯在调试时使用printf。
在bsp_UART.c里,也做好了它的重定向输出。
printf已重定向输出到UART1,在初始化 UART1后,直接可用printf。
五、接收
接收处理,共3个函数:
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1"> class="hljs-ln-code"> class="hljs-ln-line">uint16_t UART1_GetRxNum(void);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="2"> class="hljs-ln-code"> class="hljs-ln-line">uint8_t* UART1_GetRxdData(void);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="3"> class="hljs-ln-code"> class="hljs-ln-line">void UART1_ClearRx(void);
class="hljs-button signin active" data-title="登录复制" data-report-click="{"spm":"1001.2101.3001.4334"}" onclick="hljs.signin(event)">
接收机制上,使用:接收中断 + 空闲中断 + 双缓冲区。这些底层工作都已封装处理好,不用管。使用上,只管调用上面这仨函数。
① 获取字节数:UART1_GetRxNum ( )
作用:获取最后一帧接收到的 字节数;
- 参数:无
- 返回:字节数 ( uint16_t)
- 串口在调用 初始化函数 后,再调用这个函数判断返回值,即可知道接收状态:
- 当返回值 (接收字节数 ) ==0 时:没有接收到数据;
- 当返回值 (接收字节数 ) > 0时:接收到新一帧数据 ;
② 获取数据:UART1_GetRxData ( )
作用:获取最后一帧接收到的 数据地址;
- 参数:无
- 返回:数据地址 (uint8_t* ,注意:是指针)
- 如果不会使用指针,可以把结果当数组使用,用符号 [ ] 对数据进行访问。
③ 清0本次接收:UART1_ClearRx ( ) ;
作用:在处理完最后一帧的数据后,清0本帧数据的缓存
- 参数:无
- 返回:无
- 其实就是清0 最后一帧的接收字节数。
- 重要:每次接收到一帧数据,处理完了,就调用这函数,清0,以方便下一轮的判断!
下面代码,示范如何接收、处理数据(以串口1为例,其它串口同理):

六、常见冲突、错误的解决
本文所提供的 bsp_UART.c 和 bsp_UART.h ,支持标准库、HAL库,复制过去即可。
1、添加到原子哥的标准库工程中可能的冲突
原子哥的示例,很多人喜欢使用。
这些示例中,一般已带有uart.c和printf的重定向处理。
如果想添加到这些示例中,建议先备份工程!删除工程中UART文件和代码,再移植此文件。
2、添加到CubeMX、CubeIDE工程中可能的冲突
明确地,无需在CubeMX、CubeIDE中做任何UART的设置。
如果工程中已配置UART,建议先备份工程!关闭CubeMX、CubeIDE中对UART使能,再移植。
如果,使用CubeMX、CubeIDEE配置工程时,想使用此代码,又想标记哪些串口和相关的UART引脚已使用,可以的,在CubeMX、CubeIDE上使能相关的UART即可,这样就能方便地标记哪些引脚被使用了。
但是,记得使用上述表格中的引脚,和,不能打勾串口配置选项的中断、DMA,否则冲突。
使用CubeMX时重点注意的冲突:
- 使用上述表格的所用的串口引脚
- 在CubeMX或CubeIDE中,可以使能UART,但不要打勾串口的中断、配置DMA,否则冲突。

当在CubeMX、CubeIDE中,如上使能串口后,也能使用HAL库的发送函数、接收函数,不冲突:
- HAL_UART_Transmit ( )
- HAL_UART_Receive( )
只是,不建议使用了。因为bsp_USART.c的函数,使用起来更方便。
3、不同串口,使用不同的方式
如果,某个串口,想使用CubeMX进行中断、DMA配置; 而某些串口,想使用文件中的函数:
可以的.
在bsp_UART.h文件中,修改下面的宏定义,默认是1,即开启,修改为0值关闭即可。

宏定义 值解释:
- 0:自己另行配置、编写,例如使用CubeMX的中断、DMA配置等
- 1:使用文件的配置、函数
4、发现通信中漏数据
这种情况,是缓存过小。
在bsp_UART.h里,把发送缓存或接收缓存改大一些即可
5、接收时,发现漏帧
不是漏了一帧的某些内容,是整帧漏了。
这种情况,一般是接收处理的不及时。
如对方每100ms发送一次,但我们的代码while里,每间隔500ms才执行一次接收处理。
把接收处理的间隔,调小一些即可。或者,while里的接收处理,完全不用时间间隔。
七、STM32F103 源代码
可复制以下代码到文件,也可以直接下载:bsp_UART.c + bsp_UART.h
1、bsp_UART.h
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1"> class="hljs-ln-code"> class="hljs-ln-line">#ifndef __BSP__UART_H
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="2"> class="hljs-ln-code"> class="hljs-ln-line">#define __BSP__UART_H
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="3"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="4"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="5"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="6"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="7"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="8"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="9"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="10"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="11"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="12"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="13"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="14"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="15"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="16"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="17"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="18"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="19"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="20"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="21"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="22"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="23"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="24"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="25"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="26"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="27"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="28"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="29"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="30"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="31"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="32"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="33"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="34"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="35"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="36"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="37"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="38"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="39"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="40"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="41"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="42"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="43"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="44"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="45"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="46"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="47"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="48"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="49"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="50"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="51"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="52"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="53"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="54"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="55"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="56"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="57"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="58"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="59"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="60"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="61"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="62"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="63"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="64"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="65"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="66"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="67"> class="hljs-ln-code"> class="hljs-ln-line">#include "stdio.h"
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="68"> class="hljs-ln-code"> class="hljs-ln-line">#include "stdarg.h"
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="69"> class="hljs-ln-code"> class="hljs-ln-line">#include "string.h"
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="70"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="71"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="72"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="73"> class="hljs-ln-code"> class="hljs-ln-line">#ifdef USE_STDPERIPH_DRIVER
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="74"> class="hljs-ln-code"> class="hljs-ln-line"> #include "stm32f10x.h"
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="75"> class="hljs-ln-code"> class="hljs-ln-line">#endif
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="76"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="77"> class="hljs-ln-code"> class="hljs-ln-line">#ifdef USE_HAL_DRIVER
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="78"> class="hljs-ln-code"> class="hljs-ln-line"> #include "stm32f1xx_hal.h"
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="79"> class="hljs-ln-code"> class="hljs-ln-line">#endif
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="80"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="81"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="82"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="83"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="84"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="85"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="86"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="87"> class="hljs-ln-code"> class="hljs-ln-line">#define UART1_EN 1
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="88"> class="hljs-ln-code"> class="hljs-ln-line">#define UART2_EN 1
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="89"> class="hljs-ln-code"> class="hljs-ln-line">#define UART3_EN 1
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="90"> class="hljs-ln-code"> class="hljs-ln-line">#define UART4_EN 1
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="91"> class="hljs-ln-code"> class="hljs-ln-line">#define UART5_EN 1
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="92"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="93"> class="hljs-ln-code"> class="hljs-ln-line">#define UART1_TX_BUF_SIZE 2048
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="94"> class="hljs-ln-code"> class="hljs-ln-line">#define UART2_TX_BUF_SIZE 512
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="95"> class="hljs-ln-code"> class="hljs-ln-line">#define UART3_TX_BUF_SIZE 512
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="96"> class="hljs-ln-code"> class="hljs-ln-line">#define UART4_TX_BUF_SIZE 512
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="97"> class="hljs-ln-code"> class="hljs-ln-line">#define UART5_TX_BUF_SIZE 512
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="98"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="99"> class="hljs-ln-code"> class="hljs-ln-line">#define UART1_RX_BUF_SIZE 2048
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="100"> class="hljs-ln-code"> class="hljs-ln-line">#define UART2_RX_BUF_SIZE 512
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="101"> class="hljs-ln-code"> class="hljs-ln-line">#define UART3_RX_BUF_SIZE 512
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="102"> class="hljs-ln-code"> class="hljs-ln-line">#define UART4_RX_BUF_SIZE 512
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="103"> class="hljs-ln-code"> class="hljs-ln-line">#define UART5_RX_BUF_SIZE 512
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="104"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="105"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="106"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="107"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="108"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="109"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="110"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="111"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="112"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="113"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="114"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="115"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="116"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="117"> class="hljs-ln-code"> class="hljs-ln-line">void UART1_Init(uint32_t ulBaudrate);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="118"> class="hljs-ln-code"> class="hljs-ln-line">void UART1_SendData(uint8_t *puData, uint16_t usNum);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="119"> class="hljs-ln-code"> class="hljs-ln-line">void UART1_SendString(const char *pcString, ...);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="120"> class="hljs-ln-code"> class="hljs-ln-line">uint8_t UART1_SendAT(char *pcAT, char *pcAckString, uint16_t usTimeOutMs);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="121"> class="hljs-ln-code"> class="hljs-ln-line">uint16_t UART1_GetRxNum(void);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="122"> class="hljs-ln-code"> class="hljs-ln-line">uint8_t * UART1_GetRxData(void);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="123"> class="hljs-ln-code"> class="hljs-ln-line">void UART1_ClearRx(void);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="124"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="125"> class="hljs-ln-code"> class="hljs-ln-line">void UART2_Init(uint32_t ulBaudrate);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="126"> class="hljs-ln-code"> class="hljs-ln-line">void UART2_SendData(uint8_t *puData, uint16_t usNum);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="127"> class="hljs-ln-code"> class="hljs-ln-line">void UART2_SendString(const char *pcString, ...);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="128"> class="hljs-ln-code"> class="hljs-ln-line">uint8_t UART2_SendAT(char *pcAT, char *pcAckString, uint16_t usTimeOutMs);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="129"> class="hljs-ln-code"> class="hljs-ln-line">uint16_t UART2_GetRxNum(void);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="130"> class="hljs-ln-code"> class="hljs-ln-line">uint8_t * UART2_GetRxData(void);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="131"> class="hljs-ln-code"> class="hljs-ln-line">void UART2_ClearRx(void);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="132"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="133"> class="hljs-ln-code"> class="hljs-ln-line">void UART3_Init(uint32_t ulBaudrate);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="134"> class="hljs-ln-code"> class="hljs-ln-line">void UART3_SendData(uint8_t *puData, uint16_t usNum);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="135"> class="hljs-ln-code"> class="hljs-ln-line">void UART3_SendString(const char *pcString, ...);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="136"> class="hljs-ln-code"> class="hljs-ln-line">uint8_t UART3_SendAT(char *pcAT, char *pcAckString, uint16_t usTimeOutMs);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="137"> class="hljs-ln-code"> class="hljs-ln-line">uint16_t UART3_GetRxNum(void);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="138"> class="hljs-ln-code"> class="hljs-ln-line">uint8_t * UART3_GetRxData(void);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="139"> class="hljs-ln-code"> class="hljs-ln-line">void UART3_ClearRx(void);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="140"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="141"> class="hljs-ln-code"> class="hljs-ln-line">#ifdef STM32F10X_HD
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="142"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="143"> class="hljs-ln-code"> class="hljs-ln-line">void UART4_Init(uint32_t ulBaudrate);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="144"> class="hljs-ln-code"> class="hljs-ln-line">void UART4_SendData(uint8_t *puData, uint16_t usNum);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="145"> class="hljs-ln-code"> class="hljs-ln-line">void UART4_SendString(const char *pcString, ...);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="146"> class="hljs-ln-code"> class="hljs-ln-line">uint8_t UART4_SendAT(char *pcAT, char *pcAckString, uint16_t usTimeOutMs);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="147"> class="hljs-ln-code"> class="hljs-ln-line">uint16_t UART4_GetRxNum(void);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="148"> class="hljs-ln-code"> class="hljs-ln-line">uint8_t * UART4_GetRxData(void);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="149"> class="hljs-ln-code"> class="hljs-ln-line">void UART4_ClearRx(void);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="150"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="151"> class="hljs-ln-code"> class="hljs-ln-line">void UART5_Init(uint32_t ulBaudrate);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="152"> class="hljs-ln-code"> class="hljs-ln-line">void UART5_SendData(uint8_t *puData, uint16_t usNum);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="153"> class="hljs-ln-code"> class="hljs-ln-line">void UART5_SendString(const char *pcString, ...);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="154"> class="hljs-ln-code"> class="hljs-ln-line">uint8_t UART5_SendAT(char *pcAT, char *pcAckString, uint16_t usTimeOutMs);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="155"> class="hljs-ln-code"> class="hljs-ln-line">uint16_t UART5_GetRxNum(void);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="156"> class="hljs-ln-code"> class="hljs-ln-line">uint8_t * UART5_GetRxData(void);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="157"> class="hljs-ln-code"> class="hljs-ln-line">void UART5_ClearRx(void);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="158"> class="hljs-ln-code"> class="hljs-ln-line">#endif
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="159"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="160"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="161"> class="hljs-ln-code"> class="hljs-ln-line">void Modbus_AddCRC16(uint8_t *_pcData, uint16_t _usLen);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="162"> class="hljs-ln-code"> class="hljs-ln-line">uint8_t Modbus_CheckCRC16(uint8_t *_pcData, uint16_t _usLen);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="163"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="164"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="165"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="166"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="167"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="168"> class="hljs-ln-code"> class="hljs-ln-line">#endif
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="169"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="170"> class="hljs-ln-code"> class="hljs-ln-line">
class="hide-preCode-box">
class="hljs-button signin active" data-title="登录复制" data-report-click="{"spm":"1001.2101.3001.4334"}" onclick="hljs.signin(event)">
2、bsp_UART.c
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="2"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="3"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="4"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="5"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="6"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="7"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="8"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="9"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="10"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="11"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="12"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="13"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="14"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="15"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="16"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="17"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="18"> class="hljs-ln-code"> class="hljs-ln-line">#include "bsp_UART.h"
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="19"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="20"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="21"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="22"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="23"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="24"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="25"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="26"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="27"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="28"> class="hljs-ln-code"> class="hljs-ln-line">typedef struct
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="29"> class="hljs-ln-code"> class="hljs-ln-line">{
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="30"> class="hljs-ln-code"> class="hljs-ln-line"> uint16_t usRxNum;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="31"> class="hljs-ln-code"> class="hljs-ln-line"> uint8_t *puRxData;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="32"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="33"> class="hljs-ln-code"> class="hljs-ln-line"> uint8_t *puTxFiFoData;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="34"> class="hljs-ln-code"> class="hljs-ln-line"> uint16_t usTxFiFoData ;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="35"> class="hljs-ln-code"> class="hljs-ln-line"> uint16_t usTxFiFoTail ;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="36"> class="hljs-ln-code"> class="hljs-ln-line">} xUSATR_TypeDef;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="37"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="38"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="39"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="40"> class="hljs-ln-code"> class="hljs-ln-line">#if 0
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="41"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="42"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="43"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="44"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="45"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="46"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="47"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="48"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="49"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="50"> class="hljs-ln-code"> class="hljs-ln-line">static volatile uint32_t ulTimesUS;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="51"> class="hljs-ln-code"> class="hljs-ln-line">static void delay_us(uint16_t us)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="52"> class="hljs-ln-code"> class="hljs-ln-line">{
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="53"> class="hljs-ln-code"> class="hljs-ln-line"> ulTimesUS = us ;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="54"> class="hljs-ln-code"> class="hljs-ln-line"> while (ulTimesUS)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="55"> class="hljs-ln-code"> class="hljs-ln-line"> ulTimesUS--;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="56"> class="hljs-ln-code"> class="hljs-ln-line">}
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="57"> class="hljs-ln-code"> class="hljs-ln-line">#endif
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="58"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="59"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="60"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="61"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="62"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="63"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="64"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="65"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="66"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="67"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="68"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="69"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="70"> class="hljs-ln-code"> class="hljs-ln-line">static volatile uint32_t ulTimesMS;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="71"> class="hljs-ln-code"> class="hljs-ln-line">static void delay_ms(uint16_t ms)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="72"> class="hljs-ln-code"> class="hljs-ln-line">{
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="73"> class="hljs-ln-code"> class="hljs-ln-line"> ulTimesMS = ms * 5500;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="74"> class="hljs-ln-code"> class="hljs-ln-line"> while (ulTimesMS)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="75"> class="hljs-ln-code"> class="hljs-ln-line"> ulTimesMS--;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="76"> class="hljs-ln-code"> class="hljs-ln-line">}
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="77"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="78"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="79"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="80"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="81"> class="hljs-ln-code"> class="hljs-ln-line">/
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="82"> class="hljs-ln-code"> class="hljs-ln-line">#if UART1_EN
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="83"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="84"> class="hljs-ln-code"> class="hljs-ln-line">static xUSATR_TypeDef xUART1 = { 0 };
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="85"> class="hljs-ln-code"> class="hljs-ln-line">static uint8_t uaUART1RxData[UART1_RX_BUF_SIZE];
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="86"> class="hljs-ln-code"> class="hljs-ln-line">static uint8_t uaUART1TxFiFoData[UART1_TX_BUF_SIZE];
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="87"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="88"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="89"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="90"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="91"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="92"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="93"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="94"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="95"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="96"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="97"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="98"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="99"> class="hljs-ln-code"> class="hljs-ln-line">void UART1_Init(uint32_t ulBaudrate)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="100"> class="hljs-ln-code"> class="hljs-ln-line">{
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="101"> class="hljs-ln-code"> class="hljs-ln-line">#ifdef USE_STDPERIPH_DRIVER
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="102"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="103"> class="hljs-ln-code"> class="hljs-ln-line"> RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="104"> class="hljs-ln-code"> class="hljs-ln-line"> RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="105"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="106"> class="hljs-ln-code"> class="hljs-ln-line"> RCC_APB2PeriphResetCmd(RCC_APB2Periph_USART1, ENABLE);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="107"> class="hljs-ln-code"> class="hljs-ln-line"> RCC_APB2PeriphResetCmd(RCC_APB2Periph_USART1, DISABLE);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="108"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="109"> class="hljs-ln-code"> class="hljs-ln-line"> GPIO_InitTypeDef GPIO_InitStructure = {0};
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="110"> class="hljs-ln-code"> class="hljs-ln-line"> GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="111"> class="hljs-ln-code"> class="hljs-ln-line"> GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="112"> class="hljs-ln-code"> class="hljs-ln-line"> GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="113"> class="hljs-ln-code"> class="hljs-ln-line"> GPIO_Init(GPIOA, &GPIO_InitStructure);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="114"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="115"> class="hljs-ln-code"> class="hljs-ln-line"> GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="116"> class="hljs-ln-code"> class="hljs-ln-line"> GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="117"> class="hljs-ln-code"> class="hljs-ln-line"> GPIO_Init(GPIOA, &GPIO_InitStructure);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="118"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="119"> class="hljs-ln-code"> class="hljs-ln-line"> USART_DeInit(USART1);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="120"> class="hljs-ln-code"> class="hljs-ln-line"> USART_InitTypeDef USART_InitStructure = {0};
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="121"> class="hljs-ln-code"> class="hljs-ln-line"> USART_InitStructure.USART_BaudRate = ulBaudrate;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="122"> class="hljs-ln-code"> class="hljs-ln-line"> USART_InitStructure.USART_WordLength = USART_WordLength_8b;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="123"> class="hljs-ln-code"> class="hljs-ln-line"> USART_InitStructure.USART_StopBits = USART_StopBits_1;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="124"> class="hljs-ln-code"> class="hljs-ln-line"> USART_InitStructure.USART_Parity = USART_Parity_No;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="125"> class="hljs-ln-code"> class="hljs-ln-line"> USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="126"> class="hljs-ln-code"> class="hljs-ln-line"> USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="127"> class="hljs-ln-code"> class="hljs-ln-line"> USART_Init(USART1, &USART_InitStructure);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="128"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="129"> class="hljs-ln-code"> class="hljs-ln-line"> USART_ITConfig(USART1, USART_IT_TXE, DISABLE);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="130"> class="hljs-ln-code"> class="hljs-ln-line"> USART_ITConfig(USART1, USART_IT_RXNE, ENABLE);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="131"> class="hljs-ln-code"> class="hljs-ln-line"> USART_ITConfig(USART1, USART_IT_IDLE, ENABLE);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="132"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="133"> class="hljs-ln-code"> class="hljs-ln-line"> NVIC_InitTypeDef NVIC_InitStructure = {0};
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="134"> class="hljs-ln-code"> class="hljs-ln-line"> NVIC_InitStructure .NVIC_IRQChannel = USART1_IRQn;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="135"> class="hljs-ln-code"> class="hljs-ln-line"> NVIC_InitStructure .NVIC_IRQChannelPreemptionPriority = 0 ;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="136"> class="hljs-ln-code"> class="hljs-ln-line"> NVIC_InitStructure .NVIC_IRQChannelSubPriority = 0;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="137"> class="hljs-ln-code"> class="hljs-ln-line"> NVIC_InitStructure .NVIC_IRQChannelCmd = ENABLE;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="138"> class="hljs-ln-code"> class="hljs-ln-line"> NVIC_Init(&NVIC_InitStructure);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="139"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="140"> class="hljs-ln-code"> class="hljs-ln-line"> USART_Cmd(USART1, ENABLE);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="141"> class="hljs-ln-code"> class="hljs-ln-line">#endif
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="142"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="143"> class="hljs-ln-code"> class="hljs-ln-line">#ifdef USE_HAL_DRIVER
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="144"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="145"> class="hljs-ln-code"> class="hljs-ln-line"> __HAL_RCC_GPIOA_CLK_ENABLE();
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="146"> class="hljs-ln-code"> class="hljs-ln-line"> __HAL_RCC_USART1_CLK_ENABLE();
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="147"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="148"> class="hljs-ln-code"> class="hljs-ln-line"> __HAL_RCC_USART1_FORCE_RESET();
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="149"> class="hljs-ln-code"> class="hljs-ln-line"> __HAL_RCC_USART1_RELEASE_RESET();
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="150"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="151"> class="hljs-ln-code"> class="hljs-ln-line"> GPIO_InitTypeDef GPIO_InitStruct = {0};
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="152"> class="hljs-ln-code"> class="hljs-ln-line"> GPIO_InitStruct.Pin = GPIO_PIN_9 ;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="153"> class="hljs-ln-code"> class="hljs-ln-line"> GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="154"> class="hljs-ln-code"> class="hljs-ln-line"> GPIO_InitStruct.Pull = GPIO_NOPULL;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="155"> class="hljs-ln-code"> class="hljs-ln-line"> GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="156"> class="hljs-ln-code"> class="hljs-ln-line"> HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="157"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="158"> class="hljs-ln-code"> class="hljs-ln-line"> GPIO_InitStruct.Pin = GPIO_PIN_10;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="159"> class="hljs-ln-code"> class="hljs-ln-line"> GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="160"> class="hljs-ln-code"> class="hljs-ln-line"> GPIO_InitStruct.Pull = GPIO_PULLUP;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="161"> class="hljs-ln-code"> class="hljs-ln-line"> GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="162"> class="hljs-ln-code"> class="hljs-ln-line"> HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="163"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="164"> class="hljs-ln-code"> class="hljs-ln-line"> float temp;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="165"> class="hljs-ln-code"> class="hljs-ln-line"> uint16_t mantissa, fraction;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="166"> class="hljs-ln-code"> class="hljs-ln-line"> SystemCoreClockUpdate();
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="167"> class="hljs-ln-code"> class="hljs-ln-line"> temp = (float)SystemCoreClock / (ulBaudrate * 16);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="168"> class="hljs-ln-code"> class="hljs-ln-line"> mantissa = temp;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="169"> class="hljs-ln-code"> class="hljs-ln-line"> fraction = (temp - mantissa) * 16;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="170"> class="hljs-ln-code"> class="hljs-ln-line"> USART1 -> BRR = mantissa << 4 | fraction;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="171"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="172"> class="hljs-ln-code"> class="hljs-ln-line"> USART1 -> CR1 = 0;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="173"> class="hljs-ln-code"> class="hljs-ln-line"> USART1 -> CR1 |= 0x01 << 2;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="174"> class="hljs-ln-code"> class="hljs-ln-line"> USART1 -> CR1 |= 0x01 << 3;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="175"> class="hljs-ln-code"> class="hljs-ln-line"> USART1 -> CR1 |= 0x00 << 9;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="176"> class="hljs-ln-code"> class="hljs-ln-line"> USART1 -> CR1 |= 0x00 << 10;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="177"> class="hljs-ln-code"> class="hljs-ln-line"> USART1 -> CR1 |= 0x00 << 12;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="178"> class="hljs-ln-code"> class="hljs-ln-line"> USART1 -> CR2 = 0;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="179"> class="hljs-ln-code"> class="hljs-ln-line"> USART1 -> CR2 &= ~(0x03 << 12);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="180"> class="hljs-ln-code"> class="hljs-ln-line"> USART1 -> CR3 = 0;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="181"> class="hljs-ln-code"> class="hljs-ln-line"> USART1 -> CR3 &= ~(0x01 << 6);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="182"> class="hljs-ln-code"> class="hljs-ln-line"> USART1 -> CR3 &= ~(0x01 << 7);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="183"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="184"> class="hljs-ln-code"> class="hljs-ln-line"> USART1 -> CR1 &= ~(0x01 << 7);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="185"> class="hljs-ln-code"> class="hljs-ln-line"> USART1 -> CR1 |= 0x01 << 5;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="186"> class="hljs-ln-code"> class="hljs-ln-line"> USART1 -> CR1 |= 0x01 << 4;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="187"> class="hljs-ln-code"> class="hljs-ln-line"> USART1 -> SR = ~(0x00F0);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="188"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="189"> class="hljs-ln-code"> class="hljs-ln-line"> HAL_NVIC_SetPriority(USART1_IRQn, 0, 0);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="190"> class="hljs-ln-code"> class="hljs-ln-line"> HAL_NVIC_EnableIRQ(USART1_IRQn);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="191"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="192"> class="hljs-ln-code"> class="hljs-ln-line"> USART1 -> CR1 |= 0x01 << 13;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="193"> class="hljs-ln-code"> class="hljs-ln-line">#endif
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="194"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="195"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="196"> class="hljs-ln-code"> class="hljs-ln-line"> xUART1.puRxData = uaUART1RxData;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="197"> class="hljs-ln-code"> class="hljs-ln-line"> xUART1.puTxFiFoData = uaUART1TxFiFoData;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="198"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="199"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="200"> class="hljs-ln-code"> class="hljs-ln-line"> printf("\r\r\r=========== STM32F103 外设 初始化报告 ===========\r");
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="201"> class="hljs-ln-code"> class="hljs-ln-line"> SystemCoreClockUpdate();
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="202"> class="hljs-ln-code"> class="hljs-ln-line"> printf("系统时钟频率 %d MHz\r", SystemCoreClock / 1000000);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="203"> class="hljs-ln-code"> class="hljs-ln-line"> printf("UART1 初始化配置 %d-None-8-1; 已完成初始化配置、收发配置\r", ulBaudrate);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="204"> class="hljs-ln-code"> class="hljs-ln-line">}
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="205"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="206"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="207"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="208"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="209"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="210"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="211"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="212"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="213"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="214"> class="hljs-ln-code"> class="hljs-ln-line">void USART1_IRQHandler(void)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="215"> class="hljs-ln-code"> class="hljs-ln-line">{
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="216"> class="hljs-ln-code"> class="hljs-ln-line"> static uint16_t cnt = 0;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="217"> class="hljs-ln-code"> class="hljs-ln-line"> static uint8_t rxTemp[UART1_RX_BUF_SIZE];
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="218"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="219"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="220"> class="hljs-ln-code"> class="hljs-ln-line"> if ((USART1->SR & USART_SR_TXE) && (USART1->CR1 & USART_CR1_TXEIE))
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="221"> class="hljs-ln-code"> class="hljs-ln-line"> {
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="222"> class="hljs-ln-code"> class="hljs-ln-line"> USART1->DR = xUART1.puTxFiFoData[xUART1.usTxFiFoTail++];
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="223"> class="hljs-ln-code"> class="hljs-ln-line"> if (xUART1.usTxFiFoTail == UART1_TX_BUF_SIZE)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="224"> class="hljs-ln-code"> class="hljs-ln-line"> xUART1.usTxFiFoTail = 0;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="225"> class="hljs-ln-code"> class="hljs-ln-line"> if (xUART1.usTxFiFoTail == xUART1.usTxFiFoData)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="226"> class="hljs-ln-code"> class="hljs-ln-line"> USART1->CR1 &= ~USART_CR1_TXEIE;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="227"> class="hljs-ln-code"> class="hljs-ln-line"> return;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="228"> class="hljs-ln-code"> class="hljs-ln-line"> }
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="229"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="230"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="231"> class="hljs-ln-code"> class="hljs-ln-line"> if (USART1->SR & USART_SR_RXNE)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="232"> class="hljs-ln-code"> class="hljs-ln-line"> {
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="233"> class="hljs-ln-code"> class="hljs-ln-line"> if (cnt == UART1_RX_BUF_SIZE)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="234"> class="hljs-ln-code"> class="hljs-ln-line"> {
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="235"> class="hljs-ln-code"> class="hljs-ln-line"> printf("警告:UART1单帧接收量,已超出接收缓存大小!\r修改文件bsp_UART.h的UART1_RX_BUF_SIZE值,可解决此问题!\r");
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="236"> class="hljs-ln-code"> class="hljs-ln-line"> USART1->DR;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="237"> class="hljs-ln-code"> class="hljs-ln-line"> return;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="238"> class="hljs-ln-code"> class="hljs-ln-line"> }
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="239"> class="hljs-ln-code"> class="hljs-ln-line"> rxTemp[cnt++] = USART1->DR ;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="240"> class="hljs-ln-code"> class="hljs-ln-line"> return;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="241"> class="hljs-ln-code"> class="hljs-ln-line"> }
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="242"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="243"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="244"> class="hljs-ln-code"> class="hljs-ln-line"> if (USART1->SR & USART_SR_IDLE)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="245"> class="hljs-ln-code"> class="hljs-ln-line"> {
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="246"> class="hljs-ln-code"> class="hljs-ln-line"> memcpy(xUART1.puRxData, rxTemp, UART1_RX_BUF_SIZE);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="247"> class="hljs-ln-code"> class="hljs-ln-line"> xUART1.usRxNum = cnt;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="248"> class="hljs-ln-code"> class="hljs-ln-line"> cnt = 0;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="249"> class="hljs-ln-code"> class="hljs-ln-line"> memset(rxTemp, 0, UART1_RX_BUF_SIZE);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="250"> class="hljs-ln-code"> class="hljs-ln-line"> USART1 ->SR;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="251"> class="hljs-ln-code"> class="hljs-ln-line"> USART1 ->DR;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="252"> class="hljs-ln-code"> class="hljs-ln-line"> return;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="253"> class="hljs-ln-code"> class="hljs-ln-line"> }
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="254"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="255"> class="hljs-ln-code"> class="hljs-ln-line"> return;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="256"> class="hljs-ln-code"> class="hljs-ln-line">}
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="257"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="258"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="259"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="260"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="261"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="262"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="263"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="264"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="265"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="266"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="267"> class="hljs-ln-code"> class="hljs-ln-line">void UART1_SendData(uint8_t *puData, uint16_t usNum)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="268"> class="hljs-ln-code"> class="hljs-ln-line">{
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="269"> class="hljs-ln-code"> class="hljs-ln-line"> for (uint16_t i = 0; i < usNum; i++)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="270"> class="hljs-ln-code"> class="hljs-ln-line"> {
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="271"> class="hljs-ln-code"> class="hljs-ln-line"> xUART1.puTxFiFoData[xUART1.usTxFiFoData++] = puData[i];
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="272"> class="hljs-ln-code"> class="hljs-ln-line"> if (xUART1.usTxFiFoData == UART1_TX_BUF_SIZE)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="273"> class="hljs-ln-code"> class="hljs-ln-line"> xUART1.usTxFiFoData = 0;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="274"> class="hljs-ln-code"> class="hljs-ln-line"> }
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="275"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="276"> class="hljs-ln-code"> class="hljs-ln-line"> if ((USART1->CR1 & USART_CR1_TXEIE) == 0)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="277"> class="hljs-ln-code"> class="hljs-ln-line"> USART1->CR1 |= USART_CR1_TXEIE;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="278"> class="hljs-ln-code"> class="hljs-ln-line">}
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="279"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="280"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="281"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="282"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="283"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="284"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="285"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="286"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="287"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="288"> class="hljs-ln-code"> class="hljs-ln-line">void UART1_SendString(const char *pcString, ...)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="289"> class="hljs-ln-code"> class="hljs-ln-line">{
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="290"> class="hljs-ln-code"> class="hljs-ln-line"> char mBuffer[512] = {0};;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="291"> class="hljs-ln-code"> class="hljs-ln-line"> va_list ap;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="292"> class="hljs-ln-code"> class="hljs-ln-line"> va_start(ap, pcString);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="293"> class="hljs-ln-code"> class="hljs-ln-line"> vsnprintf(mBuffer, 512, pcString, ap);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="294"> class="hljs-ln-code"> class="hljs-ln-line"> va_end(ap);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="295"> class="hljs-ln-code"> class="hljs-ln-line"> UART1_SendData((uint8_t *)mBuffer, strlen(mBuffer));
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="296"> class="hljs-ln-code"> class="hljs-ln-line">}
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="297"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="298"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="299"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="300"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="301"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="302"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="303"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="304"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="305"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="306"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="307"> class="hljs-ln-code"> class="hljs-ln-line">uint8_t UART1_SendAT(char *pcAT, char *pcAckString, uint16_t usTimeOutMs)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="308"> class="hljs-ln-code"> class="hljs-ln-line">{
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="309"> class="hljs-ln-code"> class="hljs-ln-line"> UART1_ClearRx();
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="310"> class="hljs-ln-code"> class="hljs-ln-line"> UART1_SendString(pcAT);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="311"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="312"> class="hljs-ln-code"> class="hljs-ln-line"> while (usTimeOutMs--)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="313"> class="hljs-ln-code"> class="hljs-ln-line"> {
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="314"> class="hljs-ln-code"> class="hljs-ln-line"> if (UART1_GetRxNum())
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="315"> class="hljs-ln-code"> class="hljs-ln-line"> {
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="316"> class="hljs-ln-code"> class="hljs-ln-line"> UART1_ClearRx();
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="317"> class="hljs-ln-code"> class="hljs-ln-line"> if (strstr((char *)UART1_GetRxData(), pcAckString))
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="318"> class="hljs-ln-code"> class="hljs-ln-line"> return 1;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="319"> class="hljs-ln-code"> class="hljs-ln-line"> }
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="320"> class="hljs-ln-code"> class="hljs-ln-line"> delay_ms(1);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="321"> class="hljs-ln-code"> class="hljs-ln-line"> }
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="322"> class="hljs-ln-code"> class="hljs-ln-line"> return 0;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="323"> class="hljs-ln-code"> class="hljs-ln-line">}
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="324"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="325"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="326"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="327"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="328"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="329"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="330"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="331"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="332"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="333"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="334"> class="hljs-ln-code"> class="hljs-ln-line">#if 0
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="335"> class="hljs-ln-code"> class="hljs-ln-line">void UART1_SendStringForDMA(char *stringTemp)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="336"> class="hljs-ln-code"> class="hljs-ln-line">{
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="337"> class="hljs-ln-code"> class="hljs-ln-line"> static uint8_t Flag_DmaTxInit = 0;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="338"> class="hljs-ln-code"> class="hljs-ln-line"> uint32_t num = 0;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="339"> class="hljs-ln-code"> class="hljs-ln-line"> char *t = stringTemp ;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="340"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="341"> class="hljs-ln-code"> class="hljs-ln-line"> while (*t++ != 0) num++;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="342"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="343"> class="hljs-ln-code"> class="hljs-ln-line"> while (DMA1_Channel4->CNDTR > 0);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="344"> class="hljs-ln-code"> class="hljs-ln-line"> if (Flag_DmaTxInit == 0)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="345"> class="hljs-ln-code"> class="hljs-ln-line"> {
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="346"> class="hljs-ln-code"> class="hljs-ln-line"> Flag_DmaTxInit = 1;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="347"> class="hljs-ln-code"> class="hljs-ln-line"> USART1 ->CR3 |= 1 << 7;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="348"> class="hljs-ln-code"> class="hljs-ln-line"> RCC->AHBENR |= 1 << 0;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="349"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="350"> class="hljs-ln-code"> class="hljs-ln-line"> DMA1_Channel4->CCR = 0;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="351"> class="hljs-ln-code"> class="hljs-ln-line"> DMA1_Channel4->CNDTR = num;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="352"> class="hljs-ln-code"> class="hljs-ln-line"> DMA1_Channel4->CMAR = (uint32_t)stringTemp;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="353"> class="hljs-ln-code"> class="hljs-ln-line"> DMA1_Channel4->CPAR = (uint32_t)&USART1->DR;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="354"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="355"> class="hljs-ln-code"> class="hljs-ln-line"> DMA1_Channel4->CCR |= 1 << 4;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="356"> class="hljs-ln-code"> class="hljs-ln-line"> DMA1_Channel4->CCR |= 0 << 5;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="357"> class="hljs-ln-code"> class="hljs-ln-line"> DMA1_Channel4->CCR |= 0 << 6;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="358"> class="hljs-ln-code"> class="hljs-ln-line"> DMA1_Channel4->CCR |= 1 << 7;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="359"> class="hljs-ln-code"> class="hljs-ln-line"> DMA1_Channel4->CCR |= 0 << 8;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="360"> class="hljs-ln-code"> class="hljs-ln-line"> DMA1_Channel4->CCR |= 0 << 10;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="361"> class="hljs-ln-code"> class="hljs-ln-line"> DMA1_Channel4->CCR |= 0 << 12;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="362"> class="hljs-ln-code"> class="hljs-ln-line"> DMA1_Channel4->CCR |= 0 << 14;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="363"> class="hljs-ln-code"> class="hljs-ln-line"> }
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="364"> class="hljs-ln-code"> class="hljs-ln-line"> DMA1_Channel4->CCR &= ~((uint32_t)(1 << 0));
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="365"> class="hljs-ln-code"> class="hljs-ln-line"> DMA1_Channel4->CNDTR = num;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="366"> class="hljs-ln-code"> class="hljs-ln-line"> DMA1_Channel4->CMAR = (uint32_t)stringTemp;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="367"> class="hljs-ln-code"> class="hljs-ln-line"> DMA1_Channel4->CCR |= 1 << 0;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="368"> class="hljs-ln-code"> class="hljs-ln-line">}
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="369"> class="hljs-ln-code"> class="hljs-ln-line">#endif
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="370"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="371"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="372"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="373"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="374"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="375"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="376"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="377"> class="hljs-ln-code"> class="hljs-ln-line">uint16_t UART1_GetRxNum(void)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="378"> class="hljs-ln-code"> class="hljs-ln-line">{
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="379"> class="hljs-ln-code"> class="hljs-ln-line"> return xUART1.usRxNum ;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="380"> class="hljs-ln-code"> class="hljs-ln-line">}
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="381"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="382"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="383"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="384"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="385"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="386"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="387"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="388"> class="hljs-ln-code"> class="hljs-ln-line">uint8_t *UART1_GetRxData(void)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="389"> class="hljs-ln-code"> class="hljs-ln-line">{
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="390"> class="hljs-ln-code"> class="hljs-ln-line"> return xUART1.puRxData ;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="391"> class="hljs-ln-code"> class="hljs-ln-line">}
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="392"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="393"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="394"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="395"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="396"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="397"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="398"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="399"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="400"> class="hljs-ln-code"> class="hljs-ln-line">void UART1_ClearRx(void)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="401"> class="hljs-ln-code"> class="hljs-ln-line">{
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="402"> class="hljs-ln-code"> class="hljs-ln-line"> xUART1.usRxNum = 0 ;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="403"> class="hljs-ln-code"> class="hljs-ln-line">}
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="404"> class="hljs-ln-code"> class="hljs-ln-line">#endif
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="405"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="406"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="407"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="408"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="409"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="410"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="411"> class="hljs-ln-code"> class="hljs-ln-line">/
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="412"> class="hljs-ln-code"> class="hljs-ln-line">#if UART2_EN
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="413"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="414"> class="hljs-ln-code"> class="hljs-ln-line">static xUSATR_TypeDef xUART2 = { 0 };
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="415"> class="hljs-ln-code"> class="hljs-ln-line">static uint8_t uaUART2RxData[UART2_RX_BUF_SIZE];
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="416"> class="hljs-ln-code"> class="hljs-ln-line">static uint8_t uaUART2TxFiFoData[UART2_TX_BUF_SIZE];
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="417"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="418"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="419"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="420"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="421"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="422"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="423"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="424"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="425"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="426"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="427"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="428"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="429"> class="hljs-ln-code"> class="hljs-ln-line">void UART2_Init(uint32_t ulBaudrate)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="430"> class="hljs-ln-code"> class="hljs-ln-line">{
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="431"> class="hljs-ln-code"> class="hljs-ln-line">#ifdef USE_STDPERIPH_DRIVER
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="432"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="433"> class="hljs-ln-code"> class="hljs-ln-line"> RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="434"> class="hljs-ln-code"> class="hljs-ln-line"> RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="435"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="436"> class="hljs-ln-code"> class="hljs-ln-line"> RCC_APB1PeriphResetCmd(RCC_APB1Periph_USART2, ENABLE);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="437"> class="hljs-ln-code"> class="hljs-ln-line"> RCC_APB1PeriphResetCmd(RCC_APB1Periph_USART2, DISABLE);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="438"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="439"> class="hljs-ln-code"> class="hljs-ln-line"> GPIO_InitTypeDef GPIO_InitStructure = {0};
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="440"> class="hljs-ln-code"> class="hljs-ln-line"> GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="441"> class="hljs-ln-code"> class="hljs-ln-line"> GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="442"> class="hljs-ln-code"> class="hljs-ln-line"> GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="443"> class="hljs-ln-code"> class="hljs-ln-line"> GPIO_Init(GPIOA, &GPIO_InitStructure);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="444"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="445"> class="hljs-ln-code"> class="hljs-ln-line"> GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="446"> class="hljs-ln-code"> class="hljs-ln-line"> GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="447"> class="hljs-ln-code"> class="hljs-ln-line"> GPIO_Init(GPIOA, &GPIO_InitStructure);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="448"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="449"> class="hljs-ln-code"> class="hljs-ln-line"> USART_DeInit(USART2);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="450"> class="hljs-ln-code"> class="hljs-ln-line"> USART_InitTypeDef USART_InitStructure = {0};
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="451"> class="hljs-ln-code"> class="hljs-ln-line"> USART_InitStructure.USART_BaudRate = ulBaudrate;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="452"> class="hljs-ln-code"> class="hljs-ln-line"> USART_InitStructure.USART_WordLength = USART_WordLength_8b;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="453"> class="hljs-ln-code"> class="hljs-ln-line"> USART_InitStructure.USART_StopBits = USART_StopBits_1;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="454"> class="hljs-ln-code"> class="hljs-ln-line"> USART_InitStructure.USART_Parity = USART_Parity_No;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="455"> class="hljs-ln-code"> class="hljs-ln-line"> USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="456"> class="hljs-ln-code"> class="hljs-ln-line"> USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="457"> class="hljs-ln-code"> class="hljs-ln-line"> USART_Init(USART2, &USART_InitStructure);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="458"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="459"> class="hljs-ln-code"> class="hljs-ln-line"> USART_ITConfig(USART2, USART_IT_TXE, DISABLE);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="460"> class="hljs-ln-code"> class="hljs-ln-line"> USART_ITConfig(USART2, USART_IT_RXNE, ENABLE);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="461"> class="hljs-ln-code"> class="hljs-ln-line"> USART_ITConfig(USART2, USART_IT_IDLE, ENABLE);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="462"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="463"> class="hljs-ln-code"> class="hljs-ln-line"> NVIC_InitTypeDef NVIC_InitStructure = {0};
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="464"> class="hljs-ln-code"> class="hljs-ln-line"> NVIC_InitStructure .NVIC_IRQChannel = USART2_IRQn;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="465"> class="hljs-ln-code"> class="hljs-ln-line"> NVIC_InitStructure .NVIC_IRQChannelPreemptionPriority = 0 ;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="466"> class="hljs-ln-code"> class="hljs-ln-line"> NVIC_InitStructure .NVIC_IRQChannelSubPriority = 0;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="467"> class="hljs-ln-code"> class="hljs-ln-line"> NVIC_InitStructure .NVIC_IRQChannelCmd = ENABLE;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="468"> class="hljs-ln-code"> class="hljs-ln-line"> NVIC_Init(&NVIC_InitStructure);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="469"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="470"> class="hljs-ln-code"> class="hljs-ln-line"> USART_Cmd(USART2, ENABLE);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="471"> class="hljs-ln-code"> class="hljs-ln-line">#endif
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="472"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="473"> class="hljs-ln-code"> class="hljs-ln-line">#ifdef USE_HAL_DRIVER
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="474"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="475"> class="hljs-ln-code"> class="hljs-ln-line"> __HAL_RCC_GPIOA_CLK_ENABLE();
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="476"> class="hljs-ln-code"> class="hljs-ln-line"> __HAL_RCC_USART2_CLK_ENABLE();
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="477"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="478"> class="hljs-ln-code"> class="hljs-ln-line"> __HAL_RCC_USART2_FORCE_RESET();
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="479"> class="hljs-ln-code"> class="hljs-ln-line"> __HAL_RCC_USART2_RELEASE_RESET();
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="480"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="481"> class="hljs-ln-code"> class="hljs-ln-line"> GPIO_InitTypeDef GPIO_InitStruct = {0};
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="482"> class="hljs-ln-code"> class="hljs-ln-line"> GPIO_InitStruct.Pin = GPIO_PIN_2 ;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="483"> class="hljs-ln-code"> class="hljs-ln-line"> GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="484"> class="hljs-ln-code"> class="hljs-ln-line"> GPIO_InitStruct.Pull = GPIO_NOPULL;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="485"> class="hljs-ln-code"> class="hljs-ln-line"> GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="486"> class="hljs-ln-code"> class="hljs-ln-line"> HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="487"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="488"> class="hljs-ln-code"> class="hljs-ln-line"> GPIO_InitStruct.Pin = GPIO_PIN_3;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="489"> class="hljs-ln-code"> class="hljs-ln-line"> GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="490"> class="hljs-ln-code"> class="hljs-ln-line"> GPIO_InitStruct.Pull = GPIO_PULLUP;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="491"> class="hljs-ln-code"> class="hljs-ln-line"> GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="492"> class="hljs-ln-code"> class="hljs-ln-line"> HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="493"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="494"> class="hljs-ln-code"> class="hljs-ln-line"> float temp;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="495"> class="hljs-ln-code"> class="hljs-ln-line"> uint16_t mantissa, fraction;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="496"> class="hljs-ln-code"> class="hljs-ln-line"> SystemCoreClockUpdate();
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="497"> class="hljs-ln-code"> class="hljs-ln-line"> temp = (float)(SystemCoreClock / 2) / (ulBaudrate * 16);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="498"> class="hljs-ln-code"> class="hljs-ln-line"> mantissa = temp;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="499"> class="hljs-ln-code"> class="hljs-ln-line"> fraction = (temp - mantissa) * 16;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="500"> class="hljs-ln-code"> class="hljs-ln-line"> USART2 -> BRR = mantissa << 4 | fraction;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="501"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="502"> class="hljs-ln-code"> class="hljs-ln-line"> USART2 -> CR1 = 0;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="503"> class="hljs-ln-code"> class="hljs-ln-line"> USART2 -> CR1 |= 0x01 << 2;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="504"> class="hljs-ln-code"> class="hljs-ln-line"> USART2 -> CR1 |= 0x01 << 3;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="505"> class="hljs-ln-code"> class="hljs-ln-line"> USART2 -> CR1 |= 0x00 << 9;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="506"> class="hljs-ln-code"> class="hljs-ln-line"> USART2 -> CR1 |= 0x00 << 10;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="507"> class="hljs-ln-code"> class="hljs-ln-line"> USART2 -> CR1 |= 0x00 << 12;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="508"> class="hljs-ln-code"> class="hljs-ln-line"> USART2 -> CR2 = 0;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="509"> class="hljs-ln-code"> class="hljs-ln-line"> USART2 -> CR2 &= ~(0x03 << 12);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="510"> class="hljs-ln-code"> class="hljs-ln-line"> USART2 -> CR3 = 0;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="511"> class="hljs-ln-code"> class="hljs-ln-line"> USART2 -> CR3 &= ~(0x01 << 6);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="512"> class="hljs-ln-code"> class="hljs-ln-line"> USART2 -> CR3 &= ~(0x01 << 7);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="513"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="514"> class="hljs-ln-code"> class="hljs-ln-line"> USART2 -> CR1 &= ~(0x01 << 7);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="515"> class="hljs-ln-code"> class="hljs-ln-line"> USART2 -> CR1 |= 0x01 << 5;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="516"> class="hljs-ln-code"> class="hljs-ln-line"> USART2 -> CR1 |= 0x01 << 4;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="517"> class="hljs-ln-code"> class="hljs-ln-line"> USART2 -> SR = ~(0x00F0);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="518"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="519"> class="hljs-ln-code"> class="hljs-ln-line"> HAL_NVIC_SetPriority(USART2_IRQn, 0, 0);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="520"> class="hljs-ln-code"> class="hljs-ln-line"> HAL_NVIC_EnableIRQ(USART2_IRQn);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="521"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="522"> class="hljs-ln-code"> class="hljs-ln-line"> USART2 -> CR1 |= 0x01 << 13;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="523"> class="hljs-ln-code"> class="hljs-ln-line">#endif
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="524"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="525"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="526"> class="hljs-ln-code"> class="hljs-ln-line"> xUART2.puRxData = uaUART2RxData;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="527"> class="hljs-ln-code"> class="hljs-ln-line"> xUART2.puTxFiFoData = uaUART2TxFiFoData;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="528"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="529"> class="hljs-ln-code"> class="hljs-ln-line"> printf("UART2 初始化配置 %d-None-8-1; 已完成初始化配置、收发配置\r", ulBaudrate);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="530"> class="hljs-ln-code"> class="hljs-ln-line">}
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="531"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="532"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="533"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="534"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="535"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="536"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="537"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="538"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="539"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="540"> class="hljs-ln-code"> class="hljs-ln-line">void USART2_IRQHandler(void)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="541"> class="hljs-ln-code"> class="hljs-ln-line">{
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="542"> class="hljs-ln-code"> class="hljs-ln-line"> static uint16_t cnt = 0;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="543"> class="hljs-ln-code"> class="hljs-ln-line"> static uint8_t rxTemp[UART2_RX_BUF_SIZE];
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="544"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="545"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="546"> class="hljs-ln-code"> class="hljs-ln-line"> if ((USART2->SR & USART_SR_TXE) && (USART2->CR1 & USART_CR1_TXEIE))
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="547"> class="hljs-ln-code"> class="hljs-ln-line"> {
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="548"> class="hljs-ln-code"> class="hljs-ln-line"> USART2->DR = xUART2.puTxFiFoData[xUART2.usTxFiFoTail++];
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="549"> class="hljs-ln-code"> class="hljs-ln-line"> if (xUART2.usTxFiFoTail == UART2_TX_BUF_SIZE)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="550"> class="hljs-ln-code"> class="hljs-ln-line"> xUART2.usTxFiFoTail = 0;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="551"> class="hljs-ln-code"> class="hljs-ln-line"> if (xUART2.usTxFiFoTail == xUART2.usTxFiFoData)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="552"> class="hljs-ln-code"> class="hljs-ln-line"> USART2->CR1 &= ~USART_CR1_TXEIE;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="553"> class="hljs-ln-code"> class="hljs-ln-line"> return;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="554"> class="hljs-ln-code"> class="hljs-ln-line"> }
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="555"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="556"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="557"> class="hljs-ln-code"> class="hljs-ln-line"> if (USART2->SR & USART_SR_RXNE)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="558"> class="hljs-ln-code"> class="hljs-ln-line"> {
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="559"> class="hljs-ln-code"> class="hljs-ln-line"> if (cnt == UART2_RX_BUF_SIZE)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="560"> class="hljs-ln-code"> class="hljs-ln-line"> {
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="561"> class="hljs-ln-code"> class="hljs-ln-line"> printf("警告:UART2单帧接收量,已超出接收缓存大小!\r修改文件bsp_UART.h的UART2_RX_BUF_SIZE值,可解决此问题!\r");
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="562"> class="hljs-ln-code"> class="hljs-ln-line"> USART2->DR;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="563"> class="hljs-ln-code"> class="hljs-ln-line"> return;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="564"> class="hljs-ln-code"> class="hljs-ln-line"> }
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="565"> class="hljs-ln-code"> class="hljs-ln-line"> rxTemp[cnt++] = USART2->DR ;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="566"> class="hljs-ln-code"> class="hljs-ln-line"> return;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="567"> class="hljs-ln-code"> class="hljs-ln-line"> }
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="568"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="569"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="570"> class="hljs-ln-code"> class="hljs-ln-line"> if (USART2->SR & USART_SR_IDLE)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="571"> class="hljs-ln-code"> class="hljs-ln-line"> {
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="572"> class="hljs-ln-code"> class="hljs-ln-line"> memcpy(xUART2.puRxData, rxTemp, UART2_RX_BUF_SIZE);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="573"> class="hljs-ln-code"> class="hljs-ln-line"> xUART2.usRxNum = cnt;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="574"> class="hljs-ln-code"> class="hljs-ln-line"> cnt = 0;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="575"> class="hljs-ln-code"> class="hljs-ln-line"> memset(rxTemp, 0, UART2_RX_BUF_SIZE);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="576"> class="hljs-ln-code"> class="hljs-ln-line"> USART2 ->SR;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="577"> class="hljs-ln-code"> class="hljs-ln-line"> USART2 ->DR;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="578"> class="hljs-ln-code"> class="hljs-ln-line"> return;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="579"> class="hljs-ln-code"> class="hljs-ln-line"> }
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="580"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="581"> class="hljs-ln-code"> class="hljs-ln-line"> return;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="582"> class="hljs-ln-code"> class="hljs-ln-line">}
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="583"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="584"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="585"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="586"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="587"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="588"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="589"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="590"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="591"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="592"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="593"> class="hljs-ln-code"> class="hljs-ln-line">void UART2_SendData(uint8_t *puData, uint16_t usNum)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="594"> class="hljs-ln-code"> class="hljs-ln-line">{
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="595"> class="hljs-ln-code"> class="hljs-ln-line"> for (uint16_t i = 0; i < usNum; i++)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="596"> class="hljs-ln-code"> class="hljs-ln-line"> {
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="597"> class="hljs-ln-code"> class="hljs-ln-line"> xUART2.puTxFiFoData[xUART2.usTxFiFoData++] = puData[i];
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="598"> class="hljs-ln-code"> class="hljs-ln-line"> if (xUART2.usTxFiFoData == UART2_TX_BUF_SIZE)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="599"> class="hljs-ln-code"> class="hljs-ln-line"> xUART2.usTxFiFoData = 0;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="600"> class="hljs-ln-code"> class="hljs-ln-line"> }
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="601"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="602"> class="hljs-ln-code"> class="hljs-ln-line"> if ((USART2->CR1 & USART_CR1_TXEIE) == 0)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="603"> class="hljs-ln-code"> class="hljs-ln-line"> USART2->CR1 |= USART_CR1_TXEIE;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="604"> class="hljs-ln-code"> class="hljs-ln-line">}
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="605"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="606"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="607"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="608"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="609"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="610"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="611"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="612"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="613"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="614"> class="hljs-ln-code"> class="hljs-ln-line">void UART2_SendString(const char *pcString, ...)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="615"> class="hljs-ln-code"> class="hljs-ln-line">{
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="616"> class="hljs-ln-code"> class="hljs-ln-line"> char mBuffer[512] = {0};;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="617"> class="hljs-ln-code"> class="hljs-ln-line"> va_list ap;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="618"> class="hljs-ln-code"> class="hljs-ln-line"> va_start(ap, pcString);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="619"> class="hljs-ln-code"> class="hljs-ln-line"> vsnprintf(mBuffer, 512, pcString, ap);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="620"> class="hljs-ln-code"> class="hljs-ln-line"> va_end(ap);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="621"> class="hljs-ln-code"> class="hljs-ln-line"> UART2_SendData((uint8_t *)mBuffer, strlen(mBuffer));
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="622"> class="hljs-ln-code"> class="hljs-ln-line">}
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="623"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="624"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="625"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="626"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="627"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="628"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="629"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="630"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="631"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="632"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="633"> class="hljs-ln-code"> class="hljs-ln-line">uint8_t UART2_SendAT(char *pcAT, char *pcAckString, uint16_t usTimeOutMs)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="634"> class="hljs-ln-code"> class="hljs-ln-line">{
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="635"> class="hljs-ln-code"> class="hljs-ln-line"> UART2_ClearRx();
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="636"> class="hljs-ln-code"> class="hljs-ln-line"> UART2_SendString(pcAT);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="637"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="638"> class="hljs-ln-code"> class="hljs-ln-line"> while (usTimeOutMs--)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="639"> class="hljs-ln-code"> class="hljs-ln-line"> {
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="640"> class="hljs-ln-code"> class="hljs-ln-line"> if (UART2_GetRxNum())
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="641"> class="hljs-ln-code"> class="hljs-ln-line"> {
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="642"> class="hljs-ln-code"> class="hljs-ln-line"> UART2_ClearRx();
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="643"> class="hljs-ln-code"> class="hljs-ln-line"> if (strstr((char *)UART2_GetRxData(), pcAckString))
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="644"> class="hljs-ln-code"> class="hljs-ln-line"> return 1;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="645"> class="hljs-ln-code"> class="hljs-ln-line"> }
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="646"> class="hljs-ln-code"> class="hljs-ln-line"> delay_ms(1);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="647"> class="hljs-ln-code"> class="hljs-ln-line"> }
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="648"> class="hljs-ln-code"> class="hljs-ln-line"> return 0;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="649"> class="hljs-ln-code"> class="hljs-ln-line">}
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="650"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="651"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="652"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="653"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="654"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="655"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="656"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="657"> class="hljs-ln-code"> class="hljs-ln-line">uint16_t UART2_GetRxNum(void)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="658"> class="hljs-ln-code"> class="hljs-ln-line">{
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="659"> class="hljs-ln-code"> class="hljs-ln-line"> return xUART2.usRxNum ;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="660"> class="hljs-ln-code"> class="hljs-ln-line">}
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="661"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="662"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="663"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="664"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="665"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="666"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="667"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="668"> class="hljs-ln-code"> class="hljs-ln-line">uint8_t *UART2_GetRxData(void)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="669"> class="hljs-ln-code"> class="hljs-ln-line">{
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="670"> class="hljs-ln-code"> class="hljs-ln-line"> return xUART2.puRxData ;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="671"> class="hljs-ln-code"> class="hljs-ln-line">}
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="672"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="673"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="674"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="675"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="676"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="677"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="678"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="679"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="680"> class="hljs-ln-code"> class="hljs-ln-line">void UART2_ClearRx(void)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="681"> class="hljs-ln-code"> class="hljs-ln-line">{
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="682"> class="hljs-ln-code"> class="hljs-ln-line"> xUART2.usRxNum = 0 ;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="683"> class="hljs-ln-code"> class="hljs-ln-line">}
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="684"> class="hljs-ln-code"> class="hljs-ln-line">#endif
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="685"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="686"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="687"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="688"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="689"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="690"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="691"> class="hljs-ln-code"> class="hljs-ln-line">/
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="692"> class="hljs-ln-code"> class="hljs-ln-line">#if UART3_EN
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="693"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="694"> class="hljs-ln-code"> class="hljs-ln-line">static xUSATR_TypeDef xUART3 = { 0 };
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="695"> class="hljs-ln-code"> class="hljs-ln-line">static uint8_t uaUart3RxData[UART3_RX_BUF_SIZE];
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="696"> class="hljs-ln-code"> class="hljs-ln-line">static uint8_t uaUart3TxFiFoData[UART3_TX_BUF_SIZE];
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="697"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="698"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="699"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="700"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="701"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="702"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="703"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="704"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="705"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="706"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="707"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="708"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="709"> class="hljs-ln-code"> class="hljs-ln-line">void UART3_Init(uint32_t ulBaudrate)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="710"> class="hljs-ln-code"> class="hljs-ln-line">{
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="711"> class="hljs-ln-code"> class="hljs-ln-line">#ifdef USE_STDPERIPH_DRIVER
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="712"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="713"> class="hljs-ln-code"> class="hljs-ln-line"> RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="714"> class="hljs-ln-code"> class="hljs-ln-line"> RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, ENABLE);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="715"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="716"> class="hljs-ln-code"> class="hljs-ln-line"> RCC_APB1PeriphResetCmd(RCC_APB1Periph_USART3, ENABLE);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="717"> class="hljs-ln-code"> class="hljs-ln-line"> RCC_APB1PeriphResetCmd(RCC_APB1Periph_USART3, DISABLE);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="718"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="719"> class="hljs-ln-code"> class="hljs-ln-line"> GPIO_InitTypeDef GPIO_InitStructure = {0};
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="720"> class="hljs-ln-code"> class="hljs-ln-line"> GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="721"> class="hljs-ln-code"> class="hljs-ln-line"> GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="722"> class="hljs-ln-code"> class="hljs-ln-line"> GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="723"> class="hljs-ln-code"> class="hljs-ln-line"> GPIO_Init(GPIOB, &GPIO_InitStructure);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="724"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="725"> class="hljs-ln-code"> class="hljs-ln-line"> GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="726"> class="hljs-ln-code"> class="hljs-ln-line"> GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="727"> class="hljs-ln-code"> class="hljs-ln-line"> GPIO_Init(GPIOB, &GPIO_InitStructure);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="728"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="729"> class="hljs-ln-code"> class="hljs-ln-line"> USART_DeInit(USART3);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="730"> class="hljs-ln-code"> class="hljs-ln-line"> USART_InitTypeDef USART_InitStructure = {0};
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="731"> class="hljs-ln-code"> class="hljs-ln-line"> USART_InitStructure.USART_BaudRate = ulBaudrate;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="732"> class="hljs-ln-code"> class="hljs-ln-line"> USART_InitStructure.USART_WordLength = USART_WordLength_8b;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="733"> class="hljs-ln-code"> class="hljs-ln-line"> USART_InitStructure.USART_StopBits = USART_StopBits_1;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="734"> class="hljs-ln-code"> class="hljs-ln-line"> USART_InitStructure.USART_Parity = USART_Parity_No;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="735"> class="hljs-ln-code"> class="hljs-ln-line"> USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="736"> class="hljs-ln-code"> class="hljs-ln-line"> USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="737"> class="hljs-ln-code"> class="hljs-ln-line"> USART_Init(USART3, &USART_InitStructure);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="738"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="739"> class="hljs-ln-code"> class="hljs-ln-line"> USART_ITConfig(USART3, USART_IT_TXE, DISABLE);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="740"> class="hljs-ln-code"> class="hljs-ln-line"> USART_ITConfig(USART3, USART_IT_RXNE, ENABLE);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="741"> class="hljs-ln-code"> class="hljs-ln-line"> USART_ITConfig(USART3, USART_IT_IDLE, ENABLE);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="742"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="743"> class="hljs-ln-code"> class="hljs-ln-line"> NVIC_InitTypeDef NVIC_InitStructure = {0};
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="744"> class="hljs-ln-code"> class="hljs-ln-line"> NVIC_InitStructure .NVIC_IRQChannel = USART3_IRQn;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="745"> class="hljs-ln-code"> class="hljs-ln-line"> NVIC_InitStructure .NVIC_IRQChannelPreemptionPriority = 0 ;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="746"> class="hljs-ln-code"> class="hljs-ln-line"> NVIC_InitStructure .NVIC_IRQChannelSubPriority = 0;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="747"> class="hljs-ln-code"> class="hljs-ln-line"> NVIC_InitStructure .NVIC_IRQChannelCmd = ENABLE;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="748"> class="hljs-ln-code"> class="hljs-ln-line"> NVIC_Init(&NVIC_InitStructure);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="749"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="750"> class="hljs-ln-code"> class="hljs-ln-line"> USART_Cmd(USART3, ENABLE);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="751"> class="hljs-ln-code"> class="hljs-ln-line">#endif
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="752"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="753"> class="hljs-ln-code"> class="hljs-ln-line">#ifdef USE_HAL_DRIVER
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="754"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="755"> class="hljs-ln-code"> class="hljs-ln-line"> __HAL_RCC_GPIOB_CLK_ENABLE();
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="756"> class="hljs-ln-code"> class="hljs-ln-line"> __HAL_RCC_USART3_CLK_ENABLE();
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="757"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="758"> class="hljs-ln-code"> class="hljs-ln-line"> __HAL_RCC_USART3_FORCE_RESET();
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="759"> class="hljs-ln-code"> class="hljs-ln-line"> __HAL_RCC_USART3_RELEASE_RESET();
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="760"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="761"> class="hljs-ln-code"> class="hljs-ln-line"> GPIO_InitTypeDef GPIO_InitStruct = {0};
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="762"> class="hljs-ln-code"> class="hljs-ln-line"> GPIO_InitStruct.Pin = GPIO_PIN_10 ;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="763"> class="hljs-ln-code"> class="hljs-ln-line"> GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="764"> class="hljs-ln-code"> class="hljs-ln-line"> GPIO_InitStruct.Pull = GPIO_NOPULL;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="765"> class="hljs-ln-code"> class="hljs-ln-line"> GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="766"> class="hljs-ln-code"> class="hljs-ln-line"> HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="767"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="768"> class="hljs-ln-code"> class="hljs-ln-line"> GPIO_InitStruct.Pin = GPIO_PIN_11;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="769"> class="hljs-ln-code"> class="hljs-ln-line"> GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="770"> class="hljs-ln-code"> class="hljs-ln-line"> GPIO_InitStruct.Pull = GPIO_PULLUP;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="771"> class="hljs-ln-code"> class="hljs-ln-line"> GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="772"> class="hljs-ln-code"> class="hljs-ln-line"> HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="773"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="774"> class="hljs-ln-code"> class="hljs-ln-line"> float temp;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="775"> class="hljs-ln-code"> class="hljs-ln-line"> uint16_t mantissa, fraction;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="776"> class="hljs-ln-code"> class="hljs-ln-line"> SystemCoreClockUpdate();
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="777"> class="hljs-ln-code"> class="hljs-ln-line"> temp = (float)(SystemCoreClock / 2) / (ulBaudrate * 16);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="778"> class="hljs-ln-code"> class="hljs-ln-line"> mantissa = temp;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="779"> class="hljs-ln-code"> class="hljs-ln-line"> fraction = (temp - mantissa) * 16;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="780"> class="hljs-ln-code"> class="hljs-ln-line"> USART3 -> BRR = mantissa << 4 | fraction;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="781"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="782"> class="hljs-ln-code"> class="hljs-ln-line"> USART3 -> CR1 = 0;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="783"> class="hljs-ln-code"> class="hljs-ln-line"> USART3 -> CR1 |= 0x01 << 2;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="784"> class="hljs-ln-code"> class="hljs-ln-line"> USART3 -> CR1 |= 0x01 << 3;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="785"> class="hljs-ln-code"> class="hljs-ln-line"> USART3 -> CR1 |= 0x00 << 9;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="786"> class="hljs-ln-code"> class="hljs-ln-line"> USART3 -> CR1 |= 0x00 << 10;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="787"> class="hljs-ln-code"> class="hljs-ln-line"> USART3 -> CR1 |= 0x00 << 12;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="788"> class="hljs-ln-code"> class="hljs-ln-line"> USART3 -> CR2 = 0;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="789"> class="hljs-ln-code"> class="hljs-ln-line"> USART3 -> CR2 &= ~(0x03 << 12);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="790"> class="hljs-ln-code"> class="hljs-ln-line"> USART3 -> CR3 = 0;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="791"> class="hljs-ln-code"> class="hljs-ln-line"> USART3 -> CR3 &= ~(0x01 << 6);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="792"> class="hljs-ln-code"> class="hljs-ln-line"> USART3 -> CR3 &= ~(0x01 << 7);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="793"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="794"> class="hljs-ln-code"> class="hljs-ln-line"> USART3 -> CR1 &= ~(0x01 << 7);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="795"> class="hljs-ln-code"> class="hljs-ln-line"> USART3 -> CR1 |= 0x01 << 5;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="796"> class="hljs-ln-code"> class="hljs-ln-line"> USART3 -> CR1 |= 0x01 << 4;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="797"> class="hljs-ln-code"> class="hljs-ln-line"> USART3 -> SR = ~(0x00F0);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="798"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="799"> class="hljs-ln-code"> class="hljs-ln-line"> HAL_NVIC_SetPriority(USART3_IRQn, 0, 0);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="800"> class="hljs-ln-code"> class="hljs-ln-line"> HAL_NVIC_EnableIRQ(USART3_IRQn);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="801"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="802"> class="hljs-ln-code"> class="hljs-ln-line"> USART3 -> CR1 |= 0x01 << 13;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="803"> class="hljs-ln-code"> class="hljs-ln-line">#endif
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="804"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="805"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="806"> class="hljs-ln-code"> class="hljs-ln-line"> xUART3.puRxData = uaUart3RxData;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="807"> class="hljs-ln-code"> class="hljs-ln-line"> xUART3.puTxFiFoData = uaUart3TxFiFoData;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="808"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="809"> class="hljs-ln-code"> class="hljs-ln-line"> printf("UART3 初始化配置 %d-None-8-1; 已完成初始化配置、收发配置\r", ulBaudrate);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="810"> class="hljs-ln-code"> class="hljs-ln-line">}
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="811"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="812"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="813"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="814"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="815"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="816"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="817"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="818"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="819"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="820"> class="hljs-ln-code"> class="hljs-ln-line">void USART3_IRQHandler(void)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="821"> class="hljs-ln-code"> class="hljs-ln-line">{
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="822"> class="hljs-ln-code"> class="hljs-ln-line"> static uint16_t cnt = 0;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="823"> class="hljs-ln-code"> class="hljs-ln-line"> static uint8_t rxTemp[UART3_RX_BUF_SIZE];
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="824"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="825"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="826"> class="hljs-ln-code"> class="hljs-ln-line"> if ((USART3->SR & USART_SR_TXE) && (USART3->CR1 & USART_CR1_TXEIE))
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="827"> class="hljs-ln-code"> class="hljs-ln-line"> {
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="828"> class="hljs-ln-code"> class="hljs-ln-line"> USART3->DR = xUART3.puTxFiFoData[xUART3.usTxFiFoTail++];
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="829"> class="hljs-ln-code"> class="hljs-ln-line"> if (xUART3.usTxFiFoTail == UART3_TX_BUF_SIZE)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="830"> class="hljs-ln-code"> class="hljs-ln-line"> xUART3.usTxFiFoTail = 0;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="831"> class="hljs-ln-code"> class="hljs-ln-line"> if (xUART3.usTxFiFoTail == xUART3.usTxFiFoData)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="832"> class="hljs-ln-code"> class="hljs-ln-line"> USART3->CR1 &= ~USART_CR1_TXEIE;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="833"> class="hljs-ln-code"> class="hljs-ln-line"> return;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="834"> class="hljs-ln-code"> class="hljs-ln-line"> }
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="835"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="836"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="837"> class="hljs-ln-code"> class="hljs-ln-line"> if (USART3->SR & USART_SR_RXNE)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="838"> class="hljs-ln-code"> class="hljs-ln-line"> {
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="839"> class="hljs-ln-code"> class="hljs-ln-line"> if (cnt == UART3_RX_BUF_SIZE)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="840"> class="hljs-ln-code"> class="hljs-ln-line"> {
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="841"> class="hljs-ln-code"> class="hljs-ln-line"> printf("警告:UART3单帧接收量,已超出接收缓存大小!\r修改文件bsp_UART.h的UART3_RX_BUF_SIZE值,可解决此问题!\r");
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="842"> class="hljs-ln-code"> class="hljs-ln-line"> USART3->DR;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="843"> class="hljs-ln-code"> class="hljs-ln-line"> return;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="844"> class="hljs-ln-code"> class="hljs-ln-line"> }
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="845"> class="hljs-ln-code"> class="hljs-ln-line"> rxTemp[cnt++] = USART3->DR ;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="846"> class="hljs-ln-code"> class="hljs-ln-line"> return;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="847"> class="hljs-ln-code"> class="hljs-ln-line"> }
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="848"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="849"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="850"> class="hljs-ln-code"> class="hljs-ln-line"> if (USART3->SR & USART_SR_IDLE)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="851"> class="hljs-ln-code"> class="hljs-ln-line"> {
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="852"> class="hljs-ln-code"> class="hljs-ln-line"> memcpy(xUART3.puRxData, rxTemp, UART3_RX_BUF_SIZE);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="853"> class="hljs-ln-code"> class="hljs-ln-line"> xUART3.usRxNum = cnt;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="854"> class="hljs-ln-code"> class="hljs-ln-line"> cnt = 0;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="855"> class="hljs-ln-code"> class="hljs-ln-line"> memset(rxTemp, 0, UART3_RX_BUF_SIZE);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="856"> class="hljs-ln-code"> class="hljs-ln-line"> USART3 ->SR;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="857"> class="hljs-ln-code"> class="hljs-ln-line"> USART3 ->DR;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="858"> class="hljs-ln-code"> class="hljs-ln-line"> return;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="859"> class="hljs-ln-code"> class="hljs-ln-line"> }
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="860"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="861"> class="hljs-ln-code"> class="hljs-ln-line"> return;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="862"> class="hljs-ln-code"> class="hljs-ln-line">}
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="863"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="864"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="865"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="866"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="867"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="868"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="869"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="870"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="871"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="872"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="873"> class="hljs-ln-code"> class="hljs-ln-line">void UART3_SendData(uint8_t *puData, uint16_t usNum)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="874"> class="hljs-ln-code"> class="hljs-ln-line">{
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="875"> class="hljs-ln-code"> class="hljs-ln-line"> for (uint16_t i = 0; i < usNum; i++)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="876"> class="hljs-ln-code"> class="hljs-ln-line"> {
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="877"> class="hljs-ln-code"> class="hljs-ln-line"> xUART3.puTxFiFoData[xUART3.usTxFiFoData++] = puData[i];
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="878"> class="hljs-ln-code"> class="hljs-ln-line"> if (xUART3.usTxFiFoData == UART3_TX_BUF_SIZE)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="879"> class="hljs-ln-code"> class="hljs-ln-line"> xUART3.usTxFiFoData = 0;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="880"> class="hljs-ln-code"> class="hljs-ln-line"> }
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="881"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="882"> class="hljs-ln-code"> class="hljs-ln-line"> if ((USART3->CR1 & USART_CR1_TXEIE) == 0)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="883"> class="hljs-ln-code"> class="hljs-ln-line"> USART3->CR1 |= USART_CR1_TXEIE;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="884"> class="hljs-ln-code"> class="hljs-ln-line">}
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="885"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="886"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="887"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="888"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="889"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="890"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="891"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="892"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="893"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="894"> class="hljs-ln-code"> class="hljs-ln-line">void UART3_SendString(const char *pcString, ...)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="895"> class="hljs-ln-code"> class="hljs-ln-line">{
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="896"> class="hljs-ln-code"> class="hljs-ln-line"> char mBuffer[512] = {0};;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="897"> class="hljs-ln-code"> class="hljs-ln-line"> va_list ap;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="898"> class="hljs-ln-code"> class="hljs-ln-line"> va_start(ap, pcString);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="899"> class="hljs-ln-code"> class="hljs-ln-line"> vsnprintf(mBuffer, 512, pcString, ap);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="900"> class="hljs-ln-code"> class="hljs-ln-line"> va_end(ap);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="901"> class="hljs-ln-code"> class="hljs-ln-line"> UART3_SendData((uint8_t *)mBuffer, strlen(mBuffer));
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="902"> class="hljs-ln-code"> class="hljs-ln-line">}
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="903"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="904"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="905"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="906"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="907"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="908"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="909"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="910"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="911"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="912"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="913"> class="hljs-ln-code"> class="hljs-ln-line">uint8_t UART3_SendAT(char *pcAT, char *pcAckString, uint16_t usTimeOutMs)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="914"> class="hljs-ln-code"> class="hljs-ln-line">{
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="915"> class="hljs-ln-code"> class="hljs-ln-line"> UART3_ClearRx();
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="916"> class="hljs-ln-code"> class="hljs-ln-line"> UART3_SendString(pcAT);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="917"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="918"> class="hljs-ln-code"> class="hljs-ln-line"> while (usTimeOutMs--)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="919"> class="hljs-ln-code"> class="hljs-ln-line"> {
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="920"> class="hljs-ln-code"> class="hljs-ln-line"> if (UART3_GetRxNum())
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="921"> class="hljs-ln-code"> class="hljs-ln-line"> {
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="922"> class="hljs-ln-code"> class="hljs-ln-line"> UART3_ClearRx();
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="923"> class="hljs-ln-code"> class="hljs-ln-line"> if (strstr((char *)UART3_GetRxData(), pcAckString))
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="924"> class="hljs-ln-code"> class="hljs-ln-line"> return 1;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="925"> class="hljs-ln-code"> class="hljs-ln-line"> }
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="926"> class="hljs-ln-code"> class="hljs-ln-line"> delay_ms(1);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="927"> class="hljs-ln-code"> class="hljs-ln-line"> }
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="928"> class="hljs-ln-code"> class="hljs-ln-line"> return 0;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="929"> class="hljs-ln-code"> class="hljs-ln-line">}
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="930"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="931"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="932"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="933"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="934"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="935"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="936"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="937"> class="hljs-ln-code"> class="hljs-ln-line">uint16_t UART3_GetRxNum(void)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="938"> class="hljs-ln-code"> class="hljs-ln-line">{
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="939"> class="hljs-ln-code"> class="hljs-ln-line"> return xUART3.usRxNum ;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="940"> class="hljs-ln-code"> class="hljs-ln-line">}
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="941"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="942"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="943"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="944"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="945"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="946"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="947"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="948"> class="hljs-ln-code"> class="hljs-ln-line">uint8_t *UART3_GetRxData(void)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="949"> class="hljs-ln-code"> class="hljs-ln-line">{
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="950"> class="hljs-ln-code"> class="hljs-ln-line"> return xUART3.puRxData ;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="951"> class="hljs-ln-code"> class="hljs-ln-line">}
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="952"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="953"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="954"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="955"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="956"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="957"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="958"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="959"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="960"> class="hljs-ln-code"> class="hljs-ln-line">void UART3_ClearRx(void)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="961"> class="hljs-ln-code"> class="hljs-ln-line">{
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="962"> class="hljs-ln-code"> class="hljs-ln-line"> xUART3.usRxNum = 0 ;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="963"> class="hljs-ln-code"> class="hljs-ln-line">}
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="964"> class="hljs-ln-code"> class="hljs-ln-line">#endif
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="965"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="966"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="967"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="968"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="969"> class="hljs-ln-code"> class="hljs-ln-line">#ifdef STM32F10X_HD
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="970"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="971"> class="hljs-ln-code"> class="hljs-ln-line">/
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="972"> class="hljs-ln-code"> class="hljs-ln-line">#if UART4_EN
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="973"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="974"> class="hljs-ln-code"> class="hljs-ln-line">static xUSATR_TypeDef xUART4 = { 0 };
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="975"> class="hljs-ln-code"> class="hljs-ln-line">static uint8_t uaUart4RxData[UART4_RX_BUF_SIZE];
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="976"> class="hljs-ln-code"> class="hljs-ln-line">static uint8_t uaUart4TxFiFoData[UART4_TX_BUF_SIZE];
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="977"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="978"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="979"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="980"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="981"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="982"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="983"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="984"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="985"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="986"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="987"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="988"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="989"> class="hljs-ln-code"> class="hljs-ln-line">void UART4_Init(uint32_t ulBaudrate)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="990"> class="hljs-ln-code"> class="hljs-ln-line">{
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="991"> class="hljs-ln-code"> class="hljs-ln-line">#ifdef USE_STDPERIPH_DRIVER
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="992"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="993"> class="hljs-ln-code"> class="hljs-ln-line"> RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="994"> class="hljs-ln-code"> class="hljs-ln-line"> RCC_APB1PeriphClockCmd(RCC_APB1Periph_UART4, ENABLE);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="995"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="996"> class="hljs-ln-code"> class="hljs-ln-line"> RCC_APB1PeriphResetCmd(RCC_APB1Periph_UART4, ENABLE);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="997"> class="hljs-ln-code"> class="hljs-ln-line"> RCC_APB1PeriphResetCmd(RCC_APB1Periph_UART4, DISABLE);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="998"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="999"> class="hljs-ln-code"> class="hljs-ln-line"> GPIO_InitTypeDef GPIO_InitStructure = {0};
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1000"> class="hljs-ln-code"> class="hljs-ln-line"> GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1001"> class="hljs-ln-code"> class="hljs-ln-line"> GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1002"> class="hljs-ln-code"> class="hljs-ln-line"> GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1003"> class="hljs-ln-code"> class="hljs-ln-line"> GPIO_Init(GPIOC, &GPIO_InitStructure);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1004"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1005"> class="hljs-ln-code"> class="hljs-ln-line"> GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1006"> class="hljs-ln-code"> class="hljs-ln-line"> GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1007"> class="hljs-ln-code"> class="hljs-ln-line"> GPIO_Init(GPIOC, &GPIO_InitStructure);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1008"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1009"> class="hljs-ln-code"> class="hljs-ln-line"> USART_DeInit(UART4);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1010"> class="hljs-ln-code"> class="hljs-ln-line"> USART_InitTypeDef USART_InitStructure = {0};
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1011"> class="hljs-ln-code"> class="hljs-ln-line"> USART_InitStructure.USART_BaudRate = ulBaudrate;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1012"> class="hljs-ln-code"> class="hljs-ln-line"> USART_InitStructure.USART_WordLength = USART_WordLength_8b;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1013"> class="hljs-ln-code"> class="hljs-ln-line"> USART_InitStructure.USART_StopBits = USART_StopBits_1;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1014"> class="hljs-ln-code"> class="hljs-ln-line"> USART_InitStructure.USART_Parity = USART_Parity_No;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1015"> class="hljs-ln-code"> class="hljs-ln-line"> USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1016"> class="hljs-ln-code"> class="hljs-ln-line"> USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1017"> class="hljs-ln-code"> class="hljs-ln-line"> USART_Init(UART4, &USART_InitStructure);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1018"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1019"> class="hljs-ln-code"> class="hljs-ln-line"> USART_ITConfig(UART4, USART_IT_TXE, DISABLE);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1020"> class="hljs-ln-code"> class="hljs-ln-line"> USART_ITConfig(UART4, USART_IT_RXNE, ENABLE);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1021"> class="hljs-ln-code"> class="hljs-ln-line"> USART_ITConfig(UART4, USART_IT_IDLE, ENABLE);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1022"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1023"> class="hljs-ln-code"> class="hljs-ln-line"> NVIC_InitTypeDef NVIC_InitStructure = {0};
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1024"> class="hljs-ln-code"> class="hljs-ln-line"> NVIC_InitStructure .NVIC_IRQChannel = UART4_IRQn;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1025"> class="hljs-ln-code"> class="hljs-ln-line"> NVIC_InitStructure .NVIC_IRQChannelPreemptionPriority = 0 ;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1026"> class="hljs-ln-code"> class="hljs-ln-line"> NVIC_InitStructure .NVIC_IRQChannelSubPriority = 0;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1027"> class="hljs-ln-code"> class="hljs-ln-line"> NVIC_InitStructure .NVIC_IRQChannelCmd = ENABLE;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1028"> class="hljs-ln-code"> class="hljs-ln-line"> NVIC_Init(&NVIC_InitStructure);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1029"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1030"> class="hljs-ln-code"> class="hljs-ln-line"> USART_Cmd(UART4, ENABLE);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1031"> class="hljs-ln-code"> class="hljs-ln-line">#endif
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1032"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1033"> class="hljs-ln-code"> class="hljs-ln-line">#ifdef USE_HAL_DRIVER
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1034"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1035"> class="hljs-ln-code"> class="hljs-ln-line"> __HAL_RCC_GPIOC_CLK_ENABLE();
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1036"> class="hljs-ln-code"> class="hljs-ln-line"> __HAL_RCC_UART4_CLK_ENABLE();
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1037"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1038"> class="hljs-ln-code"> class="hljs-ln-line"> __HAL_RCC_UART4_FORCE_RESET();
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1039"> class="hljs-ln-code"> class="hljs-ln-line"> __HAL_RCC_UART4_RELEASE_RESET();
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1040"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1041"> class="hljs-ln-code"> class="hljs-ln-line"> GPIO_InitTypeDef GPIO_InitStruct = {0};
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1042"> class="hljs-ln-code"> class="hljs-ln-line"> GPIO_InitStruct.Pin = GPIO_PIN_10 ;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1043"> class="hljs-ln-code"> class="hljs-ln-line"> GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1044"> class="hljs-ln-code"> class="hljs-ln-line"> GPIO_InitStruct.Pull = GPIO_NOPULL;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1045"> class="hljs-ln-code"> class="hljs-ln-line"> GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1046"> class="hljs-ln-code"> class="hljs-ln-line"> HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1047"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1048"> class="hljs-ln-code"> class="hljs-ln-line"> GPIO_InitStruct.Pin = GPIO_PIN_11;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1049"> class="hljs-ln-code"> class="hljs-ln-line"> GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1050"> class="hljs-ln-code"> class="hljs-ln-line"> GPIO_InitStruct.Pull = GPIO_PULLUP;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1051"> class="hljs-ln-code"> class="hljs-ln-line"> GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1052"> class="hljs-ln-code"> class="hljs-ln-line"> HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1053"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1054"> class="hljs-ln-code"> class="hljs-ln-line"> float temp;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1055"> class="hljs-ln-code"> class="hljs-ln-line"> uint16_t mantissa, fraction;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1056"> class="hljs-ln-code"> class="hljs-ln-line"> SystemCoreClockUpdate();
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1057"> class="hljs-ln-code"> class="hljs-ln-line"> temp = (float)(SystemCoreClock / 2) / (ulBaudrate * 16);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1058"> class="hljs-ln-code"> class="hljs-ln-line"> mantissa = temp;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1059"> class="hljs-ln-code"> class="hljs-ln-line"> fraction = (temp - mantissa) * 16;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1060"> class="hljs-ln-code"> class="hljs-ln-line"> UART4 -> BRR = mantissa << 4 | fraction;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1061"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1062"> class="hljs-ln-code"> class="hljs-ln-line"> UART4 -> CR1 = 0;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1063"> class="hljs-ln-code"> class="hljs-ln-line"> UART4 -> CR1 |= 0x01 << 2;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1064"> class="hljs-ln-code"> class="hljs-ln-line"> UART4 -> CR1 |= 0x01 << 3;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1065"> class="hljs-ln-code"> class="hljs-ln-line"> UART4 -> CR1 |= 0x00 << 9;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1066"> class="hljs-ln-code"> class="hljs-ln-line"> UART4 -> CR1 |= 0x00 << 10;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1067"> class="hljs-ln-code"> class="hljs-ln-line"> UART4 -> CR1 |= 0x00 << 12;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1068"> class="hljs-ln-code"> class="hljs-ln-line"> UART4 -> CR2 = 0;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1069"> class="hljs-ln-code"> class="hljs-ln-line"> UART4 -> CR2 &= ~(0x03 << 12);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1070"> class="hljs-ln-code"> class="hljs-ln-line"> UART4 -> CR3 = 0;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1071"> class="hljs-ln-code"> class="hljs-ln-line"> UART4 -> CR3 &= ~(0x01 << 6);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1072"> class="hljs-ln-code"> class="hljs-ln-line"> UART4 -> CR3 &= ~(0x01 << 7);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1073"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1074"> class="hljs-ln-code"> class="hljs-ln-line"> UART4 -> CR1 &= ~(0x01 << 7);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1075"> class="hljs-ln-code"> class="hljs-ln-line"> UART4 -> CR1 |= 0x01 << 5;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1076"> class="hljs-ln-code"> class="hljs-ln-line"> UART4 -> CR1 |= 0x01 << 4;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1077"> class="hljs-ln-code"> class="hljs-ln-line"> UART4 -> SR = ~(0x00F0);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1078"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1079"> class="hljs-ln-code"> class="hljs-ln-line"> HAL_NVIC_SetPriority(UART4_IRQn, 0, 0);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1080"> class="hljs-ln-code"> class="hljs-ln-line"> HAL_NVIC_EnableIRQ(UART4_IRQn);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1081"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1082"> class="hljs-ln-code"> class="hljs-ln-line"> UART4 -> CR1 |= 0x01 << 13;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1083"> class="hljs-ln-code"> class="hljs-ln-line">#endif
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1084"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1085"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1086"> class="hljs-ln-code"> class="hljs-ln-line"> xUART4.puRxData = uaUart4RxData;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1087"> class="hljs-ln-code"> class="hljs-ln-line"> xUART4.puTxFiFoData = uaUart4TxFiFoData;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1088"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1089"> class="hljs-ln-code"> class="hljs-ln-line"> printf("UART4 初始化配置 %d-None-8-1; 已完成初始化配置、收发配置\r", ulBaudrate);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1090"> class="hljs-ln-code"> class="hljs-ln-line">}
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1091"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1092"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1093"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1094"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1095"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1096"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1097"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1098"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1099"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1100"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1101"> class="hljs-ln-code"> class="hljs-ln-line">void UART4_IRQHandler(void)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1102"> class="hljs-ln-code"> class="hljs-ln-line">{
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1103"> class="hljs-ln-code"> class="hljs-ln-line"> static uint16_t cnt = 0;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1104"> class="hljs-ln-code"> class="hljs-ln-line"> static uint8_t rxTemp[UART4_RX_BUF_SIZE];
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1105"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1106"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1107"> class="hljs-ln-code"> class="hljs-ln-line"> if ((UART4->SR & USART_SR_TXE) && (UART4->CR1 & USART_CR1_TXEIE))
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1108"> class="hljs-ln-code"> class="hljs-ln-line"> {
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1109"> class="hljs-ln-code"> class="hljs-ln-line"> UART4->DR = xUART4.puTxFiFoData[xUART4.usTxFiFoTail++];
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1110"> class="hljs-ln-code"> class="hljs-ln-line"> if (xUART4.usTxFiFoTail == UART4_TX_BUF_SIZE)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1111"> class="hljs-ln-code"> class="hljs-ln-line"> xUART4.usTxFiFoTail = 0;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1112"> class="hljs-ln-code"> class="hljs-ln-line"> if (xUART4.usTxFiFoTail == xUART4.usTxFiFoData)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1113"> class="hljs-ln-code"> class="hljs-ln-line"> UART4->CR1 &= ~USART_CR1_TXEIE;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1114"> class="hljs-ln-code"> class="hljs-ln-line"> return;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1115"> class="hljs-ln-code"> class="hljs-ln-line"> }
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1116"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1117"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1118"> class="hljs-ln-code"> class="hljs-ln-line"> if (UART4->SR & USART_SR_RXNE)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1119"> class="hljs-ln-code"> class="hljs-ln-line"> {
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1120"> class="hljs-ln-code"> class="hljs-ln-line"> if (cnt == UART4_RX_BUF_SIZE)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1121"> class="hljs-ln-code"> class="hljs-ln-line"> {
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1122"> class="hljs-ln-code"> class="hljs-ln-line"> printf("警告:UART4单帧接收量,已超出接收缓存大小!\r修改文件bsp_UART.h的UART4_RX_BUF_SIZE值,可解决此问题!\r");
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1123"> class="hljs-ln-code"> class="hljs-ln-line"> UART4->DR;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1124"> class="hljs-ln-code"> class="hljs-ln-line"> return;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1125"> class="hljs-ln-code"> class="hljs-ln-line"> }
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1126"> class="hljs-ln-code"> class="hljs-ln-line"> rxTemp[cnt++] = UART4->DR ;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1127"> class="hljs-ln-code"> class="hljs-ln-line"> return;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1128"> class="hljs-ln-code"> class="hljs-ln-line"> }
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1129"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1130"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1131"> class="hljs-ln-code"> class="hljs-ln-line"> if (UART4->SR & USART_SR_IDLE)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1132"> class="hljs-ln-code"> class="hljs-ln-line"> {
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1133"> class="hljs-ln-code"> class="hljs-ln-line"> memcpy(xUART4.puRxData, rxTemp, UART4_RX_BUF_SIZE);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1134"> class="hljs-ln-code"> class="hljs-ln-line"> xUART4.usRxNum = cnt;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1135"> class="hljs-ln-code"> class="hljs-ln-line"> cnt = 0;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1136"> class="hljs-ln-code"> class="hljs-ln-line"> memset(rxTemp, 0, UART4_RX_BUF_SIZE);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1137"> class="hljs-ln-code"> class="hljs-ln-line"> UART4 ->SR;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1138"> class="hljs-ln-code"> class="hljs-ln-line"> UART4 ->DR;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1139"> class="hljs-ln-code"> class="hljs-ln-line"> return;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1140"> class="hljs-ln-code"> class="hljs-ln-line"> }
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1141"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1142"> class="hljs-ln-code"> class="hljs-ln-line"> return;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1143"> class="hljs-ln-code"> class="hljs-ln-line">}
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1144"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1145"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1146"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1147"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1148"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1149"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1150"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1151"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1152"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1153"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1154"> class="hljs-ln-code"> class="hljs-ln-line">void UART4_SendData(uint8_t *puData, uint16_t usNum)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1155"> class="hljs-ln-code"> class="hljs-ln-line">{
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1156"> class="hljs-ln-code"> class="hljs-ln-line"> for (uint16_t i = 0; i < usNum; i++)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1157"> class="hljs-ln-code"> class="hljs-ln-line"> {
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1158"> class="hljs-ln-code"> class="hljs-ln-line"> xUART4.puTxFiFoData[xUART4.usTxFiFoData++] = puData[i];
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1159"> class="hljs-ln-code"> class="hljs-ln-line"> if (xUART4.usTxFiFoData == UART4_TX_BUF_SIZE)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1160"> class="hljs-ln-code"> class="hljs-ln-line"> xUART4.usTxFiFoData = 0;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1161"> class="hljs-ln-code"> class="hljs-ln-line"> }
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1162"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1163"> class="hljs-ln-code"> class="hljs-ln-line"> if ((UART4->CR1 & USART_CR1_TXEIE) == 0)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1164"> class="hljs-ln-code"> class="hljs-ln-line"> UART4->CR1 |= USART_CR1_TXEIE;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1165"> class="hljs-ln-code"> class="hljs-ln-line">}
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1166"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1167"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1168"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1169"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1170"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1171"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1172"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1173"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1174"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1175"> class="hljs-ln-code"> class="hljs-ln-line">void UART4_SendString(const char *pcString, ...)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1176"> class="hljs-ln-code"> class="hljs-ln-line">{
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1177"> class="hljs-ln-code"> class="hljs-ln-line"> char mBuffer[512] = {0};;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1178"> class="hljs-ln-code"> class="hljs-ln-line"> va_list ap;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1179"> class="hljs-ln-code"> class="hljs-ln-line"> va_start(ap, pcString);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1180"> class="hljs-ln-code"> class="hljs-ln-line"> vsnprintf(mBuffer, 512, pcString, ap);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1181"> class="hljs-ln-code"> class="hljs-ln-line"> va_end(ap);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1182"> class="hljs-ln-code"> class="hljs-ln-line"> UART4_SendData((uint8_t *)mBuffer, strlen(mBuffer));
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1183"> class="hljs-ln-code"> class="hljs-ln-line">}
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1184"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1185"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1186"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1187"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1188"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1189"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1190"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1191"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1192"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1193"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1194"> class="hljs-ln-code"> class="hljs-ln-line">uint8_t UART4_SendAT(char *pcAT, char *pcAckString, uint16_t usTimeOutMs)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1195"> class="hljs-ln-code"> class="hljs-ln-line">{
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1196"> class="hljs-ln-code"> class="hljs-ln-line"> UART4_ClearRx();
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1197"> class="hljs-ln-code"> class="hljs-ln-line"> UART4_SendString(pcAT);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1198"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1199"> class="hljs-ln-code"> class="hljs-ln-line"> while (usTimeOutMs--)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1200"> class="hljs-ln-code"> class="hljs-ln-line"> {
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1201"> class="hljs-ln-code"> class="hljs-ln-line"> if (UART4_GetRxNum())
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1202"> class="hljs-ln-code"> class="hljs-ln-line"> {
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1203"> class="hljs-ln-code"> class="hljs-ln-line"> UART4_ClearRx();
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1204"> class="hljs-ln-code"> class="hljs-ln-line"> if (strstr((char *)UART4_GetRxData(), pcAckString))
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1205"> class="hljs-ln-code"> class="hljs-ln-line"> return 1;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1206"> class="hljs-ln-code"> class="hljs-ln-line"> }
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1207"> class="hljs-ln-code"> class="hljs-ln-line"> delay_ms(1);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1208"> class="hljs-ln-code"> class="hljs-ln-line"> }
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1209"> class="hljs-ln-code"> class="hljs-ln-line"> return 0;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1210"> class="hljs-ln-code"> class="hljs-ln-line">}
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1211"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1212"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1213"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1214"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1215"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1216"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1217"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1218"> class="hljs-ln-code"> class="hljs-ln-line">uint16_t UART4_GetRxNum(void)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1219"> class="hljs-ln-code"> class="hljs-ln-line">{
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1220"> class="hljs-ln-code"> class="hljs-ln-line"> return xUART4.usRxNum ;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1221"> class="hljs-ln-code"> class="hljs-ln-line">}
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1222"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1223"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1224"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1225"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1226"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1227"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1228"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1229"> class="hljs-ln-code"> class="hljs-ln-line">uint8_t *UART4_GetRxData(void)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1230"> class="hljs-ln-code"> class="hljs-ln-line">{
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1231"> class="hljs-ln-code"> class="hljs-ln-line"> return xUART4.puRxData ;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1232"> class="hljs-ln-code"> class="hljs-ln-line">}
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1233"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1234"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1235"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1236"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1237"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1238"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1239"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1240"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1241"> class="hljs-ln-code"> class="hljs-ln-line">void UART4_ClearRx(void)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1242"> class="hljs-ln-code"> class="hljs-ln-line">{
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1243"> class="hljs-ln-code"> class="hljs-ln-line"> xUART4.usRxNum = 0 ;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1244"> class="hljs-ln-code"> class="hljs-ln-line">}
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1245"> class="hljs-ln-code"> class="hljs-ln-line">#endif
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1246"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1247"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1248"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1249"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1250"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1251"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1252"> class="hljs-ln-code"> class="hljs-ln-line">/
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1253"> class="hljs-ln-code"> class="hljs-ln-line">#if UART5_EN
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1254"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1255"> class="hljs-ln-code"> class="hljs-ln-line">static xUSATR_TypeDef xUART5 = { 0 };
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1256"> class="hljs-ln-code"> class="hljs-ln-line">static uint8_t uaUart5RxData[UART5_RX_BUF_SIZE];
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1257"> class="hljs-ln-code"> class="hljs-ln-line">static uint8_t uaUart5TxFiFoData[UART5_TX_BUF_SIZE];
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1258"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1259"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1260"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1261"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1262"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1263"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1264"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1265"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1266"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1267"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1268"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1269"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1270"> class="hljs-ln-code"> class="hljs-ln-line">void UART5_Init(uint32_t ulBaudrate)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1271"> class="hljs-ln-code"> class="hljs-ln-line">{
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1272"> class="hljs-ln-code"> class="hljs-ln-line">#ifdef USE_STDPERIPH_DRIVER
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1273"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1274"> class="hljs-ln-code"> class="hljs-ln-line"> RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1275"> class="hljs-ln-code"> class="hljs-ln-line"> RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD, ENABLE);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1276"> class="hljs-ln-code"> class="hljs-ln-line"> RCC_APB1PeriphClockCmd(RCC_APB1Periph_UART5, ENABLE);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1277"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1278"> class="hljs-ln-code"> class="hljs-ln-line"> RCC_APB1PeriphResetCmd(RCC_APB1Periph_UART5, ENABLE);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1279"> class="hljs-ln-code"> class="hljs-ln-line"> RCC_APB1PeriphResetCmd(RCC_APB1Periph_UART5, DISABLE);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1280"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1281"> class="hljs-ln-code"> class="hljs-ln-line"> GPIO_InitTypeDef GPIO_InitStructure = {0};
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1282"> class="hljs-ln-code"> class="hljs-ln-line"> GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1283"> class="hljs-ln-code"> class="hljs-ln-line"> GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1284"> class="hljs-ln-code"> class="hljs-ln-line"> GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1285"> class="hljs-ln-code"> class="hljs-ln-line"> GPIO_Init(GPIOC, &GPIO_InitStructure);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1286"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1287"> class="hljs-ln-code"> class="hljs-ln-line"> GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1288"> class="hljs-ln-code"> class="hljs-ln-line"> GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1289"> class="hljs-ln-code"> class="hljs-ln-line"> GPIO_Init(GPIOD, &GPIO_InitStructure);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1290"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1291"> class="hljs-ln-code"> class="hljs-ln-line"> USART_DeInit(UART5);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1292"> class="hljs-ln-code"> class="hljs-ln-line"> USART_InitTypeDef USART_InitStructure = {0};
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1293"> class="hljs-ln-code"> class="hljs-ln-line"> USART_InitStructure.USART_BaudRate = ulBaudrate;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1294"> class="hljs-ln-code"> class="hljs-ln-line"> USART_InitStructure.USART_WordLength = USART_WordLength_8b;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1295"> class="hljs-ln-code"> class="hljs-ln-line"> USART_InitStructure.USART_StopBits = USART_StopBits_1;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1296"> class="hljs-ln-code"> class="hljs-ln-line"> USART_InitStructure.USART_Parity = USART_Parity_No;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1297"> class="hljs-ln-code"> class="hljs-ln-line"> USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1298"> class="hljs-ln-code"> class="hljs-ln-line"> USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1299"> class="hljs-ln-code"> class="hljs-ln-line"> USART_Init(UART5, &USART_InitStructure);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1300"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1301"> class="hljs-ln-code"> class="hljs-ln-line"> USART_ITConfig(UART5, USART_IT_TXE, DISABLE);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1302"> class="hljs-ln-code"> class="hljs-ln-line"> USART_ITConfig(UART5, USART_IT_RXNE, ENABLE);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1303"> class="hljs-ln-code"> class="hljs-ln-line"> USART_ITConfig(UART5, USART_IT_IDLE, ENABLE);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1304"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1305"> class="hljs-ln-code"> class="hljs-ln-line"> NVIC_InitTypeDef NVIC_InitStructure = {0};
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1306"> class="hljs-ln-code"> class="hljs-ln-line"> NVIC_InitStructure .NVIC_IRQChannel = UART5_IRQn;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1307"> class="hljs-ln-code"> class="hljs-ln-line"> NVIC_InitStructure .NVIC_IRQChannelPreemptionPriority = 0 ;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1308"> class="hljs-ln-code"> class="hljs-ln-line"> NVIC_InitStructure .NVIC_IRQChannelSubPriority = 0;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1309"> class="hljs-ln-code"> class="hljs-ln-line"> NVIC_InitStructure .NVIC_IRQChannelCmd = ENABLE;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1310"> class="hljs-ln-code"> class="hljs-ln-line"> NVIC_Init(&NVIC_InitStructure);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1311"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1312"> class="hljs-ln-code"> class="hljs-ln-line"> USART_Cmd(UART5, ENABLE);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1313"> class="hljs-ln-code"> class="hljs-ln-line">#endif
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1314"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1315"> class="hljs-ln-code"> class="hljs-ln-line">#ifdef USE_HAL_DRIVER
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1316"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1317"> class="hljs-ln-code"> class="hljs-ln-line"> __HAL_RCC_GPIOC_CLK_ENABLE();
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1318"> class="hljs-ln-code"> class="hljs-ln-line"> __HAL_RCC_GPIOD_CLK_ENABLE();
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1319"> class="hljs-ln-code"> class="hljs-ln-line"> __HAL_RCC_UART5_CLK_ENABLE();
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1320"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1321"> class="hljs-ln-code"> class="hljs-ln-line"> __HAL_RCC_UART5_FORCE_RESET();
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1322"> class="hljs-ln-code"> class="hljs-ln-line"> __HAL_RCC_UART5_RELEASE_RESET();
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1323"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1324"> class="hljs-ln-code"> class="hljs-ln-line"> GPIO_InitTypeDef GPIO_InitStruct = {0};
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1325"> class="hljs-ln-code"> class="hljs-ln-line"> GPIO_InitStruct.Pin = GPIO_PIN_12 ;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1326"> class="hljs-ln-code"> class="hljs-ln-line"> GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1327"> class="hljs-ln-code"> class="hljs-ln-line"> GPIO_InitStruct.Pull = GPIO_NOPULL;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1328"> class="hljs-ln-code"> class="hljs-ln-line"> GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1329"> class="hljs-ln-code"> class="hljs-ln-line"> HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1330"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1331"> class="hljs-ln-code"> class="hljs-ln-line"> GPIO_InitStruct.Pin = GPIO_PIN_2;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1332"> class="hljs-ln-code"> class="hljs-ln-line"> GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1333"> class="hljs-ln-code"> class="hljs-ln-line"> GPIO_InitStruct.Pull = GPIO_PULLUP;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1334"> class="hljs-ln-code"> class="hljs-ln-line"> GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1335"> class="hljs-ln-code"> class="hljs-ln-line"> HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1336"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1337"> class="hljs-ln-code"> class="hljs-ln-line"> float temp;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1338"> class="hljs-ln-code"> class="hljs-ln-line"> uint16_t mantissa, fraction;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1339"> class="hljs-ln-code"> class="hljs-ln-line"> SystemCoreClockUpdate();
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1340"> class="hljs-ln-code"> class="hljs-ln-line"> temp = (float)(SystemCoreClock / 2) / (ulBaudrate * 16);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1341"> class="hljs-ln-code"> class="hljs-ln-line"> mantissa = temp;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1342"> class="hljs-ln-code"> class="hljs-ln-line"> fraction = (temp - mantissa) * 16;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1343"> class="hljs-ln-code"> class="hljs-ln-line"> UART5 -> BRR = mantissa << 4 | fraction;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1344"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1345"> class="hljs-ln-code"> class="hljs-ln-line"> UART5 -> CR1 = 0;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1346"> class="hljs-ln-code"> class="hljs-ln-line"> UART5 -> CR1 |= 0x01 << 2;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1347"> class="hljs-ln-code"> class="hljs-ln-line"> UART5 -> CR1 |= 0x01 << 3;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1348"> class="hljs-ln-code"> class="hljs-ln-line"> UART5 -> CR1 |= 0x00 << 9;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1349"> class="hljs-ln-code"> class="hljs-ln-line"> UART5 -> CR1 |= 0x00 << 10;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1350"> class="hljs-ln-code"> class="hljs-ln-line"> UART5 -> CR1 |= 0x00 << 12;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1351"> class="hljs-ln-code"> class="hljs-ln-line"> UART5 -> CR2 = 0;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1352"> class="hljs-ln-code"> class="hljs-ln-line"> UART5 -> CR2 &= ~(0x03 << 12);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1353"> class="hljs-ln-code"> class="hljs-ln-line"> UART5 -> CR3 = 0;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1354"> class="hljs-ln-code"> class="hljs-ln-line"> UART5 -> CR3 &= ~(0x01 << 6);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1355"> class="hljs-ln-code"> class="hljs-ln-line"> UART5 -> CR3 &= ~(0x01 << 7);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1356"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1357"> class="hljs-ln-code"> class="hljs-ln-line"> UART5 -> CR1 &= ~(0x01 << 7);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1358"> class="hljs-ln-code"> class="hljs-ln-line"> UART5 -> CR1 |= 0x01 << 5;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1359"> class="hljs-ln-code"> class="hljs-ln-line"> UART5 -> CR1 |= 0x01 << 4;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1360"> class="hljs-ln-code"> class="hljs-ln-line"> UART5 -> SR = ~(0x00F0);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1361"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1362"> class="hljs-ln-code"> class="hljs-ln-line"> HAL_NVIC_SetPriority(UART5_IRQn, 0, 0);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1363"> class="hljs-ln-code"> class="hljs-ln-line"> HAL_NVIC_EnableIRQ(UART5_IRQn);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1364"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1365"> class="hljs-ln-code"> class="hljs-ln-line"> UART5 -> CR1 |= 0x01 << 13;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1366"> class="hljs-ln-code"> class="hljs-ln-line">#endif
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1367"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1368"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1369"> class="hljs-ln-code"> class="hljs-ln-line"> xUART5.puRxData = uaUart5RxData;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1370"> class="hljs-ln-code"> class="hljs-ln-line"> xUART5.puTxFiFoData = uaUart5TxFiFoData;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1371"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1372"> class="hljs-ln-code"> class="hljs-ln-line"> printf("UART5 初始化配置 %d-None-8-1; 已完成初始化配置、收发配置\r", ulBaudrate);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1373"> class="hljs-ln-code"> class="hljs-ln-line">}
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1374"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1375"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1376"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1377"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1378"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1379"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1380"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1381"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1382"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1383"> class="hljs-ln-code"> class="hljs-ln-line">void UART5_IRQHandler(void)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1384"> class="hljs-ln-code"> class="hljs-ln-line">{
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1385"> class="hljs-ln-code"> class="hljs-ln-line"> static uint16_t cnt = 0;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1386"> class="hljs-ln-code"> class="hljs-ln-line"> static uint8_t rxTemp[UART5_RX_BUF_SIZE];
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1387"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1388"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1389"> class="hljs-ln-code"> class="hljs-ln-line"> if ((UART5->SR & USART_SR_TXE) && (UART5->CR1 & USART_CR1_TXEIE))
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1390"> class="hljs-ln-code"> class="hljs-ln-line"> {
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1391"> class="hljs-ln-code"> class="hljs-ln-line"> UART5->DR = xUART5.puTxFiFoData[xUART5.usTxFiFoTail++];
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1392"> class="hljs-ln-code"> class="hljs-ln-line"> if (xUART5.usTxFiFoTail == UART5_TX_BUF_SIZE)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1393"> class="hljs-ln-code"> class="hljs-ln-line"> xUART5.usTxFiFoTail = 0;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1394"> class="hljs-ln-code"> class="hljs-ln-line"> if (xUART5.usTxFiFoTail == xUART5.usTxFiFoData)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1395"> class="hljs-ln-code"> class="hljs-ln-line"> UART5->CR1 &= ~USART_CR1_TXEIE;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1396"> class="hljs-ln-code"> class="hljs-ln-line"> return;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1397"> class="hljs-ln-code"> class="hljs-ln-line"> }
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1398"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1399"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1400"> class="hljs-ln-code"> class="hljs-ln-line"> if (UART5->SR & USART_SR_RXNE)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1401"> class="hljs-ln-code"> class="hljs-ln-line"> {
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1402"> class="hljs-ln-code"> class="hljs-ln-line"> if (cnt == UART5_RX_BUF_SIZE)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1403"> class="hljs-ln-code"> class="hljs-ln-line"> {
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1404"> class="hljs-ln-code"> class="hljs-ln-line"> printf("警告:UART5单帧接收量,已超出接收缓存大小!\r修改文件bsp_UART.h的UART5_RX_BUF_SIZE值,可解决此问题!\r");
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1405"> class="hljs-ln-code"> class="hljs-ln-line"> UART5->DR;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1406"> class="hljs-ln-code"> class="hljs-ln-line"> return;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1407"> class="hljs-ln-code"> class="hljs-ln-line"> }
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1408"> class="hljs-ln-code"> class="hljs-ln-line"> rxTemp[cnt++] = UART5->DR ;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1409"> class="hljs-ln-code"> class="hljs-ln-line"> return;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1410"> class="hljs-ln-code"> class="hljs-ln-line"> }
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1411"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1412"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1413"> class="hljs-ln-code"> class="hljs-ln-line"> if (UART5->SR & USART_SR_IDLE)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1414"> class="hljs-ln-code"> class="hljs-ln-line"> {
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1415"> class="hljs-ln-code"> class="hljs-ln-line"> memcpy(xUART5.puRxData, rxTemp, UART5_RX_BUF_SIZE);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1416"> class="hljs-ln-code"> class="hljs-ln-line"> xUART5.usRxNum = cnt;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1417"> class="hljs-ln-code"> class="hljs-ln-line"> cnt = 0;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1418"> class="hljs-ln-code"> class="hljs-ln-line"> memset(rxTemp, 0, UART5_RX_BUF_SIZE);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1419"> class="hljs-ln-code"> class="hljs-ln-line"> UART5 -> SR;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1420"> class="hljs-ln-code"> class="hljs-ln-line"> UART5 -> DR;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1421"> class="hljs-ln-code"> class="hljs-ln-line"> return;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1422"> class="hljs-ln-code"> class="hljs-ln-line"> }
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1423"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1424"> class="hljs-ln-code"> class="hljs-ln-line"> return;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1425"> class="hljs-ln-code"> class="hljs-ln-line">}
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1426"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1427"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1428"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1429"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1430"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1431"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1432"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1433"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1434"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1435"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1436"> class="hljs-ln-code"> class="hljs-ln-line">void UART5_SendData(uint8_t *pudata, uint16_t usNum)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1437"> class="hljs-ln-code"> class="hljs-ln-line">{
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1438"> class="hljs-ln-code"> class="hljs-ln-line"> for (uint16_t i = 0; i < usNum; i++)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1439"> class="hljs-ln-code"> class="hljs-ln-line"> {
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1440"> class="hljs-ln-code"> class="hljs-ln-line"> xUART5.puTxFiFoData[xUART5.usTxFiFoData++] = pudata[i];
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1441"> class="hljs-ln-code"> class="hljs-ln-line"> if (xUART5.usTxFiFoData == UART5_TX_BUF_SIZE)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1442"> class="hljs-ln-code"> class="hljs-ln-line"> xUART5.usTxFiFoData = 0;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1443"> class="hljs-ln-code"> class="hljs-ln-line"> }
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1444"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1445"> class="hljs-ln-code"> class="hljs-ln-line"> if ((UART5->CR1 & USART_CR1_TXEIE) == 0)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1446"> class="hljs-ln-code"> class="hljs-ln-line"> UART5->CR1 |= USART_CR1_TXEIE;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1447"> class="hljs-ln-code"> class="hljs-ln-line">}
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1448"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1449"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1450"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1451"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1452"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1453"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1454"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1455"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1456"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1457"> class="hljs-ln-code"> class="hljs-ln-line">void UART5_SendString(const char *pcString, ...)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1458"> class="hljs-ln-code"> class="hljs-ln-line">{
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1459"> class="hljs-ln-code"> class="hljs-ln-line"> char mBuffer[512] = {0};;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1460"> class="hljs-ln-code"> class="hljs-ln-line"> va_list ap;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1461"> class="hljs-ln-code"> class="hljs-ln-line"> va_start(ap, pcString);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1462"> class="hljs-ln-code"> class="hljs-ln-line"> vsnprintf(mBuffer, 512, pcString, ap);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1463"> class="hljs-ln-code"> class="hljs-ln-line"> va_end(ap);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1464"> class="hljs-ln-code"> class="hljs-ln-line"> UART5_SendData((uint8_t *)mBuffer, strlen(mBuffer));
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1465"> class="hljs-ln-code"> class="hljs-ln-line">}
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1466"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1467"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1468"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1469"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1470"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1471"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1472"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1473"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1474"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1475"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1476"> class="hljs-ln-code"> class="hljs-ln-line">uint8_t UART5_SendAT(char *pcAT, char *pcAckString, uint16_t usTimeOutMs)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1477"> class="hljs-ln-code"> class="hljs-ln-line">{
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1478"> class="hljs-ln-code"> class="hljs-ln-line"> UART5_ClearRx();
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1479"> class="hljs-ln-code"> class="hljs-ln-line"> UART5_SendString(pcAT);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1480"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1481"> class="hljs-ln-code"> class="hljs-ln-line"> while (usTimeOutMs--)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1482"> class="hljs-ln-code"> class="hljs-ln-line"> {
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1483"> class="hljs-ln-code"> class="hljs-ln-line"> if (UART5_GetRxNum())
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1484"> class="hljs-ln-code"> class="hljs-ln-line"> {
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1485"> class="hljs-ln-code"> class="hljs-ln-line"> UART5_ClearRx();
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1486"> class="hljs-ln-code"> class="hljs-ln-line"> if (strstr((char *)UART5_GetRxData(), pcAckString))
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1487"> class="hljs-ln-code"> class="hljs-ln-line"> return 1;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1488"> class="hljs-ln-code"> class="hljs-ln-line"> }
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1489"> class="hljs-ln-code"> class="hljs-ln-line"> delay_ms(1);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1490"> class="hljs-ln-code"> class="hljs-ln-line"> }
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1491"> class="hljs-ln-code"> class="hljs-ln-line"> return 0;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1492"> class="hljs-ln-code"> class="hljs-ln-line">}
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1493"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1494"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1495"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1496"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1497"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1498"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1499"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1500"> class="hljs-ln-code"> class="hljs-ln-line">uint16_t UART5_GetRxNum(void)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1501"> class="hljs-ln-code"> class="hljs-ln-line">{
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1502"> class="hljs-ln-code"> class="hljs-ln-line"> return xUART5.usRxNum ;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1503"> class="hljs-ln-code"> class="hljs-ln-line">}
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1504"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1505"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1506"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1507"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1508"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1509"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1510"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1511"> class="hljs-ln-code"> class="hljs-ln-line">uint8_t *UART5_GetRxData(void)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1512"> class="hljs-ln-code"> class="hljs-ln-line">{
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1513"> class="hljs-ln-code"> class="hljs-ln-line"> return xUART5.puRxData ;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1514"> class="hljs-ln-code"> class="hljs-ln-line">}
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1515"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1516"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1517"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1518"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1519"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1520"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1521"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1522"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1523"> class="hljs-ln-code"> class="hljs-ln-line">void UART5_ClearRx(void)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1524"> class="hljs-ln-code"> class="hljs-ln-line">{
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1525"> class="hljs-ln-code"> class="hljs-ln-line"> xUART5.usRxNum = 0 ;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1526"> class="hljs-ln-code"> class="hljs-ln-line">}
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1527"> class="hljs-ln-code"> class="hljs-ln-line">#endif
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1528"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1529"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1530"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1531"> class="hljs-ln-code"> class="hljs-ln-line">#endif
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1532"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1533"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1534"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1535"> class="hljs-ln-code"> class="hljs-ln-line">/ ModbusCRC16 校验 /
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1536"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1537"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1538"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1539"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1540"> class="hljs-ln-code"> class="hljs-ln-line">static const uint8_t aModbusCRC16[] =
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1541"> class="hljs-ln-code"> class="hljs-ln-line">{
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1542"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1543"> class="hljs-ln-code"> class="hljs-ln-line"> 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40,
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1544"> class="hljs-ln-code"> class="hljs-ln-line"> 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41,
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1545"> class="hljs-ln-code"> class="hljs-ln-line"> 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41,
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1546"> class="hljs-ln-code"> class="hljs-ln-line"> 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40,
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1547"> class="hljs-ln-code"> class="hljs-ln-line"> 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41,
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1548"> class="hljs-ln-code"> class="hljs-ln-line"> 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40,
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1549"> class="hljs-ln-code"> class="hljs-ln-line"> 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40,
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1550"> class="hljs-ln-code"> class="hljs-ln-line"> 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41,
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1551"> class="hljs-ln-code"> class="hljs-ln-line"> 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41,
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1552"> class="hljs-ln-code"> class="hljs-ln-line"> 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40,
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1553"> class="hljs-ln-code"> class="hljs-ln-line"> 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40,
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1554"> class="hljs-ln-code"> class="hljs-ln-line"> 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41,
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1555"> class="hljs-ln-code"> class="hljs-ln-line"> 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40,
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1556"> class="hljs-ln-code"> class="hljs-ln-line"> 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41,
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1557"> class="hljs-ln-code"> class="hljs-ln-line"> 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41,
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1558"> class="hljs-ln-code"> class="hljs-ln-line"> 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40,
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1559"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1560"> class="hljs-ln-code"> class="hljs-ln-line"> 0x00, 0xC0, 0xC1, 0x01, 0xC3, 0x03, 0x02, 0xC2, 0xC6, 0x06, 0x07, 0xC7, 0x05, 0xC5, 0xC4, 0x04,
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1561"> class="hljs-ln-code"> class="hljs-ln-line"> 0xCC, 0x0C, 0x0D, 0xCD, 0x0F, 0xCF, 0xCE, 0x0E, 0x0A, 0xCA, 0xCB, 0x0B, 0xC9, 0x09, 0x08, 0xC8,
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1562"> class="hljs-ln-code"> class="hljs-ln-line"> 0xD8, 0x18, 0x19, 0xD9, 0x1B, 0xDB, 0xDA, 0x1A, 0x1E, 0xDE, 0xDF, 0x1F, 0xDD, 0x1D, 0x1C, 0xDC,
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1563"> class="hljs-ln-code"> class="hljs-ln-line"> 0x14, 0xD4, 0xD5, 0x15, 0xD7, 0x17, 0x16, 0xD6, 0xD2, 0x12, 0x13, 0xD3, 0x11, 0xD1, 0xD0, 0x10,
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1564"> class="hljs-ln-code"> class="hljs-ln-line"> 0xF0, 0x30, 0x31, 0xF1, 0x33, 0xF3, 0xF2, 0x32, 0x36, 0xF6, 0xF7, 0x37, 0xF5, 0x35, 0x34, 0xF4,
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1565"> class="hljs-ln-code"> class="hljs-ln-line"> 0x3C, 0xFC, 0xFD, 0x3D, 0xFF, 0x3F, 0x3E, 0xFE, 0xFA, 0x3A, 0x3B, 0xFB, 0x39, 0xF9, 0xF8, 0x38,
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1566"> class="hljs-ln-code"> class="hljs-ln-line"> 0x28, 0xE8, 0xE9, 0x29, 0xEB, 0x2B, 0x2A, 0xEA, 0xEE, 0x2E, 0x2F, 0xEF, 0x2D, 0xED, 0xEC, 0x2C,
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1567"> class="hljs-ln-code"> class="hljs-ln-line"> 0xE4, 0x24, 0x25, 0xE5, 0x27, 0xE7, 0xE6, 0x26, 0x22, 0xE2, 0xE3, 0x23, 0xE1, 0x21, 0x20, 0xE0,
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1568"> class="hljs-ln-code"> class="hljs-ln-line"> 0xA0, 0x60, 0x61, 0xA1, 0x63, 0xA3, 0xA2, 0x62, 0x66, 0xA6, 0xA7, 0x67, 0xA5, 0x65, 0x64, 0xA4,
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1569"> class="hljs-ln-code"> class="hljs-ln-line"> 0x6C, 0xAC, 0xAD, 0x6D, 0xAF, 0x6F, 0x6E, 0xAE, 0xAA, 0x6A, 0x6B, 0xAB, 0x69, 0xA9, 0xA8, 0x68,
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1570"> class="hljs-ln-code"> class="hljs-ln-line"> 0x78, 0xB8, 0xB9, 0x79, 0xBB, 0x7B, 0x7A, 0xBA, 0xBE, 0x7E, 0x7F, 0xBF, 0x7D, 0xBD, 0xBC, 0x7C,
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1571"> class="hljs-ln-code"> class="hljs-ln-line"> 0xB4, 0x74, 0x75, 0xB5, 0x77, 0xB7, 0xB6, 0x76, 0x72, 0xB2, 0xB3, 0x73, 0xB1, 0x71, 0x70, 0xB0,
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1572"> class="hljs-ln-code"> class="hljs-ln-line"> 0x50, 0x90, 0x91, 0x51, 0x93, 0x53, 0x52, 0x92, 0x96, 0x56, 0x57, 0x97, 0x55, 0x95, 0x94, 0x54,
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1573"> class="hljs-ln-code"> class="hljs-ln-line"> 0x9C, 0x5C, 0x5D, 0x9D, 0x5F, 0x9F, 0x9E, 0x5E, 0x5A, 0x9A, 0x9B, 0x5B, 0x99, 0x59, 0x58, 0x98,
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1574"> class="hljs-ln-code"> class="hljs-ln-line"> 0x88, 0x48, 0x49, 0x89, 0x4B, 0x8B, 0x8A, 0x4A, 0x4E, 0x8E, 0x8F, 0x4F, 0x8D, 0x4D, 0x4C, 0x8C,
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1575"> class="hljs-ln-code"> class="hljs-ln-line"> 0x44, 0x84, 0x85, 0x45, 0x87, 0x47, 0x46, 0x86, 0x82, 0x42, 0x43, 0x83, 0x41, 0x81, 0x80, 0x40
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1576"> class="hljs-ln-code"> class="hljs-ln-line">};
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1577"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1578"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1579"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1580"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1581"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1582"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1583"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1584"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1585"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1586"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1587"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1588"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1589"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1590"> class="hljs-ln-code"> class="hljs-ln-line">void Modbus_AddCRC16(uint8_t *_pcData, uint16_t _usLen)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1591"> class="hljs-ln-code"> class="hljs-ln-line">{
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1592"> class="hljs-ln-code"> class="hljs-ln-line"> uint8_t ucCRCHi = 0xFF;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1593"> class="hljs-ln-code"> class="hljs-ln-line"> uint8_t ucCRCLo = 0xFF;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1594"> class="hljs-ln-code"> class="hljs-ln-line"> uint16_t usIndex;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1595"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1596"> class="hljs-ln-code"> class="hljs-ln-line"> while (_usLen--)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1597"> class="hljs-ln-code"> class="hljs-ln-line"> {
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1598"> class="hljs-ln-code"> class="hljs-ln-line"> usIndex = ucCRCHi ^ *_pcData++;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1599"> class="hljs-ln-code"> class="hljs-ln-line"> ucCRCHi = ucCRCLo ^ aModbusCRC16[usIndex];
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1600"> class="hljs-ln-code"> class="hljs-ln-line"> ucCRCLo = aModbusCRC16[usIndex + 256];
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1601"> class="hljs-ln-code"> class="hljs-ln-line"> }
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1602"> class="hljs-ln-code"> class="hljs-ln-line"> _pcData[0] = ucCRCHi;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1603"> class="hljs-ln-code"> class="hljs-ln-line"> _pcData[1] = ucCRCLo;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1604"> class="hljs-ln-code"> class="hljs-ln-line">}
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1605"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1606"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1607"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1608"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1609"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1610"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1611"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1612"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1613"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1614"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1615"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1616"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1617"> class="hljs-ln-code"> class="hljs-ln-line">uint8_t Modbus_CheckCRC16(uint8_t *_pcData, uint16_t _usLen)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1618"> class="hljs-ln-code"> class="hljs-ln-line">{
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1619"> class="hljs-ln-code"> class="hljs-ln-line"> uint8_t ucCRCHi = 0xFF;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1620"> class="hljs-ln-code"> class="hljs-ln-line"> uint8_t ucCRCLo = 0xFF;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1621"> class="hljs-ln-code"> class="hljs-ln-line"> uint16_t usIndex;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1622"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1623"> class="hljs-ln-code"> class="hljs-ln-line"> _usLen -= 2;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1624"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1625"> class="hljs-ln-code"> class="hljs-ln-line"> while (_usLen--)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1626"> class="hljs-ln-code"> class="hljs-ln-line"> {
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1627"> class="hljs-ln-code"> class="hljs-ln-line"> usIndex = ucCRCHi ^ *_pcData++;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1628"> class="hljs-ln-code"> class="hljs-ln-line"> ucCRCHi = ucCRCLo ^ aModbusCRC16[usIndex];
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1629"> class="hljs-ln-code"> class="hljs-ln-line"> ucCRCLo = aModbusCRC16[usIndex + 256];
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1630"> class="hljs-ln-code"> class="hljs-ln-line"> }
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1631"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1632"> class="hljs-ln-code"> class="hljs-ln-line"> if ((ucCRCHi == *_pcData++) && (ucCRCLo == *_pcData))
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1633"> class="hljs-ln-code"> class="hljs-ln-line"> return 1;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1634"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1635"> class="hljs-ln-code"> class="hljs-ln-line"> return 0;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1636"> class="hljs-ln-code"> class="hljs-ln-line">}
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1637"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1638"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1639"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1640"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1641"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1642"> class="hljs-ln-code"> class="hljs-ln-line">/ 辅助功能 /
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1643"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1644"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1645"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1646"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1647"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1648"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1649"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1650"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1651"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1652"> class="hljs-ln-code"> class="hljs-ln-line">void showData(uint8_t *rxData, uint16_t rxNum)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1653"> class="hljs-ln-code"> class="hljs-ln-line">{
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1654"> class="hljs-ln-code"> class="hljs-ln-line">#if 0
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1655"> class="hljs-ln-code"> class="hljs-ln-line"> printf("字节数: %d \r", rxNum);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1656"> class="hljs-ln-code"> class="hljs-ln-line"> printf("ASCII 显示数据: %s\r", (char *)rxData);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1657"> class="hljs-ln-code"> class="hljs-ln-line"> printf("16进制显示数据: ");
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1658"> class="hljs-ln-code"> class="hljs-ln-line"> while (rxNum--)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1659"> class="hljs-ln-code"> class="hljs-ln-line"> printf("0x%X ", *rxData++);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1660"> class="hljs-ln-code"> class="hljs-ln-line"> printf("\r\r");
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1661"> class="hljs-ln-code"> class="hljs-ln-line">#else
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1662"> class="hljs-ln-code"> class="hljs-ln-line"> UART1_SendString("字节数:%d \r", rxNum);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1663"> class="hljs-ln-code"> class="hljs-ln-line"> UART1_SendString("ASCII : %s\r", (char *)rxData);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1664"> class="hljs-ln-code"> class="hljs-ln-line"> UART1_SendString("16进制: ");
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1665"> class="hljs-ln-code"> class="hljs-ln-line"> while (rxNum--)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1666"> class="hljs-ln-code"> class="hljs-ln-line"> UART1_SendString("0x%X ", *rxData++);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1667"> class="hljs-ln-code"> class="hljs-ln-line"> UART1_SendString("\r\r");
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1668"> class="hljs-ln-code"> class="hljs-ln-line">#endif
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1669"> class="hljs-ln-code"> class="hljs-ln-line">}
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1670"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1671"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1672"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1673"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1674"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1675"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1676"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1677"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1678"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1679"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1680"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1681"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1682"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1683"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1684"> class="hljs-ln-code"> class="hljs-ln-line">#pragma import(__use_no_semihosting)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1685"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1686"> class="hljs-ln-code"> class="hljs-ln-line">struct __FILE
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1687"> class="hljs-ln-code"> class="hljs-ln-line">{
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1688"> class="hljs-ln-code"> class="hljs-ln-line"> int handle;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1689"> class="hljs-ln-code"> class="hljs-ln-line">};
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1690"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1691"> class="hljs-ln-code"> class="hljs-ln-line">FILE __stdout;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1692"> class="hljs-ln-code"> class="hljs-ln-line">void _sys_exit(int x)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1693"> class="hljs-ln-code"> class="hljs-ln-line">{
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1694"> class="hljs-ln-code"> class="hljs-ln-line"> x = x;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1695"> class="hljs-ln-code"> class="hljs-ln-line">}
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1696"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1697"> class="hljs-ln-code"> class="hljs-ln-line">int fputc(int ch, FILE *f)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1698"> class="hljs-ln-code"> class="hljs-ln-line">{
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1699"> class="hljs-ln-code"> class="hljs-ln-line">#if 0
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1700"> class="hljs-ln-code"> class="hljs-ln-line"> while ((USART1->SR & 0X40) == 0);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1701"> class="hljs-ln-code"> class="hljs-ln-line"> USART1->DR = (u8) ch;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1702"> class="hljs-ln-code"> class="hljs-ln-line">#else
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1703"> class="hljs-ln-code"> class="hljs-ln-line"> UART1_SendData((uint8_t *)&ch, 1);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1704"> class="hljs-ln-code"> class="hljs-ln-line">#endif
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1705"> class="hljs-ln-code"> class="hljs-ln-line"> return ch;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1706"> class="hljs-ln-code"> class="hljs-ln-line">}
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1707"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1708"> class="hljs-ln-code"> class="hljs-ln-line">
class="hide-preCode-box">
class="hljs-button signin active" data-title="登录复制" data-report-click="{"spm":"1001.2101.3001.4334"}" onclick="hljs.signin(event)">
八、STM32F407 源代码
可复制以下代码到文件,也可以直接下载:
bsp_UART.c + bsp_UART.h
1、bsp_UART.h
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1"> class="hljs-ln-code"> class="hljs-ln-line">#ifndef __BSP__UART_H
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="2"> class="hljs-ln-code"> class="hljs-ln-line">#define __BSP__UART_H
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="3"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="4"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="5"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="6"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="7"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="8"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="9"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="10"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="11"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="12"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="13"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="14"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="15"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="16"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="17"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="18"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="19"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="20"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="21"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="22"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="23"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="24"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="25"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="26"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="27"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="28"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="29"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="30"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="31"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="32"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="33"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="34"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="35"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="36"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="37"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="38"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="39"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="40"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="41"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="42"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="43"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="44"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="45"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="46"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="47"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="48"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="49"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="50"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="51"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="52"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="53"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="54"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="55"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="56"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="57"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="58"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="59"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="60"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="61"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="62"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="63"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="64"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="65"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="66"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="67"> class="hljs-ln-code"> class="hljs-ln-line">#include "stdio.h"
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="68"> class="hljs-ln-code"> class="hljs-ln-line">#include "stdarg.h"
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="69"> class="hljs-ln-code"> class="hljs-ln-line">#include "string.h"
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="70"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="71"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="72"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="73"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="74"> class="hljs-ln-code"> class="hljs-ln-line">#ifdef USE_STDPERIPH_DRIVER
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="75"> class="hljs-ln-code"> class="hljs-ln-line"> #include "stm32f4xx.h"
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="76"> class="hljs-ln-code"> class="hljs-ln-line">#endif
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="77"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="78"> class="hljs-ln-code"> class="hljs-ln-line">#ifdef USE_HAL_DRIVER
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="79"> class="hljs-ln-code"> class="hljs-ln-line"> #include "stm32f4xx_hal.h"
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="80"> class="hljs-ln-code"> class="hljs-ln-line">#endif
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="81"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="82"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="83"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="84"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="85"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="86"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="87"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="88"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="89"> class="hljs-ln-code"> class="hljs-ln-line">#define UART1_EN 1
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="90"> class="hljs-ln-code"> class="hljs-ln-line">#define UART2_EN 1
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="91"> class="hljs-ln-code"> class="hljs-ln-line">#define UART3_EN 1
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="92"> class="hljs-ln-code"> class="hljs-ln-line">#define UART4_EN 1
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="93"> class="hljs-ln-code"> class="hljs-ln-line">#define UART5_EN 1
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="94"> class="hljs-ln-code"> class="hljs-ln-line">#define UART6_EN 1
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="95"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="96"> class="hljs-ln-code"> class="hljs-ln-line">#define UART1_TX_BUF_SIZE 2048
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="97"> class="hljs-ln-code"> class="hljs-ln-line">#define UART2_TX_BUF_SIZE 512
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="98"> class="hljs-ln-code"> class="hljs-ln-line">#define UART3_TX_BUF_SIZE 512
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="99"> class="hljs-ln-code"> class="hljs-ln-line">#define UART4_TX_BUF_SIZE 512
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="100"> class="hljs-ln-code"> class="hljs-ln-line">#define UART5_TX_BUF_SIZE 512
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="101"> class="hljs-ln-code"> class="hljs-ln-line">#define UART6_TX_BUF_SIZE 512
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="102"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="103"> class="hljs-ln-code"> class="hljs-ln-line">#define UART1_RX_BUF_SIZE 2048
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="104"> class="hljs-ln-code"> class="hljs-ln-line">#define UART2_RX_BUF_SIZE 1024
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="105"> class="hljs-ln-code"> class="hljs-ln-line">#define UART3_RX_BUF_SIZE 1024
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="106"> class="hljs-ln-code"> class="hljs-ln-line">#define UART4_RX_BUF_SIZE 1024
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="107"> class="hljs-ln-code"> class="hljs-ln-line">#define UART5_RX_BUF_SIZE 1024
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="108"> class="hljs-ln-code"> class="hljs-ln-line">#define UART6_RX_BUF_SIZE 1024
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="109"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="110"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="111"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="112"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="113"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="114"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="115"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="116"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="117"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="118"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="119"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="120"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="121"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="122"> class="hljs-ln-code"> class="hljs-ln-line">void UART1_Init(uint32_t ulBaudrate);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="123"> class="hljs-ln-code"> class="hljs-ln-line">void UART1_SendData(uint8_t *puData, uint16_t usNum);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="124"> class="hljs-ln-code"> class="hljs-ln-line">void UART1_SendString(const char *pcString, ...);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="125"> class="hljs-ln-code"> class="hljs-ln-line">uint8_t UART1_SendAT(char *pcAT, char *pcAckString, uint16_t usTimeOutMs);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="126"> class="hljs-ln-code"> class="hljs-ln-line">uint16_t UART1_GetRxNum(void);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="127"> class="hljs-ln-code"> class="hljs-ln-line">uint8_t * UART1_GetRxData(void);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="128"> class="hljs-ln-code"> class="hljs-ln-line">void UART1_ClearRx(void);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="129"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="130"> class="hljs-ln-code"> class="hljs-ln-line">void UART2_Init(uint32_t ulBaudrate);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="131"> class="hljs-ln-code"> class="hljs-ln-line">void UART2_SendData(uint8_t *puData, uint16_t usNum);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="132"> class="hljs-ln-code"> class="hljs-ln-line">void UART2_SendString(const char *pcString, ...);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="133"> class="hljs-ln-code"> class="hljs-ln-line">uint8_t UART2_SendAT(char *pcAT, char *pcAckString, uint16_t usTimeOutMs);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="134"> class="hljs-ln-code"> class="hljs-ln-line">uint16_t UART2_GetRxNum(void);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="135"> class="hljs-ln-code"> class="hljs-ln-line">uint8_t * UART2_GetRxData(void);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="136"> class="hljs-ln-code"> class="hljs-ln-line">void UART2_ClearRx(void);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="137"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="138"> class="hljs-ln-code"> class="hljs-ln-line">void UART3_Init(uint32_t ulBaudrate);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="139"> class="hljs-ln-code"> class="hljs-ln-line">void UART3_SendData(uint8_t *puData, uint16_t usNum);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="140"> class="hljs-ln-code"> class="hljs-ln-line">void UART3_SendString(const char *pcString, ...);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="141"> class="hljs-ln-code"> class="hljs-ln-line">uint8_t UART3_SendAT(char *pcAT, char *pcAckString, uint16_t usTimeOutMs);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="142"> class="hljs-ln-code"> class="hljs-ln-line">uint16_t UART3_GetRxNum(void);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="143"> class="hljs-ln-code"> class="hljs-ln-line">uint8_t * UART3_GetRxData(void);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="144"> class="hljs-ln-code"> class="hljs-ln-line">void UART3_ClearRx(void);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="145"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="146"> class="hljs-ln-code"> class="hljs-ln-line">void UART4_Init(uint32_t ulBaudrate);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="147"> class="hljs-ln-code"> class="hljs-ln-line">void UART4_SendData(uint8_t *puData, uint16_t usNum);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="148"> class="hljs-ln-code"> class="hljs-ln-line">void UART4_SendString(const char *pcString, ...);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="149"> class="hljs-ln-code"> class="hljs-ln-line">uint8_t UART4_SendAT(char *pcAT, char *pcAckString, uint16_t usTimeOutMs);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="150"> class="hljs-ln-code"> class="hljs-ln-line">uint16_t UART4_GetRxNum(void);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="151"> class="hljs-ln-code"> class="hljs-ln-line">uint8_t * UART4_GetRxData(void);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="152"> class="hljs-ln-code"> class="hljs-ln-line">void UART4_ClearRx(void);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="153"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="154"> class="hljs-ln-code"> class="hljs-ln-line">void UART5_Init(uint32_t ulBaudrate);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="155"> class="hljs-ln-code"> class="hljs-ln-line">void UART5_SendData(uint8_t *puData, uint16_t usNum);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="156"> class="hljs-ln-code"> class="hljs-ln-line">void UART5_SendString(const char *pcString, ...);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="157"> class="hljs-ln-code"> class="hljs-ln-line">uint8_t UART5_SendAT(char *pcAT, char *pcAckString, uint16_t usTimeOutMs);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="158"> class="hljs-ln-code"> class="hljs-ln-line">uint16_t UART5_GetRxNum(void);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="159"> class="hljs-ln-code"> class="hljs-ln-line">uint8_t * UART5_GetRxData(void);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="160"> class="hljs-ln-code"> class="hljs-ln-line">void UART5_ClearRx(void);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="161"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="162"> class="hljs-ln-code"> class="hljs-ln-line">void UART6_Init(uint32_t ulBaudrate);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="163"> class="hljs-ln-code"> class="hljs-ln-line">void UART6_SendData(uint8_t *puData, uint16_t usNum);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="164"> class="hljs-ln-code"> class="hljs-ln-line">void UART6_SendString(const char *pcString, ...);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="165"> class="hljs-ln-code"> class="hljs-ln-line">uint8_t UART6_SendAT(char *pcAT, char *pcAckString, uint16_t usTimeOutMs);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="166"> class="hljs-ln-code"> class="hljs-ln-line">uint16_t UART6_GetRxNum(void);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="167"> class="hljs-ln-code"> class="hljs-ln-line">uint8_t * UART6_GetRxData(void);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="168"> class="hljs-ln-code"> class="hljs-ln-line">void UART6_ClearRx(void);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="169"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="170"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="171"> class="hljs-ln-code"> class="hljs-ln-line">void Modbus_AddCRC16(uint8_t *_pcData, uint16_t _usLen);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="172"> class="hljs-ln-code"> class="hljs-ln-line">uint8_t Modbus_CheckCRC16(uint8_t *_pcData, uint16_t _usLen);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="173"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="174"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="175"> class="hljs-ln-code"> class="hljs-ln-line">#endif
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="176"> class="hljs-ln-code"> class="hljs-ln-line">
class="hide-preCode-box">
class="hljs-button signin active" data-title="登录复制" data-report-click="{"spm":"1001.2101.3001.4334"}" onclick="hljs.signin(event)">
2、bsp_UART.c
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="2"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="3"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="4"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="5"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="6"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="7"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="8"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="9"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="10"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="11"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="12"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="13"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="14"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="15"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="16"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="17"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="18"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="19"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="20"> class="hljs-ln-code"> class="hljs-ln-line">#include "bsp_UART.h"
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="21"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="22"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="23"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="24"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="25"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="26"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="27"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="28"> class="hljs-ln-code"> class="hljs-ln-line">typedef struct
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="29"> class="hljs-ln-code"> class="hljs-ln-line">{
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="30"> class="hljs-ln-code"> class="hljs-ln-line"> uint16_t usRxNum;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="31"> class="hljs-ln-code"> class="hljs-ln-line"> uint8_t *puRxData;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="32"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="33"> class="hljs-ln-code"> class="hljs-ln-line"> uint8_t *puTxFiFoData;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="34"> class="hljs-ln-code"> class="hljs-ln-line"> uint16_t usTxFiFoData ;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="35"> class="hljs-ln-code"> class="hljs-ln-line"> uint16_t usTxFiFoTail ;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="36"> class="hljs-ln-code"> class="hljs-ln-line">} xUSATR_TypeDef;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="37"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="38"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="39"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="40"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="41"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="42"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="43"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="44"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="45"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="46"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="47"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="48"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="49"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="50"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="51"> class="hljs-ln-code"> class="hljs-ln-line">static volatile uint32_t ulTimesMS;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="52"> class="hljs-ln-code"> class="hljs-ln-line">static void delay_ms(uint16_t ms)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="53"> class="hljs-ln-code"> class="hljs-ln-line">{
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="54"> class="hljs-ln-code"> class="hljs-ln-line"> ulTimesMS = ms * 16500;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="55"> class="hljs-ln-code"> class="hljs-ln-line"> while (ulTimesMS)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="56"> class="hljs-ln-code"> class="hljs-ln-line"> ulTimesMS--;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="57"> class="hljs-ln-code"> class="hljs-ln-line">}
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="58"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="59"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="60"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="61"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="62"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="63"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="64"> class="hljs-ln-code"> class="hljs-ln-line">/
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="65"> class="hljs-ln-code"> class="hljs-ln-line">#if UART1_EN
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="66"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="67"> class="hljs-ln-code"> class="hljs-ln-line">static xUSATR_TypeDef xUART1 = { 0 };
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="68"> class="hljs-ln-code"> class="hljs-ln-line">static uint8_t uaUART1RxData[UART1_RX_BUF_SIZE];
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="69"> class="hljs-ln-code"> class="hljs-ln-line">static uint8_t uaUART1TxFiFoData[UART1_TX_BUF_SIZE];
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="70"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="71"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="72"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="73"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="74"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="75"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="76"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="77"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="78"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="79"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="80"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="81"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="82"> class="hljs-ln-code"> class="hljs-ln-line">void UART1_Init(uint32_t ulBaudrate)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="83"> class="hljs-ln-code"> class="hljs-ln-line">{
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="84"> class="hljs-ln-code"> class="hljs-ln-line">#ifdef USE_STDPERIPH_DRIVER
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="85"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="86"> class="hljs-ln-code"> class="hljs-ln-line"> RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="87"> class="hljs-ln-code"> class="hljs-ln-line"> RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="88"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="89"> class="hljs-ln-code"> class="hljs-ln-line"> GPIO_PinAFConfig(GPIOA, GPIO_PinSource9, GPIO_AF_USART1);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="90"> class="hljs-ln-code"> class="hljs-ln-line"> GPIO_PinAFConfig(GPIOA, GPIO_PinSource10, GPIO_AF_USART1);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="91"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="92"> class="hljs-ln-code"> class="hljs-ln-line"> RCC_APB2PeriphResetCmd(RCC_APB2Periph_USART1, ENABLE);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="93"> class="hljs-ln-code"> class="hljs-ln-line"> RCC_APB2PeriphResetCmd(RCC_APB2Periph_USART1, DISABLE);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="94"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="95"> class="hljs-ln-code"> class="hljs-ln-line"> GPIO_InitTypeDef GPIO_InitStructure = {0};
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="96"> class="hljs-ln-code"> class="hljs-ln-line"> GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="97"> class="hljs-ln-code"> class="hljs-ln-line"> GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="98"> class="hljs-ln-code"> class="hljs-ln-line"> GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="99"> class="hljs-ln-code"> class="hljs-ln-line"> GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="100"> class="hljs-ln-code"> class="hljs-ln-line"> GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="101"> class="hljs-ln-code"> class="hljs-ln-line"> GPIO_Init(GPIOA, &GPIO_InitStructure);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="102"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="103"> class="hljs-ln-code"> class="hljs-ln-line"> GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="104"> class="hljs-ln-code"> class="hljs-ln-line"> GPIO_Init(GPIOA, &GPIO_InitStructure);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="105"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="106"> class="hljs-ln-code"> class="hljs-ln-line"> USART_InitTypeDef USART_InitStructure;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="107"> class="hljs-ln-code"> class="hljs-ln-line"> USART_InitStructure.USART_BaudRate = ulBaudrate;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="108"> class="hljs-ln-code"> class="hljs-ln-line"> USART_InitStructure.USART_WordLength = USART_WordLength_8b;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="109"> class="hljs-ln-code"> class="hljs-ln-line"> USART_InitStructure.USART_StopBits = USART_StopBits_1;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="110"> class="hljs-ln-code"> class="hljs-ln-line"> USART_InitStructure.USART_Parity = USART_Parity_No;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="111"> class="hljs-ln-code"> class="hljs-ln-line"> USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="112"> class="hljs-ln-code"> class="hljs-ln-line"> USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="113"> class="hljs-ln-code"> class="hljs-ln-line"> USART_Init(USART1, &USART_InitStructure);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="114"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="115"> class="hljs-ln-code"> class="hljs-ln-line"> USART_ITConfig(USART1, USART_IT_RXNE, ENABLE);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="116"> class="hljs-ln-code"> class="hljs-ln-line"> USART_ITConfig(USART1, USART_IT_IDLE, ENABLE);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="117"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="118"> class="hljs-ln-code"> class="hljs-ln-line"> NVIC_InitTypeDef NVIC_InitStructure = {0};
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="119"> class="hljs-ln-code"> class="hljs-ln-line"> NVIC_InitStructure .NVIC_IRQChannel = USART1_IRQn;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="120"> class="hljs-ln-code"> class="hljs-ln-line"> NVIC_InitStructure .NVIC_IRQChannelPreemptionPriority = 1;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="121"> class="hljs-ln-code"> class="hljs-ln-line"> NVIC_InitStructure .NVIC_IRQChannelSubPriority = 1;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="122"> class="hljs-ln-code"> class="hljs-ln-line"> NVIC_InitStructure .NVIC_IRQChannelCmd = ENABLE;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="123"> class="hljs-ln-code"> class="hljs-ln-line"> NVIC_Init(&NVIC_InitStructure);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="124"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="125"> class="hljs-ln-code"> class="hljs-ln-line"> USART_Cmd(USART1, ENABLE);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="126"> class="hljs-ln-code"> class="hljs-ln-line">#endif
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="127"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="128"> class="hljs-ln-code"> class="hljs-ln-line">#ifdef USE_HAL_DRIVER
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="129"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="130"> class="hljs-ln-code"> class="hljs-ln-line"> __HAL_RCC_GPIOA_CLK_ENABLE();
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="131"> class="hljs-ln-code"> class="hljs-ln-line"> __HAL_RCC_USART1_CLK_ENABLE();
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="132"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="133"> class="hljs-ln-code"> class="hljs-ln-line"> __HAL_RCC_USART1_FORCE_RESET();
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="134"> class="hljs-ln-code"> class="hljs-ln-line"> __HAL_RCC_USART1_RELEASE_RESET();
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="135"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="136"> class="hljs-ln-code"> class="hljs-ln-line"> GPIO_InitTypeDef GPIO_InitStruct = {0};
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="137"> class="hljs-ln-code"> class="hljs-ln-line"> GPIO_InitStruct.Pin = GPIO_PIN_9 | GPIO_PIN_10;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="138"> class="hljs-ln-code"> class="hljs-ln-line"> GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="139"> class="hljs-ln-code"> class="hljs-ln-line"> GPIO_InitStruct.Pull = GPIO_PULLUP;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="140"> class="hljs-ln-code"> class="hljs-ln-line"> GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="141"> class="hljs-ln-code"> class="hljs-ln-line"> GPIO_InitStruct.Alternate = GPIO_AF7_USART1;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="142"> class="hljs-ln-code"> class="hljs-ln-line"> HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="143"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="144"> class="hljs-ln-code"> class="hljs-ln-line"> float temp;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="145"> class="hljs-ln-code"> class="hljs-ln-line"> uint16_t mantissa, fraction;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="146"> class="hljs-ln-code"> class="hljs-ln-line"> SystemCoreClockUpdate();
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="147"> class="hljs-ln-code"> class="hljs-ln-line"> temp = (float)(SystemCoreClock / 2) / (ulBaudrate * 16);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="148"> class="hljs-ln-code"> class="hljs-ln-line"> mantissa = temp;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="149"> class="hljs-ln-code"> class="hljs-ln-line"> fraction = (temp - mantissa) * 16;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="150"> class="hljs-ln-code"> class="hljs-ln-line"> USART1 -> BRR = mantissa << 4 | fraction;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="151"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="152"> class="hljs-ln-code"> class="hljs-ln-line"> USART1 -> CR1 = 0;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="153"> class="hljs-ln-code"> class="hljs-ln-line"> USART1 -> CR1 |= 0x01 << 2;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="154"> class="hljs-ln-code"> class="hljs-ln-line"> USART1 -> CR1 |= 0x01 << 3;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="155"> class="hljs-ln-code"> class="hljs-ln-line"> USART1 -> CR1 |= 0x00 << 9;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="156"> class="hljs-ln-code"> class="hljs-ln-line"> USART1 -> CR1 |= 0x00 << 10;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="157"> class="hljs-ln-code"> class="hljs-ln-line"> USART1 -> CR1 |= 0x00 << 12;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="158"> class="hljs-ln-code"> class="hljs-ln-line"> USART1 -> CR2 = 0;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="159"> class="hljs-ln-code"> class="hljs-ln-line"> USART1 -> CR2 &= ~(0x03 << 12);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="160"> class="hljs-ln-code"> class="hljs-ln-line"> USART1 -> CR3 = 0;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="161"> class="hljs-ln-code"> class="hljs-ln-line"> USART1 -> CR3 &= ~(0x01 << 6);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="162"> class="hljs-ln-code"> class="hljs-ln-line"> USART1 -> CR3 &= ~(0x01 << 7);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="163"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="164"> class="hljs-ln-code"> class="hljs-ln-line"> USART1 -> CR1 &= ~(0x01 << 7);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="165"> class="hljs-ln-code"> class="hljs-ln-line"> USART1 -> CR1 |= 0x01 << 5;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="166"> class="hljs-ln-code"> class="hljs-ln-line"> USART1 -> CR1 |= 0x01 << 4;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="167"> class="hljs-ln-code"> class="hljs-ln-line"> USART1 -> SR = ~(0x00F0);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="168"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="169"> class="hljs-ln-code"> class="hljs-ln-line"> HAL_NVIC_SetPriority(USART1_IRQn, 1, 1);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="170"> class="hljs-ln-code"> class="hljs-ln-line"> HAL_NVIC_EnableIRQ(USART1_IRQn);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="171"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="172"> class="hljs-ln-code"> class="hljs-ln-line"> USART1 -> CR1 |= 0x01 << 13;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="173"> class="hljs-ln-code"> class="hljs-ln-line">#endif
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="174"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="175"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="176"> class="hljs-ln-code"> class="hljs-ln-line"> xUART1.puRxData = uaUART1RxData;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="177"> class="hljs-ln-code"> class="hljs-ln-line"> xUART1.puTxFiFoData = uaUART1TxFiFoData;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="178"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="179"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="180"> class="hljs-ln-code"> class="hljs-ln-line"> printf("\r\r\r=========== STM32F407VE 外设 初始化报告 ===========\r");
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="181"> class="hljs-ln-code"> class="hljs-ln-line"> SystemCoreClockUpdate();
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="182"> class="hljs-ln-code"> class="hljs-ln-line"> printf("系统时钟频率 %d MHz\r", SystemCoreClock / 1000000);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="183"> class="hljs-ln-code"> class="hljs-ln-line"> printf("UART1 初始化配置 %d-None-8-1; 已完成初始化配置、收发配置\r", ulBaudrate);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="184"> class="hljs-ln-code"> class="hljs-ln-line">}
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="185"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="186"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="187"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="188"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="189"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="190"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="191"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="192"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="193"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="194"> class="hljs-ln-code"> class="hljs-ln-line">void USART1_IRQHandler(void)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="195"> class="hljs-ln-code"> class="hljs-ln-line">{
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="196"> class="hljs-ln-code"> class="hljs-ln-line"> static uint16_t cnt = 0;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="197"> class="hljs-ln-code"> class="hljs-ln-line"> static uint8_t rxTemp[UART1_RX_BUF_SIZE];
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="198"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="199"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="200"> class="hljs-ln-code"> class="hljs-ln-line"> if ((USART1->SR & USART_SR_TXE) && (USART1->CR1 & USART_CR1_TXEIE))
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="201"> class="hljs-ln-code"> class="hljs-ln-line"> {
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="202"> class="hljs-ln-code"> class="hljs-ln-line"> USART1->DR = xUART1.puTxFiFoData[xUART1.usTxFiFoTail++];
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="203"> class="hljs-ln-code"> class="hljs-ln-line"> if (xUART1.usTxFiFoTail == UART1_TX_BUF_SIZE)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="204"> class="hljs-ln-code"> class="hljs-ln-line"> xUART1.usTxFiFoTail = 0;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="205"> class="hljs-ln-code"> class="hljs-ln-line"> if (xUART1.usTxFiFoTail == xUART1.usTxFiFoData)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="206"> class="hljs-ln-code"> class="hljs-ln-line"> USART1->CR1 &= ~USART_CR1_TXEIE;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="207"> class="hljs-ln-code"> class="hljs-ln-line"> return;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="208"> class="hljs-ln-code"> class="hljs-ln-line"> }
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="209"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="210"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="211"> class="hljs-ln-code"> class="hljs-ln-line"> if (USART1->SR & USART_SR_RXNE)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="212"> class="hljs-ln-code"> class="hljs-ln-line"> {
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="213"> class="hljs-ln-code"> class="hljs-ln-line"> if (cnt == UART1_RX_BUF_SIZE)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="214"> class="hljs-ln-code"> class="hljs-ln-line"> {
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="215"> class="hljs-ln-code"> class="hljs-ln-line"> printf("警告:UART1单帧接收量,已超出接收缓存大小!\r修改文件bsp_UART.h的UART1_RX_BUF_SIZE值,可解决此问题!\r");
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="216"> class="hljs-ln-code"> class="hljs-ln-line"> USART1->DR;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="217"> class="hljs-ln-code"> class="hljs-ln-line"> return;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="218"> class="hljs-ln-code"> class="hljs-ln-line"> }
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="219"> class="hljs-ln-code"> class="hljs-ln-line"> rxTemp[cnt++] = USART1->DR ;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="220"> class="hljs-ln-code"> class="hljs-ln-line"> return;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="221"> class="hljs-ln-code"> class="hljs-ln-line"> }
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="222"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="223"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="224"> class="hljs-ln-code"> class="hljs-ln-line"> if (USART1->SR & USART_SR_IDLE)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="225"> class="hljs-ln-code"> class="hljs-ln-line"> {
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="226"> class="hljs-ln-code"> class="hljs-ln-line"> memcpy(xUART1.puRxData, rxTemp, UART1_RX_BUF_SIZE);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="227"> class="hljs-ln-code"> class="hljs-ln-line"> xUART1.usRxNum = cnt;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="228"> class="hljs-ln-code"> class="hljs-ln-line"> cnt = 0;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="229"> class="hljs-ln-code"> class="hljs-ln-line"> memset(rxTemp, 0, UART1_RX_BUF_SIZE);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="230"> class="hljs-ln-code"> class="hljs-ln-line"> USART1 ->SR;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="231"> class="hljs-ln-code"> class="hljs-ln-line"> USART1 ->DR;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="232"> class="hljs-ln-code"> class="hljs-ln-line"> return;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="233"> class="hljs-ln-code"> class="hljs-ln-line"> }
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="234"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="235"> class="hljs-ln-code"> class="hljs-ln-line"> return;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="236"> class="hljs-ln-code"> class="hljs-ln-line">}
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="237"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="238"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="239"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="240"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="241"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="242"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="243"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="244"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="245"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="246"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="247"> class="hljs-ln-code"> class="hljs-ln-line">void UART1_SendData(uint8_t *puData, uint16_t usNum)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="248"> class="hljs-ln-code"> class="hljs-ln-line">{
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="249"> class="hljs-ln-code"> class="hljs-ln-line"> for (uint16_t i = 0; i < usNum; i++)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="250"> class="hljs-ln-code"> class="hljs-ln-line"> {
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="251"> class="hljs-ln-code"> class="hljs-ln-line"> xUART1.puTxFiFoData[xUART1.usTxFiFoData++] = puData[i];
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="252"> class="hljs-ln-code"> class="hljs-ln-line"> if (xUART1.usTxFiFoData == UART1_TX_BUF_SIZE)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="253"> class="hljs-ln-code"> class="hljs-ln-line"> xUART1.usTxFiFoData = 0;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="254"> class="hljs-ln-code"> class="hljs-ln-line"> }
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="255"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="256"> class="hljs-ln-code"> class="hljs-ln-line"> if ((USART1->CR1 & USART_CR1_TXEIE) == 0)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="257"> class="hljs-ln-code"> class="hljs-ln-line"> USART1->CR1 |= USART_CR1_TXEIE;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="258"> class="hljs-ln-code"> class="hljs-ln-line">}
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="259"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="260"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="261"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="262"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="263"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="264"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="265"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="266"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="267"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="268"> class="hljs-ln-code"> class="hljs-ln-line">void UART1_SendString(const char *pcString, ...)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="269"> class="hljs-ln-code"> class="hljs-ln-line">{
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="270"> class="hljs-ln-code"> class="hljs-ln-line"> char mBuffer[512] = {0};;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="271"> class="hljs-ln-code"> class="hljs-ln-line"> va_list ap;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="272"> class="hljs-ln-code"> class="hljs-ln-line"> va_start(ap, pcString);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="273"> class="hljs-ln-code"> class="hljs-ln-line"> vsnprintf(mBuffer, 512, pcString, ap);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="274"> class="hljs-ln-code"> class="hljs-ln-line"> va_end(ap);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="275"> class="hljs-ln-code"> class="hljs-ln-line"> UART1_SendData((uint8_t *)mBuffer, strlen(mBuffer));
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="276"> class="hljs-ln-code"> class="hljs-ln-line">}
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="277"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="278"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="279"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="280"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="281"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="282"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="283"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="284"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="285"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="286"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="287"> class="hljs-ln-code"> class="hljs-ln-line">uint8_t UART1_SendAT(char *pcAT, char *pcAckString, uint16_t usTimeOutMs)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="288"> class="hljs-ln-code"> class="hljs-ln-line">{
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="289"> class="hljs-ln-code"> class="hljs-ln-line"> UART1_ClearRx();
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="290"> class="hljs-ln-code"> class="hljs-ln-line"> UART1_SendString(pcAT);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="291"> class="hljs-ln-code"> class="hljs-ln-line"> while (usTimeOutMs--)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="292"> class="hljs-ln-code"> class="hljs-ln-line"> {
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="293"> class="hljs-ln-code"> class="hljs-ln-line"> if (UART1_GetRxNum())
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="294"> class="hljs-ln-code"> class="hljs-ln-line"> {
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="295"> class="hljs-ln-code"> class="hljs-ln-line"> UART1_ClearRx();
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="296"> class="hljs-ln-code"> class="hljs-ln-line"> if (strstr((char *)UART1_GetRxData(), pcAckString))
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="297"> class="hljs-ln-code"> class="hljs-ln-line"> return 1;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="298"> class="hljs-ln-code"> class="hljs-ln-line"> }
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="299"> class="hljs-ln-code"> class="hljs-ln-line"> delay_ms(1);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="300"> class="hljs-ln-code"> class="hljs-ln-line"> }
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="301"> class="hljs-ln-code"> class="hljs-ln-line"> return 0;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="302"> class="hljs-ln-code"> class="hljs-ln-line">}
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="303"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="304"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="305"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="306"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="307"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="308"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="309"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="310"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="311"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="312"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="313"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="314"> class="hljs-ln-code"> class="hljs-ln-line">#if 0
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="315"> class="hljs-ln-code"> class="hljs-ln-line">void UART1_SendStringForDMA(char *stringTemp)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="316"> class="hljs-ln-code"> class="hljs-ln-line">{
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="317"> class="hljs-ln-code"> class="hljs-ln-line"> static uint8_t Flag_DmaTxInit = 0;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="318"> class="hljs-ln-code"> class="hljs-ln-line"> uint32_t num = 0;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="319"> class="hljs-ln-code"> class="hljs-ln-line"> char *t = stringTemp ;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="320"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="321"> class="hljs-ln-code"> class="hljs-ln-line"> while (*t++ != 0) num++;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="322"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="323"> class="hljs-ln-code"> class="hljs-ln-line"> while (DMA1_Channel4->CNDTR > 0);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="324"> class="hljs-ln-code"> class="hljs-ln-line"> if (Flag_DmaTxInit == 0)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="325"> class="hljs-ln-code"> class="hljs-ln-line"> {
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="326"> class="hljs-ln-code"> class="hljs-ln-line"> Flag_DmaTxInit = 1;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="327"> class="hljs-ln-code"> class="hljs-ln-line"> USART1 ->CR3 |= 1 << 7;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="328"> class="hljs-ln-code"> class="hljs-ln-line"> RCC->AHBENR |= 1 << 0;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="329"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="330"> class="hljs-ln-code"> class="hljs-ln-line"> DMA1_Channel4->CCR = 0;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="331"> class="hljs-ln-code"> class="hljs-ln-line"> DMA1_Channel4->CNDTR = num;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="332"> class="hljs-ln-code"> class="hljs-ln-line"> DMA1_Channel4->CMAR = (uint32_t)stringTemp;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="333"> class="hljs-ln-code"> class="hljs-ln-line"> DMA1_Channel4->CPAR = (uint32_t)&USART1->DR;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="334"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="335"> class="hljs-ln-code"> class="hljs-ln-line"> DMA1_Channel4->CCR |= 1 << 4;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="336"> class="hljs-ln-code"> class="hljs-ln-line"> DMA1_Channel4->CCR |= 0 << 5;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="337"> class="hljs-ln-code"> class="hljs-ln-line"> DMA1_Channel4->CCR |= 0 << 6;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="338"> class="hljs-ln-code"> class="hljs-ln-line"> DMA1_Channel4->CCR |= 1 << 7;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="339"> class="hljs-ln-code"> class="hljs-ln-line"> DMA1_Channel4->CCR |= 0 << 8;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="340"> class="hljs-ln-code"> class="hljs-ln-line"> DMA1_Channel4->CCR |= 0 << 10;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="341"> class="hljs-ln-code"> class="hljs-ln-line"> DMA1_Channel4->CCR |= 0 << 12;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="342"> class="hljs-ln-code"> class="hljs-ln-line"> DMA1_Channel4->CCR |= 0 << 14;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="343"> class="hljs-ln-code"> class="hljs-ln-line"> }
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="344"> class="hljs-ln-code"> class="hljs-ln-line"> DMA1_Channel4->CCR &= ~((uint32_t)(1 << 0));
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="345"> class="hljs-ln-code"> class="hljs-ln-line"> DMA1_Channel4->CNDTR = num;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="346"> class="hljs-ln-code"> class="hljs-ln-line"> DMA1_Channel4->CMAR = (uint32_t)stringTemp;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="347"> class="hljs-ln-code"> class="hljs-ln-line"> DMA1_Channel4->CCR |= 1 << 0;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="348"> class="hljs-ln-code"> class="hljs-ln-line">}
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="349"> class="hljs-ln-code"> class="hljs-ln-line">#endif
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="350"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="351"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="352"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="353"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="354"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="355"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="356"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="357"> class="hljs-ln-code"> class="hljs-ln-line">uint16_t UART1_GetRxNum(void)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="358"> class="hljs-ln-code"> class="hljs-ln-line">{
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="359"> class="hljs-ln-code"> class="hljs-ln-line"> return xUART1.usRxNum ;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="360"> class="hljs-ln-code"> class="hljs-ln-line">}
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="361"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="362"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="363"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="364"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="365"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="366"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="367"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="368"> class="hljs-ln-code"> class="hljs-ln-line">uint8_t *UART1_GetRxData(void)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="369"> class="hljs-ln-code"> class="hljs-ln-line">{
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="370"> class="hljs-ln-code"> class="hljs-ln-line"> return xUART1.puRxData ;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="371"> class="hljs-ln-code"> class="hljs-ln-line">}
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="372"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="373"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="374"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="375"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="376"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="377"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="378"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="379"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="380"> class="hljs-ln-code"> class="hljs-ln-line">void UART1_ClearRx(void)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="381"> class="hljs-ln-code"> class="hljs-ln-line">{
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="382"> class="hljs-ln-code"> class="hljs-ln-line"> xUART1.usRxNum = 0 ;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="383"> class="hljs-ln-code"> class="hljs-ln-line">}
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="384"> class="hljs-ln-code"> class="hljs-ln-line">#endif
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="385"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="386"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="387"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="388"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="389"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="390"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="391"> class="hljs-ln-code"> class="hljs-ln-line">/
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="392"> class="hljs-ln-code"> class="hljs-ln-line">#if UART2_EN
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="393"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="394"> class="hljs-ln-code"> class="hljs-ln-line">static xUSATR_TypeDef xUART2 = { 0 };
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="395"> class="hljs-ln-code"> class="hljs-ln-line">static uint8_t uaUART2RxData[UART2_RX_BUF_SIZE];
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="396"> class="hljs-ln-code"> class="hljs-ln-line">static uint8_t uaUART2TxFiFoData[UART2_TX_BUF_SIZE];
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="397"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="398"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="399"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="400"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="401"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="402"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="403"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="404"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="405"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="406"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="407"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="408"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="409"> class="hljs-ln-code"> class="hljs-ln-line">void UART2_Init(uint32_t ulBaudrate)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="410"> class="hljs-ln-code"> class="hljs-ln-line">{
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="411"> class="hljs-ln-code"> class="hljs-ln-line">#ifdef USE_STDPERIPH_DRIVER
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="412"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="413"> class="hljs-ln-code"> class="hljs-ln-line"> RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="414"> class="hljs-ln-code"> class="hljs-ln-line"> RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="415"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="416"> class="hljs-ln-code"> class="hljs-ln-line"> GPIO_PinAFConfig(GPIOA, GPIO_PinSource2, GPIO_AF_USART2);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="417"> class="hljs-ln-code"> class="hljs-ln-line"> GPIO_PinAFConfig(GPIOA, GPIO_PinSource3, GPIO_AF_USART2);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="418"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="419"> class="hljs-ln-code"> class="hljs-ln-line"> RCC_APB1PeriphResetCmd(RCC_APB1Periph_USART2, ENABLE);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="420"> class="hljs-ln-code"> class="hljs-ln-line"> RCC_APB1PeriphResetCmd(RCC_APB1Periph_USART2, DISABLE);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="421"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="422"> class="hljs-ln-code"> class="hljs-ln-line"> GPIO_InitTypeDef GPIO_InitStructure = {0};
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="423"> class="hljs-ln-code"> class="hljs-ln-line"> GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="424"> class="hljs-ln-code"> class="hljs-ln-line"> GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="425"> class="hljs-ln-code"> class="hljs-ln-line"> GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="426"> class="hljs-ln-code"> class="hljs-ln-line"> GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="427"> class="hljs-ln-code"> class="hljs-ln-line"> GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="428"> class="hljs-ln-code"> class="hljs-ln-line"> GPIO_Init(GPIOA, &GPIO_InitStructure);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="429"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="430"> class="hljs-ln-code"> class="hljs-ln-line"> GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="431"> class="hljs-ln-code"> class="hljs-ln-line"> GPIO_Init(GPIOA, &GPIO_InitStructure);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="432"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="433"> class="hljs-ln-code"> class="hljs-ln-line"> USART_InitTypeDef USART_InitStructure;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="434"> class="hljs-ln-code"> class="hljs-ln-line"> USART_InitStructure.USART_BaudRate = ulBaudrate;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="435"> class="hljs-ln-code"> class="hljs-ln-line"> USART_InitStructure.USART_WordLength = USART_WordLength_8b;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="436"> class="hljs-ln-code"> class="hljs-ln-line"> USART_InitStructure.USART_StopBits = USART_StopBits_1;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="437"> class="hljs-ln-code"> class="hljs-ln-line"> USART_InitStructure.USART_Parity = USART_Parity_No;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="438"> class="hljs-ln-code"> class="hljs-ln-line"> USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="439"> class="hljs-ln-code"> class="hljs-ln-line"> USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="440"> class="hljs-ln-code"> class="hljs-ln-line"> USART_Init(USART2, &USART_InitStructure);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="441"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="442"> class="hljs-ln-code"> class="hljs-ln-line"> USART_ITConfig(USART2, USART_IT_RXNE, ENABLE);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="443"> class="hljs-ln-code"> class="hljs-ln-line"> USART_ITConfig(USART2, USART_IT_IDLE, ENABLE);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="444"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="445"> class="hljs-ln-code"> class="hljs-ln-line"> NVIC_InitTypeDef NVIC_InitStructure = {0};
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="446"> class="hljs-ln-code"> class="hljs-ln-line"> NVIC_InitStructure .NVIC_IRQChannel = USART2_IRQn;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="447"> class="hljs-ln-code"> class="hljs-ln-line"> NVIC_InitStructure .NVIC_IRQChannelPreemptionPriority = 1;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="448"> class="hljs-ln-code"> class="hljs-ln-line"> NVIC_InitStructure .NVIC_IRQChannelSubPriority = 1;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="449"> class="hljs-ln-code"> class="hljs-ln-line"> NVIC_InitStructure .NVIC_IRQChannelCmd = ENABLE;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="450"> class="hljs-ln-code"> class="hljs-ln-line"> NVIC_Init(&NVIC_InitStructure);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="451"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="452"> class="hljs-ln-code"> class="hljs-ln-line"> USART_Cmd(USART2, ENABLE);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="453"> class="hljs-ln-code"> class="hljs-ln-line">#endif
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="454"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="455"> class="hljs-ln-code"> class="hljs-ln-line">#ifdef USE_HAL_DRIVER
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="456"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="457"> class="hljs-ln-code"> class="hljs-ln-line"> __HAL_RCC_GPIOA_CLK_ENABLE();
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="458"> class="hljs-ln-code"> class="hljs-ln-line"> __HAL_RCC_USART2_CLK_ENABLE();
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="459"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="460"> class="hljs-ln-code"> class="hljs-ln-line"> __HAL_RCC_USART2_FORCE_RESET();
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="461"> class="hljs-ln-code"> class="hljs-ln-line"> __HAL_RCC_USART2_RELEASE_RESET();
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="462"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="463"> class="hljs-ln-code"> class="hljs-ln-line"> GPIO_InitTypeDef GPIO_InitStruct = {0};
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="464"> class="hljs-ln-code"> class="hljs-ln-line"> GPIO_InitStruct.Pin = GPIO_PIN_2 | GPIO_PIN_3;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="465"> class="hljs-ln-code"> class="hljs-ln-line"> GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="466"> class="hljs-ln-code"> class="hljs-ln-line"> GPIO_InitStruct.Pull = GPIO_PULLUP;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="467"> class="hljs-ln-code"> class="hljs-ln-line"> GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="468"> class="hljs-ln-code"> class="hljs-ln-line"> GPIO_InitStruct.Alternate = GPIO_AF7_USART2;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="469"> class="hljs-ln-code"> class="hljs-ln-line"> HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="470"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="471"> class="hljs-ln-code"> class="hljs-ln-line"> float temp;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="472"> class="hljs-ln-code"> class="hljs-ln-line"> uint16_t mantissa, fraction;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="473"> class="hljs-ln-code"> class="hljs-ln-line"> SystemCoreClockUpdate();
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="474"> class="hljs-ln-code"> class="hljs-ln-line"> temp = (float)(SystemCoreClock / 4) / (ulBaudrate * 16);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="475"> class="hljs-ln-code"> class="hljs-ln-line"> mantissa = temp;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="476"> class="hljs-ln-code"> class="hljs-ln-line"> fraction = (temp - mantissa) * 16;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="477"> class="hljs-ln-code"> class="hljs-ln-line"> USART2 -> BRR = mantissa << 4 | fraction;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="478"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="479"> class="hljs-ln-code"> class="hljs-ln-line"> USART2 -> CR1 = 0;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="480"> class="hljs-ln-code"> class="hljs-ln-line"> USART2 -> CR1 |= 0x01 << 2;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="481"> class="hljs-ln-code"> class="hljs-ln-line"> USART2 -> CR1 |= 0x01 << 3;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="482"> class="hljs-ln-code"> class="hljs-ln-line"> USART2 -> CR1 |= 0x00 << 9;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="483"> class="hljs-ln-code"> class="hljs-ln-line"> USART2 -> CR1 |= 0x00 << 10;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="484"> class="hljs-ln-code"> class="hljs-ln-line"> USART2 -> CR1 |= 0x00 << 12;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="485"> class="hljs-ln-code"> class="hljs-ln-line"> USART2 -> CR2 = 0;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="486"> class="hljs-ln-code"> class="hljs-ln-line"> USART2 -> CR2 &= ~(0x03 << 12);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="487"> class="hljs-ln-code"> class="hljs-ln-line"> USART2 -> CR3 = 0;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="488"> class="hljs-ln-code"> class="hljs-ln-line"> USART2 -> CR3 &= ~(0x01 << 6);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="489"> class="hljs-ln-code"> class="hljs-ln-line"> USART2 -> CR3 &= ~(0x01 << 7);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="490"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="491"> class="hljs-ln-code"> class="hljs-ln-line"> USART2 -> CR1 &= ~(0x01 << 7);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="492"> class="hljs-ln-code"> class="hljs-ln-line"> USART2 -> CR1 |= 0x01 << 5;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="493"> class="hljs-ln-code"> class="hljs-ln-line"> USART2 -> CR1 |= 0x01 << 4;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="494"> class="hljs-ln-code"> class="hljs-ln-line"> USART2 -> SR = ~(0x00F0);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="495"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="496"> class="hljs-ln-code"> class="hljs-ln-line"> HAL_NVIC_SetPriority(USART2_IRQn, 1, 1);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="497"> class="hljs-ln-code"> class="hljs-ln-line"> HAL_NVIC_EnableIRQ(USART2_IRQn);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="498"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="499"> class="hljs-ln-code"> class="hljs-ln-line"> USART2 -> CR1 |= 0x01 << 13;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="500"> class="hljs-ln-code"> class="hljs-ln-line">#endif
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="501"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="502"> class="hljs-ln-code"> class="hljs-ln-line"> xUART2.puRxData = uaUART2RxData;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="503"> class="hljs-ln-code"> class="hljs-ln-line"> xUART2.puTxFiFoData = uaUART2TxFiFoData;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="504"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="505"> class="hljs-ln-code"> class="hljs-ln-line"> printf("UART2 初始化配置 %d-None-8-1; 已完成初始化配置、收发配置\r", ulBaudrate);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="506"> class="hljs-ln-code"> class="hljs-ln-line">}
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="507"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="508"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="509"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="510"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="511"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="512"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="513"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="514"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="515"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="516"> class="hljs-ln-code"> class="hljs-ln-line">void USART2_IRQHandler(void)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="517"> class="hljs-ln-code"> class="hljs-ln-line">{
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="518"> class="hljs-ln-code"> class="hljs-ln-line"> static uint16_t cnt = 0;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="519"> class="hljs-ln-code"> class="hljs-ln-line"> static uint8_t rxTemp[UART2_RX_BUF_SIZE];
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="520"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="521"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="522"> class="hljs-ln-code"> class="hljs-ln-line"> if ((USART2->SR & USART_SR_TXE) && (USART2->CR1 & USART_CR1_TXEIE))
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="523"> class="hljs-ln-code"> class="hljs-ln-line"> {
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="524"> class="hljs-ln-code"> class="hljs-ln-line"> USART2->DR = xUART2.puTxFiFoData[xUART2.usTxFiFoTail++];
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="525"> class="hljs-ln-code"> class="hljs-ln-line"> if (xUART2.usTxFiFoTail == UART2_TX_BUF_SIZE)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="526"> class="hljs-ln-code"> class="hljs-ln-line"> xUART2.usTxFiFoTail = 0;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="527"> class="hljs-ln-code"> class="hljs-ln-line"> if (xUART2.usTxFiFoTail == xUART2.usTxFiFoData)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="528"> class="hljs-ln-code"> class="hljs-ln-line"> USART2->CR1 &= ~USART_CR1_TXEIE;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="529"> class="hljs-ln-code"> class="hljs-ln-line"> return;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="530"> class="hljs-ln-code"> class="hljs-ln-line"> }
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="531"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="532"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="533"> class="hljs-ln-code"> class="hljs-ln-line"> if (USART2->SR & USART_SR_RXNE)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="534"> class="hljs-ln-code"> class="hljs-ln-line"> {
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="535"> class="hljs-ln-code"> class="hljs-ln-line"> if (cnt == UART2_RX_BUF_SIZE)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="536"> class="hljs-ln-code"> class="hljs-ln-line"> {
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="537"> class="hljs-ln-code"> class="hljs-ln-line"> printf("警告:UART2单帧接收量,已超出接收缓存大小!\r修改文件bsp_UART.h的UART2_RX_BUF_SIZE值,可解决此问题!\r");
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="538"> class="hljs-ln-code"> class="hljs-ln-line"> USART2->DR;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="539"> class="hljs-ln-code"> class="hljs-ln-line"> return;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="540"> class="hljs-ln-code"> class="hljs-ln-line"> }
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="541"> class="hljs-ln-code"> class="hljs-ln-line"> rxTemp[cnt++] = USART2->DR ;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="542"> class="hljs-ln-code"> class="hljs-ln-line"> return;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="543"> class="hljs-ln-code"> class="hljs-ln-line"> }
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="544"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="545"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="546"> class="hljs-ln-code"> class="hljs-ln-line"> if (USART2->SR & USART_SR_IDLE)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="547"> class="hljs-ln-code"> class="hljs-ln-line"> {
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="548"> class="hljs-ln-code"> class="hljs-ln-line"> memcpy(xUART2.puRxData, rxTemp, UART2_RX_BUF_SIZE);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="549"> class="hljs-ln-code"> class="hljs-ln-line"> xUART2.usRxNum = cnt;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="550"> class="hljs-ln-code"> class="hljs-ln-line"> cnt = 0;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="551"> class="hljs-ln-code"> class="hljs-ln-line"> memset(rxTemp, 0, UART2_RX_BUF_SIZE);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="552"> class="hljs-ln-code"> class="hljs-ln-line"> USART2 ->SR;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="553"> class="hljs-ln-code"> class="hljs-ln-line"> USART2 ->DR;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="554"> class="hljs-ln-code"> class="hljs-ln-line"> return;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="555"> class="hljs-ln-code"> class="hljs-ln-line"> }
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="556"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="557"> class="hljs-ln-code"> class="hljs-ln-line"> return;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="558"> class="hljs-ln-code"> class="hljs-ln-line">}
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="559"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="560"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="561"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="562"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="563"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="564"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="565"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="566"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="567"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="568"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="569"> class="hljs-ln-code"> class="hljs-ln-line">void UART2_SendData(uint8_t *puData, uint16_t usNum)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="570"> class="hljs-ln-code"> class="hljs-ln-line">{
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="571"> class="hljs-ln-code"> class="hljs-ln-line"> for (uint16_t i = 0; i < usNum; i++)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="572"> class="hljs-ln-code"> class="hljs-ln-line"> {
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="573"> class="hljs-ln-code"> class="hljs-ln-line"> xUART2.puTxFiFoData[xUART2.usTxFiFoData++] = puData[i];
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="574"> class="hljs-ln-code"> class="hljs-ln-line"> if (xUART2.usTxFiFoData == UART2_TX_BUF_SIZE)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="575"> class="hljs-ln-code"> class="hljs-ln-line"> xUART2.usTxFiFoData = 0;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="576"> class="hljs-ln-code"> class="hljs-ln-line"> }
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="577"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="578"> class="hljs-ln-code"> class="hljs-ln-line"> if ((USART2->CR1 & USART_CR1_TXEIE) == 0)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="579"> class="hljs-ln-code"> class="hljs-ln-line"> USART2->CR1 |= USART_CR1_TXEIE;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="580"> class="hljs-ln-code"> class="hljs-ln-line">}
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="581"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="582"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="583"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="584"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="585"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="586"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="587"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="588"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="589"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="590"> class="hljs-ln-code"> class="hljs-ln-line">void UART2_SendString(const char *pcString, ...)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="591"> class="hljs-ln-code"> class="hljs-ln-line">{
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="592"> class="hljs-ln-code"> class="hljs-ln-line"> char mBuffer[512] = {0};;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="593"> class="hljs-ln-code"> class="hljs-ln-line"> va_list ap;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="594"> class="hljs-ln-code"> class="hljs-ln-line"> va_start(ap, pcString);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="595"> class="hljs-ln-code"> class="hljs-ln-line"> vsnprintf(mBuffer, 512, pcString, ap);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="596"> class="hljs-ln-code"> class="hljs-ln-line"> va_end(ap);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="597"> class="hljs-ln-code"> class="hljs-ln-line"> UART2_SendData((uint8_t *)mBuffer, strlen(mBuffer));
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="598"> class="hljs-ln-code"> class="hljs-ln-line">}
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="599"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="600"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="601"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="602"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="603"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="604"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="605"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="606"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="607"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="608"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="609"> class="hljs-ln-code"> class="hljs-ln-line">uint8_t UART2_SendAT(char *pcAT, char *pcAckString, uint16_t usTimeOutMs)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="610"> class="hljs-ln-code"> class="hljs-ln-line">{
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="611"> class="hljs-ln-code"> class="hljs-ln-line"> UART2_ClearRx();
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="612"> class="hljs-ln-code"> class="hljs-ln-line"> UART2_SendString(pcAT);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="613"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="614"> class="hljs-ln-code"> class="hljs-ln-line"> while (usTimeOutMs--)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="615"> class="hljs-ln-code"> class="hljs-ln-line"> {
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="616"> class="hljs-ln-code"> class="hljs-ln-line"> if (UART2_GetRxNum())
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="617"> class="hljs-ln-code"> class="hljs-ln-line"> {
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="618"> class="hljs-ln-code"> class="hljs-ln-line"> UART2_ClearRx();
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="619"> class="hljs-ln-code"> class="hljs-ln-line"> if (strstr((char *)UART2_GetRxData(), pcAckString))
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="620"> class="hljs-ln-code"> class="hljs-ln-line"> return 1;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="621"> class="hljs-ln-code"> class="hljs-ln-line"> }
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="622"> class="hljs-ln-code"> class="hljs-ln-line"> delay_ms(1);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="623"> class="hljs-ln-code"> class="hljs-ln-line"> }
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="624"> class="hljs-ln-code"> class="hljs-ln-line"> return 0;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="625"> class="hljs-ln-code"> class="hljs-ln-line">}
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="626"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="627"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="628"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="629"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="630"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="631"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="632"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="633"> class="hljs-ln-code"> class="hljs-ln-line">uint16_t UART2_GetRxNum(void)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="634"> class="hljs-ln-code"> class="hljs-ln-line">{
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="635"> class="hljs-ln-code"> class="hljs-ln-line"> return xUART2.usRxNum ;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="636"> class="hljs-ln-code"> class="hljs-ln-line">}
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="637"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="638"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="639"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="640"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="641"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="642"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="643"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="644"> class="hljs-ln-code"> class="hljs-ln-line">uint8_t *UART2_GetRxData(void)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="645"> class="hljs-ln-code"> class="hljs-ln-line">{
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="646"> class="hljs-ln-code"> class="hljs-ln-line"> return xUART2.puRxData ;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="647"> class="hljs-ln-code"> class="hljs-ln-line">}
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="648"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="649"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="650"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="651"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="652"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="653"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="654"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="655"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="656"> class="hljs-ln-code"> class="hljs-ln-line">void UART2_ClearRx(void)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="657"> class="hljs-ln-code"> class="hljs-ln-line">{
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="658"> class="hljs-ln-code"> class="hljs-ln-line"> xUART2.usRxNum = 0 ;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="659"> class="hljs-ln-code"> class="hljs-ln-line">}
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="660"> class="hljs-ln-code"> class="hljs-ln-line">#endif
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="661"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="662"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="663"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="664"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="665"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="666"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="667"> class="hljs-ln-code"> class="hljs-ln-line">/
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="668"> class="hljs-ln-code"> class="hljs-ln-line">#if UART3_EN
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="669"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="670"> class="hljs-ln-code"> class="hljs-ln-line">static xUSATR_TypeDef xUART3 = { 0 };
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="671"> class="hljs-ln-code"> class="hljs-ln-line">static uint8_t uaUart3RxData[UART3_RX_BUF_SIZE];
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="672"> class="hljs-ln-code"> class="hljs-ln-line">static uint8_t uaUart3TxFiFoData[UART3_TX_BUF_SIZE];
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="673"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="674"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="675"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="676"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="677"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="678"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="679"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="680"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="681"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="682"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="683"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="684"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="685"> class="hljs-ln-code"> class="hljs-ln-line">void UART3_Init(uint32_t ulBaudrate)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="686"> class="hljs-ln-code"> class="hljs-ln-line">{
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="687"> class="hljs-ln-code"> class="hljs-ln-line">#ifdef USE_STDPERIPH_DRIVER
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="688"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="689"> class="hljs-ln-code"> class="hljs-ln-line"> RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="690"> class="hljs-ln-code"> class="hljs-ln-line"> RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, ENABLE);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="691"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="692"> class="hljs-ln-code"> class="hljs-ln-line"> GPIO_PinAFConfig(GPIOB, GPIO_PinSource10, GPIO_AF_USART3);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="693"> class="hljs-ln-code"> class="hljs-ln-line"> GPIO_PinAFConfig(GPIOB, GPIO_PinSource11, GPIO_AF_USART3);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="694"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="695"> class="hljs-ln-code"> class="hljs-ln-line"> RCC_APB1PeriphResetCmd(RCC_APB1Periph_USART3, ENABLE);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="696"> class="hljs-ln-code"> class="hljs-ln-line"> RCC_APB1PeriphResetCmd(RCC_APB1Periph_USART3, DISABLE);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="697"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="698"> class="hljs-ln-code"> class="hljs-ln-line"> GPIO_InitTypeDef GPIO_InitStructure = {0};
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="699"> class="hljs-ln-code"> class="hljs-ln-line"> GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="700"> class="hljs-ln-code"> class="hljs-ln-line"> GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="701"> class="hljs-ln-code"> class="hljs-ln-line"> GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="702"> class="hljs-ln-code"> class="hljs-ln-line"> GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="703"> class="hljs-ln-code"> class="hljs-ln-line"> GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="704"> class="hljs-ln-code"> class="hljs-ln-line"> GPIO_Init(GPIOB, &GPIO_InitStructure);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="705"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="706"> class="hljs-ln-code"> class="hljs-ln-line"> GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="707"> class="hljs-ln-code"> class="hljs-ln-line"> GPIO_Init(GPIOB, &GPIO_InitStructure);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="708"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="709"> class="hljs-ln-code"> class="hljs-ln-line"> USART_InitTypeDef USART_InitStructure;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="710"> class="hljs-ln-code"> class="hljs-ln-line"> USART_InitStructure.USART_BaudRate = ulBaudrate;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="711"> class="hljs-ln-code"> class="hljs-ln-line"> USART_InitStructure.USART_WordLength = USART_WordLength_8b;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="712"> class="hljs-ln-code"> class="hljs-ln-line"> USART_InitStructure.USART_StopBits = USART_StopBits_1;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="713"> class="hljs-ln-code"> class="hljs-ln-line"> USART_InitStructure.USART_Parity = USART_Parity_No;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="714"> class="hljs-ln-code"> class="hljs-ln-line"> USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="715"> class="hljs-ln-code"> class="hljs-ln-line"> USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="716"> class="hljs-ln-code"> class="hljs-ln-line"> USART_Init(USART3, &USART_InitStructure);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="717"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="718"> class="hljs-ln-code"> class="hljs-ln-line"> USART_ITConfig(USART3, USART_IT_RXNE, ENABLE);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="719"> class="hljs-ln-code"> class="hljs-ln-line"> USART_ITConfig(USART3, USART_IT_IDLE, ENABLE);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="720"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="721"> class="hljs-ln-code"> class="hljs-ln-line"> NVIC_InitTypeDef NVIC_InitStructure = {0};
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="722"> class="hljs-ln-code"> class="hljs-ln-line"> NVIC_InitStructure .NVIC_IRQChannel = USART3_IRQn;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="723"> class="hljs-ln-code"> class="hljs-ln-line"> NVIC_InitStructure .NVIC_IRQChannelPreemptionPriority = 1;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="724"> class="hljs-ln-code"> class="hljs-ln-line"> NVIC_InitStructure .NVIC_IRQChannelSubPriority = 1;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="725"> class="hljs-ln-code"> class="hljs-ln-line"> NVIC_InitStructure .NVIC_IRQChannelCmd = ENABLE;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="726"> class="hljs-ln-code"> class="hljs-ln-line"> NVIC_Init(&NVIC_InitStructure);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="727"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="728"> class="hljs-ln-code"> class="hljs-ln-line"> USART_Cmd(USART3, ENABLE);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="729"> class="hljs-ln-code"> class="hljs-ln-line">#endif
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="730"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="731"> class="hljs-ln-code"> class="hljs-ln-line">#ifdef USE_HAL_DRIVER
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="732"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="733"> class="hljs-ln-code"> class="hljs-ln-line"> __HAL_RCC_GPIOB_CLK_ENABLE();
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="734"> class="hljs-ln-code"> class="hljs-ln-line"> __HAL_RCC_USART3_CLK_ENABLE();
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="735"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="736"> class="hljs-ln-code"> class="hljs-ln-line"> __HAL_RCC_USART3_FORCE_RESET();
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="737"> class="hljs-ln-code"> class="hljs-ln-line"> __HAL_RCC_USART3_RELEASE_RESET();
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="738"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="739"> class="hljs-ln-code"> class="hljs-ln-line"> GPIO_InitTypeDef GPIO_InitStruct = {0};
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="740"> class="hljs-ln-code"> class="hljs-ln-line"> GPIO_InitStruct.Pin = GPIO_PIN_10 | GPIO_PIN_11;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="741"> class="hljs-ln-code"> class="hljs-ln-line"> GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="742"> class="hljs-ln-code"> class="hljs-ln-line"> GPIO_InitStruct.Pull = GPIO_PULLUP;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="743"> class="hljs-ln-code"> class="hljs-ln-line"> GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="744"> class="hljs-ln-code"> class="hljs-ln-line"> GPIO_InitStruct.Alternate = GPIO_AF7_USART3;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="745"> class="hljs-ln-code"> class="hljs-ln-line"> HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="746"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="747"> class="hljs-ln-code"> class="hljs-ln-line"> float temp;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="748"> class="hljs-ln-code"> class="hljs-ln-line"> uint16_t mantissa, fraction;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="749"> class="hljs-ln-code"> class="hljs-ln-line"> SystemCoreClockUpdate();
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="750"> class="hljs-ln-code"> class="hljs-ln-line"> temp = (float)(SystemCoreClock / 4) / (ulBaudrate * 16);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="751"> class="hljs-ln-code"> class="hljs-ln-line"> mantissa = temp;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="752"> class="hljs-ln-code"> class="hljs-ln-line"> fraction = (temp - mantissa) * 16;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="753"> class="hljs-ln-code"> class="hljs-ln-line"> USART3 -> BRR = mantissa << 4 | fraction;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="754"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="755"> class="hljs-ln-code"> class="hljs-ln-line"> USART3 -> CR1 = 0;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="756"> class="hljs-ln-code"> class="hljs-ln-line"> USART3 -> CR1 |= 0x01 << 2;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="757"> class="hljs-ln-code"> class="hljs-ln-line"> USART3 -> CR1 |= 0x01 << 3;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="758"> class="hljs-ln-code"> class="hljs-ln-line"> USART3 -> CR1 |= 0x00 << 9;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="759"> class="hljs-ln-code"> class="hljs-ln-line"> USART3 -> CR1 |= 0x00 << 10;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="760"> class="hljs-ln-code"> class="hljs-ln-line"> USART3 -> CR1 |= 0x00 << 12;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="761"> class="hljs-ln-code"> class="hljs-ln-line"> USART3 -> CR2 = 0;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="762"> class="hljs-ln-code"> class="hljs-ln-line"> USART3 -> CR2 &= ~(0x03 << 12);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="763"> class="hljs-ln-code"> class="hljs-ln-line"> USART3 -> CR3 = 0;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="764"> class="hljs-ln-code"> class="hljs-ln-line"> USART3 -> CR3 &= ~(0x01 << 6);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="765"> class="hljs-ln-code"> class="hljs-ln-line"> USART3 -> CR3 &= ~(0x01 << 7);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="766"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="767"> class="hljs-ln-code"> class="hljs-ln-line"> USART3 -> CR1 &= ~(0x01 << 7);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="768"> class="hljs-ln-code"> class="hljs-ln-line"> USART3 -> CR1 |= 0x01 << 5;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="769"> class="hljs-ln-code"> class="hljs-ln-line"> USART3 -> CR1 |= 0x01 << 4;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="770"> class="hljs-ln-code"> class="hljs-ln-line"> USART3 -> SR = ~(0x00F0);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="771"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="772"> class="hljs-ln-code"> class="hljs-ln-line"> HAL_NVIC_SetPriority(USART3_IRQn, 1, 1);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="773"> class="hljs-ln-code"> class="hljs-ln-line"> HAL_NVIC_EnableIRQ(USART3_IRQn);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="774"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="775"> class="hljs-ln-code"> class="hljs-ln-line"> USART3 -> CR1 |= 0x01 << 13;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="776"> class="hljs-ln-code"> class="hljs-ln-line">#endif
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="777"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="778"> class="hljs-ln-code"> class="hljs-ln-line"> xUART3.puRxData = uaUart3RxData;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="779"> class="hljs-ln-code"> class="hljs-ln-line"> xUART3.puTxFiFoData = uaUart3TxFiFoData;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="780"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="781"> class="hljs-ln-code"> class="hljs-ln-line"> printf("UART3 初始化配置 %d-None-8-1; 已完成初始化配置、收发配置\r", ulBaudrate);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="782"> class="hljs-ln-code"> class="hljs-ln-line">}
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="783"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="784"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="785"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="786"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="787"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="788"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="789"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="790"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="791"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="792"> class="hljs-ln-code"> class="hljs-ln-line">void USART3_IRQHandler(void)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="793"> class="hljs-ln-code"> class="hljs-ln-line">{
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="794"> class="hljs-ln-code"> class="hljs-ln-line"> static uint16_t cnt = 0;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="795"> class="hljs-ln-code"> class="hljs-ln-line"> static uint8_t rxTemp[UART3_RX_BUF_SIZE];
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="796"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="797"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="798"> class="hljs-ln-code"> class="hljs-ln-line"> if ((USART3->SR & USART_SR_TXE) && (USART3->CR1 & USART_CR1_TXEIE))
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="799"> class="hljs-ln-code"> class="hljs-ln-line"> {
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="800"> class="hljs-ln-code"> class="hljs-ln-line"> USART3->DR = xUART3.puTxFiFoData[xUART3.usTxFiFoTail++];
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="801"> class="hljs-ln-code"> class="hljs-ln-line"> if (xUART3.usTxFiFoTail == UART3_TX_BUF_SIZE)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="802"> class="hljs-ln-code"> class="hljs-ln-line"> xUART3.usTxFiFoTail = 0;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="803"> class="hljs-ln-code"> class="hljs-ln-line"> if (xUART3.usTxFiFoTail == xUART3.usTxFiFoData)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="804"> class="hljs-ln-code"> class="hljs-ln-line"> USART3->CR1 &= ~USART_CR1_TXEIE;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="805"> class="hljs-ln-code"> class="hljs-ln-line"> return;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="806"> class="hljs-ln-code"> class="hljs-ln-line"> }
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="807"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="808"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="809"> class="hljs-ln-code"> class="hljs-ln-line"> if (USART3->SR & USART_SR_RXNE)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="810"> class="hljs-ln-code"> class="hljs-ln-line"> {
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="811"> class="hljs-ln-code"> class="hljs-ln-line"> if (cnt == UART3_RX_BUF_SIZE)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="812"> class="hljs-ln-code"> class="hljs-ln-line"> {
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="813"> class="hljs-ln-code"> class="hljs-ln-line"> printf("警告:UART3单帧接收量,已超出接收缓存大小!\r修改文件bsp_UART.h的UART3_RX_BUF_SIZE值,可解决此问题!\r");
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="814"> class="hljs-ln-code"> class="hljs-ln-line"> USART3->DR;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="815"> class="hljs-ln-code"> class="hljs-ln-line"> return;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="816"> class="hljs-ln-code"> class="hljs-ln-line"> }
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="817"> class="hljs-ln-code"> class="hljs-ln-line"> rxTemp[cnt++] = USART3->DR ;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="818"> class="hljs-ln-code"> class="hljs-ln-line"> return;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="819"> class="hljs-ln-code"> class="hljs-ln-line"> }
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="820"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="821"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="822"> class="hljs-ln-code"> class="hljs-ln-line"> if (USART3->SR & USART_SR_IDLE)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="823"> class="hljs-ln-code"> class="hljs-ln-line"> {
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="824"> class="hljs-ln-code"> class="hljs-ln-line"> memcpy(xUART3.puRxData, rxTemp, UART3_RX_BUF_SIZE);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="825"> class="hljs-ln-code"> class="hljs-ln-line"> xUART3.usRxNum = cnt;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="826"> class="hljs-ln-code"> class="hljs-ln-line"> cnt = 0;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="827"> class="hljs-ln-code"> class="hljs-ln-line"> memset(rxTemp, 0, UART3_RX_BUF_SIZE);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="828"> class="hljs-ln-code"> class="hljs-ln-line"> USART3 ->SR;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="829"> class="hljs-ln-code"> class="hljs-ln-line"> USART3 ->DR;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="830"> class="hljs-ln-code"> class="hljs-ln-line"> return;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="831"> class="hljs-ln-code"> class="hljs-ln-line"> }
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="832"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="833"> class="hljs-ln-code"> class="hljs-ln-line"> return;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="834"> class="hljs-ln-code"> class="hljs-ln-line">}
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="835"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="836"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="837"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="838"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="839"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="840"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="841"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="842"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="843"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="844"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="845"> class="hljs-ln-code"> class="hljs-ln-line">void UART3_SendData(uint8_t *puData, uint16_t usNum)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="846"> class="hljs-ln-code"> class="hljs-ln-line">{
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="847"> class="hljs-ln-code"> class="hljs-ln-line"> for (uint16_t i = 0; i < usNum; i++)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="848"> class="hljs-ln-code"> class="hljs-ln-line"> {
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="849"> class="hljs-ln-code"> class="hljs-ln-line"> xUART3.puTxFiFoData[xUART3.usTxFiFoData++] = puData[i];
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="850"> class="hljs-ln-code"> class="hljs-ln-line"> if (xUART3.usTxFiFoData == UART3_TX_BUF_SIZE)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="851"> class="hljs-ln-code"> class="hljs-ln-line"> xUART3.usTxFiFoData = 0;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="852"> class="hljs-ln-code"> class="hljs-ln-line"> }
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="853"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="854"> class="hljs-ln-code"> class="hljs-ln-line"> if ((USART3->CR1 & USART_CR1_TXEIE) == 0)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="855"> class="hljs-ln-code"> class="hljs-ln-line"> USART3->CR1 |= USART_CR1_TXEIE;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="856"> class="hljs-ln-code"> class="hljs-ln-line">}
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="857"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="858"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="859"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="860"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="861"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="862"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="863"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="864"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="865"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="866"> class="hljs-ln-code"> class="hljs-ln-line">void UART3_SendString(const char *pcString, ...)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="867"> class="hljs-ln-code"> class="hljs-ln-line">{
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="868"> class="hljs-ln-code"> class="hljs-ln-line"> char mBuffer[512] = {0};;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="869"> class="hljs-ln-code"> class="hljs-ln-line"> va_list ap;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="870"> class="hljs-ln-code"> class="hljs-ln-line"> va_start(ap, pcString);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="871"> class="hljs-ln-code"> class="hljs-ln-line"> vsnprintf(mBuffer, 512, pcString, ap);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="872"> class="hljs-ln-code"> class="hljs-ln-line"> va_end(ap);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="873"> class="hljs-ln-code"> class="hljs-ln-line"> UART3_SendData((uint8_t *)mBuffer, strlen(mBuffer));
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="874"> class="hljs-ln-code"> class="hljs-ln-line">}
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="875"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="876"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="877"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="878"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="879"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="880"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="881"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="882"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="883"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="884"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="885"> class="hljs-ln-code"> class="hljs-ln-line">uint8_t UART3_SendAT(char *pcAT, char *pcAckString, uint16_t usTimeOutMs)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="886"> class="hljs-ln-code"> class="hljs-ln-line">{
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="887"> class="hljs-ln-code"> class="hljs-ln-line"> UART3_ClearRx();
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="888"> class="hljs-ln-code"> class="hljs-ln-line"> UART3_SendString(pcAT);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="889"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="890"> class="hljs-ln-code"> class="hljs-ln-line"> while (usTimeOutMs--)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="891"> class="hljs-ln-code"> class="hljs-ln-line"> {
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="892"> class="hljs-ln-code"> class="hljs-ln-line"> if (UART3_GetRxNum())
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="893"> class="hljs-ln-code"> class="hljs-ln-line"> {
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="894"> class="hljs-ln-code"> class="hljs-ln-line"> UART3_ClearRx();
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="895"> class="hljs-ln-code"> class="hljs-ln-line"> if (strstr((char *)UART3_GetRxData(), pcAckString))
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="896"> class="hljs-ln-code"> class="hljs-ln-line"> return 1;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="897"> class="hljs-ln-code"> class="hljs-ln-line"> }
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="898"> class="hljs-ln-code"> class="hljs-ln-line"> delay_ms(1);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="899"> class="hljs-ln-code"> class="hljs-ln-line"> }
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="900"> class="hljs-ln-code"> class="hljs-ln-line"> return 0;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="901"> class="hljs-ln-code"> class="hljs-ln-line">}
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="902"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="903"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="904"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="905"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="906"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="907"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="908"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="909"> class="hljs-ln-code"> class="hljs-ln-line">uint16_t UART3_GetRxNum(void)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="910"> class="hljs-ln-code"> class="hljs-ln-line">{
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="911"> class="hljs-ln-code"> class="hljs-ln-line"> return xUART3.usRxNum ;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="912"> class="hljs-ln-code"> class="hljs-ln-line">}
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="913"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="914"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="915"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="916"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="917"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="918"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="919"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="920"> class="hljs-ln-code"> class="hljs-ln-line">uint8_t *UART3_GetRxData(void)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="921"> class="hljs-ln-code"> class="hljs-ln-line">{
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="922"> class="hljs-ln-code"> class="hljs-ln-line"> return xUART3.puRxData ;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="923"> class="hljs-ln-code"> class="hljs-ln-line">}
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="924"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="925"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="926"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="927"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="928"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="929"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="930"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="931"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="932"> class="hljs-ln-code"> class="hljs-ln-line">void UART3_ClearRx(void)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="933"> class="hljs-ln-code"> class="hljs-ln-line">{
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="934"> class="hljs-ln-code"> class="hljs-ln-line"> xUART3.usRxNum = 0 ;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="935"> class="hljs-ln-code"> class="hljs-ln-line">}
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="936"> class="hljs-ln-code"> class="hljs-ln-line">#endif
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="937"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="938"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="939"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="940"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="941"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="942"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="943"> class="hljs-ln-code"> class="hljs-ln-line">/
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="944"> class="hljs-ln-code"> class="hljs-ln-line">#if UART4_EN
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="945"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="946"> class="hljs-ln-code"> class="hljs-ln-line">static xUSATR_TypeDef xUART4 = { 0 };
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="947"> class="hljs-ln-code"> class="hljs-ln-line">static uint8_t uaUart4RxData[UART4_RX_BUF_SIZE];
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="948"> class="hljs-ln-code"> class="hljs-ln-line">static uint8_t uaUart4TxFiFoData[UART4_TX_BUF_SIZE];
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="949"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="950"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="951"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="952"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="953"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="954"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="955"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="956"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="957"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="958"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="959"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="960"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="961"> class="hljs-ln-code"> class="hljs-ln-line">void UART4_Init(uint32_t ulBaudrate)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="962"> class="hljs-ln-code"> class="hljs-ln-line">{
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="963"> class="hljs-ln-code"> class="hljs-ln-line">#ifdef USE_STDPERIPH_DRIVER
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="964"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="965"> class="hljs-ln-code"> class="hljs-ln-line"> RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC, ENABLE);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="966"> class="hljs-ln-code"> class="hljs-ln-line"> RCC_APB1PeriphClockCmd(RCC_APB1Periph_UART4, ENABLE);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="967"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="968"> class="hljs-ln-code"> class="hljs-ln-line"> GPIO_PinAFConfig(GPIOC, GPIO_PinSource10, GPIO_AF_UART4);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="969"> class="hljs-ln-code"> class="hljs-ln-line"> GPIO_PinAFConfig(GPIOC, GPIO_PinSource11, GPIO_AF_UART4);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="970"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="971"> class="hljs-ln-code"> class="hljs-ln-line"> RCC_APB1PeriphResetCmd(RCC_APB1Periph_UART4, ENABLE);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="972"> class="hljs-ln-code"> class="hljs-ln-line"> RCC_APB1PeriphResetCmd(RCC_APB1Periph_UART4, DISABLE);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="973"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="974"> class="hljs-ln-code"> class="hljs-ln-line"> GPIO_InitTypeDef GPIO_InitStructure = {0};
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="975"> class="hljs-ln-code"> class="hljs-ln-line"> GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="976"> class="hljs-ln-code"> class="hljs-ln-line"> GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="977"> class="hljs-ln-code"> class="hljs-ln-line"> GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="978"> class="hljs-ln-code"> class="hljs-ln-line"> GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="979"> class="hljs-ln-code"> class="hljs-ln-line"> GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="980"> class="hljs-ln-code"> class="hljs-ln-line"> GPIO_Init(GPIOC, &GPIO_InitStructure);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="981"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="982"> class="hljs-ln-code"> class="hljs-ln-line"> GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="983"> class="hljs-ln-code"> class="hljs-ln-line"> GPIO_Init(GPIOC, &GPIO_InitStructure);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="984"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="985"> class="hljs-ln-code"> class="hljs-ln-line"> USART_InitTypeDef USART_InitStructure;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="986"> class="hljs-ln-code"> class="hljs-ln-line"> USART_InitStructure.USART_BaudRate = ulBaudrate;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="987"> class="hljs-ln-code"> class="hljs-ln-line"> USART_InitStructure.USART_WordLength = USART_WordLength_8b;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="988"> class="hljs-ln-code"> class="hljs-ln-line"> USART_InitStructure.USART_StopBits = USART_StopBits_1;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="989"> class="hljs-ln-code"> class="hljs-ln-line"> USART_InitStructure.USART_Parity = USART_Parity_No;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="990"> class="hljs-ln-code"> class="hljs-ln-line"> USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="991"> class="hljs-ln-code"> class="hljs-ln-line"> USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="992"> class="hljs-ln-code"> class="hljs-ln-line"> USART_Init(UART4, &USART_InitStructure);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="993"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="994"> class="hljs-ln-code"> class="hljs-ln-line"> USART_ITConfig(UART4, USART_IT_RXNE, ENABLE);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="995"> class="hljs-ln-code"> class="hljs-ln-line"> USART_ITConfig(UART4, USART_IT_IDLE, ENABLE);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="996"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="997"> class="hljs-ln-code"> class="hljs-ln-line"> NVIC_InitTypeDef NVIC_InitStructure = {0};
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="998"> class="hljs-ln-code"> class="hljs-ln-line"> NVIC_InitStructure .NVIC_IRQChannel = UART4_IRQn;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="999"> class="hljs-ln-code"> class="hljs-ln-line"> NVIC_InitStructure .NVIC_IRQChannelPreemptionPriority = 1;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1000"> class="hljs-ln-code"> class="hljs-ln-line"> NVIC_InitStructure .NVIC_IRQChannelSubPriority = 1;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1001"> class="hljs-ln-code"> class="hljs-ln-line"> NVIC_InitStructure .NVIC_IRQChannelCmd = ENABLE;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1002"> class="hljs-ln-code"> class="hljs-ln-line"> NVIC_Init(&NVIC_InitStructure);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1003"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1004"> class="hljs-ln-code"> class="hljs-ln-line"> USART_Cmd(UART4, ENABLE);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1005"> class="hljs-ln-code"> class="hljs-ln-line">#endif
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1006"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1007"> class="hljs-ln-code"> class="hljs-ln-line">#ifdef USE_HAL_DRIVER
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1008"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1009"> class="hljs-ln-code"> class="hljs-ln-line"> __HAL_RCC_GPIOC_CLK_ENABLE();
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1010"> class="hljs-ln-code"> class="hljs-ln-line"> __HAL_RCC_UART4_CLK_ENABLE();
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1011"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1012"> class="hljs-ln-code"> class="hljs-ln-line"> __HAL_RCC_UART4_FORCE_RESET();
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1013"> class="hljs-ln-code"> class="hljs-ln-line"> __HAL_RCC_UART4_RELEASE_RESET();
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1014"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1015"> class="hljs-ln-code"> class="hljs-ln-line"> GPIO_InitTypeDef GPIO_InitStruct = {0};
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1016"> class="hljs-ln-code"> class="hljs-ln-line"> GPIO_InitStruct.Pin = GPIO_PIN_10 | GPIO_PIN_11;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1017"> class="hljs-ln-code"> class="hljs-ln-line"> GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1018"> class="hljs-ln-code"> class="hljs-ln-line"> GPIO_InitStruct.Pull = GPIO_PULLUP;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1019"> class="hljs-ln-code"> class="hljs-ln-line"> GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1020"> class="hljs-ln-code"> class="hljs-ln-line"> GPIO_InitStruct.Alternate = GPIO_AF8_UART4;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1021"> class="hljs-ln-code"> class="hljs-ln-line"> HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1022"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1023"> class="hljs-ln-code"> class="hljs-ln-line"> float temp;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1024"> class="hljs-ln-code"> class="hljs-ln-line"> uint16_t mantissa, fraction;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1025"> class="hljs-ln-code"> class="hljs-ln-line"> SystemCoreClockUpdate();
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1026"> class="hljs-ln-code"> class="hljs-ln-line"> temp = (float)(SystemCoreClock / 4) / (ulBaudrate * 16);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1027"> class="hljs-ln-code"> class="hljs-ln-line"> mantissa = temp;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1028"> class="hljs-ln-code"> class="hljs-ln-line"> fraction = (temp - mantissa) * 16;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1029"> class="hljs-ln-code"> class="hljs-ln-line"> UART4 -> BRR = mantissa << 4 | fraction;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1030"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1031"> class="hljs-ln-code"> class="hljs-ln-line"> UART4 -> CR1 = 0;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1032"> class="hljs-ln-code"> class="hljs-ln-line"> UART4 -> CR1 |= 0x01 << 2;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1033"> class="hljs-ln-code"> class="hljs-ln-line"> UART4 -> CR1 |= 0x01 << 3;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1034"> class="hljs-ln-code"> class="hljs-ln-line"> UART4 -> CR1 |= 0x00 << 9;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1035"> class="hljs-ln-code"> class="hljs-ln-line"> UART4 -> CR1 |= 0x00 << 10;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1036"> class="hljs-ln-code"> class="hljs-ln-line"> UART4 -> CR1 |= 0x00 << 12;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1037"> class="hljs-ln-code"> class="hljs-ln-line"> UART4 -> CR2 = 0;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1038"> class="hljs-ln-code"> class="hljs-ln-line"> UART4 -> CR2 &= ~(0x03 << 12);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1039"> class="hljs-ln-code"> class="hljs-ln-line"> UART4 -> CR3 = 0;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1040"> class="hljs-ln-code"> class="hljs-ln-line"> UART4 -> CR3 &= ~(0x01 << 6);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1041"> class="hljs-ln-code"> class="hljs-ln-line"> UART4 -> CR3 &= ~(0x01 << 7);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1042"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1043"> class="hljs-ln-code"> class="hljs-ln-line"> UART4 -> CR1 &= ~(0x01 << 7);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1044"> class="hljs-ln-code"> class="hljs-ln-line"> UART4 -> CR1 |= 0x01 << 5;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1045"> class="hljs-ln-code"> class="hljs-ln-line"> UART4 -> CR1 |= 0x01 << 4;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1046"> class="hljs-ln-code"> class="hljs-ln-line"> UART4 -> SR = ~(0x00F0);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1047"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1048"> class="hljs-ln-code"> class="hljs-ln-line"> HAL_NVIC_SetPriority(UART4_IRQn, 1, 1);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1049"> class="hljs-ln-code"> class="hljs-ln-line"> HAL_NVIC_EnableIRQ(UART4_IRQn);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1050"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1051"> class="hljs-ln-code"> class="hljs-ln-line"> UART4 -> CR1 |= 0x01 << 13;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1052"> class="hljs-ln-code"> class="hljs-ln-line">#endif
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1053"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1054"> class="hljs-ln-code"> class="hljs-ln-line"> xUART4.puRxData = uaUart4RxData;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1055"> class="hljs-ln-code"> class="hljs-ln-line"> xUART4.puTxFiFoData = uaUart4TxFiFoData;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1056"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1057"> class="hljs-ln-code"> class="hljs-ln-line"> printf("UART4 初始化配置 %d-None-8-1; 已完成初始化配置、收发配置\r", ulBaudrate);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1058"> class="hljs-ln-code"> class="hljs-ln-line">}
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1059"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1060"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1061"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1062"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1063"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1064"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1065"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1066"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1067"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1068"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1069"> class="hljs-ln-code"> class="hljs-ln-line">void UART4_IRQHandler(void)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1070"> class="hljs-ln-code"> class="hljs-ln-line">{
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1071"> class="hljs-ln-code"> class="hljs-ln-line"> static uint16_t cnt = 0;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1072"> class="hljs-ln-code"> class="hljs-ln-line"> static uint8_t rxTemp[UART4_RX_BUF_SIZE];
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1073"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1074"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1075"> class="hljs-ln-code"> class="hljs-ln-line"> if ((UART4->SR & USART_SR_TXE) && (UART4->CR1 & USART_CR1_TXEIE))
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1076"> class="hljs-ln-code"> class="hljs-ln-line"> {
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1077"> class="hljs-ln-code"> class="hljs-ln-line"> UART4->DR = xUART4.puTxFiFoData[xUART4.usTxFiFoTail++];
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1078"> class="hljs-ln-code"> class="hljs-ln-line"> if (xUART4.usTxFiFoTail == UART4_TX_BUF_SIZE)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1079"> class="hljs-ln-code"> class="hljs-ln-line"> xUART4.usTxFiFoTail = 0;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1080"> class="hljs-ln-code"> class="hljs-ln-line"> if (xUART4.usTxFiFoTail == xUART4.usTxFiFoData)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1081"> class="hljs-ln-code"> class="hljs-ln-line"> UART4->CR1 &= ~USART_CR1_TXEIE;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1082"> class="hljs-ln-code"> class="hljs-ln-line"> return;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1083"> class="hljs-ln-code"> class="hljs-ln-line"> }
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1084"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1085"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1086"> class="hljs-ln-code"> class="hljs-ln-line"> if (UART4->SR & USART_SR_RXNE)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1087"> class="hljs-ln-code"> class="hljs-ln-line"> {
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1088"> class="hljs-ln-code"> class="hljs-ln-line"> if (cnt == UART4_RX_BUF_SIZE)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1089"> class="hljs-ln-code"> class="hljs-ln-line"> {
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1090"> class="hljs-ln-code"> class="hljs-ln-line"> printf("警告:UART4单帧接收量,已超出接收缓存大小!\r修改文件bsp_UART.h的UART4_RX_BUF_SIZE值,可解决此问题!\r");
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1091"> class="hljs-ln-code"> class="hljs-ln-line"> UART4->DR;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1092"> class="hljs-ln-code"> class="hljs-ln-line"> return;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1093"> class="hljs-ln-code"> class="hljs-ln-line"> }
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1094"> class="hljs-ln-code"> class="hljs-ln-line"> rxTemp[cnt++] = UART4->DR ;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1095"> class="hljs-ln-code"> class="hljs-ln-line"> return;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1096"> class="hljs-ln-code"> class="hljs-ln-line"> }
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1097"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1098"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1099"> class="hljs-ln-code"> class="hljs-ln-line"> if (UART4->SR & USART_SR_IDLE)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1100"> class="hljs-ln-code"> class="hljs-ln-line"> {
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1101"> class="hljs-ln-code"> class="hljs-ln-line"> memcpy(xUART4.puRxData, rxTemp, UART4_RX_BUF_SIZE);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1102"> class="hljs-ln-code"> class="hljs-ln-line"> xUART4.usRxNum = cnt;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1103"> class="hljs-ln-code"> class="hljs-ln-line"> cnt = 0;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1104"> class="hljs-ln-code"> class="hljs-ln-line"> memset(rxTemp, 0, UART4_RX_BUF_SIZE);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1105"> class="hljs-ln-code"> class="hljs-ln-line"> UART4 ->SR;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1106"> class="hljs-ln-code"> class="hljs-ln-line"> UART4 ->DR;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1107"> class="hljs-ln-code"> class="hljs-ln-line"> return;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1108"> class="hljs-ln-code"> class="hljs-ln-line"> }
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1109"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1110"> class="hljs-ln-code"> class="hljs-ln-line"> return;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1111"> class="hljs-ln-code"> class="hljs-ln-line">}
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1112"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1113"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1114"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1115"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1116"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1117"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1118"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1119"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1120"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1121"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1122"> class="hljs-ln-code"> class="hljs-ln-line">void UART4_SendData(uint8_t *puData, uint16_t usNum)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1123"> class="hljs-ln-code"> class="hljs-ln-line">{
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1124"> class="hljs-ln-code"> class="hljs-ln-line"> for (uint16_t i = 0; i < usNum; i++)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1125"> class="hljs-ln-code"> class="hljs-ln-line"> {
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1126"> class="hljs-ln-code"> class="hljs-ln-line"> xUART4.puTxFiFoData[xUART4.usTxFiFoData++] = puData[i];
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1127"> class="hljs-ln-code"> class="hljs-ln-line"> if (xUART4.usTxFiFoData == UART4_TX_BUF_SIZE)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1128"> class="hljs-ln-code"> class="hljs-ln-line"> xUART4.usTxFiFoData = 0;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1129"> class="hljs-ln-code"> class="hljs-ln-line"> }
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1130"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1131"> class="hljs-ln-code"> class="hljs-ln-line"> if ((UART4->CR1 & USART_CR1_TXEIE) == 0)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1132"> class="hljs-ln-code"> class="hljs-ln-line"> UART4->CR1 |= USART_CR1_TXEIE;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1133"> class="hljs-ln-code"> class="hljs-ln-line">}
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1134"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1135"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1136"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1137"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1138"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1139"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1140"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1141"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1142"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1143"> class="hljs-ln-code"> class="hljs-ln-line">void UART4_SendString(const char *pcString, ...)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1144"> class="hljs-ln-code"> class="hljs-ln-line">{
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1145"> class="hljs-ln-code"> class="hljs-ln-line"> char mBuffer[512] = {0};;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1146"> class="hljs-ln-code"> class="hljs-ln-line"> va_list ap;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1147"> class="hljs-ln-code"> class="hljs-ln-line"> va_start(ap, pcString);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1148"> class="hljs-ln-code"> class="hljs-ln-line"> vsnprintf(mBuffer, 512, pcString, ap);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1149"> class="hljs-ln-code"> class="hljs-ln-line"> va_end(ap);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1150"> class="hljs-ln-code"> class="hljs-ln-line"> UART4_SendData((uint8_t *)mBuffer, strlen(mBuffer));
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1151"> class="hljs-ln-code"> class="hljs-ln-line">}
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1152"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1153"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1154"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1155"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1156"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1157"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1158"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1159"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1160"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1161"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1162"> class="hljs-ln-code"> class="hljs-ln-line">uint8_t UART4_SendAT(char *pcAT, char *pcAckString, uint16_t usTimeOutMs)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1163"> class="hljs-ln-code"> class="hljs-ln-line">{
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1164"> class="hljs-ln-code"> class="hljs-ln-line"> UART4_ClearRx();
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1165"> class="hljs-ln-code"> class="hljs-ln-line"> UART4_SendString(pcAT);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1166"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1167"> class="hljs-ln-code"> class="hljs-ln-line"> while (usTimeOutMs--)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1168"> class="hljs-ln-code"> class="hljs-ln-line"> {
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1169"> class="hljs-ln-code"> class="hljs-ln-line"> if (UART4_GetRxNum())
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1170"> class="hljs-ln-code"> class="hljs-ln-line"> {
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1171"> class="hljs-ln-code"> class="hljs-ln-line"> UART4_ClearRx();
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1172"> class="hljs-ln-code"> class="hljs-ln-line"> if (strstr((char *)UART4_GetRxData(), pcAckString))
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1173"> class="hljs-ln-code"> class="hljs-ln-line"> return 1;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1174"> class="hljs-ln-code"> class="hljs-ln-line"> }
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1175"> class="hljs-ln-code"> class="hljs-ln-line"> delay_ms(1);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1176"> class="hljs-ln-code"> class="hljs-ln-line"> }
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1177"> class="hljs-ln-code"> class="hljs-ln-line"> return 0;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1178"> class="hljs-ln-code"> class="hljs-ln-line">}
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1179"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1180"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1181"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1182"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1183"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1184"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1185"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1186"> class="hljs-ln-code"> class="hljs-ln-line">uint16_t UART4_GetRxNum(void)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1187"> class="hljs-ln-code"> class="hljs-ln-line">{
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1188"> class="hljs-ln-code"> class="hljs-ln-line"> return xUART4.usRxNum ;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1189"> class="hljs-ln-code"> class="hljs-ln-line">}
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1190"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1191"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1192"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1193"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1194"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1195"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1196"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1197"> class="hljs-ln-code"> class="hljs-ln-line">uint8_t *UART4_GetRxData(void)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1198"> class="hljs-ln-code"> class="hljs-ln-line">{
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1199"> class="hljs-ln-code"> class="hljs-ln-line"> return xUART4.puRxData ;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1200"> class="hljs-ln-code"> class="hljs-ln-line">}
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1201"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1202"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1203"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1204"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1205"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1206"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1207"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1208"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1209"> class="hljs-ln-code"> class="hljs-ln-line">void UART4_ClearRx(void)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1210"> class="hljs-ln-code"> class="hljs-ln-line">{
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1211"> class="hljs-ln-code"> class="hljs-ln-line"> xUART4.usRxNum = 0 ;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1212"> class="hljs-ln-code"> class="hljs-ln-line">}
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1213"> class="hljs-ln-code"> class="hljs-ln-line">#endif
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1214"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1215"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1216"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1217"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1218"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1219"> class="hljs-ln-code"> class="hljs-ln-line">/
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1220"> class="hljs-ln-code"> class="hljs-ln-line">#if UART5_EN
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1221"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1222"> class="hljs-ln-code"> class="hljs-ln-line">static xUSATR_TypeDef xUART5 = { 0 };
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1223"> class="hljs-ln-code"> class="hljs-ln-line">static uint8_t uaUart5RxData[UART5_RX_BUF_SIZE];
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1224"> class="hljs-ln-code"> class="hljs-ln-line">static uint8_t uaUart5TxFiFoData[UART5_TX_BUF_SIZE];
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1225"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1226"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1227"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1228"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1229"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1230"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1231"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1232"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1233"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1234"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1235"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1236"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1237"> class="hljs-ln-code"> class="hljs-ln-line">void UART5_Init(uint32_t ulBaudrate)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1238"> class="hljs-ln-code"> class="hljs-ln-line">{
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1239"> class="hljs-ln-code"> class="hljs-ln-line">#ifdef USE_STDPERIPH_DRIVER
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1240"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1241"> class="hljs-ln-code"> class="hljs-ln-line"> RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC, ENABLE);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1242"> class="hljs-ln-code"> class="hljs-ln-line"> RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1243"> class="hljs-ln-code"> class="hljs-ln-line"> RCC_APB1PeriphClockCmd(RCC_APB1Periph_UART5, ENABLE);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1244"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1245"> class="hljs-ln-code"> class="hljs-ln-line"> GPIO_PinAFConfig(GPIOC, GPIO_PinSource12, GPIO_AF_UART5);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1246"> class="hljs-ln-code"> class="hljs-ln-line"> GPIO_PinAFConfig(GPIOD, GPIO_PinSource2, GPIO_AF_UART5);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1247"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1248"> class="hljs-ln-code"> class="hljs-ln-line"> RCC_APB1PeriphResetCmd(RCC_APB1Periph_UART5, ENABLE);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1249"> class="hljs-ln-code"> class="hljs-ln-line"> RCC_APB1PeriphResetCmd(RCC_APB1Periph_UART5, DISABLE);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1250"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1251"> class="hljs-ln-code"> class="hljs-ln-line"> GPIO_InitTypeDef GPIO_InitStructure = {0};
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1252"> class="hljs-ln-code"> class="hljs-ln-line"> GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1253"> class="hljs-ln-code"> class="hljs-ln-line"> GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1254"> class="hljs-ln-code"> class="hljs-ln-line"> GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1255"> class="hljs-ln-code"> class="hljs-ln-line"> GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1256"> class="hljs-ln-code"> class="hljs-ln-line"> GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1257"> class="hljs-ln-code"> class="hljs-ln-line"> GPIO_Init(GPIOC, &GPIO_InitStructure);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1258"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1259"> class="hljs-ln-code"> class="hljs-ln-line"> GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1260"> class="hljs-ln-code"> class="hljs-ln-line"> GPIO_Init(GPIOD, &GPIO_InitStructure);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1261"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1262"> class="hljs-ln-code"> class="hljs-ln-line"> USART_InitTypeDef USART_InitStructure;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1263"> class="hljs-ln-code"> class="hljs-ln-line"> USART_InitStructure.USART_BaudRate = ulBaudrate;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1264"> class="hljs-ln-code"> class="hljs-ln-line"> USART_InitStructure.USART_WordLength = USART_WordLength_8b;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1265"> class="hljs-ln-code"> class="hljs-ln-line"> USART_InitStructure.USART_StopBits = USART_StopBits_1;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1266"> class="hljs-ln-code"> class="hljs-ln-line"> USART_InitStructure.USART_Parity = USART_Parity_No;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1267"> class="hljs-ln-code"> class="hljs-ln-line"> USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1268"> class="hljs-ln-code"> class="hljs-ln-line"> USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1269"> class="hljs-ln-code"> class="hljs-ln-line"> USART_Init(UART5, &USART_InitStructure);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1270"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1271"> class="hljs-ln-code"> class="hljs-ln-line"> USART_ITConfig(UART5, USART_IT_RXNE, ENABLE);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1272"> class="hljs-ln-code"> class="hljs-ln-line"> USART_ITConfig(UART5, USART_IT_IDLE, ENABLE);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1273"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1274"> class="hljs-ln-code"> class="hljs-ln-line"> NVIC_InitTypeDef NVIC_InitStructure = {0};
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1275"> class="hljs-ln-code"> class="hljs-ln-line"> NVIC_InitStructure .NVIC_IRQChannel = UART5_IRQn;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1276"> class="hljs-ln-code"> class="hljs-ln-line"> NVIC_InitStructure .NVIC_IRQChannelPreemptionPriority = 1;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1277"> class="hljs-ln-code"> class="hljs-ln-line"> NVIC_InitStructure .NVIC_IRQChannelSubPriority = 1;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1278"> class="hljs-ln-code"> class="hljs-ln-line"> NVIC_InitStructure .NVIC_IRQChannelCmd = ENABLE;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1279"> class="hljs-ln-code"> class="hljs-ln-line"> NVIC_Init(&NVIC_InitStructure);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1280"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1281"> class="hljs-ln-code"> class="hljs-ln-line"> USART_Cmd(UART5, ENABLE);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1282"> class="hljs-ln-code"> class="hljs-ln-line">#endif
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1283"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1284"> class="hljs-ln-code"> class="hljs-ln-line">#ifdef USE_HAL_DRIVER
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1285"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1286"> class="hljs-ln-code"> class="hljs-ln-line"> __HAL_RCC_GPIOC_CLK_ENABLE();
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1287"> class="hljs-ln-code"> class="hljs-ln-line"> __HAL_RCC_GPIOD_CLK_ENABLE();
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1288"> class="hljs-ln-code"> class="hljs-ln-line"> __HAL_RCC_UART5_CLK_ENABLE();
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1289"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1290"> class="hljs-ln-code"> class="hljs-ln-line"> __HAL_RCC_UART5_FORCE_RESET();
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1291"> class="hljs-ln-code"> class="hljs-ln-line"> __HAL_RCC_UART5_RELEASE_RESET();
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1292"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1293"> class="hljs-ln-code"> class="hljs-ln-line"> GPIO_InitTypeDef GPIO_InitStruct = {0};
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1294"> class="hljs-ln-code"> class="hljs-ln-line"> GPIO_InitStruct.Pin = GPIO_PIN_12 ;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1295"> class="hljs-ln-code"> class="hljs-ln-line"> GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1296"> class="hljs-ln-code"> class="hljs-ln-line"> GPIO_InitStruct.Pull = GPIO_NOPULL;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1297"> class="hljs-ln-code"> class="hljs-ln-line"> GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1298"> class="hljs-ln-code"> class="hljs-ln-line"> GPIO_InitStruct.Alternate = GPIO_AF8_UART5;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1299"> class="hljs-ln-code"> class="hljs-ln-line"> HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1300"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1301"> class="hljs-ln-code"> class="hljs-ln-line"> GPIO_InitStruct.Pin = GPIO_PIN_2 ;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1302"> class="hljs-ln-code"> class="hljs-ln-line"> HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1303"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1304"> class="hljs-ln-code"> class="hljs-ln-line"> float temp;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1305"> class="hljs-ln-code"> class="hljs-ln-line"> uint16_t mantissa, fraction;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1306"> class="hljs-ln-code"> class="hljs-ln-line"> SystemCoreClockUpdate();
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1307"> class="hljs-ln-code"> class="hljs-ln-line"> temp = (float)(SystemCoreClock / 4) / (ulBaudrate * 16);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1308"> class="hljs-ln-code"> class="hljs-ln-line"> mantissa = temp;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1309"> class="hljs-ln-code"> class="hljs-ln-line"> fraction = (temp - mantissa) * 16;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1310"> class="hljs-ln-code"> class="hljs-ln-line"> UART5 -> BRR = mantissa << 4 | fraction;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1311"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1312"> class="hljs-ln-code"> class="hljs-ln-line"> UART5 -> CR1 = 0;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1313"> class="hljs-ln-code"> class="hljs-ln-line"> UART5 -> CR1 |= 0x01 << 2;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1314"> class="hljs-ln-code"> class="hljs-ln-line"> UART5 -> CR1 |= 0x01 << 3;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1315"> class="hljs-ln-code"> class="hljs-ln-line"> UART5 -> CR1 |= 0x00 << 9;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1316"> class="hljs-ln-code"> class="hljs-ln-line"> UART5 -> CR1 |= 0x00 << 10;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1317"> class="hljs-ln-code"> class="hljs-ln-line"> UART5 -> CR1 |= 0x00 << 12;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1318"> class="hljs-ln-code"> class="hljs-ln-line"> UART5 -> CR2 = 0;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1319"> class="hljs-ln-code"> class="hljs-ln-line"> UART5 -> CR2 &= ~(0x03 << 12);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1320"> class="hljs-ln-code"> class="hljs-ln-line"> UART5 -> CR3 = 0;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1321"> class="hljs-ln-code"> class="hljs-ln-line"> UART5 -> CR3 &= ~(0x01 << 6);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1322"> class="hljs-ln-code"> class="hljs-ln-line"> UART5 -> CR3 &= ~(0x01 << 7);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1323"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1324"> class="hljs-ln-code"> class="hljs-ln-line"> UART5 -> CR1 &= ~(0x01 << 7);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1325"> class="hljs-ln-code"> class="hljs-ln-line"> UART5 -> CR1 |= 0x01 << 5;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1326"> class="hljs-ln-code"> class="hljs-ln-line"> UART5 -> CR1 |= 0x01 << 4;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1327"> class="hljs-ln-code"> class="hljs-ln-line"> UART5 -> SR = ~(0x00F0);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1328"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1329"> class="hljs-ln-code"> class="hljs-ln-line"> HAL_NVIC_SetPriority(UART5_IRQn, 0, 0);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1330"> class="hljs-ln-code"> class="hljs-ln-line"> HAL_NVIC_EnableIRQ(UART5_IRQn);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1331"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1332"> class="hljs-ln-code"> class="hljs-ln-line"> UART5 -> CR1 |= 0x01 << 13;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1333"> class="hljs-ln-code"> class="hljs-ln-line">#endif
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1334"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1335"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1336"> class="hljs-ln-code"> class="hljs-ln-line"> xUART5.puRxData = uaUart5RxData;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1337"> class="hljs-ln-code"> class="hljs-ln-line"> xUART5.puTxFiFoData = uaUart5TxFiFoData;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1338"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1339"> class="hljs-ln-code"> class="hljs-ln-line"> printf("UART5 初始化配置 %d-None-8-1; 已完成初始化配置、收发配置\r", ulBaudrate);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1340"> class="hljs-ln-code"> class="hljs-ln-line">}
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1341"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1342"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1343"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1344"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1345"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1346"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1347"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1348"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1349"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1350"> class="hljs-ln-code"> class="hljs-ln-line">void UART5_IRQHandler(void)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1351"> class="hljs-ln-code"> class="hljs-ln-line">{
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1352"> class="hljs-ln-code"> class="hljs-ln-line"> static uint16_t cnt = 0;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1353"> class="hljs-ln-code"> class="hljs-ln-line"> static uint8_t rxTemp[UART5_RX_BUF_SIZE];
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1354"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1355"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1356"> class="hljs-ln-code"> class="hljs-ln-line"> if ((UART5->SR & USART_SR_TXE) && (UART5->CR1 & USART_CR1_TXEIE))
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1357"> class="hljs-ln-code"> class="hljs-ln-line"> {
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1358"> class="hljs-ln-code"> class="hljs-ln-line"> UART5->DR = xUART5.puTxFiFoData[xUART5.usTxFiFoTail++];
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1359"> class="hljs-ln-code"> class="hljs-ln-line"> if (xUART5.usTxFiFoTail == UART5_TX_BUF_SIZE)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1360"> class="hljs-ln-code"> class="hljs-ln-line"> xUART5.usTxFiFoTail = 0;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1361"> class="hljs-ln-code"> class="hljs-ln-line"> if (xUART5.usTxFiFoTail == xUART5.usTxFiFoData)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1362"> class="hljs-ln-code"> class="hljs-ln-line"> UART5->CR1 &= ~USART_CR1_TXEIE;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1363"> class="hljs-ln-code"> class="hljs-ln-line"> return;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1364"> class="hljs-ln-code"> class="hljs-ln-line"> }
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1365"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1366"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1367"> class="hljs-ln-code"> class="hljs-ln-line"> if (UART5->SR & USART_SR_RXNE)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1368"> class="hljs-ln-code"> class="hljs-ln-line"> {
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1369"> class="hljs-ln-code"> class="hljs-ln-line"> if (cnt == UART5_RX_BUF_SIZE)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1370"> class="hljs-ln-code"> class="hljs-ln-line"> {
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1371"> class="hljs-ln-code"> class="hljs-ln-line"> printf("警告:UART5单帧接收量,已超出接收缓存大小!\r修改文件bsp_UART.h的UART5_RX_BUF_SIZE值,可解决此问题!\r");
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1372"> class="hljs-ln-code"> class="hljs-ln-line"> UART5->DR;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1373"> class="hljs-ln-code"> class="hljs-ln-line"> return;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1374"> class="hljs-ln-code"> class="hljs-ln-line"> }
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1375"> class="hljs-ln-code"> class="hljs-ln-line"> rxTemp[cnt++] = UART5->DR ;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1376"> class="hljs-ln-code"> class="hljs-ln-line"> return;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1377"> class="hljs-ln-code"> class="hljs-ln-line"> }
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1378"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1379"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1380"> class="hljs-ln-code"> class="hljs-ln-line"> if (UART5->SR & USART_SR_IDLE)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1381"> class="hljs-ln-code"> class="hljs-ln-line"> {
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1382"> class="hljs-ln-code"> class="hljs-ln-line"> memcpy(xUART5.puRxData, rxTemp, UART5_RX_BUF_SIZE);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1383"> class="hljs-ln-code"> class="hljs-ln-line"> xUART5.usRxNum = cnt;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1384"> class="hljs-ln-code"> class="hljs-ln-line"> cnt = 0;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1385"> class="hljs-ln-code"> class="hljs-ln-line"> memset(rxTemp, 0, UART5_RX_BUF_SIZE);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1386"> class="hljs-ln-code"> class="hljs-ln-line"> UART5 -> SR;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1387"> class="hljs-ln-code"> class="hljs-ln-line"> UART5 -> DR;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1388"> class="hljs-ln-code"> class="hljs-ln-line"> return;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1389"> class="hljs-ln-code"> class="hljs-ln-line"> }
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1390"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1391"> class="hljs-ln-code"> class="hljs-ln-line"> return;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1392"> class="hljs-ln-code"> class="hljs-ln-line">}
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1393"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1394"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1395"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1396"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1397"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1398"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1399"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1400"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1401"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1402"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1403"> class="hljs-ln-code"> class="hljs-ln-line">void UART5_SendData(uint8_t *pudata, uint16_t usNum)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1404"> class="hljs-ln-code"> class="hljs-ln-line">{
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1405"> class="hljs-ln-code"> class="hljs-ln-line"> for (uint16_t i = 0; i < usNum; i++)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1406"> class="hljs-ln-code"> class="hljs-ln-line"> {
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1407"> class="hljs-ln-code"> class="hljs-ln-line"> xUART5.puTxFiFoData[xUART5.usTxFiFoData++] = pudata[i];
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1408"> class="hljs-ln-code"> class="hljs-ln-line"> if (xUART5.usTxFiFoData == UART5_TX_BUF_SIZE)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1409"> class="hljs-ln-code"> class="hljs-ln-line"> xUART5.usTxFiFoData = 0;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1410"> class="hljs-ln-code"> class="hljs-ln-line"> }
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1411"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1412"> class="hljs-ln-code"> class="hljs-ln-line"> if ((UART5->CR1 & USART_CR1_TXEIE) == 0)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1413"> class="hljs-ln-code"> class="hljs-ln-line"> UART5->CR1 |= USART_CR1_TXEIE;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1414"> class="hljs-ln-code"> class="hljs-ln-line">}
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1415"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1416"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1417"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1418"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1419"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1420"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1421"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1422"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1423"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1424"> class="hljs-ln-code"> class="hljs-ln-line">void UART5_SendString(const char *pcString, ...)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1425"> class="hljs-ln-code"> class="hljs-ln-line">{
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1426"> class="hljs-ln-code"> class="hljs-ln-line"> char mBuffer[512] = {0};;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1427"> class="hljs-ln-code"> class="hljs-ln-line"> va_list ap;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1428"> class="hljs-ln-code"> class="hljs-ln-line"> va_start(ap, pcString);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1429"> class="hljs-ln-code"> class="hljs-ln-line"> vsnprintf(mBuffer, 512, pcString, ap);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1430"> class="hljs-ln-code"> class="hljs-ln-line"> va_end(ap);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1431"> class="hljs-ln-code"> class="hljs-ln-line"> UART5_SendData((uint8_t *)mBuffer, strlen(mBuffer));
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1432"> class="hljs-ln-code"> class="hljs-ln-line">}
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1433"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1434"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1435"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1436"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1437"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1438"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1439"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1440"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1441"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1442"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1443"> class="hljs-ln-code"> class="hljs-ln-line">uint8_t UART5_SendAT(char *pcAT, char *pcAckString, uint16_t usTimeOutMs)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1444"> class="hljs-ln-code"> class="hljs-ln-line">{
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1445"> class="hljs-ln-code"> class="hljs-ln-line"> UART5_ClearRx();
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1446"> class="hljs-ln-code"> class="hljs-ln-line"> UART5_SendString(pcAT);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1447"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1448"> class="hljs-ln-code"> class="hljs-ln-line"> while (usTimeOutMs--)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1449"> class="hljs-ln-code"> class="hljs-ln-line"> {
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1450"> class="hljs-ln-code"> class="hljs-ln-line"> if (UART5_GetRxNum())
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1451"> class="hljs-ln-code"> class="hljs-ln-line"> {
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1452"> class="hljs-ln-code"> class="hljs-ln-line"> UART5_ClearRx();
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1453"> class="hljs-ln-code"> class="hljs-ln-line"> if (strstr((char *)UART5_GetRxData(), pcAckString))
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1454"> class="hljs-ln-code"> class="hljs-ln-line"> return 1;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1455"> class="hljs-ln-code"> class="hljs-ln-line"> }
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1456"> class="hljs-ln-code"> class="hljs-ln-line"> delay_ms(1);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1457"> class="hljs-ln-code"> class="hljs-ln-line"> }
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1458"> class="hljs-ln-code"> class="hljs-ln-line"> return 0;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1459"> class="hljs-ln-code"> class="hljs-ln-line">}
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1460"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1461"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1462"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1463"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1464"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1465"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1466"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1467"> class="hljs-ln-code"> class="hljs-ln-line">uint16_t UART5_GetRxNum(void)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1468"> class="hljs-ln-code"> class="hljs-ln-line">{
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1469"> class="hljs-ln-code"> class="hljs-ln-line"> return xUART5.usRxNum ;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1470"> class="hljs-ln-code"> class="hljs-ln-line">}
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1471"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1472"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1473"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1474"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1475"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1476"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1477"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1478"> class="hljs-ln-code"> class="hljs-ln-line">uint8_t *UART5_GetRxData(void)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1479"> class="hljs-ln-code"> class="hljs-ln-line">{
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1480"> class="hljs-ln-code"> class="hljs-ln-line"> return xUART5.puRxData ;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1481"> class="hljs-ln-code"> class="hljs-ln-line">}
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1482"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1483"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1484"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1485"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1486"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1487"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1488"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1489"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1490"> class="hljs-ln-code"> class="hljs-ln-line">void UART5_ClearRx(void)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1491"> class="hljs-ln-code"> class="hljs-ln-line">{
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1492"> class="hljs-ln-code"> class="hljs-ln-line"> xUART5.usRxNum = 0 ;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1493"> class="hljs-ln-code"> class="hljs-ln-line">}
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1494"> class="hljs-ln-code"> class="hljs-ln-line">#endif
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1495"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1496"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1497"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1498"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1499"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1500"> class="hljs-ln-code"> class="hljs-ln-line">/
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1501"> class="hljs-ln-code"> class="hljs-ln-line">#if UART6_EN
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1502"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1503"> class="hljs-ln-code"> class="hljs-ln-line">static xUSATR_TypeDef xUART6 = { 0 };
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1504"> class="hljs-ln-code"> class="hljs-ln-line">static uint8_t uaUart6RxData[UART6_RX_BUF_SIZE];
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1505"> class="hljs-ln-code"> class="hljs-ln-line">static uint8_t uaUart6TxFiFoData[UART6_TX_BUF_SIZE];
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1506"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1507"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1508"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1509"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1510"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1511"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1512"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1513"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1514"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1515"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1516"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1517"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1518"> class="hljs-ln-code"> class="hljs-ln-line">void UART6_Init(uint32_t ulBaudrate)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1519"> class="hljs-ln-code"> class="hljs-ln-line">{
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1520"> class="hljs-ln-code"> class="hljs-ln-line">#ifdef USE_STDPERIPH_DRIVER
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1521"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1522"> class="hljs-ln-code"> class="hljs-ln-line"> RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC, ENABLE);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1523"> class="hljs-ln-code"> class="hljs-ln-line"> RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART6, ENABLE);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1524"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1525"> class="hljs-ln-code"> class="hljs-ln-line"> GPIO_PinAFConfig(GPIOC, GPIO_PinSource6, GPIO_AF_USART6);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1526"> class="hljs-ln-code"> class="hljs-ln-line"> GPIO_PinAFConfig(GPIOC, GPIO_PinSource7, GPIO_AF_USART6);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1527"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1528"> class="hljs-ln-code"> class="hljs-ln-line"> RCC_APB2PeriphResetCmd(RCC_APB2Periph_USART6, ENABLE);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1529"> class="hljs-ln-code"> class="hljs-ln-line"> RCC_APB2PeriphResetCmd(RCC_APB2Periph_USART6, DISABLE);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1530"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1531"> class="hljs-ln-code"> class="hljs-ln-line"> GPIO_InitTypeDef GPIO_InitStructure = {0};
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1532"> class="hljs-ln-code"> class="hljs-ln-line"> GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1533"> class="hljs-ln-code"> class="hljs-ln-line"> GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1534"> class="hljs-ln-code"> class="hljs-ln-line"> GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1535"> class="hljs-ln-code"> class="hljs-ln-line"> GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1536"> class="hljs-ln-code"> class="hljs-ln-line"> GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1537"> class="hljs-ln-code"> class="hljs-ln-line"> GPIO_Init(GPIOC, &GPIO_InitStructure);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1538"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1539"> class="hljs-ln-code"> class="hljs-ln-line"> GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1540"> class="hljs-ln-code"> class="hljs-ln-line"> GPIO_Init(GPIOC, &GPIO_InitStructure);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1541"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1542"> class="hljs-ln-code"> class="hljs-ln-line"> USART_InitTypeDef USART_InitStructure;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1543"> class="hljs-ln-code"> class="hljs-ln-line"> USART_InitStructure.USART_BaudRate = ulBaudrate;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1544"> class="hljs-ln-code"> class="hljs-ln-line"> USART_InitStructure.USART_WordLength = USART_WordLength_8b;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1545"> class="hljs-ln-code"> class="hljs-ln-line"> USART_InitStructure.USART_StopBits = USART_StopBits_1;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1546"> class="hljs-ln-code"> class="hljs-ln-line"> USART_InitStructure.USART_Parity = USART_Parity_No;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1547"> class="hljs-ln-code"> class="hljs-ln-line"> USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1548"> class="hljs-ln-code"> class="hljs-ln-line"> USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1549"> class="hljs-ln-code"> class="hljs-ln-line"> USART_Init(USART6, &USART_InitStructure);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1550"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1551"> class="hljs-ln-code"> class="hljs-ln-line"> USART_ITConfig(USART6, USART_IT_RXNE, ENABLE);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1552"> class="hljs-ln-code"> class="hljs-ln-line"> USART_ITConfig(USART6, USART_IT_IDLE, ENABLE);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1553"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1554"> class="hljs-ln-code"> class="hljs-ln-line"> NVIC_InitTypeDef NVIC_InitStructure = {0};
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1555"> class="hljs-ln-code"> class="hljs-ln-line"> NVIC_InitStructure .NVIC_IRQChannel = USART6_IRQn;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1556"> class="hljs-ln-code"> class="hljs-ln-line"> NVIC_InitStructure .NVIC_IRQChannelPreemptionPriority = 1;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1557"> class="hljs-ln-code"> class="hljs-ln-line"> NVIC_InitStructure .NVIC_IRQChannelSubPriority = 1;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1558"> class="hljs-ln-code"> class="hljs-ln-line"> NVIC_InitStructure .NVIC_IRQChannelCmd = ENABLE;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1559"> class="hljs-ln-code"> class="hljs-ln-line"> NVIC_Init(&NVIC_InitStructure);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1560"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1561"> class="hljs-ln-code"> class="hljs-ln-line"> USART_Cmd(USART6, ENABLE);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1562"> class="hljs-ln-code"> class="hljs-ln-line">#endif
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1563"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1564"> class="hljs-ln-code"> class="hljs-ln-line">#ifdef USE_HAL_DRIVER
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1565"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1566"> class="hljs-ln-code"> class="hljs-ln-line"> __HAL_RCC_GPIOC_CLK_ENABLE();
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1567"> class="hljs-ln-code"> class="hljs-ln-line"> __HAL_RCC_USART6_CLK_ENABLE();
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1568"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1569"> class="hljs-ln-code"> class="hljs-ln-line"> __HAL_RCC_USART6_FORCE_RESET();
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1570"> class="hljs-ln-code"> class="hljs-ln-line"> __HAL_RCC_USART6_RELEASE_RESET();
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1571"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1572"> class="hljs-ln-code"> class="hljs-ln-line"> GPIO_InitTypeDef GPIO_InitStruct = {0};
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1573"> class="hljs-ln-code"> class="hljs-ln-line"> GPIO_InitStruct.Pin = GPIO_PIN_6 | GPIO_PIN_7;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1574"> class="hljs-ln-code"> class="hljs-ln-line"> GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1575"> class="hljs-ln-code"> class="hljs-ln-line"> GPIO_InitStruct.Pull = GPIO_PULLUP;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1576"> class="hljs-ln-code"> class="hljs-ln-line"> GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1577"> class="hljs-ln-code"> class="hljs-ln-line"> GPIO_InitStruct.Alternate = GPIO_AF8_USART6;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1578"> class="hljs-ln-code"> class="hljs-ln-line"> HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1579"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1580"> class="hljs-ln-code"> class="hljs-ln-line"> float temp;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1581"> class="hljs-ln-code"> class="hljs-ln-line"> uint16_t mantissa, fraction;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1582"> class="hljs-ln-code"> class="hljs-ln-line"> SystemCoreClockUpdate();
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1583"> class="hljs-ln-code"> class="hljs-ln-line"> temp = (float)(SystemCoreClock / 2) / (ulBaudrate * 16);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1584"> class="hljs-ln-code"> class="hljs-ln-line"> mantissa = temp;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1585"> class="hljs-ln-code"> class="hljs-ln-line"> fraction = (temp - mantissa) * 16;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1586"> class="hljs-ln-code"> class="hljs-ln-line"> USART6 -> BRR = mantissa << 4 | fraction;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1587"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1588"> class="hljs-ln-code"> class="hljs-ln-line"> USART6 -> CR1 = 0;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1589"> class="hljs-ln-code"> class="hljs-ln-line"> USART6 -> CR1 |= 0x01 << 2;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1590"> class="hljs-ln-code"> class="hljs-ln-line"> USART6 -> CR1 |= 0x01 << 3;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1591"> class="hljs-ln-code"> class="hljs-ln-line"> USART6 -> CR1 |= 0x00 << 9;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1592"> class="hljs-ln-code"> class="hljs-ln-line"> USART6 -> CR1 |= 0x00 << 10;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1593"> class="hljs-ln-code"> class="hljs-ln-line"> USART6 -> CR1 |= 0x00 << 12;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1594"> class="hljs-ln-code"> class="hljs-ln-line"> USART6 -> CR2 = 0;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1595"> class="hljs-ln-code"> class="hljs-ln-line"> USART6 -> CR2 &= ~(0x03 << 12);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1596"> class="hljs-ln-code"> class="hljs-ln-line"> USART6 -> CR3 = 0;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1597"> class="hljs-ln-code"> class="hljs-ln-line"> USART6 -> CR3 &= ~(0x01 << 6);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1598"> class="hljs-ln-code"> class="hljs-ln-line"> USART6 -> CR3 &= ~(0x01 << 7);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1599"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1600"> class="hljs-ln-code"> class="hljs-ln-line"> USART6 -> CR1 &= ~(0x01 << 7);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1601"> class="hljs-ln-code"> class="hljs-ln-line"> USART6 -> CR1 |= 0x01 << 5;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1602"> class="hljs-ln-code"> class="hljs-ln-line"> USART6 -> CR1 |= 0x01 << 4;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1603"> class="hljs-ln-code"> class="hljs-ln-line"> USART6 -> SR = ~(0x00F0);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1604"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1605"> class="hljs-ln-code"> class="hljs-ln-line"> HAL_NVIC_SetPriority(USART6_IRQn, 1, 1);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1606"> class="hljs-ln-code"> class="hljs-ln-line"> HAL_NVIC_EnableIRQ(USART6_IRQn);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1607"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1608"> class="hljs-ln-code"> class="hljs-ln-line"> USART6 -> CR1 |= 0x01 << 13;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1609"> class="hljs-ln-code"> class="hljs-ln-line">#endif
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1610"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1611"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1612"> class="hljs-ln-code"> class="hljs-ln-line"> xUART6.puRxData = uaUart6RxData;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1613"> class="hljs-ln-code"> class="hljs-ln-line"> xUART6.puTxFiFoData = uaUart6TxFiFoData;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1614"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1615"> class="hljs-ln-code"> class="hljs-ln-line"> printf("UART6 初始化配置 %d-None-8-1; 已完成初始化配置、收发配置\r", ulBaudrate);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1616"> class="hljs-ln-code"> class="hljs-ln-line">}
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1617"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1618"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1619"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1620"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1621"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1622"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1623"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1624"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1625"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1626"> class="hljs-ln-code"> class="hljs-ln-line">void USART6_IRQHandler(void)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1627"> class="hljs-ln-code"> class="hljs-ln-line">{
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1628"> class="hljs-ln-code"> class="hljs-ln-line"> static uint16_t cnt = 0;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1629"> class="hljs-ln-code"> class="hljs-ln-line"> static uint8_t rxTemp[UART6_RX_BUF_SIZE];
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1630"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1631"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1632"> class="hljs-ln-code"> class="hljs-ln-line"> if ((USART6->SR & USART_SR_TXE) && (USART6->CR1 & USART_CR1_TXEIE))
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1633"> class="hljs-ln-code"> class="hljs-ln-line"> {
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1634"> class="hljs-ln-code"> class="hljs-ln-line"> USART6->DR = xUART6.puTxFiFoData[xUART6.usTxFiFoTail++];
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1635"> class="hljs-ln-code"> class="hljs-ln-line"> if (xUART6.usTxFiFoTail == UART6_TX_BUF_SIZE)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1636"> class="hljs-ln-code"> class="hljs-ln-line"> xUART6.usTxFiFoTail = 0;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1637"> class="hljs-ln-code"> class="hljs-ln-line"> if (xUART6.usTxFiFoTail == xUART6.usTxFiFoData)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1638"> class="hljs-ln-code"> class="hljs-ln-line"> USART6->CR1 &= ~USART_CR1_TXEIE;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1639"> class="hljs-ln-code"> class="hljs-ln-line"> return;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1640"> class="hljs-ln-code"> class="hljs-ln-line"> }
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1641"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1642"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1643"> class="hljs-ln-code"> class="hljs-ln-line"> if (USART6->SR & USART_SR_RXNE)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1644"> class="hljs-ln-code"> class="hljs-ln-line"> {
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1645"> class="hljs-ln-code"> class="hljs-ln-line"> if (cnt >= UART6_RX_BUF_SIZE)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1646"> class="hljs-ln-code"> class="hljs-ln-line"> {
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1647"> class="hljs-ln-code"> class="hljs-ln-line"> printf("警告:USART6单帧接收量,已超出接收缓存大小!\r修改文件bsp_UART.h的UART6_RX_BUF_SIZE值,可解决此问题!\r");
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1648"> class="hljs-ln-code"> class="hljs-ln-line"> USART6->DR;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1649"> class="hljs-ln-code"> class="hljs-ln-line"> return;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1650"> class="hljs-ln-code"> class="hljs-ln-line"> }
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1651"> class="hljs-ln-code"> class="hljs-ln-line"> rxTemp[cnt++] = USART6->DR ;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1652"> class="hljs-ln-code"> class="hljs-ln-line"> return;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1653"> class="hljs-ln-code"> class="hljs-ln-line"> }
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1654"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1655"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1656"> class="hljs-ln-code"> class="hljs-ln-line"> if (USART6->SR & USART_SR_IDLE)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1657"> class="hljs-ln-code"> class="hljs-ln-line"> {
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1658"> class="hljs-ln-code"> class="hljs-ln-line"> memcpy(xUART6.puRxData, rxTemp, UART6_RX_BUF_SIZE);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1659"> class="hljs-ln-code"> class="hljs-ln-line"> xUART6.usRxNum = cnt;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1660"> class="hljs-ln-code"> class="hljs-ln-line"> cnt = 0;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1661"> class="hljs-ln-code"> class="hljs-ln-line"> memset(rxTemp, 0, UART6_RX_BUF_SIZE);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1662"> class="hljs-ln-code"> class="hljs-ln-line"> USART6 ->SR;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1663"> class="hljs-ln-code"> class="hljs-ln-line"> USART6 ->DR;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1664"> class="hljs-ln-code"> class="hljs-ln-line"> return;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1665"> class="hljs-ln-code"> class="hljs-ln-line"> }
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1666"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1667"> class="hljs-ln-code"> class="hljs-ln-line"> return;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1668"> class="hljs-ln-code"> class="hljs-ln-line">}
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1669"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1670"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1671"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1672"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1673"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1674"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1675"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1676"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1677"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1678"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1679"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1680"> class="hljs-ln-code"> class="hljs-ln-line">void UART6_SendData(uint8_t *puData, uint16_t usNum)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1681"> class="hljs-ln-code"> class="hljs-ln-line">{
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1682"> class="hljs-ln-code"> class="hljs-ln-line"> for (uint16_t i = 0; i < usNum; i++)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1683"> class="hljs-ln-code"> class="hljs-ln-line"> {
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1684"> class="hljs-ln-code"> class="hljs-ln-line"> xUART6.puTxFiFoData[xUART6.usTxFiFoData++] = puData[i];
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1685"> class="hljs-ln-code"> class="hljs-ln-line"> if (xUART6.usTxFiFoData == UART6_TX_BUF_SIZE)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1686"> class="hljs-ln-code"> class="hljs-ln-line"> xUART6.usTxFiFoData = 0;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1687"> class="hljs-ln-code"> class="hljs-ln-line"> }
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1688"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1689"> class="hljs-ln-code"> class="hljs-ln-line"> if ((USART6->CR1 & USART_CR1_TXEIE) == 0)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1690"> class="hljs-ln-code"> class="hljs-ln-line"> USART6->CR1 |= USART_CR1_TXEIE;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1691"> class="hljs-ln-code"> class="hljs-ln-line">}
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1692"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1693"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1694"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1695"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1696"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1697"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1698"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1699"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1700"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1701"> class="hljs-ln-code"> class="hljs-ln-line">void UART6_SendString(const char *pcString, ...)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1702"> class="hljs-ln-code"> class="hljs-ln-line">{
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1703"> class="hljs-ln-code"> class="hljs-ln-line"> char mBuffer[512] = {0};;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1704"> class="hljs-ln-code"> class="hljs-ln-line"> va_list ap;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1705"> class="hljs-ln-code"> class="hljs-ln-line"> va_start(ap, pcString);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1706"> class="hljs-ln-code"> class="hljs-ln-line"> vsnprintf(mBuffer, 512, pcString, ap);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1707"> class="hljs-ln-code"> class="hljs-ln-line"> va_end(ap);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1708"> class="hljs-ln-code"> class="hljs-ln-line"> UART6_SendData((uint8_t *)mBuffer, strlen(mBuffer));
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1709"> class="hljs-ln-code"> class="hljs-ln-line">}
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1710"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1711"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1712"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1713"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1714"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1715"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1716"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1717"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1718"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1719"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1720"> class="hljs-ln-code"> class="hljs-ln-line">uint8_t UART6_SendAT(char *pcAT, char *pcAckString, uint16_t usTimeOutMs)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1721"> class="hljs-ln-code"> class="hljs-ln-line">{
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1722"> class="hljs-ln-code"> class="hljs-ln-line"> UART6_ClearRx();
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1723"> class="hljs-ln-code"> class="hljs-ln-line"> UART6_SendString(pcAT);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1724"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1725"> class="hljs-ln-code"> class="hljs-ln-line"> while (usTimeOutMs--)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1726"> class="hljs-ln-code"> class="hljs-ln-line"> {
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1727"> class="hljs-ln-code"> class="hljs-ln-line"> if (UART6_GetRxNum())
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1728"> class="hljs-ln-code"> class="hljs-ln-line"> {
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1729"> class="hljs-ln-code"> class="hljs-ln-line"> UART6_ClearRx();
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1730"> class="hljs-ln-code"> class="hljs-ln-line"> if (strstr((char *)UART6_GetRxData(), pcAckString))
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1731"> class="hljs-ln-code"> class="hljs-ln-line"> return 1;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1732"> class="hljs-ln-code"> class="hljs-ln-line"> }
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1733"> class="hljs-ln-code"> class="hljs-ln-line"> delay_ms(1);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1734"> class="hljs-ln-code"> class="hljs-ln-line"> }
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1735"> class="hljs-ln-code"> class="hljs-ln-line"> return 0;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1736"> class="hljs-ln-code"> class="hljs-ln-line">}
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1737"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1738"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1739"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1740"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1741"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1742"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1743"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1744"> class="hljs-ln-code"> class="hljs-ln-line">uint16_t UART6_GetRxNum(void)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1745"> class="hljs-ln-code"> class="hljs-ln-line">{
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1746"> class="hljs-ln-code"> class="hljs-ln-line"> return xUART6.usRxNum ;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1747"> class="hljs-ln-code"> class="hljs-ln-line">}
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1748"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1749"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1750"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1751"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1752"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1753"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1754"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1755"> class="hljs-ln-code"> class="hljs-ln-line">uint8_t *UART6_GetRxData(void)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1756"> class="hljs-ln-code"> class="hljs-ln-line">{
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1757"> class="hljs-ln-code"> class="hljs-ln-line"> return xUART6.puRxData ;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1758"> class="hljs-ln-code"> class="hljs-ln-line">}
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1759"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1760"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1761"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1762"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1763"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1764"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1765"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1766"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1767"> class="hljs-ln-code"> class="hljs-ln-line">void UART6_ClearRx(void)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1768"> class="hljs-ln-code"> class="hljs-ln-line">{
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1769"> class="hljs-ln-code"> class="hljs-ln-line"> xUART6.usRxNum = 0 ;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1770"> class="hljs-ln-code"> class="hljs-ln-line">}
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1771"> class="hljs-ln-code"> class="hljs-ln-line">#endif
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1772"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1773"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1774"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1775"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1776"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1777"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1778"> class="hljs-ln-code"> class="hljs-ln-line">/ ModbusCRC16 校验 /
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1779"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1780"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1781"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1782"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1783"> class="hljs-ln-code"> class="hljs-ln-line">static const uint8_t aModbusCRC16[] =
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1784"> class="hljs-ln-code"> class="hljs-ln-line">{
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1785"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1786"> class="hljs-ln-code"> class="hljs-ln-line"> 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40,
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1787"> class="hljs-ln-code"> class="hljs-ln-line"> 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41,
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1788"> class="hljs-ln-code"> class="hljs-ln-line"> 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41,
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1789"> class="hljs-ln-code"> class="hljs-ln-line"> 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40,
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1790"> class="hljs-ln-code"> class="hljs-ln-line"> 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41,
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1791"> class="hljs-ln-code"> class="hljs-ln-line"> 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40,
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1792"> class="hljs-ln-code"> class="hljs-ln-line"> 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40,
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1793"> class="hljs-ln-code"> class="hljs-ln-line"> 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41,
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1794"> class="hljs-ln-code"> class="hljs-ln-line"> 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41,
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1795"> class="hljs-ln-code"> class="hljs-ln-line"> 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40,
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1796"> class="hljs-ln-code"> class="hljs-ln-line"> 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40,
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1797"> class="hljs-ln-code"> class="hljs-ln-line"> 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41,
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1798"> class="hljs-ln-code"> class="hljs-ln-line"> 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40,
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1799"> class="hljs-ln-code"> class="hljs-ln-line"> 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41,
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1800"> class="hljs-ln-code"> class="hljs-ln-line"> 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41,
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1801"> class="hljs-ln-code"> class="hljs-ln-line"> 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40,
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1802"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1803"> class="hljs-ln-code"> class="hljs-ln-line"> 0x00, 0xC0, 0xC1, 0x01, 0xC3, 0x03, 0x02, 0xC2, 0xC6, 0x06, 0x07, 0xC7, 0x05, 0xC5, 0xC4, 0x04,
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1804"> class="hljs-ln-code"> class="hljs-ln-line"> 0xCC, 0x0C, 0x0D, 0xCD, 0x0F, 0xCF, 0xCE, 0x0E, 0x0A, 0xCA, 0xCB, 0x0B, 0xC9, 0x09, 0x08, 0xC8,
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1805"> class="hljs-ln-code"> class="hljs-ln-line"> 0xD8, 0x18, 0x19, 0xD9, 0x1B, 0xDB, 0xDA, 0x1A, 0x1E, 0xDE, 0xDF, 0x1F, 0xDD, 0x1D, 0x1C, 0xDC,
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1806"> class="hljs-ln-code"> class="hljs-ln-line"> 0x14, 0xD4, 0xD5, 0x15, 0xD7, 0x17, 0x16, 0xD6, 0xD2, 0x12, 0x13, 0xD3, 0x11, 0xD1, 0xD0, 0x10,
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1807"> class="hljs-ln-code"> class="hljs-ln-line"> 0xF0, 0x30, 0x31, 0xF1, 0x33, 0xF3, 0xF2, 0x32, 0x36, 0xF6, 0xF7, 0x37, 0xF5, 0x35, 0x34, 0xF4,
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1808"> class="hljs-ln-code"> class="hljs-ln-line"> 0x3C, 0xFC, 0xFD, 0x3D, 0xFF, 0x3F, 0x3E, 0xFE, 0xFA, 0x3A, 0x3B, 0xFB, 0x39, 0xF9, 0xF8, 0x38,
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1809"> class="hljs-ln-code"> class="hljs-ln-line"> 0x28, 0xE8, 0xE9, 0x29, 0xEB, 0x2B, 0x2A, 0xEA, 0xEE, 0x2E, 0x2F, 0xEF, 0x2D, 0xED, 0xEC, 0x2C,
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1810"> class="hljs-ln-code"> class="hljs-ln-line"> 0xE4, 0x24, 0x25, 0xE5, 0x27, 0xE7, 0xE6, 0x26, 0x22, 0xE2, 0xE3, 0x23, 0xE1, 0x21, 0x20, 0xE0,
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1811"> class="hljs-ln-code"> class="hljs-ln-line"> 0xA0, 0x60, 0x61, 0xA1, 0x63, 0xA3, 0xA2, 0x62, 0x66, 0xA6, 0xA7, 0x67, 0xA5, 0x65, 0x64, 0xA4,
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1812"> class="hljs-ln-code"> class="hljs-ln-line"> 0x6C, 0xAC, 0xAD, 0x6D, 0xAF, 0x6F, 0x6E, 0xAE, 0xAA, 0x6A, 0x6B, 0xAB, 0x69, 0xA9, 0xA8, 0x68,
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1813"> class="hljs-ln-code"> class="hljs-ln-line"> 0x78, 0xB8, 0xB9, 0x79, 0xBB, 0x7B, 0x7A, 0xBA, 0xBE, 0x7E, 0x7F, 0xBF, 0x7D, 0xBD, 0xBC, 0x7C,
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1814"> class="hljs-ln-code"> class="hljs-ln-line"> 0xB4, 0x74, 0x75, 0xB5, 0x77, 0xB7, 0xB6, 0x76, 0x72, 0xB2, 0xB3, 0x73, 0xB1, 0x71, 0x70, 0xB0,
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1815"> class="hljs-ln-code"> class="hljs-ln-line"> 0x50, 0x90, 0x91, 0x51, 0x93, 0x53, 0x52, 0x92, 0x96, 0x56, 0x57, 0x97, 0x55, 0x95, 0x94, 0x54,
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1816"> class="hljs-ln-code"> class="hljs-ln-line"> 0x9C, 0x5C, 0x5D, 0x9D, 0x5F, 0x9F, 0x9E, 0x5E, 0x5A, 0x9A, 0x9B, 0x5B, 0x99, 0x59, 0x58, 0x98,
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1817"> class="hljs-ln-code"> class="hljs-ln-line"> 0x88, 0x48, 0x49, 0x89, 0x4B, 0x8B, 0x8A, 0x4A, 0x4E, 0x8E, 0x8F, 0x4F, 0x8D, 0x4D, 0x4C, 0x8C,
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1818"> class="hljs-ln-code"> class="hljs-ln-line"> 0x44, 0x84, 0x85, 0x45, 0x87, 0x47, 0x46, 0x86, 0x82, 0x42, 0x43, 0x83, 0x41, 0x81, 0x80, 0x40
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1819"> class="hljs-ln-code"> class="hljs-ln-line">};
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1820"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1821"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1822"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1823"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1824"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1825"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1826"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1827"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1828"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1829"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1830"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1831"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1832"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1833"> class="hljs-ln-code"> class="hljs-ln-line">void Modbus_AddCRC16(uint8_t *_pcData, uint16_t _usLen)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1834"> class="hljs-ln-code"> class="hljs-ln-line">{
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1835"> class="hljs-ln-code"> class="hljs-ln-line"> uint8_t ucCRCHi = 0xFF;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1836"> class="hljs-ln-code"> class="hljs-ln-line"> uint8_t ucCRCLo = 0xFF;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1837"> class="hljs-ln-code"> class="hljs-ln-line"> uint16_t usIndex;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1838"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1839"> class="hljs-ln-code"> class="hljs-ln-line"> while (_usLen--)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1840"> class="hljs-ln-code"> class="hljs-ln-line"> {
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1841"> class="hljs-ln-code"> class="hljs-ln-line"> usIndex = ucCRCHi ^ *_pcData++;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1842"> class="hljs-ln-code"> class="hljs-ln-line"> ucCRCHi = ucCRCLo ^ aModbusCRC16[usIndex];
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1843"> class="hljs-ln-code"> class="hljs-ln-line"> ucCRCLo = aModbusCRC16[usIndex + 256];
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1844"> class="hljs-ln-code"> class="hljs-ln-line"> }
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1845"> class="hljs-ln-code"> class="hljs-ln-line"> _pcData[0] = ucCRCHi;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1846"> class="hljs-ln-code"> class="hljs-ln-line"> _pcData[1] = ucCRCLo;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1847"> class="hljs-ln-code"> class="hljs-ln-line">}
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1848"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1849"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1850"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1851"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1852"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1853"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1854"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1855"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1856"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1857"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1858"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1859"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1860"> class="hljs-ln-code"> class="hljs-ln-line">uint8_t Modbus_CheckCRC16(uint8_t *_pcData, uint16_t _usLen)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1861"> class="hljs-ln-code"> class="hljs-ln-line">{
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1862"> class="hljs-ln-code"> class="hljs-ln-line"> uint8_t ucCRCHi = 0xFF;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1863"> class="hljs-ln-code"> class="hljs-ln-line"> uint8_t ucCRCLo = 0xFF;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1864"> class="hljs-ln-code"> class="hljs-ln-line"> uint16_t usIndex;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1865"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1866"> class="hljs-ln-code"> class="hljs-ln-line"> _usLen -= 2;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1867"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1868"> class="hljs-ln-code"> class="hljs-ln-line"> while (_usLen--)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1869"> class="hljs-ln-code"> class="hljs-ln-line"> {
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1870"> class="hljs-ln-code"> class="hljs-ln-line"> usIndex = ucCRCHi ^ *_pcData++;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1871"> class="hljs-ln-code"> class="hljs-ln-line"> ucCRCHi = ucCRCLo ^ aModbusCRC16[usIndex];
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1872"> class="hljs-ln-code"> class="hljs-ln-line"> ucCRCLo = aModbusCRC16[usIndex + 256];
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1873"> class="hljs-ln-code"> class="hljs-ln-line"> }
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1874"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1875"> class="hljs-ln-code"> class="hljs-ln-line"> if ((ucCRCHi == *_pcData++) && (ucCRCLo == *_pcData))
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1876"> class="hljs-ln-code"> class="hljs-ln-line"> return 1;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1877"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1878"> class="hljs-ln-code"> class="hljs-ln-line"> return 0;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1879"> class="hljs-ln-code"> class="hljs-ln-line">}
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1880"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1881"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1882"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1883"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1884"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1885"> class="hljs-ln-code"> class="hljs-ln-line">/ 辅助功能 /
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1886"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1887"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1888"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1889"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1890"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1891"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1892"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1893"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1894"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1895"> class="hljs-ln-code"> class="hljs-ln-line">#if 0
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1896"> class="hljs-ln-code"> class="hljs-ln-line">void debug_showData(uint8_t *puRxData, uint16_t usRxNum)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1897"> class="hljs-ln-code"> class="hljs-ln-line">{
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1898"> class="hljs-ln-code"> class="hljs-ln-line"> printf("字节数: %d \r", usRxNum);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1899"> class="hljs-ln-code"> class="hljs-ln-line"> printf("ASCII 显示数据: %s\r", (char *)puRxData);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1900"> class="hljs-ln-code"> class="hljs-ln-line"> printf("16进制显示数据: ");
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1901"> class="hljs-ln-code"> class="hljs-ln-line"> while (usRxNum--)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1902"> class="hljs-ln-code"> class="hljs-ln-line"> printf("0x%X ", *puRxData++);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1903"> class="hljs-ln-code"> class="hljs-ln-line"> printf("\r\r");
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1904"> class="hljs-ln-code"> class="hljs-ln-line">}
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1905"> class="hljs-ln-code"> class="hljs-ln-line">#endif
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1906"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1907"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1908"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1909"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1910"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1911"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1912"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1913"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1914"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1915"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1916"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1917"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1918"> class="hljs-ln-code"> class="hljs-ln-line">#pragma import(__use_no_semihosting)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1919"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1920"> class="hljs-ln-code"> class="hljs-ln-line">struct __FILE
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1921"> class="hljs-ln-code"> class="hljs-ln-line">{
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1922"> class="hljs-ln-code"> class="hljs-ln-line"> int handle;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1923"> class="hljs-ln-code"> class="hljs-ln-line">};
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1924"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1925"> class="hljs-ln-code"> class="hljs-ln-line">FILE __stdout;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1926"> class="hljs-ln-code"> class="hljs-ln-line">void _sys_exit(int x)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1927"> class="hljs-ln-code"> class="hljs-ln-line">{
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1928"> class="hljs-ln-code"> class="hljs-ln-line"> x = x;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1929"> class="hljs-ln-code"> class="hljs-ln-line">}
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1930"> class="hljs-ln-code"> class="hljs-ln-line">
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1931"> class="hljs-ln-code"> class="hljs-ln-line">int fputc(int ch, FILE *f)
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1932"> class="hljs-ln-code"> class="hljs-ln-line">{
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1933"> class="hljs-ln-code"> class="hljs-ln-line"> UART1_SendData((uint8_t *)&ch, 1);
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1934"> class="hljs-ln-code"> class="hljs-ln-line"> return ch;
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1935"> class="hljs-ln-code"> class="hljs-ln-line">}
- class="hljs-ln-numbers"> class="hljs-ln-line hljs-ln-n" data-line-number="1936"> class="hljs-ln-code"> class="hljs-ln-line">
class="hide-preCode-box">
class="hljs-button signin active" data-title="登录复制" data-report-click="{"spm":"1001.2101.3001.4334"}" onclick="hljs.signin(event)">
data-report-view="{"mod":"1585297308_001","spm":"1001.2101.3001.6548","dest":"https://blog.csdn.net/qq_49053936/article/details/135478892","extend1":"pc","ab":"new"}">>
评论记录:
回复评论: