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

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

Using the Z8051 MCU s USI Peripheral as an SPI Interface

Interfacing Z8 Encore! XP MCUs with an I 2 C-Based Character LCD

Challenge. Hardware Circuit Details. Solution. Result. Features and Functions. Z8 Encore! MC

S3 Flash In-System Programmer

High Resolution Digital Weigh-Scale Design Using Z8 Encore! Microcontrollers

A Simple Console Application for Z8 Encore! XP MCUs

EEPROM Emulation with the ez80f91 MCU. Discussion

Flash Loader Utility for the Z8 Encore! XP MCU

Z8 Encore! XP/Z8 Encore! Development Kits

Z8 Encore! XP F0822 Series

An Automatic Temperature Control System Using RZK

Zilog Real-Time Kernel

Ethernet Smart Cable

Real Time Embedded Systems. Lecture 1 January 17, 2012

Implementing a Secure Digital Card with a ZNEO Microcontroller

Character LCD Interface for ez80acclaim! MCUs

Z8 Encore! XP F1680 Series 8-Bit Flash Solution with Extended Peripherals

Boot Loader for the Z51F6412 MCU

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

< W3150A+ / W5100 Application Note for SPI >

5x7 LED Matrix Display with Z8 Encore! XP

Lecture 14 Serial Peripheral Interface

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)

Microcontrollers and Interfacing

Set Up a PLL Loop Filter on the ez80f91 MCU

Serial Communication Controllers (SCC) MULTIPROTOCOL DATA COMMUNICATION SOLUTIONS

ZCRMZNICE01ZEMG Crimzon In-Circuit Emulator

ez80f91 Modular Development Kit

Universal Motor Control with Z8 Encore! XP 8-Pin Highly Integrated Microcontroller

ZLF645 Crimzon Flash Microcontroller with ZBase Database Industry Leading Universal Infrared Remote Control (UIR) Solution

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

High-Performance 8-Bit Microcontrollers. Up to 8 10-Bit ADC Channels. Two 16-Bit Timers/PWM. Internal Precision Oscillator

ZMOTION Detection Module Development Kit

Z8 Encore! XP F0822 Series Development Kit

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

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

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

Zatara Series ARM ASSP High-Performance 32-bit Solution for Secure Transactions

spi 1 Fri Oct 13 13:04:

Real Time Embedded Systems. Lecture 1 January 17, 2012

SPI Protocol of the TLE941xy family

Product Update. Errata to Z8 Encore! 8K Series Silicon. Z8 Encore! 8K Series Silicon with Date Codes 0402 and Later

Emulating Dual SPI Using FlexIO

SPI (Serial & Peripheral Interface)

Z8 Encore! XP 4K Series with extended Peripherals

ams AG austriamicrosystems AG is now The technical content of this austriamicrosystems document is still valid. Contact information:

C8051F700 Serial Peripheral Interface (SPI) Overview

BOOST YOUR SYSTEM PERFORMANCE USING THE ZILOG ESCC CONTROLLER

SPI Overview and Operation

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

Zilog TCP/IP Software Suite

SBAT90USB162 Atmel. SBAT90USB162 Development Board User s Manual

EDBG. Description. Programmers and Debuggers USER GUIDE

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

AN10428 UART-SPI Gateway for Philips SPI slave bridges

PIC Serial Peripheral Interface (SPI) to Digital Pot

S3F8S5A Development Kit

Arduino Uno R3 INTRODUCTION

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

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

Z8 Encore! XP Family of Microcontrollers Development Kits

Introduction to I2C & SPI. Chapter 22

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

USER GUIDE EDBG. Description

Serial Peripheral Interface (SPI) Host Controller Data Sheet

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

EE 308: Microcontrollers

SPI Block User Guide V02.07

Raspberry Pi - I/O Interfaces

Digital UART Product Specification

Please refer to "4. Evaluation Board" on page 2 for more information about these steps. Figure 1. System Connections

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

Using FlexIO to emulate communications and timing peripherals

Understanding SPI with Precision Data Converters

USER GUIDE. Atmel OLED1 Xplained Pro. Preface

PremierWave 2050 Enterprise Wi-Fi IoT Module Evaluation Kit User Guide

PARALLEL COMMUNICATIONS

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

Read section 8 of this document for detailed instructions on how to use this interface spec with LibUSB For OSX

