嵌入式系统代写代做代考 Embedded Systems Reconfigurable computing

Reconfigurable computing

Small Embedded Systems

Unit 4.2 The UART Protocol:
Data Format and Timing

Introduction
Data format
Error detection
Baud rate
Permissible baud rate error
UART functions

Data Format
Data is sent in words
1 start bit
Data bit (can be between 5 and 9 bits per word)
Parity bit (optional)
1 or 2 stop bit(s)
Example of format descriptor: 9600 8-N-1:
9600 baud rate
8 number of data bits in a word
N – no parity bit is used
1 – 1 stop bit is used

Data Format Example
Example, transmit ASCII “OK” using 8-N-1 lsb-first

Data Format Example
Example, transmit ASCII “OK” using 8-N-1 lsb-first
“O” is 0x4F or 0b01001111
“K” is 0x4B or 0b01001011
0 1 1 1 1 0 0 1 0 1 0 1 1 0 1 0 0 1 0 1
st b0 b1 b2 b3 b4 b5 b6 b7 sp st b0 b1 b2 b3 b4 b5 b6 b7 sp

5V
0V
TTL signal levels
RS232 signal levels
+12V
-12V

Parity
Parity provides primitive form of error detection
Example, transmit ASCII “O” using 7-E-1 lsb-first
“O” is 0x4F or 0b1001111
E means even parity
Insert an additional bit into word to ensure that number of 1s in the data plus the parity bit is an even number

Suppose one bit gets corrupted during transmission
0 1 1 1 1 0 0 1 1
st b0 b1 b2 b3 b4 b5 b6 p sp

0 1 1 1 0 0 0 1 1 1
st b0 b1 b2 b3 b4 b5 b6 p sp

6 bits are 1: even number
5 bits are 1: odd number
Parity should be even
This word contains an error
1

Parity
Likewise O means odd parity
Insert an additional bit into word to ensure that number of 1s in the data plus the parity bit is an odd number
Example, transmit ASCII “K” using 7-O-1 lsb-first
“K” is 0x4B or 0b1001011

0 1 1 0 1 0 0 1 1
st b0 b1 b2 b3 b4 b5 b6 p sp

5 bits are 1: odd number
1

Timing
Each is bit has equal duration (1 / baud rate)
Example: 9600 baud has bit time t = 1/ 9600 = 104 s
Transmitter send bits at interval of t
After detecting start bit, receiver samples incoming waveform at expected midpoint of bits

1.5t
0 1 1 1 1 0 0 1 0 1
st b0 b1 b2 b3 b4 b5 b6 b7 sp

9.5t
3.5t
5.5t
7.5t
0
10t
9t
1t
2t

Timing Tolerance
Local oscillators may not be precisely matched: tTX ≠ tRX
To get correct operation for 8-N-1, we must have 9.5tRX>9tTX
Also, 9.5tRX<10tTX Solving this gives us a ~5.6% margin We would normally take 40% of this to be safe So timing mismatch must be no more than ~2.3% 1.5t 0 1 1 1 1 0 0 1 0 1 st b0 b1 b2 b3 b4 b5 b6 b7 sp 9.5t 3.5t 5.5t 7.5t 0 10t 9t Framing Errors The use of start bits and stop bits to frame data word gives some ability to detect mismatch of speed Say RX clock is faster than TX clock 1.5t 0 1 1 1 1 0 0 1 0 1 st b0 b1 b2 b3 b4 b5 b6 b7 sp 9.5t 3.5t 5.5t 7.5t 0 10t 9t Framing error For 8-N-1 this bit should be 1: Baud Rate In principle baud rate can take any value In practice only specific values are used, e.g. 4800 bps 9600 bps 4400 bps 19200 bps 38400 bps 57600 bps 115200 bps We want the transmit and receive devices to have accurate match of clock: use precision crystal oscillator Original crystal oscillators had frequency of 1.8432 MHz These baud rates are derived by integer division ratio 1843.2k ÷ 16 = 115.2k 1843.2k ÷ 192 = 9.6k UART UART is a device that exchanges parallel data with data bus and converts to/from serial for communication Automatically manages framing (start/stop bits), parity and baud rate generation Detail of operation is controlled by writing values to special function registers D0 D1 D2 D3 D4 D5 D6 D7 TX RX R/W CLK Data bus USART Universal Synchronous/Asynchronous Receiver Transmitter Adds the ability to operate the device in synchronous mode (i.e. transmitting a clock along with data) In this lecture we talk only about asynchronous function Summary Asynchronous communication does not assume a shared clock Baud rate and data format must be agreed in advance by both ends of the link Data is transmitted in very small chunks, typically 7 or 8 bits Framing bits are used to wrap the data to give some tolerance on timing Parity bits may be used to give some protection against data corruption UART handles low level details of asynchronous serial communications (framing bits, parity, etc.) /docProps/thumbnail.jpeg