Download presentation
Presentation is loading. Please wait.
Published byEustace Ramsey Modified over 6 years ago
1
Serial Communication Originally created by Anurag Dwidedi and Rudra Pratap Suman
2
Essentials of Communication
Sender Communication Link Receiver Data This simple model requires many guarantees.
3
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.
4
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.
5
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.
6
Types of Communication Protocols
There are different ways of categorizing protocols First Categorization: Second Categorization: Serial Mode Transfer Parallel Mode Transfer Synchronous Mode Transfer Asynchronous Mode Transfer
7
Serial and Parallel Mode
SERIAL MODE SENDER RECEIVER PARALLEL MODE
8
Serial vs Parallel Mode
Parameter Reliability Speed Power Cost Complexity Range Serial Mode Parallel Mode Reliable Unreliable Slow Fast Low High High Low Long Short
9
Need of Synchronization
1 1 1 1 1 1 1 1 RECEIVER SENDER 0 0 0 0 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
10
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 1 1 SENDER CLOCK RECEIVER
11
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'.
12
Synchronous vs Asynchronous Mode
Parameter Reliability Cost Complexity Synchronous Asynchronous Reliable Error Prone Expensive Inexpensive Complicated Simple
13
Only one way transmission takes place
Transmission Modes SENDER RECEIVER Simplex Only one way transmission takes place
14
Transmission Modes SENDER RECEIVER Half-Duplex Two way transmission takes place but only one end can communicate at a time
15
Transmission Modes SENDER RECEIVER Full-Duplex Two way transmission takes place and both end can communicate simultaneously
16
UART Universal Asynchronous Receiver Transmitter
17
Asynchronous Serial Communication
With asynchronous communication, the transmitter and receiver do not share a common clock Add: Start, Stop, Parity Bits Remove: Start, Stop, Parity Bits Transmitter + – Receiver Data 1 byte-wide 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 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
18
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: baud = bits/sec If using 8-bit data, 1 start, 1 stop, and no parity bits, the effective throughput is: * 8 / 10 = bits/sec
19
Asynchronous Serial Communication
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
20
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 Transmitter Receiver Data 1 byte-wide 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 The Receiver Extracts the data using the clock provided by the transmitter Converts the serial data back to the parallel form
21
UART in Atmega328P
22
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); } }
23
SPI Serial Peripheral Interface
24
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.
25
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??
26
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)
27
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.
28
SPI Schematics: Multiple Slaves
29
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 0b ). 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.
30
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.
31
SPI in Atmega328P
32
Arduino SPI Library (<SPI.h>)
The Arduino development kit comes with an SPI library. To use it you just need to include it: #include <SPI.h> 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. İki Arduino’yu SPI protokolü ile iletişime geçirebilmek için Master ve Slave cihazlar için ayrı kodlar yazıp yüklemelisiniz.
33
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.
34
SPI in AVR C (Master Device)
35
SPI in AVR C (Slave Device)
36
I2C Inter-Integrated Circuit I-Squared-C
37
I2C Basics I2C (pronounced I-squared-C) created by Philips Semiconductors (now NXP) in 1982 and commonly written as "I2C" stands for Inter-Integrated 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).
38
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)
39
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.
40
Theory of Operation I2C has a master/slave protocol. The master initiates the communication. The sequence of events are: 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) 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) The Slave device with the matching address responds with an acknowledgement signal. 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. 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)
41
Theory of Operation
42
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.
43
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.
44
Arduino TWI Library (<Wire.h>)
46
TWI in AVR C (Master Device)
47
TWI in AVR C (Slave Device)
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.