AVR1309: Using the XMEGA SPI. 8-bit Microcontrollers. Application Note. Features. 1 Introduction SCK MOSI MISO SS



Similar documents
AVR1318: Using the XMEGA built-in AES accelerator. 8-bit Microcontrollers. Application Note. Features. 1 Introduction

AVR1600: Using the XMEGA Quadrature Decoder. 8-bit Microcontrollers. Application Note. Features. 1 Introduction. Sensors

AVR32701: AVR32AP7 USB Performance. 32-bit Microcontrollers. Application Note. Features. 1 Introduction

Using CryptoMemory in Full I 2 C Compliant Mode. Using CryptoMemory in Full I 2 C Compliant Mode AT88SC0104CA AT88SC0204CA AT88SC0404CA AT88SC0808CA

AVR1301: Using the XMEGA DAC. 8-bit Microcontrollers. Application Note. Features. 1 Introduction

AVR319: Using the USI module for SPI communication. 8-bit Microcontrollers. Application Note. Features. Introduction

8-bit. Application Note. Microcontrollers. AVR282: USB Firmware Upgrade for AT90USB

AVR1900: Getting started with ATxmega128A1 on STK bit Microcontrollers. Application Note. 1 Introduction

AVR1510: Xplain training - XMEGA USART. 8-bit Microcontrollers. Application Note. Prerequisites. 1 Introduction

AVR1922: Xplain Board Controller Firmware. 8-bit Microcontrollers. Application Note. Features. 1 Introduction

AVR317: Using the Master SPI Mode of the USART module. 8-bit Microcontrollers. Application Note. Features. Introduction

Application Note. 8-bit Microcontrollers. AVR270: USB Mouse Demonstration

AVR32138: How to optimize the ADC usage on AT32UC3A0/1, AT32UC3A3 and AT32UC3B0/1 series. 32-bit Microcontrollers. Application Note.

AVR353: Voltage Reference Calibration and Voltage ADC Usage. 8-bit Microcontrollers. Application Note. Features. 1 Introduction

AVR033: Getting Started with the CodeVisionAVR C Compiler. 8-bit Microcontrollers. Application Note. Features. 1 Introduction

AVR305: Half Duplex Compact Software UART. 8-bit Microcontrollers. Application Note. Features. 1 Introduction

Application Note. 8-bit Microcontrollers. AVR272: USB CDC Demonstration UART to USB Bridge

AVR2006: Design and characterization of the Radio Controller Board's 2.4GHz PCB Antenna. Application Note. Features.

AVR32788: AVR 32 How to use the SSC in I2S mode. 32-bit Microcontrollers. Application Note. Features. 1 Introduction

AVR151: Setup and Use of the SPI. Introduction. Features. Atmel AVR 8-bit Microcontroller APPLICATION NOTE

Atmel AVR4921: ASF - USB Device Stack Differences between ASF V1 and V2. 8-bit Atmel Microcontrollers. Application Note. Features.

AVR287: USB Host HID and Mass Storage Demonstration. 8-bit Microcontrollers. Application Note. Features. 1 Introduction

Atmel AVR4920: ASF - USB Device Stack - Compliance and Performance Figures. Atmel Microcontrollers. Application Note. Features.

AVR115: Data Logging with Atmel File System on ATmega32U4. Microcontrollers. Application Note. 1 Introduction. Atmel

Application Note. 8-bit Microcontrollers. AVR293: USB Composite Device

8051 Flash Microcontroller. Application Note. A Digital Thermometer Using the Atmel AT89LP2052 Microcontroller

General Porting Considerations. Memory EEPROM XRAM

USER GUIDE EDBG. Description

3-output Laser Driver for HD-DVD/ Blu-ray/DVD/ CD-ROM ATR0885. Preliminary. Summary. Features. Applications. 1. Description

AVR245: Code Lock with 4x4 Keypad and I2C LCD. 8-bit Microcontrollers. Application Note. Features. 1 Introduction

AVR055: Using a 32kHz XTAL for run-time calibration of the internal RC. 8-bit Microcontrollers. Application Note. Features.

AT91SAM ARM-based Flash MCU. Application Note

AVR2004: LC-Balun for AT86RF230. Application Note. Features. 1 Introduction

Atmel AVR4903: ASF - USB Device HID Mouse Application. Atmel Microcontrollers. Application Note. Features. 1 Introduction

