SPI Overview and Operation

Similar documents
Operation of Timer A (2-phase pulse signal process in event counter mode, multiply-by-4 processing operation)

M32C/84, 85, 86, 87, 88 Group

M32C/84, 85, 86, 87, 88 Group

In timer mode, choose functions from those listed in Table 1. Operations of the circled items are described below.

This document describes a program for timer RF in pulse width measurement mode.

This document describes a program for timer RA in pulse period measurement mode.

Old Company Name in Catalogs and Other Documents

Data Transfer between On-chip RAM Areas with DMAC (Burst Mode) 1. Introduction Description of Sample Application... 3

Old Company Name in Catalogs and Other Documents

Old Company Name in Catalogs and Other Documents

Old Company Name in Catalogs and Other Documents

Old Company Name in Catalogs and Other Documents

Old Company Name in Catalogs and Other Documents

Silicon Planar Zener Diode for Low Noise Application. Part No. Cathode Band Package Name Package Code HZ-L Series Navy blue DO-35 GRZZ0002ZB-A 7 B 2

Old Company Name in Catalogs and Other Documents

DATA SHEET ZENER DIODES 1.0 W PLANAR TYPE 2-PIN SMALL POWER MINI MOLD. Parameter Symbol Ratings Unit Remarks

Old Company Name in Catalogs and Other Documents

Old Company Name in Catalogs and Other Documents

Old Company Name in Catalogs and Other Documents

Old Company Name in Catalogs and Other Documents

Renesas E8 On-Chip Debugging Emulator

Old Company Name in Catalogs and Other Documents

E1/E20 Emulator Additional Document for User s Manual (RX User System Design)

Old Company Name in Catalogs and Other Documents

Renesas E10A-USB Emulator

REJ10J I/O DLL Kit. User's Manual. Simulator Debugger Customizing Kit

Renesas LIN Overview. White paper REU05B Introduction

ESD NOISE CLIPPING DIODE NNCD2.0DA to NNCD39DA

1. Specification Applicable Conditions Description of Modules Used Principles of Operation... 9

Old Company Name in Catalogs and Other Documents

M3H Group(1) Application Note. I 2 C Interface (I2C-B) MASTER/SLAVE

REJ10J High-performance Embedded Workshop V User's Manual. Renesas Microcomputer Development Environment System

M3H Group(1) Application Note I 2 C Interface (I2C-B)

Old Company Name in Catalogs and Other Documents

Understanding SPI with Precision Data Converters

M3H Group(2) Application Note I 2 C Interface (I2C-B) arbitration

SuperH RISC engine C/C++ Compiler Package

Integrated Development Environment

Old Company Name in Catalogs and Other Documents

SPI Protocol of the TLE941xy family

Flash Self-programming Library

M32C Simulator Debugger V.1.03

Growing Together Globally Serial Communication Design In Embedded System

AN10428 UART-SPI Gateway for Philips SPI slave bridges

Audio digital potentiometers

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

In repeat transfer mode of DMAC, choose functions from those listed in Table 1. Operations of the checked items are described below.

M3H Group(2) Application Note Asynchronous Serial Communication Circuit (UART-C)

Asynchronous Transfer of Data with Appended CRC Codes via an SCI Interface

M3H Group(2) Application Note 12-bit Analog to Digital Converter (ADC-A)

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

38K2 Group User's Manual

AN510 Using SPI protocol with pressure sensor modules

AN2737 Application note Basic in-application programming example using the STM8 I 2 C and SPI peripherals Introduction

EOL announced Product. Old Company Name in Catalogs and Other Documents

APPLICATION NOTE. Basic SPI Bus Information. Bus Configuration and SPI Protocol of Multiple DCPs. SPI Protocol and Bus Configuration of Multiple DCPs

Lecture 14 Serial Peripheral Interface

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

DALI Master Controller GUI

Raspberry Pi - I/O Interfaces

Regarding the change of names mentioned in the document, such as Hitachi Electric and Hitachi XX, to Renesas Technology Corp.

AN10955 Full-duplex software UART for LPC111x and LPC13xx

EDBG. Description. Programmers and Debuggers USER GUIDE

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

Old Company Name in Catalogs and Other Documents

UART TO SPI SPECIFICATION

UM PCAL6524 demonstration board OM Document information

