SPI Universal Serial Communication Interface SPI Mode

Similar documents
Introduction to I2C & SPI. Chapter 22

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

PARALLEL COMMUNICATIONS

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

or between microcontrollers)

< W3150A+ / W5100 Application Note for SPI >

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

Understanding SPI with Precision Data Converters

Arduino Uno R3 INTRODUCTION

Microcontrollers and Interfacing

SPI (Serial & Peripheral Interface)

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

Introduction the Serial Communications Parallel Communications Parallel Communications with Handshaking Serial Communications

Growing Together Globally Serial Communication Design In Embedded System

Interfacing Techniques in Embedded Systems

I2C a learn.sparkfun.com tutorial

Amarjeet Singh. January 30, 2012

Raspberry Pi - I/O Interfaces

Infineon C167CR microcontroller, 256 kb external. RAM and 256 kb external (Flash) EEPROM. - Small single-board computer (SBC) with an

Basics of UART Communication

PD215 Mechatronics. Week 3/4 Interfacing Hardware and Communication Systems

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

UART TO SPI SPECIFICATION

Serial Communications

C8051F700 Serial Peripheral Interface (SPI) Overview

Lecture 25 March 23, 2012 Introduction to Serial Communications

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

CSCI 6907 PROJECT PROPOSAL LIGHTS OUT MANAGEMENT

EECS 373 Design of Microprocessor-Based Systems

Serial Communications

Lecture 14 Serial Peripheral Interface

Network Embedded Systems Sensor Networks Fall Hardware. Marcus Chang,

EECS 373 Design of Microprocessor-Based Systems

Using the Z8051 MCU s USI Peripheral as an SPI Interface

Microcontroller basics

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

BLE 1.4 SPI Driver Design Version 1.x (Draft)

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

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

Developing Reusable Device Drivers for MCU's

Communication. Chirag Sangani

ArduCAM-M-2MP Camera Shield

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

Real Time Embedded Systems. Lecture 1 January 17, 2012

VORAGO VA108x0 I 2 C programming application note

DESIGN AND VERIFICATION OF LOW SPEED PERIPHERAL SUBSYSTEM SUPPORTING PROTOCOLS LIKE SPI, I 2 C AND UART

ECE Microcontrollers. Serial Peripheral Interface (SPI) & NRF24 Radio

Part 1 Using Serial EEPROMs

Serial Communication. Simplex Half-Duplex Duplex

I2C and SPI Foundation

Serial Communication. Spring, 2018 Prof. Jungkeun Park

1.6inch SPI Module user manual

MICROPROCESSOR BASED SYSTEM DESIGN

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

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

I2C Master-Slave Connection

EE 308 Spring Using the 9S12 SPI

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

AN-895 APPLICATION NOTE

Working with Quad and Other SPI Protocols Testing and Debugging (Quad-) SPI-based ASIC, FPGA, SoC and Embedded Systems

1.3inch OLED User Manual

Unit 19 - Serial Communications 19.1

spi 1 Fri Oct 13 13:04:

IV B.Tech. I Sem (R13) ECE : Embedded Systems : UNIT -4 1 UNIT 4

keyestudio Keyestudio MEGA 2560 R3 Board

AVR XMEGA Product Line Introduction AVR XMEGA TM. Product Introduction.

Review for Exam 3. Write 0x05 to ATD0CTL4 to set at fastest conversion speed and 10-bit conversions

Serial Peripheral Interface (SPI)

M68HC08 Microcontroller The MC68HC908GP32. General Description. MCU Block Diagram CPU08 1

USER GUIDE EDBG. Description

Real-Time Embedded Systems. CpE-450 Spring 06

18-349: Introduction to Embedded Real-Time Systems

17. I 2 C communication channel

EECS 373 Design of Microprocessor-Based Systems

CS 134. Operating Systems. April 8, 2013 Lecture 20. Input/Output. Instructor: Neil Rhodes. Monday, April 7, 14

EECS 452 Lab 7: SPI, I2S on C5515 and DE2 70

I2C a learn.sparkfun.com tutorial

Pmod modules are powered by the host via the interface s power and ground pins.

MISO MOSI Clock. The master and the slave use a protocol based on the following frame structure. Preamble Body Postamble

Review for Exam III. Analog/Digital Converters. The MC9S12 has two 10-bit successive approximation A/D converters - can be used in 8-bit mode

Mbed Microcontroller SPI. Spring, 2018 Prof. Jungkeun Park

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

AT90SO36 Summary Datasheet

Pridgen Vermeer Robotics Xmega128 Manual

ZigBee Compliant Platform 2.4G RF Low Power Transceiver Module for IEEE Standard. DATA SHEET Version B

HZX N03 Bluetooth 4.0 Low Energy Module Datasheet

Arduino Uno. Arduino Uno R3 Front. Arduino Uno R2 Front

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

ECE 471 Embedded Systems Lecture 20

Nano RK And Zigduino. wnfa ta course hikaru4

EE4390 Microprocessors. Lessons 2, 3 68HC12 Hardware Overview, Subsystems, and memory System

AN Sleep programming for NXP bridge ICs. Document information

An Arduino Controlled 1 Hz to 60 MHz Signal Generator

EDBG. Description. Programmers and Debuggers USER GUIDE

ECE 1160/2160 Embedded Systems Design. Midterm Review. Wei Gao. ECE 1160/2160 Embedded Systems Design

ARDUINO MICRO WITHOUT HEADERS Code: A000093

