MSP432 Chapter4 UART
MSP432 Chapter4 UART
1
Serial vs. Parallel Data Transfer
2
• Serial data communication uses two methods,
asynchronous and synchronous.
• With synchronous communication, the clock is transmitted
alongside with the data.
• With asynchronous communication, no clock is transmitted.
• The transmitter and receiver agree on a clock speed for data
transmission. They may have slight speed differences so the
receiver will try to synchronize the clock to the incoming
data for every character received.
3
• The synchronous method usually transfers a block of data (characters) at
a time while the asynchronous transfers a single byte at a time.
• It is possible to write software to use either of these methods, but the
programs can be tedious and inefficient. For this reason, special IC chips
are made by many manufacturers for serial data communications.
• These chips are commonly referred to as UART (universal asynchronous
receiver transmitter) and USART (universal synchronous-asynchronous
receiver-transmitter).
• The COM port in the PC uses a UART. When this function is incorporated
into a microcontroller, it is often referred to as SCI (Serial Communication
Interface).
4
Parallel In – Serial Out
5
Serial In – Parallel Out
6
Simplex, Half-, and Full-Duplex Data Transmission methods
7
Classification of Data Comm (Data Terminal
Equipment PC – Data Communication Equipment
MODEM)
8
Framing ASCII "A" (0x41)
9
Data Transfer Rate
• The rate of data transfer in serial data communication is specified in
bps (bits per second). Another often used term for bps is Baud rate.
• However, the baud and bps rates are not necessarily equal.
• This is due to the fact that baud rate is defined as the number of signal
changes per second. In modems, it is possible for each signal to
transfer multiple bits of data.
• As far as the unmodulated signal is concerned, the baud rate and bps
are the same
10
RS232 to TTL Conversion
MAX232
11
MAX232 IC (RS232 Serial to TTL Converter)
12
RS232 DB9 Connector Pins
Pin Description
1 Data carrier detect (DCD)
2 Received data (RxD)
3 Transmitted data (TxD)
4 Data terminal ready (DTR)
5 Signal ground (GND)
6 Data set ready (DSR)
7 Request to send (RTS)
8 Clear to send (CTS)
9 Ring indicator (RI)
13
• DTR (data terminal ready): When the terminal (or a PC COM
port) is turned on, after going through a self-test, it sends out a
signal DTR to indicate that it is ready for communication.
• DSR (data set ready): When a DCE (modem) is turned on and
has gone through the self-test, it asserts DSR to indicate that it is
ready to communicate.
• RTS (request to send): When the DTE device (such as a PC) has
a byte to transmit, it asserts RTS to signal the modem that it has a
byte of data to transmit.
14
• CTS (clear to send): In response to RTS, when the modem has
room for storing the data it is to receive, it sends out signal CTS to
the DTE (PC) to indicate that it can receive the data now.
• CD (carrier detect, or DCD, data carrier detect): The modem
asserts signal DCD to inform the DTE (PC) that a valid carrier has
been detected and that contact between it and the other modem is
established.
• RI (ring indicator): An output from the modem (DCE) and an
input to a PC (DTE) indicates that the telephone is ringing.
15
PC- Modem Communication
• While signals DTR and DSR are used by the PC and modem, - to
indicate that they are alive, it is RTS and CTS that actually control
the flow of data.
• When the PC wants to send data it asserts RTS, and in response, if
the modem is ready to accept the data, it sends back CTS.
• If Modem is not ready, the modem does not activate CTS, the PC
will de-assert DTR and try again.
16
Programming the UART Ports
17
18
MSP432 LaunchPad board
19
XDS110-ET emulator USB Port
20
Partial list of UART0 Registers and their
addresses
Register
Register Name Register Function
Address
UCA0CTLW0 Control Word 0 4000_1000
UCA0BRW Baud Rate Control Word 4000_1006
UCA0STATW Status 4000_100A
UCA0RXBUF Receive Buffer 4000_100C
UCA0TXBUF Transfer Buffer 4000_100E
UCA0IFG Interrupt Flag 4000_101C
21
A Simplified Block Diagram of UART
22
Clock Circuit of UART0
23
UART pins in MSP432
24
PxSEL1 and PxSEL0 Alternate Function
Selection registers (P1.3 & P1.2)
25
Alternate Function Selection - UARTs
I/O pin Function PxSEL1=0 PxSEL0=1
P1.2 UCA0RXD P1SEL1=00000000 P1SEL0=00000100
P1.3 UCA0TXD P1SEL1=00000000 P1SEL0=00001000
FOR UART0: P1SEL1=0x00 P1SEL0=00001100=0x0C
P2.2 UCA1RXD P2SEL1=00000000 P2SEL0=00000100
P2.3 UCA1TXD P2SEL1=00000000 P2SEL0=00001000
For UART1 P2SEL1=0x00 P2SEL0=00001100=0x0C
P3.2 UCA2RXD P3SEL1=00000000 P3SEL0=00000100
P3.3 UCA2TXD P3SEL1=00000000 P3SEL0=00001000
For UART2 P3SEL1=0x00 P3SEL0=00001100=0x0C
P9.6 UCA3RXD P9SEL1=00000000 P9SEL0=01000000
P9.7 UCA3TXD P9SEL1=00000000 P9SEL0=10000000
For UART3 P9SEL1=0x00 P9SEL0=11000000=0xC0
0 0
UART Control Word 0 (UCAxCTLW0) register
Field Bit Description
00b = UCLK
01b = ACLK
UCSSELx D7:6
10b = SMCLK
11b = SMCLK
0b = Erroneous characters rejected and UCRXIFG is not set.
UCRXEIE D5
1b = Erroneous characters received set UCRXIFG.
0b = Received break characters do not set UCRXIFG.
UCBRKIE D4
1b = Received break characters set UCRXIFG.
0b = Not dormant. All received characters set UCRXIFG.
1b = Dormant. Only characters that are preceded by an idle-line or
UCDORM D3 with address bit set UCRXIFG. In UART mode with automatic
baud-rate detection, only the combination of a break and synch
field sets UCRXIFG.
0b = Next frame transmitted is data.
UCTXADDR D2
1b = Next frame transmitted is an address.
0b = Next frame transmitted is not a break.
UCTXBRK D1
1b = Next frame transmitted is a break or a break/synch.
0b = Disabled. eUSCI_A reset released for operation.
UCSWRST D0
1b = Enabled. eUSCI_A logic held in reset state.
EUSCI_A0->CTLW0 = 0x0081 1 0 0 0 0 0 0 1 28
8 1
UART Control Word 1(UCAxCTLW1) register
29
Clock Circuit Modes
30
UCAxMCTLW ModulationCTLW
(UCOS16 = 0 Low Freq. BR Mode)
31
UCAxBRW
33
UART Status Register (UCAxSTATW)
36
void UART0_init(void)
{
EUSCI_A0->CTLW0 |= 1; /* put in reset mode for
#include "msp.h" config */
EUSCI_A0->MCTLW = 0; /* disable oversampling
void UART0_init(void); */
void delayMs(int n); EUSCI_A0->CTLW0 = 0x0081; /* 1 stop bit, no parity,
SMCLK, 8-bit data */
int main(void) { EUSCI_A0->BRW = 26; /* 3,000,000 / 115200 =
UART0_init(); 26 */
while (1) { P1->SEL0 |= 0x0C; /* P1.3, P1.2 for UART */
while(!(EUSCI_A0->IFG & 0x02)) { } /* wait for P1->SEL1 &= ~0x0C;
transmit buffer empty */ EUSCI_A0->CTLW0 &= ~1; /* take UART out of
EUSCI_A0->TXBUF = 'Y'; /* send a char */ reset mode */
while(!(EUSCI_A0->IFG & 0x02)) { } }
EUSCI_A0->TXBUF = 'e'; /* send a char */
while(!(EUSCI_A0->IFG & 0x02)) { } /* delay milliseconds when system clock is at 3 MHz */
EUSCI_A0->TXBUF = 's'; /* send a char */ void delayMs(int n) {
delayMs(2); /* leave a gap between int i, j;
messages */
} for (j = 0; j < n; j++)
} for (i = 750; i > 0; i--); /* Delay */
37