Interfacing Techniques in Embedded Systems

Universität Dortmund. IO and Peripheral Interfaces

Level Shifter. for. Hardware User s Manual.

Temperature Sensor TMP2 PMOD Part 1

SPI 3-Wire Master (VHDL)

Serial Peripheral Interface (SPI)

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

UM0792 User manual. Demonstration firmware for the DMX-512 communication protocol transmitter based on the STM32F103Zx.

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

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

CB-1 Peripheral Board Technical Manual

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

Atmel ATtiny1634 MCU Atmel ATA SBC LIN transceiver with integrated voltage regulator Touch. Three Atmel QTouch buttons One Atmel QTouch slider

AN2673 Application note

AN4113 Application note

Mbed Microcontroller SPI. Spring, 2018 Prof. Jungkeun Park

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

From Datasheets to Digital Logic. synthesizing an FPGA SPI slave from the gates

Amarjeet Singh. January 30, 2012

Transcription:

Application Note Getting Started with ESPI Interface Using the Z8 Encore! XP F1680 AN027301-0308 Abstract This application note demonstrates how to use the Enhanced Serial Peripheral Interface (ESPI) in Master and Slave mode on Z8 Encore! XP F1680 microcontrollers. The software implementation provides several functions that enable users to initialize, send and receive a byte, and send and receive a block of up to 256 bytes. Note: The source code (AN0273-SC01) associated with this application note is available for download from www.zilog.com. Discussion The Serial Peripheral Interface bus is a synchronous, serial communication link that operates in full duplex, meaning that a device transmits and receives data simultaneously. The devices communicate as a Master/Slave, where the Master initiates communication by selecting a Slave device with a hardware line and also provides the synchronous clock used to shift data bits in and out of the Slave. The signals required for communication are the Slave Select (SS), Master In Slave Out (MISO), Master Out Slave In (MOSI), and Serial Clock (SCK). The advantages of SPI over other communication protocols is that the addressing is performed in hardware with the SS line, making it faster to address a device, and that communication is full duplex, allowing for faster transfers of data. SPI communication begins with the Master asserting the SS line. Depending upon the device, the SS line might be active high or active low. The Master must then wait at least one clock period before starting communication. Much like the active polarity of the SS line, the waiting period after SS activation varies from device to device. As an example, an analog-to-digital converter might require that the Master wait for a conversion to be completed after its SS line has been asserted. Next, the Master will begin shifting data out of the MOSI line, and it will shift data in on the MISO. Data is always transferred as full duplex, even when that data is not meaningful. As an example, for a Master to receive 24 bits of data from a Slave device it must also transmit 24 bits to the Slave device. See Figures 1 and 2 on page 2. Copyright 2008 by Zilog, Inc. All rights reserved. www.zilog.com

Phase 0 Timing Figure 1. Phase 0 Timing Phase 1 Timing Figure 2. Phase 1 Timing AN027301-0308 Page 2 of 8

There is no standard for which clock edges are used for transmitting and receiving data, which leaves four possible modes of operation, depending on clock polarity and clock phasing. See the following table. SPI Modes MODE SCK Polarity SCK Phase SCK Transmit Edge SCK Receive Edge SCK Idle State 0 0 0 Falling Rising Low 1 0 1 Rising Falling Low 2 1 0 Rising Falling High 3 1 1 Falling Rising High Using Mode 1 as an example, the Master would idle the bus with the SCK line low. When the Master pushes the SCK line high, it will also place the most significant bit first on the MOSI line. At the same time, the Slave will place the most significant first on the MISO line. Next, the Master pulls the SCK line and reads the stable bit from the Slave on the MISO line. At the same time, the Slave reads a stable bit generated from the Master on the MOSI line. Communication is terminated when the SS line is deactivated, so it must remain active during the entire communication frame. Testing the SPI Master/Slave Sample Hardware The Z8 Encore! XP F1680 microcontroller does have a hardware peripheral for SPI support. To test the software provided with this application note, two Z8 Encore! XP F1680 28-Pin Development Kits are required. Hardware Preparation One development kit will be used as a Master device, and the second development kit will be used as a Slave device. Along with a common ground, the SS, SCK, MOSI, and MISO lines will need to be jumpered together between the two devices. 1. Run a wire from the Master s J2-16 to the Slave s J2-16. This will serve as ground. 2. Run a wire from the Master s JP2-12 to the Slave s JP2-12. This will serve as the SCK line. 3. Run a wire from the Master s J2-11 to the Slave s J2-11. This will serve as the MISO line. 4. Run a wire from the Master s J2-13 to the Slave s J2-13. This will serve as the SS line 5. Run a wire from the Master s JP2-11 to the Slave s JP2-11. This will serve as the MOSI line. Software APIs The software APIs required for using the Master and Slave driver are located in the spi.c file. Three functions are available to drive the SPI hardware interface: SPI_Init SPI_SendReceive SPI_SendReceiveBlock AN027301-0308 Page 3 of 8

