AVR306: Using the AVR USART on tinyavr and megaavr devices. Introduction. Features. 8-bit AVR Microcontrollers APPLICATION NOTE

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

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

USER GUIDE EDBG. Description

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

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

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

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

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

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

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

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

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

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

AT88CK490 Evaluation Kit

CryptoAuth Xplained Pro

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

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

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

General Porting Considerations. Memory EEPROM XRAM

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

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

USER GUIDE. ZigBit USB Stick User Guide. Introduction

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

Atmel AVR4921: ASF - USB Device Stack Differences between ASF V1 and V2. 8-bit Atmel 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

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

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

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

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

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

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

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

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

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

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

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

ET-BASE AVR ATmega64/128

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

QT1 Xplained Pro. Preface. Atmel QTouch USER GUIDE

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

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

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

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

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

AT09333: USB Host Interface (UHI) for Communication Class Device (CDC) Introduction. Atmel Microcontrollers APPLICATION NOTE

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

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

AVR126: ADC of megaavr in Single Ended Mode. Introduction. Features. AVR 8-bit Microcontrollers APPLICATION NOTE

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

AT11805: Capacitive Touch Long Slider Design with PTC. Introduction. Features. Touch Solutions APPLICATION NOTE

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

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

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

USART and Asynchronous Communication

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. Atmel AVR443: Sensor-based Control of Three Phase Brushless DC Motor. Atmel AVR 8-bit Microcontrollers. Features.

APPLICATION NOTE. AT12405: Low Power Sensor Design with PTC. Atmel MCU Integrated Touch. Introduction

AT91SAM ARM-based Flash MCU. Application Note

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

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

AVR127: Understanding ADC Parameters. Introduction. Features. Atmel 8-bit and 32-bit Microcontrollers APPLICATION NOTE

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

APPLICATION NOTE. AT05558: Wireless Manufacturing Test Kit. Atmel ATmega256RFR2. Description. Features

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

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

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

Introducing a platform to facilitate reliable and highly productive embedded developments

AN3265 Application note

STK User Guide

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

AN3332 Application note

Atmel Power Line Communications. Solutions for the Smart Grid

Atmel SMART ARM Core-based Embedded Microprocessors

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

AN3998 Application note

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

SAMA5D2. Scope. Reference Documents. Atmel SMART ARM-based MPU ERRATA

AN3252 Application note

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

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

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

AN Boot mode jumper settings for LPC1800 and LPC4300. Document information

AT12181: ATWINC1500 Wi-Fi Network Controller - AP Provision Mode. Introduction. Features. Atmel SmartConnect APPLICATION NOTE

Atmel Norway XMEGA Introduction

APPLICATION NOTE. RF System Architecture Considerations ATAN0014. Description

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

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

APPLICATION NOTE. AVR042: AVR Hardware Design Considerations. AVR 8-bit Microcontrollers. Features. Description

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

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

RS-422/485 Multiport Serial PCI Card. RS-422/485 Multiport Serial PCI Card Installation Guide

Serial Communications

TCP/IP MODULE CA-ETHR-A INSTALLATION MANUAL

Designing Feature-Rich User Interfaces for Home and Industrial Controllers

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

AN2604 Application note

Develop a Dallas 1-Wire Master Using the Z8F1680 Series of MCUs

Capacitive Touch Technology Opens the Door to a New Generation of Automotive User Interfaces

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

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

Transcription:

8-bit AVR Microcontrollers AVR306: Using the AVR USART on tinyavr and megaavr devices APPLICATION NOTE Introduction This application note provides code examples to use the USART/UART on AVR devices in asynchronous mode. Most of the tinyavr and megaavr devices have USART peripheral which can perform both asynchronous and synchronous transfers. For AVR devices with UART peripheral which do not have capability to perform synchronous serial data transfer, separate examples are provided in the zip file available with this application note. Features Setup and use of the AVR USART/UART in asynchronous mode Code examples for polled and interrupt controlled USART/UART

Table of Contents Introduction...1 Features... 1 1. USART Transfer Methods...3 1.1. Polled Transfer... 3 1.2. Interrupt Controlled Transfer... 3 2. BAUD Rate Generator...4 3. Examples of Baud Rate Setting...5 4. About Code Examples...9 5. Testing the Examples...10 6. References...11 7. Revision History...12 2

