SPI: Serial Peripheral Interface

Similar documents
Marten van Dijk Department of Electrical & Computer Engineering University of Connecticut

Marten van Dijk, Syed Kamran Haider

EE 308: Microcontrollers

Marten van Dijk, Syed Kamran Haider

spi 1 Fri Oct 13 13:04:

EE 456 Fall, Table 1 SPI bus signals. Figure 1 SPI Bus exchange of information between a master and a slave.

Serial Peripheral Interface (SPI)

The 9S12 Serial Peripheral Inteface (SPI) Huang Section 10.2 through 10.6 SPI Block User Guide

< W3150A+ / W5100 Application Note for SPI >

AVR Board Setup General Purpose Digital Output

Design with Microprocessors

More on the 9S12 SPI Using the Dallas Semiconductor DS1302 Real Time Clock with the 9S12 SPI

Embedded Systems and Software. Serial Interconnect Buses I 2 C (SMB) and SPI

EE 308 Spring Using the 9S12 SPI

Module 3.C. Serial Peripheral Interface (SPI) Tim Rogers 2017

C-CODE EXAMPLE FOR SCP1000-D01 PRESSURE SENSOR

Marten van Dijk, Syed Kamran Haider

a Serial Peripheral Interace (SPI). Embedded RISC Microcontroller Core Peripheral

PARALLEL COMMUNICATIONS

APPLICATION NOTE. Atmel AT02260: Driving AT42QT1085. Atmel QTouch. Features. Description

Microcontrollers and Interfacing

Amarjeet Singh. January 30, 2012

Introduction the Serial Communications Huang Sections 9.2, 10.2 SCI Block User Guide SPI Block User Guide

Menu. What is SPI? EEL 3744 EEL 3744 SPI

SPI Block User Guide V02.07

LAB4. Program the on chip SPI module

Serial versus Parallel Data Transfers

Serial Peripheral Interface. What is it? Basic SPI. Capabilities. Protocol. Pros and Cons. Uses

AT89S4D12. 8-Bit Microcontroller with 132K Bytes Flash Data Memory AT89S4D12. Features. Description. Pin Configurations

Serial Peripheral Interface (SPI) Host Controller Data Sheet

Serial Peripheral Interface (SPI) Last updated 8/7/18

Serial Peripheral Interface (SPI)

Raspberry Pi - I/O Interfaces

Design Development and Implementation of SPI

An SPI interface for the 65(C)02 family of microprocessors

8-bit RISC Microcontroller. Application Note. AVR151: Setup And Use of The SPI

Synchronous = SPI (3 options)

Setting up Eclipse (Windows), or GCC (Mac) Setting up Atmel Studio (Windows & Mac)

Mbed Microcontroller SPI. Spring, 2018 Prof. Jungkeun Park

Using the Z8051 MCU s USI Peripheral as an SPI Interface

Design and development of embedded systems for the Internet of Things (IoT) Fabio Angeletti Fabrizio Gattuso

Getting Started with ESPI Interface Using the Z8 Encore! XP F1680

Understanding SPI with Precision Data Converters

SPI 3-Wire Master (VHDL)

Marten van Dijk Department of Electrical & Computer Engineering University of Connecticut

USER GUIDE. ATmega328P Xplained Mini User Guide. Introduction

Asynchronous & Synchronous Serial Communications Interface. Student's name & ID (1): Partner's name & ID (2): Your Section number & TA's name

Asynchronous & Synchronous Serial Communications Interface. Student's name & ID (1): Partner's name & ID (2): Your Section number & TA's name

ATmega328PB Xplained Mini. Introduction. AVR 8-bit Microcontrollers USER GUIDE

PIC Serial Peripheral Interface (SPI) to Digital Pot

McMaster University Embedded Systems. Computer Engineering 4DS4 Lecture 6 Serial Peripherals Amin Vali Feb. 2016

The Serial Peripheral Interface

AVR PCD8544 DRIVER DOCUMENTATION

SPI (Serial & Peripheral Interface)

Lecture 14 Serial Peripheral Interface

Real Time Embedded Systems. Lecture 1 January 17, 2012

Introduction. Serial Peripheral Interface (SPI) SPI Basics. Capabilities of SPI

