Professional Documents
Culture Documents
Register Bits
PORTxn
The PORTxn bits in the PORTx register have two functions. They can
control the output state of a pin and the setup of an input pin.
As an Output:
If a '1' is written to the bit when the pin is configured as an output pin, the
port pin is driven high. If a ‘0’ is written to the bit when the pin is
configured as an output pin, the port pin is driven low.
As an Input:
If a '1' is written to the bit when the pin is configured as an input pin, the
pull-up resistor is activated. If a ‘0’ is written to the bit when the pin is
configured as an input pin, the port pin is tri-stated.
PINxn
The PINxn bits in the PINx register are used to read data from port pin.
When the pin is configured as a digital input (in the DDRx register), and
the pull-up is enabled (in the PORTx register) the bit will indicate the
state of the signal at the pin (high or low).
Note: If a port is made an output, then reading the PINx register will give
you data that has been written to the port pins.
Interrupts
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.
Procedure that ensures that only one of the master decide 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 simultaneously so constantly
monitoring the bus continuously start and stop condition they can
determine whether the bus is idle(first) or not
multiple master start transfers at the same time in this case only one
master will be win who ever send zero first is called arbitration
When we use more than one master. consider 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 until 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 waits at slave condition until
master1 finish.
This is how I2C bus arbitration work.
Clock Synchronization
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 SCL output have the same wired
-AND behavior as the SDA
Clock Synchronization is activated from the moment that the arbitration
is started.
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.
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
• 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.
• 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
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.
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.
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.
In this article, you will learn the I2C protocol and its bus configuration
and uses in the chip to chip communication.
The I2C protocol are also used for two-wire interface to connect
low-speed devices like microcontrollers, EEPROMs, A/D and D/A
converters, I/O interfaces and other similar peripherals in embedded
systems.
What is I2C?
I2C is a serial communication protocol. It provides the good support to
the slow devices, for example, EEPROM, ADC, and RTC etc.
I2c is not only used with the single board but also used with the other
external components which have connected with boards through the
cables.
In I2C, both buses are bidirectional, which means master able to send and
receive the data from the slave. The clock bus is controlled by the master
but in some situations, slave is also able to suppress the clock signal, but
we will discuss it later.
SDA (Serial Data) – The line for the master and slave to send and
receive data.
SCL (Serial Clock) – The line that carries the clock signal.
Arbitration in I2C
The arbitration is required in case of multi-master, where more than one
master is tried to communicate with a slave simultaneously. In I2C
arbitration is achieved by the SDA line
Summary
In summary, I have compiled all the various advantages / disadvantages
and functions of the various communication peripherals and compared
them so you can easily pick which is the best for your project. Do keep in
mind that the device you are using must support the communication
peripheral as well.
Easy to
Complex as device
Complexity Simple chain many
increases
devices.
Faster than
Speed Slowest Fastest
UART
Up to 127
but may
Many, but there are
Number of Up to 2 get
practical limits and
devices devices complex
may get complicated
as devices
increases
Number of wires 1 2 4
Half
Duplex Full Duplex Full Duplex
Duplex