serial printf displaying the same line 3 times in terminal

19 Jun 2012

/media/uploads/willydlw/mbed_serial.png

Strange behavior with the serial member function printf. It is printing the same line 3 times. Modified the example program for changing led brightness. Using the Cutecom terminal program, Ubuntu 11.04. Attaching a screenshot of the behavior and my code.

You can see from the screen shot that Cutecom terminal settings are 9600 baud, 8 data bits, 1 stop bit, no parity bit, and no handshaking. /media/uploads/willydlw/mbed_serial.png

When I type a u or d, the character is correctly printed once in the Cutecom terminal. The problem lies in the second call to pc.printf to print the brightness. It prints the same line 3 times.

Bug? or what am I doing wrong?

/media/uploads/willydlw/mbed_serial.txt

19 Jun 2012

Plain guess: the micro runs so fast that it executes the code several time in your loop.

Lerche

19 Jun 2012

Try adding the printf in both the decreasing and increasing if loops. This should do the trick.

Lerche

19 Jun 2012

The issue appears to be with Cutecom. The option CR,LF line end was chosen. When I change the option to No line end this behavior does not happen. My hypothesis was that Cutecom is sending 2 extra characters \r\n with the CR, LF line end option and that is causing the strange behavior since my program is not reading those characters from the buffer.

Looked for more documentation on getc method. As I read it, it only removes one character. The hypothesis was not correct as I do not capture extra characters with the new code.

I changed the code to the following and it works for me now.

/media/uploads/willydlw/mbed_serial02.png /media/uploads/willydlw/mbed_serial02.txt