M16C/62 APPLICATION NOTE. Using the M16C/62 CRC. 1.0 Abstract. 2.0 Introduction. 3.0 A Lesson in CRC and the CCITT Polynomial

Stepping motor driver

M16C/62 APPLICATION NOTE. Programming the M16C/62 in Flash Parallel Mode. 1.0 Abstract. 2.0 Introduction. 3.0 Setting Up the PGM1000 Programmer

Old Company Name in Catalogs and Other Documents

Microcontrollers and Interfacing

AARDVARK. Level Shifter Board. Level Shifter Board. Datasheet v1.00 February 15, 2008 I 2 C/SPI. Features

PoExtBusOC16-CNC User s manual

MSM GENERAL DESCRIPTION FEATURES. Single Rail CODEC

H8SX Family APPLICATION NOTE. Vector Table Address Switching. Introduction. Target Devices. Contents

Old Company Name in Catalogs and Other Documents

Renesas Starter Kit Sample Code for Cubesuite + Toolchain

Real Time Embedded Systems. Lecture 1 January 17, 2012

RL78 Family. User s Manual. Flash Self-Programming Library Type Bit Single-Chip Microcontrollers. Rev.1.04 Dec 2016.

How to use the NTAG I²C plus for bidirectional communication. Rev June

M16C/62 APPLICATION NOTE. Using the M16C/62 DMAC in Forward Source Mode. 1.0 Abstract. 2.0 Introduction

AN Sleep programming for NXP bridge ICs. Document information

SPI Block User Guide V02.07

Multifunction Serial Interface (PDL_MFS) Features. General Description. When to Use a PDL_MFS Component. Quick Start 1.0

CDB4350 Evaluation Board for CS4350

Using the Z8051 MCU s USI Peripheral as an SPI Interface

Basics of UART Communication

User s Manual. RX65N Group. beans for RX65N User s Manual. RENESAS 32-Bit MCU RX Family / RX600 Series

Renesas Flash Programmer V3.04

AN4113 Application note

or between microcontrollers)

M16C/26 APPLICATION NOTE. Using the DMAC with a Forward Source. 1.0 Abstract. 2.0 Introduction

Drop-In Replacement: CG2163X3. Part Number Order Number Package Marking Supplying Form G4X CAUTION

< W3150A+ / W5100 Application Note for SPI >

Renesas Flash Programmer V3.03

AN2672 Application note

UnRegistered MB39C602 LED LIGHTING SYSTEM BULB 9W ZIGBEE CONTROL USER MANUAL. Fujitsu Semiconductor Design (Chengdu) Co. Ltd.

Evaluation Board for CS4351

A 24-hour clock (which is updated at 1-minute intervals) is created by using the 32K timer.

Transcription:

White Paper Abstract Communications between semiconductor devices is very common. Many different protocols are already defined in addition to the infinite ways to communicate with a proprietary protocol. This paper will provide an overview of SPI, show some of its advantages and disadvantages, and provide a working example for the M16C/Tiny Series of microcontrollers. REJxxxxxxx-xxxx/Rev.5.00 August 2007 Page 1 of 10

Contents 1. SPI Overview... 3 2. Interface... 3 3. Communication... 4 4. Advantages and Disadvantages... 8 5. References... 8 REJxxxxxxx-xxxx/Rev.0.10 February 2008 Page 2 of 10

