35
SERIAL PERIPHERAL INTERFACE (SPI) By: Prof. Snehal Laddha

Serial peripheral interface SPI, I2C, ICSP

Embed Size (px)

Citation preview

Page 1: Serial peripheral interface SPI, I2C, ICSP

SERIAL PERIPHERAL INTERFACE (SPI)By: Prof. Snehal Laddha

Page 2: Serial peripheral interface SPI, I2C, ICSP

it is used to communicate data to and from the PIC microcontroller

it considered as one of the fastest serial data transfer interface for the embedded system

SPI is a synchronous protocol that allows a master device to initiate communication with a slave device

Page 3: Serial peripheral interface SPI, I2C, ICSP

Because of its special in/out register configuration, the SPI master device could transfer its data and at the same time it receive a data from the SPI slave device with the clock speed as high as 10 MHz

Page 4: Serial peripheral interface SPI, I2C, ICSP

When the SPI master device want to send the data to the SPI slave device, then the SPI master will just simply shifting its own data through a special 8-bits register and at the same time the SPI master will receive the data from the SPI slave into the same register as shown on this following picture:

Page 5: Serial peripheral interface SPI, I2C, ICSP
Page 6: Serial peripheral interface SPI, I2C, ICSP

With this circular shift register connection between the SPI master and the SPI slave devices, the complete data transfer from both devices will be accomplished in just 8 clock cycles

This means the SPI devices only need about 0.8 us to complete transfer the 8-bit data if we use 10 MHz clock

Page 7: Serial peripheral interface SPI, I2C, ICSP
Page 8: Serial peripheral interface SPI, I2C, ICSP
Page 9: Serial peripheral interface SPI, I2C, ICSP
Page 10: Serial peripheral interface SPI, I2C, ICSP

SPI creates a data loop between two devices

Data leaving the master exits on the SDO (serial data output) line Data entering the master enters on the serial data input, SDI line

A clock (SCK), is generated by the master device It controls when and how quickly data is exchanged between the

two devices SS, allows a master device to control when a particular slave is being addressed This allows the possibility of having more than one slave and

simplifies the communications. When the SS signal goes low at a slave device, only that slave is

accessed by SPI

Page 11: Serial peripheral interface SPI, I2C, ICSP

SSPSR is the shift register for the SPI module. It shifts data in and out of the device

The data travels in a loop to the next shift register

The data is shifted out the SDO pin of one device and into the SDI pin of the other

Page 12: Serial peripheral interface SPI, I2C, ICSP

Once a byte of data has been exchanged between the two devices, it is copied to the SSPBUF register. The SSPBUF is then read by the user software

If any data is to be exchanged, this register is written to by your program.

Writing to the SSPBUF will transfer the contents of SSPBUF to the SSPSR.

If this is a master device, this will initiate the data transfer.

If this is a slave device, it will wait for a clock from the master device.

Page 13: Serial peripheral interface SPI, I2C, ICSP

As 74LS395 is a 4 bit shift register so we will be able to see only four Least Significant bits

Page 14: Serial peripheral interface SPI, I2C, ICSP
Page 15: Serial peripheral interface SPI, I2C, ICSP

THE SSPCON REGISTER CONTROLS THE SPI ENGINE

Page 16: Serial peripheral interface SPI, I2C, ICSP
Page 17: Serial peripheral interface SPI, I2C, ICSP

SSPSTAT SSPSTAT stands for “Synchronous Serial

Port STATus” and provides a few bits for controlling the SPI communication

Page 18: Serial peripheral interface SPI, I2C, ICSP
Page 19: Serial peripheral interface SPI, I2C, ICSP
Page 20: Serial peripheral interface SPI, I2C, ICSP
Page 21: Serial peripheral interface SPI, I2C, ICSP
Page 22: Serial peripheral interface SPI, I2C, ICSP
Page 23: Serial peripheral interface SPI, I2C, ICSP

IN-CIRCUIT SERIAL PROGRAMMING All midrange devices can be In-Circuit

Serial Programmed (ICSP™) while in the end application circuit. This is simply done with two lines for clock and data, and three other lines for power, ground, and the programming voltage

For the vast majority of PIC micro devices, the protocol is known as In-Circuit Serial Programming

Page 24: Serial peripheral interface SPI, I2C, ICSP

The protocol allows programming functions to be multiplexed with existing device pins, avoiding the need of tying up precious I/O real estate with ports that might only be used occasionally, if at all

When the device is supplied with a normal power supply and a specific voltage on the Master Clear (MCLR) pin, a state machine built

into the core architecture takes control

Page 25: Serial peripheral interface SPI, I2C, ICSP

It accepts serial data and clock on two of the port pins and writes the information to the appropriate target memory space.

The entire process is controlled by a set of special commands that accompany the serial data stream

Page 26: Serial peripheral interface SPI, I2C, ICSP

THE ICSP HARDWARE PROTOCOL

All PIC microcontrollers are placed in Serial Programming mode by doing these three things in sequence:

1. Applying the appropriate power source and ground (VDDa nd VSS) to the device;

2. Raising the voltage on the MCLR pin to the programming voltage level (in general, around 13V), while at the same time:

3. Pulling the two designated I/O port pins to logiclow and holding them there

Page 27: Serial peripheral interface SPI, I2C, ICSP

The device is placed into a program/verify mode by holding the RB6 and RB7 pins low while raising the MCLR (VPP) pin from VIL to VIHH(see programming specification) and having VDD at the programming voltage

RB6 becomes the programming clock and RB7 becomes the programming data

Both RB6 and RB7 are Schmitt Trigger inputs in this mode, and when RB7 is driving data it is a CMOS output driver

Page 28: Serial peripheral interface SPI, I2C, ICSP

After reset, to place the device into programming/verify mode, the program counter (PC) is at location 00h

A 6-bit command is then supplied to the device. Some commands then specify that 14-bits of

program data are then supplied to or read from the device, depending on if the command was a load or a read

During the In-Circuit Serial Programming Mode, the WDT circuitry is disabled from generating a device reset

Page 29: Serial peripheral interface SPI, I2C, ICSP

I2C PROTOCOL

Page 30: Serial peripheral interface SPI, I2C, ICSP
Page 31: Serial peripheral interface SPI, I2C, ICSP
Page 32: Serial peripheral interface SPI, I2C, ICSP
Page 33: Serial peripheral interface SPI, I2C, ICSP
Page 34: Serial peripheral interface SPI, I2C, ICSP
Page 35: Serial peripheral interface SPI, I2C, ICSP