stm8l152串口中断怎么写
发布网友
发布时间:2022-06-26 12:28
我来回答
共1个回答
热心网友
时间:2024-01-12 21:43
这是stm32f2系列的中断可参考
void UART4_IRQHandler(void)
{
uint8_t Rx_buffer_num = 0;
if (UART4_Get_Flag)
{
USART_ClearITPendingBit(UART4, USART_IT_RXNE); //清标志
return;
}
if(USART_GetITStatus(UART4, USART_IT_RXNE) == SET) //非空标志
{
RxBuffer[UART4_ReceiveCounter++] = USART_ReceiveData(EVAL_COM1); //读接收缓存
if(RxBuffer[0] != 0xaa)
{
UART4_ReceiveCounter = 0;
}
else if (UART4_ReceiveCounter > RxBuffer[1] + 1)
{
UART4_ReceiveCounter = 0;
}
if(UART4_ReceiveCounter >= 2)
{
Rx_buffer_num=RxBuffer[1] + 1;
if(UART4_ReceiveCounter == Rx_buffer_num) //确定接收的长度 表明一帧以接完
{
if((RxBuffer[UART4_ReceiveCounter - 1] == 0xef) //帧头帧尾正确
&&RxBuffer[counter-1]==0xef&&RxBuffer[counter-2]==0xef)
{
UART4_ReceiveCounter = 0;
UART4_Get_Flag = TRUE;
//USART_ITConfig(UART4,USART_IT_RXNE, DISABLE);//失能中断接收
TestOutputBuffer.EndingFlag=RxBuffer[3]; //结束
}
}
}
// PrepareOutputBuffer();
}
if(USART_GetFlagStatus(UART4, USART_FLAG_ORE)==SET) //溢出清标志
{
USART_ClearFlag(EVAL_COM1,USART_FLAG_ORE);//读SR
USART_ReceiveData(EVAL_COM1);//读DR
}
USART_ClearITPendingBit(UART4, USART_IT_RXNE);
}