Serial communications with SPI

ECE 471 Embedded Systems Lecture 20

EEPROM Watchdog Timer

Section 5 SERCOM. Tasks SPI. In this section you will learn:

Arduino Uno R3 INTRODUCTION

LCD H C 1 2 GP2D PP4 MISO MOSI DIN DOUT SCK PP5 SCK D0 D1 D2 D3 D4 D5 D6 D7 DIN. Maximum SCK = 500 khz SCK D0 D1 D2 D3 D4 D5 D6 D7 DOUT

USER GUIDE. Atmel OLED1 Xplained Pro. Preface

C8051F700 Serial Peripheral Interface (SPI) Overview

Growing Together Globally Serial Communication Design In Embedded System

OUTLINE. SPI Theory SPI Implementation STM32F0 SPI Resources System Overview Registers SPI Application Initialization Interface Examples

SPI bus communication with LDE/LME pressure sensors

Task Based Programming Revisited Real Time Operating Systems

ECE2049: Embedded Computing in Engineering Design C Term Spring 2018

Hello, and welcome to this presentation of the STM32 Universal Synchronous/Asynchronous Receiver/Transmitter Interface. It covers the main features

Parallel Data Transfer. Suppose you need to transfer data from one HCS12 to another. How can you do this?

AN1228. Motorola Semiconductor Application Note. Interfacing the M68HC05 MCU to the MC A/D Converter. Freescale Semiconductor, I.

Introduction to I2C & SPI. Chapter 22

Using the Serial Peripheral Interface (SPI) Module on 68HC(9)08 Microcontrollers

Serial Peripheral Interface (SPI)

USER GUIDE. Atmel maxtouch Xplained Pro. Preface

Serial Communication. Spring, 2018 Prof. Jungkeun Park

An SPI Temperature Sensor Interface with the Z8 Encore! SPI Bus

Groking the Linux SPI Subsystem FOSDEM Matt Porter

3.2inch SPI Module MSP3218 User Manual

SBAT90USB162 Atmel. SBAT90USB162 Development Board User s Manual

ECE 4510/5530 Microcontroller Applications Week 6

ADC: Analog to Digital Conversion

SPI Universal Serial Communication Interface SPI Mode

ArduCAM-M-2MP Camera Shield

App Note Application Note: Addressing Multiple FPAAs Using a SPI Interface

1.6inch SPI Module user manual

i_csn i_wr i_rd i_cpol i_cpha i_lsb_first i_data [15:0] o_data [15:0] o_tx_ready o_rx_ready o_rx_error o_tx_error o_tx_ack o_tx_no_ack

USER GUIDE. ATmega168 Xplained Mini User Guide. Introduction

SPI Storm. Data sheet

Context Switching & Task Scheduling

SPI/USB Interface board Data sheet for HF RFID Reader/Writer module LXRFZZHBBA-044

DBAT90USB162 Atmel. DBAT90USB162 Enhanced Development Board User s Manual

Using the MagAlpha Serial Interface Advanced Features. Application Note

LABORATORIO DI ARCHITETTURE E PROGRAMMAZIONE DEI SISTEMI ELETTRONICI INDUSTRIALI. Laboratory Lesson 9: Serial Peripheral Interface (SPI)

AREA OPTIMIZATION OF SPI MODULE USING VERILOG HDL

1.3inch OLED User Manual

Universität Dortmund. IO and Peripheral Interfaces

SPI Overview and Operation

Transcription:

ECE3411 Fall 2015 Lab 6c. SPI: Serial Peripheral Interface Marten van Dijk, Syed Kamran Haider Department of Electrical & Computer Engineering University of Connecticut Email: {vandijk, syed.haider}@engr.uconn.edu With the help of: www.wikipedia.org ATmega328P Datasheet

SPI: Serial Peripheral Interface The SPI bus specifies four logic signals: SCLK : Serial Clock (output from master). MOSI : Master Output, Slave Input (output from master). MISO : Master Input, Slave Output (output from slave). SS : Slave Select (active low, output from master). SPI Master SPI Slave SCLK MOSI MISO SS SCLK MOSI MISO SS 2

