The problem I have is that the ISR I use works fine when you're dealing with static and known string lengths. But in this case the strings I'm receiving could have different lengths at any time. Depending e.g. on if the device has an error or not. So lets say that the first 5 requests result in an error string which is shorter or longer than the expected length. And at attempt 6 it does result a in a string with the expected length, the (software) buffer seems corrupted some way. The bytes aren't on the right place, like some framing problem.
This is the ISR as I it is now:
Code: Select all
void UART1RXInterrupt() iv IVT_ADDR_U1RXINTERRUPT {
uart_rd2[LoopVar0] = UART1_Read();
LoopVar0++;
if (LoopVar0 >= q) //Fill array until certain lenght
{
LoopVar0 = 0;
ready0 = 1;
}
if (U1STA.OERR = 1)
{
U1STA.OERR = 0;
U1STA.FERR = 0;
}
U1RXIF_bit = 0;
}
Code: Select all
UART1_Write_Text("A"); //Command
if (ready0 == 1)//Data received
{
if (uart_rd2[0] == 0x4F && uart_rd2[1] == 0x4B) //Check message ID
{
//Found answer that I was looking for
}
ready0 = 0;
}
else
delay_ms(2000); //Wait and try again
}