赞
踩
书写串口接收中断函数
HAL_UART_Receive_IT (&huart3 ,&uart1_rxbuff,1);
调用串口中断回调函数,将接收到的数据进行细处理
void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
{
uint8_t tem1;
if(huart->Instance==USART3)//openmv1µÄͨÐÅ´®¿Ú
{
tem1=uart1_rxbuff;
Openmv1_Receive_Data(tem1);
// HAL_UART_Transmit_IT (&huart3 ,(uint8_t *)my_data4 ,1);
}
HAL_UART_Receive_IT(&huart3,&uart1_rxbuff,1);
}
调用串口中断回调函数
void Openmv1_Receive_Data(uint8_t com_data)
{
static uint8_t RxCounter1=0;
static uint16_t RxBuffer1[50]={0};
static uint8_t RxState = 0;
if(RxState==0&&com_data==0xFC)
{
RxState=1;
RxBuffer1[RxCounter1++]=com_data;
}
else if (RxState==1)
{
RxBuffer1[RxCounter1++]=com_data;
if(RxCounter1>=10||com_data==0xFE)//读取到帧尾或超过10位数据
{
RxState=4;
my_data1=RxBuffer1[1];
my_data2=RxBuffer1[2];
my_data3=RxBuffer1[3];
my_data4=RxBuffer1[4];
my_data5=RxBuffer1[5];//最终获得的函数
}
}
else if (RxState==4)
{
if(RxBuffer1[RxCounter1-1]==0xFE)
{
RxState=0;
RxCounter1=0;
}
}
else
{
RxState = 0;
RxCounter1=0;
for(int i=0;i<10;i++)
{
RxBuffer1[i]=0x00;
}
}
} ```
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。