Page 1 of 1

UART receive interrupt issue

Posted: 09 Sep 2013 15:27
by dcggames
I'm communicating with an other device over UART. I'm requesting certain information by sending commands to the device. I'm repeating the command until I receive a usable answer.

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;
  }
And the way I handle it in the main code:

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
          }
How should my code be setup to handle this situation better?

Re: UART receive interrupt issue

Posted: 12 Sep 2013 12:58
by marina.petrovic
Hi,

I believe I already answered you on this question via e-mail.

Best regards,
Marina