EEE 343 - Lecture 2 - Communication Protocols in Embedded Systems PDF
EEE 343 - Lecture 2 - Communication Protocols in Embedded Systems PDF
Ikechi A. Ukaegbu
Embedded Microcontrollers
Modes of Communication
●
Simplex
●
Half Duplex
● Duplex
2
ES Communication Interfaces
3
On-board Communication Interfaces
4
I2C
On-board Communication Interfaces
Vdd
R1 R2
Master
SCL
Slave
SCL
SDA SDA
7
I2C (Inter Integrated Circuit)
Multiple Slaves
8
I2C (Inter Integrated Circuit)
• Advantages
– Low cost (due to low gate count)
– Low pin count (just 2!)
– Addressing built-in
– Ubiquitous
• Disadvantages
– Half-duplex (about 400 kbps max)
– Careful consideration of hardware
– More complicated than SPI and UART
N.B.: I2C can reach up to 1MHz ~ 5 MHz but these speeds are not very common
9
I2C (Inter Integrated Circuit)
10
I2C (Inter Integrated Circuit)
Control Byte Data Byte
SDA
SCL
Slave Address
(Each slave must have a fixed and different address)
Start condition:
• Master SDA = High to Low Initiated from idle bus state
• Master SCL = Hold High
ACK/NACK:
• R/W: High = read data request • Receiving device sends ACK/NACK
• R/W: Low = data will be sent • ACK = Acknowledge = Low (zero)
• NACK = No Acknowledgement = High (one)
Stop condition:
• Master SDA = Low to High
• Master SCL = Hold High
Bus becomes idle
11
SPI
On-board Communication Interfaces
13
SPI (Serial Peripheral Interface)
SCLK SCLK
Master
Slave
SPI
MOSI
SPI
MOSI
MISO MISO
SS SS
14
SPI (Serial Peripheral Interface)
Multiple Slaves
15
SPI (Serial Peripheral Interface)
• Advantages
– Full duplex
– Higher speed than UART and I2C
– No start and stop bits (data can be streamed without
interruptions)
– No complicated slave addressing system like the I2C
– Ubiquitous
• Disadvantages
– More pins than UART and I2C
– Short distances
16
SPI (Serial Peripheral Interface)
2. The master switches the SS/CS pin to a low voltage state which
activates the slave
17
SPI (Serial Peripheral Interface)
4. If a response is needed, the slave returns data one bit at a time to the
master along the MISO line. The master reads the bits as they are
received
18
SPI (Serial Peripheral Interface)
• Data transmission:
19
SPI (Serial Peripheral Interface)
• Data transmission:
20
SPI (Serial Peripheral Interface)
• Data transmission:
21
SPI (Serial Peripheral Interface)
• Data transmission:
22
SPI (Serial Peripheral Interface)
• Data transmission:
23
SPI (Serial Peripheral Interface)
• Data transmission:
24
SPI (Serial Peripheral Interface)
• Data transmission:
25
SPI (Serial Peripheral Interface)
• Data transmission:
26
SPI (Serial Peripheral Interface)
• Data validity:
27
UART
On-board Communication Interfaces
29
UART (Universal Asynchronous Rx/Tx)
Device FPGA
UART Tx UART Rx
UART Rx UART Tx
GND GND
UART Communication
30
UART (Universal Asynchronous Rx/Tx)
– Data travels in parallel to and from the UART to the controlling device (ex.
a CPU)
– When sending on the Tx pin, the first UART translates this parallel
information into serial and transmits it to the receiving counterpart
– The second UART receives this data on its Rx pin and transforms it back
into parallel to communicate with its controlling device
31
UART (Universal Asynchronous Rx/Tx)
• UART
– The transmitter and receiver use start bit, stop bit and timing parameters to
synchronize with each other
– The original data is in parallel form
– We need a parallel to serial converter
32
Recap – [D-type Flip-flop]
SR Flip-flop TT
Clk S R Q+
0 x x Q D S Qn D Qn
Memory
1 0 0 Q
Clk
1 0 1 0
Q’n Q’n
1 1 0 1 R
1 1 1 Not used
D Flip-flop TT
Clk D Q+
0 x Q
1 0 0
1 1 1
33
Recap – [D-type Flip-flop]
Clk D Q+ Q D Q+
Q Q+ D
0 x Q 0 0 0 0 0 0
1 0 0 0 1 1 1
0 1
1 1 1 1 0 0 1 0 0
1 1 1 1 1 1
Q+ = D
D S Q
Clk
R Q’
34
Recap – [Classification of Registers]
– Storage registers
35
Recap – [Classification of Registers]
Clk
Serial 1 1 1
Parallel Input Input D 0
1
1 1 0 1
D3
Serial Serial
FF3 FF2 FF1 FF0 1
Input Output D2
Parallel
Input D1
0
Parallel Output 1
D0
36
Recap – [Shift Registers (SISO)]
• They are sequential circuits that are used for data storage, data
transfer and certain arithmetic and logic operations
1 1 1 1
1 1 1 1 1
1111 1 1 1 1 1 1 0 0
1 1 1 1 0 0 0 0
0 1 0 0 0 0 0 0
Din D3 Q3 D2 Q2 D1 Q1 D0 Q0 Serial
Output
Clk
Clk
Clk Q3 Q2 Q1 Q 0
D Flip-flop TT Din
Clk D Q+ Initial 0 0 0 0 Q3 1 1 1 1
First clk 1
0 x 1 1
Q edge 1 0 0 0 Q2 0
0 0
Next clk
Q1 1 1
1 edge 1 1 0 0 0 0
Next clk
1 1 1 Q0 1
edge 1 1 1 0 0 0 0
Next clk
edge 1 1 1 1
37
Recap – [Shift Registers (SIPO)]
• They are sequential circuits that are used for data storage, data
transfer and certain arithmetic and logic operations
Din D3 Q3 D2 Q2 D1 Q1 D0 Q0
Clk
Parallel Output
Clk
Din SISO
Q3 1 1 1 1
1 1 1
Q2 0
Q1 1 1
0 0 SIPO
1
Q0 0 0 0
38
Recap – [Storage Registers (PIPO)]
• They are sequential circuits that are used for data storage, data
transfer and certain arithmetic and logic operations
Parallel Input
D3 Q3 D2 Q2 D1 Q1 D0 Q0
Clk
Parallel Output
PIPO
39
Recap – [Storage Registers (PISO)]
Operating modes:
1. Load Mode PISO
2. Shift Mode
1 1 0 1
Load/ A3
A2 A1 A0
Shift 0
1 01 0
1 0
1
0 10
10 10
1 01
1 2 3 4
5 6
0 A20 0 A01 0 A00
Q3 Q2 Q1
Clk
40
UART (Universal Asynchronous Rx/Tx)
• Start Bit
– The first bit of one-byte UART transmission
– Indicates that the data line is leaving its idle state
– Idle state is logically high (start bit is logic low)
– Its an overhead bit and facilitates communication between the receiver and
the transmitter but does not transfer meaningful data
• Stop Bit
– The last bit of one-byte UART transmission
– The same level as the idle state
41
UART (Universal Asynchronous Rx/Tx)
• Baud Rate
– The approximate rate (in bits per second or bps) at which data can be
transferred
– It is the frequency (in bps) corresponding to the time (in seconds) required
to transmit one bit of digital data
– Ex., with 9600-baud system, one bit requires 1/(9600 bps) ~ 104.2 us.
42
UART (Universal Asynchronous Rx/Tx)
• Parity Bit
– An error detection bit is added at the end of the byte
– There are “even parity” and “odd parity”
– “Even parity” means that the parity bit will be logic high if the data byte
contains even number of logic-high bits
– “Odd parity” means that the parity bit will be logic high if the data byte
contains odd number of logic-high bits
43
UART (Universal Asynchronous Rx/Tx)
44
UART (Universal Asynchronous Rx/Tx)
45
Other Communication Interfaces
External/Peripheral Communication Interface
47
I/O Subsystem
48
LED (Light Emitting Diode)
49
7 Segment LED Display
50