Panel Cookies
Serial communications

Help me by sharing this post



PREVIOUS TUTORIAL       NEXT PART

In this page and video you will see the main differences between 3 protocols of serial communication, UART, i2c and SPI. Serial communication is the most widely used communication methodology as far as embedded systems are concerned. Before talking about types of serial protocols used in embedded industry and comparing them, let us first see what a serial communication is.




PART 1 - What is Serial Communication?

As its name suggests, in this kind of communication data is transferred serially (one after another) and not parallel (everything together). So as expected, a serial communication can be done using fewer wires as compared to its parallel counterpart and it also needs some sort of syncing mechanism (clock) to make a successful communication.

serial communication and parallel differences

In Serial Communication, only communication is done serially rest everything, like processing of the data etc., happens in a parallel fashion i.e. in form of registers. Serial communication can be further categorized into synchronous and asynchronous type. Synchronous serial communication: In this type of communication both transmitter and receiver share a common clock to remain in sync with each other. Asynchronous serial communication: This type of serial communication does not require any common clock source between the transmitter and receiver, both the sides work according to their independent clocks. Types of Serial Communication Protocols: There are various types of serial communication protocols being used in embedded industry. Let us discuss them here:



PART 2 - SPI (Serial Peripheral Interface)

This is a synchronous type serial communication protocol which consists of two data lines (MOSI and MISO), one clock line (SCK) and a slave select line (SS). Before moving ahead here are some terms that you should be aware of:

Master – Device which provides clock for communication
Slave – Device other than master which utilises master’s clock to communicate
MOSI – Master Out Salve In (line though which master sends data to its slaves)
MISO – Master In Slave Out (line though which salves responds back to the master)
SCK – Serial Clock (clock provided by master device)
SS – Slave Select (line used to select slave to which master wants to communicate)

In a SPI, at any given time there could be only one master device and several other slaves under it who only respond to master’s call. The entire communication is handled by master itself; no slave can send data on its own will. Master sends data via MOSI while slaves respond via MISO line. In the entire process SCK (serial clock) plays a very important role, every slave device depends on this clock to read data from MOSI and respond through MISO. SS (slave select) is used to make a particular slave awake with who master wants to communicate. Here is an illustration of SPI:


SPI protocol theory how Arduino

Now there are few register which are used to implement SPI communication. We have these below and as you can se we have SPDR, SPSR and SPCR so let's see each one.

SPDR (SPI Data Register)
➢ This is used to store one byte of data which is to be transferred or received.
SPSR (SPI Status Register)
➢ This register holds the status bits involved in SPI communication
SPCR (SPI Control Register)
➢ This register holds the control bits involved in SPI communication.
All the above registers are 8 bit in length.


Advantages:
1. Provides synchronous serial communication which is much more reliable over asynchronous
2. Multiple devices(Slaves) can be connected to single master
3. Faster form of serial communication

Disadvantages:
1. Requires multiple slave select wires for connecting multiple slaves
2. Only master has control over entire communication process; no two slaves can communicate with each other directly




PART 3 - I2C (Inter-Integrated Circuit) or Two Wire Interface

Another very useful synchronous serial communication protocol is I2C or Inter-Integrated Circuit protocol. Unlike SPI, I2C uses only two wires for the entire process, maybe that’s why it is also known as Two Wire Interface (TWI) protocol. These two wires are SDA (Serial Data) and SCL (Serial Clock). I2C protocol can support multiple slave devices but unlike SPI, which only supports one master device, I2C can support multiple master devices as well. Every device sends/receives data using only one wire which is SDA. SCL maintains sync between devices through common clock which is provided by the active master.


i2c protocol theory how Arduino

Each slave has its own unique 7 to 10 bit address which master uses to identify them. Whenever master wants to send data it first generates a request which has particular address of that slave. Every slave matches this address with its own and the one whose address gets matched responds to the master. Every message initiates with a start condition and ends with a stop condition. A single message can hold multiple data bytes, each having an acknowledge (ACK) or negative acknowledge (NACK) bit in between them.

Pull-up resistors with SDA and SCL are necessary in order to run this protocol.
Advantages:
1. Multiple masters and multiple slaves can be interfaced together
2. Only two wires are required for this communication

Disadvantages:
1. It is slower as compared to SPI because a lot of framing work is done within this protocol




PART 4 - UART/USART

UART stands for Universal Asynchronous Receiver and Transmitter while USART stands for Universal Synchronous and Asynchronous Receiver and Transmitter. The difference between them is that UART performs only asynchronous serial communication while USART can perform both synchronous as well as asynchronous serial communication process.

For Asynchronous mode, this protocol makes use of only two wires i.e. Rx and TX. Since no clock is needed here, both the devices have to make use of their independent internal clocks to work. Yet there is a term called baud rate which helps these devices to remain in sync by fixing the speed of data exchange. Baud rate refers to the number of data bits transmitted per second, so both devices should work on same baud rate in order to maintain its proper functioning. UART/USART has a big limitation that only two devices can communicate using this protocol at once. TX pin of one device transmits data to the RX pin of another device and similarly TX of latter transmits data to RX of former device. This is how exchange of data takes place. *Note: Both the communicating devices should have a common ground (GND).


UART protocol theory how Arduino

Advantages:
1. Provides both synchronous as well as asynchronous serial communication
2. Availability of various baud rates making it suitable for wide applications and devices
3. One of the easiest form of serial communication

Disadvantages:
1. Can connect only two devices at a time

Conclusion
Use SPI when you have only one master and multiple slave devices. SPI proves to be a faster protocol for this. When you have multiple master devices as well, apart from multiple slave devices, then one should prefer using I2C or TWI over SPI. This will also reduce the number of wires to be used. Now if you are looking for a device to device serial communication then USART/UART proves itself the best as it is easy to deal with and widely used in many peripheral devices.







Help me by sharing this post












yt_link
insta_link
fb_link
twitter_link

Serial communications
page 1/1



ADVERTISERS



PCBWAY PCB service





Curso Arduino Online nivel bajo