1. USART Transfer Methods There are two methods in which the CPU transfers data through a USART/UART - Polled Transfer and Interrupt Controlled Transfer. Table 1-1. Properties of Polled/Interrupt Controlled USART Routines Polled USART Compact code Application busy while communicating Interrupt Controlled USART Reasonable code size Application free while communicating 1.1. Polled Transfer The application continuously checks the UDRE bit in the USART Status Register to identify when the USART has finished sending a byte. Then the next byte can be loaded to the data register. When receiving data, the application continuously checks the RXC bit in the USART Status Register to identify when the USART has completed receiving a byte. In this case, the CPU waits for the reception of a byte and then proceed with further processing. 1.2. Interrupt Controlled Transfer In interrupt controlled transfer, the USART generates an interrupt when the USART has finished transmitting or receiving a byte. Thus the CPU can perform other functions while the USART module transmit or receive a byte. Interrupts corresponding to receive and transmit functionality of the USART module should be enabled for interrupt controlled transfers. In addition to this the Global Interrupt Enable bit in SREG must be set for the interrupts to be enabled. 3

2. BAUD Rate Generator The USART Baud Rate Register (UBRRxx) and the down-counter connected to it function as a programmable prescaler or baud rate generator. The down-counter, running at system clock (f osc ), is loaded with the UBRRxx value each time the counter has counted down to zero or when the UBRRxx register is written. A clock is generated each time the counter reaches zero. 4

3. Examples of Baud Rate Setting The following table contains equations for calculating the baud rate (in bits per second) and for calculating the UBRR value for each mode of operation using an internally generated clock source. Table 3-1. Equations for Calculating Baud Rate Register Setting Operating Mode Asynchronous Normal mode (U2X = 0) Asynchronous Double Speed mode (U2X = 1) Equation for Calculating Baud Rate (1) BAUD = BAUD = OSC 16 + 1 OSC 8 + 1 Equation for Calculating UBRR Value = = OSC 16BAUD 1 OSC 8BAUD 1 Synchronous Master mode BAUD = OSC 2 +1 = OSC 2BAUD 1 Note: 1. The baud rate is defined to be the transfer rate in bit per second (bps). BAUD f OSC Baud rate (in bits per second, bps). System oscillator clock frequency. UBRR Contents of the UBRRH and UBRRL Registers, (0-4095). For standard crystal and resonator frequencies, the most commonly used baud rates for asynchronous operation can be generated by using the UBRR settings as listed in the following table. For details on clock options supported by a device, refer the device datasheet. UBRR values which yield an actual baud rate differing less than 0.5% from the target baud rate, are bold in the table. Higher error ratings are acceptable, but the Receiver will have less noise resistance when the error ratings are high, especially for large serial frames. The error values are calculated using the following equation: % = BaudRate Closest Match BaudRate 1 100 % Table 3-2. Examples of UBRR Settings for Commonly Used Oscillator Frequencies Baud Rate [bps] f osc = 1.0000MHz f osc = 1.8432MHz f osc = 2.0000MHz U2X = 0 U2X = 1 U2X= 0 U2X = 1 U2X = 0 U2X = 1 UBRR Error UBRR Error UBRR Error UBRR Error UBRR Error UBRR Error 2400 25 0.2% 51 0.2% 47 0.0% 95 0.0% 51 0.2% 103 0.2% 4800 12 0.2% 25 0.2% 23 0.0% 47 0.0% 25 0.2% 51 0.2% 9600 6-7.0% 12 0.2% 11 0.0% 23 0.0% 12 0.2% 25 0.2% 14.4k 3 8.5% 8-3.5% 7 0.0% 15 0.0% 8-3.5% 16 2.1% 19.2k 2 8.5% 6-7.0% 5 0.0% 11 0.0% 6-7.0% 12 0.2% 28.8k 1 8.5% 3 8.5% 3 0.0% 7 0.0% 3 8.5% 8-3.5% 5

