usb serial, byte missing send by putc after using getc

28 Jul 2011

I have this weird problem with serial over USB (UART) on my mbed_scope2 project. After using getc the next byte send with putc disappears.

I am sending commands from mbed to PC via the serial class over usb, using putc (but only if writeable).

Sending streams of commands works fine, commands are things like drawline and the format is something like this "!l10,20,30,40;" for drawing a line on the PC. so commands start with an exclamation point.

However there are also some commands that can send data back to mbed. They start with a question mark. So "?Q;" means send back the ID number of the last event (like if keyboard was pressed or click on button).

So after sending the "?Q;" command with putc commands (if writeable) i wait for the response with readable and getc, which works fine too.

However ...

If i after that write the next command to the PC, the first character (the exclamation point) disappears. So the PC doesn't recognizes the next command.

So i found a fix by just sending a "space" to PC by using putc (if writable) after i have used getc. If i do that the next command is recognized fine by the PC.

But the space send disappears. As everything which is not a command is printed on the screen, you would expect the space on the screen. Also if the exclamation point disappears from the stream the rest of the command which could not be interpreted is printed on the screen.

I thought maybe its a problem in my PC software, but i don't seem to have the same probem with javelin stamps using the same code/protocol.

20 Aug 2011

Never mind, it has been fixed after a lot of debugging.

Apparantly what happend is that the PC software also is used for basic stamps. Basic stamps have a resistor between the RX and TX line of the serial port, so it can use the negative voltage of the RX line for its TX line without it having a negative power suply. So which also means that every character send by the PC is returned by the basic stamp to the PC (echoed).

So the PC software has a "basic stamp" mode in which the echoed character is ignored. And i guess when we where debugging we send the data we got from the PC back to the PC so it appeared in the debug window. Which made the PC software thing a basic stamp was attached and it jumped into basic stamp mode. Anyway .. commands where added to force software in and out of basic stamp mode.

result is this:

http://apsdev.com/stampscope2/home.html

Greetings APS.