Professional Documents
Culture Documents
Serial Communication
(UART),
https://www.youtube.com/watch?v=WKcn__hxUz4
Serial I/O
Serial communication
Transmit Data (TxD), Receive Data (RxD), and Signal Ground
(SG) implement duplex communication link
Both communicating devices must operate at the same bit
rate
Least significant bit sent first
Simplex
Half duplex
Full duplex
2
1
eUSCI : Enhanced Universal Serial Communication Interface
UART OVERVIEW
Block diagram of the
eUCSI_Ax module
configured for UART
mode (UCSYNC bit D0)
[slau208g]. Illustration
used with permission of
Texas Instruments
www.ti.com.
15 – 0
0x40001006 UCBRx UCAxBRW
15 – 8 7–4 3–1 0
0x40001008 BRSx BRFx UCOS16 UCAxMCTLW
7 6 5 4 3 2 1 0
0x4000100A LISTEN FE OE PE BRK RXERR IDLE BUSY UCAxSTATW
15 – 8 7–0
0x4000100C RXBUFx UCAxRXBUF
15 – 8 7–0
0x4000100E TXBUFx UCAxTXBUF
15 – 4 3 2 1 0
0x4000101A TXCPTIE STTIE TXIE RXIE UCAxIE
15 – 4 3 2 1 0
0x4000101C TXCPTIFG STTIFG TXIFG RXIFG UCAxIFG
2
UART ports.
...
static consteUSCI_UART_ConfiguartConfig=
{
EUSCI_A_UART_CLOCKSOURCE_SMCLK, // SMCLK Clock Source
39, // BRDIV = 39 , integral part
1, // UCxBRF= 1 , fractional part * 16
0, // UCxBRS= 0
EUSCI_A_UART_NO_PARITY, // No Parity
EUSCI_A_UART_LSB_FIRST, // LSB First
EUSCI_A_UART_ONE_STOP_BIT, // One stop bit
EUSCI_A_UART_MODE, // UART mode
EUSCI_A_UART_OVERSAMPLING_BAUDRATE_GENERATION}; // Oversampling Mode
GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P1,
GPIO_PIN2 | GPIO_PIN3, GPIO_PRIMARY_MODULE_FUNCTION ); //Configure CPU signals
UART_initModule(EUSCI_A0_BASE, &uartConfig); // Configuring UART Module A0
UART_enableModule(EUSCI_A0_BASE); // Enable UART module A0
UART_transmitData(EUSCI_A0_BASE,'a’); // Write character ‘a’ to UART
3
Replacing UART_transmitData(EUSCI_A0_BASE,'a') by a direct access to
registers:
declare pointers to
... UART configuration
volatile uint16_t* uca0ifg = (uint16_t*) 0x4000101C; registers
volatile uint16_t* uca0txbuf = (uint16_t*) 0x4000100E;
...
// Initialization of UART as before
... wait until transmit
buffer is empty
while ( !((*uca0ifg >> 1) & 0x0001) );
11
12
4
RS-232 Serial Port
Send/receive a frame of (5-8) data bits with a single (start) bit prefix and a 1 or
2 (stop) bit suffix
Baud rate is total number of bits per unit time
Baudrate = 1 / bit-time
Bandwidth is data per unit time
Bandwidth = (data-bits / frame-bits) * baudrate
14
15
5
UART - Transmitter
Tx Operation
Data written to UCA0TXBUF
Shift clock is generated from 16x clock
permits differences in Tx and Rx clocks to be reconciled
16
UART - Transmitter
Stop 7 6 5 4 3 2 1 0 Start
Shift 1 Data 0 P1.3/UCA0TXD
clock
Transmit shift register
Write data UCA0TXBUF
UCTXIFG 1 means
Transmit data register TXBUF empty
17
UART - Receiver
Rx Operation
UCRXIFG is 1 when data are available
entries have four control bits
BRK set when Tx signal held low for more than one frame
(break)
OE set when FIFO is full and new frame has arrived
PE set if frame parity error
FE set if stop bit timing error
18
6
UART - Receiver
Stop 7 6 5 4 3 2 1 0 Start
Shift 1 Data 0 P1.2/UCA0RXD
clock Receive shift register
FE OE PE BRK RXERR
UCRXIFG 1 means data
Read data UCA0RXBUF
in RXBUF
Receive data register
InChar UCRXIFG
UART Synchronization
Busy-wait operation
InChar OutChar
Empty Busy
0
UCRXIFG 0
UCTXIFG
1 Not empty 1 Idle
return return
20
21
7
UART Interrupts
22
INPUT
OUTPUT
23
24
8
I/O Sync Options (3)
What to do while the peripheral is BUSY?
INTERRUPT/TRANSFER
Hardware INTERRUPTS processor on condition of READY/NOT BUSY
Facilitates performing other – background - processing between I/O
transfers
Processor changes context when current transfer complete
Requires program structure to process context change
25
UART Setup
26
AnalogReadSerial
27
9
SERIAL PERIPHERAL INTERFACE-SPI
8-bits transferred in each direction every time
Master generates clock
MOSI: “Master Out Slave In”; MISO: “Master In Slave Out”
Connect MOSI to MOSI and MISO to MISO
Slave Select (SS) used to select one of many slaves
Terminology varies:
Instead of SS, “Chip Select” (CS)
Instead of MOSI and MISO, SIMOD and SOMI
28
SPI timing diagram when the data is read on a rising clock edge.
29
10
SERIAL PERIPHERAL INTERFACE-SPI
31
33
11
Serial data format
34
Byte transfer
Multi-byte transfers
• first byte contains address of receiver
• all devices check address to determine if following data is for them
• second byte usually contains address of sender
35
36
12
MSP432 SPI
the MSP432 provides support for SPI communication in both of the eUSCI_A and eUSCI_B
modules.
13