SPI 4-Wire 3-Wire - Atomic Rhubarb SPI.pdf · • The Enhanced Serial Peripheral Interface (SPI) is...

56
SPI 4-Wire 3-Wire

Transcript of SPI 4-Wire 3-Wire - Atomic Rhubarb SPI.pdf · • The Enhanced Serial Peripheral Interface (SPI) is...

Page 1: SPI 4-Wire 3-Wire - Atomic Rhubarb SPI.pdf · • The Enhanced Serial Peripheral Interface (SPI) is a synchronous interface allowing several SPI-type devices to be interconnected.

SPI 4-Wire3-Wire

Page 2: SPI 4-Wire 3-Wire - Atomic Rhubarb SPI.pdf · • The Enhanced Serial Peripheral Interface (SPI) is a synchronous interface allowing several SPI-type devices to be interconnected.

Real Time Embedded Systems

www.atomicrhubarb.com/embeddedLecture 1 – January 17, 2012

Topic

Page 3: SPI 4-Wire 3-Wire - Atomic Rhubarb SPI.pdf · • The Enhanced Serial Peripheral Interface (SPI) is a synchronous interface allowing several SPI-type devices to be interconnected.

Section Topic

• Where in the books– Catsoulis chapter/page– Simon chapter/page– Zilog UM197 (ZNEO Z16F Series Flash Microcontroller Contest Kit User Manual)

– Zilog UM171 (ZiLOG Developer Studio II—ZNEO User Manual)

– Zilog PS220 (ZNEO Z16F Series Product Specification)

– Zilog UM188 (ZNEO CPU Core User Manual)

– Assorted datasheets

Page 4: SPI 4-Wire 3-Wire - Atomic Rhubarb SPI.pdf · • The Enhanced Serial Peripheral Interface (SPI) is a synchronous interface allowing several SPI-type devices to be interconnected.
Page 5: SPI 4-Wire 3-Wire - Atomic Rhubarb SPI.pdf · • The Enhanced Serial Peripheral Interface (SPI) is a synchronous interface allowing several SPI-type devices to be interconnected.

Synchronous Serial Buses

1-wire 2-wire 3-wire 4-wire

… but not in this order

Page 6: SPI 4-Wire 3-Wire - Atomic Rhubarb SPI.pdf · • The Enhanced Serial Peripheral Interface (SPI) is a synchronous interface allowing several SPI-type devices to be interconnected.

Serial Buses

Communication between components Typically between integrated circuit components CPU to peripherals

Typically short distances (at least that was the plan)

Number of wires = number of SIGNAL wires Power & ground not included in the counting

Usually synchronous (data on one line and clock on another)

Lots of variety, lots of similarity.

Page 7: SPI 4-Wire 3-Wire - Atomic Rhubarb SPI.pdf · • The Enhanced Serial Peripheral Interface (SPI) is a synchronous interface allowing several SPI-type devices to be interconnected.

The nice thing about standards is that there are so many of them to choose from.

- Andrew Tannenbaum (or was it Grace Hopper)

Page 8: SPI 4-Wire 3-Wire - Atomic Rhubarb SPI.pdf · • The Enhanced Serial Peripheral Interface (SPI) is a synchronous interface allowing several SPI-type devices to be interconnected.

Why so many?

• 1,2,3,4 wire?

Page 9: SPI 4-Wire 3-Wire - Atomic Rhubarb SPI.pdf · • The Enhanced Serial Peripheral Interface (SPI) is a synchronous interface allowing several SPI-type devices to be interconnected.

Why so many?

4-wire – SPI – Motorola 3-wire – Maxim IC

Microwire – National Semiconductor 2-wire – I2C – Phillips Semiconductor 1-wire – Dallas Semiconductor

SensorPath – National SemiconductorUNI/O - Microchip

Page 10: SPI 4-Wire 3-Wire - Atomic Rhubarb SPI.pdf · • The Enhanced Serial Peripheral Interface (SPI) is a synchronous interface allowing several SPI-type devices to be interconnected.

SPI (4 wire)

Serial Peripheral Interface 4 wires (really 3 + 1 for each device) Low Cost Simple Intended for CPU to Peripheral

communication and control. Defined by Motorola.

Page 11: SPI 4-Wire 3-Wire - Atomic Rhubarb SPI.pdf · • The Enhanced Serial Peripheral Interface (SPI) is a synchronous interface allowing several SPI-type devices to be interconnected.

SPI Specification

The Specification is hidden inside the HC08 microcontroller data sheets

Motorola Semiconductor is now Freescale Semiconductor.

Defines 4 signals