Application Note. C51 Bootloaders. C51 General Information about Bootloader and In System Programming. Overview. Abreviations

AVR32100: Using the AVR32 USART. 32-bit Microcontrollers. Application Note. Features. 1 Introduction

AVR1003: Using the XMEGA Clock System. 8-bit Microcontrollers. Application Note. Features. 1 Introduction

8-bit RISC Microcontroller. Application Note. AVR910: In-System Programming

AVR030: Getting Started with IAR Embedded Workbench for Atmel AVR. 8-bit Microcontrollers. Application Note. Features.

How To Use An Atmel Atmel Avr32848 Demo For Android (32Bit) With A Microcontroller (32B) And An Android Accessory (32D) On A Microcontroller (32Gb) On An Android Phone Or

APPLICATION NOTE. Atmel AVR134: Real Time Clock (RTC) Using the Asynchronous Timer. Atmel AVR 8-bit Microcontroller. Introduction.

AVR1321: Using the Atmel AVR XMEGA 32-bit Real Time Counter and Battery Backup System. 8-bit Microcontrollers. Application Note.

AVR32110: Using the AVR32 Timer/Counter. 32-bit Microcontrollers. Application Note. Features. 1 Introduction

8-bit RISC Microcontroller. Application Note. AVR182: Zero Cross Detector

AT91 ARM Thumb Microcontrollers. AT91SAM CAN Bootloader. AT91SAM CAN Bootloader User Notes. 1. Description. 2. Key Features

32-bit AVR UC3 Microcontrollers. 32-bit AtmelAVR Application Note. AVR32769: How to Compile the standalone AVR32 Software Framework in AVR32 Studio V2

AVR125: ADC of tinyavr in Single Ended Mode. 8-bit Microcontrollers. Application Note. Features. 1 Introduction

AVR134: Real Time Clock (RTC) using the Asynchronous Timer. 8-bit Microcontrollers. Application Note. Features. 1 Introduction

8-bit RISC Microcontroller. Application Note. AVR155: Accessing an I 2 C LCD Display using the AVR 2-wire Serial Interface

Atmel AVR1017: XMEGA - USB Hardware Design Recommendations. 8-bit Atmel Microcontrollers. Application Note. Features.

Application Note. Atmel ATSHA204 Authentication Modes. Prerequisites. Overview. Introduction

8-bit RISC Microcontroller. Application Note. AVR236: CRC Check of Program Memory

APPLICATION NOTE. Atmel AT04389: Connecting SAMD20E to the AT86RF233 Transceiver. Atmel SAMD20. Description. Features

APPLICATION NOTE. Atmel AT02985: User s Guide for USB-CAN Demo on SAM4E-EK. Atmel AVR 32-bit Microcontroller. Features. Description.

AT89C5131A Starter Kit... Software User Guide

APPLICATION NOTE Atmel AT02509: In House Unit with Bluetooth Low Energy Module Hardware User Guide 8-bit Atmel Microcontroller Features Description

Application Note. USB Microcontrollers. USB PC Drivers Based on Generic HID Class. 1. Introduction

8-bit Microcontroller. Application Note. AVR415: RC5 IR Remote Control Transmitter. Features. Introduction. Figure 1.

AT91 ARM Thumb Microcontrollers. Application Note. Interfacing a PC Card to an AT91RM9200-DK. Introduction. Hardware Interface

APPLICATION NOTE. Atmel LF-RFID Kits Overview. Atmel LF-RFID Kit. LF-RFID Kit Introduction

8-bit Microcontroller. Application Note. AVR222: 8-point Moving Average Filter

SMARTCARD XPRO. Preface. SMART ARM-based Microcontrollers USER GUIDE

USER GUIDE. ZigBit USB Stick User Guide. Introduction

APPLICATION NOTE. Atmel AVR443: Sensor-based Control of Three Phase Brushless DC Motor. Atmel AVR 8-bit Microcontrollers. Features.

256K (32K x 8) Battery-Voltage Parallel EEPROMs AT28BV256

AVR ONE!... Quick-start Guide. EVK Windows 32104B AVR ONE! 02/10

AVR223: Digital Filters with AVR. 8-bit Microcontrollers. Application Note. Features. 1 Introduction

Application Note. Atmel CryptoAuthentication Product Uses. Atmel ATSHA204. Abstract. Overview

