AVR- Serial Communication


Modes of Data Transfer:

(i) Synchronous

(ii) Asynchronous 

SYNCHRONOUS TRANSMISSION- In this type the actual data is transferred BIT by BIT on the DATA line. The clock line signals the end of 1 bit and the start of another bit. When the clock line changes its level, that is when it goes HIGH from a LOW level or vice versa the data is transferred. When the CLOCK line goes HIGH it signals that a new bit is available for transfer. The "other" device which is receiving the data reads the data line at the rising edge or the falling edge of the clock depending upon our settings.

The diagram corresponds  to the transfer of the data  10010111. It corresponds  to the value of the data at  every rising edge of the  clock.

ASYNCHRONOUS TRANSMISSION - Asynchronous transmission allows data to be transmitted without the sender having to send a clock signal to the receiver. Instead, the sender and receiver must agree on timing parameters in advance and special bits are added to each word which are used to synchronize the sending and receiving units. When a word is given for Asynchronous transmissions, a bit called the "Start Bit" is added to the beginning of each word that is to be transmitted. The Start Bit is used to alert the receiver that a word of data is about to be sent, and to force the clock in the receiver into synchronization with the clock in the transmitter. One solution is to have both devices share the same clock source. 

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'. 

When the entire data word has been sent, the transmitter may add a Parity Bit that the transmitter generates. The Parity Bit may be used by the receiver to perform simple error checking. Then at least one Stop Bit is sent by the transmitter. When the receiver has received all of the bits in the data word, it may check for the Parity Bits (both sender and receiver must agree on whether a Parity Bit is to be used), and then the receiver looks for a Stop Bit.   In short, asynchronous data is 'self synchronizing'. 



Atmega16 is equipped with three different kinds of serial communication peripheral systems:
        i.            SPI (Serial Peripheral Interface)
      ii.           Serial USART
     iii.            TWI (Two wire Interface)

In SPI, data is transmitted serially, i.e. bit by bit as opposed to parallel communication where all the data is sent multiple bits at a time. We will study synchronous SPI, where there is a clock generated and the data is transferred at the rate of the clock pulse. What is clock pulse?  Clock pulse is basically a sequence of alternating 0s and 1s that is used to indicate that one Bit of data has been sent. In SPI set up when we have to set up communication between two systems, first we have make one system as master and the other as slave. The difference between master and the slave is that the clock pulse is generated by the master and both master and the slave agree to work on the clock frequency that is set up by the master.  

The basic connections in any SPI set up are as follows:

MOSI is Master Out Slave In, so it is the channel where the master sends the data to the slave and the slave receives it. 

MISO is Master In Slave Out, so it is the channel where the slave sends the data and the master receives it. 

Clock is the clock that is send by the master. 

SS is slave select when the master wants to send data to a particular slave it makes its SS pin low, sends the data and then again makes it high. It is especially useful when multiple slaves are connected to the master, but the basic purpose is to select the slave and transmitting data to it. 

In SPI, the data the data is exchanged between the transmitter and the receiver. It happens as follows: 

First the master and the slave keep the data bits to transfer in their respective registers. Suppose master wants to send bm1,bm2,bm3…..bm8 and the slave wants to send bs1, b s2, b s3 …..b s8. 

What happens is as follows:  


The data is transferred one bit at a time between the master and the slave, and at the end of 8 cycles the data is completely exchanged. 

   2. USART

Like many microcontrollers, AVR also has a dedicated hardware for serial communication. This part is called the USART - Universal Synchronous Asynchronous Receiver Transmitter. This special hardware makes your life as a programmer easier. You just have to supply the data you need to transmit and it will do the rest. The advantage of hardware USART is that you just need to write the data to one of the registers of USART and your done, you are free to do other things while USART is transmitting the byte. Also the USART automatically senses the start of transmission of RX line and then inputs the whole byte and when it has the byte it informs you (CPU) to read that data from one of its registers. 

The USART of AVR is very versatile and can be setup for various different modes as required by your application. In this tutorial we will show you how to configure the USART in a most common configuration and simply send and receive data. 


USART consists of only three connections – Rx, Tx and GND. Rx means Receive and Tx means Transmit. The GND connection is for a common reference level. 

Here’s a simple diagram explaining the connections:



USART connection with a computer is accomplished through a protocol called RS232. RS232 is an asynchronous serial communication protocol widely used in computers and digital systems. A simple example is the serial port used in old computers. One thing to note about this protocol is that, while in an MCU circuit, HIGH = 5V and LOW = 0, for RS232 the values are +12V and -12V respectively. For this conversion, an IC called MAX232 is used: 


The USART clock generator provides the clock source for the USART system and sets the baud rate for the USART. The baud rate is derived from the overall microcontroller clock source.  The overall system clock is divided by the USART baud rate registers UBRRx[H:L]  and several additional dividers to set the baud rate. for the asynchronous normal mode (U2X bit=0), the baud rate is determined using the expression: 

baud rate=(system clk freq.)/(2(UBRRx + 1))    

where UBRRx is the content of the UBRRxH and UBRRxL registers (0.4095). solving for UBRRx yields

UBRxR=((system clk freq.)/(16 X baud rate))-1



Who's new

  • ravirajpatil871...
  • shubhambajoria
  • yassir
  • demiholyman890954
  • scottgillum51169040

Get Notified



We are Social


Subscribe to Syndicate