What makes a reliable serial RS232 communication circuitry on an embedded device?

So, I'm starting to have a problem with writing serial communication circuits, and it seems to be related to the timing. My embedded platform is the Rabbit Semiconductor BL2600, in which case it is a RS232 device. It sends a command to the device, and the device sends a response back to the BL2600, which is then processed.

My problem is that when I send a command and then wait for a response, I do not receive it. However, if I set a breakpoint at the right points and one step through the code, I often get an answer. I put my computer between the BL2600 and the device for listening to the RS232 stream (after watching the initial problem), and the response is sent regardless of whether I remain a breakpoint or not, but the BL2600 only sees it in its buffers if I stop immediately before that part, where I parse the code and try to find its start bit. If I stop when I just read the entire line after that, it will not find it.

So, it sounds like I’m not waiting enough, so now it’s just funny, I set the timeouts for checking the buffer to 1 second (and with a baud rate of 38400, it’s better to show in this window), and yet I NEVER get nothing but breakpoints and one-step.

The following is a significant portion of my code:

    //clear the buffers
 serCwrFlush();
 while(serCwrUsed())
 {
  ;
 }
 startwait = MS_TIMER;
 while((serCrdUsed() > 1) && (device_timeout_check < 1000))
 {
  if (MS_TIMER < startwait)
  {                                    // fix the rollover
   device_timeout_check = MS_TIMER + (ULONG_MAX - startwait);  
  }

  else
  {                                   //set it like normal
   device_timeout_check = MS_TIMER - startwait;     
  }

  serCrdFlush();
 }
 serCputs("mpcal=d\r");     //This is what requests the response from the device
 while(serCwrUsed())
 {
  ;
 }
 startwait = MS_TIMER;
 while((serCrdUsed() < 11) && (device_timeout_check < 1000))
 {
  if (MS_TIMER < startwait)
  {                        // fix the rollover
   device_timeout_check = MS_TIMER + (ULONG_MAX - startwait);  
  }
  else
  {                       //set it like normal
   device_timeout_check = MS_TIMER - startwait;     
  }
 }
 //grab it
 temp=serCpeek();
 i=0;
        //It expects a response like "H0V0M00.0 /r"
        //So I am looking for the first character.
 while((temp != 'H' ) && (i<100))
 {
  serCgetc();     //breakpoint works here
  temp=serCpeek();
  i++;
 }
 c=serCread(comp_cal_string,20, 20);   //breakpoint doesn't work here

I have a feeling that I’m reinventing the wheel and that someone probably did it in front of me, at least on another platform, so that it lingers long enough for the data to be received, but fast enough for it to really catch data.

+3
source share
3 answers

, RS-232 ? , RS-232, (ISR) - , , . RS-232 , (. ) .

BL2600 - , :

http://ftp1.digi.com/support/documentation/019-0113_N.pdf

- . setVectIntern . 476.

, RS-232 16 . , DMA, , , BL2600. ( DMA .)

+3

.

, -, , -. , . , , .

, :

  • device_timeout_check , .
  • MS_TIMER device_timeout_check.
  • , -.

, startwait, : unsigned long startwait;. :

startwait = MS_TIMER;
do {
  device_timeout_check = (MS_TIMER - startwait >= 1000);
} while((serCrdUsed() > 1) && !device_timeout_check);

if (device_timeout_check) {
   /* Handle the timeout error here */
}

, device_timeout_check 999, .

, "H" . 11 . 100 , . 11 , 'H ', , "H" .

"H" , . , .

+2

, . device_timeout_check , , . , , , 1000. while (tsk tsk), while, "H", 100 , ( ) .

, 100? , , , , .

. -, serCgetc(), .

, , - - , . , " " . , O-scope, , " " ( ) .

Those peek and read functions do not return error status, because they return data, but they can easily be placed in shells that at least checked parity errors or bytes in FIFO and instead returned data in a pointer so that the status can be returned. Something like that

STATUS myCpeek( unsigned char *data)
{
  if ( 0 == serCrdUsed() )
    return ERROR_NO_DATA;
  *data = serCpeek();
  if ( serCParityError() )  //Just guessing at a function name here
  {
    return ERROR_PARITY_BAD;
  }
  return OK;
}

or something similar.

0
source

Source: https://habr.com/ru/post/1788579/


All Articles