本帖最后由 zjwxj 于 2010-11-2 09:25 编辑
stm32 串口收发中断冲突?
我用中断收,中断发。电脑(windows)串口没有发数据时,stm32发过来的串口数据正常。当我向stm32发数据较频繁时,stm32发到电脑上的数据就丢失很多,而且,有一个字节数据还是电脑发过去的,难道是usart->rdr,usart->tdr是公用的?请问这是什么原因。光是收,或者光是发的时候都正常。下面是中断服务程序
void USART_IRQHandler(int n)
{
if(USART_GetFlagStatus(coms[n-1].com,USART_FLAG_ORE)==SET)
{
USART_ClearFlag(coms[n-1].com,USART_FLAG_ORE); //读SR其实就是清除标志
USART_ReceiveData(coms[n-1].com); //读DR
}
if(USART_GetITStatus(coms[n-1].com, USART_IT_RXNE) != RESET)
{
/* Read one byte from the receive data register */
coms[n-1].RxBuffer[coms[n-1].RxTail] = (USART_ReceiveData(coms[n-1].com) & 0xFF);
coms[n-1].RxTail=(coms[n-1].RxTail+1)&RxBufferSize;
/* Clear the USART1 Receive interrupt */
USART_ClearITPendingBit(coms[n-1].com, USART_IT_RXNE);
}
if(USART_GetITStatus(coms[n-1].com, USART_IT_TXE) != RESET)
{
/* Write one byte to the transmit data register */
if(coms[n-1].TxHead!=coms[n-1].TxTail)
{
USART_SendData(coms[n-1].com, coms[n-1].TxBuffer[coms[n-1].TxHead]);
coms[n-1].TxHead = (coms[n-1].TxHead+1)&TxBufferSize;
/* Clear the USART transmit interrupt */
USART_ClearITPendingBit(coms[n-1].com, USART_IT_TXE);
}
else
{
/* Disable the USART Transmit interrupt */
USART_ITConfig(coms[n-1].com, USART_IT_TXE, DISABLE);
}
}
} |