Atmel 8465 8 and 16 Bit AVR Microcontrollers XMEGA C - Manual PDF
Atmel 8465 8 and 16 Bit AVR Microcontrollers XMEGA C - Manual PDF
XMEGA C MANUAL
This document contains complete and detailed description of all modules included in the
Atmel® AVR® XMEGA® C microcontroller family. The Atmel AVR XMEGA C is a family of low-
power, high-performance, and peripheral-rich CMOS 8/16-bit microcontrollers based on the
AVR enhanced RISC architecture. The available Atmel AVR XMEGA C modules described in
this manual are:
Atmel AVR CPU
Memories
DMAC - Direct memory access controller
Event system
System clock and clock options
Power management and sleep modes
System control and reset
WDT - Watchdog timer
Interrupts and programmable multilevel interrupt controller
PORT - I/O ports
TC - 16-bit timer/counters
AWeX - Advanced waveform extension
Hi-Res - High resolution extension
RTC - Real-time counter
USB - Universal serial bus interface
TWI - Two-wire serial interface
SPI - Serial peripheral interface
USART - Universal synchronous and asynchronous serial receiver and transmitter
IRCOM - Infrared communication module
AES cryptographic engine
CRC - Cyclic redundancy check
ADC - Analog-to-digital converter
AC - Analog comparator
PDI - Program and debug interface
Memory programming
Peripheral address map
Register summary
Interrupt vector summary
Instruction set summary
Atmel-8465H-AVR-XMEGA C-12/2014
1. About the Manual
This document contains in-depth documentation of all peripherals and modules available for the Atmel AVR XMEGA C
microcontroller family. All features are documented on a functional level and described in a general sense. All peripherals
and modules described in this manual may not be present in all Atmel AVR XMEGA C devices.
For all device-specific information such as characterization data, memory sizes, modules, peripherals available and their
absolute memory addresses, refer to the device datasheets. When several instances of a peripheral exists in one device,
each instance will have a unique name. For example each port module (PORT) have unique name, such as PORTA,
PORTB, etc. Register and bit names are unique within one module instance.
For more details on applied use and code examples for peripherals and modules, refer to the Atmel AVR XMEGA
specific application notes available from http://www.atmel.com/avr.
1.2 Resources
A comprehensive set of development tools, application notes, and datasheets are available for download from
http://www.atmel.com/avr.
This manual contains general modules and peripheral descriptions. The AVR XMEGA C device datasheets contains the
device-specific information. The XMEGA application notes and AVR Software Framework contain example code and
show applied use of the modules and peripherals.
For new users, it is recommended to read the AVR1000: Getting Started Writing C-code for Atmel XMEGA.
XMEGA C [MANUAL] 2
Atmel-8465H-AVR-XMEGA C-12/2014
Atmel-8465H-AVR-XMEGA C-Datasheet_12/2014
2. Overview
The AVR XMEGA C microcontrollers is a family of low-power, high-performance, and peripheral-rich CMOS 8/16-bit
microcontrollers based on the AVR enhanced RISC architecture. By executing powerful instructions in a single clock
cycle, the Atmel AVR XMEGA C devices achieve throughputs approaching one million instructions per second (MIPS)
per megahertz, allowing the system designer to optimize power consumption versus processing speed.
The AVR CPU combines a rich instruction set with 32 general purpose working registers. All 32 registers are directly
connected to the arithmetic logic unit (ALU), allowing two independent registers to be accessed in a single instruction,
executed in one clock cycle. The resulting architecture is more code efficient while achieving throughputs many times
faster than conventional single-accumulator or CISC based microcontrollers.
The Atmel AVR XMEGA C devices provide the following features: in-system programmable flash with read-while-write
capabilities; internal EEPROM and SRAM; two-channel DMA controller on the selected devices; four-channel event
system and programmable multilevel interrupt controller; up to 50 general purpose I/O lines; 16-bit real-time counter
(RTC); up to five flexible, 16-bit timer/counters with capture, compare and PWM modes; up to three USARTs; two I2C
and SMBUS compatible two-wire serial interfaces (TWIs); one full-speed USB 2.0 interface; up to two serial peripheral
interfaces (SPIs); CRC module; AES cryptographic engine on selected devices; one 16-channel, 12-bit ADC with
programmable gain; two analog comparators (ACs) with window mode; programmable watchdog timer with separate
internal oscillator; accurate internal oscillators with PLL and prescaler; and programmable brown-out detection.
The program and debug interface (PDI), a fast, two-pin interface for programming and debugging, is available.
The Atmel AVR XMEGA devices have five software selectable power saving modes. The idle mode stops the CPU while
allowing the SRAM, DMA controller, event system, interrupt controller, and all peripherals to continue functioning. The
power-down mode saves the SRAM and register contents, but stops the oscillators, disabling all other functions until the
next TWI, USB resume, or pin-change interrupt, or reset. In power-save mode, the asynchronous real-time counter
continues to run, allowing the application to maintain a timer base while the rest of the device is sleeping. In standby
mode, the external crystal oscillator keeps running while the rest of the device is sleeping. This allows very fast startup
from the external crystal, combined with low power consumption. In extended standby mode, both the main oscillator and
the asynchronous timer continue to run. To further reduce power consumption, the peripheral clock to each individual
peripheral can optionally be stopped in active mode and idle sleep mode.
The devices are manufactured using Atmel high-density, nonvolatile memory technology. The program flash memory can
be reprogrammed in-system through the PDI interface. A boot loader running in the device can use any interface to
download the application program to the flash memory. The boot loader software in the boot flash section will continue to
run while the application flash section is updated, providing true read-while-write operation. By combining an 8/16-bit
RISC CPU with In-system, self-programmable flash, the Atmel AVR XMEGA is a powerful microcontroller family that
provides a highly flexible and cost effective solution for many embedded applications.
The Atmel AVR XMEGA C devices are supported with a full suite of program and system development tools, including C
compilers, macro assemblers, program debugger/simulators, programmers, and evaluation kits.
XMEGA C [MANUAL] 3
Atmel-8465H-AVR-XMEGA C-12/2014
Atmel-8465H-AVR-XMEGA C-Datasheet_12/2014
Figure 2-1. Atmel AVR XMEGA C Block Diagram
PR[0..1]
Power Programming, debug, test
XTAL1
Ground External clock /Crystal pins TOSC1
Digital function General Purpose I /O
XTAL2
Analog function /Oscillators TOSC2
Oscillator
Real Time Circuits/
PORT R (2) Counter Clock
Generation
Watchdog
EVENT ROUTING NETWORK Oscillator
DATA BUS
Watchdog
Timer
ACA
Event System Oscillator
Controller Control
Power VCC
PA[0..7] PORT A (8) SRAM
Supervision
DMA Sleep POR/BOD & GND
Controller Controller RESET
ADCA
RESET/
BUS Prog/Debug PDI_CLK
PDI
AREFA Matrix Controller
PDI_DATA
VCC/10
Int. Refs.
AES OCD
Tempref
AREFB
CPU Interrupt
CRC
Controller
ADCB
NVM Controller
PB[0..7] PORT B (8)
Flash EEPROM
ACB
DATA BUS
USARTD0
USARTE0
USARTF0
TCC0:1
IRCOM
TCD0
TWIC
TCE0
TWIE
TCF0
SPIC
SPID
USB
In Table 2-1 on page 5 a feature summary for the XMEGA C family is shown, split into one feature summary column for
each sub-family. Each sub-family has identical feature set, but different memory options, refer to their device datasheet
for ordering codes and memory options.
XMEGA C [MANUAL] 4
Atmel-8465H-AVR-XMEGA C-12/2014
Atmel-8465H-AVR-XMEGA C-Datasheet_12/2014
Table 2-1. XMEGA C Feature Summary Overview
Total 64 44
Pins, I/O
Programmable I/O pins 50 34
BGA – 49C2
Channels 4 4
Event System
QDEC 1 1
TC0 - 16-bit, 4 CC 4 3
TC1 - 16-bit, 2 CC 1 1
TC2 - 2x 8-bit 4 2
Timer / Counter
Hi-Res 1 1
AWeX 1 1
RTC 1 1
USART 3 3
Serial Communication
SPI 2 2
TWI 2 2
XMEGA C [MANUAL] 5
Atmel-8465H-AVR-XMEGA C-12/2014
Atmel-8465H-AVR-XMEGA C-Datasheet_12/2014
Feature Details / sub-family C3 C4
(1)
AES-128 Yes –
1 1
Resolution (bits) 12 12
Conversion channels 1 1
Boundary scan – –
Note: 1. Selected devices only.
XMEGA C [MANUAL] 6
Atmel-8465H-AVR-XMEGA C-12/2014
Atmel-8465H-AVR-XMEGA C-Datasheet_12/2014
3. Atmel AVR CPU
3.1 Features
8/16-bit, high-performance Atmel AVR RISC CPU
142 instructions
Hardware multiplier
32x8-bit registers directly connected to the ALU
Stack in RAM
Stack pointer accessible in I/O memory space
Direct addressing of up to 16MB of program memory and 16MB of data memory
True 16/24-bit access to 16/24-bit I/O registers
Efficient support for 8-, 16-, and 32-bit arithmetic
Configuration change protection of system-critical features
3.2 Overview
All Atmel AVR XMEGA devices use the 8/16-bit AVR CPU. The main function of the CPU is to execute the code and
perform all calculations. The CPU is able to access memories, perform calculations, control peripherals, and execute the
program in the flash memory. Interrupt handling is described in a separate section, “Interrupts and Programmable
Multilevel Interrupt Controller” on page 112.
XMEGA C [MANUAL] 7
Atmel-8465H-AVR-XMEGA C-12/2014
The arithmetic logic unit (ALU) supports arithmetic and logic operations between registers or between a constant and a
register. Single-register operations can also be executed in the ALU. After an arithmetic operation, the status register is
updated to reflect information about the result of the operation.
The ALU is directly connected to the fast-access register file. The 32 x 8-bit general purpose working registers all have
single clock cycle access time allowing single-cycle arithmetic logic unit operation between registers or between a
register and an immediate. Six of the 32 registers can be used as three 16-bit address pointers for program and data
space addressing, enabling efficient address calculations.
The memory spaces are linear. The data memory space and the program memory space are two different memory
spaces.
The data memory space is divided into I/O registers, SRAM, and external RAM. In addition, the EEPROM can be
memory mapped in the data memory.
All I/O status and control registers reside in the lowest 4KB addresses of the data memory. This is referred to as the I/O
memory space. The lowest 64 addresses can be accessed directly, or as the data space locations from 0x00 to 0x3F.
The rest is the extended I/O memory space, ranging from 0x0040 to 0x0FFF. I/O registers here must be accessed as
data space locations using load (LD/LDS/LDD) and store (ST/STS/STD) instructions.
The SRAM holds data. Code execution from SRAM is not supported. It can easily be accessed through the five different
addressing modes supported in the AVR architecture. The first SRAM address is 0x2000.
Data addresses 0x1000 to 0x1FFF are reserved for memory mapping of EEPROM.
The program memory is divided in two sections, the application program section and the boot program section. Both
sections have dedicated lock bits for write and read/write protection. The SPM instruction that is used for self-
programming of the application flash memory must reside in the boot program section. The application section contains
an application table section with separate lock bits for write and read/write protection. The application table section can
be used for save storing of nonvolatile data in the program memory.
XMEGA C [MANUAL] 8
Atmel-8465H-AVR-XMEGA C-12/2014
3.5 Program Flow
After reset, the CPU starts to execute instructions from the lowest address in the flash program memory ‘0.’ The program
counter (PC) addresses the next instruction to be fetched.
Program flow is provided by conditional and unconditional jump and call instructions capable of addressing the whole
address space directly. Most AVR instructions use a 16-bit word format, while a limited number use a 32-bit format.
During interrupts and subroutine calls, the return address PC is stored on the stack. The stack is allocated in the general
data SRAM, and consequently the stack size is only limited by the total SRAM size and the usage of the SRAM. After
reset, the stack pointer (SP) points to the highest address in the internal SRAM. The SP is read/write accessible in the
I/O memory space, enabling easy implementation of multiple stacks or stack areas. The data SRAM can easily be
accessed through the five different addressing modes supported in the AVR CPU.
clkCPU
Figure 3-3 shows the internal timing concept for the register file. In a single clock cycle, an ALU operation using two
register operands is executed and the result is stored back to the destination register.
clkCPU
Total Execution Time
XMEGA C [MANUAL] 9
Atmel-8465H-AVR-XMEGA C-12/2014
3.7 Status Register
The status register (SREG) contains information about the result of the most recently executed arithmetic or logic
instruction. This information can be used for altering program flow in order to perform conditional operations. Note that
the status register is updated after all ALU operations, as specified in the instruction set reference. This will in many
cases remove the need for using the dedicated compare instructions, resulting in faster and more compact code.
The status register is not automatically stored when entering an interrupt routine nor restored when returning from an
interrupt. This must be handled by software.
The status register is accessible in the I/O memory space.
Six of the 32 registers can be used as three 16-bit address register pointers for data space addressing, enabling efficient
address calculations. One of these address pointers can also be used as an address pointer for lookup tables in flash
program memory.
XMEGA C [MANUAL] 10
Atmel-8465H-AVR-XMEGA C-12/2014
Figure 3-4. AVR CPU General Purpose Working Registers
7 0 Addr.
R0 0x00
R1 0x01
R2 0x02
R13 0x0D
The register file is located in a separate address space, and so the registers are not accessible as data memory.
The lowest register address holds the least-significant byte (LSB), and the highest register address holds the most-
significant byte (MSB). In the different addressing modes, these address registers function as fixed displacement,
automatic increment, and automatic decrement (see the instruction set reference for details).
XMEGA C [MANUAL] 11
Atmel-8465H-AVR-XMEGA C-12/2014
3.10 RAMP and Extended Indirect Registers
In order to access program memory or data memory above 64KB, the address pointer must be larger than 16 bits. This is
done by concatenating one register to one of the X-, Y-, or Z-registers. This register then holds the most-significant byte
(MSB) in a 24-bit address or address pointer.
These registers are available only on devices with external bus interface and/or more than 64KB of program or data
memory space. For these devices, only the number of bits required to address the whole program and data memory
space in the device is implemented in the registers.
Bit (Individually) 7 0 7 0 7 0
RAMPX XH XL
Bit (X-pointer) 23 16 15 8 7 0
Bit (Individually) 7 0 7 0 7 0
RAMPY YH YL
Bit (Y-pointer) 23 16 15 8 7 0
Bit (Individually) 7 0 7 0 7 0
RAMPZ ZH ZL
Bit (Z-pointer) 23 16 15 8 7 0
When reading (ELPM) and writing (SPM) program memory locations above the first 128KB of the program memory,
RAMPZ is concatenated with the Z-register to form the 24-bit address. LPM is not affected by the RAMPZ setting.
Bit (Individually) 7 0 15 0
RAMPD K
Bit (D-pointer) 23 16 15 0
Bit (Individually) 7 0 7 0 7 0
EIND ZH ZL
Bit (D-pointer) 23 16 15 8 7 0
XMEGA C [MANUAL] 12
Atmel-8465H-AVR-XMEGA C-12/2014
3.11 Accessing 16-bit Registers
The AVR data bus is 8 bits wide, and so accessing 16-bit registers requires atomic operations. These registers must be
byte-accessed using two read or write operations. 16-bit registers are connected to the 8-bit bus and a temporary register
using a 16-bit bus.
For a write operation, the low byte of the 16-bit register must be written before the high byte. The low byte is then written
into the temporary register. When the high byte of the 16-bit register is written, the temporary register is copied into the
low byte of the 16-bit register in the same clock cycle.
For a read operation, the low byte of the 16-bit register must be read before the high byte. When the low byte register is
read by the CPU, the high byte of the 16-bit register is copied into the temporary register in the same clock cycle as the
low byte is read. When the high byte is read, it is then read from the temporary register.
This ensures that the low and high bytes of 16-bit registers are always accessed simultaneously when reading or writing
the register.
Interrupts can corrupt the timed sequence if an interrupt is triggered and accesses the same 16-bit register during an
atomic 16-bit read/write operation. To prevent this, interrupts can be disabled when writing or reading 16-bit registers.
The temporary registers can also be read and written directly from user software.
XMEGA C [MANUAL] 13
Atmel-8465H-AVR-XMEGA C-12/2014
3.13 Fuse Lock
For some system-critical features, it is possible to program a fuse to disable all changes to the associated I/O control
registers. If this is done, it will not be possible to change the registers from the user software, and the fuse can only be
reprogrammed using an external programmer. Details on this are described in the datasheet module where this feature is
available.
XMEGA C [MANUAL] 14
Atmel-8465H-AVR-XMEGA C-12/2014
3.14 Register Descriptions
Bit 7 6 5 4 3 2 1 0
+0x04 CCP[7:0]
Read/Write W W W W W W R/W R/W
Initial Value 0 0 0 0 0 0 0 0
XMEGA C [MANUAL] 15
Atmel-8465H-AVR-XMEGA C-12/2014
Bit 7:0 – RAMPX[7:0]: Extended X-pointer Address bits
These bits hold the MSB of the 24-bit address created by RAMPX and the 16-bit X-register. Only the number of bits
required to address the available data memory is implemented for each device. Unused bits will always read as zero.
XMEGA C [MANUAL] 16
Atmel-8465H-AVR-XMEGA C-12/2014
3.14.7 SPL – Stack Pointer Register Low
The SPH and SPL register pair represent the 16-bit SP value. The SP holds the stack pointer that points to the top of the
stack. After reset, the stack pointer points to the highest internal SRAM address. To prevent corruption when updating
the stack pointer from software, a write to SPL will automatically disable interrupts for the next four instructions or until
the next I/O memory write.
Only the number of bits required to address the available data memory, including external memory, up to 64KB is
implemented for each device. Unused bits will always read as zero.
Bit 7 6 5 4 3 2 1 0
+0x0D SP[7:0]
Read/Write R/W R/W R/W R/W R/W R/W R/W R/W
(1)
Initial Value 0/1 0/1 0/1 0/1 0/1 0/1 0/1 0/1
Note: 1. Refer to specific device datasheets for exact initial values.
Bit 7 6 5 4 3 2 1 0
+0x0E SP[15:8]
Read/Write R/W R/W R/W R/W R/W R/W R/W R/W
(1)
Initial Value 0/1 0/1 0/1 0/1 0/1 0/1 0/1 0/1
Note: 1. Refer to specific device datasheets for exact initial values.
XMEGA C [MANUAL] 17
Atmel-8465H-AVR-XMEGA C-12/2014
Bit 4 – S: Sign Bit, S = N V
The sign bit is always an exclusive or between the negative flag, N, and the two’s complement overflow flag, V. See
“Instruction Set Manual” for detailed information.
Bit 3 – V: Two’s Complement Overflow Flag
The two’s complement overflow flag (V) supports two’s complement arithmetic. See “Instruction Set Manual” for detailed
information.
Bit 2 – N: Negative Flag
The negative flag (N) indicates a negative result in an arithmetic or logic operation. See “Instruction Set Manual” for
detailed information.
Bit 1 – Z: Zero Flag
The zero flag (Z) indicates a zero result in an arithmetic or logic operation. See “Instruction Set Manual” for detailed
information.
Bit 0 – C: Carry Flag
The carry flag (C) indicates a carry in an arithmetic or logic operation. See “Instruction Set Manual” for detailed
information.
XMEGA C [MANUAL] 18
Atmel-8465H-AVR-XMEGA C-12/2014
3.15 Register Summary
Address Name Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0 Page
+0x00 Reserved – – – – – – – –
+0x01 Reserved – – – – – – – –
+0x02 Reserved – – – – – – – –
+0x03 Reserved – – – – – – – –
+0x04 CCP CCP[7:0] 15
+0x05 Reserved – – – – – – – –
+0x06 Reserved – – – – – – – –
+0x07 Reserved – – – – – – – –
+0x08 RAMPD RAMPD[7:0] 15
+0x09 RAMPX RAMPX[7:0] 15
+0x0A RAMPY RAMPY[7:0] 16
+0x0B RAMPZ RAMPZ[7:0] 16
+0x0C EIND EIND[7:0] 16
+0x0D SPL SPL[7:0] 17
+0x0E SPH SPH[7:0] 17
+0x0F SREG I T H S V N Z C 17
XMEGA C [MANUAL] 19
Atmel-8465H-AVR-XMEGA C-12/2014
4. Memories
4.1 Features
Flash program memory
One linear address space
In-system programmable
Self-programming and boot loader support
Application section for application code
Application table section for application code or data storage
Boot section for application code or bootloader code
Separate read/write protection lock bits for all sections
Built in fast CRC check of a selectable flash program memory section
Data memory
One linear address space
Single-cycle access from CPU
SRAM
EEPROM
Byte and page accessible
Optional memory mapping for direct load and store
I/O memory
Configuration and status registers for all peripherals and modules
Four bit-accessible general purpose registers for global variables or flags
Bus arbitration
Safe and deterministic handling of priority between CPU, DMA controller, and other bus masters
Separate buses for SRAM, EEPROM, I/O memory, and external memory access
Simultaneous bus access for CPU and DMA controller
Production signature row memory for factory programmed data
ID for each microcontroller device type
Serial number for each device
Calibration bytes for factory calibrated peripherals
User signature row
One flash page in size
Can be read and written from software
Content is kept after chip erase
4.2 Overview
This section describes the different memory sections. The AVR architecture has two main memory spaces, the program
memory and the data memory. Executable code can reside only in the program memory, while data can be stored in the
program memory and the data memory. The data memory includes the internal SRAM, and EEPROM for nonvolatile
data storage. All memory spaces are linear and require no memory bank switching. Nonvolatile memory (NVM) spaces
can be locked for further write and read/write operations. This prevents unrestricted access to the application software.
A separate memory section contains the fuse bytes. These are used for configuring important system functions, and can
only be written by an external programmer.
XMEGA C [MANUAL] 20
Atmel-8465H-AVR-XMEGA C-12/2014
of the different sections are fixed, but device-dependent. These two sections have separate lock bits, and can have
different levels of protection. The store program memory (SPM) instruction, which is used to write to the flash from the
application software, will only operate when executed from the boot loader section.
The application section contains an application table section with separate lock settings. This enables safe storage of
nonvolatile data in the program memory.
Application Flash
Section
Application Table
Flash Section
End Application
Start Boot Loader
Boot Loader Flash
Section
Flashend
XMEGA C [MANUAL] 21
Atmel-8465H-AVR-XMEGA C-12/2014
4.3.4 Production Signature Row
The production signature row is a separate memory section for factory programmed data. It contains calibration data for
functions such as oscillators and analog modules. Some of the calibration values will be automatically loaded to the
corresponding module or peripheral unit during reset. Other values must be loaded from the signature row and written to
the corresponding peripheral registers from software. For details on calibration conditions such as temperature, voltage
references, etc., refer to the device datasheet.
The production signature row also contains an ID that identifies each microcontroller device type and a serial number for
each manufactured device. The serial number consists of the production lot number, wafer number, and wafer
coordinates for the device.
The production signature row cannot be written or erased, but it can be read from application software and external
programmers.
For accessing the production signature row, refer to “NVM Flash Commands” on page 328.
XMEGA C [MANUAL] 22
Atmel-8465H-AVR-XMEGA C-12/2014
4.5 Data Memory
The data memory contains the I/O memory, internal SRAM, optionally memory mapped and EEPROM. The data memory
is organized as one continuous memory section, as shown in Figure 4-2.
Start/End
Data Memory
Address
0x0000
I/O Memory
(Up to 4 KB)
0x1000
EEPROM
(Up to 4 KB)
0x2000
Internal SRAM
I/O memory, EEPROM, and SRAM will always have the same start addresses for all XMEGA devices.
4.7 EEPROM
All XMEGA devices have EEPROM for nonvolatile data storage. It is addressable in a separate data space (default) or
memory mapped and accessed in normal data space. The EEPROM supports both byte and page access. Memory
mapped EEPROM allows highly efficient EEPROM reading and EEPROM buffer loading. When doing this, EEPROM is
accessible using load and store instructions. Memory mapped EEPROM will always start at hexadecimal address
0x1000.
XMEGA C [MANUAL] 23
Atmel-8465H-AVR-XMEGA C-12/2014
4.9 Data Memory and Bus Arbitration
Since the data memory is organized as four separate sets of memories, the different bus masters (CPU, DMA controller
read and DMA controller write, etc.) can access different memory sections at the same time. See Figure 4-3. The USB
module acts as a bus master, and is connected directly to internal SRAM through a pseudo-dual-port (PDP) interface.
Bus matrix
Interrupt
Flash CRC Controller
USB
NVM Power
EEPROM Controller Management
USART
Event System
AC Controller SPI SRAM
Non-Volatile
Oscillator
Memory ADC Control
TWI RAM
Timer /
I/O Counter
XMEGA C [MANUAL] 24
Atmel-8465H-AVR-XMEGA C-12/2014
4.12 I/O Memory Protection
Some features in the device are regarded as critical for safety in some applications. Due to this, it is possible to lock the
I/O register related to the clock system, the event system, and the advanced waveform extensions. As long as the lock is
enabled, all related I/O registers are locked and they can not be written from the application software. The lock registers
themselves are protected by the configuration change protection mechanism. For details, refer to “Configuration Change
Protection” on page 13.
XMEGA C [MANUAL] 25
Atmel-8465H-AVR-XMEGA C-12/2014
4.13 Register Description – NVM Controller
Bit 7 6 5 4 3 2 1 0
+0x01 ADDR[15:8]
Read/Write R/W R/W R/W R/W R/W R/W R/W R/W
Initial Value 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
+0x02 ADDR[23:16]
Read/Write R/W R/W R/W R/W R/W R/W R/W R/W
Initial Value 0 0 0 0 0 0 0 0
XMEGA C [MANUAL] 26
Atmel-8465H-AVR-XMEGA C-12/2014
4.13.5 DATA1 – Data Register 1
Bit 7 6 5 4 3 2 1 0
+0x05 DATA[15:8]
Read/Write R/W R/W R/W R/W R/W R/W R/W R/W
Initial Value 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
+0x06 DATA[23:16]
Read/Write R/W R/W R/W R/W R/W R/W R/W R/W
Initial Value 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
+0x0A – CMD[6:0]
Read/Write R R/W R/W R/W R/W R/W R/W R/W
Initial Value 0 0 0 0 0 0 0 0
Bit 7 – Reserved
This bit is unused and reserved for future use. For compatibility with future devices, always write this bit to zero when this
register is written.
Bit 6:0 – CMD[6:0]: Command
These bits define the programming commands for the flash. Bit 6 is only set for external programming commands. See
“Memory Programming” on page 323” for programming commands.
Bit 7 6 5 4 3 2 1 0
+0x0B – – – – – – – CMDEX
Read/Write R R R R R R R S
Initial Value 0 0 0 0 0 0 0 0
XMEGA C [MANUAL] 27
Atmel-8465H-AVR-XMEGA C-12/2014
4.13.9 CTRLB – Control Register B
Bit 7 6 5 4 3 2 1 0
+0x0C – – – – EEMAPEN FPRM EPRM SPMLOCK
Read/Write R R R R R/W R/W R/W R/W
Initial Value 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
+0x0D – – – – SPMLVL[1:0] EELVL[1:0]
Read/Write R R R R R/W R/W R/W R/W
Initial Value 0 0 0 0 0 0 0 0
XMEGA C [MANUAL] 28
Atmel-8465H-AVR-XMEGA C-12/2014
4.13.11 STATUS – Status Register
Bit 7 6 5 4 3 2 1 0
+0x04 NVMBUSY FBUSY – – – – EELOAD FLOAD
Read/Write R R R R R R R R
Initial Value 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
+0x07 BLBB[1:0] BLBA[1:0] BLBAT[1:0] LB[1:0]
Read/Write R R R R R R R R
Initial Value 1 1 1 1 1 1 1 1
This register is a mapping of the NVM lock bits into the I/O memory space, which enables direct read access from the
application software. Refer to “LOCKBITS – Lock Bit Register” on page 33 for a description.
XMEGA C [MANUAL] 29
Atmel-8465H-AVR-XMEGA C-12/2014
4.14 Register Descriptions – Fuses and Lock Bits
Bit 7 6 5 4 3 2 1 0
+0x01 WDWPER[3:0] WDPER[3:0]
Read/Write R/W R/W R/W R/W R/W R/W R/W R/W
Initial Value 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
+0x02 – BOOTRST TOSCSEL – – – BODPD[1:0]
Read/Write R/W R/W R/W R/W R/W R/W R/W R/W
Initial Value 1 1 1 1 1 1 1 1
Bit 7 – Reserved
This bit is unused and reserved for future use. For compatibility with future devices, always write this bit to one when this
register is written.
Bit 6 – BOOTRST: Boot Loader Section Reset Vector
This fuse can be programmed so the reset vector is pointing to the first address in the boot loader flash section. The
device will then start executing from the boot loader flash section after reset.
XMEGA C [MANUAL] 30
Atmel-8465H-AVR-XMEGA C-12/2014
Bit 4:2 – Reserved
These bits are unused and reserved for future use. For compatibility with future devices, always write these bits to one
when this register is written.
Bit 1:0 – BODPD[1:0]: BOD Operation in Power-down Mode
These fuse bits set the BOD operation mode in all sleep modes except idle mode.
For details on the BOD and BOD operation modes, refer to “Brownout Detection” on page 102.
BODPD[1:0] Description
00 Reserved
11 BOD disabled
Bit 7 6 5 4 3 2 1 0
+0x04 – – – RSTDISBL STARTUPTIME[1:0] WDLOCK –
Read/Write R/W R/W R/W R/W R/W R/W R/W R/W
Initial Value 1 1 1 1 1 1 1 1
00 64
01 4
10 Reserved
11 0
XMEGA C [MANUAL] 31
Atmel-8465H-AVR-XMEGA C-12/2014
Bit 1 – WDLOCK: Watchdog Timer Lock
The WDLOCK fuse can be programmed to lock the watchdog timer configuration. When this fuse is programmed, the
watchdog timer configuration cannot be changed, and the ENABLE bit in the watchdog CTRL register is automatically set
at reset and cannot be cleared from the application software. The WEN bit in the watchdog WINCTRL register is not set
automatically, and needs to be set from software. A reset is required before this bit will be read correctly after it is
changed.
WDLOCK Description
Bit 0 – Reserved
This bit is unused and reserved for future use. For compatibility with future devices, always write this bit to one when this
register is written.
Bit 7 6 5 4 3 2 1 0
+0x05 – – BODACT[1:0] EESAVE BODLEVEL[2:0]
Read/Write R R R/W R/W R/W R/W R/W R/W
Initial Value 1 1 – – – – – –
BODACT[1:0] Description
00 Reserved
11 BOD disabled
XMEGA C [MANUAL] 32
Atmel-8465H-AVR-XMEGA C-12/2014
Table 4-7. EEPROM Preserved through Chip Erase
EESAVE Description
Changes to the EESAVE fuse bit take effect immediately after the write timeout elapses. Hence, it is possible to update
EESAVE and perform a chip erase according to the new setting of EESAVE without leaving and reentering programming
mode.
Bit 2:0 – BODLEVEL[2:0]: Brownout Detection Voltage Level
These fuse bits sets the BOD voltage level. Refer to “Reset System” on page 100 for details. For BOD level nominal
values, see Table 9-2 on page 103.
Bit 7 6 5 4 3 2 1 0
+0x07 BLBB[1:0] BLBA[1:0] BLBAT[1:0] LB[1:0]
Read/Write R/W R/W R/W R/W R/W R/W R/W R/W
Initial Value 1 1 1 1 1 1 1 1
Table 4-8. Boot Lock Bit for the Boot Loader Section
10 WLOCK Write lock – SPM is not allowed to write the boot loader section.
Read and write lock – SPM is not allowed to write to the boot loader
section, and (E)LPM executing from the application section is not
allowed to read from the boot loader section.
00 RWLOCK
If the interrupt vectors are placed in the application section,
interrupts are disabled while executing from the boot loader
section.
XMEGA C [MANUAL] 33
Atmel-8465H-AVR-XMEGA C-12/2014
Table 4-9. Boot Lock Bit for the Application Section
10 WLOCK Write lock – SPM is not allowed to write the application section.
Read lock – (E)LPM executing from the boot loader section is not
allowed to read from the application section.
01 RLOCK
If the interrupt vectors are placed in the boot loader section,
interrupts are disabled while executing from the application section.
Read and write lock – SPM is not allowed to write to the application
section, and (E)LPM executing from the boot loader section is not
00 RWLOCK allowed to read from the application section.
If the interrupt vectors are placed in the boot loader section,
interrupts are disabled while executing from the application section.
Table 4-10. Boot Lock Bit for the Application Table Section
10 WLOCK Write lock – SPM is not allowed to write the application table
Read lock – (E)LPM executing from the boot loader section is not
allowed to read from the application table section.
01 RLOCK If the interrupt vectors are placed in the boot loader section,
interrupts are disabled while executing from the application
section.
XMEGA C [MANUAL] 34
Atmel-8465H-AVR-XMEGA C-12/2014
Table 4-11. Lock Bit Protection Mode
Note: 1. Program the Fuse Bits and Boot Lock Bits before programming the Lock Bits.
XMEGA C [MANUAL] 35
Atmel-8465H-AVR-XMEGA C-12/2014
4.15 Register Description – Production Signature Row
Bit 7 6 5 4 3 2 1 0
0x00 RCOSC2M[7:0]
Read/Write R R R R R R R R
Initial Value x x x x x x x x
Bit 7 6 5 4 3 2 1 0
0x01 RCOSC2MA[7:0]
Read/Write R R R R R R R R
Initial Value x x x x x x x x
Bit 7 6 5 4 3 2 1 0
0x02 RCOSC32K[7:0]
Read/Write R R R R R R R R
Initial Value x x x x x x x x
Bit 7 6 5 4 3 2 1 0
0x03 RCOSC32M[7:0]
Read/Write R R R R R R R R
Initial Value x x x x x x x x
XMEGA C [MANUAL] 36
Atmel-8465H-AVR-XMEGA C-12/2014
4.15.5 RCOSC32MA – Internal 32MHz RC Oscillator Calibration Register
Bit 7 6 5 4 3 2 1 0
0x04 RCOSC32MA[7:0]
Read/Write R R R R R R R R
Initial Value x x x x x x x x
Bit 7 6 5 4 3 2 1 0
0x09 LOTNUM1[7:0]
Read/Write R R R R R R R R
Initial Value x x x x x x x x
Bit 7 6 5 4 3 2 1 0
0x0A LOTNUM2[7:0]
Read/Write R R R R R R R R
Initial Value x x x x x x x x
XMEGA C [MANUAL] 37
Atmel-8465H-AVR-XMEGA C-12/2014
4.15.9 LOTNUM3 – Lot Number Register 3
Bit 7 6 5 4 3 2 1 0
0x0B LOTNUM3[7:0]
Read/Write R R R R R R R R
Initial Value x x x x x x x x
Bit 7 6 5 4 3 2 1 0
0x0C LOTNUM4[7:0]
Read/Write R R R R R R R R
Initial Value x x x x x x x x
Bit 7 6 5 4 3 2 1 0
0x0D LOTNUM5[7:0]
Read/Write R R R R R R R R
Initial Value x x x x x x x x
Bit 7 6 5 4 3 2 1 0
0x10 WAFNUM[7:0]
Read/Write R R R R R R R R
Initial Value 0 0 0 x x x x x
XMEGA C [MANUAL] 38
Atmel-8465H-AVR-XMEGA C-12/2014
4.15.14 COORDX1 – Wafer Coordinate X Register 1
Bit 7 6 5 4 3 2 1 0
0x13 COORDX1[7:0]
Read/Write R R R R R R R R
Initial Value x x x x x x x x
Bit 7 6 5 4 3 2 1 0
0x14 COORDY0[7:0]
Read/Write R R R R R R R R
Initial Value x x x x x x x x
Bit 7 6 5 4 3 2 1 0
0x15 COORDY1[7:0]
Read/Write R R R R R R R R
Initial Value x x x x x x x x
Bit 7 6 5 4 3 2 1 0
0x1B USBCAL1[7:0]
Read/Write R R R R R R R R
Initial Value x x x x x x x x
XMEGA C [MANUAL] 39
Atmel-8465H-AVR-XMEGA C-12/2014
4.15.19 USBRCOSC – USB RCOSC Calibration
Bit 7 6 5 4 3 2 1 0
0x1C USBRCOSC[7:0]
Read/Write R R R R R R R R
Initial Value x x x x x x x x
Bit 7 6 5 4 3 2 1 0
0x21 ADCACAL1[7:0]
Read/Write R R R R R R R R
Initial Value x x x x x x x x
XMEGA C [MANUAL] 40
Atmel-8465H-AVR-XMEGA C-12/2014
4.15.23 TEMPSENSE1 – Temperature Sensor Calibration Register 1
Bit 7 6 5 4 3 2 1 0
0x2F TEMPSENSE1[7:0]
Read/Write R R R R R R R R
Initial Value 0 0 0 0 x x x x
Bit 7 6 5 4 3 2 1 0
+n GPIORn[7:0]
Read/Write R/W R/W R/W R/W R/W R/W R/W R/W
Initial Value 0 0 0 0 0 0 0 0
These are general purpose registers that can be used to store data, such as global variables and flags, in the bit-
accessible I/O memory space.
Bit 7 6 5 4 3 2 1 0
+0x01 DEVID1[7:0]
Read/Write R R R R R R R R
Initial Value 1/0 1/0 1/0 1/0 1/0 1/0 1/0 1/0
XMEGA C [MANUAL] 41
Atmel-8465H-AVR-XMEGA C-12/2014
4.17.3 DEVID2 – Device ID Register 2
Bit 7 6 5 4 3 2 1 0
+0x02 DEVID2[7:0]
Read/Write R R R R R R R R
Initial Value 1/0 1/0 1/0 1/0 1/0 1/0 1/0 1/0
Bit 7 6 5 4 3 2 1 0
+0x03 – – – – REVID[3:0]
Read/Write R R R R R R R R
Initial Value 0 0 0 0 1/0 1/0 1/0 1/0
Bit 7 6 5 4 3 2 1 0
+0x07 – – – – – – STARTUPDLYA[1:0]
Read/Write R R R R R R R/W R/W
Initial Value 0 0 0 0 0 0 0 0
11 2CLK 2 * CLKPER
10 8CLK 8 * CLKPER
11 32CLK 32 * CLKPER
XMEGA C [MANUAL] 42
Atmel-8465H-AVR-XMEGA C-12/2014
4.17.6 EVSYSLOCK – Event System Lock Register
Bit 7 6 5 4 3 2 1 0
+0x08 – – – – – – – EVSYS0LOCK
Read/Write R R R R R R R R/W
Initial Value 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
+0x09 – – – – – – – AWEXCLOCK
Read/Write R R R R R R R R/W
Initial Value 0 0 0 0 0 0 0 0
XMEGA C [MANUAL] 43
Atmel-8465H-AVR-XMEGA C-12/2014
4.18 Register Summary - NVM Controller
Address Name Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0 Page
+0x00 ADDR0 Address Byte 0 26
+0x01 ADDR1 Address Byte 1 26
+0x02 ADDR2 Address Byte 2 26
+0x03 Reserved – – – – – – – –
+0x04 DATA0 Data Byte 0 26
+0x05 DATA1 Data Byte 1 27
+0x06 DATA2 Data Byte 2 27
+0x07 Reserved – – – – – – – –
+0x08 Reserved – – – – – – – –
+0x09 Reserved – – – – – – – –
+0x0A CMD – CMD[6:0] 27
+0x0B CTRLA – – – – – – – CMDEX 27
+0x0C CTRLB – – – – EEMAPEN FPRM EPRM SPMLOCK 28
+0x0D INTCTRL – – – – SPMLVL[1:0] EELVL[1:0] 28
+0x0E Reserved – – – – – – – –
+0x0F STATUS NVMBUSY FBUSY – – – – EELOAD FLOAD 29
+0x10 LOCKBITS BLBB[1:0] BLBA[1:0] BLBAT[1:0] LB[1:0] 29
XMEGA C [MANUAL] 44
Atmel-8465H-AVR-XMEGA C-12/2014
Address Auto load Name Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0 Page
0x1E Reserved – – – – – – – –
0x20 NO ADCACAL0 ADCACAL0[7:0] 40
0x21 NO ADCACAL1 ADCACAL1{7:0] 40
0x22 Reserved – – – – – – – –
0x23 Reserved – – – – – – – –
0x24 Reserved – – – – – – – –
0x25 Reserved – – – – – – – –
0x26 Reserved – – – – – – – –
0x27 Reserved – – – – – – – –
0x28 Reserved – – – – – – – –
0x29 Reserved – – – – – – – –
0x2A Reserved – – – – – – – –
0x2B Reserved – – – – – – – –
0x2C Reserved – – – – – – – –
0x2D Reserved – – – – – – – –
0x2E NO TEMPSENSE0 TEMPSENSE0[7:0] 40
0x2F NO TEMPSENSE1 – – – – TEMPSENSE1[11:8] 41
0x38 Reserved – – – – – – – –
0x39 Reserved – – – – – – – –
0x3A Reserved – – – – – – – –
0x3B Reserved – – – – – – – –
0x3C Reserved – – – – – – – –
0x3D Reserved – – – – – – – –
0x3E Reserved – – – – – – – –
XMEGA C [MANUAL] 45
Atmel-8465H-AVR-XMEGA C-12/2014
5. DMAC - Direct Memory Access Controller
5.1 Features
Allows high speed data transfers with minimal CPU intervention
from data memory to data memory
from data memory to peripheral
from peripheral to data memory
from peripheral to peripheral
Two DMA channels with separate
transfer triggers
interrupt vectors
addressing modes
Programmable channel priority
From 1 byte to 16MB of data in a single transaction
Up to 64KB block transfers with repeat
1, 2, 4, or 8 byte burst transfers
Multiple addressing modes
Static
Incremental
Decremental
Optional reload of source and destination addresses at the end of each
Burst
Block
Transaction
Optional interrupt on end of transaction
Optional connection to CRC generator for CRC on DMA data
5.2 Overview
The two-channel direct memory access (DMA) controller can transfer data between memories and peripherals, and thus
offload these tasks from the CPU. It enables high data transfer rates with minimum CPU intervention, and frees up CPU
time. The two DMA channels enable up to two independent and parallel transfers.
The DMA controller can move data between SRAM and peripherals, between SRAM locations and directly between
peripheral registers. With access to all peripherals, the DMA controller can handle automatic transfer of data to/from
communication modules. The DMA controller can also read from memory mapped EEPROM.
Data transfers are done in continuous bursts of 1, 2, 4, or 8 bytes. They build block transfers of configurable size from 1
byte to 64KB. A repeat counter can be used to repeat each block transfer for single transactions up to 16MB. Source and
destination addressing can be static, incremental or decremental. Automatic reload of source and/or destination
addresses can be done after each burst or block transfer, or when a transaction is complete. Application software,
peripherals, and events can trigger DMA transfers.
The two DMA channels have individual configuration and control settings. This include source, destination, transfer
triggers, and transaction sizes. They have individual interrupt settings. Interrupt requests can be generated when a
transaction is complete or when the DMA controller detects an error on a DMA channel.
To allow for continuous transfers, two channels can be interlinked so that the second takes over the transfer when the
first is finished, and vice versa.
XMEGA C [MANUAL] 46
Atmel-8465H-AVR-XMEGA C-12/2014
Figure 5-1. DMA Overview
DMA Channel 0
DMA trigger /
CTRLA
Event
CTRLB
Enable TRIGSRC Arbitration
Burst
R/W Master port
Control Logic Arbiter
Slave port
Read /
Write
DMA transaction
XMEGA C [MANUAL] 47
Atmel-8465H-AVR-XMEGA C-12/2014
5.4 Transfer Triggers
DMA transfers can be started only when a DMA transfer request is detected. A transfer request can be triggered from
software, from an external trigger source (peripheral), or from an event. There are dedicated source trigger selections for
each DMA channel. The available trigger sources may vary from device to device, depending on the modules or
peripherals that exist in the device. Using a transfer trigger for a module or peripherals that does not exist will have no
effect. For a list of all transfer triggers, refer to “TRIGSRC – Trigger Source” on page 55.
By default, a trigger starts a block transfer operation. When the block transfer is complete, the channel is automatically
disabled. When enabled again, the channel will wait for the next block transfer trigger. It is possible to select the trigger to
start a burst transfer instead of a block transfer. This is called a single-shot transfer, and for each trigger only one burst is
transferred. When repeat mode is enabled, the next block transfer does not require a transfer trigger. It will start as soon
as the previous block is done.
If the trigger source generates a transfer request during an ongoing transfer, this will be kept pending, and the transfer
can start when the ongoing one is done. Only one pending transfer can be kept, and so if the trigger source generates
more transfer requests when one is already pending, these will be lost.
5.5 Addressing
The source and destination address for a DMA transfer can either be static or automatically incremented or
decremented, with individual selections for source and destination. When address increment or decrement is used, the
default behaviour is to update the address after each access. The original source and destination addresses are stored
by the DMA controller, and so the source and destination addresses can be individually configured to be reloaded at the
following points:
End of each burst transfer
End of each block transfer
End of transaction
Never reloaded
XMEGA C [MANUAL] 48
Atmel-8465H-AVR-XMEGA C-12/2014
5.9 Error Detection
The DMA controller can detect erroneous operation. Error conditions are detected individually for each DMA channel,
and the error conditions are:
Write to memory mapped EEPROM locations
Reading EEPROM when the EEPROM is off (sleep entered)
DMA controller or a busy channel is disabled in software during a transfer
5.11 Protection
In order to ensure safe operation, some of the channel registers are protected during a transaction. When the DMA
channel busy flag (CHnBUSY) is set for a channel, the user can modify only the following registers and bits:
CTRL register
INTFLAGS register
TEMP registers
CHEN, CHRST, TRFREQ, and REPEAT bits of the channel CTRL register
TRIGSRC register
5.12 Interrupts
The DMA controller can generate interrupts when an error is detected on a DMA channel or when a transaction is
complete for a DMA channel. Each DMA channel has a separate interrupt vector, and there are different interrupt flags
for error and transaction complete.
If repeat is not enabled, the transaction complete flag is set at the end of the block transfer. If unlimited repeat is enabled,
the transaction complete flag is also set at the end of each block transfer.
XMEGA C [MANUAL] 49
Atmel-8465H-AVR-XMEGA C-12/2014
5.13 Register Description – DMA Controller
Bit 7 6 5 4 3 2 1 0
+0x00 ENABLE RESET – – – DBUFMODE – PRIMODE
Read/Write R/W R/W R R R R/W R R/W
Initial Value 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
+0x03 – – CH1ERRIF CH0ERRIF – – CH1TRNFIF CH0TRNFIF
Read/Write R R R/W R/W R R R/W R/W
Initial Value 0 0 0 0 0 0 0 0
XMEGA C [MANUAL] 50
Atmel-8465H-AVR-XMEGA C-12/2014
Bit 3:2 – Reserved
These bits are unused and reserved for future use. For compatibility with future devices, always write these bits to zero
when this register is written.
Bit 1:0 – CHnTRNFIF[1:0]: Channel n Transaction Complete Interrupt Flag
When a transaction on channel n has been completed, the CHnTRFIF flag will be set. If unlimited repeat count is
enabled, this flag is read as one after each block transfer. Writing a one to this bit location will clear the flag.
Bit 7 6 5 4 3 2 1 0
+0x04 – – CH1BUSY CH0BUSY – – CH1PEND CH0PEND
Read/Write R R R R R R R R
Initial Value 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
+0x06 TEMP[7:0]
Read/Write R/W R/W R/W R/W R/W R/W R/W R/W
Initial Value 0 0 0 0 0 0 0 0
XMEGA C [MANUAL] 51
Atmel-8465H-AVR-XMEGA C-12/2014
5.13.5 TEMPH – Temporary Register High
Bit 7 6 5 4 3 2 1 0
+0x07 TEMP[15:8]
Read/Write R/W R/W R/W R/W R/W R/W R/W R/W
Initial Value 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
+0x00 ENABLE RESET REPEAT TRFREQ – SINGLE BURSTLEN[1:0]
Read/Write R/W R/W R/W R/W R R/W R/W R/W
Initial Value 0 0 0 0 0 0 0 0
XMEGA C [MANUAL] 52
Atmel-8465H-AVR-XMEGA C-12/2014
Table 5-2. DMA Channel Burst Mode
Table 5-3. Summary of Triggers, Transaction Complete Flag, and Channel Disable According to DMA Channel
Configuration
REPEAT SINGLE REPCNT Trigger Flag set after Channel disabled after
Bit 7 6 5 4 3 2 1 0
+0x01 CHBUSY CHPEND ERRIF TRNIF ERRINTLVL[1:0] TRNINTLVL[1:0]
Read/Write R R R/W R/W R/W R/W R/W R/W
Initial Value 0 0 0 0 0 0 0 0
XMEGA C [MANUAL] 53
Atmel-8465H-AVR-XMEGA C-12/2014
interrupt, ERRIF will not be cleared when the interrupt vector is executed. This flag is cleared by writing a one to this
location.
Bit 4 – TRNIF: Channel n Transaction Complete Interrupt Flag
When a transaction on the DMA channel has been completed, the TRNIF flag will be set and the optional interrupt is
generated. When repeat is not enabled, the transaction is complete and TRNIFR is set after the block transfer. When
unlimited repeat is enabled, TRNIF is also set after each block transfer.
Since the DMA channel transaction n complete interrupt shares the interrupt address with the DMA channel error
interrupt, TRNIF will not be cleared when the interrupt vector is executed. This flag is cleared by writing a one to this
location.
Bit 3:2 – ERRINTLVL[1:0]: Channel Error Interrupt Level
These bits enable the interrupt for DMA channel transfer errors and select the interrupt level, as described in “Interrupts
and Programmable Multilevel Interrupt Controller” on page 112. The enabled interrupt will trigger for the conditions when
ERRIF is set.
Bit 1:0 – TRNINTLVL[1:0]: Channel Transaction Complete Interrupt Level
These bits enable the interrupt for DMA channel transaction completes and select the interrupt level, as described in
“Interrupts and Programmable Multilevel Interrupt Controller” on page 112. The enabled interrupt will trigger for the
conditions when TRNIF is set.
Bit 7 6 5 4 3 2 1 0
+0x02 SRCRELOAD[1:0] SRCDIR[1:0] DESTRELOAD[1:0] DESTDIR[1:0]
Read/Write R/W R/W R/W R/W R/W R/W R/W R/W
Initial Value 0 0 0 0 0 0 0 0
XMEGA C [MANUAL] 54
Atmel-8465H-AVR-XMEGA C-12/2014
Table 5-5. DMA Channel Source Address Mode Settings
00 FIXED Fixed
01 INC Increment
10 DEC Decrement
11 - Reserved
00 FIXED Fixed
01 INC Increment
10 DEC Decrement
11 - Reserved
Bit 7 6 5 4 3 2 1 0
+0x03 TRIGSRC[7:0]
Read/Write R/W R/W R/W R/W R/W R/W R/W R/W
Initial Value 0 0 0 0 0 0 0 0
XMEGA C [MANUAL] 55
Atmel-8465H-AVR-XMEGA C-12/2014
shows the base value for all modules and peripherals. Table 5-9 to Table 5-11 on page 57 shows the offset value for the
trigger sources in the different modules and peripheral types. For modules or peripherals which do not exist for a device,
the transfer trigger does not exist. Refer to the device datasheet for the list of peripherals available.
If the interrupt flag related to the trigger source is cleared or the interrupt level enabled so that an interrupt is triggered,
the DMA request will be lost. Since a DMA request can clear the interrupt flag, interrupts can be lost.
Note: For most trigger sources, the request is cleared by accessing a register belonging to the peripheral with the request. Refer to the dif-
ferent peripheral chapters for how requests are generated and cleared.
Table 5-8. DMA Trigger Source Base Values for all Modules and Peripherals
Table 5-9. DMA Trigger Source Offset Values for Event System Triggers
XMEGA C [MANUAL] 56
Atmel-8465H-AVR-XMEGA C-12/2014
Table 5-10. DMA Trigger Source Offset Values for Timer/ Counter Triggers
Table 5-11. DMA Trigger Source Offset Values for USART Triggers
The group configuration is the “base_offset;” for example, TCC1_CCA for the timer/counter C1 CC channel A the transfer
trigger.
XMEGA C [MANUAL] 57
Atmel-8465H-AVR-XMEGA C-12/2014
5.14.7 REPCNT – Repeat Counter Register
Bit 7 6 5 4 3 2 1 0
+0x06 REPCNT[7:0]
Read/Write R/W R/W R/W R/W R/W R/W R/W R/W
Initial Value 0 0 0 0 0 0 0 0
REPCNT counts how many times a block transfer is performed. For each block transfer, this register will be
decremented.
When repeat mode is enabled (see REPEAT bit in “ADDRCTRL – Address Control Register” on page 54), this register is
used to control when the transaction is complete. The counter is decremented after each block transfer if the DMA has to
serve a limited number of repeated block transfers. When repeat mode is enabled, the channel is disabled when
REPCNT reaches zero and the last block transfer is completed. Unlimited repeat is achieved by setting this register to
zero.
Bit 7 6 5 4 3 2 1 0
+0x09 SRCADDR[15:8]
Read/Write R/W R/W R/W R/W R/W R/W R/W R/W
Initial Value 0 0 0 0 0 0 0 0
XMEGA C [MANUAL] 58
Atmel-8465H-AVR-XMEGA C-12/2014
5.14.11 DESTADDR0 – Channel Destination Address 0
DESTADDR0, DESTADDR1, and DESTADDR2 represent the 24-bit value DESTADDR, which is the DMA channel
destination address. DESTADDR2 holds the most significant byte in the register. DESTADDR may be automatically
incremented or decremented based on settings in the DESTDIR bits in “ADDRCTRL – Address Control Register” on
page 54.
Bit 7 6 5 4 3 2 1 0
+0x0C DESTADDR[7:0]
Read/Write R/W R/W R/W R/W R/W R/W R/W R/W
Initial Value 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
+0x0D DESTADDR[15:8]
Read/Write R/W R/W R/W R/W R/W R/W R/W R/W
Initial Value 0 0 0 0 0 0 0 0
XMEGA C [MANUAL] 59
Atmel-8465H-AVR-XMEGA C-12/2014
5.15 Register Summary – DMA Controller
Address Name Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0 Page
+0x00 CTRL ENABLE RESET – – – DBUFMODE – PRIMODE 50
+0x01 Reserved – – – – – – – –
+0x02 Reserved – – – – – – – –
+0x03 INTFLAGS – – CH1ERRIF CH0ERRIF – – CH1TRNFIF CH0TRNFIF 50
+0x04 STATUS – – CH1BUSY CH0BUSY – – CH1PEND CH0PEND 51
+0x05 Reserved – – – – – – – –
+0x06 TEMPL TEMP[7:0] 51
+0x07 TEMPH TEMP[15:8] 52
+0x10 CH0 Offset Offset address for DMA Channel 0
+0x20 CH1 Offset Offset address for DMA Channel 1
+0x30 Reserved – – – – – – – –
+0x40 Reserved – – – – – – – –
XMEGA C [MANUAL] 60
Atmel-8465H-AVR-XMEGA C-12/2014
6. Event System
6.1 Features
System for direct peripheral-to-peripheral communication and signaling
Peripherals can directly send, receive, and react to peripheral events
CPU and DMA controller independent operation
100% predictable signal timing
Short and guaranteed response time
Four event channels for up to eight different and parallel signal routings and configurations
Events can be sent and/or used by most peripherals, clock system, and software
Additional functions include
Quadrature decoders
Digital filtering of I/O pin state
Works in active mode and idle sleep mode
6.2 Overview
The event system enables direct peripheral-to-peripheral communication and signaling. It allows a change in one
peripheral’s state to automatically trigger actions in other peripherals. It is designed to provide a predictable system for
short and predictable response times between peripherals. It allows for autonomous peripheral control and interaction
without the use of interrupts CPU or DMA controller resources, and is thus a powerful tool for reducing the complexity,
size and execution time of application code. It also allows for synchronized timing of actions in several peripheral
modules.
A change in a peripheral’s state is referred to as an event, and usually corresponds to the peripheral’s interrupt
conditions. Events can be directly passed to other peripherals using a dedicated routing network called the event routing
network. How events are routed and used by the peripherals is configured in software.
Figure 6-1 on page 62 shows a basic diagram of all connected peripherals. The event system can directly connect
together analog converters, analog comparators, I/O port pins, the real-time counter, timer/counters, IR communication
module (IRCOM) and USB interface. It can also be used to trigger DMA transactions (DMA controller). Events can also
be generated from software and the peripheral clock.
XMEGA C [MANUAL] 61
Atmel-8465H-AVR-XMEGA C-12/2014
Figure 6-1. Event System Overview and Connected Peripherals
CPU / DMA
Software Controller
USB
The event routing network consists of four software-configurable multiplexers that control how events are routed and
used. These are called event channels, and allow for up to four parallel event configurations and routings. The maximum
routing latency is two peripheral clock cycles. The event system works in both active mode and idle sleep mode.
6.3 Events
In the context of the event system, an indication that a change of state within a peripheral has occurred is called an
event. There are two main types of events: signaling events and data events. Signaling events only indicate a change of
state while data events contain additional information about the event.
The peripheral from which the event originates is called the event generator. Within each peripheral (for example, a
timer/counter), there can be several event sources, such as a timer compare match or timer overflow. The peripheral
using the event is called the event user, and the action that is triggered is called the event action.
XMEGA C [MANUAL] 62
Atmel-8465H-AVR-XMEGA C-12/2014
Figure 6-2. Example of Event Source, Generator, User, and Action
Timer/Counter ADC
Compare Match
Event Syncsweep
Over-/Underflow
| Routing
Network Single
Conversion
Error
XMEGA C [MANUAL] 63
Atmel-8465H-AVR-XMEGA C-12/2014
Table 6-1. Manually Generated Events and Decoding of Events
0 0 No event No event
XMEGA C [MANUAL] 64
Atmel-8465H-AVR-XMEGA C-12/2014
Figure 6-3. Event Routing Network
Event Channel 3
Event Channel 2
Event Channel 1
Event Channel 0
(10)
TCC0 (6)
(4)
TCC1 (4)
CH0CTRL[7:0]
CH0MUX[7:0]
(4) TCD0 (6)
CH1CTRL[7:0]
(4) TCF0 (6)
CH1MUX[7:0]
(29)
(4) ADCA (4)
USB (4)
CH2CTRL[7:0]
CH2MUX[7:0]
ACA (3)
RTC (2)
ClkPER (16)
(48)
PORTA (8)
PORTB (8)
CH3CTRL[7:0]
PORTC (8)
CH3MUX[7:0]
PORTD (8)
PORTE (8)
PORTF (8)
Four multiplexers means that it is possible to route up to four events at the same time. It is also possible to route one
event through several multiplexers.
Not all XMEGA devices contain all peripherals. This only means that a peripheral is not available for generating or using
events. The network configuration itself is compatible between all devices.
XMEGA C [MANUAL] 65
Atmel-8465H-AVR-XMEGA C-12/2014
It takes a maximum of two peripheral clock cycles from when an event is generated until the event actions in other
peripherals are triggered. This ensures short and 100% predictable response times, independent of CPU or DMA
controller load or software revisions.
6.6 Filtering
Each event channel includes a digital filter. When this is enabled, an event must be sampled with the same value for a
configurable number of system clock cycles before it is accepted. This is primarily intended for pin change events.
0 0 No event No event
0 1 Index/reset No event
Forward Direction
QDPH0
QDPH90
QDINDX
00 10 11 01
Backward
Direction
QDPH0
QDPH90
QDINDX
01 11 10 00
Figure 6-4 shows typical quadrature signals from a rotary encoder. The signals QDPH0 and QDPH90 are the two
quadrature signals. When QDPH90 leads QDPH0, the rotation is defined as positive or forward. When QDPH0 leads
QDPH90, the rotation is defined as negative or reverse. The concatenation of the two phase signals is called the
quadrature state or the phase state.
In order to know the absolute rotary displacement, a third index signal (QINDX) can be used. This gives an indication
once per revolution.
XMEGA C [MANUAL] 66
Atmel-8465H-AVR-XMEGA C-12/2014
6.7.2 QDEC Setup
For a full QDEC setup, the following is required:
Tho or three I/O port pins for quadrature signal input
Two event system channels for quadrature decoding
One timer/counter for up, down, and optional index count
The following procedure should be used for QDEC setup:
1. Choose two successive pins on a port as QDEC phase inputs.
2. Set the pin direction for QDPH0 and QDPH90 as input.
3. Set the pin configuration for QDPH0 and QDPH90 to low level sense.
4. Select the QDPH0 pin as a multiplexer input for an event channel, n.
5. Enable quadrature decoding and digital filtering in the event channel.
6. Optional:
1. Set up a QDEC index (QINDX).
2. Select a third pin for QINDX input.
3. Set the pin direction for QINDX as input.
4. Set the pin configuration for QINDX to sense both edges.
5. Select QINDX as a multiplexer input for event channel n+1.
6. Set the quadrature index enable bit in event channel n+1.
7. Select the index recognition mode for event channel n+1.
7. Set quadrature decoding as the event action for a timer/counter.
8. Select event channel n as the event source for the timer/counter.
Set the period register of the timer/counter to ('line count' * 4 - 1), the line count of the quadrature encoder
Enable the timer/counter without clock prescaling
The angle of a quadrature encoder attached to QDPH0, QDPH90 (and QINDX) can now be read directly from the
timer/counter count register. If the count register is different from BOTTOM when the index is recognized, the
timer/counter error flag is set. Similarly, the error flag is set if the position counter passes BOTTOM without the
recognition of the index.
XMEGA C [MANUAL] 67
Atmel-8465H-AVR-XMEGA C-12/2014
6.8 Register Description
Bit 7 6 5 4 3 2 1 0
CHnMUX[7:0]
Read/Write R/W R/W R/W R/W R/W R/W R/W R/W
Initial Value 0 0 0 0 0 0 0 0
0000 0 0 0 1 (Reserved)
0000 0 0 1 X (Reserved)
0000 0 1 X X (Reserved)
0000 1 0 1 X (Reserved)
0000 1 1 X X (Reserved)
0001 0 0 1 1 (Reserved)
0001 0 1 X X (Reserved)
0001 1 X X X (Reserved)
0010 0 0 0 1 (Reserved)
0010 0 0 1 X (Reserved)
0010 0 1 X X (Reserved)
0010 1 X X X (Reserved)
0011 X X X X (Reserved)
XMEGA C [MANUAL] 68
Atmel-8465H-AVR-XMEGA C-12/2014
CHnMUX[7:4] CHnMUX[3:0] Group configuration Event source
0100 X X X X (Reserved)
1001 X X X X (Reserved)
1010 X X X X (Reserved)
1011 X X X X (Reserved)
1111 1 X X X (Reserved)
1111 1 X X X (Reserved)
1111 1 X X X (Reserved)
Notes: 1. The description of how the ports generate events is described in “Port Event” on page 126.
2. The different USB events can be selected for only event channel, 0 to 3.
0 1 X – (Reserved)
XMEGA C [MANUAL] 69
Atmel-8465H-AVR-XMEGA C-12/2014
6.8.2 CHnCTRL – Event Channel n Control Register
Bit 7 6 5 4 3 2 1 0
– QDIRM[1:0](1) QDIEN(1) QDEN(1) DIGFILT[2:0]
– – – – – DIGFILT[2:0]
Read/Write R R/W R/W R/W R/W R/W R/W R
Initial Value 0 0 0 0 0 0 0 0
Note: 1. Only available for CH0CTRL and CH2CTRL. These bits are reserved in CH1CTRL and CH3CTRL.
Bit 7 – Reserved
This bit is reserved and will always be read as zero. For compatibility with future devices, always write this bit to zero
when this register is written.
Bit 6:5 – QDIRM[1:0]: Quadrature Decode Index Recognition Mode
These bits determine the quadrature state for the QDPH0 and QDPH90 signals, where a valid index signal is recognized
and the counter index data event is given according to Table 6-5. These bits should only be set when a quadrature
encoder with a connected index signal is used.These bits are available only for CH0CTRL and CH2CTRL.
XMEGA C [MANUAL] 70
Atmel-8465H-AVR-XMEGA C-12/2014
Table 6-6. Digital Filter Coefficient Values (Continued)
XMEGA C [MANUAL] 71
Atmel-8465H-AVR-XMEGA C-12/2014
6.9 Register Summary
Address Name Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0 Page
XMEGA C [MANUAL] 72
Atmel-8465H-AVR-XMEGA C-12/2014
7. System Clock and Clock Options
7.1 Features
Fast start-up time
Safe run-time clock switching
Internal oscillators:
32MHz run-time calibrated and tunable oscillator
2MHz run-time calibrated oscillator
32.768kHz calibrated oscillator
32kHz ultra low power (ULP) oscillator with 1kHz output
External clock options
0.4MHz - 16MHz crystal oscillator
32.768kHz crystal oscillator
External clock
PLL with 20MHz - 128MHz output frequency
Internal and external clock options and 1x to 31x multiplication
Lock detector
Clock prescalers with 1x to 2048x division
Fast peripheral clocks running at 2 and 4 times the CPU clock
Automatic run-time calibration of internal oscillators
External oscillator and PLL lock failure detection with optional non-maskable interrupt
7.2 Overview
XMEGA devices have a flexible clock system supporting a large number of clock sources. It incorporates both accurate
internal oscillators and external crystal oscillator and resonator support. A high-frequency phase locked loop (PLL) and
clock prescalers can be used to generate a wide range of clock frequencies. A calibration feature (DFLL) is available,
and can be used for automatic run-time calibration of the internal oscillators to remove frequency drift over voltage and
temperature. An oscillator failure monitor can be enabled to issue a non-maskable interrupt and switch to the internal
oscillator if the external oscillator or PLL fails.
When a reset occurs, all clock sources except the 32kHz ultra low power oscillator are disabled. After reset, the device
will always start up running from the 2MHz internal oscillator. During normal operation, the system clock source and
prescalers can be changed from software at any time.
Figure 7-1 on page 74 presents the principal clock system in the XMEGA family of devices. Not all of the clocks need to
be active at a given time. The clocks for the CPU and peripherals can be stopped using sleep modes and power
reduction registers, as described in “Power Management and Sleep Modes” on page 93.
XMEGA C [MANUAL] 73
Atmel-8465H-AVR-XMEGA C-12/2014
Figure 7-1. The Clock System, Clock Sources, and Clock Distribution
clkPER
clkPER2 clkCPU
clkPER4
USB
clkUSB
System Clock Prescalers
Brown-out Watchdog
Prescaler
Detector Timer
clkSYS
clkRTC
System Clock Multiplexer
RTCSRC (SCLKSEL) USBSRC
DIV32
DIV32
DIV32
PLL
PLLSRC
DIV4
XOSCSEL
TOSC2
XTAL1
XTAL2
XMEGA C [MANUAL] 74
Atmel-8465H-AVR-XMEGA C-12/2014
7.3 Clock Distribution
Figure 7-1 on page 74 presents the principal clock distribution system used in XMEGA devices.
XMEGA C [MANUAL] 75
Atmel-8465H-AVR-XMEGA C-12/2014
oscillator frequency. The oscillator employs a built-in prescaler, which provides both a 32.768kHz output and a 1.024kHz
output, see “RTCCTRL – RTC Control Register” on page 83 for details.
C2
XTAL2
C1
XTAL1
GND
Two capacitors, C1 and C2, may be added to match the required load capacitance for the connected crystal.
General
Purpose XTAL2
I/O
External
Clock XTAL1
Signal
XMEGA C [MANUAL] 76
Atmel-8465H-AVR-XMEGA C-12/2014
7.4.2.3 32.768kHz Crystal Oscillator
A 32.768kHz crystal oscillator can be connected between the TOSC1 and TOSC2 pins and enables a dedicated low
frequency oscillator input circuit. A typical connection is shown in Figure 7-4. A low power mode with reduced voltage
swing on TOSC2 is available. This oscillator can be used as a clock source for the system clock and RTC, and as the
DFLL reference clock.
C1
TOSC1
GND
Two capacitors, C1 and C2, may be added to match the required load capacitance for the connected crystal. For details
on recommended TOSC characteristics and capacitor load, refer to device datasheets.
Prescaler A divides the system clock, and the resulting clock is clkPER4. Prescalers B and C can be enabled to divide the
clock speed further to enable peripheral modules to run at twice or four times the CPU clock frequency. If Prescalers B
and C are not used, all the clocks will run at the same frequency as the output from Prescaler A.
The system clock selection and prescaler registers are protected by the configuration change protection mechanism,
employing a timed write procedure for changing the system clock and prescaler settings. For details, refer to
“Configuration Change Protection” on page 13.
XMEGA C [MANUAL] 77
Atmel-8465H-AVR-XMEGA C-12/2014
7.6 PLL with 1x-31x Multiplication Factor
The built-in phase locked loop (PLL) can be used to generate a high-frequency system clock. The PLL has a user-
selectable multiplication factor of from 1 to 31. The output frequency, fOUT, is given by the input frequency, fIN, multiplied
by the multiplication factor, PLL_FAC.
f OUT = f IN PLL_FAC
XMEGA C [MANUAL] 78
Atmel-8465H-AVR-XMEGA C-12/2014
Figure 7-6. DFLL Reference Clock Selection
XOSCSEL
TOSC1
32.768 kHz Crystal Osc
TOSC2
DIV32 DIV32
USB Start of Frame
clkRC2MCREF
clkRC32MCREF
DFLL32M
DFLL2M
The ideal counter value representing the frequency ratio between the internal oscillator and a 1.024kHz reference clock
is loaded into the DFLL oscillator compare register (COMP) during reset. For the 32MHz oscillator, this register can be
written from software to make the oscillator run at a different frequency or when the ratio between the reference clock
and the oscillator is different (for example when the USB start of frame is used). The 48MHz calibration values must be
read from the production signature row and written to the 32MHz CAL register before the DFLL is enabled with USB SOF
as reference source.
The value that should be written to the COMP register is given by the following formula:
f OSC
COMP hex ( )
f RCnCREF
When the DFLL is enabled, it controls the ratio between the reference clock frequency and the oscillator frequency. If the
internal oscillator runs too fast or too slow, the DFLL will decrement or increment its calibration register value by one to
adjust the oscillator frequency. The oscillator is considered running too fast or too slow when the error is more than a half
calibration step size.
XMEGA C [MANUAL] 79
Atmel-8465H-AVR-XMEGA C-12/2014
Figure 7-7. Automatic Run-time Calibration
clkRCnCREF
COMP
RCOSC slow,
Frequency CALA incremented
OK RCOSC fast,
CALA decremented
The DFLL will stop when entering a sleep mode where the oscillators are stopped. After wake up, the DFLL will continue
with the calibration value found before entering sleep. The reset value of the DFLL calibration register can be read from
the production signature row.
When the DFLL is disabled, the DFLL calibration register can be written from software for manual run-time calibration of
the oscillator.
XMEGA C [MANUAL] 80
Atmel-8465H-AVR-XMEGA C-12/2014
7.9 Register Description – Clock
Bit 7 6 5 4 3 2 1 0
+0x00 – – – – – SCLKSEL[2:0]
Read/Write R R R R R R/W R/W R/W
Initial Value 0 0 0 0 0 0 0 0
101 – Reserved
110 – Reserved
111 – Reserved
Bit 7 – Reserved
This bit is unused and reserved for future use. For compatibility with future devices, always write this bit to zero when this
register is written.
XMEGA C [MANUAL] 81
Atmel-8465H-AVR-XMEGA C-12/2014
Bit 6:2 – PSADIV[4:0]: Prescaler A Division Factor
These bits define the division ratio of the clock prescaler A according to Table 7-2. These bits can be written at run-time
to change the frequency of the ClkPER4 clock relative to the system clock, ClkSYS.
00000 1 No division
00001 2 Divide by 2
00011 4 Divide by 4
00101 8 Divide by 8
00111 16 Divide by 16
01001 32 Divide by 32
01011 64 Divide by 64
10101 – Reserved
10111 – Reserved
11001 – Reserved
11011 – Reserved
11101 – Reserved
11111 – Reserved
XMEGA C [MANUAL] 82
Atmel-8465H-AVR-XMEGA C-12/2014
7.9.3 LOCK – Lock Register
Bit 7 6 5 4 3 2 1 0
+0x02 – – – – – – – LOCK
Read/Write R R R R R R R R/W
Initial Value 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
+0x03 – – – – RTCSRC[2:0] RTCEN
Read/Write R R R R R/W R/W R/W R/W
Initial Value 0 0 0 0 0 0 0 0
011 — Reserved
100 — Reserved
XMEGA C [MANUAL] 83
Atmel-8465H-AVR-XMEGA C-12/2014
7.9.5 USBSCTRL – USB Control Register
Bit 7 6 5 4 3 2 1 0
+0x04 – – USBPSDIV[2:0] USBSRC[1:0] USBSEN
Read/Write R R R/W R/W R/W R/W R/W R/W
Initial Value 0 0 0 0 0 0 0 0
000 1 No division
001 2 Divide by 2
010 4 Divide by 4
011 8 Divide by 8
100 16 Divide by 16
101 32 Divide by 32
110 — Reserved
111 — Reserved
00 PLL PLL
Note: 1. The 32MHz internal oscillator must be calibrated to 48MHz before selecting this as source for the USB device module. Refer to “DFLL 2MHz and
DFLL 32MHz” on page 78.
XMEGA C [MANUAL] 84
Atmel-8465H-AVR-XMEGA C-12/2014
7.10 Register Description – Oscillator
Bit 7 6 5 4 3 2 1 0
+0x00 – – – PLLEN XOSCEN RC32KEN RC32MEN RC2MEN
Read/Write R R R R/W R/W R/W R/W R/W
Initial Value 0 0 0 0 0 0 0 1
Bit 7 6 5 4 3 2 1 0
+0x01 – – – PLLRDY XOSCRDY RC32KRDY RC32MRDY RC2MRDY
Read/Write R R R R R R R R
Initial Value 0 0 0 0 0 0 0 0
XMEGA C [MANUAL] 85
Atmel-8465H-AVR-XMEGA C-12/2014
Bit 0 – RC2MRDY: 2MHz Internal Oscillator Ready
This flag is set when the 2MHz internal oscillator is stable and is ready to be used as the system clock source.
Bit 7 6 5 4 3 2 1 0
+0x02 FRQRANGE[1:0] X32KLPM XOSCPWR XOSCSEL[3:0]
Read/Write R/W R/W R/W R/W R/W R/W R/W R/W
Initial Value 0 0 0 0 0 0 0 0
Bit 7:6 – FRQRANGE[1:0]: 0.4 - 16MHz Crystal Oscillator Frequency Range Select
These bits select the frequency range for the connected crystal oscillator according to Table 7-7.
10 9TO12 9 - 12 10-40
11 12TO16 12 - 16 10-30
XMEGA C [MANUAL] 86
Atmel-8465H-AVR-XMEGA C-12/2014
Table 7-8. External Oscillator Selection and Start-up Time
Notes: 1. This option should be used only when frequency stability at startup is not important for the application. The option is not suitable for crystals.
2. This option is intended for use with ceramic resonators. It can also be used when the frequency stability at startup is not important for the
application.
3. When the external oscillator is used as the reference for a DFLL, only EXTCLK and 32KHZ can be selected.
Bit 7 6 5 4 3 2 1 0
+0x03 – – – – PLLFDIF PLLFDEN XOSCFDIF XOSCFDEN
Read/Write R R R R R/W R/W R/W R/W
Initial Value 0 0 0 0 0 0 0 0
XMEGA C [MANUAL] 87
Atmel-8465H-AVR-XMEGA C-12/2014
7.10.5 RC32KCAL – 32kHz Oscillator Calibration Register
Bit 7 6 5 4 3 2 1 0
+0x04 RC32KCAL[7:0]
Read/Write R/W R/W R/W R/W R/W R/W R/W R/W
Initial Value x x x x x x x x
Bit 7 6 5 4 3 2 1 0
+0x05 PLLSRC[1:0] PLLDIV PLLFAC[4:0]
Read/Write R/W R/W R/W R/W R/W R/W R/W R/W
Initial Value 0 0 0 0 0 0 0 0
01 — Reserved
Notes: 1. The 32.768kHz TOSC cannot be selected as the source for the PLL. An external clock must be a minimum 0.4MHz to be used as the source clock.
Bit 7 6 5 4 3 2 1 0
+0x06 – – – – – RC32MCREF[1:0] RC2MCREF
Read/Write R R R R R R/W R/W R/W
Initial Value 0 0 0 0 0 0 0 0
XMEGA C [MANUAL] 88
Atmel-8465H-AVR-XMEGA C-12/2014
Bit 2:1 – RC32MCREF[1:0]: 32MHz Oscillator Calibration Reference
These bits are used to select the calibration source for the 32MHz DFLL according to the Table 7-10. These bits will
select only which calibration source to use for the DFLL. In addition, the actual clock source that is selected must enabled
and configured for the calibration to function.
11 – Reserved
Bit 7 6 5 4 3 2 1 0
+0x00 – – – – – – – ENABLE
Read/Write R R R R R R R R/W
Initial Value 0 0 0 0 0 0 0 0
XMEGA C [MANUAL] 89
Atmel-8465H-AVR-XMEGA C-12/2014
Bit 7 – Reserved
This bit is unused and reserved for future use. For compatibility with future devices, always write this bit to zero when this
register is written.
Bit 6:0 – CALA[6:0]: DFLL Calibration Bits
These bits hold the part of the oscillator calibration value that is used for automatic runtime calibration. A factory-
calibrated value is loaded from the signature row of the device and written to this register during reset, giving an oscillator
frequency approximate to the nominal frequency for the oscillator. The bits cannot be written when the DFLL is enabled.
Bit 7 6 5 4 3 2 1 0
+0x03 – – CALB[5:0]
Read/Write R/W R/W R/W R/W R/W R/W R/W R/W
Initial Value 0 0 x x x x x x
Bit 7 6 5 4 3 2 1 0
+0x06 COMP[15:8]
Read/Write R/W R/W R/W R/W R/W R/W R/W R/W
Initial Value 0 0 0 0 0 0 0 0
XMEGA C [MANUAL] 90
Atmel-8465H-AVR-XMEGA C-12/2014
Table 7-11. Nominal DFLL32M COMP Values for Different Output Frequencies
30.0 0x7270
32.0 0x7A12
34.0 0x81B3
36.0 0x8954
38.0 0x90F5
40.0 0x9896
42.0 0xA037
44.0 0xA7D8
46.0 0xAF79
48.0 0xB71B
50.0 0xBEBC
52.0 0xC65D
54.0 0xCDFE
XMEGA C [MANUAL] 91
Atmel-8465H-AVR-XMEGA C-12/2014
7.12 Register Summary - Clock
Address Name Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0 Page
+0x00 CTRL – – – – – SCLKSEL[2:0] 81
+0x01 PSCTRL – PSADIV[4:0] PSBCDIV[1:0] 81
+0x02 LOCK – – – – – – – LOCK 83
+0x03 RTCCTRL – – – – RTCSRC[2:0] RTCEN 83
+0x04 USBSCTR – – USBPSDIV[2:0] USBSRC[1:0] USBSEN 84
+0x05 Reserved – – – – – – – –
+0x06 Reserved – – – – – – – –
+0x07 Reserved – – – – – – – –
0x00 OSCF_vect PLL and external oscillator failure interrupt vector (NMI)
XMEGA C [MANUAL] 92
Atmel-8465H-AVR-XMEGA C-12/2014
8. Power Management and Sleep Modes
8.1 Features
Power management for adjusting power consumption and functions
Five sleep modes
Idle
Power down
Power save
Standby
Extended standby
Power reduction register to disable clock and turn off unused peripherals in active and idle modes
8.2 Overview
Various sleep modes and clock gating are provided in order to tailor power consumption to application requirements.
This enables the XMEGA microcontroller to stop unused modules to save power.
All sleep modes are available and can be entered from active mode. In active mode, the CPU is executing application
code. When the device enters sleep mode, program execution is stopped and interrupts or a reset is used to wake the
device again. The application code decides which sleep mode to enter and when. Interrupts from enabled peripherals
and all enabled reset sources can restore the microcontroller from sleep to active mode.
In addition, power reduction registers provide a method to stop the clock to individual peripherals from software. When
this is done, the current state of the peripheral is frozen, and there is no power consumption from that peripheral. This
reduces the power consumption in active mode and idle sleep modes and enables much more fine-tuned power
management than sleep modes alone.
XMEGA C [MANUAL] 93
Atmel-8465H-AVR-XMEGA C-12/2014
Table 8-1. Active Clock Domains and Wake-up Sources in the Different Sleep Modes
All interrupts
USB resume
CPU clock
RTC clock
Sleep Modes
Idle X X X X X X X X X
Power down X X X
Power save X X X X X X
Standby X X X X
Extended standby X X X X X X X
The wake-up time for the device is dependent on the sleep mode and the main clock source. The startup time for the
system clock source must be added to the wake-up time for sleep modes where the system clock source is not kept
running. For details on the startup time for the different oscillator options, refer to “System Clock and Clock Options” on
page 73.
The content of the register file, SRAM and registers are kept during sleep. If a reset occurs during sleep, the device will
reset, start up, and execute from the reset vector.
XMEGA C [MANUAL] 94
Atmel-8465H-AVR-XMEGA C-12/2014
8.4 Power Reduction Registers
The power reduction (PR) registers provide a method to stop the clock to individual peripherals. When this is done, the
current state of the peripheral is frozen and the associated I/O registers cannot be read or written. Resources used by the
peripheral will remain occupied; hence, the peripheral should be disabled before stopping the clock. Enabling the clock to
a peripheral again puts the peripheral in the same state as before it was stopped. This can be used in idle mode and
active modes to reduce the overall power consumption. In all other sleep modes, the peripheral clock is already stopped.
Not all devices have all the peripherals associated with a bit in the power reduction registers. Setting a power reduction
bit for a peripheral that is not available will have no effect.
XMEGA C [MANUAL] 95
Atmel-8465H-AVR-XMEGA C-12/2014
8.6 Register Description – Sleep
Bit 7 6 5 4 3 2 1 0
+0x00 – – – – SMODE[2:0] SEN
Read/Write R R R R R/W R/W R/W R/W
Initial Value 0 0 0 0 0 0 0 0
001 – Reserved
100 – Reserved
101 – Reserved
XMEGA C [MANUAL] 96
Atmel-8465H-AVR-XMEGA C-12/2014
8.7 Register Description – Power Reduction
Bit 7 6 5 4 3 2 1 0
+0x00 – USB – AES – RTC EVSYS DMA
Read/Write R R/W R R/W R R/W R/W R/W
Initial Value 0 0 0 0 0 0 0 0
Bit 7 – Reserved
This bit is unused and reserved for future use. For compatibility with future devices, always write this bit to zero when this
register is written.
Bit 6 – USB: USB Module
Setting this bit stops the clock to the USB module. When this bit is cleared, the peripheral should be reinitialized to
ensure proper operation.
Bit 5 – Reserved
This bit is unused and reserved for future use. For compatibility with future devices, always write this bit to zero when this
register is written.
Bit 4 – AES: AES Module
Setting this bit stops the clock to the AES module. When this bit is cleared, the peripheral should be reinitialized to
ensure proper operation.
Bit 3 – Reserved
This bit is unused and reserved for future use. For compatibility with future devices, always write this bit to zero when this
register is written.
Bit 2 – RTC: Real-Time Counter
Setting this bit turns off the peripheral clock to the RTC. This means that register access, interrupt generation and event
generation is stopped, but the counter will continue to run.
Bit 1 – EVSYS: Event System
Setting this stops the clock to the event system. When this bit is cleared, the module will continue as before it was
stopped.
Bit 0 – DMA: DMA Controller
Setting this bit stops the clock to the DMA controller. This bit can be set only if the DMA controller is disabled.
Bit 7 6 5 4 3 2 1 0
+0x01/+0x02 – – – – – – ADC AC
Read/Write R R R R R R R/W R/W
Initial Value 0 0 0 0 0 0 0 0
Note: Disabling of analog modules stops the clock to the analog blocks themselves and not only the interfaces.
Bit 7:2 – Reserved
These bits are unused and reserved for future use. For compatibility with future devices, always write these bits to zero
when this register is written.
Bit 1 – ADC: Power Reduction ADC
Setting this bit stops the clock to the ADC. The ADC should be disabled before stopped.
Bit 0 – AC: Power Reduction Analog Comparator
Setting this bit stops the clock to the analog comparator. The AC should be disabled before shutdown.
XMEGA C [MANUAL] 97
Atmel-8465H-AVR-XMEGA C-12/2014
8.7.3 PRPC/D/E/F – Power Reduction Port C/D/E/F Register
Bit 7 6 5 4 3 2 1 0
+0x03/+0x04/
– TWI – USART0 SPI(1) HIRES(2) TC1(2) TC0
+0x05/+0x06
Read/Write R R/W R R/W R/W R/W R/W R/W
Initial Value 0 0 0 0 0 0 0 0
Notes: 1. Only available for PRPC and PRPD. Reserved bit for PRPE and PRPF.
2. Only available for PRPC. Reserved bit for PRPD, PRPE and PRPF.
Bit 7 – Reserved
This bit is unused and reserved for future use. For compatibility with future devices, always write this bit to zero when this
register is written.
Bit 6 – TWI: Two-Wire Interface
Setting this bit stops the clock to the two-wire interface. When this bit is cleared, the peripheral should be reinitialized to
ensure proper operation.
Bit 5 – Reserved
This bit is unused and reserved for future use. For compatibility with future devices, always write this bit to zero when this
register is written.
Bit 4 – USART0
Setting this bit stops the clock to USART0. When this bit is cleared, the peripheral should be reinitialized to ensure proper
operation.
Bit 3 – SPI: Serial Peripheral Interface
Setting this bit stops the clock to the SPI. When this bit is cleared, the peripheral should be reinitialized to ensure proper
operation.
Bit 2 – HIRES: High-Resolution Extension
Setting this bit stops the clock to the high-resolution extension for the timer/counters. When this bit is cleared, the
peripheral should be reinitialized to ensure proper operation.
Bit 1 – TC1: Timer/Counter 1
Setting this bit stops the clock to timer/counter 1. When these bit is cleared, the peripheral will continue like before the
shut down.
Bit 0 – TC0: Timer/Counter 0
Setting this bit stops the clock to timer/counter 0. When this bit is cleared, the peripheral will continue like before the shut
down.
XMEGA C [MANUAL] 98
Atmel-8465H-AVR-XMEGA C-12/2014
8.8 Register Summary – Sleep
Address Name Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0 Page
+0x00 CTRL – – – – SMODE[2:0] SEN 96
XMEGA C [MANUAL] 99
Atmel-8465H-AVR-XMEGA C-12/2014
9. Reset System
9.1 Features
Reset the microcontroller and set it to initial state when a reset source goes active
Multiple reset sources that cover different situations
Power-on reset
External reset
Watchdog reset
Brownout reset
PDI reset
Software reset
Asynchronous operation
No running system clock in the device is required for reset
Reset status register for reading the reset source from the application code
9.2 Overview
The reset system issues a microcontroller reset and sets the device to its initial state. This is for situations where
operation should not start or continue, such as when the microcontroller operates below its power supply rating. If a reset
source goes active, the device enters and is kept in reset until all reset sources have released their reset. The I/O pins
are immediately tri-stated. The program counter is set to the reset vector location, and all I/O registers are set to their
initial values. The SRAM content is kept. However, if the device accesses the SRAM when a reset occurs, the content of
the accessed location can not be guaranteed.
After reset is released from all reset sources, the default oscillator is started and calibrated before the device starts
running from the reset vector address. By default, this is the lowest program memory address, 0, but it is possible to
move the reset vector to the lowest address in the boot section.
The reset functionality is asynchronous, and so no running system clock is required to reset the device. The software
reset feature makes it possible to issue a controlled system reset from the user software.
The reset status register has individual status flags for each reset source. It is cleared at power-on reset, and shows
which sources have issued a reset since the last power-on.
An overview of the reset system is shown in Figure 9-1 on page 101.
MCU Status
Register (MCUSR)
PORF
BORF
EXTRF
WDRF
JTRF
Power-on Reset
Brown-out
BODLEVEL [2:0] Reset
Pull-up Resistor
SPIKE External
FILTER Reset
PDI
Reset
Software
Reset
Watchdog
Reset
ULP
Delay Counters
Oscillator TIMEOUT
SUT[1:0]
10 Reserved -
VPOT
VCC
VRST
RESET
tTOUT
TIME-OUT
INTERNAL
RESET
VPOT
VCC
VRST
RESET
tTOUT
TIME-OUT
INTERNAL
RESET
tBOD
VCC VBOT+
VBOT-
TIME-OUT tTOUT
INTERNAL
RESET
For BOD characterization data consult the device datasheet. The programmable BODLEVEL setting is shown in Table 9-
2.
Notes: 1. The values are nominal values only. For accurate, actual numbers, consult the device datasheet.
2. Changing these fuse bits will have no effect until leaving programming mode.
00 Reserved
01 Sampled
10 Enabled
11 Disabled
tEXT
CC
For information on configuration and use of the WDT, refer to the “WDT – Watchdog Timer” on page 107.
CC
Bit 7 6 5 4 3 2 1 0
+0x00 – – SRF PDIRF WDRF BORF EXTRF PORF
Read/Write R R R/W R/W R/W R/W R/W R/W
Initial Value - - - - - - - -
Bit 7 6 5 4 3 2 1 0
+0x01 – – – – – – – SWRST
Read/Write R R R R R R R R/W
Initial Value 0 0 0 0 0 0 0 0
10.1 Features
Issues a device reset if the timer is not reset before its timeout period
Asynchronous operation from dedicated oscillator
1kHz output of the 32kHz ultra low power oscillator
11 selectable timeout periods, from 8ms to 8s
Two operation modes:
Normal mode
Window mode
Configuration lock to prevent unwanted changes
10.2 Overview
The watchdog timer (WDT) is a system function for monitoring correct program operation. It makes it possible to recover
from error situations such as runaway or deadlocked code. The WDT is a timer, configured to a predefined timeout
period, and is constantly running when enabled. If the WDT is not reset within the timeout period, it will issue a
microcontroller reset. The WDT is reset by executing the WDR (watchdog timer reset) instruction from the application
code.
The window mode makes it possible to define a time slot or window inside the total timeout period during which WDT
must be reset. If the WDT is reset outside this window, either too early or too late, a system reset will be issued.
Compared to the normal mode, this can also catch situations where a code error causes constant WDR execution.
The WDT will run in active mode and all sleep modes, if enabled. It is asynchronous, runs from a CPU-independent clock
source, and will continue to operate to issue a system reset even if the main clocks fail.
The configuration change protection mechanism ensures that the WDT settings cannot be changed by accident. For
increased safety, a fuse for locking the WDT settings is also available.
Bit 7 6 5 4 3 2 1 0
+0x00 – – PER[3:0] ENABLE CEN
Read/Write (unlocked) R R R/W R/W R/W R/W R/W R/W
Read/Write (locked) R R R R R R R R
Initial Value (x = fuse) 0 0 X X X X X 0
1011 – Reserved
1100 – Reserved
1101 – Reserved
1110 – Reserved
1111 – Reserved
Bit 7 6 5 4 3 2 1 0
+0x01 – – WPER[3:0] WEN WCEN
Read/Write (unlocked) R R R/W R/W R/W R/W R/W R/W
Read/Write (locked) R R R R R R R/W R/W
Initial Value (x = fuse) 0 0 X X X X X 0
1011 – Reserved
1100 – Reserved
1101 – Reserved
1110 – Reserved
1111 – Reserved
Note: Reserved settings will not give any timeout for the window.
Bit 7 6 5 4 3 2 1 0
+0x02 – – – – – – – SYNCBUSY
Read/Write R R R R R R R R
Initial Value 0 0 0 0 0 0 0 0
11.1 Features
Short and predictable interrupt response time
Separate interrupt configuration and vector address for each interrupt
Programmable multilevel interrupt controller
Interrupt prioritizing according to level and vector address
Three selectable interrupt levels for all interrupts: low, medium and high
Selectable, round-robin priority scheme within low-level interrupts
Non-maskable interrupts for critical functions
Interrupt vectors optionally placed in the application section or the boot loader section
11.2 Overview
Interrupts signal a change of state in peripherals, and this can be used to alter program execution. Peripherals can have
one or more interrupts, and all are individually enabled and configured. When an interrupt is enabled and configured, it
will generate an interrupt request when the interrupt condition is present. The programmable multilevel interrupt
controller (PMIC) controls the handling and prioritizing of interrupt requests. When an interrupt request is acknowledged
by the PMIC, the program counter is set to point to the interrupt vector, and the interrupt handler can be executed.
All peripherals can select between three different priority levels for their interrupts: low, medium, and high. Interrupts are
prioritized according to their level and their interrupt vector address. Medium-level interrupts will interrupt low-level
interrupt handlers. High-level interrupts will interrupt both medium- and low-level interrupt handlers. Within each level, the
interrupt priority is decided from the interrupt vector address, where the lowest interrupt vector address has the highest
interrupt priority. Low-level interrupts have an optional round-robin scheduling scheme to ensure that all interrupts are
serviced within a certain amount of time.
Non-maskable interrupts (NMI) are also supported, and can be used for system critical functions.
11.3 Operation
Interrupts must be globally enabled for any interrupts to be generated. This is done by setting the global interrupt enable
( I ) bit in the CPU status register. The I bit will not be cleared when an interrupt is acknowledged. Each interrupt level
must also be enabled before interrupts with the corresponding level can be generated.
When an interrupt is enabled and the interrupt condition is present, the PMIC will receive the interrupt request. Based on
the interrupt level and interrupt priority of any ongoing interrupts, the interrupt is either acknowledged or kept pending
until it has priority. When the interrupt request is acknowledged, the program counter is updated to point to the interrupt
vector. The interrupt vector is normally a jump to the interrupt handler; the software routine that handles the interrupt.
After returning from the interrupt handler, program execution continues from where it was before the interrupt occurred.
One instruction is always executed before any pending interrupt is served.
The PMIC status register contains state information that ensures that the PMIC returns to the correct interrupt level when
the RETI (interrupt return) instruction is executed at the end of an interrupt handler. Returning from an interrupt will return
the PMIC to the state it had before entering the interrupt. The status register (SREG) is not saved automatically upon an
interrupt request. The RET (subroutine return) instruction cannot be used when returning from the interrupt handler
routine, as this will not return the PMIC to its correct state.
Interrupt Controller
Priority
INT LEVEL
decoder
INT LEVEL
INT LEVEL CPU
CPU INT REQ
Peripheral n
INT REQ
INT REQ
INT ACK
INT ACK Global
Interrupt
LEVEL Enable STATUS Enable Wake-up Sleep
CTRL INTPRI CPU.SREG Controller
11.4 Interrupts
All interrupts and the reset vector each have a separate program vector address in the program memory space. The
lowest address in the program memory space is the reset vector. All interrupts are assigned individual control bits for
enabling and setting the interrupt level, and this is set in the control registers for each peripheral that can generate
interrupts. Details on each interrupt are described in the peripheral where the interrupt is available.
All interrupts have an interrupt flag associated with it. When the interrupt condition is present, the interrupt flag will be set,
even if the corresponding interrupt is not enabled. For most interrupts, the interrupt flag is automatically cleared when
executing the interrupt vector. Writing a logical one to the interrupt flag will also clear the flag. Some interrupt flags are
not cleared when executing the interrupt vector, and some are cleared automatically when an associated register is
accessed (read or written). This is described for each individual interrupt flag.
If an interrupt condition occurs while another, higher priority interrupt is executing or pending, the interrupt flag will be set
and remembered until the interrupt has priority. If an interrupt condition occurs while the corresponding interrupt is not
enabled, the interrupt flag will be set and remembered until the interrupt is enabled or the flag is cleared by software.
Similarly, if one or more interrupt conditions occur while global interrupts are disabled, the corresponding interrupt flag
will be set and remembered until global interrupts are enabled. All pending interrupts are then executed according to their
order of priority.
Interrupts can be blocked when executing code from a locked section; e.g., when the boot lock bits are programmed.
This feature improves software security. Refer to “Memory Programming” on page 323 for details on lock bit settings.
Interrupts are automatically disabled for up to four CPU clock cycles when the configuration change protection register is
written with the correct signature. Refer to “Configuration Change Protection” on page 13 for more details.
If an interrupt occurs when the device is in sleep mode, the interrupt execution response time is increased by five clock
cycles. In addition, the response time is increased by the start-up time from the selected sleep mode.
A return from an interrupt handling routine takes four to five clock cycles, depending on the size of the program counter.
During these clock cycles, the program counter is popped from the stack and the stack pointer is incremented.
01 LO Low-level interrupt
11 HI High-level interrupt
The interrupt level of an interrupt request is compared against the current level and status of the interrupt controller. An
interrupt request of a higher level will interrupt any ongoing interrupt handler from a lower level interrupt. When returning
from the higher level interrupt handler, the execution of the lower level interrupt handler will continue.
:
:
:
IVEC x
IVEC x+1
:
:
:
IV EC 0 IV EC 0
: :
: :
: :
IV EC N IV EC N
1 0 0x0000 0x0002
Bit 7 6 5 4 3 2 1 0
+0x00 NMIEX – – – – HILVLEX MEDLVLEX LOLVLEX
Read/Write R R R R R R R R
Initial Value 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
+0x01 INTPRI[7:0]
Read/Write R/W R/W R/W R/W R/W R/W R/W R/W
Initial Value 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
+0x02 RREN IVSEL – – – HILVLEN MEDLVLEN LOLVLEN
Read/Write R/W R/W R R R R/W R/W R/W
Initial Value 0 0 0 0 0 0 0 0
12.1 Features
General purpose input and output pins with individual configuration
Output driver with configurable driver and pull settings:
Totem-pole
Wired-AND
Wired-OR
Bus-keeper
Inverted I/O
Input with synchronous and/or asynchronous sensing with interrupts and events
Sense both edges
Sense rising edges
Sense falling edges
Sense low level
Optional pull-up and pull-down resistor on input and Wired-OR/AND configurations
Asynchronous pin change sensing that can wake the device from all sleep modes
Two port interrupts with pin masking per I/O port
Efficient and safe access to port pins
Hardware read-modify-write through dedicated toggle/clear/set registers
Configuration of multiple pins in a single operation
Mapping of port registers into bit-accessible I/O memory space
Peripheral clocks output on port pin
Real-time counter clock output to port pin
Event channels can be output on port pin
Remapping of digital peripheral pin functions
Selectable USART, SPI, and timer/counter input/output pin locations
12.2 Overview
AVR XMEGA microcontrollers have flexible general purpose I/O ports. One port consists of up to eight port pins: pin 0 to
7. Each port pin can be configured as input or output with configurable driver and pull settings. They also implement
synchronous and asynchronous input sensing with interrupts and events for selectable pin change conditions.
Asynchronous pin-change sensing means that a pin change can wake the device from all sleep modes, included the
modes where no clocks are running.
All functions are individual and configurable per pin, but several pins can be configured in a single operation. The pins
have hardware read-modify-write (RMW) functionality for safe and correct change of drive value and/or pull resistor
configuration. The direction of one port pin can be changed without unintentionally changing the direction of any other
pin.
The port pin configuration also controls input and output selection of other device functions. It is possible to have both the
peripheral clock and the real-time clock output to a port pin, and available for external use. The same applies to events
from the event system that can be used to synchronize and control external functions. Other digital peripherals, such as
USART, SPI, and timer/counters, can be remapped to selectable pin locations in order to optimize pin-out versus
application needs.
Figure 12-1 on page 120 shows the I/O pin functionality and the registers that are available for controlling a pin.
Pull Enable
C
o Pull Keep
n
PINnCTRL
t Pull Direction
D Q r
o
l
R
L
o Input Disable
g
i Wired AND/OR
c
Inverted I/O
OUTn
Pxn
D Q
DIRn
D Q
Synchronizer
INn
Q D Q D
R R
Analog Input/Output
12.3.1 Totem-pole
In the totem-pole (push-pull) configuration, the pin is driven low or high according to the corresponding bit setting in the
OUT register. In this configuration, there is no current limitation for sink or source other than what the pin is capable of. If
the pin is configured for input, the pin will float if no external pull resistor is connected.
OUTxn Pxn
INxn
Figure 12-3. I/O Pin Configuration - Totem-pole with Pull-down (on Input)
DIRxn
OUTxn Pxn
INxn
Figure 12-4. I/O Pin Configuration - Totem-pole with Pull-up (on Input)
DIRxn
OUTxn Pxn
INxn
12.3.2 Bus-keeper
In the bus-keeper configuration, it provides a weak bus-keeper that will keep the pin at its logic level when the pin is no
longer driven to high or low. If the last level on the pin/bus was 1, the bus-keeper configuration will use the internal pull
resistor to keep the bus high. If the last logic level on the pin/bus was 0, the bus-keeper will use the internal pull resistor
to keep the bus low.
DIRxn
OUTxn Pxn
INxn
OUTxn
Pxn
INxn
12.3.4 Wired-AND
In the wired-AND configuration, the pin will be driven low when the corresponding bits in the OUT and DIR registers are
written to zero. When the OUT register is set to one, the pin is released allowing the pin to be pulled high with the internal
or an external pull-resistor. If internal pull-up is used, this is also active if the pin is set as input.
INxn
Pxn
OUTxn
PERIPHERAL CLK
SYNCHRONIZER FLIPFLOP
IN
tpd, min
EDGE
DETECT Interrupt
IRQ
Control
Synchronous sensing
Pxn
Synchronizer
INn
EDGE Synchronous
D Q D Q
DETECT Events
R R
INVERTED I/O
Asynchronous
Events
Low level Yes Pin level must be kept unchanged during wake up
Low level Yes Pin level must be kept unchanged during wake up
Rising edge No -
Falling edge No -
Any edge Yes Pin value must be kept unchanged during wake up
Low level Yes Pin level must be kept unchanged during wake up
Pull Enable
Pull Keep
C
o
Pull Direction
n
PINnCTRL t
r
D Q
o
l
R
L Digital Input Disable (DID)
o DID Override Value
g
i DID Override Enable
c
Wired AND/OR
Inverted I/O
OUTn
Pxn
D Q
DIRn
D Q
Synchronizer
INn
Q D Q D
R R
Analog Input/Output
Bit 7 6 5 4 3 2 1 0
+0x00 DIR[7:0]
Read/Write R/W R/W R/W R/W R/W R/W R/W R/W
Initial Value 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
+0x01 DIRSET[7:0]
Read/Write R/W R/W R/W R/W R/W R/W R/W R/W
Initial Value 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
+0x02 DIRCLR[7:0]
Read/Write R/W R/W R/W R/W R/W R/W R/W R/W
Initial Value 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
+0x03 DIRTGL[7:0]
Read/Write R/W R/W R/W R/W R/W R/W R/W R/W
Initial Value 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
+0x04 OUT[7:0]
Read/Write R/W R/W R/W R/W R/W R/W R/W R/W
Initial Value 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
+0x05 OUTSET[7:0]
Read/Write R/W R/W R/W R/W R/W R/W R/W R/W
Initial Value 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
+0x06 OUTCLR[7:0]
Read/Write R/W R/W R/W R/W R/W R/W R/W R/W
Initial Value 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
+0x07 OUTTGL[7:0]
Read/Write R/W R/W R/W R/W R/W R/W R/W R/W
Initial Value 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
+0x08 IN[7:0]
Read/Write R R R R R R R R
Initial Value 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
+0x09 – – – – INT1LVL[1:0] INT0LVL[1:0]
Read/Write R R R R R/W R/W R/W R/W
Initial Value 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
+0x0A INT0MSK[7:0]
Read/Write R/W R/W R/W R/W R/W R/W R/W R/W
Initial Value 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
+0x0B INT1MSK[7:0]
Read/Write R/W R/W R/W R/W R/W R/W R/W R/W
Initial Value 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
+0x0C – – – – – – INT1IF INT0IF
Read/Write R R R R R R R/W R/W
Initial Value 0 0 0 0 0 0 0 0
OC0A
OC1A
OCA
Bit 7 6 5 4 3 2 1 0
– INVEN OPC[2:0] ISC[2:0]
Read/Write R/W R/W R/W R/W R/W R/W R/W R/W
Initial Value 0 0 0 0 0 0 0 0
Bit 7 – Reserved
This bit is unused and reserved for future use. For compatibility with future devices, always write this bit to zero when this
register is written.
Bit 6 – INVEN: Inverted I/O Enable
Setting this bit will enable inverted output and input data on pin n.
Bit 5:3 – OPC: Output and Pull Configuration
These bits set the output/pull configuration on pin n according to Table 12-5.
Description
100 – Reserved
101 – Reserved
110 – Reserved
Note: 1. A low-level pin value will not generate events, and a high-level pin value will continuously generate events.
2. Only PORTA - PORTF support the input buffer disable option. If the pin is used for analog functionality, such as AC or ADC, it is recommended to
configure the pin to INPUT_DISABLE.
Bit 7 6 5 4 3 2 1 0
+0x00 MPCMASK[7:0]
Read/Write R/W R/W R/W R/W R/W R/W R/W R/W
Initial Value 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
+0x02 VP1MAP[3:0] VP0MAP[3:0]
Read/Write R/W R/W R/W R/W R/W R/W R/W R/W
Initial Value 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
+0x03 VP3MAP[3:0] VP2MAP[3:0]
Read/Write R/W R/W R/W R/W R/W R/W R/W R/W
Initial Value 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
+0x04 CLKEVPIN RTCOUT EVOUT[1:0] CLKOUTSEL[1:0] CLKOUT[1:0]
Read/Write R/W R/W R/W R/W R/W R/W R/W R/W
Initial Value 0 0 0 0 0 0 0 0
11 – (Reserved)
Bit 7 6 5 4 3 2 1 0
+0x06 – – – – – EVOUTSEL[2:0]
Read/Write R R R R R R/W R/W R/W
Initial Value 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
+0x00 DIR[7:0]
Read/Write R/W R/W R/W R/W R/W R/W R/W R/W
Initial Value 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
+0x01 OUT[7:0]
Read/Write R/W R/W R/W R/W R/W R/W R/W R/W
Initial Value 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
+0x02 IN[7:0]
Read/Write R/W R/W R/W R/W R/W R/W R/W R/W
Initial Value 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
+0x03 – – – – – – INT1IF INT0IF
Read/Write R R R R R R R/W R/W
Initial Value 0 0 0 0 0 0 0 0
13.1 Features
16-bit timer/counter
32-bit timer/counter support by cascading two timer/counters
Up to four compare or capture (CC) channels
Four CC channels for timer/counters of type 0
Two CC channels for timer/counters of type 1
Double buffered timer period setting
Double buffered capture or compare channels
Waveform generation:
Frequency generation
Single-slope pulse width modulation
Dual-slope pulse width modulation
Input capture:
Input capture with noise cancelling
Frequency capture
Pulse width capture
32-bit input capture
Timer overflow and error interrupts/events
One compare match or input capture interrupt/event per CC channel
Can be used with event system for:
Quadrature decoding
Count and direction control
Capture
Can be used with DMA and to trigger DMA transactions
High-resolution extension
Increases frequency and waveform resolution by 4x (2-bit) or 8x (3-bit)
Advanced waveform extension:
Low- and high-side output with programmable dead-time insertion (DTI)
Event controlled fault protection for safe disabling of drivers
13.2 Overview
Atmel AVR XMEGA devices have a set of flexible, 16-bit timer/counters (TC). Their capabilities include accurate program
execution timing, frequency and waveform generation, and input capture with time and frequency measurement of digital
signals. Two timer/counters can be cascaded to create a 32-bit timer/counter with optional 32-bit capture.
A timer/counter consists of a base counter and a set of compare or capture (CC) channels. The base counter can be
used to count clock cycles or events. It has direction control and period setting that can be used for timing. The CC
channels can be used together with the base counter to do compare match control, frequency generation, and pulse
width waveform modulation, as well as various input capture operations. A timer/counter can be configured for either
capture or compare functions, but cannot perform both at the same time.
A timer/counter can be clocked and timed from the peripheral clock with optional prescaling or from the event system.
The event system can also be used for direction control and capture trigger or to synchronize operations.
There are two differences between timer/counter type 0 and type 1. Timer/counter 0 has four CC channels, and
timer/counter 1 has two CC channels. All information related to CC channels 3 and 4 is valid only for timer/counter 0.
Only Timer/Counter 0 has the split mode feature that split it into 2 8-bit Timer/Counters with four compare channels each.
Some timer/counters have extensions to enable more specialized waveform and frequency generation. The advanced
waveform extension (AWeX) is intended for motor control and other power control applications. It enables low- and high-
clkPER4
Compare/Capture Channel D
Compare/Capture Channel C
AWeX
Compare/Capture Channel B
PORTS
Hi-Res
Pattern
Compare/Capture Channel A Dead-Time Generation
Capture Insertion Fault
Comparator
Control Protection
Waveform
Buffer
Generation
13.2.1 Definitions
The following definitions are used throughout the documentation:
Name Description
The counter reaches TOP when it becomes equal to the highest value in the count sequence. The TOP
TOP value can be equal to the period (PER) or the compare channel A (CCA) register setting. This is selected
by the waveform generator mode.
The timer/counter signals an update when it reaches BOTTOM or TOP, depending on the waveform
UPDATE
generator mode.
In general, the term “timer” is used when the timer/counter clock control is handled by an internal source, and the term
“counter” is used when the clock control is handled externally (e.g. counting external events). When used for compare
operations, the CC channels are referred to as “compare channels.” When used for capture operations, the CC channels
are referred to as “capture channels.”
Base Counter
Clock Select
BV PERBUF CTRLA
Event
Select
PER CTRLD
"count"
Counter
"clear"
OVF/UNF
(INT/DMA Req.)
"load"
CNT Control Logic
"direction"
ERRIF
(INT Req.)
TOP
UPDATE
=
"ev"
BOTTOM
=0
Compare/Capture
(Unit x = {A,B,C,D})
CCx
Waveform
Generation
OCx Out
"match" CCxIF
= (INT/DMA
Req.)
The counter register (CNT), period registers with buffer (PER and PERBUF), and compare and capture registers with
buffers (CCx and CCxBUF) are 16-bit registers. All buffer register have a buffer valid (BV) flag that indicates when the
buffer contains a new value.
During normal operation, the counter value is continuously compared to zero and the period (PER) value to determine
whether the counter has reached TOP or BOTTOM.
The counter value is also compared to the CCx registers. These comparisons can be used to generate interrupt
requests, request DMA transactions or generate events for the event system. The waveform generator modes use these
comparisons to set the waveform period or pulse width.
A prescaled peripheral clock and events from the event system can be used to control the counter. The event system is
also used as a source to the input capture. Combined with the quadrature decoding functionality in the event system
(QDEC), the timer/counter can be used for quadrature decoding.
Common clkPER /
clkPER
2{0,...,15}
Event System events
Prescaler
clkPER /
{1,2,4,8,64,256,1024} event channels
CKSEL
Control Logic
EVSEL
CNT
EVACT (Encoding)
The peripheral clock is fed into a common prescaler (common for all timer/counters in a device). Prescaler outputs from 1
to 1/1024 are directly available for selection by the timer/counter. In addition, the whole range of prescaling from 1 to 215
times is available through the event system.
Clock selection (CLKSEL) selects one of the prescaler outputs directly or an event channel as the counter (CNT) input.
This is referred to as normal operation of the counter. For details, refer to “Normal Operation” on page 146. By using the
event system, any event source, such as an external clock signal on any I/O pin, may be used as the clock input.
In addition, the timer/counter can be controlled via the event system. The event selection (EVSEL) and event action
(EVACT) settings are used to trigger an event action from one or more events. This is referred to as event action
controlled operation of the counter. For details, refer to “Event Action Controlled Operation” on page 146. When event
action controlled operation is used, the clock selection must be set to use an event channel as the counter input.
By default, no clock input is selected and the timer/counter is not running.
BV EN CCxBUF
EN CCx
UPDATE
CNT
"match"
=
When the CC channels are used for a capture operation, a similar double buffering mechanism is used, but in this case
the buffer valid flag is set on the capture event, as shown in Figure 13-5 on page 146. For capture, the buffer register and
"capture" CNT
BV EN CCxBUF
IF EN CCx
"INT/DMA
request" data read
Both the CCx and CCxBUF registers are available as an I/O register. This allows initialization and bypassing of the buffer
register and the double buffering function.
MAX
"update"
TOP
CNT
BOTTOM
DIR
As shown in Figure 13-6, it is possible to change the counter value when the counter is running. The write access has
higher priority than count, clear, or reload, and will be immediate. The direction of the counter can also be changed
during normal operation.
Normal operation must be used when using the counter as timer base for the capture channels.
Counter Wraparound
MAX
"update"
"write"
CNT
BOTTOM
A counter wraparound can occur in any mode of operation when up-counting without buffering, as shown in Figure 13-8.
This due to the fact that CNT and PER are continuously compared, and if a new TOP value that is lower than current
CNT is written to PER, it will wrap before a compare match happen.
MAX
"update"
"write"
CNT
BOTTOM
When double buffering is used, the buffer can be written at any time and still maintain correct operation. The period
register is always updated on the UPDATE condition, as shown for dual-slope operation in Figure 13-9 on page 148. This
prevents wraparound and the generation of odd waveforms.
MAX
"update"
"write"
CNT
BOTTOM
Event System
CCA capture
CH0MUX Event channel 0
CH1MUX Event channel 1 CCB capture
CCC capture
CHnMUX Event channel n
CCD capture
Rotate
The event action setting in the timer/counter will determine the type of capture that is done.
The CC channels must be enabled individually before capture can be done. When the capture condition occur, the
timer/counter will time-stamp the event by copying the current CNT value in the count register into the enabled CC
channel register.
When an I/O pin is used as an event source for the capture, the pin must be configured for edge sensing. For details on
sense configuration on I/O pins, refer to “Input Sense Configuration” on page 125. If the period register value is lower
than 0x8000, the polarity of the I/O pin edge will be stored in the most-significant bit (msb) of the capture register. If the
msb of the capture register is zero, a falling edge generated the capture. If the msb is one, a rising edge generated the
capture.
events
TOP
CNT
BOTTOM
Figure 13-12 shows an example where the period of an external signal is measured twice.
Period (T)
external signal
events
MAX
"capture"
CNT
BOTTOM
Since all capture channels use the same counter (CNT), only one capture channel must be enabled at a time. If two
capture channels are used with different sources, the counter will be restarted on positive edge events from both input
sources, and the result will have no meaning.
Pulsewitdh (tp)
external signal
events
MAX
"capture"
CNT
BOTTOM
MAX
"update"
TOP
CNT
BOTTOM
WG Output
fclk PER
f FRQ = ----------------------------------
2N CCA + 1
where N represents the prescaler divider used. The waveform generated will have a maximum frequency of half of the
peripheral clock frequency (fclkPER) when CCA is set to zero (0x0000) and no prescaling is used. This also applies when
using the hi-res extension, since this increases the resolution and not the frequency.
CNT
CCx
BOTTOM
WG Output
The PER register defines the PWM resolution. The minimum resolution is 2 bits (PER=0x0003), and the maximum
resolution is 16 bits (PER=MAX).
The following equation calculate the exact resolution for single-slope PWM (RPWM_SS):
log PER + 1
R PWM_SS = ---------------------------------
log 2
fclk PER
f PWM_SS = -----------------------------
N PER + 1
where N represents the prescaler divider used. The waveform generated will have a maximum frequency of half of the
peripheral clock frequency (fclkPER) when CCA is set to zero (0x0000) and no prescaling is used. This also applies when
using the hi-res extension, since this increases the resolution and not the frequency.
CCx
TOP
CNT
BOTTOM
WG Output
Using dual-slope PWM results in a lower maximum operation frequency compared to the single-slope PWM operation.
The period register (PER) defines the PWM resolution. The minimum resolution is 2 bits (PER=0x0003), and the
maximum resolution is 16 bits (PER=MAX).
The following equation calculate the exact resolution for dual-slope PWM (RPWM_DS):
log PER + 1
R PWM_DS = ---------------------------------
log 2
The PWM frequency depends on the period setting (PER) and the peripheral clock frequency (fclkPER), and can be
calculated by the following equation:
fclk PER
f PWM_DS = -------------------
2NPER
N represents the prescaler divider used. The waveform generated will have a maximum frequency of half of the
peripheral clock frequency (fclkPER) when CCA is set to zero (0x0000) and no prescaling is used. This also applies when
using the hi-res extension, since this increases the resolution and not the frequency.
OUT
OCx
Waveform
CCExEN INVEN
ERRIF N/A
Bit 7 6 5 4 3 2 1 0
+0x00 – – – – CLKSEL[3:0]
Read/Write R R R R R/W R/W R/W R/W
Initial Value 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
+0x01 CCDEN CCCEN CCBEN CCAEN – WGMODE[2:0]
Read/Write R/W R/W R/W R/W R R/W R/W R/W
Initial Value 0 0 0 0 0 0 0 0
Group Mode of
WGMODE[2:0] configuration operation Top Update OVFIF/Event
010 Reserved - - -
Single-slope
011 SINGLESLOPE PER BOTTOM BOTTOM
PWM
100 Reserved - - -
Bit 7 6 5 4 3 2 1 0
+0x02 – – – – CMPD CMPC CMPB CMPA
Read/Write R R R R R/W R/W R/W R/W
Initial Value 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
+0x03 EVACT[2:0] EVDLY EVSEL[3:0]
Read/Write R/W R/W R/W R/W R/W R/W R/W R/W
Initial Value 0 0 0 0 0 0 0 0
111 Reserved
Selecting any of the capture event actions changes the behavior of the CCx registers and related status and control bits
to be used for capture. The error status flag (ERRIF) will indicate a buffer overflow in this configuration. See “Event
Action Controlled Operation” on page 146 for further details.
Bit 4 – EVDLY: Timer Delay Event
When this bit is set, the selected event source is delayed by one peripheral clock cycle. This is intended for 32-bit input
capture operation. Adding the event delay is necessary to compensate for the carry propagation delay when cascading
two counters via the event system.
Bit 3:0 – EVSEL[3:0]:Timer Event Source Select
These bits select the event channel source for the timer/counter. For the selected event channel to have any effect, the
event action bits (EVACT) must be set according to Table 13-6. When the event action is set to a capture operation, the
selected event channel n will be the event channel source for CC channel A, and event channel (n+1)%8, (n+2)%8, and
(n+3)%8 will be the event channel source for CC channel B, C, and D.
0001 – Reserved
0010 – Reserved
0011 – Reserved
0100 – Reserved
0101 – Reserved
0110 – Reserved
0111 – Reserved
Bit 7 6 5 4 3 2 1 0
+0x04 – – – – – – BYTEM[1:0]
Read/Write R R R R R R R R/W
Initial Value 0 0 0 0 0 0 0 0
Upper byte of the counter (CNTH) will be set to zero after each counter
01 BYTEMODE
clock cycle
11 – Reserved
Bit 7 6 5 4 3 2 1 0
+0x06 – – – – ERRINTLVL[1:0] OVFINTLVL[1:0]
Read/Write R R R R R/W R/W R/W R/W
Initial Value 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
+0x07 CCDINTLVL[1:0] CCCINTLVL[1:0] CCBINTLVL[1:0] CCAINTLVL[1:0]
Read/Write R/W R/W R/W R/W R/W R/W R/W R/W
Initial Value 0 0 0 0 0 0 0 0
13.12.8.1 CTRLFCLR
Bit 7 6 5 4 3 2 1 0
+0x08 – – – – CMD[1:0] LUPD DIR
Read/Write R R R R R R R/W R/W
Initial Value 0 0 0 0 0 0 0 0
13.12.8.2 CTRLFSET
Bit 7 6 5 4 3 2 1 0
+0x09 – – – – CMD[1:0] LUPD DIR
Read/Write R R R R R/W R/W R/W R/W
Initial Value 0 0 0 0 0 0 0 0
00 NONE None
Bit 7 6 5 4 3 2 1 0
+0x0A/ +0x0B – – – CCDBV CCCBV CCBBV CCABV PERBV
Read/Write R R R R/W R/W R/W R/W R/W
Initial Value 0 0 0 0 0 0 0 0
Refer to “CTRLFCLR/CTRLFSET – Control register F Clear/Set” on page 158 for information on how to access this type
of status register.
Bit 7:5 – Reserved
These bits are unused and reserved for future use. For compatibility with future devices, always write these bits to zero
when this register is written.
Bit 4:1 – CCxBV: Compare or Capture x Buffer Valid
These bits are set when a new value is written to the corresponding CCxBUF register. These bits are automatically
cleared on an UPDATE condition.
Note that when input capture operation is used, this bit is set on a capture event and cleared if the corresponding CCxIF
is cleared.
Bit 0 – PERBV: Period Buffer Valid
This bit is set when a new value is written to the PERBUF register. This bit is automatically cleared on an UPDATE
condition.
Bit 7 6 5 4 3 2 1 0
+0x0C CCDIF CCCIF CCBIF CCAIF – – ERRIF OVFIF
Read/Write R/W R/W R/W R/W R R R/W R/W
Initial Value 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
+0x21 CNT[15:8]
Read/Write R/W R/W R/W R/W R/W R/W R/W R/W
Initial Value 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
+0x27 PER[15:8]
Read/Write R/W R/W R/W R/W R/W R/W R/W R/W
Initial Value 1 1 1 1 1 1 1 1
Bit 7 6 5 4 3 2 1 0
CCx[15:8]
Read/Write R/W R/W R/W R/W R/W R/W R/W R/W
Initial Value 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
+0x37 PERBUF[15:8]
Read/Write R/W R/W R/W R/W R/W R/W R/W R/W
Initial Value 1 1 1 1 1 1 1 1
Bit 7 6 5 4 3 2 1 0
CCxBUF[15:8]
Read/Write R/W R/W R/W R/W R/W R/W R/W R/W
Initial Value 0 0 0 0 0 0 0 0
14.1 Features
A system of two eight-bit timer/counters
Low-byte timer/counter
High-byte timer/counter
Eight compare channels
Four compare channels for the low-byte timer/counter
Four compare channels for the high-byte timer/counter
Waveform generation
Single slope pulse width modulation
Timer underflow interrupts/events
One compare match interrupt/event per compare channel for the low-byte timer/counter
Can be used with the event system for count control
Can be used to trigger DMA transactions
14.2 Overview
A timer/counter 2 is realized when a timer/counter 0 is set in split mode. It is a system of two eight-bit
timer/counters, each with four compare channels. This results in eight configurable pulse width modulation (PWM)
channels with individually controlled duty cycles, and is intended for applications that require a high number of PWM
channels.
The two eight-bit timer/counters in this system are referred to as the low-byte timer/counter and high-byte timer/counter,
respectively. The difference between them is that only the low-byte timer/counter can be used to generate compare
match interrupts, events and DMA triggers.
The two eight-bit timer/counters have a shared clock source and separate period and compare settings. They can be
clocked and timed from the peripheral clock, with optional prescaling, or from the event system. The counters are always
counting down.
The timer/counter 2 is set back to timer/counter 0 by setting it in normal mode; hence, one timer/counter can exist only as
either type 0 or type 2.
A detailed block diagram of the timer/counter 2 showing the low-byte (L) and high-byte (H) timer/counter register split and
compare modules is shown in Figure 14-1 on page 165.
Figure 14-1. Block Diagram of the 16-bit Timer/counter 0 with Split Mode
Base Counter
Clock Select
HPER LPER CTRLA
"count high"
Counter
"load high" HUNF
"count low" (INT/DMA Req.)
HCNT LCNT Control Logic
"load low"
LUNF
(INT/DMA Req.)
BOTTOML
=0
BOTTOMH
=0
Compare
(Unit x = {A,B,C,D})
LCMPx
Waveform
Generation
OCLx Out
"match" LCMPx
= (INT/DMA
Req.)
Compare
(Unit x = {A,B,C,D})
HCMPx
Waveform
Generation
OCHx Out
"match"
=
CLKSEL
CNT
CNT written
MAX
"reload"
TOP
CNT
BOTTOM
As shown in Figure 14-3, the counter can change the counter value while running. The write access has higher priority
than the count clear, and reloads and will be immediate.
MAX
"reload"
"write"
CNT
BOTTOM
CNT
CMPx
BOTTOM
WG Output
The PER register defines the PWM resolution. The minimum resolution is two bits (PER=0x0003), and the maximum
resolution is eight bits (PER=MAX).
The following equation is used to calculate the exact resolution for a single-slope PWM (RPWM_SS) waveform:
log PER + 1
R PWM_SS = ---------------------------------
log 2
The single, slow PWM frequency (fPWM_SS) depends on the period setting (PER) and the peripheral clock frequency
(fPER), and it is calculated by using the following equation:
f PER
f PWM_SS = -----------------------------
N PER + 1
where N represents the prescaler divider used (1, 2, 4, 8, 64, 256, 1024, or event channel n).
OUT
OCx
Waveform
LCMPENx / INVEN
HCMPENx
DMAC access of
CCIF{D,C,B,A} Output compare operation
LCMP{D,C,B,A}
Bit 7 6 5 4 3 2 1 0
+0x00 – – – – CLKSEL[3:0]
Read/Write R R R R R/W R/W R/W R/W
Initial Value 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
+0x01 HCMPEND HCMPENC HCMPENB HCMPENA LCMPEND LCMPENC LCMPENB LCMPENA
Read/Write R/W R/W R/W R/W R/W R/W R/W R/W
Initial Value 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
+0x02 HCMPD HCMPC HCMPB HCMPA LCMPD LCMPC LCMPB LCMPA
Read/Write R/W R/W R/W R/W R/W R/W R/W R/W
Initial Value 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
+0x04 – – – – – – BYTEM[1:0]
Read/Write R R R R R R R/W R/W
Initial Value 0 0 0 0 0 0 0 0
Upper byte of the counter (HCNT) will be set to zero after each counter
01 BYTEMODE
clock.
11 — Reserved
Bit 7 6 5 4 3 2 1 0
+0x06 – – – – HUNFINTLVL[1:0] LUNFINTLVL[1:0]
Read/Write R R R R R/W R/W R/W R/W
Initial Value 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
+0x07 LCMPDINTLVL[1:0] LCMPCINTLVL[1:0] LCMPBINTLVL[1:0] LCMPAINTLVL[1:0]
Read/Write R/W R/W R/W R/W R/W R/W R/W R/W
Initial Value 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
+0x08 – – – – CMD[1:0] CMDEN[1:0]
Read/Write R R R R R/W R/W R/W R/W
Initial Value 0 0 0 0 0 0 0 0
00 NONE None
01 — Reserved
00 – Reserved
Bit 7 6 5 4 3 2 1 0
+0x0C LCMPDIF LCMPCIF LCMPBIF LCMPAIF – – HUNFIF LUNFIF
Read/Write R/W R/W R/W R/W R R R/W R/W
Initial Value 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
+0x20 LCNT[7:0]
Read/Write R/W R/W R/W R/W R/W R/W R/W R/W
Initial Value 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
+0x21 HCNT[7:0]
Read/Write R/W R/W R/W R/W R/W R/W R/W R/W
Initial Value 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
+0x27 LPER[7:0]
Read/Write R/W R/W R/W R/W R/W R/W R/W R/W
Initial Value 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
+0x26 HPER[7:0]
Read/Write R/W R/W R/W R/W R/W R/W R/W R/W
Initial Value 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
LCMPx[7:0]
Read/Write R/W R/W R/W R/W R/W R/W R/W R/W
Initial Value 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
HCMPx[7:0]
Read/Write R/W R/W R/W R/W R/W R/W R/W R/W
Initial Value 0 0 0 0 0 0 0 0
15.1 Features
Waveform output with complementary output from each compare channel
Four dead-time insertion (DTI) units
8-bit resolution
Separate high and low side dead-time setting
Double buffered dead time
Optionally halts timer during dead-time insertion
Pattern generation unit creating synchronised bit pattern across the port pins
Double buffered pattern generation
Optional distribution of one compare channel output across the port pins
Event controlled fault protection for instant and predictable fault triggering
15.2 Overview
The advanced waveform extension (AWeX) provides extra functions to the timer/counter in waveform generation (WG)
modes. It is primarily intended for use with different types of motor control and other power control applications. It
enables low- and high side output with dead-time insertion and fault protection for disabling and shutting down external
drivers. It can also generate a synchronized bit pattern across the port pins.
Figure 15-1. Advanced Waveform Extention and Closely Related Peripherals (grey)
AWeX
Pattern
Generation
Timer/Counter 0
Px0
WG DTI
Channel A Channel A
Px1
Px2
WG DTI
Channel B Channel B
Px3
Port
Override
Px4
WG DTI
Channel C Channel C
Px5
Px6
WG DTI
Channel D Channel D
Px7
Event Fault
System Protection
As shown in Figure 15-1, each of the waveform generator outputs from timer/counter 0 are split into a complimentary pair
of outputs when any AWeX features are enabled. These output pairs go through a dead-time insertion (DTI) unit that
generates the non-inverted low side (LS) and inverted high side (HS) of the WG output with dead-time insertion between
LS and HS switching. The DTI output will override the normal port value according to the port override setting. Refer to
“I/O Ports” on page 119 for more details.
DTICCAEN
Channel
WG 0A
A
OUTOVEN1
CCBEN INVEN1
HS
Px1
OC0B
OCAHS
WG 0B OUT1
WG 0C OUT2
Px2
OC0C
OCBLS
DTI CCCEN INVEN2
LS
OUTOVEN2
DTICCBEN
Channel
WG 0B
B
OUTOVEN3
CCDEN INVEN3
HS
Px3
OC0D
OCBHS
WG 0D OUT3
WG 1A OUT4
Px4
OC1A
OCCLS
DTI CCAEN INVEN4
LS
OUTOVEN4
DTICCCEN
Channel
WG 0C
C
OUTOVEN5
CCBEN INVEN5
HS
Px5
OC1B
OCCHS
WG 1B OUT5
OUT6
Px6
OCDLS
DTI "0" INVEN6
LS
OUTOVEN6
DTICCDEN
Channel
WG 0D
D
OUTOVEN7
"0" INVEN7
HS
Px7
OCDHS
OUT7
DTLS DTHS
LOAD
Counter
EN
=0
"DTLS"
WG output D Q (To PORT)
"DTHS"
Edge Detect (To PORT)
As shown in Figure 15-4, the 8-bit dead-time counter is decremented by one for each peripheral clock cycle, until it
reaches zero. A nonzero counter value will force both the low side and high side outputs into their OFF state. When a
change is detected on the WG output, the dead-time counter is reloaded according to the edge of the input. A positive
edge initiates a counter reload of the DTLS register, and a negative edge a reload of DTHS register.
"dti_cnt"
T
tP
tDTILS tDTIHS
"WG output"
"DTLS"
"DTHS"
Timer/Counter 0 (TCx0)
UPDATE CCA WG output
1 to 8
BV DTLSBUF BV DTHSBUF Expand
EN OUTOVEN EN OUTx
Px[7:0]
As with the other timer/counter double buffered registers, the register update is synchronized to the UPDATE condition
set by the waveform generation mode. If the synchronization provided is not required by the application, the application
code can simply access the DTIOE and PORTx registers directly.
The pin directions must be set for any output from the pattern generator to be visible on the port.
Bit 7 6 5 4 3 2 1 0
+0x00 – – PGM CWCM DTICCDEN DTICCCEN DTICCBEN DTICCAEN
Read/Write R R R/W R/W R/W R/W R/W R/W
Initial Value 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
+0x02 FDEVMASK[7:0]
Read/Write R/W R/W R/W R/W R/W R/W R/W R/W
Initial Value 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
+0x03 – – – FDDBD – FDMODE FDACT[1:0]
Read/Write R R R R/W R R/W R/W R/W
Initial Value 0 0 0 0 0 0 0 0
01 – Reserved
10 – Reserved
Clear all direction (DIR) bits which correspond to the enabled DTI
11 CLEARDIR
channel(s); i.e., tri-state the outputs
Bit 7 6 5 4 3 2 1 0
+0x04 – – – – – FDF DTHSBUFV DTLSBUFV
Read/Write R R R R R R/W R/W R/W
Initial Value 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
+0x06 DTBOTH[7:0]
Read/Write R/W R/W R/W R/W R/W R/W R/W R/W
Initial Value 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
+0x07 DTBOTHBUF[7:0]
Read/Write R/W R/W R/W R/W R/W R/W R/W R/W
Initial Value 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
+0x08 DTLS[7:0]
Read/Write R/W R/W R/W R/W R/W R/W R/W R/W
Initial Value 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
+0x09 DTHS[7:0]
Read/Write R/W R/W R/W R/W R/W R/W R/W R/W
Initial Value 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
+0x0A DTLSBUF[7:0]
Read/Write R/W R/W R/W R/W R/W R/W R/W R/W
Initial Value 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
+0x0B DTHSBUF[7:0]
Read/Write R/W R/W R/W R/W R/W R/W R/W R/W
Initial Value 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
+0x0C OUTOVEN[7:0]
Read/Write R/W(1) R/W(1) R/W(1) R/W(1) R/W(1) R/W(1) R/W(1) R/W(1)
Initial Value 0 0 0 0 0 0 0 0
Note: 1. Can be written only if the fault detect flag (FDF) is zero.
Bit 7:0 – OUTOVEN[7:0]: Output Override Enable
These bits enable override of the corresponding port output register (i.e., one-to-one bit relation to pin position). The port
direction is not overridden.
16.1 Features
Increases waveform generator resolution up to 8x (3 bits)
Supports frequency, single-slope PWM, and dual-slope PWM generation
Supports the AWeX when this is used for the same timer/counter
16.2 Overview
The high-resolution (hi-res) extension can be used to increase the resolution of the waveform generation output from a
timer/counter by four or eight. It can be used for a timer/counter doing frequency, single-slope PWM, or dual-slope PWM
generation. It can also be used with the AWeX if this is used for the same timer/counter.
The hi-res extension uses the peripheral 4x clock (ClkPER4). The system clock prescalers must be configured so the
peripheral 4x clock frequency is four times higher than the peripheral and CPU clock frequency when the hi-res extension
is enabled. Refer to “System Clock Selection and Prescalers” on page 77 for more details.
PER[15:2] 0
clkPER clkPER4
CNT[15:2] 0
=0 =
BOTTOM TOP
CCxBUF[15:0]
Time /Counter
When the hi-res extension is enabled, the timer/counter must run from a non-prescaled peripheral clock. The
timer/counter will ignore its two least-significant bits (lsb) in the counter, and counts by four for each peripheral clock
cycle. Overflow/underflow and compare match of the 14 most-significant bits (msb) is done in the timer/counter. Count
and compare of the two lsb is handled and compared in the hi-res extension running from the peripheral 4x clock.
The two lsb of the timer/counter period register must be set to zero to ensure correct operation. If the count register is
read from the application code, the two lsb will always be read as zero, since the timer/counter run from the peripheral
clock. The two lsb are also ignored when generating events.
When the hi-res plus feature is enabled, the function is the same as with the hi-res extension, but the resolution will
increase by eight instead of four. This also means that the 3 lsb are handled by the hi-res extension instead of 2lsb, as
when only hi-res is enabled. The extra resolution is achieved by counting on both edges of the peripheral 4x clock.
The hi-res extension will not output any pulse shorter than one peripheral clock cycle; i.e., a compare value lower than
four will have no visible output.
Bit 7 6 5 4 3 2 1 0
+0x00 – – – – – HRPLUS HREN[1:0]
Read/Write R R R R R R/W R/W R/W
Initial Value 0 0 0 0 0 0 0 0
00 None
01 Timer/counter 0
10 Timer/counter 1
11 Both timer/counters
17.1 Features
16-bit resolution
Selectable clock source
32.768kHz external crystal
External clock
32.768kHz internal oscillator
32kHz internal ULP oscillator
Programmable 10-bit clock prescaling
One compare register
One period register
Clear counter on period overflow
Optional interrupt/event on overflow and compare match
17.2 Overview
The 16-bit real-time counter (RTC) is a counter that typically runs continuously, including in low-power sleep modes, to
keep track of time. It can wake up the device from sleep modes and/or interrupt the device at regular intervals.
The reference clock is typically the 1.024kHz output from a high-accuracy crystal of 32.768kHz, and this is the
configuration most optimized for low power consumption. The faster 32.768kHz output can be selected if the RTC needs
a resolution higher than 1ms. The RTC can also be clocked from an external clock signal, the 32.768kHz internal
oscillator or the 32kHz internal ULP oscillator.
The RTC includes a 10-bit programmable prescaler that can scale down the reference clock before it reaches the
counter. A wide range of resolutions and time-out periods can be configured. With a 32.768kHz clock source, the
maximum resolution is 30.5µs, and time-out periods can range up to 2000 seconds. With a resolution of 1s, the
maximum timeout period is more than18 hours (65536 seconds). The RTC can give a compare interrupt and/or event
when the counter equals the compare register value, and an overflow interrupt and/or event when it equals the period
register value.
External Clock
TOSC1
32.768kHz Crystal Osc
TOSC2
DIV32
RTCSRC PER
TOP/
clkRTC =
Overflow
10-bit
CNT
prescaler
”match”/
=
Compare
COMP
Bit 7 6 5 4 3 2 1 0
+0x00 – – – – – PRESCALER[2:0]
Read/Write R R R R R R/W R/W R/W
Initial Value 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
+0x01 – – – – – – – SYNCBUSY
Read/Write R R R R R R R R
Initial Value 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
+0x02 – – – – COMPINTLVL[1:0] OVFINTLVL[1:0]
Read/Write R R R R R/W R/W R/W R/W
Initial Value 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
+0x03 – – – – – – COMPIF OVFIF
Read/Write R R R R R R R/W R/W
Initial Value 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
+0x04 TEMP[7:0]
Read/Write R/W R/W R/W R/W R/W R/W R/W R/W
Initial Value 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
+0x09 CNT[15:8]
Read/Write R/W R/W R/W R/W R/W R/W R/W R/W
Initial Value 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
+0x0B PER[15:8]
Read/Write R/W R/W R/W R/W R/W R/W R/W R/W
Initial Value 1 1 1 1 1 1 1 1
Bit 7 6 5 4 3 2 1 0
+0x0D COMP[15:8]
Read/Write R/W R/W R/W R/W R/W R/W R/W R/W
Initial Value 0 0 0 0 0 0 0 0
18.1 Features
USB 2.0 full speed (12Mbps) and low speed (1.5Mbps) device compliant interface
Integrated on-chip USB transceiver, no external components needed
16 endpoint addresses with full endpoint flexibility for up to 31 endpoints
One input endpoint per endpoint address
One output endpoint per endpoint address
Endpoint address transfer type selectable to
Control transfers
Interrupt transfers
Bulk transfers
Isochronous transfers
Configurable data payload size per endpoint, up to 1023 bytes
Endpoint configuration and data buffers located in internal SRAM
Configurable location for endpoint configuration data
Configurable location for each endpoint's data buffer
Built-in direct memory access (DMA) to internal SRAM for:
Endpoint configurations
Reading and writing endpoint data
Ping-pong operation for higher throughput and double buffered operation
Input and output endpoint data buffers used in a single direction
CPU/DMA controller can update data buffer during transfer
Multipacket transfer for reduced interrupt load and software intervention
Data payload exceeding maximum packet size is transferred in one continuous transfer
No interrupts or software interaction on packet transaction level
Transaction complete FIFO for workflow management when using multiple endpoints
Tracks all completed transactions in a first-come, first-served work queue
Clock selection independent of system clock source and selection
Minimum 1.5MHz CPU clock required for low speed USB operation
Minimum 12MHz CPU clock required for full speed operation
Connection to event system
On chip debug possibilities during USB transactions
18.2 Overview
The USB module is a USB 2.0 full speed (12Mbps) and low speed (1.5Mbps) device compliant interface.
The USB supports 16 endpoint addresses. All endpoint addresses have one input and one output endpoint, for a total of
31 configurable endpoints and one control endpoint. Each endpoint address is fully configurable and can be configured
for any of the four transfer types: control, interrupt, bulk, or isochronous. The data payload size is also selectable, and it
supports data payloads up to 1023 bytes.
No dedicated memory is allocated for or included in the USB module. Internal SRAM is used to keep the configuration for
each endpoint address and the data buffer for each endpoint. The memory locations used for endpoint configurations
and data buffers are fully configurable. The amount of memory allocated is fully dynamic, according to the number of
endpoints in use and the configuration of these. The USB module has built-in direct memory access (DMA), and will
read/write data from/to the SRAM when a USB transaction takes place.
To maximize throughput, an endpoint address can be configured for ping-pong operation. When done, the input and
output endpoints are both used in the same direction. The CPU or DMA controller can then read/write one data buffer
while the USB module writes/reads the others, and vice versa. This gives double buffered communication.
Figure 18-1. USB OUT Transfer: Data Packet from Host to USB Device
HOST
Internal SRAM
ENDPOINT 2 DATA
time
Figure 18-2. USB IN Transfer: Data Packet from USB Device to Host after Request from Host
Internal SRAM
CPU
HOST
18.3 Operation
This section gives an overview of the USB module operation during normal transactions. For general details on USB and
the USB protocol, refer to http://www.usb.org and the USB specification documents.
18.3.2 SETUP
When a SETUP token is detected, the USB module fetches the endpoint control register (CTRL) from the addressed
output endpoint in the endpoint configuration table. If the endpoint type is not set to control, the USB module returns to
idle and waits for the next token packet.
No No No No
No No
STORE UPDATE
DATA STATUS
The USB module then fetches the endpoint data pointer register (DATAPTR) and waits for a DATA0 packet. If a PID
error or any other PID than DATA0 is detected, the USB module returns to idle and waits for the next token packet.
The incoming data are written to the data buffer pointed to by DATAPTR. If a bit-stuff error is detected in the incoming
data, the USB module returns to idle and waits for the next token packet. If the number of received data bytes exceeds
the endpoint's maximum data payload size, as specified by the data size (SIZE) in the endpoint CTRL register, the
remaining received data bytes are discarded. The packet will still be checked for bit-stuff and CRC errors. Software must
never report a maximum data payload size to the host that is greater than specified in SIZE. If there was a bit-stuff or
CRC error in the packet, the USB module returns to idle and waits for the next token packet.
If data was successfully received, an ACK handshake is returned to the host, and the number of received data bytes,
excluding the CRC, is written to the endpoint byte counter (CNT). If the number of received data bytes is the maximum
data payload specified by SIZE, no CRC data are written in the data buffer. If the number of received data bytes is the
maximum data payload specified by SIZE minus one, only the first CRC data byte is written in the data buffer. If the
number of received data bytes is equal or less than the data byte payload specified by SIZE minus two, the two CRC
data bytes are written in the data buffer.
Finally, the setup transaction complete flag (SETUP), data buffer 0 not acknowledge flag (NACK0), and data toggle flag
(TOGGLE) are set, while the remaining flags in the endpoint status register (STATUS) are cleared for the addressed
input and output endpoints. The setup transaction complete interrupt flag (SETUPIF) in INTFLAGSBCLR/SET is set. The
STALL flag in the endpoint CTRL register is cleared for the addressed input and output endpoints.
When a SETUP token is detected and the device address of the token packet does not match that of the endpoint, the
packet is discarded, and the USB module returns to idle and waits for the next token packet.
18.3.3 OUT
When an OUT token is detected, the USB module fetches the endpoint CTRL and STATUS register data from the
addressed output endpoint in its endpoint configuration table. If the endpoint is disabled, the USB module returns to idle
and waits for the next token packet.
No No No No
Yes
No No
Yes No
No Yes
BUSNACK0 Yes
NAK
SET?
No
No No
STORE
DATA
The USB module then fetches the endpoint DATAPTR register and waits for a DATA0 or DATA1 packet. If a PID error or
any other PID than DATA0 or DATA1 is detected, the USB module returns to idle and waits for the next token packet.
If the STALL flag in the endpoint CTRL register is set, the incoming data are discarded. If the endpoint is not
isochronous, and the bit stuffing and CRC of the received data are OK, a STALL handshake is returned to the host, and
the STALL interrupt flag is set.
For isochronous endpoints, data from both a DATA0 and DATA1 packet will be accepted. For other endpoint types, the
PID is checked against TOGGLE. If they don't match, the incoming data are discarded and a NAK handshake is returned
to the host. If BUSNACK0 is set, the incoming data are discarded. The overflow flag (OVF) in the endpoint STATUS
register and the overflow interrupt flag (OVFIF) in the INTFLAGSASET/CLR register are set. If the endpoint is not
isochronous, a NAK handshake is returned to the host.
The incoming data are written to the data buffer pointed to by DATAPTR. If a bit-stuff error is detected in the incoming
data, the USB module returns to idle and waits for the next token packet. If the number of received data bytes exceeds
the maximum data payload specified by SIZE, the remaining received data bytes are discarded. The packet will still be
checked for bit-stuff and CRC errors. If there was a bit-stuff or CRC error in the packet, the USB module returns to idle
and waits for the next token packet.
If the endpoint is isochronous and there was a bit-stuff or CRC error in the incoming data, the number of received data
bytes, excluding CRC, is written to the endpoint CNT register. Finally, CRC and BUSNACK0 in the endpoint and
STATUS and CRCIF in INTFLAGSASET/CLR are set.
If data was successfully received, an ACK handshake is returned to the host if the endpoint is not isochronous, and the
number of received data bytes, excluding CRC, is written to CNT. If the number of received data bytes is the maximum
data payload specified by SIZE no CRC data are written in the data buffer. If the number of received data bytes is the
maximum data payload specified by SIZE minus one, only the first CRC data byte is written in the data buffer If the
number of received data bytes is equal or less than the data payload specified by SIZE minus two, the two CRC data
bytes are written in the data buffer.
Finally, the transaction complete flag (TRNCOMPL0) and BUSNACK0 are set and TOGGLE is toggled if the endpoint is
not isochronous. The transaction complete interrupt flag (TRNIF) in INTFLAGSBCLR/SET is set. The endpoint's
configuration table address is written to the FIFO if the transaction complete FIFO mode is enabled.
18.3.4 IN
If an IN token is detected the, the USB module fetches the endpoint CTRL and STATUS register data from the addressed
input endpoint in the endpoint configuration table. If the endpoint is disabled, the USB module returns to idle and waits for
the next token packet.
If the STALL flag in endpoint CTRL register is set, and the endpoint is not isochronous, a STALL handshake is returned
to the host, the STALL flag in the endpoint STATUS register and the STALL interrupt flag (STALLIF) in
INTFLAGSACLR/SET are set.
If BUSNACK0 is set, OVF in the endpoint STATUS register and OVFIF in the INTFLAGSACLR/SET register are set. If
the endpoint is not isochronous, a NAK handshake is returned to the host.
The data in the data buffer pointed to by the endpoint DATAPTR register are sent to the host in a DATA0 packet if the
endpoint is isochronous; otherwise, a DATA0 or DATA1 packet according to TOGGLE is sent. When the number of data
bytes specified in endpoint CNT is sent, the CRC is appended and sent to the host. If not, a ZLP handshake is returned
to the host.
For isochronous endpoints, BUSNACK0 and TRNCOMPL0 in the endpoint STATUS register are set. TRNIF is set, and
the endpoint's configuration table address is written to the FIFO if the transaction complete FIFO mode is enabled.
For all non-isochronous endpoints, the USB module waits for an ACK handshake from the host. If an ACK handshake is
not received within 16 USB clock cycles, the USB module returns to idle and waits for the next token packet. If an ACK
handshake was successfully received, BUSNACK0 and TRNCOMPL0 are set and TOGGLE is toggled. TRNIF is set and
the endpoint's configuration table address is written to the FIFO if the transaction complete FIFO mode is enabled.
When an IN token is detected and the device address of the token packet does not match that of the endpoint, the packet
is discarded and the USB module returns to idle and waits for the next token packet.
No No No
No
BUSNACK0 Yes No
ISO? NAK
SET?
No Yes
ZLP
No
Yes Yes
STATUS
CTRL
CNTL
ENDPOINT
CNTH
MAXEP IN
DATAPTRL
DATAPTRH
AUXDATAL
EPPTR + AUXDATAH
2 Bytes
(MAXEP+1)*16 FRAME (MAXEP+1)<<4 FRAMENUML
Active when
NUMBER FRAMENUMH
STFRNUM==1
SRAM
ADDRESS
USBSRC
USBPSDIV
Without Ping-Pong t
Endpoint
Double bank
With Ping-Pong
t Bank0
Bank1
USB data packet
Without multipacket
With multipacket
INTERNAL SRAM
EPPTR–
4x( MAXEP+1) TC_ EP_ ADDRH_ MAX
USB_ TC_ FIFO
SRAM
ADDRESS
To manage the FIFO, a five-bit write pointer (FIFOWP) and five-bit read pointer (FIFORP) are used by the USB module
and application software, respectively. FIFORP and FIFOWP are one's complemented, and thus hold negative values.
The SRAM location of the data is the sum of EPPTR and the read or write pointer. The number of items in the FIFO is the
difference between FIFOWP and FIFORP. For the programmer, the FIFORP and FIFOWP values have to be cast to a
signed 8-bit integer, and then the offset into the FIFO from this signed integer must be deducted.
The transaction complete interrupt flag (TRNIF) in the INFLAGSB[CLR,SET] register is set to indicate a non-empty FIFO
when FIFORP != FIFOWP, cleared when they are equal, and also set when the FIFO is full.
Each time an endpoint IN or OUT transaction completes successfully, its endpoint configuration table address is stored in
the FIFO at the current write pointer position (i.e., EPPTR + 2 × FIFOWP) and FIFOWP is decremented. When the
pointer reaches the FIFO size, it wraps to zero. When application software reads FIFORP, this is decremented in the
same way. Reading the write pointer has no effect. The endpoint configuration table address can then be read directly
from (EPPTR + 2 × FIFORP).
Ep X EpY Ep Z t
SOFIF
SUSPENDIF SOFIE
RESUMEIF
RSTIF
BSEVIE Busevent
Interrupt request
CRCIF
UNFIF
OVFIF
BUSSERRIE
STALLIF
STALLIE
SETUPIF
SETUPIE
Transaction Complete
Interrupt request
TRNIF
TRNIE
18.10.3 Events
The USB module can generate several events, and these are available to the event system, allowing latency-free
signaling to other peripherals or performance analysis of USB operation.
SETUP SETUPIF
Bit 7 6 5 4 3 2 1 0
+0x00 ENABLE SPEED FIFOEN STFRNUM MAXEP[3:0]
Read/Write R/W R/W R/W R/W R/W R/W R/W R/W
Initial Value 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
+0x01 – – – PULLRST – RWAKEUP GNACK ATTACH
Read/Write R R R R/W R R/W R/W R/W
Initial Value 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
+0x02 – – – – URESUME RESUME SUSPEND BUSRST
Read/Write R R R R R R R R
Initial Value 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
+0x03 – ADDR[6:0]
Read/Write R R/W R/W R/W R/W R/W R/W R/W
Initial Value 0 0 0 0 0 0 0 0
Bit 7 – Reserved
This bit is unused and reserved for future use. For compatibility with future devices, always write this bit to zero when this
register is written.
Bit 6:0 – ADDR[6:0]: Device Address
These bits contain the USB address the device will respond to.
Bit 7 6 5 4 3 2 1 0
+0x04 – – – FIFOWP[4:0]
Read/Write R R R R/W R/W R/W R/W R/W
Initial Value 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
+0x05 – – – FIFORP[4:0]
Read/Write R R R R/W R/W R/W R/W R/W
Initial Value 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
+0x07 EPPTR[15:8]
Read/Write R/W R/W R/W R/W R/W R/W R/W R/W
Initial Value 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
+0x06 SOFIE BUSEVIE BUSERRIE STALLIE – – INTLVL[1:0]
Read/Write R/W R/W R/W R/W R R R/W R/W
Initial Value 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
+0x07 – – – – – – TRNIE SETUPIE
Read/Write R R R R R R R/W R/W
Initial Value 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
STALL SETUP
+0x00 (1)
UNF/ OVF TRNCOMPL0 BANK BUSNACK1 BUSNACK0 TOGGLE
CRC TRNCOMPL1
Read/Write R/W R/W R/W R/W R/W R/W R/W R/W
Initial Value 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
STALL SIZE[1:0]
+0x01 TYPE[1:0] MULTIPKT PINGPONG INTDSBL
SIZE[2:0](1)
Read/Write R/W R/W R/W R/W R/W R/W R/W R/W
Initial Value 0 0 0 0 0 0 0 0
01 CONTROL Control
10 BULK Bulk/interrupt
11 ISOCHRONOUS Isochronous
Bit 7 6 5 4 3 2 1 0
+0x03 AZLP – – – – – CNT[9:8]
Read/Write R/W R R R R R R/W R/W
Initial Value X X X X X X X X
Bit 7 6 5 4 3 2 1 0
+0x05 DATAPTR[15:8]
Read/Write R/W R/W R/W R/W R/W R/W R/W R/W
Initial Value X X X X X X X X
Bit 7 6 5 4 3 2 1 0
+0x07 AUXDATA[15:8]
Read/Write R/W R/W R/W R/W R/W R/W R/W R/W
Initial Value X X X X X X X X
Bit 7 6 5 4 3 2 1 0
+0x01 FRAMEERR – – – – FRAMENUM[10:8]
Read/Write R R R R R R R R
Initial Value 0 0 0 0 0 0 0 0
0x00 BUSEVENT_vect SOF, suspend, resume, bus reset, CRC, underflow, overflow, and stall error interrupts
19.1 Features
Bidirectional, two-wire communication interface
Phillips I2C compatible
System Management Bus (SMBus) compatible
Bus master and slave operation supported
Slave operation
Single bus master operation
Bus master in multi-master bus environment
Multi-master arbitration
Flexible slave address match functions
7-bit and general call address recognition in hardware
10-bit addressing supported
Address mask register for dual address match or address range masking
Optional software address recognition for unlimited number of addresses
Slave can operate in all sleep modes, including power-down
Slave address match can wake device from all sleep modes
100kHz and 400kHz bus frequency support
Slew-rate limited output drivers
Input filter for bus noise and spike suppression
Support arbitration between start/repeated start and data bit (SMBus)
Slave arbitration allows support for address resolve protocol (ARP) (SMBus)
19.2 Overview
The two-wire interface (TWI) is a bidirectional, two-wire communication interface. It is I2C and System Management Bus
(SMBus) compatible. The only external hardware needed to implement the bus is one pull-up resistor on each bus line.
A device connected to the bus must act as a master or a slave. The master initiates a data transaction by addressing a
slave on the bus and telling whether it wants to transmit or receive data. One bus can have many slaves and one or
several masters that can take control of the bus. An arbitration process handles priority if more than one master tries to
transmit data at the same time. Mechanisms for resolving bus contention are inherent in the protocol.
The TWI module supports master and slave functionality. The master and slave functionality are separated from each
other, and can be enabled and configured separately. The master module supports multi-master bus operation and
arbitration. It contains the baud rate generator. Both 100kHz and 400kHz bus frequency is supported. Quick command
and smart mode can be enabled to auto-trigger operations and reduce software complexity.
The slave module implements 7-bit address match and general address call recognition in hardware. 10-bit addressing is
also supported. A dedicated address mask register can act as a second address match register or as a register for
address range masking. The slave continues to operate in all sleep modes, including power-down mode. This enables
the slave to wake up the device from all sleep modes on TWI address match. It is possible to disable the address
matching to let this be handled in software instead.
The TWI module will detect START and STOP conditions, bus collisions, and bus errors. Arbitration lost, errors, collision,
and clock hold on the bus are also detected and indicated in separate status flags available in both master and slave
modes.
It is possible to disable the TWI drivers in the device, and enable a four-wire digital interface for connecting to an external
TWI bus driver. This can be used for applications where the device operates from a different VCC voltage than used by
the TWI bus.
VCC
RS RS RS RS RS RS
SDA
SCL
Note: RS is optional
A unique address is assigned to all slave devices connected to the bus, and the master will use this to address a slave
and initiate a data transaction.
Several masters can be connected to the same bus, called a multi-master environment. An arbitration mechanism is
provided for resolving bus ownership among masters, since only one master device may own the bus at any given time.
A device can contain both master and slave logic, and can emulate multiple slave devices by responding to more than
one address.
A master indicates the start of a transaction by issuing a START condition (S) on the bus. An address packet with a slave
address (ADDRESS) and an indication whether the master wishes to read or write data (R/W) are then sent. After all
data packets (DATA) are transferred, the master issues a STOP condition (P) on the bus to end the transaction. The
receiver must acknowledge (A) or not-acknowledge (A) each byte received.
Figure 19-2 on page 218 shows a TWI transaction.
SDA
Direction
Transaction
The master provides the clock signal for the transaction, but a device connected to the bus is allowed to stretch the low-
level period of the clock to decrease the clock speed.
SDA
SCL
S P
START STOP
Condition Condition
Multiple START conditions can be issued during a single transaction. A START condition that is not directly following a
STOP condition is called a repeated START condition (Sr).
SDA
SCL
DATA Change
Valid Allowed
Combining bit transfers results in the formation of address and data packets. These packets consist of eight data bits
(one byte) with the most-significant bit transferred first, plus a single-bit not-acknowledge (NACK) or acknowledge (ACK)
response. The addressed device signals ACK by pulling the SCL line low during the ninth clock cycle, and signals NACK
by leaving the line SCL high.
19.3.6 Transaction
A transaction is the complete transfer from a START to a STOP condition, including any repeated START conditions in
between. The TWI standard defines three fundamental transaction modes: Master write, master read, and a combined
transaction.
Figure 19-5 illustrates the master write transaction. The master initiates the transaction by issuing a START condition (S)
followed by an address packet with the direction bit set to zero (ADDRESS+W).
Transaction
Address Packet Data Packet
N data packets
Assuming the slave acknowledges the address, the master can start transmitting data (DATA) and the slave will ACK or
NACK (A/A) each byte. If no data packets are to be transmitted, the master terminates the transaction by issuing a STOP
condition (P) directly after the address packet. There are no limitations to the number of data packets that can be
Transaction
Address Packet Data Packet
N data packets
Assuming the slave acknowledges the address, the master can start receiving data from the slave. There are no
limitations to the number of data packets that can be transferred. The slave transmits the data while the master signals
ACK or NACK after each data byte. The master terminates the transfer with a NACK before issuing a STOP condition.
Figure 19-7 illustrates a combined transaction. A combined transaction consists of several read and write transactions
separated by repeated START conditions (Sr).
Transaction
Address Packet #1 N Data Packets Address Packet #2 M Data Packets
Direction Direction
SCL
S
Note: 1. Clock stretching is not supported by all I2C slaves and masters.
If a slave device is in sleep mode and a START condition is detected, the clock stretching normally works during the
wake-up period. For AVR XMEGA devices, the clock stretching will be either directly before or after the ACK/NACK bit,
as AVR XMEGA devices do not need to wake up for transactions that are not addressed to it.
A slave device can slow down the bus frequency by stretching the clock periodically on a bit level. This allows the slave
to run at a lower system clock frequency. However, the overall performance of the bus will be reduced accordingly. Both
19.3.8 Arbitration
A master can start a bus transaction only if it has detected that the bus is idle. As the TWI bus is a multi-master bus, it is
possible that two devices may initiate a transaction at the same time. This results in multiple masters owning the bus
simultaneously. This is solved using an arbitration scheme where the master loses control of the bus if it is not able to
transmit a high level on the SDA line. The masters who lose arbitration must then wait until the bus becomes idle (i.e.,
wait for a STOP condition) before attempting to reacquire bus ownership. Slave devices are not involved in the arbitration
procedure.
DEVICE1_SDA
DEVICE2_SDA
SDA
bit 7 bit 6 bit 5 bit 4
(wired-AND)
SCL
S
Figure 19-9 shows an example where two TWI masters are contending for bus ownership. Both devices are able to issue
a START condition, but DEVICE1 loses arbitration when attempting to transmit a high level (bit 5) while DEVICE2 is
transmitting a low level.
Arbitration between a repeated START condition and a data bit, a STOP condition and a data bit, or a repeated START
condition and a STOP condition are not allowed and will require special handling by software.
19.3.9 Synchronization
A clock synchronization algorithm is necessary for solving situations where more than one master is trying to control the
SCL line at the same time. The algorithm is based on the same principles used for the clock stretching previously
described. Figure 19-10 on page 222 shows an example where two masters are competing for control over the bus clock.
The SCL line is the wired-AND result of the two masters clock outputs.
DEVICE1_SCL
DEVICE2_SCL
SCL
(wired-AND)
A high-to-low transition on the SCL line will force the line low for all masters on the bus, and they will start timing their low
clock period. The timing length of the low clock period can vary among the masters. When a master (DEVICE1 in this
case) has completed its low period, it releases the SCL line. However, the SCL line will not go high until all masters have
released it. Consequently, the SCL line will be held low by the device with the longest low period (DEVICE2). Devices
with shorter low periods must insert a wait state until the clock is released. All masters start their high period when the
SCL line is released by all devices and has gone high. The device which first completes its high period (DEVICE1) forces
the clock line low, and the procedure is then repeated. The result is that the device with the shortest clock period
determines the high period, while the low period of the clock is determined by the device with the longest clock period.
RESET
UNKNOWN
(0b00)
P + Timeout
S
Sr
IDLE BUSY
(0b01) P + Timeout (0b11)
Command P
Arbitration
Write ADDRESS Lost
(S) OWNER
(0b10)
Write
ADDRESS(Sr)
After a system reset and/or TWI master enable, the bus state is unknown. The bus state machine can be forced to enter
idle by writing to the bus state bits accordingly. If no state is set by application software, the bus state will become idle
when the first STOP condition is detected. If the master inactive bus timeout is enabled, the bus state will change to idle
on the occurrence of a timeout. After a known bus state is established, only a system reset or disabling of the TWI master
will set the state to unknown.
When the bus is idle, it is ready for a new transaction. If a START condition generated externally is detected, the bus
becomes busy until a STOP condition is detected. The STOP condition will change the bus state to idle. If the master
inactive bus timeout is enabled, the bus state will change from busy to idle on the occurrence of a timeout.
If a START condition is generated internally while in idle state, the owner state is entered. If the complete transaction was
performed without interference, i.e., no collisions are detected, the master will issue a STOP condition and the bus state
will change back to idle. If a collision is detected, the arbitration is assumed lost and the bus state becomes busy until a
STOP condition is detected. A repeated START condition will only change the bus state if arbitration is lost during the
issuing of the repeated START. Arbitration during repeated START can be lost only if the arbitration has been ongoing
since the first START condition. This happens if two masters send the exact same ADDRESS+DATA before one of the
masters issues a repeated START (Sr).
M1 M2 M3 M4
Wait for
SW
IDLE
R/W A SW P IDLE M2
W A SW Sr M3 BUSY M4
SW DATA A/A
SW Driver software
MASTER READ INTERRUPT + HOLD
The master provides data
on the bus
A/A Sr M3
Mn Diagram connections
A/A
R A DATA
The number of interrupts generated is kept to a minimum by automatic handling of most conditions. Quick command and
smart mode can be enabled to auto-trigger operations and reduce software complexity.
19.5.1.1 Case M1: Arbitration lost or bus error during address packet
If arbitration is lost during the sending of the address packet, the master write interrupt flag and arbitration lost flag are
both set. Serial data output to the SDA line is disabled, and the SCL line is released. The master is no longer allowed to
perform any operation on the bus until the bus state has changed back to idle.
A bus error will behave in the same way as an arbitration lost condition, but the error flag is set in addition to the write
interrupt and arbitration lost flags.
19.5.1.2 Case M2: Address packet transmit complete - Address not acknowledged by slave
If no slave device responds to the address, the master write interrupt flag and the master received acknowledge flag are
set. The clock hold is active at this point, preventing further activity on the bus.
19.5.1.3 Case M3: Address packet transmit complete - Direction bit cleared
If the master receives an ACK from the slave, the master write interrupt flag is set and the master received acknowledge
flag is cleared. The clock hold is active at this point, preventing further activity on the bus.
P S2
S1 S3 A S1 Sr S3
P S2
A S1 Sr S3
SW Driver software
W SW A/A DATA SW A/A
The master provides data
on the bus
Interrupt on STOP
SW
Condition Enabled
Slave provides data on
the bus Collision Release
(SMBus)
SW
Hold S1
Sn Diagram connections
The number of interrupts generated is kept to a minimum by automatic handling of most conditions. Quick command can
be enabled to auto-trigger operations and reduce software complexity.
Promiscuous mode can be enabled to allow the slave to respond to all received addresses.
Bit 7 6 5 4 3 2 1 0
+0x00 – – – – – SDAHOLD[1:0] EDIEN
Read/Write R R R R R R/W R/W R/W
Initial Value 0 0 0 0 0 0 0 0
0 Normal TWI Two-pin interface, slew rate control, and input filter.
Bit 7 6 5 4 3 2 1 0
+0x00 INTLVL[1:0] RIEN WIEN ENABLE – – –
Read/Write R/W R/W R/W R/W R/W R R R
Initial Value 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
+0x01 – – – – TIMEOUT[1:0] QCEN SMEN
Read/Write R R R R R/W R/W R/W R/W
Initial Value 0 0 0 0 0 0 0 0
10 100US 100µs
11 200US 200µs
Bit 7 6 5 4 3 2 1 0
+0x02 – – – – – ACKACT CMD[1:0]
Read/Write R R R R R R/W R/W R/W
Initial Value 0 0 0 0 0 0 0 0
ACKACT Action
0 Send ACK
1 Send NACK
00 NOACT X Reserved
W No operation
10 BYTEREC Execute acknowledge action succeeded by a byte
R
receive
Writing a command to the CMD bits will clear the master interrupt flags and the CLKHOLD flag.
Bit 7 6 5 4 3 2 1 0
+0x03 RIF WIF CLKHOLD RXACK ARBLOST BUSERR BUSSTATE[1:0]
Read/Write R/W R/W R R R/W R/W R/W R/W
Initial Value 0 0 0 0 0 0 0 0
Writing 01 to the BUSSTATE bits forces the bus state logic into the idle state. The bus state logic cannot be forced into
any other state. When the master is disabled, and after reset, the bus state logic is disabled and the bus state is
unknown.
Bit 7 6 5 4 3 2 1 0
+0x04 BAUD[7:0]
Read/Write R/W R/W R/W R/W R/W R/W R/W R/W
Initial Value 0 0 0 0 0 0 0 0
The baud rate (BAUD) register defines the relation between the system clock and the TWI bus clock (SCL) frequency.
The frequency relation can be expressed by using the following equation:
f sys
f TWI = --------------------------------------- [Hz] [1]
2(5 + BAUD )
The BAUD register must be set to a value that results in a TWI bus clock frequency (fTWI) equal or less than 100kHz or
400kHz, depending on which standard the application should comply with. The following equation [2] expresses equation
[1] solved for the BAUD value:
f sys
BAUD = -------------- – 5 [2]
2f TWI
The BAUD register should be written only while the master is disabled.
Bit 7 6 5 4 3 2 1 0
+0x05 ADDR[7:0]
Read/Write R/W R/W R/W R/W R/W R/W R/W R/W
Initial Value 0 0 0 0 0 0 0 0
When the address (ADDR) register is written with a slave address and the R/W bit while the bus is idle, a START
condition is issued and the 7-bit slave address and the R/W bit are transmitted on the bus. If the bus is already owned
when ADDR is written, a repeated START is issued. If the previous transaction was a master read and no acknowledge
is sent yet, the acknowledge action is sent before the repeated START condition.
After completing the operation and the acknowledge bit from the slave is received, the SCL line is forced low if arbitration
was not lost. WIF is set.
If the bus state is unknown when ADDR is written, WIF is set and BUSERR is set.
Bit 7 6 5 4 3 2 1 0
+0x06 DATA[7:0]
Read/Write R/W R/W R/W R/W R/W R/W R/W R/W
Initial Value 0 0 0 0 0 0 0 0
The data (DATA) register is used when transmitting and receiving data. During data transfer, data are shifted from/to the
DATA register and to/from the bus. This implies that the DATA register cannot be accessed during byte transfers, and
this is prevented by hardware. The DATA register can only be accessed when the SCL line is held low by the master; i.e.,
when CLKHOLD is set.
In master write mode, writing the DATA register will trigger a data byte transfer followed by the master receiving the
acknowledge bit from the slave. WIF and CLKHOLD are set.
In master read mode, RIF and CLKHOLD are set when one byte is received in the DATA register. If smart mode is
enabled, reading the DATA register will trigger the bus operation as set by the ACKACT bit. If a bus error occurs during
reception, WIF and BUSERR are set instead of RIF.
Accessing the DATA register will clear the master interrupt flags and CLKHOLD.
Bit 7 6 5 4 3 2 1 0
+0x00 INTLVL[1:0] DIEN APIEN ENABLE PIEN PMEN SMEN
Read/Write R/W R/W R/W R/W R/W R/W R/W R/W
Initial Value 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
+0x01 – – – – – ACKACT CMD[1:0]
Read/Write R R R R R R/W R/W R/W
Initial Value 0 0 0 0 0 0 0 0
ACKACT Action
0 Send ACK
1 Send NACK
00 NOACT X No action
01 X Reserved
1 No operation
Bit 7 6 5 4 3 2 1 0
+0x02 DIF APIF CLKHOLD RXACK COLL BUSERR DIR AP
Read/Write R/W R/W R R R/W R/W R/W R/W
Initial Value 0 0 0 0 0 0 0 0
AP Description
Bit 7 6 5 4 3 2 1 0
+0x04 DATA[7:0]
Read/Write R/W R/W R/W R/W R/W R/W R/W R/W
Initial Value 0 0 0 0 0 0 0 0
The data (DATA) register is used when transmitting and received data. During data transfer, data are shifted from/to the
DATA register and to/from the bus. This implies that the DATA register cannot be accessed during byte transfers, and
this is prevented by hardware. The DATA register can be accessed only when the SCL line is held low by the slave; i.e.,
when CLKHOLD is set.
When a master is reading data from the slave, data to send must be written to the DATA register. The byte transfer is
started when the master starts to clock the data byte from the slave, followed by the slave receiving the acknowledge bit
from the master. DIF and CLKHOLD are set.
When a master writes data to the slave, DIF and CLKHOLD are set when one byte has been received in the DATA
register. If smart mode is enabled, reading the DATA register will trigger the bus operation as set by the ACKACT bit.
Accessing the DATA register will clear the slave interrupt flags and CLKHOLD. When an address match occurs, the
received address will be stored in the DATA register.
Bit 7 6 5 4 3 2 1 0
+0x05 ADDRMASK[7:1] ADDREN
Read/Write R/W R/W R/W R/W R/W R/W R/W R/W
Initial Value 0 0 0 0 0 0 0 0
20.1 Features
Full-duplex, three-wire synchronous data transfer
Master or slave operation
Lsb first or msb first data transfer
Eight programmable bit rates
Interrupt flag at the end of transmission
Write collision flag to indicate data collision
Wake up from idle sleep mode
Double speed master mode
20.2 Overview
The Serial Peripheral Interface (SPI) is a high-speed synchronous data transfer interface using three or four pins. It
allows fast communication between an XMEGA device and peripheral devices or between several microcontrollers. The
SPI supports full-duplex communication.
A device connected to the bus must act as a master or slave.The master initiates and controls all data transactions. The
interconnection between master and slave devices with SPI is shown in Figure 20-1. The system consists of two shift
registers and a master clock generator. The SPI master initiates the communication cycle by pulling the slave select (SS)
signal low for the desired slave. Master and slave prepare the data to be sent in their respective shift registers, and the
master generates the required clock pulses on the SCK line to interchange data. Data are always shifted from master to
slave on the master output, slave input (MOSI) line, and from slave to master on the master input, slave output (MISO)
line. After each data packet, the master can synchronize the slave by pulling the SS line high.
SHIFT
ENABLE
The SPI module is unbuffered in the transmit direction and single buffered in the receive direction. This means that bytes
to be transmitted cannot be written to the SPI DATA register before the entire shift cycle is completed. When receiving
data, a received character must be read from the DATA register before the next character has been completely shifted in.
Otherwise, the first byte will be lost.
In SPI slave mode, the control logic will sample the incoming signal on the SCK pin. To ensure correct sampling of this
clock signal, the minimum low and high periods must each be longer than two CPU clock cycles.
When the SPI module is enabled, the data direction of the MOSI, MISO, SCK, and SS pins is overridden according to
Table 20-1 on page 239. The pins with user-defined direction must be configured from software to have the correct
direction according to the application.
Mode 0
Mode 2
SAMPLE I
MOSI/MISO
CHANGE 0
MOSI PIN
CHANGE 0
MISO PIN
SS
MSB first (DORD = 0) MSB Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 LSB
LSB first (DORD = 1) LSB Bit 1 Bit 2 Bit 3 Bit 4 Bit 5 Bit 6 MSB
Mode 1
Mode 3
SAMPLE I
MOSI/MISO
CHANGE 0
MOSI PIN
CHANGE 0
MISO PIN
SS
MSB first (DORD = 0) MSB Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 LSB
LSB first (DORD = 1) LSB Bit 1 Bit 2 Bit 3 Bit 4 Bit 5 Bit 6 MSB
Bit 7 6 5 4 3 2 1 0
+0x00 CLK2X ENABLE DORD MASTER MODE[1:0] PRESCALER[1:0]
Read/Write R/W R/W R/W R/W R/W R/W R/W R/W
Initial Value 0 0 0 0 0 0 0 0
Table 20-3. Relationship between SCK and the Peripheral Clock (ClkPER) Frequency
0 00 ClkPER/4
0 01 ClkPER/16
0 10 ClkPER/64
0 11 ClkPER/128
1 00 ClkPER/2
1 01 ClkPER/8
1 10 ClkPER/32
1 11 ClkPER/64
Bit 7 6 5 4 3 2 1 0
+0x01 – – – – – – INTLVL[1:0]
Read/Write R R R R R R R/W R/W
Initial Value 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
+0x02 IF WRCOL – – – – – –
Read/Write R R R R R R R R
Initial Value 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
+0x03 DATA[7:0]
Read/Write R/W R/W R/W R/W R/W R/W R/W R/W
Initial Value 0 0 0 0 0 0 0 0
The DATA register is used for sending and receiving data. Writing to the register initiates the data transmission, and the
byte written to the register will be shifted out on the SPI output line. Reading the register causes the shift register receive
buffer to be read, returning the last byte successfully received.
21.1 Features
Full-duplex operation
Asynchronous or synchronous operation
Synchronous clock rates up to 1/2 of the device clock frequency
Asynchronous clock rates up to 1/8 of the device clock frequency
Supports serial frames with 5, 6, 7, 8, or 9 data bits and 1 or 2 stop bits
Fractional baud rate generator
Can generate desired baud rate from any system clock frequency
No need for external oscillator with certain frequencies
Built-in error detection and correction schemes
Odd or even parity generation and parity check
Data overrun and framing error detection
Noise filtering includes false start bit detection and digital low-pass filter
Separate interrupts for
Transmit complete
Transmit data register empty
Receive complete
Multiprocessor communication mode
Addressing scheme to address a specific devices on a multi-device bus
Enable unaddressed devices to automatically ignore all frames
Master SPI mode
Double buffered operation
Configurable data order
Operation up to 1/2 of the peripheral clock frequency
IRCOM module for IrDA compliant pulse modulation/demodulation
21.2 Overview
The universal synchronous and asynchronous serial receiver and transmitter (USART) is a fast and flexible serial
communication module. The USART supports full-duplex communication and asynchronous and synchronous operation.
The USART can be configured to operate in SPI master mode and used for SPI communication.
Communication is frame based, and the frame format can be customized to support a wide range of standards. The
USART is buffered in both directions, enabling continued data transmission without any delay between frames. Separate
interrupts for receive and transmit complete enable fully interrupt driven communication. Frame error and buffer overflow
are detected in hardware and indicated with separate status flags. Even or odd parity generation and parity check can
also be enabled.
A block diagram of the USART is shown in Figure 21-1 on page 245. The main functional blocks are the clock generator,
the transmitter, and the receiver, which are indicated in dashed boxes.
Transmitter
TX
DATA (Transmit)
CONTROL
PARITY
GENERATOR
DATA BUS
PIN
TRANSMIT SHIFT REGISTER TxD
CONTROL
Receiver
CLOCK RX
RECOVERY CONTROL
DATA PIN
RECEIVE SHIFT REGISTER RxD
RECOVERY CONTROL
PARITY
DATA (Receive)
CHECKER
The clock generator includes a fractional baud rate generator that is able to generate a wide range of USART baud rates
from any system clock frequencies. This removes the need to use an external crystal oscillator with a specific frequency
to achieve a required baud rate. It also supports external clock input in synchronous slave operation.
The transmitter consists of a single write buffer (DATA), a shift register, and a parity generator. The write buffer allows
continuous data transmission without any delay between frames.
The receiver consists of a two-level receive buffer (DATA) and a shift register. Data and clock recovery units ensure
robust synchronization and noise filtering during asynchronous data reception. It includes frame error, buffer overflow,
and parity error detection.
When the USART is set in master SPI mode, all USART-specific logic is disabled, leaving the transmit and receive
buffers, shift registers, and baud rate generator enabled. Pin control and interrupt generation are identical in both modes.
The registers are used in both modes, but their functionality differs for some control settings.
An IRCOM module can be enabled for one USART to support IrDA 1.4 physical compliant pulse modulation and
demodulation for baud rates up to 115.2kbps. For details, refer to “IRCOM - IR Communication Module” on page 264.
BSEL
CLK2X
fBAUD
Baud Rate
/2 /4 /2
Generator 0
1
0
fOSC txclk
1
DDR_XCK
PORT_INV
Sync Edge
xcki Register Detector 0
XCK UMSEL [1]
xcko 1
Pin
DDR_XCK 1
rxclk
0
BSCALE ≥ 0
f PER f PER
f PER f BAUD = ------------------------------------------------------------ BSEL = ----------------------------------------------- –1
f BAUD ----------- BSCALE
16( BSEL + 1)
BSCALE
16 f BAUD
Asynchronous normal 16 2 2
speed mode (CLK2X = 0)
BSCALE < 0
f PER f PER
1 - ---------------------
f PER f BAUD = ----------------------------------------------------------------- BSEL = --------------------
BSCALE 16f
– 1
f BAUD ----------- 16((2
BSCALE
BSEL + 1) 2 BAUD
16
BSCALE ≥ 0
f PER f PER
f PER f BAUD = -------------------------------------------------------------
- BSEL = -------------------------------------------- –1
f BAUD ----------- 2
BSCALE
8 BSEL + 1 2
BSCALE
8 f BAUD
Asynchronous double 8
speed mode (CLK2X = 1)
BSCALE < 0
f PER f PER
- ------------------ – 1
1
f PER f BAUD = --------------------------------------------------------------
- BSEL = --------------------
BSCALE 8f
f BAUD ----------- BSCALE
8 8((2 BSEL + 1) 2 BAUD
Note: 1. The baud rate is defined to be the transfer rate in bits per second (bps).
1 0 0 1
2 0 0 3
3 0 0 7
4 0 0 15
5 0 0 31
6 0 0 63
7 0 0 127
f PER
f XCK -----------
4
For each high and low period, XCK clock cycles must be sampled twice by the peripheral clock. If the XCK clock has
jitter, or if the high/low period duty cycle is not 50/50, the maximum XCK clock speed must be reduced or the peripheral
clock must be increased accordingly.
UCPOL = 1 XCK
RxD / TxD
Sample
UCPOL = 0 XCK
RxD / TxD
Sample
Using the inverted I/O (INVEN) setting for the corresponding XCK port pin, the XCK clock edges used for data sampling
and data change can be selected. If inverted I/O is disabled (INVEN=0), data will be changed at the rising XCK clock
edge and sampled at the falling XCK clock edge. If inverted I/O is enabled (INVEN=1), data will be changed at the falling
XCK clock edge and sampled at the rising XCK clock edge. For more details, see “I/O Ports” on page 119.
The leading edge is the first clock edge of a clock cycle. The trailing edge is the last clock edge of a clock cycle.
UCPHA=1
XCK XCK
XCK XCK
FRAME
(IDLE) St 0 1 2 3 4 [5] [6] [7] [8] [P] Sp1 [Sp2] (St / IDLE)
Sample
(U2X = 0) 0 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 1 2 3
Sample
(U2X = 1) 0 1 2 3 4 5 6 7 8 1 2
When the clock recovery logic detects a high (idle) to low (start) transition on the RxD line, the start bit detection
sequence is initiated. Sample 1 denotes the first zero-sample, as shown in the figure. The clock recovery logic then uses
samples 8, 9, and 10 for normal mode and samples 4, 5, and 6 for double speed mode to decide if a valid start bit is
received. If two or three samples have a low level, the start bit is accepted. The clock recovery unit is synchronized, and
the data recovery can begin. If two or three samples have a high level, the start bit is rejected as a noise spike, and the
receiver looks for the next high-to-low transition. The process is repeated for each start bit.
RxD BIT n
Sample
(CLK2X = 0) 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 1
Sample
(CLK2X = 1) 1 2 3 4 5 6 7 8 1
As for start bit detection, an identical majority voting technique is used on the three center samples for deciding of the
logic level of the received bit. The process is repeated for each bit until a complete frame is received. It includes the first
stop bit, but excludes additional ones. If the sampled stop bit is a 0 value, the frame error (FERR) flag will be set.
Figure 21-8 shows the sampling of the stop bit in relation to the earliest possible beginning of the next frame's start bit.
Sample
(CLK2X = 0) 1 2 3 4 5 6 7 8 9 10 0/1 0/1 0/1
Sample
(CLK2X = 1) 1 2 3 4 5 6 0/1
A new high-to-low transition indicating the start bit of a new frame can come right after the last of the bits used for
majority voting. For normal speed mode, the first low level sample can be at the point marked (A) in Stop Bit Sampling
and Next Start Bit Sampling. For double speed mode, the first low level must be delayed to point (B). Point (C) marks a
stop bit of full length at nominal baud rate. The early start bit detection influences the operational range of the receiver.
D + 1 S D + 2 S
R slow = ------------------------------------------ R fast = -----------------------------------
S – 1 + D S + SF D + 1 S + S M
Table 21-3 and Table 21-4 list the maximum receiver baud rate error that can be tolerated. Normal speed mode has
higher tolerance of baud rate variations.
Table 21-3. Recommended Maximum Receiver Baud Rate Error for Normal Speed Mode
D Recommended max.
#(Data + Parity Bit) Rslow [%] Rfast [%] Max. total error [%] receiver error [%]
Table 21-4. Recommended Maximum Receiver Baud Rate Error for Double Speed Mode
D Recommended max.
#(Data + Parity Bit) Rslow [%] Rfast [%] Max. total error [%] receiver error [%]
The recommendations for the maximum receiver baud rate error assume that the receiver and transmitter equally divide
the maximum total error.
BSEL=0
BSCALE=0
fBAUD=fPER/8
clkBAUD8
BSEL=3
BSCALE=-6
fBAUD=fPER/8.375
clkBAUD8
BSEL=3
BSCALE=-4
fBAUD=fPER/9.5
clkBAUD8
34 2 0.8 34 3 0.8
14.4k
138 0 -0.1 138 1 -0.1
34 1 -0.8 34 2 -0.8
28.8k
137 -1 -0.1 138 0 -0.1
34 0 -0.8 34 1 -0.8
57.6k
135 -2 -0.1 137 -1 -0.1
33 -1 -0.8 34 0 -0.8
115.2k
131 -3 -0.1 135 -2 -0.1
31 -2 -0.8 33 -1 -0.8
230.4k
123 -4 -0.1 131 -3 -0.1
27 -3 -0.8 31 -2 -0.8
460.8k
107 -5 -0.1 123 -4 -0.1
19 -4 -0.8 27 -3 -0.8
921.6k
75 -6 -0.1 107 -5 -0.1
7 -4 0.6 15 -3 0.6
1.382M
57 -7 0.1 121 -6 0.1
3 -5 -0.8 19 -4 -0.8
1.843M
11 -7 -0.1 75 -6 -0.1
3 -2 -0.8
2.304M – – –
47 -6 -0.1
19 -4 0.4
2.5M – – –
77 -7 -0.1
11 -5 -0.8
3.0M – – –
43 -7 -0.2
4.0M – – – 0 0 0.0
Table 21-6. Comparison of USART in Master SPI Mode and SPI Pins
Bit 7 6 5 4 3 2 1 0
RXB[[7:0]
+0x00
TXB[[7:0]
Read/Write R/W R/W R/W R/W R/W R/W R/W R/W
Initial Value 0 0 0 0 0 0 0 0
The USART transmit data buffer register (TXB) and USART receive data buffer register (RXB) share the same I/O
address and is referred to as USART data register (DATA). The TXB register is the destination for data written to the
DATA register location. Reading the DATA register location returns the contents of the RXB register.
For 5-bit, 6-bit, or 7-bit characters, the upper unused bits will be ignored by the transmitter and set to zero by the receiver.
The transmit buffer can be written only when DREIF in the STATUS register is set. Data written to the DATA register
when DREIF is not set will be ignored by the USART transmitter. When data are written to the transmit buffer and the
transmitter is enabled, the transmitter will load the data into the transmit shift register when the shift register is empty.
The data are then transmitted on the TxD pin.
The receive buffer consists of a two-level FIFO. Always read STATUS before DATA in order to get the correct status of
the receive buffer.
Bit 7 6 5 4 3 2 1 0
+0x01 RXCIF TXCIF DREIF FERR BUFOVF PERR – RXB8
Read/Write R R/W R R R R R R/W
Initial Value 0 0 1 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
+0x03 – – RXCINTLVL[1:0] TXCINTLVL[1:0] DREINTLVL[1:0]
Read/Write R R R/W R/W R/W R/W R/W R/W
Initial Value 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
+0x04 – – – RXEN TXEN CLK2X MPCM TXB8
Read/Write R R R R/W R/W R/W R/W R/W
Initial Value 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
+0x05 CMODE[1:0] PMODE[1:0] SBMODE CHSIZE[2:0]
(1)
+0x05 CMODE[1:0] – – – UDORD UCPHA –
Read/Write R/W R/W R/W R/W R/W R/W R/W R/W
Initial Value 0 0 0 0 0 1 1 0
10 IRCOM IRCOM(1)
Notes: 1. See “IRCOM - IR Communication Module” on page 264 for full description on using IRCOM mode.
2. See “USART in Master SPI Mode” on page 256 for full description of the master SPI operation.
00 DISABLED Disabled
01 Reserved
0 1
1 2
100 Reserved
101 Reserved
110 Reserved
Bit 7 6 5 4 3 2 1 0
+0x06 BSEL[7:0]
Read/Write R/W R/W R/W R/W R/W R/W R/W R/W
Initial Value 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
+0x07 BSCALE[3:0] BSEL[11:8]
Read/Write R/W R/W R/W R/W R/W R/W R/W R/W
Initial Value 0 0 0 0 0 0 0 0
22.1 Features
Pulse modulation/demodulation for infrared communication
IrDA compatible for baud rates up to 115.2kbps
Selectable pulse modulation scheme
3/16 of the baud rate period
Fixed pulse period, 8-bit programmable
Pulse modulation disabled
Built-in filtering
Can be connected to and used by any USART
22.2 Overview
XMEGA devices contain an infrared communication module (IRCOM) that is IrDA compatible for baud rates up to
115.2kbps. It can be connected to any USART to enable infrared pulse encoding/decoding for that USART.
RXDxn
USARTxn
TXDxn
IRCOM
.... RXD...
TXD...
encoded RXD USARTD0 RXDD0
Pulse
TXDD0
Decoding
USARTC0 RXDC0
decoded RXD TXDC0
decoded TXD
Pulse
Encoding encoded TXD
The IRCOM is automatically enabled when a USART is set in IRCOM mode. The signals between the USART and the
RX/TX pins are then routed through the module as shown in Figure 22-1. The data on the TX/RX pins are the inverted
value of the transmitted/received infrared pulse. It is also possible to select an event channel from the event system as
input for the IRCOM receiver. This will disable the RX input from the USART pin.
For transmission, three pulse modulation schemes are available:
3/16 of the baud rate period
Fixed programmable pulse time based on the peripheral clock frequency
Pulse modulation disabled
For reception, a fixed programmable minimum high-level pulse width for the pulse to be decoded as a logical 0 is used.
Shorter pulses will then be discarded, and the bit will be decoded to logical 1 as if no pulse was received.
Bit 7 6 5 4 3 2 1 0
+0x01 TXPLCTRL[7:0]
Read/Write R/W R/W R/W R/W R/W R/W R/W R/W
Initial Value 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
+0x02 RXPLCTRL[7:0]
Read/Write R/W R/W R/W R/W R/W R/W R/W R/W
Initial Value 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
+0x00 – – – – EVSEL[3:0]
Read/Write R R R R R/W R/W R/W R/W
Initial Value 0 0 0 0 0 0 0 0
0000 – None
0001 – (Reserved)
0010 – (Reserved)
0011 – (Reserved)
0100 – (Reserved)
0101 – (Reserved)
0110 – (Reserved)
0111 – (Reserved)
23.1 Features
Advanced Encryption Standard (AES) crypto module
AES crypto module
Encryption and decryption
Supports 128-bit keys
Supports XOR data load mode to the state memory
Encryption/decryption in 375 clock cycles per 16-byte block
23.2 Overview
The Advanced Encryption Standard (AES) is a commonly used standard for cryptography. This is supported through an
AES peripheral module, and the communication interfaces and the CPU can use this for fast, encrypted communication
and secure data storage.
The AES crypto module encrypts and decrypts 128-bit data blocks with the use of a 128-bit key. The key and data must
be loaded into the key and state memory in the module before encryption/decryption is started. It takes 375 peripheral
clock cycles before the encryption/decryption is done. The encrypted/encrypted data can then be read out, and an
optional interrupt can be generated. The AES crypto module also has DMA support with transfer triggers when
encryption/decryption is done and optional auto-start of encryption/decryption when the state memory is fully loaded.
Reset pointer
-
Reset pointer
reset or access
to AES Control STATE
XOR
STATE[read pointer]
The state memory contains the AES state throughout the encryption/decryption process. The initial value of the state is
the initial data (i.e., plaintext in the encryption mode, and ciphertext in the decryption mode). The last value of the state is
the encrypted/decrypted data.
Reset pointer
-
Reset pointer
reset or
access to CTRL KEY
In the AES crypto module, the following definition of the key is used:
In encryption mode, the key is the one defined in the AES standard
In decryption mode, the key is the last subkey of the expanded key defined in the AES standard
In decryption mode, the key expansion procedure must be executed by software before operation with the AES crypto
module so that the last subkey is ready to be loaded through the KEY register. Alternatively, this procedure can be run in
hardware by using the AES crypto module to process a dummy data block in encryption mode using the same key. After
the end of the encryption, reading from the key memory allows the last subkey to be obtained; i.e., get the result of the
key expansion procedure. Table 23-1 on page 270 shows the results of reading the key, depending on the mode
(encryption or decryption) and status of the AES crypto module.
Encryption Decryption
Before data processing After data processing Before data processing After data processing
Bit 7 6 5 4 3 2 1 0
+0x00 START AUTO RESET DECRYPT – XOR – –
Read/Write R/W R/W R/W R/W R R/W R R
Initial Value 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
+0x01 ERROR – – – – – – SRIF
Read/Write R/W R R R R R R R/W
Initial Value 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
+0x02 STATE[7:0]
Read/Write R/W R/W R/W R/W R/W R/W R/W R/W
Initial Value 0 0 0 0 0 0 0 0
The STATE register is used to access the state memory. Before encryption/decryption can take place, the state memory
must be written sequentially, byte-by-byte, through the STATE register. After encryption/decryption is done, the
ciphertext/plaintext can be read sequentially, byte-by-byte, through the STATE register.
Loading the initial data to the STATE register should be done after setting the appropriate AES mode and direction. This
register can not be accessed during encryption/decryption.
Bit 7 6 5 4 3 2 1 0
+0x03 KEY[7:0]
Read/Write R/W R/W R/W R/W R/W R/W R/W R/W
Initial Value 0 0 0 0 0 0 0 0
The KEY register is used to access the key memory. Before encryption/decryption can take place, the key memory must
be written sequentially, byte-by-byte, through the KEY register. After encryption/decryption is done, the last subkey can
be read sequentially, byte-by-byte, through the KEY register.
Loading the initial data to the KEY register should be done after setting the appropriate AES mode and direction.
Bit 7 6 5 4 3 2 1 0
+0x04 – – – – – – INTLVL[1:0]
Read/Write R R R R R R R/W R/W
Initial Value 0 0 0 0 0 0 0 0
24.1 Features
Cyclic redundancy check (CRC) generation and checking for
Communication data
Program or data in flash memory
Data in SRAM and I/O memory space
Integrated with flash memory, DMA controller and CPU
Continuous CRC on data going through a DMA channel
Automatic CRC of the complete or a selectable range of the flash memory
CPU can load data to the CRC generator through the I/O interface
CRC polynomial software selectable to
CRC-16 (CRC-CCITT)
CRC-32 (IEEE 802.3)
Zero remainder detection
24.2 Overview
A cyclic redundancy check (CRC) is an error detection technique test algorithm used to find accidental errors in data, and
it is commonly used to determine the correctness of a data transmission, and data present in the data and program
memories. A CRC takes a data stream or a block of data as input and generates a 16- or 32-bit output that can be
appended to the data and used as a checksum. When the same data are later received or read, the device or application
repeats the calculation. If the new CRC result does not match the one calculated earlier, the block contains a data error.
The application will then detect this and may take a corrective action, such as requesting the data to be sent again or
simply not using the incorrect data.
Typically, an n-bit CRC applied to a data block of arbitrary length will detect any single error burst not longer than n bits
(any single alteration that spans no more than n bits of the data), and will detect the fraction 1-2-n of all longer error
bursts. The CRC module in XMEGA devices supports two commonly used CRC polynomials; CRC-16 (CRC-CCITT) and
CRC-32 (IEEE 802.3).
CRC-16:
Polynomial: x16+x12+x5+1
CRC-32:
Polynomial: x32+x26+x23+x22+x16+x12+x11+x10+x8+x7+x5+x4+x2+x+1
24.3 Operation
The data source for the CRC module must be selected in software as either flash memory, the DMA channels, or the I/O
interface. The CRC module then takes data input from the selected source and generates a checksum based on these
data. The checksum is available in the CHECKSUM registers in the CRC module. When CRC-32 polynomial is used, the
final checksum read is bit reversed and complemented (see Figure 24-1 on page 275).
For the I/O interface or DMA controller, which CRC polynomial is used is software selectable, but the default setting is
CRC-16. CRC-32 is automatically used if Flash Memory is selected as the source. The CRC module operates on bytes
only.
DMA Flash
Controller Memory
DATAIN
CTRL
8 16 8 32
CRC-16 CRC-32
crc32
CHECKSUM
bit-reverse +
complement
Checksum read
Bit 7 6 5 4 3 2 1 0
+0x00 RESET[1:0] CRC32 – SOURCE[3:0]
Read/Write R/W R/W R/W R R/W R/W R/W R/W
Initial Value 0 0 0 0 0 0 0 0
00 NO No reset
01 – Reserved
Bit 7 6 5 4 3 2 1 0
+0x02 – – – – – – ZERO BUSY
Read/Write R R R R R R R R/W
Initial Value 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
+0x03 DATAIN[7:0]
Read/Write W W W W W W W W
Initial Value 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
+0x05 CHECKSUM[15:8]
Read/Write R/W R/W R/W R/W R/W R/W R/W R/W
Initial Value 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
+0x06 CHECKSUM[23:16]
Read/Write R/W R/W R/W R/W R/W R/W R/W R/W
Initial Value 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
+0x07 CHECKSUM[31:24]
Read/Write R/W R/W R/W R/W R/W R/W R/W R/W
Initial Value 0 0 0 0 0 0 0 0
25.1 Features
12-bit resolution
Up to 300 thousand samples per second
Down to 2.3µs conversion time with 8-bit resolution
Down to 3.35µs conversion time with 12-bit resolution
Differential and single-ended input
Up to 16 single-ended inputs
Up to 16x4 differential inputs without gain
8x4 differential input with gain
Built-in differential gain stage
1/2x, 1x, 2x, 4x, 8x, 16x, 32x, and 64x gain options
Single, continuous and scan conversion options
Three internal inputs
Internal temperature sensor
AVCC voltage divided by 10
1.1V bandgap voltage
Internal and external reference options
Compare function for accurate monitoring of user defined thresholds
Optional DMA transfer of conversion results
Optional event triggered conversion for accurate timing
Optional interrupt/event on compare result
25.2 Overview
The ADC converts analog signals to digital values. The ADC has 12-bit resolution and is capable of converting up to 300
thousand samples per second (ksps). The input selection is flexible, and both single-ended and differential
measurements can be done. For differential measurements, an optional gain stage is available to increase the dynamic
range. In addition, several internal signal inputs are available. The ADC can provide both signed and unsigned results.
The ADC measurements can either be started by application software or an incoming event from another peripheral in
the device. The ADC measurements can be started with predictable timing, and without software intervention. It is
possible to use DMA to move ADC results directly to memory or peripherals when conversions are done.
Both internal and external reference voltages can be used. An integrated temperature sensor is available for use with the
ADC. The AVCC/10 and the bandgap voltage can also be measured by the ADC.
The ADC has a compare function for accurate monitoring of user defined thresholds with minimum software intervention
required.
ADC DAC
2 bits
Compare
ADC0
• Register
•
• VINP Stage Stage <
ADC15
1 2 > Threshold
2 2
(Int Req)
Internal
clkADC CH0 Result
signals
Internal 1.00V
Internal AVCC/1.6V Enable Action
Start Select
Internal AVCC/2
Reference
AREFA Mode
Voltage
AREFB Resolution
ADC0
•
•
•
ADC15
+
ADC0
• -
•
•
ADC3
GND
INTGND
ADC0
•
•
•
ADC15
+
ADC4
• -
•
•
ADC7
GND
INTGND
ADC0
•
•• +
ADC15
ADC
-
In unsigned mode, the negative input is connected to half of the voltage reference (VREF) voltage minus a fixed offset.
The nominal value for the offset is:
V = VREF 0.05
Since the ADC is differential, the input range is VREF to zero for the positive single-ended input. The offset enables the
ADC to measure zero crossing in unsigned mode, and allows for calibration of any positive offset when the internal
ground in the device is higher than the external ground. See Figure 25-11 on page 285 for details.
ADC0
••
• +
ADC15
ADC
VREF
____ −ΔV -
2
TEMP REF
BANDGAP REF +
AVCC SCALED ADC
-
To measure the internal signals in unsigned mode, the negative input is connected to a fixed value given by the formula
below, which is half of the voltage reference (VREF) minus a fixed offset, as it is for single-ended unsigned input. Refer to
Figure 25-11 on page 285 for details.
VINN = VREF/2 - V
TEMP REF
BANDGAP REF +
AVCC SCALED ADC
VREF
____ −ΔV -
2
Internal 1.00V
Internal AVCC/1.6V
Internal AVCC/2.0V VREF
AREFA
AREFB
VINP - VINN
RES = ---------------------------------- GAIN TOP +1
VREF
VINP and VINN are the positive and negative inputs to the ADC.
For differential measurements, GAIN is 1/2 to 64. For single-ended and internal measurements, GAIN is always 1 and
VINP is the internal ground.
In unsigned mode, only positive results are generated. The TOP value of an unsigned result is 4095, and the results will
be in the range 0 to +4095 (0x0 - 0x0FFF).
The ADC transfer functions can be written as:
VINP - (-V
RES = --------------------------------- TOP +1
VREF
Figure 25-9. Signed Differential Input (with Gain), Input Range, and Result Representation
VREF Dec Hex Binary 16-bit result register
GAIN 2047 7FF 0111 1111 1111 0000 0111 1111 1111
VINN 2046 7FE 0111 1111 1110 0000 0111 1111 1110
2045 7FD 0111 1111 1101 0000 0111 1111 1101
... ... ... ...
3 3 0000 0000 0011 0000 0000 0000 0011
VINP 2 2 0000 0000 0010 0000 0000 0000 0010
1 1 0000 0000 0001 0000 0000 0000 0001
0V 0 0 0000 0000 0000 0000 0000 0000 0000
-1 FFF 1111 1111 1111 1111 1111 1111 1111
-2 FFE 1111 1111 1110 1111 1111 1111 1110
... ... ... ...
RES -2045 803 1000 0000 0011 1111 1000 0000 0011
-2046 802 1000 0000 0010 1111 1000 0000 0010
-2047 801 1000 0000 0001 1111 1000 0000 0001
-VREF -2048 800 1000 0000 0000 1111 1000 0000 0000
GAIN
Figure 25-11.Unsigned Single-ended and Internal Input, Input Range, and Result Representation
Dec Hex Binary 16-bit result register
VREF − ΔV
4095 FFF 1111 1111 1111 0000 1111 1111 1111
VINP 4094 FFE 1111 1111 1110 0000 1111 1111 1110
4093 FFD 1111 1111 1101 0000 1111 1111 1101
... ... ... ...
203 0CB 0000 1100 1011 0000 0000 1100 1011
202 0CA 0000 1100 1010 0000 0000 1100 1010
VREF 201 0C9 0000 1100 1001 0000 0000 1100 1001
VINN = − ΔV
2 200 0C8 0000 1100 1000 0000 0000 1100 1000
GND
...
0 0 0000 0000 0000 0000 0000 0000 0000
CLK/128
CLK/256
CLK/512
CLK/16
CLK/32
CLK/64
CLK/4
CLK/8
PRESCALER[2:0]
ClkADC
RESOLUTION is the resolution, 8 or 12 bits. The propagation delay will increase by extra ADC clock cycles if the gain
stage (GAIN) is used. A new ADC conversion can start as soon as the previous is completed.
The most-significant bit (msb) of the result is converted first, and the rest of the bits are converted during the next three
(for 8-bit results) or five (for 12-bit results) ADC clock cycles. Converting one bit takes a half ADC clock period. During the
last cycle, the result is prepared before the interrupt flag is set and the result is available in the result register for readout.
clkADC
START
ADC SAMPLE
IF
clkADC
START
ADC SAMPLE
IF
clkADC
START
ADC SAMPLE
AMPLIFY
IF
clkADC
START
ADC SAMPLE
AMPLIFY
IF
1 2 3 4 5 6 7 8 9 10
clkADC
START
ADC SAMPLE
AMPLIFY
IF
VCC/2
Figure 25-19.ADC Input for Differential Measurements and Differential Measurements with Gain
Positive
input
Rchannel Rswitch
CSample
VCC/2
CSample
Negative
input
Rchannel Rswitch
In order to achieve n bits of accuracy, the source output resistance, Rsource, must be less than the ADC input resistance
on a pin:
Ts
R source ----------------------------------------------
n+1
- – R channel – R switch
C sample ln 2
where the ADC sample time, TS is one-half the ADC clock cycle given by:
1
T s -------------------
2 f ADC
For details on Rchannel, Rswitch, and Csample, refer to the ADC electrical characteristic in the device datasheet.
25.13 Calibration
The ADC has built-in linearity calibration. The value from the production test calibration must be loaded from the
signature row and into the ADC calibration register from software to achieve specified accuracy. User calibration of the
linearity is not needed, hence not possible. Offset and gain calibration must be done in software.
Bit 7 6 5 4 3 2 1 0
+0x00 – – – – – CH0START FLUSH ENABLE
Read/Write R R R R R R/W R/W R/W
Initial Value 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
+0x01 – CURRLIMIT[1:0] CONVMODE FREERUN RESOLUTION[1:0] –
Read/Write R R/W R/W R/W R/W R/W R/W R
Initial Value 0 0 0 0 0 0 0 0
Bit 7 – Reserved
This bit is unused and reserved for future use. For compatibility with future devices, always write this bit to zero when this
register is written.
Bit 6:5 – CURRLIMIT[1:0]: Current Limitation
These bits can be used to limit the current consumption of the ADC by reducing the maximum ADC sample rate. The
available settings are shown in Table 25-1. The indicated current limitations are nominal values. Refer to the device
datasheet for actual current limitation for each setting.
00 NO No limit
01 – Reserved
Bit 0 – Reserved
This bit is unused and reserved for future use. For compatibility with future devices, always write this bit to zero when this
register is written.
Bit 7 6 5 4 3 2 1 0
+0x02 – REFSEL[2:0] – – BANDGAP TEMPREF
Read/Write R R/W R/W R/W R R R/W R/W
Initial Value 0 0 0 0 0 0 0 0
Bit 7 – Reserved
This bit is unused and reserved for future use. For compatibility with future devices, always write this bit to zero when this
register is written.
Bits 6:4 – REFSEL[2:0]: Reference Selection
These bits selects the reference for the ADC according to Table 25-3.
Bit 7 6 5 4 3 2 1 0
+0x03 – – – EVSEL[1:0] EVACT[2:0]
Read/Write R R R R/W R/W R/W R/W R/W
Initial Value 0 0 0 0 0 0 0 0
010 – Reserved
011 – Reserved
100 – Reserved
101 – Reserved
110 SYNCSWEEP The ADC is flushed and restarted for accurate timing
111 – Reserved
Bit 7 6 5 4 3 2 1 0
+0x04 – – – – – PRESCALER[2:0]
Read/Write R R R R R R/W R/W R/W
Initial Value 0 0 0 0 0 0 0 0
000 DIV4 4
001 DIV8 8
010 DIV16 16
011 DIV32 32
100 DIV64 64
Bit 7 6 5 4 3 2 1 0
+0x06 – – – – – – – CH0IF
Read/Write R R R R R R R R/W
Initial Value 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
+0x07 TEMP[7:0]
Read/Write R/W R/W R/W R/W R/W R/W R/W R/W
Initial Value 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
+0x08 – – SAMPVAL[5:0]
Read/Write R R R/W R/W R/W R/W R/W R/W
Initial Value 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
12-/8-bit,
CHRES[7:0]
right
12-bit, left CHRES[3:0] – – – –
Read/Write R R R R R R R R
Initial Value 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
+0x18 CMP[7:0]
Read/Write R/W R/W R/W R/W R/W R/W R/W R/W
Initial Value 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
+0x00 START – – GAIN[2:0] INPUTMODE[1:0]
Read/Write R/W R R R/W R/W R/W R/W R/W
Initial Value 0 0 0 0 0 0 0 0
000 1X 1x
001 2X 2x
010 4X 4x
011 8X 8x
111 DIV2 ½x
10 – Reserved
11 – Reserved
Bit 7 – Reserved
This bit is unused and reserved for future use. For compatibility with future devices, always write this bit to zero when this
register is written.
0011 – Reserved
0100-1111 – Reserved
Depending on the device pin count and feature configuration, the actual number of analog input pins may be less than
16. Refer to the device datasheet and pin-out description for details.
Table 25-12. ADC MUXNEG Configuration, INPUTMODE[1:0] = 10, Differential without Gain
100 – Reserved
110 – Reserved
Table 25-13. ADC MUXNEG Configuration, INPUTMODE[1:0] = 11, Differential with Gain
101 – Reserved
110 – Reserved
Bit 7 6 5 4 3 2 1 0
+0x02 – – – – INTMODE[1:0} INTLVL[1:0]
Read/Write R R R R R/W R/W R/W R/W
Initial Value 0 0 0 0 0 0 0 0
10 – Reserved
Bit 7 6 5 4 3 2 1 0
+0x03 – – – – – – – IF
Read/Write R R R R R R R R/W
Initial Value 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
12-bit, left. RES[11:4]
12-bit, right +0x05 – – – – RES[11:8]
8-bit – – – – – – – –
Read/Write R R R R R R R R
Initial Value 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
12-/8-bit,
RES[7:0]
right +0x04
12-bit, left. RES[3:0] – – – –
Read/Write R R R R R R R R
Initial Value 0 0 0 0 0 0 0 0
Address Name Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0 Page
+0x00 CTRLA – – – – – CH0STAR FLUSH ENABLE 290
+0x01 CTRLB – CURRLIMIT[1:0] CONVMODE FREERUN RESOLUTION[1:0] – 290
+0x02 REFCTRL – REFSEL[2:0] – – BANDGAP TEMPREF 291
+0x03 EVCTRL – – – EVSEL[1:0] EVACT[2:0] 292
+0x04 PRESCALER – – – – – PRESCALER[2:0] 293
+0x05 Reserved – – – – – – – –
+0x06 INTFLAGS – – – – – – – CH0IF 293
+0x07 TEMP TEMP[7:0] 294
+0x08 SAMPCTRL – – SAMPVAL[5:0] 294
+0x09 Reserved – – – – – – – –
+0x0A Reserved – – – – – – – –
+0x0B Reserved – – – – – – – –
+0x0C CALL CAL[7:0] 294
+0x0D Reserved – – – – – – – –
+0x0E Reserved – – – – – – – –
+0x0F Reserved – – – – – – – –
+0x10 CH0RESL CH0RES[7:0] 295
+0x11 CH0RESH CH0RES[15:8] 294
+0x12 Reserved – – – – – – – –
+0x13 Reserved – – – – – – – –
+0x14 Reserved – – – – – – – –
+0x15 Reserved – – – – – – – –
+0x16 Reserved – – – – – – – –
+0x17 Reserved – – – – – – – –
+0x18 CMPL CMP[7:0] 296
+0x19 CMPH CMP[15:8] 295
+0x1A Reserved – – – – – – – –
+0x1B Reserved – – – – – – – –
+0x1C Reserved – – – – – – – –
+0x1D Reserved – – – – – – – –
+0x1E Reserved – – – – – – – –
+0x1F Reserved – – – – – – – –
+0x20 CH0 Offset Offset address for ADC channel
+0x28 Reserved – – – – – – – –
+0x30 Reserved – – – – – – – –
+0x38 Reserved – – – – – – – –
26.1 Features
Selectable hysteresis
None
Small
Large
Analog comparator output available on pin
Flexible input selection
All pins on the port
Bandgap reference voltage
A 64-level programmable voltage scaler of the internal AVCC voltage
Interrupt and event generation on:
Rising edge
Falling edge
Toggle
Window function interrupt and event generation on:
Signal above window
Signal inside window
Signal below window
Constant current source with configurable output pin selection
26.2 Overview
The analog comparator (AC) compares the voltage levels on two inputs and gives a digital output based on this
comparison. The analog comparator may be configured to generate interrupt requests and/or events upon several
different combinations of input change.
The analog comparator hysteresis can be adjusted in order to achieve the optimal operation for each application.
The input selection includes analog port pins, several internal signals, and a 64-level programmable voltage scaler. The
analog comparator output state can also be output on a pin for use by external devices.
A constant current source can be enabled and output on a selectable pin. This can be used to replace, for example,
external resistors used to charge capacitors in capacitive touch sensing applications.
The analog comparators are always grouped in pairs on each port. These are called analog comparator 0 (AC0) and
analog comparator 1 (AC1). They have identical behavior, but separate control registers. Used as pair, they can be set in
window mode to compare a signal to a voltage range instead of a voltage level.
Pin Input
AC0OUT
AC0
Pin Input
-
Hysteresis
Voltage Enable
Interrupt Interrupts
Scaler Interrupt Sensititivity
Mode Control
ACnMUXCTRL ACnCTRL WINCTRL &
Window Events
Bandgap Function
Enable
Hysteresis
+
Pin Input
AC1OUT
AC1
-
Pin Input
+
AC0
Upper limit of window -
Interrupts
Interrupt
Input signal sensitivity
Events
control
+
AC1
Lower limit of window
-
Bit 7 6 5 4 3 2 1 0
+0x00 / +0x01 INTMODE[1:0] INTLVL[1:0] – HYSMODE[2:0] ENABLE
Read/Write R/W R/W R/W R/W R R/W R/W R/W
Initial Value 0 0 0 0 0 0 0 0
01 – Reserved
00 NO No hysteresis
11 – Reserved
Bit 7 6 5 4 3 2 1 0
+0x02 / +0x03 – – MUXPOS[2:0] MUXNEG[2:0]
Read/Write R R R/W R/W R/W R/W R/W R/W
Initial Value 0 0 0 0 0 0 0 0
111 – Reserved
101 – Reserved
Bit 7 6 5 4 3 2 1 0
+0x04 – – – – – – AC1OUT AC0OUT
Read/Write R R R R R R R/W R/W
Initial Value 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
+0x05 – – SCALEFAC[5:0]
Read/Write R/W R/W R/W R/W R/W R/W R/W R/W
Initial Value 0 0 0 0 0 0 0 0
V CC SCALEFAC + 1
V SCALE = ------------------------------------------------------------
64
Bit 7 6 5 4 3 2 1 0
+0x06 – – – WEN WINTMODE[1:0] WINTLVL[1:0]
Read/Write R R R R/W R/W R/W R/W R/W
Initial Value 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
+0x07 WSTATE[1:0] AC1STATE AC0STATE – WIF AC1IF AC0IF
Read/Write R/W R/W R/W R/W R R/W R/W R/W
Initial Value 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
+0x08 CURRENT – – – – – AC1CURR AC0CURR
Read/Write R/W R R R R R R/W R/W
Initial Value 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
+0x09 – – – – CALIB[3:0]
Read/Write R R R R R/W R/W R/W R/W
Initial Value 0 0 0 0 0 0 0 0
27.1 Features
Programming
External programming through PDI interface
Minimal protocol overhead for fast operation
Built-in error detection and handling for reliable operation
Boot loader support for programming through any communication interface
Debugging
Nonintrusive, real-time, on-chip debug system
No software or hardware resources required from device except pin connection
Program flow control
Go, Stop, Reset, Step Into, Step Over, Step Out, Run-to-Cursor
Unlimited number of user program breakpoints
Unlimited number of user data breakpoints, break on:
Data location read, write, or both read and write
Data location content equal or not equal to a value
Data location content is greater or smaller than a value
Data location content is within or outside a range
No limitation on device clock frequency
Program and Debug Interface (PDI)
Two-pin interface for external programming and debugging
Uses the Reset pin and a dedicated pin
No I/O pins required during programming or debugging
27.2 Overview
The Program and Debug Interface (PDI) is an Atmel proprietary interface for external programming and on-chip
debugging of a device.
The PDI supports fast programming of nonvolatile memory (NVM) spaces; flash, EEPOM, fuses, lock bits, and the user
signature row. This is done by accessing the NVM controller and executing NVM controller commands, as described in
“Memory Programming” on page 323.
Debug is supported through an on-chip debug system that offers nonintrusive, real-time debug. It does not require any
software or hardware resources except for the device pin connection. Using the Atmel tool chain, it offers complete
program flow control and support for an unlimited number of program and complex data breakpoints. Application debug
can be done from a C or other high-level language source code level, as well as from an assembler and disassembler
level.
Programming and debugging can be done through the PDI physical layer. This is a two-pin interface that uses the Reset
pin for the clock input (PDI_CLK) and one other dedicated pin for data input and output (PDI_DATA). Any external
programmer or on-chip debugger/emulator can be directly connected to this interface.
OCD
NVM
Controller
VCC
PDI Connector
PDI_CLK
PDI_DATA
GND
The remainder of this section is intended for use only by third parties developing programmers or programming support
for Atmel AVR XMEGA devices.
27.3.1 Enabling
The PDI physical layer must be enabled before use. This is done by first forcing the PDI_DATA line high for a period
longer than the equivalent external reset minimum pulse width (refer to device datasheet for external reset pulse width
data). This will disable the RESET functionality of the Reset pin, if not already disabled by the fuse settings.
Next, continue to keep the PDI_DATA line high for 16 PDI_CLK cycles. The first PDI_CLK cycle must start no later than
100µs after the RESET functionality of the Reset pin is disabled. If this does not occur in time, the enabling procedure
must start over again. The enable sequence is shown in Figure 27-3 on page 314.
PDI_DATA
PDI_CLK
The Reset pin is sampled when the PDI interface is enabled. The reset register is then set according to the state of the
Reset pin, preventing the device from running code after the reset functionality of this pin is disabled.
27.3.2 Disabling
If the clock frequency on PDI_CLK is lower than approximately 10kHz, this is regarded as inactivity on the clock line. This
will automatically disable the PDI. If not disabled by a fuse, the reset function of the Reset (PDI_CLK) pin is enabled
again. This also means that the minimum programming frequency is approximately 10kHz.
FRAME
Three different characters are used, DATA, BREAK, and IDLE. The BREAK character is equal to a 12-bit length of low
level. The IDLE character is equal to a 12- bit length of high level. The BREAK and IDLE characters can be extended
beyond the 12-bit length.
Figure 27-5. Characters and Timing for the PDI Physical Layer
1 DATA character
START 0 1 2 3 4 5 6 7 P STOP
1 BREAK character
BREAK
1 IDLE character
IDLE
PDI_CLK
PDI_DATA
St PDI DATA Receive (RX) P Sp1 Sp2 IDLE bits St PDI DATA Transmit (TX) P Sp1 Sp2
Figure 27-8. Driving Data out on the PDI_DATA Using a Bus Keeper
PDI_CLK
Output enable
PDI Output
PDI_DATA
1 0 1 1 0 0 1
If the programmer and the PDI both drive the PDI_DATA line at the same time, drive contention will occur, as illustrated
in Figure 27-9. Every time a bit value is kept for two or more clock cycles, the PDI is able to verify that the correct bit
value is driven on the PDI_DATA line. If the programmer is driving the PDI_DATA line to the opposite bit value to what
the PDI expects, a collision is detected.
Figure 27-9. Drive Contention and Collision Detection on the PDI_DATA Line
PDI_CLK
PDI Output
Programmer
output
PDI_DATA
1 0 X 1 X 1 1
Collision detect
= Collision
As long as the PDI transmits alternating ones and zeros, collisions cannot be detected, because the PDI output driver will
be active all the time, preventing polling of the PDI_DATA line. However, the two stop bits should always be transmitted
as ones within a single frame, enabling collision detection at least once per frame.
27.4.5.2 STS - Store Data to PDIBUS Data Space using Direct Addressing
The STS instruction is used to store data that are serially shifted into the physical layer shift register to locations within
the PDIBUS data space. The STS instruction is based on direct addressing, which means that the address must be given
as an argument to the instruction. Even though the protocol is based on byte-wise communication, the ST instruction
supports multiple-bytes addresses and data access. Four different address/data sizes are supported: single-byte, word
(two bytes), three-byte, and long (four bytes). Multiple-byte access is broken down internally into repeated single-byte
accesses, but this reduces protocol overhead. When using the STS instruction, the address byte(s) must be transmitted
before the data transfer.
27.4.5.3 LD - Load Data from PDIBUS Data Space using Indirect Addressing
The LD instruction is used to load data from the PDIBUS data space into the physical layer shift register for serial read
out. The LD instruction is based on indirect addressing (pointer access), which means that the address must be stored in
the pointer register prior to the data access. Indirect addressing can be combined with pointer increment. In addition to
reading data from the PDIBUS data space, the LD instruction can read the pointer register. Even though the protocol is
based on byte-wise communication, the LD instruction supports multiple-byte addresses and data access. Four different
address/data sizes are supported: single-byte, word (two bytes), three-byte, and long (four bytes). Multiple-byte access is
broken down internally into repeated single-byte accesses, but this reduces the protocol overhead.
27.4.5.5 LDCS - Load Data from PDI Control and Status Register Space
The LDCS instruction is used to load data from the PDI control and status registers into the physical layer shift register
for serial read out. The LDCS instruction supports only direct addressing and single-byte access.
27.4.5.6 STCS - Store Data to PDI Control and Status Register Space
The STCS instruction is used to store data that are serially shifted into the physical layer shift register to locations within
the PDI control and status registers. The STCS instruction supports only direct addressing and single-byte access.
LD 0 0 1 0
Size A - Address size (direct access)
0 0 Byte
0 1 Word (2 Bytes)
ST 0 1 1 0
1 0 3 Bytes
1 1 Long (4 Bytes)
CS Address
Ptr - Pointer access (indirect access)
0 0 *(ptr)
LDCS 1 0 0 0
0 1 *(ptr++)
1 0 ptr
STCS
1 1 ptr++ - Reserved
1 1 0 0
Bit 7 6 5 4 3 2 1 0
+0x00 – – – – – – NVMEN –
Read/Write R R R R R R R/W R
Initial Value 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
+0x01 RESET[7:0]
Read/Write R/W R/W R/W R/W R/W R/W R/W R/W
Initial Value 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
+0x02 – – – – – GUARDTIME[2:0]
Read/Write R R R R R R/W R/W R/W
Initial Value 0 0 0 0 0 0 0 0
000 128
001 64
010 32
011 16
100 8
101 4
110 2
111 2
28.1 Features
Read and write access to all memory spaces from
External programmers
Application software self-programming
Self-programming and boot loader support
Read-while-write self-programming
CPU can run and execute code while flash is being programmed
Any communication interface can be used for program upload/download
External programming
Support for in-system and production programming
Programming through serial PDI or JTAG interface
High security with separate boot lock bits for:
External programming access
Boot loader section access
Application section access
Application table access
Reset fuse to select reset vector address to the start of the
Application section, or
Boot loader section
28.2 Overview
This chapter describes how to program the nonvolatile memory (NVM) in Atmel AVR XMEGA devices, and covers both
self-programming and external programming. The NVM consists of the flash program memory, user signature and
production signature rows, fuses and lock bits, and EEPROM data memory. For details on the actual memories, how
they are organized, and the register description for the NVM controller used to access the memories, refer to “Memories”
on page 20.
The NVM can be accessed for read and write from application software through self-programming and from an external
programmer. Accessing the NVM is done through the NVM controller, and the two methods of programming are similar.
Memory access is done by loading address and/or data to the selected memory or NVM controller and using a set of
commands and triggers that make the NVM controller perform specific tasks on the nonvolatile memory.
From external programming, all memory spaces can be read and written, except for the production signature row, which
can only be read. The device can be programmed in-system and is accessed through the PDI using the PDI or JTAG
physical interfaces. “External Programming” on page 336 describes PDI and JTAG in detail.
Self-programming and boot loader support allows application software in the device to read and write the flash, user
signature row and EEPROM, write the lock bits to a more secure setting, and read the production signature row and
fuses. The flash allows read-while-write self-programming, meaning that the CPU can continue to operate and execute
code while the flash is being programmed. “Self-programming and Boot Loader Support” on page 327 describes this in
detail.
For both self-programming and external programming, it is possible to run a CRC check on the flash or a section of the
flash to verify its content after programming.
The device can be locked to prevent reading and/or writing of the NVM. There are separate lock bits for external
programming access and self-programming access to the boot loader section, application section, and application table
section.
Alternative 2:
Fill the flash page buffer
Perform an atomic page erase and write
Alternative 2:
Fill the EEPROM page buffer with the selected number of bytes
Perform an atomic EEPROM page erase and write
Section being addressed during programming Section that can be read during programming CPU halted?
PAGEEND
FLASHEND
0x00 NO_OPERATION No operation / read flash -/(E)LPM -/N N -/N -/ Z-pointer -/Rd
Flash
0x2F ERASE_WRITE_FLASH_PAGE Erase and write flash page SPM N/Y(2) Y Y Z-pointer -
Application Section
0x25 ERASE_WRITE_APP_PAGE Erase and write application section page SPM N Y Y Z-pointer -
0x2D ERASE_WRITE_BOOT_PAGE Erase and write boot loader section page SPM Y Y Y Z-pointer -
Notes: 1. The flash range CRC command used byte addressing of the flash.
2. Will depend on the flash section (application or boot loader) that is actually addressed.
3. This command is qualified with the lock bits, and requires that the boot lock bits are unprogrammed.
4. When using a command that changes the normal behavior of the LPM command; READ_USER_SIG_ROW and READ_CALIB_ROW; it is recommended to
disable interrupts to ensure correct execution of the LPM instruction.
5. For consistency the name Calibration Row has been renamed to Production Signature Row throughout the document.
28.11.2.10 Erase and Write Application Section / Boot Loader Section Page
The erase and write application section page and erase and write boot loader section page commands are used to erase
one flash page and then write the flash page buffer into that flash page in the application section or boot loader section in
one atomic operation.
1. Load the Z-pointer with the flash page to write. The page address must be written to FPAGE. Other bits in the Z-
pointer will be ignored during this operation.
2. Load the NVM CMD register with the erase and write application section/boot loader section page command.
3. Execute the SPM instruction. This requires the timed CCP sequence during self-programming.
The BUSY flag in the NVM STATUS register will be set until the operation is finished. The FBUSY flag is set as long as
the flash is busy, and the application section cannot be accessed.
An invalid page address in the Z-pointer will abort the NVM command. The erase and write application section command
requires that the Z-pointer addresses the application section, and the erase and write boot section page command
requires that the Z-pointer addresses the boot loader section.
01 01
02 02
E2END E2PAGEEND
When EEPROM memory mapping is enabled, loading a data byte into the EEPROM page buffer can be performed
through direct or indirect store instructions. Only the least-significant bits of the EEPROM address are used to determine
locations within the page buffer, but the complete memory mapped EEPROM address is always required to ensure
correct address mapping. Reading from the EEPROM can be done directly using direct or indirect load instructions.
When a memory mapped EEPROM page buffer load operation is performed, the CPU is halted for two cycles before the
next instruction is executed.
When the EEPROM is memory mapped, the EEPROM page buffer load and EEPROM read functionality from the NVM
controller are disabled.
EEPROM
FLASH_BASE = 0x0800000
EPPROM_BASE = 0x08C0000
FUSE_BASE = 0x08F0020
DATAMEM_BASE = 0x1000000
DATAMEM
16 MB
APP_BASE = FLASH_BASE (mapped IO/SRAM)
BOOT_BASE = FLASH_BASE + SIZE_APPL
PROD_SIGNATURE_BASE = 0x008E0200
USER_SIGNATURE_BASE = 0x008E0400
0x1000000
FUSES
0x08F0020
SIGNATURE ROW
0x08E0200
0x08C1000
EEPROM
0x08C0000
BOOT SECTION
APPLICATION
SECTION
0x0800000 16 MB
0x0000000
1 BYTE
Change
CMD[6:0] Commands / Operation Trigger protected NVM busy
0x00 No operation - - -
Flash
Application Section
0x2D Erase and write boot loader section page PDI write N Y
EEPROM
FMULSU Rd,Rr Fractional Multiply Signed with Unsigned R1:R0 Rd x Rr<<1 (SU) Z,C 2
Branch instructions
PC(15:0) Z,
IJMP Indirect Jump to (Z) None 2
PC(21:16) 0
PC(15:0) Z,
EIJMP Extended Indirect Jump to (Z) None 2
PC(21:16) EIND
XMEGA AU [MANUAL]
Atmel-8331H-AVR-Xmega AU-12/2014 343
Mnemonics Operands Description Operation Flags #Clocks
PC(15:0) Z,
ICALL Indirect Call to (Z) None 2 / 3(1)
PC(21:16) 0
PC(15:0) Z,
EICALL Extended Indirect Call to (Z) None 3(1)
PC(21:16) EIND
SBIS A, b Skip if Bit in I/O Register Set If (I/O(A,b) =1) PC PC + 2 or 3 None 2/3/4
XMEGA AU [MANUAL]
Atmel-8331H-AVR-Xmega AU-12/2014 344
Mnemonics Operands Description Operation Flags #Clocks
LDS Rd, k Load Direct from data space Rd (k) None 2 (1)(2)
Rd (X)
LD Rd, X+ Load Indirect and Post-Increment None 1(1)(2)
X X+1
X X - 1, X-1
LD Rd, -X Load Indirect and Pre-Decrement None 2(1)(2)
Rd (X) (X)
Rd (Y)
LD Rd, Y+ Load Indirect and Post-Increment None 1(1)(2)
Y Y+1
Y Y-1
LD Rd, -Y Load Indirect and Pre-Decrement None 2(1)(2)
Rd (Y)
Rd (Z),
LD Rd, Z+ Load Indirect and Post-Increment None 1(1)(2)
Z Z+1
Z Z - 1,
LD Rd, -Z Load Indirect and Pre-Decrement None 2(1)(2)
Rd (Z)
(X) Rr,
ST X+, Rr Store Indirect and Post-Increment None 1(1)
X X+1
X X - 1,
ST -X, Rr Store Indirect and Pre-Decrement None 2(1)
(X) Rr
(Y) Rr,
ST Y+, Rr Store Indirect and Post-Increment None 1(1)
Y Y+1
Y Y - 1,
ST -Y, Rr Store Indirect and Pre-Decrement None 2(1)
(Y) Rr
(Z) Rr
ST Z+, Rr Store Indirect and Post-Increment None 1(1)
Z Z+1
Rd (Z),
LPM Rd, Z+ Load Program Memory and Post-Increment None 3
Z Z+1
XMEGA AU [MANUAL]
Atmel-8331H-AVR-Xmega AU-12/2014 345
Mnemonics Operands Description Operation Flags #Clocks
Temp Rd,
XCH Z, Rd Exchange RAM location Rd (Z), None 2
(Z) Temp
Temp Rd,
LAS Z, Rd Load and Set RAM location Rd (Z), None 2
(Z) Temp v (Z)
Temp Rd,
LAC Z, Rd Load and Clear RAM location Rd (Z), None 2
(Z) ($FFh – Rd) (Z)
Temp Rd,
LAT Z, Rd Load and Toggle RAM location Rd (Z), None 2
(Z) Temp (Z)
Rd(n+1) Rd(n),
LSL Rd Logical Shift Left Rd(0) 0, Z,C,N,V,H 1
C Rd(7)
Rd(n) Rd(n+1),
LSR Rd Logical Shift Right Rd(7) 0, Z,C,N,V 1
C Rd(0)
Rd(0) C,
ROL Rd Rotate Left Through Carry Rd(n+1) Rd(n), Z,C,N,V,H 1
C Rd(7)
Rd(7) C,
ROR Rd Rotate Right Through Carry Rd(n) Rd(n+1), Z,C,N,V 1
C Rd(0)
XMEGA AU [MANUAL]
Atmel-8331H-AVR-Xmega AU-12/2014 346
Mnemonics Operands Description Operation Flags #Clocks
XMEGA AU [MANUAL]
Atmel-8331H-AVR-Xmega AU-12/2014 347
31. Datasheet Revision History
Please note that the referring page numbers in this section are referred to this document. The referring revisions in this
section are referring to the document revision.
2 Changed RCOSC48M to USBRCOSC in Section 4.15.19 on page 40 and Section 4.20 on page 44.
4. Changed VCC to AVCC in “Internal Inputs” on page 304 and in “AC – Analog Comparator” on page 303 and onwards.
ADC: Updated Table 25-11 on page 298 to include INPUT[1:0]=11 (differential with gain). Table 22-12 from revision D
2
of the datasheet is removed.
Updated description of “PRGEN – General Power Reduction Register” on page 97: Bit 3 is reserved. The XMEGA C
2.
devices does not have EBI.
Updated description of “PRPC/D/E/F – Power Reduction Port C/D/E/F Register” on page 98. Bit 5 is reserved. The
3.
XMEGA C devices does not have USART1.
3. Added reference to “NVM Flash Commands” on page 328 in “Production Signature Row” on page 22.
4. Added information on consequences of leaving some fuses unprogrammed in “Fuses and Lockbits” on page 22.
5. Removed “+” from the register addresses in “Register Description – Production Signature Row” on page 36.
Updated “32kHz Ultra Low Power Oscillator” on page 75 and “32.768kHz Calibrated Oscillator” on page 75 by adding
6.
reference to “RTCCTRL – RTC Control Register” on page 83.
Removed references to slew rate control in “I/O Ports” on page 119. This feature is not present in the I/O module of
9.
the XMEGA C devices.
10. Updated Input sense block diagram, Figure 12-9 on page 125.
2. Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .3
3. Atmel AVR CPU . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7
3.1 Features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
3.2 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
3.3 Architectural Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
3.4 ALU - Arithmetic Logic Unit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
3.5 Program Flow . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
3.6 Instruction Execution Timing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
3.7 Status Register. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
3.8 Stack and Stack Pointer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
3.9 Register File . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
3.10 RAMP and Extended Indirect Registers. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
3.11 Accessing 16-bit Registers. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
3.12 Configuration Change Protection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
3.13 Fuse Lock. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
3.14 Register Descriptions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
3.15 Register Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
4. Memories . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .20
4.1 Features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
4.2 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
4.3 Flash Program Memory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
4.4 Fuses and Lockbits . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
4.5 Data Memory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
4.6 Internal SRAM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
4.7 EEPROM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
4.8 I/O Memory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
4.9 Data Memory and Bus Arbitration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
4.10 Memory Timing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
4.11 Device ID and Revision . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
4.12 I/O Memory Protection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
4.13 Register Description – NVM Controller . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
4.14 Register Descriptions – Fuses and Lock Bits. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
4.15 Register Description – Production Signature Row . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
4.16 Register Description – General Purpose I/O Memory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
4.17 Register Descriptions – MCU Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
4.18 Register Summary - NVM Controller . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
4.19 Register Summary - Fuses and Lock Bits . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
4.20 Register Summary - Production Signature Row . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
4.21 Register Summary – General Purpose I/O Registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
4.22 Register Summary – MCU Control. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
4.23 Interrupt Vector Summary – NVM Controller . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
XMEGA C [MANUAL] i
Atmel-8465H-AVR-XMEGA C-12/2014
5. DMAC - Direct Memory Access Controller . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .46
5.1 Features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
5.2 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
5.3 DMA Transaction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
5.4 Transfer Triggers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48
5.5 Addressing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48
5.6 Priority Between Channels . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48
5.7 Double Buffering . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48
5.8 Transfer Buffers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48
5.9 Error Detection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
5.10 Software Reset. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
5.11 Protection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
5.12 Interrupts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
5.13 Register Description – DMA Controller . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
5.14 Register Description – DMA Channel . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
5.15 Register Summary – DMA Controller . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60
5.16 Register Summary – DMA Channel . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60
5.17 DMA Interrupt Vector Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60
XMEGA C [MANUAL] ii
Atmel-8465H-AVR-XMEGA C-12/2014
8.4 Power Reduction Registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95
8.5 Minimizing Power Consumption . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95
8.6 Register Description – Sleep . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96
8.7 Register Description – Power Reduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97
8.8 Register Summary – Sleep . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99
8.9 Register Summary – Power Reduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99
XMEGA C [MANUAL] iv
Atmel-8465H-AVR-XMEGA C-12/2014
17.2 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 187
17.3 Register Descriptions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 189
17.4 Register Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 193
17.5 Interrupt Vector Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 193
XMEGA C [MANUAL] v
Atmel-8465H-AVR-XMEGA C-12/2014
21. USART . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .244
21.1 Features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 244
21.2 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 244
21.3 Clock Generation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 245
21.4 Frame Formats. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 249
21.5 USART Initialization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 250
21.6 Data Transmission - The USART Transmitter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 250
21.7 Data Reception - the USART Receiver . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 250
21.8 Asynchronous Data Reception. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 251
21.9 Fractional Baud Rate Generation. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 254
21.10 USART in Master SPI Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 256
21.11 USART SPI vs. SPI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 256
21.12 Multiprocessor Communication Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 257
21.13 IRCOM Mode of Operation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 257
21.14 DMA Support . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 257
21.15 Register Description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 258
21.16 Register Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 263
21.17 Interrupt Vector Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 263
XMEGA C [MANUAL] vi
Atmel-8465H-AVR-XMEGA C-12/2014
25.9 ADC Clock and Conversion Timing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 285
25.10 ADC Input Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 288
25.11 DMA Transfer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 289
25.12 Interrupts and Events . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 289
25.13 Calibration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 289
25.14 Synchronous Sampling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 289
25.15 Register Description – ADC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 290
25.16 Register Description - ADC Channel . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 296
25.17 Register Summary – ADC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 302
25.18 Register Summary – ADC Channel . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 302
25.19 Interrupt Vector Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 302
Table of Contents. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . i
Atmel Corporation 1600 Technology Drive, San Jose, CA 95110 USA T: (+1)(408) 441.0311 F: (+1)(408) 436.4200 | www.atmel.com
© 2014 Atmel Corporation. All rights reserved. / Rev.: 8465H–AVR–XMEGA C Datasheet –12/2014
Atmel®, Atmel logo and combinations thereof, AVR®, Enabling Unlimited Possibilities®, XMEGA®, QTouch®, and others are registered trademarks or trademarks of
Atmel Corporation or its subsidiaries. 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.