cancel
Showing results for 
Search instead for 
Did you mean: 

Error in receiving serial data(USART)

parisa
Senior
Posted on October 24, 2016 at 20:50

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?
1 REPLY 1
Posted on October 24, 2016 at 21:23

Where exactly is it Hard Faulting?

Could you be getting a NULL pointer, and use it without checking? Could you be overrunning an array?

Could you perhaps bounds check bitpos1?

Can you check the PHY?

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..