Definitions DATASIZE Determines the size of the input buffer. Because the Master determines how much data is exchanged on a transfer, DATASIZE needs to be at least as large as the number of bytes exchanged by the Master. Globals No global variable is defined in the SPI module. However, the main file contains one global, which is used for the input buffer, DataIn[DATASIZE]. APIs void SPI_Init(unsigned short freq, char mode, char phase, char clkpol) This function will initialize the SPI interface. The parameter freq is used to set the baud rate (value from 0 to 0xFFFF, 0 = slowest baud rate, 0x0001 = fastest baud rate), the parameter mode is used to determine if the SPI interface is configured as Master or as Slave (value = MASTER or SLAVE), the parameter phase is used to determine the phase (value = TRUE or FALSE), and the parameter clkpol is used to determine the clock polarity (value = TRUE or FALSE). char SPI_SendReceive(char data, char mode) This function will transmit the byte in data and will return the byte received. The parameter mode is used to determine if the SPI interface is configured as Master or as Slave (value = MASTER or SLAVE). void SPI_SendReceiveBlock(char* p_out, char* p_in, unsigned char length, char mode) This function will transmit length bytes (value from 0 to 0xFF, 0 = 256 bytes) pointed to by p_out and will store length bytes received in the buffer pointed to by p_in. The parameter mode is used to determine if the SPI interface is configured as Master or as Slave (value = MASTER or SLAVE). Usage In addition to calling the SPI_Init function, your software must include code to set the alternate function register in order to route the SPI pins to the IO pins. This code can be: PCADDR = 0x02; PCCTL = 0x36; // Select alternate function // Enable SPI interface To perform a data transfer in your application, use the SPI_SendReceive function for a single byte or SPI_SendReceiveBlock with the parameter p_out pointing to the n data (n is passed in the parameter length) to send and the parameter p_in pointing to the buffer where the data received will be stored. Software Preparation 1. Build the Master Zilog Developer Studio (ZDS) project and flash the code into the Master development board. 2. Build the Slave ZDS project and flash the code into the Slave development board. 3. Reset the Slave then the Master development boards by pressing SW1 or power cycling the boards. AN027301-0308 Page 4 of 8

Testing the Hardware SPI Master/Slave Sample Software Master The Master software will send the string Hello ZiLOG! to the Slave; then it will wait until the switch SW2 is pressed. The Slave will respond with the same string to the Master and will light D3 if the string received is correct. If this response is not received by the Master, then the Master will light LED D4 to signal that an error has occurred. If no error occurs, the Master lights LED D2. Then, with each press of switch SW2, the Master will increase the value of the byte sent to the Slave until the value reaches 128, and then the Master will start over again sending a value of 1. If the response sent by the slave is equal to 0xAA, the Master will light LED D2. If it is not, the Master will light LED D4. At power-up, the Master will call SPI_Init to configure the SPI interface. Next, the Master calls IdlePorts() to configure switch SW2 and LEDs D2, D4 for the correct direction and configure the alternate function register. Next, the Master will send the string Hello ZiLOG! and verify that it is also received from the Slave. In this case, it will light the LED D2. If the string received is not correct, it will light the LED D4. The Main Loop waits 62.5 ms to help debounce the switch, and then the switch is read. If the switch is closed, a byte is increased for use by the Slave s PWM. Next, the Master starts the exchange by calling SPI_SendReceive. After SPI_SendReceive completes, the Master compares the data received to verify that the Slave responded 0xAA. If the Slave responded, then LED D4 is turned off, and LED D2 is turned on. If the Slave did not respond, then LED D2 is turned off, and LED D4 is turned on. Slave At power-up, the Slave will call SPI_Init to configure the SPI interface. Next, the Slave will call IdlePorts to initialize the PWM on LED D3 and configure the alternate register. Next, the Slave will call SPI_SendReceiveBlock to send the string Hello ZiLOG! and will turn on LED D3 if the same string is received from the Master. In the Main loop, the Slave will wait for an exchange from the Master and perform a PWM on LED D3 based upon the value received by the Master. The Slave always responds to the Master with the value 0xAA. AN027301-0308 Page 5 of 8

