Serial Peripheral Interface (SPI)

Slides:



Advertisements
Similar presentations
INPUT-OUTPUT ORGANIZATION
Advertisements

Anurag Dwivedi Rudra Pratap Suman. Scope of Communica tion Telephones and Cell Phones.
ECE 371 Unit 13 - Part 1 Serial Peripheral Interface (SPI)
SHIFT REGISTERS: CONVERTING BETWEEN SERIAL AND PARALLEL DATA Mark Neil - Microprocessor Course 1 Serial versus Parallel Data Transfers.
Serial Interfaces, Part Deux -I 2 C and SPI December 4, 2002 Presented by Eugene Ho.
SPI Serial Peripheral Interface. SPI Serial Peripheral Interface is communication between two devices, one bit at a time sequential one bit at time over.
Lecture 8: Serial Interfaces
SPI on the ATmega SS’ line only used in Slave mode SPDR
Lab3 -- Lab 4 Design and implementation details on the way to a valid SPI-LCD interface driver.
Serial Communication Buses: I 2 C and SPI By Brody Dunn.
Guitar Effects Processor Critical Design Review October, 07, 2003 Groups Members: Adam Bernstein Hosam Ghaith Jasenko Alagic Matthew Iyer Yousef Alyousef.
ECE200 – Computer Organization Chapter 8 – Interfacing Processors and Peripherals.
SPISPI Term Dr Abdelhafid Bouhraoua Term Dr Abdelhafid Bouhraoua.
7-1 Digital Serial Input/Output Two basic approaches  Synchronous shared common clock signal all devices synchronised with the shared clock signal data.
Configuration. Mirjana Stojanovic Process of loading bitstream of a design into the configuration memory. Bitstream is the transmission.
Two Wire Interface Another popular serial peripheral interface bus -More flexible than SPI -Master and slave modes supported -7-bit slave address -400khz.
INPUT-OUTPUT ORGANIZATION
Interfaces A practical approach. Lesson 2 I2C and SPI
Serial Peripheral Interface (SPI) Bus. SPI Bus There is no official specification for the SPI bus. It is necessary to consult the data sheets of the devices.
Serial Peripheral Interface Module MTT M SERIAL PERIPHERAL INTERFACE (SPI)
ECE 265 – LECTURE 12 The Hardware Interface 8/22/ ECE265.
Khaled A. Al-Utaibi  Intel Peripheral Controller Chips  Basic Description of the 8255  Pin Configuration of the 8255  Block Diagram.
LSU 10/22/2004Serial I/O1 Programming Unit, Lecture 5.
CRKit RF Control WINLAB – Rutgers University Date : June Authors : Prasanthi Maddala, Khanh Le,
CRKit RF Control WINLAB – Rutgers University Date : June Authors : Prasanthi Maddala, Khanh Le,
DEVICES AND COMMUNICATION BUSES FOR DEVICES NETWORK–
CRKit RF Control WINLAB – Rutgers University Date : June Authors : Prasanthi Maddala, Khanh Le,
CRKit RF Control WINLAB – Rutgers University Date : June Authors : Prasanthi Maddala, Khanh Le,
7/23 Inter-chip Serial Communication: SPI and I 2 C Computer Science & Engineering Department Arizona State University Tempe, AZ Dr. Yann-Hang Lee.
Volume. 1-the idea of the program is to increase, decrease the volume. 2-the program does the following: A-PF8:decrease the volume B-Pf9:increase the.
Lecture 20: Communications Lecturers: Professor John Devlin Mr Robert Ross.
Embedded System Design Laboratory October 4, 2002Stanford University - EE281 Lecture #3#1 Lecture #3 Outline Announcements AVR Processor Resources –UART.
8279 KEYBOARD AND DISPLAY INTERFACING
ELE22MIC Lecture 11 Serial Peripheral Interface - SPI AS11 PAL/PLD
Network and Systems Laboratory nslab.ee.ntu.edu.tw se.
12/16/  List the elements of 8255A Programmable Peripheral Interface (PPI)  Explain its various operating modes  Develop a simple program to.
OCRP RF Control WINLAB – Rutgers University Date : June Authors : Prasanthi Maddala, Khanh Le,
PPI-8255.
OCRP RF Control WINLAB – Rutgers University Date : June Authors : Prasanthi Maddala, Khanh Le,
S4525A Peripherals & Enhanced FLASH 1 © 1999 Microchip Technology Incorporated. All Rights Reserved. S4525A Peripherals & Enhanced FLASH 1 Peripherals.
Essentials of Communication This simple model requires many guarantees. Sender Receiver Communication Link Data.
Revised: Aug 1, ECE263 Embedded System Design Lessons 27, 28 Serial Peripheral Interface.
Department of Electronic & Electrical Engineering Serial interfaces Serial Interfaces allow communication between devices sending one bit at a time. In.
Serial Peripheral Interface SPI I2C (i-squared cee)
© 2008, Renesas Technology America, Inc., All Rights Reserved 1 Course Introduction Purpose  This course provides an introduction to the peripheral functions.
SHIFT REGISTERS: CONVERTING BETWEEN SERIAL AND PARALLEL DATA Mark Neil - Microprocessor Course 1 Serial versus Parallel Data Transfers.
1 MPC 555: Queued Serial Module. 2 MPC 555 QSM QSPI: Queued Serial Peripheral Interface: full duplex serial, synchronous interface. 160B of queue RAM.
Embedded Systems February 10, Serial Interface - SPI  Serial Peripheral Interface  Synchronous communications  Clock supplied by the Master.
Communicating. The ATmega16 communicates through one of the following ways: Serial Peripheral Interface (SPI) Universal Synchronous and Asynchronous serial.
Embedded Communication Protocols Don Heer 10/18/10 1.
Networked Embedded Systems Sachin Katti & Pengyu Zhang EE107 Spring 2016 Lecture 9 Serial Buses – SPI, I2C.
BIRLA VISHVAKARMA MAHAVIDYALAY SUBJECT: SPI PROTOCOL & MAX7221 DISPLAY INTERFACING SUBMITTED BY: KISHAN AVASTHI( ) MANSI CHANDEGARA( )
میکرو کنترلرهای AVR Serial Interfaces, I2C and SPI
1 Serial Peripheral Interface What is it? Basic SPI Capabilities Protocol Pros and Cons Uses Serial Peripheral Interface
©F.M. Rietti Communication Lines Fundamentals. ©F.M. Rietti LM-18 Computer Science SSI Embedded Systems I 2 Communication Lines Generally used to connect.
Serial Communication Originally created by Anurag Dwidedi and Rudra Pratap Suman.
ECE 382 Lesson 15 Lesson Outline S/W Delays Wrap up
Serial Communication Buses: I2C and SPI
Tutorial Introduction
ECE 3430 – Intro to Microcomputer Systems
SERIAL PERIPHERAL INTERFACE
Atmega32 Serial Programming Basics
EEPROM Comparison – Parallel or Serial
SPI Protocol and DAC Interfacing
SPI Protocol and DAC Interfacing
Преглед Начин функционисања Имплементације
SPI Protocol Sepehr Naimi
HD44780 LCD programming From the Hardware Side
HD44780 LCD programming From the Hardware Side
Serial Communication 19th Han Seung Uk.
Presentation transcript:

