Serial Port I/O

17.13 Serial Port I/O

In addition to the SPI communication protocol that was presented earlier in this manual, the more basic serial port I/O was also implemented in this simulator. Serial Ports 0 and 1 are simulated in this package. An example of this commu- nication protocol has been used a couple of times in this section of the manual. The show_baud_gen ( ) subroutine is used to set up the output display of pro- gramming example results on the Serial #1 window. The show_baud_gen ( ) subroutine is described following.

Parallel port P3 is set so that P3.0 is an input pin, and P3.1 is an output pin. Referring to the chapter on Parallel ports will reveal that port pins 0 and 1 are also alternate pins for Serial Port 0 receive and Serial Port 0 transmit, respec- tively, for Serial Port 0 in either modes 1, 2, or 3. In Serial Port Mode 0, P3.0 is the bidirectional data transfer pin for Serial Port 0, and P3.1 emits the syn- chronizing clock for serial port 0 communication.

The Timer 2 timer overflow flag is cleared, in order to remove any preexisting Timer 2 interrupt request. The Timer 2 external input is also set to 0. Timer 2 in baud rate generation mode generates the data communication baud rate. On the basis of the fOSC divide-by-4 selection made by setting the Timer 2 Clock Select bit (bit T2M of the CKCON SFR) and the oscillator clock frequency, the auto-reload value for the Timer 2 Capture pair, RCAP2H:RCAP2L (RCAP2), required to produce a baud rate of 37 500bps was computed to be 0xFFC4. Presetting the Timer 2 register pair TH2:TL2 (THL2) to 0xFFFF ensures that Timer 2 generates an overflow on the first fOSC divide-by-4 clock. This automatically generates an overflow pulse, which is further divided by 16 to drive the Rx and/or Tx clocks. In addition, upon overflow, the contents of the RCAP2 register pair are automatically transferred into the THL2 register pair, which would have just rolled over to 0x0000. Note that in this mode, Timer 2 does not generate an overflow interrupt signal. Please refer to Section 8.5, Timer 2, for more information.

The timer overflow pulse for Timer 2 is used to generate baud rate clock for the transmit block, and Timer 1 overflow is used for the receive block. Setting the Timer 2 run control bit through T2CON also enables the Timer 2 clock. For this operation, the following options were selected for Timer 2: auto-reload, timer option, specify timer overflow pulse as baud rate clock for the transmit block and not for the receive block, and specify the option to ignore all external events on the T2EX (P1.1) pin.

The bit pattern for the previous specifications requires that TCON2 be as- signed a value of 0x14.

For the serial communication, Serial Port 0 was set for an asynchronous 10-bit (1 start bit, 8 data bits and one stop bit) mode 1, serial data communication operation. The serial port 0 is also receive enabled. These were accomplished by setting the SCON0 SFR to 0x50.

The baud rate doubling option 16X was selected by setting the SMOD0 bit of the PCON SFR.

17-40

Page 268
Image 268
Texas Instruments MSC1210 manual Serial Port I/O