Baud Rate [bps] f osc = 1.0000MHz f osc = 1.8432MHz f osc = 2.0000MHz U2X = 0 U2X = 1 U2X= 0 U2X = 1 U2X = 0 U2X = 1 UBRR Error UBRR Error UBRR Error UBRR Error UBRR Error UBRR Error 38.4k 1-18.6% 2 8.5% 2 0.0% 5 0.0% 2 8.5% 6-7.0% 57.6k 0 8.5% 1 8.5% 1 0.0% 3 0.0% 1 8.5% 3 8.5% 76.8k 1-18.6% 1-25.0% 2 0.0% 1-18.6% 2 8.5% 115.2k 0 8.5% 0 0.0% 1 0.0% 0 8.5% 1 8.5% 230.4k 0 0.0% 250k 0 0.0% Max (1) 62.5kbps 125kbps 115.2kbps 230.4kbps 125kbps 250kbps Note: 1. UBRR = 0, Error = 0.0% Table 3-3. Examples of UBRR Settings for Commonly Used Oscillator Frequencies (Continued) Baud Rate [bps] f osc = 3.6864MHz f osc = 4.0000MHz f osc = 7.3728MHz U2X = 0 U2X = 1 U2X = 0 U2X = 1 U2X = 0 U2X = 1 UBRR Error UBRR Error UBRR Error UBRR Error UBRR Error UBRR Error 2400 95 0.0% 191 0.0% 103 0.2% 207 0.2% 191 0.0% 383 0.0% 4800 47 0.0% 95 0.0% 51 0.2% 103 0.2% 95 0.0% 191 0.0% 9600 23 0.0% 47 0.0% 25 0.2% 51 0.2% 47 0.0% 95 0.0% 14.4k 15 0.0% 31 0.0% 16 2.1% 34-0.8% 31 0.0% 63 0.0% 19.2k 11 0.0% 23 0.0% 12 0.2% 25 0.2% 23 0.0% 47 0.0% 28.8k 7 0.0% 15 0.0% 8-3.5% 16 2.1% 15 0.0% 31 0.0% 38.4k 5 0.0% 11 0.0% 6-7.0% 12 0.2% 11 0.0% 23 0.0% 57.6k 3 0.0% 7 0.0% 3 8.5% 8-3.5% 7 0.0% 15 0.0% 76.8k 2 0.0% 5 0.0% 2 8.5% 6-7.0% 5 0.0% 11 0.0% 115.2k 1 0.0% 3 0.0% 1 8.5% 3 8.5% 3 0.0% 7 0.0% 230.4k 0 0.0% 1 0.0% 0 8.5% 1 8.5% 1 0.0% 3 0.0% 250k 0-7.8% 1-7.8% 0 0.0% 1 0.0% 1-7.8% 3-7.8% 0.5M 0-7.8% 0 0.0% 0-7.8% 1-7.8% 1M 0-7.8% Max. (1) 230.4kbps 460.8kbps 250kbps 0.5Mbps 460.8kbps 921.6kbps Note: 1. UBRR = 0, Error = 0.0% 6

