https://blog.csdn.net/qq_36958104/article/details/103496897
STM32F103共有五个串口,有时候在项目中,其他的引脚已经配置用了,重新改太麻烦
STM32串口3 映射和完全重映射 PB10 PB11 PD8 PD9 PC10 PC11
所有本次实验 使用了串口3的映射端口,配置和普通的类似
只是注意要使用映射使能说明
GPIO_PinRemapConfig(GPIO_FullRemap_USART3 , ENABLE);
-
void USART3_Configuration(u32 bound)
-
{
-
//GPIO端口设置
-
GPIO_InitTypeDef GPIO_InitStructure;
-
USART_InitTypeDef USART_InitStructure;
-
NVIC_InitTypeDef NVIC_InitStructure;
-
-
#if 1
-
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC|RCC_APB2Periph_GPIOD|RCC_APB2Periph_AFIO, ENABLE); //remap时钟|RCC_APB2Periph_AFIO //开启GPIOB时钟
-
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, ENABLE);//这里要分开打开 //USART3时钟 来自APB1
-
#endif
-
-
#if 0
-
-
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3,ENABLE);
-
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB,ENABLE);//开启GPIOB和USART3时钟
-
-
//USART3_TX GPIOB.10
-
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10; //PB.10
-
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
-
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; //复用推挽输出
-
GPIO_Init(GPIOB, &GPIO_InitStructure);//初始化GPIOA.10
-
-
//USART3_RX GPIOB.11初始化
-
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11;//PB11
-
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;//浮空输入
-
GPIO_Init(GPIOB, &GPIO_InitStructure);//初始化GPIOB.11
-
-
#endif
-
-
-
#if 0 //重映射
-
-
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC|RCC_APB2Periph_GPIOD|RCC_APB2Periph_AFIO, ENABLE); //remap时钟|RCC_APB2Periph_AFIO //开启GPIOB时钟
-
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, ENABLE);//这里要分开打开 //USART3时钟 来自APB1
-
-
//GPIO_PartialRemap_USART3 部分重映射 GPIOC_10 GPIOC_11
-
-
GPIO_PinRemapConfig(GPIO_PartialRemap_USART3,ENABLE);
-
//USART3_TX GPIOC.10
-
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10; //
-
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
-
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; //复用推挽输出
-
GPIO_Init(GPIOC, &GPIO_InitStructure);//初始化
-
-
//USART3_RX GPIOC.11初始化
-
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11;//
-
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;//浮空输入
-
GPIO_Init(GPIOC, &GPIO_InitStructure);//初始
-
#endif
-
-
-
#if 1
-
-
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD|RCC_APB2Periph_AFIO, ENABLE); //remap时钟|RCC_APB2Periph_AFIO //开启GPIOB时钟
-
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, ENABLE);//这里要分开打开 //USART3时钟 来自APB1
-
-
//GPIO_FullRemap_USART3 完全重映射 D8 D9
-
GPIO_PinRemapConfig(GPIO_FullRemap_USART3,ENABLE);
-
//USART3_TX GPIOD8
-
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8; //
-
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
-
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; //复用推挽输出
-
GPIO_Init(GPIOD, &GPIO_InitStructure);//初始化
-
-
//USART3_RX GPIOD9
-
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;//
-
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;//浮空输入
-
GPIO_Init(GPIOD, &GPIO_InitStructure);//初始
-
#endif
-
-
-
//Usart3 NVIC 配置
-
NVIC_InitStructure.NVIC_IRQChannel = USART3_IRQn;
-
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=1 ;//抢占优先级3
-
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2; //子优先级3
-
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //IRQ通道使能
-
NVIC_Init(&NVIC_InitStructure); //根据指定的参数初始化VIC寄存器
-
-
//USART 初始化设置
-
-
USART_InitStructure.USART_BaudRate = bound;//串口波特率
-
USART_InitStructure.USART_WordLength = USART_WordLength_8b;//字长为8位数据格式
-
USART_InitStructure.USART_StopBits = USART_StopBits_1;//一个停止位
-
USART_InitStructure.USART_Parity = USART_Parity_No;//无奇偶校验位
-
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;//无硬件数据流控制
-
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; //收发模式
-
-
USART_Init(USART3, &USART_InitStructure); //初始化串口3
-
USART_ITConfig(USART3, USART_IT_RXNE, ENABLE);//开启串口接受中断
-
USART_Cmd(USART3, ENABLE); //使能串口3
-
-
}
-
#include "sys.h"
-
#include "usart.h"
-
#include "timer.h"
-
#include "stdint.h"
-
u8 checkdata[8]; //检测串口1接收的特定数据数据
-
//发送上位机的数据
-
//
-
uint32_t crc16_data1[] = { 0x00,0x00, 0x00 };//饮水机数据
-
uint32_t crc16_data2[] = { 0x00,0x00, 0x00 };//
-
uint32_t crc16_data3[] = { 0x00,0x00, 0x00 };//
-
uint32_t crc16_data4[] = { 0x00,0x00, 0x00 };//
-
uint32_t crc16_data5[] = { 0x00,0x00, 0x00 };//
-
uint32_t crc16_data6[] = { 0x00,0x00, 0x00 };//
-
uint32_t crc16_data7[] = { 0x00,0x00, 0x00 };//
-
uint32_t crc16_data8[] = { 0x00,0x00, 0x00 };//
-
uint32_t crc16_data9[] = { 0x00,0x00, 0x00 };//
-
uint32_t crc16_data10[]= { 0x00,0x00, 0x00 };//
-
-
-
//串口1队列定义
-
u8 UART1SendBuff[UART1BuffSize]; //发送数据
-
u8 UART1ReceBuff[UART1BuffSize]; //接收数据?
-
u16 UART1ReceIn = 0;//接收状态标记数据位
-
u8 UART1ReceFullFlag = 0;//接收完数据标志位
-
-
-
//串口3队列定义
-
u8 UART3SendBuff[UART3BuffSize]; //发送数据
-
u8 UART3ReceBuff[UART3BuffSize]; //接收数据?
-
u16 UART3ReceIn = 0;//接收状态标记数据位
-
u8 UART3ReceFullFlag = 0;//接收完数据标志位
-
-
void USART1_Configuration(u32 bound){
-
//GPIO端口设置
-
GPIO_InitTypeDef GPIO_InitStructure;
-
USART_InitTypeDef USART_InitStructure;
-
NVIC_InitTypeDef NVIC_InitStructure;
-
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1|RCC_APB2Periph_GPIOA, ENABLE); //使能USART1,GPIOA时钟
-
-
//USART1_TX GPIOA.9
-
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9; //PA.9
-
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
-
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; //复用推挽输出
-
GPIO_Init(GPIOA, &GPIO_InitStructure);//初始化GPIOA.9
-
-
//USART1_RX GPIOA.10初始化
-
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;//PA10
-
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;//浮空输入
-
GPIO_Init(GPIOA, &GPIO_InitStructure);//初始化GPIOA.10
-
-
//Usart1 NVIC 配置
-
NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn;
-
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=2 ;//抢占优先级3
-
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2; //子优先级3
-
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //IRQ通道使能
-
NVIC_Init(&NVIC_InitStructure); //根据指定的参数初始化VIC寄存器
-
-
//USART 初始化设置
-
USART_InitStructure.USART_BaudRate = bound;//串口波特率
-
USART_InitStructure.USART_WordLength = USART_WordLength_8b;//字长为8位数据格式
-
USART_InitStructure.USART_StopBits = USART_StopBits_1;//一个停止位
-
USART_InitStructure.USART_Parity = USART_Parity_No;//无奇偶校验位
-
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;//无硬件数据流控制
-
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; //收发模式
-
-
USART_Init(USART1, &USART_InitStructure); //初始化串口1
-
USART_ITConfig(USART1, USART_IT_RXNE, ENABLE);//开启串口接受中断
-
USART_Cmd(USART1, ENABLE); //使能串口1
-
-
}
-
-
void USART3_Configuration(u32 bound)
-
{
-
//GPIO端口设置
-
GPIO_InitTypeDef GPIO_InitStructure;
-
USART_InitTypeDef USART_InitStructure;
-
NVIC_InitTypeDef NVIC_InitStructure;
-
-
#if 1
-
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC|RCC_APB2Periph_GPIOD|RCC_APB2Periph_AFIO, ENABLE); //remap时钟|RCC_APB2Periph_AFIO //开启GPIOB时钟
-
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, ENABLE);//这里要分开打开 //USART3时钟 来自APB1
-
#endif
-
-
#if 0
-
-
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3,ENABLE);
-
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB,ENABLE);//开启GPIOB和USART3时钟
-
-
//USART3_TX GPIOB.10
-
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10; //PB.10
-
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
-
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; //复用推挽输出
-
GPIO_Init(GPIOB, &GPIO_InitStructure);//初始化GPIOA.10
-
-
//USART3_RX GPIOB.11初始化
-
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11;//PB11
-
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;//浮空输入
-
GPIO_Init(GPIOB, &GPIO_InitStructure);//初始化GPIOB.11
-
-
#endif
-
-
-
#if 0 //重映射
-
-
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC|RCC_APB2Periph_GPIOD|RCC_APB2Periph_AFIO, ENABLE); //remap时钟|RCC_APB2Periph_AFIO //开启GPIOB时钟
-
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, ENABLE);//这里要分开打开 //USART3时钟 来自APB1
-
-
//GPIO_PartialRemap_USART3 部分重映射 GPIOC_10 GPIOC_11
-
-
GPIO_PinRemapConfig(GPIO_PartialRemap_USART3,ENABLE);
-
//USART3_TX GPIOC.10
-
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10; //
-
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
-
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; //复用推挽输出
-
GPIO_Init(GPIOC, &GPIO_InitStructure);//初始化
-
-
//USART3_RX GPIOC.11初始化
-
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11;//
-
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;//浮空输入
-
GPIO_Init(GPIOC, &GPIO_InitStructure);//初始
-
#endif
-
-
-
#if 1
-
-
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD|RCC_APB2Periph_AFIO, ENABLE); //remap时钟|RCC_APB2Periph_AFIO //开启GPIOB时钟
-
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, ENABLE);//这里要分开打开 //USART3时钟 来自APB1
-
-
//GPIO_FullRemap_USART3 完全重映射 D8 D9
-
GPIO_PinRemapConfig(GPIO_FullRemap_USART3,ENABLE);
-
//USART3_TX GPIOD8
-
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8; //
-
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
-
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; //复用推挽输出
-
GPIO_Init(GPIOD, &GPIO_InitStructure);//初始化
-
-
//USART3_RX GPIOD9
-
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;//
-
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;//浮空输入
-
GPIO_Init(GPIOD, &GPIO_InitStructure);//初始
-
#endif
-
-
-
//Usart3 NVIC 配置
-
NVIC_InitStructure.NVIC_IRQChannel = USART3_IRQn;
-
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=1 ;//抢占优先级3
-
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2; //子优先级3
-
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //IRQ通道使能
-
NVIC_Init(&NVIC_InitStructure); //根据指定的参数初始化VIC寄存器
-
-
//USART 初始化设置
-
-
USART_InitStructure.USART_BaudRate = bound;//串口波特率
-
USART_InitStructure.USART_WordLength = USART_WordLength_8b;//字长为8位数据格式
-
USART_InitStructure.USART_StopBits = USART_StopBits_1;//一个停止位
-
USART_InitStructure.USART_Parity = USART_Parity_No;//无奇偶校验位
-
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;//无硬件数据流控制
-
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; //收发模式
-
-
USART_Init(USART3, &USART_InitStructure); //初始化串口3
-
USART_ITConfig(USART3, USART_IT_RXNE, ENABLE);//开启串口接受中断
-
USART_Cmd(USART3, ENABLE); //使能串口3
-
-
}
-
-
-
-
-
-
-
//串口1发送一帧数据
-
void USART1_SendOneData(uint32_t SendOneData)
-
{
-
USART_SendData(USART1, SendOneData);
-
while (USART_GetFlagStatus(USART1, USART_FLAG_TC) == RESET)
-
{}
-
}
-
//串口2发送一帧数据
-
void USART2_SendOneData(uint32_t SendOneData)
-
{
-
USART_SendData(USART2, SendOneData);
-
while (USART_GetFlagStatus(USART2, USART_FLAG_TC) == RESET)
-
{}
-
}
-
-
//串口3发送一帧数据
-
void USART3_SendOneData(uint32_t SendOneData)
-
{
-
USART_SendData(USART3, SendOneData);
-
while (USART_GetFlagStatus(USART3, USART_FLAG_TC) == RESET)
-
{}
-
}
-
//串口1发送一列数据
-
void USART1_SendUnfixedData(uint32_t *Buffer, uint8_t Length)
-
{
-
uint8_t i;
-
for(i=0;i<Length;i++)
-
{
-
USART1_SendOneData(*Buffer++);
-
}
-
}
-
-
//串口2发送一列数据
-
void USART2_SendUnfixedData(uint32_t *Buffer, uint8_t Length)
-
{
-
uint8_t i;
-
for(i=0;i<Length;i++)
-
{
-
USART2_SendOneData(*Buffer++);
-
}
-
}
-
-
//串口3发送一列数据
-
void USART3_SendUnfixedData(uint32_t *Buffer, uint8_t Length)
-
{
-
uint8_t i;
-
for(i=0;i<Length;i++)
-
{
-
USART3_SendOneData(*Buffer++);
-
}
-
}
-
-
-
-
//串口1中断服务函数
-
void USART1_IRQHandler(void)
-
{
-
u8 Res;//数据暂存
-
if(USART_GetITStatus(USART1, USART_IT_RXNE) != RESET) //接收中断
-
{
-
Res =USART_ReceiveData(USART1); //读取接收到的数据
-
switch(UART1ReceIn)//读取接收到的数据有几位 每一位对应的数据协议校验
-
{
-
case 0:
-
if(Res==0xFE)
-
UART1ReceBuff[UART1ReceIn++] = Res;
-
else
-
UART1ReceIn = 0;
-
break;
-
case 1:
-
if(Res==0xFE)
-
UART1ReceBuff[UART1ReceIn++] = Res;
-
else
-
UART1ReceIn = 0;
-
break;
-
case 2://此处为判断数据的位置 正反转
-
// if(Res==0x02)//在其他位置判断数据
-
// {UART1ReceBuff[UART1ReceIn++] = Res;
-
// checkdata[0]=UART1ReceBuff[2];}
-
{UART1ReceBuff[UART1ReceIn++] = Res;
-
checkdata[0]=UART1ReceBuff[2];
-
-
}
-
break;
-
case 3://此处为判断数据的位置 旋转角度
-
// if(Res==0x02)//在其他位置判断数据
-
// {UART1ReceBuff[UART1ReceIn++] = Res;
-
// checkdata[0]=UART1ReceBuff[2];}
-
{UART1ReceBuff[UART1ReceIn++] = Res;
-
checkdata[1]=UART1ReceBuff[3]; //接收到的角度数据和实际齿轮数据不一致
-
}
-
break;
-
case 4:
-
if(Res==0xFD)
-
UART1ReceBuff[UART1ReceIn++] = Res;
-
else
-
UART1ReceIn = 0;
-
break;
-
case 5:
-
if(Res==0xFD)
-
UART1ReceBuff[UART1ReceIn++] = Res;
-
else
-
UART1ReceIn = 0;
-
break;
-
default:
-
UART1ReceBuff[UART1ReceIn++] = Res;
-
break;
-
}
-
-
if(UART1ReceIn >= 5)
-
{
-
UART1ReceFullFlag = 1; //数据完整接受完
-
UART1ReceIn = 0;
-
timer8flag=0;
-
}
-
// USART_ClearFlag(USART1, USART_IT_RXNE);//清除相对应的中断位 清除中断预处理位USART_ClearITPendingBit左移八位是USART_ClearFlag
-
USART_ClearITPendingBit(USART1, USART_IT_RXNE);//清除相对应的中断位 清除中断预处理位USART_ClearITPendingBit左移八位是USART_ClearFlag
-
//
-
}
-
if(USART_GetITStatus(USART1, USART_IT_TXE) != RESET) // 发送中断 USART_GetITStatus
-
{
-
// USART_ClearFlag(USART1, USART_IT_TXE); // clear interrupt 清除中断预处理位
-
USART_ClearITPendingBit(USART1, USART_IT_TXE); // clear interrupt 清除中断预处理位
-
}
-
// if(USART_GetFlagStatus(USART1, USART_FLAG_ORE) != RESET)
-
// {
-
// USART_ClearFlag(USART1, USART_FLAG_ORE);
-
// }
-
-
}
-
-
-
//串口3中断服务函数
-
void USART3_IRQHandler(void)
-
{
-
u8 Res;//数据暂存
-
if(USART_GetITStatus(USART3, USART_IT_RXNE) != RESET) //接收中断
-
{
-
Res =USART_ReceiveData(USART3); //读取接收到的数据 USART_ReceiveData
-
USART_SendData(USART1,Res);//将读取到的数据通过串口1发送
-
switch(UART3ReceIn)//读取接收到的数据有几位 每一位对应的数据协议校验
-
{
-
case 0:
-
if(Res==0XFE)
-
UART3ReceBuff[UART3ReceIn++] = Res;
-
else
-
UART3ReceIn = 0;
-
break;
-
case 10:
-
if(Res==0xFF)
-
UART3ReceBuff[UART3ReceIn++] = Res;
-
else
-
UART3ReceIn = 0;
-
break;
-
default:
-
UART3ReceBuff[UART3ReceIn++] = Res;
-
break;
-
}
-
-
if(UART3ReceIn >= 11)
-
{
-
UART3ReceFullFlag = 1; //数据完整接受完
-
}
-
USART_ClearITPendingBit(USART3, USART_IT_RXNE);//清除相对应的中断位 清除中断预处理位USART_ClearITPendingBit左移八位是USART_ClearFlag
-
}
-
else if(USART_GetITStatus(USART3, USART_IT_TXE) != RESET) // 发送中断 USART_GetITStatus
-
{
-
USART_ClearITPendingBit(USART3, USART_IT_TXE); // clear interrupt 清除中断预处理位
-
}
-
}
-
-
void send_data()
-
{
-
//刷新位置信息
-
if(timer8flag100ms==1)
-
{
-
timer8flag100ms=0;
-
-
//发送协议头 FE FE D1
-
USART_SendData(USART1,0xFA);//向串口1发送数据
-
while(USART_GetFlagStatus(USART1,USART_FLAG_TC)!=SET);//等待发送结束
-
USART_SendData(USART1,0xFC);
-
while(USART_GetFlagStatus(USART1,USART_FLAG_TC)!=SET);//等待发送结束
-
//发送数据内容1
-
USART1_SendUnfixedData(crc16_data1,1);//空开1
-
while(USART_GetFlagStatus(USART1,USART_FLAG_TC)!=SET);//等待发送结束
-
//发送数据内容2
-
USART1_SendUnfixedData(crc16_data2,1);//空开2
-
while(USART_GetFlagStatus(USART1,USART_FLAG_TC)!=SET);//等待发送结束
-
//发送数据内容3
-
USART1_SendUnfixedData(crc16_data3,1);//空开3
-
while(USART_GetFlagStatus(USART1,USART_FLAG_TC)!=SET);//等待发送结束
-
//发送数据内容4
-
USART1_SendUnfixedData(crc16_data4,1);//空开4
-
while(USART_GetFlagStatus(USART1,USART_FLAG_TC)!=SET);//等待发送结束
-
//发送数据内容5
-
USART1_SendUnfixedData(crc16_data5,2);//饮水机 空烧数据
-
while(USART_GetFlagStatus(USART1,USART_FLAG_TC)!=SET);//等待发送结束
-
//发送数据内容设备接地的数据 (过载实验)(1111 1111)(八个设备)
-
USART1_SendUnfixedData(crc16_data6,1);
-
while(USART_GetFlagStatus(USART1,USART_FLAG_TC)!=SET);//等待发送结束
-
//发送数据内容7 接地触电 crc16_data7[0] 湿手触电 crc16_data7[1]
-
USART1_SendUnfixedData(crc16_data7,1);
-
while(USART_GetFlagStatus(USART1,USART_FLAG_TC)!=SET);//等待发送结束
-
//发送数据内容8 发送给串口的数据
-
USART1_SendUnfixedData(crc16_data8,1);
-
while(USART_GetFlagStatus(USART1,USART_FLAG_TC)!=SET);//等待发送结束
-
//发送协议尾 FD FD
-
USART_SendData(USART1,0xFD);//向串口1发送数据
-
while(USART_GetFlagStatus(USART1,USART_FLAG_TC)!=SET);//等待发送结束
-
USART_SendData(USART1,0xFD);
-
while(USART_GetFlagStatus(USART1,USART_FLAG_TC)!=SET);//等待发送结束
-
}
-
-
}
-
-
void send_data_usart3(void)
-
{
-
//刷新位置信息
-
if(timer8flag200ms==1)
-
{
-
timer8flag200ms=0;
-
-
//发送协议头 FE FE D1
-
USART_SendData(USART3,0xFA);//向串口1发送数据
-
while(USART_GetFlagStatus(USART3,USART_FLAG_TC)!=SET);//等待发送结束
-
USART_SendData(USART3,0xFC);
-
while(USART_GetFlagStatus(USART3,USART_FLAG_TC)!=SET);//等待发送结束
-
//发送数据内容1
-
USART3_SendUnfixedData(crc16_data1,1);//空开1
-
while(USART_GetFlagStatus(USART3,USART_FLAG_TC)!=SET);//等待发送结束
-
//发送数据内容2
-
USART3_SendUnfixedData(crc16_data2,1);//空开2
-
while(USART_GetFlagStatus(USART3,USART_FLAG_TC)!=SET);//等待发送结束
-
//发送数据内容3
-
USART3_SendUnfixedData(crc16_data3,1);//空开3
-
while(USART_GetFlagStatus(USART3,USART_FLAG_TC)!=SET);//等待发送结束
-
//发送数据内容4
-
USART3_SendUnfixedData(crc16_data4,1);//空开4
-
while(USART_GetFlagStatus(USART3,USART_FLAG_TC)!=SET);//等待发送结束
-
//发送数据内容5
-
USART3_SendUnfixedData(crc16_data5,2);//饮水机 空烧数据
-
while(USART_GetFlagStatus(USART3,USART_FLAG_TC)!=SET);//等待发送结束
-
//发送数据内容设备接地的数据 (过载实验)(1111 1111)(八个设备)
-
USART3_SendUnfixedData(crc16_data6,1);
-
while(USART_GetFlagStatus(USART3,USART_FLAG_TC)!=SET);//等待发送结束
-
//发送数据内容7 接地触电 crc16_data7[0] 湿手触电 crc16_data7[1]
-
USART3_SendUnfixedData(crc16_data7,1);
-
while(USART_GetFlagStatus(USART3,USART_FLAG_TC)!=SET);//等待发送结束
-
//发送数据内容8 发送给串口的数据
-
USART3_SendUnfixedData(crc16_data8,1);
-
while(USART_GetFlagStatus(USART3,USART_FLAG_TC)!=SET);//等待发送结束
-
//发送协议尾 FD FD
-
USART_SendData(USART3,0xFD);//向串口1发送数据
-
while(USART_GetFlagStatus(USART3,USART_FLAG_TC)!=SET);//等待发送结束
-
USART_SendData(USART3,0xFD);
-
while(USART_GetFlagStatus(USART3,USART_FLAG_TC)!=SET);//等待发送结束
-
}
-
-
}
阅读(5785) | 评论(0) | 转发(0) |