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



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

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

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

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

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

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

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

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

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

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

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

AVR033: Getting Started with the CodeVisionAVR C Compiler. 8-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

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

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

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

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

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

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

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

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

AT91SAM ARM-based Flash MCU. Application Note

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.

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

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

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

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

USER GUIDE EDBG. Description

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

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

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

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

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

General Porting Considerations. Memory EEPROM XRAM

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

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

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

USER GUIDE. ZigBit USB Stick User Guide. Introduction

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Introducing a platform to facilitate reliable and highly productive embedded developments

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

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

AT88CK490 Evaluation Kit

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

AT89C5131A Starter Kit... Software User Guide

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

Atmel AT32UC3A3256 microcontroller 64MBit SDRAM Analog input (to ADC) Temperature sensor RC filter

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

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

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

Two mechanical buttons Two user LEDs Four expansion headers. Board controller with USB interface. One power LED and one status LED

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

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

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

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

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

AVR106: C Functions for Reading and Writing to Flash Memory. Introduction. Features. AVR 8-bit Microcontrollers APPLICATION NOTE

Application Note. 1. Introduction. 2. Associated Documentation. 3. Gigabit Ethernet Implementation on SAMA5D3 Series. AT91SAM ARM-based Embedded MPU

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

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

Dell One Identity Cloud Access Manager How to Configure vworkspace Integration

New Features and Enhancements

Atmel AVR ATxmega384C3 microcontroller OLED display with pixels resolution Analog sensors. Ambient light sensor Temperature sensor

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

APPLICATION NOTE. AT16268: JD Smart Cloud Based Smart Plug Getting. Started Guide ATSAMW25. Introduction. Features

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

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

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

AVR1324: XMEGA ADC Selection Guide. 8-bit Atmel Microcontrollers. Application Note. Features. 1 Introduction

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

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

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

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

AT15007: Differences between ATmega328/P and ATmega328PB. Introduction. Features. Atmel AVR 8-bit Microcontrollers APPLICATION NOTE

formerly Help Desk Authority Quest Free Network Tools User Manual

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

Dell Spotlight on Active Directory Server Health Wizard Configuration Guide

AVR131: Using the AVR s High-speed PWM. Introduction. Features. AVR 8-bit Microcontrollers APPLICATION NOTE

APPLICATION NOTE. Atmel AVR600: STK600 Expansion, Routing and Socket Boards. Atmel Microcontrollers. Introduction

Transcription:

AVR1510: Xplain training - XMEGA USART Prerequisites Required knowledge AVR1500: Xplain training XMEGA Basics AVR1502: Xplain training XMEGA Direct Memory Access Controller Software prerequisites Atmel AVR Studio 4.18 or later WinAVR/GCC 20100110 or later Hardware prerequisites Xplain evaluation board JTAGICE mkii Estimated completion time: 1.5 hours 8-bit Microcontrollers Application Note 1 Introduction The USART (Universal Synchronous Asynchronous Receiver Transmitter) is the key element in serial communications between computers, terminals and other devices. This training covers basic setup and use of the Atmel XMEGA USART and the three tasks will demonstrate how to use the USART I polling-mode, interrupt mode and how to use the DMAC (Direct Memory Access Controller) to transfer data without CPU interaction. Rev.

2 Overview This training covers some of the Atmel XMEGA USART basic features: Task 1: Polled mode The first task shows how to set up the USART in polling mode. Some characters will be transferred in loop-back mode. Task 2: Interrupt mode This task shows how to use a driver to set up the USART. The driver has a ring buffer that makes life easier for the developer. Also the hardware buffer is shown in this task. Task 3: DMAC Atmel XMEGA introduces Direct Memory Access Controller (DMAC) for 8-bit processors. With the USART, DMAC is very useful allowing data to flow with nearly no CPU intervention. This task will show how to set up the USART with the DMAC. 2 AVR1510

