Download as pdf or txt
Download as pdf or txt
You are on page 1of 13

I2C PROTOCOL(two wire interface TWI)

-Inter integrated circuit


-Bidirectional data transfer
-Half duplex (have only one data line)
-Synchronous bus so data is clocked with clock signal
-Clock is controlled when data line is changed
speed of I2C:
Low (under:100kps)
Fast(400kbps)
High speed(3.4Mbps) I2C V2.0

2 wire communication
Vtg high=1,low=0
I2c multi master
It is multi master bus
So bus arbitration is required
If is traying to send logic one but hears logic 0, it immediatly
stops transmision and gives sender priority

Synchronization needed in SCL


Advantages
Support multi master, multi slave communication.
Better error handling is available with ACK bit
Due to clock stretching it can work with both slow and fast ICs.
Good for communication in on broad devices
Easy to link multiple devices b/c addressing scheme
Cost and complexity do not scale up with the number of devices
Disadvantages
The hard ware complexity increases when more number of
maser/slave device are added.
Slow transmission speed sue to frame overhead b/c device
address bits and ACK bits
It works in half duplex mode.

SPI(serial peripheral interface)


Capabilities of SPL
More bytes
High speed
Audio , video signal
Software flashing
Data logger
SPI is better for these tasks

Using 4 wires
Always full-duplex
Multiple Mbps transmition
Multiple slaves
Transfer data 4-16 bit character
Advantages
full-duplex communication
Higher throughput than i2c protocol
Not limited to 8-bit words in the case of bit transfering.
Arbitrary choise of message size,content,and purpuse
Simple and hardware interfacing
Typicaly lawer power requiremeents than i2c due to less
circuitry

UART (universal asynchronious reciever


transmiter)
Is defined protocol
Fairly device independet
Serial communication porotocol
Two wire communication porotocol
Data formate and transmition speed are configurable

Data synchroniouzation in UART


Baud rate
Start and stop bit
Baud rate is a measure of the speed of data transfer, expressed in
bits per second(bps)

Advantages
Simle to setup
electrically robust
Most microcontroller support
Easy to use
Only use 2 wires
No clock signal is necessary
Provide error detection by parity bit check
Cost and size will be much lesser compare to the paralel
communication
Disdvantages
No protocol level error correction
Fairly requires reference clock
Baud should match
No support for multiple master and slave
The size of the data frame is limited to a maximum of 9 bit.
Limited speed is the bottleneck for the application which
required higher data transmission rate.

Three registers control the behavior


of the pins:
1. Data Direction Register (DDR): Each bidirectional port has
its own DDR, which contains one bit for each pin of the port.
The functionality of a pin (input or output) is determined by
clearing or setting its bit in the DDR. Different pins of a port
may be configured differently, so it is perfectly okay to have
three pins configured to output and use the other five as inputs.
After a reset, the DDR bits are generally initialized to input.
Reading the register returns its value. Digital I/O …
2. Port Register (PORT): This register is used to control the
voltage level of output pins. Assuming a pin has been
configured to output, then if its bit in the PORT register is set,
the pin will be high; if the bit is cleared, the pin will be low. To
avoid overwriting the other bits in the port when setting a
particular bit, it is generally best to use the controller’s bit
operations.
For output pins, reading the register returns the value you
have written. For input pins, the functionality depends on the
controller. Some controllers allow you to read the state of input
pins through the port register. Other controllers, e.g. the
ATmega16, use the port bits for other purposes if the
corresponding pins are set to input, so here you will read back
the value you have written to the register .
Digital I/O …
3. Port Input Register (PIN): The PIN register is generally
read-only and contains the current state (high or low) of all
pins, whether they are configured as output or as input. It is
used to read the state of input pins, but it can also be used to
read the state of output pins to verify that the output was taken
over correctly . A write to this register generally has
no effect

Interrupts
It is a methed of creating a temporary halt during program
excution and allows peripheral(output) device to access
mpu(microprocesor unit)
Microprocesor unit response to that interrupt with interrupt
service routine ISR (short prog indicating how to handle the
interrupt(events that come into the program)).
The microprocesor jumps to ISR to service peripherals after it
microprocesor again continue to the main program
An interrupt is a condition that causes the microprocessor to
temporarily work on a different task, and then later return to its
previous task. Interrupts can be internal or external. Internal
interrupts, or "software interrupts," are triggered by a software
instruction and operate similarly to a jump or branch instruction.
An external interrupt, or a "hardware interrupt," is caused by an
external hardware module. As an example, many computer
systems use interrupt driven I/O, a process where pressing a key
on the keyboard or clicking a button on the mouse triggers an
interrupt. The processor stops what it is doing, it reads the input
from the keyboard or mouse, and then it returns to the current
program.

