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;
}
}
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.
<<code>>
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;
}
}
<</code>>
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.
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.
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.
That looks perfect, I'll try it tonight.
Thanks
Ringo
That looks perfect, I'll try it tonight.
Thanks
Ringo
Important Information for this Arm website
This site uses cookies to store information on your computer.
By continuing to use our site, you consent to our cookies.
If you are not happy with the use of these cookies, please review our
Cookie Policy
to learn how they can be disabled.
By disabling cookies, some features of the site will not work.
Access Warning
You do not have the correct permissions to perform this operation.
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.