Table 3-4. Examples of UBRR Settings for Commonly Used Oscillator Frequencies (Continued) Baud Rate [bps] f osc = 8.0000MHz f osc = 11.0592MHz f osc = 14.7456MHz U2X = 0 U2X = 1 U2X = 0 U2X = 1 U2X = 0 U2X = 1 UBRR Error UBRR Error UBRR Error UBRR Error UBRR Error UBRR Error 2400 207 0.2% 416-0.1% 287 0.0% 575 0.0% 383 0.0% 767 0.0% 4800 103 0.2% 207 0.2% 143 0.0% 287 0.0% 191 0.0% 383 0.0% 9600 51 0.2% 103 0.2% 71 0.0% 143 0.0% 95 0.0% 191 0.0% 14.4k 34-0.8% 68 0.6% 47 0.0% 95 0.0% 63 0.0% 127 0.0% 19.2k 25 0.2% 51 0.2% 35 0.0% 71 0.0% 47 0.0% 95 0.0% 28.8k 16 2.1% 34-0.8% 23 0.0% 47 0.0% 31 0.0% 63 0.0% 38.4k 12 0.2% 25 0.2% 17 0.0% 35 0.0% 23 0.0% 47 0.0% 57.6k 8-3.5% 16 2.1% 11 0.0% 23 0.0% 15 0.0% 31 0.0% 76.8k 6-7.0% 12 0.2% 8 0.0% 17 0.0% 11 0.0% 23 0.0% 115.2k 3 8.5% 8-3.5% 5 0.0% 11 0.0% 7 0.0% 15 0.0% 230.4k 1 8.5% 3 8.5% 2 0.0% 5 0.0% 3 0.0% 7 0.0% 250k 1 0.0% 3 0.0% 2-7.8% 5-7.8% 3-7.8% 6 5.3% 0.5M 0 0.0% 1 0.0% 2-7.8% 1-7.8% 3-7.8% 1M 0 0.0% 0-7.8% 1-7.8% Max. (1) 0.5Mbps 1Mbps 691.2kbps 1.3824Mbps 921.6kbps 1.8432Mbps Note: 1. UBRR = 0, Error = 0.0% Table 3-5. Examples of UBRR Settings for Commonly Used Oscillator Frequencies (Continued) Baud Rate [bps] f osc = 16.0000MHz f osc = 18.4320MHz f osc = 20.0000MHz U2X = 0 U2X = 1 U2X = 0 U2X = 1 U2X = 0 U2X = 1 UBRR Error UBRR Error UBRR Error UBRR Error UBRR Error UBRR Error 2400 416-0.1% 832 0.0% 479 0.0% 959 0.0% 520 0.0% 1041 0.0% 4800 207 0.2% 416-0.1% 239 0.0% 479 0.0% 259 0.2% 520 0.0% 9600 103 0.2% 207 0.2% 119 0.0% 239 0.0% 129 0.2% 259 0.2% 14.4k 68 0.6% 138-0.1% 79 0.0% 159 0.0% 86-0.2% 173-0.2% 19.2k 51 0.2% 103 0.2% 59 0.0% 119 0.0% 64 0.2% 129 0.2% 28.8k 34-0.8% 68 0.6% 39 0.0% 79 0.0% 42 0.9% 86-0.2% 38.4k 25 0.2% 51 0.2% 29 0.0% 59 0.0% 32-1.4% 64 0.2% 57.6k 16 2.1% 34-0.8% 19 0.0% 39 0.0% 21-1.4% 42 0.9% 76.8k 12 0.2% 25 0.2% 14 0.0% 29 0.0% 15 1.7% 32-1.4% 7

Baud Rate [bps] f osc = 16.0000MHz f osc = 18.4320MHz f osc = 20.0000MHz U2X = 0 U2X = 1 U2X = 0 U2X = 1 U2X = 0 U2X = 1 UBRR Error UBRR Error UBRR Error UBRR Error UBRR Error UBRR Error 115.2k 8-3.5% 16 2.1% 9 0.0% 19 0.0% 10-1.4% 21-1.4% 230.4k 3 8.5% 8-3.5% 4 0.0% 9 0.0% 4 8.5% 10-1.4% 250k 3 0.0% 7 0.0% 4-7.8% 8 2.4% 4 0.0% 9 0.0% 0.5M 1 0.0% 3 0.0% 4-7.8% 4 0.0% 1M 0 0.0% 1 0.0% Max. (1) 1Mbps 2Mbps 1.152Mbps 2.304Mbps 1.25Mbps 2.5Mbps Note: 1. UBRR = 0, Error = 0.0% 8

4. About Code Examples There are three projects available in the zip file which comes with this application note, one for UART and two for USART. Each of these projects contains two source files (polling method and interrupt method). The projects contain the code example for polling method. To test interrupt method, the corresponding file can be added to the project after removing the existing source file. UART based examples are tested for ATmega8515 device and USART based ones are tested on ATmega324PB and ATtiny104. All Six files can be rebuild using avr-gcc or IAR Toolchain and can be used on any AVR ATtiny and AVR ATmega devices with minor changes if any such as register name or register bit name. Baudrate calculations in these examples are based on 8MHz and 1MHz (ATtiny104) CPU clock frequency. The main application stays in an infinite loop and sends back the data byte received. The interrupt handling routines uses modulo 2n addressing of circular buffers for buffering incoming and outgoing data. The buffer sizes must be defined before using the routines. Set the UART_RX_BUFFER_SIZE and UART_TX_BUFFER_SIZE variables to the buffer size in bytes. These variables must be a power of 2 for the given example, if not, a compiler error message will be flagged. Note: The interrupt handling for ATtiny104 does not use circular buffering incoming and outgoing data to reduce RAM usage. 9

