EmbeddedRelated.com
Forums
The 2024 Embedded Online Conference

baud rate autodetection on AVR 8-bit?

Started by Ivan Shmakov December 7, 2012
On 07/12/2012 20:47, Ivan Shmakov wrote:
>>>>>> Dave Nadler <drn@nadler.com> writes: >>>>>> On Friday, December 7, 2012 11:31:21 AM UTC-5, Ivan Shmakov wrote: > > >> Well, I guess I can use a pin change interrupt instead, and just > >> save the timer's counter in the handler. (Thus introducing a > >> constant delay, which will disappear anyway in the delta.) > > > No "capture" function available on the timer, so that you get an > > exact measurement? Sorry I don't remember on this part... > > AIUI, ATmega8 only allows for input capture to happen on an > "event" occuring either on analog comparator output, or a > specific ICP1 pin. Unfortunately, I'd need the latter for GPIO. > (Naturally, ICP1 is distinct from UART's RxD.) >
Since you are starting out on a new project why use an obsolete processor ? You can buy an LPC1113 (or some one else's ARM Cortex M0) for less money than an ATmega8 and it has much better timers with input capture. It also has a good 10x the performance ! Michael Kellett
>>>>> MK <mk@nospam.co.uk> writes: >>>>> On 07/12/2012 20:47, Ivan Shmakov wrote:
(I vaguely recall that there already was a discussion on this.) [...] >> AIUI, ATmega8 only allows for input capture to happen on an "event" >> occurring either on analog comparator output, or a specific ICP1 >> pin. Unfortunately, I'd need the latter for GPIO. (Naturally, ICP1 >> is distinct from UART's RxD.) > Since you are starting out on a new project why use an obsolete > processor? You can buy an LPC1113 (or some one else's ARM Cortex M0) > for less money than an ATmega8 and it has much better timers with > input capture. Apart from lacking any experience whatsoever with ARM, I'm also somewhat concerned about the ARM's /generally/ being unavailable in TQFP, SO or DIP packages, which may be important should I'll be making a "kit" of the design I'm currently working on. Besides, where can I find an ARM for $0.9 (or less; including shipping)? (For the quantity, I'd readily buy 10 or so.) > It also has a good 10x the performance! ... And what about the power consumption? -- FSF associate member #7257
On Fri, 07 Dec 2012 10:28:41 -0500, Rich Webb
<bbew.ar@mapson.nozirev.ten> wrote:

>On Fri, 07 Dec 2012 21:17:16 +0700, Ivan Shmakov <oneingray@gmail.com> >wrote: > >> BTW, is there an easy way to autodetect the baud rate while >> using an AVR UART? (Preferably something that works with >> ATmega8, given that those MCU's are such a cheap thing >> nowadays.) >> >> There're some ideas (and 8051 code) for that on [1], but I'd >> like to know if there could be any better techniques. > >It's pretty straightforward if you can use a timer capture pin; it takes >care of grabbing the timer count on the active edge and you can examine >it at leisure. Essentially, you will want to listen to an incoming >serial stream to measure the narrowest pulse and when you've seen enough >identical pulses, that determines the rate. If you get a narrower pulse >(that is wider than a glitch width), start the count over.
When using capture pins or using simple bit banging, if there are something known about the signal source, some heuristics can be used to reduce the possible combinations. In asynchronous communication, the line is in the "idle" state (Mark, logical 1) 20 mA in current lop, -12 V in RS-232 and so on. The "fail-safe" termination will pull the line to idle state in RS-485. Each character starts by the start bit (Space, logical 0, 0 mA, +12 V..) ), following by a number (usually 5-14) of data bits, followed by an optional parity bit, followed by 1, 1.5 or 2 stop bits (logical 1). After the last stop bit, if there are no more characters to send, the idle period (logical 1) starts. The line remains in the idle state for an arbitrary time, unless there is more characters to send. While this time can be absolutely anything, typical UARTs start transmitting at some clocked intervals, typically 1/16 multiples of the bit clock period. If there is a lot of characters in to be transmitted, immediately after the last stop bit ("1"), the start bit ("0") will be immediately sent. However, in quite a few situations, the line remains longer or shorter periods in the idle "1" state, thus detecting the if&#4294967295;dle state will help in detecting the start bit "0" after the idle period and hence help figuring out the timing. For instance, if the signal source is a keyboard operated by a human, even with autorepeat and line speeds above 300 bits/s, there are quite long idle periods between characters. Even with half duplex protocols (request/response) even with full duplex capable hardware, there are some idle periods between master requests and slave responses (especially Modbus requires a 3.5 character idle period between request and response). If you are only listening to master requests or only slave responses, there are quite long idle periods between two requests or two responses. Once you have identified the idle state, wait for the start bit "1"->"0" transition. Most UARTs use some kind of false start bit detection to see, if the line is still in the "0" state, by sampling at the middle of start bit of use three 1/16 bit time samples and majority voting. Of course, this assumes that the bit rate is known. Since the bit rate is not known, check for each possible half bit length point for various possible standard bit rates, is the line still in "0" state and continue validation. However, if you get a "1" state at some of the sampling points, it can be assumed, that the original falling edge was not a true start bit and discard it or that the data rate is higher than you expected. Search for other alternatives.
Op 07-Dec-12 15:17, Ivan Shmakov schreef:
> BTW, is there an easy way to autodetect the baud rate while > using an AVR UART? (Preferably something that works with > ATmega8, given that those MCU's are such a cheap thing > nowadays.)
You might find something useful in this article which uses a ATtiny2313: http://spritesmods.com/?art=autobaud
On 07/12/12 15.17, Ivan Shmakov wrote:
> BTW, is there an easy way to autodetect the baud rate while > using an AVR UART? (Preferably something that works with > ATmega8, given that those MCU's are such a cheap thing > nowadays.) > > There're some ideas (and 8051 code) for that on [1], but I'd > like to know if there could be any better techniques. > > TIA. > > [1] http://www.pjrc.com/tech/8051/autobaud.html > > PS. It seems that I'm slowly drifting into designing my own, AVR-based > Bus Pirate clone. The good news is that the parts for this one > will likely cost under $10... (connectors included.) >
(Please respond to news://comp.arch.embedded ) Hi! I am so "pissed" about RS-232/EIA-232. After so many years with that "stupid vintage" serial communications protocol, we still do not have autonegotiation (and auto-baud-detection) built into the protocol definitions. Why not? Why have nobody made a request-for-comment about that, then so many people do not have to bother with a myriad of out-of-bound signals and in-band signal (xon, xoff) manually. It is simply incredibly, that after so many decades, you manually has to find out, how to get it to work. Please be inspired to release open and free RFC-definitions now, so that "vintage" serial communication will work smoothly - and with backward compatibility and of cause with auto "null-modem" functionality. I am looking forward to, that all out-of-bound signals can automatically be mapped by software by a series of signal pertubations and response measurements. I know I am very demanding, but it ought to be possible? At least the software should detect and notify the user, that a null-modem cable connection is required. But it is a bad compromise. The communications world (and its users) would be much happier with a full blown software solution. Let us exterminate 232 jumper boxes. They are the ultimate time eating stupid solution, that shows we have given up finding a better solution: http://www.amazon.com/DB25-Female-RS-232-Jumper-Assembly/dp/B000I996EE Instead we should have a 232 autonegotiation-box/cable, that can be inserted between no-negotiation 232 equipped equipment. ;-) Glenn PS: I know that USB exists...
Glenn wrote:

> On 07/12/12 15.17, Ivan Shmakov wrote:
[%X]
> I am so "pissed" about RS-232/EIA-232. > > After so many years with that "stupid vintage" serial communications > protocol, we still do not have autonegotiation (and auto-baud-detection) > built into the protocol definitions. Why not? > > Why have nobody made a request-for-comment about that, then so many > people do not have to bother with a myriad of out-of-bound signals and > in-band signal (xon, xoff) manually. > > It is simply incredibly, that after so many decades, you manually has to > find out, how to get it to work.
Having dealt with the RS232 protocol for many years I am wondering why you are suddenly so vexed about it. The protocol precedes computing devices, having been created as a communication protocol for teleprinters (originally the 5 bit code before becoming the 7 bit and 8 bit codes we have today). Auto-negotiation takes intelligence at each end. As that was not available at that time we just accepted the need to get things set-up right before we started.
> Please be inspired to release open and free RFC-definitions now, so that > "vintage" serial communication will work smoothly - and with backward > compatibility and of cause with auto "null-modem" functionality. > > I am looking forward to, that all out-of-bound signals can automatically > be mapped by software by a series of signal pertubations and response > measurements.
I am sure there is an official way to propose a new RFC if you need to. You could try and do that if you have some ideas that you would like to see implemented as standard. I am not sure you would get much support with such an old protocol though. -- ******************************************************************** Paul E. Bennett...............<email://Paul_E.Bennett@topmail.co.uk> Forth based HIDECS Consultancy Mob: +44 (0)7811-639972 Tel: +44 (0)1235-510979 Going Forth Safely ..... EBA. www.electric-boat-association.org.uk.. ********************************************************************
"Glenn" <glenn2233@gmail.com> wrote in message 
news:50c45e31$0$284$14726298@news.sunsite.dk...
> On 07/12/12 15.17, Ivan Shmakov wrote: >> BTW, is there an easy way to autodetect the baud rate while >> using an AVR UART? (Preferably something that works with >> ATmega8, given that those MCU's are such a cheap thing >> nowadays.) >> >> There're some ideas (and 8051 code) for that on [1], but I'd >> like to know if there could be any better techniques. >> >> TIA. >> >> [1] http://www.pjrc.com/tech/8051/autobaud.html >> >> PS. It seems that I'm slowly drifting into designing my own, AVR-based >> Bus Pirate clone. The good news is that the parts for this one >> will likely cost under $10... (connectors included.) >> > > (Please respond to news://comp.arch.embedded ) > > Hi! > > I am so "pissed" about RS-232/EIA-232. > > After so many years with that "stupid vintage" serial communications > protocol, we still do not have autonegotiation (and auto-baud-detection) > built into the protocol definitions. Why not? > > Why have nobody made a request-for-comment about that, then so many people > do not have to bother with a myriad of out-of-bound signals and in-band > signal (xon, xoff) manually. > > It is simply incredibly, that after so many decades, you manually has to > find out, how to get it to work. > > Please be inspired to release open and free RFC-definitions now, so that > "vintage" serial communication will work smoothly - and with backward > compatibility and of cause with auto "null-modem" functionality. > > I am looking forward to, that all out-of-bound signals can automatically > be mapped by software by a series of signal pertubations and response > measurements. > > I know I am very demanding, but it ought to be possible? At least the > software should detect and notify the user, that a null-modem cable > connection is required. But it is a bad compromise. > > The communications world (and its users) would be much happier with a full > blown software solution. > > Let us exterminate 232 jumper boxes. They are the ultimate time eating > stupid solution, that shows we have given up finding a better solution: > http://www.amazon.com/DB25-Female-RS-232-Jumper-Assembly/dp/B000I996EE > > Instead we should have a 232 autonegotiation-box/cable, that can be > inserted between no-negotiation 232 equipped equipment. > > ;-) > > Glenn > > PS: I know that USB exists...
The problem isn't RS232, it's simply end points that don't talk the same language. You can have just as much grief with any other comunication protocol, for exactly the same reasons. In fact, IME some others can deliver heaps more grief in setting up than serial async/RS232. It's a matter of standards, and in the case of RS232 specifically, there's a lot to like. The voltage levels are compatible, as long as you don't violate the specified cable specs (and even if you do by a reasonable margin) crosstalk won't cause errors, and drivers are specified against damage from wiring errors. Higher up the stack - not RS232 any more, which deals with electrical behaviour only - the ASCII character set is locked in, including various standard control sequences if you want to use them. Higher up still the situation is less clear, but that's due to the facts that there are a huge multiplicity of client devices involved, with little or no unifying behaviour in many cases, and mutiple producers of equipment. If the devices at each end of the link come from the same supplier, then you're likely to find the setup plug-n-play. If they don't then the chances of mismatch are greater, and the problem isn't clearly owned by anyone except yourself. This lack of ownership is a large part of the problem, and it can only be solved by more encompassing standards.
In article <50c45e31$0$284$14726298@news.sunsite.dk>, glenn2233
@gmail.com says...
> > On 07/12/12 15.17, Ivan Shmakov wrote: > > BTW, is there an easy way to autodetect the baud rate while > > using an AVR UART? (Preferably something that works with > > ATmega8, given that those MCU's are such a cheap thing > > nowadays.) > > > > There're some ideas (and 8051 code) for that on [1], but I'd > > like to know if there could be any better techniques. > > > > TIA. > > > > [1] http://www.pjrc.com/tech/8051/autobaud.html > > > > PS. It seems that I'm slowly drifting into designing my own, AVR-based > > Bus Pirate clone. The good news is that the parts for this one > > will likely cost under $10... (connectors included.) > > > > (Please respond to news://comp.arch.embedded ) > > Hi! > > I am so "pissed" about RS-232/EIA-232. > > After so many years with that "stupid vintage" serial communications > protocol, we still do not have autonegotiation (and auto-baud-detection) > built into the protocol definitions. Why not?
As others have said it is old, but first of lets consider some things RS-232 is a voltage levels and cable spec, nothing to do with how many bits or how transmitted in its framing. You can use RS232 quite vailidly for on/off control of lights as DC levels. There is NO protocol in RS232 Your problem is poor implementations higher up the chain. UART and other communications can be done many ways even without any form of RS-xxx level conversions. -- Paul Carpenter | paul@pcserviceselectronics.co.uk <http://www.pcserviceselectronics.co.uk/> PC Services <http://www.pcserviceselectronics.co.uk/fonts/> Timing Diagram Font <http://www.gnuh8.org.uk/> GNU H8 - compiler & Renesas H8/H8S/H8 Tiny <http://www.badweb.org.uk/> For those web sites you hate
On 08/12/2012 11:31, Ivan Shmakov wrote:
>>>>>> MK <mk@nospam.co.uk> writes: >>>>>> On 07/12/2012 20:47, Ivan Shmakov wrote: > > (I vaguely recall that there already was a discussion on this.) > > [...] > > >> AIUI, ATmega8 only allows for input capture to happen on an "event" > >> occurring either on analog comparator output, or a specific ICP1 > >> pin. Unfortunately, I'd need the latter for GPIO. (Naturally, ICP1 > >> is distinct from UART's RxD.) > > > Since you are starting out on a new project why use an obsolete > > processor? You can buy an LPC1113 (or some one else's ARM Cortex M0) > > for less money than an ATmega8 and it has much better timers with > > input capture. > > Apart from lacking any experience whatsoever with ARM, I'm also > somewhat concerned about the ARM's /generally/ being unavailable > in TQFP, SO or DIP packages, which may be important should I'll > be making a "kit" of the design I'm currently working on. > > Besides, where can I find an ARM for $0.9 (or less; including > shipping)? (For the quantity, I'd readily buy 10 or so.) > > > It also has a good 10x the performance! > > ... And what about the power consumption? >
ARMs are easily available in TQFP packages and I rarely use anything else. As for prices: 100 off Digikey, LPC1113FBD48/302,1 = $2.05 ATMEGA8A-AU = $1.79 You'll need to compare power consumption yourself but generally ARM M0s are pretty good and will easily beat the AVR in terms of useful calculations per watt. If you'll relax your package demands and accept LPC1111FHN33/201,5 in QFN it'll only cost you $1.38 (Digikey 100 off). I've hand soldered quite a few of these and it's perfectly feasible (you may need a microscope but I use one for TQFPs any way.) Michael Kellett
On 09.12.2012 10:47, Glenn wrote:

> After so many years with that "stupid vintage" serial communications > protocol, we still do not have autonegotiation (and auto-baud-detection) > built into the protocol definitions. Why not?
Because there really is nothing to negotiate.
> Why have nobody made a request-for-comment about that,
For starters, because I'm pretty sure there is no RFC mechanism in place for the body that this specification is from. If that body still exists, that is.
> It is simply incredibly, that after so many decades, you manually has to > find out, how to get it to work.
Actually no. It's exactly because of all those decades, and the myriad of devices already in the field, that this specification is, for all practical intents and purposes, immutable. No change you could come up with now would help one bit with all those devices. And if a change doesn't achieve anything for the overwhelming majority of applications, what point could there possibly be?

The 2024 Embedded Online Conference