Page 12: SPI 4-Wire 3-Wire - Atomic Rhubarb SPI.pdf · • The Enhanced Serial Peripheral Interface (SPI) is a synchronous interface allowing several SPI-type devices to be interconnected.

SPI Signals

SCLK – Serial Clock MISO – Master In, Slave Out MOSI – Master Out, Slave In SS – Slave Select

Based on shifting data between 2 shift registers.

Page 13: SPI 4-Wire 3-Wire - Atomic Rhubarb SPI.pdf · • The Enhanced Serial Peripheral Interface (SPI) is a synchronous interface allowing several SPI-type devices to be interconnected.

Whats a shift register?

Page 14: SPI 4-Wire 3-Wire - Atomic Rhubarb SPI.pdf · • The Enhanced Serial Peripheral Interface (SPI) is a synchronous interface allowing several SPI-type devices to be interconnected.

Shift Register

A cascade of flip flops sharing the same clock. The output of any one but the last flip-flop connected to the input of the next one in the chain. Resulting in a circuit that shifts by one position the one-dimensional "bit array" stored in it.

Page 15: SPI 4-Wire 3-Wire - Atomic Rhubarb SPI.pdf · • The Enhanced Serial Peripheral Interface (SPI) is a synchronous interface allowing several SPI-type devices to be interconnected.

SPI Signals

• Swap 2 bytes, 1 bit at at time using the BRG as our serial clock.

Page 16: SPI 4-Wire 3-Wire - Atomic Rhubarb SPI.pdf · • The Enhanced Serial Peripheral Interface (SPI) is a synchronous interface allowing several SPI-type devices to be interconnected.

• Multiple chips can beconnected to the master.

• Individual SS wires are necessary to select theone we want to talk to.

Page 17: SPI 4-Wire 3-Wire - Atomic Rhubarb SPI.pdf · • The Enhanced Serial Peripheral Interface (SPI) is a synchronous interface allowing several SPI-type devices to be interconnected.

SPI Modes

4 timing modes Based on clock polarity and clock

phase.

Page 18: SPI 4-Wire 3-Wire - Atomic Rhubarb SPI.pdf · • The Enhanced Serial Peripheral Interface (SPI) is a synchronous interface allowing several SPI-type devices to be interconnected.
Page 19: SPI 4-Wire 3-Wire - Atomic Rhubarb SPI.pdf · • The Enhanced Serial Peripheral Interface (SPI) is a synchronous interface allowing several SPI-type devices to be interconnected.
Page 20: SPI 4-Wire 3-Wire - Atomic Rhubarb SPI.pdf · • The Enhanced Serial Peripheral Interface (SPI) is a synchronous interface allowing several SPI-type devices to be interconnected.

Timing

It is common to see a reference to the SPI mode as CKPOL = 0, PHASE = 0

This is by far the most common SPI transfer.

Page 21: SPI 4-Wire 3-Wire - Atomic Rhubarb SPI.pdf · • The Enhanced Serial Peripheral Interface (SPI) is a synchronous interface allowing several SPI-type devices to be interconnected.

SPI data

Is device specific Some need a single byte Some need multiple bytes Reads follow writes A dummy write is necessary to initiate

a read.

Page 22: SPI 4-Wire 3-Wire - Atomic Rhubarb SPI.pdf · • The Enhanced Serial Peripheral Interface (SPI) is a synchronous interface allowing several SPI-type devices to be interconnected.

What?

• A dummy write is necessary to initiate a read.

Page 23: SPI 4-Wire 3-Wire - Atomic Rhubarb SPI.pdf · • The Enhanced Serial Peripheral Interface (SPI) is a synchronous interface allowing several SPI-type devices to be interconnected.

To read THIS data we need to write something (anything) to shift the slave data to the master.

Page 24: SPI 4-Wire 3-Wire - Atomic Rhubarb SPI.pdf · • The Enhanced Serial Peripheral Interface (SPI) is a synchronous interface allowing several SPI-type devices to be interconnected.

What if...• ... I only have• one SS pin?

?

Page 25: SPI 4-Wire 3-Wire - Atomic Rhubarb SPI.pdf · • The Enhanced Serial Peripheral Interface (SPI) is a synchronous interface allowing several SPI-type devices to be interconnected.

SPI Devices

IO Expanders Clocks Temperature Sensors Non-volatile memory ... lots of things.

Page 26: SPI 4-Wire 3-Wire - Atomic Rhubarb SPI.pdf · • The Enhanced Serial Peripheral Interface (SPI) is a synchronous interface allowing several SPI-type devices to be interconnected.
Page 27: SPI 4-Wire 3-Wire - Atomic Rhubarb SPI.pdf · • The Enhanced Serial Peripheral Interface (SPI) is a synchronous interface allowing several SPI-type devices to be interconnected.