3 Task 1: USART in polling mode AVR1510 Using polling mode with the USART is especially useful when for example debugging the application or when steps in the program are expected to happen synchronously. In this task, we will set up the Xplain evaluation board to send data from USART to another USART. This is a good way to test the USART. The goal for this task is that you know how to: Set up the USART in polling mode Send some characters in loop-back mode Verify that the transmission was successful 1. Start Atmel AVR Studio and open the project file Polled_Usart.aps in the XMEGA- USART folder 2. On the Xplain evaluation board, connect a jumper or cable between pins PD2 and PD3 3.1 Baud rate The Baud rate is calculated by using the peripheral frequency (f PER ), the BSCALE and BSEL as parameters. The target frequency and peripheral frequency on the Atmel XMEGA is set to 2 MHz default. The BSEL bits are setting the baud rate, and the BSCALE is adding even more functionality, but is ignored at this stage. By setting BSCALE to 0, the BSEL can be found by Equation 3-1. Equation 3-1. Equation for Calculating BSEL Value f PER BSEL = 1 BSCALE 2 16 f BAUD 3. Calculate and find the BSEL value for f BAUD = 9600 4. Verify that the calculated value is the same as in task1.c 5. Compile the project and verify that there are no errors or warnings 3

3.2 Debugging the Polled USART 6. Look through the code and see comments. Try to understand what happens 7. Build the project and start a debug session (click the Play icon) 8. Add a breakpoint on the while-loop as seen in Figure 3-1 9. Add watches to the Rx_Buf and the Tx_Buf 10. Run the code (press F5) 11. Confirm that the Rx_Buf and the Tx_Buf are equal 12. Single step (F11) and check that no transfer error occurred (LEDs light up) Figure 3-1: Add break-point in the last while-loop 4 AVR1510

AVR1510 4 Task 2: USART in interrupt mode USART in interrupt mode will free CPU cycles since the microcontroller doesn t have to poll the transmit register to see if it is empty or poll the receive register to see if it contains new data. This way, the microcontroller can do other and more useful things than waiting, and increase use of its performance. New to Atmel XMEGA are the three byte hardware buffers to keep data. The advantage of this buffer is to reduce occurrences of buffer overflow. Buffer overflow can occur, for instance, when interrupt service routines (ISRs) with higher priority are starving out 1 other ISRs with lower priority. A driver is used to set up a USART in interrupt mode. The driver also has a ring buffer implemented which will be explored briefly. As seen from Figure 4-1, the application will send data to the driver which transfers it via the cable to the receiving USART. At the receiver, the driver sends the data to the application. Figure 4-1: Data flow in task 2 The goal for this task is to: Know how to set up the Atmel XMEGA USART in interrupt mode Understand how to use a driver for the setup Take a quick look at the ring buffer in the driver Understand how the hardware buffer works 1. Locate and open the project InterruptControlled.aps 2. Connect a jumper between Tx and Rx on PORTD, that is PD2 and PD3 3. Look through the code (task2.c) and try to understand what happens 4. Compile the code and assure that there are no warnings or errors 5. Start the debugging session 1 The high priority interrupts are running so frequently that the lower priority interrupt routines never get time (CPU cycles) to run. 5

6. Step into USART_InterruptDriver_Initialize() (press F11) and access the driver file 7. Try to understand how the driver sets up the registers. Step out of the driver file, press Shift+F11 8. Locate the receivearray[] buffer and add a watch, see Figure 4-2 Figure 4-2. Add a watch to the buffer pointers 9. Now, run the code for a while by pressing F5 10. After a short while, break the execution (press Ctrl+F5) 11. Now, take a look at receivearray[]. Have the characters been transferred correctly? 12. Reset the debug session (Shift+F5) and place break-points to the ISR routines. Run the program and see if it acts as expected 13. Open the usart_driver.h and set both USART_RX_BUFFER_SIZE and USART_TX_BUFFER_SIZE to 2 14. In Task2.c, set NUM_BYTES to 7 and recompile the project 15. In the Atmel AVR Studio menu, press Debug->Remove all Breakpoints 16. Run the program for a while (press F5) and break the execution (Ctrl+F5) Why cannot the program run to completion? (Hint: What sizes are the software ring buffer and the hardware buffer and what is the size of the array to send.) 6 AVR1510

