Go Down

Topic: Serial.read() bug (Read 1 time) previous topic - next topic

Cooper Baker

While working on a project dealing with parsing ascii strings, I noticed some odd behavior when using the Serial object.  When using Serial.read to read in strings, repeated characters led to unexpected, but repeatable, results.  For example, sending the string 555 resulted in 55ë.

More specifically:

Sending ascii 555 to a chip running this:

void loop()
{
   character = Serial.read();
   Serial.print( character );
}

resulted in output that looks like this:

55ë

Has anyone else experienced this?  Can anyone repeat the bug? Am I missing something?

- Cooper Baker
www.cooperbaker.com

paulb

Cooper


You may be experiencing a documented bug in the serial buffer.

See this thread http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1168309608

It's supposed to be patched in the just released Arduino 008 so the easiest fix would be to upgrade and see if it's still there.

It could be your  baud rate is varying for some reason too, but that usually results in completely random characters.

Here are links to 008

Mac PPC: http://www.arduino.cc/files/arduino-0008-mac-ppc.zip
Mac Intel: http://www.arduino.cc/files/arduino-0008-mac-intel.zip
Windows: http://www.arduino.cc/files/arduino-0008-win.zip

Paul Badger

mellis

Cooper: can you post the full code for your sketch?  What are you using to send and read the data to and from the board?

Cooper Baker

Thanks for the tip Paulb.

mellis:

I was using hyperterminal to send ascii characters at 9600 baud to a max232 chip, which was connected to the RX arduino pin.  The TX pin was sending ascii characters and was hooked up to a sparkfun serial lcd. Unfortunately I can't paste the sketch because of an n.d.a...

mellis

Hmm, I would try splitting up the different tasks to see which one (if it's only one) that's the problem.  Out of curiosity why are you using the Max chip instead of the builtin USB or serial connection on the Arduino board?  Can you try simply echoing the characters back to the computer to see if the problem is in the communication with the LCD or the computer?

Cooper Baker

I used a max232 because I was receiving rs232 line signals and needed to convert them to TTL level signals to send into the arduino serial port.  So, I actually did use the arduino serial port after the incoming rs232 signal was converted to the proper signal for the atmel chip.

I tried several different debug methods (echo to computer, to lcd, to memory, etc...) and determined the bug was software based.

Cheers,
Cooper

mellis

It's certainly possible that the problem is in the Arduino software.  Can you give us more details about the communication?  Are you seeing a problem when you send just the three characters "555"?  Do you see 55ë every time you send those characters?  What if you send other three character strings?  Longer or shorter strings?

I've seen this sort of problem with the software serial on Arduino, but the hardware serial seems to reasonably reliable, so if you get an incorrect character when you only send 3 bytes, I suspect it has something to do with the setup (not that it's wrong, but just that it's making different assumptions than the Arduino software does).  Is it possible there's a mismatch between the serial settings that the Arduino is using (8-bit, no parity, one stop bit, no flow control) and those that HyperTerminal is using?

Go Up