Application Note, V1.0, Jul AP XC16x. Interfacing the XC16x Microcontroller to a Serial SPI EEPROM. Microcontrollers

Temperature Sensor TMP2 PMOD Part 1

Graduate Institute of Electronics Engineering, NTU FIR Filter Design, Implement, and Applicate on Audio Equalizing System ~System Architecture

AT90SO72 Summary Datasheet

Transcription:

SPI Universal Serial Communication Interface SPI Mode

Serial Peripheral Interface (SPI) is not really a protocol, but more of a general idea. It s the bare-minimum way to transfer a lot of data between two chips as quickly as possible, WHAT IS SPI? The core idea of SPI is that each device has a shift-register that it can use to send or receive a byte of data. These two shift registers are connected together in a ring, the output of one going to the input of the other and vice-versa. One device, the master,controls the common clock signal that makes sure that each register shifts one bit in just exactly as the other is shifting one bit out (and vice-versa). It s hard to get simpler than that. https://hackaday.com/2016/07/01/what-could-go-wrong-spi/

It s this simplicity that makes SPI fast. While asynchronous serial communications can run in the hundred-of-thousands of bits per second, SPI is usually good for ten megabits per second or more. You often see asynchronous serial between man and machine, because people are fairly slow. But between machine and machine, it s going to be SPI or I2C. Turning this pair of shift registers into a fullblown data bus involves a couple more wires

To begin communication, the master configures the clock, using a frequency supported by the slave device, typically up to a few MHz. The master then selects the slave device with a logic level 0 on the chip select line. If a waiting period is required, such as for an analog-todigital conversion, the master must wait for at least that period of time before issuing clock cycles. During each SPI clock cycle, a full duplex data transmission occurs. 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 one-directional data transfer is intended.

The master controls the clock (CLK or SCK) line, that s shared among all of the devices on the bus. Instead of a simple ring as drawn above, the master s shift register is effectively in a ring with each of the slave devices, and the lines making up this ring are labelled MISO ( master-in, slave-out ) and MOSI ( master-out, slave-in ) depending on the direction of data flow. Since all of the rings are shared, each slave has an additional dedicated line that tells it when to attach and detach from the bus. Each slave has a slave-select (SS or sometimes called chip-select CS) line, and when it s high, the slave disconnects its MISO line, and ignores what comes in over MOSI. When the individual SS line is pulled low, the slave engages. Note that the master is responsible for keeping one and only one SS lineactive low at any given time.

Typical SPI Communication: 1. The master pulls the slave s personal slave-select line low, at which point the slave wakes up, starts listening, and connects to the MISO line. Depending on the phase both chips may also set up their first bit of output

2. The master sends the first clock pulse and the first bit of data moves from master to slave (along MOSI) and from slave to master (along MISO).

3. The master keeps cycling the clock, bits are traded, and after eight bits, both sides read in the received data and queue up the next byte for transmission. Address Command Data

3. The master keeps cycling the clock, bits are traded, and after eight bits, both sides read in the received data and queue up the next byte for transmission. 4. After a number of bytes are traded this way, the master again drives the SS line high and the slave disengages.

SPEED Because SPI is clocked, and the slave-select line delimits a conversation, there s not much that can go wrong in syncronize the two devices. Not much, except when the master talks too fast for the slave to follow. The good news? This is easy to debug. For debugging purposes, there s nothing to lose by going slow. Nearly every chip that can handle SPI data at 10 MHz can handle it at 100 khz as well. On the other hand, due to all sorts of real-world issues with voltages propagating from one side of a wire to another and the chip s ability to push current into the wire to overcome its parasitic capacitance, the maximum speed at which your system can run is variable. For really high SPI speeds (say, 10 MHz and above?) your system design may be the limiting factor.

Find Arduino code: Convert Loop to Timer functions Replace calls to library which is not interrupt able or locally coded Use RT_ADC3 as work horse 10 interrupts per second replace Loop: Analyze library functions used

Original Arduino Code library functions used

SetUp SPI functions used: begin() setdatamode() GPIO pin used for Chip Select pinmode(cs, OUTPUT) digitalwrite(cs, HIGH/LOW)

Replace loop: with TimerA0_A3 CCR0 interrupts (10/second) Serial.print is replaced with sprintf() and UARTPrint() functions

digitalwrite changes CS output pin HIGH/LOW SPI.transfer(value) both input/output the SPI transfers

SAME THING: digitalwrite changes CS output pin HIGH/LOW SPI.transfer(value) both input/output the SPI transfers

SPI is always two directions. When you send, you also receive, and to receive, you have to send. In your code, when you send the command, you ll receive a dummy answer while you re sending the command. While the bits of the commands are sent (and the slave hasn t received the command), the SPI hardware is already receiving bits simultaneously. So once the command byte has been sent, a byte has been received too, which you ll need to discard. THEN you send one or two dummy bytes and while they re sent, you re receiving the 8 or 16 bit answer. My code does not use TXISR to interrupt, because this two-way transfer is for 6 bytes only. Code in the next Module can show way to start one byte and enter low power mode to wait for that byte to be sent. So the MSP430 routines here just poll until the TX is complete and then sends/receives the next transfer byte

sketch_spi_adxl345.ino

SetUp

SPI SetUp

Timer setup - 10/second

Timer ISR This is where Loop Tasks go

UART Print the string

UART SetUp and UARTPutString

SPI_Transfer Polled method

Chip Select and writeregister for ADXL345 SPI

Chip Select and readregister for ADXL345 SPI