home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #20 / NN_1992_20.iso / spool / sci / electron / 15341 < prev    next >
Encoding:
Text File  |  1992-09-08  |  2.1 KB  |  51 lines

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