home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: sci.electronics
- Path: sparky!uunet!sun-barr!decwrl!csus.edu!netcom.com!nagle
- From: nagle@netcom.com (John Nagle)
- Subject: Re: How does a UART do it...
- Message-ID: <v=rn0!p.nagle@netcom.com>
- Date: Tue, 08 Sep 92 05:57:25 GMT
- Organization: Netcom - Online Communication Services (408 241-9760 guest)
- Keywords: uart comms asynchronous
- References: <18ff9hINNa5b@grapevine.EBay.Sun.COM> <1992Sep7.183135.21197@sobeco.com>
- Lines: 39
-
- dchouina@sobeco.com (Daniel Chouinard) writes:
-
-
- >In sci.electronics you write:
-
- >>Given a stream of 1s & 0s, how does a UART get the character framing
- >>established, i.e. how is the 'start' bit differentiated from all the
- >>others? (I want to emulate one in software)
-
- >>Steve
-
- >I once wrote a terminal emulator for the Color Computer (TRS-80) that uses
- >its "bit banger" (no uart, just a PIA input).
-
- >1: Assume T being the period of half a bit. (That's 1/600th sec. for 300 baud)
- >2: Loop until receive line goes low. (Beginning of start bit)
- >3: Wait T three times (ignore start bit, end wait time in middle of first bit)
- >4: Get bit, shift it in register, wait T twice (go to middle of next bit)
- >5: Repeat step 4 six, seven or eight times, depending on word length.
- >6: Wait T twice (end in middle of stop bit)
- >7: go to step 2.
-
- >The framing's done in step 2. Given a random stream of bytes, it synchronizes
- >after a while.
-
- This isn't quite right. If the receive line is stuck at low (SPACE)
- (no input) this code will think it is getting solid NUL characters.
- You really want something like
- >2a: Loop until receive line goes high (waiting for STOP bit).
- >2b: Loop until receive line goes low (beginning of START bit).
- This insists that the program see the STOP/START transition.
- This will also speed up resynchronization after noise and will
- produce more consistent behavior when set at the wrong baud rate.
- Also, after step 6, if the receive line is low, you have detected a
- "framing error", if you want to check for that. If you detect
- all 0 data bits plus a framing error, and the time spent waiting for
- a stop bit is >100ms, you have found a "break".
-
- John Nagle
-