home *** CD-ROM | disk | FTP | other *** search
/ ftp.whtech.com / ftp.whtech.com.tar / ftp.whtech.com / Geneve / 9640news / CAT14 / RS232.ARK < prev    next >
Text File  |  2006-10-19  |  17KB  |  526 lines

  1. ?
  2. RS232 Tutorial written By Mack McCormick
  3.  
  4.  
  5.      Many people have asked me to
  6. explain in better detail how they can
  7. directly access the RS232 ports on their
  8. 99/4As for such things as terminal
  9. emulators, BBS Software, protocol file
  10. transfer software, and so on. Many of
  11. these people have made some attempt at
  12. trying to do single byte I/O using the
  13. standard DSR entries but soon get
  14. frustrated with the hassle that is
  15. involved, not to mention the lack of
  16. ability to tell when a character has
  17. arrived at the port, detecting carrier
  18. and ringing signals and other such
  19. useful features. In this article we will
  20. give you an overview of the TMS 9902
  21. Asynchronous Communications Controller
  22. Chip used in the TI RS232 Card and
  23. define the input CRU testing bits; the
  24. final article will explain the details
  25. of programming the 9902 directly with
  26. some code examples.
  27.  
  28.       TMS 9902 Overview. Figure 1 shows
  29. the pinout of the TMS 9902 ACC Chip. The
  30. 9902 is fabricated using NMOS and uses
  31. standard TTL level signals on all inputs
  32. and outputs. The device is capable of
  33. handling asynchronous communications
  34. with word lengths from 5 to 8 bits with
  35. 1, 1 1/2 and 2 stop bits, full parity
  36. checking (even/odd/none) with built in
  37. data rate generation (no external bit
  38. rate generators required) up to 19,200
  39. bits per second. The 9902 also includes
  40. an interval timer with resolution from
  41. 64 to 16,320 microseconds. Interfacing
  42. between the 9902 and the 9900 host
  43. environment is done thru the
  44. Communications Register Unit, the CRU.
  45. As you look at Figure 1 you see S0-S4,
  46. these are the CRU address lines that are
  47. used to interface the 9902 to any 9900
  48. series microprocessor. When the chip
  49. enable (pin 17) is asserted the 9902 is
  50. placed on the bus and the function
  51. requested is determined by S0-S4 and the
  52. CRU control logic. CRUCLK (pin 15)
  53. provides the CRU timing while the system
  54. clock (pin 16) provides the timing for
  55. the rest of the 9902. CRUIN (pin 4) and
  56. CRUOUT (pin 8) are the CRU input and
  57. output bits, respectively. In addition
  58. to the CRU logic additional lines are
  59. provided for Request To Send (pin 5),
  60. Clear To Send (pin 6) and Data Set Ready
  61. (pin 7.) The received data is on pin 3,
  62. the transmitted data is sent out over on
  63. pin 2, and the interrupt line for the
  64. 9902 is on pin 1. Finally, +5 volts goes
  65. on pin 18 and logic zero (ground) is on
  66. pin 9. For RS232 applications the widely
  67. used 75188/75189 buffer chips are used
  68. for bringing out the transmit/receive
  69. signals, as well as DSR, RTS and CTS. In
  70. the 99/4A RTS and CTS are tied
  71. together.
  72.  
  73. The interrupt pin will go to a low logic
  74. level when certain conditions occur
  75. during the operation of the 9902, these
  76. will be explained shortly.
  77.  
  78.       TMS 9902 CRU Input Assignments.
  79. Accessing the 9902 in your program
  80. requires the use of assembly language
  81. with the CRU instructions TB, SBO, SBZ,
  82. LDCR and STCR; check your Assembly
  83. Language reference manual for the format
  84. of the instructions. Table 1 shows the
  85. input bit assignments which goes as
  86. follows:
  87.  
  88.  Bit 31: Interrupt. When programmed, any
  89. of the following conditions, if met;
  90. will set this bit and also cause the
  91. interrupt pin on the 9902 to be
  92. asserted: DSCINT, TIMINT, XBINT, RBINT.
  93. In addition, the respective bit that
  94. raised this condition will also be set.
  95.  
  96.  Bit 30: Flag. Set when any of the load
  97. register commands are issued or when the
  98. break bit is set (See Table 2.)
  99.  
  100.  Bit 29: Data Set Status Change. Set
  101. when DSR or CTS changes logic states and
  102. is stable for 2 clock cycles. This bit
  103. is cleared when an output to bit 21
  104. (DSCENB) is made.
  105.  Bit 28: Clear To Send. Indicates the
  106. logic level on the Clear To Send pin.
  107. Note that the bit present will be the
  108. inverse of the logic level on the pin.
  109.  
  110.  Bit 27: Data Set Ready. Indicates the
  111. logic level on the Data Set Ready pin.
  112. The bit will be inverse of the input.
  113.  Bit 26: Request To Send. Indicates the
  114. logic level of the Request To Send pin.
  115. The bit will be the inverse of the pin.
  116.  
  117.  Bit 25: Timer Elapsed. Set when the
  118. timer register equals zero. Cleared by
  119. an output to bit 20 (TIMENB).
  120.  
  121.  Bit 24: Timer Error. This bit is set
  122. when the timer has reached zero and when
  123. TIMELP is set. This is raised when the
  124. software fails to recognize TIMELP and
  125. reset it before another interval passed.
  126. This is also cleared by an output to bit
  127. 20.
  128.  
  129.  Bit 23: Transmitter Shift Register
  130.  
  131.  Empty. Set when the Transmitter shift
  132. register is not sending data (also
  133. indicates that XOUT is at a high logic
  134. level.) When this bit is at logic zero,
  135. character transmission is in progress.
  136.  
  137.  Bit 22: Transmit Buffer Register Empty.
  138. When set, this indicates that there is
  139. not a character waiting to be
  140. transmitted. It is set to a logic zero
  141. when a character is written to the
  142. transmit buffer register.
  143.  
  144.  Bit 21: Receive Buffer Register Loaded.
  145. When set, indicates that a complete
  146. character has been assembled in the
  147. receive buffer register. It is cleared
  148. by an output to bit 18 (RIENB).
  149.  
  150.  Bit 20: Data Set Status Change
  151.  
  152.  Interrupt. Set when either DSR or CTS
  153. changes state and the Data Set Status
  154. Interrupt has been enabled.
  155.  Bit 19: Timer Interrupt. Set when the
  156. timer has elapsed and the Timer
  157. Interrupt has been enabled.
  158.  
  159.  Bit 17: Transmitter Interrupt. Set when
  160. the Transmit buffer register is empty
  161. and the Transmitter Interrupt has been
  162. enabled.
  163.  
  164.  Bit 16: Receive Interrupt. Set when the
  165. Receive Buffer register is loaded and
  166. the receive interrupt has been enabled.
  167.  
  168.  Bit 15: Receive Input. The logic level
  169. of the RIN line at the time that the
  170. inpu was sampled.
  171.  
  172.  Bit 14: Receive Start Bit Detect. Set
  173. during transition of the first bit of a
  174. word. Normally not used.
  175.  
  176.  Bit 13: Receive Full Bit Detect. Set
  177. when the first bit of the character
  178. (excluing the start bit) is received,
  179. and is cleared when the character is
  180. completed. Not normally used.
  181.  
  182.  Bit 12: Receive Framing Error. Set when
  183. the stop bit of the recived character is
  184. a logic zero (should be a logic one),
  185. indicating a transmission error. Reset
  186. when a character with a correct stop bit
  187. is received. It is recommended that this
  188. bit only be sampled when RBRL is set.
  189.  
  190.  Bit 11: Receive Overrun Error. Set when
  191. another character is being assembled in
  192. the 9902 and the previous characeter has
  193. not been acquired from the 9902 by the
  194. software and the RBRL flag reset.
  195.  
  196.  Bit 10: Receive Parity Error. Set when
  197. the parity of the incoming character is
  198. incorrect, indicating transmission
  199. error. Reset when a character with
  200. correct parity is processed.
  201.  
  202.  Bit 9: Receive Error. Set when RFER,
  203. ROVER, or RPER is set.
  204.  
  205.  Bits 7-0: Receive Buffer Register. This
  206. is the register where the received
  207. character is stored. For data lengths
  208. shorter than eight bits the data is
  209. right-justified in the register.
  210.  
  211.      In the last issue we covered the
  212. Input CRU bit assignments of the TMS
  213. 9902 Asynchronous Communications
  214. Controller Chip. In this part we will
  215. cover the Output CRU Bit assignemnts,
  216. programming examples and the TMS 9902 in
  217. the TI 99/4A environment.
  218.  
  219.       CRU Output Bit Assignments (Also
  220. see Table 2.) Described below are the
  221. Output CRU Bit assignments and their
  222. function:
  223.  
  224.  Bit 31: Reset. Setting this bit high
  225. causes the 9902 to reset the entire
  226. chip. All interrupts are disabled, RTS
  227. is set high, all register flags (LDCTRL,
  228. LDIR, LRDR, LXDR) are set high and the
  229. BREAK flag is reset. No operation to the
  230. TMS 9902 should be performed for 11
  231. clock cycles after setting this bit.
  232.  
  233.  Bits 30-22: Not used.
  234.  
  235.  Bit 21: Data Set Change Interrupt
  236.  
  237.  Enable. Setting this bit causes the
  238. 9902 to generate an interrupt when input
  239. bit 29 (Data Set Status Change) is set.
  240. Resetting this bit disables the DSCH
  241. interrupt. Writing any value to this bit
  242. will reset input bit 29.
  243.  
  244.  Bit 20: Timer Interrupt Enable. Setting
  245. this bit causes the 9902 to generate an
  246. interrupt when TIMELP (Input bit 25) is
  247. set. Resetting this bit disables the
  248. TIMELP interrupts. Writing any value to
  249. this bit will reset input bit 25.
  250.  
  251.  Bit 19: Transmit Buffer Interuupt
  252.  
  253.  Enable. Setting this bit causes the
  254. 9902 to generate an interrupt when XBRE
  255. (input bit 22) is set. Resetting this
  256. bit disables XBRE interrupts. This bit
  257. dos not affect the current value of
  258. XBRE.
  259.  
  260.  Bit 18: Receiver Interrupt Enable.
  261. Setting this bit causes the 9902 to
  262. generate an interrupt when RBRL (input
  263. bit 21) is set. Resetting this bit
  264. disables RBRL interrupts. Wrtiing any
  265. value to this bit causes RBRL to reset.
  266.  
  267.  Bit 17: Break On. Setting this bit
  268. causes the XOUT line to go to logic zero
  269. whenever the transmitter is active and
  270. XBR and XSR (both transmitter buffer and
  271. shift registers) are empty and inhibits
  272. loading characters into the transmit
  273. buffer register. Resetting this bit
  274. causes the transmitter to return to
  275. normal operation.
  276.  
  277.  Bit 16: RTS On. Setting this bit causes
  278. the RTS handshake signal to be active
  279. (low.) Resetting this bit causes RTS to
  280. go high after XSR and XBR are empty and
  281. BRKON is reset. (RTS will not go
  282. inactive until a character has completed
  283. tansmission.)
  284.  
  285.  Bit 15: Test Mode. Setting this bit
  286. causes RTS to be internally connected to
  287. CTS, XOUT to RIN, DSR held internally
  288. low, and the interval timer to operate
  289. at 32 times its normal rate. This is
  290. useful for debugging programs that are
  291. transmitting and receiving data and for
  292. tsting to insure that the internal 9902
  293. functions are working properly.
  294. Resetting this bit causes the 9902 to
  295. return to normal operating mode.
  296.  
  297.  Bits 14-11: Register Load Control
  298.  Flags. These bits are described below:
  299.  
  300.  Bit 14: Load Control Register. This bit
  301. when set (either explicitly or after the
  302. RESET bit is set) causes the control
  303. regiter in bits 0-7 to be loaded into
  304. the 9902. Resetting this bit (or upon
  305. reception of the last control register
  306. bit) causes the control register to be
  307. inhibited from loading.
  308.  Bit 13: Load Interval Register. Setting
  309. this bit causes the next 8 bits (bits
  310. 0-7) to be loaded into the 9902's
  311. interval register. the Bit is reset when
  312. the last data bit is loaded or a logic
  313. zeo is written to LDIR. To load this
  314. regiter, LDCTRL must be reset (See Table
  315. 3.)
  316.  
  317.  Bit 12: Load Receive Data Rate Register.
  318. Setting this bit causes the next 11 bits
  319. (0-10) to be loaded into the 9902's
  320. Receive data rate register. The bit is
  321. reset when the last data bit is loaded
  322. or a lofic zero is written to LRDR. To
  323. load this register LDCTRL and LDIR must
  324. be zero.
  325.  
  326.  bit 11:Load Transmit Data Rate Register.
  327. Setting this bit causes the next 11 bits
  328. (0-10) to be loaded into the 9902's
  329. Transmit data rate register. The bit is
  330. reset when the last data bit is loaded
  331. or a logic zero is written to LXDR. To
  332. load this register LDCTRL and LDIR must
  333. be zero.
  334.  
  335.  Note: If both the transmit and receive
  336. data rates are the same both registers
  337. can be loaded simultaneously by setting
  338. both LRDR and LXDR.
  339.  
  340.  Bits 10 thru 0: Data. Depending on the
  341. control bits set data rate registers,
  342. the interval register, the control
  343. register or data to be transmitted are
  344. written to these bits.
  345.  
  346.  The Control Register. The control
  347. regiser is used to define the character
  348. size, the parity of the word, the number
  349. of stop bits and the operating frequency
  350. of the 9902. Table 4 outlines the bit
  351. positions and their settings. Of
  352. importance is bit 3: for the /4A
  353. environment this bit should always be
  354. zero. The PENB bit determines if parity
  355. checking is done, if set parity checking
  356. is done; if reset no parity checking is
  357. done. The PODD bit determines if the
  358. 9902 will check for/generate odd parity;
  359. if set odd parity is processed; if reset
  360. even parity is processed.
  361.  
  362.  The Data Rate Registers. Both receive
  363. and transmit registers share the same
  364. format. The data rate registers are
  365. basically 2 programmable counters that
  366. divide the system clock depending on the
  367. bit settings in the counters to derive
  368. the data rate. The first counter is a
  369. divide by eight counter that is active
  370. if bit 10 of the data rate register is
  371. loaded. Since the internal 9902 clock
  372. frequency is 1 MHz, setting this bit
  373. causes its output to be 125KHz, while
  374. resetting this bit passes the system
  375. clock right thru. The output of this
  376. first counter is fed into a 10-bit
  377. counter and is further divided down by a
  378. value from 0 to 1023. The output from
  379. this counter is actually twice the data
  380. rate (interval for half the bit period.)
  381. so this output is divided by 2 to get
  382. the actual data rate. Since this formula
  383. is not exactly the asiest way to get the
  384. baud rate, here's a list of the more
  385. popular speeds and their register values
  386. for your use:
  387.  
  388.  
  389.  
  390.     Speed            Hex Value
  391.  
  392.     =====            =========
  393.  
  394.  
  395.  
  396.     110 bps          >400 + >238
  397.  
  398.     300 bps          >400 + >0D0
  399.  
  400.     600 bps                 >341
  401.  
  402.    1200 bps                 >1A1
  403.  
  404.    2400 bps                 >0D0
  405.  
  406.    4800 bps                 >068
  407.  
  408.    9600 bps                 >034
  409.  
  410.  
  411.  
  412. (Note the >400 is the divide by 8
  413. counter enable. If you need an oddball
  414. baud rate, the formula is below:
  415.  
  416.  
  417.  
  418.  
  419.  
  420.  
  421.  
  422.     F     =      Fint (1 MHz)
  423.  
  424.             --------------------------
  425.      bps      2 * (D9-D0) * (8 D10)
  426.  
  427.  
  428. where D9-D0 is from 0 to 1023 and D10 is
  429. the divide by eight counter.)
  430.  
  431.  
  432.  
  433.  The Interval Register. The Interval
  434. register is a 8-bit counter which is
  435. decremented every 64 clock cycles. When
  436. the interval counter reches zero, the
  437. appropraite interval register flags are
  438. set and if interval interrups have been
  439. enables the 9902 will generate an
  440. interrupt. Taking into account the
  441. register size the interval counter has
  442. resolution from 64 to 16,320
  443. microseconds in 64 microsecond
  444. increments.
  445.  
  446.  Programming The TMS9902. This seems
  447. like an awful lot of stuff to swallow in
  448. order to program the 9902 but in reality
  449. a lot of the nasty things are done for
  450. you by the chip, so now lets look at
  451. some code examples, but first we need to
  452. know something about the way the 9902 is
  453. addressed in the /4A environment.
  454.  
  455. Most of you who have gotten the
  456. disassembly listing of the RS232 DSR
  457. know that the DSR code is at CRU address
  458. >1300. The 9902 themselves are at +>40
  459. for the first 9902 and the second is at
  460. +>80, so the values used for 9902
  461. accesses are >1340 and >1380. If you
  462. have the additonal RS232 card its CRU
  463. offset is >1500 and the 9902s are also
  464. +>40 and >+80. Its suggested that when
  465. you code your routines you have a
  466. subroutne which sets up the base address
  467. to turn the DSR on and then adjusts R12
  468. to access the proper 9902.
  469.  
  470.  Interrupts in the RS232 DSR. Tracing
  471. thru the disassembly listing reveals
  472. that during an interrupt request from
  473. the RS232 DSR it determines the device
  474. which fired the interrupt and determines
  475. if a character was received. If a
  476. character was not received it RESETS the
  477. 9902--so be careful how you program
  478. the 9902 in the /4A environment. As a
  479. side benefit tho, if you use interrupts
  480. the DSR provides you with a mechanism of
  481. getting incoming characters and
  482. buffering them. Carefully trace the
  483. interrupt code and you'll find that
  484. >8300 contains a VDP address and >8302
  485. an >8304 are pointers that are
  486. manipulated to place characters into a
  487. queue in VDR RAM.
  488.  
  489.  Example. To give you an idea of what
  490. goes on with the 9902, Assembly source
  491. code is being provided that shows how
  492. the 9902 is initialized and how
  493. characters are transmitted and received.
  494. The program is the infamous T99 dumb
  495.  
  496. terminal emulator I wrote over a year
  497. ago that uses the first RS232 port for
  498. a modem running at 300 baud, 1 stop bit
  499. and even parity with a printer attached
  500. off of port 2 running at 9600 bps at odd
  501. parity and 1 stop bit. The printer is
  502. turned on by receipr of a control R and
  503. is shut off by receipt of a control T.
  504. This code also shows you some of the
  505. things that are involved in writing a
  506. terminal emulator and can serve as a
  507. basis for writing more powerful
  508. emulators. (the T99 source code can be
  509. found in DL2 in the file T99.ASM.)
  510.  
  511.  Summary. There is still a lot of things
  512. that we didn't cover in regards to the
  513. 9902 but with the information we have
  514. provided here you should be in a good
  515. postion to do some exploring on your
  516. own; such as using one or two of the
  517. control lines to hook up with modems
  518. that provide auto-answer/auto-dial
  519. capabilites and write a assembly program
  520. to get you those features. The rest is
  521. up to you and your imagination!
  522.  
  523. Download complete.  Turn off Capture File.
  524.  
  525.  
  526.