The Receiver

Download Report

Transcript The Receiver

Essentials of Communication
Communication Link
Sender
Data
Receiver
This simple model requires many guarantees.
Guarantees in Communications
 The communication link exists.
 The communication link is safe and sound.
 The sender and receiver are the correct nodes.
 The sender is sending the correct data.
 The receiver is able to correctly interpret the incoming
data.
Protocols in Communication
 In order to have robust communication, the
guarantees needs to be realized.
 To do so, we need an elaborate and standardized
mechanism.
 These standard rules that defines the parameters of
communications and ensures these guarantees are
called protocol.
Advantages of Protocols
 Standardized, so interoperability is ensured.
 Usually include error-detection and error-correction
mechanisms.
 Available as implemented chips that can be directly
used.
Types of Communication Protocols
 There are different ways of categorizing protocols
 First Categorization:
Serial Mode
Transfer
Parallel Mode
Transfer
 Second Categorization:
Synchronous
Mode Transfer
Asynchronous
Mode Transfer
Serial and Parallel Mode
SERIAL MODE
SENDER
RECEIVER
PARALLEL MODE
Serial vs Parallel Mode
Parameter
Serial Mode
Parallel Mode
Reliability
Speed
Power
Cost
Complexity
Range
Reliable
Slow
Low
Low
High
Long
Unreliable
Fast
High
High
Low
Short
Need of Synchronization
T/2
T
RECEIVER
SENDER
1
1
1
1 1 1
000
111
000
1
1
000
Suppose Sender sends data with a Time Period of T
What if Receiver doesn’t know the speed and assume it to be say T/2
The Data received will be
Synchronous Mode
 Sender sends a clock signal along with data at every
rising / falling edge of the clock, the data value is read
by the receiver.
SENDER
0
1
0
1
0
1
SENDER CLOCK
RECEIVER
0
1
Asynchronous Mode
 There is no clock signal.
 The receiver and the sender communicate at a
predetermined speed (bauds or bits per second).
 Baud Rate: Baud Rate is a measurement of transmission
speed in asynchronous communication. The devices that
allows communication must all agree on a single speed of
information - 'bits per second'.
Synchronous vs Asynchronous Mode
Parameter
Reliability
Cost
Complexity
Synchronous
Reliable
Expensive
Complicated
Asynchronous
Error Prone
Inexpensive
Simple
Transmission Modes
SENDER
RECEIVER
Simplex
Only one way transmission takes place
Transmission Modes
SENDER
RECEIVER
Half-Duplex
Two way transmission takes place but only one
end can communicate at a time
Transmission Modes
SENDER
RECEIVER
Full-Duplex
Two way transmission takes place and both
end can communicate simultaneously
UART
Universal Asynchronous
Receiver Transmitter
Asynchronous Serial Communication
 With asynchronous communication, the transmitter
and receiver do not share a common clock
Remove: Start, Stop, Parity Bits
Add: Start, Stop, Parity Bits
Transmitter
–
+
Receiver
Data
1 byte-wide Data
The Transmitter
 Shifts the parallel data onto
the serial line using its own
clock
 Also adds the start, stop
and parity check bits
1 byte-wide Data
The Receiver
 Extracts the data using its
own clock
 Converts the serial data back
to the parallel form after
stripping off the start, stop
and parity bits
Asynchronous Serial Communication
 Start bit—indicates the beginning of the data word
 Stop bit—indicates the end of the data word
 Parity bit—added for error detection (optional)
 Data bits—the actual data to be transmitted
 Baud rate—the bit rate of the serial port
 Throughput—actual data transmitted per sec (total bits transmitted—
overhead)
 Example: 115200 baud = 115200 bits/sec
 If using 8-bit data, 1 start, 1 stop, and no parity bits, the effective
throughput is: 115200 * 8 / 10 = 92160 bits/sec
Asynchronous Serial Communication
Start Bit
D0
Parity Bit
D1
D2
D3
D4
D5
D6
1 or 2 Stop Bits
D7
1 Asynchronous Byte
 Asynchronous transmission is easy to implement but less
efficient as it requires an extra 2-3 control bits for every 8
data bits
 This method is usually used for low volume transmission
Synchronous Serial Communication
 In the synchronous mode, the transmitter and receiver share a common
clock
 The transmitter typically provides the clock as a separate signal in addition
to the serial data
Clock
Receiver
Transmitter
Data
1 byte-wide Data
The Transmitter
 Shifts the data onto the serial
line using its own clock
 Provides the clock as a
separate signal
 No start, stop, or parity bits
added to data
1 byte-wide Data
The Receiver
 Extracts the data using
the clock provided by the
transmitter
 Converts the serial data
back to the parallel form
UART in Atmega328P
Arduino Serial Library
int incomingByte = 0; // for incoming serial data
void setup()
{
Serial.begin(9600); // opens serial port, sets data rate to 9600 bps
}
void loop()
{
// send data only when you receive data:
if (Serial.available() > 0)
{
// read the incoming byte:
incomingByte = Serial.read();
// say what you got:
Serial.print("I received: ");
Serial.println(incomingByte, DEC);
}
}
SPI
Serial Peripheral Interface
SPI
SPI is an interface bus commonly used to send data between
microcontrollers and small peripherals such as shift registers,
sensors, SD cards and LCDs. It uses separate clock and data lines,
along with a select line to choose the device you wish to talk to.
 SPI was originally developed by Motorola (now Freescale) in






1979.
It works on serial mode of transfer.
It is also synchronous and full duplex.
It has the capability of communicate with many nodes.
It allows LSB or MSB first bit transfer.
It supports multiple bit rates.
It has end of transmission interrupt.
SPI
 In SPI, the sender and receiver follows a master-slave





