Mode 2 and 3, Application: serial port initialization – Maxim Integrated Secure Microcontroller User Manual

Page 125

Advertising
background image

Secure Microcontroller User’s Guide

125 of 187

Mode 2 and 3

For Mode 1 operation, the baud rate generator clock is the Timer 1 Overflow output as described for
Mode 1. Transmission and reception takes place for Modes 2 and 3 as described except as noted below.

In Mode 2 and 3, the asynchronous serial data word is 11 bits long, including one start bit, eight data bits,
a programmable 9th data bit, and one stop bit. For Mode 2, the baud rate generator clock divides the clock
oscillator frequency (f

CLK

) by either f

CLK

/32 (SMOD = 1) or f

CLK

/64 (SMOD = 0).


When the Transmit Shift register is written in Mode 2, the register is simultaneously written with a 0 in
bit position D0 for a Start bit and a 1 is written into D10 for a Stop bit. D9 is the programmable bit that is
written with the state of TB8 (SCON.3). TB8 can be written with the value of 1 or 0 by software.

On receive, the eight data bits are shifted into the Receive Shift register following a valid Start bit. After
the Stop bit has been detected, the Receive Data Buffer will be loaded with the contents of the Receive
Shift register if RI = 0 and SM2 = 0. Also at this time, the programmable 9th data bit will be loaded into
RB8 in the SCON register. If RI = 1 after the time the Stop bit is sampled, the incoming word will be lost.

The SM2 flag may be used in the implementation of a multiprocessor communication scheme by
selectively discarding incoming serial data words according to the state of the programmable 9th data bit.
When SM2=1, only those words in which this 9th bit is a 1 will be loaded into the Receive Data Buffer
and cause a serial interrupt to be generated. Thus, the programmable 9th bit can be used to flag an
incoming data character as an address field as opposed to a data field, for example.

Application: Serial Port Initialization

This example demonstrates how to initialize the serial port and includes an example showing how to
perform asynchronous communication with a PC COM port.

A typical goal of microcontroller to PC communication is to transfer stored data from the nonvolatile
RAM. This example will show how to move 256 bytes from NV RAM to the PC via the serial port. Once
the PC receives the 256 bytes, it sends confirmation. For this example, the confirmation code is A5h. The
microcontroller runs at 11.0592MHz, a common crystal choice. This example demonstrates both 9600bps
and 19,200bps. This code therefore runs at 8N1 or 8 bits, no parity, 1 stop bit. This is a common selection
for PC terminal emulator software. The setup summary is as follows:

Communication type:

Asynchronous

Baud Rate:

9600, 19200

Bits per word:

8

Stop bits:

1

Table 14-C

shows this most closely corresponds to serial mode 1.

Advertising