SPI communication between PICs

From Mech
Revision as of 14:08, 6 February 2008 by SamPickerill (Talk | contribs)
Jump to: navigation, search

Contents

Original Assignment

Microcontrollers commonly talk to each other using protocols such as RS-232, SPI (for "serial peripheral interface"), I2C (or I^2C, "I squared C," for inter-integrated circuit), CAN bus, or other. This project is to demonstrate bidirectional SPI communication between two PICs. A demonstration might have the value of an analog input (potentiometer) at one PIC displayed as a "light bar" on the LEDs of the other PIC board, and simultaneously vice-versa.

Overview

SPI is a communication method that was once used to connect devices such as printers, cameras, scanners, etc. to a desktop computer. This function has now been taken over by USB, however SPI can still be a useful communication tool for some applications. SPI runs as a master slave set-up and can run in full duplex mode, meaning that signals from the master to the slave and vis versa can be transferred at the same time. SPI involves four lines, and is therefore often termed the “four wire” serial bus. The four lines are: • SCLK — Serial Clock (output from master) • MOSI/SIMO — Master Output, Slave Input (output from master) • MISO/SOMI — Master Input, Slave Output (output from slave) • SS — Slave Select(active low; output from master) The Master controls all communication. It starts the clock, decides when data is sent and received and selects the slaves to communicate with (SS line). Within each clock cycle a full duplex communication is carried out. Each bit is shuffled into the slave line and a bit is shuffled from the slave line back to the master line. The SS line selects the slave to transfer data with. Multiple slaves may be selected with an output low. If a slave is not selected they must disregard signals sent by the master. Although possible it is rare for a multi-master system. The master first sends logic low to select the slave. There is no general protocol for the transmission. The slave can then either just receive or receive and reply to the Master. The Master can also either just send data or send and receive data.

Circuit

Code

Personal tools