AVR1510 5 Task 3: USART using DMAC Atmel XMEGA introduces DMA controller for 8-bit microcontrollers. Using a DMA controller will offload the CPU when handling data transmission and help increase the performance of the microcontroller significantly. This task will show how to set up the USART with the DMAC driver. Figure 5-1 illustrates the data flow in this task using DMA. The goal for this task is that you know how to: Set up the USART using DMAC Set up the DMAC to read data from SRAM Set up the DMAC to write data to USART Set up the DMAC to read data from USART Set up the DMAC to write data to SRAM Figure 5-1. Data flow in the DMA example 1. Open the project file USART_DMA.aps in Atmel AVR Studio and open task3.c 2. Connect a jumper between Tx and Rx on PORTD, that is PD2 and PD3 3. Study how the Transmit channel is set up (SetupTransmitChannel) a. Tx_Buf is the input for the DMA transmit channel b. The DMA is set up to increase the address of Tx_Buf. Why? c. The USART data register is the output for the DMA transmit channel d. The DMA is set up to keep the address to the data register fixed during transmission. Why? e. Are you able to verify the correct trigger source (Data Register Empty) in the Atmel XMEGA manual? (0x6C) 4. Study how the Receive channel is set up (SetupReceiveChannel) a. The USART data register is the input for the DMA receive channel b. Rx_Buf is the output for the DMA receive channel c. The DMA is set up to have fixed receive data register address and to increase the address of Rx_Buf. Why? d. Are you able to verify that the correct trigger source (Receive complete) is used in the XMEGA manual? 7

5. Build the project and start a debug session (click the Play icon) 6. Put a breakpoint on the first line after the DMA has completed ( LEDPORT.OUT = ). Run the code (press F5) 7. What is shown on the LEDs? Was the CPU able to increment the variable i while waiting for the DMA to complete? 8. Put a breakpoint on the line LEDPORT.OUT = Rx_Buf[i]; 9. Run the code(press F5) 10. Check the status of the LEDs in comparison with the code; do the LEDs blink as expected? 11. Add watches to Rx_Buf and Tx_Buf and compare them, are they equal and contain characters from a to t, see Figure 5-2. Figure 5-2. Verify DMA transmission 8 AVR1510

AVR1510 6 Summary Here are some of the high-lights from this training: USART in Polling mode USART in interrupt mode USART driver USART software ring buffer USART hardware buffer USART DMA 7 Resources Atmel XMEGA Manual and Datasheets o http://www.atmel.com/xmega Atmel AVR Studio with help files o http://www.atmel.com/products/avr/ WINAVR GCC compiler o http://winavr.sourceforge.net/ Atmel IAR Embedded Workbench compiler o http://www.iar.com/ 8 Atmel Technical Support Center Atmel has several support channels available: Web portal: http://support.atmel.no/ All Atmel microcontrollers Email: avr@atmel.com All Atmel AVR products Email: avr32@atmel.com All AVR32 products Please register on the web portal to gain access to the following services: Access to a rich FAQ database Easy submission of technical support requests History of all your past support requests Register to receive Atmel microcontrollers newsletters Get information about available trainings and training material 9

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 Unit 1-5 & 16, 19/F BEA Tower, Millennium City 5 418 Kwun Tong Road Kwun Tong, Kowloon Hong Kong Tel: (852) 2245-6100 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 ASSUMES NO LIABILITY WHATSOEVER AND DISCLAIMS ANY EXPRESS, IMPLIED OR STATUTORY WARRANTY RELATING TO ITS PRODUCTS INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS 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 LOSS OF PROFITS, BUSINESS INTERRUPTION, OR LOSS OF INFORMATION) ARISING OUT OF THE USE OR INABILITY TO USE THIS DOCUMENT, EVEN IF ATMEL HAS BEEN ADVISED OF THE POSSIBILITY 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. 2010 Atmel Corporation. All rights reserved. Atmel, Atmel logo and combinations thereof, AVR, AVR logo, AVR Studio and others, are the registered trademarks, XMEGA and others are trademarks of Atmel Corporation or its subsidiaries. Other terms and product names may be trademarks of others.