Quick Start Guide. CAN Microcontrollers. ATADAPCAN01 - STK501 CAN Extension. Requirements

APPLICATION NOTE. Secure Personalization with Transport Key Authentication. ATSHA204A, ATECC108A, and ATECC508A. Introduction.

AT88CK490 Evaluation Kit

AVR106: C functions for reading and writing to Flash memory. 8-bit Microcontrollers. Application Note. Features. Introduction

8-bit Microcontroller. Application Note. AVR134: Real-Time Clock (RTC) using the Asynchronous Timer. Features. Theory of Operation.

Implementing SPI Master and Slave Functionality Using the Z8 Encore! F083A

3-output Laser Driver for HD-DVD/ Blu-ray/DVD/ CD-ROM ATR0885. Preliminary. Summary

8-bit Microcontroller. Application Note. AVR400: Low Cost A/D Converter

8-bit Microcontroller. Application Note. AVR105: Power Efficient High Endurance Parameter Storage in Flash Memory

Introducing a platform to facilitate reliable and highly productive embedded developments

APPLICATION NOTE. Atmel AT01095: Joystick Game Controller Reference Design. 8-/16-bit Atmel Microcontrollers. Features.

How to Calculate the Capacitor of the Reset Input of a C51 Microcontroller 80C51. Application Note. Microcontrollers. Introduction

APPLICATION NOTE. Authentication Counting. Atmel CryptoAuthentication. Features. Introduction

AT89LP Flash Data Memory. Application Note. AT89LP Flash Data Memory API. 1. Introduction. 2. Theory of Operation. 2.1 Flash Memory Operation

APPLICATION NOTE. AT07175: SAM-BA Bootloader for SAM D21. Atmel SAM D21. Introduction. Features

Application Note. 8-bit Microcontrollers. AVR280: USB Host CDC Demonstration. 1. Introduction

8-bit Microcontroller. Application Note. AVR201: Using the AVR Hardware Multiplier

How To Design An Ism Band Antenna For 915Mhz/2.4Ghz Ism Bands On A Pbbb (Bcm) Board

8-bit Microcontroller. Application Note. AVR286: LIN Firmware Base for LIN/UART Controller. LIN Features. 1. Atmel LIN/UART Controller

AVR442: PC Fan Control using ATtiny13. 8-bit Microcontrollers. Application Note. Features. 1 Introduction

8-bit Microcontroller. Application Note. AVR314: DTMF Generator

64K (8K x 8) Parallel EEPROM with Page Write and Software Data Protection AT28C64B

Software Prerequisites Linux Ubuntu LTS. Estimated completion time: 15min. The goal of this hands-on is to:

AVR318: Dallas 1-Wire master. 8-bit Microcontrollers. Application Note. Features. Introduction

USB Test Environment ATUSBTEST- SS7400. Summary

AVR315: Using the TWI Module as I2C Master. Introduction. Features. AVR 8-bit Microcontrollers APPLICATION NOTE

Tag Tuning/RFID. Application Note. Tag Tuning. Introduction. Antenna Equivalent Circuit

Atmel AVR4027: Tips and Tricks to Optimize Your C Code for 8-bit AVR Microcontrollers. 8-bit Atmel Microcontrollers. Application Note.

MODFLEX MINI GATEWAY ETHERNET USER S GUIDE

QT1 Xplained Pro. Preface. Atmel QTouch USER GUIDE

AVR311: Using the TWI Module as I2C Slave. Introduction. Features. AVR 8-bit Microcontrollers APPLICATION NOTE

CryptoAuth Xplained Pro

Transcription:

AVR1309: Using the XMEGA SPI Features Introduction to SPI and the XMEGA SPI module Setup and use of the XMEGA SPI module Implementation of module drivers Polled master Interrupt controlled master Polled slave Interrupt controlled slave Code examples for interrupt controlled and polled drivers 8-bit Microcontrollers Application Note 1 Introduction This application note describes how to set up and use the SPI module in the AVR XMEGA. Both interrupt controlled and polled C code drivers and examples are included for master and slave applications. Serial buses are more and more preferred over parallel. The wiring is simpler, and as the efficiency of serial interfaces increases, the speed advantage of a parallel transmission gets less important. Typical peripherals that use a serial interface are converters (A/D and D/A), memories (RAM and EEPROM), real time clocks, sensors and other controllers for LCD, CAN USB etc. Figure 1-1. Basic SPI implementation MASTER SLAVE Rev.

