本帖最后由 1040128183 于 2016-5-10 07:26 编辑
void USART1_IRQHandler()
{
u16 n=0;
USART_ITConfig(USART1,USART_IT_RXNE,DISABLE);
USART_ITConfig(USART3,USART_IT_RXNE,DISABLE);
do
{
while(!USART_GetFlagStatus(USART1,USART_FLAG_RXNE));
buf[n++]=USART_ReceiveData(USART1);
USART_ClearFlag(USART1,USART_FLAG_RXNE);
}while(!((buf[n-2]==0x0d)&&(buf[n-1]==0x0a)));
n=0;
do
{
USART_SendData(USART1,buf[n++]);
while(!USART_GetFlagStatus(USART1,USART_FLAG_TC));
USART_ClearFlag(USART1,USART_FLAG_TC);
}while(!(buf[n-2]==0x0d&&buf[n-1]==0x0a));
USART_ITConfig(USART1,USART_IT_RXNE,ENABLE);
USART_ITConfig(USART3,USART_IT_RXNE,ENABLE);
}
void USART3_IRQHandler()
{
int n=0;
USART_ITConfig(USART3,USART_IT_RXNE,DISABLE);
USART_ITConfig(USART1,USART_IT_RXNE,DISABLE);
do
{
while(!USART_GetFlagStatus(USART3,USART_FLAG_RXNE));
buf[n++]=USART_ReceiveData(USART3);
USART_ClearFlag(USART3,USART_FLAG_RXNE);
}while(!((buf[n-2]==0x0d)&&(buf[n-1]==0x0a)));
n=0;
do
{
USART_SendData(USART3,buf[n++]);
while(!USART_GetFlagStatus(USART3,USART_FLAG_TC));
USART_ClearFlag(USART3,USART_FLAG_TC);
}while(!(buf[n-2]==0x0d&&buf[n-1]==0x0a));
USART_ITConfig(USART3,USART_IT_RXNE,ENABLE);
USART_ITConfig(USART1,USART_IT_RXNE,ENABLE);
}
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
惜字如金,
出什么问题了?要说话。
看他代码就知道,他在瞎写,在串口中断函数里,死循环读取串口数据
一周热门 更多>