Serial Peripheral Interface (SPI) SPI = Simple, 3 wire, full duplex, synchronous serial data transfer Interfaces to many devices, even many non-SPI peripherals Can be a master or slave interface 4 interface pins: -MOSI master out slave in -MIOS master in slave out -SCK serial clock -SS_n slave select 3 registers: -SPCR control register -SPSR status register -SPDR data register

Serial Peripheral Interface (SPI) Full duplex, synchronous serial data transfer Data is shifted out of the master's (mega128) MOSI pin and in its MISO pin Data transfer is initiated by simply writing data to the SPI data register. All data movement is coordinated by SCK. Slave select may or may not be used depending on interfacing device. To get input data only you send “junk” data to SPDR to start the clock. master SPI device slave SPI device

Serial Peripheral Interface (SPI) Slave Select... use it carefully! In master mode: -SPI interface has no control of SS_n -User software has full control of SS_n (Port B, bit 0) -If configured as output, it’s a general purpose output -If configured as input, it must be held high, else you will enter slave mode We will use SPI in master mode, full duplex

Serial Peripheral Interface (SPI) SPI Control Register (SPCR) interrupt enable: if set, interrupt occurs when SPI interrupt flag and global interrupt enable are set (in SPSR) clock rate spi enable: if set, SPI interface is enabled SPI2X SPR1 SPR0 SCLK 0 0 0 fosc/4 0 0 1 fosc/16 0 1 0 fosc/64 0 1 1 fosc/128 1 0 0 fosc/2 1 0 1 fosc/8 1 1 0 fosc/32 1 1 1 fosc/64 data order: if set, LSB is transmitted first master/slave select: if set, SPI in master mode clock polarity: '0' SCK low in idle '1' SCK high in idle clock phase: '0' leading edge sample, trailing edge setup '1' leading edge setup, trailing edge sample