2 The SPI bus The Serial Peripheral Interface (SPI) is mainly used in synchronous serial transmissions in a master/slave relationship. The master initiates and controls the transfer, while the slave responds. SPI is a full duplex interface, and at a low cost enabling high-speed communication between master and slave. SPI does not have a specific higher-level protocol, which means there is almost no overhead. The drawback is that there is no acknowledgement and flow control, and the master doesn t even have to be aware of the slave s presence. 2.1 Data and control lines The standard SPI configuration makes use of two control and two data lines. The data lines are (Master Out, Slave In) and (Master In, Slave Out), transferring data in each direction. The control lines are (SPI Clock) and (Slave Select). If is used, the master selects a slave device by pulling this line low, and supplies the clock signal. Data is now transferred in both directions simultaneously, and it is up to a higher-level protocol to define the meaning of each byte. Figure 2-1. Master/slave interconnection MASTER SLAVE MSB LSB 8 BIT SHIFT REGISTER MSB LSB 8 BIT SHIFT REGISTER SPI CLOCK GENERATOR SHIFT ENABLE GPIO If multiple slaves exists and should be independently addressed, the master must generate a signal for each slave. This is illustrated in Figure 2-2. 2 AVR1309

AVR1309 Figure 2-2. Multi slave implementation MASTER 1 SLAVE #1 2 3 SLAVE #2 SLAVE #3 2.2 Modes and configuration There is no official specification for SPI communication, making flexibility of the devices important. Clock polarity (CPOL) and clock phase (CPHA) determines the data setup and sampling point, and must be configured the same for devices to communicate. Table 2-1. SPI modes SPI mode Configuration CPOL CPHA Leading edge Trailing edge 0 0 0 Rising Sample Falling Setup 1 0 1 Rising Setup Falling Sample 2 1 0 Falling Sample Rising Setup 3 1 1 Falling Setup Rising Sample For more information about SPI modes and configuration, please see the XMEGA SPI data sheet. 3

3 The XMEGA SPI module The XMEGA SPI module is designed for high-speed data transfers between the XMEGA and other SPI devices. The control bits allow flexible configuration to enable a flawless connection. 3.1 Registers The SPI module consists of the baud rate generator, status and control logic with supporting registers listed in Table 3-1. Table 3-1. SPI module registers. Register name SPI Control Register SPI Interrupt Control Register SPI Status Register SPI Data Register C struct and element SPIx.CTRL SPIx.INTCTRL SPIx.STATUS SPIx.DATA All control bits with exception of the interrupt level bits, are located in CTRL. The two interrupt level bits are found in INTCTRL, and the SPI interrupt and write collision flags in STATUS. The DATA register is a read/write register for data transfers. Reading the registers returns the data currently in the SPI shift register, while writing will initiate a data transmission. The system is single buffered in the transmit direction and double buffered in the receive direction. As a result, new data must not be written to the DATA register before the entire shift cycle is complete. To avoid losing data, a received character must be read from DATA before the next character has been completely shifted in. 3.2 The pin In master mode the pin is fully configurable from software, and typically used as one of these three options: Input (interrupt) from other master(s) accessing the bus Output signal to slave General output If the SPI module s pin is configured as input, the function is like the first option above. This input function is controlled from the SPI module hardware, and the pin must be held logic high to ensure master SPI operation. If pulled low by other master(s) using the SPI bus, the SPI module will avoid bus contention by entering slave mode and consequently not driving the and lines. Entering slave mode is signaled by setting the SPI interrupt flag, generating an interrupt if enabled. Configuring the pin as output enables the two last typical options, both controlled from software and not affecting the SPI module operation. The pin is no different than any other GPIO pins when it is configured as an output. Often, several slaves are connected to the same bus, while the application would address one slave at a time. As illustrated in Figure 2-2, this can be done using 4 AVR1309

