samizard
Junior Member level 2
when the length of data received is not specified, during that time the rcif bit is set and never returned to 0 causing the program to go in infinite loop.....so how can i come out of the infinite loop.??
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
volatile char rx_buffer[100];
volatile char *rx_ptr;
volatile int rx_complete;
volatile int rx_timeout;
uart_rx_interrupt()
{
*rx_ptr = RCREGx; // Receives the character and resets the RCxIF bit
if(*rx_ptr++ == '\n') // Do this if we are checking for the '\n' character here
{ rx_complete = true; } // '\n' seen so set a flag
TMRx0H = 0;
TMRx0L= 0; // Reset the timer counter as we have received a character
}
timer_x_interrupt()
{
rx_timeout = true; // Flag the timeout
_TMRxON = 0; // Turn off the timer
_TMRxIF = 0; // Clear the timer IF bit
}
main()
{
....
rx_ptr = rx_buffer;
rx_complete = false;
rx_timout - false;
....
while(!rx_complete && !rx_timeout); // Wait until the complete message has been received or the timeout occurs
if(rx_timeout)
{
// Handle the incomplete received string
}
if(rx_complete)
{
// Process the received string
}
}