 Chapter 1 Hardware Structure
by the UART. Clearing the TXEN bit during a transmission will cause the transmission to be
aborted and will reset the transmitter. If this occurs, the TX pin can be used as a general purpose
I/O pin.
Baud Rate Generator
To setup the speed of the serial data communication, the UART function contains its own dedi-
cated baud rate generator. The baud rate is controlled by its own internal free running 8-bit timer,
the period of which is determined by two factors. The first of these is the value placed in the BRG
register and the second is the value of the BRGH bit within the UCR2 control register. The BRGH
bit decides, if the baud rate generator is to be used in a high speed mode or low speed mode,
which in turn determines the formula that is used to calculate the baud rate. The value in the BRG
register determines the division factor, N, which is used in the following baud rate calculation for-
mula. Note that N is the decimal value placed in the BRG register and has a range of between 0
and 255.
UCR2 BRGH Bit
Baud Rate
0
1
f
SYS
[64 (N + 1)]
f
SYS
[16 (N + 1)]
By programming the BRGH bit which allows selection of the related formula and programming the
required value in the BRG register, the required baud rate can be setup. Note that because the ac-
tual baud rate is determined using a discrete value, N, placed in the BRG register, there will be an
error associated between the actual and requested value. The following example shows how the
BRG register value N and the error value can be calculated.
Calculating the Register and Error Values
For a clock frequency of 8MHz, and with BRGH set to
²0²,
determine the BRG register value N, the
actual baud rate and the error value for a desired baud rate of 9600.
From the above table the desired baud rate BR =
f
SYS
[64 (N + 1)]
Re-arranging this equation gives N =
f
SYS
-1
(BRx64)
Giving a value for N =
8000000
-1
= 12.0208
(9600x64)
To obtain the closest value, a decimal value of 12 should be placed into the BRG register. This
gives an actual or calculated baud rate value of
BR =
8000000
= 9615
[64(12 + 1)]
9615
-
9600
= 0.16%
9600
Therefore the error is equal to
91
Pages: Home Index