AVR1309 several GPIO pins, one for each slave or through some external logic reducing the number of pins needed. 4 SPI driver The driver included in this application note supports both polled and interruptcontrolled SPI operation for both master and slave. The driver is intended for rapid prototyping and to get started with the XMEGA SPI module. 4.1 Files The SPI driver source code consists of the following files: spi_driver.c driver source file spi_driver.h driver header file For a complete overview of the available driver interface functions and their use, please refer to the source code documentation. 5 Code examples Two code examples are included that show how to use the SPI drivers for interruptdriven and polled operation. In both examples, SPIC is used as master, while SPID serves as slave. 5.1 Files The SPI code examples are contained in the following files: spi_interrupt_example.c spi_polled_example.c Example of interrupt-driven SPI operation Example of polled SPI operation 5.2 Interrupt-driven The interrupt-driven code example uses the SPI driver to instantiate a master and a slave. A data packet is then initialized and sent to the slave. When data is received at the slave, an ISR increments the data before it is put back in the data register, ready to be shifted back to the master. The master interrupt handler will transfer the number of bytes contained in the data packet. When the complete flag for the data packet is set, the master verifies that it has received the correct values. 5.3 Polled The polled code example uses the SPI driver to instantiate a master and slave. The example is split into two sections: First, the master sends one byte at the time to the slave, the slave increments the byte and puts it in the shift register. The master sends a dummy byte, in order to fetch the byte from the slave. The master then verifies that it has received the correct value. In the second section, a data packet is initialized and sent to the slave. The slave does not manipulate the data, which is shifted back to the slave as new bytes are 5

transferred. When the whole packet is sent, the master verifies that the received bytes match the sent bytes (except for the last byte which is not shifted back to the master). 6 Doxygen Documentation All source code is prepared for automatic documentation generation using Doxygen. Doxygen is a tool for generating documentation from source code by analyzing the source code and using special keywords. For more details about Doxygen please visit http://www.doxygen.org. Precompiled Doxygen documentation is also supplied with the source code accompanying this application note, available from the readme.html file in the source code folder. 6 AVR1309

Disclaimer Headquarters International Atmel Corporation 2325 Orchard Parkway San Jose, CA 95131 USA Tel: 1(408) 441-0311 Fax: 1(408) 487-2600 Atmel Asia Room 1219 Chinachem Golden Plaza 77 Mody Road Tsimshatsui East Kowloon Hong Kong Tel: (852) 2721-9778 Fax: (852) 2722-1369 Atmel Europe Le Krebs 8, Rue Jean-Pierre Timbaud BP 309 78054 Saint-Quentin-en- Yvelines Cedex France Tel: (33) 1-30-60-70-00 Fax: (33) 1-30-60-71-11 Atmel Japan 9F, Tonetsu Shinkawa Bldg. 1-24-8 Shinkawa Chuo-ku, Tokyo 104-0033 Japan Tel: (81) 3-3523-3551 Fax: (81) 3-3523-7581 Product Contact Web Site www.atmel.com Technical Support avr@atmel.com Sales Contact www.atmel.com/contacts Literature Request www.atmel.com/literature Disclaimer: The information in this document is provided in connection with Atmel products. No license, express or implied, by estoppel or otherwise, to any intellectual property right is granted by this document or in connection with the sale of Atmel products. EXCEPT AS SET FORTH IN ATMEL S TERMS AND CONDITIONS OF SALE LOCATED ON ATMEL S WEB SITE, ATMEL AUMES NO LIABILITY WHATSOEVER AND DISCLAIMS ANY EXPRE, IMPLIED OR STATUTORY WARRANTY RELATING TO ITS PRODUCTS INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTY OF MERCHANTABILITY, FITNE FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, CONSEQUENTIAL, PUNITIVE, SPECIAL OR INCIDENTAL DAMAGES (INCLUDING, WITHOUT LIMITATION, DAMAGES FOR LO OF PROFITS, BUSINE INTERRUPTION, OR LO OF INFORMATION) ARISING OUT OF THE USE OR INABILITY TO USE THIS DOCUMENT, EVEN IF ATMEL HAS BEEN ADVISED OF THE POIBILITY OF SUCH DAMAGES. Atmel makes no representations or warranties with respect to the accuracy or completeness of the contents of this document and reserves the right to make changes to specifications and product descriptions at any time without notice. Atmel does not make any commitment to update the information contained herein. Unless specifically provided otherwise, Atmel products are not suitable for, and shall not be used in, automotive applications. Atmel s products are not intended, authorized, or warranted for use as components in applications intended to support or sustain life. 2008 Atmel Corporation. All rights reserved. Atmel, logo and combinations thereof, AVR and others, are the registered trademarks or trademarks of Atmel Corporation or its subsidiaries. Other terms and product names may be trademarks of others.