ESPI on the ZNEO

Enhanced Serial Peripheral Interface

Page 28: SPI 4-Wire 3-Wire - Atomic Rhubarb SPI.pdf · • The Enhanced Serial Peripheral Interface (SPI) is a synchronous interface allowing several SPI-type devices to be interconnected.

ESPI• The Enhanced Serial Peripheral Interface (SPI) is a synchronous

interface allowing several SPI-type devices to be interconnected. SPI-compatible devices include EEPROMs, Analog-to-Digital Converters, and ISDN devices. Features of the SPI include:

• Full-duplex, synchronous, character-oriented communication• Four-wire interface• Data transfers rates up to a maximum of one-fourth the system

clock frequency• Error detection• Write and mode collision detection• Dedicated Baud Rate Generator

Page 29: SPI 4-Wire 3-Wire - Atomic Rhubarb SPI.pdf · • The Enhanced Serial Peripheral Interface (SPI) is a synchronous interface allowing several SPI-type devices to be interconnected.

ESPI Pins

• PC2 - /SS• PC3 - SCK• PC4 - MOSI• PC5 - MISO

Page 30: SPI 4-Wire 3-Wire - Atomic Rhubarb SPI.pdf · • The Enhanced Serial Peripheral Interface (SPI) is a synchronous interface allowing several SPI-type devices to be interconnected.

ESPI Block Diagram

Page 31: SPI 4-Wire 3-Wire - Atomic Rhubarb SPI.pdf · • The Enhanced Serial Peripheral Interface (SPI) is a synchronous interface allowing several SPI-type devices to be interconnected.

What was that thing we could do to access multiple

SPI devices with onlyONE /SS pin?

Page 32: SPI 4-Wire 3-Wire - Atomic Rhubarb SPI.pdf · • The Enhanced Serial Peripheral Interface (SPI) is a synchronous interface allowing several SPI-type devices to be interconnected.
Page 33: SPI 4-Wire 3-Wire - Atomic Rhubarb SPI.pdf · • The Enhanced Serial Peripheral Interface (SPI) is a synchronous interface allowing several SPI-type devices to be interconnected.
Page 34: SPI 4-Wire 3-Wire - Atomic Rhubarb SPI.pdf · • The Enhanced Serial Peripheral Interface (SPI) is a synchronous interface allowing several SPI-type devices to be interconnected.

ESPI

Several Modes Master controller of a single device Slave Device Master controller of multiple devices

Page 35: SPI 4-Wire 3-Wire - Atomic Rhubarb SPI.pdf · • The Enhanced Serial Peripheral Interface (SPI) is a synchronous interface allowing several SPI-type devices to be interconnected.

ESPI Registers

ESPIDATA – Byte to be transmitted or byte received

ESPITDCR – Transmit Data Command Register ESPICTL – Configuration register ESPISTAT – Status Register ESPISTATE – State register ESPIMODE – More configuration ESPIBRH/L – Baud Rate

Page 36: SPI 4-Wire 3-Wire - Atomic Rhubarb SPI.pdf · • The Enhanced Serial Peripheral Interface (SPI) is a synchronous interface allowing several SPI-type devices to be interconnected.

ESPIDATA

Page 37: SPI 4-Wire 3-Wire - Atomic Rhubarb SPI.pdf · • The Enhanced Serial Peripheral Interface (SPI) is a synchronous interface allowing several SPI-type devices to be interconnected.

ESPICTL

Page 38: SPI 4-Wire 3-Wire - Atomic Rhubarb SPI.pdf · • The Enhanced Serial Peripheral Interface (SPI) is a synchronous interface allowing several SPI-type devices to be interconnected.
Page 39: SPI 4-Wire 3-Wire - Atomic Rhubarb SPI.pdf · • The Enhanced Serial Peripheral Interface (SPI) is a synchronous interface allowing several SPI-type devices to be interconnected.
Page 40: SPI 4-Wire 3-Wire - Atomic Rhubarb SPI.pdf · • The Enhanced Serial Peripheral Interface (SPI) is a synchronous interface allowing several SPI-type devices to be interconnected.

SPISTAT

Page 41: SPI 4-Wire 3-Wire - Atomic Rhubarb SPI.pdf · • The Enhanced Serial Peripheral Interface (SPI) is a synchronous interface allowing several SPI-type devices to be interconnected.
Page 42: SPI 4-Wire 3-Wire - Atomic Rhubarb SPI.pdf · • The Enhanced Serial Peripheral Interface (SPI) is a synchronous interface allowing several SPI-type devices to be interconnected.

