0% found this document useful (0 votes)
6 views

Communication Protocols - Practicals

This document summarizes three common communication protocols: UART, I2C, and SPI. UART uses two wires for serial communication between devices, converting data to packets. I2C allows multiple master/slave devices on a bus using device addresses. SPI uses four connections in a master-slave configuration with a serial clock for synchronous transfers. The document provides examples of initializing and using each protocol with an Arduino, including configuring baud rates, reading/writing data, and transferring data on the bus.

Uploaded by

iveynesh5
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

Communication Protocols - Practicals

This document summarizes three common communication protocols: UART, I2C, and SPI. UART uses two wires for serial communication between devices, converting data to packets. I2C allows multiple master/slave devices on a bus using device addresses. SPI uses four connections in a master-slave configuration with a serial clock for synchronous transfers. The document provides examples of initializing and using each protocol with an Arduino, including configuring baud rates, reading/writing data, and transferring data on the bus.

Uploaded by

iveynesh5
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 20

Communication Protocols

Practical
Vimukthi Pathirana
MEng. (AIT), BSc (Hons) Eng. (AIT)
Content
UART

I2C

SPI
What is UART?
• Universal Asynchronous Receiver/Transmitter

• Hardware device used for serial communication between two devices


How UART works?
• One wire is for transmitting data (Tx pin)
• Other is for receiving data (Rx pin)

• UART convert data into packets for sending or rebuilding data from
packets received
How UART works?
• Data Packet

• What is the use of Parity Bit?


• What is the use of UART buffer?
• Can data loss occur? If so, how?
ARDUINO UART Interface
ARDUINO UART Interface
• Serial.begin(VALUE); - initialize UART
• VALUE – baud rate (generally 9600 bps)

• Serial.available(); - check if data waiting to read in buffer

• Serial.read(); - read data waiting in buffer

• Serial.write(VALUE); - send data via Tx pin


• VALUE – byte to be sent
ARDUINO UART Interface Example
ARDUINO UART Interface Example
What is I2C?
• Inter-Integrated Circuit

• Low speed serial communication protocol


used for transferring data over short
distances

• Consists of a master device and slave device

• Can have multiple master and slave devices?


How I2C works?
• Each slave device has an I2C address – used to identify

• Can master device send and receive data?

• Slave device responds to whatever master device sends

• Can only one device send data at a time?


ARDUINO I2C Network
ARDUINO I2C Network
• Sending data over I2C
• Wire.beginTransmission()
• Wire.write()
• Wire.endTransmission()

• Receiving data over I2C


• Wire.requestForm()
• Wire.available()
• Wire.read()
ARDUINO I2C Example
• Follow the example given in the link bellow
https://www.circuitbasics.com/how-to-set-up-i2c-communication-for-arduino/
What is SPI?
• Serial Parallel Interface

• Type of synchronous serial communication – data transfer is timed


with cock pulses.

• Short range – less than 10 meters


How SPI works?
• Consists of one master and one or more slave devices

• Each master and slave device has four connections


• MOSI – Master out Slave In
• MISO – Master In Slave Out
• SCLK - Serial Clock
• SS/CS – Slave Select/Chip Select
SPI Configurations
Independent Slave Configuration DAISY Chain Configuration
ARDUINO SPI Network
ARDUINO SPI Network
• Using SPI protocol in Arduino - <SPI.h>

• SPI.begin()

• SPI.setClockDivider(divider)
• Divider – 2, 4, 8, 16, 32, 64, 128

• SPI.attachInterrupt(handler)

• SPI.transfer(val)
ARDUINO SPI Network
• Follow the example given in the link bellow
https://circuitdigest.com/microcontroller-projects/arduino-spi-communication-tutorial

You might also like