Está en la página 1de 24

10/14/2012

Serial Peripheral Interface (SPI) is frequently used when few I/O lines are available, but communication between two or more devices must be fast and easy to implement.

10/14/2012

10/14/2012

SPI Bus Interface


The SPI interface has four signal lines: MOSI, MISO, SCLK, and SS. MOSI (Master Output, Slave Input) MOSI line is used to transfer data from master to slave. MISO (Master Input, Slave Output) MISO line is used to transfer data from slave to master. SCLK (Serial Clock) SCLK clock pulse output from the master and clock pulse input for the slave. The SCLK line is used to synchronize data transfer between master and slave devices via MOSI and MISO lines. SS (Slave Select) The SPI master device uses this line to select the SPI slave. SS is an active low line. The data is transferred bit by bit, starting with the high bit. The slave must be in high-impedance state if the slave is not selected through the SS line.

10/14/2012

SPI Operation Modes SPI Full Duplex Mode


In full duplex mode SPI master device simultaneously transmits data to a slave and receives data from a slave. This way only a single slave device can be engaged at one time. An SS line is used to select the particular SPI slave device.

www.diolan.com

SPI Half Duplex Mode (Single Read)


In half duplex single read mode SPI master device only receives data from a slave. This way only a single slave device can be engaged at one time. An SS line is used to select the slave device.

10/14/2012

SPI Half Duplex Mode (Single Write)


In half duplex single write mode SPI master device only transmits data to a slave, and doesn't receive any data from the slave. This way simultaneous operation with several slave devices is possible.

10/14/2012

10/14/2012

SPI Transfer Modes


SPI interface allows to transmit and receive data simultaneously on two lines (MOSI and MISO). Clock polarity (CPOL) and clock phase (CPHA) are the main parameters that define a clock format to be used by the SPI bus. Depending on CPOL parameter, SPI clock may be inverted or noninverted. CPHA parameter is used to shift the sampling phase. - If CPHA=0 the data are sampled on the leading (first) clock edge. - If CPHA=1 the data are sampled on the trailing (second) clock edge, regardless of whether that clock edge is rising or falling.

CPOL parameter, SPI clock may be inverted or non-inverted. - If CPHA=0 the data are sampled on the leading (first) clock edge. - If CPHA=1 the data are sampled on the trailing (second) clock edge, regardless of whether that clock edge is rising or falling.

CPOL=0, CPHA=0

The data must be available before the first clock signal rising. The clock idle state is zero. The data on MISO and MOSI lines must be stable while the clock is high and can be changed when the clock is low. The data is captured on the clock's low-to-high transition and propagated on high-to-low clock transition.

10/14/2012

CPOL parameter, SPI clock may be inverted or non-inverted. - If CPHA=0 the data are sampled on the leading (first) clock edge. - If CPHA=1 the data are sampled on the trailing (second) clock edge, regardless of whether that clock edge is rising or falling.

CPOL=0, CPHA=1

The first clock signal rising can be used to prepare the data. The clock idle state is zero. The data on MISO and MOSI lines must be stable while the clock is low and can be changed when the clock is high. The data is captured on the clock's high-tolow transition and propagated on low-to-high clock transition.

CPOL parameter, SPI clock may be inverted or non-inverted. - If CPHA=0 the data are sampled on the leading (first) clock edge. - If CPHA=1 the data are sampled on the trailing (second) clock edge, regardless of whether that clock edge is rising or falling.

CPOL=1, CPHA=0

The data must be available before the first clock signal falling. The clock idle state is one. The data on MISO and MOSI lines must be stable while the clock is low and can be changed when the clock is high. The data is captured on the clock's high-to-low transition and propagated on low-to-high clock transition.

10/14/2012

CPOL parameter, SPI clock may be inverted or non-inverted. - If CPHA=0 the data are sampled on the leading (first) clock edge. - If CPHA=1 the data are sampled on the trailing (second) clock edge, regardless of whether that clock edge is rising or falling.

CPOL=1, CPHA=1

The first clock signal falling can be used to prepare the data. The clock idle state is one. The data on MISO and MOSI lines must be stable while the clock is high and can be changed when the clock is low. The data is captured on the clock's low-to-high transition and propagated on high-tolow clock transition.

Synchronous Serial Port (SSP) module.

10/14/2012

In the PICmicro device, a module is used for the SPI protocol. This module is named the SSP or MSSP module and allows SPI or I2C to be implemented. SPI and I2C are both synchronous serial protocols, and hence the name of the SSP module. SSP stands for Synchronous Serial Port. If you want to use SPI ensure your PICmicro device has this port. Check the product line card or the device datasheet to ensure it has an SSP or MSSP module. The M is MSSP stands for Master and relates to how it handles I2C data. It does not affect its SPI performance, so either a MSSP or SSP module can be used for SPI.

Advantages of the SPI interface

Very fast > 10Mhz. Supports full duplex data streaming.

10

10/14/2012

11

10/14/2012

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.

12

10/14/2012

13

10/14/2012

An overflow error occurs whenever an SPI transfer finishes, but the previous data had not been read from the SSPBUF. If SSPOV is set, it must be cleared by the user program. The user program should check to ensure SSPOV remains clear. This is part of good error checking in program design. Note, data in the SSPBUF will not be updated until the overflow condition is cleared.

14

10/14/2012

15

10/14/2012

16

10/14/2012

17

10/14/2012

18

10/14/2012

19

10/14/2012

20

10/14/2012

21

10/14/2012

22

10/14/2012

23

10/14/2012

RS232 - SPI Interface


http://www.gedanken.demon.co.uk/rs232-converters/spi.html

ZIO-USB
Interface SPI devices, I2C devices, motors, sensors to a PC. ZIO comes with an API that can be used to access the IO interfaces provided by the motherboard, from the PC.

24

También podría gustarte