Libstock browse code
It is currently 08 Feb 2016 21:13

All times are UTC + 1 hour

Post new topic Reply to topic  [ 2 posts ] 
Author Message
PostPosted: 09 Sep 2013 15:27 

Joined: 09 Apr 2013 23:54
Posts: 53
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:


  uart_rd2[LoopVar0] = UART1_Read();
  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:

          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;
          delay_ms(2000); //Wait and try again

How should my code be setup to handle this situation better?

PostPosted: 12 Sep 2013 12:58 
User avatar

Joined: 18 Apr 2013 08:11
Posts: 2986

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

Best regards,

Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC + 1 hour

Who is online

Users browsing this forum: No registered users and 3 guests

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group