electroSome

PIC to PIC Communication using UART

PIC16F877A

Introduction

PIC to PIC communication will be needed in some embedded applications. We have two options to transmit data through transmission lines.

Parallel Transmission

Parallel Data Transmission

In parallel communication an entire byte of data is transmitted at a time. That is each bit has dedicated line. Thus for 8-bit data transfer we need 8 dedicated lines as shown above.

Serial Transmission

Serial Data Transmission

In Serial Transmission only one bit of a byte is transmitted at a time. There is only one communication line, thorough which bits are transmitted sequentially.

Data can be transmitted using Parallel or Serial techniques, as the pros and cons of two methods are equal and the selection depends on application. Parallel Transmission is very fast compared to serial transmission, as it transmits a byte at a time. Serial Transmission is cost effective as compared to Parallel Transmission as it requires only one line for transmission.

Transmission Systems are also classified into 2 on the basis of transmission synchronization.

Need for Synchronization

When an electronic device transmits data to other there must be certain synchronization between them, ie the receiving device must have a way to know the beginning and end of each unit (byte) of data.

Synchronous Transmission

Synchronous Transmission are synchronised using a clock line, ie the communications are time synchronised. An external clock line is also used along with data line to synchronize transmission and reception ends.

Asynchronous Transmission

There is no separate clock line in this system. Transmitter and Receiver works on separate clocks. Start and Stop bits are also send along with data to identify start and end of a byte.

We can transmit data in three ways.

Simplex

Simplex Transmission

In Simplex Transmission, data is transmitted only in one direction.

Half Duplex

Half Duplex Transmission

In Half Duplex Transmission, data can be transmitted in both directions but to one side at a time.

Full Duplex

Full Duplex Transmission

In Full Duplex Transmission data can be transmitted simultaneously in two directions.

USART – Universal Synchronous Asynchronous Receiver Transmitter

USART is the most commonly used serial I/O module. It is also known as Serial Communications Interface (SCI). USART can be easily configured as a full-duplex asynchronous communication system that can communicate with peripheral devices, such as personal computers and CRT terminals, or it can be configured as a half-duplex synchronous communication system that can communicate with peripheral devices, such as serial EEPROMs,  A/D or D/A integrated circuits, etc. USART can be configured in the following modes.

We don’t want to bother about configuring USART registers as MikroC Pro for PIC Microcontrollers have built-in library function to handle asynchronous communication.

Circuit Diagram

PIC to PIC Communication using USART

The above circuit can demonstrate the PIC to PIC  Communication using USART. Here we are using Asynchronous communication. The switch status read by the first PIC is transmitted to the second PIC and displayed using LED’s.

MikroC Code

 Transmitter

void main()
{
  TRISB = 0xFF;
  PORTB = 0;
  UART1_Init(9600); // Initialize UART module at 9600bps
  Delay_ms(100); // Wait for UART module to stabilize
  while (1)
  { // Endless loop
    UART1_Write(PORTB); // and send data via UART
    Delay_ms(500);
  }
}

Receiver

void main() 
{
  TRISB = 0;
  PORTB = 0;
  UART1_Init(9600); // Initialize UART module at 9600bps
  Delay_ms(100); // Wait for UART module to stabilize
  while (1) 
  { // Endless loop
    if (UART1_Data_Ready()) 
    { // If data is received,
      PORTB = UART1_Read(); // read the received data,
    }
   }
}

Download Here

You can download MikroC files and Proteus files here..
PIC to PIC Communication using UART