Testing the Hardware SPI Master/Software SPI Slave Testing the Software SPI Master/Hardware SPI Slave It is possible to connect the F1680 development board to the F083A development board in order to have hardware SPI communicating with software SPI. Hardware Preparation One development kit will be used as a Master device, and the second development kit will be used as a Slave device. Along with a common ground, the SS, SCK, MOSI, and MISO lines will need to be jumpered together between the two devices. 1. Run a wire from the F1680 s J2-16 to the F083A s J2-16. This will serve as ground. 2. Run a wire from the F1680 s JP2-12 to the F083A s J2-9. This will serve as the SCK line. 3. Run a wire from the F1680 s J2-11 to the F083A s J2-11. This will serve as the MISO line. 4. Run a wire from the F1680 s J2-13 to the F083A s J2-13. This will serve as the SS line 5. Run a wire from the F1680 s JP2-11 to the F083A s J2-15. This will serve as the MOSI line. Software Preparation The source code (AN0267-SC01) available from www.zilog.com will be used for the software SPI. 1. Build the Master ZDS project and flash the code into the Master development board. 2. Build the Slave ZDS project and flash the code into the Slave development board. 3. Reset the Slave then the Master development boards by pressing SW1 or power cycling the boards. AN027301-0308 Page 6 of 8

Summary This application note demonstrates how to use the hardware Serial Peripheral Interface Master and Slave functionality on Z8 Encore! XP F1680 microcontrollers. Appendix A References Topic Z8 Encore! MCU ZDS II SPI Master Development Kit SPI Protocol Document Name Z8 Encore! XP F1680 Series Product Specification (PS0250) Z8 Encore! MCU User Manual (UM0128) Zilog Developer Studio II Z8 Encore! User Manual (UM0130) Z8 Encore! XP F64xx Series Product Specification (PS0199) Z8 Encore! XP F1680 Series Development Kit User Manual (UM0203) http://www.embedded.com/story/oeg20020124s0116 AN027301-0308 Page 7 of 8

Warning: DO NOT USE IN LIFE SUPPORT LIFE SUPPORT POLICY ZILOG'S PRODUCTS ARE NOT AUTHORIZED FOR USE AS CRITICAL COMPONENTS IN LIFE SUPPORT DEVICES OR SYSTEMS WITHOUT THE EXPRESS PRIOR WRITTEN APPROVAL OF THE PRESIDENT AND GENERAL COUNSEL OF ZILOG CORPORATION. As used herein Life support devices or systems are devices which (a) are intended for surgical implant into the body, or (b) support or sustain life and whose failure to perform when properly used in accordance with instructions for use provided in the labeling can be reasonably expected to result in a significant injury to the user. A critical component is any component in a life support device or system whose failure to perform can be reasonably expected to cause the failure of the life support device or system or to affect its safety or effectiveness. Document Disclaimer 2008 by Zilog, Inc. All rights reserved. Information in this publication concerning the devices, applications, or technology described is intended to suggest possible uses and may be superseded. ZILOG, INC. DOES NOT ASSUME LIABILITY FOR OR PROVIDE A REPRESENTATION OF ACCURACY OF THE INFORMATION, DEVICES, OR TECHNOLOGY DESCRIBED IN THIS DOCUMENT. ZILOG ALSO DOES NOT ASSUME LIABILITY FOR INTELLECTUAL PROPERTY INFRINGEMENT RELATED IN ANY MANNER TO USE OF INFORMATION, DEVICES, OR TECHNOLOGY DESCRIBED HEREIN OR OTHERWISE. The information contained within this document has been verified according to the general principles of electrical and mechanical engineering. Z8, Z8 Encore!, and Z8 Encore! XP are registered trademarks of Zilog, Inc. All other product or service names are the property of their respective owners. AN027301-0308 Page 8 of 8