1. SPI Overview SPI Overview and Operation SPI stands for Serial Peripheral Interface. It is often referred to as Es Pee Eye or Spy. These are generally accepted as interchangeable and mean the same thing. Originally defined at Motorola, SPI is one of the main serial interfaces used in embedded systems today, and consists of a simple 4 wire interface and basic signaling rules. In any SPI system, there is always at least one Master device which generates the bus clock for the system, and always at least one Slave device which is the peripheral in the system. A very common setup is to have a 16bit Microcontroller as the Master, and a SPI EEPROM (Electrically Erasable Programmable Read Only Memory) device as a slave. A real world application could be a diagnostic module where the microcontroller collects environmental information and stores it periodically in Non-Volatile memory (the EEPROM). SPI is one of the least constrictive serial standards. Other than the definition of the bus interface, and the polarity and phase of the signaling (explained in depth later), almost all of the other elements of communication are either left to the system designer or are required by the logic of the slave for proper operation. 2. Interface Figure 1, below, shows a simple single Master, single Slave SPI system. The interface lines are: SCLK Serial Clock (from the master) MOSI Master Out / Slave In (data from the master) MISO Master In / Slave Out (data from the slave, but clocked out by the master) SS Slave Select (Active Low signal selects/enables the slave device) Figure 1. Simple SPI Block Diagram / Bus Interface These names are not strictly defined although they make logical sense from a system perspective. Some datasheets and descriptions will use other naming conventions for the bus wires, such as Chip Select (CS) for Slave Select, or more usually SDO and SDI (Serial Data Out and Serial Data In, respectively) which is more complex to deal with because those descriptions rely on the perspective from one of the devices. i.e. A Slave s SDO pin would have to be connected to the SDI pin of the Master. REJxxxxxxx-xxxx/Rev.0.10 February 2008 Page 3 of 10

3. Communication 3.1 SPI Modes SPI supports four modes of operation. There are two choices of clock polarity and two choices of phase. The labels for these modes are usually CPOL (Clock Polarity) and CPHA (Clock Phase) and they describe when data should be sampled relative to the clock and the clocks behavior. So Mode 0,0 would be polarity (CPOL) = zero, and phase (CPHA) = zero. The other modes are 0,1 1,0 and 1,1 Here is a visual description of the clock signal in the various modes: Figure 3: SPI Modes In the case of Mode 0,0 shown in the top-left corner of Figure 3, CPOL dictates that the clock s rest state is at logic 0. You can see that the clock starts out low. CPHA in this mode is 0, which means that data will be sampled on the first clock edge in this case the rising edge. This is shown by the red sample line. In the case of Mode 0,1 shown in the top-right corner, CPOL dictates that the clock s rest state is at logic 0. The clock starts out low. CPHA in this mode is 1, which means that data will be sampled on the second clock edge in this case the falling edge. This is shown by the red sample line. In the case of Mode 1,0 shown in the bottom-left corner of Figure 3, CPOL dictates that the clock s rest state is at logic 1. The clock starts out high. CPHA in this mode is 0, which means that data will be sampled on the first clock edge in this case a falling edge. In the case of Mode 1,1 shown in the bottom-right corner, CPOL dictates that the clock s rest state is at logic 1. The clock starts out high. CPHA in this mode is 1, which means that data will be sampled on the second clock edge in this case the rising edge. Take another look at the real trace in Figure 2, you can see that the data on the SDO line from the microcontroller is being latched on the falling edge and read to be sampled on the 2 nd edge i.e. rising. The rest state of the clock is high, so this communication is in Mode 1,1. Not all devices support all SPI modes. Some examples are below: ST Micro M95080 EEPROM supports MODE 0, MODE 3 National Semi LM74 Temp Sensor supports MODE 0, MODE 3 Maxim MAX5422 Digital Potentiometer - supports MODE 3 only REJxxxxxxx-xxxx/Rev.0.10 February 2008 Page 4 of 10

3.2 Slave Select SPI Overview and Operation In a single or multiple slave system, the active slave is designated by its individual SS pin. This negates the need for any addressing, but can add to the physical resources used, as each slave may need its own dedicated SS from the master. The master sends the SS line low, sends data, and then deselects the SS line by sending it high. Some slaves may allow themselves to be permanently active, meaning the master in a single master, single slave configuration doesn t need to control the SS line it can be connected to ground. Of course, you will need to check the slave datasheet to make sure this is valid operation. In the majority of embedded systems where a microcontroller acts as the master, the SS is implemented with a simple I/O pin, sent high or low using software. 3.3 Clock Generation The Master device is responsible for generating the clock signal. There are a number of ways to achieve this if you intend to use a microcontroller as the master. One partly automated way to send and receive 8-bit data, is to configure the UART of the device to clock out the transmitted data, and send dummy bytes (the data sent could be 0x00 for example) to clock data back out of the slave. One thing to be mindful of here is the speed of the clock. Take care to set the generated clock speed (or baud rate) at a frequency equal to or less than the maximum specified frequency of the slave. 3.4 Framing It should be noted that SPI words are not framed. There are no start or stop bits, nor any built in arbitration or error checking. This can be a major advantage in terms of flexibility, speed and ease of use, or a big problem if communications don t go to plan. Robust design is always encouraged and mechanisms such as check-summing and timeouts should be employed to ensure the system doesn t crash in some way. However, these things are not mandatory in SPI. 3.5 Full Duplex Operation SPI communications are full duplex. Often, when the Master provides clock signals, the slave will send out data. This data is not always relevant and the Master should decide whether to accept or discard the data on the MISO line. REJxxxxxxx-xxxx/Rev.0.10 February 2008 Page 5 of 10