SPI Master & Slaves The SPI bus can operate with a single Master device and with one or more Slave devices. In case of multiple slaves, the master selects the slave device with a logic 0 on the select (SS) line. During each SPI clock cycle, the master sends a bit on the MOSI line and the slave reads it, while the slave sends a bit on the MISO line and the master reads it. This sequence is maintained even when only onedirectional data transfer is intended. 3

SPI Data Modes There are four combinations of SCK phase and polarity with respect to serial data, which are determined by control bits CPHA and CPOL. 4

SPI Frame Transfer with CPHA=0 5

SPI Frame Transfer with CPHA=1 6

SPI Master Example void SPI_MasterInit(void) { /* Set SS, MOSI and SCK output, all others input */ DDR_SPI = (1<<DD_SS) (1<<DD_MOSI) (1<<DD_SCK); /* Enable SPI, Master, set clock rate fck/128 */ SPCR = (1<<SPE) (1<<MSTR) (1<<SPR1) (1<<SPR0); } uint8_t SPI_Master_Transceiver(uint8_t cdata) { PORTB &= ~(1<<SPI_SS); // Pull Slave_Select low SPDR = cdata; // Start transmission while(!(spsr & (1<<SPIF)) ); // Wait for transmission complete PORTB = (1<<SPI_SS); // Pull Slave Select High return SPDR; // Return received data } Note: DDR_SPI in the examples must be replaced by the actual Data Direction Register controlling the SPI pins. DD_SS, DD_MOSI, DD_MISO and DD_SCK must be replaced by the actual data direction bits for these pins. E.g. if MOSI is placed on pin PB3, replace DD_MOSI with DDB3 and DDR_SPI with DDRB. SPI_SS should be replaced with actual bit position of SS pin in the port corresponding to SPI pins. 7

SPI Slave Example void SPI_SlaveInit(void) { /* Set MISO output, all others input */ DDR_SPI = (1<<DD_MISO); /* Enable SPI */ SPCR = (1<<SPE); } uint8_t SPI_SlaveReceive(void) { /* Wait for reception complete */ while(!(spsr & (1<<SPIF))); /* Return Data Register */ return SPDR; } Note: DDR_SPI in the examples must be replaced by the actual Data Direction Register controlling the SPI pins. DD_MOSI, DD_MISO and DD_SCK must be replaced by the actual data direction bits for these pins. E.g. if MOSI is placed on pin PB5, replace DD_MOSI with DDB5 and DDR_SPI with DDRB. 8

Important Notes On Xplained Mini, ATmega328P is programmed by ATmega32U4 Programming in ISP mode and/or enabling/disabling fuses uses SPI bus. If you program in ISP mode, you ll need to restart Atmel Studio every time you program the ATmega328P. Therefore, use debugwire interface to program the ATmega328P for this lab. REMEMBER: debugwire interface requires DWEN fuse to be enabled, which is done over SPI bus between ATmega32U4 and ATmega328P. Therefore, if you plan to connect MOSI and MISO pins together to perform loopback testing of SPI, do so only after entering into debugwire interface and programming the ATmega328P at least once. This will enable the DWEN fuse before the SPI pins MOSI and MISO are shorted together. 9

Task1: SPI Loopback Testing Write a simple program to test SPI in loopback mode. In particular: Configure SPI in Master mode Read a potentiometer s voltage through ADC every 100ms (only upper 8 bits). Transmit the byte containing voltage reading over SPI. Loopback the transmitted byte by connecting MOSI and MISO pins together according to the instructions given on previous slide. Print on LCD the byte value received over SPI. 10

Task2: SPI Master Slave Communication Extend Task1 so that you can exchange voltage readings between yours and your friend s board over SPI bus. Configure your board as SPI Master and ask your friend to configure his as SPI Slave. Make proper wire connections of SS, SCK, MOSI and MISO pins between the two boards. The slave MCU should read its ADC value and write it to SPDR register every 50ms. Transmit Master s voltage value every 100ms. This will also result in receiving the last voltage value written in SPDR register in the slave MCU. For both Master and Slave, print both transmitted and received values on LCD. Homework: Use SPI interrupts on both Master and Slave sides for non-blocking SPI communication. 11