SPIMODE

Page 43: SPI 4-Wire 3-Wire - Atomic Rhubarb SPI.pdf · • The Enhanced Serial Peripheral Interface (SPI) is a synchronous interface allowing several SPI-type devices to be interconnected.

SPIBRH,L

Page 44: SPI 4-Wire 3-Wire - Atomic Rhubarb SPI.pdf · • The Enhanced Serial Peripheral Interface (SPI) is a synchronous interface allowing several SPI-type devices to be interconnected.

SPI recipe

SPI

1. Configure SPI pins (alternate function)2. Configure ESPISTL (phase, pol, etc)3. Configure ESPIMODE (ssio, etc)4. Set ESPI BRG5. Write the spi_read functions **6. Write the spi_write functions **7. Write device specific functions8. Configure interrupts if desired9. Write Interrupt Service Routine, set vector10. Configure SPI to generate interrupts

(set DIRQE bit of ESPICTL)10. Enable interrupts (EI)11. Enable SPI (set bit 0 of SPICTL)

** non-trivial

Page 45: SPI 4-Wire 3-Wire - Atomic Rhubarb SPI.pdf · • The Enhanced Serial Peripheral Interface (SPI) is a synchronous interface allowing several SPI-type devices to be interconnected.

SPI Details

Data read/written is device specific.

Page 46: SPI 4-Wire 3-Wire - Atomic Rhubarb SPI.pdf · • The Enhanced Serial Peripheral Interface (SPI) is a synchronous interface allowing several SPI-type devices to be interconnected.

DS1722

This is on the ZNEO developer board

Page 47: SPI 4-Wire 3-Wire - Atomic Rhubarb SPI.pdf · • The Enhanced Serial Peripheral Interface (SPI) is a synchronous interface allowing several SPI-type devices to be interconnected.
Page 48: SPI 4-Wire 3-Wire - Atomic Rhubarb SPI.pdf · • The Enhanced Serial Peripheral Interface (SPI) is a synchronous interface allowing several SPI-type devices to be interconnected.

DS1722

Get the datasheet !

Page 49: SPI 4-Wire 3-Wire - Atomic Rhubarb SPI.pdf · • The Enhanced Serial Peripheral Interface (SPI) is a synchronous interface allowing several SPI-type devices to be interconnected.
Page 50: SPI 4-Wire 3-Wire - Atomic Rhubarb SPI.pdf · • The Enhanced Serial Peripheral Interface (SPI) is a synchronous interface allowing several SPI-type devices to be interconnected.

Note

CE = active HIGH /SS = active LOW

Use the SSPO bit of the ESPIMODE register to control this.

Page 51: SPI 4-Wire 3-Wire - Atomic Rhubarb SPI.pdf · • The Enhanced Serial Peripheral Interface (SPI) is a synchronous interface allowing several SPI-type devices to be interconnected.
Page 52: SPI 4-Wire 3-Wire - Atomic Rhubarb SPI.pdf · • The Enhanced Serial Peripheral Interface (SPI) is a synchronous interface allowing several SPI-type devices to be interconnected.
Page 53: SPI 4-Wire 3-Wire - Atomic Rhubarb SPI.pdf · • The Enhanced Serial Peripheral Interface (SPI) is a synchronous interface allowing several SPI-type devices to be interconnected.

DS1722 Error

Page 54: SPI 4-Wire 3-Wire - Atomic Rhubarb SPI.pdf · • The Enhanced Serial Peripheral Interface (SPI) is a synchronous interface allowing several SPI-type devices to be interconnected.

3-wire

Page 55: SPI 4-Wire 3-Wire - Atomic Rhubarb SPI.pdf · • The Enhanced Serial Peripheral Interface (SPI) is a synchronous interface allowing several SPI-type devices to be interconnected.

3-Wire/Microwire

The MICROWIRE protocol is essentially a subset of the SPI interface, specifically CPOL = 0 and CPHA = 0.

The Maxim 3-wire interface is found on some ICs from Maxim. The data flow to and from the device is multiplexed on one pin (DQ) while SPI needs two separate signals (MOSI, MISO).

Page 56: SPI 4-Wire 3-Wire - Atomic Rhubarb SPI.pdf · • The Enhanced Serial Peripheral Interface (SPI) is a synchronous interface allowing several SPI-type devices to be interconnected.

ESPI ExampleExample_SpiDs1722

Read from the DS1722 SPI Temperature sensor