3.6 Example Communication SPI Overview and Operation Figure 2, below shows a real SPI communication between a Renesas M16C28 microcontroller and a ST Micro M95080 SPI serial EEPROM. Figure 2: A real SPI trace REJxxxxxxx-xxxx/Rev.0.10 February 2008 Page 6 of 10

Picture 1 The SS (labeled CS for Chip Select in the scope trace) is sent low to enable the EEPROM. Picture 2 SPI Overview and Operation The first byte is sent from the M16C28. Eight clocks are sent on SCLK (SCK in the scope trace), and the MOSI (SDO) data is Binary 00000011 (Hexadecimal 0x03) sent Most Significant Bit first. This is a command to the EEPROM to read from the memory. Picture 3 The next two bytes sent are 0x00 and 0x00 which is the 16bit address that the read should start from. Picture 4 Then with each byte clocked, the EEPROM will send back the contents of the memory at that address and automatically increment its address pointer. In the example we are clocking out 4 bytes from the memory starting at address 0x0000. The first byte is 0xAA so the contents of the EEPROM at address 0x0000 is 0xAA. Picture 5 The data on the MISO line shows the contents of the EEPROM at addresses 0x0001 thru 0x0003 are all 0xFF Picture 6 The SS is then sent high to deselect the slave and reset its logic, ready for the next command. 3.7 Data Words In keeping with the unrestrictive nature of SPI, the bit size of a data word is not defined. There are SPI slaves that logically use 8, 12, 16bit and other word sizes. The master configuration and software needs to be aware of this as it generates the correct number of clocks and interprets data to and from the buffers. To send a data word which is not a standard 8 bits, it is important to either set up the UART or serial peripheral to send clocked data bits without start and stop edges. Some peripherals may not support this, but it would always be possible to send words of any length using bit-banged I/O pins and custom firmware. This also means that there is no defined error checking or recovery system. At the application level it may be prudent to employ a checksum when communicating with a storage device like a serial EEPROM. For example; when writing a block of data to an EEPROM, the data could be used to calculate a checksum, then written to the EEPROM and then read back. The read data is then used to calculate a checksum and compared against the original to ensure the correct data was stored without errors. 3.8 Data Direction SPI data is sent and received Most Significant Bit (MSB) first. REJxxxxxxx-xxxx/Rev.0.10 February 2008 Page 7 of 10

4. Advantages and Disadvantages 4.1 Advantages Full Duplex Operation Potentially faster than I2C or Microwire due to decreased overhead Flexible packet size - not restricted to 8bit data User chooses message content and meaning Simple hardware interface Slaves use the master clock no need for additional oscillators No transceivers required physical interface is user defined Less pins required than parallel interface 4.2 Disadvantages More pins required on each device than I2C or < 4-wire interfaces No addressing so each slave needs independent SS signals No Slave acknowledgment No bus arbitration Multi-master systems are difficult to implement No formal standard makes quality control and testing more difficult 5. References SPI Block Guide - Freescale Semiconductor ST Micro M95080 SPI EEPROM Device Datasheet Maxim MAX542x Digital Potentiometer Datasheet National Semiconductor LM74 Temp Sensor Datasheet Renesas M16C28 Device Datasheet REJxxxxxxx-xxxx/Rev.0.10 February 2008 Page 8 of 10

Website and Support Renesas Technology Website http://www.renesas.com/ Renesas Technology America Website http://america.renesas.com/ Inquiries http://www.renesas.com/inquiry csc@renesas.com (Global Support) TechSupport.rta@renesas.com (United States / Canada / Mexico only) Revision Record Description Rev. Date Page Summary 0.10 Feb.07.08 Pre-Release 0.20 Feb.25.08 Multiple Changes to Layout and Content from 1 st Draft REJxxxxxxx-xxxx/Rev.0.10 February 2008 Page 9 of 10

