Go Down

Topic: Auto Detect Baud Rate (Read 3 times) previous topic - next topic

tnovak

I have been searching for a solution to auto detect a baud rate of a serial connection with a gps reciever. Lefty has an old post showing interest in this concept, but I had no luck finding a finished solution. Any thoughts??

James C4S

Hope that the GPS unit occasionally sends an ASCII "U".  (so you can detect the 1010 pattern...)
Capacitor Expert By Day, Enginerd by night.  ||  Personal Blog: www.baldengineer.com  || Electronics Tutorials for Beginners:  www.addohms.com

jwatte

You don't need to detect the 1010 pattern. All you need is to measure the shortest interval between two flanks (rising -> falling, or falling -> rising) for some amount of traffic. Assuming the communications wiring is good, the shortest duration between two flanks will be the duration of a single bit. The baud rate will then be 1 divided by that duration (in seconds.) You probably want to round/clamp/adjust that to be the closest "standard" baud rate once measured.

Coding Badly


For a device that transmits continuously (like a GPS) I've found the easiest way to detect the baud rate is to simply try each possibility until something recognizable arrives.  If the baud rates are tested in a logical order (e.g. 4800 first) then, in most cases, the detection takes just a few frames.  On success, saving the baud rate to EEPROM makes detection even faster the next time around.

retrolefty

#4
Mar 29, 2012, 04:14 pm Last Edit: Mar 29, 2012, 04:22 pm by retrolefty Reason: 1

I have been searching for a solution to auto detect a baud rate of a serial connection with a gps reciever. Lefty has an old post showing interest in this concept, but I had no luck finding a finished solution. Any thoughts??


My memory from my attempt was that I was only able to 100% reliably detect the proper baudrate if I could control what character(s) were being sent to base the detection method on using the pulseIn() method, as some characters would falsely cause that method to think the baudrate is slower then actual as there was no single bit length avalible in certain characters. That means a reliable algorithm when using arbitrary input characters would have to look at multiple characters and search for a minimum bit length. That was too complex for me to continue playing with, but certainly possible. On using a single character baudrate detection using the 'U' character I think, did work reliably as did several other characters, but several characters would 'spoof' the detection method, it's been while.

Lefty

Go Up