Mauricio Culibrk wrote: > In one of my applications, I need a serial RX/TX routine capable > to 'recognize' the speed of the serial line, so it can adjust > itself to that speed (eg. I have a '84 based 'host' to which I > want to attach few 'terminals' working at 1200, 2400, 4800, 9600 > baud). Did anybody try something similar? Any ideas on how to > determine the RX speed, possibly without loosing a byte of data? Joel Carvajal replied: > To summarize, in order to connect to a host at his baud rate, the > host must send a "synchronization" data. Of course you must know > the data. You then adjust your baud rate until you receive the > correct data. When you finally is in "harmony" with your host, > inform him, and the rest of the communication then proceeds. Mauricio: If you're sending standard ASCII using no parity, 8 data bits, and 1 stop bit, you don't need to send a string of known synchronization data at the start of your transmissions as Joel suggests. Instead, you can simply start a timer at the first HI-to-LO transition (the start bit), then check the timer at every LO-to-HI transition. Set the timer up so that it'll time out after slightly more than the length of 9 bits at your slowest baud rate (>7.5 milliseconds for your 1200 baud rate). I'd probably set the timer to expire in 8.192 milliseconds; if I used the RTCC and were running at 4 MHz, I'd set the prescaler to divide-by-32 so that the timer could be contained in just one byte. When the timer expires, the value it contained at the last LO-to-HI transition will be the time between the leading (falling) edge of the start bit and the leading (rising) edge of the stop bit. A simple table-lookup will tell you what baud rate you're receiving. This technique works because the MSB is never set in standard ASCII, so the leading edge of the stop bit will always be visible. Note that this technique will NOT work if there's no delay between one character and the next; the second character must not be transmitted until at least 8.192 milliseconds after the start of the first character. -Andy Andrew Warren - fastfwd@ix.netcom.com Fast Forward Engineering, Vista, California http://www.geopages.com/SiliconValley/2499