Mod serial interupt help

16 Jan 2013

I'm sending commands to the mbed at 19200. A command looks like this "pwm 1:40 2:89\r"

I can send that command about 16 times then the mbed quits responding on that serial port. I can send it with a 10ms delay after each command or a 1 second delay and it acts the same way. Is there some buffer I need to clear after receiving data? Here is my int code. What am I missing? I added the print statement only for debugging this problem ISP is a different serial port.

void rxCallback(MODSERIAL_IRQ_INFO *q) 
{
    MODSERIAL *serial = q->serial;
    char c=serial->rxGetLastChar();
    int ii;
    *curPos = c;
    
    // Make sure we don't overrun the buffer:
    if (curCnt < SERIAL_BUFFER_SIZE)
    {
       // End of command, set flag to process the command:
       if (*curPos =='\r')
       {
        
          isp.printf("saw a command # %d\r\n",counter++);
          ProcessCommands();

          // Reset pointer to beginning of buffer:
          curPos = SERIAL_BUFFER;
          curCnt = 0;
       }
  
       else
       {
            // Increment buffer position:
            curPos++;
            curCnt++;
       }
     }
     else
     {
         curCnt = 0;
         curPos = SERIAL_BUFFER;
     }

}
16 Jan 2013

The problem is that you use rxGetLastChar(). This function does give you the last received byte, but it does not remove it from the modserial buffer. So in the end your buffer gets full and then it probably goes wrong. Replacing it with getc() probably will already fix the issue.

A bit more elegant solution is using the modserial functions provided for this. Specifically RxAutoDetect interrupt type, in combination with setting autodetect char to '\r', and the move command.

16 Jan 2013

Here is a thread where I posted a code snippet that does as Erik suggested above.

http://mbed.org/forum/helloworld/topic/3550/?page=1#comment-17945

Good Luck.

16 Jan 2013

That looks perfect, I'll try it tonight. Thanks Ringo