Steve, Good job with the explanation. Where were you when I was learning this stuff years ago? I had to plow through tons of crazy documents (many that I paid for) before I figured it out. I put this one with Thomas McGahee's stepper tutor. Dan -----Original Message----- From: Steve Thackery To: PICLIST@MITVMA.MIT.EDU Date: Saturday, August 28, 1999 1:28 AM Subject: Re: Start and Stop Bits >Hi Mario, > >You are doing nothing wrong. The start and stop bits must have opposite >polarity, and this requirement arises from the way in which asynchronous >serial communications work. > >There are two ways to look at this. I'll try the simple way first and then >give a slightly fuller explanation. The start and stop bits mark the start >and end of each transmitted character, right? Imagine a stream of >characters: you get a start bit, the character, a stop bit(s), a start bit, >the character, a stop bit(s), and so on. > >If you look at that sequence it should be obvious that the stop and start >bits between the two characters must have opposite polarities otherwise you >couldn't tell them apart, right? If they were both the same polarity you >couldn't tell when the stop bit finished and the start bit started. In >other words, the receiver needs an "edge" or a "transition" to signal the >commencement of the start bit. So it's gotta be of opposite polarity to the >stop bit preceding it. > >Incidentally, before proceeding, I need to tell you about marks and spaces. >Basically, with serial comms you talk about marks and spaces rather than 1s >and 0s, or highs and lows. A mark represents a logic 1, a space represents >a logic 0. A stop bit happens to be a mark, a start bit is a space. > >Just to confuse you even further, the polarity of marks and spaces on an >RS232 serial transmission line seems the wrong way round: marks are sent as >a negative voltage, spaces as a positive voltage. > >I'll just summarise that again, as a sanity check: a mark represents a logic >1 and is a negative voltage, a space represents a logic 0 and is a positive >voltage. A start bit is a space (positive), a stop bit is a mark >(negative). > >In the eight bits of the transmitted character, the 1s are negative (marks) >and the 0s are positive (spaces). I said it seemed the wrong way round!! > >One more thing, which I'm sure you know. The duration of the bits is >determined by the bits-per-second rate of the line (often, but not always >correctly, called the baud rate). So, on a 1200 baud link each bit lasts >1/1200th of a second. This is relevant later. > >The thing about asynchronous comms is that there is, or can be, any amount >of idle time between the characters transmitted. So the receiver can't >synchronise itself to the incoming bit stream (hence "asynchronous"). When >the line is idle, the transmitter sends out a continuous "marking" >(negative) voltage. You might like to think of this as a continuous stream >of stop bits. The receiver sits there drumming its fingers, having no idea >when the next character is going to arrive. > >Eventually a character is transmitted. Here is the crucial part: the start >bit is of opposite polarity, so the first thing the receiver sees is a >transition from a mark to a space. The receiver now knows the precise >moment in time at which this transition - the leading edge of the start >bit - arrived. It also knows how long each bit (including the start bit) >should last (i.e. 1/1200th of a second). So, it waits >for the duration of half a bit and samples the voltage on the line again. >This puts it right smack in the middle of the start bit. If it still sees a >'space' it knows the start bit is real (i.e. it wasn't just a noise blip on >the line). It then waits 1/1200th of a second and samples the line yet >again. This puts it smack in the middle of the first bit of the character. >It continues to sample at 1/1200th of a second intervals thereafter until it >gets to the stop bit(s). Once it has registered the stop bit it then goes >into continuous monitoring mode in order to pick up the next transition to a >start bit. > >You will see that the receiver's internal clock (for measuring out the >1/1200th of a second sampling intervals) doesn't need to be particularly >accurate. All that's required is that it stays within half a bit over the >duration of the received character. In other words, an accuracy of a few >percent if fine. This means that asynchronous comms are cheap and easy to >implement. > >Just a couple of odds and sods. It is not uncommon to transmit two stop >bits. Interestingly, in this case you can configure the receiver to expect >either one or two and it will still work. If you tell it to expect just >one, it simply assumes there is a slight gap between the characters. >Remember, the stop bit - a mark - looks like the line idle condition. >Sometimes a parity bit is transmitted. What this means is that, according >to how you set things up, a character may be anything from 10 to 12 bits >long. > >At one time some systems were set up to transmit just seven bits for the >character, that being sufficient for the entire ASCII character set. So >these could be as short as 9 bits in length. > >You might be interested to know that the worldwide telex standard uses a >five bit code, with a stop bit one-and-a-half bits long! This gives 7 1/2 >bits per character. > >Phew!! Sorry for the awesome length of this email. I hope you will find at >least some of it of use. > >Regards, > >Steve > >Steve Thackery >Suffolk, England. >Web Site: http://www.btinternet.com/~stevethack/