首页 > 其他 > 详细

stm32串口接收发送数据处理

时间:2019-04-10 16:33:22      阅读:93      评论:0      收藏:0      [点我收藏+]

/************************************************************
* Function Name : Uart1_Send_Byte
* Description : ´®¿Ú1·¢ËÍ×Ö½ÚÊý¾Ý
* Input : ·¢ËÍ×Ö½Ú
* Return : ÎÞ
*************************************************************/
void Uart1_Send_Byte(u8 Data)
{
USART_SendData(USART1,(u8)Data);
while(USART_GetFlagStatus(USART1,USART_FLAG_TXE)==RESET);
}


/************************************************************
* Function Name : USART1_IRQHandler
* Description : ´®¿Ú1½ÓÊÕÖжÏ
* Input : ·¢ËÍ×Ö½Ú
* Return : ÎÞ
*************************************************************/
void USART1_IRQHandler(void) //´®¿Ú1ÖжϷþÎñ³ÌÐò
{
int Data;

if(USART_GetITStatus(USART1, USART_IT_RXNE) != RESET) //½ÓÊÕÖжÏ
{

Data =USART_ReceiveData(USART1); //¶ÁÈ¡½ÓÊÕµ½µÄÊý¾Ý
switch(ReceiveState)
{
case RecSta1:
if(Data == 0xFE)
{
ReceiveState = RecSta2;
}
else
{
ReceiveState = RecSta1;
}
break;

case RecSta2:
if(Data == 0xEF)
{
ReceiveState = RecSta3;
}
else
{
ReceiveState = RecSta1;
}
break;

case RecSta3:
if(Data == 0x7F)
{
ReceiveState = RecSta5;
}
else if(Data == 0x02)
{
ReceiveState = RecSta6;
}
else
{
LedChannel = Data;
ReceiveState = RecSta4;
}
break;

case RecSta4:
ReceiveFlag = 1;
LedState = Data;
ReceiveState = RecSta1;
break;

case RecSta5:
if(Data == 0x8F)
{
Uart1_Send_Byte(0xFE);
Uart1_Send_Byte(0xEF);
Uart1_Send_Byte(0x7F);
Uart1_Send_Byte(0x68);

}
else if(Data == 0xF8)
{
Uart1_Send_Byte(0x04);
Uart1_Send_Byte(0x09);
Uart1_Send_Byte(0xB1);
Uart1_Send_Byte(0x03);
}
ReceiveState = RecSta1;
break;

case RecSta6 :
if(Data == 0x02)
{
LedInitial(1);
flag=1;
ReceiveState = RecSta1;
}
break ;

default:
ReceiveState = RecSta1;
break;
}

}
X86_ControlLed(); //X86µãµÆ
}

stm32串口接收发送数据处理

原文:https://www.cnblogs.com/fengbaobao/p/10684255.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!