Notes regarding these materials 1. This document is provided for reference purposes only so that Renesas customers may select the appropriate Renesas products for their use. Renesas neither makes warranties or representations with respect to the accuracy or completeness of the information contained in this document nor grants any license to any intellectual property rights or any other rights of Renesas or any third party with respect to the information in this document. 2. Renesas shall have no liability for damages or infringement of any intellectual property or other rights arising out of the use of any information in this document, including, but not limited to, product data, diagrams, charts, programs, algorithms, and application circuit examples. 3. You should not use the products or the technology described in this document for the purpose of military applications such as the development of weapons of mass destruction or for the purpose of any other military use. When exporting the products or technology described herein, you should follow the applicable export control laws and regulations, and procedures required by such laws and regulations. 4. All information included in this document such as product data, diagrams, charts, programs, algorithms, and application circuit examples, is current as of the date this document is issued. Such information, however, is subject to change without any prior notice. Before purchasing or using any Renesas products listed in this document, please confirm the latest product information with a Renesas sales office. Also, please pay regular and careful attention to additional and different information to be disclosed by Renesas such as that disclosed through our website. (http://www.renesas.com) 5. Renesas has used reasonable care in compiling the information included in this document, but Renesas assumes no liability whatsoever for any damages incurred as a result of errors or omissions in the information included in this document. 6. When using or otherwise relying on the information in this document, you should evaluate the information in light of the total system before deciding about the applicability of such information to the intended application. Renesas makes no representations, warranties or guaranties regarding the suitability of its products for any particular application and specifically disclaims any liability arising out of the application and use of the information in this document or Renesas products. 7. With the exception of products specified by Renesas as suitable for automobile applications, Renesas products are not designed, manufactured or tested for applications or otherwise in systems the failure or malfunction of which may cause a direct threat to human life or create a risk of human injury or which require especially high quality and reliability such as safety systems, or equipment or systems for transportation and traffic, healthcare, combustion control, aerospace and aeronautics, nuclear power, or undersea communication transmission. If you are considering the use of our products for such purposes, please contact a Renesas sales office beforehand. Renesas shall have no liability for damages arising out of the uses set forth above. 8. Notwithstanding the preceding paragraph, you should not use Renesas products for the purposes listed below: (1) artificial life support devices or systems (2) surgical implantations (3) healthcare intervention (e.g., excision, administration of medication, etc.) (4) any other purposes that pose a direct threat to human life Renesas shall have no liability for damages arising out of the uses set forth in the above and purchasers who elect to use Renesas products in any of the foregoing applications shall indemnify and hold harmless Renesas Technology Corp., its affiliated companies and their officers, directors, and employees against any and all damages arising out of such applications. 9. You should use the products described herein within the range specified by Renesas, especially with respect to the maximum rating, operating supply voltage range, movement power voltage range, heat radiation characteristics, installation and other product characteristics. Renesas shall have no liability for malfunctions or damages arising out of the use of Renesas products beyond such specified ranges. 10. Although Renesas endeavors to improve the quality and reliability of its products, IC products have specific characteristics such as the occurrence of failure at a certain rate and malfunctions under certain use conditions. Please be sure to implement safety measures to guard against the possibility of physical injury, and injury or damage caused by fire in the event of the failure of a Renesas product, such as safety design for hardware and software including but not limited to redundancy, fire control and malfunction prevention, appropriate treatment for aging degradation or any other applicable measures. Among others, since the evaluation of microcomputer software alone is very difficult, please evaluate the safety of the final products or system manufactured by you. 11. In case Renesas products listed in this document are detached from the products to which the Renesas products are attached or affixed, the risk of accident such as swallowing by infants and small children is very high. You should implement safety measures so that Renesas products may not be easily detached from your products. Renesas shall have no liability for damages arising out of such detachment. 12. This document may not be reproduced or duplicated, in any form, in whole or in part, without prior written approval from Renesas. 13. Please contact a Renesas sales office if you have any questions regarding the information contained in this document, Renesas semiconductor products, or if you have any other inquiries. 2007. Renesas Technology Corp., All rights reserved. REJxxxxxxx-xxxx/Rev.0.10 February 2008 Page 10 of 10