Serial peripheral interface SPI, I2C, ICSP

Preview:

Citation preview

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

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

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

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:

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

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

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

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.

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

THE SSPCON REGISTER CONTROLS THE SPI ENGINE

SSPSTAT SSPSTAT stands for “Synchronous Serial

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

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

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

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

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

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

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

I2C PROTOCOL

Recommended