5. Testing the Examples UART examples based on ATmega8515 can be tested on STK600. Use the appropriate socket card and routing card to place the device on the STK600. The UART pins of this device are as follows: Table 5-1. UART Pins Used in the Example Signal RXD TXD Pin Name on ATmega8515 PD0 PD1 1. Open the Atmel Studio project in Atmel Studio 7. 2. Rebuild the project and load the hex file into the device using an ISP programmer. 3. Use wired jumpers to connect PD0 to RXD pin of the RS232 SPARE connector on the STK600 and PD1 to TXD pin of the connector. 4. Connect an RS232 cable from STK600 to the PC and open a terminal application (9600 Baud, 8 data bits, 1 stop bit) to transfer characters. 5. Type characters on the terminal window. These will be echoed by the application running on the ATmega8515 device. USART examples based on ATmega324PB can be tested on the ATmega324PB Xplained Pro. This board has an embedded debugger (EDBG) which provides a virtual COM port. Pins of USART1 are connected to this virtual COM port. To test the code, 1. Connect the ATmega324PB Xplained Pro to the PC. 2. Build the project and load the hex file into the device using EDBG as programmer. 3. Open a terminal application for the EDBG Virtual COM port (9600 Baud, 8 data bits, 1 stop bit). 4. Type characters on the terminal window. These will be echoed by the application running on the ATmega324PB device. USART examples based on ATtiny104 can be tested on the ATTiny104 Xplained NANO. This board has an embedded debugger (medbg) which provides a virtual COM port. Pins of USART are connected to this virtual COM port. To test the code, 1. Connect the ATTiny104 Xplained NANO to the PC. 2. Build the project and load the hex file into the device using medbg as programmer. 3. Open a terminal application for the medbg Virtual COM port(2400 Baud, 8 data bits, 1 stop bit). 4. Type characters on the terminal window. These will be echoed by the application running on the ATtiny104 device. Note: 1. Link which shows details on programming an Atmel microcontroller can be found in References. 2. Turn OFF local echo in the terminal application while testing these examples, the application will echo the received character. 10

6. References 1. AVR317: Using the USART on the ATmega48/88/168 as a SPI master 2. AVR054: Run-time calibration of the internal RC oscillator via the UART 3. STK600 Routing Cards and Socket Cards 4. ATmega324PB Xplained Pro User Guide 5. Atmel Studio - Programming Dialogue 6. ATTINY104-XNANO User Guide 11

7. Revision History Doc Rev. Date Comments 1451C 04/2016 Updated content to SDL format Added new sections on BAUD rate settings and testing the examples Included examples based on ATmega324PB Xplained Pro and ATtiny104 Xplained NANO 1451B 1451A 06/2002 Updated with new device 08/1999 Initial document release 12

Atmel Corporation 1600 Technology Drive, San Jose, CA 95110 USA T: (+1)(408) 441.0311 F: (+1)(408) 436.4200 www.atmel.com 2016 Atmel Corporation. / Rev.: Atmel, Atmel logo and combinations thereof, Enabling Unlimited Possibilities, AVR, TinyAVR, MegaAVR and others are registered trademarks or trademarks of Atmel Corporation in U.S. and other countries. Other terms and product names may be trademarks of others. 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 THE ATMEL TERMS AND CONDITIONS OF SALES LOCATED ON THE ATMEL WEBSITE, 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 AND 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 products 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 products are not intended, authorized, or warranted for use as components in applications intended to support or sustain life. SAFETY-CRITICAL, MILITARY, AND AUTOMOTIVE APPLICATIONS DISCLAIMER: Atmel products are not designed for and will not be used in connection with any applications where the failure of such products would reasonably be expected to result in significant personal injury or death ( Safety-Critical Applications ) without an Atmel officer's specific written consent. Safety-Critical Applications include, without limitation, life support devices and systems, equipment or systems for the operation of nuclear facilities and weapons systems. Atmel products are not designed nor intended for use in military or aerospace applications or environments unless specifically designated by Atmel as military-grade. Atmel products are not designed nor intended for use in automotive applications unless specifically designated by Atmel as automotive-grade.