完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
#include "user_usart.h" #include "stm32f10x_usart.h" /*使用microLib的方法*/ /* int fputc(int ch, FILE *f) { USART_SendData(USART1, (uint8_t) ch); while (USART_GetFlagStatus(USART1, USART_FLAG_TC) == RESET) {} return ch; } int GetKey (void) { while (!(USART1->SR & USART_FLAG_RXNE)); return ((int)(USART1->DR & 0x1FF)); } */ //#if EN_USART1_RX //如果使能了接收 //#if EN_USART1_RX //如果使能了接收 //串口1中断服务程序 //注意,读取USARTx->SR能避免莫名其妙的错误 //u8 USART_RX_BUF[USART_REC_LEN]; //接收缓冲,最大USART_REC_LEN个字节. //接收状态 //bit15, 接收完成标志 //bit14, 接收到0x0d //bit13~0, 接收到的有效字节数目 u8 checkdata[1]; //检测串口1接收的特定数据数据 //串口1队列定义 u8 UART1SendBuff[UART1BuffSize]; //发送数据 u8 UART1ReceBuff[UART1BuffSize]; //接收数据? u16 UART1ReceIn = 0;//接收状态标记数据位 u8 UART1ReceFullFlag = 0;//接收完数据标志位 //串口2队列定义 u8 UART2SendBuff[UART2BuffSize]; u8 UART2ReceBuff[UART2BuffSize]; u16 UART2ReceIn = 0; u8 UART2ReceFullFlag = 0; //串口3队列定义 u8 UART3SendBuff[UART3BuffSize]; u8 UART3ReceBuff[UART3BuffSize]; u16 UART3ReceIn = 0; u8 UART3ReceFullFlag = 0; //串口4队列定义 u8 UART4SendBuff[UART4BuffSize]; u8 UART4ReceBuff[UART4BuffSize]; u16 UART4ReceIn = 0; u8 UART4ReceFullFlag = 0; //串口5队列定义 u8 UART5SendBuff[UART5BuffSize]; u8 UART5ReceBuff[UART5BuffSize]; u16 UART5ReceIn = 0; u8 UART5ReceFullFlag = 0; u8 usartflag; //串口中断接收数据的标志位 串口2 串口3 //串口1初始化 void USART1_Configuration(u32 bound) { GPIO_InitTypeDef GPIO_InitStructure; NVIC_InitTypeDef NVIC_InitStructure; USART_InitTypeDef USART_InitStructure;; RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA|RCC_APB2Periph_USART1,ENABLE);//开启GPIOA和USART1时钟 //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 = 0; //子优先级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 } //串口2初始化 void USART2_Configuration(u32 bound) { GPIO_InitTypeDef GPIO_InitStructure; NVIC_InitTypeDef NVIC_InitStructure; USART_InitTypeDef USART_InitStructure;; RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2,ENABLE); RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE);//开启GPIOA和USART1时钟 //USART2_TX GPIOA.2 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2; //PA.2 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; //复用推挽输出 GPIO_Init(GPIOA, &GPIO_InitStructure);//初始化GPIOA.2 //USART2_RX GPIOA.3初始化 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3;//PA3 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;//浮空输入 GPIO_Init(GPIOA, &GPIO_InitStructure);//初始化GPIOA.3 //Usart2 NVIC 配置 NVIC_InitStructure.NVIC_IRQChannel = USART2_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=2 ;//抢占优先级3 NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; //子优先级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(USART2, &USART_InitStructure); //初始化串口2 USART_ITConfig(USART2,USART_IT_RXNE,ENABLE); //开启串口接收中断 USART_Cmd(USART2, ENABLE); //使能串口2 } //串口3初始化 void USART3_Configuration(u32 bound) { GPIO_InitTypeDef GPIO_InitStructure; NVIC_InitTypeDef NVIC_InitStructure; USART_InitTypeDef USART_InitStructure;; RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3,ENABLE); RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB,ENABLE);//开启GPIOA和USART1时钟 //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.3初始化 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11;//PB11 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;//浮空输入 GPIO_Init(GPIOB, &GPIO_InitStructure);//初始化GPIOB.11 //Usart3 NVIC 配置 NVIC_InitStructure.NVIC_IRQChannel = USART3_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=2 ;//抢占优先级3 NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; //子优先级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 } //串口4初始化 void UART4_Configuration(u32 bound) { GPIO_InitTypeDef GPIO_InitStructure; USART_InitTypeDef USART_InitStructure; NVIC_InitTypeDef NVIC_InitStructure; RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE ); RCC_APB1PeriphClockCmd(RCC_APB1Periph_UART4, ENABLE ); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10; //UART4 TX; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; //复用推挽输出; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOC, &GPIO_InitStructure); //端口C; GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11; //UART4 RX; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; //浮空输入; GPIO_Init(GPIOC, &GPIO_InitStructure); //端口C; USART_InitStructure.USART_BaudRate = bound; //波特率; USART_InitStructure.USART_WordLength = USART_WordLength_8b; //数据位8位; USART_InitStructure.USART_StopBits = USART_StopBits_1; //停止位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(UART4, &USART_InitStructure);//配置串口参数; // NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2); //设置中断组,4位抢占优先级,4位响应优先级; NVIC_InitStructure.NVIC_IRQChannel = UART4_IRQn; //中断号; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 2; //抢占优先级; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; //响应优先级; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); USART_ITConfig(UART4, USART_IT_RXNE, ENABLE); USART_Cmd(UART4, ENABLE); //使能串口; } //串口5初始化 void UART5_Configuration(u32 bound) { GPIO_InitTypeDef GPIO_InitStructure; USART_InitTypeDef USART_InitStructure; NVIC_InitTypeDef NVIC_InitStructure; RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC|RCC_APB2Periph_GPIOD, ENABLE ); RCC_APB1PeriphClockCmd(RCC_APB1Periph_UART5, ENABLE ); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12; //UART5 TX; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; //复用推挽输出; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOC, &GPIO_InitStructure); //端口C; GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2; //UART5 RX; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; //浮空输入; GPIO_Init(GPIOD, &GPIO_InitStructure); //端口D; USART_InitStructure.USART_BaudRate = bound; //波特率; USART_InitStructure.USART_WordLength = USART_WordLength_8b; //数据位8位; USART_InitStructure.USART_StopBits = USART_StopBits_1; //停止位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(UART5, &USART_InitStructure);//配置串口参数; //NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2); //设置中断组,4位抢占优先级,4位响应优先级; NVIC_InitStructure.NVIC_IRQChannel = UART5_IRQn; //中断号; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 2; //抢占优先级; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; //响应优先级; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); USART_ITConfig(UART5, USART_IT_RXNE, ENABLE); USART_Cmd(UART5, ENABLE); //使能串口; } //串口1发送一帧数据 void USART1_SendOneData(uint8_t SendOneData) { USART_SendData(USART1, SendOneData); while (USART_GetFlagStatus(USART1, USART_FLAG_TC) == RESET) {} } //串口2发送一帧数据 void USART2_SendOneData(uint8_t SendOneData) { USART_SendData(USART2, SendOneData); while (USART_GetFlagStatus(USART2, USART_FLAG_TC) == RESET) {} } //串口3发送一帧数据 void USART3_SendOneData(uint8_t SendOneData) { USART_SendData(USART3, SendOneData); while (USART_GetFlagStatus(USART3, USART_FLAG_TC) == RESET) {} } //串口4发送一帧数据 void UART4_SendOneData(uint8_t SendOneData) { USART_SendData(UART4, SendOneData); while (USART_GetFlagStatus(UART4, USART_FLAG_TC) == RESET) {} } //串口5发送一帧数据 void UART5_SendOneData(uint8_t SendOneData) { USART_SendData(UART5, SendOneData); while (USART_GetFlagStatus(UART5, USART_FLAG_TC) == RESET) {} } //串口1发送一列数据 void USART1_SendUnfixedData(uint8_t *Buffer, uint8_t Length) { uint8_t i; for(i=0;i USART1_SendOneData(*Buffer++); } } //串口2发送一列数据 void USART2_SendUnfixedData(uint8_t *Buffer, uint8_t Length) { uint8_t i; for(i=0;i USART2_SendOneData(*Buffer++); } } //串口3发送一列数据 void USART3_SendUnfixedData(uint8_t *Buffer, uint8_t Length) { uint8_t i; for(i=0;i USART3_SendOneData(*Buffer++); } } //串口4发送一列数据 void UART4_SendUnfixedData(uint8_t *Buffer, uint8_t Length) { uint8_t i; for(i=0;i UART4_SendOneData(*Buffer++); } } //串口5发送一列数据 void UART5_SendUnfixedData(uint8_t *Buffer, uint8_t Length) { uint8_t i; for(i=0;i UART5_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==0xFF) 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];} // // else // UART1ReceIn = 0; // break; case 3: if(Res==0xFE) UART1ReceBuff[UART1ReceIn++] = Res; else UART1ReceIn = 0; break; case 4: if(Res==0xFE) UART1ReceBuff[UART1ReceIn++] = Res; else UART1ReceIn = 0; break; default: UART1ReceBuff[UART1ReceIn++] = Res; break; } if(UART1ReceIn >= 5) { UART1ReceFullFlag = 1; //数据完整接受完 } USART_ClearITPendingBit(USART1, USART_IT_RXNE);//清除相对应的中断位 清除中断预处理位USART_ClearITPendingBit左移八位是USART_ClearFlag } else if(USART_GetITStatus(USART1, USART_IT_TXE) != RESET) // 发送中断 USART_GetITStatus { USART_ClearITPendingBit(USART1, USART_IT_TXE); // clear interrupt 清除中断预处理位 } } //串口2中断服务函数 void USART2_IRQHandler(void) { u8 Res;//数据暂存 if(USART_GetITStatus(USART2, USART_IT_RXNE) != RESET) //接收中断 { Res =USART_ReceiveData(USART2); //读取接收到的数据 USART_SendData(USART1,Res);//将读取到的数据通过串口1发送 usartflag=2; switch(UART2ReceIn)//读取接收到的数据有几位 每一位对应的数据协议校验 { case 0: if(Res==0xFF) UART2ReceBuff[UART2ReceIn++] = Res; else UART2ReceIn = 0; break; case 1: if(Res==0xFF) UART2ReceBuff[UART2ReceIn++] = Res; else UART2ReceIn = 0; break; case 2: if(Res==0x0f) UART2ReceBuff[UART2ReceIn++] = Res; else UART2ReceIn = 0; break; case 3: if(Res==0x01) UART2ReceBuff[UART2ReceIn++] = Res; else UART2ReceIn = 0; break; default: UART2ReceBuff[UART2ReceIn++] = Res; break; } if(UART2ReceIn >= 4) { UART2ReceFullFlag = 1; //数据完整接受完 } USART_ClearITPendingBit(USART2, USART_IT_RXNE);//清除相对应的中断位 清除中断预处理位USART_ClearITPendingBit左移八位是USART_ClearFlag } else if(USART_GetITStatus(USART2, USART_IT_TXE) != RESET) // 发送中断 USART_GetITStatus { USART_ClearITPendingBit(USART2, USART_IT_TXE); // clear interrupt 清除中断预处理位 } } //串口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发送 usartflag=3; switch(UART3ReceIn)//读取接收到的数据有几位 每一位对应的数据协议校验 { case 0: if(Res==0xFF) UART3ReceBuff[UART3ReceIn++] = Res; else UART3ReceIn = 0; break; case 1: if(Res==0xFF) UART3ReceBuff[UART3ReceIn++] = Res; else UART3ReceIn = 0; break; case 2: if(Res==0x0f) UART3ReceBuff[UART3ReceIn++] = Res; else UART3ReceIn = 0; break; case 3: if(Res==0x01) UART3ReceBuff[UART3ReceIn++] = Res; else UART3ReceIn = 0; break; case 4: if(Res==0x31) UART3ReceBuff[UART3ReceIn++] = Res; else UART3ReceIn = 0; break; default: UART3ReceBuff[UART3ReceIn++] = Res; break; } if(UART3ReceIn >= 57) { 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 清除中断预处理位 } } //串口4中断服务函数 void UART4_IRQHandler(void) { u8 Res;//数据暂存 if(USART_GetITStatus(UART4, USART_IT_RXNE) != RESET) //接收中断 { Res =USART_ReceiveData(UART4); //读取接收到的数据 USART_ReceiveData USART_SendData(USART1,Res);//将读取到的数据通过串口1发送 usartflag=4; switch(UART4ReceIn)//读取接收到的数据有几位 每一位对应的数据协议校验 { case 0: if(Res==0xFF) UART4ReceBuff[UART4ReceIn++] = Res; else UART4ReceIn = 0; break; case 1: if(Res==0xFF) UART4ReceBuff[UART4ReceIn++] = Res; else UART4ReceIn = 0; break; case 2: if(Res==0x0f) UART4ReceBuff[UART4ReceIn++] = Res; else UART4ReceIn = 0; break; case 3: if(Res==0x01) UART4ReceBuff[UART4ReceIn++] = Res; else UART4ReceIn = 0; break; case 4: if(Res==0x31) UART4ReceBuff[UART4ReceIn++] = Res; else UART4ReceIn = 0; break; default: UART4ReceBuff[UART4ReceIn++] = Res; break; } if(UART4ReceIn >= 57) { UART4ReceFullFlag = 1; //数据完整接受完 } USART_ClearITPendingBit(UART4, USART_IT_RXNE);//清除相对应的中断位 清除中断预处理位USART_ClearITPendingBit左移八位是USART_ClearFlag } else if(USART_GetITStatus(UART4, USART_IT_TXE) != RESET) // 发送中断 USART_GetITStatus { USART_ClearITPendingBit(UART4, USART_IT_TXE); // clear interrupt 清除中断预处理位 } } //串口5中断服务函数 void UART5_IRQHandler(void) { u8 Res;//数据暂存 if(USART_GetITStatus(UART5, USART_IT_RXNE) != RESET) //接收中断 { Res =USART_ReceiveData(UART5); //读取接收到的数据 USART_ReceiveData USART_SendData(USART1,Res);//将读取到的数据通过串口1发送 usartflag=5; switch(UART5ReceIn)//读取接收到的数据有几位 每一位对应的数据协议校验 { case 0: if(Res==0xFF) UART5ReceBuff[UART5ReceIn++] = Res; else UART5ReceIn = 0; break; case 1: if(Res==0xFF) UART5ReceBuff[UART5ReceIn++] = Res; else UART5ReceIn = 0; break; case 2: if(Res==0x0f) UART5ReceBuff[UART5ReceIn++] = Res; else UART5ReceIn = 0; break; case 3: if(Res==0x01) UART5ReceBuff[UART5ReceIn++] = Res; else UART5ReceIn = 0; break; case 4: if(Res==0x31) UART5ReceBuff[UART5ReceIn++] = Res; else UART5ReceIn = 0; break; default: UART5ReceBuff[UART5ReceIn++] = Res; break; } if(UART5ReceIn >= 57) { UART5ReceFullFlag = 1; //数据完整接受完 } USART_ClearITPendingBit(UART5, USART_IT_RXNE);//清除相对应的中断位 清除中断预处理位USART_ClearITPendingBit左移八位是USART_ClearFlag } else if(USART_GetITStatus(UART5, USART_IT_TXE) != RESET) // 发送中断 USART_GetITStatus { USART_ClearITPendingBit(UART5, USART_IT_TXE); // clear interrupt 清除中断预处理位 } } /********************************* 串口中断服务函数 void USART1_IRQHandler(void) { if(USART_GetITStatus(USART1, USART_IT_RXNE) != RESET) //接收中断 { RS485_RX_BUF[RS485_RX_CNT]=USART_ReceiveData(USART1);//RS485_RX_BUF 接收缓存 switch(RS485_RX_CNT) { case 0: if(RS485_RX_BUF[RS485_RX_CNT]==0xaa) { RS485_RX_CNT++; } else { RS485_RX_CNT=0; } break; case 1: if(RS485_RX_BUF[RS485_RX_CNT]==0xbb) { RS485_RX_CNT++; } else { RS485_RX_CNT=0; } break; case 2: if(RS485_RX_BUF[RS485_RX_CNT]==0x01) { RS485_RX_CNT++; } else { RS485_RX_CNT=0; } break; case 3: if(RS485_RX_BUF[RS485_RX_CNT]==0x04) { RS485_RX_CNT++; } else { RS485_RX_CNT=0; } break; case 4: RecDuoji[0]=RS485_RX_BUF[4]; RS485_RX_CNT++; break; case 5: if(RS485_RX_BUF[RS485_RX_CNT]==0xcc) { RS485_RX_CNT++; } else { RS485_RX_CNT=0; } break; case 6: if(RS485_RX_BUF[RS485_RX_CNT]==0xdd) { RS485_RX_CNT++; } else { RS485_RX_CNT=0; } break; default: RS485_RX_CNT++; break ; } if(RS485_RX_CNT>=6) { RS485_RX_CNT=0; // UART1ReceFullFlag = 1; //接收完数据标志位 } } } ******************************/ |
|
|
|
只有小组成员才能发言,加入小组>>
调试STM32H750的FMC总线读写PSRAM遇到的问题求解?
1590 浏览 1 评论
X-NUCLEO-IHM08M1板文档中输出电流为15Arms,15Arms是怎么得出来的呢?
1529 浏览 1 评论
962 浏览 2 评论
STM32F030F4 HSI时钟温度测试过不去是怎么回事?
676 浏览 2 评论
ST25R3916能否对ISO15693的标签芯片进行分区域写密码?
1572 浏览 2 评论
1856浏览 9评论
STM32仿真器是选择ST-LINK还是选择J-LINK?各有什么优势啊?
629浏览 4评论
STM32F0_TIM2输出pwm2后OLED变暗或者系统重启是怎么回事?
512浏览 3评论
520浏览 3评论
stm32cubemx生成mdk-arm v4项目文件无法打开是什么原因导致的?
495浏览 3评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-17 04:17 , Processed in 0.728311 second(s), Total 76, Slave 59 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号