You are on page 1of 25

System Design and Applications for

IoT
Unit3: Cortex-M Peripheral Interface
Session 6 : UART(Universal Asynchronous Receivers and
Transmitters )
Topic
• UART Introduction.
• Features of UART.
• DATA Transmitter.
• UART Mode.
• Control Register.
• DTE and DCE Connections.
• Sample code.

Company Confidential www.industry-mitra.com 2


UART Introduction
• The Universal Asynchronous Receivers and
Transmitters (UARTs) provide asynchronous serial
data communications for MCU- and UART-compatible
devices.
• The UART is very similar to SSI in working principle
and structure, but the only difference is that the former
belongs to the asynchronous communications and the
latter is the synchronous SCI.

Company Confidential www.industry-mitra.com 3


UART Introduction
• The UART performs the parallel-to-serial
functions in the transmitting mode and serial-to-
parallel conversions in the receiving mode. It is
very similar in functionality to a popular UART,
but is not register compatible with any UART.

Company Confidential www.industry-mitra.com 4


UART Features
• Programmable baud rate generator
• Automatic generation and stripping of start, stop,
and parity bits
• Line-break generation and detection
• Separate transmit and receive buffer registers and
shift registers
• LSB-first or MSB-first data transmit and receive
• Programmable serial interface with
-7 or 8 data bits with even, odd, or no parity bit
-generation and detection
- 1 or 2 stop bits generation
• Company
Baud rate generation,
Confidential
from 0 to processor clock/16
www.industry-mitra.com 5
Asynchronous serial communication
protocols
• Unlike SPI, in which both transmitter and receiver use
the same clock rate as the data operation timing base
to ensure both master and slave transmit and receive
data correctly.
• In asynchronous serial data communications, the
transmitter and receiver use its own clock as the
timing base, and therefore the predefined data
communication protocols and data framing are
necessary to make this kind of data transmitting and
receiving successful.

Company Confidential www.industry-mitra.com 6


DATA Transmitter

1. A logic high is appeared on the communication line


when the transmission line is idle.
2. A high-to-low transaction starts an asynchronously
data communication.
3. The data can be 7- or 8-bit long attached with 0 or
1 parity bit and 1 or 2 stop bits.

Company Confidential www.industry-mitra.com 7


DATA Transmitter
• The MSP432P401R MCU system uses eUSCI_A
module to provide four UART modules
(eUSCI_A0~eUSCI_A3), and each module can work
independently to perform asynchronous serial data
communications.
• Each module can be programmed to transmit (TX)
and receive (RX) data by using the different baud
rates and each module can be driven by using the
different system System Clock sources, such as
UC0CLK, ACLK, and SMCLK.

Company Confidential www.industry-mitra.com 8


UART Mode
• UART mode comprises four components:
• UART data transmit control
• UART data receive control
• UART clock selection (CKSL) and bit rate
generation control UART interrupt mechanism
control

Company Confidential www.industry-mitra.com 9


UART Interrupt Mechanism Controls
1. Start interrupt
2. Transmit interrupt
3. Receive interrupt
4. Transmit complete interrupt

Company Confidential www.industry-mitra.com 10


Control Register
• All registers can be divided into the following
four groups:
1. UART control and status registers
2. UART baud rate generation and control registers
3. UART data transmit and receive registers
4. UART interrupt processing registers

Company Confidential www.industry-mitra.com 11


UART control and status registers
• Three registers are involved in this group:

1. The eUSCI_Ax Control Word Register 0


(UCAxCTLW0)
2. The eUSCI_Ax Control Word Register 1
(UCAxCTLW1)
3. The eUSCI_Ax Status (UCAxSTATW) register

Company Confidential www.industry-mitra.com 12


UART data transmit and receive
registers
• Two registers are involved in this group:
1. The eUSCI_Ax Transmit Buffer Register (UCAxTXBUF)
2. The eUSCI_Ax Receive Buffer Register
(UCAxRXBUF)
• The UCAxTXBUF register is a 16-bit register but only the
lower 8 bits are used to temporarily hold the data byte to
be transmitted to the receiver. Similarly, the UCAxRXBUF
register is also a 16-bit register with lower 8 bits being
used to hold the received data byte from the transmitter.
• The data transmit will not start until a valid data byte is
written into the UCAxTXBUF register. Similarly, the data
receiving will not start until a valid data byte has been
received in the UCAxRXBUF register.
Company Confidential www.industry-mitra.com 13
UART interrupt processing registers
• Three registers are involved in this group:
1. The eUSCI_Ax Interrupt Enable Register (UCAxIE)
2. The eUSCI_Ax Interrupt Flag Register (UCAxIFG)
3. The eUSCI_Ax Interrupt Vector Register (UCAxIV)

• The UCAxIE register is used to enable or disable


four UART-related interrupt sources.
• This is a 16-bit register but only the lower 4 bits are
used to enable (bit value = 1) or disable (bit value =
0) four UART-related interrupt sources

Company Confidential www.industry-mitra.com 14


Operational procedure of UART
• The operation procedure of a UART can be
divided into the following sections:
• The UART initialization and configuration
• The UART baud rate generation
• The UART transmit enable and data transmit
operation
• The UART receive enable and data receive
operation The UART errors detection

Company Confidential www.industry-mitra.com 15


UART initialization and configuration
• Generally, the following operations should be
performed to initialize and configure an
eUSCI_A module for the UART mode:

Company Confidential www.industry-mitra.com 16


UART baud rate generation
• Since the eUSCI_A baud rate generator can
generate standard baud rates from nonstandard
source frequencies, therefore two possible
modes may be used to calculate the correct
baud rate and this makes the situation a little
complicated.
• For a selected BRCLK CKSE, first a division
factor N should be determined based on the
following equation:
• N = fBRCLK/Baud rate

Company Confidential www.industry-mitra.com 17


UART Errors Detection
• The eUSCI_A module can automatically detect the
following errors when receiving characters:
• Framing errors
• Parity errors
• Overrun errors
• Break conditions
• The error flag bits UCFE, UCPE, UCOE, and UCBRK
in the UCAxSTATW register are set when their
respective condition is detected.
• When the error flags UCFE, UCPE, or UCOE are set,
the UCRXERR bit in the UCAxSTATW register is also
set.
Company Confidential www.industry-mitra.com 18
UART serial communication mode
• A UART can work as a modem to provide the
interface between a computer and a serial
asynchronous device.
• A computer can also be considered as UART device
when it is connected as data terminal equipment
(DTE) and a model can be considered a data
communication equipment (DCE).
• In general, a modem is a DCE and a computing
device that connects to a modem is a DTE.

Company Confidential www.industry-mitra.com 19


DTE and DCE connections.

Company Confidential www.industry-mitra.com 20


MSP432 Two UART ports

Company Confidential www.industry-mitra.com 21


MSP432-PIN7/PIN98/PIN99

Company Confidential www.industry-mitra.com 22


SAMPLE CODE

Company Confidential www.industry-mitra.com 23


Illustration of UART

Company Confidential www.industry-mitra.com 24


Thank You

Company Confidential www.industry-mitra.com 25

You might also like