Summary of Lecture 45 : PIC Serial Communication using Serial Peripheral Interface (SPI)
This project establishes SPI serial communication between two PIC16F877A microcontrollers. The master microcontroller reads an 8-bit digital input from Port B and transmits it via SPI to the slave microcontroller. Using SPI lines (SDO, SDI, SCK), the slave receives the data and outputs it to its Port B. The communication is configured through the SSPCON register, enabling SPI mode with appropriate clock settings. The process uses interrupts on the slave side to handle incoming data and continuously repeats transmission on the master side.
Parts used in the PIC16F877A SPI Serial Communication Project:
- PIC16F877A microcontroller (master)
- PIC16F877A microcontroller (slave)
- Digital input source (connected to Port B of master)
- Wiring for Serial Data Out (SDO) line
- Wiring for Serial Data In (SDI) line
- Wiring for Serial Clock (SCK) line
- Power supply for PIC microcontrollers
Objective
To establish serial communication between two PIC16F877A microcontrollers
Description |
In this experiment, 8-bit digital input is applied at Port-B to one of the PIC16F877A microcontroller which acts as a master in serial communication. The input value is transmitted by the master serially via Serial Peripheral Interface (SPI) to the second PIC16F877A microcontroller, which acts as a slave. The slave then outputs the value to its Port-B. Following three lines are used for serial communication |
|
The SDO for master acts as SDI for slave and vice-versa. Serial clock is invariably provided by the master. The SPI communication settings are done using SSPCON register.
|
Transmission is initiated by the Master by writing to the SSPBUF register. When transfer is complete, Synchronous Serial Port Interface Flag (SSPIF) will be set. This can cause an interrupt if peripheral interrupt is enabled. |
Assembly Code
|
|
Mainline: |
|
|
|
|
Mainline: bsf STATUS, RP0 ; Bank 1
|
loop: goto loop ; Infinite loop |
|
For more detail: Lecture 45 PIC Serial Communication using Serial Peripheral Interface (SPI) Schematic