Serial Peripheral Interface (SPI) SPI Status Register (SPSR) reserved bits interrupt flag: set when serial transfer is complete write collision: set if SPDR is written during a receive transfer 2x clock rate: if set, doubles clock rate in master mode SPI Data Register (SPDR) SPDR is a read/write register used for data transfer. Writing SPDR sends data out MOSI. Reading SPDR gets the data that was clocked into MISO.

Serial Peripheral Interface (SPI) Mega128 LCD interface SCK, PB1 LCD strobe, PF3 MOSI, PB2 9-bit shift register enable pulse generator

Serial Peripheral Interface (SPI) SPI Application - Code /*********************************************************************/ // spi_init //Initializes the SPI port on the mega128. Does not do any further //external device specific initializations. void spi_init(void){ DDRB = DDRB | 0x07; //Turn on SS, MOSI, SCLK (SS is output) SPCR |= (1<<SPEN) | (1<<MSTR); //spi enabled, master, low polarity, msb 1st SPSR |= (1<<SPI2X); //run at i/o clock div 2 }//spi_init /***********************************************************************/ // digi_pot_send //Sends command and data to the digital pot. SPI device chip select is //active low and is connected to port F bit 2. Total of 16 bits are sent. //One byte for control and one byte as data passed in. void digi_pot_send(uint8_t data){ PORTF &= 0xFB; //port F bit 2, assert active low SPDR = 0x13; //send command byte (fixed value) while (bit_is_clear(SPSR,SPIF)) {} //wait till data is sent out SPDR = data; //send data byte PORTF |= 0x04; //port F bit 2, deassert to logic high } //digi_pot_send

Serial Peripheral Interface (SPI) Typical SPI IC (MCP42010)

Serial Peripheral Interface (SPI) 74HC595 – A perfectly fine SPI peripheral

Serial Peripheral Interface (SPI) What if you want only to read the SPI port? To get the SPI clock to run, a "dummy" write is made to the SPI SPDR register. This starts the clock running so the data on MISO is brough into the uC. If no peripherals are selected, the outgoing data will be ignored. If you are clever, you can send data out and bring data in at the same time. /*********************************************************************/ // spi_read //Reads the SPI port. uint8_t spi_read(void){ SPDR = 0x00; //"dummy" write to SPDR while (bit_is_clear(SPSR,SPIF)){} //wait till 8 clock cycles are done return(SPDR); //retrun incoming data from SPDR }//read_spi

Serial Peripheral Interface (SPI) 74HC165 – Another fine SPI peripheral

Serial Peripheral Interface (SPI) SPI “Gotchas” “Now my board won’t program.” SPI shares SCK with programming interface. If it won’t program anymore, you likely messed up SCK. “SPI acts totally wierd.” Often a symptom of SS_n being configured as an input and being left to float or allowed to go high. SPI goes in and out between slave and master modes. “I never get data to the SPI device.” Is clock correctly oriented ? Did you assert the device chip select? (hint: put SPI write inside a “tight” loop and check with scope. Watch SCK, data, and chip select) "SPI device interactions:" When programming, the programmer first does a chip reset. When the mega128 resets, all pins are set to input with high impedance (floating). If a SPI device is on the SPI bus, it's chip-select may float low and enable the device, and SPI data will crash the programming data. Adding a pull-up resistor to chip selects will solve this problem.