relationship.
There may be multiple nodes in the network.
One node is master, the rest are slaves.
The communication is always initiated by the master.
The slaves can communicate only with the master.
How do master selects the slave??
SPI Pins
 SCK is generated by Master and is used as the mode is
synchronous.
 MOSI is Master Out Slave In: Data sent by Master to Slave.
 MISO is Master In Slave Out: Data sent by Slave to Master.
 S̅S̅ is Slave Select: Slave communicates with Master only if
this pin’s value is set as LOW. (Active Low)
SPI Schematics: Single Slave
The SPI bus uses two data lines, a clock line, and a slave select line.
An additional slave select line is added for each slave device, but the
other three lines are shared on the bus.
SPI Schematics: Multiple Slaves
•A - No data (SS is high, SCK is low)
•B - SS taken low to enable the slave (peripheral). At this point the slave should prepare to
transfer data by setting the MOSI and the SCK lines as inputs, and the MISO line as an
output. The slave can now prepare to notice clock pulses on the SCK line.
•C - First character arrives (the letter "F" or 0x46 or 0b01000110). For each of the 8 bits the
SCK line is briefly brought high, and then low again. This tells the slave to read the data on
the MOSI line. Also the slave can place data on the MISO line for the master to
simultaneously read in.
•D - The letter "a" arrives
•E - The letter "b" arrives
•F - "No data" after "Fab" - however the SS is still enabled.
•G - SS taken high to indicate end of the sequence of data.
Sending the Character 'F'
(0x46 or 0b01000110) (MSB First)
Notice how for each bit (starting with the most significant bit), the
MOSI line is first changed to the correct state (0 or 1) and then the
SCK line is pulsed to indicate that the data should be read.
SPI in Atmega328P
Arduino SPI Library (<SPI.h>)
The Arduino development kit comes with an SPI library. To use it
you just need to include it:
İki Arduino’yu SPI protokolü ile
#include <SPI.h>
iletişime geçirebilmek için Master ve
Slave cihazlar için ayrı kodlar yazıp
yüklemelisiniz.
To control the hardware you call SPI.begin() which configures the
SPI pins (SCK, MOSI, SS) as outputs and MISO as input. It also sets
SCK and MOSI low, and SS high.
The function SPI.transfer() does the actual transferring of bytes. It
is up to you to set SS low at an appropriate time.
When finished call SPI.end() to turn the SPI hardware off.
SPI Registers
 The AVR contains the following three registers that deal with SPI:
 SPCR – SPI Control Register – This register is basically the
master register i.e. it contains the bits to initialize SPI and control it.
 SPSR – SPI Status Register – This is the status register. This
register is used to read the status of the bus lines.
 SPDR – SPI Data Register – The SPI Data Register is 8 bit
read/write shift register where the actual data transfer takes place.
SPI in AVR C (Master Device)
SPI in AVR C (Slave Device)
I2C
Inter-Integrated Circuit
I-Squared-C
I2C Basics
I2C (pronounced I-squared-C) created by Philips Semiconductors
(now NXP) in 1982 and commonly written as "I2C" stands for InterIntegrated Circuit and allows communication of data between I2C
devices over two wires.
It sends information serially using one line for data (SDA – Serial
DAta) and one for clock (SCL – Serial CLock).
I2C Basics
The I2C protocol defines the concept of master and slave devices. A
master device is the device that is in charge of the bus. This device
controls the clock and generates the START and STOP signals. Slave
devices listen to the commands sent by the Master and respond to
them.
Basic details:
Transfer rate: 10 Kb/s (low speed) - 100Kb/s (high speed)
SDA - Serial DAta line
SCL - Serial CLock line
128 possible addresses (7 bits)
16 reserved addresses
112 devices max
Devices have to share both 5V (Power) and GND (Ground)
Theory of Operation
Regardless of how many slave units are attached to the I2C bus, there
are only two signals connected to all of them. Consequently, there is an
additional overhead because:
 an addressing mechanism is required for the master device to
communicate with a specific slave device.
 an acknowledgement mechanism is required for such a
communication.
Theory of Operation
I2C has a master/slave protocol. The master initiates the
communication. The sequence of events are:
1. The Master device issues a start condition. This condition informs all
the slave devices to listen on the serial data line for instructions. (SDA
goes from HIGH to LOW when SCL is HIGH)
2. The Master device sends the address of the target slave device and a
read/write flag. (Flag is 1 for read and 0 for write)
3. The Slave device with the matching address responds with an
acknowledgement signal.
4. Communication proceeds between the Master and the Slave on the
data bus. Both the master and slave can receive or transmit data
depending on whether the communication is a read or write. The
transmitter sends 8-bits of data to the receiver which replies with a 1-bit
acknowledgement.
5. When the communication is complete, the master issues a stop
condition indicating that everything is done. (SDA goes from LOW to
HIGH when SCL is HIGH)
Theory of Operation
TWI (Two Wire Interface)
TWI stands for Two Wire Interface and it is identical to I²C.
The name TWI was introduced by Atmel and other companies to
avoid conflicts with trademark issues with Philips related to I²C.
TWI in Atmega328P
I2C Requires Analog Pins 4 (SDA) and 5 (SCL) and two pull-up resistors.
You can connect more than 100 Arduino's on the same 2 pins.
It's simple, reliable and easy-to-use.
Arduino TWI Library (<Wire.h>)
TWI in AVR C (Master Device)
TWI in AVR C (Slave Device)