The grey bars represent the control flow. The top line is the
program that is currently running, and the bottom bar is the
interrupt service routine (ISR). Notice that when the interrupt
(Int) occurs, the program stops executing and the
microcontroller begins to execute the ISR. Once the ISR is
complete, the microcontroller returns to processing the
program where it left off.

Microcontrollers tend to be deployed in systems that have to


react to events. Events signify state changes in the controlled
system and generally require some sort of reaction by the
microcontroller. Reactions range from simple responses like
incrementing a counter whenever a workpiece crosses a
photoelectric barrier on the conveyor belt to time-critical
measures like shutting down the system if someone reaches into
the working area of a machine.
As soon as the event occurs, the microcontroller calls an
interrupt service routine (ISR) which handles the event. The ISR
must be provided by the application programmer.

I2C bus arbitration

Procedure that ensures that only one of the master dicide will
control the bus. This ensure that the transfer data does not get
corrupted.
Process to get the bus access
Related to SDA line
It is a multi master bus driving the bus symentanioully so
costantlly monitoring the bus continouslly start and stop
condition they can ditermine whethere the bus is idle(first) or
not
multiple master start transfer at the same time in this case only
one master will be win who ever send zero first is called
arbitration

Whhen we use more than one master. concider a scenario when


both master(master1 and master2) start the communication at
time in this condition only the bus arbitration occur.
1f master1 starts the communication by pulling the clock low
then then the master2 cannot able to control the clock untill the
SCL is released by the master1(master2 is considered as a slave
in this condition). after the stop bit is observed by the master2
then it will start the communication.
When the two masters want to write or read they compared by
their one or two first bits this is an arbitration master2 weits at
slave condition untill master1 finish.
This is how I2C bus arbitraation work.

Clock Synchronasation
Procedure where the clock signals of two or more device are
synchronized

Every master has an internal computer_L determining the time


during which it’s generated clock will be SCL=0 and internal
computer_H determine the SCL=’1’ period. The SCLoutput
have the same wired -AND behaviour as the SDA
Clock Synchronasation is activate from the moment that the
arbitration is started.

In Synchronasation master decides the clock speed by


controlling the it. How evr the slave may not cooperate with the
clock speed given by master and it may need to slow down. This
can be done by clock synckronization.
I2C is not Synchronazed with the predefined baud rate.

What is UART?
UART stands for Universal Asynchronous Receiver Transmitter. At a
high-level, a UART is simply a microchip that enables communications
between a computing device (PC, embedded system, etc.) and other
equipment.

To understand what a UART does in more detail, it is useful to


understand serial communication and parallel communication. We will
provide a crash course on those two topics here.

Serial communication in simple terms is sending data a single bit at a


time over a given communications bus. While RS-232 (note that UART
is commonly used for RS-232) and RS-485 are the two protocols we most
commonly associate with the term “serial communication”, many other
modern technologies such as USB (Universal Serial Bus), SATA (Serial
ATA), and Firewire/IEEE 1394 are also serial protocols. One of the
advantages of serial communication is that data can be transmitted at
higher frequencies, therefore increasing the amount of data that can be
sent despite the fact that less data is sent at once when compared to
parallel communication.

Parallel communication, on the other hand, is sending multiple bits of


data at the same time over a given communications bus. For example, a
32-bit parallel communications medium such as conventional PCI
(Peripheral Component Interconnect) would send 32-bits of data per
clock cycle. While one would think that this would give parallel
communication significant speed advantages over serial, in practice serial
is faster because it can accommodate more clock cycles per second (e.g.
GHz speeds).

So, what exactly does this have to do with UART anyway? Simple,
UART chips are used to convert inbound serial data to parallel data for
the system to read and conversely converts outbound parallel data to
serial before sending it on to other systems. Worded differently, a UART
enables a system to act as a DTE (Data Terminal Equipment) Device.
Before we move onto SPI, let’s quickly cover a few other important
details about UART communication:

 UART uses 2 wires: 1 for transmit (or Tx) and one for receive (or
Rx)
 UART communication is asynchronous, meaning that it is not
