AnsweredAssumed Answered

Error in receiving serial data(USART)

Question asked by mohamadi.parisa on Oct 24, 2016
Latest reply on Oct 24, 2016 by Clive One
Hello
Here is my code:

void USART1_IRQHandler(void){
     
    if (USART_GetITStatus(USART1, USART_IT_TXE) != RESET)
  {
         
            if(DataReady==1 && count<=150){
            if(msg[count]=='\0' ){USART_ITConfig(USART1, USART_IT_TXE, DISABLE);DataReady=0;}  
            USART_SendData(USART1,msg[count]); 
            count=count+1;         
            }          
            if(DataReady==0 || count>=150){USART_ITConfig(USART1, USART_IT_TXE, DISABLE);DataReady=0;}
}  
     
if (USART_GetITStatus(USART1, USART_IT_RXNE) != RESET)
{
    temp=USART_ReceiveData(USART1);
    if(temp==65){
    Received=1;
    bitpos1=0;
    }
    else if(temp!=66 && Received==1 && temp>47 && temp<58){
    bufferu1[bitpos1]=temp;
    bitpos1+=1;
    }
    else if(temp==66 && Received==1)
    {
    Received=0;
    cop1();
    endbitpos1=bitpos1;
    SerialFlag=1;
    }else if(Received==1 && bitpos1>150){
        bitpos1=0;
        Received=0;
    }else if(bitpos1>150){
        bitpos1=0;
        Received=0;
    }
}
 
}
Unfortunately when I'm in receiving mode and suddenly  I disconnect cable it causes a hard fault for my network connection(Ethernet). How can prevent from being hang when cable has been disconnecting? How can detect this states?

Outcomes