不定长度的中断方式串口接收程序段
void USART2_IRQHandler(void) //串口中断服务程序
{
unsigned char i;
if(USART_GetITStatus(USART2, USART_IT_RXNE) != RESET) //接收到一个字节
{
if((USART_RX_STA&0X00FF) > 254) USART_RX_STA = 0; //防止溢出、一帧数据最大为254字节.
USART_RX_BUF[USART_RX_STA++]=USART_ReceiveData(USART2);//(USART1->DR); //读取接收到的数据
}
else if(USART_GetITStatus(USART2, USART_IT_IDLE) != RESET)//接收到一帧数据(接收到空闲帧)
{
//i = USART2->SR; //读SR后读DR清空IDLE标志位;
i = USART2->DR;
USART_RX_STA|=0x8000; //接收完成了;
}
else if(USART_GetITStatus(USART2, USART_IT_ORE_RX) != RESET) //溢出错误
{
i = USART2->DR; //读SR后读DR清空ORE标志位;
i = Res;
}
}