Society of Robots - Robot Forum

Electronics => Electronics => Topic started by: airman00 on March 15, 2009, 06:29:59 PM

Title: Strange UART problem
Post by: airman00 on March 15, 2009, 06:29:59 PM
SETUP : Axon that outputs '7' (decimal of 55) through UART at 2400 baud , 8 data bits, no parity, 1 stop bit, no handshaking.
FT232 reads output of Axon's UART and displays it in my Terminal program. Terminal is set to the correct setting to "talk" with the Axon.
I used this breakout board for the FT232 - http://www.sparkfun.com/commerce/product_info.php?products_id=718 (http://www.sparkfun.com/commerce/product_info.php?products_id=718)
All devices have a common ground.

When all the wires are connected and THEN the devices are all turned on , then I do in fact see the correct data being received in the Terminal window.
PROBLEM: Sometimes if I disconnect the Data wire from the Axon's UART pins and then plug it back in ( while all the devices are powered on) , then I no longer receive the correct data. If I disconnect it and replug the wire while the devices are on(and therefore the Axon is still constantly transmitting UART data) , then I get either º(decimal 186)  or   Ó(decimal 211)

Here's some data that might help out
Correct Data   -  decimal of 55  , binary of 00110111
Incorrect Data - decimal of 186 , binary of 10111010
Incorrect Data - decimal of 211, binary of 11010011

My code for transmitting the UART
Code: [Select]
void SendByte(char c) {
// Syntax is SendByte(#); where # is any number
while (!(UCSR0A & (1<<UDRE0))); // Wait until you are able to send a byte
UDR0 = c; // pass the value of the c variable into the UDR ,
}

QUESTION:
How can I always receive correct data from the UART ?

Thank you
Title: Re: Strange UART problem
Post by: Soeren on March 15, 2009, 08:08:27 PM
Hi,

EIA/TIA232 was never meant to be hot plugged!
So... Just don't disconnect in the middle of a transmission, You won't put a car in reverse going down the highway at full speed, would you?

That said, If you leave enough time in between transmissions, it should be able to get into synch, but you have to empty the receive buffer, or you will go on from an unknown state.

Title: Re: Strange UART problem
Post by: airman00 on March 15, 2009, 08:15:33 PM
Hi,

EIA/TIA232 was never meant to be hot plugged!
So... Just don't disconnect in the middle of a transmission, You won't put a car in reverse going down the highway at full speed, would you?

That said, If you leave enough time in between transmissions, it should be able to get into synch, but you have to empty the receive buffer, or you will go on from an unknown state.
Thanks Soeren that cleared it up for me!

If I use RF transmitter and RF receiver to have a wireless link I get the same problem , so I assume emptying the receive buffer like you said would solve my issue?
Title: Re: Strange UART problem
Post by: Admin on March 15, 2009, 09:02:30 PM
I noticed this problem when using the Blackfin with the Axon . . . I just flushed the buffer right before requesting data and the problems went away.