Study
Study
PROTOCOLS
SANJAY S B
COMMUNICATION PROTOCOLS
SPI, I2C, and UART are ideal for communication between microcontrollers and between
microcontrollers and sensors where large amounts of high speed data don’t need to be
transferred.
Parallel Serial
2
SERIAL PERIPHERAL INTERFACE
I2C and UART, data is sent in packets, limited to a specific number of bits. Start and stop
conditions define the beginning and end of each packet, so the data is interrupted during
transmission.
• Unique benefit of SPI is the fact that data can be transferred without interruption.
• Any number of bits can be sent or received in a continuous stream.
3
SPI CONTINUED
Wires Used 4
Max Speed Up to 10 Mbps
Synchronous or Async Sync
Serial or Parallel Serial
Max # of Masters 1
Max # of Slaves Theoretically Infinite
But in practical the number of slaves is limited by the load capacitance of the system,
which reduces the ability of the master to accurately switch between voltage levels.
4
SERIAL PERIPHERAL INTERFACE
MOSI Line for the master to send data to the slave. (MSB First)
MISO Line for the slave to send data to the master. (LSB First)
SCLK Line for the clock signal.
SS/CS Line for the master to select which slave to send data.
5
WORKING OF SPI
Clock
• The clock signal synchronizes the output of data bits from the master to the sampling
of bits by the slave.
• One bit of data is transferred in each clock cycle.
• Speed of data transfer is determined by the frequency of the clock signal.
• SPI communication is always initiated by the master.
The clock signal in SPI can be modified using the properties of clock polarity and clock
phase.
These two properties work together to define when the bits are output and when they are
sampled.
Clock polarity (CPOL) can be set by the master to allow for bits to be output and
sampled on either the rising or falling edge of the clock cycle.
Clock phase (CPHA) can be set for output and sampling to occur on either the first
edge or second edge of the clock cycle, regardless of whether it is rising or falling.
6
WORKING OF SPI
Slave select:
• The master can choose which slave it wants to talk to by setting the slave’s CS/SS line
to a low voltage level.
• In the idle, non-transmitting state, the slave select line is kept at a high voltage level.
• Multiple CS/SS pins may be available on the master, which allows for multiple slaves to
be wired in parallel.
• If only one CS/SS pin is present, multiple slaves can be wired to the master by daisy-
chaining.
7
WORKING OF SPI
MOSI/MISO:
The master sends data to the slave bit by bit, in serial through the MOSI line.
The slave send data back to the master through the MISO line in serial.
8
WORKING OF SPI
9
PRO’S AND CON’S OF SPI
Advantages
• No start and stop bits, so the data can be streamed continuously without interruption
• No complicated slave addressing system like I2C
• Higher data transfer rate than I2C (almost twice as fast)
• Separate MISO and MOSI lines, so data can be sent and received at the same time
Disadvantage
10
11
12
13
MODES OF SPI
14
SPI MODES AND CLOCK CONFIGURATION
15
TIMING REQUIREMENT IN SPI (ADS1118
16
UART
17
UNIVERSAL ASYNCHRONOUS RECEIVER
TRANSMITTER
https://www.ti.com/lit/ug/sprugp1/sprugp1.pdf
UART, which stands for Universal Asynchronous Receiver-Transmitter, is a hardware
communication protocol used for asynchronous serial communication between devices.
UART does not require a clock signal to synchronize the sender and receiver. Instead,
both Transmitter and Receiver should be preconfigured with the same baud rate.
It uses start and stop bits to indicate the beginning and end of a data packet.
18
APPLICATION OF UART
• UART widely used in microcontroller to communicate with sensors, actuators and other
microcontroller.
• It I often used to connect Microcontrollers with computer using USB to UART convertor
for debugging.
• Many modem and communication devices uses UART.
• UART is commonly used in GPS, Bluetooth and other wireless communication module.
19
The UART peripheral is based on the industry standard TL16C550 asynchronous
communications element
TL16C550 : Single UART with 16-Byte FIFOs and Auto Flow Control
The UART contains a programmable baud generator that takes an input clock and divides
it by a divisor in the range between 1 and ( - 1) to produce a baud clock (BCLK).
23
DATA FORMAT
The UART transmitter section includes a transmitter hold register (THR) and a transmitter
shift register (TSR)
The UART receiver section includes a receiver shift register (RSR) and a receiver buffer
register (RBR).
Based on the settings chosen in LCR (Line control register), the UART receiver accepts
the above mentioned format from the transmitting device.
24
25
IER: register hold the status
signal like receive and transmit
line status.
26
PRO’S AND CON’S OF SPI
Advantage:
• UARTs are simple and they only rely on two wires.
• They possess a parity bit in order to check for errors in data packets.
• If both sides are set up for structural data change it can happen.
• UART is a widely used method.
Disadvantage:
• The data frame is limited to 9 bits.
• The baud rates of the receiving and transmitting UAT must be within ten percent.
27
I2C
28
INTER INTEGRATED CIRCUIT
I2C, which stands for Inter-Integrated Circuit, is a synchronous serial communication
protocol developed by Philips (now NXP Semiconductors) for connecting low-speed
devices like microcontrollers, sensors, EEPROMs, and other peripherals in embedded
systems.
29
30
31
32
33
34
35
36
37
38
39
40
I2C MODES
Figure shows the Data frame fields used in different
modes by I2C
41
MULTI-MASTER ATTRIBUTION
When we have a multi-master, only one will be allowed to transfer the data to slave.
So, when we have multiple master then the data from master with lower address will
have the priority
This can be solved by ARBITRATION that uses Wired AND Logic.
42
INTERFACING EEPROM AT24C04
This is a Atmel EEROM 4KB memory, we have other Atmel EEPROM like
AT24C01/02/04/08/16.
Refer this Manual for Atmel EEPROM.
43
44
45
PROTOCOL SUMMARY
46
BASIC
ELECTRONICS
47
APPLICATION OF PULL UP AND PULL DOWN
RESISTOR
https://www.electronics-tutorials.ws/dccircuits/voltage-divider.html
48
To avoid the floating condition when using in switching conditions, we use pull up and pull
down resistor for logic level.
For example: In figure 1, when the switch is open due to external interference the switch
will be in floating condition (0 or 1), whereas in figure 2 we have Used pull up resistor.
49
Sometimes we need to interface logic gates of different logic family.
Then we use pull-up or down resistor, because the voltage level of different logic family
will be different.
Ex: Logic level like 1.8v and 3.3v devices.
When we want to drive the devices that operate
in higher voltages than the supply voltage of the
logic gates then we use pull up resistor.
50
Pull up resistor are also used in I2C protocol in slave select lines
51
HOW TO CHOOSE PULL UP RES VALUE
• Lower the value of pull up resistor, stronger is the pull.
• Higher the value of pull up resistor, weaker is the pull.
Note:
When we choose very low resistor, then excessive current flow on strong pull up lead to
more dissipation.
When we choose very high resistor, then no current may flow through peripheral and lead
to logic zero
52
And in microcontrollers when we consider the input impedance, then the voltage drop
appearinf across the MC may not be sufficient, so we should choose Rp considering input
impedence of MC and also the drop due to leakage current.
For fast switching application, large value of pull up resistor should be avoided.
Typically, 5k to 50Kohms works for application.
53
CAPACITOR BASICS
54
CAPACITOR BASICS
• Capacitor with the larger distance between two plates has the smaller capacitance.
• Capacitor with the larger area of plates has the larger capacitance.
• Smaller capacitance charges quickly, and larger capacitance charges slowly.
All capacitors in series will have the same charge, but the voltage across each will vary
based on their capacitance.
When capacitors are in series, the voltage across each capacitor will be different,
depending on their capacitance values. The capacitor with the smallest capacitance will
have the highest voltage across it
56
CAPACITOR IN PARALLEL
When capacitors are connected in parallel, the total capacitance () is the sum of the
individual capacitances. The formula for calculating the total capacitance in parallel is:
In a parallel configuration, all capacitors experience the same voltage across their
terminals. The voltage rating of the parallel combination is determined by the lowest
voltage rating of the individual capacitors.
If one capacitor in a parallel configuration fails (for example, short-circuits), the other
capacitors can continue to function.
When connecting capacitors in parallel, it is important to ensure that they have the same
voltage rating to avoid overvoltage conditions on any individual capacitor.
57
APPLICATION OF CAPACITOR
Series Capacitors: Useful for increasing voltage ratings, creating voltage dividers, tuning
circuits, and designing high-pass filters.
Parallel Capacitors: Ideal for increasing total capacitance, smoothing power supplies,
decoupling in digital circuits.
58