UART
UART
By Christopher Mar
UART on PLP Board Demo
Available in Video Lecture
2
PLPTool Interface
Simulates external UART device connected to PLP UART
UART
Universal Asynchronous Receiver/Transmitter
Used for serial communication
At most one wire per direction of data
Sent sequentially one bit at a time
UART
Other common serial interfaces include:
USB
SATA
RS-232
SPI
I2C
ASCII
Computers only “understand” binary so how are characters represented?
ASCII character encodings
American Standard Code of Information Interchange
ASCII
Each character is represented by 7-bit value
Character Decimal Value Hex Value
‘A’ 65 0x41
‘Z’ 90 0x5A
‘a’ 97 0x61
‘z’ 122 0x7A
‘.’ (Period) 46 0x2E
‘ ’ (Space) 32 0x20
The 8th bit can be used for parity checking, but this isn’t a requirement of ASCII
Lecture Question
What value would be used to encode the character, ‘B’?
65
0x65
66
0x66
98
Character Strings
Sequence of characters
Null terminated string ends with a null character (‘\0’)
Has an ASCII value of zero
Terminating character can be any character agreed upon by sender and receiver
I/O Device: UART
I/O Device: UART
I/O Device: UART
I/O Device: UART
I/O Device: UART
UART Registers
Command register (0xf0000000)
Write-only
Bit at 21 position: clear status bit
Used to indicate to UART that your program has read current byte
Status register (0xf0000004)
Read-only
Bit at 21 position: ready bit
Indicates a byte has been received by the UART
UART Buffers
Receive buffer (0xf0000008)
Read-only
Contains most recent byte received by UART
Send buffer (0xf000000c)
Not used in Project 3
Lecture Question
The status register is a read-only location so what instruction would you use to interact with it?
store word
load word
move
copy
Polling
Also called busy waiting
Loop waiting for an I/O device status to change to a specific condition
Exit loop when condition is met
Poll UART ready bit waiting for new character
Lecture Question
Polling requires either a beq or bne?
True
False
I/O Device: UART
External Device
UART
(PLPTool GUI UART)
RX
TX
TX
RX
Command Register
Status Register: 0b01
Receive Buffer: 0x00
PLP
CPU
PLP UART
polling
I/O Device: UART
External Device
UART
(PLPTool GUI UART)
RX
TX
PLP UART
TX
RX
Command Register
Status Register: 0b01
Receive Buffer: 0x00
PLP
CPU
Send buffer:
a
D
.
polling
I/O Device: UART
External Device
UART
(PLPTool GUI UART)
RX
TX
TX
RX
Command Register
Status Register: 0b01
Receive Buffer: 0x61
PLP
CPU
Send buffer:
D
.
PLP UART
polling
I/O Device: UART
External Device
UART
(PLPTool GUI UART)
RX
TX
TX
RX
Command Register
Status Register: 0b11
Receive Buffer: 0x61
PLP
CPU
Send buffer:
D
.
PLP UART
polling
I/O Device: UART
External Device
UART
(PLPTool GUI UART)
RX
TX
TX
RX
Command Register
Status Register: 0b11
Receive Buffer: 0x61
PLP
CPU
Send buffer:
D
.
0x61
PLP UART
I/O Device: UART
External Device
UART
(PLPTool GUI UART)
RX
TX
TX
RX
Command Register
Status Register: 0b11
Receive Buffer: 0x61
PLP
CPU
Send buffer:
D
.
0b10
PLP UART
I/O Device: UART
External Device
UART
(PLPTool GUI UART)
RX
TX
TX
RX
Command Register
Status Register: 0b01
Receive Buffer: 0x61
PLP
CPU
Send buffer:
D
.
0b10
PLP UART
I/O Device: UART
External Device
UART
(PLPTool GUI UART)
RX
TX
TX
RX
Command Register
Status Register: 0b01
Receive Buffer: 0x61
PLP
CPU
Send buffer:
D
.
0b10
PLP UART
I/O Device: UART
External Device
UART
(PLPTool GUI UART)
RX
TX
TX
RX
Command Register
Status Register: 0b01
Receive Buffer: 0x44
PLP
CPU
Send buffer:
.
PLP UART
polling
I/O Device: UART
External Device
UART
(PLPTool GUI UART)
RX
TX
TX
RX
Command Register
Status Register: 0b11
Receive Buffer: 0x44
PLP
CPU
Send buffer:
.
PLP UART
polling
I/O Device: UART
External Device
UART
(PLPTool GUI UART)
RX
TX
TX
RX
Command Register
Status Register: 0b11
Receive Buffer: 0x44
PLP
CPU
Send buffer:
.
0x44
PLP UART
I/O Device: UART
External Device
UART
(PLPTool GUI UART)
RX
TX
TX
RX
Command Register
Status Register: 0b11
Receive Buffer: 0x44
PLP
CPU
Send buffer:
.
0b10
PLP UART
I/O Device: UART
External Device
UART
(PLPTool GUI UART)
RX
TX
TX
RX
Command Register
Status Register: 0b01
Receive Buffer: 0x44
PLP
CPU
Send buffer:
.
0b10
PLP UART
I/O Device: UART
External Device
UART
(PLPTool GUI UART)
RX
TX
TX
RX
Command Register
Status Register: 0b01
Receive Buffer: 0x44
PLP
CPU
Send buffer:
.
0b10
PLP UART
I/O Device: UART
External Device
UART
(PLPTool GUI UART)
RX
TX
TX
RX
Command Register
Status Register: 0b01
Receive Buffer: 0x2E
PLP
CPU
Send buffer:
PLP UART
polling
I/O Device: UART
External Device
UART
(PLPTool GUI UART)
RX
TX
TX
RX
Command Register
Status Register: 0b11
Receive Buffer: 0x2E
PLP
CPU
Send buffer:
PLP UART
polling
I/O Device: UART
External Device
UART
(PLPTool GUI UART)
RX
TX
TX
RX
Command Register
Status Register: 0b11
Receive Buffer: 0x2E
PLP
CPU
Send buffer:
0x2E
PLP UART
I/O Device: UART
External Device
UART
(PLPTool GUI UART)
RX
TX
TX
RX
Command Register
Status Register: 0b11
Receive Buffer: 0x2E
PLP
CPU
Send buffer:
0b10
PLP UART
I/O Device: UART
External Device
UART
(PLPTool GUI UART)
RX
TX
TX
RX
Command Register
Status Register: 0b01
Receive Buffer: 0x2E
PLP
CPU
Send buffer:
PLP UART
polling
Lecture Question
When polling the UART, the PLP CPU controls which actions?
Data transfers from the status register to a CPU register
Data transfers from the receive buffer to a CPU register
Updating the status register when a new character is received
Both (a) and (b)
Both (b) and (c)
Bit Masking
Used to isolate specific bits in a value
Bit masking takes advantage of AND operation
Only the bits set in your mask are the ones that will be kept
Bit Masking
Example: put the isolate the third bit (22 position) of $t0 in $t2
li $t1, 0b100
Create a mask
AND value register with mask
and $t2, $t0, $t1
Bit Masking
Example: put the isolate the third bit (22 position) of $t0 in $t2
If $t0 contained 0b1101
0b1101
0b0100
Value
Mask
Result
0b0100
Bit Masking
Example: put the isolate the third bit (22 position) of $t0 in $t2
If $t0 contained 0b0010
0b0010
0b0100
Value
Mask
Result
0b0000
Lecture Question
What will the following instruction let you do?
andi $t1, $t0, 0b10
Set the 20 bit position of $t1 to 1
Set the 21 bit position of $t1 to 1
Assign the 20 bit position of $t1 the 20 bit position of $t0 (all other bits will be zero)
Assign the 21 bit position of $t1 the 21 bit position of $t0 (all other bits will be zero)
Memory Access Offset
Address Contents
0xF0000000 0x00000000
0xF0000004 0x00000001
0xF0000008 0x00000000
0xF000000C 0x00000000
li $s0, 0xf0000000
$s0
Memory Access Offset
Address Contents
0xF0000000 0x00000000
0xF0000004 0x00000001
0xF0000008 0x00000000
0xF000000C 0x00000000
$s0
li $s0, 0xf0000000
lw $t1, 4($s0) #UART Status Register
$t1
Copied
$s0 + 4
Lecture Question
If $s0 contains 0xf0000000, which instruction will copy a word from the UART receive buffer into register $t2?
lw $t2, 0($s0)
lw $t2, 4($s0)
lw $t2, 8($s0)
lw $s0, 0($t2)
lw $s0, 4($t2)
lw $s0, 8($t2)