图文概述:
主要代码:
#include "stm32f10x.h" // Device header
#include <stdio.h>
#include <stdarg.h>
/*对应的引脚号*/
#define USART1_TX GPIO_Pin_9
#define USART1_RX GPIO_Pin_10
/*模块需要使用到的端口:GPIOA或GPIOB*/
#define BUS GPIOA
/*发送或接收HEX数据包的包头包尾标识位*/
#define Packet_Front '@'
#define Packet_Rear1 '\r'
#define Packet_Rear2 '\n'
/*发送或接收HEX数据包的载荷数据个数*/
#define Packet_Num 100
uint8_t Serial_RxFlag = 0; //接收处理完数据包的标识位(0为数据包处理完,1为还处在发送完数据和处理数据包之间的状态)
char Serial_RxPacket[Packet_Num]; //存储接收的载荷数据
/**
* @brief Serial_Init---对串口通信的初始化配置(针对发送数据即USART1外设的TX引脚)
* @param 无
* @retval 无
*/
void Serial_Init(void)
{
//1.开启APB2