synchronized using a clock
 UART has a max communication distance of 15 meters
 UART leverages shift registers to convert serial communication to
parallel communication
 UART is commonly used as a “serial port” on computers or in
microcontrollers
 UART supports full-duplex communication

ADVANTAGES AND DISADVANTAGES OF UARTS


No communication protocol is perfect, but UARTs are pretty good at
what they do. Here are some pros and cons to help you decide whether or
not they fit the needs of your project:

ADVANTAGES
 Only uses two wires
 No clock signal is necessary
 Has a parity bit to allow for error checking
 The structure of the data packet can be changed as long as both
sides are set up for it
 Well documented and widely used method
DISADVANTAGES
 The size of the data frame is limited to a maximum of 9 bits
 Doesn’t support multiple slave or multiple master systems
 The baud rates of each UART must be within 10% of each other

What is SPI?
SPI (Serial Peripheral Interface) is a serial communication protocol
originally developed by Motorola that enables communication between
nearly any electronic device that supports clocked serial streams. SPI uses
a master-slave method for communication that enables high-speed data
streaming.

As opposed to just using two wires, SPI must use at least 4 wires. As
there can be multiple slave devices in an SPI implementation, the actual
amount of wires or traces used will be n+3 where n = the number of slave
devices in use.

A few additional key details on SPI before we move on:

 SPI is synchronous
 SPI is a simple protocol with little overhead
 SPI supports full-duplex communication
 SPI communication does not have a means for acknowledgment or
flow control
 SPI does not use much board space

Differences between UART vs SPI


While UART and SPI both support full-duplex communication, both use
“serial” communication in some way, and they are both only suitable for
short-distance use cases, there are not too many similarities beyond that.
So, what are the differences between UART vs SPI? The answer is there
are many; we will cover a number of them here.

Hardware vs protocol
One of the biggest differences is that UART is a type of hardware while
SPI is a protocol. When you are dealing with the nuances of getting
things to work in an embedded system, this can be easy to overlook.
However, UART is an actual piece of hardware (a microchip) while SPI
is a protocol or specification for communication.

Number of pins
UARTs use just two pins while SPI devices need at least 4. When
designing a system this means that if pins/traces are scarce, SPI may not
be an attractive solution.

Number of devices that can be connected


A corollary to the number of pins, UARTs and SPI devices support a
different number of devices. UART, leveraging only Tx and Rx for
outbound communication, is effectively limited to 1 to 1 communication.
SPI, on the other hand, can leverage its master/slave paradigm to enable
one too many communications.

Communications speed
SPI is significantly faster than UART. In some cases, an SPI solution can
be three times faster than a UART solution.

Price
In any engineering endeavor, the cost of a given solution is a big driver of
choice. Generally speaking, SPI is cheaper than UART.

Asynchronous vs Synchronous
As you can tell from the descriptions of the two earlier, another major
difference when comparing UART vs SPI is UART communication is
asynchronous while SPI is synchronous.

Size
Generally speaking, SPI devices take up relatively less space than UART
chips. This means use cases where there is limited board space may be
better served by SPI.

UART vs SPI: What should I use?


There is no one-size-fits-all answer to the “UART vs SPI: What should I
use?” question. However, with the information we have given you here,
you are now equipped to make an informed decision about which solution
is best for a given application you may be working on.

Generally speaking, SPI is preferred in applications that require higher


speed communication between chips or applications that require
communications between multiple devices. On the other hand, UART
may be better suited for applications that have to travel slightly more
distance such as diagnostic displays or other applications that require
RS-232 support.

Tools to debug and develop UART vs SPI


Here at Total Phase, we manufacture solutions designed to enable
debugging and development of embedded systems. Given the prevalence
of SPI in embedded systems, it is no surprise that we have a variety of
solutions that can aid with the debugging and development of systems
that use SPI.

For example, our SPI Development Kit enables developers to test target
devices as a master device, simulate a master device, program flash
devices that are SPI-based, and monitor an SPI bus with granularity down
to 20 nanoseconds.

Alternatively, if you need to debug data traveling to or from a UART, a


Total Phase protocol analyzer may prove useful. For example, check out
this article that covers how to monitor UART data over RS232 with the
Beagle USB 480 Power Protocol Analyzer.

You might also like