
Rev. 1.00
144
October 26, 2018
Rev. 1.00
145
October 26, 2018
BS86DH12C
High Voltage Touch A/D Flash MCU with HVIO
BS86DH12C
High Voltage Touch A/D Flash MCU with HVIO
Baud Rate Generator
To set the speed of the serial data communication, the UART function contains its own dedicated
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 baud rate
register BRG and the second is the value of the BRGH bit with the control register UCR2. 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 N in the BRG
register which is used in the following baud rate calculation formula determines the division factor.
Note that N is the decimal value placed in the BRG register and has a range of between 0 and 255.
UCR2 BRGH Bit
0
1
Baud Rate (BR)
f
H
/[64 (N+1)]
f
H
/[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 set. Note that because the actual
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 Baud Rate and Error Values
For a clock frequency of 4MHz, and with BRGH cleared to zero determine the BRG register value N,
the actual baud rate and the error value for a desired baud rate of 4800.
From the above table the desired baud rate BR=f
H
/[64(N+1)]
Re-arranging this equation gives N=[f
H
/(BR×64)] - 1
Giving a value for N=[4000000/(4800×64)] - 1=12.0208
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=4000000/[64×(12+1)]=4808
Therefore the error is equal to (4808 - 4800)/4800=0.16%
UART Setup and Control
For data transfer, the UART function utilizes a non-return-to-zero, more commonly known as NRZ,
format. This is composed of one start bit, eight or nine data bits, and one or two stop bits. Parity is
supported by the UART hardware, and can be set to be even, odd or no parity. For the most common
data format, 8 data bits along with no parity and one stop bit, denoted as 8, N, 1, is used as the
default setting, which is the setting at power-on. The number of data bits and stop bits, along with
the parity, are set by programming the corresponding BNO, PRT, PREN, and STOPS bits in the
UCR1 register. The baud rate used to transmit and receive data is set using the internal 8-bit baud
rate generator, while the data is transmitted and received LSB first. Although the UART transmitter
and receiver are functionally independent, they both use the same data format and baud rate. In all
cases stop bits will be used for data transmission.
Enabling/Disabling the UART Interface
The basic on/off function of the internal UART function is controlled using the UARTEN bit in the
UCR1 register. If the UARTEN, TXEN and RXEN bits are set, then these two UART pins will act
as normal TX output pin and RX input pin respectively. If no data is being transmitted on the TX
pin, then it will default to a logic high value.
Clearing the UARTEN bit will disable the TX and RX pins and allow these two pins to be in a
floating state. When the UART function is disabled the buffer will be reset to an empty condition, at
the same time discarding any remaining residual data. Disabling the UART will also reset the error