Atmel SAM D20J / SAM D20G / SAM D20E ARM-Based Embedded Flash Microcontroller PRELIMINARY DATASHEET Description The Atmel® SAM D20 family is a series of low-power, high-performance, ARM®-based embedded flash microcontrollers based on the ARM Cortex®-M0+ 32-bit processor. Operating at a maximum speed of 48MHz, and with a two-stage pipeline, single-cycle I/O access, single-cycle 32x32 multiplier, Event System and a fast and flexible interrupt controller, the SAM D20 series microcontrollers are highly efficient, reaching 2.14 Coremark/MHz – 0.93 DMIPS/MHz. All devices in the SAM D20 series contain multiple instances of the Serial Communication Interface (SERCOM). The SERCOM is a very flexible serial communication interface, configurable to operate as I2C, SPI or USART, giving developers extended flexibility not only in the mix of serial interfaces available, but also in PCB layout. Additionally, each SERCOM instance can be assigned to different I/O pins through I/O multiplexing, further increasing flexibility. The devices include multiple instances of 16-bit Timer/Counters (TC). Each TC can be individually programmed to perform frequency and waveform generation, accurate program execution timing and input capture with time and frequency measurement of digital signals. The TCs can be configured to operate in 8-bit and 16-bit modes, and two TCs can be cascaded to form a 32-bit TC. The SAM D20 series Power Manager (PM) has two software-selectable sleep modes, idle and standby. The standby mode supports SleepWalking functionality, by which a peripheral can be selectively activated based on events, even when the peripheral clock is stopped. In addition the Event System (EVSYS) supports asynchronous events, allowing peripherals to receive, react to and send events, even in standby mode. The devices feature several oscillators, such as a 48MHz Digital Frequency Locked Loop (DFLL48M), 400kHz – 32MHz External Crystal Oscillator (XOSC), 8MHz Internal Oscillator (OSC8M), 32kHz Ultra-Low-Power Internal Oscillator (OSCULP32K), 32.768kHz High-Accuracy Internal Oscillator (OSC32K) and 32.768kHz Crystal Oscillator (XOSC32K). Any of these oscillators can be used as a source for the system clock. Different clock domains can be independently configured to run at different speeds, enabling the user to save power by running each peripheral at the optimal clock frequency, and thus maintain a high CPU speed and throughput while reducing system power consumption. 42129A–SAM–06/2013 Features z Processor ARM Cortex-M0+ CPU running at up to 48MHz z Single-cycle hardware multiplier Memories z 16/32/64/128/256KB in-system self-programmable flash z 2/4/8/16/32KB SRAM System z Power-on reset (POR) and brown-out detection (BOD) z Internal and external clock options with 48MHz Digital Frequency Locked Loop (DFLL48M) z External Interrupt Controller (EIC) z 16 external interrupts z One non-maskable interrupt z Two-pin Serial Wire Debug (SWD) programming, test and debugging interface Low Power z Idle and standby sleep modes z SleepWalking peripherals Peripherals z 8-channel Event System z Up to eight 16-bit Timer/Counters (TC), configurable as either: z z z z z z One 16-bit TC with compare/capture channels One 8-bit TC with compare/capture channels z One 32-bit TC with compare/capture channels, by using two TCs z z z z z z z z z 32-bit Real Time Counter (RTC) with clock/calendar function Watchdog Timer (WDT) CRC-32 generator Up to six Serial Communication Interfaces (SERCOM), each configurable to operate as either: z USART with full-duplex and single-wire half-duplex configuration 2 z I C z SPI One 12-bit, 350ksps Analog-to-Digital Converter (ADC) with up to 20 channels z Differential and single-ended channels z 1/2x to 16x gain stage z Automatic offset and gain error compensation z Oversampling and decimation in hardware to support 13-, 14-, 15- or 16-bit resolution 10-bit, 350ksps Digital-to-Analog Converter (DAC) Two Analog Comparators (AC) with window compare function Peripheral Touch Controller (PTC) z I/O z Up to 52 programmable I/O lines z Packages 64-pin TQFP, QFN 48-pin TQFP, QFN z 32-pin TQFP, QFN z Operating Voltage z 1.62V – 3.63V z z Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 2 1. Configuration Summary SAM D20J SAM D20G SAM D20E Flash 256/128/64/32/16KB 256/128/64/32/16KB 128/64/32/16KB SRAM 32/16/8/4/2KB 32/16/8/4/2KB 16/8/4/2KB Timer Counter (TC) instances 8 6 6 Waveform output channels per Timer Counter instance 2 2 2 Serial Communication Interface (SERCOM) instances 6 6 4 Analog-to-Digital Converter (ADC) channels 20 14 10 Analog Comparators (AC) 2 2 2 Digital-to-Analog Converter (DAC) instances 1 1 1 Real-Time Counter (RTC) instances 1 1 1 RTC alarms 1 1 1 1 32-bit value or 2 16-bit values 1 32-bit value or 2 16-bit values 1 32-bit value or 2 16-bit values General Purpose I/O-lines (GPIOs) 52 38 26 External Interrupt lines 16 16 16 16x16 12x10 10x6 RTC compare values Peripheral Touch Controller (PTC) X and Y lines Maximum speed Number of pins Packages 48MHz 64 48 32 QFN QFN QFN TQFP TQFP TQFP 32.768kHz crystal oscillator (XOSC32K) 0.4-32MHz crystal oscillator (XOSC) 32.768kHz high-accuracy internal oscillator (OSC32K) 32.768kHz ultra-low-power internal oscillator (OSCULP32K) 8MHz internal oscillator (OSC8M) 48MHz Digital Frequency Locked Loop (DFLL48M) Oscillators Event System channels 8 8 8 SW Debug Interface 1 1 1 Watchdog Timer (WDT) instances 1 1 1 Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 3 2. Ordering Information SAM D20 SAMD 20 E 14 A ‐ M U T Product Family Package Carrier SAMD = Base Line Microcontroller No character = Tray (Default) T = Tape and Reel Product Series 20 = Cortex M0+ CPU, Basic feature set Package Grade Pin count U = ‐40 ‐ 85°C Matte Sn Plating H = ‐40 ‐ 85°C NiPdAu Plating E = 32 pins G = 48 pins J = 64 pins Package Type Flash memory density A = TQFP M = QFN C = UBGA U = WLCSP 18 = 256KB 17 = 128KB 16 = 64KB 15 = 32KB 14 = 16KB Product Variant A = Default Variant 2.1 Ordering Information SAM D20E Ordering Code FLASH (bytes) SRAM (bytes) Package SAMD20E14A-AU Carrier Type Tray TQFP32 SAMD20E14A-AUT Tape & Reel 16K 2K SAMD20E14A-MU Tray QFN32 SAMD20E14A-MUT Tape & Reel SAMD20E15A-AU Tray TQFP32 SAMD20E15A-AUT Tape & Reel 32K 4K SAMD20E15A-MU Tray QFN32 SAMD20E15A-MUT Tape & Reel SAMD20E16A-AU Tray TQFP32 SAMD20E16A-AUT Tape & Reel 64K 8K SAMD20E16A-MU Tray QFN32 SAMD20E16A-MUT Tape & Reel Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 4 Ordering Code FLASH (bytes) SRAM (bytes) Package SAMD20E17A-AU Carrier Type Tray TQFP32 SAMD20E17A-AUT Tape & Reel 128K 16K SAMD20E17A-MU Tray QFN32 SAMD20E17A-MUT 2.2 Tape & Reel Ordering Information SAM D20G Ordering Code FLASH (bytes) SRAM (bytes) Package SAMD20G14A-AU Carrier Type Tray TQFP48 SAMD20G14A-AUT Tape & Reel 16K 2K SAMD20G14A-MU Tray QFN48 SAMD20G14A-MUT Tape & Reel SAMD20G15A-AU Tray TQFP48 SAMD20G15A-AUT Tape & Reel 32K 4K SAMD20G15A-MU Tray QFN48 SAMD20G15A-MUT Tape & Reel SAMD20G16A-AU Tray TQFP48 SAMD20G16A-AUT Tape & Reel 64K 8K SAMD20G16A-MU Tray QFN48 SAMD20G16A-MUT Tape & Reel SAMD20G17A-AU Tray TQFP48 SAMD20G17A-AUT Tape & Reel 128K 16K SAMD20G17A-MU Tray QFN48 SAMD20G17A-MUT Tape & Reel SAMD20G18A-AU Tray TQFP48 SAMD20G18A-AUT Tape & Reel 256K 32K SAMD20G18A-MU Tray QFN48 SAMD20G18A-MUT Tape & Reel Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 5 2.3 Ordering Information SAM D20J Ordering Code FLASH (bytes) SRAM (bytes) Package SAMD20J14A-AU Carrier Type Tray TQFP64 SAMD20J14A-AUT Tape & Reel 16K 2K SAMD20J14A-MU Tray QFN64 SAMD20J14A-MUT Tape & Reel SAMD20J15A-AU Tray TQFP64 SAMD20J15A-AUT Tape & Reel 32K 4K SAMD20J15A-MU Tray QFN64 SAMD20J15A-MUT Tape & Reel SAMD20J16A-AU Tray TQFP64 SAMD20J16A-AUT Tape & Reel 64K 8K SAMD20J16A-MU Tray QFN64 SAMD20J16A-MUT Tape & Reel SAMD20J17A-AU Tray TQFP64 SAMD20J17A-AUT Tape & Reel 128K 16K SAMD20J17A-MU Tray QFN64 SAMD20J17A-MUT Tape & Reel SAMD20J18A-AU Tray TQFP64 SAMD20J18A-AUT Tape & Reel 256K 32K SAMD20J18A-MU Tray QFN64 SAMD20J18A-MUT Tape & Reel Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 6 3. About This Document 3.1 Conventions 3.1.1 Numerical Notation Table 3-1. 3.1.2 Symbol Description 165 Decimal number 0b0101 Binary number (example 0b0101 = 5 decimal) 0101 Binary numbers are given without suffix if unambiguous 0x3B24 Hexadecimal number X Represents an unknown or don't care value Z Represents a high-impedance (floating) state for either a signal or a bus Memory Size and Type Table 3-2. 3.1.3 Numerical Notation Memory Size and Bit Rate Symbol Description KB/kbyte kilobyte (210 = 1024) MB/Mbyte megabyte (220 = 1024*1024) GB/Gbyte gigabyte (230 = 1024*1024*1024) b bit (binary 0 or 1) B byte (8 bits) 1kbit/s 1,000 bit/s rate (not 1,024 bit/s) 1Mbit/s 1,000,000 bit/s rate 1Gbit/s 1,000,000,000 bit/s rate word 32 bit half-word 16 bit Frequency and Time Table 3-3. Frequency and Time Symbol Description kHz 1kHz = 103Hz = 1,000Hz MHz 106 = 1,000,000Hz GHz 109 = 1,000,000,000Hz s second Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 7 3.1.4 Table 3-3. Frequency and Time (Continued) Symbol Description ms millisecond µs microsecond ns nanosecond Registers and Bits Table 3-4. 3.2 Register and Bit Mnemonics Symbol Description R/W Read/Write accessible register bit. The user can read from and write to this bit. R Read-only accessible register bit. The user can only read this bit. Writes will be ignored. W Write-only accessible register bit. The user can only write this bit. Reading this bit will return an undefined value. BIT Bit names are shown in uppercase. (Example ENABLE) FIELD[n:m] A set of bits from bit n down to m. (Example: PINA[3:0] = {PINA3, PINA2, PINA1, PINA0} Reserved Reserved bits are unused and reserved for future use. For compatibility with future devices, always write reserved bits to zero when the register is written. Reserved bits will always return zero when read. PERIPHERALi If several instances of a peripheral exist, the peripheral name is followed by a number to indicate the number of the instance in the range 0-n. PERIPHERAL0 denotes one specific instance. Reset Value of a register after a power reset. This is also the value of registers in a peripheral after performing a software reset of the peripheral, except for the Debug Control registers. SET/CLR Registers with SET/CLR suffix allows the user to clear and set bits in a register without doing a readmodify-write operation. These registers always come in pairs. Writing a one to a bit in the CLR register will clear the corresponding bit in both registers, while writing a one to a bit in the SET register will set the corresponding bit in both registers. Both registers will return the same value when read. If both registers are written simultaneously, the write to the CLR register will take precedence. Acronyms and Abbreviations Table 1-5 contains acronyms and abbreviations used in this document. Table 3-5. Acronyms and Abbreviations Abbreviation Description AC Analog Comparator ADC Analog-to-Digital Converter ADDR Address AHB AMBA Advanced High-performance Bus AMBA® Advance Microcontroller Bus Architecture AHB AMBA Advanced High-Performance Bus Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 8 Table 3-5. Acronyms and Abbreviations (Continued) Abbreviation Description APB AMBA Advanced Peripheral Bus AREF Analog reference voltage BLB Boot Lock Bit BOD Brown-out detector CAL Calibration CC Compare/Capture CLK Clock CRC Cyclic Redundancy Check CTRL Control DAC Digital-to-Analog Converter DAP Debug Access Port DFLL Digital Frequency Locked Loop DSU Device Service Unit EEPROM Electrically Erasable Programmable Read-Only Memory EIC External Interrupt Controller EVSYS Event System GCLK Generic Clock Controller GND Ground GPIO General Purpose Input/Output I2C Inter-Integrated Circuit IF Interrupt flag INT Interrupt MBIST Memory built-in self-test MEM-AP Memory Access Port NMI Non-maskable interrupt NVIC Nested Vector Interrupt Controller NVM Non-Volatile Memory NVMCTRL Non-Volatile Memory Controller OSC Oscillator PAC Peripheral Access Controller PC Program Counter PER Period PM Power Manager Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 9 Table 3-5. Acronyms and Abbreviations (Continued) Abbreviation Description POR Power-on reset PTC Peripheral Touch Controller PWM Pulse Width Modulation RAM Random-Access Memory REF Reference RTC Real-Time Counter RX Receiver/Receive SERCOM Serial Communication Interface SMBus™ System Management Bus SP Stack Pointer SPI Serial Peripheral Interface SRAM Static Random-Access Memory SYSCTRL System Controller SWD Serial Wire Debug TC Timer/Counter TX Transmitter/Transmit ULP Ultra-low power USART Universal Synchronous and Asynchronous Serial Receiver and Transmitter VDD Common voltage to be applied to VDDIO, VDDIN and VDDANA VDDIN Digital supply voltage VDDIO Digital supply voltage VDDANA Analog supply voltage VREF Voltage reference WDT Watchdog Timer XOSC Crystal Oscillator Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 10 4. Block Diagram SWCLK CORTEX-M0+ PROCESSOR Fmax 48MHz SERIAL WIRE SWDIO DEVICE SERVICE UNIT M M HIGH SPEED BUS MATRIX S S AHB/APB BRIDGE A 32/16/8/4KB RAM S AHB/APB BRIDGE C S NVM 256/128/64/32KB CONTROLLER FLASH S PERIPHERAL ACCESS CONTROLLER AHB/APB BRIDGE B PERIPHERAL ACCESS CONTROLLER PERIPHERAL ACCESS CONTROLLER VREF BOD33 OSCULP32K BOD12 OSC32K XOSC32K OSC8M XOSC DFLL48M POWER MANAGER CLOCK CONTROLLER RESET RESET CONTROLLER GCLK_IO[7:0] SLEEP CONTROLLER PAD[3:0] 8 x TIMER COUNTER 8 x(See Timer Counter Note1) WO[1:0] AIN[19:0] ADC WATCHDOG TIMER EXTERNAL INTERRUPT CONTROLLER VREFA VREFB 2 ANALOG COMPARATORS GENERIC CLOCK REAL TIME COUNTER EXTINT[15:0] NMI 66xxSERCOM SERCOM PORT XIN32 XOUT32 XIN XOUT VREG EVENT SYSTEM PORT SYSTEM CONTROLLER AIN[3:0] VOUT DAC PERIPHERAL TOUCH CONTROLLER VREFP X[15:0] Y[15:0] Notes: 1. Some products have different number of SERCOM instances, Timer/Counter instances, PTC signals and ADC signals. Refer to “Configuration Summary” on page 3 for details. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 11 Pinout Diagrams 5.1 SAM D20J 64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 PB03 PB02 PB01 PB00 PB31 PB30 PA31 PA30 VDDIN VDDCOR GND PA28 RESET PA27 PB23 PB22 5. 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 VDDIO GND PA25 PA24 PA23 PA22 PA21 PA20 PB17 PB16 PA19 PA18 PA17 PA16 VDDIO GND PA08 PA09 PA10 PA11 VDDIO GND PB10 PB11 PB12 PB13 PB14 PB15 PA12 PA13 PA14 PA15 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 PA00 PA01 PA02 PA03 PB04 PB05 GNDANA VDDANA PB06 PB07 PB08 PB09 PA04 PA05 PA06 PA07 DIGITAL PIN ANALOG PIN OSCILLATOR GROUND INPUT SUPPLY REGULATED OUTPUT SUPPLY RESET PIN Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 12 48 47 46 45 44 43 42 41 40 39 38 37 PB03 PB02 PA31 PA30 VDDIN VDDCORE GND PA28 RESET PA27 PB23 PB22 SAM D20G 36 35 34 33 32 31 30 29 28 27 26 25 1 2 3 4 5 6 7 8 9 10 11 12 VDDIO GND PA25 PA24 PA23 PA22 PA21 PA20 PA19 PA18 PA17 PA16 13 14 15 16 17 18 19 20 21 22 23 24 PA00 PA01 PA02 PA03 GNDANA VDDANA PB08 PB09 PA04 PA05 PA06 PA07 PA08 PA09 PA10 PA11 VDDIO GND PB10 PB11 PA12 PA13 PA14 PA15 5.2 DIGITAL PIN ANALOG PIN OSCILLATOR GROUND INPUT SUPPLY REGULATED OUTPUT SUPPLY RESET PIN Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 13 32 31 30 29 28 27 26 25 PA31 PA30 VDDIN VDDCORE GND PA28 RESET PA27 SAM D20E 24 23 22 21 20 19 18 17 1 2 3 4 5 6 7 8 PA25 PA24 PA23 PA22 PA19 PA18 PA17 PA16 9 10 11 12 13 14 15 16 PA00 PA01 PA02 PA03 PA04 PA05 PA06 PA07 VDDANA GND PA08 PA09 PA10 PA11 PA14 PA15 5.3 DIGITAL PIN ANALOG PIN OSCILLATOR GROUND INPUT SUPPLY REGULATED OUTPUT SUPPLY RESET PIN Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 14 6. I/O Multiplexing and Considerations 6.1 Multiplexed Signals Each pin is either controlled by the PORT as a general purpose I/O or can be assigned to one of the peripheral functions A, B, C, D, E, F, G or H. By default, each pin is controlled by the PORT. To enable a peripheral function on a pin, the Peripheral Multiplexer Enable bit in the Pin Configuration register corresponding to that pin (PINCFGn.PMUXEN, n = 031) in the PORT must be written to one. The selection of peripheral function A to H is done by writing to the Peripheral Multiplexing Odd and Even bits in the Peripheral Multiplexing register (PMUXn.PMUXE/O) in the PORT. Refer to “PORT” on page 289 for details on how to configure the I/O multiplexing. Table 6-1 describes the peripheral signals multiplexed to the PORT I/O lines. Table 6-1. PORT Controller Function Multiplexing (Sheet 1 of 2) Pin B(1) A SAM SAM SAM I/O D20E D20G D20J Line Supply Type EIC REF ADC AC C PTC DAC D SERCOM(2) E F TC(3) G H AC/GCLK 1 1 1 PA00 VDDANA EXTINT[0] SERCOM1 PAD[0] TC2/WO[0] 2 2 2 PA01 VDDANA EXTINT[1] SERCOM1 PAD[1] TC2/WO[1] 3 3 3 PA02 VDDANA EXTINT[2] AIN[0] Y[0] 4 PA03 VDDANA ADC/VREFA EXTINT[3] AIN[1] DAC/VREFP Y[1] 5 PB04 VDDANA EXTINT[4] AIN[12] Y[10] 6 PB05 VDDANA EXTINT[5] AIN[13] Y[11] 9 PB06 VDDANA EXTINT[6] AIN[14] Y[12] 10 PB07 VDDANA EXTINT[7] AIN[15] Y[13] 7 11 PB08 VDDANA EXTINT[8] AIN[2] Y[14] SERCOM4 PAD[0] TC4/WO[0] 8 12 PB09 VDDANA EXTINT[9] AIN[3] Y[15] SERCOM4 PAD[1] TC4/WO[1] 5 9 13 PA04 VDDANA EXTINT[4] AIN[4] AIN[0] Y[2] SERCOM0 PAD[0] TC0/WO[0] 6 10 14 PA05 VDDANA EXTINT[5] AIN[5] AIN[1] Y[3] SERCOM0 PAD[1] TC0/WO[1] 7 11 15 PA06 VDDANA EXTINT[6] AIN[6] AIN[2] Y[4] SERCOM0 PAD[2] TC1/WO[0] 8 12 16 PA07 VDDANA EXTINT[7] AIN[7] AIN[3] Y[5] SERCOM0 PAD[3] TC1/WO[1] 11 13 17 PA08 VDDIO I2C NMI AIN[16] X[0] SERCOM0 SERCOM2 TC0/WO[0] PAD[0] PAD[0] 12 14 18 PA09 VDDIO I2C EXTINT[9] AIN[17] X[1] SERCOM0 SERCOM2 TC0/WO[1] PAD[1] PAD[1] 13 15 19 PA10 VDDIO EXTINT[10] AIN[18] X[2] SERCOM0 SERCOM2 TC1/WO[0] PAD[2] PAD[2] GCLK_IO[4] 14 16 20 PA11 VDDIO EXTINT[11] AIN[19] X[3] SERCOM0 SERCOM2 TC1/WO[1] PAD[3] PAD[3] GCLK_IO[5] 19 23 PB10 VDDIO EXTINT[10] SERCOM4 PAD[2] TC5/WO[0] GCLK_IO[4] 20 24 PB11 VDDIO EXTINT[11] SERCOM4 PAD[3] TC5/WO[1] GCLK_IO[5] 25 PB12 VDDIO I2C EXTINT[12] X[12] SERCOM4 PAD[0] TC4/WO[0] GCLK_IO[6] 26 PB13 VDDIO I2C EXTINT[13] X[13] SERCOM4 PAD[1] TC4/WO[1] GCLK_IO[7] 27 PB14 VDDIO EXTINT[14] X[14] SERCOM4 PAD[2] TC5/WO[0] GCLK_IO[0] 4 4 ADC VREFB VOUT Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 15 Table 6-1. PORT Controller Function Multiplexing (Sheet 2 of 2) Pin B(1) A SAM SAM SAM I/O D20E D20G D20J Line Supply Type 28 PB15 VDDIO 21 29 PA12 VDDIO I2C 22 30 PA13 VDDIO I2C 15 23 31 PA14 16 24 32 17 25 18 EIC REF ADC EXTINT[15] AC C PTC DAC X[15] D SERCOM(2) SERCOM4 PAD[3] E F TC(3) G H AC/GCLK TC5/WO[1] GCLK_IO[1] EXTINT[12] SERCOM2 SERCOM4 TC2/WO[0] PAD[0] PAD[0] AC/CMP[0] EXTINT[13] SERCOM2 SERCOM4 TC2/WO[1] PAD[1] PAD[1] AC/CMP[1] VDDIO EXTINT[14] SERCOM2 SERCOM4 TC3/WO[0] PAD[2] PAD[2] GCLK_IO[0] PA15 VDDIO EXTINT[15] SERCOM2 SERCOM4 TC3/WO[1] PAD[3] PAD[3] GCLK_IO[1] 35 PA16 VDDIO EXTINT[0] X[4] SERCOM1 SERCOM3 PAD[0] PAD[0] TC2/WO[0] GCLK_IO[2] 26 36 PA17 VDDIO EXTINT[1] X[5] SERCOM1 SERCOM3 PAD[1] PAD[1] TC2/WO[1] GCLK_IO[3] 19 27 37 PA18 VDDIO EXTINT[2] X[6] SERCOM1 SERCOM3 PAD[2] PAD[2] TC3/WO[0] AC/CMP[0] 20 28 38 PA19 VDDIO EXTINT[3] X[7] SERCOM1 SERCOM3 PAD[3] PAD[3] TC3/WO[1] AC/CMP[1] 39 PB16 VDDIO I2C EXTINT[0] SERCOM5 PAD[0] TC6/WO[0] GCLK_IO[2] 40 PB17 VDDIO I2C EXTINT[1] SERCOM5 PAD[1] TC6/WO[1] GCLK_IO[3] 29 41 PA20 VDDIO EXTINT[4] X[8] SERCOM5 SERCOM3 TC7/WO[0] PAD[2] PAD[2] GCLK_IO[4] 30 42 PA21 VDDIO EXTINT[5] X[9] SERCOM5 SERCOM3 TC7/WO[1] PAD[3] PAD[3] GCLK_IO[5] 21 31 43 PA22 VDDIO I2C EXTINT[6] X[10] SERCOM3 SERCOM5 PAD[0] PAD[0] TC4/WO[0] GCLK_IO[6] 22 32 44 PA23 VDDIO I2C EXTINT[7] X[11] SERCOM3 SERCOM5 PAD[1] PAD[1] TC4/WO[1] GCLK_IO[7] 23 33 45 PA24 VDDIO EXTINT[12] SERCOM3 SERCOM5 PAD[2] PAD[2] TC5/WO[0] 24 34 46 PA25 VDDIO EXTINT[13] SERCOM3 SERCOM5 PAD[3] PAD[3] TC5/WO[1] 37 49 PB22 VDDIO EXTINT[6] SERCOM5 PAD[2] TC7/WO[0] GCLK_IO[0] 38 50 PB23 VDDIO EXTINT[7] SERCOM5 PAD[3] TC7/WO[1] GCLK_IO[1] 25 39 51 PA27 VDDIO EXTINT[15] 27 41 53 PA28 VDDIO EXTINT[8] GCLK_IO[0] GCLK_IO[0] 31 45 57 PA30 VDDIO EXTINT[10] SERCOM1 PAD[2] 32 46 58 PA31 VDDIO EXTINT[11] SERCOM1 PAD[3] TC1/WO[1] 59 PB30 VDDIO I2C EXTINT[14] SERCOM5 PAD[0] TC0/WO[0] 60 PB31 VDDIO I2C EXTINT[15] SERCOM5 PAD[1] TC0/WO[1] 61 PB00 VDDANA EXTINT[0] AIN[8] Y[6] SERCOM5 PAD[2] TC7/WO[0] 62 PB01 VDDANA EXTINT[1] AIN[9] Y[7] SERCOM5 PAD[3] TC7/WO[1] 47 63 PB02 VDDANA EXTINT[2] AIN[10] Y[8] SERCOM5 PAD[0] TC6/WO[0] 48 64 PB03 VDDANA EXTINT[3] AIN[11] Y[9] SERCOM5 PAD[1] TC6/WO[1] Note: TC1/WO[0] SWCLK GCLK_IO[0] 1. All analog pad functions are on peripheral function B. Peripheral function B must be selected to disable the digital control of the pad. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 16 2. Only some pads can be used in SERCOM I2C mode. Check the Type column before trying to use a SERCOM pad in I2C mode. 3. Note that TC6 and TC7 are not supported on the SAM D20G. Refer to “Configuration Summary” on page 3 for details. 6.2 Other Functions 6.2.1 Oscillator Pinout The oscillators are not mapped to the normal PORT functions and their multiplexing are controlled by registers in the System Controller (SYSCTRL). Refer to “SYSCTRL – System Controller” on page 132 for more information. Oscillator Supply XOSC VDDIO XOSC32K 6.2.2 Signal I/O Line XIN PA14 XOUT PA15 XIN32 PA00 XOUT32 PA01 VDDANA Serial Wire Debug Interface Pinout Only the SWCLK pin is mapped to the normal PORT functions. A debugger cold-plugging or hot-plugging detection will automatically switch the SWDIO port to the SWDIO function. Refer to “DSU – Device Service Unit” on page 41 for more information. Signal Supply I/O Line SWCLK VDDIO PA30 SWDIO VDDIO PA31 Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 17 7. Signal Descriptions List The following table gives details on signal names classified by peripheral. Signal Name Function Type Active Level Comments Analog Comparators - AC AIN3 - AIN0 Analog Inputs Analog CMP1 - CMP0 Comparator Outputs Digital Analog Digital Converter - ADC AIN19 - AIN0 ADC Analog Inputs Analog VREFP ADC Voltage External Reference Analog Digital Analog Converter - DAC VOUT DAC Voltage output Analog VREFP DAC Voltage External Reference Analog External Interrupt Controller - EIC EXTINT15 - EXTINT0 External Interrupts Input NMI External Non-Maskable Interrupt Input Generic Clock Generator - GCLK GCLK_IO7 - GCLK_IO0 Generic Clock (source clock or generic clock generator output) I/O Power Manager - PM RESET_N Reset Input Low Serial Communication Interface - SERCOMx PAD3 - PAD0 SERCOM I/O Pads I/O System Control - SYSCTRL XIN Crystal Input Analog/ Digital XIN32 32kHz Crystal Input Analog/ Digital XOUT Crystal Output Analog XOUT32 32kHz Crystal Output Analog Timer Counter - TCx WO1 - WO0 Waveform Outputs Output Low Peripheral Touch Controller - PTC X15-X0 PTC Input Analog Y15-Y0 PTC Input Analog Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 18 Signal Name Function Type Active Level Comments General Purpose I/O - PORT PA25 - PA00 Parallel I/O Controller I/O Port A I/O PA28 - PA27 Parallel I/O Controller I/O Port A I/O PA31 - PA30 Parallel I/O Controller I/O Port A I/O PB17 - PB00 Parallel I/O Controller I/O Port B I/O PB23 - PB22 Parallel I/O Controller I/O Port B I/O PB31 - PB30 Parallel I/O Controller I/O Port B I/O Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 19 ADC PA[7:2] VOLTAGE REGULATOR PB[31:10] OSC8M PA[13:8] XOSC AC PB[9:0] VDDIO VDDIN GND Power Domain Overview VDDCORE 8.1 GNDANA Power Supply and Start-Up Considerations VDDANA 8. PA[15:14] PA[31:16] DAC PTC Digital Logic (CPU, peripherals) PA[1:0] XOSC32K POR OSC32K BOD33 OSCULP32K BOD12 8.2 Power Supply Considerations 8.2.1 Power Supplies DFLL48M The Atmel® SAM D20 has several different power supply pins: z VDDIO: Powers I/O lines, OSC8M and XOSC. Voltage is 1.62V to 3.63V, nominal. z VDDIN: Powers I/O lines and the internal regulator. Voltage is 1.62V to 3.63V, nominal. z VDDANA: Powers I/O lines and the ADC, AC, DAC, PTC, OSCULP32K, OSC32K, XOSC32K. Voltage is 1.62V to 3.63V, nominal. z VDDCORE: Internal regulated voltage output. Powers the core, memories and peripherals. Voltage is 1.2V, nominal. The same voltage must be applied to both VDDIN, VDDIO and VDDANA. This common voltage is referred to as VDD in the datasheet. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 20 The ground pins, GND, are common to VDDCORE, VDDIO and VDDIN. The ground pin for VDDANA is GNDANA. For decoupling recommendations for the different power supplies, refer to the schematic checklist. 8.2.2 Voltage Regulator An embedded voltage regulator supplies all the digital logic. The voltage regulator features two different modes: 8.2.3 z Normal mode: To be used when the CPU and peripherals are running z Low Power (LP) mode: To be used when the regulator draws small static current. It can be used in standby mode Typical Powering Schematics The SAM D20 uses a single supply from 1.62V to 3.63V. This is the recommended power supply connection. Figure 8-1. Power Supply Connection SAM D20 Main Supply (1.62V — 3.63V) VDDIO VDDANA VDDIN VDDCORE GND GNDANA 8.2.4 Power-Up Sequence 8.2.4.1 Minimum Rise Rate The integrated power-on reset (POR) circuitry monitoring the VDDANA power supply requires a minimum rise rate. 8.2.4.2 Maximum Rise Rate To avoid risk of latch-up, the rise rate of the power supply must not exceed the values described in Electrical Characteristics. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 21 8.3 Start-Up Considerations This section summarizes the boot sequence of the SAM D20. The behavior after power-up is controlled by the Power Manager. For specific details, refer to “PM – Power Manager” on page 105. 8.3.1 Starting of Clocks After power-up, the device will be held in its initial state by the power-on reset circuitry, until the power has stabilized throughout the device. Once the power has stabilized, the device will use a 1MHz clock. This clock is derived from the 8MHz Internal Oscillator (OSC8M), which is divided by eight and used as a clock source for generic clock generator 0. Generic clock generator 0 is the main clock for the Power Manager (PM). On system start-up, the 48MHz Digital Frequency Locked Loop (DFLL48M) is disabled. Some synchronous system clocks are active, allowing software execution. Refer to the “Clock Mask Register” section in “PM – Power Manager” on page 105 for the list of peripheral clocks running. Synchronous system clocks that are running are by default not divided and receive a 1MHz clock through generic clock generator 0. All the generic clocks are disabled except GCLK_WDT, which is used by the Watchdog Timer (WDT). 8.3.2 I/O Pins After power-up, the I/O pins are tri-stated. 8.3.3 Fetching of Initial Instructions After reset has been released, the CPU starts fetching PC and SP values from the reset address, which is 0x00000000. This address points to the first executable address in the internal flash. The code read from the internal flash is free to configure the clock system and clock sources. Refer to “PM – Power Manager” on page 105, “GCLK – Generic Clock Controller” on page 83 and “SYSCTRL – System Controller” on page 132 for details. Refer to the ARM Architecture Reference Manual for more information on CPU startup. 8.4 Power-On Reset and Brown-Out Detector The SAM D20 embeds three features to monitor, warn and/or reset the device: 8.4.1 z POR: Power-on reset on VDDANA z BOD33: Brown-out detector on VDDANA z BOD12: Brown-out detector on VDDCORE Power-On Reset on VDDANA POR monitors VDDANA. It is always activated and monitors voltage at startup and also during all the sleep modes. If VDDANA goes below the threshold voltage, the entire chip is reset. 8.4.2 Brown-Out Detector on VDDANA BOD33 monitors VDDANA. Refer to “SYSCTRL – System Controller” on page 132 for details. 8.4.3 Brown-Out Detector on VDDCORE Once the device has started up, BOD12 monitors the internal VDDCORE. Refer to “SYSCTRL – System Controller” on page 132 for details. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 22 9. Product Mapping Figure 9-1. SAM D20 Product Mapping Global Memory Space 0x00000000 Code 0x00000000 Internal flash Code 0x20000000 0x00040000 Reserved SRAM 0x1FFFFFFF SRAM 0x20008000 0x20000000 Undefined 0x40000000 Peripheral Bridge C Internal SRAM 0x42000000 PAC2 0x20008000 0x42000400 Peripherals Peripherals 0x40000000 0x43000000 SERCOM0 Peripheral Bridge A Reserved 0x42000C00 SERCOM1 0x42001000 0x41000000 0x60000000 SERCOM2 Peripheral Bridge B Undefined 0x42001400 SERCOM3 0x42000000 0x60000200 Reserved System 0x42001800 SERCOM4 Peripheral Bridge C 0xE0000000 EVSYS 0x42000800 0x42001C00 SERCOM5 0x42FFFFFF 0x42002000 0xFFFFFFFF TC0 System 0x42002400 0xE0000000 TC1 Reserved 0x42002800 0xE000E000 TC2 SCS 0x42002C00 0xE000F000 TC3 Reserved Peripheral Bridge A 0x40000000 PAC0 0x42003000 0xE00FF000 TC4 ROM Table 0x42003400 0xE0100000 TC5 Reserved 0xFFFFFFFF 0x40000400 0x42003800 TC6 PM 0x40000800 SYSCTRL Peripheral Bridge B 0x42004800 0x41004000 0x41004400 0x42004C00 PORT EIC 0x41004800 0x40001C00 DAC NVMCTRL RTC 0x40001800 AC DSU WDT Reserved 0x40FFFFFF 0x42004400 0x41002000 0x40001400 ADC PAC1 GCLK 0x40001000 TC7 0x42004000 0x41000000 0x40000C00 0x42003C00 PTC 0x42005000 Reserved 0x41FFFFFF Reserved 0x42FFFFFF This figure represents the full configuration of the Atmel® SAM D20 with maximum flash and SRAM capabilities and a full set of peripherals. Refer to the “Configuration Summary” on page 3 for details. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 23 10. Memories 10.1 Embedded Memories 10.2 z Internal high-speed flash z Internal high-speed RAM, single-cycle access at full speed z Dedicated flash area for EEPROM emulation Physical Memory Map The High-Speed bus is implemented as a Bus Matrix. Refer to “High-Speed Bus Matrix” on page 29 for details. All HighSpeed bus addresses are fixed, and they are never remapped in any way, even during boot. The 32-bit physical address space is mapped as follows: Table 10-1. SAM D20 Physical Memory Map(1) Size Memory Start address SAMD20x18 SAMD20x17 SAMD20x16 SAMD20x15 SAMD20x14 Embedded Flash 0x00000000 256KB 128KB 64KB 32KB 16KB Embedded SRAM 0x20000000 32KB 16KB 8KB 4KB 2KB Peripheral Bridge A 0x40000000 64KB 64KB 64KB 64KB 64KB Peripheral Bridge B 0x41000000 64KB 64KB 64KB 64KB 64KB Peripheral Bridge C 0x42000000 64KB 64KB 64KB 64KB 64KB Note: 1. x = G, J or E. SAMD20E18 is not available. Refer to “Ordering Information SAM D20” on page 4 for details. Table 10-2. Flash Memory Parameters(1) Device Flash Size Number of Pages (NVMP) Page Size (PSZ) Row Size SAMD20x18 256KB 4096 64 bytes 4 pages = 256 bytes SAMD20x17 128KB 2048 64 bytes 4 pages = 256 bytes SAMD20x16 64KB 1024 64 bytes 4 pages = 256 bytes SAMD20x15 32KB 512 64 bytes 4 pages = 256 bytes SAMD20x14 16KB 256 64 bytes 4 pages = 256 bytes Notes: 1. x = G, J or E. SAMD20E18 is not available. Refer to “Ordering Information SAM D20” on page 4 for details. 2. The number of pages (NVMP) and page size (PSZ) can be read from the NVM Pages and Page Size bits in the NVM Parameter register in the NVMCTRL (PARAM.NVMP and PARAM.PSZ, respectively). Refer to PARAM for details. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 24 10.3 Non-Volatile Memory (NVM) User Row Mapping The NVM User Row contains calibration data that are automatically read at device power on. The NVM User Row can be read at address 0x804000. To write the NVM User Row refer to “NVMCTRL – Non-Volatile Memory Controller” on page 266. Note that when writing to the User Row the values will only be loaded at device reset. Table 10-3. NVM User Row Mapping Bit Position Name Description 2:0 BOOTPROT 3 Reserved 6:4 EEPROM 7 Reserved 13:8 BOD33 Level BOD33 Threshold Level (BOD33.LEVEL) at power on. Refer to BOD33 register. 14 BOD33 Enable BOD33 Enable at power on. Refer to BOD33 register. 16:15 BOD33 Action BOD33 Action at power on. Refer to BOD33 register. 21:17 BOD12 Level BOD12 Threshold Level at power on. Refer to BOD12 register. 22 BOD12 Enable BOD12 Enable at power on. Refer to BOD12 register. 24:23 BOD12 Action BOD12 Action at power on. Refer to BOD12 register. 25 WDT Enable WDT Enable at power on. Refer to WDT CTRL register. 26 WDT Always-On WDT Always-On at power on. Refer to WDT CTRL register. 30:27 WDT Period WDT Period at power on. Refer to WDT CONFIG register. 34:31 WDT Window WDT Window mode time-out at power on. Refer to WDT CONFIG register. 38:35 WDT EWOFFSET WDT Early Warning Interrupt Time Offset at power on. Refer to WDT EWCTRL register. 39 WDT WEN WDT Timer Window Mode Enable at power on. Refer to WDT CTRL register. 47:40 Reserved 63:48 LOCK Used to select one of eight different bootloader sizes. Refer to “NVMCTRL – Non-Volatile Memory Controller” on page 266. Used to select one of eight different EEPROM area sizes<. Refer to “NVMCTRL – Non-Volatile Memory Controller” on page 266. NVM Region Lock Bits. Refer to “NVMCTRL – Non-Volatile Memory Controller” on page 266. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 25 10.4 NVM Software Calibration Row Mapping The NVM Software Calibration Row contains calibration data that are measured and written during production test. These calibration values should be read by the application software and written back to the corresponding register. The NVM Software Calibration Row can be read at address 0x806020. The NVM Software Calibration Row can not be written. Table 10-4. NVM Software Calibration Row Mapping Bit Position Name Description 2:0 Reserved 14:3 ADC GAINCORR ADC Gain Correction. Should be written to GAINCORR register. 26:15 ADC OFFSETCORR ADC Offset Correction. Should be written to OFFSETCORR register. 34:27 ADC LINEARITY ADC Linearity Calibration. Should be written to CALIB register. 37:35 ADC BIASCAL ADC Bias Calibration. Should be written to CALIB register. 63:38 Reserved Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 26 11. Processor and Architecture 11.1 Cortex-M0+ Processor The Atmel® SAM D20 implements the ARM® Cortex®-M0+ processor, which is based on the ARMv6 architecture and Thumb®-2 ISA. The Cortex M0+ is 100% instruction set compatible with its predecessor, the Cortex-M0 processor, and upward compatible with the Cortex-M3 and Cortex-M4 processors. The ARM Cortex-M0+ implemented is revision r0p1. For more information, refer to www.arm.com. 11.1.1 Cortex-M0+ Configuration Feature Configurable Option SAM D20 Configuration Interrupts External interrupts 0-32 32 Data endianness Little-endian or big-endian Little-endian SysTick timer Present or absent Present Number of watchpoint comparators 0, 1, 2 2 Number of breakpoint comparators 0, 1, 2, 3, 4 4 Halting debug support Present or absent Present Multiplier Fast or small Fast (single cycle) Single-cycle I/O port Present or absent Present Wake-up interrupt controller Supported or not supported Not supported Vector Table Offset Register Present or absent Present Unprivileged/Privileged support Present or absent Absent Memory Protection Unit Not present or 8-region Not present Reset all registers Present or absent Absent(1) Instruction fetch width 16-bit only or mostly 32-bit 32-bit Note: 1. All software run in privileged mode only The ARM Cortex-M0+ processor has two bus interfaces: z Single 32-bit AMBA® 3 AHB-Lite™ system interface that provides connections to peripherals and all system memory, including flash and RAM z Single 32-bit I/O port bus interfacing to the PORT with one-cycle loads and stores 11.1.2 Cortex-M0+ Peripherals z System Control Space (SCS) z z System Timer (SysTick) z z The processor provides debug through registers in the SCS. Refer to the Cortex-M0+ Technical Reference Manual for details. The System Timer is a 24-bit timer that extends the functionality of both the processor and the NVIC. Refer to the Cortex-M0+ Technical Reference Manual for details. Nested Vectored Interrupt Controller (NVIC) Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 27 z z External interrupt signals connect to the NVIC, and the NVIC prioritizes the interrupts. Software can set the priority of each interrupt. The NVIC and the Cortex-M0+ processor core are closely coupled, providing low latency interrupt processing and efficient processing of late arriving interrupts. Refer to “Nested Vector Interrupt Controller” on page 28 and the Cortex-M0+ Technical Reference Manual for details. System Control Block (SCB) z The System Control Block provides system implementation information, and system control. This includes configuration, control, and reporting of the system exceptions. Refer to the Cortex-M0+ Devices Generic User Guide for details. 11.1.3 Cortex-M0+ Address Map Table 11-1. Cortex-M0+ Address Map Address Peripheral 0xE000E000 System Control Space (SCS) 0xE000E010 System Timer (SysTick) 0xE000E100 Nested Vectored Interrupt Controller (NVIC) 0xE000ED00 System Control Block (SCB) 11.1.4 I/O Interface 11.1.4.1 Overview Because accesses to the AMBA AHB-Lite and the single-cycle I/O interface can be made concurrently, the Cortex-M0+ processor can fetch the next instructions while accessing the I/Os. This enables single-cycle I/O accesses to be sustained for as long as needed. 11.1.4.2 Description Direct access to PORT registers. 11.2 Nested Vector Interrupt Controller 11.2.1 Overview The ARMv6-M Nested Vectored Interrupt Controller (NVIC) in the SAM D20 supports 32 interrupt lines with four different priority levels. For more details, refer to the Cortex-M0+ Technical Reference Manual (www.arm.com). 11.2.2 Interrupt Line Mapping Each of the 32 interrupt lines is connected to one peripheral instance, as shown in the table below. Each peripheral can have one or more interrupt flags, located in the peripheral’s Interrupt Flag Status and Clear (INTFLAG) register. The interrupt flag is set when the interrupt condition occurs. Each interrupt in the peripheral can be individually enabled by writing a one to the corresponding bit in the peripheral’s Interrupt Enable Set (INTENSET) register, and disabled by writing a one to the corresponding bit in the peripheral’s Interrupt Enable Clear (INTENCLR) register. An interrupt request is generated from the peripheral when the interrupt flag is set and the corresponding interrupt is enabled. The interrupt requests for one peripheral are ORed together on system level, generating one interrupt request for each peripheral. An interrupt request will set the corresponding interrupt pending bit in the NVIC interrupt pending registers (SETPEND/CLRPEND bits in ISPR/ICPR). For the NVIC to activate the interrupt, it must be enabled in the NVIC interrupt enable register (SETENA/CLRENA bits in ISER/ICER). The NVIC interrupt priority registers IPR0-IPR7 provide a priority field for each interrupt. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 28 Peripheral Source NVIC Line EIC NMI – External Interrupt Controller Non Maskable Interrupt 11.3 NMI PM – Power Manager 0 SYSCTRL – System Controller 1 WDT – Watchdog Timer 2 RTC – Real Time Counter 3 EIC – External Interrupt Controller 4 NVMCTRL – Non-Volatile Memory Controller 5 EVSYS – Event System 6 SERCOM0 – Serial Communication Interface 0 7 SERCOM1 – Serial Communication Interface 1 8 SERCOM2 – Serial Communication Interface 2 9 SERCOM3 – Serial Communication Interface 3 10 SERCOM4 – Serial Communication Interface 4 11 SERCOM5 – Serial Communication Interface 5 12 TC0 – Timer/Counter 0 13 TC1 – Timer/Counter 1 14 TC2 – Timer/Counter 2 15 TC3 – Timer/Counter 3 16 TC4 – Timer/Counter 4 17 TC5 – Timer/Counter 5 18 TC6 – Timer/Counter 6 19 TC7 – Timer/Counter 7 20 ADC – Analog-to-Digital Converter 21 AC – Analog Comparator 22 DAC – Digital-to-Analog Converter 23 PTC – Peripheral Touch Controller 24 High-Speed Bus Matrix 11.3.1 Features The High-Speed Bus Matrix includes these features: z Symmetric crossbar bus switch implementation z Allows concurrent accesses from different masters to different slaves z 32-bit data bus z Operation at a one-to-one clock frequency with the bus masters Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 29 11.3.2 Configuration High-Speed Bus Masters CM0+ 0 DSU 1 Internal Flash AHB-APB bridge A AHB-APB bridge B AHB-APB bridge C Internal SRAM High-Speed Bus Slaves 0 1 2 3 4 Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 30 11.4 AHB-APB Bridge The AHB-APB bridge is an AHB slave, providing an interface between the high-speed AHB domain and the low-power APB domain. It is used to provide access to the programmable control registers of peripherals (see “Product Mapping” on page 23). To operate the AHB-APB bridge, the clock (CLK_HPBx_AHB) must be enabled. See “PM – Power Manager” on page 105 for details. 11.5 PAC – Peripheral Access Controller 11.5.1 Overview There is one PAC associated with each AHB-APB bridge. The PAC can provide write protection for registers of each peripheral connected on the same bridge. The PAC peripheral bus clock (CLK_PACx_APB) is enabled by default, and can be enabled and disabled in the Power Manager. Refer to “PM – Power Manager” on page 105 for details. The PAC will continue to operate in any sleep mode where the selected clock source is running. Write-protection does not apply for debugger access. When the debugger makes an access to a peripheral, writeprotection is ignored so that the debugger can update the register. Write-protect registers allow the user to disable a selected peripheral’s write-protection without doing a read-modify-write operation. These registers are mapped into two I/O memory locations, one for clearing and one for setting the register bits. Writing a one to a bit in the Write Protect Clear register (WPCLR) will clear the corresponding bit in both registers (WPCLR and WPSET) and disable the write-protection for the corresponding peripheral, while writing a one to a bit in the Write Protect Set (WPSET) register will set the corresponding bit in both registers (WPCLR and WPSET) and enable the write-protection for the corresponding peripheral. Both registers (WPCLR and WPSET) will return the same value when read. If a peripheral is write-protected, and if a write access is performed, data will not be written, and the peripheral will return an access error (CPU exception). The PAC also offers a safety feature for correct program execution, with a CPU exception generated on double writeprotection or double unprotection of a peripheral. If a peripheral n is write-protected and a write to one in WPSET[n] is detected, the PAC returns an error. This can be used to ensure that the application follows the intended program flow by always following a write-protect with an unprotect, and vice versa. However, in applications where a write-protected peripheral is used in several contexts, e.g., interrupts, care should be taken so that either the interrupt can not happen while the main application or other interrupt levels manipulate the write-protection status, or when the interrupt handler needs to unprotect the peripheral, based on the current protection status, by reading WPSET. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 31 11.5.2 Register Description Atomic 8-, 16- and 32-bit accesses are supported. In addition, the 8-bit quarters and 16-bit halves of a 32-bit register, and the 8-bit halves of a 16-bit register can be accessed directly. Please refer to “Product Mapping” on page 23 for PAC locations. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 32 11.5.2.1 Write Protect Clear Name: WPCLR Offset: 0x00 Reset: 0x00000000 Property: - Bit 31 30 29 28 27 26 25 24 Access R R R R R R R R Reset 0 0 0 0 0 0 0 0 Bit 23 22 21 20 19 18 17 16 Access R R R R R R R R Reset 0 0 0 0 0 0 0 0 Bit 15 14 13 12 11 10 9 8 Access R R R R R R R R Reset 0 0 0 0 0 0 0 0 Bit 7 6 5 4 3 2 1 0 EIC RTC WDT GCLK SYSCTRL PM Access R R/W R/W R/W R/W R/W R/W R Reset 0 0 0 0 0 0 0 0 z Bits 31:7 – 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. These bits will always return zero when read. z Bits 6:1 – EIC, RTC, WDT, GCLK, SYSCTRL, PM: Write Protect Disable 0: Write-protection is disabled. 1: Write-protection is enabled. Writing a zero to these bits has no effect. Writing a one to these bits will clear the Write Protect bits for the corresponding peripherals. z 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. This bit will always return zero when read. 11.5.3 Write Protect Set Name: WPSET Offset: 0x04 Reset: 0x00000000 Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 33 Property: - Bit 31 30 29 28 27 26 25 24 Access R R R R R R R R Reset 0 0 0 0 0 0 0 0 Bit 23 22 21 20 19 18 17 16 Access R R R R R R R R Reset 0 0 0 0 0 0 0 0 Bit 15 14 13 12 11 10 9 8 Access R R R R R R R R Reset 0 0 0 0 0 0 0 0 Bit 7 6 5 4 3 2 1 0 EIC RTC WDT GCLK SYSCTRL PM Access R R/W R/W R/W R/W R/W R/W R Reset 0 0 0 0 0 0 0 0 z Bits 31:7 – 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. These bits will always return zero when read. z Bits 6:1 – EIC, RTC, WDT, GCLK, SYSCTRL, PM: Write Protect Enable 0: Write-protection is disabled. 1: Write-protection is enabled. Writing a zero to these bits has no effect. Writing a one to these bits will set the Write Protect bit for the corresponding peripherals. z 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. This bit will always return zero when read. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 34 11.5.3.1 PAC1 Register Description Write Protect Clear Name: WPCLR Offset: 0x00 Reset: 0x00000002 Property: - Bit 31 30 29 28 27 26 25 24 Access R R R R R R R R Reset 0 0 0 0 0 0 0 0 Bit 23 22 21 20 19 18 17 16 Access R R R R R R R R Reset 0 0 0 0 0 0 0 0 Bit 15 14 13 12 11 10 9 8 Access R R R R R R R R Reset 0 0 0 0 0 0 0 0 Bit 7 6 5 4 3 2 1 0 PORT NVMCTRL DSU Access R R R R R/W R/W R/W R Reset 0 0 0 0 0 0 1 0 z Bits 31:4 – 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. These bits will always return zero when read. z Bits 3:1 – PORT, NVMCTRL, DSU: Write Protect 0: Write-protection is disabled. 1: Write-protection is enabled. Writing a zero to these bits has no effect. Writing a one to these bits will clear the Write Protect bit for the corresponding peripherals. z 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. This bit will always return zero when read. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 35 Write Protect Set Name: WPSET Offset: 0x04 Reset: 0x00000002 Property: - Bit 31 30 29 28 27 26 25 24 Access R R R R R R R R Reset 0 0 0 0 0 0 0 0 Bit 23 22 21 20 19 18 17 16 Access R R R R R R R R Reset 0 0 0 0 0 0 0 0 Bit 15 14 13 12 11 10 9 8 Access R R R R R R R R Reset 0 0 0 0 0 0 0 0 Bit 7 6 5 4 3 2 1 0 PORT NVMCTRL DSU Access R R R R R/W R/W R/W R Reset 0 0 0 0 0 0 1 0 z Bits 31:4 – 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. These bits will always return zero when read. z Bits 3:1 – PORT, NVMCTRL, DSU: Write Protect 0: Write-protection is disabled. 1: Write-protection is enabled. Writing a zero to these bits has no effect. Writing a one to these bits will set the Write Protect bit for the corresponding peripherals. z 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. This bit will always return zero when read. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 36 11.5.3.2 PAC2 Register Description Write Protect Clear Name: WPCLR Offset: 0x00 Reset: 0x00100000 Property: - Bit 31 30 29 28 27 26 25 24 Access R R R R R R R R Reset 0 0 0 0 0 0 0 0 Bit 23 22 21 20 19 18 17 16 PTC DAC AC ADC Access R R R R R/W R/W R/W R/W Reset 0 0 0 1 0 0 0 0 Bit 15 14 13 12 11 10 9 8 TC7 TC6 TC5 TC4 TC3 TC2 TC1 TC0 R/W R/W R/W R/W R/W R/W R/W R/W Reset 0 0 0 0 0 0 0 0 Bit 7 6 5 4 3 2 1 0 SERCOM5 SERCOM4 SERCOM3 SERCOM2 SERCOM1 SERCOM0 EVSYS R/W R/W R/W R/W R/W R/W R/W R 0 0 0 0 0 0 0 0 Access Access Reset z Bits 31:20 – Reserved These bits are unused and reserved for future use. For compatibility with future devices, always write these bits to reset value when this register is written. These bits will always return reset value when read. z Bits 19:1 – PTC, DAC, AC, ADC, TC7, TC6, TC5, TC4, TC3, TC2, TC1, TC0, SERCOM5, SERCOM4, SERCOM3, SERCOM2, SERCOM1, SERCOM0, EVSYS: Write Protect 0: Write-protection is disabled. 1: Write-protection is enabled. Writing a zero to these bits has no effect. Writing a one to these bits will clear the Write Protect bit for the corresponding peripherals. z 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. This bit will always return zero when read. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 37 Write Protect Set Name: WPSET Offset: 0x04 Reset: 0x00100000 Property: - Bit 31 30 29 28 27 26 25 24 Access R R R R R R R R Reset 0 0 0 0 0 0 0 0 Bit 23 22 21 20 19 18 17 16 PTC DAC AC ADC Access R R R R R/W R/W R/W R/W Reset 0 0 0 1 0 0 0 0 Bit 15 14 13 12 11 10 9 8 TC7 TC6 TC5 TC4 TC3 TC2 TC1 TC0 R/W R/W R/W R/W R/W R/W R/W R/W Reset 0 0 0 0 0 0 0 0 Bit 7 6 5 4 3 2 1 0 SERCOM5 SERCOM4 SERCOM3 SERCOM2 SERCOM1 SERCOM0 EVSYS R/W R/W R/W R/W R/W R/W R/W R 0 0 0 0 0 0 0 0 Access Access Reset z Bits 31:20 – Reserved These bits are unused and reserved for future use. For compatibility with future devices, always write these bits to reset value when this register is written. These bits will always return reset value when read. z Bits 19:1 – PTC, DAC, AC, ADC, TC7, TC6, TC5, TC4, TC3, TC2, TC1, TC0, SERCOM5, SERCOM4, SERCOM3, SERCOM2, SERCOM1, SERCOM0, EVSYS: Write Protect Enable 0: Write-protection is disabled. 1: Write-protection is enabled. Writing a zero to these bits has no effect. Writing a one to these bits will set the Write Protect bit for the corresponding peripherals. z 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. This bit will always return zero when read. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 38 12. Peripherals Configuration Overview The following table shows an overview of all the peripherals in the device. The IRQ Line column shows the interrupt mapping, as described in “Nested Vector Interrupt Controller” on page 28. The AHB and APB clock indexes correspond to the bit in the AHBMASK and APBMASK (x = A, B or C) registers in the Power Manager, while the Enabled at Reset column shows whether the peripheral clock is enabled at reset (Y) or not (N). Refer to the Power Manager AHBMASK, APBAMASK, APBBMASK and APBCMASK registers for details. The Generic Clock Index column corresponds to the value of the Generic Clock Selection ID bits in the Generic Clock Control register (CLKCTRL.ID) in the Generic Clock Controller. Refer to the GCLK CLKCTRL register description for details. The PAC Index column corresponds to the bit in the PACi (i = 0, 1 or 2) registers, while the Prot at Reset column shows whether the peripheral is protected at reset (Y) or not (N). Refer to “PAC – Peripheral Access Controller” on page 31 for details. The numbers in the Events User column correspond to the value of the User Multiplexer Selection bits in the User Multiplexer register (USER.USER) in the Event System. See the USER register description and Table 23-6 for details. The numbers in the Events Generator column correspond to the value of the Event Generator bits in the Channel register (CHANNEL.EVGEN) in the Event System. See the CHANNEL register description and Table 23-3 for details. Table 12-1. Peripherals Configuration Overview AHB Clock Peripheral Name Base Address HPB0 Peripheral Bridge A 0x40000000 PAC0 0x40000000 PM 0x40000400 IRQ Line Index Enabled at Reset 0 Y 0 SYSCTRL 0x40000800 1 GCLK 0x40000C00 WDT 0x40001000 2 RTC 0x40001400 EIC 0x40001800 HPB1 Peripheral Bridge B 0x41000000 PAC1 0x41000000 DSU 0x41002000 NVMCTRL 0x41004000 PORT 0x41004400 HPB2 Peripheral Bridge C 0x42000000 PAC2 0x42000000 EVSYS 0x42000400 SERCOM0 SERCOM1 APB Clock Index Enabled at Reset 0 Y 1 Y Generic Clock Index 0: DFLL48M reference PAC Events Index Prot at Reset 1 N 2 N User Generator 2 Y 3 Y 3 N 4 Y 1 4 N 3 5 Y 2 5 N 1: CMP0/ALARM0 2: CMP1 3: OVF 4-11: PER0-7 NMI, 4 6 Y 3 6 N 12-27: EXTINT0-15 1 Y 0 Y 3 Y 1 Y 1 Y 4 Y 2 Y 2 N 3 Y 3 N 0 N 6 1 N 4-11: one per CHANNEL 1 N 0x42000800 7 2 N 13: CORE 12: SLOW 2 N 0x42000C00 8 3 N 14: CORE 12: SLOW 3 N 5 2 Y Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 39 Table 12-1. Peripherals Configuration Overview AHB Clock Peripheral Name Base Address IRQ Line Index Enabled at Reset SERCOM2 0x42001000 9 4 SERCOM3 0x42001400 10 SERCOM4 0x42001800 SERCOM5 Generic Clock PAC Events Index Index Prot at Reset N 15: CORE 12: SLOW 4 N 5 N 16: CORE 12: SLOW 5 N 11 6 N 17: CORE 12: SLOW 6 N 0x42001C00 12 7 N 18: CORE 12: SLOW 7 N TC0 0x42002000 13 8 N 19 8 TC1 0x42002400 14 9 N 19 TC2 0x42002800 15 10 N TC3 0x42002C00 16 11 TC4 0x42003000 17 TC5 0x42003400 TC6 Index Enabled at Reset APB Clock User Generator N 0: TC 28: OVF 29-30: MC0-1 9 N 1: TC 31: OVF 32-33: MC0-1 20 10 N 2: TC 34: OVF 35-36: MC0-1 N 20 11 N 3: TC 37: OVF 38-39: MC0-1 12 N 21 12 N 4: TC 40: OVF 41-42: MC0-1 18 13 N 21 13 N 5: TC 43: OVF 44-45: MC0-1 0x42003800 19 14 N 22 14 N 6: TC 46: OVF 47-48: MC0-1 TC7 0x42003C00 20 15 N 22 15 N 7: TC 49: OVF 50-51: MC0-1 ADC 0x42004000 21 16 Y 23 16 N 8: START 9: SYNC 52: RESRDY 53: WINMON AC 0x42004400 22 17 N 24: DIG 25: ANA 17 N 10-11: COMP0-1 54-55: COMP0-1 56: WIN0 DAC 0x42004800 23 18 N 26 18 N 12: START 57: EMPTY PTC 0x42004C00 24 19 N 27 19 N 13: STCONV 58: EOC 59: WCOMP Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 40 13. DSU – Device Service Unit 13.1 Overview The Device Service Unit (DSU) provides a means to detect debugger probes. This enables the ARM Debug Access Port (DAP) to have control over multiplexed debug pads and CPU reset. The DSU also provides system-level services to debug adapters in an ARM debug system. It implements a CoreSight Debug ROM that provides device identification a swell as identification of other debug components in the system. Hence, it complies with the ARM Peripheral Identification specification. The DSU also provides system services to applications that need memory testing, as required for IEC60730 Class B compliance, for example. The DSU can be accessed simultaneously by a debugger and the CPU, as it is connected on the High-Speed Bus Matrix. For security reasons, some of the DSU features will be limited or unavailable when the device is protected by the NVMCTRL security bit (refer to “Security Bit” on page 273). 13.2 Features z CPU reset extension z Debugger probe detection (Cold- and Hot-Plugging) z Chip-Erase command and status z 32-bit cyclic redundancy check (CRC32) of any memory accessible through the bus matrix z ARM® CoreSight™ compliant device identification z Two debug communications channels z Debug access port security filter z Onboard memory built-in self-test (MBIST) 13.3 Block Diagram Figure 13-1. DSU Bock Diagram DSU debugger_present RESET SWCLK DEBUGGER PROBE INTERFACE cpu_reset_extension CPU DAP AHB-AP DAP SECURITY FILTER NVMCTRL HRAM S S DBG CORESIGHT ROM PORTMUX M CRC-32 SWDIO MBIST M HIGH-SPEED HIGH-SPEE BUS US MATRIX M MATR CHIP ERASE Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 41 13.4 Signal Description Signal Name Type Description RESET Digital Input External reset SWCLK Digital Input SW clock SWDIO Digital I/O SW bidirectional data pin Refer to “I/O Multiplexing and Considerations” on page 15 for details on the pin mapping for this peripheral. 13.5 Product Dependencies In order to use this peripheral, other parts of the system must be configured correctly, as described below. 13.5.1 I/O Lines The SWCLK pin is by default assigned to the DSU module to allow debugger probe detection and the condition to stretch the CPU reset phase. For more information, refer to “Debugger Probe Detection” on page 43. The Hot-Plugging feature depends on the PORT configuration. If the SWCLK pin function is changed in the PORT or if the PORT_MUX is disabled, the Hot-Plugging feature is disabled until a power-reset or an external reset. 13.5.2 Power Management The DSU will continue to operate in any sleep mode where the selected source clock is running. Refer to “PM – Power Manager” on page 105 for details on the different sleep modes. 13.5.3 Clocks The DSU bus clocks (CLK_DSU_APB and CLK_DSU_AHB) can be enabled and disabled in the Power Manager. For more information on the CLK_DSU_APB and CLK_DSU_AHB clock masks, refer to “PM – Power Manager” on page 105. 13.5.4 Interrupts Not applicable. 13.5.5 Events Not applicable. 13.5.6 Register Access Protection All registers with write access are optionally write-protected by the Peripheral Access Controller (PAC), except the following registers: z Debug Communication Channel 0 register (DCC0) z Debug Communication Channel 1 register (DCC1) Write-protection is denoted by the Write-Protection property in the register description. Write-protection does not apply for accesses through an external debugger. Refer to “PAC – Peripheral Access Controller” on page 31 for details. 13.5.7 Analog Connections Not applicable. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 42 13.6 Debug Operation 13.6.1 Principle of Operation The DSU provides basic services to allow on-chip debug using the ARM Debug Access Port and the ARM processor debug resources: z CPU reset extension z Debugger probe detection For more details on the ARM debug components, refer to the ARM Debug Interface v5Architecture Specification. 13.6.2 CPU Reset Extension “CPU reset extension” refers to the extension of the reset phase of the CPU core after the external reset is released. This ensures that the CPU is not executing code at startup while a debugger connects to the system. It is detected on a RESET release event when SWCLK is low. At startup, SWCLK is internally pulled up to avoid false detection of a debugger if SWCLK is left unconnected. When the CPU is held in the reset extension phase, the CPU Reset Extension bit (CRSTEXT) of the Status A register (STATUSA.CRSTEXT) is set. To release the CPU, write a one to STATUSA.CRSTEXT. STATUSA.CRSTEXT will then be set to zero. Writing a zero to STATUSA.CRSTEXT has no effect. For security reasons, it is not possible to release the CPU reset extension when the device is protected by the NVMCTRL security bit (refer to “Security Bit” on page 273). Trying to do so sets the Protection Error bit (PERR) of the Status A register (STATUSA.PERR). Figure 13-2. Typical CPU Reset Extension Set and Clear Timing Diagram SWCLK RESET DSU CRSTEXT Clear CPU reset extension CPU_STATE reset running 13.6.3 Debugger Probe Detection 13.6.3.1 Cold-Plugging Cold-Plugging is the detection of a debugger when the system is in reset. Cold-Plugging is detected when the CPU reset extension is requested, as described above. 13.6.3.2 Hot-Plugging Hot-Plugging is the detection of a debugger probe when the system is not in reset. Hot-Plugging is not possible under reset because the detector is reset when POR or RESET are asserted. Hot-Plugging is active when a SWCLK falling edge is detected. The SWCLK pad is multiplexed with other functions and the user must ensure that its default function is assigned to the debug system. If the SWCLK function is changed, the Hot-Plugging feature is disabled until a powerreset or external reset occurs. Availability of the Hot-Plugging feature can be read from the Hot-Plugging Enable bit of the Status B register (STATUSB.HPE). Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 43 Figure 13-3. Hot-Plugging Detection Timing Diagram SWCLK RESET CPU_STATE reset running Hot-Plugging The presence of a debugger probe is detected when either Hot-Plugging or Cold-Plugging is detected. Once detected, the Debugger Present bit of the Status B register (STATUSB.DBGPRES) is set. For security reasons, Hot-Plugging is not available when the device is protected by the NVMCTRL security bit (refer to “Security Bit” on page 273). This detection requires that pads are correctly powered. Thus, at cold startup, this detection cannot be done until POR is released. If the device is protected, Cold-Plugging is the only way to detect a debugger probe, and so the external reset timing must be longer than the POR timing. If external reset is deasserted before POR release, the user must retry the procedure above until it gets connected to the device. 13.7 Chip-Erase Chip-Erase consists of removing all sensitive information stored in the chip and clearing the NVMCTRL security bit (refer to “Security Bit” on page 273). Hence, all volatile memories and the flash array (including the EEPROM emulation area) will be erased. The flash auxiliary rows, including the user row, will not be erased. When the device is protected, the debugger must reset the device in order to be detected. This ensures that internal registers are reset after the protected state is removed. The Chip-Erase operation is triggered by writing a one to the Chip-Erase bit in the Control register (CTRL.CE). This command will be discarded if the DSU is protected by the Peripheral Access Controller (PAC). Once issued, the module clears volatile memories prior to erasing the flash array. To ensure that the Chip-Erase operation is completed, check the Done bit of the Status A register (STATUSA.DONE). The Chip-Erase operation depends on clocks and power management features that can be altered by the CPU. For that reason, it is recommended to issue a ChipErase after a Cold-Plugging procedure to ensure that the device is in a known and safe state. The recommended sequence is as follows: 1. 2. 13.8 Issue the Cold-Plugging procedure (refer to “Cold-Plugging” on page 43). The device then: 1. Detects the debugger probe 2. Holds the CPU in reset Issue the Chip-Erase command by writing a one to CTRL.CE. The device then: 1. Clears the system volatile memories 2. Erases the whole flash array (including the EEPROM emulation area, not including auxiliary rows) 3. Erases the lock row, removing the NVMCTRL security bit protection 3. Check for completion by polling STATUSA.DONE (read as one when completed). 4. Reset the device to let the NVMCTRL update fuses. Programming Programming of the flash or RAM memories is available when the device is not protected by the NVMCTRL security bit (refer to “Security Bit” on page 273). Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 44 13.9 1. At power up, RESET is driven low by a debugger. The on-chip regulator holds the system in a POR state until the input supply is above the POR threshold. The system continues to be held in this static state until the internally regulated supplies have reached a safe operating state. 2. The PM starts, clocks are switched to the slow clock (Core Clock, System Clock, Flash Clock and any Bus Clocks that do not have clock gate control). Internal resets are maintained due to the external reset. 3. The debugger maintains a low level on SWCLK. Releasing RESET results in a debugger Cold-Plugging procedure. 4. The debugger generates a clock signal on the SWCLK pin, the Debug Access Port (DAP) receives a clock. 5. The CPU remains in reset due to the Cold-Plugging procedure; meanwhile, the rest of the system is released. 6. A Chip-Erase is issued to ensure that the flash is fully erased prior to programming. 7. Programming is available through the AHB-AP. 8. After operation is completed, the chip can be restarted either by asserting RESET, toggling power or writing a one to the Status A register CPU Reset Phase Extension bit (STATUSA.CRSTEXT). Make sure that the SWCLK pin is high when releasing RESET to prevent extending the CPU reset. Intellectual Property Protection Intellectual property protection consists of restricting access to internal memories from external tools when the device is protected, and is accomplished by setting the NVMCTRL security bit (refer to “Security Bit” on page 273). This protected state can be removed by issuing a Chip-Erase (refer to “Chip-Erase” on page 44). When the device is protected, read/write accesses using the AHB-AP are limited to the DSU address range and DSU commands are restricted. The DSU implements a security filter that monitors the AHB transactions generated by the ARM AHB-AP inside the DAP. If the device is protected, then AHB-AP read/write accesses outside the DSU external address range are discarded, causing an error response that sets the ARM AHB-AP sticky error bits (refer to the ARM Debug Interface v5 Architecture Specification on http://www.arm.com). The DSU is intended to be accessed either: z Internally from the CPU, without any limitation, even when the device is protected z Externally from a debug adapter, with some restrictions when the device is protected For security reasons, DSU features have limitations when used from a debug adapter. To differentiate external accesses from internal ones, the first 0x100 bytes of the DSU register map have been replicated at offset 0x100: z The first 0x100 bytes form the internal address range z The next 0x100 bytes form the external address range When the device is protected, the DAP can only issue MEM-AP accesses in the DSU address range limited to the 0x1000x2000 offset range. The DSU operating registers are located in the 0x00-0xFF area and remapped in 0x100-0x1FF to differentiate accesses coming from a debugger and the CPU. If the device is protected and an access is issued in the region 0x100-0x1FF, it is subject to security restrictions. For more information, refer to Table . Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 45 Figure 13-4. APB Memory Mapping 0x0000 DSU operating registers 0x00FC 0x0100 0x01FD Internal address range (cannot be accessed from debug tools when the device is protected by the NVMCTRL security bit) Replicated DSU operating registers Empty External address range (can be accessed from debug tools with some restrictions) 0x1000 DSU CoreSight ROM 0x1FFC Some features not activated by APB transactions are not available when the device is protected: Table 13-1. Feature Availability Under Protection Features Availability When the Device is Protected CPU reset extension Yes Debugger Cold-Plugging Yes Debugger Hot-Plugging No 13.10 Device Identification Device identification relies on the ARM CoreSight component identification scheme, which allows the chip to be identified as an ATMEL device implementing a DSU. The DSU contains identification registers to differentiate the device. 13.10.1 CoreSight Identification A system-level ARM CoreSight ROM table is present in the device to identify the vendor and the chip identification method. Its address is provided in the MEM-AP BASE register inside the ARM Debug Access Port. The CoreSight ROM implements a 64-bit conceptual ID composed as follows from the PID0 to PID7 CoreSight ROM Table registers: Figure 13-5. Conceptual 64-Bit Peripheral ID Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 46 Table 13-2. Conceptual 64-Bit Peripheral ID Bit Descriptions Field Size JEP-106 CC code 4 Atmel continuation code: 0x0 JEP-106 ID code 7 Atmel device ID: 0x1F 4KB count 4 Indicates that the CoreSight component is a ROM: 0x0 PID4 RevAnd 4 Not used; read as 0 PID3 CUSMOD 4 Not used; read as 0 PID3 PARTNUM 12 Contains 0xCD0 to indicate that DSU is present 4 DSU revision (starts at 0x0 and increments by 1 at both major and minor revisions). Identifies DSU identification method variants. If 0x0, this indicates that device identification can be completed by reading the Device Identification register (DID) REVISION Description Location PID4 PID1+PID2 PID0+PID1 PID3 For more information, refer to the ARM Debug Interface Version 5 Architecture Specification. 13.10.2 DSU Chip Identification Method: The DSU DID register identifies the device by implementing the following information: z Processor identification z Family identification z Subfamily identification z Device select 13.11 Functional Description 13.11.1 Principle of Operation The DSU provides memory services such as CRC32 or MBIST that require almost the same interface. Hence, the Address, Length and Data registers are shared. They must be configured first; then a command can be issued by writing the Control register. When a command is ongoing, other commands are discarded until the current operation is completed. Hence, the user must wait for the STATUSA.DONE bit to be set prior to issuing another one. 13.11.2 Basic Operation 13.11.2.1 Initialization The module is enabled by enabling its clocks. For more details, refer to “Clocks” on page 42. The DSU registers can be write-protected. Refer to “PAC – Peripheral Access Controller” on page 31. 13.11.2.2 Operation from a debug adapter Debug adapters should access the DSU registers in the external address range 0x100 – 0x2000. If the device is protected by the NVMCTRL security bit (refer to “Security Bit” on page 273), accessing the first 0x100 bytes causes the system to return an error (refer to “Intellectual Property Protection” on page 45). 13.11.2.3 Operation from the CPU There are no restrictions when accessing DSU registers from the CPU. However, the user should access DSU registers in the internal address range (0x0 – 0x100) to avoid external security restrictions (refer to “Intellectual Property Protection” on page 45). Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 47 13.11.3 32-bit Cyclic Redundancy Check (CRC32) The DSU unit provides support for calculating a cyclic redundancy check (CRC32) value for a memory area (including flash and AHB RAM). When the CRC32 command is issued from: z The internal range, the CRC32 can be operated at any memory location z The external range, the CRC32 operation is restricted; DATA, ADDR and LENGTH values are forced (see below) Table 13-3. AMOD Bit Descriptions when Operating CRC32 AMOD[1:0] Short Name 0 ARRAY 1 EEPROM 2-3 Reserved External Range Restrictions CRC32 is restricted to the full flash array area (EEPROM emulation area not included) DATA forced to 0xFFFFFFFF before calculation (no seed) CRC32 of the whole EEPROM emulation area DATA forced to 0xFFFFFFFF before calculation (no seed) The algorithm employed is the industry standard CRC32 algorithm using the generator polynomial 0xEDB88320 (reversed representation). 13.11.3.1 Starting CRC32 Calculation CRC32 calculation for a memory range is started after writing the start address into the Address register (ADDR) and the size of the memory range into the Length register (LENGTH). Both must be word-aligned. The initial value used for the CRC32 calculation must be written to the Data register. This value will usually be 0xFFFFFFFF, but can be, for example, the result of a previous CRC32 calculation if generating a common CRC32 of separate memory blocks. Once completed, the calculated CRC32 value can be read out of the Data register. The read value must be complemented to match standard CRC32 implementations or kept non-inverted if used as starting point for subsequent CRC32 calculations. If the device is in protected state by the NVMCTRL security bit (refer to “Security Bit” on page 273), it is only possible to calculate the CRC32 of the whole flash array. In most cases, this area will be the entire onboard non-volatile memory. The Address, Length and Data registers will be forced to predefined values once the CRC32 operation is started, and values written by the user are ignored. This allows the user to verify the contents of a protected device. The actual test is started by writing a one in the 32-bit Cyclic Redundancy Check bit of the Control register (CTRL.CRC). A running CRC32 operation can be canceled by resetting the module (writing a one to CTRL.SWRST). 13.11.3.2 Interpreting the Results The user should monitor the Status A register. When the operation is completed, STATUSA.DONE is set. Then the Bus Error bit of the Status A register (STATUSA.BERR) must be read to ensure that no bus error occurred. 13.11.4 Debug Communication Channels The Debug Communication Channels (DCCO and DCC1) consist of a pair of registers with associated handshake logic, accessible by both CPU and debugger even if the device is protected by the NVMCTRL security bit (refer to “Security Bit” on page 273). The registers can be used to exchange data between the CPU and the debugger, during run time as well as in debug mode. This enables the user to build a custom debug protocol using only these registers. The DCC0 and DCC1 registers are accessible when the protected state is active. When the device is protected, however, it is not possible to connect a debugger while the CPU is running (STATUSA.CRSTEXT is not writable and the CPU is held under reset). Dirty bits in the status registers indicate whether a new value has been written in DCC0 or DCC1. These bits,DCC0D and DCC1D, are located in the STATUSB registers. They are automatically set on write and cleared on Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 48 read. The DCC0 and DCC1 registers are shared with the onboard memory testing logic (MBIST). Accordingly, DCC0 and DCC1 must not be used while performing MBIST operations. 13.11.5 Testing of Onboard Memories (MBIST) The DSU implements a feature for automatic testing of memory also known as MBIST. This is primarily intended for production test of onboard memories. MBIST cannot be operated from the external address range when the device is protected by the NVMCTRL security bit (refer to “Security Bit” on page 273). If a MBIST command is issued when the device is protected, a protection error is reported in the Protection Error bit in the Status A register (STATUSA.PERR). 1. Algorithm The algorithm used for testing is a type of March algorithm called "March LR". This algorithm is able to detect a wide range of memory defects, while still keeping a linear run time. The algorithm is: 1. Write entire memory to 0, in any order. 2. Bit for bit read 0, write 1, in descending order. 3. Bit for bit read 1, write 0, read 0, write 1, in ascending order. 4. Bit for bit read 1, write 0, in ascending order. 5. Bit for bit read 0, write 1, read 1, write 0, in ascending order. 6. Read 0 from entire memory, in ascending order. The specific implementation used has a run time of O(14n) where n is the number of bits in the RAM. The detected faults are: 2. z Address decoder faults z Stuck-at faults z Transition faults z Coupling faults z Linked Coupling faults z Stuck-open faults Starting MBIST To test a memory, you need to write the start address of the memory to the ADDR.ADDR bit group, and the size of the memory into the Length register. See “Physical Memory Map” on page 24 to know which memories are available, and which address they are at. For best test coverage, an entire physical memory block should be tested at once. It is possible to test only a subset of a memory, but the test coverage will then be somewhat lower. The actual test is started by writing a one to CTRL.MBIST. A running MBIST operation can be canceled by writing a one to CTRL.SWRST. 3. Interpreting the Results The tester should monitor the STATUSA register. When the operation is completed, STATUSA.DONE is set. There are three different modes: z ADDR.AMOD=0: exit-on-error (default) In this mode, the algorithm terminates either when a fault is detected or on successful completion. In both cases, STATUSA.DONE is set. If an error was detected, STATUSA.FAIL will be set. User then can read the DATA and ADDR registers to locate the fault. Refer to “Locating Errors” on page 49. z ADDR.AMOD=1: pause-on-error In this mode, the MBIST algorithm is paused when an error is detected. In such a situation, only STATUSA.FAIL is asserted. The state machine waits for user to clear STATUSA.FAIL by writing a one in STATUSA.FAIL to resume. Prior to resuming, user can read the DATA and ADDR registers to locate the fault. Refer to “Locating Errors” on page 49. 4. Locating Errors If the test stops with STATUSA.FAIL set, one or more bits failed the test. The test stops at the first detected error. The position of the failing bit can be found by reading the following registers: Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 49 z ADDR: Address of the word containing the failing bit. z DATA: contains data to identify which bit failed, and during which phase of the test it failed. The DATA register will in this case contains the following bit groups: Table 13-4. DATA bits Description When MBIST Operation Returns An Error Bit 31 30 29 28 27 26 25 24 Bit 23 22 21 20 19 18 17 16 Bit 15 14 13 12 11 10 9 8 phase Bit 7 6 5 4 3 2 1 0 bit_index z bit_index: contains the bit number of the failing bit z phase: indicates which phase of the test failed and the cause of the error. See Table 13-5 on page 50. Table 13-5. MBIST Operation Phases Phase Test Actions 0 Write all bits to zero. This phase cannot fail. 1 Read 0, write 1, increment address 2 Read 1, write 0 3 Read 0, write 1, decrement address 4 Read 1, write 0, decrement address 5 Read 0, write 1 6 Read 1, write 0, decrement address 7 Read all zeros. bit_index is not used 13.11.6 System Services Availability When Accessed Externally External access: Access performed in the DSU address offset 0x200-0x1FFF range. Internal access: Access performed in the DSU address offset 0x0-0x100 range. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 50 Table 13-6. Available Features When Operated From The External Address Range Features Chip-Erase command and status CRC32 Availability From The External Address Range Yes Yes, only full array or full EEPROM CoreSight Compliant Device identification Yes Debug communication channels Yes Testing of onboard memories (MBIST) Yes STATUSA.CRSTEXT clearing No (STATUSA.PERR is set when attempting to do so) Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 51 13.12 Register Summary Table 13-7. Register Summary Offset Name Bit Pos 0x0000 CTRL 7:0 CE MBIST CRC 0x0001 STATUSA 7:0 PERR FAIL BERR CRSTEXT DONE 0x0002 STATUSB 7:0 HPE DCCD1 DCCD0 DBGPRES PROT 0x0003 Reserved 0x0004 7:0 0x0005 SWRST ADDR[5:0] 15:8 ADDR[13:6] 0x0006 23:16 ADDR[21:14] 0x0007 31:24 ADDR[29:22] 0x0008 7:0 ADDR 0x0009 LENGTH[5:0] 15:8 LENGTH[13:6] 0x000A 23:16 LENGTH[21:14] 0x000B 31:24 LENGTH[29:22] 0x000C 7:0 DATA[7:0] 15:8 DATA[15:8] 0x000E 23:16 DATA[23:16] 0x000F 31:24 DATA[31:24] 0x0010 7:0 DATA[7:0] 15:8 DATA[15:8] 0x0012 23:16 DATA[23:16] 0x0013 31:24 DATA[31:24] 0x0014 7:0 DATA[7:0] 15:8 DATA[15:8] 0x0016 23:16 DATA[23:16] 0x0017 31:24 DATA[31:24] 0x0018 7:0 DEVSEL[7:0] LENGTH 0x000D DATA 0x0011 DCC0 0x0015 DCC1 0x0019 15:8 DIE[3:0] REVISION[3:0] DID 0x001A 23:16 0x001C 31:24 0x001D Reserved ... ... 0x00FF Reserved SUBFAMILY[7:0] PROCESSOR[3:0] FAMILY[3:0] External address range: 0x01000x01FF Replicates the 0x00:0x1C address range, Gives access to the same resources but with security restrictions when the device is protected. This address range is the only one accessible externally (using the ARM DAP) when the device is protected. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 52 0x1000 7:0 0x1001 15:8 FMT EPRES FMT EPRES ADDOFF[3:0] ENTRY0 0x1002 23:16 ADDOFF[11:4] 0x1003 31:24 ADDOFF[19:12] 0x1004 7:0 0x1005 15:8 ADDOFF[3:0] ENTRY1 0x1006 23:16 ADDOFF[11:4] 0x1007 31:24 ADDOFF[19:12] 0x1008 7:0 END[7:0] 15:8 END[15:8] 0x100A 23:16 END[23:16] 0x100B 31:24 END[31:24] 0x1FCC 7:0 0x1009 END 0x1FCD SMEMP 15:8 MEMTYPE 0x1FCE 23:16 0x1FCF 31:24 0x1FD0 7:0 0x1FD1 FKBC[3:0] JEPCC[3:0] 15:8 PID4 0x1FD2 23:16 0x1FD3 31:24 0x1FD4 Reserved … … 0x1FDF Reserved 0x1FE0 7:0 0x1FE1 PARTNBL[7:0] 15:8 PID0 0x1FE2 23:16 0x1FE3 31:24 0x1FE4 7:0 0x1FE5 JEPIDCL[3:0] PARTNBH[3:0] 15:8 PID1 0x1FE6 23:16 0x1FE7 31:24 0x1FE8 7:0 0x1FE9 REVISION[3:0] JEPU JEPIDCH[2:0] 15:8 PID2 0x1FEA 23:16 0x1FEB 31:24 0x1FEC 7:0 0x1FED REVAND[3:0] CUSMOD[3:0] 15:8 PID3 0x1FEE 23:16 0x1FEF 31:24 Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 53 0x1FF0 7:0 0x1FF1 PREAMBLEB0[7:0] 15:8 CID0 0x1FF2 23:16 0x1FF3 31:24 0x1FF4 7:0 0x1FF5 CCLASS[3:0] PREAMBLE[3:0] 15:8 CID1 0x1FF6 23:16 0x1FF7 31:24 0x1FF8 7:0 0x1FF9 PREAMBLEB2[7:0] 15:8 CID2 0x1FFA 23:16 0x1FFB 31:24 0x1FFC 7:0 0x1FFD PREAMBLEB3[7:0] 15:8 CID3 0x1FFE 23:16 0x1FFF 31:24 Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 54 13.13 Register Description Registers can be 8, 16 or 32 bits wide. Atomic 8-, 16- and 32-bit accesses are supported. In addition, the 8-bit quarters and 16-bit halves of a 32-bit register and the 8-bit halves of a 16-bit register can be accessed directly. Some registers are optionally write-protected by the Peripheral Access Controller (PAC). Write protection is denoted by the Write-Protected property in each individual register description. Please refer to “Register Access Protection” on page 42 for details. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 55 13.13.1 Control Name: CTRL Offset: 0x0000 Reset: 0x00 Property: Write-Protected Bit 7 6 5 4 3 2 CE MBIST CRC 1 0 SWRST Access R R R W W W R W Reset 0 0 0 0 0 0 0 0 z Bits 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. These bits will always return zero when read. z Bit 4 – CE: Chip-Erase Writing a zero to this bit has no effect. Writing a one to this bit starts the Chip-Erase operation. z Bit 3 – MBIST: Memory built-in self-test Writing a zero to this bit has no effect. Writing a one to this bit starts the memory BIST algorithm. z Bit 2 – CRC: 32-bit Cyclic Redundancy Check Writing a zero to this bit has no effect. Writing a one to this bit starts the cyclic redundancy check algorithm. z Bit 1 – 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. z Bit 0 – SWRST: Software Reset Writing a zero to this bit has no effect. Writing a one to this bit resets the module. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 56 13.13.2 Status A Name: STATUSA Offset: 0x0001 Reset: 0x00 Property: Write-Protected Bit 7 6 5 4 3 2 1 0 PERR FAIL BERR CRSTEXT DONE Access R R R R/W R/W R/W R/W R/W Reset 0 0 0 0 0 0 0 0 z Bits 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. These bits will always return zero when read. z Bit 4 – PERR: Protection Error Writing a zero to this bit has no effect. Writing a one to this bit clears the Protection Error bit. This bit is set when a command that is not allowed in protected state is issued. z Bit 3 – FAIL: Failure Writing a zero to this bit has no effect. Writing a one to this bit clears the Failure bit. This bit is set when a DSU operation failure is detected. z Bit 2 – BERR: Bus Error Writing a zero to this bit has no effect. Writing a one to this bit clears the Bus Error bit. This bit is set when a bus error is detected. z Bit 1 – CRSTEXT: CPU Reset Phase Extension Writing a zero to this bit has no effect. Writing a one to this bit clears the CPU Reset Phase Extension bit. This bit is set when a debug adapter Cold-Plugging is detected, which extends the CPU reset phase. z Bit 0 – DONE: Done Writing a zero to this bit has no effect. Writing a one to this bit clears the Done bit. This bit is set when a DSU operation is completed. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 57 13.13.3 Status B Name: STATUSB Offset: 0x0002 Reset: 0x1X Property: Write-Protected Bit 7 6 5 4 3 2 1 0 HPE DCCD1 DCCD0 DBGPRES PROT Access R R R R R R R R Reset 0 0 0 1 0 0 X X z Bits 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. These bits will always return zero when read. z Bit 4 – HPE: Hot-Plugging Enable Writing a zero to this bit has no effect. Writing a one to this bit has no effect. This bit is set when Hot-Plugging is enabled. This bit is cleared when Hot-Plugging is disabled. This is the case when the SWCLK function is changed. Only a power-reset or a external reset can set it again. z Bits 3:2 – DCCDx [x=1..0]: Debug Communication Channel x Dirty Writing a zero to this bit has no effect. Writing a one to this bit has no effect. This bit is set when DCCx is written. This bit is cleared when DCCx is read. z Bit 1 – DBGPRES: Debugger Present Writing a zero to this bit has no effect. Writing a one to this bit has no effect. This bit is set when a debugger probe is detected. This bit is never cleared. z Bit 0 – PROT: Protected Writing a zero to this bit has no effect. Writing a one to this bit has no effect. This bit is set at powerup when the device is protected. This bit is never cleared. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 58 13.13.4 Address Name: ADDR Offset: 0x0004 Reset: 0x00000000 Property: Write-Protected Bit 31 30 29 28 27 26 25 24 ADDR[29:22] Access R/W R/W R/W R/W R/W R/W R/W R/W Reset 0 0 0 0 0 0 0 0 Bit 23 22 21 20 19 18 17 16 ADDR[21:14] Access R/W R/W R/W R/W R/W R/W R/W R/W Reset 0 0 0 0 0 0 0 0 Bit 15 14 13 12 11 10 9 8 ADDR[13:6] Access R/W R/W R/W R/W R/W R/W R/W R/W Reset 0 0 0 0 0 0 0 0 Bit 7 6 5 4 3 2 1 0 ADDR[5:0] Access Reset R/W R/W R/W R/W R/W R/W R R 0 0 0 0 0 0 0 0 z Bits 31:2 – ADDR[29:0]: Address Initial word start address needed for memory operations. z Bits 1:0 – 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. These bits will always return zero when read. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 59 13.13.5 Length Name: LENGTH Offset: 0x0008 Reset: 0x00000000 Property: Write-Protected Bit 31 30 29 28 27 26 25 24 LENGTH[29:22] Access R/W R/W R/W R/W R/W R/W R/W R/W Reset 0 0 0 0 0 0 0 0 Bit 23 22 21 20 19 18 17 16 LENGTH[21:14] Access R/W R/W R/W R/W R/W R/W R/W R/W Reset 0 0 0 0 0 0 0 0 Bit 15 14 13 12 11 10 9 8 LENGTH[13:6] Access R/W R/W R/W R/W R/W R/W R/W R/W Reset 0 0 0 0 0 0 0 0 Bit 7 6 5 4 3 2 1 0 LENGTH[5:0] Access Reset R/W R/W R/W R/W R/W R/W R R 0 0 0 0 0 0 0 0 z Bits 31:2 – LENGTH[29:0]: Length Length in words needed for memory operations. z Bits 1:0 – 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. These bits will always return zero when read. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 60 13.13.6 Data Name: DATA Offset: 0x000C Reset: 0x00000000 Property: Write-Protected Bit 31 30 29 28 27 26 25 24 DATA[31:24] Access R/W R/W R/W R/W R/W R/W R/W R/W Reset 0 0 0 0 0 0 0 0 Bit 23 22 21 20 19 18 17 16 DATA[23:16] Access R/W R/W R/W R/W R/W R/W R/W R/W Reset 0 0 0 0 0 0 0 0 Bit 15 14 13 12 11 10 9 8 DATA[15:8] Access R/W R/W R/W R/W R/W R/W R/W R/W Reset 0 0 0 0 0 0 0 0 Bit 7 6 5 4 3 2 1 0 DATA[7:0] Access Reset z R/W R/W R/W R/W R/W R/W R/W R/W 0 0 0 0 0 0 0 0 Bits 31:0 – DATA[31:0]: Data Memory operation initial value or result value. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 61 13.13.7 Debug Communication Channel n Name: DCCn Offset: 0x0010+n*0x4 [n=0..1] Reset: 0x00000000 Property: - Bit 31 30 29 28 27 26 25 24 DATA[31:24] Access R/W R/W R/W R/W R/W R/W R/W R/W Reset 0 0 0 0 0 0 0 0 Bit 23 22 21 20 19 18 17 16 DATA[23:16] Access R/W R/W R/W R/W R/W R/W R/W R/W Reset 0 0 0 0 0 0 0 0 Bit 15 14 13 12 11 10 9 8 DATA[15:8] Access R/W R/W R/W R/W R/W R/W R/W R/W Reset 0 0 0 0 0 0 0 0 Bit 7 6 5 4 3 2 1 0 DATA[7:0] Access Reset z R/W R/W R/W R/W R/W R/W R/W R/W 0 0 0 0 0 0 0 0 Bits 31:0 – DATA[31:0]: Data Data register. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 62 13.13.8 Device Identification Name: DID Offset: 0x0018 Reset: 0x1000XXXX Property: Write-Protected Bit 31 30 29 28 27 26 PROCESSOR[3:0] 25 24 FAMILY[3:0] Access R R R R R R R R Reset 0 0 0 0 0 0 0 0 Bit 23 22 21 20 19 18 17 16 SUBFAMILY[7:0] Access R R R R R R R R Reset 0 0 0 0 0 0 0 0 Bit 15 14 13 12 11 10 9 8 Access R R R R R R R R Reset X X X X X X X X Bit 7 6 5 4 3 2 1 0 DEVSEL[7:0] Access R R R R R R R R Reset X X X X X X X X z Bits 31:28 – PROCESSOR[3:0]: Processor Id Description 0x0 Reserved 0x1 Cortex-M0+ 0x2-0xF Reserved z Bits 27:24 – FAMILY[3:0]: Family Id Description 0x0 General purpose 0x1-0xF Reserved Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 63 z Bits 23:16 – SUBFAMILY[7:0]: Sub-family Id Description 0x00 Baseline 0x01-0xFF Reserved z Bits 15:8 – Reserved These bits are unused and reserved for future use. z Bits 7:0 – DEVSEL[7:0]: Device Select The value of DEVSEL is related to the pin count and flash memory density. Refer to the “Ordering Information SAM D20” on page 4 for details, and Table 13-8. Table 13-8. DEVSEL Select DEVSEL Flash RAM Pincount 0x0 256KB 32KB 64 0x1 128KB 16KB 64 0x2 64KB 8KB 64 0x3 32KB 4KB 64 0x4 16KB 2KB 64 0x5 256KB 32KB 48 0x6 128KB 16KB 48 0x7 64KB 8KB 48 0x8 32KB 4KB 48 0x9 16KB 2KB 48 0xA Reserved 0xB 128KB 16KB 32 0xC 64KB 8KB 32 0xD 32KB 4KB 32 0xE 16KB 2KB 32 0xF-0xFF Reserved Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 64 13.13.9 CoreSight ROM Table Entry n Name: ENTRYn Offset: 0x1000+n*0x4 [n=0..1] Reset: 0xXXXXX00X Property: Write-Protected Bit 31 30 29 28 27 26 25 24 ADDOFF[19:12] Access R R R R R R R R Reset X X X X X X X X Bit 23 22 21 20 19 18 17 16 ADDOFF[11:4] Access R R R R R R R R Reset X X X X X X X X Bit 15 14 13 12 11 10 9 8 ADDOFF[3:0] Access R R R R R R R R Reset X X X X 0 0 0 0 Bit 7 6 5 4 3 2 1 0 FMT EPRES Access R R R R R R R R Reset 0 0 0 0 0 0 1 X z Bits 31:12 – ADDOFF[19:0]: Address Offset The base address of the component, relative to the base address of this ROM table. z Bits 11: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. These bits will always return zero when read. z Bit 1 – FMT: Format Always read as one, indicates a 32-bit ROM table. z Bit 0 – EPRES: Entry Present This bit indicates whether an entry is present at this location in the ROM table. This bit is set at powerup if the device is not protected indicating that the entry is not present. This bit is cleared at powerup if the device is not protected indicating that the entry is present. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 65 13.13.10CoreSight ROM Table End Name: END Offset: 0x1008 Reset: 0x00000000 Property: - Bit 31 30 29 28 27 26 25 24 END[31:24] Access R R R R R R R R Reset 0 0 0 0 0 0 0 0 Bit 23 22 21 20 19 18 17 16 END[23:16] Access R R R R R R R R Reset 0 0 0 0 0 0 0 0 Bit 15 14 13 12 11 10 9 8 END[15:8] Access R R R R R R R R Reset 0 0 0 0 0 0 0 0 Bit 7 6 5 4 3 2 1 0 END[7:0] Access R R R R R R R R Reset 0 0 0 0 0 0 0 0 z Bits 31:0 – END[31:0]: End Marker Indicates the end of the CoreSight ROM table entries. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 66 13.13.11Coresight ROM Table Memory Type Name: MEMTYPE Offset: 0x1FCC Reset: 0x0000000X Property: - Bit 31 30 29 28 27 26 25 24 Access R R R R R R R R Reset 0 0 0 0 0 0 0 0 Bit 23 22 21 20 19 18 17 16 Access R R R R R R R R Reset 0 0 0 0 0 0 0 0 Bit 15 14 13 12 11 10 9 8 Access R R R R R R R R Reset 0 0 0 0 0 0 0 0 Bit 7 6 5 4 3 2 1 0 SMEMP Access R R R R R R R R Reset 0 0 0 0 0 0 0 X z Bits 31:1 – 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. These bits will always return zero when read. z Bit 0 – SMEMP: System Memory Present This bit indicates whether system memory is present on the bus that connects to the ROM table. This bit is set at powerup if the device is not protected indicating that the system memory is accessible from a debug adapter. This bit is cleared at powerup if the device is protected indicating that the system memory is not accessible from a debug adapter. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 67 13.13.12Peripheral Identification 4 Name: PID4 Offset: 0x1FD0 Reset: 0x00000000 Property: - Bit 31 30 29 28 27 26 25 24 Access R R R R R R R R Reset 0 0 0 0 0 0 0 0 Bit 23 22 21 20 19 18 17 16 Access R R R R R R R R Reset 0 0 0 0 0 0 0 0 Bit 15 14 13 12 11 10 9 8 Access R R R R R R R R Reset 0 0 0 0 0 0 0 0 Bit 7 6 5 4 3 2 1 0 FKBC[3:0] JEPCC[3:0] Access R R R R R R R R Reset 0 0 0 0 0 0 0 0 z Bits 31:8 – 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. These bits will always return zero when read. z Bits 7:4 – FKBC[3:0]: 4KB count These bits will always return zero when read, indicating that this debug component occupies one 4KB block. z Bits 3:0 – JEPCC[3:0]: JEP-106 Continuation Code These bits will always return zero when read, indicating a Atmel device. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 68 13.13.13Peripheral Identification 0 Name: PID0 Offset: 0x1FE0 Reset: 0x000000D0 Property: - Bit 31 30 29 28 27 26 25 24 Access R R R R R R R R Reset 0 0 0 0 0 0 0 0 Bit 23 22 21 20 19 18 17 16 Access R R R R R R R R Reset 0 0 0 0 0 0 0 0 Bit 15 14 13 12 11 10 9 8 Access R R R R R R R R Reset 0 0 0 0 0 0 0 0 Bit 7 6 5 4 3 2 1 0 PARTNBL[7:0] Access R R R R R R R R Reset 1 1 0 1 0 0 0 0 z Bits 31:8 – 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. These bits will always return zero when read. z Bits 7:0 – PARTNBL[7:0]: Part Number Low These bits will always return 0xD0 when read, indicating that this device implements a DSU module instance. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 69 13.13.14Peripheral Identification 1 Name: PID1 Offset: 0x1FE4 Reset: 0x000000FC Property: - Bit 31 30 29 28 27 26 25 24 Access R R R R R R R R Reset 0 0 0 0 0 0 0 0 Bit 23 22 21 20 19 18 17 16 Access R R R R R R R R Reset 0 0 0 0 0 0 0 0 Bit 15 14 13 12 11 10 9 8 Access R R R R R R R R Reset 0 0 0 0 0 0 0 0 Bit 7 6 5 4 3 2 1 0 JEPIDCL[3:0] PARTNBH[3:0] Access R R R R R R R R Reset 1 1 1 1 1 1 0 0 z Bits 31:8 – 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. These bits will always return zero when read. z Bits 7:4 – JEPIDCL[3:0]: Low part of the JEP-106 Identity Code These bits will always return 0xF when read, indicating a Atmel device (Atmel JEP-106 identity code is 0x1F). z Bits 3:0 – PARTNBH[3:0]: Part Number High These bits will always return 0xC when read, indicating that this device implements a DSU module instance. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 70 13.13.15Peripheral Identification 2 Name: PID2 Offset: 0x1FE8 Reset: 0x00000009 Property: - Bit 31 30 29 28 27 26 25 24 Access R R R R R R R R Reset 0 0 0 0 0 0 0 0 Bit 23 22 21 20 19 18 17 16 Access R R R R R R R R Reset 0 0 0 0 0 0 0 0 Bit 15 14 13 12 11 10 9 8 Access R R R R R R R R Reset 0 0 0 0 0 0 0 0 Bit 7 6 5 4 3 2 1 0 REVISION[3:0] JEPU JEPIDCH[2:0] Access R R R R R R R R Reset 0 0 0 0 1 0 0 1 z Bits 31:8 – 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. These bits will always return zero when read. z Bits 7:4 – REVISION[3:0]: Revision Number Revision of the peripheral. Starts at 0x0 and increments by one at both major and minor revisions. z Bit 3 – JEPU: JEP-106 Identity Code is used This bit will always return one when read, indicating that JEP-106 code is used. z Bits 2:0 – JEPIDCH[2:0]: JEP-106 Identity Code High These bits will always return 0x1 when read, indicating a Atmel device (Atmel JEP-106 identity code is 0x1F). Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 71 13.13.16Peripheral Identification 3 Name: PID3 Offset: 0x1FEC Reset: 0x00000000 Property: - Bit 31 30 29 28 27 26 25 24 Access R R R R R R R R Reset 0 0 0 0 0 0 0 0 Bit 23 22 21 20 19 18 17 16 Access R R R R R R R R Reset 0 0 0 0 0 0 0 0 Bit 15 14 13 12 11 10 9 8 Access R R R R R R R R Reset 0 0 0 0 0 0 0 0 Bit 7 6 5 4 3 2 1 0 REVAND[3:0] CUSMOD[3:0] Access R R R R R R R R Reset 0 0 0 0 0 0 0 0 z Bits 31:8 – 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. These bits will always return zero when read. z Bits 7:4 – REVAND[3:0]: Revision Number These bits will always return 0x0 when read. z Bits 3:0 – CUSMOD[3:0]: ARM CUSMOD These bits will always return 0x0 when read. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 72 13.13.17Component Identification 0 Name: CID0 Offset: 0x1FF0 Reset: 0x0000000D Property: - Bit 31 30 29 28 27 26 25 24 Access R R R R R R R R Reset 0 0 0 0 0 0 0 0 Bit 23 22 21 20 19 18 17 16 Access R R R R R R R R Reset 0 0 0 0 0 0 0 0 Bit 15 14 13 12 11 10 9 8 Access R R R R R R R R Reset 0 0 0 0 0 0 0 0 Bit 7 6 5 4 3 2 1 0 PREAMBLEB0[7:0] Access R R R R R R R R Reset 0 0 0 0 1 1 0 1 z Bits 31:8 – 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. These bits will always return zero when read. z Bits 7:0 – PREAMBLEB0[7:0]: Preamble Byte 0 These bits will always return 0xD when read. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 73 13.13.18Component Identification 1 Name: CID1 Offset: 0x1FF4 Reset: 0x00000010 Property: - Bit 31 30 29 28 27 26 25 24 Access R R R R R R R R Reset 0 0 0 0 0 0 0 0 Bit 23 22 21 20 19 18 17 16 Access R R R R R R R R Reset 0 0 0 0 0 0 0 0 Bit 15 14 13 12 11 10 9 8 Access R R R R R R R R Reset 0 0 0 0 0 0 0 0 Bit 7 6 5 4 3 2 1 0 CCLASS[3:0] PREAMBLE[3:0] Access R R R R R R R R Reset 0 0 0 1 0 0 0 0 z Bits 31:8 – 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. These bits will always return zero when read. z Bits 7:4 – CCLASS[3:0]: Component Class These bits will always return 0x1 when read indicating that this ARM CoreSight component is ROM table (refer to the ARM Debug Interface v5 Architecture Specification at http://www.arm.com). z Bits 3:0 – PREAMBLE[3:0]: Preamble These bits will always return 0x0 when read. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 74 13.13.19Component Identification 2 Name: CID2 Offset: 0x1FF8 Reset: 0x00000005 Property: - Bit 31 30 29 28 27 26 25 24 Access R R R R R R R R Reset 0 0 0 0 0 0 0 0 Bit 23 22 21 20 19 18 17 16 Access R R R R R R R R Reset 0 0 0 0 0 0 0 0 Bit 15 14 13 12 11 10 9 8 Access R R R R R R R R Reset 0 0 0 0 0 0 0 0 Bit 7 6 5 4 3 2 1 0 PREAMBLEB2[7:0] Access R R R R R R R R Reset 0 0 0 0 0 1 0 1 z Bits 31:8 – 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. These bits will always return zero when read. z Bits 7:0 – PREAMBLEB2[7:0]: Preamble Byte 2 These bits will always return 0x05 when read. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 75 13.13.20Component Identification 3 Name: CID3 Offset: 0x1FFC Reset: 0x000000B1 Property: - Bit 31 30 29 28 27 26 25 24 Access R R R R R R R R Reset 0 0 0 0 0 0 0 0 Bit 23 22 21 20 19 18 17 16 Access R R R R R R R R Reset 0 0 0 0 0 0 0 0 Bit 15 14 13 12 11 10 9 8 Access R R R R R R R R Reset 0 0 0 0 0 0 0 0 Bit 7 6 5 4 3 2 1 0 PREAMBLEB3[7:0] Access R R R R R R R R Reset 1 0 1 1 0 0 0 1 z Bits 31:8 – 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. These bits will always return zero when read. z Bits 7:0 – PREAMBLEB3[7:0]: Preamble Byte 3 These bits will always return 0xB1 when read. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 76 14. Clock System This chapter only aims to summarize the clock distribution and terminology in the SAMD20 device. It will not explain every detail of its configuration. For in-depth documentation, see the referenced module chapters. 14.1 Clock Distribution Figure 14-1. Clock distribution PM SYSCTRL GCLK XOSC GCLK Generator 0 GCLK Multiplexer 0 (DFLL48M Reference) GCLK Generator 1 GCLK Multiplexer 1 OSCULP32K OSC32K GCLKMAIN XOSC32K Peripheral 0 Generic Clocks OSC8M DFLL48M Syncronous Clock Controller GCLK Generator x GCLK Multiplexer y Peripheral z AHB/APB System Clocks The clock system on the SAMD20 consists of: z Clock sources, controlled by SYSCTRL z z z A Clock source is the base clock signal used in the system. Example clock sources are the internal 8MHz oscillator (OSC8M), External crystal oscillator (XOSC) and the Digital frequency locked loop (DFLL48M). Generic Clock Controller (GCLK) which controls the clock distribution system, made up of: z Generic Clock generators: A programmable prescaler, that can use any of the system clock sources as its source clock. The Generic Clock Generator 0, also called GCLKMAIN, is the clock feeding the Power Manager used to generate synchronous clocks. z Generic Clocks: Typically the clock input of a peripheral on the system. The generic clocks, through the Generic Clock Multiplexer, can use any of the Generic Clock generators as its clock source. Multiple instances of a peripheral will typically have a separate generic clock for each instance. The DFLL48M clock input (when multiplying another clock source) is generic clock 0. Power Manager (PM) z The PM controls synchronous clocks on the system. This includes the CPU, BUS clocks (APB, AHB) as well as the synchronous (to the CPU) user interfaces of the peripherals. It contains clock masks that can turn on/off the user interface of a peripheral as well as prescalers for the CPU and bus clocks. Figure 14-2 shows an example where SERCOM0 is clocked by the DFLL48M in open loop mode. The DFLL48M is enabled, the Generic Clock Generator 1 uses the DFLL48M as its clock source, and the generic clock 13, also called GCLK_SERCOM0_CORE, that is connected to SERCOM0 uses generator 1 as its source. The SERCOM0 interface, clocked by CLK_SERCOM0_APB, has been unmasked in the APBC Mask register in the PM. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 77 Figure 14-2. Example of SERCOM clock PM Syncronous Clock Controller SYSCTRL DFLL48M 14.2 CLK_SERCOM0_APB GCLK Generic Clock Generator 1 Generic Clock Multiplexer 13 GCLK_SERCOM0_CORE SERCOM 0 Synchronous and Asynchronous Clocks As the CPU and the peripherals can be clocked from different clock sources, possibly with widely different clock speeds, some peripheral accesses by the CPU needs to be synchronized between the different clock domains. In these cases the peripheral includes a SYNCBUSY status flag that can be used to check if a sync operation is in progress. As the nature of the synchronization might vary between different peripherals, detailed description for each peripheral can be found in the sub-chapter “synchronization” for each peripheral where this is necessary. In the datasheet references to synchronous clocks are referring to the CPU and bus clocks, while asynchronous clocks are clock generated by generic clocks. 14.3 Register Synchronization 14.3.1 Overview All peripherals are composed of one digital bus interface, which is connected to the APB or AHB bus and clocked using a corresponding synchronous clock, and one core clock, which is clocked using a generic clock. Access between these clock domains must be synchronized. As this mechanism is implemented in hardware the synchronization process takes place even if the different clocks domains are clocked from the same source and on the same frequency. All registers in the bus interface are accessible without synchronization. All core registers in the generic clock domain must be synchronized when written. Some core registers must be synchronized when read. Registers that need synchronization has this denoted in each individual register description. Two properties are used: write-synchronization and readsynchronization. A common synchronizer is used for all registers in one peripheral, as shown in Figure 14-3. Therefore, only one register per peripheral can be synchronized at a time. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 78 Figure 14-3. Synchronization Asynchronous Domain (generic clock) Synchronous Domain (CLK_APB) Sync Non Sync'd reg Peripheral bus INTFLAG Write-Sync'd reg SYNCBUSY STATUS READREQ Synchronizer Write-Sync'd reg R/W-Sync'd reg 14.3.2 Write-Synchronization The write-synchronization is triggered by a write to any generic clock core register. The Synchronization Busy bit in the Status register (STATUS.SYNCBUSY) will be set when the write-synchronization starts and cleared when the writesynchronization is complete. Refer to REF for details on the synchronization delay. When the write-synchronization is ongoing (STATUS.SYNCBUSY is one), any of the following actions will cause the peripheral bus to stall until the synchronization is complete: z Writing a generic clock core register z Reading a read-synchronized core register z Reading the register that is being written (and thus triggered the synchronization) Core registers without read-synchronization will remain static once they have been written and synchronized, and can be read while the synchronization is ongoing without causing the peripheral bus to stall. APB registers can also be read while the synchronization is ongoing without causing the peripheral bus to stall. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 79 14.3.3 Read-Synchronization Reading a read-synchronized core register will cause the peripheral bus to stall immediately until the readsynchronization is complete. STATUS.SYNCBUSY will not be set. Refer to REF for details on the synchronization delay. Note that reading a read-synchronized core register while STATUS.SYNCBUSY is one will cause the peripheral bus to stall twice; first because of the ongoing synchronization, and then again because reading a read-synchronized core register will cause the peripheral bus to stall immediately. 14.3.4 Completion of synchronization The user can either poll STATUS.SYNCBUSY or use the Synchronisation Ready interrupt (if available) to check when the synchronization is complete. It is also possible to perform the next read/write operation and wait, as this next operation will be started once the previous write/read operation is synchronized and/or complete. 14.3.5 Read Request The read request functionality is only available to peripherals that have the Read Request register (READREQ) implemented. Refer to the register description of individual peripheral chapters for details. To avoid forcing the peripheral bus to stall when reading read-synchronized core registers, the read request mechanism can be used. 14.3.5.1 Basic Read Request Writing a one to the Read Request bit in the Read Request register (READREQ.RREQ) will request readsynchronization of the register specified in the Address bits in READREQ (READREQ.ADDR) and set STATUS.SYNCBUSY. When read-synchronization is complete, STATUS.SYNCBUSY is cleared. The readsynchronized value is then available for reading without delay until READREQ.RREQ is written to one again. The address to use is the offset to the peripherals base address of the register that should be synchronized. HJELP! 14.3.5.2 Continuous Read Request Writing a one to the Read Continuously bit in READREQ (READREQ.RCONT) will force continuous readsynchronization of the register specified in READREQ.ADDR. The latest value is always available for reading without stalling the bus, as the synchronization mechanism is continuously synchronizing the given value. SYNCBUSY is set for the first synchronization, but not for the subsequent synchronizations. If another synchronization is attempted, i.e. by executing a write-operation of a write-synchronized register, the read request will be stopped, and will have to be manually restarted. Note that continuous read-synchronization is paused in sleep modes where the generic clock is not running. This means that a new read request is required if the value is needed immediately after exiting sleep. 14.3.6 Enable Write-Synchronization Writing to the Enable bit in the Control register (CTRL.ENABLE) will also trigger write-synchronization and set STATUS.SYNCBUSY. CTRL.ENABLE will read its new value immediately after being written. The Synchronisation Ready interrupt (if available) cannot be used for Enable write-synchronization. When the enable write-synchronization is ongoing (STATUS.SYNCBUSY is one), attempt to do any of the following will cause the peripheral bus to stall until the enable synchronization is complete: z Writing a core register z Writing an APB register z Reading a read-synchronized core register APB registers can be read while the enable write-synchronization is ongoing without causing the peripheral bus to stall. 14.3.7 Software Reset Write-Synchronization Writing a one to the Software Reset bit in CTRL (CTRL.SWRST) will also trigger write-synchronization and set STATUS.SYNCBUSY. When writing a one to the CTRL.SWRST bit it will immediately read as one. CTRL.SWRST and Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 80 STATUS.SYNCBUSY will be cleared by hardware when the peripheral has been reset. Writing a zero to the CTRL.SWRST bit has no effect. The Synchronisation Ready interrupt (if available) cannot be used for Software Reset write-synchronization. When the software reset is in progress (STATUS.SYNCBUSY and CTRL.SWRST are one), attempt to do any of the following will cause the peripheral bus to stall until the Software Reset synchronization and the reset is complete: z Writing a core register z Writing an APB register z Reading a read-synchronized register APB registers can be read while the software reset is being write-synchronized without causing the peripheral bus to stall. 14.3.8 Synchronization Delay The synchronization will delay the write or read access duration by a delay D, given by the equation: 5 ⋅ P GCLK + 2 ⋅ P APB < D < 6 ⋅ P GCLK + 3 ⋅ P APB Where P GCLK is the period of the generic clock and P APB is the period of the peripheral bus clock. A normal peripheral bus register access duration is 2 ⋅ P APB . 14.4 Enabling a Peripheral To enable a peripheral clocked by a generic clock, the following parts of the system needs to be configured: 14.5 z A running clock source. z A clock from the Generic Clock Generator must be configured to use one of the running clock sources, and the generator must be enabled. z The generic clock, through the Generic Clock Multiplexer, that connects to the peripheral needs to be configured with a running clock from the Generic Clock Generator, and the generic clock must be enabled. z The user interface of the peripheral needs to be unmasked in the PM. If this is not done the peripheral registers will read as all 0’s and any writes to the peripheral will be discarded. On-demand, Clock Requests Figure 14-4. Clock request routing Clock request DFLL48M Generic Clock Generator ENABLE GENEN RUNSTDBY RUNSTDBY Clock request Generic Clock Multiplexer CLKEN Clock request Peripheral ENABLE RUNSTDBY ONDEMAND All the clock sources in the system can be run in an on-demand mode, where the clock source is in a stopped state when no peripherals are requesting the clock source. Clock requests propagate from the peripheral, via the GCLK, to the clock source. If one or more peripheral is using a clock source, the clock source will be started/kept running. As soon as the clock source is no longer needed and no peripheral have an active request the clock source will be stopped until requested again. For the clock request to reach the clock source, the peripheral, the generic clock and the clock from the Generic Clock Generator in-between must be enabled. The time taken from a clock request being asserted to the clock source being ready is dependent on the clock source startup time, clock source frequency as well as the divider used in the Generic Clock Generator. The total startup time from a clock request to the clock is available for the peripheral is: Delay_start_max = Clock source startup time + 2 * clock source periods + 2 * divided clock source periods Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 81 Delay_start_min = Clock source startup time + 1 * clock source period + 1 * divided clock source period The delay for shutting down the clock source when there is no longer an active request is: Delay_stop_min = 1 * divided clock source period + 1 * clock source period Delay_stop_max = 2 * divided clock source periods + 2 * clock source periods The On-Demand principle can be disabled individually for each clock source by clearing the ONDEMAND bit located in each clock source controller. The clock is always running whatever is the clock request. This has the effect to remove the clock source startup time at the cost of the power consumption. In standby mode, the clock request mechanism is still working if the modules are configured to run in standby mode (RUNSTDBY bit). 14.6 Power Consumption vs Speed Due to the nature of the asynchronous clocking of the peripherals there are some considerations that needs to be taken if either targeting a low-power or a fast-acting system. If clocking a peripheral with a very low clock, the active power consumption of the peripheral will be lower. At the same time the synchronization to the synchronous (CPU) clock domain is dependent on the peripheral clock speed, and will be longer with a slower peripheral clock; giving lower response time and more time waiting for the synchronization to complete. 14.7 Clocks after Reset On any reset the synchronous clocks start to their initial state: z OSC8M is enabled and divided by 8 z GCLKMAIN uses OSC8M as source z CPU and BUS clocks are undivided On a power reset the GCLK starts to their initial state: z z All generic clock generators disabled except: z the generator 0 (GCLKMAIN) using OSC8M as source, with no division z the generator 2 using OSCULP32K as source, with no division All generic clocks disabled except: z the WDT generic clock using the generator 2 as source On a user reset the GCLK starts to their initial state, except for: z generic clocks that are write-locked (WRTLOCK is written to one prior to reset or the WDT generic clock if the WDT Always-On at power on bit set in the NVM User Row) z The generic clock dedicated to the RTC if the RTC generic clock is enabled On any reset the clock sources are reset to their initial state except the 32KHz clock sources which are reset only by a power reset. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 82 15. GCLK – Generic Clock Controller 15.1 Overview Several peripherals may require specific clock frequencies to operate correctly. The GCLK provides a number of generic clock generators that can provide a wide range of clock frequencies. The generic clock generators can be set to use different external and internal clock sources. The clock in each generic clock generator can be divided down. The outputs from the generic clock generators are used as clock sources for the generic clock multiplexers, which select one of the sources to generate a generic clock (GCLK_PERIPH), as shown in Figure 15-2. The number of generic clocks, m, depends on how many peripherals the device has. 15.2 Features z Provides a user-defined number (max 64) of generic clocks z Wide frequency range 15.3 Block Diagram The GCLK can be seen in the clocking diagram, which is shown in Figure 15-1 . Figure 15-1. Device Clocking Diagram GENERIC CLOCK CONTROLLER SYSCTRL Generic Clock Generator XOSC OSCULP32K Generic Clock Multiplexer OSC32K GCLK_PERIPH XOSC32K OSC8M DFLL48M Clock Divider & Masker Clock Gate PERIPHERALS GCLK_IO GCLKMAIN PM The GCLK block diagram is shown in Figure 15-2 . Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 83 Figure 15-2. Generic Clock Controller Block Diagram Generic Clock Generator 0 Clock Sources Clock Divider & Masker GCLK_IO[0] (I/O input) GCLKMAIN GCLKGEN[0] Generic Clock Multiplexer 0 GCLK_PERIPH[0] Clock Gate Generic Clock Generator 1 Generic Clock Multiplexer 1 Clock Divider & Masker GCLK_IO[1] (I/O input) GCLK_IO[0] (I/O output) GCLK_IO[1] (I/O output) GCLKGEN[1] GCLK_PERIPH[1] Clock Gate Generic Clock Generator n Clock Divider & Masker GCLK_IO[n] (I/O input) GCLK_IO[n] (I/O output) GCLKGEN[n] Generic Clock Multiplexer m Clock Gate GCLK_PERIPH[m]] GCLKGEN[n:0] 15.4 Signal Description Signal Name Type GCLK_IO[n..0] Digital I/O Description Source clock when input Generic clock when output Please refer to “I/O Multiplexing and Considerations” on page 15 for details on the pin mapping for this peripheral. One signal can be mapped on several pins. 15.5 Product Dependencies In order to use this peripheral, other parts of the system must be configured correctly, as described below. 15.5.1 I/O Lines Using the GCLK’s I/O lines requires the I/O pins to be configured. Refer to “PORT” on page 289 for details. 15.5.2 Power Management The GCLK can operate in all sleep modes, if required. Refer to “PM – Power Manager” on page 105 for details on the different sleep modes. 15.5.3 Clocks The GCLK bus clock (CLK_GCLK_APB) can be enabled and disabled in the Power Manager, and the default state of CLK_GCLK_APB can be found in the Peripheral Clock Masking section in “PM – Power Manager” on page 105. 15.5.4 Interrupts Not applicable. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 84 15.5.5 Events Not applicable. 15.5.6 Debug Operation Not applicable. 15.5.7 Register Access Protection All registers with write-access are optionally write-protected by the Peripheral Access Controller (PAC). Write-protection is denoted by the Write-Protection property in the register description. When the CPU is halted in debug mode or the CPU reset is extended, all write-protection is automatically disabled. Write-protection does not apply for accesses through an external debugger. Refer to “PAC – Peripheral Access Controller” on page 31 for details. 15.5.8 Analog Connections Not applicable. 15.6 Functional Description 15.6.1 Principle of Operation The GCLK module is comprised of eight generic clock generators sourcing m generic clock multiplexers. A clock source selected as input to one of the generic clock generators can be used directly, or it can be prescaled in the generic clock generator before the generator output is used as input to one or more of the generic clock multiplexers . A generic clock multiplexer provides a generic clock to the peripherals (GCLK_PERIPHERAL). A generic clock can act as the clock to one or several of the peripherals. 15.6.2 Basic Operation 15.6.2.1 Initialization Before a generic clock is enabled, the clock source of its generic clock generator should be enabled. The generic clock must be configured as outlined by the following steps: 1. 2. 3. The generic clock generator division factor must be set by performing a single 32-bit write to the Generic Clock Generator Division register (GENDIV): z The generic clock generator that will be selected as the source of the generic clock must be written to the ID bit group (GENDIV.ID) z The division factor must be written to the DIV bit group (GENDIV.DIV) The generic clock generator must be enabled by performing a single 32-bit write to the Generic Clock Generator Control register (GENCTRL): z The generic clock generator that will be selected as the source of the generic clock must be written to the ID bit group (GENCTRL.ID) z The generic clock generator must be enabled by writing a one to the GENEN bit (GENCTRL.GENEN) The generic clock must be configured by performing a single 16-bit write to the Generic Clock Control register (CLKCTRL): z The generic clock that will be configured must be written to the ID bit group (CLKCTRL.ID) z The generic clock generator used as the source of the the generic clock must be written to the GEN bit group (CLKCTRL.GEN). 15.6.2.2 Enabling, Disabling and Resetting The GCLK module has no enable/disable bit to enable or disable the whole module. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 85 The GCLK is reset by writing a one to the Software Reset bit in the Control register (CTRL.SWRST). All registers in the GCLK will be reset to their initial state except for generic clocks and associated generators that have their Write Lock bit written to one. Refer to “Configuration Lock” on page 88 for details. 15.6.2.3 Generic Clock Generator Each generic clock generator (GCLKGEN) can be set to run from one of eight different clock sources except GCLKGEN[1] which can be set to run from one of seven sources. GCLKGEN[1] can act as source to the other generic clock generators but can not act as source to itself. Each generic clock generator GCLKGEN[x] can be connected to one specific GCLK_IO[x] pin. The GCLK_IO[x] can be set to act as source to GCLKGEN[x] or GCLK_IO[x] can be set up to output the clock generated by GCLKGEN[x]. The selected source (GCLKGENSRC see Figure 15-3) can optionally be divided. Each generic clock generator can be independently enabled and disabled. Each GCLKGEN clock can then be used as a clock source for the generic clock multiplexers. Each generic clock is allocated to one or several peripherals. GCLKGEN[0], is used as GCLKMAIN for the synchronous clock controller inside the Power Manager. Refer to “PM – Power Manager” on page 105 for details on the synchronous clock generation. Figure 15-3. Generic Clock Generator Clock Sources 0 GCLKGENSRC DIVIDER Clock Gate GCLKGEN 1 GCLK_IO GENCTRL.GENEN GENCTRL.DIVSEL GENCTRL.SRC GENDIV.DIV 15.6.2.4 Enabling a Generic Clock Generator A generic clock generator is enabled by writing a one to the Generic Clock Generator Enable bit in the Generic Clock Generator Control register (GENCTRL.GENEN). 15.6.2.5 Disabling a Generic Clock Generator A generic clock generator is disabled by writing a zero to GENCTRL.GENEN. When GENCTRL.GENEN is read as zero, the GCLKGEN clock is disabled and clock gated. 15.6.2.6 Selecting a Clock Source for the Generic Clock Generator Each generic clock generator can individually select a clock source by writing to the Source Select bit group in GENCTRL (GENCTRL.SRC). Changing from one clock source, A, to another clock source, B, can be done on the fly. If clock source B is not ready, the generic clock generator will continue running with clock source A. As soon as clock source B is ready, however, the generic clock generator will switch to it. During the switching, the generic clock generator holds clock requests to clock sources A and B and then releases the clock source A request when the switch is done. The available clock sources are device dependent (usually the oscillators, RC oscillators, PLL and DFLL clocks). GCLKGEN[1] can be used as a common source for all the generic clock generators except generic clock generator 1. 15.6.2.7 Changing Clock Frequency The selected generic clock generator source, GENCLKSRC can optionally be divided by writing a division factor Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 86 in the Division Factor bit group in the Generic Clock Generator Division register (GENDIV.DIV). Depending on the value of the Divide Selection bit in GENCTRL (GENCTRL.DIVSEL), it can be interpreted in two ways by the integer divider, as shown in Table 15-1. Note that the number of DIV bits for each generic clock generator is device dependent. Refer to Table 15-10 for details. Table 15-1. Division Factor GENCTRL.DIVSEL Division Factor 0 GENDIV.DIV 1 2^(GENDIV.DIV+1) If GENCTRL.DIVSEL is zero and GENDIV.DIV is zero or one, the output clock will be undivided. 15.6.2.8 Duty Cycle 15.6.2.9 When dividing a clock with an odd division factor, the duty-cycle will not be 50/50. Writing a one to the Improve Duty Cycle bit in GENCTRL (GENCTRL.IDC) will result in a 50/50 duty cycle.External Clock Each generic clock generator output clock (GCLKGEN) can be output. If the Output Enable bit in GENCTRL (GENCTRL.OE) is one and the generic clock generator is enabled (GENCTRL.GENEN is one), the generic clock generator requests its clock source and the GCLKGEN clock is output to a GCLK_IO pin. If GENCTRL.OE is zero, GCLK_IO is set according to the Output Off Value bit. If the Output Off Value bit in GENCTRL (GENCTRL.OOV) is zero, the output clock will be low when turned off. If GENCTRL.OOV is one, the output clock will be high when turned off. In standby mode, if the clock is output (GENCTRL.OE is one), the clock on the GCLK_IO pin is frozen to the OOV value if the Run In Standby bit in GENCTRL (GENCTRL.RUNSTDBY) is zero. If GENCTRL.RUNSTDBY is one, the GCLKGEN clock is kept running and output to GCLK_IO. 15.6.3 Generic Clock Figure 15-4. Generic Clock GCLKGEN[0] GCLKGEN[1] GCLKGEN[2] GCLKGEN[n] Clock Gate GCLK_PERIPH CLKCTRL.CLKEN CLKCTRL.GEN 15.6.3.1 Enabling a Generic Clock Before a generic clock is enabled, one of the generic clock generators must be selected as the source for the generic clock by writing to CLKCTRL.GEN. The clock source selection is individually set for each generic clock. When a generic clock generator has been selected, the generic clock is enabled by writing a one to the Clock Enable bit in CLKCTRL (CLKCTRL.CLKEN). The CLKCTRL.CLKEN bit must be synchronized to the generic clock domain. CLKCTRL.CLKEN will continue to read as its previous state until the synchronization is complete. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 87 15.6.3.2 Disabling a Generic Clock A generic clock is disabled by writing a zero to CLKCTRL.CLKEN. The CLKCTRL.CLKEN bit must be synchronized to the generic clock domain and the clock actually switched off. CLKCTRL.CLKEN will continue to read as its previous state until the synchronization is complete. When the generic clock is disabled, the generic clock is clock gated. 15.6.3.3 Selecting a Clock Source for the Generic Clock When changing a generic clock source by writing to CLKCTRL.GEN, the generic clock must be disabled before being reenabled with the new clock source setting. This prevents glitches during the transition: a. Write a zero to CLKCTRL.CLKEN b. Wait until CLKCTRL.CLKEN reads as zero c. Change the source of the generic clock by writing CLKCTRL.GEN d. Re-enable the generic clock by writing a one to CLKCTRL.CLKEN 15.6.3.4 Configuration Lock The generic clock configuration is locked for further write accesses by writing the Write Lock bit (WRTLOCK) in the CLKCTRL register. All writes to the CLKCTRL register will be ignored. It can only be unlocked by a power reset. The generic clock generator sources of a “locked” generic clock are also locked. The corresponding GENCTRL and GENDIV are locked, and can be unlocked only by a power reset. There is one exception concerning the GCLKGEN[0]. As it is used as GCLKMAIN, it can not be locked. It is reset by any reset to startup with a known configuration. The SWRST can not unlock the registers. 15.6.4 Additional Features 15.6.4.1 Indirect Access The Generic Clock Generator Control and Division registers (GENCTRL and GENDIV) and the Generic Clock Control register (CLKCTRL) are indirectly addressed as shown in Figure 15-5. Figure 15-5. GCLK Indirect Access User Interface GCLK Generator [i] GENCTRL GENDIV CLKCTRL GENCTRL.ID=i GENCTRL GENDIV.ID=i GENDIV CLKCTRL.ID=j GCLK[j] CLKCTRL Writing these registers is done by setting the corresponding ID bit group. To read a register, the user must write (byte access) the ID of the channel, i, in the corresponding register. The value of the register for the corresponding ID is available in the user interface by a read access. For example, the sequence to read the GENCTRL register of generic clock generator i is: a. Do an 8-bit write of the i value to GENCTRL.ID b. Read GENCTRL Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 88 15.6.4.2 Generic Clock Enable after Reset The Generic Clock Controller must be able to provide a generic clock to some specific peripherals after a reset. That means that the configuration of the generic clock generators and generic clocks after reset is device-dependent. Refer to Table 15-8 and Table 15-9 for details on GENCTRL reset. Refer to Table 15-12 and Table 15-13 for details on GENDIV reset. Refer to Table 15-4 and Table 15-5 for details on CLKCTRL reset. 15.6.5 Sleep Mode Operation 15.6.5.1 SleepWalking The GCLK module supports the SleepWalking feature. During a sleep mode where the generic clocks are stopped, a peripheral that needs its generic clock to execute a process must request it from the Generic Clock Controller. The Generic Clock Controller will receive this request and then determine which generic clock generator is involved and which clock source needs to be awakened. It then wakes up the clock source, enables the generic clock generator and generic clock stages successively and delivers the generic clock to the peripheral. 15.6.5.2 Run in Standby Mode In standby mode, the GCLK can continuously output the generic clock generator output to GCLK_IO. Refer to “When dividing a clock with an odd division factor, the duty-cycle will not be 50/50. Writing a one to the Improve Duty Cycle bit in GENCTRL (GENCTRL.IDC) will result in a 50/50 duty cycle.External Clock” on page 87 for details. 15.6.6 Synchronization Due to the asynchronicity between CLK_GCLK_APB and GCLKGENSRC some registers must be synchronized when accessed. A register can require: z Synchronization when written z Synchronization when read z Synchronization when written and read z No synchronization When executing an operation that requires synchronization, the Synchronization Busy bit in the Status register (STATUS.SYNCBUSY) will be set immediately, and cleared when synchronization is complete. If an operation that requires synchronization is executed while STATUS.SYNCBUSY is one, the bus will be stalled. All operations will complete successfully, but the CPU will be stalled and interrupts will be pending as long as the bus is stalled. The following registers need synchronization when written: z Generic Clock Generator Control register (GENCTRL) z Generic Clock Generator Division register (GENDIV) z Control register (CTRL) Write-synchronization is denoted by the Write-Synchronization property in the register description. Refer to the Synchronization chapter for further details. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 89 15.7 Register Summary Offset Name Bit Pos. 0x0 CTRL 7:0 0x1 STATUS 7:0 0x2 SWRST SYNCBUSY 7:0 ID[5:0] CLKCTRL 0x3 15:8 0x4 7:0 0x5 WRTLOCK CLKEN GEN[3:0] ID[3:0] 15:8 SRC[4:0] GENCTRL 0x6 23:16 0x7 31:24 0x8 7:0 0x9 RUNSTDBY DIVSEL OE OOV IDC GENEN ID[3:0] 15:8 DIV[7:0] 0xA 23:16 DIV[15:8] 0xB 31:24 GENDIV Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 90 15.8 Register Description Registers can be 8, 16 or 32 bits wide. Atomic 8-, 16- and 32-bit accesses are supported. In addition, the 8-bit quarters and 16-bit halves of a 32-bit register and the 8-bit halves of a 16-bit register can be accessed directly. Some registers are optionally write-protected by the Peripheral Access Controller (PAC). Write-protection is denoted bythe Write-protected property in each individual register description. Please refer to “Register Access Protection” on page 85 for details. Some registers require synchronization when read and/or written. Synchronization is denoted by the Write-Synchronized or the Read-Synchronized property in each individual register description. Please refer to “Synchronization” on page 89 for details. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 91 15.8.1 Control Name: CTRL Offset: 0x0 Reset: 0x00 Property: Write-Protected, Write-Synchronized Bit 7 6 5 4 3 2 1 0 SWRST Access R R R R R R R R/W Reset 0 0 0 0 0 0 0 0 z Bits 7:1 – 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. These bits will always return zero when read. z Bit 0 – SWRST: Software Reset 0: There is no reset operation ongoing. 1: There is a reset operation ongoing. Writing a zero to this bit has no effect. Writing a one to this bit resets all registers in the GCLK to their initial state after a power reset, except for generic clocks and associated generators that have their WRTLOCK bit in CLKCTRL read as one. Refer to Table 15-8 for details on GENCTRL reset. Refer to Table 15-12 for details on GENDIV reset. Refer to Table 15-4 for details on CLKCTRL reset. Due to synchronization, there is a delay from writing CTRL.SWRST until the reset is complete. CTRL.SWRST and STATUS.SYNCBUSY will both be cleared when the reset is complete. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 92 15.8.2 Status Name: STATUS Offset: 0x1 Reset: 0x00 Property: – Bit 7 6 5 4 3 2 1 0 SYNCBUSY Access R R R R R R R R Reset 0 0 0 0 0 0 0 0 z Bit 7 – SYNCBUSY: Synchronization Busy Status This bit is cleared when the synchronization of registers between the clock domains is complete. This bit is set when the synchronization of registers between clock domains is started. z Bits 6:0 – 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. These bits will always return zero when read. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 93 15.8.3 Generic Clock Control This register allows the user to configure one of the generic clocks, as specified in the CLKCTRL.ID bit group. To write to the CLKCTRL register, do a 16-bit write with all configurations and the ID. To read the CLKCTRL register, first do an 8-bit write to the CLKCTRL.ID bit group with the ID of the generic clock whose configuration is to be read, and then read the CLKCTRL register. Name: CLKCTRL Offset: 0x2 Reset: 0x0000 Property: Write-Protected Bit 15 14 WRTLOCK CLKEN R/W R/W R R R/W Reset 0 0 0 0 Bit 7 6 5 4 Access 13 12 11 10 9 8 R/W R/W R/W 0 0 0 0 3 2 1 0 GEN[3:0] ID[5:0] Access R R R/W R/W R/W R/W R/W R/W Reset 0 0 0 0 0 0 0 0 z Bit 15 – WRTLOCK: Write Lock When this bit is written, it will lock from further writes the generic clock pointed to by CLKCTRL.ID, the generic clock generator pointed to in CLKCTRL.GEN and the division factor used in the generic clock generator. It can only be unlocked by a power reset. One exception to this is generic clock generator 0, which cannot be locked. 0: The generic clock and the associated generic clock generator and division factor are not locked. 1: The generic clock and the associated generic clock generator and division factor are locked. z Bit 14 – CLKEN: Clock Enable This bit is used to enable and disable a generic clock. 0: The generic clock is disabled. 1: The generic clock is enabled. z Bits 13:12 – 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. These bits will always return zero when read. z Bits 11:8 – GEN[3:0]: Generic Clock Generator These bits select the generic clock generator to be used as the source of a generic clock. The value of the GEN bit group versus generic clock generator is shown in Table 15-2. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 94 Table 15-2. Generic Clock Generator Value Description 0x0 Generic clock generator 0 0x1 Generic clock generator 1 0x2 Generic clock generator 2 0x3 Generic clock generator 3 0x4 Generic clock generator 4 0x5 Generic clock generator 5 0x6 Generic clock generator 6 0x7 Generic clock generator 7 0x8-0xF Reserved z Bits 7:6 – 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. These bits will always return zero when read. z Bits 5:0 – ID[5:0]: Generic Clock Selection ID These bits select the generic clock that will be configured. The value of the ID bit group versus module instance is shown in Table 15-3. Table 15-3. Generic Clock Selection ID Value Description 0x00 DFLL48M Reference 0x01 WDT 0x02 RTC 0x03 EIC 0x04 EVSYS_CHANNEL_0 0x05 EVSYS_CHANNEL_1 0x06 EVSYS_CHANNEL_2 0x07 EVSYS_CHANNEL_3 0x08 EVSYS_CHANNEL_4 0x09 EVSYS_CHANNEL_5 0x0A EVSYS_CHANNEL_6 0x0B EVSYS_CHANNEL_7 0x0C SERCOMx_SLOW 0x0D SERCOM0_CORE 0x0E SERCOM1_CORE Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 95 Table 15-3. Generic Clock Selection ID (Continued) 0x0F SERCOM2_CORE 0x10 SERCOM3_CORE 0x11 SERCOM4_CORE 0x12 SERCOM5_CORE 0x13 TC0,TC1 0x14 TC2,TC3 0x15 TC4,TC5 0x16 TC6,TC7 0x17 ADC 0x18 AC_DIG 0x19 AC_ANA 0x1A DAC 0x1B PTC 0x1C-0x3F Reserved A power reset will reset the CLKCTRL register for all IDs, including the RTC. If the WRTLOCK bit of the corresponding ID is zero and the ID is not the RTC, a user reset will reset the CLKCTRL register for this ID. After a power reset, the reset value of the CLKCTRL register versus module instance is as shown in Table 15-4. Table 15-4. CLKCTRL Reset Value after a Power Reset Module Instance Reset Value after a Power Reset CLKCTRL.GEN CLKCTRL.CLKEN CLKCTRL.WRTLOCK 0x00 0x00 0x00 WDT 0x02 0x01 if WDT Enable bit in NVM User Row written to one 0x00 if WDT Enable bit in NVM User Row written to zero 0x01 if WDT Always-On bit in NVM User Row written to one 0x00 if WDT Always-On bit in NVM User Row written to zero Others 0x00 0x00 0x00 RTC After a user reset, the reset value of the CLKCTRL register versus module instance is as shown in Table 15-5. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 96 Table 15-5. CLKCTRL Reset Value after a User Reset Module Instance Reset Value after a User Reset CLKCTRL.GEN CLKCTRL.CLKEN CLKCTRL.WRTLOCK 0x00 if WRTLOCK=0 and CLKEN=0 No change if WRTLOCK=1 or CLKEN=1 0x00 if WRTLOCK=0 and CLKEN=0 No change if WRTLOCK=1 or CLKEN=1 No change WDT 0x02 if WRTLOCK=0 No change if WRTLOCK=1 If WRTLOCK=0 0x01 if WDT Enable bit in NVM User Row written to one 0x00 if WDT Enable bit in NVM User Row written to zero If WRTLOCK=1 no change No change Others 0x00 if WRTLOCK=0 No change if WRTLOCK=1 0x00 if WRTLOCK=0 No change if WRTLOCK=1 No change RTC Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 97 15.8.4 Generic Clock Generator Control This register allows the user to configure one of the generic clock generators, as specified in the GENCTRL.ID bit group. To write to the GENCTRL register, do a 32-bit write with all configurations and the ID. To read the GENCTRL register, first do an 8-bit write to the GENCTRL.ID bit group with the ID of the generic clock generator twhose configuration is to be read, and then read the GENCTRL register. Name: GENCTRL Offset: 0x4 Reset: 0x00010600 Property: Write-protected, Write-Synchronized Bit 31 30 29 28 27 26 25 24 Access R R R R R R R R Reset 0 0 0 0 0 0 0 0 Bit 23 22 21 20 19 18 17 16 RUNSTDBY DIVSEL OE OOV IDC GENEN Access R R R/W R/W R/W R/W R/W R/W Reset 0 0 0 0 0 0 0 0 Bit 15 14 13 12 11 10 9 8 SRC[4:0] Access R R R R/W R/W R/W R/W R/W Reset 0 0 0 0 0 0 0 0 Bit 7 6 5 4 3 2 1 0 ID[3:0] Access R R R R R/W R/W R/W R/W Reset 0 0 0 0 0 0 0 0 z Bits 31:22 – 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. These bits will always return zero when read. z Bit 21 – RUNSTDBY: Run in Standby This bit is used to keep the generic clock generator running when it is configured to be output to its dedicated GCLK_IO pin. If GENCTRL.OE is zero, this bit has no effect and the generic clock generator will only be running if a peripheral requires the clock. 0: The generic clock generator is stopped in standby and the GCLK_IO pin state (one or zero) will be dependent on the setting in GENCTRL.OOV. 1: The generic clock generator is kept running and output to its dedicated GCLK_IO pin during standby mode. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 98 z Bit 20 – DIVSEL: Divide Selection This bit is used to decide how the clock source used by the generic clock generator will be divided. If the clock source should not be divided, the DIVSEL bit must be zero and the GENDIV.DIV value for the corresponding generic clock generator must be zero or one. 0: The generic clock generator equals the clock source divided by GENDIV.DIV. 1: The generic clock generator equals the clock source divided by 2^(GENDIV.DIV+1). z Bit 19 – OE: Output Enable This bit is used to enable output of the generated clock to GCLK_IO when GCLK_IO is not selected as a source in the GENCLK.SRC bit group. 0: The generic clock generator is not output. 1: The generic clock generator is output to the corresponding GCLK_IO, unless the corresponding GCLK_IO is selected as a source in the GENCLK.SRC bit group. z Bit 18 – OOV: Output Off Value This bit is used to control the value of GCLK_IO when GCLK_IO is not selected as a source in the GENCLK.SRC bit group. 0: The GCLK_IO will be zero when the generic clock generator is turned off or when the OE bit is zero. 1: The GCLK_IO will be one when the generic clock generator is turned off or when the OE bit is zero. z Bit 17 – IDC: Improve Duty Cycle This bit is used to improve the duty cycle of the generic clock generator when odd division factors are used. 0: The generic clock generator duty cycle is not 50/50 for odd division factors. 1: The generic clock generator duty cycle is 50/50. z Bit 16 – GENEN: Generic Clock Generator Enable This bit is used to enable and disable the generic clock generator. 0: The generic clock generator is disabled. 1: The generic clock generator is enabled. z Bits 15:13 – 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. These bits will always return zero when read. z Bits 12:8 – SRC[4:0]: Source Select These bits define the clock source to be used as the source for the generic clock generator, as shown in Table 156. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 99 Table 15-6. Source Select Value Name Description 0x00 XOSC XOSC oscillator output 0x01 GCLKIO Generator input pad 0x02 GCLKGEN[1] Generic clock generator 1 output 0x03 OSCULP32K OSCULP32K oscillator output 0x04 OSC32K OSC32K oscillator output 0x05 XOSC32K XOSC32K oscillator output 0x06 OSC8M OSC8M oscillator output 0x07 DFLL48M DFLL48M output 0x08-0x1F Reserved Reserved for future use z Bits 7:4 – 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. These bits will always return zero when read. z Bits 3:0 – ID[3:0]: Generic Clock Generator Selection These bits select the generic clock generator that will be configured or read. The value of the ID bit group versus which generic clock generator is configured is shown in Table 15-7. Table 15-7. Generic Clock Generator Selection Value Description 0x0 Generic clock generator 0 0x1 Generic clock generator 1 0x2 Generic clock generator 2 0x3 Generic clock generator 3 0x4 Generic clock generator 4 0x5 Generic clock generator 5 0x6 Generic clock generator 6 0x7 Generic clock generator 7 0x8-0xF Reserved A power reset will reset the GENCTRL register for all IDs, including the generic clock generator used by the RTC. If a generic clock generator ID other than generic clock generator 0 is not a source of a “locked” generic clock or a source of the RTC generic clock, a user reset will reset the GENCTRL for this ID. After a power reset, the reset value of the GENCTRL register is as shown in Table 15-8. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 100 Table 15-8. GENCTRL Reset Value after a Power Reset GCLK Generator ID Reset Value after a Power Reset 0x00 0x00010600 0x01 0x00000001 0x02 0x00010302 0x03 0x00000003 0x04 0x00000004 0x05 0x00000005 0x06 0x00000006 0x07 0x00000007 After a user reset, the reset value of the GENCTRL register is as shown in Table 15-9. . Table 15-9. GENCTRL Reset Value after a User Reset GCLK Generator ID Reset Value after a User Reset 0x00 0x00010600 0x01 0x00000001 if the generator is not used by the RTC No change if the generator is used by the RTC or used by a GCLK with a WRTLOCK as one 0x02 0x00010302 if the generator is not used by the RTC No change if the generator is used by the RTC or used by a GCLK with a WRTLOCK as one 0x03 0x00000003 if the generator is not used by the RTC No change if the generator is used by the RTC or used by a GCLK with a WRTLOCK as one 0x04 0x00000004 if the generator is not used by the RTC No change if the generator is used by the RTC or used by a GCLK with a WRTLOCK as one 0x05 0x00000005 if the generator is not used by the RTC No change if the generator is used by the RTC or used by a GCLK with a WRTLOCK as one 0x06 0x00000006 if the generator is not used by the RTC No change if the generator is used by the RTC or used by a GCLK with a WRTLOCK as one 0x07 0x00000007 if the generator is not used by the RTC No change if the generator is used by the RTC or used by a GCLK with a WRTLOCK as one Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 101 15.8.5 Generic Clock Generator Division This register allows the user to configure one of the generic clock generators, as specified in the GENDIV.ID bit group. To write to theGENDIV register, do a 32-bit write with all configurations and the ID. To read theGENDIV register, first do an 8-bit write to the GENDIV.ID bit group with the ID of the generic clock generator whose configuration is to be read, and then read the GENDIV register. Name: GENDIV Offset: 0x8 Reset: 0x00000000 Property: Write-protected, Write-Synchronized Bit 31 30 29 28 27 26 25 24 Access R R R R R R R R Reset 0 0 0 0 0 0 0 0 Bit 23 22 21 20 19 18 17 16 DIV[15:8] Access R/W R/W R/W R/W R/W R/W R/W R/W Reset 0 0 0 0 0 0 0 0 Bit 15 14 13 12 11 10 9 8 DIV[7:0] Access R/W R/W R/W R/W R/W R/W R/W R/W Reset 0 0 0 0 0 0 0 0 Bit 7 6 5 4 3 2 1 0 ID[3:0] Access R R R R R/W R/W R/W R/W Reset 0 0 0 0 0 0 0 0 z Bits 31:24 – 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. These bits will always return zero when read. z Bits 23:8 – DIV[15:0]: Division Factor These bits apply a division on each selected generic clock generator. The number of DIV bits each generator has can be seen in Table 15-10. Writes to bits above the specified number will be ignored. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 102 Table 15-10. Division Factor Generator Division Factor Bits Generic clock generator 0 5 division factor bits - DIV[4:0] Generic clock generator 1 16 division factor bits - DIV[15:0] Generic clock generators 2 - 7 8 division factor bits - DIV[7:0] z Bits 7:4 – 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. These bits will always return zero when read. z Bits 3:0 – ID[3:0]: Generic Clock Generator Selection These bits select the generic clock generator on which the division factor will be applied, as shown in Table 15-11. Table 15-11. Generic Clock Generator Selection Value Description 0x0 Generic clock generator 0 0x1 Generic clock generator 1 0x2 Generic clock generator 2 0x3 Generic clock generator 3 0x4 Generic clock generator 4 0x5 Generic clock generator 5 0x6 Generic clock generator 6 0x7 Generic clock generator 7 0x8-0xF Reserved A power reset will reset the GENDIV register for all IDs, including the generic clock generator used by the RTC. If a generic clock generator ID other than generic clock generator 0 is not a source of a “locked” genericclock or a source of the RTC generic clock, a user reset will reset the GENDIV for this ID. After a power reset, the reset value of the GENDIV register is as shown in Table 15-12. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 103 Table 15-12. GENDIV Reset value after a Power Reset GCLK Generator ID Reset Value after a Power Reset 0x00 0x00000000 0x01 0x00000001 0x02 0x00000002 0x03 0x00000003 0x04 0x00000004 0x05 0x00000005 0x06 0x00000006 0x07 0x00000007 After a user reset, the reset value of the GENDIV register is as shown in Table 15-13. Table 15-13. GENDIV Reset Value after a User Reset GCLK Generator ID Reset Value after a User Reset 0x00 0x00000000 0x01 0x00000001 if the generator is not used by the RTC No change if the generator is used by the RTC or used by a GCLK with a WRTLOCK as one 0x02 0x00000002 if the generator is not used by the RTC No change if the generator is used by the RTC or used by a GCLK with a WRTLOCK as one 0x03 0x00000003 if the generator is not used by the RTC No change if the generator is used by the RTC or used by a GCLK with a WRTLOCK as one 0x04 0x00000004 if the generator is not used by the RTC No change if the generator is used by the RTC or used by a GCLK with a WRTLOCK as one 0x05 0x00000005 if the generator is not used by the RTC No change if the generator is used by the RTC or used by a GCLK with a WRTLOCK as one 0x06 0x00000006 if the generator is not used by the RTC No change if the generator is used by the RTC or used by a GCLK with a WRTLOCK as one 0x07 0x00000007 if the generator is not used by the RTC No change if the generator is used by the RTC or used by a GCLK with a WRTLOCK as one Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 104 16. 16.1 PM – Power Manager Overview The Power Manager (PM) controls the reset, clock generation and power save modes of the microcontroller. Utilizing a main clock chosen from a large number of clock sources from the GCLK, the clock controller provides synchronous system clocks to the CPU and the modules connected to the AHB and the APBx bus. The synchronous system clocks are divided into a number of clock domains; one for the CPU and AHB and one for each APBx. Any synchronous system clock can be changed at run-time during normal operation. The clock domains can run at different speeds, enabling the user to save power by running peripherals at a relatively low clock frequency, while maintaining high CPU performance. In addition, the clock can be masked for individual modules, enabling the user to minimize power consumption. If for some reason the main clock stops oscillating, the clock failure detector allows switching the main clock to the safe OSC8M clock. Various sleep modes and clock gating are provided in order to fit power consumption requirements. This enables the microcontroller to stop unused modules to save power. In ACTIVE mode, the CPU is executing application code. When the device enters a sleep mode, program execution is stopped and some modules and clock domains are automatically switched off by the PM according to the sleep mode. 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 a sleep mode to ACTIVE mode. The PM also contains a reset controller, which collects all possible reset sources. It issues a microcontroller reset and sets the device to its initial state, and allows the reset source to be identified by software. 16.2 Features z Reset control z Reset the microcontroller and set it to an initial state according to the reset source Multiple reset sources z Power reset sources: POR, BOD12, BOD33 z User reset sources: External reset (RESET), Watchdog Timer reset, software reset z Reset status register for reading the reset source from the application code z z Clock control z Generates CPU, AHB and APB system clocks z Multiple clock sources and division factor from GCLK z Clock prescaler with 1x to 128x division z Safe run-time clock switching from GCLK z Module-level clock gating through maskable peripheral clocks z Clock failure detector z Power management control z z Sleep modes: IDLE, STANDBY SleepWalking support on APB and GCLK clocks Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 105 16.3 Block Diagram Figure 16-1. PM Block Diagram POWER MANAGER CLK_APB OSC8M GCLK SYNCHRONOUS CLOCK CONTROLLER CLK_AHB PERIPHERALS CLK_CPU SLEEP MODE CONTROLLER CPU BOD12 USER RESET BOD33 POWER RESET POR WDT RESET CONTROLLER CPU RESET RESET SOURCES 16.4 Signal Description Signal Name Type Description RESET Digital input External reset Please refer to “I/O Multiplexing and Considerations” on page 15 for details on the pin mapping for this peripheral. One signal can be mapped on several pins. 16.5 Product Dependencies In order to use this peripheral, other parts of the system must be configured correctly, as described below. 16.5.1 I/O Lines Not applicable. 16.5.2 Power Management Not applicable. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 106 16.5.3 Clocks The PM bus clock (CLK_PM_APB) can be enabled and disabled in the power manager, and the default state of CLK_PM_APB can be found in Table 16-1. If this clock is disabled in the Power Manager, it can only be re-enabled by a reset. A generic clock (GCLK_MAIN) is required to generate the main clock. This clock is configured by default in the Generic Clock Controller, and can be re-configured by the user if needed. Please refer to “GCLK – Generic Clock Controller” on page 83 for details. 16.5.3.1 Main Clock The main clock (CLK_MAIN) is the common source for the synchronous clocks. This is fed into the common 8-bit prescaler that is used to generate synchronous clocks to the CPU, AHB and APBx modules. 16.5.3.2 CPU Clock The CPU clock (CLK_CPU) is routed to the CPU. Halting the CPU clock inhibits the CPU from executing instructions. 16.5.3.3 AHB Clock The AHB clock (CLK_AHB) is the root clock source used by peripherals requiring an AHB clock. The AHB clock is always synchronous to the CPU clock and has the same frequency, but may run even when the CPU clock is turned off. A clock gate is inserted from the common AHB clock to any AHB clock of a peripheral. 16.5.3.4 APBx Clocks The APBx clock (CLK_APBX) is the root clock source used by modules requiring a clock on the APBx bus. The APBx clock is always synchronous to the CPU clock, but can be divided by a prescaler, and will run even when the CPU clock is turned off. A clock gater is inserted from the common APB clock to any APBx clock of a module on APBx bus. 16.5.4 Interrupts The interrupt request line is connected to the Interrupt Controller. Using the PM interrupt requires the Interrupt Controller to be configured first. 16.5.5 Events Not applicable. 16.5.6 Debug Operation When the CPU is halted in debug mode, the PM continues normal operation. In sleep mode, the clocks generated from the PM are kept running to allow the debugger accessing any modules. As a consequence, power measurements are not possible in debug mode. 16.5.7 Register Access Protection All registers with write access are optionally write-protected by the Peripheral Access Controller (PAC), except the following registers: z Interrupt Flag register (INTFLAG) z Reset Cause register (RCAUSE) Write-protection is denoted by the Write-Protection property in the register description. Write-protection does not apply for accesses through an external debugger. Refer to “PAC – Peripheral Access Controller” on page 31 for details. 16.5.8 Analog Connections Not applicable. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 107 16.6 Functional Description 16.6.1 Principle of Operation 16.6.1.1 Synchronous Clocks The GCLK_MAIN clock from GCLK module provides the source for the main clock, which is the common root for the synchronous clocks for the CPU and APBx modules. The main clock is divided by an 8-bit prescaler, and each of the derived clocks can run from any tapping off this prescaler or the undivided main clock, as long as fCPU ≥ fAPBx. The synchronous clock source can be changed on the fly to respond to varying load in the application. The clocks for each module in each synchronous clock domain can be individually masked to avoid power consumption in inactive modules. Depending on the sleep mode, some clock domains can be turned off. 16.6.1.2 Reset Controller The Reset Controller collects the various reset sources and generates resets for the device. The device contains a power-on-reset (POR) detector, which keeps the system reset until power is stable. This eliminates the need for external reset circuitry to guarantee stable operation when powering up the device. 16.6.1.3 Sleep Mode Controller In ACTIVE mode, all clock domains are active, allowing software execution and peripheral operation. The PM Sleep Mode Controller allows the user to choose between different sleep modes depending on application requirements, to save power. 16.6.2 Basic Operation 16.6.2.1 Initialization After a power-on reset, the PM is enabled and the Reset Cause (RCAUSE) register indicates the POR source. The default clock source of the GCLK_MAIN clock is started and calibrated before the CPU starts running. The GCLK_MAIN clock is selected as the main clock without any division on the prescaler. The device is in the ACTIVE mode. By default, only the necessary clocks are enabled (see Table 16-1). 16.6.2.2 Enabling, Disabling and Resetting The PM module is always enabled and can not be reset. 16.6.2.3 Selecting the Main Clock Source Refer to “GCLK – Generic Clock Controller” on page 83 for details on how to configure the main clock source. 16.6.2.4 Selecting the Synchronous Clock Division Ratio The main clock feeds an 8-bit prescaler, which can be used to generate the synchronous clocks. By default, the synchronous clocks run on the undivided main clock. The user can select a prescaler division for the CPU clock by writing the CPU Prescaler Selection bits in the CPU Select register (CPUSEL.CPUDIV), resulting in a CPU clock frequency determined by this equation: f main f CPU = --------------------CPUDIV 2 Similarly, the clock for the APBx can be divided by writing their respective registers. To ensure correct operation, frequencies must be selected so that fCPU ≥ fAPBx. Also, frequencies must never exceed the specified maximum frequency for each clock domain. Note that the AHB clock is always equal to the CPU clock. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 108 CPUSEL and APBxSEL can be written without halting or disabling peripheral modules. Writing CPUSEL and APBxSEL allows a new clock setting to be written to all synchronous clocks at the same time. It is possible to keep one or more clocks unchanged. This way, it is possible to, for example, scale the CPU speed according to the required performance, while keeping the APBx frequency constant. Figure 16-2. Synchronous Clock Selection and Prescaler Sleep Controller Sleep mode APBCMASK Clock gate APBCDIV APBBDIV Clock gate Clock gate Clock gate CLK_APBB clk_apbb_ipn clk_apbb_ip1 clk_apbb_ip0 APBAMASK Clock gate GCLKMAIN clk_apbc_ipn clk_apbc_ip1 clk_apbc_ip0 APBBMASK Clock gate GCLK Clock gate Clock gate Clock gate CLK_APBC Clock gate Clock gate Clock gate clk_apba_ipn clk_apba_ip1 clk_apba_ip0 Clock gate Clock gate Clock gate clk_ahb_ipn clk_ahb_ip1 clk_ahb_ip0 CLK_APBA CLK_MAIN APBADIV OSC8M BKUPCLK Clock Failure Detector Prescaler AHBMASK Clock gate CLK_AHB Clock gate CLK_CPU CPUDIV 16.6.2.5 Clock Ready Flag There is a slight delay from when CPUSEL and APBxSEL are written until the new clock setting becomes effective. During this interval, the Clock Ready flag in the Interrupt Flag Status and Clear register (INTFLAG.CKRDY) will read as zero. If CKRDY in the INTENSET register is written to one, the Power Manager interrupt can be triggered when the new clock setting is effective. CKSEL must not be re-written while CKRDY is zero, or the system may become unstable or hang. 16.6.2.6 Peripheral Clock Masking It is possible to disable or enable the clock for a peripheral in the AHB or APBx clock domain by writing the corresponding bit in the Clock Mask register (APBxMASK) to zero or one. Refer to Table 16-1 for the default state of each of the peripheral clocks. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 109 Table 16-1. Peripheral Clock Default State Peripheral Clock Default State CLK_PAC0_APB Enabled CLK_PM_APB Enabled CLK_SYSCTRL_APB Enabled CLK_GCLK_APB Enabled CLK_WDT_APB Enabled CLK_RTC_APB Enabled CLK_EIC_APB Enabled CLK_PAC1_APB Enabled CLK_DSU_APB Enabled CLK_NVMCTRL_APB Enabled CLK_PORT_APB Enabled CLK_PAC2_APB Disabled CLK_SERCOMx_APB Disabled CLK_TCx_APB Disabled CLK_ADC_APB Enabled CLK_AC_APB Disabled CLK_DAC_APB Disabled CLK_PTC_APB Disabled When a module is not clocked, it will cease operation, and its registers cannot be read or written. The module can be reenabled later by writing the corresponding mask bit to one. A module may be connected to several clock domains (for instance, AHB and APB), in which case it will have several mask bits. Note that clocks should only be switched off if it is certain that the module will not be used. Switching off the clock for the NVM Controller (NVMCTRL) will cause a problem if the CPU needs to read from the flash memory. Switching off the clock to the Power Manager (PM), which contains the mask registers, or the corresponding APBx bridge, will make it impossible to write the mask registers again. In this case, they can only be re-enabled by a system reset. 16.6.2.7 Clock Failure Detector This mechanism allows the main clock to be switched automatically to the safe OSC8M clock when the main clock source is considered off. This may happen for instance when an external crystal oscillator is selected as the clock source for the main clock and the crystal fails. The mechanism is to designed to detect, during a OSCULP32K clock period, at least one rising edge of the main clock. If no rising edge is seen, the clock is considered failed. The clock failure detector is enabled by writing a one to the Clock Failure Detector Enable bit in CTRL (CFDEN.CTRL). As soon as the Clock Failure Detector Enable bit (CTRL.CFDEN) is one, the clock failure detector (CFD) will monitor the divided main clock. When a clock failure is detected, the main clock automatically switches to the OSC8M clock and the Clock Failure Detector flag in the interrupt Flag Status and Clear register (INTFLAG.CFD) is generated, if enabled. The BKUPCLK bit in the CTRL register is set by hardware to indicate that the main clock comes from OSC8M. The Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 110 GCLKMAIN clock source can be selected again by writing a zero to the CTRL.BKUPCLK bit. Writing the bit does not fix the failure, however. Note 1: The detector does not monitor while the main clock is temporarily unavailable (startup time after a wake-up, etc.) or in sleep mode. Note 2: The clock failure detector must not be enabled if the source of the main clock is not significantly faster than the OSCULP32K clock. For instance, if GCLKMAIN is the internal 32kHz RC, then the clock failure detector must be disabled. 16.6.2.8 Reset Controller The latest reset cause is available in RCAUSE, and can be read during the application boot sequence in order to determine proper action. There are two groups of reset sources: z Power Reset: Resets caused by an electrical issue. z User Reset: Resets caused by the application. The table below lists the parts of the device that are reset, depending on the reset type. Table 16-2. Effects of the Different Reset Events Power Reset User Reset POR, BOD12, BOD33 External Reset WDT Reset, SysResetReq RTC All the 32kHz sources WDT with ALWAYSON feature GCLK with WRTLOCK feature Y N N Debug logic Y Y N Others Y Y Y The external reset is generated when pulling the RESET pin low. This pin has an internal pull-up, and does not need to be driven externally during normal operation. The POR, BOD12 and BOD33 reset sources are generated by their corresponding module in the System Controller Interface (SYSCTRL). The WDT reset is generated by the Watchdog Timer. The System Reset Request (SysResetReq) is a software reset generated by the CPU when asserting the SYSRESETREQ bit located in the Reset Control register of the CPU (please see the ARM® Cortex® Technical Reference Manual on http://www.arm.com). Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 111 Figure 16-3. Reset Controller RESET CONTROLLER BOD12 BOD33 POR RTC 32kHz clock sources WDT with ALWAYSON GCLK with WRTLOCK Debug Logic RESET WDT Others CPU RCAUSE RESET SOURCES 16.6.2.9 Sleep Mode Controller Sleep mode is activated by the Wait For Interrupt instruction (WFI). The Idle bits in the Sleep Mode register (SLEEP.IDLE) and the SLEEPDEEP bit of the System Control register of the CPU should be used as argument to select the level of the sleep mode. There are two main types of sleep mode: z IDLE mode: The CPU is stopped. Optionally, some synchronous clock domains are stopped, depending on the IDLE argument. Regulator operates in normal mode z STANDBY mode: All clock sources are stopped, except those where the RUNSTDBY bit is set. Regulator operates in low-power mode Table 16-3. Sleep Mode Entry and Exit Table Mode Level 0 IDLE 1 2 STANDBY Mode Entry SCR.SLEEPDEEP = 0 SLEEP.IDLE=Level WFI SCR.SLEEPDEEP = 1 WFI Wake-Up Sources Synchronous (APB, AHB), asynchronous Synchronous (APB), asynchronous Asynchronous Asynchronous Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 112 SLEEP Mode SLEEP. IDLE CPU Clock AHB Clock APB Clock Clock Sources(1)(2) Main Clock 0 Stop Run Run Run (if demanded) Run 1 Stop Stop Run Run (if demanded) Run 2 Stop Stop Stop Run (if demanded) Run Stop Stop Stop Stop (if not demanded) Stop IDLE STANDBY Notes: 1. 2. Regulator Mode RAM Mode Normal Normal Low power Low power Refer to “SYSCTRL – System Controller” on page 132 to determine the clock sources. A clock source is demanded if either a module requests it or the clock source ONDEMAND bit is set. IDLE Mode The IDLE mode allows power optimization with the fastest wake-up time. The CPU is stopped. To further reduce power consumption, the user can disable the clocking of modules and clock sources by configuring the SLEEP.IDLE bit group. The module will be halted regardless of the bit settings of the mask registers in the Power Manager (PM.AHBMASK, PM.APBxMASK). Regulator operates in normal mode. z Entering IDLE mode: The IDLE mode is entered by executing the WFI instruction. Additionally, if the SLEEPONEXIT bit in the ARM Cortex System Control register (SCR) is set, the IDLE mode will also be entered when the CPU exits the lowest priority ISR. This mechanism can be useful for applications that only require the processor to run when an interrupt occurs. Before entering the IDLE mode, the user must configure the IDLE mode configuration bit group and must write a zero to the SCR.SLEEPDEEP bit. z Exiting IDLE mode: The processor wakes the system up when it detects any non-masked interrupt with sufficient priority to cause exception entry. The system goes back to the ACTIVE mode. The CPU and affected modules are restarted. STANDBY Mode The STANDBY modes allow achieving very low power consumption. In this mode, all clocks are stopped except those which are kept running if requested by a running module or have the ONDEMAND bit set to zero. For example, the RTC can operate in STANDBY mode. In this case, its GCLK clock source will also be enabled. The regulator and the RAM operate in low-power mode. A SLEEPONEXIT feature is also available. z z Entering STANDBY mode: This mode is entered by executing the WFI instruction with the SCR.SLEEPDEEP bit of the CPU is written to 1. Exiting STANDBY mode: Any peripheral able to generate an asynchronous interrupt can wake up the system. For example, a module running on a GCLK clock can trigger an interrupt. When the enabled asynchronous wake-up event occurs and the system is woken up, the device will either execute the interrupt service routine or continue the normal program execution according to the Priority Mask Register (PRIMASK) configuration of the CPU. 16.6.3 Additional Features 16.6.4 Interrupts The peripheral has the following interrupt sources: Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 113 z Clock Ready flag z Clock failure detector Each interrupt source has an interrupt flag associated with it. The interrupt flag in the Interrupt Flag Status and Clear (INTFLAG) register is set when the interrupt condition occurs. Each interrupt can be individually enabled by writing a one to the corresponding bit in the Interrupt Enable Set (INTENSET) register, and disabled by writing a one to the corresponding bit in the Interrupt Enable Clear (INTENCLR) register. An interrupt request is generated when the interrupt flag is set and the corresponding interrupt is enabled. The interrupt request remains active until the interrupt flag is cleared, the interrupt is disabled or the peripheral is reset. An interrupt flag is cleared by writing a one to the corresponding bit in the INTFLAG register. Each peripheral can have one interrupt request line per interrupt source or one common interrupt request line for all the interrupt sources. Refer to “Nested Vector Interrupt Controller” on page 28 for details. If the peripheral has one common interrupt request line for all the interrupt sources, the user must read the INTFLAG register to determine which interrupt condition is present. 16.6.5 Events Not applicable. 16.6.6 Sleep Mode Operation In all IDLE sleep modes, the power manager is still running on the selected main clock. In STANDDBY sleep mode, the power manager is frozen and is able to go back to ACTIVE mode upon any asynchronous interrupt. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 114 16.7 Register Summary Offset Name Bit Pos. 0x00 CTRL 7:0 0x01 SLEEP 7:0 0x02 Reserved 0x03 Reserved … … 0x06 Reserved 0x07 Reserved 0x08 CPUSEL 7:0 CPUDIV[2:0] 0x09 APBASEL 7:0 APBADIV[2:0] 0x0A APBBSEL 7:0 APBBDIV[2:0] 0x0B APBCSEL 7:0 APBCDIV[2:0] 0x0C Reserved 0x0D Reserved … BKUPCLK CFDEN IDLE[1:0] … … … … … … … … … 0x12 Reserved 0x13 Reserved 0x14 7:0 0x15 NVMCTRL DSU HPB2 HPB1 HPB0 WDT GCLK SYSCTRL PM PAC0 PORT NVMCTRL DSU PAC1 15:8 AHBMASK 0x16 23:16 0x17 31:24 0x18 7:0 0x19 EIC RTC 15:8 APBAMASK 0x1A 23:16 0x1B 31:24 0x1C 7:0 0x1D 15:8 APBBMASK 0x1E 23:16 0x1F 31:24 0x20 7:0 SERCOM5 SERCOM4 SERCOM3 SERCOM2 SERCOM1 SERCOM0 EVSYS PAC2 15:8 TC7 TC6 TC5 TC4 TC3 TC2 TC1 TC0 PTC DAC AC ADC … … … … 0x21 APBCMASK 0x22 23:16 0x23 31:24 0x24 Reserved 0x25 Reserved … … 0x32 Reserved … … … … … Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 115 Offset Name Bit Pos. 0x33 Reserved 0x34 INTENCLR 7:0 CFD CKRDY 0x35 INTENSET 7:0 CFD CKRDY 0x36 INTFLAG 7:0 CFD CKRDY 0x37 Reserved 0x38 RCAUSE BOD12 POR 7:0 SYST WDT EXT BOD33 Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 116 16.8 Register Description Registers can be 8, 16 or 32 bits wide. Atomic 8-, 16- and 32-bit accesses are supported. In addition, the 8-bit quarters and 16-bit halves of a 32-bit register, and the 8-bit halves of a 16-bit register can be accessed directly. Exception for APBASEL, APBBSEL and APBCSEL: These registers must only be accessed with 8-bit access. Some registers are optionally write-protected by the Peripheral Access Controller (PAC). Write-protection is denoted by the Write-Protected property in each individual register description. Please refer to “Register Access Protection” on page 107 for details. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 117 16.8.1 Control Name: CTRL Offset: 0x00 Reset: 0x00 Property: Write-Protected Bit 7 6 5 4 3 BKUPCLK 2 1 0 CFDEN Access R R R R/W R R/W R R Reset 0 0 0 0 0 0 0 0 z Bits 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. These bits will always return zero when read. z Bit 4 – BKUPCLK: Backup Clock Select This bit is set by hardware when a clock failure is detected. 0: The GCLKMAIN clock is selected for the main clock. 1: The OSC8M backup clock is selected for the main clock. z 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. This bit will always return zero when read. z Bit 2 – CFDEN: Clock Failure Detector Enable 0: The clock failure detector is disabled. 1: The clock failure detector is enabled. z Bits 1:0 – 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. These bits will always return zero when read. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 118 16.8.2 Sleep Mode Name: SLEEP Offset: 0x01 Reset: 0x00 Property: Write-Protected Bit 7 6 5 4 3 2 1 0 IDLE[1:0] Access R R R R R R R/W R/W Reset 0 0 0 0 0 0 0 0 z Bits 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. These bits will always return zero when read. z Bits 1:0 – IDLE[1:0]: IDLE Mode Configuration These bits select the IDLE mode configuration after a WFI instruction. Table 16-4. IDLE Mode Configuration IDLE[1:0] Description 0x0 The CPU clock domain is stopped 0x1 The CPU and AHB clock domains are stopped 0x2 The CPU, AHB and APB clock domains are stopped 0x3 Reserved Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 119 16.8.3 CPU Clock Select Name: CPUSEL Offset: 0x08 Reset: 0x00 Property: Write-Protected Bit 7 6 5 4 3 2 1 0 CPUDIV[2:0] Access R R R R R R/W R/W R/W Reset 0 0 0 0 0 0 0 0 z Bits 7:3 – 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. These bits will always return zero when read. z Bits 2:0 – CPUDIV[2:0]: CPU Prescaler Selection These bits define the division ratio of the main clock prescaler (2n). Table 16-5. CPU Clock Frequency Ratio CPUDIV[1:0] Description 0x0 Divide by 1 0x1 Divide by 2 0x2 Divide by 4 0x3 Divide by 8 0x4 Divide by 16 0x5 Divide by 32 0x6 Divide by 64 0x7 Divide by 128 Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 120 16.8.4 APBA Clock Select Name: APBASEL Offset: 0x09 Reset: 0x00 Property: Write-Protected Bit 7 6 5 4 3 2 1 0 APBADIV[2:0] Access R R R R R R/W R/W R/W Reset 0 0 0 0 0 0 0 0 z Bits 7:3 – 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. These bits will always return zero when read. z Bits 2:0 – APBADIV[2:0]: APBA Prescaler Selection These bits define the division ratio of the APBA clock prescaler (2n). Table 16-6. APBA Prescaler Selection APBADIV[1:0] Description 0x0 Divide by 1 0x1 Divide by 2 0x2 Divide by 4 0x3 Divide by 8 0x4 Divide by 16 0x5 Divide by 32 0x6 Divide by 64 0x7 Divide by 128 Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 121 16.8.5 APBB Clock Select Name: APBBSEL Offset: 0x0A Reset: 0x00 Property: Write-Protected Bit 7 6 5 4 3 2 1 0 APBBDIV[2:0] Access R R R R R R/W R/W R/W Reset 0 0 0 0 0 0 0 0 z Bits 7:3 – 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. These bits will always return zero when read. z Bits 2:0 – APBBDIV[2:0]: APBB Prescaler Selection These bits define the division ratio of the APBB clock prescaler (2n). Table 16-7. APBB Prescaler Selection APBBDIV[1:0] Description 0x0 Divide by 1 0x1 Divide by 2 0x2 Divide by 4 0x3 Divide by 8 0x4 Divide by 16 0x5 Divide by 32 0x6 Divide by 64 0x7 Divide by 128 Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 122 16.8.6 APBC Clock Select Name: APBCSEL Offset: 0x0B Reset: 0x00 Property: Write-Protected Bit 7 6 5 4 3 2 1 0 APBCDIV[2:0] Access R R R R R R/W R/W R/W Reset 0 0 0 0 0 0 0 0 z Bits 7:3 – 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. These bits will always return zero when read. z Bits 2:0 – APBCDIV[2:0]: APBC Prescaler Selection These bits define the division ratio of the APBC clock prescaler (2n). Table 16-8. APBC Prescaler Selection APBCDIV[1:0] Description 0x0 Divide by 1 0x1 Divide by 2 0x2 Divide by 4 0x3 Divide by 8 0x4 Divide by 16 0x5 Divide by 32 0x6 Divide by 64 0x7 Divide by 128 Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 123 16.8.7 AHB Mask Name: AHBMASK Offset: 0x14 Reset: 0x0000001F Property: Write-Protected Bit 31 30 29 28 27 26 25 24 Access R R R R R R R R Reset 0 0 0 0 0 0 0 0 Bit 23 22 21 20 19 18 17 16 Access R R R R R R R R Reset 0 0 0 0 0 0 0 0 Bit 15 14 13 12 11 10 9 8 Access R R R R R R R R Reset 0 0 0 0 0 0 0 0 Bit 7 6 5 4 3 2 1 0 NVMCTRL DSU HPB2 HPB1 HPB0 Access R R R R/W R/W R/W R/W R/W Reset 0 0 0 1 1 1 1 1 z Bits 31: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. These bits will always return zero when read. z Bits 4:0 – NVMCTRL, DSU, HPB2, HPB1, HPB0: AHB Clock Enable For any bit: 0: The AHB clock for the corresponding module is stopped. 1: The AHB clock for the corresponding module is enabled. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 124 16.8.8 APBA Mask Name: APBAMASK Offset: 0x18 Reset: 0x0000007F Property: Write-Protected Bit 31 30 29 28 27 26 25 24 Access R R R R R R R R Reset 0 0 0 0 0 0 0 0 Bit 23 22 21 20 19 18 17 16 Access R R R R R R R R Reset 0 0 0 0 0 0 0 0 Bit 15 14 13 12 11 10 9 8 Access R R R R R R R R Reset 0 0 0 0 0 0 0 0 Bit 7 6 5 4 3 2 1 0 EIC RTC WDT GCLK SYSCTRL PM PAC0 Access R R/W R/W R/W R/W R/W R/W R/W Reset 0 1 1 1 1 1 1 1 z Bits 31:7 – 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. These bits will always return zero when read. z Bits 6:0 – EIC, RTC, WDT, GCLK, SYSCTRL, PM, PAC0: APB Clock Enable For any bit: 0: The APBA clock for the corresponding module is stopped. 1: The APBA clock for the corresponding module is enabled. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 125 16.8.9 APBB Mask Name: APBBMASK Offset: 0x1C Reset: 0x0000001F Property: Write-Protected Bit 31 30 29 28 27 26 25 24 Access R R R R R R R R Reset 0 0 0 0 0 0 0 0 Bit 23 22 21 20 19 18 17 16 Access R R R R R R R R Reset 0 0 0 0 0 0 0 0 Bit 15 14 13 12 11 10 9 8 Access R R R R R R R R Reset 0 0 0 0 0 0 0 0 Bit 7 6 5 4 3 2 1 0 PORT NVMCTRL DSU PAC1 Access R R R R R/W R/W R/W R/W Reset 0 0 0 1 1 1 1 1 z Bits 31:4 – 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. These bits will always return zero when read. z Bits 3:0 – PORT, NVMCTRL, DSU, PAC1: APB Clock Enable For any bit: 0: The APBB clock for the corresponding module is stopped. 1: The APBB clock for the corresponding module is enabled. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 126 16.8.10 APBC Mask Name: APBCMASK Offset: 0x20 Reset: 0x00010000 Property: Write-Protected Bit 31 30 29 28 27 26 25 24 Access R R R R R R R R Reset 0 0 0 0 0 0 0 0 23 22 21 20 19 18 17 16 PTC DAC AC ADC Bit Access R R R R R/W R/W R/W R/W Reset 0 0 0 0 0 0 0 1 Bit 15 14 13 12 11 10 9 8 TC7 TC6 TC5 TC4 TC3 TC2 TC1 TC0 R/W R/W R/W R/W R/W R/W R/W R/W Reset 0 0 0 0 0 0 0 0 Bit 7 6 5 4 3 2 1 0 SERCOM5 SERCOM4 SERCOM3 SERCOM2 SERCOM1 SERCOM0 EVSYS PAC2 R/W R/W R/W R/W R/W R/W R/W R/W 0 0 0 0 0 0 0 0 Access Access Reset z Bits 31:20 – 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. These bits will always return zero when read. z Bits 19:0 – PTC, DAC, AC, ADC, TC7, TC6, TC5, TC4, TC3, TC2, TC1, TC0, SERCOM5, SERCOM4, SERCOM3, SERCOM2, SERCOM1, SERCOM0, EVSYS, PAC2: APB Clock Enable For any bit: 0: The APBC clock for the corresponding module is stopped. 1: The APBC clock for the corresponding module is enabled. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 127 16.8.11 Interrupt Enable Clear This register allows the user to disable an interrupt without doing a read-modify-write operation. Changes in this register will also be reflected in the Interrupt Enable Set (INTENSET) register. Name: INTENCLR Offset: 0x34 Reset: 0x00 Property: Write-Protected Bit 7 6 5 4 3 2 1 0 CFD CKRDY Access R R R R R R R/W R/W Reset 0 0 0 0 0 0 0 0 z Bits 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. These bits will always return zero when read. z Bit 1 – CFD: Clock Failure Detector Interrupt Enable 0: The Clock Failure Detector interrupt is disabled. 1: The Clock Failure Detector interrupt is enabled and an interrupt request will be generated when the Clock Failure Detector Interrupt flag is set. Writing a zero to this bit has no effect. Writing a one to this bit will clear the Clock Failure Detector Interrupt Enable bit and the corresponding interrupt request. z Bit 0 – CKRDY: Clock Ready Interrupt Enable 0: The Clock Ready interrupt is disabled. 1: The Clock Ready interrupt is enabled and will generate an interrupt request when the Clock Ready Interrupt flag is set. Writing a zero to this bit has no effect. Writing a one to this bit will clear the Clock Ready Interrupt Enable bit and the corresponding interrupt request. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 128 16.8.12 Interrupt Enable Set This register allows the user to enable an interrupt without doing a read-modify-write operation. Changes in this register will also be reflected in the Interrupt Enable Clear (INTENCLR) register. Name: INTENSET Offset: 0x35 Reset: 0x00 Property: Write-Protected Bit 7 6 5 4 3 2 1 0 CFD CKRDY Access R R R R R R R/W R/W Reset 0 0 0 0 0 0 0 0 z Bits 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. These bits will always return zero when read. z Bit 1 – CFD: Clock Failure Detector Interrupt Enable 0: The Clock Failure Detector interrupt is disabled. 1: The Clock Failure Detector interrupt is enabled. Writing a zero to this bit has no effect. Writing a one to this bit will set the Clock Failure Detector Interrupt Enable bit and enable the Clock Failure Detector interrupt. z Bit 0 – CKRDY: Clock Ready Interrupt Enable 0: The Clock Ready interrupt is disabled. 1: The Clock Ready interrupt is enabled. Writing a zero to this bit has no effect. Writing a one to this bit will set the Clock Ready Interrupt Enable bit and enable the Clock Ready interrupt. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 129 16.8.13 Interrupt Flag Status and Clear Name: INTFLAG Offset: 0x36 Reset: 0x00 Property: – Bit 7 6 5 4 3 2 1 0 CFD CKRDY Access R R R R R R R/W R/W Reset 0 0 0 0 0 0 0 0 z Bits 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. These bits will always return zero when read. z Bit 1 – CFD: Clock Failure Detector This flag is cleared by writing a one to the flag. This flag is set on the next cycle after a clock failure detector occurs and will generate an interrupt request if INTENCLR/SET.CFD is one. Writing a zero to this bit has no effect. Writing a one to this bit clears the Clock Failure Detector Interrupt flag. z Bit 0 – CKRDY: Clock Ready This flag is cleared by writing a one to the flag. This flag is set when the synchronous CPU and APBx clocks have frequencies as indicated in the CPUSEL and APBxSEL registers, and will generate an interrupt if INTENCLR/SET.CKRDY is one. Writing a zero to this bit has no effect. Writing a one to this bit clears the Clock Ready Interrupt flag. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 130 16.8.14 Reset Cause Name: RCAUSE Offset: 0x38 Reset: Latest Reset Source Property: – Bit 7 6 5 4 SYST WDT EXT 3 2 1 0 BOD33 BOD12 POR Access R R R R R R R R Reset 0 X X X 0 X X X z 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. This bit will always return zero when read. z Bit 6 – SYST: System Reset Request This bit is set if a system reset request has been performed. Refer to the Cortex processor documentation for more details. z Bit 5 – WDT: Watchdog Reset This flag is set if a Watchdog Timer reset occurs. z Bit 4 – EXT: External Reset This flag is set if an external reset occurs. z 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. This bit will always return zero when read. z Bit 2 – BOD33: Brown Out 33 Detector Reset This flag is set if a BOD33 reset occurs. z Bit 1 – BOD12: Brown Out 12 Detector Reset This flag is set if a BOD12 reset occurs. z Bit 0 – POR: Power On Reset This flag is set if a POR occurs. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 131 17. 17.1 SYSCTRL – System Controller Overview The System Controller (SYSCTRL) provides a user interface to the XOSC, XOSC32K, OSC32K, OSCULP32K, OSC8M, DFLL48M, BOD33, BOD12, VREG and VREF. Through the interface registers, it is possible to enable, disable, calibrate and monitor the SYSCTRL sub-peripherals. All sub-peripheral statuses are collected in the Power and Clocks Status register (PCLKSR). They can additionally trigger interrupts upon status changes via the INTENSET, INTENCLR and INTFLAG registers. Additionally, BOD33 and BOD12 interrupts can be used to wake up the device from standby mode upon a programmed brown-out detection. 17.2 Features z 0.4-32MHz Crystal Oscillator (XOSC) z Tunable gain control Programmable start-up time z Crystal or external input clock on XIN I/O z z 32.768kHz Crystal Oscillator (XOSC32K) z Automatic or manual gain control Programmable start-up time z Crystal or external input clock on XIN32 I/O z z 32.768kHz High Accuracy Internal Oscillator (OSC32K) z z Frequency fine tuning Programmable start-up time z 32.768kHz Ultra Low Power Internal Oscillator (OSCULP32K) z Ultra low power, always-on oscillator Frequency fine tuning z Calibration value loaded from Flash Factory Calibration at reset z z 8MHz Internal Oscillator (OSC8M) z Fast startup Output frequency fine tuning z 4/2/1MHz divided output frequencies available z Calibration value loaded from Flash Factory Calibration at reset z z Digital Frequency Locked Loop (DFLL48M) z Internal oscillator with no external components 48MHz output frequency z Operates standalone as a high-frequency programmable oscillator in open loop mode z Operates as an accurate frequency multiplier against a known frequency in closed loop mode z z 3.3V Brown-Out Detector (BOD33) z Programmable threshold Threshold value loaded from Flash User Calibration at startup z Triggers resets or interrupts z Operating modes: z Continuous mode z Sampled mode for low power applications (programmable refresh frequency) z Hysteresis z z 1.2V Brown-Out Detector (BOD12) z Programmable threshold Threshold value loaded from Flash User Calibration at startup z Triggers resets or interrupts z Operating modes: z Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 132 z Continuous mode Sampled mode for low power applications (programmable refresh frequency) z Hysteresis z z Voltage Reference System (VREF) z Bandgap voltage generator with programmable calibration value Temperature sensor z Bandgap calibration value loaded from Flash Factory Calibration at startup z z Voltage Regulator System (VREG) z z 17.3 Trimable core supply voltage level Voltage regulator trim value loaded from Flash Factory Calibration at startup Block Diagram Figure 17-1. SYSCTRL Block Diagram SYSCTRL XOSC XOSC32K OSCILLATORS CONTROL OSC32K OSCULP32K OSC8M DFLL48M POWER MONITOR CONTROL BOD12 BOD33 VOLTAGE REFERENCE CONTROL VOLTAGE REFERENCE SYSTEM VOLTAGE REGULATOR CONTROL VOLTAGE REGULATOR SYSTEM STATUS (PCLKSR register) INTERRUPTS GENERATOR Interrupts Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 133 17.4 Signal Description Signal Name Type Description XIN Analog Input Multipurpose Crystal Oscillator or external clock generator input XOUT Analog Output External Multipurpose Crystal Oscillator output XIN32 Analog Input 32kHz Crystal Oscillator or external clock generator input XOUT32 Analog Output 32kHz Crystal Oscillator output The I/O lines are automatically selected when XOSC or XOSC32K are enabled. 17.5 Product Dependencies In order to use this peripheral, other parts of the system must be configured correctly, as described below. 17.5.1 I/O Lines I/O lines are configured by SYSCTRL when either XOSC or XOSC32K are enabled, and need no user configuration. 17.5.2 Power Management The SYSCTRL can continue to operate in any sleep mode where the selected source clock is running. The SYSCTRL interrupts can be used to wake up the device from sleep modes. The events can trigger other operations in the system without exiting sleep modes. Refer to “PM – Power Manager” on page 105 for details on the different sleep modes. 17.5.3 Clocks The SYSCTRL gathers controls for all device oscillators and provides clock sources to the Generic Clock Controller (GCLK). The available clock sources are: XOSC, XOSC32K, OSC32K, OSCULP32K, OSC8M and DFLL48M. The SYSCTRL bus clock (CLK_SYSCTRL_APB) can be enabled and disabled in the Power Manager, and the default state of CLK_SYSCTRL_APB can be found in the Peripheral Clock Masking section in the “PM – Power Manager” on page 105. The clock used by BOD33 and BOD12 in sampled mode is asynchronous to the user interface clock (CLK_SYSCTRL_APB). Likewise, the DFLL48M control logic uses the DFLL oscillator output, which is also asynchronous to the user interface clock (CLK_SYSCTRL_APB). Due to this asynchronicity, writes to certain registers will require synchronization between the clock domains. Refer to “Synchronization” on page 143 for further details. 17.5.4 Interrupts The interrupt request line is connected to the Interrupt Controller. Using the SYSCTRL interrupts requires the interrupt controller to be configured first. Refer to “Nested Vector Interrupt Controller” on page 28 for details. 17.5.5 Debug Operation When the CPU is halted in debug mode, the SYSCTRL continues normal operation. If the SYSCTRL is configured in a way that requires it to be periodically serviced by the CPU through interrupts or similar, improper operation or data loss may result during debugging. If a debugger connection is detected by the system, BOD33 and BOD12 resets will be blocked. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 134 17.5.6 Register Access Protection All registers with write-access are optionally write-protected by the peripheral access controller (PAC), except the following registers: z Interrupt Flag Status and Clear register (INTFLAG) Write-protection is denoted by the Write-Protection property in the register description. When the CPU is halted in debug mode, all write-protection is automatically disabled. Write-protection does not apply for accesses through an external debugger. Refer to “PAC – Peripheral Access Controller” on page 31 for details. 17.5.7 Analog Connections The 32.768kHz crystal must be connected between the XIN32 and XOUT32 pins, and the 0.4-32MHz crystal must be connected between the XIN and XOUT pins, along with any required load capacitors. 17.6 Functional Description 17.6.1 Principle of Operation XOSC, XOSC32K, OSC32K, OSCULP32K, OSC8M, DFLL48M, BOD33, BOD12, VREG and VREF are configured via SYSCTRL control registers. Through this interface, the sub-peripherals are enabled, disabled or have their calibration values updated. The Power and Clocks Status register gathers different status signals coming from the sub-peripherals controlled by the SYSCTRL. The status signals can be used to generate system interrupts, and in some cases wake up the system from standby mode, provided the corresponding interrupt is enabled. 17.6.2 External Multipurpose Crystal Oscillator (XOSC) Operation The XOSC can operate in two different modes: c. External clock, with an external clock signal connected to the XIN pin d. Crystal oscillator, with an external 0.4-32MHz crystal The XOSC can be used as a clock source for generic clock generators, as described in the “GCLK – Generic Clock Controller” on page 83 chapter. At reset, the XOSC is disabled, and the XIN/XOUT pins can be used as General Purpose I/O (GPIO) pins or by other peripherals in the system. When XOSC is enabled, the operating mode determines the GPIO usage. When in crystal oscillator mode, the XIN and XOUT pins are controlled by the SYSCTRL, and GPIO functions are overridden on both pins. When in external clock mode, the only XIN pin will be overridden and controlled by the SYSCTRL, while the XOUT pin can still be used as a GPIO pin. The XOSC is enabled by writing a one to the Enable bit in the External Multipurpose Crystal Oscillator Control register (XOSC.ENABLE). To enable the XOSC as a crystal oscillator, the XTAL Enable bit (XOSC.XTALEN) must written to one. If XOSC.XTALEN is zero, external clock input will be enabled. When in crystal oscillator mode (XOSC.XTALEN is one), the External Multipurpose Crystal Oscillator Gain (XOSC.GAIN) must be set to match the external crystal oscillator frequency. If the External Multipurpose Crystal Oscillator Automatic Amplitude Gain Control (XOSC.AMPGC) is one, the oscillator amplitude will be automatically adjusted, and in most cases result in a lower power consumption. The XOSC will behave differently in different sleep modes based on the settings of XOSC.RUNSTDBY, XOSC.ONDEMAND and XOSC.ENABLE: Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 135 XOSC.RUNSTDBY XOSC.ONDEMAND XOSC.ENABLE Sleep Behavior - - 0 Disabled 0 0 1 Always run in IDLE sleep modes. Disabled in STANDBY sleep mode. 0 1 1 Only run in IDLE sleep modes if requested by a peripheral. Disabled in STANDBY sleep mode. 1 0 1 Always run in IDLE and STANDBY sleep modes. 1 1 1 Only run in IDLE or STANDBY sleep modes if requested by a peripheral. After a hard reset, or when waking up from a sleep mode where the XOSC was disabled, the XOSC will need a certain amount of time to stabilize on the correct frequency. This start-up time can be configured by changing the Oscillator Start-Up Time bit group (XOSC.STARTUP) in the External Multipurpose Crystal Oscillator Control register. During the start-up time, the oscillator output is masked to ensure that no unstable clock propagates to the digital logic. The External Multipurpose Crystal Oscillator Ready bit in the Power and Clock Status register (PCLKSR.XOSCRDY) is set when the external clock or crystal oscillator is stable and ready to be used as a clock source. An interrupt is generated on a zeroto-one transition on PCLKSR.XOSCRDY if the External Multipurpose Crystal Oscillator Ready bit in the Interrupt Enable Set register (INTENSET.XOSCRDY) is set. 17.6.3 32kHz External Crystal Oscillator (XOSC32K) Operation The XOSC32K can operate in two different modes: 1. External clock, with an external clock signal connected to XIN32 2. Crystal oscillator, with an external 32.768kHz crystal connected between XIN32 and XOUT32 The XOSC32K can be used as a source for generic clock generators, as described in the “GCLK – Generic Clock Controller” on page 83 chapter. At power-on, reset the XOSC32K is disabled, and the XIN32/XOUT32 pins can be used as General Purpose I/O (GPIO) pins or by other peripherals in the system. When XOSC32K is enabled, the operating mode determines the GPIO usage. When in crystal oscillator mode, XIN32 and XOUT32 are controlled by the SYSCTRL, and GPIO functions are overridden on both pins. When in external clock mode, only the XIN32 pin will be overridden and controlled by the SYSCTRL, while the XOUT32 pin can still be used as a GPIO pin. The external clock or crystal oscillator is enabled by writing a one to the Enable bit (XOSC32K.ENABLE) in the 32kHz External Crystal Oscillator Control register. To enable the XOSC32K as a crystal oscillator, a one must be written to the XTAL Enable bit (XOSC32K.XTALEN). If XOSC32K.XTALEN is zero, external clock input will be enabled. The oscillator is disabled by writing a zero to the Enable bit (XOSC32K.ENABLE) in the 32kHz External Crystal Oscillator Control register while keeping the other bits unchanged. Writing to the XOSC32K.ENABLE bit while writing to other bits may result in unpredictable behavior. The oscillator remains enabled in all sleep modes if it has been enabled beforehand. The start-up time of the 32kHz External Crystal Oscillator is selected by writing to the Oscillator Start-Up Time bit group (XOSC32K.STARTUP) in the in the 32kHz External Crystal Oscillator Control register. The SYSCTRL masks the oscillator output during the start-up time to ensure that no unstable clock propagates to the digital logic. The 32kHz External Crystal Oscillator Ready bit (PCLKSR.XOSC32KRDY) in the Power and Clock Status register is set when the oscillator is stable and ready to be used as a clock source. An interrupt is generated on a zero-to-one transition Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 136 of PCLKSR.XOSC32KRDY if the 32kHz External Crystal Oscillator Ready bit (INTENSET.XOSC32KRDY) in the Interrupt Enable Set Register is set. As a crystal oscillator usually requires a very long start-up time (up to one second), the 32kHz External Crystal Oscillator will keep running across resets, except for power-on reset (POR). The XOSC32K has a 32.768kHz output enabled by writing a one to the 32kHz External Crystal Oscillator 32kHz Output Enable bit (XOSC32K.EN32K) in the 32kHz External Crystal Oscillator Control register. The XOSC32K also has a 1.024kHz clock output enabled by writing a one to the 32kHz External Crystal Oscillator 1kHz Output Enable bit (XOSC32K.EN1K) in the External 32kHz Crystal Oscillator Control register. XOSC32K.EN32K and XOSC32K.EN1K are only usable when XIN32 is connected to a crystal, and not when an external digital clock is applied on XIN32. 17.6.4 32kHz Internal Oscillator (OSC32K) Operation The OSC32K provides a tunable, low-speed and low-power clock source. The OSC32K can be used as a source for the generic clock generators, as described in the “GCLK – Generic Clock Controller” on page 83 chapter. The OSC32K is disabled by default. The OSC32K is enabled by writing a one to the 32kHz Internal Oscillator Enable bit (OSC32K.ENABLE) in the 32kHz Internal Oscillator Control register. It is disabled by writing a zero to OSC32K.ENABLE. The OSC32K has a 32.768kHz output enabled by writing a one to the 32kHz Internal Oscillator 32kHz Output Enable bit (OSC32K.EN32K). The OSC32K also has a 1.024kHz clock output enabled by writing a one to the 32kHz Internal Oscillator 1kHz Output Enable bit (OSC32K.EN1K). The frequency of the OSC32K oscillator is controlled by the value in the 32kHz Internal Oscillator Calibration bits (OSC32K.CALIB) in the 32kHz Internal Oscillator Control register. The CALIB value must be written by the user. Flash Factory Calibration values are stored in the non-volatile memory. When writing to the Calibration bits, the user must wait for the PCLKSR.OSC32KRDY bit to go high before the value is committed to the oscillator. 17.6.5 32kHz Ultra Low Power Internal Oscillator (OSCULP32K) Operation The OSCULP32K provides a tunable, low-speed and ultra-low-power clock source. The OSCULP32K is factorycalibrated under typical voltage and temperature conditions. The OSCULP32K should be preferred to the OSC32K whenever the power requirements are prevalent over frequency stability and accuracy. The OSCULP32K can be used as a source for the generic clock generators, as described in the “GCLK – Generic Clock Controller” on page 83 chapter. The OSCULP32K is enabled by default after a power-on reset (POR) and will always run except during POR. The OSCULP32K has a 32.768kHz output and a 1.024kHz output that are always running. The frequency of the OSCULP32K oscillator is controlled by the value in the 32kHz Ultra Low Power Internal Oscillator Calibration bits (OSCULP32K.CALIB) in the 32kHz Ultra Low Power Internal Oscillator Control register. OSCULP32K.CALIB is automatically loaded from Flash Factory Calibration during startup, and is used to compensate for process variation. The calibration value can be overridden by the user by writing to OSCULP32K.CALIB. 17.6.6 8MHz Internal Oscillator (OSC8M) Operation OSC8M is an internal oscillator operating in open-loop mode and generating an 8MHz frequency. The OSC8M is factorycalibrated under typical voltage and temperature conditions. OSC8M is the default clock source that is used after a power-on reset (POR). The OSC8M can be used as a source for the generic clock generators, as described in the “GCLK – Generic Clock Controller” on page 83 chapter, as well as function as the backup clock if a main clock failure is detected. OSC8M is enabled by writing a one to the Oscillator Enable bit (OSC8M.ENABLE) in the OSC8M Control register, and disabled by writing a zero to this bit. When enabling OSC8M, OSC8M.ENABLE must be read back until it reads one. The user must ensure that the OSC8M is fully disabled before enabling it, and that the OSC8M is fully enabled before disabling it by reading OSC8M.ENABLE. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 137 The frequency of the OSC8M oscillator is controlled by the value in the calibration bits (OSC8M.CALIB) in the OSC8M Control register. CALIB is automatically loaded from Flash Factory Calibration during startup, and is used to compensate for process variation. The user can control the oscillation frequency by writing to the Frequency Range (FRANGE) and Calibration (CALIB) bit groups in the 8MHz RC Oscillator Control register (OSC8M). The FRANGE and CALIB bit groups should only be updated when the OSC8M is disabled. As this is in open-loop mode, the frequency will be voltage, temperature and process dependent. OSC8M is automatically switched off in certain sleep modes to reduce power consumption, as described in the “PM – Power Manager” on page 105 chapter. 17.6.7 Digital Frequency Locked Loop (DFLL48M) Operation The DFLL48M can operate in both open-loop mode and closed-loop mode. In closed-loop mode, a low-frequency clock with high accuracy can be used as the reference clock to get high accuracy on the output clock (CLK_DFLL48M). The DFLL48M can be used as a source for the generic clock generators, as described in the “GCLK – Generic Clock Controller” on page 83 chapter. 17.6.7.1 Basic Operation Open-Loop Operation After any reset, the open-loop mode is selected. When operating in open-loop mode, the output frequency of the DFLL48M will be determined by the values written to the DFLL Coarse Value bit group and the DFLL Fine Value bit group (DFLLVAL.COARSE and DFLLVAL.FINE) in the DFLL Value register. It is possible to change the values of DFLLVAL.COARSE and DFLLVAL.FINE and thereby the output frequency of the DFLL48M output clock, CLK_DFLL48M, while the DFLL48M is enabled and in use. CLK_DFLL48M is ready to be used when PCLKSR.DFLLRDY is set after enabling the DFLL48M. Closed-Loop Operation In closed-loop operation, the output frequency is continuously regulated against a reference clock. Once the multiplication factor is set, the oscillator fine tuning is automatically adjusted. The DFLL48M must be correctly configured before closed-loop operation can be enabled. After enabling the DFLL48M, it must be configured in the following way: 1. Enable and select a reference clock (CLK_DFLL48M_REF). CLK_DFLL48M_REF is Generic Clock Channel 0 (DFLL48M_Reference). Refer to “GCLK – Generic Clock Controller” on page 83 chapter for details. 2. Select the maximum step size allowed in finding the Coarse and Fine values by writing the appropriate values to the DFLL Coarse Maximum Step and DFLL Fine Maximum Step bit groups (DFLLMUL.CSTEP and DFLLMUL.FSTEP) in the DFLL Multiplier register. A small step size will ensure low overshoot on the output frequency, but will typically result in longer lock times. A high value might give a large overshoot, but will typically provide faster locking. DFLLMUL.CSTEP and DFLLMUL.FSTEP should not be higher than 50% of the maximum value of DFLLVAL.COARSE and DFLLVAL.FINE, respectively. 3. Select the multiplication factor in the DFLL Multiply Factor bit group (DFLLMUL.MUL) in the DFLL Multiplier register. Care must be taken when choosing DFLLMUL.MUL so that the output frequency does not exceed the maximum frequency of the device. If the target frequency is below the minimum frequency of the DFLL48M, the output frequency will be equal to the DFLL minimum frequency. 4. Start the closed loop mode by writing a one to the DFLL Mode Selection bit (DFLLCTRL.MODE) in the DFLL Control register. The frequency of CLK_DFLL48M (Fclkdfll48m) is given by: F clkdfll48m = DFLLMUL ⋅ MUL × F clkdfll48mref Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 138 where Fclkdfll48mref is the frequency of the reference clock (CLK_DFLL48M_REF). DFLLVAL.COARSE and DFLLVAL.FINE are read-only in closed-loop mode, and are controlled by the frequency tuner shown in Figure 17-1 to meet user specified frequency. In closed-loop mode, the value in DFLLVAL.COARSE is used by the frequency tuner as a starting point for Coarse. Writing DFLLVAL.COARSE to a value close to the final value before entering closed-oop mode will reduce the time needed to get a lock on Coarse. Frequency Locking The locking of the frequency in closed-loop mode is divided into two stages. In the first, coarse stage, the control logic quickly finds the correct value for DFLLVAL.COARSE and sets the output frequency to a value close to the correct frequency. On coarse lock, the DFLL Locked on Coarse Value bit (PCLKSR.DFLLLOCKC) in the Power and Clocks Status register will be set. In the second, fine stage, the control logic tunes the value in DFLLVAL.FINE so that the output frequency is very close to the desired frequency. On fine lock, the DFLL Locked on Fine Value bit (PCLKSR.DFLLLOCKF) in the Power and Clocks Status register will be set. Interrupts are generated by both PCLKSR.DFLLLOCKC and PCLKSR.DFLLLOCKF if INTENSET.DFLLOCKC or INTENSET.DFLLOCKF are written to one. CLK_DFLL48M is ready to be used when the DFLL Ready bit (PCLKSR.DFLLRDY) in the Power and Clocks Status register is set, but the accuracy of the output frequency depends on which locks are set. Frequency Error Measurement The ratio between CLK_DFLL48M_REF and CLK48M_DFLL is measured automatically when the DFLL48M is in closedloop mode. The difference between this ratio and the value in DFLLMUL.MUL is stored in the DFLL Multiplication Ratio Difference bit group(DFLLVAL.DIFF) in the DFLL Value register . The relative error on CLK_DFLL48M compared to the target frequency is calculated as follows: ERROR = DIFF -------------MUL Drift Compensation If the Stable DFLL Frequency bit (DFLLCTRL.STABLE) in the DFLL Control register is zero, the frequency tuner will automatically compensate for drift in the CLK_DFLL48M without losing either of the locks. This means that DFLLVAL.FINE can change after every measurement of CLK_DFLL48M. If the DFLLVAL.FINE value overflows or underflows due to large drift in temperature and/or voltage, the DFLL Out Of Bounds bit (PCLKSR.DFLLOOB) in the Power and Clocks Status register will be set. After an Out of Bounds error condition, the user must rewrite DFLLMUL.MUL to ensure correct CLK_DFLL48M frequency. An interrupt is generated on a zero-to-one transition on PCLKSR.DFLLOOB if the DFLL Out Of Bounds bit (INTENSET.DFLLOOB) in the Interrupt Enable Set register is set. This interrupt will also be set if the tuner is not able to lock on the correct Coarse value. Reference Clock Stop Detection If CLK_DFLL48M_REF stops or is running at a very low frequency (slower than CLK_DFLL48M/(2 * MULMAX)), the DFLL Reference Clock Stopped bit (PCLKSR.DFLLRCS) in the Power and Clocks Status register will be set. Detecting a stopped reference clock can take a long time, on the order of 217 CLK_DFLL48M cycles. When the reference clock is stopped, the DFLL48M will operate as if in open-loop mode. Closed-loop mode operation will automatically resume if the CLK_DFLL48M_REF is restarted. An interrupt is generated on a zero-to-one transition on PCLKSR.DFLLRCS if the DFLL Reference Clock Stopped bit (INTENSET.DFLLRCS) in the Interrupt Enable Set register is set. 17.6.7.2 Additional Features Dealing with Delay in the DFLL in Closed-Loop Mode The time from selecting a new CLK_DFLL48M frequency until this frequency is output by the DFLL48M can be up to several microseconds. If the value in DFLLMUL.MUL is small, this can lead to instability in the DFLL48M locking mechanism, which can prevent the DFLL48M from achieving locks. To avoid this, a chill cycle, during which the CLK_DFLL48M frequency is not measured, can be enabled. The chill cycle is enabled by default, but can be disabled by Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 139 writing a one to the DFLL Chill Cycle Disable bit (DFLLCTRL.CCDIS) in the DFLL Control register. Enabling chill cycles might double the lock time. Another solution to this problem consists of using less strict lock requirements. This is called Quick Lock (QL), which is also enabled by default, but it can be disabled by writing a one to the Quick Lock Disable bit (DFLLCTRL.QLDIS) in the DFLL Control register. The Quick Lock might lead to a larger spread in the output frequency than chill cycles, but the average output frequency is the same. Wake from Sleep Modes DFLL48M can optionally reset its lock bits when it is disabled. This is configured by the Lose Lock After Wake bit (DFLLCTRL.LLAW) in the DFLL Control register. If DFLLCTRL.LLAW is zero, the DFLL48M will be re-enabled and start running with the same configuration as before being disabled, even if the reference clock is not available. The locks will not be lost. When the reference clock has restarted, the Fine tracking will quickly compensate for any frequency drift during sleep if DFLLCTRL.STABLE is zero. If DFLLCTRL.LLAW is one when disabling the DFLL48M, the DFLL48M will lose all its locks, and needs to regain these through the full lock sequence. Accuracy There are three main factors that determine the accuracy of Fclkdfll48m. These can be tuned to obtain maximum accuracy when fine lock is achieved. z Fine resolution: The frequency step between two Fine values. This is relatively smaller for high output frequencies. z Resolution of the measurement: If the resolution of the measured Fclkdfll48m is low, i.e., the ratio between the CLK_DFLL48M frequency and the CLK_DFLL48M_REF frequency is small, then the DFLL48M might lock at a frequency that is lower than the targeted frequency. It is recommended to use a reference clock frequency of 32kHz or lower to avoid this issue for low target frequencies. z The accuracy of the reference clock. 17.6.8 Brown-Out Detector Operation The SYSCTRL provides user control to two Brown-Out Detectors (BOD) monitoring two supply domains. One BOD monitors the 3.3V VDDANA supply (BOD33), and a second BOD monitors the 1.2V VDDCORE supply (BOD12). Both Brown-Out Detectors support continuous or sampling modes. For each BOD, the threshold value action (reset the device or generate an interrupt) as well as the enable/disable settings are loaded from Flash User Calibration at startup, and can be overridden by writing to the corresponding user register bit groups. 17.6.8.1 3.3V Brown-Out Detector (BOD33) The 3.3V Brown-Out Detector (BOD33) monitors the VDDANA supply and compares the voltage with the brown-out threshold level set in the BOD33 Level bit group (BOD33.LEVEL) in the BOD33 register. The Brown-Out Detector can generate either an interrupt or a reset when VDDANA crosses below the brown-out threshold level. The BOD33 detection status can be read from the BOD33 Detection bit (PCLKSR.BOD33DET) in the Power and Clocks Status register. At startup or at power-on reset (POR), the BOD33 register values are loaded from the Flash User Row. Refer to “NonVolatile Memory (NVM) User Row Mapping” on page 25 for more details. 17.6.8.2 1.2V Brown-Out Detector (BOD12) The 1.2V Brown-Out Detector (BOD12) monitors the VDDCORE supply and compares the voltage with the brown-out threshold level set in the BOD12 Level bit group (BOD12.LEVEL) in the BOD12 register. The BOD12 can generate either an interrupt or a reset when VDDCORE crosses below the brown-out threshold level. The BOD12 detection status can be read from the BOD12 Detection bit (PCLKSR.BOD12DET) in the Power and Clocks Status register. At startup or at power-on reset (POR), the BOD12 register values are loaded from the Flash User Row. Refer to “NonVolatile Memory (NVM) User Row Mapping” on page 25 for more details. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 140 17.6.8.3 Continuous Mode When the BOD33 Mode bit (BOD33.MODE) in the BOD33 register is written to zero and the BOD33 is enabled (BOD33.ENABLE is written to one), the BOD33 operates in continuous mode. In this mode, the BOD33 is continuously monitoring the VDDANA supply voltage. When the BOD12 Mode bit (BOD12.MODE) in the BOD12 register is written to zero and the BOD12 is enabled (BOD12.ENABLE is written to one), the BOD12 operates in continuous mode. In this mode, the BOD12 is continuously monitoring the VDDCORE supply voltage. Continuous mode is the default mode for both BOD12 and BOD33. 17.6.8.4 Sampling Mode The sampling mode is a low-power mode where the BOD33 or BOD12 is being repeatedly enabled on a sampling clock’s ticks. The BOD33 or BOD12 will monitor the supply voltage for a short period of time and then go to a low-power disabled state until the next sampling clock tick. Sampling mode is enabled by writing one to BOD33.MODE for BOD33, and by writing one to BOD12.MODE for BOD12. The frequency of the clock ticks (Fclksampling) is controlled by the BOD33 Prescaler Select bit group (BOD33.PSEL) in the BOD33 register and Prescaler Select bit group(BOD12.PSEL) in the BOD12 BOD12 register for BOD33 and BOD12, respectively. F clkprescaler F clksampling = -----------------------------2 ( PSEL + 1 ) The prescaler signal (Fclkprescaler) is a 1kHz clock, output from the32kHz Ultra Low Power Oscillator, OSCULP32K. As the sampling mode clock is different from the APB clock domain, synchronization among the clocks is necessary. Figure 17-2 shows a block diagram of the sampling mode. The BOD33 and BOD12 Synchronization Ready bits (PCLKSR.B33SRDY and PCLKSR.B12SRDY, respectively) in the Power and Clocks Status register show the synchronization ready status of the synchronizer. Writing attempts to the BOD33 register are ignored while PCLKSR.B33SRDY is zero. Writing attempts to the BOD12 register are ignored while PCLKSR.B12SRDY is zero. Figure 17-2. Sampling Mode Block diagram USER INTERFACE REGISTERS (APB clock domain) PSEL CEN PRESCALER (clk_prescaler domain) SYNCHRONIZER MODE CLK_SAMPLING ENABLE CLK_APB CLK_PRESCALER The BOD33 Clock Enable bit (BOD33.CEN) in the BOD33 register and the BOD12 Clock Enable bit (BOD12.CEN) in the BOD12 register should always be disabled before changing the prescaler value. To change the prescaler value for the BOD33 or BOD12 during sampling mode, the following steps need to be taken: 1. Wait until the PCLKSR.B33SRDY bit or the PCLKSR.B12SRDY bit is set. 2. Write the selected value to the BOD33.PSEL or BOD12.PSEL bit group. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 141 17.6.8.5 Hysteresis The hysteresis functionality can be used in both continuous and sampling mode. Writing a one to the BOD33 Hysteresis bit (BOD33.HYST) in the BOD33 register will add hysteresis to the BOD33 threshold level. Writing a one to the BOD12 Hysteresis bit (BOD12.HYST) in the BOD12 register will add hysteresis to the BOD12 threshold level. 17.6.9 Voltage Regulator System Operation The embedded Voltage Regulator (VREG) is an internal voltage regulator that provides the core logic supply (VDDCORE). 17.6.9.1 User Control of the Voltage Regulator System The Voltage Regulator is enabled after any reset, and can be disabled by writing a zero to the Enable bit (VREG.ENABLE) of the VREG register. The Voltage Regulator output supply level is determined by the LEVEL bit group (VREG.LEVEL) value in the VREG register. At reset, the VREG.LEVEL register value is loaded from Flash Factory Calibration. Via the VDDCORE Monitoring bit group (VREG.VDDMON), it is possible to monitor the core supply voltage so that if it drops below a critical level, a power-on reset is applied. The device is allowed to restart executing code only after the core supply voltage is restored to an acceptable level. The threshold at which this system triggers is significantly lower than the 1.2V Brown-Out Detector's own threshold (BOD12). This can, therefore, be seen as a complementary voltage monitoring feature. 17.6.10 Voltage Reference System Operation The Voltage Reference System (VREF) consists of a Bandgap Reference Voltage Generator and a temperature sensor. The Bandgap Reference Voltage Generator is factory-calibrated under typical voltage and temperature conditions. At reset, the VREF.CAL register value is loaded from Flash Factory Calibration. The temperature sensor can be used to get an absolute temperature in the temperature range of CMIN to CMAX degrees Celsius. The sensor will output a linear voltage proportional to the temperature. To calculate the temperature from a measured voltage, the following formula can be used: Δtemperature C MIN + ( Vmes – Vout MAX ) -----------------------------------Δvoltage 17.6.10.1 User Control of the Voltage Regulator System ITo enable the temperature sensor, write a one the Temperature Sensor Enable bit (VREF.TSEN) in the VREF register. The temperature sensor can be redirected to the ADC for conversion. The Bandgap Reference Voltage Generator output can also be routed to the ADC if the Bandgap Output Enable bit (VREF.BGOUTEN) in the VREF register is set. The Bandgap Reference Voltage Generator output level is determined by the CALIB bit group (VREF.CALIB) value in the VREF register.The default calibration value can be overridden by the user by writing to the CALIB bit group. 17.6.11 Interrupts The SYSCTRL has the following interrupt sources: z XOSCRDY - Multipurpose Crystal Oscillator Ready: A 0 to 1 transition on the PCLKSR.XOSCRDY bit is detected z XOSC32KRDY - 32kHz Crystal Oscillator Ready: A 0 to 1 transition on the PCLKSR.XOSC32KRDY bit is detected z OSC32KRDY - 32kHz Internal Oscillator Ready: A 0 to 1 transition on the PCLKSR.OSC32KRDY bit is detected z OSC8MRDY - 8MHz Internal Oscillator Ready: A 0 to 1 transition on the PCLKSR.OSC8MRDY bit is detected z DFLLRDY - DFLL48M Ready: A 0 to 1 transition on the PCLKSR.DFLLRDY bit is detected z DFLLOOB - DFLL48M Out Of Boundaries: A 0 to 1 transition on the PCLKSR.DFLLOOB bit is detected z DFLLLOCKF - DFLL48M Fine Lock: A 0 to 1 transition on the PCLKSR.DFLLLOCKF bit is detected Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 142 z DFLLLOCKC - DFLL48M Coarse Lock: A 0 to 1 transition on the PCLKSR.DFLLLOCKC bit is detected z DFLLRCS - DFLL48M Reference Clock has Stopped: A 0 to 1 transition on the PCLKSR.DFLLRCS bit is detected z BOD33RDY - BOD33 Ready: A 0 to 1 transition on the PCLKSR.BOD33RDY bit is detected z BOD33DET - BOD33 Detection: A 0 to 1 transition on the PCLKSR.BOD33DET bit is detected z B33SRDY - BOD33 Synchronization Ready: A 1 to 0 transition on the PCLKSR.B33SRDY bit is detected z BOD12RDY - BOD12 Ready: A 0 to 1 transition on the PCLKSR.BOD12RDY bit is detected z BOD12DET - BOD12 Detection: A 0 to 1 transition on the PCLKSR.BOD12DET bit is detected z B12SRDY - BOD12 Synchronization Ready: A 1 to 0 transition on the PCLKSR.B12SRDY bit is detected Each interrupt source has an interrupt flag associated with it. The interrupt flag in the Interrupt Flag Status and Clear register (INTFLAG) is set when the interrupt condition occurs. Each interrupt can be individually enabled by writing a one to the corresponding bit in the Interrupt Enable Set register (INTENSET), and disabled by writing a one to the corresponding bit in the Interrupt Enable Clear register (INTENCLR). An interrupt request is generated when the interrupt flag is set and the corresponding interrupt is enabled. The interrupt request remains active until the interrupt flag is cleared, the interrupt is disabled or the SYSCTRL is reset. See the INTFLAG register for details on how to clear interrupt flags. The SYSCTRL has one common interrupt request line for all the interrupt sources.The user must read the INTFLAG register to determine which interrupt condition is present. Refer to the <Interrupt Controller- cross reference needed> chapter for details. Note that interrupts must be globally enabled for interrupt requests to be generated. Refer to the “Nested Vector Interrupt Controller” on page 28 chapter for details. 17.6.12 Synchronization Due to the multiple clock domains, values in the DFLL48M control registers need to be synchronized to other clock domains. The status of this synchronization can be read from the Power and Clocks Status register (PCLKSR). Before writing to any of the DFLL48M control registers, the user must check that the DFLL Ready bit (PCLKSR.DFLLRDY) in PCLKSR is set to one. When this bit is set, the DFLL48M can be configured and CLK_DFLL48M is ready to be used. Any write to any of the DFLL48M control registers while DFLLRDY is zero will be ignored. An interrupt is generated on a zeroto-one transition of DFLLRDY if the DFLLRDY bit (INTENSET.DFLLDY) in the Interrupt Enable Set register is set. In order to read from any of the DFLL48M configuration registers, the user must request a read synchronization by writing a one to DFLLSYNC.READREQ. The registers can be read only when PCLKSR.DFLLRDY is set. If DFLLSYNC.READREQ is not written before a read, a synchronization will be started, and the bus will be halted until the synchronization is complete. Reading the DFLL48M registers when the DFLL48M is dsiabled will not halt the bus. rsimplyThe prescaler counter used to trigger one-shot brown-out detections also operates asynchronously from the peripheral bus. As a consequence, the prescaler registers require synchronization when written or read. The synchronization results in a delay from when the initialization of the write or read operation begins until the operation is complete. The write-synchronization is triggered by a write to the BOD12 or BOD33 control register. The Synchronization Ready bit (PCLKSR.B12SRDY or PCLKSR.B33SRDY) in the PCLKSR register will be cleared when the write-synchronization starts and set when the write-synchronization is complete. When the write-synchronization is ongoing (PCLKSR.B33SRDY or PCLKSR.B12SRDY is zero), an attempt to do any of the following will cause the peripheral bus to stall until the synchronization is complete: z Writing to the BOD33 or BOD12 control register z Reading the BOD33 or BOD12 control register that was written The user can either poll PCLKSR.B12SRDY or PCLKSR.B33SRDY or use the INTENSET.B12SRDY or INTENSET.B33SRDY interrupts to check when the synchronization is complete. It is also possible to perform the next read/write operation and wait, as this next operation will be completed after the ongoing read/write operation is synchronized. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 143 17.7 Register Summary Table 17-1. SYSCTRL Register Summary (Sheet 1 of 2) Offset Name 0x00 0x01 Bit Pos. 7:0 INTENCLR DFLLLCKC 15:8 0x02 23:16 0x03 31:24 0x04 7:0 0x05 15:8 DFLLLCKC DFLLLCKF DFLLOOB DFLLRDY OSC8MRDY OSC32KRDY XOSC32KRDY XOSCRDY B12SRDY BOD12DET BOD12RDY B33SRDY BOD33DET BOD33RDY DFLLRCS DFLLLCKF DFLLOOB DFLLRDY OSC8MRDY OSC32KRDY XOSC32KRDY XOSCRDY B12SRDY BOD12DET BOD12RDY B33SRDY BOD33DET BOD33RDY DFLLRCS DFLLLCKF DFLLOOB DFLLRDY OSC8MRDY OSC32KRDY XOSC32KRDY XOSCRDY B12SRDY BOD12DET BOD12RDY B33SRDY BOD33DET BOD33RDY DFLLRCS INTENSET 0x06 23:16 0x07 31:24 0x08 7:0 0x09 DFLLLCKC 15:8 INTFLAG 0x0A 23:16 0x0B 31:24 0x0C 7:0 0x0D 15:8 DFLLLCKC DFLLLCKF DFLLOOB DFLLRDY OSC8MRDY OSC32KRDY XOSC32KRDY XOSCRDY B12SRDY BOD12DET BOD12RDY B33SRDY BOD33DET BOD33RDY DFLLRCS XTALEN ENABLE PCLKSR 0x0E 23:16 0x0F 31:24 0x10 7:0 ONDEMAND RUNSTDBY XOSC 0x11 15:8 0x12 Reserved 0x13 Reserved 0x14 7:0 STARTUP[3:0] ONDEMAND RUNSTDBY AAMPEN AMPGC EN1K EN32K GAIN[2:0] XTALEN ENABLE XOSC32K 0x15 15:8 0x16 Reserved 0x17 Reserved 0x18 7:0 0x19 15:8 STARTUP[2:0] WRTLOCK ONDEMAND RUNSTDBY EN1K EN32K ENABLE STARTUP[2:0] WRTLOCK OSC32K 0x1A 23:16 0x1B CALIB[6:0] 31:24 0x1C OSCULP32K 0x1D Reserved 0x1E Reserved 0x1F Reserved 0x20 0x21 7:0 WRTLOCK 7:0 ONDEMAND CALIB[4:0] RUNSTDBY ENABLE 15:8 PRESC[1:0] OSC8M 0x22 23:16 0x23 31:24 0x24 7:0 CALIB[7:0] FRANGE[1:0] ONDEMAND RUNSTDBY CALIB[11:8] LLAW STABLE MODE ENABLE DFLLCTRL 0x25 15:8 0x26 Reserved 0x27 Reserved QLDIS CCDIS Atmel SAM D20 [Preliminary DATASHEET] 42129A‚ÄìSAM‚Äì06/2013 144 Table 17-1. SYSCTRL Register Summary (Sheet 2 of 2) Offset Name 0x28 Bit Pos. 7:0 0x29 FINE[7:0] 15:8 COARSE[4:0] DFLLVAL 0x2A 23:16 DIFF[7:0] 0x2B 31:24 DIFF[15:8] 0x2C 7:0 MUL[7:0] 0x2D 0x2E DFLLMUL 0x2F 15:8 MUL[15:8] 23:16 FSTEP[7:0] 31:24 0x30 DFLLSYNC 0x31 Reserved 0x32 Reserved 0x33 Reserved 0x34 7:0 7:0 0x35 15:8 CSTEP[4:0] READREQ RUNSTDBY ACTION[1:0] HYST PSEL[3:0] ENABLE CEN MODE BOD33 0x36 23:16 0x37 31:24 0x38 7:0 0x39 15:8 LEVEL[5:0] RUNSTDBY ACTION[1:0] HYST PSEL[3:0] ENABLE CEN MODE BOD12 0x3A 23:16 0x3B 31:24 0x3C 7:0 LEVEL[4:0] RUNSTDBY VDDMON[1:0] ENABLE VREG 0x3D 15:8 0x3E Reserved 0x3F Reserved 0x40 7:0 0x41 15:8 CALIB[2:0] LEVEL[2:0] BGOUTEN TSEN VREF 0x42 23:16 0x43 31:24 CALIB[7:0] CALIB[10:8] Atmel SAM D20 [Preliminary DATASHEET] 42129A‚ÄìSAM‚Äì06/2013 145 17.8 Register Description Registers can be 8, 16 or 32 bits wide. Atomic 8-, 16- and 32-bit accesses are supported. In addition, the 8-bit quarters and 16-bit halves of a 32-bit register and the 8-bit halves of a 16-bit register can be accessed directly. Some registers are optionally write-protected by the Peripheral Access Controller (PAC). Write-protection is denoted by the Write-Protected property in each individual register description. Please refer to the Register Access Protection section and the PAC chapter for details. Some registers require synchronization when read and/or written. Synchronization is denoted by the Synchronized property in each individual register description. Refer to “Synchronization” on page 143 for details. Atmel SAM D20 [Preliminary DATASHEET] 42129A‚ÄìSAM‚Äì06/2013 146 17.8.1 Interrupt Enable Clear This register allows the user to disable an interrupt without doing a read-modify-write operation. Changes in this register will also be reflected in the Interrupt Enable Set register (INTENSET). Name: INTENCLR Offset: 0x00 Reset: 0x00000000 Property: Write-Protected Bit 31 30 29 28 27 26 25 24 Access R R R R R R R R Reset 0 0 0 0 0 0 0 0 Bit 23 22 21 20 19 18 17 16 Access R R R R R R R R Reset 0 0 0 0 0 0 0 0 Bit 15 14 13 12 11 10 9 8 B12SRDY BOD12DET BOD12RDY B33SRDY BOD33DET BOD33RDY DFLLRCS Access R R/W R/W R/W R/W R/W R/W R/W Reset 0 0 0 0 0 0 0 0 Bit 7 6 5 4 3 2 1 0 DFLLLCKC DFLLLCKF DFLLOOB DFLLRDY OSC8MRDY OSC32KRDY XOSC32KRDY XOSCRDY R/W R/W R/W R/W R/W R/W R/W R/W 0 0 0 0 0 0 0 0 Access Reset z Bits 31:15 – 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. These bits will always return zero when read. z Bit 14 – B12SRDY: BOD12 Synchronization Ready Interrupt Enable 0: The BOD12 Synchronization Ready interrupt is disabled. 1: The BOD12 Synchronization Ready interrupt is enabled, and an interrupt request will be generated when the BOD12 Synchronization Ready Interrupt flag is set. Writing a zero to this bit has no effect. Writing a one to this bit will clear the BOD12 Synchronization Ready Interrupt Enable bit, disable the BOD12 Synchronization Ready interrupt and clear the corresponding interrupt request. z Bit 13 – BOD12DET: BOD12 Detection Interrupt Enable 0: The BOD12 Detection interrupt is disabled. 1: The BOD12 Detection interrupt is enabled, and an interrupt request will be generated when the BOD12 Detection Interrupt flag is set. Atmel SAM D20 [Preliminary DATASHEET] 42129A‚ÄìSAM‚Äì06/2013 147 Writing a zero to this bit has no effect. Writing a one to this bit will clear the BOD12 Detection Interrupt Enable bit, disable the BOD12 Detection interrupt and clear the corresponding interrupt request. z Bit 12 – BOD12RDY: BOD12 Ready Interrupt Enable 0: The BOD12 Ready interrupt is disabled. 1: The BOD12 Ready interrupt is enabled and an interrupt request will be generated when the BOD12 Ready Interrupt flag is set. Writing a zero to this bit has no effect. Writing a one to this bit will clear the BOD12 Ready Interrupt Enable bit, disable the BOD12 Ready interrupt and clear the corresponding interrupt request. z Bit 11 – B33SRDY: BOD33 Synchronization Ready Interrupt Enable 0: The BOD33 Synchronization Ready interrupt is disabled. 1: The BOD33 Synchronization Ready interrupt is enabled, and an interrupt request will be generated when the BOD33 Synchronization Ready Interrupt flag is set. Writing a zero to this bit has no effect. Writing a one to this bit will clear the BOD33 Synchronization Ready Interrupt Enable bit, disable the BOD33 Synchronization Ready interrupt and clear the corresponding interrupt request. z Bit 10 – BOD33DET: BOD33 Detection Interrupt Enable 0: The BOD33 Detection interrupt is disabled. 1: The BOD33 Detection interrupt is enabled, and an interrupt request will be generated when the BOD33 Detection Interrupt flag is set. Writing a zero to this bit has no effect. Writing a one to this bit will clear the BOD33 Detection Interrupt Enable bit, disable the BOD33 Detection interrupt and clear the corresponding interrupt request. z Bit 9 – BOD33RDY: BOD33 Ready Interrupt Enable 0: The BOD33 Ready interrupt is disabled. 1: The BOD33 Ready interrupt is enabled, and an interrupt request will be generated when the BOD33 Ready Interrupt flag is set. Writing a zero to this bit has no effect. Writing a one to this bit will clear the BOD33 Ready Interrupt Enable bit, disable the BOD33 Ready interrupt and clear the corresponding interrupt request. z Bit 8 – DFLLRCS: DFLL Reference Clock Stopped Interrupt Enable 0: The DFLL Reference Clock Stopped interrupt is disabled. 1: The DFLL Reference Clock Stopped interrupt is enabled, and an interrupt request will be generated when the DFLL Reference Clock Stopped Interrupt flag is set. Writing a zero to this bit has no effect. Writing a one to this bit will clear the DFLL Reference Clock Stopped Interrupt Enable bit, disable the DFLL Reference Clock Stopped interrupt and clear the corresponding interrupt request. z Bit 7 – DFLLLCKC: DFLL Lock Coarse Interrupt Enable 0: The DFLL Lock Coarse interrupt is disabled. 1: The DFLL Lock Coarse interrupt is enabled, and an interrupt request will be generated when the DFLL Lock Coarse Interrupt flag is set. Writing a zero to this bit has no effect. Writing a one to this bit will clear the DFLL Lock Coarse Interrupt Enable bit, disable the DFLL Lock Coarse interrupt and clear the corresponding interrupt request. Atmel SAM D20 [Preliminary DATASHEET] 42129A‚ÄìSAM‚Äì06/2013 148 z Bit 6 – DFLLLCKF: DFLL Lock Fine Interrupt Enable 0: The DFLL Lock Fine interrupt is disabled. 1: The DFLL Lock Fine interrupt is enabled, and an interrupt request will be generated when the DFLL Lock Fine Interrupt flag is set. Writing a zero to this bit has no effect. Writing a one to this bit will clear the DFLL Lock Fine Interrupt Enable bit, disable the DFLL Lock Fine interrupt and clear the corresponding interrupt request. z Bit 5 – DFLLOOB: DFLL Out Of Bounds Interrupt Enable 0: The DFLL Out Of Bounds interrupt is disabled. 1: The DFLL Out Of Bounds interrupt is enabled, and an interrupt request will be generated when the DFLL Out Of Bounds Interrupt flag is set. Writing a zero to this bit has no effect. Writing a one to this bit will clear the DFLL Out Of Bounds Interrupt Enable bit, disable the DFLL Out Of Bounds interrupt and clear the corresponding interrupt request. z Bit 4 – DFLLRDY: DFLL Ready Interrupt Enable 0: The DFLL Ready interrupt is disabled. 1: The DFLL Ready interrupt is enabled, and an interrupt request will be generated when the DFLL Ready Interrupt flag is set. Writing a zero to this bit has no effect. Writing a one to this bit will clear the DFLL Ready Interrupt Enable bit, disable the DFLL Ready interrupt and clear the corresponding interrupt request. z Bit 3 – OSC8MRDY: OSC8M Ready Interrupt Enable 0: The OSC8M Ready interrupt is disabled. 1: The OSC8M Ready interrupt is enabled, and an interrupt request will be generated when the OSC8M Ready Interrupt flag is set. Writing a zero to this bit has no effect. Writing a one to this bit will clear the OSC8M Ready Interrupt Enable bit, disable the OSC8M Ready interrupt and clear the corresponding interrupt request. z Bit 2 – OSC32KRDY: OSC32K Ready Interrupt Enable 0: The OSC32K Ready interrupt is disabled. 1: The OSC32K Ready interrupt is enabled, and an interrupt request will be generated when the OSC32K Ready Interrupt flag is set. Writing a zero to this bit has no effect. Writing a one to this bit will clear the OSC32K Ready Interrupt Enable bit, disable the OSC32K Ready interrupt and clear the corresponding interrupt request. z Bit 1 – XOSC32KRDY: XOSC32K Ready Interrupt Enable 0: The XOSC32K Ready interrupt is disabled. 1: The XOSC32K Ready interrupt is enabled, and an interrupt request will be generated when the XOSC32K Ready Interrupt flag is set. Writing a zero to this bit has no effect. Writing a one to this bit will clear the XOSC32K Ready Interrupt Enable bit, disable the XOSC32K Ready interrupt and clear the corresponding interrupt request. z Bit 0 – XOSCRDY: XOSC Ready Interrupt Enable 0: The XOSC Ready interrupt is disabled. 1: The XOSC Ready interrupt is enabled, and an interrupt request will be generated when the XOSC Ready Interrupt flag is set. Atmel SAM D20 [Preliminary DATASHEET] 42129A‚ÄìSAM‚Äì06/2013 149 Writing a zero to this bit has no effect. Writing a one to this bit will clear the XOSC Ready Interrupt Enable bit, disable the XOSC Ready interrupt and clear the corresponding interrupt request. Atmel SAM D20 [Preliminary DATASHEET] 42129A‚ÄìSAM‚Äì06/2013 150 17.8.2 Interrupt Enable Set This register allows the user to enable an interrupt without doing a read-modify-write operation. Changes in this register will also be reflected in the Interrupt Enable Clear register (INTENCLR). Name: INTENSET Offset: 0x04 Reset: 0x00000000 Property: Write-Protected Bit 31 30 29 28 27 26 25 24 Access R R R R R R R R Reset 0 0 0 0 0 0 0 0 Bit 23 22 21 20 19 18 17 16 Access R R R R R R R R Reset 0 0 0 0 0 0 0 0 Bit 15 14 13 12 11 10 9 8 B12SRDY BOD12DET BOD12RDY B33SRDY BOD33DET BOD33RDY DFLLRCS Access R R/W R/W R/W R/W R/W R/W R/W Reset 0 0 0 0 0 0 0 0 Bit 7 6 5 4 3 2 1 0 DFLLLCKC DFLLLCKF DFLLOOB DFLLRDY OSC8MRDY OSC32KRDY XOSC32KRDY XOSCRDY R/W R/W R/W R/W R/W R/W R/W R/W 0 0 0 0 0 0 0 0 Access Reset z Bits 31:15 – 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. These bits will always return zero when read. z Bit 14 – B12SRDY: BOD12 Synchronization Ready Interrupt Enable 0: The BOD12 Synchronization Ready interrupt is disabled. 1: The BOD12 Synchronization Ready interrupt is enabled, and an interrupt request will be generated when the BOD12 Synchronization Ready Interrupt flag is set. Writing a zero to this bit has no effect. Writing a one to this bit will set the BOD12 Synchronization Ready Interrupt Disable/Enable bit, disable the BOD12 Synchronization Ready interrupt and set the corresponding interrupt request. z Bit 13 – BOD12DET: BOD12 Detection Interrupt Enable 0: The BOD12 Detection interrupt is disabled. 1: The BOD12 Detection interrupt is enabled, and an interrupt request will be generated when the BOD12 Detection Interrupt flag is set. Atmel SAM D20 [Preliminary DATASHEET] 42129A‚ÄìSAM‚Äì06/2013 151 Writing a zero to this bit has no effect. z Bit 12 – BOD12RDY: BOD12 Ready Interrupt Enable 0: The BOD12 Ready interrupt is disabled. 1: The BOD12 Ready interrupt is enabled, and an interrupt request will be generated when the BOD12 Ready Interrupt flag is set. Writing a zero to this bit has no effect. Writing a one to this bit will set the BOD12 Ready Interrupt Disable/Enable bit, disable the BOD12 Ready interrupt and set the corresponding interrupt request. z Bit 11 – B33SRDY: BOD33 Synchronization Ready Interrupt Enable 0: The BOD33 Synchronization Ready interrupt is disabled. 1: The BOD33 Synchronization Ready interrupt is enabled, and an interrupt request will be generated when the BOD33 Synchronization Ready Interrupt flag is set. Writing a zero to this bit has no effect. Writing a one to this bit will set the BOD33 Synchronization Ready Interrupt Disable/Enable bit, disable the BOD33 Synchronization Ready interrupt and set the corresponding interrupt request. z Bit 10 – BOD33DET: BOD33 Detection Interrupt Enable 0: The BOD33 Detection interrupt is disabled. 1: The BOD33 Detection interrupt is enabled, and an interrupt request will be generated when the BOD33 Detection Interrupt flag is set. Writing a zero to this bit has no effect. Writing a one to this bit will set the BOD33 Detection Interrupt Disable/Enable bit, disable the BOD33 Detection interrupt and set the corresponding interrupt request. z Bit 9 – BOD33RDY: BOD33 Ready Interrupt Enable 0: The BOD33 Ready interrupt is disabled. 1: The BOD33 Ready interrupt is enabled, and an interrupt request will be generated when the BOD33 Ready Interrupt flag is set. Writing a zero to this bit has no effect. Writing a one to this bit will set the BOD33 Ready Interrupt Disable/Enable bit, disable the BOD33 Ready interrupt and set the corresponding interrupt request. z Bit 8 – DFLLRCS: DFLL Reference Clock Stopped Interrupt Enable 0: The DFLL Reference Clock Stopped interrupt is disabled. 1: The DFLL Reference Clock Stopped interrupt is enabled, and an interrupt request will be generated when the DFLL Reference Clock Stopped Interrupt flag is set. Writing a zero to this bit has no effect. Writing a one to this bit will set the DFLL Reference Clock Stopped Interrupt Disable/Enable bit, disable the DFLL Reference Clock Stopped interrupt and set the corresponding interrupt request. z Bit 7 – DFLLLCKC: DFLL Lock Coarse Interrupt Enable 0: The DFLL Lock Coarse interrupt is disabled. 1: The DFLL Lock Coarse interrupt is enabled, and an interrupt request will be generated when the DFLL Lock Coarse Interrupt flag is set. Writing a zero to this bit has no effect. Writing a one to this bit will set the DFLL Lock Coarse Interrupt Disable/Enable bit, disable the DFLL Lock Coarse interrupt and set the corresponding interrupt request. z Bit 6 – DFLLLCKF: DFLL Lock Fine Interrupt Enable 0: The DFLL Lock Fine interrupt is disabled. Atmel SAM D20 [Preliminary DATASHEET] 42129A‚ÄìSAM‚Äì06/2013 152 1: The DFLL Lock Fine interrupt is enabled, and an interrupt request will be generated when the DFLL Lock Fine Interrupt flag is set. Writing a zero to this bit has no effect. Writing a one to this bit will set the DFLL Lock Fine Interrupt Disable/Enable bit, disable the DFLL Lock Fine interrupt and set the corresponding interrupt request. z Bit 5 – DFLLOOB: DFLL Out Of Bounds Interrupt Enable 0: The DFLL Out Of Bounds interrupt is disabled. 1: The DFLL Out Of Bounds interrupt is enabled, and an interrupt request will be generated when the DFLL Out Of Bounds Interrupt flag is set. Writing a zero to this bit has no effect. Writing a one to this bit will set the DFLL Out Of Bounds Interrupt Disable/Enable bit, disable the DFLL Out Of Bounds interrupt and set the corresponding interrupt request. z Bit 4 – DFLLRDY: DFLL Ready Interrupt Enable 0: The DFLL Ready interrupt is disabled. 1: The DFLL Ready interrupt is enabled, and an interrupt request will be generated when the DFLL Ready Interrupt flag is set. Writing a zero to this bit has no effect. Writing a one to this bit will set the DFLL Ready Interrupt Disable/Enable bit, disable the DFLL Ready interrupt and set the corresponding interrupt request. z Bit 3 – OSC8MRDY: OSC8M Ready Interrupt Enable 0: The OSC8M Ready interrupt is disabled. 1: The OSC8M Ready interrupt is enabled, and an interrupt request will be generated when the OSC8M Ready Interrupt flag is set. Writing a zero to this bit has no effect. Writing a one to this bit will set the OSC8M Ready Interrupt Disable/Enable bit, disable the OSC8M Ready interrupt and set the corresponding interrupt request. z Bit 2 – OSC32KRDY: OSC32K Ready Interrupt Enable 0: The OSC32K Ready interrupt is disabled. 1: The OSC32K Ready interrupt is enabled, and an interrupt request will be generated when the OSC32K Ready Interrupt flag is set. Writing a zero to this bit has no effect. Writing a one to this bit will set the OSC32K Ready Interrupt Disable/Enable bit, disable the OSC32K Ready interrupt and set the corresponding interrupt request. z Bit 1 – XOSC32KRDY: XOSC32K Ready Interrupt Enable 0: The XOSC32K Ready interrupt is disabled. 1: The XOSC32K Ready interrupt is enabled, and an interrupt request will be generated when the XOSC32K Ready Interrupt flag is set. Writing a zero to this bit has no effect. Writing a one to this bit will set the XOSC32K Ready Interrupt Disable/Enable bit, disable the XOSC32K Ready interrupt and set the corresponding interrupt request. z Bit 0 – XOSCRDY: XOSC Ready Interrupt Enable 0: The XOSC Ready interrupt is disabled. 1: The XOSC Ready interrupt is enabled, and an interrupt request will be generated when the XOSC Ready Interrupt flag is set. Writing a zero to this bit has no effect. Atmel SAM D20 [Preliminary DATASHEET] 42129A‚ÄìSAM‚Äì06/2013 153 17.8.3 Interrupt Flag Status and Clear Name: INTFLAG Offset: 0x08 Reset: 0x00000000 Property: - Bit 31 30 29 28 27 26 25 24 Access R R R R R R R R Reset 0 0 0 0 0 0 0 0 Bit 23 22 21 20 19 18 17 16 Access R R R R R R R R Reset 0 0 0 0 0 0 0 0 Bit 15 14 13 12 11 10 9 8 B12SRDY BOD12DET BOD12RDY B33SRDY BOD33DET BOD33RDY DFLLRCS Access R R/W R/W R/W R/W R/W R/W R/W Reset 0 0 0 0 0 0 0 0 Bit 7 6 5 4 3 2 1 0 DFLLLCKC DFLLLCKF DFLLOOB DFLLRDY OSC8MRDY OSC32KRDY XOSC32KRDY XOSCRDY R/W R/W R/W R/W R/W R/W R/W R/W 0 0 0 0 0 0 0 0 Access Reset z Bits 31:15 – 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. These bits will always return zero when read. z Bit 14 – B12SRDY: BOD12 Synchronization Ready This flag is cleared by writing a one to it. This flag is set on a zero-to-one transition of the BOD12 Synchronization Ready bit in the Status register (PCLKSR.B12SRDY) and will generate an interrupt request if INTENSET.B12SRDY is one. Writing a zero to this bit has no effect. Writing a one to this bit clears the BOD12 Synchronization Ready interrupt flag. z Bit 13 – BOD12DET: BOD12 Detection This flag is cleared by writing a one to it. This flag is set on a zero-to-one transition of the BOD12 Detection bit in the Status register (PCLKSR.BOD12DET) and will generate an interrupt request if INTENSET.BOD12DET is one. Writing a zero to this bit has no effect. Writing a one to this bit clears the BOD12 Detection interrupt flag. Atmel SAM D20 [Preliminary DATASHEET] 42129A‚ÄìSAM‚Äì06/2013 154 z Bit 12 – BOD12RDY: BOD12 Ready This flag is cleared by writing a one to it. This flag is set on a zero-to-one transition of the BOD12 Ready bit in the Status register (PCLKSR.BOD12RDY) and will generate an interrupt request if INTENSET.BOD12RDY is one. Writing a zero to this bit has no effect. Writing a one to this bit clears the BOD12 Ready interrupt flag. z Bit 11 – B33SRDY: BOD33 Synchronization Ready This flag is cleared by writing a one to it. This flag is set on a zero-to-one transition of the BOD33 Synchronization Ready bit in the Status register (PCLKSR.B33SRDY) and will generate an interrupt request if INTENSET.B33SRDY is one. Writing a zero to this bit has no effect. Writing a one to this bit clears the BOD33 Synchronization Ready interrupt flag z Bit 10 – BOD33DET: BOD33 Detection This flag is cleared by writing a one to it. This flag is set on a zero-to-one transition of the BOD33 Detection bit in the Status register (PCLKSR.BOD33DET) and will generate an interrupt request if INTENSET.BOD33DET is one. Writing a zero to this bit has no effect. Writing a one to this bit clears the BOD33 Detection interrupt flag. z Bit 9 – BOD33RDY: BOD33 Ready This flag is cleared by writing a one to it. This flag is set on a zero-to-one transition of the BOD33 Ready bit in the Status register (PCLKSR.BOD33RDY) and will generate an interrupt request if INTENSET.BOD33RDY is one. Writing a zero to this bit has no effect. Writing a one to this bit clears the BOD33 Ready interrupt flag. z Bit 8 – DFLLRCS: DFLL Reference Clock Stopped This flag is cleared by writing a one to it. This flag is set on a zero-to-one transition of the DFLL Reference Clock Stopped bit in the Status register (PCLKSR.DFLLRCS) and will generate an interrupt request if INTENSET.DFLLRCS is one. Writing a zero to this bit has no effect. Writing a one to this bit clears the DFLL Reference Clock Stopped interrupt flag. z Bit 7 – DFLLLCKC: DFLL Lock Coarse This flag is cleared by writing a one to it. This flag is set on a zero-to-one transition of the DFLL Lock Coarse bit in the Status register (PCLKSR.DFLLLCKC) and will generate an interrupt request if INTENSET.DFLLLCKC is one. Writing a zero to this bit has no effect. Writing a one to this bit clears the DFLL Lock Coarse interrupt flag. z Bit 6 – DFLLLCKF: DFLL Lock Fine This flag is cleared by writing a one to it. This flag is set on a zero-to-one transition of the DFLL Lock Fine bit in the Status register (PCLKSR.DFLLLCKF) and will generate an interrupt request if INTENSET.DFLLLCKF is one. Writing a zero to this bit has no effect. Writing a one to this bit clears the DFLL Lock Fine interrupt flag. z Bit 5 – DFLLOOB: DFLL Out Of Bounds This flag is cleared by writing a one to it. Atmel SAM D20 [Preliminary DATASHEET] 42129A‚ÄìSAM‚Äì06/2013 155 This flag is set on a zero-to-one transition of the DFLL Out Of Bounds bit in the Status register (PCLKSR.DFLLOOB) and will generate an interrupt request if INTENSET.DFLLOOB is one. Writing a zero to this bit has no effect. Writing a one to this bit clears the DFLL Out Of Bounds interrupt flag. z Bit 4 – DFLLRDY: DFLL Ready This flag is cleared by writing a one to it. This flag is set on a zero-to-one transition of the DFLL Ready bit in the Status register (PCLKSR.DFLLRDY) and will generate an interrupt request if INTENSET.DFLLRDY is one. Writing a zero to this bit has no effect. Writing a one to this bit clears the DFLL Ready interrupt flag. z Bit 3 – OSC8MRDY: OSC8M Ready This flag is cleared by writing a one to it. This flag is set on a zero-to-one transition of the OSC8M Ready bit in the Status register (PCLKSR.OSC8MRDY) and will generate an interrupt request if INTENSET.OSC8MRDY is one. Writing a zero to this bit has no effect. Writing a one to this bit clears the OSC8M Ready interrupt flag. z Bit 2 – OSC32KRDY: OSC32K Ready This flag is cleared by writing a one to it. This flag is set on a zero-to-one transition of the OSC32K Ready bit in the Status register (PCLKSR.OSC32KRDY) and will generate an interrupt request if INTENSET.OSC32KRDY is one. Writing a zero to this bit has no effect. Writing a one to this bit clears the OSC32K Ready interrupt flag. z Bit 1 – XOSC32KRDY: XOSC32K Ready This flag is cleared by writing a one to it. This flag is set on a zero-to-one transition of the XOSC32K Ready bit in the Status register (PCLKSR.XOSC32KRDY) and will generate an interrupt request if INTENSET.XOSC32KRDY is one. Writing a zero to this bit has no effect. Writing a one to this bit clears the XOSC32K Ready interrupt flag. z Bit 0 – XOSCRDY: XOSC Ready This flag is cleared by writing a one to it. This flag is set on a zero-to-one transition of the XOSC Ready bit in the Status register (PCLKSR.XOSCRDY) and will generate an interrupt request if INTENSET.XOSCRDY is one. Writing a zero to this bit has no effect. Writing a one to this bit clears the XOSC Ready interrupt flag. Atmel SAM D20 [Preliminary DATASHEET] 42129A‚ÄìSAM‚Äì06/2013 156 17.8.4 Power and Clocks Status Name: PCLKSR Offset: 0x0C Reset: 0x00000000 Property: - Bit 31 30 29 28 27 26 25 24 Access R R R R R R R R Reset 0 0 0 0 0 0 0 0 Bit 23 22 21 20 19 18 17 16 Access R R R R R R R R Reset 0 0 0 0 0 0 0 0 Bit 15 14 13 12 11 10 9 8 B12SRDY BOD12DET BOD12RDY B33SRDY BOD33DET BOD33RDY DFLLRCS Access R R R R R R R R Reset 0 0 0 0 0 0 0 0 Bit 7 6 5 4 3 2 1 0 DFLLLCKC DFLLLCKF DFLLOOB DFLLRDY OSC8MRDY OSC32KRDY XOSC32KRDY XOSCRDY Access R R R R R R R R Reset 0 0 0 0 0 0 0 0 z Bits 31:15 – 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. These bits will always return zero when read. z Bit 14 – B12SRDY: BOD12 Synchronization Ready 0: BOD12 synchronization is ongoing. 1: BOD12 synchronization is complete. z Bit 13 – BOD12DET: BOD12 Detection 0: No BOD12 detection. 1: BOD12 has detected that the core power supply is going below the BOD12 reference value. z Bit 12 – BOD12RDY: BOD12 Ready 0: BOD12 is not ready. 1: BOD12 is ready. z Bit 11 – B33SRDY: BOD33 Synchronization Ready 0: BOD33 synchronization is ongoing. 1: BOD33 synchronization is complete. Atmel SAM D20 [Preliminary DATASHEET] 42129A‚ÄìSAM‚Äì06/2013 157 z Bit 10 – BOD33DET: BOD33 Detection 0: No BOD33 detection. 1: BOD33 has detected that the I/O power supply is going below the BOD33 reference value. z Bit 9 – BOD33RDY: BOD33 Ready 0: BOD33 is not ready. 1: BOD33 is ready. z Bit 8 – DFLLRCS: DFLL Reference Clock Stopped 0: DFLL reference clock is running. 1: DFLL reference clock has stopped. z Bit 7 – DFLLLCKC: DFLL Lock Coarse 0: No DFLL coarse lock detected. 1: DFLL coarse lock detected. z Bit 6 – DFLLLCKF: DFLL Lock Fine 0: No DFLL fine lock detected. 1: DFLL fine lock detected. z Bit 5 – DFLLOOB: DFLL Out Of Bounds 0: No DFLL Out Of Bounds detected. 1: DFLL Out Of Bounds detected. z Bit 4 – DFLLRDY: DFLL Ready 0: DFLL is not ready. 1: DFLL is stable and ready to be used as a clock source. z Bit 3 – OSC8MRDY: OSC8M Ready 0: OSC8M is not ready. 1: OSC8M is stable and ready to be used as a clock source. z Bit 2 – OSC32KRDY: OSC32K Ready 0: OSC32K is not ready. 1: OSC32K is stable and ready to be used as a clock source. z Bit 1 – XOSC32KRDY: XOSC32K Ready 0: XOSC32K is not ready. 1: XOSC32K is stable and ready to be used as a clock source. z Bit 0 – XOSCRDY: XOSC Ready 0: XOSC is not ready. 1: XOSC is stable and ready to be used as a clock source. Atmel SAM D20 [Preliminary DATASHEET] 42129A‚ÄìSAM‚Äì06/2013 158 17.8.5 External Multipurpose Crystal Oscillator (XOSC) Control Name: XOSC Offset: 0x10 Reset: 0x0080 Property: Write-Protected Bit 15 14 13 12 STARTUP[3:0] Access 11 10 AMPGC 9 8 GAIN[2:0] R/W R/W R/W R/W R/W R/W R/W R/W Reset 0 0 0 0 0 0 0 0 Bit 7 6 5 4 3 2 1 0 ONDEMAND RUNSTDBY XTALEN ENABLE R/W R/W R R R R/W R/W R 1 0 0 0 0 0 0 0 Access Reset z Bits 15:12 – STARTUP[3:0]: Start-Up Time These bits select start-up time for the oscillator according to Table 17-2. The OSCULP32K oscillator is used to clock the start-up counter. Table 17-2. Start-UpTime for External Multipurpose Crystal Oscillator STARTUP[3:0] Number of OSCULP32K Clock Cycles Approximate Equivalent Time 0x0 1 32µs 0x1 2 64µs 0x2 4 128µs 0x3 8 256µ 0x4 16 512µs 0x5 32 1ms 0x6 64 2ms 0x7 128 4ms 0x8 256 8ms 0x9 512 16ms 0xA 1024 32ms 0xB 2048 64ms 0xC 4096 128ms 0xD 8192 256ms 0xE 16384 512ms 0xF 32768 1s Atmel SAM D20 [Preliminary DATASHEET] 42129A‚ÄìSAM‚Äì06/2013 159 z Bit 11 – AMPGC: Automatic Amplitude Gain Control 0: The automatic amplitude gain control is disabled. 1: The automatic amplitude gain control is enabled. Amplitude gain will be automatically adjusted during Crystal Oscillator operation. z Bits 10:8 – GAIN[2:0]: Oscillator Gain These bits select the gain for the oscillator, given in table Table 17-3. The listed maximum frequencies are recommendations, and might vary based on capacitive load and crystal characteristics. Setting this bit group has no effect when the Automatic Amplitude Gain Control is active. Table 17-3. External Multipurpose Crystal Oscillator Gain Settings GAIN[2:0] Recommended Max Frequency 0x0 2MHz 0x1 4MHz 0x2 8MHz 0x3 16MHz 0x4 30MHz 0x5-0x7 Reserved z Bit 7 – ONDEMAND: On Demand Control The On Demand operation mode allows an oscillator to be enabled or disabled, depending on peripheral clock requests. In On Demand operation mode, i.e., if the XOSC.ONDEMAND bit has been previously written to one, the oscillator will be running only when requested by a peripheral. If there is no peripheral requesting the oscillator’s clock source, the oscillator will be in a disabled state. If On Demand is disabled, the oscillator will always be running when enabled. In standby sleep mode, the On Demand operation is still active if the XOSC.RUNSTDBY bit is one. If XOSC.RUNSTDBY is zero, the oscillator is disabled. 0: The oscillator is always on, if enabled. 1: The oscillator is enabled when a peripheral is requesting the oscillator to be used as a clock source. The oscillator is disabled if no peripheral is requesting the clock source. z Bit 6 – RUNSTDBY: Run in Standby This bit controls how the XOSC behaves during standby sleep mode: 0: The oscillator is disabled in standby sleep mode. 1: The oscillator is not stopped in standby sleep mode. If XOSC.ONDEMAND is one, the clock source will be running when a peripheral is requesting the clock. If XOSC.ONDEMAND is zero, the clock source will always be running in standby sleep mode. z Bits 5:3 – 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. These bits will always return zero when read. z Bit 2 – XTALEN: Crystal Oscillator Enable This bit controls the connections between the I/O pads and the external clock or crystal oscillator: 0: External clock connected on XIN. XOUT can be used as general-purpose I/O. 1: Crystal connected to XIN/XOUT. Atmel SAM D20 [Preliminary DATASHEET] 42129A‚ÄìSAM‚Äì06/2013 160 z Bit 1 – ENABLE: Oscillator Enable 0: The oscillator is disabled. 1: The oscillator is enabled. z 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. This bit will always return zero when read. Atmel SAM D20 [Preliminary DATASHEET] 42129A‚ÄìSAM‚Äì06/2013 161 17.8.6 32kHz External Crystal Oscillator (XOSC32K) Control Name: XOSC32K Offset: 0x14 Reset: 0x0080 Property: Write-Protected Bit 15 14 13 12 11 10 WRTLOCK 9 8 STARTUP[2:0] Access R R R R R R/W R/W R/W Reset 0 0 0 0 0 0 0 0 Bit 7 6 5 4 3 2 1 0 ONDEMAND RUNSTDBY AAMPEN EN1K EN32K XTALEN ENABLE R/W R/W R/W R/W R/W R/W R/W R 1 0 0 0 0 0 0 0 Access Reset z Bits 15:13 – 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. These bits will always return zero when read. z Bit 12 – WRTLOCK: Write Lock 0: The generic clock and the associated generic clock generator and division factor using the XOSC32K as a clock source are not locked. 1: The generic clock and the associated generic clock generator and division factor using the XOSC32K as a clock source are locked. Refer to “GCLK – Generic Clock Controller” on page 83 for details. z Bit 11 – 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. This bit will always return zero when read. z Bits 10:8 – STARTUP[2:0]: Oscillator Start-Up Time These bits select the start-up time for the oscillator according to Table 17-4 The OSCULP32K oscillator is used to clock the start-up counter. Table 17-4. Start-Up Time for 32kHz External Crystal Oscillator STARTUP[2:0] Number of OSCULP32K Clock Cycles Approximate Equivalent Time (OSCULP = 32kHz) 0x0 1 32us 0x1 2 64us 0x2 4 128us 0x3 8 256us 0x4 16 512us 0x5 32 1ms 0x6 64 2ms 0x7 128 4ms Atmel SAM D20 [Preliminary DATASHEET] 42129A‚ÄìSAM‚Äì06/2013 162 z Bit 7 – ONDEMAND: On Demand Control The On Demand operation mode allows an oscillator to be enabled or disabled depending on peripheral clock requests. In On Demand operation mode, i.e., if the ONDEMAND bit has been previously written to one, the oscillator will only be running when requested by a peripheral. If there is no peripheral requesting the oscillator’s clock source, the oscillator will be in a disabled state. If On Demand is disabled the oscillator will always be running when enabled. In standby sleep mode, the On Demand operation is still active if the XOSC32K.RUNSTDBY bit is one. If XOSC32K.RUNSTDBY is zero, the oscillator is disabled. 0: The oscillator is always on, if enabled. 1: The oscillator is enabled when a peripheral is requesting the oscillator to be used as a clock source. The oscillator is disabled if no peripheral is requesting the clock source. z Bit 6 – RUNSTDBY: Run in Standby This bit controls how the XOSC32K behaves during standby sleep mode: 0: The oscillator is disabled in standby sleep mode. 1: The oscillator is not stopped in standby sleep mode. If XOSC32K.ONDEMAND is one, the clock source will be running when a peripheral is requesting the clock. If XOSC32K.ONDEMAND is zero, the clock source will always be running in standby sleep mode. z Bit 5 – AAMPEN: Automatic Amplitude Control Enable 0: The automatic amplitude control for the crystal oscillator is disabled. 1: The automatic amplitude control for the crystal oscillator is enabled. z Bit 4 – EN1K: 1kHz Output Enable 0: The 1kHz output is disabled. 1: The 1kHz output is enabled. z Bit 3 – EN32K: 32kHz Output Enable 0: The 32kHz output is disabled. 1: The 32kHz output is enabled. z Bit 2 – XTALEN: Crystal Oscillator Enable This bit controls the connections between the I/O pads and the external clock or crystal oscillator: 0: External clock connected on XIN32. XOUT32 can be used as general-purpose I/O. 1: Crystal connected to XIN32/XOUT32. z Bit 1 – ENABLE: Oscillator Enable 0: The oscillator is disabled. 1: The oscillator is enabled. z 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. This bit will always return zero when read. Atmel SAM D20 [Preliminary DATASHEET] 42129A‚ÄìSAM‚Äì06/2013 163 17.8.7 32kHz Internal Oscillator (OSC32K) Control Name: OSC32K Offset: 0x18 Reset: 0x00000080 Property: Write-Protected Bit 31 30 29 28 27 26 25 24 Access R R R R R R R R Reset 0 0 0 0 0 0 0 0 Bit 23 22 21 20 19 18 17 16 CALIB[6:0] Access R R/W R/W R/W R/W R/W R/W R/W Reset 0 0 0 0 0 0 0 0 Bit 15 14 13 12 11 10 9 8 WRTLOCK STARTUP[2:0] Access R R R R R R/W R/W R/W Reset 0 0 0 0 0 0 0 0 Bit 7 6 5 4 3 2 1 0 ONDEMAND RUNSTDBY EN1K EN32K ENABLE R/W R/W R R R/W R/W R/W R 1 0 0 0 0 0 0 0 Access Reset z Bits 31:23 – 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. These bits will always return zero when read. z Bits 22:16 – CALIB[6:0]: Oscillator Calibration These bits control the oscillator calibration. This value must be written by the user. Factory calibration values can be loaded from the non-volatile memory. Refer to “Non-Volatile Memory (NVM) User Row Mapping” on page 25. z Bits 15:13 – 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. These bits will always return zero when read. z Bit 12 – WRTLOCK: Write Lock 0: The generic clock and the associated generic clock generator and division factor using the OSC32K as clock source are not locked. 1: The generic clock and the associated generic clock generator and division factor using the OSC32K as clock source are locked. Refer to “GCLK – Generic Clock Controller” on page 83 for details. Atmel SAM D20 [Preliminary DATASHEET] 42129A‚ÄìSAM‚Äì06/2013 164 z Bit 11 – 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. This bit will always return zero when read. z Bits 10:8 – STARTUP[2:0]: Oscillator Start-Up Time These bits select start-up time for the oscillator according to Table 17-5. The OSCULP32K oscillator is used as input clock to the startup counter. Table 17-5. Start-Up Time for 32kHz Internal Oscillator STARTUP[2:0] Number of OSCULP32K clock cycles Approximate Equivalent Time (OSCULP= 32 kHz) 0x0 0 0 0x1 32 1ms 0x2 2048 64ms 0x3 4096 128ms 0x4 16384 512ms 0x5 32768 1s 0x6 65536 2s 0x7 131072 4s z Bit 7 – ONDEMAND: On Demand Control The On Demand operation mode allows an oscillator to be enabled or disabled depending on peripheral clock requests. In On Demand operation mode, i.e., if the ONDEMAND bit has been previously written to one, the oscillator will only be running when requested by a peripheral. If there is no peripheral requesting the oscillator’s clock source, the oscillator will be in a disabled state. If On Demand is disabled the oscillator will always be running when enabled. In standby sleep mode, the On Demand operation is still active if the OSC32K.RUNSTDBY bit is one. If OSC32K.RUNSTDBY is zero, the oscillator is disabled. 0: The oscillator is always on, if enabled. 1: The oscillator is enabled when a peripheral is requesting the oscillator to be used as a clock source. The oscillator is disabled if no peripheral is requesting the clock source. z Bit 6 – RUNSTDBY: Run in Standby This bit controls how the OSC32K behaves during standby sleep mode: 0: The oscillator is disabled in standby sleep mode. 1: The oscillator is not stopped in standby sleep mode. If OSC32K.ONDEMAND is one, the clock source will be running when a peripheral is requesting the clock. If OSC32K.ONDEMAND is zero, the clock source will always be running in standby sleep mode. z Bits 5:4 – 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. These bits will always return zero when read. z Bit 3 – EN1K: 1kHz Output Enable 0: The 1kHz output is disabled. 1: The 1kHz output is enabled. Atmel SAM D20 [Preliminary DATASHEET] 42129A‚ÄìSAM‚Äì06/2013 165 z Bit 2 – EN32K: 32kHz Output Enable 0: The 32kHz output is disabled. 1: The 32kHz output is enabled. z Bit 1 – ENABLE: Oscillator Enable 0: The oscillator is disabled. 1: The oscillator is enabled. z 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. This bit will always return zero when read. Atmel SAM D20 [Preliminary DATASHEET] 42129A‚ÄìSAM‚Äì06/2013 166 17.8.8 32kHz Ultra Low Power Internal Oscillator (OSCULP32K) Control Name: OSCULP32K Offset: 0x1C Reset: 0xXX Property: Write-Protected Bit 7 6 5 4 3 WRTLOCK 2 1 0 CALIB[4:0] Access R R R R/W R/W R/W R/W R/W Reset 0 0 0 X X X X X z Bit 7 – WRTLOCK: Write Lock 0: The generic clock and the associated generic clock generator and division factor using the OSCULP32K as clock source are not locked. 1: The generic clock and the associated generic clock generator and division factor using the OSCULP32K as clock source are locked. Refer to “GCLK – Generic Clock Controller” on page 83 for details. z Bits 6: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. These bits will always return zero when read. z Bits 4:0 – CALIB[4:0]: Oscillator Calibration These bits control the oscillator calibration. These bits are loaded from Flash Calibration at startup. Atmel SAM D20 [Preliminary DATASHEET] 42129A‚ÄìSAM‚Äì06/2013 167 17.8.9 8MHz Internal Oscillator (OSC8M) Control Name: OSC8M Offset: 0x20 Reset: 0x0XXX0082 Property: Write-Protected Bit 31 30 29 28 27 26 FRANGE[1:0] Access 25 24 CALIB[11:8] R/W R/W R R R/W R/W R/W R/W Reset 0 0 0 0 X X X X Bit 23 22 21 20 19 18 17 16 CALIB[7:0] Access R/W R/W R/W R/W R/W R/W R/W R/W Reset X X X X X X X x Bit 15 14 13 12 11 10 9 8 PRESC[1:0] Access R R R R R R R/W R/W Reset 0 0 0 0 0 0 0 0 Bit 7 6 5 4 3 2 1 0 ONDEMAND RUNSTDBY R/W R/W R R R R R/W R 1 0 0 0 0 0 1 0 Access Reset z ENABLE Bits 31:30 – FRANGE[1:0]: Oscillator Frequency Range These bits control the oscillator frequency range according to Table 17-6. Table 17-6. Oscillator Frequency Range FRANGE[1:0] Description 0x0 4 to 6MHz 0x1 6 to 8MHz 0x2 8 to 11MHz 0x3 11 to 15MHz z Bits 29:28 – 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. These bits will always return zero when read. z Bits 27:16 – CALIB[11:0]: Oscillator Calibration These bits control the oscillator calibration. The calibration field is split in two: Atmel SAM D20 [Preliminary DATASHEET] 42129A‚ÄìSAM‚Äì06/2013 168 CALIB[11:7] is for temperature calibration CALIB[6:0] is for overall process calibration These bits are loaded from Flash Calibration at startup. z Bits 15:10 – 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. These bits will always return zero when read. z Bits 9:8 – PRESC[1:0]: Oscillator Prescaler These bits select the oscillator prescaler factor setting according to the Table 17-7 table. Table 17-7. Oscillator Prescaler PRESC[1:0] Description 0x0 1 0x1 2 0x2 4 0x3 8 z Bit 7 – ONDEMAND: On Demand Control The On Demand operation mode allows an oscillator to be enabled or disabled depending on peripheral clock requests. In On Demand operation mode, i.e., if the ONDEMAND bit has been previously written to one, the oscillator will only be running when requested by a peripheral. If there is no peripheral requesting the oscillator’s clock source, the oscillator will be in a disabled state. If On Demand is disabled the oscillator will always be running when enabled. In standby sleep mode, the On Demand operation is still active if the OSC8M.RUNSTDBY bit is one. If OSC8M.RUNSTDBY is zero, the oscillator is disabled. 0: The oscillator is always on, if enabled. 1: The oscillator is enabled when a peripheral is requesting the oscillator to be used as a clock source. The oscillator is disabled if no peripheral is requesting the clock source. z Bit 6 – RUNSTDBY: Run in Standby This bit controls how the OSC8M behaves during standby sleep mode: 0: The oscillator is disabled in standby sleep mode. 1: The oscillator is not stopped in standby sleep mode. If OSC8M.ONDEMAND is one, the clock source will be running when a peripheral is requesting the clock. If OSC8M.ONDEMAND is zero, the clock source will always be running in standby sleep mode. z Bits 5: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. These bits will always return zero when read. z Bit 1 – ENABLE: Oscillator Enable 0: The oscillator is disabled. 1: The oscillator is enabled. z 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. This bit will always return zero when read. Atmel SAM D20 [Preliminary DATASHEET] 42129A‚ÄìSAM‚Äì06/2013 169 17.8.10 DFLL48M Control Name: DFLLCTRL Offset: 0x24 Reset: 0x0080 Property: Write-Protected Bit 15 14 13 12 11 10 9 8 QLDIS CCDIS Access R R R R R R R/W R/W Reset 0 0 0 0 0 0 0 0 Bit 7 6 5 4 3 2 1 0 ONDEMAND RUNSTDBY LLAW STABLE MODE ENABLE R/W R/W R R/W R/W R/W R/W R 1 0 0 0 0 0 0 0 Access Reset z Bits 15:10 – 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. These bits will always return zero when read. z Bit 9 – QLDIS: Quick Lock Disable 0: Quick Lock is enabled. 1: Quick Lock is disabled. z Bit 8 – CCDIS: Chill Cycle Disable 0: Chill Cycle is enabled. 1: Chill Cycle is disabled. z Bit 7 – ONDEMAND: On Demand Control The On Demand operation mode allows an oscillator to be enabled or disabled depending on peripheral clock requests. In On Demand operation mode, i.e., if the ONDEMAND bit has been previously written to one, the oscillator will only be running when requested by a peripheral. If there is no peripheral requesting the oscillator’s clock source, the oscillator will be in a disabled state. If On Demand is disabled the oscillator will always be running when enabled. In standby sleep mode, the On Demand operation is still active if the DFLLCTRL.RUNSTDBY bit is one. If DFLLCTRL.RUNSTDBY is zero, the oscillator is disabled. 0: The oscillator is always on, if enabled. 1: The oscillator is enabled when a peripheral is requesting the oscillator to be used as a clock source. The oscillator is disabled if no peripheral is requesting the clock source. z Bit 6 – RUNSTDBY: Run in Standby This bit controls how the DFLL behaves during standby sleep mode: 0: The oscillator is disabled in standby sleep mode. 1: The oscillator is not stopped in standby sleep mode. If DFLLCTRL.ONDEMAND is one, the clock source will be running when a peripheral is requesting the clock. If DFLLCTRL.ONDEMAND is zero, the clock source will always be running in standby sleep mode. Atmel SAM D20 [Preliminary DATASHEET] 42129A‚ÄìSAM‚Äì06/2013 170 z 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. This bit will always return zero when read. z Bit 4 – LLAW: Lose Lock After Wake 0: Locks will not be lost after waking up from sleep modes if the DFLL clock has been stopped. 1: Locks will be lost after waking up from sleep modes if the DFLL clock has been stopped. z Bit 3 – STABLE: Stable DFLL Frequency 0: FINE calibration tracks changes in output frequency. 1: FINE calibration register value will be fixed after a fine lock. z Bit 2 – MODE: Operating Mode Selection 0: The DFLL operates in open-loop operation. 1: The DFLL operates in closed-loop operation. z Bit 1 – ENABLE: DFLL Enable 0: The DFLL oscillator is disabled. 1: The DFLL oscillator is enabled. Due to synchronization, there is delay from updating the register until the peripheral is enabled/disabled. The value written to DFLLCTRL.ENABLE will read back immediately after written. z 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. This bit will always return zero when read. Atmel SAM D20 [Preliminary DATASHEET] 42129A‚ÄìSAM‚Äì06/2013 171 17.8.11 DFLL48M Value Name: DFLLVAL Offset: 0x28 Reset: 0x00000000 Property: Write-Protected Bit 31 30 29 28 27 26 25 24 DIFF[15:8] Access R/W R/W R/W R/W R/W R/W R/W R/W Reset 0 0 0 0 0 0 0 0 Bit 23 22 21 20 19 18 17 16 DIFF[7:0] Access R/W R/W R/W R/W R/W R/W R/W R/W Reset 0 0 0 0 0 0 0 0 Bit 15 14 13 12 11 10 9 8 COARSE[4:0] Access R R R R/W R/W R/W R/W R/W Reset 0 0 0 0 0 0 0 0 Bit 7 6 5 4 3 2 1 0 FINE[7:0] Access Reset R/W R/W R/W R/W R/W R/W R/W R/W 0 0 0 0 0 0 0 0 z Bits 31:16 – DIFF: Multiplication Ratio Difference In closed-loop mode (DFLLCTRL.MODE is written to one), this bit group indicates the difference between the ideal number of DFLL cycles and the counted number of cycles. This value is not updated in open-loop mode, and should be considered invalid in that case. z Bits 15:13 – 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. These bits will always return zero when read. z Bits 12:8 – COARSE: Coarse Value Set the value of the Coarse Calibration register. In closed-loop mode, this field is read-only. z Bits 7:0 – FINE: Fine Value Set the value of the Fine Calibration register. In closed-loop mode, this field is read-only. Atmel SAM D20 [Preliminary DATASHEET] 42129A‚ÄìSAM‚Äì06/2013 172 17.8.12 DFLL48M Multiplier Name: DFLLMUL Offset: 0x2C Reset: 0x00000000 Property: Write-Protected Bit 31 30 29 28 27 26 25 24 CSTEP[4:0] Access R R R R/W R/W R/W R/W R/W Reset 0 0 0 0 0 0 0 0 Bit 23 22 21 20 19 18 17 16 FSTEP[7:0] Access R/W R/W R/W R/W R/W R/W R/W R/W Reset 0 0 0 0 0 0 0 0 Bit 15 14 13 12 11 10 9 8 MUL[15:8] Access R/W R/W R/W R/W R/W R/W R/W R/W Reset 0 0 0 0 0 0 0 0 Bit 7 6 5 4 3 2 1 0 MUL[7:0] Access Reset R/W R/W R/W R/W R/W R/W R/W R/W 0 0 0 0 0 0 0 0 z Bits 31:29 – 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. These bits will always return zero when read. z Bits 28:24 – CSTEP: Coarse Maximum Step This bit group indicates the maximum step size allowed during coarse adjustment in closed-loop mode. When adjusting to a new frequency, the expected output frequency overshoot depends on this step size. z Bits 23:16 – FSTEP: Fine Maximum Step This bit group indicates the maximum step size allowed during fine adjustment in closed-loop mode. When adjusting to a new frequency, the expected output frequency overshoot depends on this step size. z Bits 15:0 – MUL: DFLL Multiply Factor This field determines the ratio of the CLK_DFLL output frequency to the CLK_DFLL_REF input frequency. Writing to the MUL register will cause locks to be lost and the fine calibration value to be reset to its midpoint. Atmel SAM D20 [Preliminary DATASHEET] 42129A‚ÄìSAM‚Äì06/2013 173 17.8.13 DFLL48M Synchronization Name: DFLLSYNC Offset: 0x30 Reset: 0x00 Property: Write-Protected Bit 7 6 5 4 3 2 1 0 READREQ Access W R R R R R R R Reset 0 0 0 0 0 0 0 0 z Bit 7 – READREQ: Read Request To be able to read the current value of DFLLVAL in closed-loop mode, this bit should be written to one. The updated value is available in DFLLVAL when PCLKSR.DFLLRDY is set. z Bits 6:0 – 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. These bits will always return zero when read. Atmel SAM D20 [Preliminary DATASHEET] 42129A‚ÄìSAM‚Äì06/2013 174 17.8.14 3.3V Brown-Out Detector (BOD33) Control Name: BOD33 Offset: 0x34 Reset: 0x00XX00XX Property: Synchronized, Write-Protected Bit 31 30 29 28 27 26 25 24 Access R R R R R R R R Reset 0 0 0 0 0 0 0 0 Bit 23 22 21 20 19 18 17 16 LEVEL[5:0] Access R R R/W R/W R/W R/W R/W R/W Reset 0 0 X X X X X X Bit 15 14 13 12 11 10 9 8 CEN MODE PSEL[3:0] Access R/W R/W R/W R/W R R R/W R/W Reset 0 0 0 0 0 0 0 0 Bit 7 6 5 4 3 2 1 0 HYST ENABLE RUNSTDBY ACTION[1:0] Access R R/W R R/W R/W R/W R/W R Reset 0 0 0 X X 0 X 0 z Bits 31:22 – 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. These bits will always return zero when read. z Bits 21:16 – LEVEL[5:0]: BOD33 Threshold Level This field sets the triggering voltage threshold for the BOD33. Note that any change to the LEVEL field of the BOD33 register should be done when the BOD33 is disabled in order to avoid spurious resets or interrupts. These bits are loaded from Flash User Row at startup. Refer to “Non-Volatile Memory (NVM) User Row Mapping” on page 25 for more details. z Bits 15:12 – PSEL[3:0]: Prescaler Select Selects the prescaler divide-by output for the BOD33 sampling mode, as given in Table 17-8. The input clock comes from the OSCULP32K 1kHz output. Atmel SAM D20 [Preliminary DATASHEET] 42129A‚ÄìSAM‚Äì06/2013 175 Table 17-8. BOD33 Prescaler Select PSEL[3:0] Name Description 0x0 DIV2 Divide clock by 2 0x1 DIV4 Divide clock by 4 0x2 DIV8 Divide clock by 8 0x3 DIV16 Divide clock by 16 0x4 DIV32 Divide clock by 32 0x5 DIV64 Divide clock by 64 0x6 DIV128 Divide clock by 128 0x7 DIV256 Divide clock by 256 0x8 DIV512 Divide clock by 512 0x9 DIV1K Divide clock by 1024 0xA DIV2K Divide clock by 2048 0xB DIV4K Divide clock by 4096 0xC DIV8K Divide clock by 8192 0xD DIV16K Divide clock by 16384 0xE DIV32K Divide clock by 32768 0xF DIV64K Divide clock by 65536 z Bits 11:10 – 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. These bits will always return zero when read. z Bit 9 – CEN: Clock Enable 0: The BOD33 sampling clock is either disabled and stopped, or enabled but not yet stable. 1: The BOD33 sampling clock is either enabled and stable, or disabled but not yet stopped. Writing a zero to this bit will stop the BOD33 sampling clock. Writing a one to this bit will start the BOD33 sampling clock. z Bit 8 – MODE: Operation Mode 0: The BOD33 operates in continuous mode. 1: The BOD33 operates in sampling mode. z 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. This bit will always return zero when read. z Bit 6 – RUNSTDBY: Run in Standby 0: The BOD33 is disabled in standby sleep mode. 1: The BOD33 is enabled in standby sleep mode. z 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. This bit will always return zero when read. Atmel SAM D20 [Preliminary DATASHEET] 42129A‚ÄìSAM‚Äì06/2013 176 z Bits 4:3 – ACTION: BOD33 Action These bits are used to select the BOD33 action when the supply voltage crosses below the BOD33 threshold, as shown in Table 17-9. These bits are loaded from Flash User Row at startup. Refer to “Non-Volatile Memory (NVM) User Row Mapping” on page 25 for more details. Table 17-9. BOD33 Action ACTION[1:0] Name Description 0x0 NONE No action 0x1 RESET The BOD33 generates a reset 0x2 INTERRUPT The BOD33 generates an interrupt 0x3 - Reserved z Bit 2 – HYST: Hysteresis This bit indicates whether hysteresis is enabled for the BOD33 threshold voltage: 0: No hysteresis. 1: Hysteresis enabled. z Bit 1 – ENABLE: Enable 0: BOD33 is disabled. 1: BOD33 is enabled. This bit is loaded from Flash User Row at startup. Refer to “Non-Volatile Memory (NVM) User Row Mapping” on page 25 for more details. z 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. This bit will always return zero when read. Atmel SAM D20 [Preliminary DATASHEET] 42129A‚ÄìSAM‚Äì06/2013 177 17.8.15 1.2V Brown-Out Detector (BOD12) Control Name: BOD12 Offset: 0x38 Reset: 0x00XX00XX Property: Synchronized, Write-Protected Bit 31 30 29 28 27 26 25 24 Access R R R R R R R R Reset 0 0 0 0 0 0 0 0 Bit 23 22 21 20 19 18 17 16 LEVEL[4:0] Access R R R R/W R/W R/W R/W R/W Reset 0 0 0 X X X X X 15 14 13 12 11 10 9 8 CEN MODE Bit PSEL[3:0] Access R/W R/W R/W R/W R R R/W R/W Reset 0 0 0 0 0 0 0 0 Bit 7 6 5 4 3 2 1 0 HYST ENABLE RUNSTDBY ACTION[1:0] Access R R/W R R/W R/W R/W R/W R Reset 0 0 0 X X 0 X 0 z Bits 31:21 – 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. These bits will always return zero when read. z Bits 20:16 – LEVEL[4:0]: BOD12 Threshold Level This field sets the triggering voltage threshold for the BOD12. Note that any change to the LEVEL field of the BOD12 register should be done when the BOD12 is disabled in order to avoid spurious resets or interrupts. These bits are loaded from Flash User Row at startup. Refer to “Non-Volatile Memory (NVM) User Row Mapping” on page 25 for more details. z Bits 15:12 – PSEL[3:0]: Prescaler Select Selects the prescaler divide-by output for the BOD12 Sampling mode, as given in Table 17-10. The input clock comes from the OSCULP32K 1kHz output. Atmel SAM D20 [Preliminary DATASHEET] 42129A‚ÄìSAM‚Äì06/2013 178 Table 17-10. BOD12 Prescaler Select PSEL[3:0] Name Description 0x0 DIV2 Divide clock by 2 0x1 DIV4 Divide clock by 4 0x2 DIV8 Divide clock by 8 0x3 DIV16 Divide clock by 16 0x4 DIV32 Divide clock by 32 0x5 DIV64 Divide clock by 64 0x6 DIV128 Divide clock by 128 0x7 DIV256 Divide clock by 256 0x8 DIV512 Divide clock by 512 0x9 DIV1K Divide clock by 1024 0xA DIV2K Divide clock by 2048 0xB DIV4K Divide clock by 4096 0xC DIV8K Divide clock by 8192 0xD DIV16K Divide clock by 16384 0xE DIV32K Divide clock by 32768 0xF DIV64K Divide clock by 65536 z Bits 11:10 – 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. These bits will always return zero when read. z Bit 9 – CEN: Clock Enable 0: The BOD12 sampling clock is either disabled and stopped, or enabled but not yet stable. 1: The BOD12 sampling clock is either enabled and stable, or disabled but not yet stopped. Writing a zero to this bit will stop the BOD12 sampling clock. Writing a one to this bit will start the BOD12 sampling clock. z Bit 8 – MODE: Operation mode 0: The BOD12 operates in continuous mode. 1: The BOD12 operates in sampling mode. z 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. This bit will always return zero when read. z Bit 6 – RUNSTDBY: Run in Standby 0: The BOD12 is disabled in standby sleep mode. 1: The BOD12 is enabled in standby sleep mode. z 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. This bit will always return zero when read. Atmel SAM D20 [Preliminary DATASHEET] 42129A‚ÄìSAM‚Äì06/2013 179 z Bits 4:3 – ACTION: BOD12 Action These bits are used to select the BOD12 action when the supply voltage crosses below the BOD12 threshold, as shown in Table 17-11. These bits are loaded from Flash User Row at startup. Refer to “Non-Volatile Memory (NVM) User Row Mapping” on page 25 for more details. Table 17-11. BOD12 Action ACTION[1:0] Name Description 0x0 NONE No action 0x1 RESET The BOD12 generates a reset 0x2 INTERRUPT The BOD12 generates an interrupt 0x3 - Reserved z Bit 2 – HYST: Hysteresis This bit indicates whether hysteresis is enabled for the BOD12 threshold voltage: 0: No hysteresis. 1: Hysteresis enabled. z Bit 1 – ENABLE: Enable 0: BOD12 is disabled. 1: BOD12 is enabled. This bit is loaded from Flash User Row at startup. Refer to “Non-Volatile Memory (NVM) User Row Mapping” on page 25 for more details. z 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. This bit will always return zero when read. Atmel SAM D20 [Preliminary DATASHEET] 42129A‚ÄìSAM‚Äì06/2013 180 17.8.16 Voltage Regulator System (VREG) Control Name: VREG Offset: 0x3C Reset: 0x0X02 Property: Write protected Bit 15 14 13 12 11 10 CALIB[2:0] 9 8 LEVEL[2:0] Access R R/W R/W R/W R R/W R/W R/W Reset 0 0 0 0 0 X X X Bit 7 6 5 4 3 2 1 0 RUNSTDBY ENABLE Access R R/W R R R R R/W R Reset 0 0 0 0 0 0 1 0 z Bit 15 – 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. This bit will always return zero when read. z Bits 14:12 – CALIB[2:0]: Voltage Regulator Calibration These bits are used for voltage regulator calibration. z Bit 11 – 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. This bit will always return zero when read. z Bits 10:8 – LEVEL[2:0]: Voltage Regulator Level These bits are used to set the voltage level of the regulator. These bits are loaded from Flash Calibration Row at startup. Refer to “Non-Volatile Memory (NVM) User Row Mapping” on page 25 for more details z 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. This bit will always return zero when read. z Bit 6 – RUNSTDBY: Run in Standby 0: The voltage regulator is in low-power configuration in standby sleep mode. 1: The voltage regulator is not in low-power configuration in standby sleep mode. z Bits 5: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. These bits will always return zero when read. z Bit 1 – ENABLE: Enable 0: The voltage regulator is disabled. 1: The voltage regulator is enabled. z 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. This bit will always return zero when read. Atmel SAM D20 [Preliminary DATASHEET] 42129A‚ÄìSAM‚Äì06/2013 181 17.8.17 Voltage References System (VREF) Control Name: VREF Offset: 0x40 Reset: 0x0XXX0000 Property: Write-Protected Bit 31 30 29 28 27 26 25 24 CALIB[10:8] Access R R R R R R/W R/W R/W Reset 0 0 0 0 0 X X X 23 22 21 20 19 18 17 16 Bit CALIB[7:0] Access R/W R/W R/W R/W R/W R/W R/W R/W Reset X X X X X X X X Bit 15 14 13 12 11 10 9 8 Access R R R R R R R R Reset 0 0 0 0 0 0 0 0 Bit 7 6 5 4 3 2 1 0 BGOUTEN TSEN Access R R R R R R/W R/W R Reset 0 0 0 0 0 0 0 0 z Bits 31:27 – 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. These bits will always return zero when read. z Bits 26:16 – CALIB[10:0]: Bandgap Voltage Generator Calibration These bits are used to calibrate the output level of the bandgap voltage reference. These bits are loaded from Flash Calibration Row at startup. Refer to “Non-Volatile Memory (NVM) User Row Mapping” on page 25 for more details. z Bits 15:3 – 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. These bits will always return zero when read. z Bit 2 – BGOUTEN: Bandgap Output Enable 0: The bandgap output is not available as an ADC input channel. 1: The bandgap output is routed to an ADC input channel. z Bit 1 – TSEN: Temperature Sensor Enable 0: Temperature sensor is disabled. Atmel SAM D20 [Preliminary DATASHEET] 42129A‚ÄìSAM‚Äì06/2013 182 1: Temperature sensor is enabled and routed to an ADC input channel. z 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. This bit will always return zero when read. Atmel SAM D20 [Preliminary DATASHEET] 42129A‚ÄìSAM‚Äì06/2013 183 18. WDT – Watchdog Timer 18.1 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 configured to a predefined time-out period, and is constantly running when enabled. If the WDT is not cleared within the time-out period, it will issue a system reset. An early-warning interrupt is available to indicate an upcoming watchdog time-out condition. The window mode makes it possible to define a time slot (or window) inside the total time-out period during which the WDT must be cleared. If the WDT is cleared 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 the WDT to be cleared frequently. When enabled, the WDT will run in active mode and all sleep modes. It is asynchronous and runs from a CPUindependent clock source.The WDT will continue operation and issue a system reset or interrupt even if the main clocks fail. 18.2 Features z Issues a system reset if the Watchdog Timer is not cleared before its time-out period z Early Warning interrupt generation z Asynchronous operation from dedicated oscillator z Two types of operation: z z Normal mode Window mode z Selectable time-out periods, from 8 cycles to 16,000 cycles in normal mode or 16 cycles to 32,000 cycles in window mode z Always-on capability 18.3 Block Diagram Figure 18-1. WDT Block Diagram 0xA5 0 CLEAR GCLK_WDT COUNT PER/WINDOW/EWOFFSET Early Warning Interrupt Reset Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 184 18.4 Signal Description Not applicable. 18.5 Product Dependencies In order to use this peripheral, other parts of the system must be configured correctly, as described below. 18.5.1 I/O Lines Not applicable. 18.5.2 Power Management The WDT can continue to operate in any sleep mode where the selected source clock is running. The WDT interrupts can be used to wake up the device from sleep modes. The events can trigger other operations in the system without exiting sleep modes. Refer to “PM – Power Manager” on page 105 for details on the different sleep modes. 18.5.3 Clocks The WDT bus clock (CLK_WDT_APB) is enabled by default, and can be enabled and disabled in the Power Manager. Refer to “PM – Power Manager” on page 105 for details. A generic clock (GCLK_WDT) is required to clock the WDT. This clock must be configured and enabled in the Generic Clock Controller before using the WDT. Refer to “GCLK – Generic Clock Controller” on page 83 for details. This generic clock is asynchronous to the user interface clock (CLK_WDT_APB). Due to this asynchronicity, accessing certain registers will require synchronization between the clock domains. Refer to “Synchronization” on page 189 for further details. GCLK_WDT is intended to be sourced from the clock of the internal ultra-low-power (ULP) oscillator. Due to the ultralow-power design, the oscillator is not very accurate, and so the exact time-out period may vary from device to device. This variation must be kept in mind when designing software that uses the WDT to ensure that the time-out periods used are valid for all devices. GCLK_WDT can also be clocked from other sources if a more accurate clock is needed, but at the cost of higher power consumption. 18.5.4 DMA Not applicable. 18.5.5 Interrupts The interrupt request line is connected to the Interrupt Controller. Using the WDT interrupts requires the interrupt controller to be configured first. Refer to “Nested Vector Interrupt Controller” on page 28 for details. 18.5.6 Events Not applicable. 18.5.7 Debug Operation When the CPU is halted in debug mode, the WDT will halt normal operation. If the WDT is configured in a way that requires it to be periodically serviced by the CPU through interrupts or similar, improper operation or data loss may result during debugging. The WDT can be forced to halt operation during debugging. 18.5.8 Register Access Protection All registers with write-access are optionally write-protected by the peripheral access controller (PAC), except the following registers: Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 185 z Interrupt Flag Status and Clear register (INTFLAG) Write-protection is denoted by the Write-Protection property in the register description. When the CPU is halted in debug mode, all write-protection is automatically disabled. Write-protection does not apply for accesses through an external debugger. Refer to “PAC – Peripheral Access Controller” on page 31 for details. 18.5.9 Analog Connections Not applicable. 18.6 Functional Description 18.6.1 Principle of Operation The Watchdog Timer (WDT) is a system for monitoring correct program operation, making it possible to recover from error situations such as runaway code by issuing a reset. When enabled, the WDT is a constantly running timer that is configured to a predefined time-out period. Before the end of the time-out period, the WDT should be reconfigured. The WDT has two modes of operation, normal and window. Additionally, the user can enable Early Warning interrupt generation in each of the modes. The description for each of the basic modes is given below. The settings in the Control register (CTRL) and the Interrupt Enable register (INTENCLR/SET) determine the mode of operation, as illustrated in Table 18-1. Table 18-1. WDT Operating Modes ENABLE WEN Interrupt Enable 0 x x Stopped 1 0 0 Normal 1 0 1 Normal with Early Warning interrupt 1 1 0 Window 1 1 1 Window with Early Warning interrupt Mode 18.6.2 Basic Operation 18.6.2.1 Initialization The following registers are enable-protected: z Control register (CTRL), except the Enable bit (CTRL.ENABLE) z Configuration register (CONFIG) z Early Warning Interrupt Control register (EWCTRL) Any writes to these bits or registers when the WDT is enabled or is being enabled (CTRL.ENABLE is one) will be discarded. Writes to these registers while the WDT is being disabled will be completed after the disabling is complete. Enable-protection is denoted by the Enable-Protected property in the register description. Initialization of the WDT can be done only while the WDT is disabled. The WDT is configured by defining the required Time-Out Period bits in the Configuration register (CONFIG.PER). If window-mode operation is required, the Window Enable bit in the Control register (CTRL.WEN) must be written to one and the Window Period bits in the Configuration register (CONFIG.WINDOW) must be defined. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 186 18.6.2.2 Configurable Reset Values On a power-on reset, some registers will be loaded with initial values from the NVM User Row. Refer to “Non-Volatile Memory (NVM) User Row Mapping” on page 25 for more details. This encompasses the following bits and bit groups: z Enable bit in the Control register (CTRL.ENABLE) z Always-On bit in the Control register (CTRL.ALWAYSON) z Watchdog Timer Windows Mode Enable bit in the Control register (CTRL.WEN) z Watchdog Timer Windows Mode Time-Out Period bits in the Configuration register (CONFIG.WINDOW) z Time-Out Period in the Configuration register (CONFIG.PER) z Early Warning Interrupt Time Offset bits in the Early Warning Interrupt Control register (EWCTRL.EWOFFSET) For more information about fuse locations, see “Non-Volatile Memory (NVM) User Row Mapping” on page 25. 18.6.2.3 Enabling and Disabling The WDT is enabled by writing a one to the Enable bit in the Control register (CTRL.ENABLE). The WDT is disabled by writing a zero to CTRL.ENABLE. The WDT can be disabled only while the Always-On bit in the Control register (CTRL.ALWAYSON) is zero. 18.6.2.4 Normal Mode In normal-mode operation, the length of a time-out period is configured in CONFIG.PER. The WDT is enabled by writing a one to the Enable bit in the Control register (CTRL.ENABLE). Once enabled, if the WDT is not cleared from the application code before the time-out occurs, the WDT will issue a system reset. There are 12 possible WDT time-out (TOWDT) periods, selectable from 8ms to 16s, and the WDT can be cleared at any time during the time-out period. A new WDT time-out period will be started each time the WDT is cleared by writing 0xA5 to the Clear register (CLEAR). Writing any value other than 0xA5 to CLEAR will issue an immediate system reset. By default, WDT issues a system reset upon a time-out, and the early warning interrupt is disabled. If an early warning interrupt is required, the Early Warning Interrupt Enable bit in the Interrupt Enable register (INTENSET.EW) must be enabled. Writing a one to the Early Warning Interrupt bit in the Interrupt Enable Set register (INTENSET.EW) enables the interrupt, and writing a one to the Early Warning Interrupt bit in the Interrupt Enable Clear register (INTENCLR.EW) disables the interrupt. If the Early Warning Interrupt is enabled, an interrupt is generated prior to a watchdog time-out condition. In normal mode, the Early Warning Offset bits in the Early Warning Interrupt Control register (EWCTRL.EWOFFSET) define the time where the early warning interrupt occurs. The normal-mode operation is illustrated in Figure 18-2. Figure 18-2. Normal-Mode Operation System Reset WDT Count Timely WDT Clear PER[3:0]=1 WDT Timeout Early Warning Interrupt EWOFFSET[3:0]=0 5 10 15 20 25 30 TOWDT 35 t [ms] Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 187 18.6.2.5 Window Mode In window-mode operation, the WDT uses two different time-out periods, a closed window time-out period (TOWDTW) and the normal, or open, time-out period (TOWDT). The closed window time-out period defines a duration from 8ms to 16s where the WDT cannot be reset. If the WDT is cleared during this period, the WDT will issue a system reset. The normal WDT time-out period, which is also from 8ms to 16s, defines the duration of the open period during which the WDT can be cleared. The open period will always follow the closed period, and so the total duration of the time-out period is the sum of the closed window and the open window time-out periods. The closed window is defined by the Window Period bits in the Configuration register (CONFIG.WINDOW), and the open window is defined by the Period bits in the Configuration register (CONFIG.PER). By default, the WDT issues a system reset upon a time-out and the Early Warning interrupt is disabled. If an Early Warning interrupt is required, INTENCLR/SET.EW must be set. Writing a one to INTENSET.EW enables the interrupt, and writing a one to INTENCLR.EW disables the interrupt. If the Early Warning interrupt is enabled in window mode, the interrupt is generated at the start of the open window period. The window mode operation is illustrated in Figure 18-3. Figure 18-3. Window-Mode Operation WDT Count Timely WDT Clear Open PER[3:0]=0 Early Warning Interrupt Early WDT Clear Closed WINDOW[3:0]=0 WDT Timeout 5 10 15 20 TOWDTW 25 30 TOWDT 35 t [ms] 18.6.3 Additional Features 18.6.3.1 Always-On Mode The always-on mode is enabled by writing a one to the Always-On bit in the Control register (CTRL.ALWAYSON). When the always-on mode is enabled, the WDT runs continuously, regardless of the state of CTRL.ENABLE. Once written, the Always-On bit can only be cleared by a power-on reset. The Configuration (CONFIG) and Early Warning Control (EWCTRL) registers are read-only registers while the CTRL.ALWAYSON bit is set. Thus, the time period configuration bits (CONFIG.PER, CONFIG.WINDOW, EWCTRL.EWOFFSET) of the WDT cannot be changed. Enabling or disabling window-mode operation by writing the Window Enable bit (CTRL.WEN) is allowed while in the always-on mode, but note that CONFIG.PER cannot be changed. The Interrupt Clear and Interrupt Set registers are accessible in the always-on mode. The Early Warning interrupt can still be enabled or disabled while in the always-on mode, but note that EWCTRL.EWOFFSET cannot be changed. Table 18-2 shows the operation of the WDT when CTRL.ALWAYSON is set. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 188 Table 18-2. WDT Operating Modes With Always-On WEN Interrupt enable Mode 0 0 Always-on and normal mode 0 1 Always-on and normal mode with Early Warning interrupt 1 0 Always-on and window mode 1 1 Always-on and window mode with Early Warning interrupt 18.6.4 Interrupts The WDT has the following interrupt sources: z Early Warning Each interrupt source has an interrupt flag associated with it. The interrupt flag in the Interrupt Flag Status and Clear register (INTFLAG) is set when the interrupt condition occurs. Each interrupt can be individually enabled by writing a one to the corresponding bit in the Interrupt Enable Set register (INTENSET), and disabled by writing a one to the corresponding bit in the Interrupt Enable Clear register (INTENCLR). An interrupt request is generated when the interrupt flag is set and the corresponding interrupt is enabled. The interrupt request remains active until the interrupt flag is cleared, the interrupt is disabled or the WDT is reset. See INTFLAG for details on how to clear interrupt flags. The WDT has one common interrupt request line for all the interrupt sources. The user must read INTFLAG to determine which interrupt condition is present. Note that interrupts must be globally enabled for interrupt requests to be generated. Refer to “Nested Vector Interrupt Controller” on page 28 for details. The Early Warning interrupt behaves differently in normal mode and in window mode. In normal mode, the Early Warning interrupt generation is defined by the Early Warning Offset in the Early Warning Control register (EWCTRL.EWOFFSET). The Early Warning Offset bits define the number of GCLK_WDT clocks before the interrupt is generated, relative to the start of the watchdog time-out period. For example, if the WDT is operating in normal mode with CONFIG.PER = 0x2 and EWCTRL.EWOFFSET = 0x1, the Early Warning interrupt is generated 16 GCLK_WDT clock cycles from the start of the watchdog time-out period, and the watchdog time-out system reset is generated 32 GCLK_WDT clock cycles from the start of the watchdog time-out period. The user must take caution when programming the Early Warning Offset bits. If these bits define an Early Warning interrupt generation time greater than the watchdog time-out period, the watchdog time-out system reset is generated prior to the Early Warning interrupt. Thus, the Early Warning interrupt will never be generated. In window mode, the Early Warning interrupt is generated at the start of the open window period. In a typical application where the system is in sleep mode, it can use this interrupt to wake up and clear the Watchdog Timer, after which the system can perform other tasks or return to sleep mode. 18.6.5 Synchronization Due to the asynchronicity between CLK_WDT_APB and GCLK_WDT some registers must be synchronized when accessed. A register can require: z Synchronization when written z Synchronization when read z Synchronization when written and read z No synchronization When executing an operation that requires synchronization, the Synchronization Busy bit in the Status register(STATUS.SYNCBUSY) will be set immediately, and cleared when synchronization is complete. The synchronization Ready interrupt can be used to signal when sync is complete. This can be accessed via the Synchronization Ready Interrupt Flag in the Interrupt Flag Status and Clear register (INTFLAG.SYNCRDY). Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 189 If an operation that requires synchronization is executed while STATUS.SYNCBUSY is one, the bus will be stalled. All operations will complete successfully, but the CPU will be stalled and interrupts will be pending as long as the bus is stalled. The following registers need synchronization when written: z Control register (CTRL) z Clear register (CLEAR) Write-synchronization is denoted by the Write-Synchronized property in the register description. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 190 18.7 Register Summary Register summary Offset Name Bit Pos. 0x0 CTRL 7:0 0x1 CONFIG 7:0 0x2 EWCTRL 7:0 0x3 Reserved 0x4 INTENCLR 7:0 EW 0x5 INTENSET 7:0 EW 0x6 INTFLAG 7:0 EW 0x7 STATUS 7:0 0x8 CLEAR 7:0 ALWAYSON WEN WINDOW[3:0] ENABLE PER[3:0] EWOFFSET[3:0] SYNCBUSY CLEAR[7:0] Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 191 18.8 Register Description Registers can be 8, 16 or 32 bits wide. Atomic 8-, 16- and 32-bit accesses are supported. In addition, the 8-bit quarters and 16-bit halves of a 32-bit register and the 8-bit halves of a 16-bit register can be accessed directly. Some registers are optionally write-protected by the Peripheral Access Controller (PAC). Write-protection is denoted by the Write-Protected property in each individual register description. Please refer to “Register Access Protection” on page 185 for details. Some registers require synchronization when read and/or written. Synchronization is denoted by the Write-Synchronized or the Read-Synchronized property in each individual register description. Please refer to “Synchronization” on page 189 for details. Some registers are enable-protected, meaning they can be written only when the WDT is disabled. Enable-protection is denoted by the Enable-Protected property in each individual register description. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 192 18.8.1 Control Name: CTRL Offset: 0x0 Reset: N/A - Loaded from NVM User Row at startup Property: Write-Protected, Enable-Protected, Write-Synchronized Bit 7 6 5 4 3 ALWAYSON Access Reset z 2 1 WEN ENABLE 0 R/W1 R/W R/W R/W R/W R/W R/W R/W X 0 0 0 0 X X 0 Bit 7 – ALWAYSON: Always-On This bit allows the WDT to run continuously. After being written to one, this bit cannot be written to zero, and the WDT will remain enabled until a power-on reset is received. When this bit is one, the Control register (CTRL), the Configuration register (CONFIG) and the Early Warning Control register (EWCTRL) will be read-only, and any writes to these registers are not allowed. Writing a zero to this bit has no effect. 0: The WDT is enabled and disabled through the ENABLE bit. 1: The WDT is enabled and can only be disabled by a power-on reset (POR). This bit is not enable-protected. These bits are loaded from NVM User Row at startup. Refer to “Non-Volatile Memory (NVM) User Row Mapping” on page 25 for more details. z Bits 6:3 – 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. These bits will always return zero when read. z Bit 2 – WEN: Watchdog Timer Window Mode Enable This bit enables window mode. Can be written only while CTRL.ALWAYSON is zero. The initial value of this bit is loaded from Flash Calibration. 0: Window mode is disabled (normal operation). 1: Window mode is enabled. This bit is loaded from NVM User Row at startup. Refer to “Non-Volatile Memory (NVM) User Row Mapping” on page 25 for more details. z Bit 1 – ENABLE: Enable This bit enables or disables the WDT. Can only be written while CTRL.ALWAYSON is zero. 0: The WDT is disabled. 1: The WDT is enabled. Due to synchronization, there is delay from writing CTRL.ENABLE until the peripheral is enabled/disabled. The value written to CTRL.ENABLE will read back immediately, and the Synchronization Busy bit in the Status register (STATUS.SYNCBUSY) will be set. STATUS.SYNCBUSY will be cleared when the operation is complete. This bit is not enable-protected. This bit is loaded from NVM User Row at startup. Refer to “Non-Volatile Memory (NVM) User Row Mapping” on page 25 for more details. z 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. This bit will always return zero when read. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 193 18.8.2 Configuration Name: CONFIG Offset: 0x1 Reset: N/A - Loaded from NVM User Row at startup Property: Write-Protected, Enable-Protected, Write-Synchronized Bit 7 6 5 4 3 2 WINDOW[3:0] Access Reset z 1 0 PER[3:0] R/W R/W R/W R/W R/W R/W R/W R/W X X X X X X X X Bits 7:4 – WINDOW[3:0]: Window Mode Time-Out Period In window mode, these bits determine the watchdog closed window period as a number of oscillator cycles. The closed window periods are defined in Table 18-3. These bits are loaded from NVM User Row at startup. Refer to “Non-Volatile Memory (NVM) User Row Mapping” on page 25 for more details. Table 18-3. Window Mode Time-Out Period Value 0x0 8 clock cycles 0x1 16 clock cycles 0x2 32 clock cycles 0x3 64 clock cycles 0x4 128 clock cycles 0x5 256 clocks cycles 0x6 512 clocks cycles 0x7 1024 clock cycles 0x8 2048 clock cycles 0x9 4096 clock cycles 0xA 8192 clock cycles 0xB 16384 clock cycles 0xC-0xF z Description Reserved Bits 3:0 – PER[3:0]: Time-Out Period These bits determine the watchdog time-out period as a number of GCLK_WDT clock cycles. In window mode operation, these bits define the open window period. The different typical time-out periods are found in Table 18-4. These bits are loaded from NVM User Row at startup. Refer to “Non-Volatile Memory (NVM) User Row Mapping” on page 25 for more details. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 194 Table 18-4. Time-Out Period Value Description 0x0 8 clock cycles 0x1 16 clock cycles 0x2 32 clock cycles 0x3 64 clock cycles 0x4 128 clock cycles 0x5 256 clocks cycles 0x6 512 clocks cycles 0x7 1024 clock cycles 0x8 2048 clock cycles 0x9 4096 clock cycles 0xA 8192 clock cycles 0xB 16384 clock cycles 0xC-0xF Reserved Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 195 18.8.3 Early Warning Interrupt Control Name: EWCTRL Offset: 0x2 Reset: N/A - Loaded from NVM User Row at startup Property: Write-Protected, Enable-Protected Bit 7 6 5 4 3 2 1 0 EWOFFSET[3:0] Acces s R R R R R/W R/W R/W R/W Reset 0 0 0 0 X X X X z Bits 7:4 – 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. These bits will always return zero when read. z Bits 3:0 – EWOFFSET[3:0]: Early Warning Interrupt Time Offset These bits determine the number of GCLK_WDT clocks in the offset from the start of the watchdog time-out period to when the Early Warning interrupt is generated. The Early Warning Offset is defined in Table 18-5. These bits are loaded from NVM User Row at startup. Refer to “Non-Volatile Memory (NVM) User Row Mapping” on page 25 for more details. Table 18-5. Early Warning Interrupt Time Offset Value Description 0x0 8 clock cycles 0x1 16 clock cycles 0x2 32 clock cycles 0x3 64 clock cycles 0x4 128 clock cycles 0x5 256 clocks cycles 0x6 512 clocks cycles 0x7 1024 clock cycles 0x8 2048 clock cycles 0x9 4096 clock cycles 0xA 8192 clock cycles 0xB 16384 clock cycles 0xC-0xF Reserved Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 196 18.8.4 Interrupt Enable Clear This register allows the user to disable an interrupt without doing a read-modify-write operation. Changes in this register will also be reflected in the Interrupt Enable Set register (INTENSET). Name: INTENCLR Offset: 0x4 Reset: 0x00 Property: Write-Protected Bit 7 6 5 4 3 2 1 0 EW Access R R R R R R R R/W Reset 0 0 0 0 0 0 0 0 z Bits 7:1 – 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. These bits will always return zero when read. z Bit 0 – EW: Early Warning Interrupt Enable 0: The Early Warning interrupt is disabled. 1: The Early Warning interrupt is enabled. Writing a zero to this bit has no effect. Writing a one to this bit disables the Early Warning interrupt. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 197 18.8.5 Interrupt Enable Set This register allows the user to enable an interrupt without doing a read-modify-write operation. Changes in this register will also be reflected in the Interrupt Enable Clear register (INTENCLR). Name: INTENSET Offset: 0x5 Reset: 0x00 Property: Write-Protected Bit 7 6 5 4 3 2 1 0 EW Access R R R R R R R R/W Reset 0 0 0 0 0 0 0 0 z Bits 7:1 – 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. These bits will always return zero when read. z Bit 0 – EW: Early Warning Interrupt Enable 0: The Early Warning interrupt is disabled. 1: The Early Warning interrupt is enabled. Writing a zero to this bit has no effect. Writing a one to this bit enables the Early Warning interrupt. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 198 18.8.6 Interrupt Flag Status and Clear Name: INTFLAG Offset: 0x6 Reset: 0x00 Property: – Bit 7 6 5 4 3 2 1 0 EW Access R R R R R R R R/W Reset 0 0 0 0 0 0 0 0 z Bits 7:1 – 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. These bits will always return zero when read. z Bit 0 – EW: Early Warning This flag is set when an Early Warning interrupt occurs, as defined in EWCTRL.EWOFFSET. Writing a zero to this bit has no effect. Writing a one to this bit clears the Early Warning interrupt flag. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 199 18.8.7 Status Name: STATUS Offset: 0x7 Reset: 0x00 Property: – Bit 7 6 5 4 3 2 1 0 SYNCBUSY Access R R R R R R R R Reset 0 0 0 0 0 0 0 0 z Bit 7 – SYNCBUSY: Synchronization Busy This bit is cleared when the synchronization of registers between clock domains is complete. This bit is set when the synchronization of registers between clock domains is started. z Bits 6:0 – 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. These bits will always return zero when read. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 200 18.8.8 Clear Name: CLEAR Offset: Offset: 0x8 Reset: 0x00 Property: Write-Protected, Write-Synchronized Bit 7 6 5 4 3 2 1 0 CLEAR[7:0] Access W W W W W W W W Reset 0 0 0 0 0 0 0 0 z Bits 7:0 – CLEAR: Watchdog Clear Writing 0xA5 to this register will clear the Watchdog Timer and the watchdog time-out period is restarted. Writing any other value will issue an immediate system reset. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 201 18.9 Asynchronous Watchdog Clock Characterization The source intended for the asynchronous watchdog clock (OSCULP32K) has a variance of +/- 15%. In a typical application with GCLK_WDT = 1kHz or GCLK_WDT = 32kHz, the time period is illustrated in Table 18-6. Table 18-6. Typical Time-Out Period Typical Time-Out Periods GCLK_WDT = 1kHz Min Typ GCLK_WDT = 32kHz Max Min Typ Max 8 clock cycles 6.64ms 7.81ms 8.98ms 0.20ms 0.24ms 0.28ms 16 clock cycles 13.28ms 15.62ms 17.97ms 0.41ms 0.48ms 0.56ms 32 clock cycles 26.56ms 31.25ms 39.94ms 0.83ms 0.97ms 1.12ms 64 clock cycles 53.12ms 62.50ms 71.87ms 1.66ms 1.95ms 2.24ms 128 clock cycles 0.10s 0.12s 0.14s 3.32ms 3.90ms 4.49ms 256 clocks cycles 0.21s 0.25s 0.28s 6.64ms 7.81ms 8.98ms 512 clocks cycles 0.42s 0.50s 0.57s 13.28ms 15.62ms 17.96ms 1024 clock cycles 0.85s 1.00s 1.15s 26.56ms 31.25ms 35.93ms 2048 clock cycles 1.70s 2.00s 2.30s 53.12ms 62.50ms 71.87ms 4096 clock cycles 3.40s 4.00s 4.60s 0.10s 0.12s 0.14s 8192 clock cycles 6.80s 8.00s 9.20s 0.21s 0.25s 0.28s 16384 clock cycles 13.60s 16.00s 18.40s 0.42s 0.50s 0.57s Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 202 19. RTC – Real-Time Counter z 19.1 Overview The Real-Time Counter (RTC) is a 32-bit counter with a 10-bit programmable prescaler that typically runs continuously to keep track of time. The RTC can wake up the device from sleep modes using the alarm/compare wake up, periodic wake up or overflow wake up mechanisms. The RTC is typically clocked by the 1.024kHz output from the32.768kHz High-Accuracy Internal Crystal Oscillator(OSC32K) and this is the configuration optimized for the lowest 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 other sources, selectable through the Generic Clock module (GCLK). The RTC can generate periodic peripheral events from outputs of the prescaler, as well as alarm/compare interrupts and peripheral events, which can trigger at any counter value. Additionally, the timer can trigger an overflow interrupt and peripheral event, and be reset on the occurrence of an alarm/compare match. This allows periodic interrupts and peripheral events at very long and accurate intervals. The 10-bit programmable prescaler can scale down the clock source, and so a wide range of resolutions and time-out periods can be configured. With a 32.768kHz clock source, the minimum counter tick interval is 30.5µs, and time-out periods can range up to 36 hours. With the counter tick interval configured to 1s, the maximum time-out period is more than 136 years. 19.2 Features z 32-bit counter with 10-bit prescaler z Multiple clock sources z 32-bit or 16-bit Counter mode z One 32-bit or two 16-bit compare values z Clock/Calendar mode z Time in seconds, minutes and hours (12/24) Date in day of month, month and year z Leap year correction z z Digital prescaler correction/tuning for increased accuracy z Overflow, alarm/compare match and prescaler interrupts and events z 19.3 Optional clear on alarm/compare match Block Diagram Figure 19-1. RTC Block Diagram (Mode 0 — 32-Bit Counter) 0 MATCHCLR GCLK_RTC 10-bit Prescaler CLK_RTC_CNT Overflow COUNT 32 = Periodic Events Compare n 32 COMPn Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 203 Figure 19-2. RTC Block Diagram (Mode 1 — 16-Bit Counter) 0 GCLK_RTC 10-bit Prescaler CLK_RTC_CNT COUNT = 16 Overflow 16 Periodic Events PER = Compare n 16 COMPn Figure 19-3. RTC Block Diagram (Mode 2 — Clock/Calendar) 0 MATCHCLR GCLK_RTC 10-bit Prescaler CLK_RTC_CNT 32 Y/M/D H:M:S 32 Y/M/D H:M:S = MASKn Periodic Events 19.4 Overflow CLOCK Alarm n ALARMn Signal Description Not applicable. 19.5 Product Dependencies In order to use this peripheral, other parts of the system must be configured correctly, as described below. 19.5.1 I/O Lines Not applicable. 19.5.2 Power Management The RTC can continue to operate in any sleep mode. The RTC interrupts can be used to wake up the device from sleep modes. The events can trigger other operations in the system without exiting sleep modes. Refer to “PM – Power Manager” on page 105 for details on the different sleep modes. The RTC will be reset only at power-on (POR) or by writing a one to the Software Reset bit in the Control register (CTRL.SWRST). - Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 204 19.5.3 Clocks The RTC bus clock (CLK_RTC_APB) can be enabled and disabled in the Power Manager, and the default state of CLK_RTC_APB can be found in the Peripheral Clock Masking section in the “PM – Power Manager” on page 105. A generic clock (GCLK_RTC) is required to clock the RTC. This clock must be configured and enabled in the Generic Clock Controller before using the RTC. Refer to “GCLK – Generic Clock Controller” on page 83 for details. This generic clock is asynchronous to the user interface clock (CLK_RTC_APB). Due to this asynchronicity, accessing certain registers will require synchronization between the clock domains. Refer to “Synchronization” on page 209 for further details. 19.5.4 DMA Not applicable. 19.5.5 Interrupts The interrupt request line is connected to the Interrupt Controller. Using the RTC interrupts requires the interrupt controller to be configured first. Refer to “Nested Vector Interrupt Controller” on page 28 for details. 19.5.6 Events To use the RTC event functionality, the corresponding events need to be configured in the event system. Refer to “EVSYS – Event System” on page 314 for details. 19.5.7 Debug Operation When the CPU is halted in debug mode the RTC will halt normal operation. The RTC can be forced to continue operation during debugging. Refer to the DBGCTRL register for details. 19.5.8 Register Access Protection All registers with write-access are optionally write-protected by the peripheral access controller (PAC), except the following registers: z Interrupt Flag Status and Clear register (INTFLAG) z Read Request register (READREQ) z Status register (STATUS) z Debug register (DBGCTRL) Write-protection is denoted by the Write-Protection property in the register description. When the CPU is halted in debug mode, all write-protection is automatically disabled. Write-protection does not apply for accesses through an external debugger. Refer to “PAC – Peripheral Access Controller” on page 31 for details. 19.5.9 Analog Connections A 32.768kHz crystal can be connected to the TOSC1 and TOSC2 pins, along with any required load capacitors. 19.6 Functional Description 19.6.1 Principle of Operation The RTC keeps track of time in the system and enables periodic events, as well as interrupts and events at a specified time. The RTC consists of a 10-bit prescaler that feeds a 32-bit counter. The actual format of the 32-bit counter depends on the RTC operating mode. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 205 19.6.2 Basic Operation 19.6.2.1 Initialization The following bits are enable-protected, meaning that they can only be written when the RTC is disabled (CTRL.ENABLE is zero): z Operating Mode bits in the Control register (CTRL.MODE) z Prescaler bits in the Control register (CTRL.PRESCALER) z Clear on Match bit in the Control register (CTRL.MATCHCLR) z Clock Representation bit in the Control register (CTRL.CLKREP) The following register is enable-protected: z Event Control register (EVCTRL) Any writes to these bits or registers when the RTC is enabled or being disabled (CTRL.ENABLE is one) will be discarded. Writes to these bits or registers while the RTC is being disabled will be completed after the disabling is complete. Enable-protection is denoted by the Enable-Protection property in the register description. Before the RTC is enabled, it must be configured, as outlined by the following steps: z RTC operation mode must be selected by writing the Operating Mode bit group in the Control register (CTRL.MODE) z Clock representation must be selected by writing the Clock Representation bit in the Control register (CTRL.CLKREP) z Prescaler value must be selected by writing the Prescaler bit group in the Control register (CTRL.PRESCALER) The RTC prescaler divides down the source clock for the RTC counter. The frequency of the RTC clock (CLK_RTC_CNT) is given by the following formula: f GCLK_RTC f CLK_RTC_CNT = ---------------------------PRESCALER 2 The frequency of the generic clock, GCLK_RTC, is given by fGCLK_RTC, and fCLK_RTC_CNT is the frequency of the internal prescaled RTC clock, CLK_RTC_CNT. Note that in the Clock/Calendar mode, the prescaler must be configured to provide a 1Hz clock to the counter for correct operation. 19.6.2.2 Enabling, Disabling and Resetting The RTC is enabled by writing a one to the Enable bit in the Control register (CTRL.ENABLE). The RTC is disabled by writing a zero to CTRL.ENABLE. The RTC should be disabled before resetting it. The RTC is reset by writing a one to the Software Reset bit in the Control register (CTRL.SWRST). All registers in the RTC, except DBGCTRL, will be reset to their initial state, and the RTC will be disabled. Refer to the CTRL register for details. 19.6.3 Operating Modes The RTC counter supports three RTC operating modes: 32-bit Counter, 16-bit Counter and Clock/Calendar. The operating mode is selected by the Operating Mode bit group in the Control register (CTRL.MODE). 19.6.3.1 32-Bit Counter (Mode 0) When the RTC Operating Mode bits in the Control register (CTRL.MODE) are zero, the counter operates in 32-bit Counter mode. The block diagram of this mode is shown in Figure 19-1. When the RTC is enabled, the counter will increment on every 0-to-1 transition of CLK_RTC_CNT. The counter will increment until it reaches the top value of Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 206 0xFFFFFFFF, and then wrap to 0x00000000. This sets the Overflow Interrupt flag in the Interrupt Flag Status and Clear register (INTFLAG.OVF). The RTC counter value can be read from or written to the Counter Value register (COUNT) in 32-bit format. The counter value is continuously compared with the 32-bit Compare register (COMP0). When a compare match occurs, the Compare 0Interrupt flag in the Interrupt Flag Status and Clear register (INTFLAG.CMP0) is set on the next 0-to-1 transition of CLK_RTC_CNT. If the Clear on Match bit in the Control register (CTRL.MATCHCLR) is one, the counter is cleared on the next counter cycle when a compare match with COMP0 occurs. This allows the RTC to generate periodic interrupts or events with longer periods than are possible with the prescaler events. Note that when CTRL.MATCHCLR is one, INTFLAG.CMP0 and INTFLAG.OVF will both be set simultaneously on a compare match with COMP0. 19.6.3.2 16-Bit Counter (Mode 1) When CTRL.MODE is one, the counter operates in 16-bit Counter mode as shown in Figure 19-2. When the RTC is enabled, the counter will increment on every 0-to-1 transition of CLK_RTC_CNT. In 16-bit Counter mode, the 16-bit Period register (PER) holds the maximum value of the counter. The counter will increment until it reaches the PER value, and then wrap to 0x0000. This sets the Overflow Interrupt flag in the Interrupt Flag Status and Clear register (INTFLAG.OVF). The RTC counter value can be read from or written to the Counter Value register (COUNT) in 16-bit format. The counter value is continuously compared with the 16-bit Compare registers (COMPn, n=0–1). When a compare match occurs, the Compare n Interrupt flag in the Interrupt Flag Status and Clear register (INTFLAG.CMPn, n=0–1) is set on the next 0-to-1 transition of CLK_RTC_CNT. 19.6.3.3 Clock/Calendar (Mode 2) When CTRL.MODE is two, the counter operates in Clock/Calendar mode, as shown in Figure 19-3. When the RTC is enabled, the counter will increment on every 0-to-1 transition of CLK_RTC_CNT. The selected clock source and RTC prescaler must be configured to provide a 1Hz clock to the counter for correct operation in this mode. The time and date can be read from or written to the Clock Value register (CLOCK) in a 32-bit time/date format. Time is represented as: z Seconds z Minutes z Hours Hours can be represented in either 12- or 24-hour format, selected by the Clock Representation bit in the Control register (CTRL.CLKREP). This bit can be changed only while the RTC is disabled. Date is represented as: z Day as the numeric day of the month (starting at 1) z Month as the numeric month of the year (1 = January, 2 = February, etc.) z Year as a value counting the offset from a reference value that must be defined in software The date is automatically adjusted for leap years, assuming every year divisible by 4 is a leap year. Therefore, the reference value must be a leap year, e.g. 2000. The RTC will increment until it reaches the top value of 23:59:59 December 31 of year 63, and then wrap to 00:00:00 January 1 of year 0. This will set the Overflow Interrupt flag in the Interrupt Flag Status and Clear registers (INTFLAG.OVF). The clock value is continuously compared with the 32-bit Alarm register (ALARM0). When an alarm match occurs, the Alarm 0 Interrupt flag in the Interrupt Flag Status and Clear registers (INTFLAG.ALARMn0) is set on the next 0-to-1 transition of CLK_RTC_CNT. A valid alarm match depends on the setting of the Alarm Mask Selection bits in the Alarm 0 Mask register (MASK0.SEL). These bits determine which time/date fields of the clock and alarm values are valid for comparison and which are ignored. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 207 If the Clear on Match bit in the Control register (CTRL.MATCHCLR) is one, the counter is cleared on the next counter cycle when an alarm match with ALARM0 occurs. This allows the RTC to generate periodic interrupts or events with longer periods than are possible with the prescaler events (see “Periodic Events” on page 208). Note that when CTRL.MATCHCLR is one, INTFLAG.ALARM0 and INTFLAG.OVF will both be set simultaneously on an alarm match with ALARM0. 19.6.4 Additional Features 19.6.4.1 Periodic Events The RTC prescaler can generate events at periodic intervals, allowing flexible system tick creation. Any of the upper eight bits of the prescaler (bits 2 to 9) can be the source of an event. When one of the Periodic Event Output bits in the Event Control register (EVCTRL.PEREOm) is one, an event is generated on the 0-to1 transition of the related bit in the prescaler, resulting in a periodic event frequency of: f PERIODIC = f GCLK _ RTC 2 n +3 fGCLK_RTC is the frequency of the internal prescaler clock, GCLK_RTC, and n is the position of the EVCTRL.PERnEO bit. For example, PER0 will generate an event every 8 GCLK_RTC cycles, PER1 every 16 cycles, etc. This is shown in Figure 19-4. Periodic events are independent of the prescaler setting used by the RTC counter, except if CTRL.PRESCALER is zero. Then, no periodic events will be generated. Figure 19-4. Example Periodic Events GCLK_RTC PER0 PER1 PER2 PER3 PER4 19.6.4.2 Frequency Correction The RTC Frequency Correction module employs periodic counter corrections to compensate for a too-slow or too-fast oscillator. Frequency correction requires that CTRL.PRESCALER is greater than 1. The digital correction circuit adds or subtracts cycles from the RTC prescaler to adjust the frequency in approximately 1PPM steps. Digital correction is achieved by adding or skipping a single count in the prescaler once every 1024 GCLK_RTC cycles. The Value bit group in the Frequency Correction register (FREQCORR.VALUE) determines the number of times the adjustment is applied over 976 of these periods. The resulting correction is as follows: 6 FREQCORR.VALUE Correction in PPM = ----------------------------------------------------- ⋅ 10 PPM 1024 ⋅ 976 This results in a resolution of 1.0006PPM. The Sign bit in the Frequency Correction register (FREQCORR.SIGN) determines the direction of the correction. A positive value will speed up the frequency, and a negative value will slow down the frequency. Digital correction also affects the generation of the periodic events from the prescaler. When the correction is applied at the end of the correction cycle period, the interval between the previous periodic event and the next occurrence may also be shortened or lengthened depending on the correction value. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 208 19.6.5 DMA Operation Not applicable. 19.6.6 Interrupts The RTC has the following interrupt sources: z Overflow z Compare m z Alarm m z Synchronization Ready Each interrupt source has an interrupt flag associated with it. The interrupt flag in the Interrupt Flag Status and Clear register (INTFLAG) is set when the interrupt condition occurs. Each interrupt can be individually enabled by writing a one to the corresponding bit in the Interrupt Enable Set register (INTENSET), and disabled by writing a one to the corresponding bit in the Interrupt Enable Clear register (INTENCLR). An interrupt request is generated when the interrupt flag is set and the corresponding interrupt is enabled. The interrupt request remains active until the interrupt flag is cleared, the interrupt is disabled or the RTC is reset. See INTFLAG for details on how to clear interrupt flags. The RTC has one common interrupt request line for all the interrupt sources. The user must read INTFLAG to determine which interrupt condition is present. Note that interrupts must be globally enabled for interrupt requests to be generated. Refer to “Nested Vector Interrupt Controller” on page 28 for details. 19.6.7 Events The RTC can generate the following output events, which are generated in the same way as the corresponding interrupts: z Overflow (OVF) z Period n (PERn) z Compare n (CMPn) z Alarm n (ALARMn) Output events must be enabled to be generated. Writing a one to an Event Output bit in the Event Control register (EVCTRL.xxEO) enables the corresponding output event. Writing a zero to this bit disables the corresponding output event. Refer to “EVSYS – Event System” on page 314 for details. 19.6.8 Sleep Mode Operation The RTC will continue to operate in any sleep mode where the source clock is active. The RTC interrupts can be used to wake up the device from a sleep mode, or the RTC events can trigger other operations in the system without exiting the sleep mode. An interrupt request will be generated after the wake-up if the Interrupt Controller is configured accordingly. Otherwise the CPU will wake up directly, without triggering an interrupt. In this case, the CPU will continue executing from the instruction following the entry into sleep. The periodic events can also wake up the CPU through the interrupt function of the Event System. In this case, the event must be enabled and connected to an event channel with its interrupt enabled. See “EVSYS – Event System” on page 314 for more information. 19.6.9 Synchronization Due to the asynchronicity between CLK_RTC_APB and GCLK_RTC some registers must be synchronized when accessed. A register can require: z Synchronization when written z Synchronization when read Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 209 z Synchronization when written and read z No synchronization When executing an operation that requires synchronization, the Synchronization Busy bit in the Status register(STATUS.SYNCBUSY) will be set immediately, and cleared when synchronization is complete. The synchronization Ready interrupt can be used to signal when sync is complete. This can be accessed via the Synchronization Ready Interrupt Flag in the Interrupt Flag Status and Clear register (INTFLAG.SYNCRDY). If an operation that requires synchronization is executed while STATUS.SYNCBUSY is one, the bus will be stalled. All operations will complete successfully, but the CPU will be stalled and interrupts will be pending as long as the bus is stalled. The following bits need synchronization when written: z Software Reset bit in the Control register (CTRL.SWRST) z Enable bit in the Control register (CTRL.ENABLE) The following registers need synchronization when written: z The Counter Value register (COUNT) z The Clock Value register (CLOCK) z The Counter Period register (PER) z The Compare n Value registers (COMPn) z The Alarm n Value registers (ALARMn) z The Frequency Correction register (FREQCORR) z The Alarm n Mask register (MASKn) Write-synchronization is denoted by the Write-Synchronization property in the register description. The following registers need synchronization when read: z The Counter Value register (COUNT) z The Clock Value register (CLOCK) Read-synchronization is denoted by the Read-Synchronization property in the register description. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 210 19.7 Register Summary The register mapping depends on the Operating Mode bits in the Control register (CTRL.MODE). The register summary is presented for each of the three modes. Table 19-1. Register Summary - Mode 0 Registers Offset Name 0x00 Bit Pos. 7:0 MATCHCLR CLKREP MODE[1:0] ENABLE SWRST CTRL 0x01 15:8 0x02 PRESCALER[3:0] 7:0 ADDR[5:0] READREQ 0x03 0x04 15:8 RREQ RCONT 7:0 PEREO7 PEREO6 15:8 OVFEO PEREO5 PEREO4 PEREO3 PEREO2 PEREO1 PEREO0 EVCTRL 0x05 CMPEO0 0x06 INTENCLR 7:0 OVF SYNCRDY CMP0 0x07 INTENSET 7:0 OVF SYNCRDY CMP0 0x08 INTFLAG 7:0 OVF SYNCRDY CMP0 0x09 Reserved 0x0A STATUS 7:0 SYNCBUSY 0x0B DBGCTRL 7:0 0x0C FREQCORR 7:0 0x0D Reserved 0x0E Reserved 0x0F Reserved 0x10 DBGRUN SIGN VALUE[6:0] 7:0 COUNT[7:0] 15:8 COUNT[15:8] 0x12 23:16 COUNT[23:16] 0x13 31:24 COUNT[31:24] 7:0 COMP[7:0] 15:8 COMP[15:8] 0x1A 23:16 COMP[23:16] 0x1B 31:24 COMP[31:24] 0x11 COUNT 0x14 Reserved 0x15 Reserved 0x16 Reserved 0x17 Reserved 0x18 0x19 COMP0 Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 211 Table 19-2. Register Summary - Mode 1 Registers Offset Name 0x00 Bit Pos. 7:0 MATCHCLR CLKREP MODE[1:0] ENABLE SWRST CTRL 0x01 PRESCALER[3:0] 15:8 7:0 0x02 ADDR[5:0] READREQ 0x03 0x04 15:8 RREQ RCONT 7:0 PEREO7 PEREO6 15:8 OVFEO PEREO5 PEREO4 PEREO3 PEREO2 PEREO1 PEREO0 CMPEO1 CMPEO0 EVCTRL 0x05 0x06 INTENCLR 7:0 OVF SYNCRDY CMP1 CMP0 0x07 INTENSET 7:0 OVF SYNCRDY CMP1 CMP0 0x08 INTFLAG 7:0 OVF SYNCRDY CMP1 CMP0 0x09 Reserved 0x0A STATUS 7:0 SYNCBUSY 0x0B DBGCTRL 7:0 0x0C FREQCORR 7:0 0x0D Reserved 0x0E Reserved 0x0F Reserved 0x10 DBGRUN SIGN VALUE[6:0] 7:0 COUNT[7:0] 15:8 COUNT[15:8] 7:0 PER[7:0] 15:8 PER[15:8] 7:0 COMP[7:0] 15:8 COMP[15:8] 7:0 COMP[7:0] 15:8 COMP[15:8] COUNT 0x11 0x12 Reserved 0x13 Reserved 0x14 PER 0x15 0x16 Reserved 0x17 Reserved 0x18 COMP0 0x19 0x1A COMP1 0x1B Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 212 Table 19-3. Register Summary - Mode 2 Registers Offset Name 0x00 Bit Pos. 7:0 MATCHCLR CLKREP MODE[1:0] ENABLE SWRST CTRL 0x01 PRESCALER[3:0] 15:8 7:0 0x02 ADDR[5:0] READREQ 0x03 0x04 15:8 RREQ RCONT 7:0 PEREO7 PEREO6 15:8 OVFEO PEREO5 PEREO4 PEREO3 PEREO2 PEREO1 PEREO0 EVCTRL 0x05 ALARMEO0 0x06 INTENCLR 7:0 OVF SYNCRDY ALARM0 0x07 INTENSET 7:0 OVF SYNCRDY ALARM0 0x08 INTFLAG 7:0 OVF SYNCRDY ALARM0 0x09 Reserved 0x0A STATUS 7:0 SYNCBUSY 0x0B DBGCTRL 7:0 0x0C FREQCORR 7:0 0x0D Reserved 0x0E Reserved 0x0F Reserved 0x10 7:0 0x11 DBGRUN SIGN VALUE[6:0] MINUTE[1:0] 15:8 SECOND[5:0] HOUR[3:0] MINUTE[5:2] CLOCK 0x12 23:16 0x13 31:24 0x14 Reserved 0x15 Reserved 0x16 Reserved 0x17 Reserved 7:0 0x18 0x19 MONTH[1:0] DAY[4:0] HOUR[4] YEAR[5:0] MINUTE[1:0] 15:8 MONTH[3:2] SECOND[5:0] HOUR[3:0] MINUTE[5:2] ALARM0 0x1A 23:16 0x1B 31:24 0x1C MASK0 7:0 MONTH[1:0] DAY[4:0] YEAR[5:0] HOUR[4] MONTH[3:2] SEL[2:0] Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 213 19.8 Register Description Registers can be 8, 16 or 32 bits wide. Atomic 8-, 16- and 32-bit accesses are supported. In addition, the 8-bit quarters and 16-bit halves of a 32-bit register and the 8-bit halves of a 16-bit register can be accessed directly. Some registers are optionally write-protected by the Peripheral Access Controller (PAC). Write-protection is denoted by the Write-Protected property in each individual register description. Please refer to “Register Access Protection” on page 205 for details. Some registers require synchronization when read and/or written. Synchronization is denoted by the Write-Synchronized or the Read-Synchronized property in each individual register description. Please refer to “Synchronization” on page 209 for details. Some registers are enable-protected, meaning they can only be written when the RTC is disabled. Enable-protection is denoted by the Enable-Protected property in each individual register description. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 214 19.8.1 Control 19.8.1.1 Mode 0 Name: CTRL Offset: 0x00 Reset: 0x0000 Property: Write-Protected, Enable-Protected, Write-Synchronized Bit 15 14 13 12 11 10 9 8 PRESCALER[3:0] Access R R R R R/W R/W R/W R/W Reset 0 0 0 0 0 0 0 0 Bit 7 6 5 4 3 2 1 0 ENABLE SWRST MATCHCLR Access Reset MODE[1:0] R/W R/W R R R/W R/W R/W R/W 0 0 0 0 0 0 0 0 z Bits 15:12 – 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. These bits will always return zero when read. z Bits 11:8 – PRESCALER[3:0]: Prescaler These bits define the prescaling factor for the RTC clock source (GCLK_RTC) to generate the counter clock (CLK_RTC_CNT). These bits are not synchronized. Table 19-4. Prescaler PRESCALER[3:0] Prescaler Description 0x0 DIV1 CLK_RTC_CNT = GCLK_RTC/1 0x1 DIV2 CLK_RTC_CNT = GCLK_RTC/2 0x2 DIV4 CLK_RTC_CNT = GCLK_RTC/4 0x3 DIV8 CLK_RTC_CNT = GCLK_RTC/8 0x4 DIV16 CLK_RTC_CNT = GCLK_RTC/16 0x5 DIV32 CLK_RTC_CNT = GCLK_RTC/32 0x6 DIV64 CLK_RTC_CNT = GCLK_RTC/64 0x7 DIV128 CLK_RTC_CNT = GCLK_RTC/128 0x8 DIV256 CLK_RTC_CNT = GCLK_RTC/256 0x9 DIV512 CLK_RTC_CNT = GCLK_RTC/512 0xA DIV1024 CLK_RTC_CNT = GCLK_RTC/1024 0xB-0xF - Reserved Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 215 z Bit 7 – MATCHCLR: Clear on Match This bit is valid only in Mode 0 and Mode 2. This bit can be written only when the peripheral is disabled. 0: The counter is not cleared on a Compare/Alarm 0 match. 1: The counter is cleared on a Compare/Alarm 0 match. This bit is not synchronized. z Bits 6:4 – 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. These bits will always return zero when read. z Bits 3:2 – MODE[1:0]: Operating Mode These bits define the operating mode of the RTC. These bits are not synchronized. Table 19-5. Peripheral Operating Mode MODE[1:0] Operating Mode Description 0x0 COUNT32 Mode 0: 32-bit Counter 0x1 COUNT16 Mode 1: 16-bit Counter 0x2 CLOCK Mode 2: Clock/Calendar 0x3 - Reserved z Bit 1 – ENABLE: Enable 0: The peripheral is disabled or being disabled. 1: The peripheral is enabled or being enabled. Due to synchronization, there is delay from writing CTRL.ENABLE until the peripheral is enabled/disabled. The value written to CTRL.ENABLE will read back immediately, and the Synchronization Busy bit in the Status register (STATUS.SYNCBUSY) will be set. STATUS.SYNCBUSY will be cleared when the operation is complete. This bit is not enable-protected. z Bit 0 – SWRST: Software Reset 0: There is no reset operation ongoing. 1: The reset operation is ongoing. Writing a zero to this bit has no effect. Writing a one to this bit resets all registers in the RTC, except DBGCTRL, to their initial state, and the RTC will be disabled. Writing a one to CTRL.SWRST will always take precedence, meaning that all other writes in the same write-operation will be discarded. Due to synchronization, there is a delay from writing CTRL.SWRST until the reset is complete. CTRL.SWRST and STATUS.SYNCBUSY will both be cleared when the reset is complete. This bit is not enable-protected. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 216 19.8.1.2 Mode 1 Name: CTRL Offset: 0x00 Reset: 0x0000 Property: Write-Protected, Enable-Protected, Write-Synchronized Bit 15 14 13 12 11 10 9 8 PRESCALER[3:0] Access R R R R R/W R/W R/W R/W Reset 0 0 0 0 0 0 0 0 Bit 7 6 5 4 3 2 1 0 ENABLE SWRST MODE[1:0] Access Reset R/W R/W R R R/W R/W R/W R/W 0 0 0 0 0 0 0 0 z Bits 15:12 – 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. These bits will always return zero when read. z Bits 11:8 – PRESCALER[3:0]: Prescaler These bits define the prescaling factor for the RTC clock source (GCLK_RTC) to generate the counter clock (CLK_RTC_CNT). These bits are not synchronized. Table 19-6. Prescaler PRESCALER[3:0] Prescaler Description 0x0 DIV1 CLK_RTC_CNT = GCLK_RTC/1 0x1 DIV2 CLK_RTC_CNT = GCLK_RTC/2 0x2 DIV4 CLK_RTC_CNT = GCLK_RTC/4 0x3 DIV8 CLK_RTC_CNT = GCLK_RTC/8 0x4 DIV16 CLK_RTC_CNT = GCLK_RTC/16 0x5 DIV32 CLK_RTC_CNT = GCLK_RTC/32 0x6 DIV64 CLK_RTC_CNT = GCLK_RTC/64 0x7 DIV128 CLK_RTC_CNT = GCLK_RTC/128 0x8 DIV256 CLK_RTC_CNT = GCLK_RTC/256 0x9 DIV512 CLK_RTC_CNT = GCLK_RTC/512 0xA DIV1024 CLK_RTC_CNT = GCLK_RTC/1024 0xB-0xF - Reserved Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 217 z Bits 7:4 – 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. These bits will always return zero when read. z Bits 3:2 – MODE[1:0]: Operating Mode These bits define the operating mode of the RTC. These bits are not synchronized. Table 19-7. Peripheral Operating Mode MODE[1:0] Operating Mode Description 0x0 COUNT32 Mode 0: 32-bit Counter 0x1 COUNT16 Mode 1: 16-bit Counter 0x2 CLOCK Mode 2: Clock/Calendar 0x3 - Reserved z Bit 1 – ENABLE: Enable 0: The peripheral is disabled or being disabled. 1: The peripheral is enabled or being enabled. Due to synchronization, there is delay from writing CTRL.ENABLE until the peripheral is enabled/disabled. The value written to CTRL.ENABLE will read back immediately, and the Synchronization Busy bit in the Status register (STATUS.SYNCBUSY) will be set. STATUS.SYNCBUSY will be cleared when the operation is complete. This bit is not enable-protected. z Bit 0 – SWRST: Software Reset 0: There is no reset operation ongoing. 1: The reset operation is ongoing. Writing a zero to this bit has no effect. Writing a one to this bit resets all registers in the RTC, except DBGCTRL, to their initial state, and the RTC will be disabled. Writing a one to CTRL.SWRST will always take precedence, meaning that all other writes in the same write-operation will be discarded. Due to synchronization, there is a delay from writing CTRL.SWRST until the reset is complete. CTRL.SWRST and STATUS.SYNCBUSY will both be cleared when the reset is complete. This bit is not enable-protected. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 218 19.8.1.3 Mode 2 Name: CTRL Offset: 0x00 Reset: 0x0000 Property: Write-Protected, Enable-Protected, Write-Synchronized Bit 15 14 13 12 11 10 9 8 PRESCALER[3:0] Access R R R R R/W R/W R/W R/W Reset 0 0 0 0 0 0 0 0 Bit 7 6 5 4 3 2 1 0 MATCHCLR CLKREP ENABLE SWRST R/W R/W R R R/W R/W R/W R/W 0 0 0 0 0 0 0 0 Access Reset MODE[1:0] z Bits 15:12 – 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. These bits will always return zero when read. z Bits 11:8 – PRESCALER[3:0]: Prescaler These bits define the prescaling factor for the RTC clock source (GCLK_RTC) to generate the counter clock (CLK_RTC_CNT). These bits are not synchronized. Table 19-8. Prescaler PRESCALER[3:0] Prescaler Description 0x0 DIV1 CLK_RTC_CNT = GCLK_RTC/1 0x1 DIV2 CLK_RTC_CNT = GCLK_RTC/2 0x2 DIV4 CLK_RTC_CNT = GCLK_RTC/4 0x3 DIV8 CLK_RTC_CNT = GCLK_RTC/8 0x4 DIV16 CLK_RTC_CNT = GCLK_RTC/16 0x5 DIV32 CLK_RTC_CNT = GCLK_RTC/32 0x6 DIV64 CLK_RTC_CNT = GCLK_RTC/64 0x7 DIV128 CLK_RTC_CNT = GCLK_RTC/128 0x8 DIV256 CLK_RTC_CNT = GCLK_RTC/256 0x9 DIV512 CLK_RTC_CNT = GCLK_RTC/512 0xA DIV1024 CLK_RTC_CNT = GCLK_RTC/1024 0xB-0xF - Reserved Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 219 z Bit 7 – MATCHCLR: Clear on Match This bit is valid only in Mode 0 and Mode 2. This bit can be written only when the peripheral is disabled. 0: The counter is not cleared on a Compare/Alarm 0 match. 1: The counter is cleared on a Compare/Alarm 0 match. This bit is not synchronized. z Bit 6 – CLKREP: Clock Representation This bit is valid only in Mode 2 and determines how the hours are represented in the Clock Value (CLOCK) register. This bit can be written only when the peripheral is disabled. 0: 24 Hour 1: 12 Hour (AM/PM) This bit is not synchronized. z Bits 5:4 – 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. These bits will always return zero when read. z Bits 3:2 – MODE[1:0]: Operating Mode These bits define the operating mode of the RTC. These bits are not synchronized. Table 19-9. Peripheral Operating Mode MODE[1:0] Operating Mode Description 0x0 COUNT32 Mode 0: 32-bit Counter 0x1 COUNT16 Mode 1: 16-bit Counter 0x2 CLOCK Mode 2: Clock/Calendar 0x3 - Reserved z Bit 1 – ENABLE: Enable 0: The peripheral is disabled or being disabled. 1: The peripheral is enabled or being enabled. Due to synchronization, there is delay from writing CTRL.ENABLE until the peripheral is enabled/disabled. The value written to CTRL.ENABLE will read back immediately, and the Synchronization Busy bit in the Status register (STATUS.SYNCBUSY) will be set. STATUS.SYNCBUSY will be cleared when the operation is complete. This bit is not enable-protected. z Bit 0 – SWRST: Software Reset 0: There is no reset operation ongoing. 1: The reset operation is ongoing. Writing a zero to this bit has no effect. Writing a one to this bit resets all registers in the RTC, except DBGCTRL, to their initial state, and the RTC will be disabled. Writing a one to CTRL.SWRST will always take precedence, meaning that all other writes in the same write-operation will be discarded. Due to synchronization, there is a delay from writing CTRL.SWRST until the reset is complete. CTRL.SWRST and STATUS.SYNCBUSY will both be cleared when the reset is complete. This bit is not enable-protected. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 220 19.8.2 Read Request Name: READREQ Offset: 0x02 Reset: 0x0010 Property: – Bit 15 14 13 12 11 10 9 8 RREQ RCONT Access W R/W R R R R R R Reset 0 0 0 0 0 0 0 0 Bit 7 6 5 4 3 2 1 0 ADDR[5:0] Access R R R R R R R R Reset 0 0 0 1 0 0 0 0 z Bit 15 – RREQ: Read Request Writing a zero to this bit has no effect. Writing a one to this bit requests synchronization of the register pointed to by the Address bit group (READREQ.ADDR) and sets the Synchronization Busy bit in the Status register (STATUS.SYNCBUSY). z Bit 14 – RCONT: Read Continuously Writing a zero to this bit disables continuous synchronization. Writing a one to this bit enables continuous synchronization of the register pointed to by READREQ.ADDR. The register value will be synchronized automatically every time the register is updated. READREQ.RCONT prevents READREQ.RREQ from clearing automatically. This bit is cleared when the register pointed to by READREQ.ADDR is written. z Bits 13:6 – 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. These bits will always return zero when read. z Bits 5:0 – ADDR: Address These bits select the offset of the register that needs read synchronization. In the RTC only the COUNT and CLOCK registers, which share the same address, are available for read synchronization. Therefore, the ADDR bit group is a read-only constant of 0x10. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 221 19.8.3 Event Control 19.8.3.1 Mode 0 Name: EVCTRL Offset: 0x04 Reset: 0x0000 Property: Write-Protected, Enable-Protected Bit 15 14 13 12 11 10 9 OVFEO Access 8 CMPEO0 R/W R R R R R R R/W Reset 0 0 0 0 0 0 0 0 Bit 7 6 5 4 3 2 1 0 PEREO7 PEREO6 PEREO5 PEREO4 PEREO3 PEREO2 PEREO1 PEREO0 R/W R/W R/W R/W R/W R/W R/W R/W 0 0 0 0 0 0 0 0 Access Reset z Bit 15 – OVFEO: Overflow Event Output Enable 0: Overflow event is disabled and will not be generated. 1: Overflow event is enabled and will be generated for every overflow. z Bits 14:9 – 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. These bits will always return zero when read. z Bit 8 – CMPEO0: Compare 0 Event Output Enable 0: Compare 0 event is disabled and will not be generated. 1: Compare 0 event is enabled and will be generated for every compare match. z Bits 7:0 – PEREOx: Periodic Interval x Event Output Enable 0: Periodic Interval m event is disabled and will not be generated. 1: Periodic Interval m event is enabled and will be generated. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 222 19.8.3.2 Mode 1 Name: EVCTRL Offset: 0x04 Reset: 0x0000 Property: Write-Protected, Enable-Protected Bit 15 14 13 12 11 10 OVFEO Access 9 8 CMPEO1 CMPEO0 R/W R R R R R R/W R/W Reset 0 0 0 0 0 0 0 0 Bit 7 6 5 4 3 2 1 0 PEREO7 PEREO6 PEREO5 PEREO4 PEREO3 PEREO2 PEREO1 PEREO0 R/W R/W R/W R/W R/W R/W R/W R/W 0 0 0 0 0 0 0 0 Access Reset z Bit 15 – OVFEO: Overflow Event Output Enable 0: Overflow event is disabled and will not be generated. 1: Overflow event is enabled and will be generated for every overflow. z Bits 14:10 – 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. These bits will always return zero when read. z Bit 9 – CMPEO1: Compare Event Output Enable 1 0: Compare 1 event is disabled and will not be generated. 1: Compare 1 event is enabled and will be generated for every compare match. z Bit 8 – CMPEO0: Compare Event Output Enable 0 0: Compare 0 event is disabled and will not be generated. 1: Compare 0 event is enabled and will be generated for every compare match. z Bits 7:0 – PEREOx: Periodic Interval x Event Output Enable 0: Periodic Interval m event is disabled and will not be generated. 1: Periodic Interval m event is enabled and will be generated. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 223 19.8.3.3 Mode 2 Name: EVCTRL Offset: 0x04 Reset: 0x0000 Property: Write-Protected, Enabled-Protected Bit 15 14 13 12 11 10 9 OVFEO Access 8 ALARMEO0 R/W R R R R R R R/W Reset 0 0 0 0 0 0 0 0 Bit 7 6 5 4 3 2 1 0 PEREO7 PEREO6 PEREO5 PEREO4 PEREO3 PEREO2 PEREO1 PEREO0 R/W R/W R/W R/W R/W R/W R/W R/W 0 0 0 0 0 0 0 0 Access Reset z Bit 15 – OVFEO: Overflow Event Output Enable 0: Overflow event is disabled and will not be generated. 1: Overflow event is enabled and will be generated for every overflow. z Bits 14:9 – 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. These bits will always return zero when read. z Bit 8 – ALARMEO0: Alarm 0 Event Output Enable 0: Alarm 0 event is disabled and will not be generated. 1: Alarm 0 event is enabled and will be generated for every alarm. z Bits 7:0 – PEREOx: Periodic Interval x Event Output Enable 0: Periodic Interval n event is disabled and will not be generated. 1: Periodic Interval n event is enabled and will be generated. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 224 19.8.4 Interrupt Enable Clear This register allows the user to disable an interrupt without doing a read-modify-write operation. Changes in this register will also be reflected in the Interrupt Enable Set register (INTENSET). 19.8.4.1 Mode 0 Name: INTENCLR Offset: 0x06 Reset: 0x00 Property: Write-Protected Bit Access Reset z 7 6 5 4 3 2 1 0 OVF SYNCRDY R/W R/W R R R R R R/W 0 0 0 0 0 0 0 0 CMP0 Bit 7 – OVF: Overflow Interrupt Enable 0: The Overflow interrupt is disabled. 1: The Overflow interrupt is enabled, and an interrupt request will be generated when the Overflow interrupt flag is set. Writing a zero to this bit has no effect. Writing a one to this bit will clear the Overflow Interrupt Enable bit and disable the corresponding interrupt. z Bit 6 – SYNCRDY: Synchronization Ready Interrupt Enable 0: The Synchronization Ready interrupt is disabled. 1: The Synchronization Ready interrupt is enabled, and an interrupt request will be generated when the Synchronization Ready interrupt flag is set. Writing a zero to this bit has no effect. Writing a one to this bit will clear the Synchronization Ready Interrupt Enable bit and disable the corresponding interrupt. z Bits 5:1 – 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. These bits will always return zero when read. z Bit 0 – CMP0: Compare 0 Interrupt Enable 0: The Compare 0 interrupt is disabled. 1: The Compare 0 interrupt is enabled, and an interrupt request will be generated when the Compare 0 interrupt flag is set. Writing a zero to this bit has no effect. Writing a one to this bit will clear the Compare 0 Interrupt Enable bit and disable the corresponding interrupt. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 225 19.8.4.2 Mode 1 Name: INTENCLR Offset: 0x06 Reset: 0x00 Property: Write-Protected Bit Access Reset z 7 6 5 4 3 OVF SYNCRDY R/W R/W R R R 0 0 0 0 0 2 1 0 CMP1 CMP0 R R/W R/W 0 0 0 Bit 7 – OVF: Overflow Interrupt Enable 0: The Overflow interrupt is disabled. 1: The Overflow interrupt is enabled, and an interrupt request will be generated when the Overflow interrupt flag is set. Writing a zero to this bit has no effect. Writing a one to this bit will clear the Overflow Interrupt Enable bit and disable the corresponding interrupt. z Bit 6 – SYNCRDY: Synchronization Ready Interrupt Enable 0: The Synchronization Ready interrupt is disabled. 1: The Synchronization Ready interrupt is enabled, and an interrupt request will be generated when the Synchronization Ready interrupt flag is set. Writing a zero to this bit has no effect. Writing a one to this bit will clear the Synchronization Ready Interrupt Enable bit and disable the corresponding interrupt. z Bits 5: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. These bits will always return zero when read. z Bit 1 – CMP1: Compare 1 Interrupt Enable 0: The Compare 1 interrupt is disabled. 1: The Compare 1 interrupt is enabled, and an interrupt request will be generated when the Compare 1 interrupt flag is set. Writing a zero to this bit has no effect. Writing a one to this bit will clear the Compare 1 Interrupt Enable bit and disable the corresponding interrupt. z Bit 0 – CMP0: Compare 0 Interrupt Enable 0: The Compare 0 interrupt is disabled. 1: The Compare 0 interrupt is enabled, and an interrupt request will be generated when the Compare 0 interrupt flag is set. Writing a zero to this bit has no effect. Writing a one to this bit will clear the Compare 0 Interrupt Enable bit and disable the corresponding interrupt. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 226 19.8.4.3 Mode 2 Name: INTENCLR Offset: 0x06 Reset: 0x00 Property: Write-protected Bit Access Reset z 7 6 5 4 3 2 1 0 OVF SYNCRDY R/W R/W R R R R R R/W 0 0 0 0 0 0 0 0 ALARM0 Bit 7 – OVF: Overflow Interrupt Enable 0: The Overflow interrupt is disabled. 1: The Overflow interrupt is enabled, and an interrupt request will be generated when the Overflow interrupt flag is set. Writing a zero to this bit has no effect. Writing a one to this bit will clear the Overflow Interrupt Enable bit and disable the corresponding interrupt. z Bit 6 – SYNCRDY: Synchronization Ready Interrupt Enable 0: The synchronization ready interrupt is disabled. 1: The synchronization ready interrupt is enabled, and an interrupt request will be generated when the Synchronization Ready interrupt flag is set. Writing a zero to this bit has no effect. Writing a one to this bit will clear the Synchronization Ready Interrupt Enable bit and disable the corresponding interrupt. z Bits 5:1 – 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. These bits will always return zero when read. z Bit 0 – ALARM0: Alarm 0 Interrupt Enable 0: The Alarm 0 interrupt is disabled. 1: The Alarm 0 interrupt is enabled, and an interrupt request will be generated when the Alarm 0 interrupt flag is set. Writing a zero to this bit has no effect. Writing a one to this bit disables the Alarm 0 interrupt. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 227 19.8.5 Interrupt Enable Set This register allows the user to enable an interrupt without doing a read-modify-write operation. Changes in this register will also be reflected in the Interrupt Enable Clear (INTENCLR) register. 19.8.5.1 Mode 0 Name: INTENSET Offset: 0x07 Reset: 0x00 Property: Write-Protected Bit Access Reset z 7 6 5 4 3 2 1 0 OVF SYNCRDY R/W R/W R R R R R R 0 0 0 0 0 0 0 0 CMP0 Bit 7 – OVF: Overflow Interrupt Enable 0: The overflow interrupt is disabled. 1: The overflow interrupt is enabled. Writing a zero to this bit has no effect. Writing a one to this bit will set the Overflow Interrupt Enable bit and enable the Overflow interrupt. z Bit 6 – SYNCRDY: Synchronization Ready Interrupt Enable 0: The synchronization ready interrupt is disabled. 1: The synchronization ready interrupt is enabled. Writing a zero to this bit has no effect. Writing a one to this bit will set the Synchronization Ready Interrupt Enable bit and enable the Synchronization Ready interrupt. z Bits 5:1 – 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. These bits will always return zero when read. z Bit 0 – CMP0: Compare 0 Interrupt Enable 0: The compare 0 interrupt is disabled. 1: The compare 0 interrupt is enabled. Writing a zero to this bit has no effect. Writing a one to this bit will set the Compare 0 Interrupt Enable bit and enable the Compare 0 interrupt. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 228 19.8.5.2 Mode 1 Name: INTENSET Offset: 0x07 Reset: 0x00 Property: Write-Protected Bit Access Reset z 7 6 5 4 3 OVF SYNCRDY R/W R/W R R R 0 0 0 0 0 2 1 0 CMP1 CMP0 R R/W R/W 0 0 0 Bit 7 – OVF: Overflow Interrupt Enable 0: The overflow interrupt is disabled. 1: The overflow interrupt is enabled. Writing a zero to this bit has no effect. Writing a one to this bit will set the Overflow interrupt bit and enable the Overflow interrupt. z Bit 6 – SYNCRDY: Synchronization Ready Interrupt Enable 0: The synchronization ready interrupt is disabled. 1: The synchronization ready interrupt is enabled. Writing a zero to this bit has no effect. Writing a one to this bit will set the Synchronization Ready Interrupt Enable bit and enable the Synchronization Ready interrupt. z Bits 5:4 – 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. These bits will always return zero when read. z Bit 1 – CMP1: Compare 1 Interrupt Enable 0: The compare 1 interrupt is disabled. 1: The compare 1 interrupt is enabled. Writing a zero to this bit has no effect. Writing a one to this bit will set the Compare 1 Interrupt Enable bit and enable the Compare 1 interrupt. z Bit 0 – CMP0: Compare 0 Interrupt Enable 0: The compare 0 interrupt is disabled. 1: The compare 0 interrupt is enabled. Writing a zero to this bit has no effect. Writing a one to this bit will set the Compare 0 Interrupt Enable bit and enable the Compare 0 interrupt. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 229 19.8.5.3 Mode 2 Name: INTENSET Offset: 0x07 Reset: 0x00 Property: Write-Protected Bit Access Reset z 7 6 5 4 3 2 1 0 OVF SYNCRDY R/W R/W R R R R R R/W 0 0 0 0 0 0 0 0 ALARM0 Bit 7 – OVF: Overflow Interrupt Enable 0: The overflow interrupt is disabled. 1: The overflow interrupt is enabled. Writing a zero to this bit has no effect. Writing a one to this bit will set the Overflow Interrupt Enable bit and enable the Overflow interrupt. z Bit 6 – SYNCRDY: Synchronization Ready Interrupt Enable 0: The synchronization ready interrupt is disabled. 1: The synchronization ready interrupt is enabled. Writing a zero to this bit has no effect. Writing a one to this bit will set the Synchronization Ready Interrupt bit and enable the Synchronization Ready interrupt. Reading this bit returns the state of the synchronization ready interrupt enable. z Bits 5:1 – 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. These bits will always return zero when read. z Bit 0 – ALARM0: Alarm0 Interrupt Enable 0: The alarm 0 interrupt is disabled. 1: The alarm 0 interrupt is enabled. Writing a zero to this bit has no effect. Writing a one to this bit will set the Alarm 0 Interrupt Enable bit and enable the Alarm 0 interrupt. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 230 19.8.6 Interrupt Flag Status and Clear 19.8.6.1 Mode 0 Name: INTFLAG Offset: 0x08 Reset: 0x00 Property: - Bit Access Reset z 7 6 5 4 3 2 1 0 OVF SYNCRDY R/W R/W R R R R R R/W 0 0 0 0 0 0 0 0 CMP0 Bit 7 – OVF: Overflow This flag is cleared by writing a one to the flag. This flag is set on the next CLK_RTC_CNT cycle after an overflow condition occurs, and an interrupt request will be generated ifINTENCLR/SET.OVF is one. Writing a zero to this bit has no effect. Writing a one to this bit clears the Overflow interrupt flag. z Bit 6 – SYNCRDY: Synchronization Ready This flag is cleared by writing a one to the flag. This flag is set on a 1-to-0 transition of the Synchronization Busy bit in the Status register (STATUS.SYNCBUSY), except when caused by Enable or software Reset, and an interrupt request will be generated if INTENCLR/SET.SYNCRDY is one. Writing a zero to this bit has no effect. Writing a one to this bit clears the Synchronization Ready interrupt flag. z , and an interrupt request will be generated Bits 5:1 – 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. These bits will always return zero when read. z Bit 0 – CMP0: Compare 0 This flag is cleared by writing a one to the flag. This flag is set on the next CLK_RTC_CNT cycle after a match with the compare condition, and an interrupt request will be generated if INTENCLR/SET.COMP0 is one. Writing a zero to this bit has no effect. Writing a one to this bit clears the Compare 0 interrupt flag. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 231 19.8.6.2 Mode 1 Name: INTFLAG Offset: 0x08 Reset: 0x00 Property: - Bit Access Reset z 7 6 5 4 3 OVF SYNCRDY R/W R/W R R R 0 0 0 0 0 2 1 0 CMP1 CMP0 R R/W R/W 0 0 0 Bit 7 – OVF: Overflow This flag is cleared by writing a one to the flag. This flag is set on the next CLK_RTC_CNT cycle after an overflow condition occurs, and an interrupt request will be generated ifINTENCLR/SET.OVF is one. Writing a zero to this bit has no effect. Writing a one to this bit clears the Overflow interrupt flag. z Bit 6 – SYNCRDY: Synchronization Ready This flag is cleared by writing a one to the flag. This flag is set on a 1-to-0 transition of the Synchronization Busy bit in the Status register (STATUS.SYNCBUSY), except when caused by Enable or software Reset, and an interrupt request will be generated if INTENCLR/SET.SYNCRDY is one. Writing a zero to this bit has no effect. Writing a one to this bit clears the Synchronization Ready interrupt flag. z , and an interrupt request will be generatedBits 5: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. These bits will always return zero when read. z Bit 1 – CMP1: Compare 1 This flag is cleared by writing a one to the flag. This flag is set on the next CLK_RTC_CNT cycle after a match with the compare condition, and an interrupt request will be generated if INTENCLR/SET.COMP1 is one. Writing a zero to this bit has no effect. Writing a one to this bit clears the Compare 1 interrupt flag. z Bit 0 – CMP0: Compare 0 This flag is cleared by writing a one to the flag. This flag is set on the next CLK_RTC_CNT cycle after a match with the compare condition, and an interrupt request will be generated if INTENCLR/SET.COMP0 is one. Writing a zero to this bit has no effect. Writing a one to this bit clears the Compare 0 interrupt flag. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 232 19.8.6.3 Mode 2 Name: INTFLAG Offset: 0x08 Reset: 0x00 Property: – Bit Access Reset z 7 6 5 4 3 2 1 0 OVF SYNCRDY R/W R/W R R R R R R/W 0 0 0 0 0 0 0 0 ALARM0 Bit 7 – OVF: Overflow This flag is cleared by writing a one to the flag. This flag is set on the next CLK_RTC_CNT cycle after an overflow condition occurs, and an interrupt request will be generated ifINTENCLR/SET.OVF is one. Writing a zero to this bit has no effect. Writing a one to this bit clears the Overflow interrupt flag. z Bit 6 – SYNCRDY: Synchronization Ready This flag is cleared by writing a one to the flag. This flag is set on a 1-to-0 transition of the Synchronization Busy bit in the Status register (STATUS.SYNCBUSY), except when caused by Enable or software Reset, and an interrupt request will be generated if INTENCLR/SET.SYNCRDY is one. Writing a zero to this bit has no effect. Writing a one to this bit clears the Synchronization Ready interrupt flag. z , and an interrupt request will be generatedBits 5:1 – 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. These bits will always return zero when read. z Bit 0 – ALARM0: Alarm 0 This flag is cleared by writing a one to the flag. This flag is set on the next CLK_RTC_CNT cycle after a match with ALARM0 condition occurs, and an interrupt request will be generated if INTENCLR/SET.ALARM0 is also one. Writing a zero to this bit has no effect. Writing a one to this bit clears the Alarm 0 interrupt flag. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 233 19.8.7 Status Name: STATUS Offset: 0x0A Reset: 0x00 Property: – Bit 7 6 5 4 3 2 1 0 SYNCBUSY Access R R R R R R R R Reset 0 0 0 0 0 0 0 0 z Bit 7 – SYNCBUSY: Synchronization Busy This bit is cleared when the synchronization of registers between the clock domains is complete. This bit is set when the synchronization of registers between clock domains is started. z Bits 6:0 – 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. These bits will always return zero when read. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 234 19.8.8 Debug Control Name: DBGCTRL Offset: 0x0B Reset: 0x00 Property: – Bit 7 6 5 4 3 2 1 0 DBGRUN Access R R R R R R R R/W Reset 0 0 0 0 0 0 0 0 z Bits 7:1 – 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. These bits will always return zero when read. z Bit 0 – DBGRUN: Run During Debug This bit is not reset by a software reset. Writing a zero to this bit causes the RTC to halt during debug mode. Writing a one to this bit allows the RTC to continue normal operation during debug mode. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 235 19.8.9 Frequency Correction Name: FREQCORR Offset: 0x0C Reset: 0x00 Property: Write-Protected, Write-Synchronized Bit 7 6 5 4 SIGN Access Reset 3 2 1 0 VALUE[6:0] R/W R/W R/W R/W R/W R/W R/W R/W 0 0 0 0 0 0 0 0 z Bit 7 – SIGN: Correction Sign 0: The correction value is positive, i.e., frequency will be increased. 1: The correction value is negative, i.e., frequency will be decreased. z Bits 6:0 – VALUE[6:0]: Correction Value These bits define the amount of correction applied to the RTC prescaler. 0: Correction is disabled and the RTC frequency is unchanged. 1–127: The RTC frequency is adjusted according to the value. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 236 19.8.10 Counter Value 19.8.10.1 Mode 0 Name: COUNT Offset: 0x10 Reset: 0x00000000 Property: Write-Protected, Write-Synchronized, Read-Synchronized Bit 31 30 29 28 27 26 25 24 COUNT[31:24] Access R/W R/W R/W R/W R/W R/W R/W R/W Reset 0 0 0 0 0 0 0 0 Bit 23 22 21 20 19 18 17 16 COUNT[23:16] Access R/W R/W R/W R/W R/W R/W R/W R/W Reset 0 0 0 0 0 0 0 0 Bit 15 14 13 12 11 10 9 8 COUNT[15:8] Access R/W R/W R/W R/W R/W R/W R/W R/W Reset 0 0 0 0 0 0 0 0 Bit 7 6 5 4 3 2 1 0 COUNT[7:0] Access Reset z R/W R/W R/W R/W R/W R/W R/W R/W 0 0 0 0 0 0 0 0 Bits 31:0 – COUNT[31:0]: Counter Value These bits define the value of the 32-bit RTC counter. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 237 19.8.10.2 Mode 1 Name: COUNT Offset: 0x10 Reset: 0x0000 Property: Write-Protected, Write-Synchronized, Read-Synchronized Bit 15 14 13 12 11 10 9 8 COUNT[15:8] Access R/W R/W R/W R/W R/W R/W R/W R/W Reset 0 0 0 0 0 0 0 0 Bit 7 6 5 4 3 2 1 0 COUNT[7:0] Access Reset z R/W R/W R/W R/W R/W R/W R/W R/W 0 0 0 0 0 0 0 0 Bits 15:0 – COUNT[15:0]: Counter Value These bits define the value of the 16-bit RTC counter. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 238 19.8.11 Clock Value 19.8.11.1 Mode 2 Name: CLOCK Offset: 0x10 Reset: 0x00000000 Property: Write-Protected, Write-Synchronized, Read-Synchronized Bit 31 30 29 28 27 26 25 YEAR[5:0] Access 24 MONTH[3:2] R/W R/W R/W R/W R/W R/W R/W R/W Reset 0 0 0 0 0 0 0 0 Bit 23 22 21 20 19 18 17 16 MONTH[1:0] Access DAY[4:0] HOUR[4] R/W R/W R/W R/W R/W R/W R/W R/W Reset 0 0 0 0 0 0 0 0 Bit 15 14 13 12 11 10 9 8 HOUR[3:0] Access MINUTE[5:2] R/W R/W R/W R/W R/W R/W R/W R/W Reset 0 0 0 0 0 0 0 0 Bit 7 6 5 4 3 2 1 0 MINUTE[1:0] Access R/W R/W R/W R/W R/W R/W R/W R/W 0 0 0 0 0 0 0 0 Reset z SECOND[5:0] Bits 31:26 – YEAR[5:0]: Year The year offset with respect to the reference year (defined in software). The year is considered a leap year if YEAR[1:0] is zero. z Bits 25:22 – MONTH[3:0]: Month 1 – January 2 – February … 12 – December z Bits 21:17 – DAY[4:0]: Day Day starts at 1 and ends at 28, 29, 30 or 31, depending on the month and year. z Bits 16:12 – HOUR[4:0]: Hour When CTRL.CLKREP is zero, the Hour bit group is in 24-hour format, with values 0-23. When CTRL.CLKREP is one, HOUR[3:0] has values 1-12 and HOUR[4] represents AM (0) or PM (1). z Bits 11:6 – MINUTE[5:0]: Minute 0 – 59. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 239 z Bits 5:0 – SECOND[5:0]: Second 0– 59. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 240 19.8.12 Counter Period 19.8.12.1 Mode 1 Name: PER Offset: 0x14 Reset: 0x0000 Property: Write-Protected, Write-Synchronized Bit 15 14 13 12 11 10 9 8 PER[15:8] Access R/W R/W R/W R/W R/W R/W R/W R/W Reset 0 0 0 0 0 0 0 0 Bit 7 6 5 4 3 2 1 0 PER[7:0] Access Reset z R/W R/W R/W R/W R/W R/W R/W R/W 0 0 0 0 0 0 0 0 Bits 15:0 – PER[15:0]: Counter Period These bits define the value of the 16-bit RTC period. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 241 19.8.13 Compare n Value 19.8.13.1 Mode 0 Name: COMPn Offset: 0x18 + n*0x4 [n=0..3] Reset: 0x00000000 Property: Write-Protected, Write-Synchronized Bit 31 30 29 28 27 26 25 24 COMP[31:24] Access R/W R/W R/W R/W R/W R/W R/W R/W Reset 0 0 0 0 0 0 0 0 Bit 23 22 21 20 19 18 17 16 COMP[23:16] Access R/W R/W R/W R/W R/W R/W R/W R/W Reset 0 0 0 0 0 0 0 0 Bit 15 14 13 12 11 10 9 8 COMP[15:8] Access R/W R/W R/W R/W R/W R/W R/W R/W Reset 0 0 0 0 0 0 0 0 Bit 7 6 5 4 3 2 1 0 COMP[7:0] Access Reset z R/W R/W R/W R/W R/W R/W R/W R/W 0 0 0 0 0 0 0 0 Bits 31:0 – COMP[31:0]: Compare Value The 32-bit value of COMPn is continuously compared with the 32-bit COUNT value. When a match occurs, the Compare n interrupt flag in the Interrupt Flag Status and Clear register (INTFLAG.CMPn) is set on the next counter cycle, and the counter value is cleared if CTRL.MATCHCLR is one. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 242 19.8.13.2 Mode 1 Name: COMPn Offset: 0x18 + n*0x2 [n=0..5] Reset: 0x0000 Property: Write-Protected, Write-Synchronized Bit 15 14 13 12 11 10 9 8 COMP[15:8] Access R/W R/W R/W R/W R/W R/W R/W R/W Reset 0 0 0 0 0 0 0 0 Bit 7 6 5 4 3 2 1 0 COMP[7:0] Access Reset z R/W R/W R/W R/W R/W R/W R/W R/W 0 0 0 0 0 0 0 0 Bits 15:0 – COMP[15:0]: Compare Value The 16-bit value of COMPn is continuously compared with the 16-bit COUNT value. When a match occurs, the Compare n interrupt flag in the Interrupt Flag Status and Clear register (INTFLAG.CMPn) is set on the next counter cycle. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 243 19.8.14 Alarm n Value 19.8.14.1 Mode 2 Name: ALARMn Offset: 0x18 + n*0x8 [n=0..3] Reset: 0x00000000 Property: Write-Protected, Write-Synchronized Bit 31 30 29 28 27 26 25 YEAR[5:0] Access 24 MONTH[3:2] R/W R/W R/W R/W R/W R/W R/W R/W Reset 0 0 0 0 0 0 0 0 Bit 23 22 21 20 19 18 17 16 MONTH[1:0] Access DAY[4:0] HOUR[4] R/W R/W R/W R/W R/W R/W R/W R/W Reset 0 0 0 0 0 0 0 0 Bit 15 14 13 12 11 10 9 8 HOUR[3:0] Access MINUTE[5:2] R/W R/W R/W R/W R/W R/W R/W R/W Reset 0 0 0 0 0 0 0 0 Bit 7 6 5 4 3 2 1 0 MINUTE[1:0] Access Reset SECOND[5:0] R/W R/W R/W R/W R/W R/W R/W R/W 0 0 0 0 0 0 0 0 The 32-bit value of ALARMn is continuously compared with the 32-bit CLOCK value, based on the masking set by MASKn.SEL. When a match occurs, the Alarm n interrupt flag in the Interrupt Flag Status and Clear register (INTFLAG.ALARMn) is set on the next counter cycle, and the counter is cleared if CTRL.MATCHCLR is one. z Bits 31:26 – YEAR[5:0]: Year The alarm year. Years are only matched if MASKn.SEL is 6. z Bits 25:22 – MONTH[3:0]: Month The alarm month. Months are matched only if MASKn.SEL is greater than 4. z Bits 21:17 – DAY[4:0]: Day The alarm day. Days are matched only if MASKn.SEL is greater than 3. z Bits 16:12 – HOUR[4:0]: Hour The alarm hour. Hours are matched only if MASKn.SEL is greater than 2. z Bits 11:6 – MINUTE[5:0]: Minute The alarm minute. Minutes are matched only if MASKn.SEL is greater than 1. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 244 z Bits 5:0 – SECOND[5:0]: Second The alarm second. Seconds are matched only if MASKn.SEL is greater than 0. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 245 19.8.15 Alarm n Mask 19.8.15.1 Mode 2 Name: MASKn Offset: 0x1C + n*0x8 [n=0..3] Reset: 0x00 Property: Write-Protected, Write-Synchronized Bit 7 6 5 4 3 2 1 0 SEL[2:0] Access R R R R R R/W R/W R/W Reset 0 0 0 0 0 0 0 0 z Bits 7:3 – 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. These bits will always return zero when read. z Bits 2:0 – SEL[2:0]: Alarm Mask Selection These bits define which bit groups of Alarm n are valid. Table 19-10. Alarm Mask Selection SEL[2:0] Alarm Mask Selection Description 0x0 OFF Alarm Disabled 0x1 SS Match seconds only 0x2 MMSS Match seconds and minutes only 0x3 HHMMSS Match seconds, minutes and hours only 0x4 DDHHMMSS Match seconds, minutes, hours and days only 0x5 MMDDHHMMSS Match seconds, minutes, hours, days and months only 0x6 YYMMDDHHMMSS Match seconds, minutes, hours, days, months and years 0x7 - Reserved Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 246 20. EIC – External Interrupt Controller 20.1 Overview The External Interrupt Controller (EIC) allows external pins to be configured as interrupt lines. Each interrupt line can be individually masked and can generate an interrupt on rising, falling or both edges, or on high or low levels. Each external pin has a configurable filter to remove spikes. Each external pin can also be configured to be asynchronous in order to wake up the device from sleep modes where all clocks have been disabled. External pins can also generate an event. A separate non-maskable interrupt (NMI) is also supported. It has properties similar to the other external interrupts, but is connected to the NMI request of the CPU, enabling it to interrupt any other interrupt mode. 20.2 20.3 Features z 16 external pins, plus 1 non-maskable pin z Dedicated interrupt line for each pin z Individually maskable interrupt lines z Interrupt on rising, falling or both edges z Interrupt on high or low levels z Asynchronous interrupts for sleep modes without clock z Filtering of external pins z Event generation z Configurable wake-up for sleep modes Block Diagram Figure 20-1. EIC Block Diagram FILTENx SENSEx[2:0] intreq_extint[x] Interrupt EXTINTx Filter Edge/Level Detection inwake_extint[x] Wake evt_extint[x] Event NMIFILTEN NMISENSE[2:0] intreq_nmi Interrupt NMI Filter Edge/Level Detection inwake_nmi Wake Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 247 20.4 Signal Description Signal Name Type Description EXTINT[15..0] Digital Input External interrupt pin NMI Digital Input Non-maskable interrupt pin Please refer to “I/O Multiplexing and Considerations” on page 15 for details on the pin mapping for this peripheral. One signal can be mapped on several pins. 20.5 Product Dependencies In order to use this EIC, other parts of the system must be configured correctly, as described below. 20.5.1 I/O Lines Using the EIC’s I/O lines requires the I/O pins to be configured. Refer to “PORT” on page 289 for details. 20.5.2 Power Management All interrupts are available in all sleep modes, but the EIC can be configured to automatically mask some interrupts in order to prevent device wake-up. The EIC will continue to operate in any sleep mode where the selected source clock is running. The EIC’s interrupts can be used to wake up the device from sleep modes. Events connected to the Event System can trigger other operations in the system without exiting sleep modes. Refer to “PM – Power Manager” on page 105 for details on the different sleep modes. 20.5.3 Clocks The EIC bus clock (CLK_EIC_APB) can be enabled and disabled in the Power Manager, and the default state of CLK_EIC_APB can be found in the Peripheral Clock Masking section in “PM – Power Manager” on page 105. A generic clock (GCLK_EIC) is required to clock the peripheral. This clock must be configured and enabled in the Generic Clock Controller before using the peripheral. Please refer to “GCLK – Generic Clock Controller” on page 83 for details. This generic clock is asynchronous to the user interface clock (CLK_EIC_APB). Due to this asynchronicity, writes to certain registers will require synchronization between the clock domains. Please refer to “Synchronization” on page 252 for further details. 20.5.4 Interrupts There are two interrupt request lines, one for the external interrupts (EXTINT) and one for non-maskable interrupt (NMI). The EXTINT interrupt request line is connected to the interrupt controller. Using the EIC interrupt requires the interrupt controller to be configured first. Please refer to “Nested Vector Interrupt Controller” on page 28 for details. The NMI interrupt request line is also connected to the interrupt controller, but does not require the interrupt to be configured. 20.5.5 Events The events are connected to the Event System. Using the events requires the Event System to be configured first. Please refer to “EVSYS – Event System” on page 314 for details. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 248 20.5.6 Debug Operation When the CPU is halted in debug mode, the EIC continues normal operation. If the EIC is configured in a way that requires it to be periodically serviced by the CPU through interrupts or similar, improper operation or data loss may result during debugging. 20.5.7 Register Access Protection All registers with write-access are optionally write-protected by the Peripheral Access Controller (PAC), except the following registers: z Interrupt Flag Status and Clear register (INTFLAG) z Non-Maskable Interrupt Flag Status and Clear register (NMIFLAG) Write-protection is denoted by the Write-Protected property in the register description. Write-protection does not apply to accesses through an external debugger. Refer to “PAC – Peripheral Access Controller” on page 31 for details. 20.5.8 Analog Connections Not applicable. 20.6 Functional Description 20.6.1 Principle of Operation The EIC detects edge or level condition to generate interrupts to the CPU Interrupt Controller or events to the Event System. Each external interrupt pin (EXTINT) can be filtered using majority vote filtering, clocked by generic clock GCLK_EIC. 20.6.2 Basic Operation 20.6.2.1 Initialization The EIC must be initialized in the following order: 1. Enable CLK_EIC_APB 2. If edge detection or filtering is required, GCLK_EIC must be enabled 3. Write the EIC configuration registers (NMICTRL, EVCTRL, WAKEUP, CONFIGy) 4. Enable the EIC When NMI is used, GCLK_EIC must be enabled after EIC configuration 20.6.2.2 Enabling, Disabling and Resetting The EIC is enabled by writing a one to the Enable bit in the Control register (CTRL.ENABLE). The EIC is disabled by writing a zero to CTRL.ENABLE. The EIC is reset by writing a one to the Software Reset bit in the Control register (CTRL.SWRST). All registers in the EIC will be reset to their initial state, and the EIC will be disabled. Refer to CTRL register for details. 20.6.3 External Pin Processing Each external pin can be configured to generate an interrupt/event on edge detection (rising, falling or both edges) or level detection (high or low). The sense of external pins is configured by writing the Interrupt Sense x bits in the Config y register (CONFIGy.SENSEx). The corresponding interrupt flag (INTFLAG.EXTINT[x]) in the Interrupt Flag Status and Clear register (INTFLAG) is set when the interrupt condition is met (CONFIGy.SENSEx must be different from zero). Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 249 When the interrupt has been cleared in edge-sensitive mode, INTFLAG.EXTINT[x] will only be set if a new interrupt condition is met. In level-sensitive mode, when interrupt has been cleared, INTFLAG.EXTINT[x] will be set immediately if the EXTINTx pin still matches the interrupt condition. Each external pin can be filtered by a majority vote filtering, clocked by GCLK_EIC. Filtering is enabled if bit Filter Enable x in the Configuration y register (CONFIGy.FILTENx) is written to one. The majority vote filter samples the external pin three times with GCLK_EIC and outputs the value when two or more samples are equal. Table 20-1. Majority Vote Filter Samples [0, 1, 2] Filter Output [0,0,0] 0 [0,0,1] 0 [0,1,0] 0 [0,1,1] 1 [1,0,0] 0 [1,0,1] 1 [1,1,0] 1 [1,1,1] 1 When an external interrupt is configured for level detection, or if filtering is disabled, detection is made asynchronously, and GCLK_EIC is not required. If filtering or edge detection is enabled, the EIC automatically requests the GCLK_EIC to operate (GCLK_EIC must be enabled in the GCLK module, see “GCLK – Generic Clock Controller” on page 83 for details). If level detection is enabled, GCLK_EIC is not required, but interrupt and events can still be generated. Figure 20-2. Interrupt detections GCLK_EIC CLK_EIC_APB EXTINTx intreq_extint[x] (level detection / no filter) intreq_extint[x] (level detection / filter) No interrupt intreq_extint[x] (edge detection / no filter) intreq_extint[x] (edge detection / filter) No interrupt clear INTFLAG.EXTINT[x] The detection delay depends on the detection mode. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 250 Table 20-2. Interrupt Latency Detection Mode Latency (Worst Case) Level without filter 3 CLK_EIC_APB periods Level with filter 4 GCLK_EIC periods + 3 CLK_EIC_APB periods Edge without filter 4 GCLK_EIC periods + 3 CLK_EIC_APB periods Edge with filter 6 GCLK_EIC periods + 3 CLK_EIC_APB periods 20.6.4 Additional Features The non-maskable interrupt pin can also generate an interrupt on edge or level detection, but it is configured with the dedicated NMI Control register (NMICTRL). To select the sense for NMI, write to the NMISENSE bit group in the NMI Control register (NMICTRL.NMISENSE). NMI filtering is enabled by writing a one to the NMI Filter Enable bit (NMICTRL.NMIFILTEN). NMI detection is enabled only by the NMICTRL.NMISENSE value, and the EIC is not required to be enabled. After reset, NMI is configured to no detection mode. ----- When an NMI is detected, the non-maskable interrupt flag in the NMI Flag Status and Clear register is set (NMIFLAG.NMI). NMI interrupt generation is always enabled, and NMIFLAG.NMI generates an interrupt request when set. 20.6.5 Interrupts The EIC has the following interrupt sources: z External interrupt pins (EXTINTx). See “Basic Operation” on page 249 z Non-maskable interrupt pin (NMI). See “Additional Features” on page 251 Each interrupt source has an interrupt flag associated with it. The interrupt flag in the Interrupt Flag Status and Clear register (INTFLAG) is set when an interrupt condition occurs (NMIFLAG for NMI). Each interrupt, except NMI, can be individually enabled by writing a one to the corresponding bit in the Interrupt Enable Set register (INTENSET), and disabled by writing a one to the corresponding bit in the Interrupt Enable Clear register (INTENCLR). An interrupt request is generated when the interrupt flag is set and the corresponding interrupt is enabled. The interrupt request remains active until the interrupt flag is cleared, the interrupt is disabled or the EIC is reset. See the INTFLAG register for details on how to clear interrupt flags. The EIC has one common interrupt request line for all the interrupt sources (except the NMI interrupt request line). Refer to “Processor and Architecture” on page 27 for details. The user must read the INTFLAG (or NMIFLAG) register to determine which interrupt condition is present. Note that interrupts must be globally enabled for interrupt requests to be generated. Refer to “Processor and Architecture” on page 27 for details. 20.6.6 Events The EIC can generate the following output events: z External event from pin (EXTINTx). Writing a one to an Event Output Control register (EVCTRLEXTINTEO) enables the corresponding output event. Writing a zero to this bit disables the corresponding output event. Refer to “EVSYS – Event System” on page 314 for details on configuring the Event System. When the condition on pin EXTINTx matches the configuration in the CONFIGy register, the corresponding event is generated, if enabled. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 251 20.6.7 Sleep Mode Operation In sleep modes, an EXTINTx pin can wake up the device if the corresponding condition matches the configuration in CONFIGy register. Writing a one to a Wake-Up Enable bit (WAKEUP.WAKEUPEN[x]) enables the wake-up from pin EXTINTx. Writing a zero to a Wake-Up Enable bit (WAKEUP.WAKEUPEN[x]) disables the wake-up from pin EXTINTx. Figure 20-3. Wake-Up Operation Example (High-Level Detection, No Filter, WAKEUPEN[x]=1) CLK_EIC_APB EXTINTx intwake_extint[x] intreq_extint[x] clear INTFLAG.EXTINT[x] return to sleep mode 20.6.8 Synchronization Due to the asynchronicity between CLK_EIC_APB and GCLK_EIC, some registers must be synchronized when accessed. A register can require: z Synchronization when written z Synchronization when read z Synchronization when written and read z No synchronization When executing an operation that requires synchronization, the Synchronization Busy bit in the Status register (STATUS.SYNCBUSY) will be set immediately, and cleared when synchronization is complete. The synchronization Ready interrupt can be used to signal when sync is complete. This can be accessed via the Synchronization Ready interrupt flag in the Interrupt Flag Status and Clear register (INTFLAG.SYNCRDY). If an operation that requires synchronization is executed while STATUS.SYNCBUSY is one, the bus will be stalled. All operations will complete successfully, but the CPU will be stalled, and interrupts will be pending as long as the bus is stalled. The following bits need synchronization when written: z Software Reset bit in the Control register (CTRL.SWRST) z Enable bit in the Control register (CTRL.ENABLE) No register needs synchronization when written. No register needs synchronization when read. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 252 20.7 Register Summary Table 20-3. Register Summary Name Bit Pos. 0x00 CTRL 7:0 0x01 STATUS 7:0 0x02 NMICTRL 7:0 0x03 NMIFLAG 7:0 Offset ENABLE NMIFILTEN 0x04 7:0 EXTINTEO[7:0] 15:8 EXTINTEO[15:8] EVCTRL 23:16 0x07 31:24 0x08 7:0 EXTINT[7:0] 15:8 EXTINT[15:8] 0x09 0x0A INTENCLR 23:16 0x0B 31:24 0x0C 7:0 EXTINT[7:0] 15:8 EXTINT[15:8] 0x0D 0x0E INTENSET 23:16 0x0F 31:24 0x10 7:0 EXTINT[7:0] 15:8 EXTINT[15:8] 0x11 0x12 INTFLAG 0x13 23:16 31:24 0x14 7:0 WAKEUPEN[7:0] 0x15 15:8 WAKEUPEN[15:8] 0x16 NMISENSE[2:0] NMI 0x05 0x06 WAKEUP 23:16 0x17 31:24 0x18 7:0 FILTEN1 SENSE1[2:0] FILTEN0 SENSE0[2:0] 15:8 FILTEN3 SENSE3[2:0] FILTEN2 SENSE2[2:0] 0x19 0x1A CONFIG0 23:16 FILTEN5 SENSE5[2:0] FILTEN4 SENSE4[2:0] 0x1B 31:24 FILTEN7 SENSE7[2:0] FILTEN6 SENSE6[2:0] 0x1C 7:0 FILTEN9 SENSE9[2:0] FILTEN8 SENSE8[2:0] 0x1D 0x1E 0x1F SWRST SYNCBUSY CONFIG1 15:8 FILTEN11 SENSE11[2:0] FILTEN10 SENSE10[2:0] 23:16 FILTEN13 SENSE13[2:0] FILTEN12 SENSE12[2:0] 31:24 FILTEN15 SENSE15[2:0] FILTEN14 SENSE14[2:0] Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 253 20.8 Register Description Registers can be 8, 16 or 32 bits wide. Atomic 8-, 16- and 32-bit accesses are supported. In addition, the 8-bit quarters and 16-bit halves of a 32-bit register and the 8-bit halves of a 16-bit register can be accessed directly. Some registers are optionally write-protected by the Peripheral Access Controller (PAC). Write-protection is denoted by the Write-protected property in each individual register description. Please refer to “Register Access Protection” on page 249 for details. Some registers require synchronization when read and/or written. Synchronization is denoted by the Synchronized property in each individual register description. Please refer to “Synchronization” on page 252 for details. Some registers are enable-protected, meaning they can be written only when the EIC is disabled. Enable-protection is denoted by the Enabled-Protected property in each individual register description. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 254 20.8.1 Control Name: CTRL Offset: 0x00 Reset: 0x00 Property: Write-Protected,Write-Synchronized Bit 7 6 5 4 3 2 1 0 ENABLE SWRST Access R R R R R R R/W R/W Reset 0 0 0 0 0 0 0 0 z Bits 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. These bits will always return zero when read. z Bit 1 – ENABLE: Enable 0: The EIC is disabled. 1: The EIC is enabled. Due to synchronization, there is delay from writing CTRL.ENABLE until the peripheral is enabled/disabled. The value written to CTRL.ENABLE will read back immediately, and the Synchronization Busy bit in the Status register (STATUS.SYNCBUSY) will be set. STATUS.SYNCBUSY will be cleared when the operation is complete. z Bit 0 – SWRST: Software Reset 0: There is no ongoing reset operation. 1: The reset operation is ongoing. Writing a zero to this bit has no effect. Writing a one to this bit resets all registers in the EIC to their initial state, and the EIC will be disabled. Writing a one to CTRL.SWRST will always take precedence, meaning that all other writes in the same write operation will be discarded. Due to synchronization, there is a delay from writing CTRL.SWRST until the reset is complete. CTRL.SWRST and STATUS.SYNCBUSY will both be cleared when the reset is complete. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 255 20.8.2 Status Name: STATUS Offset: 0x01 Reset: 0x00 Property: - Bit 7 6 5 4 3 2 1 0 SYNCBUSY Access R R R R R R R R Reset 0 0 0 0 0 0 0 0 z Bit 7 – SYNCBUSY: Synchronization Busy This bit is cleared when the synchronization of registers between the clock domains is complete. This bit is set when the synchronization of registers between clock domains is started. z Bits 6:0 – 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. These bits will always return zero when read. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 256 20.8.3 Non-Maskable Interrupt Control Name: NMICTRL Offset: 0x02 Reset: 0x00 Property: Write-Protected Bit 7 6 5 4 3 2 NMIFILTEN 1 0 NMISENSE[2:0] Access R R R R R/W R/W R/W R/W Reset 0 0 0 0 0 0 0 0 z Bits 7:4 – 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. These bits will always return zero when read. z Bit 3 – NMIFILTEN: Non-Maskable Interrupt Filter Enable 0: NMI filter is disabled. 1: NMI filter is enabled. z Bits 2:0 – NMISENSE: Non-Maskable Interrupt Sense These bits define on which edge or level the NMI triggers. Table 20-4. NMI Sense Configuration NMISENSE Name Description 0x0 NONE No detection 0x1 RISE Rising-edge detection 0x2 FALL Falling-edge detection 0x3 BOTH Both-edges detection 0x4 HIGH High-level detection 0x5 LOW Low-level detection 0x6-0x7 - Reserved Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 257 20.8.4 Non-Maskable Interrupt Flag Status and Clear Name: NMIFLAG Offset: 0x03 Reset: 0x00 Property: - Bit 7 6 5 4 3 2 1 0 NMI Access R R R R R R R R/W Reset 0 0 0 0 0 0 0 0 z Bits 7:1 – 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. These bits will always return zero when read. z Bit 0 – NMI: Non-Maskable Interrupt This flag is cleared by writing a one to it. This flag is set when the NMI pin matches the NMI sense configuration, and will generate an interrupt request. Writing a zero to this bit has no effect. Writing a one to this bit clears the non-maskable interrupt flag. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 258 20.8.5 Event Control Name: EVCTRL Offset: 0x04 Reset: 0x00000000 Property: Write-Protected Bit 31 30 29 28 27 26 25 24 Access R R R R R R R R Reset 0 0 0 0 0 0 0 0 Bit 23 22 21 20 19 18 17 16 Access R R R R R R R R Reset 0 0 0 0 0 0 0 0 Bit 15 14 13 12 11 10 9 8 EXTINTEO[15:8] Access R/W R/W R/W R/W R/W R/W R/W R/W Reset 0 0 0 0 0 0 0 0 Bit 7 6 5 4 3 2 1 0 EXTINTEO[7:0] Access Reset R/W R/W R/W R/W R/W R/W R/W R/W 0 0 0 0 0 0 0 0 z Bits 31:16 – 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. These bits will always return zero when read. z Bits 15:0 – EXTINTEO: External Interrupt x Event Output Enable These bits indicate whether the event associated withthe EXTINTx pin is enabled or not togenerated for every detection. 0: Event from pin EXTINTx is disabled. 1: Event from pin EXTINTx is enabled. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 259 20.8.6 Interrupt Enable Clear This register allows the user to disable an interrupt without doing a read-modify-write operation. Changes in this register will also be reflected in the Interrupt Enable Set register (INTENSET). Name: INTENCLR Offset: 0x08 Reset: 0x00000000 Property: Write-Protected Bit 31 30 29 28 27 26 25 24 Access R R R R R R R R Reset 0 0 0 0 0 0 0 0 Bit 23 22 21 20 19 18 17 16 Access R R R R R R R R Reset 0 0 0 0 0 0 0 0 Bit 15 14 13 12 11 10 9 8 EXTINT[15:8] Access R/W R/W R/W R/W R/W R/W R/W R/W Reset 0 0 0 0 0 0 0 0 Bit 7 6 5 4 3 2 1 0 EXTINT[7:0] Access Reset R/W R/W R/W R/W R/W R/W R/W R/W 0 0 0 0 0 0 0 0 z Bits 31:16 – 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. These bits will always return zero when read. z Bits 15:0 – EXTINT: External Interrupt x Enable 0: The external interrupt x is disabled. 1: The external interrupt x is enabled. Writing a zero to this bit has no effect. Writing a one to this bit will clear the External Interrupt x Enable bit, which enables the external interrupt. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 260 20.8.7 Interrupt Enable Set This register allows the user to enable an interrupt without doing a read-modify-write operation. Changes in this register will also be reflected in the Interrupt Enable Clear (INTENCLR) register. Name: INTENSET Offset: 0x0C Reset: 0x00000000 Property: Write-Protected Bit 31 30 29 28 27 26 25 24 Access R R R R R R R R Reset 0 0 0 0 0 0 0 0 Bit 23 22 21 20 19 18 17 16 Access R R R R R R R R Reset 0 0 0 0 0 0 0 0 Bit 15 14 13 12 11 10 9 8 EXTINT[15:8] Access R/W R/W R/W R/W R/W R/W R/W R/W Reset 0 0 0 0 0 0 0 0 Bit 7 6 5 4 3 2 1 0 EXTINT[7:0] Access Reset R/W R/W R/W R/W R/W R/W R/W R/W 0 0 0 0 0 0 0 0 z Bits 31:16 – 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. These bits will always return zero when read. z Bits 15:0 – EXTINT: External Interrupt x Enable 0: The external interrupt x is disabled. 1: The external interrupt x is enabled. Writing a zero to this bit has no effect. Writing a one to this bit will set the External Interrupt x Enable bit, which enables the external interrupt. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 261 20.8.8 Interrupt Flag Status and Clear Name: INTFLAG Offset: 0x10 Reset: 0x00000000 Property: - Bit 31 30 29 28 27 26 25 24 Access R R R R R R R R Reset 0 0 0 0 0 0 0 0 Bit 23 22 21 20 19 18 17 16 Access R R R R R R R R Reset 0 0 0 0 0 0 0 0 Bit 15 14 13 12 11 10 9 8 EXTINT[15:8] Access R/W R/W R/W R/W R/W R/W R/W R/W Reset 0 0 0 0 0 0 0 0 Bit 7 6 5 4 3 2 1 0 EXTINT[7:0] Access Reset R/W R/W R/W R/W R/W R/W R/W R/W 0 0 0 0 0 0 0 0 z Bits 31:16 – 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. These bits will always return zero when read. z Bits 15:0 – EXTINT: External Interrupt x This flag is cleared by writing a one to it. This flag is set when EXTINTx pin matches the external interrupt sense configuration and will generate an interrupt request if INTENCLR/SET.EXTINT[x] is one. Writing a zero to this bit has no effect. Writing a one to this bit clears the External Interrupt x flag. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 262 20.8.9 Wake-Up Enable Name: WAKEUP Offset: 0x14 Reset: 0x00000000 Property: Write-Protected Bit 31 30 29 28 27 26 25 24 Access R R R R R R R R Reset 0 0 0 0 0 0 0 0 Bit 23 22 21 20 19 18 17 16 Access R R R R R R R R Reset 0 0 0 0 0 0 0 0 Bit 15 14 13 12 11 10 9 8 WAKEUPEN[15:8] Access R/W R/W R/W R/W R/W R/W R/W R/W Reset 0 0 0 0 0 0 0 0 Bit 7 6 5 4 3 2 1 0 WAKEUPEN[7:0] Access Reset R/W R/W R/W R/W R/W R/W R/W R/W 0 0 0 0 0 0 0 0 z Bits 31:16 – 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. These bits will always return zero when read. z Bits 15:0 – WAKEUPEN: External Interrupt x Wake-up Enable This bit enables or disables wake-up from sleep modes when the EXTINTx pin matches the external interrupt sense configuration. 0: Wake-up from the EXTINTx pin is disabled. 1: Wake-up from the EXTINTx pin is enabled. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 263 20.8.10 Configuration n Name: CONFIGn Offset: 0x18+n*0x4 [n=0..1] Reset: 0x00000000 Property: Write-Protected Bit 31 30 FILTEN7 Access 29 28 SENSE7[2:0] 27 26 FILTEN6 25 24 SENSE6[2:0] R/W R/W R/W R/W R/W R/W R/W R/W Reset 0 0 0 0 0 0 0 0 Bit 23 22 21 20 19 18 17 16 FILTEN5 Access SENSE5[2:0] FILTEN4 SENSE4[2:0] R/W R/W R/W R/W R/W R/W R/W R/W Reset 0 0 0 0 0 0 0 0 Bit 15 14 13 12 11 10 9 8 FILTEN3 Access SENSE3[2:0] FILTEN2 SENSE2[2:0] R/W R/W R/W R/W R/W R/W R/W R/W Reset 0 0 0 0 0 0 0 0 Bit 7 6 5 4 3 2 1 0 FILTEN1 Access Reset z SENSE1[2:0] FILTEN0 SENSE0[2:0] R/W R/W R/W R/W R/W R/W R/W R/W 0 0 0 0 0 0 0 0 Bits 31, 27, 23, 19, 15, 11, 7, 3 – FILTENx [x=7..0]: Filter x Enable 0: Filter is disabled for EXTINT[n*8+x] input. 1: Filter is enabled for EXTINT[n*8+x] input. z Bits 30:28, 26:24, 22:20, 18:16, 14:12, 10:8, 6:4, 2:0 – SENSEx[2:0] [x=7..0]: Input Sense x Configuration These bits define on which edge or level the interrupt or event for EXTINT[n*8+x] will be generated. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 264 Table 20-5. Sense Configuration SENSE Name Description 0x0 NONE No detection 0x1 RISE Rising-edge detection 0x2 FALL Falling-edge detection 0x3 BOTH Both-edges detection 0x4 HIGH High-level detection 0x5 LOW Low-level detection 0x6-0x7 - Reserved Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 265 21. NVMCTRL – Non-Volatile Memory Controller 21.1 Overview Non-volatile memory (NVM) is a reprogrammable flash memory that retains program and data storage even with power off. The NVM Controller (NVMCTRL) connects to the AHB and APB bus interfaces for system access to the NVM block. The AHB interface is used for reads and writes to the NVM block, while the APB interface is used for commands and configuration. 21.2 Features z 32-bit AHB interface for reads and writes z All NVM sections are memory mapped to the AHB, including calibration and system configuration z 32-bit APB interface for commands and control z Programmable wait states for read optimization z 16 regions can be individually protected or unprotected z Additional protection for boot loader z Supports device protection through a security bit z Interface to Power Manager for power-down of flash blocks in sleep modes z Can optionally wake up on exit from sleep or on first access z Direct-mapped cache 21.3 Block Diagram Figure 21-1. Block Diagram NVMCTRL AHB Cache NVM Interface APB 21.4 NVM Block Command and Control Signal Description Not applicable Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 266 21.5 Product Dependencies In order to use this module, other parts of the system must be configured correctly, as described below. 21.5.1 Power Management The NVMCTRL will continue to operate in any sleep mode where the selected source clock is running. The NVMCTRL’s interrupts can be used to wake up the device from sleep modes. Refer to “PM – Power Manager” on page 105 for details on the different sleep modes. The Power Manager will automatically put the NVM block into a low-power state when entering sleep mode. This is based on the Control B register (CTRLB) SLEEPPRM bit setting. Read the CTRLB register description for more details. 21.5.2 Clocks Two synchronous clocks are used by the the NVMCTRL. One is provided by the AHB bus (CLK_NVMCTRL_AHB) and the other is provided by the APB bus (CLK_NVMCTRL_APB). For higher system frequencies, a programmable number of wait states can be used to optimize performance. When changing the AHB bus frequency, the user must ensure that the NVM Controller is configured with the proper number of wait states. - 21.5.3 Interrupts The NVM Controller interrupt request line is connected to the interrupt controller. Using the NVMCTRL interrupt requires the interrupt controller to be programmed first. 21.5.4 Debug Operation When an external debugger forces the CPU into debug mode, the peripheral continues normal operation. Access to the NVM block can be protected by the security bit. In this case, the NVM block will not be accessible. See “Security Bit” on page 273 for details. 21.5.5 Register Access Protection All registers with write-access are optionally write-protected by the Peripheral Access Controller (PAC), except the following registers: z Interrupt Flag Status and Clear register (INTFLAG) z Status register (STATUS) Write-protection is denoted by the Write-Protected property in the register description. Write-protection does not apply for accesses through an external debugger. When the CPU is halted in debug mode, all write-protection is automatically disabled. Refer to “PAC – Peripheral Access Controller” on page 31 for details. 21.5.6 Analog Connections Not applicable. 21.6 Functional Description 21.6.1 Principle of Operation The NVM Controller is a slave on the AHB and APB buses. It responds to commands, read requests and write requests, based on user configuration. 21.6.1.1 Initialization After power up, the NVM Controller goes through a power-up sequence. During this time, access to the NVM Controller from the AHB bus is halted. Upon power-up completion, the NVM Controller is operational without any need for user configuration. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 267 21.6.2 Memory Organization Refer to “Product Mapping” on page 23 for memory sizes and addresses for each device. The NVM is organized into rows, where each row contains four pages, as shown in Figure 21-2. The NVM has a rowerase granularity, while the write granularity is by page. In other words, a single row erase will erase all four pages in the row, while four write operations are used to write the complete row. Figure 21-2. Row Organization Row n Page (n * 4) + 3 Page (n * 4) + 2 z r rows z p pages z wr words per row z hw half words (16-bit) in each page and in the page buffer z pw words in total z aw words reserved for auxiliary space Page (n * 4) + 1 Page (n * 4) + 0 The NVM block contains an auxiliary space that is memory mapped, as shown in Table 21-1. The auxiliary space contains factory calibration and system configuration information. This space can be read from the AHB bus in the same way as the main NVM main address space. In addition, a boot section can be allocated at the beginning of the main array, and an EEPROM section can be allocated at the end of the NVM main address space. Table 21-1. Memory Organization Memory Section Start byte address Size Main address space 0 pw words = 4pw bytes Calibration and auxiliary space 0x0080_0000 aw words = 8 bytes User row 0x0080_4000 1 row Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 268 Figure 21-3. Memory Organization Addresses are word addresses 2^21+aw Calibration and auxillary space 2^21 pw pw-1 NVM Main Address Space NVM Base Address 0 The lower rows in the NVM main address space can be allocated as a boot section by using the BOOTPROT fuses, and the upper rows can be allocated to EEPROM, as shown in Figure 21-4. The boot sections are protected by the lock bit(s) corresponding to this address space and by the BOOTPROT[2:0] fuse. The EEPROM rows can be written, regardless of the region lock status. The number of rows protected by BOOTPROT and the number of rows allocated to the EEPROM are given in Table 21-4 and Table , respectively. Figure 21-4. EEPROM and BOOT Allocation NVM Memory Address Space pw-1 pw-(EEPROM rows) x wr pw-1-(EEPROM rows) x wr EEPROM allocation Program allocation (BOOTPROT rows) x wr (BOOTPROT rows) x wr - 1 0 BOOT allocation NVM Base Address 21.6.3 Region Lock Bits The NVM block is grouped into 16 equally sized regions. The region size is dependent on the flash memory size, and is given in the table below. Each region has a dedicated lock bit preventing writing and erasing pages in the region. After production, all regions will be unlocked. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 269 Table 21-2. Region Size Memory Size, in Kbytes Region Size, in Kbytes 256 16 128 8 64 4 32 2 To lock or unlock a region, the Lock Region and Unlock Region commands are provided. Writing one of these commands will temporarily lock/unlock the region containing the address loaded in the ADDR register. ADDR can be written by software, or the automatically loaded value from a write operation can be used. The new setting will stay in effect until the next reset, or the setting can be changed again using the lock and unlock commands. The current status of the lock can be determined by reading the LOCK register. To change the default lock/unlock setting for a region, the user configuration section of the auxiliary space must be written using the Write Auxiliary Page command. Writing to the auxiliary space will take effect after the next reset. Therefore, a boot of the device is needed for changes in the lock/unlock setting to take effect. See “Product Mapping” on page 23 for auxiliary space address mapping. 21.6.4 Command and Data Interface The NVM Controller is addressable from the APB bus, while the NVM main address space is addressable from the AHB bus. Read and automatic page write operations are performed by addressing the NVM main address space directly, while other operations such as manual page writes and row erase must be performed by issuing commands through the NVM Controller. To issue a command, the CTRLA.CMD bits must be written along with the CTRLA.CMDEX value. When a command is issued, INTFLAG.READY will be cleared until the command has completed. Any commands written while INTFLAG.READY is low will be ignored. Read the CTRLA register description for more details. The CTRLB register must be used to control the power reduction mode, read wait states and the write mode. 21.6.4.1 NVM Read Reading from the NVM main address space is performed via the AHB bus by addressing the NVM main address space or auxiliary address space directly. Read data is available after the configured number of read wait states (CTRLB.RWS) set in the NVM Controller. The number of cycles data are delayed to the AHB bus is determined by the read wait states. Examples of using zero and one wait states are shown in Figure 21-5. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 270 Figure 21-5. Read Wait State Examples 0 Wait States AHB Command Rd 0 Idle Rd 1 AHB Slave Ready Data 0 AHB Slave Data Data 1 1 Wait State AHB Command Rd 0 Rd 1 Idle AHB Slave Ready AHB Slave Data Data 0 Data 1 21.6.4.2 NVM Write The NVM Controller requires that an erase must be done before programming. The entire NVM main address space can be erased by a debugger Chip Erase command. Alternatively, rows can be individually erased by the Erase Row command. After programming, the region that the page resides in can be locked to prevent spurious write or erase sequences. Locking is performed on a per-region basis, and so locking a region locks all pages inside the region. Data to be written to the NVM block are first written and stored in an internal buffer called the page buffer. The page buffer contains hw half words. Writes to the page buffer must be 16 or 32 bits. 8-bit writes to the page buffer is not allowed, and will cause a system exception. Writing to the NVM block via the AHB bus is performed by a load operation to the page buffer. For each AHB bus write, the address is stored in the ADDR register. After the page buffer has been loaded with the required number of words, the page can be written to the addressed location by setting CMD to Write Page and setting the key value to CMDEX. The LOAD bit in the STATUS register indicates whether the page buffer has been loaded or not. Before writing the page to memory, the accessed row must be erased. By default, automatic page writes are enabled (MANW=0). This will trigger a write operation to the page addressed by ADDR when the last location of the page is written. Because the address is automatically stored in ADDR during the I/O bus write operation, the last given address will be present in the ADDR register. There is no need to load the ADDR register manually, unless a different page in memory is to be written. Procedure for Manual Page Writes (MANW=1) The row to be written must be erased before the write command is given. z Write to the page buffer by addressing the NVM main address space directly z Write the page buffer to memory: CMD=Write Page and CMDEX z The READY bit in the INTFLAG register will be low while programming is in progress, and access through the AHB will be stalled Procedure for Automatic Page Writes (MANW=0) The row to be written must be erased before the last write to the page buffer is performed. Note that partially written pages must be written with a manual write. z Write to the page buffer by addressing the NVM main address space directly. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 271 z z When the last location in the page buffer is written, the page is automatically written to NVM main address space. INTFLAG.READY will be zero while programming is in progress and access through the AHB will be stalled. 21.6.4.3 Page Buffer Clear The page buffer is automatically cleared to all ones after a page write is performed. If a partial page has been written and it is desired to clear the contents of the page buffer, the Page Buffer Clear command can be used. 21.6.4.4 Erase Row Before a page can be written, the row that contains the page must be erased. The Erase Row command can be used to erase the desired row. Erasing the row sets all bits to one. If the row resides in a region that is locked, the erase will not be performed and the Lock Error bit in the Status register (STATUS.LOCKE) will be set. Procedure for Erase Row z Write the address of the row to erase ADDR. Any address within the row can be used. z Issue an Erase Row command. 21.6.4.5 Lock and Unlock Region These commands are used to lock and unlock regions as detailed in section “Region Lock Bits” on page 269. 21.6.4.6 Set and Clear Power Reduction Mode The NVM Controller and block can be taken in and out of power reduction mode through the set and clear power reduction mode commands. When the NVM Controller and block are in power reduction mode, the Power Reduction Mode bit in the Status register (STATUS.PRM) is set. 21.6.5 User Row Table 21-3. User Row Organization Bit Position Name 2:0 BOOTPROT 3 Reserved 6:4 EEPROM 7 Reserved 47:8 Device dependant 63:48 LOCK Usage Used to select one of eight different boot loader sizes (see Table 21-4.) Rows included in the boot loader area can not be erased or programmed, except by a debugger chip erase. BOOTPROT can be changed only when the security bit is cleared. Used to select one of eight different EEPROM sizes. EEPROM can be changed only when the security bit is cleared. Refer to “Non-Volatile Memory (NVM) User Row Mapping” on page 25. Region lock bits. The boot loader resides in the main array starting at offset zero. The allocated boot loader section is protected against write. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 272 Table 21-4. Boot Loader Size BOOTPROT [2:0] Rows Protected by BOOTPROT Boot Size in Bytes 7 None 0 6 2 512 5 4 1024 4 8 2048 3 16 4096 2 32 8192 1 64 16384 0 128 32768 The EEPROM bits indicates the EEPROM size according to the Table . EEPROM resides in the upper rows of the NVM main address space and are writable, regardless of the region lock status. Table 21-5. EEPROM Size EEPROM[2:0] Rows Allocated to EEPROM EEPROM Size in Bytes 7 None 0 6 1 256 5 2 512 4 4 1024 3 8 2048 2 16 4096 1 32 8192 0 64 16384 21.6.6 Security Bit The security bit allows the entire chip to be locked from external access for code security. The security bit can be written by a dedicated command, Set Security Bit (SSB). Once set, the only way to clear the security bit is through a debugger Chip Erase command. After issuing the SSB command, the PROGE error bit can be checked. Refer to “DSU – Device Service Unit” on page 41 for details. 21.6.7 Cache The NVM Controller cache reduces the device power consumption and improves system performance when wait states are required. It is a direct-mapped cache that implements 8 lines of 64 bits (i.e., 64 bytes). NVM Controller cache can be enabled by writing a zero in the CACHEDIS bit in the CTRLB register (CTRLB.CACHEDIS). Cache can be configured to three different modes using the READMODE bit group in the CTRLB register. Refer to CTRLB register description for more details. The INVALL command can be issued through the CTRLA register to invalidate all cache lines. Commands affecting NVM content automatically invalidate cache lines. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 273 21.7 Offset Register Summary Name 0x00 Bit Pos. 7:0 CMD[6:0] CTRLA 0x01 15:8 0x2 Reserved 0x3 Reserved 0x04 7:0 0x05 CMDEX[7:0] MANW RWS[3:0] 15:8 SLEEPPRM[1:0] CTRLB CACHEDIS 0x06 23:16 0x07 31:24 0x08 7:0 NVMP[7:0] 15:8 NVMP[15:8] 0x09 0x0A PARAM 0x0B 23:16 READMODE[1:0] PSZ[2:0] 31:24 0x0C INTENCLR 0x0D Reserved 0x0E Reserved 0x0F Reserved 0x10 INTENSET 0x11 Reserved 0x12 Reserved 0x13 Reserved 0x14 INTFLAG 0x15 Reserved 0x16 Reserved 0x17 Reserved 0x18 7:0 ERROR READY 7:0 ERROR READY 7:0 ERROR READY LOAD PRM 7:0 NVME LOCKE PROGE STATUS 0x19 15:8 0x1A Reserved 0x1B Reserved 0x1C 0x1D 0x1E ADDR 0x1F SB 7:0 ADDR[7:0] 15:8 ADDR[15:8] 23:16 ADDR[21:16] 31:24 0x20 7:0 LOCK[7:0] 15:8 LOCK[15:8] LOCK 0x21 0x22 Reserved 0x23 Reserved Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 274 21.8 Register Description Registers can be 8, 16 or 32 bits wide. Atomic 8-, 16- and 32-bit accesses are supported. In addition, the 8-bit quarters and 16-bit halves of a 32-bit register and the 8-bit halves of a 16-bit register can be accessed directly. Some registers are optionally write-protected by the Peripheral Access Controller (PAC). Write-protection is denoted by the Write-Protected property in each individual register description. Please refer to the Register Access Protection section and the PAC chapter for details. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 275 21.8.1 Control A Name: CTRLA Offset: 0x00 Reset: 0x0000 Property: Write-Protected Bit 15 14 13 12 11 10 9 8 CMDEX[7:0] Access R/W R/W R/W R/W R/W R/W R/W R/W Reset 0 0 0 0 0 0 0 0 Bit 7 6 5 4 3 2 1 0 CMD[6:0] Access R R/W R/W R/W R/W R/W R/W R/W Reset 0 0 0 0 0 0 0 0 z Bits 15:8 – CMDEX: Command Execution This bit group should be written with the key value 0xA5 to enable the command written to CMD to be executed. If the bit group is written with a different key value, the write is not performed and the PROGE status bit is set. PROGE is also set if the a previously written command is not complete. The key value must be written at the same time as CMD. If a command is issued through the APB bus on the same cycle as an AHB bus access, the AHB bus access will be given priority. The command will then be executed when the NVM block and the AHB bus are idle. The READY status must be one when the command is issued. Bit 0 of the CMDEX bit group will read back as one until the command is issued. z 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. This bit will always return zero when read. z Bits 6:0 – CMD: Command These bits define the command to be executed when the CMDEX key is written, as shown in Table 21-6. Table 21-6. Command Bit Description CMD[4:0] Group Configuration Description 0x00-0x01 - Reserved 0x02 ER Erase Row - Erases the row addressed by the ADDR register. 0x03 - Reserved 0x04 WP Write Page - Writes the contents of the page buffer to the page addressed by the ADDR register. 0x05 EAR Erase Auxiliary Row - Erases the auxiliary row addressed by the ADDR register. This command can be given only when the security bit is not set and only to the user configuration row. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 276 Table 21-6. Command Bit Description (Continued) CMD[4:0] Group Configuration Description 0x06 WAP Write Auxiliary Page - Writes the contents of the page buffer to the page addressed by the ADDR register. This command can be given only when the security bit is not set and only to the user configuration row. 0x07-0x3F - Reserved 0x40 LR Lock Region - Locks the region containing the address location in the ADDR register. 0x41 UR Unlock Region - Unlocks the region containing the address location in the ADDR register. 0x42 SPRM Sets the power reduction mode. 0x43 CPRM Clears the power reduction mode. 0x44 PBC Page Buffer Clear - Clears the page buffer. 0x45 SSB Set Security Bit - Sets the security bit by writing 0x00 to the first byte in the lockbit row. 0x46 INVALL Invalidates all cache lines. 0x46-0x7F - Reserved Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 277 21.8.2 Control B Name: CTRLB Offset: 0x04 Reset: 0x00000000 Property: Write-Protected Bit 31 30 29 28 27 26 25 24 Access R R R R R R R R Reset 0 0 0 0 0 0 0 0 Bit 23 22 21 20 19 18 17 16 CACHEDIS READMODE[1:0] Access R R R R R R/W R/W R/W Reset 0 0 0 0 0 0 0 0 Bit 15 14 13 12 11 10 9 8 SLEEPPRM[1:0] Access R R R R R R R/W R/W Reset 0 0 0 0 0 0 0 0 Bit 7 6 5 4 3 2 1 0 MANW RWS[3:0] Access R R R R R R R/W R/W Reset 0 0 0 0 0 0 0 0 z Bits 31:19 – 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. These bits will always return zero when read. z Bit 18 – CACHEDIS: Cache Disable This bit is used to disable the cache. 0: The cache is enabled. 1: The cache is disabled. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 278 z Bits 17:16 – READMODE: NVMCTRL Read Mode READMODE Name Description 0x0 NO_MISS_PENALTY The NVM Controller (cache system) does not insert wait states on a cache miss. Gives the best system performance. LOW_POWER Reduces power consumption of the cache system, but inserts a wait state each time there is a cache miss. This mode may not be relevant if CPU performance is required, as the application will be stalled and may lead to increase run time. 0x2 DETERMINISTIC The cache system ensures that a cache hit or miss takes the same amount of time, determined by the number of programmed flash wait states. This mode can be used for real-time applications that require deterministic execution timings. 0x3 Reserved 0x1 z Bits 15:10 – 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. These bits will always return zero when read. z Bits 9:8 – SLEEPPRM: Power Reduction Mode During Sleep Indicates the power reduction mode during sleep. Table 21-7. Table 1-7. Power Reduction Mode During Sleep SLEEPPRM[1:0] z Name Description 0x0 WAKEONACCESS NVM block enters low-power mode when entering sleep. NVM block exits low-power mode upon first access. 0x1 WAKEUPINSTANT NVM block enters low-power mode when entering sleep. NVM block exits low-power mode when exiting sleep. 0x2 Reserved 0x3 DISABLED Auto power reduction disabled. Bit 7 – MANW: Manual Write 0: Writing to the last word in the page buffer will initiate a write operation to the page addressed by the last write operation. This includes writes to memory and auxiliary rows. 1: Write commands must be issued through the CMD register. z Bits 6: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. These bits will always return zero when read. z Bits 4:1 – RWS: NVM Read Wait States These bits give the number of wait states for a read operation. Zero indicates zero wait states, one indicates one wait state, etc., up to 15 wait states. This register is initialized to 0 wait states. Software can change this value based on the NVM access time and system frequency. z 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. This bit will always return zero when read. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 279 21.8.3 NVM Parameter Name: PARAM Offset: 0x08 Reset: 0x000XXXXX Property: – Bit 31 30 29 28 27 26 25 24 Access R R R R R R R R Reset 0 0 0 0 0 0 0 0 Bit 23 22 21 20 19 18 17 16 PSZ[2:0] Access R R R R R R R R Reset 0 0 0 0 0 X X X Bit 15 14 13 12 11 10 9 8 NVMP[15:8] Access R R R R R R R R Reset X X X X X X X X Bit 7 6 5 4 3 2 1 0 R R X X NVMP[7:0] Access R R R R R Reset X X X X X X z Bits 31:19 – 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. These bits will always return zero when read. z Bits 18:16 – PSZ: Page Size Indicates the page size. Not all device families will provide all the page sizes indicated in the table. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 280 Table 21-8. Page Size z PSZ[2:0] Name Description 0x0 8 8 bytes 0x1 16 16 bytes 0x2 32 32 bytes 0x3 64 64 bytes 0x4 128 128 bytes 0x5 256 256 bytes 0x6 512 512 bytes 0x7 1024 1024 bytes Bits 15:0 – NVMP: NVM Pages Indicates the number of pages in the NVM main address space. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 281 21.8.4 Interrupt Enable Clear This register allows the user to disable an interrupt without doing a read-modify-write operation. Changes in this register will also be reflected in the Interrupt Enable Set register (INTENSET). Name: INTENCLR Offset: 0x0C Reset: 0x00 Property: Write-Protected Bit 7 6 5 4 3 2 1 0 ERROR READY Access R R R R R R R/W R/W Reset 0 0 0 0 0 0 0 0 z Bits 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. These bits will always return zero when read. z Bit 1 – ERROR: Error Interrupt Enable Writing a zero to this bit has no effect. Writing a one to this bit clears the ERROR interrupt enable. This bit will read as the current value of the ERROR interrupt enable. z Bit 0 – READY: NVM Ready Interrupt Enable Writing a zero to this bit has no effect. Writing a one to this bit clears the READY interrupt enable. This bit will read as the current value of the READY interrupt enable. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 282 21.8.5 Interrupt Enable Set This register allows the user to enable an interrupt without doing a read-modify-write operation. Changes in this register will also be reflected in the Interrupt Enable Clear register (INTENCLR). Name: INTENSET Offset: 0x10 Reset: 0x00 Property: Write-Protected Bit 7 6 5 4 3 2 1 0 ERROR READY Access R R R R R R R/W R/W Reset 0 0 0 0 0 0 0 0 z Bits 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. These bits will always return zero when read. z Bit 1 – ERROR: Error Interrupt Enable Writing a zero to this bit has no effect. Writing a one to this bit sets the ERROR interrupt enable. This bit will read as the current value of the ERROR interrupt enable. z Bit 0 – READY: NVM Ready Interrupt Enable Writing a zero to this bit has no effect. Writing a one to this bit sets the READY interrupt enable. This bit will read as the current value of the READY interrupt enable. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 283 21.8.6 Interrupt Flag Status and Clear Name: INTFLAG Offset: 0x14 Reset: 0x00 Property: – Bit 7 6 5 4 3 2 1 0 ERROR READY Access R R R R R R R/W R Reset 0 0 0 0 0 0 0 0 z Bits 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. These bits will always return zero when read. z Bit 1 – ERROR: Error This flag is set on the occurrence of an NVME, LOCKE or PROGE error. 0: No errors have been received since the last clear. 1: At least one error has occurred since the last clear. This bit can be cleared by writing a one to its bit location. z Bit 0 – READY: NVM Ready 0: The NVM controller is busy programming or erasing. 1: The NVM controller is ready to accept a new command. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 284 21.8.7 Status Name: STATUS Offset: 0x18 Reset: 0x0X00 Property: – Bit 15 14 13 12 11 10 9 8 SB Access R R R R R R R R Reset 0 0 0 0 0 0 0 X Bit 7 6 5 4 3 2 1 0 NVME LOCKE PROGE LOAD PRM Access R R R R/W R/W R/W R/W R Reset 0 0 0 0 0 0 0 0 z Bits 15:9 – 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. These bits will always return zero when read. z Bit 8 – SB: Security Bit Status 0: The Security bit is inactive. 1: The Security bit is active. z Bits 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. These bits will always return zero when read. z Bit 4 – NVME: NVM Error 0: No programming or erase errors have been received from the NVM controller since this bit was last cleared. 1: At least one error has been registered from the NVM Controller since this bit was last cleared. -This bit can be cleared by writing a one to its bit location. z Bit 3 – LOCKE: Lock Error Status 0: No programming of any locked lock region has happened since this bit was last cleared. 1: Programming of at least one locked lock region has happened since this bit was last cleared. This bit can be cleared by writing a one to its bit location. z Bit 2 – PROGE: Programming Error Status 0: No invalid commands or bad keywords were written in the NVM Command register since this bit was last cleared. 1: An invalid command and/or a bad keyword was/were written in the NVM Command register since this bit was last cleared. This bit can be cleared by writing a one to its bit location. z Bit 1 – LOAD: NVM Page Buffer Active Loading This bit indicates that the NVM page buffer has been loaded with one or more words. Immediately after an NVM load has been performed, this flag is set, and it remains set until a page write or a page buffer clear (PBCLR) command is given. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 285 This bit can be cleared by writing a one to its bit location. z Bit 0 – PRM: Power Reduction Mode This bit indicates the current NVM power reduction state. The NVM block can be set in power reduction mode in two ways: through the command interface or automatically when entering sleep with SLEEPPRM set accordingly. PRM can be cleared in three ways: through AHB access to the NVM block, through the command interface (SPRM and CPRM) or when exiting sleep with SLEEPPRM set accordingly. 0: NVM is not in power reduction mode. 1: NVM is in power reduction mode. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 286 21.8.8 Address Name: ADDR Offset: 0x1C Reset: 0x00000000 Property: Write-Protected Bit 31 30 29 28 27 26 25 24 Access R R R R R R R R Reset 0 0 0 0 0 0 0 0 Bit 23 22 21 20 19 18 17 16 ADDR[21:16] Access R R R/W R/W R/W R/W R/W R/W Reset 0 0 0 0 0 0 0 0 Bit 15 14 13 12 11 10 9 8 ADDR[15:8] Access R/W R/W R/W R/W R/W R/W R/W R/W Reset 0 0 0 0 0 0 0 0 Bit 7 6 5 4 3 2 1 0 ADDR[7:0] Access Reset R/W R/W R/W R/W R/W R/W R/W R/W 0 0 0 0 0 0 0 0 z Bits 31:22 – 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. These bits will always return zero when read. z Bits 21:0 – ADDR: NVM Address ADDR drives the hardware (16-bit) address to the NVM when a command is executed using CMDEX. This register is also automatically updated when writing to the page buffer. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 287 21.8.9 Lock Section Name: LOCK Offset: 0x20 Reset: 0xXXXX Property: – Bit 15 14 13 12 11 10 9 8 LOCK[15:8] Access R R R R R R R R Reset X X X X X X X X Bit 7 6 5 4 3 2 1 0 LOCK[7:0] Access R R R R R R R R Reset X X X X X X X X z Bits 15:0 – LOCK: Region Lock Bits In order to set or clear these bits, the CMD register must be used. 0: The corresponding lock region is locked. 1: The corresponding lock region is not locked. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 288 22. PORT 22.1 Overview The Port (PORT) controls the I/O pins of the microcontroller. The I/O pins are organized in a series of groups, collectively referred to as a line bundle, and each group can have up to 32 pins that can be configured and controlled individually or as a group. Each pin may either be used for general-purpose I/O under direct application control or assigned to an embedded device peripheral. When used for general-purpose I/O, each pin can be configured as input or output, with highly configurable driver and pull settings. All I/O pins have true read-modify-write (RMW) functionality when used for general-purpose I/O; the direction or the output value of one or more pins may be changed (set, reset or toggled) without unintentionally changing the state of any other pins in the same line bundle via a single, atomic 8-, 16- or 32-bit write. The PORT is connected to the high-speed bus matrix through an AHB/APB bridge. The Pin Direction, Data Output Value and Data Input Value registers may also be accessed using the low-latency CPU local bus (IOBUS; ARM® single-cycle I/O port). 22.2 Features z Selectable input and output configuration individually for each pin z Software-controlled multiplexing of peripheral functions on I/O pins z Flexible pin configuration through a dedicated Pin Configuration register z Configurable output driver and pull settings: z z z Totem-pole (push-pull) Pull configuration Configurable input buffer and pull settings: z Internal pull-up or pull-down Input sampling criteria z Input buffer can be disabled if not needed for lower power consumption z z Read-modify-write support for pin configuration, output value and pin direction Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 289 22.3 Block Diagram Figure 22-1. PORT Block Diagram PORT Peripheral Mux Select Control Status Port Line Bundles IP Line Bundles PORTMUX and Pad Line Bundles I/O PADS Analog Pad Connections PERIPHERALS Digital Controls of Analog Blocks ANALOG BLOCKS 22.4 Signal Description Signal Name Type Description Pxy Digital I/O General-purpose I/O pin y Refer to “I/O Multiplexing and Considerations” on page 15 for details on the pin mapping for this peripheral. One signal can be mapped on several pins. 22.5 Product Dependencies In order to use this peripheral, other parts of the system must be configured correctly, as described below. 22.5.1 I/O Lines The I/O lines of the PORT are mapped to pins of the physical device package according to a simple naming scheme. Each line bundle of up to 32 pins is assigned a letter identifier, starting with A, that monotonically increases through the alphabet for each subsequent line bundle. Within each line bundle, each pin is assigned a numerical identifier according to its bit position. The resulting PORT pins are mapped as Pxy, where x=A, B, C,… and y=00, 01, …, 31 to uniquely identify each pin in the device, e.g., PA24, PC03, etc. Each pin may have one or more peripheral multiplexer settings, which allow the pad to be routed internally to a dedicated peripheral function. When enabled, the selected peripheral is given control over the output state of the pad, as well as the ability to read the current physical pad state. Refer to “I/O Multiplexing and Considerations” on page 15 for details. Device-specific configurations may result in some pins (and the corresponding Pxy pin) not being implemented. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 290 22.5.2 Power Management During reset, all PORT lines are configured as inputs with input buffers, output buffers and pull disabled. If the PORT peripheral is shut down, the latches contained in the pad will retain their current configuration, such as the output value and pull settings. However, the PORT configuration registers and input synchronizers will lose their contents, and these will not be restored when PORT is powered up again. The user must, therefore, reconfigure the PORT peripheral at power up to ensure it is in a well-defined state before use. The PORT will continue to operate in any sleep mode where the selected module source clock is running. 22.5.3 Clocks The PORT bus clock (CLK_PORT_APB) can be enabled and disabled in the Power Manager, and the default state of CLK_PORT_APB can be found in the Peripheral Clock Masking section in the “PM – Power Manager” on page 105. The PORT is fed by two different clocks: a CPU main clock, which allows the CPU to access the PORT through the lowlatency CPU local bus (IOBUS), and an APB clock, which is a divided clock of the CPU main clock and allows the CPU to acces the PORT registers through the high-speed matrix and the AHB/APB bridge. IOBUS accesses have priority over APB accesses. The latter must insert wait states in the event of concurrent PORT accesses. The PORT input synchronizers use the CPU main clock so that the resynchronization delay is minimized with respect to the APB clock. 22.5.4 DMA Not applicable. 22.5.5 Interrupts Not applicable. 22.5.6 Events Not applicable. 22.5.7 Debug Operation When the CPU is halted in debug mode, the PORT continues normal operation. If the PORT is configured in a way that requires it to be periodically serviced by the CPU through interrupts or similar, improper operation or data loss may result during debugging. 22.5.8 Register Access Protection All registers with write-access are optionally write-protected by the Peripheral Access Controller (PAC). Write-protection is denoted by the Write-Protected property in the register description. When the CPU is halted in debug mode, all write-protection is automatically disabled. Write-protection does not apply for accesses through an external debugger. Refer to “PAC – Peripheral Access Controller” on page 31 for details. 22.5.9 Analog Connections Analog functions are connected directly between the analog blocks and the I/O pads using analog buses. However, selecting an analog peripheral function for a given pin will disable the corresponding digital features of the pad. 22.5.10 CPU Local Bus The CPU local bus (IOBUS) is an interface that connects the CPU directly to the PORT. It is a single-cycle bus interface, and does not support wait states. It supports byte, half word and word sizes. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 291 This bus is generally used for low latency. The Data Direction (DIR) and Data Output Value (OUT) registers can be read, written, set, cleared or toggled using this bus, and the Data Input Value (IN) registers can be read. Since the IOBUS cannot wait for IN register resynchronization, the Control register (CTRL) must be configured to enable continuous sampling of all pins that will need to be read via the IOBUS to prevent stale data from being read. 22.6 Functional Description Figure 22-2. Overview of the PORT ... PADy PORTx PULLEN PULLENy Pull Resistor Port_Mux APB Bus PG OUT OUTy OE DIRy PADy 3.3V NG INEN INENy IN INy Synchronizer ... Input to Other Modules Analog Input/Output 22.6.1 Principle of Operation The I/O pins of the device are controlled by reads and writes of the PORT peripheral registers. For each port pin, a corresponding bit in the Data Direction (DIR) and Data Output Value (OUT) registers are used to enable that pin as an output and to define the output state. The direction of each pin in a port bundle is configured via the DIR register. If a bit in DIR is written to one, the corresponding pin is configured as an output pin. If a bit in DIR is written to zero, the corresponding pin is configured as an input pin. When the direction is set as output, the corresponding bit in the OUT register is used to set the level of the pin. If bit y of OUT is written to one, pin y is driven high. If bit y of OUT is written to zero, pin y is driven low. Additional pin configuration can be set by writing to the Pin Configuration (PINCFGy) registers. The Data Input Value bit (IN) is used to read the port pin with resynchronization to the PORT clock. By default, these input synchronizers are clocked only when an input value read is requested in order to reduce power consumption. Input value can always be read, whether the pin is configured as input or output, except if digital input is disabled by writing a zero to the INEN bit in the Pin Configuration registers (PINCFGy). The PORT also allows peripheral functions to be connected to individual I/O pins by writing a one to the corresponding PMUXEN bit in the PINCFGy registers and by writing the chosen selection to the Peripheral Multiplexing registers Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 292 (PMUXn) for that pin. This will override the connection between the PORT and that I/O pin, and connect the selected peripheral line bundle to the pad instead of the PORT line bundle. Each group of up to 32 pins is controlled by a set of registers, as described in Figure 22-3. This set of registers is duplicated for each group of pins, with increasing base addresses. Figure 22-3. Overview of the Peripheral Functions Multiplexing PORT bit y Port y PINCFG PMUXEN Port y Data+Config Port y PMUX[3:0] PORTMUX Port y Peripheral Mux Enable Port y Line Bundle 0 Port y PMUX Select Pad y PAD y Line Bundle Periph Line 0 0 Periph Line 1 1 1 Peripheral Line Bundles to be muxed to Pad y Periph Line 15 15 22.6.2 Basic Operation 22.6.2.1 Initialization After reset, all standard-function device I/O pads are connected to the PORT with outputs tri-stated and input buffers disabled, even if no clocks are running. Specific pins, such as the ones used for connection to a debugger, may be configured differently, as required by their special function. 22.6.3 Basic Operation Each I/O pin y can be configured and accessed by reading or writing PORT registers. Because PORT registers are grouped into sets of registers for each group of up to 32 pins, the base address of the register set for pin y is at byte address PORT + (y / 32) * 0x80. (y % 32) will be used as the index within that register set. To use pin y as an output, configure it as output by writing the (y % 32) bit in the DIR register to one. To avoid disturbing the configuration of other pins in that group, this can also be done by writing the (y % 32) bit in the DIRSET register to one. The desired output value can be set by writing the (y % 32) bit to that value in register OUT. Similarly, writing an OUTSET bit to one will set the corresponding bit in the OUT register to one, while writing an OUTCLR bit to one will set it to zero, and writing an OUTTGL bit to one will toggle that bit in OUT. To use pin y as an input, configure it as input by writing the (y % 32) bit in the DIR register to zero. To avoid disturbing the configuration of other pins in that group, this can also be done by writing the (y % 32) bit in DIRCLR register to one. The desired input value can be read from the (y % 32) bit in register IN as soon as the INEN bit in the Pin Configuration register (PINCFGy) is written to one. Refer to “I/O Multiplexing and Considerations” on page 15 for details on pin configuration. By default, the input synchronizer is clocked only when an input read is requested, which will delay the read operation by two CLK_PORT cycles. To remove that delay, the input synchronizers for each group of eight pins can be configured to Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 293 be always active, but this comes at the expense of higher power consumption. This is controlled by writing a one to the corresponding SAMPLINGn bit group of the CTRL register, where n = (y % 32) / 8. To use pin y as one of the available peripheral functions for that pin, configure it by writing a one to the corresponding PMUXEN bit of the PINCFGy register. The PINCFGy register for pin y is at byte offset (PINCFG0 + (y % 32)). The peripheral function can be selected by writing to the PMUXO or PMUXE bit group in the PMUXn register. The PMUXO/PMUXE bit group is at byte offset (PMUX0 + (y % 32) / 2), in bits 3:0 if y is even and in bits 7:4 if y is odd. The chosen peripheral must also be configured and enabled. 22.6.4 I/O Pin Configuration The Pin Configuration register (PINCFGy) is used for additional I/O pin configuration. A pin can be set in a totem-pole, open-drain or pull configuration. Because pull configuration is done through the Pin Configuration register, all intermediate PORT states during switching of pin direction and pin values are avoided. The I/O pin configurations are described further in this chapter, and summarized in Table 22-1. 22.6.4.1 Pin Configurations Summary Table 22-1. Pin Configurations Summary DIR INEN PULLEN OUT Configuration 0 0 0 X Reset or analog I/O; all digital disabled 0 0 1 0 Pull-down; input disabled 0 0 1 1 Pull-up; input disabled 0 1 0 X Input 0 1 1 0 Input with pull-down 0 1 1 1 Input with pull-up 1 0 X X Output; input disabled 1 1 X X Output; input enabled 22.6.4.2 Input Configuration Figure 22-4. I/O Configuration - Standard Input PULLEN PULLEN INEN DIR 0 1 0 DIR OUT IN INEN Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 294 Figure 22-5. I/O Configuration - Input with Pull PULLEN PULLEN INEN DIR 1 1 0 DIR OUT IN INEN Note that when pull is enabled, the pull value is defined by the OUTx value. 22.6.4.3 Totem-Pole Output When configured for totem-pole (push-pull) output, 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 is connected. Note, that enabling the output driver automatically disables pull. Figure 22-6. I/O Configuration - Totem-Pole Output with Disabled Input PULLEN PULLEN INEN DIR 0 0 1 PULLEN INEN DIR 0 1 1 DIR OUT IN INEN Figure 22-7. I/O Configuration - Totem-Pole Output with Enabled Input PULLEN DIR OUT IN INEN Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 295 Figure 22-8. I/O Configuration - Output with Pull PULLEN PULLEN INEN DIR 1 0 0 DIR OUT IN INEN 22.6.4.4 Digital Functionality Disabled Figure 22-9. I/O Configuration - Reset or Analog I/O: Digital Output, Input and Pull Disabled PULLEN PULLEN INEN DIR 0 0 0 DIR OUT IN INEN Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 296 22.7 Register Summary The I/O pins are organized in groups with up to 32 pins. Group 0 consists of the PA pins, group 1 the PB pins, etc. Each group has its own set of registers. For example, the register address offset for the Data Direction (DIR) register for group 0 (PA00 to PA31) is 0x00, while the register address offset for the DIR register for group 1 (PB00 to PB31) is 0x80. Bit Offset Name Pos. 0x00 7:0 DIR[7:0] 0x01 15:8 DIR[15:8] 0x02 23:16 DIR[23:16] 0x03 31:24 DIR[31:24] DIR 0x04 7:0 DIRCLR[7:0] 0x05 15:8 DIRCLR[15:8] 0x06 23:16 DIRCLR[23:16] 0x07 31:24 DIRCLR[31:24] DIRCLR 0x08 7:0 DIRSET[7:0] 0x09 15:8 DIRSET[15:8] 0x0A 23:16 DIRSET[23:16] 0x0B 31:24 DIRSET[31:24] DIRSET 0x0C 7:0 DIRTGL[7:0] 0x0D 15:8 DIRTGL[15:8] 0x0E 23:16 DIRTGL[23:16] 0x0F 31:24 DIRTGL[31:24] DIRTGL 0x10 7:0 OUT[7:0] 0x11 15:8 OUT[15:8] 0x12 23:16 OUT[23:16] 0x13 31:24 OUT[31:24] OUT 0x14 7:0 OUTCLR[7:0] 0x15 15:8 OUTCLR[15:8] 0x16 23:16 OUTCLR[23:16] 0x17 31:24 OUTCLR[31:24] 0x18 7:0 OUTSET[7:0] OUTCLR 15:8 OUTSET[15:8] 0x1A 0x19 23:16 OUTSET[23:16] 0x1B 31:24 OUTSET[31:24] 0x1C 7:0 OUTTGL[7:0] OUTSET 0x1D 15:8 OUTTGL[15:8] 0x1E 23:16 OUTTGL[23:16] 0x1F 31:24 OUTTGL[31:24] 0x20 7:0 IN[7:0] OUTTGL 0x21 15:8 IN[15:8] 0x22 23:16 IN[23:16] 0x23 31:24 IN[31:24] 0x24 7:0 SAMPLING[7:0] IN 0x25 15:8 SAMPLING[15:8] 0x26 23:16 SAMPLING[23:16] 0x27 31:24 SAMPLING[31:24] CTRL Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 297 Bit Offset Name 0x28 0x29 Pos. 7:0 PINMASK[7:0] 15:8 PINMASK[15:8] WRCONFIG 0x2A 23:16 0x2B 31:24 PULLEN HWSEL WRPINCFG WRPMUX INEN PMUXEN PMUX[3:0] 0x2C 0x2D Reserved 0x2E 0x2F 0x30 PMUX0 7:0 PMUXO[3:0] PMUXE[3:0] 0x31 PMUX1 7:0 PMUXO[3:0] PMUXE[3:0] … … … 0x3E PMUX14 7:0 PMUXO[3:0] PMUXE[3:0] 0x3F PMUX15 7:0 PMUXO[3:0] PMUXE[3:0] 0x40 PINCFG0 7:0 PULLEN INEN PMUXEN 0x41 PINCFG1 7:0 PULLEN INEN PMUXEN … … … 0x5E PINCFG30 7:0 PULLEN INEN PMUXEN 0x5F PINCFG31 7:0 PULLEN INEN PMUXEN Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 298 22.8 Register Description Registers can be 8, 16 or 32 bits wide. Atomic 8-, 16- and 32-bit accesses are supported. In addition, the 8-bit quarters and 16-bit halves of a 32-bit register and the 8-bit halves of a 16-bit register can be accessed directly. Some registers are optionally write-protected by the Peripheral Access Controller (PAC). Write-protection is denoted by the Write-Protected property in each individual register description. Please refer to “Register Access Protection” on page 291 for details. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 299 22.8.1 Data Direction Name: DIR Offset: 0x00+x*0x80 [x=0..1] Reset: 0x00000000 Property: Write-Protected Bit 31 30 29 28 27 26 25 24 DIR[31:24] Access R/W R/W R/W R/W R/W R/W R/W R/W Reset 0 0 0 0 0 0 0 0 Bit 23 22 21 20 19 18 17 16 DIR[23:16] Access R/W R/W R/W R/W R/W R/W R/W R/W Reset 0 0 0 0 0 0 0 0 Bit 15 14 13 12 11 10 9 8 DIR[15:8] Access R/W R/W R/W R/W R/W R/W R/W R/W Reset 0 0 0 0 0 0 0 0 Bit 7 6 5 4 3 2 1 0 DIR[7:0] Access Reset z R/W R/W R/W R/W R/W R/W R/W R/W 0 0 0 0 0 0 0 0 Bits 31:0 – DIR[31:0]: Port Data Direction These bits set the data direction for the individual I/O pins in the PORT group. 0: The corresponding I/O pin in the group is configured as an input. 1: The corresponding I/O pin in the group is configured as an output. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 300 22.8.2 Data Direction Clear This register allows the user to set one or more I/O pins as an input, without doing a read-modify-write operation. Changes in this register will also be reflected in the Data Direction (DIR), Data Direction Toggle (DIRTGL) and Data Direction Set (DIRSET) registers. Name: DIRCLR Offset: 0x04+x*0x80 [x=0..1] Reset: 0x00000000 Property: Write-Protected Bit 31 30 29 28 27 26 25 24 DIRCLR[31:24] Access Reset Bit R/W R/W R/W R/W R/W R/W R/W R/W 0 0 0 0 0 0 0 0 23 22 21 20 19 18 17 16 DIRCLR[23:16] Access Reset Bit R/W R/W R/W R/W R/W R/W R/W R/W 0 0 0 0 0 0 0 0 15 14 13 12 11 10 9 8 DIRCLR[15:8] Access R/W R/W R/W R/W R/W R/W R/W R/W Reset 0 0 0 0 0 0 0 0 Bit 7 6 5 4 3 2 1 0 DIRCLR[7:0] Access Reset z R/W R/W R/W R/W R/W R/W R/W R/W 0 0 0 0 0 0 0 0 Bits 31:0 – DIRCLR[31:0]: Port Data Direction Clear 0: The I/O pin direction is cleared. 1: The I/O pin direction is set. Writing a zero to a bit has no effect. Writing a one to a bit will clear the corresponding bit in the DIR register, which configures the I/O pin as an input. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 301 22.8.3 Data Direction Set This register allows the user to set one or more I/O pins as an output, without doing a read-modify-write operation. Changes in this register will also be reflected in the Data Direction (DIR), Data Direction Toggle (DIRTGL) and Data Direction Clear (DIRCLR) registers. Name: DIRSET Offset: 0x08+x*0x80 [x=0..1] Reset: 0x00000000 Property: Write-Protected Bit 31 30 29 28 27 26 25 24 DIRSET[31:24] Access Reset Bit R/W R/W R/W R/W R/W R/W R/W R/W 0 0 0 0 0 0 0 0 23 22 21 20 19 18 17 16 DIRSET[23:16] Access Reset Bit R/W R/W R/W R/W R/W R/W R/W R/W 0 0 0 0 0 0 0 0 15 14 13 12 11 10 9 8 DIRSET[15:8] Access R/W R/W R/W R/W R/W R/W R/W R/W Reset 0 0 0 0 0 0 0 0 Bit 7 6 5 4 3 2 1 0 DIRSET[7:0] Access Reset z R/W R/W R/W R/W R/W R/W R/W R/W 0 0 0 0 0 0 0 0 Bits 31:0 – DIRSET[31:0]: Port Data Direction Set 0: The I/O pin direction is cleared. 1: The I/O pin direction is set. Writing a zero to a bit has no effect. Writing a one to a bit will set the corresponding bit in the DIR register, which configures the I/O pin as an output. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 302 22.8.4 Data Direction Toggle This register allows the user to toggle the direction of one or more I/O pins, without doing a read-modify-write operation. Changes in this register will also be reflected in the Data Direction (DIR), Data Direction Set (DIRSET) and Data Direction Clear (DIRCLR) registers. Name: DIRTGL Offset: 0x0C+x*0x80 [x=0..1] Reset: 0x00000000 Property: Write-Protected Bit 31 30 29 28 27 26 25 24 DIRTGL[31:24] Access R/W R/W R/W R/W R/W R/W R/W R/W Reset 0 0 0 0 0 0 0 0 Bit 23 22 21 20 19 18 17 16 DIRTGL[23:16] Access Reset Bit R/W R/W R/W R/W R/W R/W R/W R/W 0 0 0 0 0 0 0 0 15 14 13 12 11 10 9 8 DIRTGL[15:8] Access R/W R/W R/W R/W R/W R/W R/W R/W Reset 0 0 0 0 0 0 0 0 Bit 7 6 5 4 3 2 1 0 DIRTGL[7:0] Access Reset z R/W R/W R/W R/W R/W R/W R/W R/W 0 0 0 0 0 0 0 0 Bits 31:0 – DIRTGL[31:0]: Port Data Direction Toggle 0: The I/O pin direction is cleared. 1: The I/O pin direction is set. Writing a zero to a bit has no effect. Writing a one to a bit will toggle the corresponding bit in the DIR register, which reverses the direction of the I/O pin. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 303 22.8.5 Data Output Value This register sets the data output drive value for the individual I/O pins in the PORT. Name: OUT Offset: 0x10+x*0x80 [x=0..1] Reset: 0x00000000 Property: Write-Protected Bit 31 30 29 28 27 26 25 24 OUT[31:24] Access R/W R/W R/W R/W R/W R/W R/W R/W Reset 0 0 0 0 0 0 0 0 Bit 23 22 21 20 19 18 17 16 OUT[23:16] Access Reset Bit R/W R/W R/W R/W R/W R/W R/W R/W 0 0 0 0 0 0 0 0 15 14 13 12 11 10 9 8 OUT[15:8] Access R/W R/W R/W R/W R/W R/W R/W R/W Reset 0 0 0 0 0 0 0 0 Bit 7 6 5 4 3 2 1 0 OUT[7:0] Access Reset z R/W R/W R/W R/W R/W R/W R/W R/W 0 0 0 0 0 0 0 0 Bits 31:0 – OUT[31:0]: Port Data Output Value These bits set the logical output drive level of I/O pins configured as outputs via the Data Direction register (DIR). For pins configured as inputs via the Data Direction register (DIR) with pull enabled via the Pull Enable register (PULLEN), these bits will set the input pull direction. 0: The I/O pin output is driven low, or the input is connected to an internal pull-down. 1: The I/O pin output is driven high, or the input is connected to an internal pull-up. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 304 22.8.6 Data Output Value Clear This register allows the user to set one or more output I/O pin drive levels low, without doing a read-modify-write operation. Changes in this register will also be reflected in the Data Output Value (OUT), Data Output Value Toggle (OUTTGL) and Data Output Value Set (OUTSET) registers. Name: OUTCLR Offset: 0x14+x*0x80 [x=0..1] Reset: 0x00000000 Property: Write-Protected Bit 31 30 29 28 27 26 25 24 OUTCLR[31:24] Access Reset Bit R/W R/W R/W R/W R/W R/W R/W R/W 0 0 0 0 0 0 0 0 23 22 21 20 19 18 17 16 OUTCLR[23:16] Access Reset Bit R/W R/W R/W R/W R/W R/W R/W R/W 0 0 0 0 0 0 0 0 15 14 13 12 11 10 9 8 OUTCLR[15:8] Access R/W R/W R/W R/W R/W R/W R/W R/W Reset 0 0 0 0 0 0 0 0 Bit 7 6 5 4 3 2 1 0 OUTCLR[7:0] Access Reset z R/W R/W R/W R/W R/W R/W R/W R/W 0 0 0 0 0 0 0 0 Bits 31:0 – OUTCLR[31:0]: PORT Data Output Value Clear 0: The I/O pin output is driven low. 1: The I/O pin output is driven high. Writing a zero to a bit has no effect. Writing a one to a bit will clear the corresponding bit in the OUT register, which sets the output drive level low for I/O pins configured as outputs via the Data Direction register (DIR). For pins configured as inputs via the Data Direction register (DIR) with pull enabled via the Pull Enable register (PULLEN), these bits will set the input pull direction to an internal pull-down. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 305 22.8.7 Data Output Value Set This register allows the user to set one or more output I/O pin drive levels high, without doing a read-modify-write operation. Changes in this register will also be reflected in the Data Output Value (OUT), Data Output Value Toggle (OUTTGL) and Data Output Value Clear (OUTCLR) registers. Name: OUTSET Offset: 0x18+x*0x80 [x=0..1] Reset: 0x00000000 Property: Write-Protected Bit 31 30 29 28 27 26 25 24 OUTSET[31:24] Access R/W R/W R/W R/W R/W R/W R/W R/W Reset 0 0 0 0 0 0 0 0 Bit 23 22 21 20 19 18 17 16 OUTSET[23:16] Access Reset Bit R/W R/W R/W R/W R/W R/W R/W R/W 0 0 0 0 0 0 0 0 15 14 13 12 11 10 9 8 OUTSET[15:8] Access R/W R/W R/W R/W R/W R/W R/W R/W Reset 0 0 0 0 0 0 0 0 Bit 7 6 5 4 3 2 1 0 OUTSET[7:0] Access Reset z R/W R/W R/W R/W R/W R/W R/W R/W 0 0 0 0 0 0 0 0 Bits 31:0 – OUTSET[31:0]: PORT Data Output Value Set 0: The I/O pin output is driven low. 1: The I/O pin output is driven high. Writing a zero to a bit has no effect. Writing a one to a bit will set the corresponding bit in the OUT register, which sets the output drive level high for I/O pins configured as outputs via the Data Direction register (DIR). For pins configured as inputs via the Data Direction register (DIR) with pull enabled via the Pull Enable register (PULLEN), these bits will set the input pull direction to an internal pull-up. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 306 22.8.8 Data Output Value Toggle This register allows the user to toggle the drive level of one or more output I/O pins, without doing a read-modify-write operation. Changes in this register will also be reflected in the Data Output Value (OUT), Data Output Value Set (OUTSET) and Data Output Value Clear (OUTCLR) registers. Name: OUTTGL Offset: 0x1C+x*0x80 [x=0..1] Reset: 0x00000000 Property: Write-Protected Bit 31 30 29 28 27 26 25 24 OUTTGL[31:24] Access R/W R/W R/W R/W R/W R/W R/W R/W Reset 0 0 0 0 0 0 0 0 Bit 23 22 21 20 19 18 17 16 OUTTGL[23:16] Access R/W R/W R/W R/W R/W R/W R/W R/W Reset 0 0 0 0 0 0 0 0 Bit 15 14 13 12 11 10 9 8 OUTTGL[15:8] Access R/W R/W R/W R/W R/W R/W R/W R/W Reset 0 0 0 0 0 0 0 0 Bit 7 6 5 4 3 2 1 0 OUTTGL[7:0] Access Reset z R/W R/W R/W R/W R/W R/W R/W R/W 0 0 0 0 0 0 0 0 Bits 31:0 – OUTTGL[31:0]: PORT Data Output Value Toggle 0: The I/O pin output is driven low. 1: The I/O pin output is driven high. Writing a zero to a bit has no effect. Writing a one to a bit will toggle the corresponding bit in the OUT register, which inverts the output drive level for I/O pins configured as outputs via the Data Direction register (DIR). For pins configured as inputs via the Data Direction register (DIR) with pull enabled via the Pull Enable register (PULLEN), these bits will toggle the input pull direction. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 307 22.8.9 Data Input Value Name: IN Offset: 0x20+x*0x80 [x=0..1] Reset: 0x00000000 Property: - Bit 31 30 29 28 27 26 25 24 IN[31:24] Access R R R R R R R R Reset 0 0 0 0 0 0 0 0 Bit 23 22 21 20 19 18 17 16 IN[23:16] Access R R R R R R R R Reset 0 0 0 0 0 0 0 0 15 14 13 12 11 10 9 8 Bit IN[15:8] Access R R R R R R R R Reset 0 0 0 0 0 0 0 0 Bit 7 6 5 4 3 2 1 0 IN[7:0] Access R R R R R R R R Reset 0 0 0 0 0 0 0 0 z Bits 31:0 – IN[31:0]: PORT Data Input Value These bits are cleared when the corresponding I/O pin input sampler detects a logical low level on the input pin. These bits are set when the corresponding I/O pin input sampler detects a logical high level on the input pin. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 308 22.8.10 Control Name: CTRL Offset: 0x24+x*0x80 [x=0..1] Reset: 0x00000000 Property: Write-Protected Bit 31 30 29 28 27 26 25 24 SAMPLING[31:24] Access Reset Bit R/W R/W R/W R/W R/W R/W R/W R/W 0 0 0 0 0 0 0 0 23 22 21 20 19 18 17 16 SAMPLING[23:16] Access Reset Bit R/W R/W R/W R/W R/W R/W R/W R/W 0 0 0 0 0 0 0 0 15 14 13 12 11 10 9 8 SAMPLING[15:8] Access R/W R/W R/W R/W R/W R/W R/W R/W Reset 0 0 0 0 0 0 0 0 Bit 7 6 5 4 3 2 1 0 SAMPLING[7:0] Access Reset z R/W R/W R/W R/W R/W R/W R/W R/W 0 0 0 0 0 0 0 0 Bits 31:0 – SAMPLING[31:0]: Input Sampling Mode Configures the input sampling functionality of the I/O pin input samplers for pins configured as inputs via the Data Direction register (DIR). 0: The I/O pin input synchronizer is disabled. 1: The I/O pin input synchronizer is enabled. The input samplers are enabled and disabled in sub-groups of eight. Thus, if any pins within a byte request continuous sampling, all pins in that eight pin sub-group will be continuously sampled. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 309 22.8.11 Write Configuration This write-only register is used to configure several pins simultaneously with the same configuration and/or peripheral multiplexing. In order to avoid the side effect of non-atomic access, 8-bit or 16-bit writes to this register will have no effect. Reading this register always returns zero. Name: WRCONFIG Offset: 0x28+x*0x80 [x=0..1] Reset: 0x00000000 Property: Write-Protected Bit 31 30 29 28 27 HWSEL WRPINCFG Access W W R W W Reset 0 0 0 0 Bit 23 22 21 20 26 25 24 W W W 0 0 0 0 19 18 17 16 PULLEN INEN PMUXEN WRPMUX PMUX[3:0] Access R W R W W W W W Reset 0 0 0 0 0 0 0 0 Bit 15 14 13 12 11 10 9 8 PINMASK[15:8] Access W W W W W W W W Reset 0 0 0 0 0 0 0 0 Bit 7 6 5 4 3 2 1 0 PINMASK[7:0] Access W W W W W W W W Reset 0 0 0 0 0 0 0 0 z Bit 31 – HWSEL: Half-Word Select This bit selects the half-word field of a 32-pin group to be reconfigured in the atomic write operation. 0: The lower 16 pins of the PORT group will be configured. 1: The upper 16 pins of the PORT group will be configured. This bit will always read as zero. z Bit 30 – WRPINCFG: Write PINCFG This bit determines whether the atomic write operation will update the Pin Configuration register (PINCFGy) or not for all pins selected by the WRCONFIG.PINMASK and WRCONFIG.HWSEL bits. 0: The PINCFGy registers of the selected pins will not be updated. 1: The PINCFGy registers of the selected pins will be updated. Writing a zero to this bit has no effect. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 310 Writing a one to this bit updates the configuration of the selected pins with the written WRCONFIG.DRVSTR, WRCONFIG.SLEWLIM, WRCONFIG.ODRAIN, WRCONFIG.PULLEN, WRCONFIG.INEN, WRCONFIG.PMUXEN and WRCONFIG.PINMASK values. This bit will always read as zero. z Bit 29 – 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. This bit will always return zero when read. z Bit 28 – WRPMUX: Write PMUX This bit determines whether the atomic write operation will update the Peripheral Multiplexing register (PMUXn) or not for all pins selected by the WRCONFIG.PINMASK and WRCONFIG.HWSEL bits. 0: The PMUXn registers of the selected pins will not be updated. 1: The PMUXn registers of the selected pins will be updated. Writing a zero to this bit has no effect. Writing a one to this bit updates the pin multiplexer configuration of the selected pins with the written WRCONFIG.PMUX value. This bit will always read as zero. z Bits 27:24 – PMUX[3:0]: Peripheral Multiplexing These bits determine the new value written to the Peripheral Multiplexing register (PMUXn) for all pins selected by the WRCONFIG.PINMASK and WRCONFIG.HWSEL bits, when the WRCONFIG.WRPMUX bit is set. These bits will always read as zero. z Bits 23:19 – 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. These bits will always return zero when read. z Bit 18 – PULLEN: Pull Enable This bit determines the new value written to PINCFGy.PULLEN for all pins selected by the WRCONFIG.PINMASK and WRCONFIG.HWSEL bits when the WRCONFIG.WRPINCFG bit is set. This bit will always read as zero. z Bit 17 – INEN: Input Enable This bit determines the new value written to PINCFGy.DRVSTR for all pins selected by the WRCONFIG.PINMASK and WRCONFIG.HWSEL bits when the WRCONFIG.WRPINCFG bit is set. This bit will always read as zero. z Bit 16 – PMUXEN: Peripheral Multiplexer Enable This bit determines the new value written to PINCFGy.PMUXEN for all pins selected by the WRCONFIG.PINMASK and WRCONFIG.HWSEL bits when the WRCONFIG.WRPINCFG bit is set. This bit will always read as zero. z Bits 15:0 – PINMASK[15:0]: Pin Mask for Multiple Pin Configuration These bits select the pins to be configured within the half-word group selected by the WRCONFIG.HWSEL bit. 0: The configuration of the corresponding I/O pin in the half-word group will be left unchanged. 1: The configuration of the corresponding I/O pin in the half-word pin group will be updated. These bits will always read as zero. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 311 22.8.12 Peripheral Multiplexing n There are up to 16 Peripheral Multiplexing registers in each group, one for every set of two subsequent I/O lines. The n denotes the number of the set of I/O lines, while the m denotes the number of the group. Name: PMUXn Offset: 0x30+n*0x1+x*0x80 [n=0..15] [x=0..1] Reset: 0x00 Property: Write-Protected Bit 7 6 5 4 3 2 PMUXO[3:0] Access 0 PMUXE[3:0] R/W R/W R/W R/W R/W R/W R/W R/W 0 0 0 0 0 0 0 0 Reset z 1 Bits 7:4 – PMUXO[3:0]: Peripheral Multiplexing Odd These bits select the peripheral function for odd-numbered pins (2*n + 1) of a PORT group, if the corresponding PINCFGy.PMUXEN bit is one. Not all possible values for this selection may be valid. For more details, refer to “I/O Multiplexing and Considerations” on page 15. z Bits 3:0 – PMUXE[3:0]: Peripheral Multiplexing Even These bits select the peripheral function for even-numbered pins (2*n) of a PORT group, if the corresponding PINCFGy.PMUXEN bit is one. Not all possible values for this selection may be valid. For more details, refer to “I/O Multiplexing and Considerations” on page 15. Value Name Description 0x0 A Peripheral function A selected 0x1 B Peripheral function B selected 0x2 C Peripheral function C selected 0x3 D Peripheral function D selected 0x4 E Peripheral function E selected 0x5 F Peripheral function F selected 0x6 G Peripheral function G selected 0x7 H Peripheral function H selected 0x8-0xF Reserved Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 312 22.8.13 Pin Configuration y There are up to 32 Pin Configuration registers in each group, one for each I/O line. The y denotes the number of the I/O line, while the x denotes the number of the group. Name: PINCFGy Offset: 0x40+y*0x1+x*0x80 [y=0..31] [x=0..1] Reset: 0x00 Property: Write-Protected Bit 7 6 5 4 3 2 1 0 PULLEN INEN PMUXEN Access R R/W R R/W R/W R/W R/W R/W Reset 0 0 0 0 0 0 0 0 z Bits 7:3 – 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. These bits will always return zero when read. z Bit 2 – PULLEN: Pull Enable This bit enables the internal pull-up or pull-down resistor of an I/O pin configured as an input. 0: Internal pull resistor is disabled, and the input is in a high-impedance configuration. 1: Internal pull resistor is enabled, and the input is driven to a defined logic level in the absence of external input. z Bit 1 – INEN: Input Enable This bit controls the input buffer of an I/O pin configured as either an input or output. 0: Input buffer for the I/O pin is disabled, and the input value will not be sampled. 1: Input buffer for the I/O pin is enabled, and the input value will be sampled when required. Writing a zero to this bit disables the input buffer completely, preventing read-back of the physical pin state when the pin is configured as either an input or output. z Bit 0 – PMUXEN: Peripheral Multiplexer Enable This bit enables or disables the peripheral multiplexer selection set in the Peripheral Multiplexing register (PMUXn) to enable or disable alternative peripheral control over an I/O pin direction and output drive value. 0: The peripheral multiplexer selection is disabled, and the PORT registers control the direction and output drive value. 1: The peripheral multiplexer selection is enabled, and the selected peripheral controls the direction and output drive value. Writing a zero to this bit allows the PORT to control the pad direction via the Data Direction register (DIR) and output drive value via the Data Output Value register (OUT). The peripheral multiplexer value in PMUXn is ignored. Writing a one to this bit enables the peripheral selection in PMUXn to control the pad. In this configuration, the physical pin state may still be read from the Data Input Value register (IN) if PINCFGy.INEN is set. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 313 23. EVSYS – Event System 23.1 Overview The Event System (EVSYS) allows autonomous, low-latency and configurable communication between peripherals. Several peripherals can be configured to emit and/or respond to signals known as events. The exact condition to generate an event, or the action taken upon receiving an event, is specific to each module. Peripherals that respond to events are called event users. Peripherals that emit events are called event generators. A peripheral can have one or more event generators and can have one or more event users. Communication is made without CPU intervention and without consuming system resources such as bus or RAM bandwidth. This reduces the load on the CPU and other system resources, compared to a traditional interrupt-based system. 23.2 Features z System for direct peripheral-to-peripheral communication and signaling z Eight configurable event channels, where each channel can: z z Be connected to any event generator Provide a pure asynchronous, resynchronized or synchronous path z 59 event generators z 14 event users z Configurable edge detector z Peripherals can be event generators, event users or both z SleepWalking and interrupt for operation in low-power modes z Software event generation z Each event user can choose which channel to listen to Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 314 23.3 Block Diagram Figure 23-1. Event System Block Diagram EVSYS USER MUX CHANNELS PERIPHERALS GENERATOR EVENTS PERIPHERALS USERS EVENTS CLOCK REQUESTS GCLK 23.4 Signal Description Not applicable. 23.5 Product Dependencies In order to use this peripheral, other parts of the system must be configured correctly, as described below. 23.5.1 I/O Lines Not applicable. 23.5.2 Power Management The EVSYS can be used to wake up the CPU from all sleep modes, even if the clock used by the EVSYS channel and the EVSYS bus clock are disabled. Refer to “PM – Power Manager” on page 105 for details on the different sleep modes. In all power save modes where the clock for the EVSYS is stopped, the device can wake up the EVSYS clock. Some event generators can generate an event when the system clock is stopped. The generic clock (GCLK) for this channel will be restarted if the channel uses a synchronized path or a resynchronized path, without waking the system from sleep. The clock remains active only as long as necessary to handle the event. After the event has been handled, the clock will be turned off and the system will remain in the original sleep mode. This is known as SleepWalking. When an asynchronous path is used, there is no need for the clock to be activated for the event to be propagated to the user. On a software reset, all registers are set to their reset values and any ongoing events are canceled. 23.5.3 Clocks The EVSYS bus clock (CLK_EVSYS_APB) can be enabled and disabled in the Power Manager, and the default state of CLK_EVSYS_APB can be found in the Peripheral Clock Masking section in “PM – Power Manager” on page 105. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 315 Each EVSYS channel has a dedicated generic clock (GCLK_EVSYS_x). These are used for detection and propagation of events for each channel. These clocks must be configured and enabled in the generic clock controller before using the EVSYS. Please refer to “GCLK – Generic Clock Controller” on page 83 for details. 23.5.4 DMA Not applicable. 23.5.5 Interrupts The interrupt request line is connected to the interrupt controller. Using the EVSYS interrupts requires the interrupt controller to be configured first. Please refer to “Nested Vector Interrupt Controller” on page 28 for details. 23.5.6 Events Not applicable. 23.5.7 Debug Operation When the CPU is halted in debug mode, the EVSYS continues normal operation. If the EVSYS is configured in a way that requires it to be periodically serviced by the CPU through interrupts or similar, improper operation or data loss may result during debugging. 23.5.8 Register Access Protection All registers with write-access are optionally write-protected by the Peripheral Access Controller (PAC), except the following register: z Interrupt Flag Status and Clear register (INTFLAG) Write-protection is denoted by the Write-Protected property in the register description. Write-protection does not apply for accesses through an external debugger. Refer to “PAC – Peripheral Access Controller” on page 31 for details. 23.5.9 Analog Connections Not applicable. 23.6 Functional Description 23.6.1 Principle of Operation Event users are connected to multiplexers that have all available event channels as input. The multiplexer must be configured to select one of these channels. The channels can be configured to route signals from any event generator, but cannot be connected to multiple event generators. 23.6.2 Basic Operation 23.6.2.1 Initialization The peripheral that is to act as event generator should be configured to be able to generate events. The peripheral to act as event user should be configured to handle incoming events. When this has been done, the event system is ready to be configured. The configuration must follow this order: 1. Configure the event user by performing a single 16-bit write to the User Multiplexer register (USER) with: 1.1. The channel that is to be connected to a user written to the Channel bit group (USER.CHANNEL) 1.2. The user to connect the channel to written to the User bit group (USER.USER) 2. Configure the channel by performing a single 32-bit write to the Channel (CHANNEL) register with: 2.1. The channel to be configured written to the Channel Selection bit group (CHANNEL.CHANNEL) Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 316 2.2. The path to be used written to the Path Selection bit group (CHANNEL.PATH) 2.3. The type of edge detection to use on the channel written to the Edge Selection bit group (CHANNEL.EDGSEL) 2.4. The event generator to be used written to the Event Generator bit group (CHANNEL.EVGEN) 23.6.2.2 Enabling, Disabling and Resetting The EVSYS is always enabled. The EVSYS is reset by writing a one to the Software Reset bit in the Control register (CTRL.SWRST). All registers in the EVSYS will be reset to their initial state. Refer to the CTRL register for details. 23.6.2.3 User Multiplexer Setup Each user multiplexer is dedicated to one event user. A user multiplexer receives all event channel outputs and must be configured to select one of these channels. The user must always be configured before the channel is configured. A full list of selectable users can be found in the User Multiplexer register (USER) description. Refer to Table 23-6 for details. To configure a user multiplexer, the USER register must be written in a single 16-bit write. It is possible to read out the configuration of a user by first selecting the user by writing to USER.USER using an 8-bit write and then performing a read of the USER register. Figure 23-2. User MUX CHANNEL_EVT_0 CHANNEL_EVT_1 CHANNEL_EVT_m USER MUX USER.CHANNEL USER_EVT_x USER_EVT_y PERIPHERAL A USER_EVT_z PERIPHERAL B 23.6.2.4 Channel Setup The channel to be used with an event user must be configured with an event generator. The path of the channel should be configured, and when using a synchronous path or resynchronized path, the edge selection should be configured. All these configurations are available in the Channel register (CHANNEL). To configure a channel, the Channel register must be written in a single, 32-bit write. It is possible to read out the configuration of a channel by first selecting the channel by writing to CHANNEL.CHANNEL using a, 8-bit write, and then performing a read of the CHANNEL register. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 317 Event Generators The event generator is selected by writing to the Event Generator bit group in the Channel register (CHANNEL.EVGEN). A full list of selectable generators can be found in the CHANNEL register description. Refer to Table 23-3 for details. The channels are not connected to any of the event generators (CHANNEL.EVGEN = 0x00) by default. 23.6.2.5 Channel Path There are three different ways to propagate the event provided by an event generator: z Asynchronous path z Synchronous path z Resynchronized path Figure 23-3. Channel CLOCK_REQUEST_m CHANNEL m SLEEPWALKING DETECTOR ASYNC GENERATORS EVENTS SYNC CHANNEL_EVT_m EDGE DETECTION PERIPHERALS RESYNC CHANNEL.SWEVT CHANNEL.EDGSEL CHANNEL.PATH CHANNEL.EVGEN The path is selected by writing to the Path Selection bit group in the Channel register (CHANNEL.PATH). Asynchronous Path When using the asynchronous path, the events are propagated from the event generator to the event user with no intervention from the event system. This means that if the GCLK_EVSYS_x for the channel used is inactive, the event will still be propagated to the user. Events propagated in the asynchronous path cannot generate any interrupts, and no channel status bits will indicate the state of the channel. No edge detection is available; this must be handled in the event user. When the event generator and the event user share the same generic clock, using the asynchronous path will propagate the event with the least amount of latency. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 318 Synchronous Path The synchronous path should be used when the event generator and the event channel share the same generic clock. If they do not share the same clock, a logic change from the event generator to the event channel might not be detected in the channel, which means that the event will not be propagated to the event user. When using the synchronous path, the channel is capable of generating interrupts. The channel status bits in the Channel Status register (CHSTATUS) are also updated and available for use. If the Generic Clocks Request bit in the Control register (CTRL.GCLKREQ) is zero, the channel operates in SleepWalking mode and request the configured generic clock only when an event is to be propagated through the channel. If CTRL.GCLKREQ is one, the generic clock will always be on for the configured channel. Resynchronized Path The resynchronized path should be used when the event generator and the event channel do not share the same clock. When the resynchronized path is used, resynchronization of the event from the event generator is done in the channel. When the resynchronized path is used, the channel is capable of generating interrupts. The channel status bits in the Channel Status register (CHSTATUS) are also updated and available for use. If the Generic Clocks Request bit in the Control register (CTRL.GCLKREQ) is zero, the channel operates in SleepWalking mode and request the configured generic clock only when an event is to be propagated through the channel. If CTRL.GCLKREQ is one, the generic clock will always be on for the configured channel. 23.6.2.6 Edge Detection When synchronous or resynchronized paths are used, edge detection must be used. The event system can perform edge detection in three different ways: z Generate an event only on the rising edge z Generate an event only on the falling edge z Generate an event on rising and falling edges. Edge detection is selected by writing to the Edge Selection bit group in the Channel register (CHANNEL.EDGSEL). If the generator event is a pulse, the Both Edges method must not be selected. Use the Rising Edge or Falling Edge detection method, depending on the generator event default level. 23.6.2.7 The Overrun Channel x Interrupt The Overrun Channel x interrupt flag in the Interrupt Flag Status and Clear register (INTFLAG.OVRx) is set and the optional interrupt is generated in the following two cases: z At least one of the event users on channel x is not ready when a new event occurs z An event occurs when the previous event on channel x has not yet been handled by all event users INTFLAG.OVRx will be set when using a synchronous or resynchronized path, but not when using an asynchronous path. 23.6.2.8 The Event Detected Channel x Interrupt The Event Detected Channel x interrupt flag in the Interrupt Flag Status and Clear register (INTFLAG.EVDx) is set when an event coming from the event generator configured on channel x is detected. INTFLAG.EVDx will be set when using a synchronous and resynchronized path, but not when using an asynchronous path. 23.6.2.9 Channel Status The Channel Status register (CHSTATUS) updates the status of the channels when a synchronous or resynchronized path is in use. There are two different status bits in CHSTATUS for each of the available channels: The CHSTATUS.CHBUSYx bit is set to one if an event on the corresponding channel x has not been handled by all event users connected to that channel. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 319 The CHSTATUS.USRRDYx bit is set to one if all event users connected to the corresponding channel x are ready to handle incoming events on that channel. 23.6.2.10 Software Event A software event can be initiated on a channel by writing a one to the Software Event bit in the Channel register (CHANNEL.SWEVT) together with the Channel bits (CHANNEL.CHANNEL). This will generate a software event on the selected channel. The software event can be used for application debugging, and functions like any event generator. To use the software event, the event path must be configured to either a synchronous path or resynchronized path (CHANNEL.PATH = 0x0 or 0x1), edge detection must be configured to rising-edge detection (CHANNEL.EDGSEL= 0x1) and the Generic Clock Request bit must be set to one (CTRL.GCLKREQ=0x1). 23.6.3 Interrupts The EVSYS has the following interrupt sources: z Overrun Channel x interrupt (INTFLAG) z Event Detected Channel x interrupt (INTFLAG) Each interrupt source has an interrupt flag associated with it. The interrupt flag in the Interrupt Flag Status and Clear register (INTFLAG) is set when the interrupt condition occurs. Each interrupt can be individually enabled by writing a one to the corresponding bit in the Interrupt Enable Set register (INTENSET), and disabled by writing a one to the corresponding bit in the Interrupt Enable Clear register (INTENCLR). An interrupt request is generated when the interrupt flag is set and the corresponding interrupt is enabled. The interrupt request remains active until the interrupt flag is cleared, the interrupt is disabled or the EVSYS is reset. See the INTFLAG register for details on how to clear interrupt flags. The EVSYS has one common interrupt request line for all the interrupt sources. The user must read the INTFLAG register to determine which interrupt condition is present. Note that interrupts must be globally enabled for interrupt requests to be generated. Please refer to “Nested Vector Interrupt Controller” on page 28 for details. 23.6.4 Sleep Mode Operation The EVSYS can generate interrupts to wake up the device from any sleep mode. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 320 23.7 Register Summary Offset Name Bit Pos. 0x00 CTRL 7:0 0x01 Reserved 0x02 Reserved 0x03 Reserved 0x04 GCLKREQ 7:0 0x05 SWRST CHANNEL[7:0] 15:8 SWEVT CHANNEL 0x06 23:16 0x07 31:24 0x08 EVGEN[7:0] EDGSEL[1:0] 7:0 USER[7:0] 15:8 CHANNEL[7:0] PATH[1:0] USER 0x09 0x0A Reserved 0x0B Reserved 0x0C 0x0D 7:0 USRRDY7 USRRDY6 USRRDY5 USRRDY4 USRRDY3 USRRDY2 USRRDY1 USRRDY0 15:8 CHBUSY7 CHBUSY6 CHBUSY5 CHBUSY4 CHBUSY3 CHBUSY2 CHBUSY1 CHBUSY0 CHSTATUS 0x0E 23:16 0x0F 31:24 0x10 7:0 OVR7 OVR6 OVR5 OVR4 OVR3 OVR2 OVR1 OVR0 15:8 EVD7 EVD6 EVD5 EVD4 EVD3 EVD2 EVD1 EVD0 0x11 INTENCLR 0x12 23:16 0x13 31:24 0x14 7:0 OVR7 OVR6 OVR5 OVR4 OVR3 OVR2 OVR1 OVR0 15:8 EVD7 EVD6 EVD5 EVD4 EVD3 EVD2 EVD1 EVD0 0x15 INTENSET 0x16 23:16 0x17 31:24 0x18 7:0 OVR7 OVR6 OVR5 OVR4 OVR3 OVR2 OVR1 OVR0 15:8 EVD7 EVD6 EVD5 EVD4 EVD3 EVD2 EVD1 EVD0 0x19 INTFLAG 0x1A 23:16 0x1B 31:24 Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 321 23.8 Register Description Registers can be 8, 16 or 32 bits wide. Atomic 8-, 16- and 32-bit accesses are supported. In addition, the 8-bit quarters and 16-bit halves of a 32-bit register and the 8-bit halves of a 16-bit register can be accessed directly. Some registers are optionally write-protected by the Peripheral Access Controller (PAC). Write-protection is denoted by the Write-Protected property in each individual register description. Please refer to “Register Access Protection” on page 316 and “PAC – Peripheral Access Controller” on page 31 for details. 23.8.1 Control Name: CTRL Offset: 0x00 Reset: 0x00 Property: Write-Protected Bit 7 6 5 4 3 2 1 GCLKREQ 0 SWRST Access R R R R/W R R R W Reset 0 0 0 0 0 0 0 0 z Bits 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. These bits will always return zero when read. z Bit 4 – GCLKREQ: Generic Clock Requests This bit is used to determine whether the generic clocks used for the different channels should be on all the time or only when an event needs the generic clock. Events propagated trough asynchronous paths will not need a generic clock. 0: Generic clock is requested and turned on only if an event is detected. 1: Generic clock for a channel is always on. z Bits 3:1 – 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. These bits will always return zero when read. z Bit 0 – SWRST: Software Reset Writing a zero to this bit has no effect. Writing a one to this bit resets all registers in the EVSYS to their initial state. Writing a one to CTRL.SWRST will always take precedence, meaning that all other writes in the same write-operation will be discarded. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 322 23.8.2 Channel This register allows the user to configure the channel specified in the CHANNEL bit group. To write to this register, do a single, 32-bit write of all the configuration and channel selection data. To read from this register, first do an 8-bit write to the CHANNEL.CHANNEL bit group specifying the channel configuration to be read, and then read the Channel register (CHANNEL). Name: CHANNEL Offset: 0x04 Reset: 0x00000000 Property: Write-Protected Bit 31 30 29 28 27 26 25 EDGSEL[1:0] 24 PATH[1:0] Access R R R R R/W R/W R/W R/W Reset 0 0 0 0 0 0 0 0 23 22 21 20 19 18 17 16 Bit EVGEN[7:0] Access R/W R/W R/W R/W R/W R/W R/W R/W Reset 0 0 0 0 0 0 0 0 Bit 15 14 13 12 11 10 9 8 SWEVT Access R R R R R R R R/W Reset 0 0 0 0 0 0 0 0 Bit 7 6 5 4 3 2 1 0 CHANNEL[7:0] Access Reset R/W R/W R/W R/W R/W R/W R/W R/W 0 0 0 0 0 0 0 0 z Bits 31:28 – 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. These bits will always return zero when read. z Bits 27:26 – EDGSEL: Edge Detection Selection These bits set the type of edge detection to be used on the channel. These bits must be written to zero when using the asynchronous path. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 323 Table 23-1. Edge Detection Selection Value Name Description 0x0 NO_EVT_OUTPUT No event output when using the resynchronized or synchronous path 0x1 RISING_EDGE Event detection only on the rising edge of the signal from the event generator 0x2 FALLING_EDGE Event detection only on the falling edge of the signal from the event generator 0x3 BOTH_EDGES Event detection on rising and falling edges of the signal from the event generator z Bits 25:24 – PATH: Path Selection These bits areused to chose which path will be used by the selected channel. Table 23-2. Path Selection Value Name Description 0x0 SYNCHRONOUS Synchronous path 0x1 RESYNCHRONIZED Resynchronized path 0x2 ASYNCHRONOUS Asynchronous path 0x3 - Reserved z Bits 23:16 – EVGEN: Event Generator These bits areused to choose the event generator to connect to the selected channel. Table 23-3. Event Generator Selection Value Event Generator Description 0x00 No event generator selected 0x01 RTC CMP0 Compare 0 (mode 0 and 1) or Alarm 0 (mode 2) 0x02 RTC CMP1 Compare 1 0x03 RTC OVF Overflow 0x04 RTC PER0 Period 0 0x05 RTC PER1 Period 1 0x06 RTC PER2 Period 2 0x07 RTC PER3 Period 3 0x08 RTC PER4 Period 4 0x09 RTC PER5 Period 5 0x0A RTC PER6 Period 6 0x0B RTC PER7 Period 7 0x0C EIC EXTINT0 External Interrupt 0 0x0D EIC EXTINT1 External Interrupt 1 Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 324 Table 23-3. Event Generator Selection (Continued) Value Event Generator Description 0x0E EIC EXTINT2 External Interrupt 2 0x0F EIC EXTINT3 External Interrupt 3 0x10 EIC EXTINT4 External Interrupt 4 0x11 EIC EXTINT5 External Interrupt 5 0x12 EIC EXTINT6 External Interrupt 6 0x13 EIC EXTINT7 External Interrupt 7 0x14 EIC EXTINT8 External Interrupt 8 0x15 EIC EXTINT9 External Interrupt 9 0x16 EIC EXTINT10 External Interrupt 10 0x17 EIC EXTINT11 External Interrupt 11 0x18 EIC EXTINT12 External Interrupt 12 0x19 EIC EXTINT13 External Interrupt 13 0x1A EIC EXTINT14 External Interrupt 14 0x1B EIC EXTINT15 External Interrupt 15 0x1C TC0 OVF Overflow/Underflow 0x1D TC0 MC0 Match/Capture 0 0x1E TC0 MC1 Match/Capture 1 0x1F TC1 OVF Overflow/Underflow 0x20 TC1 MC0 Match/Capture 0 0x21 TC1 MC1 Match/Capture 1 0x22 TC2 OVF Overflow/Underflow 0x23 TC2 MC0 Match/Capture 0 0x24 TC2 MC1 Match/Capture 1 0x25 TC3 OVF Overflow/Underflow 0x26 TC3 MC0 Match/Capture 0 0x27 TC3 MC1 Match/Capture 1 0x28 TC4 OVF Overflow/Underflow 0x29 TC4 MC0 Match/Capture 0 0x2A TC4 MC1 Match/Capture 1 0x2B TC5 OVF Overflow/Underflow 0x2C TC5 MC0 Match/Capture 0 0x2D TC5 MC1 Match/Capture 1 0x2E TC6 OVF Overflow/Underflow Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 325 Table 23-3. Event Generator Selection (Continued) Value Event Generator Description 0x2F TC6 MC0 Match/Capture 0 0x30 TC6 MC1 Match/Capture 1 0x31 TC7 OVF Overflow/Underflow 0x32 TC7 MC0 Match/Capture 0 0x33 TC7 MC1 Match/Capture 1 0x34 ADC RESRDY Result Ready 0x35 ADC WINMON Window Monitor 0x36 AC COMP0 Comparator 0 0x37 AC COMP1 Comparator 1 0x38 AC WIN Window 0 0x39 DAC EMPTY Data Buffer Empty 0x3A PTC EOC End of Conversion 0x3B PTC WCOMP Window Comparator 0x3C-0xFF Reserved z Bits 15:9 – 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. These bits will always return zero when read. z Bit 8 – SWEVT: Software Event This bit is used to insert a software event on the channel selected by the CHANNEL.CHANNEL bit group. This bit must be written together with CHANNEL.CHANNELusing a 16-bit write. Writing a zero to this bit has no effect. Writing a one to this bit will trigger a software event for the corresponding channel. This bit will always return zero when read. z Bits 7:0 – CHANNEL: Channel Selection These bits are used to select the channel to be set up or read from. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 326 Table 23-4. Channel Selection Value Channel Number 0x00 0 0x01 1 0x02 2 0x03 3 0x04 4 0x05 5 0x06 6 0x07 7 0x08-0xFF Reserved Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 327 23.8.3 User Multiplexer This register is used to configure a specified event user. To write to this register, do a single, 16-bit write of all the configuration and event user selection data. To read from this register, first do an 8-bit write to the USER.USER bit group specifying the event user configuration to be read, and then read USER. Name: USER Offset: 0x08 Reset: 0x0000 Property: Write-protected Bit 15 14 13 12 11 10 9 8 CHANNEL[7:0] Access R/W R/W R/W R/W R/W R/W R/W R/W Reset 0 0 0 0 0 0 0 0 Bit 7 6 5 4 3 2 1 0 USER[7:0] Access R/W R/W R/W R/W R/W R/W R/W R/W 0 0 0 0 0 0 0 0 Reset z Bits 15:8 – CHANNEL: Channel Event Selection These bits are used to select the channel to connect to the event user. Please note that to select channel n, the value (n+1) must be written to the USER.CHANNEL bit group. Table 23-5. Channel Event Selection Value Channel Number 0x00 No channel output selected 0x01 0 0x02 1 0x03 2 0x04 3 0x05 4 0x06 5 0x07 6 0x08 7 0x09-0xFF Reserved z Bits 7:0 – USER: User Multiplexer Selection These bits select the event user to be configured with a channel, or the event user to read the channel value from. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 328 Table 23-6. User Multiplexer Selection USER[7:0] User Multiplexer Description Path Type 0x00 TC0 Asynchronous, synchronous and resynchronized paths 0x01 TC1 Asynchronous, synchronous and resynchronized paths 0x02 TC2 Asynchronous, synchronous and resynchronized paths 0x03 TC3 Asynchronous, synchronous and resynchronized paths 0x04 TC4 Asynchronous, synchronous and resynchronized paths 0x05 TC5 Asynchronous, synchronous and resynchronized paths 0x06 TC6 Asynchronous, synchronous and resynchronized paths 0x07 TC7 Asynchronous, synchronous and resynchronized paths 0x08 ADC START ADC start conversion Asynchronous path only 0x09 ADC SYNC Flush ADC Asynchronous path only 0x0A AC COMP0 Start comparator 0 Asynchronous path only 0x0B AC COMP1 Start comparator 1 Asynchronous path only 0x0C DAC START DAC start conversion Asynchronous path only 0x0D PTC STCONV PTC start conversion Asynchronous path only 0x0E-0xFF Reserved Reserved Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 329 23.8.4 Channel Status Name: CHSTATUS Offset: 0x0C Reset: 0x000000FF Property: – Bit 31 30 29 28 27 26 25 24 Access R R R R R R R R Reset 0 0 0 0 0 0 0 0 Bit 23 22 21 20 19 18 17 16 Access R R R R R R R R Reset 0 0 0 0 0 0 0 0 Bit 15 14 13 12 11 10 9 8 CHBUSY7 CHBUSY6 CHBUSY5 CHBUSY4 CHBUSY3 CHBUSY2 CHBUSY1 CHBUSY0 Access R R R R R R R R Reset 0 0 0 0 0 0 0 0 Bit 7 6 5 4 3 2 1 0 USRRDY7 USRRDY6 USRRDY5 USRRDY4 USRRDY3 USRRDY2 USRRDY1 USRRDY0 Access R R R R R R R R Reset 0 0 0 0 0 0 0 0 z Bits 31:16 – 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. These bits will always return zero when read. z Bits 15:8 – CHBUSYx: Channel Busy x This bit is cleared when channel x is idle This bit is set if an event on channel x has not been handled by all event users connected to channel x. z Bits 7:0 – USRRDYx: User Ready for Channel x This bit is cleared when at least one of the event users connected to the channel is not ready. This bit is set when all event users connected to channel x are ready to handle incoming events on channel x. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 330 23.8.5 Interrupt Enable Clear This register allows the user to disable an interrupt without doing a read-modify-write operation. Changes in this register will also be reflected in the Interrupt Enable Set register (INTENSET). Name: INTENCLR Offset: 0x10 Reset: 0x00000000 Property: Write-Protected Bit 31 30 29 28 27 26 25 24 Access R R R R R R R R Reset 0 0 0 0 0 0 0 0 Bit 23 22 21 20 19 18 17 16 Access R R R R R R R R Reset 0 0 0 0 0 0 0 0 Bit 15 14 13 12 11 10 9 8 EVD7 EVD6 EVD5 EVD4 EVD3 EVD2 EVD1 EVD0 R/W R/W R/W R/W R/W R/W R/W R/W Reset 0 0 0 0 0 0 0 0 Bit 7 6 5 4 3 2 1 0 OVR7 OVR6 OVR5 OVR4 OVR3 OVR2 OVR1 OVR0 R/W R/W R/W R/W R/W R/W R/W R/W 0 0 0 0 0 0 0 0 Access Access Reset z Bits 31:16 – 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. These bits will always return zero when read. z Bits 15:8 – EVDx: Event Detected Channel x Interrupt Enable 0: The Event Detected Channel x interrupt is disabled. 1: The Event Detected Channel x interrupt is enabled. Writing a zero to this bit has no effect. Writing a one to this bit will clear the Event Detected Channel x Interrupt Enable bit, which disables the Event Detected Channel x interrupt. z Bits 7:0 – OVRx: Overrun Channel x Interrupt Enable 0: The Overrun Channel x interrupt is disabled. 1: The Overrun Channel x interrupt is enabled. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 331 Writing a zero to this bit has no effect. Writing a one to this bit will clear the Overrun Channel x Interrupt Enable bit, which disables the Overrun Channel x interrupt. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 332 23.8.6 Interrupt Enable Set This register allows the user to enable an interrupt without doing a read-modify-write operation. Changes in this register will also be reflected in the Interrupt Enable Clear register (INTENCLR). Name: INTENSET Offset: 0x14 Reset: 0x00000000 Property: Write-Protected Bit 31 30 29 28 27 26 25 24 Access R R R R R R R R Reset 0 0 0 0 0 0 0 0 Bit 23 22 21 20 19 18 17 16 Access R R R R R R R R Reset 0 0 0 0 0 0 0 0 Bit 15 14 13 12 11 10 9 8 EVD7 EVD6 EVD5 EVD4 EVD3 EVD2 EVD1 EVD0 R/W R/W R/W R/W R/W R/W R/W R/W Reset 0 0 0 0 0 0 0 0 Bit 7 6 5 4 3 2 1 0 OVR7 OVR6 OVR5 OVR4 OVR3 OVR2 OVR1 OVR0 R/W R/W R/W R/W R/W R/W R/W R/W 0 0 0 0 0 0 0 0 Access Access Reset z Bits 31:16 – 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. These bits will always return zero when read. z Bits 15:8 – EVDx: Event Detected Channel x Interrupt Enable 0: The Event Detected Channel x interrupt is disabled. 1: The Event Detected Channel x interrupt is enabled. Writing a zero to this bit has no effect. Writing a one to this bit will set the Event Detected Channel x Interrupt Enable bit, which enables the Event Detected Channel x interrupt. z Bits 7:0 – OVRx: Overrun Channel x Interrupt Enable 0: The Overrun Channel x interrupt is disabled. 1: The Overrun Channel x interrupt is enabled. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 333 Writing a zero to this bit has no effect. Writing a one to this bit will set the Overrun Channel x Interrupt Enable bit, which enables the Overrun Channel x interrupt. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 334 23.8.7 Interrupt Flag Status and Clear Name: INTFLAG Offset: 0x18 Reset: 0x00000000 Property: – Bit 31 30 29 28 27 26 25 24 Access R R R R R R R R Reset 0 0 0 0 0 0 0 0 Bit 23 22 21 20 19 18 17 16 Access R R R R R R R R Reset 0 0 0 0 0 0 0 0 Bit 15 14 13 12 11 10 9 8 EVD7 EVD6 EVD5 EVD4 EVD3 EVD2 EVD1 EVD0 R/W R/W R/W R/W R/W R/W R/W R/W Reset 0 0 0 0 0 0 0 0 Bit 7 6 5 4 3 2 1 0 OVR7 OVR6 OVR5 OVR4 OVR3 OVR2 OVR1 OVR0 R/W R/W R/W R/W R/W R/W R/W R/W 0 0 0 0 0 0 0 0 Access Access Reset z Bits 31:16 – 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. These bits will always return zero when read. z Bits 15:8 – EVDx: Event Detected Channel x This flag is set on the next CLK_EVSYS_APB cycle when an event is being propagated through the channel, and an interrupt request will be generated if INTENCLR/SET.EVDx is one. When the event channel path is asynchronous, the EVDx interrupt flag will not be set. Writing a zero to this bit has no effect. Writing a one to this bit will clear the Event Detected Channel n interrupt flag. z Bits 7:0 – OVRx: Overrun Channel x This flag is set on the next CLK_EVSYS cycle after an overrun channel condition occurs, and an interrupt request will be generated if INTENCLR/SET.OVRx is one. There are two possible overrun channel conditions: z One or more of the event users on channel x are not ready when a new event occurs z An event happens when the previous event on channel x has not yet been handled by all event users When the event channel path is asynchronous, the OVRx interrupt flag will not be set. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 335 Writing a zero to this bit has no effect. Writing a one to this bit will clear the Overrun Channel x interrupt flag. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 336 24. SERCOM – Serial Communication Interface 24.1 Overview The serial communication interface (SERCOM) can be configured to support a number of modes; I2C, SPI and USART. Once configured and enabled, all SERCOM resources are dedicated to the selected mode. The SERCOM serial engine consists of a transmitter and receiver, baud-rate generator and address matching functionality. It can be configured to use the internal generic clock or an external clock, making operation in all sleep modes possible. 24.2 Features z Combined interface configurable as one of the following: I2C – Two-wire serial interface z SMBus™ compatible. z SPI – Serial peripheral interface z USART – Universal synchronous and asynchronous serial receiver and transmitter z z Single transmit buffer and double receive buffer z Baud-rate generator z Address match/mask logic z Operational in all sleep modes 24.3 Block Diagram Figure 24-1. SERCOM Block Diagram SERCOM Register Interface CONTROL/STATUS Mode Specific TX/RX DATA BAUD/ADDR Serial Engine Mode n Mode 1 Baud Rate Generator Transmitter PAD[3:0] Mode 0 Address Match Receiver 24.4 Signal Description See the respective SERCOM mode chapters for details: z “SERCOM USART – SERCOM Universal Synchronous and Asynchronous Receiver and Transmitter” on page 345 z “SERCOM SPI – SERCOM Serial Peripheral Interface” on page 369 z “SERCOM I2C – SERCOM Inter-Integrated Circuit” on page 394 Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 337 24.5 Product Dependencies In order to use this peripheral, other parts of the system must be configured correctly, as described below. 24.5.1 I/O Lines Using the SERCOM I/O lines requires the I/O pins to be configured using port configuration (PORT). Refer to “PORT” on page 289 for details. From Figure 24-1 one can see that the SERCOM has four internal pads, PAD[3:0]. The signals from I2C, SPI and USART are routed through these SERCOM pads via a multiplexer. The configuration of the multiplexer is available from the different SERCOM modes. Refer to the mode specific chapters for details: z “SERCOM USART – SERCOM Universal Synchronous and Asynchronous Receiver and Transmitter” on page 345 z “SERCOM SPI – SERCOM Serial Peripheral Interface” on page 369 z “SERCOM I2C – SERCOM Inter-Integrated Circuit” on page 394 24.5.2 Power Management The SERCOM can operate in any sleep mode.SERCOM interrupts can be used to wake up the device from sleep modes. Refer to “PM – Power Manager” on page 105 for details on the different sleep modes. 24.5.3 Clocks The SERCOM bus clock (CLK_SERCOMx_APB) is enabled by default, and can be enabled and disabled in the Power Manager. Refer to “PM – Power Manager” on page 105 for details. Two generic clocks are used by the SERCOM: GCLK_SERCOMx_CORE and GCLK_SERCOMx_SLOW. The core clock (GCLK_SERCOMx_CORE) is required to clock the SERCOM while operating as a master, while the slow clock (GCLK_SERCOMx_SLOW) is only required for certain functions. See specific mode chapters for details. These clocks must be configured and enabled in the Generic Clock Controller (GCLK) before using the SERCOM. Refer to “GCLK – Generic Clock Controller” on page 83 for details. These generic clocks are asynchronous to the user interface clock (CLK_SERCOMx_APB). Due to this asynchronicity, writes to certain registers will require synchronization between the clock domains. Refer to “Synchronization” on page 344 for further details. 24.5.4 DMA Not applicable. 24.5.5 Interrupts The interrupt request line is connected to the iInterrupt Controller. Using the SERCOM interrupts requires the Interrupt Controller to be configured first. Refer to “Nested Vector Interrupt Controller” on page 28 for details. 24.5.6 Events Not applicable. 24.5.7 Debug Operation When the CPU is halted in debug mode, the SERCOM continues normal operation. If the SERCOM is configured in a way that requires it to be periodically serviced by the CPU through interrupts or similar, improper operation or data loss may result during debugging. The SERCOM can be forced to halt operation during debugging. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 338 24.5.8 Register Access Protection All registers with write-access are optionally write-protected by the Peripheral Access Controller (PAC), except the following registers: z Interrupt Flag Status and Clear register (INTFLAG) z Address register (ADDR) z Data register (DATA) Write-protection is denoted by the Write-Protection property in the register description. When the CPU is halted in debug mode, all write-protection is automatically disabled. Refer to “PAC – Peripheral Access Controller” on page 31 for details. 24.5.9 Analog Connections Not applicable. 24.6 Functional Description 24.6.1 Principle of Operation The basic structure of the SERCOM serial engine is shown in Figure 24-2. Fields shown in capital letters are synchronous to the system clock and accessible by the CPU, while fields with lowercase letters can be configured to run on the GCLK_SERCOMx_CORE clock or an external clock. Figure 24-2. SERCOM Serial Engine Transmitter Selectable Internal Clk (GCLK) Ext Clk BAUD Address Match TX DATA ADDR/ADDRMASK baud rate generator 1/- /2- /16 tx shift register Receiver rx shift register == status Baud Rate Ggenerator STATUS rx buffer RX DATA The transmitter consists of a single write buffer and a shift register. The receiver consists of a two-level receive buffer and a shift register. The baud-rate generator is capable of running on the GCLK_SERCOMx_CORE clock or an external clock. Address matching logic is included for SPI and I2C operation. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 339 24.6.2 Basic Operation 24.6.2.1 Initialization The SERCOM must be configured to the desired mode by writing to the Operating Mode bits in the Control A register (CTRLA.MODE). Refer to Figure 24-1 for details. Table 24-1. SERCOM Modes CTRLA.MODE Description 0x0 USART with external clock 0x1 USART with internal clock 0x2 SPI in slave operation 0x3 SPI in master operation 0x4 I2C slave operation 0x5 I2C master operation 0x6-0x7 Reserved For further initialization information, see the respective SERCOM mode chapters. 24.6.2.2 Enabling, Disabling and Resetting The SERCOM is enabled by writing a one to the Enable bit in the Control A register (CTRLA.ENABLE). The SERCOM is disabled by writing a zero to CTRLA.ENABLE. The SERCOM is reset by writing a one to the Software Reset bit in the Control A register (CTRLA.SWRST). All registers in the SERCOM, except DBGCTRL, will be reset to their initial state, and the SERCOM will be disabled. Refer to the CTRLA register descriptions for details. 24.6.2.3 Clock Generation – Baud-Rate Generator The baud-rate generator, as shown in Figure 24-3, is used for internal clock generation for asynchronous and synchronous communication. The generated output frequency (fBAUD) is determined by the Baud register (BAUD) setting and the baud reference frequency (fREF). The baud reference clock is the serial engine clock, and it can be internal or external. For asynchronous operation, the /16 (divide-by-16) output is used when transmitting and the /1 (divide-by-1) output is used when receiving. For synchronous operation the /2 (divide-by-2) output is used. This functionality is automatically configured, depending on the selected operating mode. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 340 Figure 24-3. Baud Rate Generator Selectable Internal Clk (GCLK) Baud Rate Generator 1 Ext Clk fref Base Period 0 /2 /1 CTRLA.MODE[0] /8 /2 /16 0 Tx Clk 1 1 CTRLA.MODE 0 1 Clock Recovery Rx Clk 0 Table 24-2 contains equations for calculating the baud rate (in bits per second) and for calculating the BAUD register value for each mode of operation. For asynchronous mode, the BAUD register value is 16 bits (0 to 65,535), while for synchronous mode, the BAUD register value is 8 bits (0 to 255). Table 24-2. Baud Rate Equations Operating Mode Condition f Asynchronous f Synchronous BAUD BAUD ≤ ≤ Baud Rate (Bits Per Second) f REF 16 f REF 2 f f f BAUD Register Value Calculation BAUD ⎞ ⎛ = ⎜1 − ⎟ BAUD 16 ⎝ 65,536 ⎠ BAUD = REF f REF 2( BAUD + 1) ⎛ BAUD = 65,536⎜1 − 16 ⎜ ⎝ BAUD = f 2 f REF f f BAUD REF ⎞ ⎟ ⎟ ⎠ −1 BAUD Asynchronous Mode BAUD Value Selection The formula given for fBAUD calculates the average frequency over 65,536 fREF cycles. Although the BAUD register can be set to any value between 0 and 65,536, the values that will change the average frequency of fBAUD over a single frame are more constrained. The BAUD register values that will affect the average frequency over a single frame lead to an integer increase in the cycles per frame (CPF) CPF = f f REF (D + S ) BAUD where z D represent the data bits per frame z S represent the sum of start and first stop bits, if present Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 341 Table 24-3 shows the BAUD register value versus baud frequency at a serial engine frequency of 48MHz. This assumes a D value of 8 bits and an S value of 2 bits (10 bits, including start and stop bits). Table 24-3. BAUD Register Value vs. Baud Frequency BAUD Register Value Serial Engine CPF fBAUD at 48MHz Serial Engine Frequency (fREF) 0 – 406 160 3MHz 407 – 808 161 2.981MHz 809 – 1205 162 2.963MHz 65206 31775 15.11kHz 65207 31871 15.06kHz 65208 31969 15.01kHz ... Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 342 24.6.3 Additional Features 24.6.3.1 Address Match and Mask The SERCOM address match and mask feature is capable of matching one address with a mask, two unique addresses or a range of addresses, based on the mode selected. The match uses seven or eight bits, depending on the mode. Address With Mask An address written to the Address bits in the Address register (ADDR.ADDR) with a mask written to the Address Mask bits in the Address register (ADDR.ADDRMASK) will yield an address match. All bits that are masked are not included in the match. Note that setting the ADDR.ADDRMASK to all zeros will match a single unique address, while setting ADDR.ADDRMASK to all ones will result in all addresses being accepted. Figure 24-4. Address With Mask ADDR ADDRMASK == Match rx shift register Two Unique Addresses The two addresses written to ADDR and ADDRMASK will cause a match. Figure 24-5. Two Unique Addresses ADDR == Match rx shift register == ADDRMASK Address Range The range of addresses between and including ADDR.ADDR and ADDR.ADDRMASK will cause a match. ADDR.ADDR and ADDR.ADDRMASK can be set to any two addresses, with ADDR.ADDR acting as the upper limit and ADDR.ADDRMASK acting as the lower limit. Figure 24-6. Address Range ADDRMASK rx shift register ADDR == Match 24.6.4 DMA Operation Not applicable. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 343 24.6.5 Interrupts Interrupt sources are mode-specific. See the respective SERCOM mode chapters for details. Each interrupt source has an interrupt flag associated with it. The interrupt flag in the Interrupt Flag Status and Clear register (INTFLAG) is set when the interrupt condition occurs. Each interrupt can be individually enabled by writing a one to the corresponding bit in the Interrupt Enable Set register (INTENSET), and disabled by writing a one to the corresponding bit in the Interrupt Enable Clear register (INTENCLR). An interrupt request is generated when the interrupt flag is set and the corresponding interrupt is enabled. The interrupt request remains active until the interrupt flag is cleared, the interrupt is disabled or the SERCOM is reset. See the register description for details on how to clear interrupt flags. The SERCOM has one common interrupt request line for all the interrupt sources. The user must read the INTFLAG register to determine which interrupt condition is present. Note that interrupts must be globally enabled for interrupt requests to be generated. Refer to “Nested Vector Interrupt Controller” on page 28 for details. 24.6.6 Events Not applicable. 24.6.7 Sleep Mode Operation The peripheral can operate in any sleep mode where the selected serial clock is running. This clock can be external or generated by the internal baud-rate generator. The SERCOM interrupts can be used to wake up the device from sleep modes. Refer to the different SERCOM mode chapters for details. 24.6.8 Synchronization Due to the asynchronicity between CLK_SERCOMx_APB and GCLK_SERCOMx_CORE, some registers must be synchronized when accessed. A register can require: z Synchronization when written z Synchronization when read z Synchronization when written and read z No synchronization When executing an operation that requires synchronization, the Synchronization Busy bit in the Status register (STATUS.SYNCBUSY) will be set immediately, and cleared when synchronization is complete. The Synchronization Ready interrupt can be used to signal when synchronization is complete. If an operation that requires synchronization is executed while STATUS.SYNCBUSY is one, the bus will be stalled. All operations will complete successfully, but the CPU will be stalled and interrupts will be pending as long as the bus is stalled. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 344 25. SERCOM USART – SERCOM Universal Synchronous and Asynchronous Receiver and Transmitter 25.1 Overview The universal synchronous and asynchronous receiver and transmitter (USART) is one of the available modes in the Serial Communication Interface (SERCOM). Refer to “SERCOM – Serial Communication Interface” on page 337 for details. The USART uses the SERCOM transmitter and receiver configured as shown in Figure 25-1. Fields shown in capital letters are synchronous to the CLK_SERCOMx_APB and accessible by the CPU, while fields with lowercase letters can be configured to run on the internal generic clock or an external clock. The transmitter consists of a single write buffer, a shift register and control logic for handling different frame formats. The write buffer allows continuous data transmission without any delay between frames. The receiver consists of a two-level receive buffer and a shift register. Status information for the received data is available for error checking. Data and clock recovery units ensure robust synchronization and noise filtering during asynchronous data reception. 25.2 Features z Full-duplex operation z Asynchronous (with clock reconstruction) or synchronous operation z Internal or external clock source for asynchronous and synchronous operation z Baud-rate generator z Supports serial frames with 5, 6, 7, 8 or 9 data bits and 1 or 2 stop bits z Odd or even parity generation and parity check z Selectable LSB- or MSB-first data transfer z Buffer overflow and frame error detection z Noise filtering, including false start-bit detection and digital low-pass filter z Can operate in all sleep modes z Operation at speeds up to half the system clock for internally generated clocks z Operation at speeds up to the system clock for externally generated clocks Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 345 25.3 Block Diagram Figure 25-1. USART Block Diagram BAUD Internal Clk (GCLK) TX DATA baud rate generator /1 - /2 - /16 tx shift register TxD rx shift register RxD XCK Signal name 25.4 Type status rx buffer STATUS RX DATA Signal Description Signal Name Type Description PAD[3:0] Digital I/O General SERCOM pins Please refer to “I/O Multiplexing and Considerations” on page 15 for details on the pin mapping for this peripheral. One signal can be mapped on several pins. 25.5 Product Dependencies In order to use this peripheral, other parts of the system must be configured correctly, as described below. 25.5.1 I/O Lines Using the USART’s I/O lines requires the I/O pins to be configured using port configuration (PORT). Refer to “PORT” on page 289 for details. When the SERCOM is used in USART mode, the pins should be configured according to Table 25-1. If the receiver or transmitter is disabled, these pins can be used for other purposes. Table 25-1. USART Pin Configuration Pin Pin Configuration TxD Output RxD Input XCK Output or input Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 346 The combined configuration of PORT and the Transmit Data Pinout and Receive Data Pinout bit groups (refer to the Control A register description) will define the physical position of the USART signals in Table 25-1. 25.5.2 Power Management The USART can continue to operate in any sleep mode where the selected source clock is running. The USART interrupts can be used to wake up the device from sleep modes. The events can trigger other operations in the system without exiting sleep modes. Refer to “PM – Power Manager” on page 105 for details on the different sleep modes. 25.5.3 Clocks The SERCOM bus clock (CLK_SERCOMx_APB, where x represents the specific SERCOM instance number) can be enabled and disabled in the Power Manager, and the default state of CLK_SERCOMx_APB can be found in the Peripheral Clock Masking section in “PM – Power Manager” on page 105. A generic clock (GCLK_SERCOMx_CORE) is required to clock the SERCOMx_CORE. This clock must be configured and enabled in the Generic Clock Controller before using the SERCOMx_CORE. Refer to “GCLK – Generic Clock Controller” on page 83 for details. This generic clock is asynchronous to the bus clock (CLK_SERCOMx_APB). Due to this asynchronicity, writes to certain registers will require synchronization between the clock domains. Refer to “Synchronization” on page 353 for further details. 25.5.4 DMA Not applicable. 25.5.5 Interrupts The interrupt request line is connected to the Interrupt Controller. Using the USART interrupts requires the Interrupt Controller to be configured first. Refer to “Nested Vector Interrupt Controller” on page 28 for details. 25.5.6 Events Not applicable. 25.5.7 Debug Operation When the CPU is halted in debug mode, the USART continues normal operation. If the USART is configured in a way that requires it to be periodically serviced by the CPU through interrupts or similar, improper operation or data loss may result during debugging. The USART can be forced to halt operation during debugging. Refer to DBGCTRL for details. 25.5.8 Register Access Protection All registers with write-access are optionally write-protected by the Peripheral Access Controller (PAC), except the following registers: z Interrupt Flag Status and Clear register (INTFLAG) z Status register (STATUS) z Data register (DATA) Write-protection is denoted by the Write-Protection property in the register description. When the CPU is halted in debug mode, all write-protection is automatically disabled. Write-protection does not apply for accesses through an external debugger. Refer to “PAC – Peripheral Access Controller” on page 31 for details. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 347 25.5.9 Analog Connections Not applicable. 25.6 Functional Description 25.6.1 Principle of Operation The USART uses three communication lines for data transfer: z RxD for receiving z TxD for transmitting z XCK for the transmission clock in synchronous operation USART data transfer is frame based, where a serial frame consists of: z 1 start bit z 5, 6, 7, 8 or 9 data bits z MSB or LSB first z No, even or odd parity bit z 1 or 2 stop bits A frame starts with the start bit followed by one character of data bits. If enabled, the parity bit is inserted after the data bits and before the first stop bit. One frame can be directly followed by a new frame, or the communication line can return to the idle (high) state. Figure 25-2 illustrates the possible frame formats. Bits inside brackets are optional. Figure 25-2. Frame Formats Frame (IDLE) St 0 1 2 3 4 [5] [6] [7] [8] [P] Sp1 [Sp2] (St/IDLE) St Start bit; always low (n) Data bits; 0 to 8 P Parity bit; odd or even Sp Stop bit; always high IDLE No transfers on the communication line; always high in this state 25.6.2 Basic Operation 25.6.2.1 Initialization The following registers are enable-protected, meaning they can only be written when the USART is disabled (CTRL.ENABLE is zero): z Control A register (CTRLA), except the Enable (ENABLE) and Software Reset (SWRST) bits z Control B register (CTRLB), except the Receiver Enable (RXEN) and Transmitter Enable (TXEN) bits z Baud register (BAUD) Any writes to these registers when the USART is enabled or is being enabled (CTRL.ENABLE is one) will be discarded. Writes to these registers) while the peripheral is being disabled will be completed after the disabling is complete. Before the USART is enabled, it must be configured, as outlined in the following steps: z USART mode with external or internal clock must be selected first by writing 0x0 or 0x1 to the Operating Mode bit group in the Control A register (CTRLA.MODE) Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 348 z Communication mode (asynchronous or synchronous) must be selected by writing to the Communication Mode bit in the Control A register (CTRLA.CMODE) z SERCOM pad to use for the receiver must be selected by writing to the Receive Data Pinout bit group in the Control A register (CTRLA.RXPO) z SERCOM pads to use for the transmitter and external clock must be selected by writing to the Transmit Data Pinout bit in the Control A register (CTRLA.TXPO) z Character size must be selected by writing to the Character Size bit group in the Control B register (CTRLB.CHSIZE) z MSB- or LSB-first data transmission must be selected by writing to the Data Order bit in the Control A register (CTRLA.DORD) z When parity mode is to be used, even or odd parity must be selected by writing to the Parity Mode bit in the Control B register (CTRLB.PMODE) and enabled by writing 0x1 to the Frame Format bit group in the Control A register (CTRLA.FORM) z Number of stop bits must be selected by writing to the Stop Bit Mode bit in the Control B register (CTRLB.SBMODE) z When using an internal clock, the Baud register (BAUD) must be written to generate the desired baud rate z The transmitter and receiver can be enabled by writing ones to the Receiver Enable and Transmitter Enable bits in the Control B register (CTRLB.RXEN and CTRLB.TXEN) 25.6.2.2 Enabling, Disabling and Resetting The USART is enabled by writing a one to the Enable bit in the Control A register (CTRLA.ENABLE). The USART is disabled by writing a zero to CTRLA.ENABLE. The USART is reset by writing a one to the Software Reset bit in the Control A register (CTRLA.SWRST). All registers in the USART, except DBGCTRL, will be reset to their initial state, and the USART will be disabled. Refer to the CTRLA register for details. 25.6.2.3 Clock Generation and Selection For both synchronous and asynchronous modes, the clock used for shifting and sampling data can be generated internally by the SERCOM baud-rate generator or supplied externally through the XCK line. Synchronous mode is selected by writing a one to the Communication Mode bit in the Control A register (CTRLA.CMODE) and asynchronous mode is selected by writing a zero to CTRLA.CMODE. The internal clock source is selected by writing 0x1 to the Operation Mode bit group in the Control A register (CTRLA.MODE) and the external clock source is selected by writing 0x0 to CTRLA.MODE. The SERCOM baud-rate generator is configured as shown in Figure 25-3. When CTRLA.CMODE is zero, the baud-rate generator is automatically set to asynchronous mode and the 16-bit Baud register value is used. When CTRLA.CMODE is one, the baud-rate generator is automatically set to synchronous mode and the eight LSBs of the Baud register are used. Refer to “Clock Generation – Baud-Rate Generator” on page 340 for details on configuring the baud rate. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 349 Figure 25-3. Clock Generation Internal C lk (G C LK ) B au d R ate G enerator 1 0 B ase Period C T R LA .M O D E [0] /2 /1 /8 /2 /16 0 Tx C lk 1 1 XCK C TR LA .C M O D E 0 1 R x C lk 0 Synchronous Clock Operation When synchronous mode is used, the CTRLA.MODE bit group controls whether the transmission clock (XCK line) is an input or output. The dependency between the clock edges and data sampling or data change is the same for internal and external clocks. Data input on the RxD pin is sampled at the opposite XCK clock edge as data is driven on the TxD pin. The Clock Polarity bit in the Control A register (CTRLA.CPOL) selects which XCK clock edge is used for RxD sampling and which is used for TxD change. As shown in Figure 25-4, when CTRLA.CPOL is zero, the data will be changed on the rising XCK edge and sampled on the falling XCK edge. If CTRLA.CPOL is one, the data will be changed on the falling edge of XCK and sampled on the rising edge of XCK. Figure 25-4. Synchronous Mode XCK Timing Change XCK CTRLA.CPOL=1 RxD / TxD Sample Change XCK CTRLA.CPOL=0 RxD / TxD Sample When the clock is provided through XCK (CTRLA.MODE is 0x0), the shift registers operate directly on the XCK clock. This means that XCK is not synchronized with the system clock and, therefore, can operate at frequencies up to the system frequency. 25.6.2.4 Data Register The USART Transmit Data register (TxDATA) and USART Receive Data register(RxDATA) share the same I/O address, referred to as the Data register (DATA). Writing the DATA register will update the Transmit Data register. Reading the DATA register will return the contents of the Receive Data register. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 350 25.6.2.5 Data Transmission A data transmission is initiated by loading the DATA register with the data to be sent. The data in TxDATA is moved to the shift register when the shift register is empty and ready to send a new frame. When the shift register is loaded with data, one complete frame will be transmitted. The Transmit Complete interrupt flag in the Interrupt Flag Status and Clear register (INTFLAG.TXC) is set, and the optional interrupt is generated, when the entire frame in the shift register has been shifted out and there is no new data written to the DATA register. The DATA register should only be written when the Data Register Empty flag in the Interrupt Flag Status and Clear register (INTFLAG.DRE) is set, which indicates that the register is empty and ready for new data. Disabling the Transmitter Disabling the transmitter will not become effective until any ongoing and pending transmissions are completed, i.e., when the transmit shift register and TxDATA do not contain data to be transmitted. The transmitter is disabled by writing a zero to the Transmitter Enable bit in the Control B register (CTRLB.TXEN). 25.6.2.6 Data Reception The receiver starts data reception when a valid start bit is detected. Each bit that follows the start bit will be sampled at the baud rate or XCK clock, and shifted into the receive shift register until the first stop bit of a frame is received. When the first stop bit is received and a complete serial frame is present in the receive shift register, the contents of the shift register will be moved into the two-level receive buffer. The Receive Complete interrupt flag in the Interrupt Flag Status and Clear register (INTFLAG.RXC) is set, and the optional interrupt is generated. A second stop bit will be ignored by the receiver. The received data can be read by reading the DATA register. DATA should not be read unless the Receive Complete interrupt flag is set. Disabling the Receiver Disabling the receiver by writing a zero to the Receiver Enable bit in the Control B register (CTRLB.RXEN) will flush the two-level receive buffer, and data from ongoing receptions will be lost. Error Bits The USART receiver has three error bits. The Frame Error (FERR), Buffer Overflow (BUFOVF) and Parity Error (PERR) bits can be read from the Status (STATUS) register. Upon error detection, the corresponding bit will be set until it is cleared by writing a one to it. These bits are also automatically cleared when the receiver is disabled. Asynchronous Data Reception The USART includes a clock recovery and data recovery unit for handling asynchronous data reception. The clock recovery logic is used to synchronize the incoming asynchronous serial frames at the RxD pin to the internally generated baud-rate clock. The data recovery logic samples and applies a low-pass filter to each incoming bit, thereby improving the noise immunity of the receiver. The asynchronous reception operational range depends on the accuracy of the internal baud-rate clock, the rate of the incoming frames and the frame size (in number of bits). Asynchronous Operational Range The operational range of the receiver depends on the difference between the received bit rate and the internally generated baud rate. If the baud rate of an external transmitter is too high or too low compared to the internally generated baud rate, the receiver will not be able to synchronize the frames to the start bit. There are two possible sources for a mismatch in baud rate. The reference clock will always have some minor instability. In addition, the baud-rate generator can not always do an exact division of the reference clock frequency to get the baud rate desired. In this case, the BAUD register value should be selected to give the lowest possible error. Refer to “Asynchronous Mode BAUD Value Selection” on page 341 for details. Recommended maximum receiver baud-rate errors for various character sizes are shown in the table below. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 351 Table 25-2. Asynchronous Receiver Error D (Data bits + Parity) RSLOW(%) RFAST(%) Max Total Error (%) Recommended Max Rx Error (%) 5 94.12 107.69 +5.88/-7.69 +/-2.5 6 94.92 106.67 +5.08/-6.67 +/-2.0 7 95.52 105.88 +4.48/-5.88 +/-2.0 8 96.00 105.26 +4.00/-5.26 +/-2.0 9 96.39 104.76 +3.61/-4.76 +/-1.5 10 96.70 104.35 +3.30/-4.35 +/-1.5 The recommended maximum receiver baud-rate error assumes that the receiver and transmitter equally divide the maximum total error. The following equations can be used to calculate the ratio of the incoming data rate and internal receiver baud rate: R SLOW = 16( D + 1) 16( D + 1) + 6 R FAST = 16( D + 2) 16( D + 1) + 8 where: z Dis the sum of character size and parity size (D = 5 to 10 bits) z RSLOW is the ratio of the slowest incoming data rate that can be accepted in relation to the receiver baud rate z RFAST is the ratio of the fastest incoming data rate that can be accepted in relation to the receiver baud rate 25.6.3 Additional Features 25.6.3.1 Parity Even or odd parity can be selected for error checking by writing 0x1 to the Frame Format bit group in the Control A register (CTRLA.FORM). If even parity is selected by writing a zero to the Parity Mode bit in the Control B register (CTRLB.PMODE), the parity bit of the outgoing frame is set to one if the number of data bits that are one is odd (making the total number of ones even). If odd parity is selected by writing a one to CTRLB.PMODE, the parity bit of the outgoing frame is set to one if the number of data bits that are one is even (making the total number of ones odd). When parity checking is enabled, the parity checker calculates the parity of the data bits in incoming frames and compares the result with the parity bit of the corresponding frame. If a parity error is detected, the Parity Error bit in the Status register (STATUS.PERR) is set. 25.6.4 Interrupts The USART has the following interrupt sources: z Receive Complete z Transmit Complete z Data Register Empty Each interrupt source has an interrupt flag associated with it. The interrupt flag in the Interrupt Flag Status and Clear register (INTFLAG) is set when the interrupt condition occurs. Each interrupt can be individually enabled by writing a one to the corresponding bit in the Interrupt Enable Set register (INTENSET), and disabled by writing a one to the corresponding bit in the Interrupt Enable Clear register (INTENCLR). An interrupt request is generated when the interrupt flag is set and the corresponding interrupt is enabled. The interrupt request remains active until the interrupt flag is Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 352 cleared, the interrupt is disabled or the USART is reset. See the register description for details on how to clear interrupt flags. The USART has one common interrupt request line for all the interrupt sources. The user must read INTFLAG to determine which interrupt condition is present. Note that interrupts must be globally enabled for interrupt requests to be generated. Refer to “Nested Vector Interrupt Controller” on page 28 for details. 25.6.5 Events Not applicable. 25.6.6 Sleep Mode Operation When using internal clocking, writing the Run In Standby bit in the Control A register (CTRLA.RUNSTDBY) to one will allow GCLK_SERCOMx_CORE to be enabled in all sleep modes. Any interrupt can wake up the device. When using external clocking, writing a one to CTRLA.RUNSTDBY will allow the Receive Complete interrupt.to wake up the device. If CTRLA.RUNSTDBY is zero, the internal clock will be disabled when any ongoing transfer is finished. A Transfer Complete interrupt can wake up the device. When using external clocking, this will be disconnected when any ongoing transfer is finished, and all reception will be dropped. 25.6.7 Synchronization Due to the asynchronicity between CLK_SERCOMx_APB and GCLK_SERCOMx_CORE, some registers must be synchronized when accessed. A register can require: z Synchronization when written z Synchronization when read z Synchronization when written and read z No synchronization When executing an operation that requires synchronization, the Synchronization Busy bit in the Status register (STATUS.SYNCBUSY) will be set immediately, and cleared when synchronization is complete. If an operation that requires synchronization is executed while STATUS.SYNCBUSY is one, the bus will be stalled. All operations will complete successfully, but the CPU will be stalled and interrupts will be pending as long as the bus is stalled. The following bits need synchronization when written: z Software Reset bit in the Control A register (CTRLA.SWRST) z Enable bit in the Control A register (CTRLA.ENABLE) z Receiver Enable bit in the Control B register (CTRLB.RXEN) z Transmitter Enable bit in the Control B register (CTRLB.TXEN) CTRLB.RXEN and CTRLB.TXEN behave somewhat differently than described above. Refer to CTRLB register description for details. Synchronization is denoted by the Write-Synchronized property in the register description. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 353 25.7 Offset Register Summary Name 0x00 Bit Pos. 7:0 0x01 RUNSTDBY MODE[2:0] ENABLE SWRST 15:8 CTRLA 0x02 23:16 0x03 31:24 DORD 0x04 7:0 SBMODE 0x05 0x06 CPOL TXPO CMODE FORM[3:0] CHSIZE[2:0] PMODE 15:8 CTRLB DBGCTRL 23:16 0x07 31:24 0x08 7:0 0x09 RXPO[1:0] RXEN TXEN DBGSTOP Reserved 0x0A 7:0 BAUD[7:0] 15:8 BAUD[15:8] BAUD 0x0B 0x0C INTENCLR 7:0 RXC TXC DRE 0x0D INTENSET 7:0 RXC TXC DRE 0x0E INTFLAG 7:0 RXC TXC DRE 0x0F Reserved 7:0 BUFOVF FERR PERR 0x10 STATUS 0x11 15:8 0x12 Reserved 0x13 Reserved 0x14 Reserved 0x15 Reserved 0x16 Reserved 0x17 Reserved 0x18 7:0 SYNCBUSY DATA[7:0] DATA 0x19 15:8 0x1A Reserved 0x1B Reserved 0x1C Reserved 0x1D Reserved 0x1E Reserved 0x1F Reserved DATA[8] Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 354 25.8 Register Description Registers can be 8, 16 or 32 bits wide. Atomic 8-, 16- and 32-bit accesses are supported. In addition, the 8-bit quarters and 16-bit halves of a 32-bit register and the 8-bit halves of a 16-bit register can be accessed directly. Some registers are optionally write-protected by the Peripheral Access Controller (PAC). Write-protection is denoted by the Write-Protected property in each individual register description. Refer to “Register Access Protection” on page 347 for details. Some registers require synchronization when read and/or written. Synchronization is denoted by the Synchronized property in each individual register description. Refer to “Synchronization” on page 353 for details. Some registers are enable-protected, meaning they can only be written when the USART is disabled. Enable-protection is denoted by the Enable-Protected property in each individual register description. 25.8.1 Control A Name: CTRLA Offset: 0x00 Reset: 0x00000000 Property: Enable-Protected, Write-Protected, Write-Synchronized Bit 31 30 29 28 DORD CPOL CMODE 27 26 25 24 FORM[3:0] Access R R/W R/W R/W R/W R/W R/W R/W Reset 0 0 0 0 0 0 0 0 Bit 23 22 21 20 19 18 17 16 RXPO[1:0] TXPO Access R R R/W R/W R R R R/W Reset 0 0 0 0 0 0 0 0 Bit 15 14 13 12 11 10 9 8 Access R R R R R R R R Reset 0 0 0 0 0 0 0 0 Bit 7 6 5 4 3 2 1 0 ENABLE SWRST RUNSTDBY Access Reset z MODE[2:0] R/W R R R/W R/W R/W R/W R/W 0 0 0 0 0 0 0 0 Bit 31 – 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. This bit will always return zero when read. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 355 z Bit 30 – DORD: Data Order This bit indicates the data order when a character is shifted out from the Data register. 0: MSB is transmitted first. 1: LSB is transmitted first. This bit is not synchronized. z Bit 29 – CPOL: Clock Polarity This bit indicates the relationship between data output change and data input sampling in synchronous mode. This bit is not synchronized. Table 25-3. Clock Polarity z CPOL TxD Change RxD Sample 0x0 Rising XCK edge Falling XCK edge 0x1 Falling XCK edge Rising XCK edge Bit 28 – CMODE: Communication Mode This bit indicates asynchronous or synchronous communication. 0: Asynchronous communication. 1: Synchronous communication. This bit is not synchronized. z Bits 27:24 – FORM[3:0]: Frame Format These bits define the frame format. These bits are not synchronized. Table 25-4. Frame Format FORM[3:0] Description 0x0 USART frame 0x1 USART frame with parity 0x2-0xF Reserved z Bits 23:22 – 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. These bits will always return zero when read. z Bits 21:20 – RXPO[1:0]: Receive Data Pinout These bits define the receive data (RxD) pin configuration. These bits are not synchronized. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 356 Table 25-5. Receive Data Pinout RXPO[1:0] Description 0x0 SERCOM_PAD0 0x1 SERCOM_PAD1 0x2 SERCOM_PAD2 0x3 SERCOM_PAD3 z Bits 19:17 – 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. These bits will always return zero when read. z Bit 16 – TXPO: Transmit Data Pinout This bit defines the transmit data (TxD) and XCK pin configurations. This bit is not synchronized. Table 25-6. Transmit Data Pinout TXPO TxD Pin Location XCK Pin Location (When Applicable) 0x0 SERCOM_PAD0 SERCOM_PAD1 0x1 SERCOM_PAD2 SERCOM_PAD3 z Bits 15:8 – 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. These bits will always return zero when read. z Bit 7 – RUNSTDBY: Run In Standby This bit defines the functionality in standby sleep mode. This bit is not synchronized. Table 25-7. Run In Standby RUNSTDBY 0x0 External Clock Internal Clock External clock is disconnected when ongoing transfer is finished. All reception is dropped. 0x1 Genericclock is enabled in all sleep modes. Any interrupt can wake up the device. z Bits 6: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. These bits will always return zero when read. z Bits 4:2 – MODE: Operating Mode These bits must be written to 0x0 or 0x1 to select the USART serial communication interface of the SERCOM. 0x0: USART with external clock. 0x1: USART with internal clock. These bits are not synchronized. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 357 z Bit 1 – ENABLE: Enable 0: The peripheral is disabled or being disabled. 1: The peripheral is enabled or being enabled. Due to synchronization, there is delay from writing CTRLA.ENABLE until the peripheral is enabled/disabled. The value written to CTRLA.ENABLE will read back immediately and the Synchronization Busy bit in the Status register (STATUS.SYNCBUSY) will be set. STATUS.SYNCBUSY is cleared when the operation is complete. This bit is not enable-protected. z Bit 0 – SWRST: Software Reset 0: There is no reset operation ongoing. 1: The reset operation is ongoing. Writing a zero to this bit has no effect. Writing a one to this bit resets all registers in the SERCOM, except DBGCTRL, to their initial state, and the SERCOM will be disabled. Writing a one to CTRLA.SWRST will always take precedence, meaning that all other writes in the same write-operation will be discarded. Due to synchronization, there is a delay from writing CTRLA.SWRST until the reset is complete. CTRLA.SWRST and STATUS.SYNCBUSY will both be cleared when the reset is complete. This bit is not enable-protected. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 358 25.8.2 Control B Name: CTRLB Offset: 0x04 Reset: 0x00000000 Property: Enable-Protected, Write-Protected, Write-Synchronized Bit 31 30 29 28 27 26 25 24 Access R R R R R R R R Reset 0 0 0 0 0 0 0 0 Bit 23 22 21 20 19 18 17 16 RXEN TXEN Access R R R R R R R/W R/W Reset 0 0 0 0 0 0 0 0 Bit 15 14 13 12 11 10 9 8 PMODE Access R R R/W R R R R/W R Reset 0 0 0 0 0 0 0 0 Bit 7 6 5 4 3 2 1 0 SBMODE CHSIZE[2:0] Access R R/W R R R R/W R/W R/W Reset 0 0 0 0 0 0 0 0 z Bits 31:18 – 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. These bits will always return zero when read. z Bit 17 – RXEN: Receiver Enable 0: The receiver is disabled or being enabled. 1: The receiver is enabled or will be enabled when the USART is enabled. Writing a zero to this bit will disable the USART receiver. Disabling the receiver will flush the receive buffer and clear the FERR, PERR and BUFOVF bits in the STATUS register. Writing a one to CTRLB.RXEN when the USART is disabled will set CTRLB.RXEN immediately. When the USART is enabled, CTRLB.RXEN will be cleared, and STATUS.SYNCBUSY will be set and remain set until the receiver is enabled. When the receiver is enabled, CTRLB.RXEN will read back as one. Writing a one to CTRLB.RXEN when the USART is enabled will set STATUS.SYNCBUSY, which will remain set until the receiver is enabled, and CTRLB.RXEN will read back as one. This bit is not enable-protected. z Bit 16 – TXEN: Transmitter Enable 0: The transmitter is disabled or being enabled. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 359 1: The transmitter is enabled or will be enabled when the USART is enabled. Writing a zero to this bit will disable the USART transmitter. Disabling the transmitter will not become effective until ongoing and pending transmissions are completed. Writing a one to CTRLB.TXEN when the USART is disabled will set CTRLB.TXEN immediately. When the USART is enabled, CTRLB.TXEN will be cleared, and STATUS.SYNCBUSY will be set and remain set until the transmitter is enabled. When the transmitter is enabled, CTRLB.TXEN will read back as one. Writing a one to CTRLB.TXEN when the USART is enabled will set STATUS.SYNCBUSY, which will remain set until the receiver is enabled, and CTRLB.TXEN will read back as one. This bit is not enable-protected. z Bits 15:14 – 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. These bits will always return zero when read. z Bit 13 – PMODE: Parity Mode This bit selects the type of parity used when parity is enabled (CTRLA.FORM is one). The transmitter will automatically generate and send the parity of the transmitted data bits within each frame. The receiver will generate a parity value for the incoming data and parity bit, compare it to the parity mode and, if a mismatch is detected, STATUS.PERR will be set. 0: Even parity. 1: Odd parity. This bit is not synchronized. z Bits 12:7 – 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. These bits will always return zero when read. -z Bit 6 – SBMODE: Stop Bit Mode This bit selects the number of stop bits transmitted. 0: One stop bit. 1: Two stop bits. This bit is not synchronized. z Bits 5:3 – 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. These bits will always return zero when read. z Bits 2:0 – CHSIZE[2:0]: Character Size These bits select the number of bits in a character. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 360 These bits are not synchronized. Table 25-8. Character Size CHSIZE[2:0] Description 0x0 8 bits 0x1 9 bits 0x2-0x4 Reserved 0x5 5 bits 0x6 6 bits 0x7 7 bits Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 361 25.8.3 Debug Control Name: DBGCTRL Offset: 0x08 Reset: 0x00 Property: Write-Protected Bit 7 6 5 4 3 2 1 0 DBGSTOP Access R R R R R R R R/W Reset 0 0 0 0 0 0 0 0 z Bits 7:1 – 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. These bits will always return zero when read. z Bit 0 – DBGSTOP: Debug Stop Mode This bit controls the baud-rate generator functionality when the CPU is halted by an external debugger. 0: The baud-rate generator continues normal operation when the CPU is halted by an external debugger. 1: The baud-rate generator is halted when the CPU is halted by an external debugger. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 362 25.8.4 Baud Name: BAUD Offset: 0x0A Reset: 0x0000 Property: Enable-Protected, Write-Protected Bit 15 14 13 12 11 10 9 8 BAUD[15:8] Access R/W R/W R/W R/W R/W R/W R/W R/W Reset 0 0 0 0 0 0 0 0 Bit 7 6 5 4 3 2 1 0 BAUD[7:0] Access Reset z R/W R/W R/W R/W R/W R/W R/W R/W 0 0 0 0 0 0 0 0 Bits 15:0 – BAUD: Baud Value These bits control the clock generation, as described in the SERCOM Baud Rate section. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 363 25.8.5 Interrupt Enable Clear This register allows the user to disable an interrupt without doing a read-modify-write operation. Changes in this register will also be reflected in the Interrupt Enable Setregister (INTENSET). Name: INTENCLR Offset: 0x0C Reset: 0x00 Property: Write-Protected Bit 7 6 5 4 3 2 1 0 RXC TXC DRE Access R R R R R R/W R/W R/W Reset 0 0 0 0 0 0 0 0 z Bits 7:3 – 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. These bits will always return zero when read. z Bit 2 – RXC: Receive Complete Interrupt Enable 0: Receive Complete interrupt is disabled. 1: Receive Complete interrupt is enabled. Writing a zero to this bit has no effect. Writing a one to this bit will clear the Receive Complete Interrupt Enable bit, which disables the Receive Complete interrupt. z Bit 1 – TXC: Transmit Complete Interrupt Enable 0: Transmit Complete interrupt is disabled. 1: Transmit Complete interrupt is enabled. Writing a zero to this bit has no effect. Writing a one to this bit will clear the Transmit Complete Interrupt Enable bit, which disables the Receive Complete interrupt. z Bit 0 – DRE: Data Register Empty Interrupt Enable 0: Data Register Empty interrupt is disabled. 1: Data Register Empty interrupt is enabled. Writing a zero to this bit has no effect. Writing a one to this bit will clear the Data Register Empty Interrupt Enable bit, which disables the Data Register Empty interrupt. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 364 25.8.6 Interrupt Enable Set This register allows the user to enable an interrupt without doing a read-modify-write operation. Changes in this register will also be reflected in the Interrupt Enable Clear register (INTENCLR) . Name: INTENSET Offset: 0x0D Reset: 0x00 Property: Write-Protected Bit 7 6 5 4 3 2 1 0 RXC TXC DRE Access R R R R R R/W R/W R/W Reset 0 0 0 0 0 0 0 0 z Bits 7:3 – 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. These bits will always return zero when read. z Bit 2 – RXC: Receive Complete Interrupt Enable 0: Receive Complete interrupt is disabled. 1: Receive Complete interrupt is enabled. Writing a zero to this bit has no effect. Writing a one to this bit will set the Receive Complete Interrupt Enable bit, which enables the Receive Complete interrupt. z Bit 1 – TXC: Transmit Complete Interrupt Enable 0: Transmit Complete interrupt is disabled. 1: Transmit Complete interrupt is enabled. Writing a zero to this bit has no effect. Writing a one to this bit will set the Transmit Complete Interrupt Enable bit, which enables the Transmit Complete interrupt. z Bit 0 – DRE: Data Register Empty Interrupt Enable 0: Data Register Empty interrupt is disabled. 1: Data Register Empty interrupt is enabled. Writing a zero to this bit has no effect. Writing a one to this bit will set the Data Register Empty Interrupt Enable bit, which enables the Data Register Empty interrupt. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 365 25.8.7 Interrupt Flag Status and Clear Name: INTFLAG Offset: 0x0E Reset: 0x00 Property: Bit 7 6 5 4 3 2 1 0 RXC TXC DRE Access R R R R R R R/W R Reset 0 0 0 0 0 0 0 0 z Bits 7:3 – 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. These bits will always return zero when read. z --Bit 2 – RXC: Receive Complete This flag is cleared by reading the Data register (DATA) or by disabling the receiver. This flag is set when there are unread data in DATA. Writing a zero to this bit has no effect. Writing a one to this bit has no effect. z Bit 1 – TXC: Transmit Complete This flag is cleared by writing a one to it or by writing new data to DATA. This flag is set when the entire frame in the transmit shift register has been shifted out and there are no new data in DATA. Writing a zero to this bit has no effect. Writing a one to this bit will clear the flag. z Bit 0 – DRE: Data Register Empty This flag is cleared by writing new data to DATA. This flag is set when DATA is empty and ready to be written. Writing a zero to this bit has no effect. Writing a one to this bit has no effect. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 366 25.8.8 Status Name: STATUS Offset: 0x10 Reset: 0x0000 Property: Bit 15 14 13 12 11 10 9 8 R/W R R R R R R R Reset 0 0 0 0 0 0 0 0 Bit 7 6 5 4 3 2 1 0 BUFOVF FERR PERR SYNCBUSY Access Access R R R R R R/W R/W R/W Reset 0 0 0 0 0 0 0 0 z Bit 15 – SYNCBUSY: Synchronization Busy This bit is cleared when the synchronization of registers between the clock domains is complete. This bit is set when the synchronization of registers between clock domains is started. z Bits 14:3 – 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. These bits will always return zero when read. z Bit 2 – BUFOVF: Buffer Overflow Reading this bit before reading the Data register will indicate the error status of the next character to be read. This bit is cleared by writing a one to the bit or by disabling the receiver. This bit is set when a buffer overflow condition is detected. A buffer overflow occurs when the receive buffer is full, there is a new character waiting in the receive shift register and a new start bit is detected. Writing a zero to this bit has no effect. Writing a one to this bit will clear it. z Bit 1 – FERR: Frame Error Reading this bit before reading the Data register will indicate the error status of the next character to be read. This bit is cleared by writing a one to the bit or by disabling the receiver. This bit is set if the received character had a frame error, i.e., when the first stop bit is zero. Writing a zero to this bit has no effect. Writing a one to this bit will clear it. z Bit 0 – PERR: Parity Error Reading this bit before reading the Data register will indicate the error status of the next character to be read. This bit is cleared by writing a one to the bit or by disabling the receiver. This bit is set if parity checking is enabled (CTRLA.FORM is one) and a parity error is detected. Writing a zero to this bit has no effect. Writing a one to this bit will clear it. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 367 25.8.9 Data Name: DATA Offset: 0x18 Reset: 0x0000 Property: - Bit 15 14 13 12 11 10 9 8 DATA[8] Access R R R R R R R R/W Reset 0 0 0 0 0 0 0 0 Bit 7 6 5 4 3 2 1 0 DATA[7:0] Access Reset R/W R/W R/W R/W R/W R/W R/W R/W 0 0 0 0 0 0 0 0 z Bits 15:9 – 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. These bits will always return zero when read. z Bits 8:0 – DATA[8:0]: Data Reading these bits will return the contents of the Receive Data register. The register should be read only when the Receive Complete Interrupt Flag bit in the Interrupt Flag Status and Clear register (INTFLAG.RXCIF) is set. The status bits in STATUS should be read before reading the DATA value in order to get any corresponding error. Writing these bits will write the Transmit Data register. This register should be written only when the Data Register Empty Interrupt Flag bit in the Interrupt Flag Status and Clear register (INTFLAG.DREIF) is set. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 368 26. SERCOM SPI – SERCOM Serial Peripheral Interface 26.1 Overview The serial peripheral interface (SPI) is one of the available modes in the Serial Communication Interface (SERCOM). Refer to “SERCOM – Serial Communication Interface” on page 337 for details. The SPI uses the SERCOM transmitter and receiver configured as shown in “Full-Duplex SPI Master Slave Interconnection” on page 369. Each side, master and slave, depicts a separate SPI containing a shift register, a transmit buffer and two receive buffers. In addition, the SPI master uses the SERCOM baud-rate generator, while the SPI slave can use the SERCOM address match logic. Fields shown in capital letters are synchronous to CLK_SERCOMx_APB and accessible by the CPU, while fields with lowercase letters are synchronous to the SCK clock. 26.2 Features z Full-duplex, four-wire interface (MISO, MOSI, SCK, _SS) z Single-buffered transmitter, double-buffered receiver z Supports all four SPI modes of operation z Single data direction operation allows alternate function on MISO or MOSI pin z Selectable LSB- or MSB-first data transfer z Master operation: z z Serial clock speed up to half the system clock 8-bit clock generator z Slave operation: z Serial clock speed up to the system clock Optional 8-bit address match operation z Operation in all sleep modes z 26.3 Block Diagram Figure 26-1. Full-Duplex SPI Master Slave Interconnection Master BAUD Slave Tx DATA Tx DATA ADDR/ADDRMASK SCK _SS baud rate generator MISO shift register shift register MOSI 26.4 rx buffer rx buffer Rx DATA Rx DATA == Address Match Signal Description Signal Name Type Description PAD[3:0] Digital I/O General SERCOM pins Refer to “I/O Multiplexing and Considerations” on page 15 for details on the pin mapping for this peripheral. One signal can be mapped to one of several pins. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 369 26.5 Product Dependencies In order to use this peripheral, other parts of the system must be configured correctly, as described below. 26.5.1 I/O Lines Using the SERCOM’s I/O lines requires the I/O pins to be configured using port configuration (PORT). Refer to “PORT” on page 289 for details. When the SERCOM is configured for SPI operation, the pins should be configured according to Table 26-1. If the receiver is disabled, the data input pin can be used for other purposes. In master mode the slave select line (_SS) is controlled by software. Table 26-1. SPI Pin Configuration Pin Master SPI Slave SPI MOSI Output Input MISO Input Output SCK Output Input _SS User defined output enable Input The combined configuration of PORT and the Data In/Data Out and Data Out Pinout bit groups in Control A register will define the physical position of the SPI signals in Table 26-1. 26.5.2 Power Management The SPI can continue to operate in any sleep mode. The SPI interrupts can be used to wake up the device from sleep modes. Refer to “PM – Power Manager” on page 105 for details on the different sleep modes. 26.5.3 Clocks The SERCOM bus clock (CLK_SERCOMx_APB) can be enabled and disabled in the Power Manager, and the default state of CLK_SERCOMx_APB can be found in the Peripheral Clock Masking section in the “PM – Power Manager” on page 105. A generic clock (GCLK_SERCOMx_CORE) is required to clock the SPI. This clock must be configured and enabled in the Generic Clock Controller before using the SPI. Refer to “GCLK – Generic Clock Controller” on page 83 for details. This generic clock is asynchronous to the bus clock (CLK_SERCOMx_APB). Due to this asynchronicity, writes to certain registers will require synchronization between the clock domains. Refer to “Synchronization” on page 377 for further details. 26.5.4 DMA Not applicable. 26.5.5 Interrupts The interrupt request line is connected to the Interrupt Controller. Using the SPI, interrupts requires the Interrupt Controller to be configured first. Refer to “Nested Vector Interrupt Controller” on page 28 for details. 26.5.6 Events Not applicable. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 370 26.5.7 Debug Operation When the CPU is halted in debug mode, the SPI continues normal operation. If the SPI is configured in a way that requires it to be periodically serviced by the CPU through interrupts or similar, improper operation or data loss may result during debugging. The SPI can be forced to halt operation during debugging. Refer to the Debug Control (DBGCTRL) register for details. 26.5.8 Register Access Protection All registers with write-access are optionally write-protected by the Peripheral Access Controller (PAC), except the following registers: z Interrupt Flag Clear and Status register (INTFLAG) z Status register (STATUS) z Data register (DATA) Write-protection is denoted by the Write-Protection property in the register description. When the CPU is halted in debug mode, all write-protection is automatically disabled. Write-protection does not apply for accesses through an external debugger. Refer to “PAC – Peripheral Access Controller” on page 31 for details. 26.5.9 Analog Connections Not applicable. 26.6 Functional Description 26.6.1 Principle of Operation The SPI is a high-speed synchronous data transfer interface. It allows fast communication between the device and peripheral devices. The SPI can operate as master or slave. As master, the SPI initiates and controls all data transactions. The SPI is single buffered for transmitting and double buffered for receiving. When transmitting data, the Data register can be loaded with the next character to be transmitted while the current transmission is in progress. For receiving, this means that the data is transferred to the two-level receive buffer upon reception, and the receiver is ready for a new character. The SPI transaction format is shown in Figure 26-2, where each transaction can contain one or more characters. The character size is configurable, and can be either 8 or 9 bits. Figure 26-2. SPI Transaction Format Transaction Character MOSI/MISO Character 0 Character 1 Character 2 _SS The SPI master must initiate a transaction by pulling low the slave select line (_SS) of the desired slave. The master and slave prepare data to be sent in their respective shift registers, and the master generates the serial clock on the SCK line. Data are always shifted from master to slave on the master output, slave input line (MOSI), and from slave to master on the master input, slave output line (MISO). The master signals the end of the transaction by pulling the _SS line high. As each character is shifted out from the master, another character is shifted in from the slave. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 371 26.6.2 Basic Operation 26.6.2.1 Initialization The following registers are enable-protected, meaning that they can only be written when the SPI is disabled (CTRL.ENABLE is zero): z Control A register (CTRLA), except Enable (CTRLA.ENABLE) and Software Reset (CTRLA.SWRST) z Control B register (CTRLB), except Receiver Enable (RXEN) z Baud register (BAUD) z Address register (ADDR) Any writes to these registers when the SPI is enabled or is being enabled (CTRL.ENABLE is one) will be discarded. Writes to these registers while the SPI is being disabled will be completed after the disabling is complete. Enable-protection is denoted by the Enable-Protection property in the register description. Before the SPI is enabled, it must be configured, as outlined by the following steps: z SPI mode in master or slave operation must be selected by writing 0x2 or 0x3 to the Operating Mode bit group in the Control A register (CTRLA.MODE) z Transfer mode must be selected by writing the Clock Polarity bit and the Clock Phase bit in the Control A register (CTRLA.CPOL and CTRLA.CPHA) z Transaction format must be selected by writing the Frame Format bit group in the Control A register (CTRLA.FORM) z SERCOM pad to use for the receiver must be selected by writing the Data In Pinout bit in the Control A register (CTRLA.DIPO) z SERCOM pads to use for the transmitter, slave select and serial clock must be selected by writing the Data Out Pinout bit group in the Control A register (CTRLA.DOPO) z Character size must be selected by writing the Character Size bit in the Control B register (CTRLB.CHSIZE) z Data direction must be selected by writing the Data Order bit in the Control A register (CTRLA.DORD) z If the SPI is used in master mode, the Baud register (BAUD) must be written to generate the desired baud rate z The receiver can be enabled by writing a one to the Receiver Enable bit in the Control B register (CTRLB.RXEN) 26.6.2.2 Enabling, Disabling and Resetting The SPI is enabled by writing a one to the Enable bit in the Control A register (CTRLA.ENABLE). The SPI is disabled by writing a zero to CTRLA.ENABLE. The SPI is reset by writing a one to the Software Reset bit in the Control A register (CTRLA.SWRST). All registers in the SPI, except DBGCTRL, will be reset to their initial state, and the SPI will be disabled. Refer to CTRLA for details. 26.6.2.3 Clock Generation In SPI master operation (CTRLA.MODE is 0x3), the serial clock (SCK) is generated internally using the SERCOM baudrate generator. When used in SPI mode, the baud-rate generator is set to synchronous mode, and the 8-bit Baud register (BAUD) value is used to generate SCK, clocking the shift register. Refer to “Clock Generation – Baud-Rate Generator” on page 340 for more details. In SPI slave operation (CTRLA.MODE is 0x2), the clock is provided by an external master on the SCK pin. This clock is used to directly clock the SPI shift register. 26.6.2.4 Data Register The SPI Transmit Data register (TxDATA) and SPI Receive Data register (RxDATA) share the same I/O address, referred to as the SPI Data register (DATA). Writing the DATA register will update the Transmit Data register. Reading the DATA register will return the contents of the Receive Data register. 26.6.2.5 SPI Transfer Modes There are four combinations of SCK phase and polarity with respect to the serial data. The SPI data transfer modes are shown in Table 26-2 and Figure 26-3. SCK phase is selected by the Clock Phase bit in the Control A register Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 372 (CTRLA.CPHA). SCK polarity is selected by the Clock Polarity bit in the Control A register (CTRLA.CPOL). Data bits are shifted out and latched in on opposite edges of the SCK signal, ensuring sufficient time for the data signals to stabilize. Table 26-2. SPI Transfer Modes Mode CPOL CPHA Leading Edge Trailing Edge 0 0 0 Rising, sample Falling, setup 1 0 1 Rising, setup Falling, sample 2 1 0 Falling, sample Rising, setup 3 1 1 Falling, setup Rising, sample Leading edge is the first clock edge in a clock cycle, while trailing edge is the second clock edge in a clock cycle. Figure 26-3. SPI Transfer Modes -ODE -ODE 3!-0,%) -/3)-)3/ #(!.'% -/3)0). #(!.'% -)3/0). 26.6.2.6 Transferring Data Master When configured as a master (CTRLA.MODE is 0x3), the _SS line can be located at any general purpose I/O pin, and must be configured as an output. When the SPI is ready for a data transaction, software must pull the _SS line low. When writing a character to the Data register (DATA), the character will be transferred to the shift register when the shift register is empty. Once the contents of TxDATA have been transferred to the shift register, the Data Register Empty flag in the Interrupt Flag Status and Clear register (INTFLAG.DRE) is set, and a new character can be written to DATA. As each character is shifted out from the master, another character is shifted in from the slave. If the receiver is enabled (CTRLA.RXEN is one), the contents of the shift register will be transferred to the two-level receive buffer. The transfer takes place in the same clock cycle as the last data bit is shifted in, and the Receive Complete Interrupt flag in the Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 373 Interrupt Flag Status and Clear register (INTFLAG.RXC) will be set. The received data can be retrieved by reading DATA. When the last character has been transmitted and there is no valid data in DATA, the Transmit Complete Interrupt flag in the Interrupt Flag Status and Clear register (INTFLAG.TXC) is set. When the transaction is finished, the master must indicate this to the slave by pulling the _SS line high. Slave When configured as a slave (CTRLA.MODE is 0x2), the SPI interface will remain inactive, with the MISO line tri-stated as long as the _SS pin is pulled high. Software may update the contents of DATA at any time, as long as the Data Register Empty flag in the Interrupt Status and Clear register (INTFLAG.DRE) is set. When _SS is pulled low and SCK is running, the slave will sample and shift out data according to the transaction mode set. When the contents of TxDATA have been loaded into the shift register, INTFLAG.DRE is set, and new data can be written to DATA. Similar to the master, the slave will receive one character for each character transmitted. On the same clock cycle as the last data bit of a character is received, the character will be transferred into the two-level receive buffer. The received character can be retrieved from DATA when INTFLAG.RCX is set. When the master pulls the _SS line high, the transaction is done and the Transmit Complete Interrupt flag in the Interrupt Flag Status and Clear register (TXC) is set. Once DATA is written, it takes three SCK clocks to load the shift register. After the DATA register is empty, it takes three CLK_SERCOM_APB cycles for INTFLAG.DRE to be set. 26.6.2.7 Receiver Error Bit The SPI receiver has one error bit: the Buffer Overflow bit (BUFOVF), which can be read from the Status register (STATUS). Upon error detection, the bit will be set until it is cleared by writing a one to it. The bit is also automatically cleared when the receiver is disabled. If the receive buffer is full and another character is received, this constitutes a buffer overflow condition (BUFOVF). When the full condition is no longer present, the overflow condition will be written to the receive buffer, along with the next frame received. Refer to STATUS for further details. 26.6.3 Additional Features 26.6.3.1 Address Recognition When the SPI is configured for slave operation (CTRLA.MODE is 0x2) with address recognition (CTRLA.FORM is 0x2), the SERCOM address recognition logic is enabled. When address recognition is enabled, the first character in a transaction is checked for an address match. If there is a match, then the Receive Complete Interrupt flag in the Interrupt Flag Status and Clear register (INTFLAG.RXC) is set, the MISO output is enabled and the transaction is processed. If there is no match, the transaction is ignored. If the device is in sleep mode, an address match can wake up the device in order to process the transaction. If the address does not match, then the complete transaction is ignored. If a 9-bit frame format is selected, only the lower 8 bits of the shift register are checked against the Address register (ADDR). Refer to “Address Match and Mask” on page 343 for further details. 26.6.3.2 Preloading of the Slave Shift Register When starting a transaction, the slave will first transmit the contents of the shift register before loading new data from DATA. The first character sent can be either the reset value of the shift register (if this is the first transmission since the last reset) or the last character in the previous transmission. Preloading can be used to preload data to the shift register while _SS is high and eliminate sending a dummy character when starting a transaction. In order to guarantee enough set-up time before the first SCK edge, enough time must be given between _SS going low and the first SCK sampling edge, as shown in Figure 26-4. Refer to <!!!CRs_ElChar_Top!!!> for further details regarding the timing. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 374 Preloading is enabled by setting the Slave Data Preload Enable bit in the Control B register (CTRLB.PLOADEN). Figure 26-4. Timing Using Preloading Required _SS to SCK time using PRELOADEN _SS _SS synchronized to system domain SCK Synchronization to system domain MISO to SCK setup time Only one data character written to DATA will be preloaded into the shift register while the synchronized _SS signal (see Figure 26-4) is high. The next character written to DATA before _SS is pulled low will be stored in DATA until transfer begins. If the shift register is not preloaded, the current contents of the shift register will be shifted out. 26.6.3.3 Master with Several Slaves If the bus consists of several SPI slaves, an SPI master can use general purpose I/O pins to control the _SS line to each of the slaves on the bus, as shown in Figure 26-5. In this configuration, the single selected SPI slave will drive the tristate MISO line. Figure 26-5. Multiple Slaves in Parallel shift register SPI Master MOSI MISO SCK _SS[0] MOSI MISO SCK _SS shift register _SS[n-1] MOSI MISO SCK _SS shift register SPI Slave 0 SPI Slave n-1 An alternate configuration is shown in Figure 26-6. In this configuration, all n attached slaves are connected in series. A common _SS line is provided to all slaves, enabling them simultaneously. The master must shift n characters for a complete transaction. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 375 Figure 26-6. Multiple Slaves in Series shift register SPI Master MOSI MISO SCK _SS MOSI MISO SCK _SS shift register MOSI MISO SCK _SS shift register SPI Slave 0 SPI Slave n-1 26.6.4 Interrupts The SPI has the following interrupt sources: z Receive Complete z Transmit Complete z Data Register Empty Each interrupt source has an interrupt flag associated with it. The interrupt flag in the Interrupt Flag Status and Clear register (INTFLAG) is set when the interrupt condition occurs. Each interrupt can be individually enabled by writing a one to the corresponding bit in the Interrupt Enable Set register (INTENSET), and disabled by writing a one to the corresponding bit in the Interrupt Enable Clear register (INTENCLR). An interrupt request is generated when the interrupt flag is set and the corresponding interrupt is enabled. The interrupt request remains active until the interrupt flag is cleared, the interrupt is disabled or the SPI is reset. See the register description for details on how to clear interrupt flags. The SPI has one common interrupt request line for all the interrupt sources. The user must read INTFLAG to determine which interrupt condition is present. Note that interrupts must be globally enabled for interrupt requests to be generated. Refer to “Nested Vector Interrupt Controller” on page 28 for details. For details on clearing interrupt flags, refer to INTFLAG. 26.6.5 Events Not applicable. 26.6.6 Sleep Mode Operation During master operation, the generic clock will continue to run in idle sleep mode. If the Run In Standby bit in the Control A register (CTRLA.RUNSTDBY) is one, the GCLK_SERCOM_CORE will also be enabled in standby sleep mode. Any interrupt can wake up the device. If CTRLA.RUNSTDBY is zero during master operation, GLK_SERCOMx_CORE will be disabled when the ongoing transaction is finished. Any interrupt can wake up the device. During slave operation, writing a one to CTRLA.RUNSTDBY will allow the Receive Complete interrupt to wake up the device. If CTRLA.RUNSTDBY is zero during slave operation, all reception will be dropped, including the ongoing transaction. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 376 26.6.7 Synchronization Due to the asynchronicity between CLK_SERCOMx_APB and GCLK_SERCOMx_CORE, some registers must be synchronized when accessed. A register can require: z Synchronization when written z Synchronization when read z Synchronization when written and read z No synchronization When executing an operation that requires synchronization, the Synchronization Busy bit in the Status register (STATUS.SYNCBUSY) will be set immediately, and cleared when synchronization is complete. If an operation that requires synchronization is executed while STATUS.SYNCBUSY is one, the bus will be stalled. All operations will complete successfully, but the CPU will be stalled and interrupts will be pending as long as the bus is stalled. The following bits need synchronization when written: z Software Reset bit in the Control A register (CTRLA.SWRST) z Enable bit in the Control A register (CTRLA.ENABLE) z Receiver Enable bit in the Control B register (CTRLB.RXEN) CTRLB.RXEN behaves somewhat differently than described above. Refer to CTRLB for details. Write-synchronization is denoted by the Write-Synchronized property in the register description. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 377 26.7 Offset Register Summary Name 0x00 Bit Pos. 7:0 0x01 RUNSTDBY MODE[2:0] ENABLE SWRST 15:8 CTRLA 0x02 23:16 0x03 31:24 DORD 0x04 7:0 PLOADEN 0x05 15:8 DIPO[1:0] CPOL DOPO CPHA FORM[3:0] CHSIZE[2:0] AMODE[1:0] CTRLB 0x06 23:16 0x07 31:24 RXEN 0x08 DBGCTRL 0x09 Reserved 0x0A BAUD 0x0B Reserved 0x0C INTENCLR 7:0 RXC TXC DRE 0x0D INTENSET 7:0 RXC TXC DRE 0x0E INTFLAG 7:0 RXC TXC DRE 0x0F Reserved 7:0 BUFOVF 0x10 7:0 DBGSTOP 7:0 BAUD[7:0] STATUS 0x11 15:8 0x12 Reserved 0x13 Reserved 0x14 7:0 0x15 SYNCBUSY ADDR[7:0] 15:8 ADDR 0x16 23:16 0x17 31:24 0x18 7:0 ADDRMASK[7:0] DATA[7:0] DATA 0x19 15:8 0x1A Reserved 0x1B Reserved 0x1C Reserved 0x1D Reserved 0x1E Reserved 0x1F Reserved DATA[8] Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 378 26.8 Register Description Registers can be 8, 16 or 32 bits wide. Atomic 8-, 16- and 32-bit accesses are supported. In addition, the 8-bit quarters and 16-bit halves of a 32-bit register and the 8-bit halves of a 16-bit register can be accessed directly. Some registers are optionally write-protected by the Peripheral Access Controller (PAC). Write-protection is denoted by the Write-Protected property in each individual register description. Refer to “Register Access Protection” on page 371 for details. Some registers require synchronization when read and/or written. Write-synchronization is denoted by the WriteSynchronized property in each individual register description. Refer to “Synchronization” on page 377 for details. Some registers are enable-protected, meaning they can only be written when the USART is disabled. Enable-protection is denoted by the Enable-Protected property in each individual register description. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 379 26.8.1 Control A Name: CTRLA Offset: 0x00 Reset: 0x00000000 Property: Write-Protected, Enable-Protected, Write-Synchronized Bit 31 30 29 28 DORD CPOL CPHA 27 26 25 24 FORM[3:0] Access R R/W R/W R/W R/W R/W R/W R/W Reset 0 0 0 0 0 0 0 0 Bit 23 22 21 20 19 18 17 16 DIPO[1:0] DOPO Access R R R/W R/W R R R R/W Reset 0 0 0 0 0 0 0 0 Bit 15 14 13 12 11 10 9 8 Access R R R R R R R R Reset 0 0 0 0 0 0 0 0 Bit 7 6 5 4 3 2 1 0 ENABLE SWRST RUNSTDBY Access Reset MODE[2:0] R/W R R R/W R/W R/W R/W R/W 0 0 0 0 0 0 0 0 z Bit 31 – 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. This bit will always return zero when read. z Bit 30 – DORD: Data Order This bit indicates the data order when a character is shifted out from the Data register. 0: MSB is transferred first. 1: LSB is transferred first. This bit is not synchronized. z Bit 29 – CPOL: Clock Polarity In combination with the Clock Phase bit (CPHA), this bit determines the SPI transfer mode. 0: SCK is low when idle. The leading edge of a clock cycle is a rising edge, while the trailing edge is a falling edge. 1: SCK is high when idle. The leading edge of a clock cycle is a falling edge, while the trailing edge is a rising edge. This bit is not synchronized. z Bit 28 – CPHA: Clock Phase In combination with the Clock Polarity bit (CPOL), this bit determines the SPI transfer mode. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 380 0: The data is sampled on a leading SCK edge and changed on a trailing SCK edge. 1: The data is sampled on a trailing SCK edge and changed on a leading SCK edge. This bit is not synchronized. Table 26-3. SPI Transfer Modes Mode CPOL CPHA Leading Edge Trailing Edge 0x0 0 0 Rising, sample Falling, change 0x1 0 1 Rising, change Falling, sample 0x2 1 0 Falling, sample Rising, change 0x3 1 1 Falling, change Rising, sample z Bits 27:24 – FORM[3:0]: Frame Format Table 26-4 shows the various frame formats supported by the SPI. When a frame format with address is selected, the first byte received is checked against the ADDR register. Table 26-4. Frame Format FORM[3:0] Name Description 0x0 SPI SPI frame 0x1 - Reserved 0x2 SPI_ADDR SPI frame with address 0x3-0xF - Reserved z Bits 23:22 – 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. These bits will always return zero when read. z Bits 21:20 – DIPO[1:0]: Data In Pinout These bits define the data in (DI) pad configurations. In master operation, DI is MISO. In slave operation, DI is MOSI. These bits are not synchronized. Table 26-5. Receive Data Pinout DIPO[1:0] Name Description 0x0 PAD0 SERCOM_PAD0 as data in 0x1 PAD1 SERCOM_PAD1 as data in 0x2 PAD2 SERCOM_PAD2 as data in 0x3 PAD3 SERCOM_PAD3 as data in z Bits 19:17 – 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. These bits will always return zero when read. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 381 z Bit 16 – DOPO: Data Out Pinout This bit defines the available pad configurations for data out (DO) and the serial clock (SCK). In slave operation, the slave select line (_SS) is controlled by DOPO, while in master operation the _SS line is controlled by the port configuration. In master operation, DO is MOSI. In slave operation, DO is MISO. This bit is not synchronized. Table 26-6. Data out pinout DOPO DO SCK Slave _SS Master _SS 0x0 SERCOM_PAD0 SERCOM_PAD1 SERCOM_PAD2 System configuration 0x1 SERCOM_PAD2 SERCOM_PAD3 SERCOM_PAD1 System configuration z Bits 15:8 – 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. These bits will always return zero when read. z Bit 7 – RUNSTDBY: Run In Standby This bit defines the functionality in standby sleep mode. These bits are not synchronized. Table 26-7. Run In Standby Configuration RUNSTDBY Slave Master 0x0 Disabled. All reception is dropped, including the ongoing transaction. Genericclock is disabled when ongoing transaction is finished. All interrupts can wake up the device. 0x1 Wake on Receive Complete interrupt. Genericclock is enabled while in sleep modes. All interrupts can wake up the device. z Bits 6: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. These bits will always return zero when read. z Bits 4:2 – MODE: Operating Mode These bits must be written to 0x2 or 0x3 to select the SPI serial communication interface of the SERCOM. 0x2: SPI slave operation 0x3: SPI master operation These bits are not synchronized. z Bit 1 – ENABLE: Enable 0: The peripheral is disabled or being disabled. 1: The peripheral is enabled or being enabled. Due to synchronization, there is delay from writing CTRLA.ENABLE until the peripheral is enabled/disabled. The value written to CTRL.ENABLE will read back immediately and the Synchronization Busy bit in the Status register (STATUS.SYNCBUSY) will be set. STATUS.SYNCBUSY is cleared when the operation is complete. This bit is not enable-protected. z Bit 0 – SWRST: Software Reset 0: There is no reset operation ongoing. 1: The reset operation is ongoing. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 382 Writing a zero to this bit has no effect. Writing a one to this bit resets all registers in the SERCOM, except DBGCTRL, to their initial state, and the SERCOM will be disabled. Writing a one to CTRL.SWRST will always take precedence, meaning that all other writes in the same write-operation will be discarded. Due to synchronization, there is a delay from writing CTRLA.SWRST until the reset is complete. CTRLA.SWRST and STATUS.SYNCBUSY will both be cleared when the reset is complete. This bit is not enable-protected. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 383 26.8.2 Control B Name: CTRLB Offset: 0x04 Reset: 0x00000000 Property: Write-Protected, Enable-Protected Bit 31 30 29 28 27 26 25 24 Access R R R R R R R R Reset 0 0 0 0 0 0 0 0 Bit 23 22 21 20 19 18 17 16 RXEN Access R/W R/W R/W R R R R R Reset 0 0 0 0 0 0 0 0 Bit 15 14 13 12 11 10 9 8 R/W R/W R R R R R R Reset 0 0 0 0 0 0 0 0 Bit 7 6 5 4 3 2 1 0 AMODE[1:0] Access PLOADEN CHSIZE[2:0] Access R R/W R R R R/W R/W R/W Reset 0 0 0 0 0 0 0 0 z Bits 31:18 – 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. These bits will always return zero when read. z Bit 17 – RXEN: Receiver Enable 0: The receiver is disabled or being enabled. 1: The receiver is enabled or it will be enabled when SPI is enabled. Writing a zero to this bit will disable the SPI receiver immediately. The receive buffer will be flushed, data from ongoing receptions will be lost and STATUS.BUFOVF will be cleared. Writing a one to CTRLB.RXEN when the SPI is disabled will set CTRLB.RXEN immediately. When the SPI is enabled, CTRLB.RXEN will be cleared, STATUS.SYNCBUSY will be set and remain set until the receiver is enabled. When the receiver is enabled CTRLB.RXEN will read back as one. Writing a one to CTRLB.RXEN when the SPI is enabled will set STATUS.SYNCBUSY, which will remain set until the receiver is enabled, and CTRLB.RXEN will read back as one. This bit is not enable-protected. z Bit 16 – Reserved Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 384 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. This bit will always return zero when read. z Bits 15:14 – AMODE: Address Mode These bits set the slave addressing mode when the frame format (CTRLA.FORM) with address is used. They are unused in master mode. Table 26-8. Address Mode AMODE[1:0] Name Description 0x0 MASK ADDRMASK is used as a mask to the ADDR register 0x1 2_ADDRS The slave responds to the two unique addresses in ADDR and ADDRMASK 0x2 RANGE The slave responds to the range of addresses between and including ADDR and ADDRMASK. ADDR is the upper limit 0x3 Reserved z Bits 13:7 – 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. These bits will always return zero when read. z Bit 6 – PLOADEN: Slave Data Preload Enable Setting this bit will enable preloading of the slave shift register when there is no transfer in progress. If the _SS line is high when DATA is written, it will be transferred immediately to the shift register. z Bits 5:3 – 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. These bits will always return zero when read. z Bits 2:0 – CHSIZE[2:0]: Character Size Table 26-9. Character Size CHSIZE[2:0] Name Description 0x0 8BIT 8 bits 0x1 9BIT 9 bits 0x2-0x7 Reserved Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 385 26.8.3 Debug Control Name: DBGCTRL Offset: 0x08 Reset: 0x00 Property: Write-Protected Bit 7 6 5 4 3 2 1 0 DBGSTOP Access R R R R R R R R/W Reset 0 0 0 0 0 0 0 0 z Bits 7:1 – 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. These bits will always return zero when read. z Bit 0 – DBGSTOP: Debug Stop Mode This bit controls the functionality when the CPU is halted by an external debugger. 0: The baud-rate generator continues normal operation when the CPU is halted by an external debugger. 1: The baud-rate generator is halted when the CPU is halted by an external debugger. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 386 26.8.4 Baud Rate Name: BAUD Offset: 0x0A Reset: 0x00 Property: Write-Protected, Enable-Protected Bit 7 6 5 4 3 2 1 0 BAUD[7:0] Access Reset z R/W R/W R/W R/W R/W R/W R/W R/W 0 0 0 0 0 0 0 0 Bits 7:0 – BAUD: Baud Register These bits control the clock generation, as described in the SERCOM “Clock Generation – Baud-Rate Generator” on page 340. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 387 26.8.5 Interrupt Enable Clear This register allows the user to disable an interrupt without doing a read-modify-write operation. Changes in this register will also be reflected in the Interrupt Enable Set register (INTENSET). Name: INTENCLR Offset: 0x0C Reset: 0x00 Property: Write-Protected Bit 7 6 5 4 3 2 1 0 RXC TXC DRE Access R R R R R R/W R/W R/W Reset 0 0 0 0 0 0 0 0 z Bits 7:3 – 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. These bits will always return zero when read. z Bit 2 – RXC: Receive Complete Interrupt Enable 0: Receive Complete interrupt is disabled. 1: Receive Complete interrupt is enabled. Writing a zero to this bit has no effect. Writing a one to this bit will clear the Receive Complete Interrupt Enable bit, which disables the Receive Complete interrupt. z Bit 1 – TXC: Transmit Complete Interrupt Enable 0: Transmit Complete interrupt is disabled. 1: Transmit Complete interrupt is enabled. Writing a zero to this bit has no effect. Writing a one to this bit will clear the Transmit Complete Interrupt Enable bit, which disable the Transmit Complete interrupt. z Bit 0 – DRE: Data Register Empty Interrupt Enable 0: Data Register Empty interrupt is disabled. 1: Data Register Empty interrupt is enabled. Writing a zero to this bit has no effect. Writing a one to this bit will clear the Data Register Empty Interrupt Enable bit, which disables the Data Register Empty interrupt. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 388 26.8.6 Interrupt Enable Set This register allows the user to disable an interrupt without doing a read-modify-write operation. Changes in this register will also be reflected in the Interrupt Enable Clear register (INTENCLR). Name: INTENSET Offset: 0x0D Reset: 0x00 Property: Write-Protected Bit 7 6 5 4 3 2 1 0 RXC TXC DRE Access R R R R R R/W R/W R/W Reset 0 0 0 0 0 0 0 0 z Bits 7:3 – 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. These bits will always return zero when read. z Bit 2 – RXC: Receive Complete Interrupt Enable 0: Receive Complete interrupt is disabled. 1: Receive Complete interrupt is enabled. Writing a zero to this bit has no effect. Writing a one to this bit will set the Receive Complete Interrupt Enable bit, which enables the Receive Complete interrupt. z Bit 1 – TXC: Transmit Complete Interrupt Enable 0: Transmit Complete interrupt is disabled. 1: Transmit Complete interrupt is enabled. Writing a zero to this bit has no effect. Writing a one to this bit will set the Transmit Complete Interrupt Enable bit, which enables the Transmit Complete interrupt. z Bit 0 – DRE: Data Register Empty Interrupt Enable 0: Data Register Empty interrupt is disabled. 1: Data Register Empty interrupt is enabled. Writing a zero to this bit has no effect. Writing a one to this bit will set the Data Register Empty Interrupt Enable bit, which enables the Data Register Empty interrupt. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 389 26.8.7 Interrupt Flag Status and Clear Name: INTFLAG Offset: 0x0E Reset: 0x00 Property: - Bit 7 6 5 4 3 2 1 0 RXC TXC DRE Access R R R R R R R/W R Reset 0 0 0 0 0 0 0 0 z Bits 7:3 – 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. These bits will always return zero when read. z Bit 2 – RXC: Receive Complete This flag is cleared by reading the Data (DATA) register or by disabling the receiver. This flag is set when there are unread data in the receive buffer. If address matching is enabled, the first data received in a transaction will be an address. Writing a zero to this bit has no effect. Writing a one to this bit has no effect. z Bit 1 – TXC: Transmit Complete This flag is cleared by writing a one to it or by writing new data to DATA. In master mode, this flag is set when the data have been shifted out and there are no new data in DATA. In slave mode, this flag is set when the _SS pin is pulled high. If address matching is enabled, this flag is only set if the transaction was initiated with an address match. Writing a zero to this bit has no effect. Writing a one to this bit will clear the flag. z Bit 0 – DRE: Data Register Empty This flag is cleared by writing new data to DATA. This flag is set when DATA is empty and ready for new data to transmit. Writing a zero to this bit has no effect. Writing a one to this bit has no effect. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 390 26.8.8 Status Name: STATUS Offset: 0x10 Reset: 0x0000 Property: – Bit 15 14 13 12 11 10 9 8 SYNCBUSY Access R R R R R R R R Reset 0 0 0 0 0 0 0 0 Bit 7 6 5 4 3 2 1 0 BUFOVF Access R R R R R R/W R R Reset 0 0 0 0 0 0 0 0 z Bit 15 – SYNCBUSY: Synchronization Busy This bit is cleared when the synchronization of registers between the clock domains is complete. This bit is set when the synchronization of registers between clock domains is in progress. z Bits 14:3 – 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. These bits will always return zero when read. z Bit 2 – BUFOVF: Buffer Overflow Reading this bit before reading DATA will indicate the error status of the next character to be read. This bit is cleared by writing a one to the bit or by disabling the receiver. This bit is set when the first character received after an overflow condition has been eliminated is available in RxDATA. An overflow condition occurs if the two-level receive buffer is full when the last bit of the incoming character is shifted into the shift register. All characters shifted into the shift registers before the overflow condition is eliminated by reading DATA will be lost. Writing a zero to this bit has no effect. Writing a one to this bit will clear it. z Bits 1:0 – 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. These bits will always return zero when read. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 391 26.8.9 Address Name: ADDR Offset: 0x14 Reset: 0x00000000 Property: Write-Protected, Enable-Protected Bit 31 30 29 28 27 26 25 24 Access R R R R R R R R Reset 0 0 0 0 0 0 0 0 Bit 23 22 21 20 19 18 17 16 ADDRMASK[7:0] Access R/W R/W R/W R/W R/W R/W R/W R/W Reset 0 0 0 0 0 0 0 0 Bit 15 14 13 12 11 10 9 8 Access R R R R R R R R Reset 0 0 0 0 0 0 0 0 Bit 7 6 5 4 3 2 1 0 ADDR[7:0] Access Reset R/W R/W R/W R/W R/W R/W R/W R/W 0 0 0 0 0 0 0 0 z Bits 31:24 – 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. These bits will always return zero when read. z Bits 23:16 – ADDRMASK[7:0]: Address Mask These bits hold the address mask when the transaction format (CTRLA.FORM) with address is used. z Bits 15:8 – 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. These bits will always return zero when read. z Bits 7:0 – ADDR[7:0]: Address These bits hold the address when the transaction format (CTRLA.FORM) with address is used. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 392 26.8.10 Data Name: DATA Offset: 0x18 Reset: 0x0000 Property: – Bit 15 14 13 12 11 10 9 8 DATA[8] Access R R R R R R R R/W Reset 0 0 0 0 0 0 0 0 Bit 7 6 5 4 3 2 1 0 DATA[7:0] Access Reset R/W R/W R/W R/W R/W R/W R/W R/W 0 0 0 0 0 0 0 0 z Bits 15:9 – 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. These bits will always return zero when read. z Bits 8:0 – DATA[8:0]: Data Reading these bits will return the contents of the receive data buffer. The register should be read only when the Receive Complete Interrupt Flag bit in the Interrupt Flag Status and Clear register (INTFLAG.RXCIF) is set. Writing these bits will write the transmit data buffer. This register should be written only when the Data Register Empty Interrupt Flag bit in the Interrupt Flag Status and Clear register (INTFLAG.DREIF) is set. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 393 27. SERCOM I2C – SERCOM Inter-Integrated Circuit 27.1 Overview The inter-integrated circuit (I2C) interface is one of the available modes in the serial communication interface (SERCOM). Refer to “SERCOM – Serial Communication Interface” on page 337 for details. The I2C interface uses the SERCOM transmitter and receiver configured as shown in Figure 27-1. Fields shown in capital letters are registers accessible by the CPU, while lowercase fields are internal to the SERCOM. Each side, master and slave, depicts a separate I2C interface containing a shift register, a transmit buffer and a receive buffer. In addition, the I2C master uses the SERCOM baud-rate generator, while the I2C slave uses the SERCOM address match logic. 27.2 Features z Master or slave operation z Philips I2C compatible z SMBus™ compatible z 100kHz and 400kHz support at low system clock frequencies z Physical interface includes: z z Slew-rate limited outputs Filtered inputs z Slave operation: z Operation in all sleep modes Wake-up on address match z Address match in hardware for: z 7-bit unique address and/or 7-bit general call address z 7-bit address range z Two unique 7-bit addresses z 27.3 Block Diagram Figure 27-1. I2C Single-Master Single-Slave Interconnection Master BAUD Slave Tx DATA Tx DATA 0 SCL ADDR/ADDRMASK 0 baud rate generator SCL low hold shift register shift register 0 Rx DATA SDA 0 Rx DATA == Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 394 27.4 Signal Description Signal Name Type Description PAD[0] Digital I/O SDA PAD[1] Digital I/O SCL PAD[2] Digital I/O SDA_OUT (4-wire) PAD[3] Digital I/O SDC_OUT (4-wire) Refer to “I/O Multiplexing and Considerations” on page 15 for details on the pin mapping for this peripheral. One signal can be mapped on several pins. Note that not all the pins are I2C pins. Refer to Table 6-1 for details on the pin type for each pin, and <!!!CRs_ElChar_Top!!!> for details on the electrical characteristics of the different pin types. 27.5 Product Dependencies In order to use this peripheral, other parts of the system must be configured correctly, as described below. 27.5.1 I/O Lines Using the SERCOM’s I/O lines requires the I/O pins to be configured. Refer to “PORT” on page 289 for details. 27.5.2 Power Management The I2C will continue to operate in any sleep mode where the selected source clock is running. I2C interrupts can be used to wake up the device from sleep modes. The events can trigger other operations in the system without exiting sleep modes. Refer to “PM – Power Manager” on page 105 for details on the different sleep modes. 27.5.3 Clocks The SERCOM bus clock (CLK_SERCOMi_APB, where i represents the specific SERCOM instance number) is enabled by default, and can be enabled and disabled in the Power Manager. Refer to “PM – Power Manager” on page 105 for details. The SERCOM bus clock (CLK_SERCOMi_APB) is enabled by default, and can be enabled and disabled in the Power Manager. Refer to “PM – Power Manager” on page 105 for details. Two generic clocks are used by the SERCOM (GCLK_SERCOMi_CORE and GCLK_SERCOM_SLOW). The core clock (GCLK_SERCOMi_CORE) is required to clock the SERCOM while operating as a master, while the slow clock (GCLK_SERCOM_SLOW) is required only for certain functions. These clocks must be configured and enabled in the Generic Clock Controller (GCLK) before using the SERCOM. Refer to “GCLK – Generic Clock Controller” on page 83 for details. These generic clocks are asynchronous to the SERCOM bus clock (CLK_SERCOMi_APB). Due to this asynchronicity, writes to certain registers will require synchronization between the clock domains. Refer to the “Synchronization” on page 407 section for further details. 27.5.4 DMA Not applicable. 27.5.5 Interrupts The interrupt request line is connected to the Interrupt Controller. Using the I2C interrupts requires the Interrupt Controller to be configured first. Refer to “Nested Vector Interrupt Controller” on page 28 for details. 27.5.6 Events Not applicable. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 395 27.5.7 Debug Operation When the CPU is halted in debug mode, the I2C interface continues normal operation. If the I2C interface is configured in a way that requires it to be periodically serviced by the CPU through interrupts or similar, improper operation or data loss may result during debugging. The I2C interface can be forced to halt operation during debugging. Refer to the DBGCTRL register for details. 27.5.8 Register Access Protection All registers with write-access are optionally write-protected by the Peripheral Access Controller (PAC), except the following registers: z Interrupt Flag Status and Clear register (INTFLAG) z Status register (STATUS) z Address register (ADDR) z Data register (DATA) Write-protection is denoted by the Write-Protected property in the register description. Write-protection does not apply to accesses through en external debugger. Refer to“PAC – Peripheral Access Controller” on page 31 for details. 27.5.9 Analog Connections Not applicable. 27.6 Functional Description 27.6.1 Principle of Operation The I2C interface uses two physical lines for communication: z Serial Data Line (SDA) for packet transfer z Serial Clock Line (SCL) for the bus clock A transaction starts with the start condition, followed by a 7-bit address and a direction bit (read or write) sent from the I2C master. The addressed I2C slave will then acknowledge (ACK) the address, and data packet transactions can commence. Every 9-bit data packet consists of 8 data bits followed by a one-bit reply indicating whether the data was acknowledged or not. In the eventthat a data packet is not acknowledged (NACK), whether sent from the I2C slave or master, it will be up to the I2C master to either terminate the connection by issuing the stop condition, or send a repeated start if more data is to be tranceived. Figure 27-2 illustrates the possible transaction formats and Figure 27-3 explains the legend used. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 396 Figure 27-2. Basic I2C Transaction Diagram SDA SCL 6 ... 0 S ADDRESS S 7 ... 0 R/W ADDRESS ACK R/W A 7 ... 0 DATA ACK DATA A DATA P ACK/NACK DATA A/A P Direction Address Packet Data Packet #0 Data Packet #1 Transaction Figure 27-3. Transaction Diagram Syntax Bus Driver: Master Drives Bus S START Condition Slave Drives Bus Sr Repeated START Condition Either Master or Slave Drives Bus P STOP Condition Data Packet Direction: R Master Read "1" W Special Bus Conditions Acknowledge: A Acknowledge (ACK) "0" Master Write "0" A Not Acknowledge (NACK) "1" 27.6.2 Basic Operation 27.6.2.1 Initialization The following registers are enable-protected, meaning they can be written only when the I2C interface is disabled (CTRLA.ENABLE is zero): z Control A register (CTRLA), except Enable (CTRLA.ENABLE) and Software Reset (CTRLA.SWRST) z Control B register (CTRLB), except Acknowledge Action (CTRLB.ACKACT) and Command (CTRLB.CMD) z Baud Rate register (BAUD) z Address register (ADDR) while in slave operation Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 397 Any writes to these bits or registers when the I2C interface is enabled or is being enabled (CTRLA.ENABLE is one) will be discarded. Writes to these registers while the I2C interface is being disabled will be completed after the disabling is complete. Enable-protection is denoted by the Enable-Protection property in the register description. Before the I2C interface is enabled, it must be configured as outlined by the following steps: I2C mode in master or slave operation must be selected by writing 0x4 or 0x5 to the Operating Mode bit group in the Control A register (CTRLA.MODE) z SCL low time-out can be enabled by writing to the SCL Low Time-Out bit in the Control A register (CTRLA.LOWTOUT) z In master operation, the inactive bus time-out can be set in the Inactive Time-Out bit group in the Control A register (CTRLA.INACTOUT) z Hold time for SDA can be set in the SDA Hold Time bit group in the Control A register (CTRLA.SDAHOLD) z Smart operation can be enabled by writing to the Smart Mode Enable bit in the Control B register (CTRLB.SMEN) z In slave operation, the address match configuration must be set in the Address Mode bit group in the Control B register (CTRLB.AMODE) z In slave operation, the addresses must be set, according to the selected address configuration, in the Address and Address Mask bit groups in the Address register (ADDR.ADDR and ADDR.ADDRMASK) z In master operation, the Baud Rate register (BAUD) must be written to generate the desired baud rate 27.6.2.2 Enabling, Disabling and Resetting The I2C interface is enabled by writing a one to the Enable bit in the Control A register (CTRLA.ENABLE). The I2C interface is disabled by writing a zero to CTRLA.ENABLE. The I2C interface is reset by writing a one to the Software Reset bit in the Control A register (CTRLA.SWRST). All registers in the I2C interface, except DBGCTRL, will be reset to their initial state, and the I2C interface will be disabled. Refer to CTRLA for details. 27.6.2.3 I2C Bus State Logic The bus state logic includes several logic blocks that continuously monitor the activity on the I2C bus lines in all sleep modes. The start and stop detectors and the bit counter are all essential in the process of determining the current bus state. The bus state is determined according to the state diagram shown in Figure 27-4. Software can get the current bus state by reading the Master Bus State bits in the Status register (STATUS.BUSSTATE). The value of STATUS.BUSSTATE in the figure is shown in binary. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 398 Figure 27-4. Bus State Diagram RESET UNKNOWN (0b00) P + Timeout Sr S IDLE (0b01) BUSY (0b11) P + Timeout Command P Write ADDR (S) Arbitration Lost OWNER (0b10) Write ADDR(Sr) The bus state machine is active when the I2C master is enabled. After the I2C master has been enabled, the bus state is unknown. From the unknown state, the bus state machine can be forced to enter the idle state by writing to STATUS.BUSSTATE accordingly. However, if no action is taken by software, the bus state will become idle if a stop condition is detected on the bus. If the inactive bus time-out is enabled, the bus state will change from unknown to idle on the occurrence of a time-out. Note that after a known bus state is established, the bus state logic will not re-enter the unknwon state from either of the other states. When the bus is idle it is ready for a new transaction. If a start condition is issued on the bus by another I2C master in a multimaster setup, the bus becomes busy until a stop condition is detected. The stop condition will cause the bus to reenter the IDLE state. If the inactive bus time-out (SMBus) is enabled, the bus state will change from busy to idle on the occurrence of a time-out. If a start condition is generated internally by writing the Address bit group in the Address register (ADDR.ADDR) while in idle state, the owner state is entered. If the complete transaction was performed without interference, i.e., arbitration not lost, the I2C master is allowed to issue a stop condition, which in turn will cause a change of the bus state back to idle. However, if a packet 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 change the bus state only if arbitration is lost while issuing a repeated start. 27.6.2.4 Clock Generation The Master I2C clock (SCL) frequency is determined by a number of factors. The low (TLOW) and high (T_HIGH) times are determined by the Baud Rate register (BAUD), while the rise (TRISE) and fall (TFALL) times are determined by the bus topology. Because of the wired-AND logic of the bus, TFALL will be considered as part of TLOW. Likewise, TRISE will be in a state between TLOW and THIGH until a high state has been detected. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 399 Figure 27-5. SCL Timing TRISE P TLOW S Sr SCL THIGH TBUF TFALL SDA THD;STA TSU;STO TSU;STA The following parameters are timed using the SCL low time period. This comes from the Master Baud Rate Low bit group in the Baud Rate register (BAUD.BAUDLOW) when non-zero, or the Master Baud Rate bit group in the Baud Rate register (BAUD.BAUD) when BAUD.BAUDLOW is zero. z TLOW – Low period of SCL clock z TSU;STO – Set-up time for stop condition z TBUF – Bus free time between stop and start conditions z THD;STA – Hold time (repeated) start condition z TSU;STA – Set-up time for repeated start condition z THIGH is timed using the SCL high time count from BAUD.BAUD z TRISE is determined by the bus impedance; for internal pull-ups see Electrical Characteristics z TFALL is determined by the open-drain current limit and bus impedance; can typically be regarded as zero; see Electrical Characteristics The SCL frequency is given by: f SCL = 1 TLOW + THIGH + TRISE When BAUD.BAUDLOW is zero, the BAUD.BAUD value is used to time both SCL high and SCL low. In this case the following formula will give the SCL frequency: f SCL = f GCLK 2(5 + BAUD) + f GCLK TRISE When BAUD.BAUDLOW is non-zero, the following formula is used to determine the SCL frequency: f SCL = f GCLK 10 + BAUD + BAUDLOW + f GCLK TRISE Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 400 When BAUDLOW is non-zero, the following formula can be used to determine the SCL frequency: f SCL = f GCLK 10 + BAUD + BAUDLOW + f GCLK TRISE The following formulas can be used to determine the SCL TLOW and THIGH times: = T low T HIGH BAUD.BAUDLOW + 5 f GCLK = BAUD.BAUD + 5 f GCLK 27.6.2.5 I2C Master Operation The I2C master is byte-oriented and interrupt based. The number of interrupts generated is kept at a minimum by automatic handling of most events. Auto-triggering of operations and a special smart mode, which can be enabled by writing a one to the Smart Mode Enable bit in the Control A register (CTRLA.SMEN), are included to reduce software driver complexity and code size. The I2C master operates according to the behavior diagram shown in Figure 27-6. The circles with a capital em followed by a number (M1, M2... etc.) indicate which node in the figure the bus logic can jump to based on software or hardware interaction. This diagram is used as reference for the description of the I2C master operation throughout the document. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 401 Figure 27-6. I2C Master Behavioral Diagram APPLICATION MASTER WRITE INTERRUPT + HOLD M1 M2 BUSY S W P M3 IDLE S Wait for IDLE M4 ADDRESS R/W BUSY S W R/W A S W P S W Sr W A M1 BUSY M2 IDLE M3 S W BUSY DATA M4 A/A MASTER READ INTERRUPT+ HOLD S W S W Software interaction A BUSY The master provides data on the bus A/A Addressed slave provides data on the bus A/A Sr P IDLE M4 M2 M3 A/A R A DATA Transmitting Address Packets The I2C master starts a bus transaction by writing ADDR.ADDR with the I2C slave address and the direction bit. If the bus is busy, the I2C master will wait until the bus becomes idle before continuing the operation. When the bus is idle, the I2C master will issue a start condition on the bus. The I2C master will then transmit an address packet using the address written to ADDR.ADDR. After the address packet has been transmitted by the I2C master, one of four cases will arise, based on arbitration and transfer direction. Case 1: Arbitration lost or bus error during address packet transmission If arbitration was lost during transmission of the address packet, the Master on Bus bit in the Interrupt Flag register (INTFLAG.MB) and the Arbitration Lost bit in the Status register (STATUS.ARBLOST) are both set. Serial data output to SDA is disabled, and the SCL is released, which disables clock stretching. In effect ,the I2C master is no longer allowed to perform any operation on the bus until the bus is idle again. A bus error will behave similarly to the arbitration lost condition. In this case, the MB interrupt flag and Master Bus Error bit in the Status register (STATUS.BUSERR) are both set in addition to STATUS.ARBLOST. The Master Received Not Acknowledge bit in the Status register (STATUS.RXNACK) will always contain the last successfully received acknowledge or not acknowledge indication. In this case, software will typically inform the application code of the condition and then clear the interrupt flag before exiting the interrupt routine. No other flags have to be cleared at this point, because all flags will be cleared automatically the next time the ADDR.ADDR register is written. Case 2: Address packet transmit complete – No ACK received If no I2C slave device responds to the address packet, then the INTFLAG.MB interrupt flag is set and STATUS.RXNACK is set. The clock hold is active at this point, preventing further activity on the bus. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 402 The missing ACK response can indicate that the I2C slave is busy with other tasks or sleeping and, therefore, not able to respond. In this event, the next step can be either issuing a stop condition (recommended) or resending the address packet by using a repeated start condition. However, the reason for the missing acknowledge can be that an invalid I2C slave address has been used or that the I2C slave is for some reason disconnected or faulty. If using SMBus logic, the slave must ACK the address, and hence no action means the slave is not available on the bus. Case 3: Address packet transmit complete – Write packet, Master on Bus set If the I2C master receives an acknowledge response from the I2C slave, INTFLAG.MB is set and STATUS.RXNACK is cleared. The clock hold is active at this point, preventing further activity on the bus. In this case, the software implementation becomes highly protocol dependent. Three possible actions can enable the I2C operation to continue. The three options are: z The data transmit operation is initiated by writing the data byte to be transmitted into DATA.DATA. z Transmit a new address packet by writing ADDR.ADDR. A repeated start condition will automatically be inserted before the address packet. z Issue a stop condition, consequently terminating the transaction. Case 4: Address packet transmit complete – Read packet, Slave on Bus set If the I2C master receives an ACK from the I2C slave, the I2C master proceeds to receive the next byte of data from the I2C slave. When the first data byte is received, the Slave on Bus bit in the Interrupt Flag register (INTFLAG.SB) is set and STATUS.RXNACK is cleared. The clock hold is active at this point, preventing further activity on the bus. In this case, the software implementation becomes highly protocol dependent. Three possible actions can enable the I2C operation to continue. The three options are: z Let the I2C master continue to read data by first acknowledging the data received. This is automatically done when reading DATA.DATA if the smart mode is enabled. z Transmit a new address packet. z Terminate the transaction by issuing a stop condition. An ACK or NACK will be automatically transmitted for the last two alternatives if smart mode is enabled. The Acknowledge Action bit in the Control B register (CTRLB.ACKACT) determines whether ACK or NACK should be sent. Transmitting Data Packets When an address packet with direction set to write (STATUS.DIR is zero) has been successfully transmitted, INTFLAG.MB will be set and the I2C master can start transmitting data by writing to DATA.DATA. The I2C master transmits data via the I2C bus while continuously monitoring for packet collisions. If a collision is detected, the I2C master looses arbitration and STATUS.ARBLOST is set. If the transmit was successful, the I2C master automatically receives an ACK bit from the I2C slave and STATUS.RXNACK will be cleared. INTFLAG.MB will be set in both cases, regardless of arbitration outcome. Testing STATUS.ARBLOST and handling the arbitration lost condition in the beginning of the I2C Master on Bus interrupt is recommended. This can be done, as there is no difference between handling address and data packet arbitration. STATUS.RXNACK must be checked for each data packet transmitted before the next data packet transmission can commence. The I2C master is not allowed to continue transmitting data packets if a NACK is given from the I2C slave. Receiving Data Packets When INTFLAG.SB is set, the I2C master will already have received one data packet. The I2C master must respond by sending either an ACK or NACK. Sending a NACK might not be successfully executed,as arbitration can be lost during the transmission. In this case, a loss of arbitration will cause INTFLAG.SB to not be set on completion. Instead, INTFLAG.MB will be used to indicate a change in arbitration. Handling of lost arbitration is the same as for data bit transmission. 27.6.2.6 I2C Slave Operation The I2C slave is byte-oriented and interrupt-based. The number of interrupts generated is kept at a minimum by automatic handling of most events. Auto triggering of operations and a special smart mode, which can be enabled by Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 403 writing a 1 to the Smart Mode Enable bit in the Control A register (CTRLA.SMEN), are included to reduce software’s complexity and code size. The I2C slave operates according to the behavior diagram shown in Figure 27-7. The circles with a capital ess followed by a number (S1, S2... etc.) indicate which node in the figure the bus logic can jump to based on software or hardware interaction. This diagram is used as reference for the description of the I2C slave operation throughout the document. Figure 27-7. I2C Slave Behavioral Diagram SLAVE ADDRESS INTERRUPT S1 S3 S2 S A ADDRESS R S W SLAVE DATA INTERRUPT S1 S2 Sr S3 S W A A P S1 P S2 Sr S3 DATA A/A SLAVE STOP INTERRUPT W Interrupt on STOP Condition Enabled S W S W A/A DATA S W A/A S W Software interaction The master provides data on the bus Addressed slave provides data on the bus Receiving Address Packets When the I2C slave is properly configured, it will wait for a start condition to be detected. When a start condition is detected, the successive address packet will be received and checked by the address match logic. If the received address is not a match, the packet is rejected and the I2C slave waits for a new start condition. The I2C slave Address Match bit in the Interrupt Flag register (INTFLAG.AMATCH) is set when a start condition followed by a valid address packet is detected. SCL will be stretched until the I2C slave clears INTFLAG.AMATCH. Because the I2C slave holds the clock by forcing SCL low, the software is given unlimited time to respond to the address. The direction of a transaction is determined by reading the Read / Write Direction bit in the Status register (STATUS.DIR), and the bit will be updated only when a valid address packet is received. If the Transmit Collision bit in the Status register (STATUS.COLL) is set, this indicates that the last packet addressed to the I2C slave had a packet collision. A collision causes the SDA and SCL lines to be released without any notification to software. The next AMATCH interrupt is, therefore, the first indication of the previous packet’s collision. Collisionsare intended to follow the SMBus Address Resolution Protocol (ARP). After the address packet has been received from the I2C master, one of two cases will arise based on transfer direction. Case 1: Address packet accepted – Read flag set The STATUS.DIR bit is one, indicating an I2C master read operation. The SCL line is forced low, stretching the bus clock. If an ACK is sent, I2C slave hardware will set the Data Ready bit in the Interrupt Flag register (INTFLAG.DRDY), Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 404 indicating data are needed for transmit. If not acknowledge is sent, the I2C slave will wait for a new start condition and address match. Typically, software will immediately acknowledge the address packet by sending an ACK/NACK bit. The I2C slave command CTRLB.CMD = 3 can be used for both read and write operation,as the command execution is dependent on the STATUS.DIR bit. Writing a one to INTFLAG.AMATCH will also cause an ACK/NACK to be sent corresponding to the CTRLB.ACKACT bit. Case 2: Address packet accepted – Write flag set The STATUS.DIR bit is cleared, indicating an I2C master write operation. The SCL line is forced low, stretching the bus clock. If an ACK is sent, the I2C slave will wait for data to be received. Data, repeated start or stop can be received. If not acknowledge is sent, the I2C slave will wait for a new start condition and address match. Typically, software will immediately acknowledge the address packet by sending an ACK/NACK bit. The I2C slave command CTRLB.CMD = 3 can be used for both read and write operation,as the command execution is dependent on STATUS.DIR. Writing a one to INTFLAG.AMATCH will also cause an ACK/NACK to be sent corresponding to the CTRLB.ACKACT bit. Receiving and Transmitting Data Packets After the I2C slave has received an address packet, it will respond according to the direction either by waiting for the data packet to be received or by startingto send a data packet by writing to DATA.DATA. When a data packet is received or sent, INTFLAG.DRDY will be set. Then, if the I2C slave was receiving data, it will send an acknowledge according to CTRLB.ACKACT. Case 1: Data received INTFLAG.DRDY is set, and SCL is held low pending SW interaction. Case 2: Data sent When a byte transmission is successfully completed, the INTFLAG.DRDY interrupt flag is set. If NACK is received, the I2C slave must expect a stop or a repeated start to be received. The I2C slave must release the data line to allow the I2C master to generate a stop or repeated start. Upon stop detection, the Stop Received bit in the Interrupt Flag register (INTFLAG.PREC) will be set and the I2C slave will return to theidle state. 27.6.3 Additional Features 27.6.3.1 SMBus The I2C hardware incorporates hardware SCL low time-out, which allows a time-out to occur if the clock line is held low too long. This time-out is driven by the GCLK_SERCOM_SLOW clock. The I2C interface also allows for a SMBus compatible SDA hold time. 27.6.3.2 Smart Mode The I2C interface incorporates a special smart mode that simplifies application code and minimizes the user interaction needed to keep hold of the I2C protocol. The smart mode accomplishes this by letting the reading of DATA.DATA automatically issue an ACK or NACK based on the state of CTRLB.ACKACT. 27.6.3.3 4-Wire Mode Setting the Pin Usage bit in the Control A register (CTRLA.PINOUT) for master or slave to 4-wire mode enables operation as shown in Figure 27-8. In this mode, the internal I2C tri-state drivers are bypassed, and an external, I2Ccompliant tri-state driver is needed when connecting to an I2C bus. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 405 Figure 27-8. I2C Pad Interface scl_out/sda_out SCL_OUT/ SDA_OUT pad PINOUT I2C Driver SCL/SDA pad scl_in/sda_in PINOUT 27.6.3.4 Quick Command Setting the Quick Command Enable bit in the Control B register (CTRLB.QCEN) enables quick command. When quick command is enabled, the corresponding interrupt flag is set immediately after the slave acknowledges the address. At this point, the software can either issue a stop command or a repeated start by writing CTRLB.CMD or ADDR.ADDR. 27.6.4 Interrupts The I2C slave has the following interrupt sources: z Data Ready z Address Match z Stop Received 2 The I C master has the following interrupt sources: z Slave on Bus z Master on Bus Each interrupt source has an interrupt flag associated with it. The interrupt flag in the Interrupt Flag Status and Clear register (INTFLAG) is set when the interrupt condition occurs. Each interrupt can be individually enabled by writing a one to the corresponding bit in the Interrupt Enable Set register (INTENSET), and disabled by writing a one to the corresponding bit in the Interrupt Enable Clear register (INTENCLR). An interrupt request is generated when the interrupt flag is set and the corresponding interrupt is enabled. The interrupt request remains active until the interrupt flag is cleared, the interrupt is disabled or the I2C is reset. See INTFLAG for details on how to clear interrupt flags. The I2C has one common interrupt request line for all the interrupt sources. The user must read INTFLAG to determine which interrupt condition is present. Note that interrupts must be globally enabled for interrupt requests to be generated. Refer to “Nested Vector Interrupt Controller” on page 28 for details. 27.6.5 Sleep Mode Operation During I2C master operation, the generic clock (GCLK_SERCOMi_CORE) will continue to run in idle sleep mode. If the Run In Standby bit in the Control A register (CTRLA.RUNSTDBY) is one, the GLK_SERCOMi_CORE will also run in standby sleep mode. Any interrupt can wake up the device. If CTRLA.RUNSTDBY is zero during I2C master operation, the GLK_SERCOMi_CORE will be disabled when an ongoing transaction is finished. Any interrupt can wake up the device. During I2C slave operation, writing a one to CTRLA.RUNSTDBY will allow the Address Match interrupt to wake up the device. In I2C slave operation, all receptions will be dropped when CTRLA.RUNSTDBY is zero. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 406 27.6.6 Synchronization Due to the asynchronicity between CLK_SERCOMi_APB and GCLK_SERCOMi_CORE, some registers must be synchronized when accessed. A register can require: z Synchronization when written z Synchronization when read z Synchronization when written and read z No synchronization When executing an operation that requires synchronization, the Synchronization Busy bit in the Status register (STATUS.SYNCBUSY) will be set immediately, and cleared when synchronization is complete. If an operation that requires synchronization is executed while STATUS.SYNCBUSY is one, the bus will be stalled. All operations will complete successfully, but the CPU will be stalled and interrupts will be pending as long as the bus is stalled. The following register needs synchronization when written: z Data (DATA) when in smart mode The following bits need synchronization when written: z Software Reset bit in the Control A register (CTRLA.SWRST) z Enable bit in the Control A register (CTRLA.ENABLE) z Write to Bus State bits in the Status register (STATUS.BUSSTATE) z Address bits in the Address register (ADDR.ADDR) when in master operation Write-synchronization is denoted by the Write-Synchronized property in the register description. The following register needs synchronization when read: z Data (DATA) when in smart mode Read-synchronization is denoted by the Read-Synchronized property in the register description. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 407 27.7 Register Summary Table 27-1. Register Summary – Slave Mode Offset Name Bit Pos. 0x00 7:0 0x01 15:8 RUNSTDBY MODE[2:0]=100 ENABLE SWRST CTRLA 0x02 23:16 0x03 31:24 0x04 7:0 0x05 15:8 SDAHOLD[1:0] PINOUT LOWTOUT AMODE[1:0] SMEN CTRLB 0x06 23:16 0x07 31:24 ACKACT CMD[1:0] 0x08 Reserved ... Reserved 0x0B Reserved 0x0C INTENCLR 7:0 DRDY AMATCH PREC 0x0D INTENSET 7:0 DRDY AMATCH PREC 0x0E INTFLAG 7:0 DRDY AMATCH PREC 0x0F Reserved Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 408 Table 27-1. Register Summary – Slave Mode (Continued) Offset Name 0x10 Bit Pos. 7:0 CLKHOLD 15:8 SYNCBUSY LOWTOUT SR DIR RXNACK COLL BUSERR STATUS 0x11 0x12 Reserved 0x13 Reserved 0x14 7:0 0x15 ADDR[6:0] GENCEN 15:8 ADDR 0x16 23:16 0x17 31:24 0x18 7:0 ADDRMASK[6:0] DATA[7:0] DATA 0x19 15:8 Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 409 Table 27-2. Register Summary – Master Mode Offset Name Bit Pos 0x00 7:0 0x01 15:8 RUNSTDBY MODE[2:0]=101 ENABLE SWRST CTRLA 0x02 23:16 0x03 31:24 0x04 7:0 0x05 SDAHOLD[1:0] LOWTOUT PINOUT INACTOUT[1:0] 15:8 QCEN SMEN CTRLB 0x06 23:16 0x07 31:24 0x08 DBGCTRL 0x09 Reserved 0x0A ACKACT CMD[1:0] 7:0 DBGSTOP 7:0 BAUD[7:0] 15:8 BAUDLOW[7:0] BAUD 0x0B 0x0C INTENCLR 7:0 SB MB 0x0D INTENSET 7:0 SB MB 0x0E INTFLAG 7:0 SB MB 0x0F Reserved Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 410 Table 27-2. Register Summary – Master Mode (Continued) Offset Name 0x10 Bit Pos 7:0 CLKHOLD 15:8 SYNCBUSY LOWTOUT BUSSTATE[1:0] RXNACK ARBLOST BUSERR STATUS 0x11 0x12 Reserved 0x13 Reserved 0x14 7:0 ADDR[7:0] ADDR 0x15 15:8 0x16 Reserved 0x17 Reserved 0x18 7:0 DATA[7:0] DATA 0x19 15:8 Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 411 27.8 Register Description Registers can be 8, 16 or 32 bits wide. Atomic 8-, 16- and 32-bit accesses are supported. In addition, the 8-bit quarters and 16-bit halves of a 32-bit register and the 8-bit halves of a 16-bit register can be accessed directly. Some registers are optionally write-protected by the Peripheral Access Controller (PAC). Write-protection is denoted by the Write-Protected property in each individual register description. Please refer to“Register Access Protection” on page 396 for details. Some registers require synchronization when read and/or written. Synchronization is denoted by the Write-Synchronized or the Read-Synchronized property in each individual register description. Please refer to “Synchronization” on page 407 for details. Some registers are enable-protected, meaning they can only be written when the I2C is disabled. Enable-protection is denoted by the Enable-Protected property in each individual register description. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 412 27.8.1 I2C Slave Register Description 27.8.1.1 Control A Name: CTRLA Offset: 0x00 Reset: 0x00000000 Property: Write-Protected, Enable-Protected, Write-Synchronized Bit 31 30 29 28 27 26 25 24 LOWTOUT Access R R/W R R R R R R Reset 0 0 0 0 0 0 0 0 Bit 23 22 21 20 19 18 17 16 SDAHOLD[1:0] PINOUT Access R R R/W R/W R R R R/W Reset 0 0 0 0 0 0 0 0 Bit 15 14 13 12 11 10 9 8 Access R R R R R R R R Reset 0 0 0 0 0 0 0 0 Bit 7 6 5 4 3 2 1 0 ENABLE SWRST RUNSTDBY Access Reset MODE[2:0]=100 R/W R R R/W R/W R/W R/W R/W 0 0 0 0 0 0 0 0 z Bit 31 – 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. This bit will always return zero when read. z Bit 30 – LOWTOUT: SCL Low Time-Out This bit enables the SCL low time-out. If SCL is held low for 25ms-35ms, the slave will release its clock hold, if enabled, and reset the internal state machine. Any interrupts set at the time of time-out will remain set. 0: Time-out disabled. 1: Time-out enabled. This bit is not synchronized. z Bits 29:22 – 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. These bits will always return zero when read. z Bits 21:20 – SDAHOLD[1:0]: SDA Hold Time These bits define the SDA hold time with respect to the negative edge of SCL. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 413 Table 27-3. SDA Hold Time Value Name Description 0x0 DIS Disabled 0x1 75 50-100ns hold time 0x2 450 300-600ns hold time 0x3 600 400-800ns hold time These bits are not synchronized. z Bits 19:17 – 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. These bits will always return zero when read. z Bit 16 – PINOUT: Pin Usage This bit sets the pin usage to either two- or four-wire operation: 0: 4-wire operation disabled 1: 4-wire operation enabled This bit is not synchronized. z Bits 15:8 – 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. These bits will always return zero when read. z Bit 7 – RUNSTDBY: Run in Standby This bit defines the functionality in standby sleep mode. 0: Disabled – All reception is dropped. 1: Wake on address match, if enabled. This bit is not synchronized. z Bits 6: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. These bits will always return zero when read. z Bits 4:2 – MODE[2:0]: Operating Mode These bits must be written to 0x04 to select the I2C slave serial communication interface of the SERCOM. These bits are not synchronized. z Bit 1 – ENABLE: Enable 0: The peripheral is disabled. 1: The peripheral is enabled. Due to synchronization, there is delay from writing CTRLA.ENABLE until the peripheral is enabled/disabled. The value written to CTRL.ENABLE will read back immediately and the Synchronization Busy bit in the Status register (STATUS.SYNCBUSY) will be set. STATUS.SYNCBUSY will be cleared when the operation is complete. This bit is not enable-protected. z Bit 0 – SWRST: Software Reset 0: There is no reset operation ongoing. 1: The reset operation is ongoing. Writing a zero to this bit has no effect. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 414 Writing a one to this bit resets all registers in the SERCOM, except DBGCTRL, to their initial state, and the SERCOM will be disabled. Writing a one to CTRLA.SWRST will always take precedence, meaning that all other writes in the same write-operation will be discarded. Due to synchronization, there is a delay from writing CTRLA.SWRST until the reset is complete. CTRLA.SWRST and STATUS.SYNCBUSY will both be cleared when the reset is complete. This bit is not enable-protected. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 415 27.8.1.2 Control B Name: CTRLB Offset: 0x04 Reset: 0x00000000 Property: Write-Protected, Enable-Protected, Write-Synchronized Bit 31 30 29 28 27 26 25 24 Access R R R R R R R R Reset 0 0 0 0 0 0 0 0 Bit 23 22 21 20 19 18 17 16 ACKACT CMD[1:0] Access R R R R R R/W R/W R/W Reset 0 0 0 0 0 0 0 0 Bit 15 14 13 12 11 10 9 8 AMODE[1:0] Access SMEN R/W R/W R R R R R R/W Reset 0 0 0 0 0 0 0 0 Bit 7 6 5 4 3 2 1 0 Access R R R R R R R R Reset 0 0 0 0 0 0 0 0 z Bits 31:19 – 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. These bits will always return zero when read. z Bit 18 – ACKACT: Acknowledge Action 0: Send ACK 1: Send NACK The Acknowledge Action (ACKACT) bit defines the slave's acknowledge behavior after an address or data byte is received from the master. The acknowledge action is executed when a command is written to the CMD bits. If smart mode is enabled (CTRLB.SMEN is one), the acknowledge action is performed when the DATA register is read. This bit is not enable-protected. This bit is not write-synchronized. z Bits 17:16 – CMD[1:0]: Command Writing the Command bits (CMD) triggers the slave operation as defined in Table 27-4. The CMD bits are strobe bits, and always read as zero. The operation is dependent on the slave interrupt flags, INTFLAG.DRDY and INTFLAG.AMATCH, in addition to STATUS.DIR (See Table 27-4). Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 416 All interrupt flags (INTFLAG.DRDY, INTFLAG.AMATCH and INTFLAG.PREC) are automatically cleared when a command is given. This bit is not enable-protected. Table 27-4. Command Description CMD[1:0] DIR Action 0x0 X (No action) 0x1 X (Reserved) Used to complete a transaction in response to a data interrupt (DRDY) 0x2 0 (Master write) Execute acknowledge action succeeded by waiting for any start (S/Sr) condition 1 (Master read) Wait for any start (S/Sr) condition Used in response to an address interrupt (AMATCH) 0 (Master write) Execute acknowledge action succeeded by reception of next byte 1 (Master read) Execute acknowledge action succeeded by slave data interrupt 0x3 Used in response to a data interrupt (DRDY) z 0 (Master write) Execute acknowledge action succeeded by reception of next byte 1 (Master read) Execute a byte read operation followed by ACK/NACK reception Bits 15:14 – AMODE[1:0]: Address Mode These bits set the addressing mode according to Table 27-5. Table 27-5. Address Mode Description Value Name Description 0x0 MASK The slave responds to the address written in ADDR.ADDR masked by the value in ADDR.ADDRMASK(1). 0x1 2_ADDRS The slave responds to the two unique addresses in ADDR.ADDR and ADDR.ADDRMASK. 0x2 RANGE The slave responds to the range of addresses between and including ADDR.ADDR and ADDR.ADDRMASK. ADDR.ADDR is the upper limit. 0x3 - Reserved. See the SERCOM datasheet for additional information. This bit is not write-synchronized. z Bits 13:9 – 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. These bits will always return zero when read. z Bit 8 – SMEN: Smart Mode Enable This bit enables smart mode. When smart mode is enabled, acknowledge action is sent when DATA.DATA is read. 0: Smart mode is disabled. 1: Smart mode is enabled. This bit is not write-synchronized. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 417 z Bits 7:0 – 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. These bits will always return zero when read. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 418 27.8.1.3 Interrupt Enable Clear This register allows the user to disable an interrupt without doing a read-modify-write operation. Changes in this register will also be reflected in the Interrupt Enable Se registert (INTENSET). Name: INTENCLR Offset: 0x0C Reset: 0x00 Property: Write-Protected Bit 7 6 5 4 3 2 1 0 DRDY AMATCH PREC Access R R R R R R/W R/W R/W Reset 0 0 0 0 0 0 0 0 z Bits 7:3 – 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. These bits will always return zero when read. z Bit 2 – DRDY: Data Ready Interrupt Enable 0: The Data Ready interrupt is disabled. 1: The Data Ready interrupt is enabled. Writing a zero to this bit has no effect. Writing a one to this bit will clear the Data Ready bit, which disables the Data Ready interrupt. z Bit 1 – AMATCH: Address Match Interrupt Enable 0: The Address Match interrupt is disabled. 1: The Address Match interrupt is enabled. Writing a zero to this bit has no effect. Writing a one to this bit will clear the Address Match bit, which disables the Address Match interrupt. z Bit 0 – PREC: Stop Received Interrupt Enable 0: The Stop Received interrupt is disabled. 1: The Stop Received interrupt is enabled. Writing a zero to this bit has no effect. Writing a one to this bit will clear the Stop Received bit, which disables the Stop Received interrupt. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 419 27.8.1.4 Interrupt Enable Set This register allows the user to enable an interrupt without doing a read-modify-write operation. Changes in this register will also be reflected in the Interrupt Enable Clear register (INTENCLR). Name: INTENSET Offset: 0x0D Reset: 0x00 Property: Write-Protected Bit 7 6 5 4 3 2 1 0 DRDY AMATCH PREC Access R R R R R R/W R/W R/W Reset 0 0 0 0 0 0 0 0 z Bits 7:3 – 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. These bits will always return zero when read. z Bit 2 – DRDY: Data Ready Interrupt Enable 0: The Data Ready interrupt is disabled. 1: The Data Ready interrupt is enabled. Writing a zero to this bit has no effect. Writing a one to this bit will set the Data Ready bit, which enables the Data Ready interrupt. z Bit 1 – AMATCH: Address Match Interrupt Enable 0: The Address Match interrupt is disabled. 1: The Address Match interrupt is enabled. Writing a zero to this bit has no effect. Writing a one to this bit will set the Address Match bit, which enables the Address Match interrupt. z Bit 0 – PREC: Stop Received Interrupt Enable 0: The Stop Received interrupt is disabled. 1: The Stop Received interrupt is enabled. Writing a zero to this bit has no effect. Writing a one to this bit will set the Stop Received bit, which enables the Stop Received interrupt. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 420 27.8.1.5 Interrupt Flag Status and Clear Name: INTFLAG Offset: 0x0E Reset: 0x00 Property: - Bit 7 6 5 4 3 2 1 0 DRDY AMATCH PREC Access R R R R R R/W R/W R/W Reset 0 0 0 0 0 0 0 0 z Bits 7:3 – 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. These bits will always return zero when read. z Bit 2 – DRDY: Data Ready This flag is set when a I2C slave byte transmission is successfully completed. The flag is cleared by hardware when either: z Writing to the DATA register. z Reading the DATA register with smart mode enabled. z Writing a valid command to the CMD register. Optionally, the flag can be cleared manually by writing a one to INTFLAG.DRDY. Writing a zero to this bit has no effect. Writing a one to this bit will clear the Data Ready interrupt flag. z Bit 1 – AMATCH: Address Match This flag is set when the I2C slave address match logic detects that a valid address has been received. The flag is cleared by hardware when CTRL.CMD is written. Optionally the flag can be cleared manually by writing a one to INTFLAG.AMATCH. When cleared, an ACK/NACK will be sent according to CTRLB.ACKACT. Writing a zero to this bit has no effect. Writing a one to this bit will clear the Address Match interrupt flag. z Bit 0 – PREC: Stop Received This flag is set when a stop condition is detected for a transaction being processed. A stop condition detected between a bus master and another slave will not set this flag. This flag is cleared by hardware after a command is issued on the next address match. Optionally, the flag can be cleared manually by writing a one to INTFLAG.PREC. Writing a zero to this bit has no effect. Writing a one to this bit will clear the Stop Received interrupt flag. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 421 27.8.1.6 Status Name: STATUS Offset: 0x10 Reset: 0x0000 Property: - Bit 15 14 13 12 11 10 9 8 SYNCBUSY Access R R R R R R R R Reset 0 0 0 0 0 0 0 0 Bit 7 6 5 4 3 2 1 0 CLKHOLD LOWTOUT SR DIR RXNACK COLL BUSERR Access R R/W R R R R R/W R/W Reset 0 0 0 0 0 0 0 0 z Bit 15 – SYNCBUSY: Synchronization Busy This bit is cleared when the synchronization of registers between the clock domains is complete. This bit is set when the synchronization of registers between clock domains is started. z Bits 14:8 – 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. These bits will always return zero when read. z Bit 7 – CLKHOLD: Clock Hold The slave Clock Hold bit (STATUS.CLKHOLD) is set when the slave is holding the SCL line low, stretching the I2C clock. Software should consider this bit a read-only status flag that is set when INTFLAG.DRDY or INTFLAG.AMATCH is set. When the corresponding interrupt flag is cleared, this bit is also automatically cleared. z Bit 6 – LOWTOUT: SCL Low Time-out This bit is set if an SCL low time-out occurs. This bit is cleared automatically if responding to a new start condition with ACK or NACK (write 3 to CTRLB.CMD) or when INTFLAG.AMATCH is cleared. 0: No SCL low time-out has occurred. 1: SCL low time-out has occurred. Writing a zero to this bit has no effect. Writing a one to this bit will clear the status. z 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. This bit will always return zero when read. z Bit 4 – SR: Repeated Start When INTFLAG.AMATCH is raised due to an address match, SR indicates a repeated start or start condition. 0: Start condition on last address match 1: Repeated start condition on last address match This flag is only valid while the INTFLAG.AMATCH flag is one. z Bit 3 – DIR: Read / Write Direction The Read/Write Direction (STATUS.DIR) bit stores the direction of the last address packet received from a master. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 422 0: Master write operation is in progress. 1: Master read operation is in progress. z Bit 2 – RXNACK: Received Not Acknowledge This bit indicates whether the last data packet sent was acknowledged or not. 0: Master responded with ACK. 1: Master responded with NACK. z Bit 1 – COLL: Transmit Collision If set, the I2C slave was not able to transmit a high data or NACK bit, the I2C slave will immediately release the SDA and SCL lines and wait for the next packet addressed to it. This flag is intended for the SMBus address resolution protocol (ARP). A detected collision in non-ARP situations indicates that there has been a protocol violation, and should be treated as a bus error. Note that this status will not trigger any interrupt, and should be checked by software to verify that the data were sent correctly. This bit is cleared automatically if responding to an address match with an ACK or a NACK (writing 0x3 to CTRLB.CMD), or INTFLAG.AMATCH is cleared. 0: No collision detected on last data byte sent. 1: Collision detected on last data byte sent. Writing a zero to this bit has no effect. Writing a one to this bit will clear the status. z Bit 0 – BUSERR: Bus Error The Bus Error bit (STATUS.BUSERR) indicates that an illegal bus condition has occurred on the bus, regardless of bus ownership. An illegal bus condition is detected if a protocol violating start, repeated start or stop is detected on the I2C bus lines. A start condition directly followed by a stop condition is one example of a protocol violation. If a time-out occurs during a frame, this is also considered a protocol violation, and will set STATUS.BUSERR. This bit is cleared automatically if responding to an address match with an ACK or a NACK (writing 0x3 to CTRLB.CMD) or INTFLAG.AMATCH is cleared. 0: No bus error detected. 1: Bus error detected. Writing a one to this bit will clear the status. Writing a zero to this bit has no effect. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 423 27.8.1.7 Address Name: ADDR Offset: 0x14 Reset: 0x00000000 Property: Write-Protected, Enable-Protected Bit 31 30 29 28 27 26 25 24 Access R R R R R R R R Reset 0 0 0 0 0 0 0 0 Bit 23 22 21 20 19 18 17 16 ADDRMASK[6:0] Access R/W R/W R/W R/W R/W R/W R/W R Reset 0 0 0 0 0 0 0 0 Bit 15 14 13 12 11 10 9 8 Access R R R R R R R R Reset 0 0 0 0 0 0 0 0 Bit 7 6 5 4 3 2 1 0 ADDR[6:0] Access Reset GENCEN R/W R/W R/W R/W R/W R/W R/W R/W 0 0 0 0 0 0 0 0 z Bits 31:24 – 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. These bits will always return zero when read. z Bits 23:17 – ADDRMASK[6:0]: Address Mask The ADDRMASK bits acts as a second address match register, an address mask register or the lower limit of an address range, depending on the CTRLB.AMODE setting. z Bits 16:8 – 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. These bits will always return zero when read. z Bits 7:1 – ADDR[6:0]: Address The slave address (ADDR) bits contain the I2C slave address used by the slave address match logic to determine if a master has addressed the slave. When using 7-bit addressing, the address register (ADDR.ADDR) represents the slave address. If using 10-bit addressing, the address match logic only supports hardware address recognition of the first 2 bits of a 10-bit address. If writing ADDR.ADDR = "0b1111 0xx," 'xx' represents bits 9 and 8 or the slave address. The next byte received is bits 7 to 0 in the 10-bit address, and this must be handled by software. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 424 When the address match logic detects a match, INTFLAG.AMATCH is set and STATUS.DIR is updated to indicate whether it is a read or a write transaction. z Bit 0 – GENCEN: General Call Address Enable Writing a one to GENCEN enables general call address recognition. A general call address is an address of all zeroes with the direction bit written to zero (master write). 0: General call address recognition disabled. 1: General call address recognition enabled. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 425 27.8.1.8 Data Name: DATA Offset: 0x18 Reset: 0x0000 Property: Write-Synchronized, Read-Synchronized Bit 15 14 13 12 11 10 9 8 Access R R R R R R R R Reset 0 0 0 0 0 0 0 0 Bit 7 6 5 4 3 2 1 0 DATA[7:0] Access Reset R/W R/W R/W R/W R/W R/W R/W R/W 0 0 0 0 0 0 0 0 z Bits 15:8 – 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. These bits will always return zero when read. z Bits 7:0 – DATA[7:0]: Data The slave data register I/O location (DATA.DATA) provides access to the master transmit and receive data buffers. Reading valid data or writing data to be transmitted can be successfully done only when SCL is held low by the slave (STATUS.CLKHOLD is set). An exception occurs when reading the last data byte after the stop condition has been received. Accessing DATA.DATA auto-triggers I2C bus operations. The operation performed depends on the state of CTRLB.ACKACT, CTRLB.SMEN and the type of access (read/write). Writing or reading DATA.DATA when not in smart mode does not require synchronization. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 426 27.8.2 I2C Master Register Description 27.8.2.1 Control A Name: CTRLA Offset: 0x00 Reset: 0x00000000 Property: Write-Protected, Enable-Protected, Write-Synchronized Bit 31 30 LOWTOUT 29 28 27 26 25 24 INACTOUT[1:0] Access R R/W R/W R/W R R R R Reset 0 0 0 0 0 0 0 0 Bit 23 22 21 20 19 18 17 16 SDAHOLD[1:0] PINOUT Access R R R/W R/W R R R R/W Reset 0 0 0 0 0 0 0 0 Bit 15 14 13 12 11 10 9 8 Access R R R R R R R R Reset 0 0 0 0 0 0 0 0 Bit 7 6 5 4 3 2 1 0 ENABLE SWRST RUNSTDBY Access Reset MODE[2:0]=101 R/W R R R/W R/W R/W R/W R/W 0 0 0 0 0 0 0 0 z Bit 31 – 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. This bit will always return zero when read. z Bit 30 – LOWTOUT: SCL Low Time-Out This bit enables the SCL low time-out. If SCL is held low for 25ms-35ms, the master will release its clock hold, if enabled, and complete the current transaction. A stop condition will automatically be transmitted. INTFLAG.SB or INTFLAG.MB will be set as normal, but the clock hold will be released. The STATUS.LOWTOUT and STATUS.BUSERR status bits will be set. 0: Time-out disabled. 1: Time-out enabled. This bit is not synchronized. z Bits 29:28 – INACTOUT[1:0]: Inactive Time-Out If the inactive bus time-out is enabled and the bus is inactive for longer than the time-out setting, the bus state logic will be set to idle. An inactive bus arise when either an I2C master or slave is holding the SCL low. The available time-outs are given in Table 27-6. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 427 Enabling this option is necessary for SMBus compatibility, but can also be used in a non-SMBus set-up. Table 27-6. Inactive Timout Value Name Description 0x0 DIS Disabled 0x1 55US 5-6 SCL cycle time-out (50-60us) 0x2 105US 10-11 SCL cycle time-out (100-110us) 0x3 205US 20-21 SCL cycle time-out (200-210us) Calculated time-out periods are based on a 100kHz baud rate. These bits are not synchronized. z Bits 27:22 – 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. These bits will always return zero when read. z Bits 21:20 – SDAHOLD[1:0]: SDA Hold Time These bits define the SDA hold time with respect to the negative edge of SCL. Table 27-7. SDA Hold Time Value Name Description 0x0 DIS Disabled 0x1 75NS 50-100ns hold time 0x2 450NS 300-600ns hold time 0x3 600NS 400-800ns hold time These bits are not synchronized. z Bits 19:17 – 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. These bits will always return zero when read. z Bit 16 – PINOUT: Pin Usage This bit set the pin usage to either two- or four-wire operation: 0: 4-wire operation disabled. 1: 4-wire operation enabled. This bit is not synchronized. z Bits 15:8 – 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. These bits will always return zero when read. z Bit 7 – RUNSTDBY: Run in Standby This bit defines the functionality in standby sleep mode. 0: GCLK_SERCOMi_CORE is disabled and the I2C master will not operate in standy sleep mode. 1: GCLK_SERCOMi_CORE is enabled in all sleep modes allowing the master to operate in standby sleep mode. This bit is not synchronized. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 428 z Bits 6: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. These bits will always return zero when read. z Bits 4:2 – MODE[2:0]: Operating Mode These bits must be written to 0x5 to select the I2C master serial communication interface of the SERCOM. These bits are not synchronized. z Bit 1 – ENABLE: Enable 0: The peripheral is disabled. 1: The peripheral is enabled. Due to synchronization, there is delay from writing CTRLA.ENABLE until the peripheral is enabled/disabled. The value written to CTRL.ENABLE will read back immediately and the Synchronization Busy bit in the Status register (STATUS.SYNCBUSY) will be set. STATUS.SYNCBUSY will be cleared when the operation is complete. This bit is not enable-protected. z Bit 0 – SWRST: Software Reset 0: There is no reset operation ongoing. 1: The reset operation is ongoing. Writing a zero to this bit has no effect. Writing a one to this bit resets all registers in the SERCOM, except DBGCTRL, to their initial state, and the SERCOM will be disabled. Writing a one to CTRLA.SWRST will always take precedence, meaning that all other writes in the same write-operation will be discarded. Due to synchronization there is a delay from writing CTRLA.SWRST until the reset is complete. CTRLA.SWRST and STATUS.SYNCBUSY will both be cleared when the reset is complete. This bit is not enable-protected. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 429 27.8.2.2 Control B Name: CTRLB Offset: 0x04 Reset: 0x00000000 Property: Write-Protected, Enable-Protected, Write-Synchronized Bit 31 30 29 28 27 26 25 24 Access R R R R R R R R Reset 0 0 0 0 0 0 0 0 Bit 23 22 21 20 19 18 17 16 ACKACT CMD[1:0] Access R R R R R R/W R/W R/W Reset 0 0 0 0 0 0 0 0 Bit 15 14 13 12 11 10 9 8 QCEN SMEN Access R R R R R R R R/W Reset 0 0 0 0 0 0 0 0 Bit 7 6 5 4 3 2 1 0 Access R R R R R R R R Reset 0 0 0 0 0 0 0 0 z Bits 31:19 – 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. These bits will always return zero when read. z Bit 18 – ACKACT: Acknowledge Action The Acknowledge Action (ACKACT) bit defines the I2C master's acknowledge behavior after a data byte is received from the I2C slave. The acknowledge action is executed when a command is written to CTRLB.CMD, or if smart mode is enabled (CTRLB.SMEN is written to one), when DATA.DATA is read. 0: Send ACK. 1: Send NACK. This bit is not enable-protected. This bit is not write-synchronized. z Bits 17:16 – CMD[1:0]: Command Writing the Command bits (CMD) triggers the master operation as defined in Table 27-8. The CMD bits are strobe bits, and always read as zero. The acknowledge action is only valid in master read mode. In master write mode, a command will only result in a repeated start or stop condition. The CTRLB.ACKACT bit and the CMD bits can be written at the same time, and then the acknowledge action will be updated before the command is triggered. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 430 Commands can only be issued when the Slave on Bus interrupt flag (INTFLAG.SB) or Master on Bus interrupt flag (INTFLAG.MB) is one. If CMD 0x1 is issued, a repeated start will be issued followed by the transmission of the current address in ADDR.ADDR. If another address is desired, ADDR.ADDR must be written instead of the CMD bits. This will trigger a repeated start followed by transmission of the new address. Issuing a command will set STATUS.SYNCBUSY. Table 27-8. Command Description CMD[1:0] DIR Action 0x0 X (No action) 0x1 X Execute acknowledge action succeeded by repeated Start 0 (Write) No operation 1 (Read) Execute acknowledge action succeeded by a byte read operation X Execute acknowledge action succeeded by issuing a stop condition 0x2 0x3 These bits are not enable-protected. z Bits 15:10 – 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. These bits will always return zero when read. z Bit 9 – QCEN: Quick Command Enable Setting the Quick Command Enable bit (QCEN) enables quick command. 0: Quick Command is disabled. 1: Quick Command is enabled. This bit is not write-synchronized. z Bit 8 – SMEN: Smart Mode Enable This bit enables smart mode. When smart mode is enabled, acknowledge action is sent when DATA.DATA is read. 0: Smart mode is disabled. 1: Smart mode is enabled. This bit is not write-synchronized. z Bits 7:0 – 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. These bits will always return zero when read. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 431 27.8.2.3 Debug Control Name: DBGCTRL Offset: 0x08 Reset: 0x00 Property: Write-Protected Bit 7 6 5 4 3 2 1 0 DBGSTOP Access R R R R R R R R/W Reset 0 0 0 0 0 0 0 0 z Bits 7:1 – 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. These bits will always return zero when read. z Bit 0 – DBGSTOP: Debug Stop Mode This bit controls functionality when the CPU is halted by an external debugger. 0: The baud-rate generator continues normal operation when the CPU is halted by an external debugger. 1: The baud-rate generator is halted when the CPU is halted by an external debugger. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 432 27.8.2.4 Baud Rate Name: BAUD Offset: 0x0A Reset: 0x0000 Property: Write-Protected, Enable-Protected Bit 15 14 13 12 11 10 9 8 BAUDLOW[7:0] Access R/W R/W R/W R/W R/W R/W R/W R/W Reset 0 0 0 0 0 0 0 0 Bit 7 6 5 4 3 2 1 0 BAUD[7:0] Access Reset z R/W R/W R/W R/W R/W R/W R/W R/W 0 0 0 0 0 0 0 0 Bits 15:8 – BAUDLOW[7:0]: Master Baud Rate Low If the Master Baud Rate Low bit group (BAUDLOW) has a non-zero value, the SCL low time will be described by the value written. For more information on how to calculate the frequency, see “SERCOM I2C – SERCOM Inter-Integrated Circuit” on page 394. z Bits 7:0 – BAUD[7:0]: Master Baud Rate The Master Baud Rate bit group (BAUD) is used to derive the SCL high time if BAUD.BAUDLOW is non-zero. If BAUD.BAUDLOW is zero, BAUD will be used to generate both high and low periods of the SCL. For more information on how to calculate the frequency, see “SERCOM I2C – SERCOM Inter-Integrated Circuit” on page 394. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 433 27.8.2.5 Interrupt Enable Clear This register allows the user to disable an interrupt without doing a read-modify-write operation. Changes in this register will also be reflected in the Interrupt Enable Set register (INTENSET). Name: INTENCLR Offset: 0x0C Reset: 0x00 Property: Write-Protected Bit 7 6 5 4 3 2 1 0 SB MB Access R R R R R R R/W R/W Reset 0 0 0 0 0 0 0 0 z Bits 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. These bits will always return zero when read. z Bit 1 – SB: Slave on Bus Interrupt Enable 0: The Slave on Bus interrupt is disabled. 1: The Slave on Bus interrupt is enabled. Writing a zero to this bit has no effect. Writing a one to this bit will clear the Slave on Bus bit, which disables the Slave on Bus interrupt. z Bit 0 – MB: Master on Bus Interrupt Enable 0: The Master on Bus interrupt is disabled. 1: The Master on Bus interrupt is enabled. Writing a zero to this bit has no effect. Writing a one to this bit will clear the Master on Bus bit, which disables the Master on Bus interrupt. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 434 27.8.2.6 Interrupt Enable Set This register allows the user to enable an interrupt without doing a read-modify-write operation. Changes in this register will also be reflected in the Interrupt Enable Clear register (INTENCLR). Name: INTENSET Offset: 0x0D Reset: 0x00 Property: Write-Protected Bit 7 6 5 4 3 2 1 0 SB MB Access R R R R R R R/W R/W Reset 0 0 0 0 0 0 0 0 z Bits 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. These bits will always return zero when read. z Bit 1 – SB: Slave on Bus Interrupt Enable 0: The Slave on Bus interrupt is disabled. 1: The Slave on Bus interrupt is enabled. Writing a zero to this bit has no effect. Writing a one to this bit will set the Slave on Bus bit, which enables the Slave on Bus interrupt. z Bit 0 – MB: Master on Bus Interrupt Enable 0: The Master on Bus interrupt is disabled. 1: The Master on Bus interrupt is enabled. Writing a zero to this bit has no effect. Writing a one to this bit will set the Master on Bus bit, which enables the Master on Bus interrupt. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 435 27.8.2.7 Interrupt Flag Status and Clear Name: INTFLAG Offset: 0x0E Reset: 0x00 Property: - Bit 7 6 5 4 3 2 1 0 SB MB Access R R R R R R R/W R/W Reset 0 0 0 0 0 0 0 0 z Bits 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. These bits will always return zero when read. z Bit 1 – SB: Slave on Bus The Slave on Bus flag (SB) is set when a byte is successfully received in master read mode, i.e., no arbitration lost or bus error occurred during the operation. When this flag is set, the master forces the SCL line low, stretching the I2C clock period. The SCL line will be released and SB will be cleared on one of the following actions: z Writing to ADDR.ADDR z Writing to DATA.DATA z Reading DATA.DATA when smart mode is enabled (CTRLB.SMEN) z Writing a valid command to CTRLB.CMD Writing a one to this bit location will clear the SB flag. The transaction will not continue or be terminated until one of the above actions is performed. Writing a zero to this bit has no effect. z Bit 0 – MB: Master on Bus The Master on Bus flag (MB) is set when a byte is transmitted in master write mode. The flag is set regardless of the occurrence of a bus error or an arbitration lost condition. MB is also set when arbitration is lost during sending of NACK in master read mode, and when issuing a start condition if the bus state is unknown. When this flag is set and arbitration is not lost, the master forces the SCL line low, stretching the I2C clock period. The SCL line will be released and MB will be cleared on one of the following actions: z Writing to ADDR.ADDR z Writing to DATA.DATA z Reading DATA.DATA when smart mode is enabled (CTRLB.SMEN) z Writing a valid command to CTRLB.CMD If arbitration is lost, writing a one to this bit location will clear the MB flag. If arbitration is not lost, writing a one to this bit location will clear the MB flag. The transaction will not continue or be terminated until one of the above actions is performed. Writing a zero to this bit has no effect. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 436 27.8.2.8 Status Name: STATUS Offset: 0x10 Reset: 0x0000 Property: Write-Synchronized Bit 15 14 13 12 11 10 9 8 SYNCBUSY Access R R R R R R R R Reset 0 0 0 0 0 0 0 0 Bit 7 6 5 4 3 2 1 0 CLKHOLD LOWTOUT RXNACK ARBLOST BUSERR Access R R/W R R/W R R R/W R/W Reset 0 0 0 0 0 0 0 0 z BUSSTATE[1:0] Bit 15 – SYNCBUSY: Synchronization Busy This bit is cleared when the synchronization of registers between the clock domains is complete. This bit is set when the synchronization of registers between clock domains is started. z Bits 14:8 – 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. These bits will always return zero when read. z Bit 7 – CLKHOLD: Clock Hold The Master Clock Hold flag (STATUS.CLKHOLD) is set when the master is holding the SCL line low, stretching the I2C clock. Software should consider this bit a read-only status flag that is set when INTFLAG.SB or INTFLAG.MB is set. When the corresponding interrupt flag is cleared and the next operation is given, this bit is automatically cleared. Writing a zero to this bit has no effect. Writing a one to this bit has no effect. This bit is not write-synchronized. z Bit 6 – LOWTOUT: SCL Low Time-Out This bit is set if an SCL low time-out occurs. Writing a one to this bit location will clear STATUS.LOWTOUT. Normal use of the I2C interface does not require the LOWTOUT flag to be cleared by this method. This flag is automatically cleared when either: z Writing to ADDR.ADDR z Writing to DATA.DATA z Reading DATA.DATA when smart mode is enabled (CTRLB.SMEN) z Writing a valid command to CTRLB.CMD Writing a zero to this bit has no effect. This bit is not write-synchronized. z Bits 5:4 – BUSSTATE[1:0]: Bus State These bits indicate the current I2C bus state as defined in Table 27-9. After enabling the SERCOM as an I2C master, the bus state will be unknown. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 437 Table 27-9. Bus State Value Name 0x0 Unknown 0x1 Idle 0x2 Owner 0x3 Busy Description The bus state is unknown to the I2C master and will wait for a stop condition to be detected or wait to be forced into an idlestate by software The bus state is waiting for a transaction to be initialized The I2C master is the current owner of the bus Some other I2C master owns the bus When the master is disabled, the bus-state is unknown. When in the unknown state, writing 0x1 to BUSSTATE forces the bus state into the idle state. The bus state cannot be forced into any other state. Writing STATUS.BUSSTATE to idle will set STATUS.SYNCBUSY. z 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. This bit will always return zero when read. z Bit 2 – RXNACK: Received Not Acknowledge This bit indicates whether the last address or data packet sent was acknowledged or not. 0: Slave responded with ACK. 1: Slave responded with NACK. Writing a zero to this bit has no effect. Writing a one to this bit has no effect. This bit is not write-synchronized. z Bit 1 – ARBLOST: Arbitration Lost The Arbitration Lost flag (STATUS.ARBLOST) is set if arbitration is lost while transmitting a high data bit or a NACK bit, or while issuing a start or repeated start condition on the bus. The Master on Bus interrupt flag (INTFLAG.MB) will be set when STATUS.ARBLOST is set. Writing the ADDR.ADDR register will automatically clear STATUS.ARBLOST. Writing a zero to this bit has no effect. Writing a one to this bit will clear it. This bit is not write-synchronized. z Bit 0 – BUSERR: Bus Error The Bus Error bit (STATUS.BUSERR) indicates that an illegal bus condition has occurred on the bus, regardless of bus ownership. An illegal bus condition is detected if a protocol violating start, repeated start or stop is detected on the I2C bus lines. A start condition directly followed by a stop condition is one example of a protocol violation. If a time-out occurs during a frame, this is also considered a protocol violation, and will set BUSERR. If the I2C master is the bus owner at the time a bus error occurs, STATUS.ARBLOST and INTFLAG.MB will be set in addition to BUSERR. Writing the ADDR.ADDR register will automatically clear the BUSERR flag. Writing a zero to this bit has no effect. Writing a one to this bit will clear it. This bit is not write-synchronized. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 438 27.8.2.9 Address Name: ADDR Offset: 0x14 Reset: 0x0000 Property: Write-Synchronized Bit 15 14 13 12 11 10 9 8 Access R R R R R R R R Reset 0 0 0 0 0 0 0 0 Bit 7 6 5 4 3 2 1 0 ADDR[7:0] Access Reset R/W R/W R/W R/W R/W R/W R/W R/W 0 0 0 0 0 0 0 0 z Bits 15:8 – 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. These bits will always return zero when read. z Bits 7:0 – ADDR[7:0]: Address When ADDR is written, the consecutive operation will depend on the bus state: Unknown: INTFLAG.MB and STATUS.BUSERR are set, and the operation is terminated. Busy: The I2C master will await further operation until the bus becomes idle. Idle: The I2C master will issue a start condition followed by the address written in ADDR. If the address is acknowledged, SCL is forced and held low, and STATUS.CLKHOLD and INTFLAG.MB are set. Owner: A repeated start sequence will be performed. If the previous transaction was a read, the acknowledge action is sent before the repeated start bus condition is issued on the bus. Writing ADDR to issue a repeated start is performed while INTFLAG.MB or INTFLAG.SB is set. Regardless of winning or loosing arbitration, the entire address will be sent. If arbitration is lost, only ones are transmitted from the point of loosing arbitration and the rest of the address length. STATUS.BUSERR, STATUS.ARBLOST, INTFLAG.MB and INTFLAG.SB will be cleared when ADDR is written. The ADDR register can be read at any time without interfering with ongoing bus activity,as a read access does not trigger the master logic to perform any bus protocol related operations. The I2C master control logic uses bit 0 of ADDR as the bus protocol’s read/write flag (R/W); 0 for write and 1 for read. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 439 27.8.2.10 Data Name: DATA Offset: 0x18 Reset: 0x0000 Property: Write-Synchronized, Read-Synchronized Bit 15 14 13 12 11 10 9 8 Access R R R R R R R R Reset 0 0 0 0 0 0 0 0 Bit 7 6 5 4 3 2 1 0 DATA[7:0] Access Reset R/W R/W R/W R/W R/W R/W R/W R/W 0 0 0 0 0 0 0 0 z Bits 15:8 – 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. These bits will always return zero when read. z Bits 7:0 – DATA[7:0]: Data The master data register I/O location (DATA) provides access to the master transmit and receive data buffers. Reading valid data or writing data to be transmitted can be successfully done only when SCL is held low by the master (STATUS.CLKHOLD is set). An exception occurswhen reading the last data byte after the stop condition has been sent. Accessing DATA.DATA auto-triggers I2C bus operations. The operation performed depends on the state of CTRLB.ACKACT, CTRLB.SMEN and the type of access (read/write). Writing or reading DATA.DATA when not in smart mode does not require synchronization. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 440 28. TC – Timer/Counter 28.1 Overview The TC consists of a counter, a prescaler, compare/capture channels and control logic. The counter can be set to count events, or it can be configured to count clock pulses. The counter, together with the compare/capture channels, can be configured to timestamp input events, allowing capture of frequency and pulse width. It can also perform waveform generation, such as frequency generation and pulse-width modulation (PWM). 28.2 Features z Selectable configuration z 8-, 16- or 32-bit TC, with compare/capture channels z Waveform generation z z Frequency generation Single-slope pulse-width modulation z Input capture z Event capture Frequency capture z Pulse-width capture z z One input event z Interrupts/output events on: z z Counter overflow/underflow Compare match or capture z Internal prescaler Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 441 Block Diagram Figure 28-1. Timer/Counter Block Diagram Base Counter PER Prescaler count Counter OVF/UNF (INT Req.) clear load COUNT Control logic direction ZERO UPDATE TOP = =0 ERR (INT Req.) event 28.3 Compare / Capture Control logic Waveform generation CC0 match = WOx Out CCx (INT Req.) Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 442 28.4 Signal Description Signal Name Type Description WO[1:0] Digital output Waveform output Refer to “I/O Multiplexing and Considerations” on page 15 for details on the pin mapping for this peripheral. One signal can be mapped on several pins. 28.5 Product Dependencies In order to use this peripheral, other parts of the system must be configured correctly, as described below. 28.5.1 I/O Lines Using the TC’s I/O lines requires the I/O pins to be configured. Refer to “PORT” on page 289 for details. 28.5.2 Power Management The TC can continue to operate in any sleep mode where the selected source clock is running. The TC interrupts can be used to wake up the device from sleep modes. The events can trigger other operations in the system without exiting sleep modes. Refer to “PM – Power Manager” on page 105 for details on the different sleep modes. 28.5.3 Clocks The TC bus clock (CLK_TCx_APB, where x represents the specific TC instance number) can be enabled and disabled in the Power Manager, and the default state of CLK_TCx_APB can be found in the Peripheral Clock Masking section in “PM – Power Manager” on page 105. The different TC instances are paired, even and odd, starting from TC0, and use the same generic clock, GCLK_TCx. This means that the TC instances in a TC pair cannot be set up to use different GCLK_TCx clocks This generic clock is asynchronous to the user interface clock (CLK_TCx_APB). Due to this asynchronicity, accessing certain registers will require synchronization between the clock domains. Refer to “Synchronization” on page 452 for further details. 28.5.4 Interrupts The interrupt request line is connected to the Interrupt Controller. Using the TC interrupts requires the interrupt controller to be configured first. Refer to “Nested Vector Interrupt Controller” on page 28 for details. 28.5.5 Events To use the TC event functionality, the corresponding events need to be configured in the event system. Refer to “EVSYS – Event System” on page 314 for details. 28.5.6 Debug Operation When the CPU is halted in debug mode the TC will halt normal operation. The TC can be forced to continue operation during debugging. Refer to the DBGCTRL register for details. 28.5.7 Register Access Protection All registers with write-access are optionally write-protected by the peripheral access controller (PAC), except the following registers: z Interrupt Flag register (INTFLAG) z Status register (STATUS) Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 443 z Read Request register (READREQ) z Count register (COUNT) z Period register (PER) z Compare/Capture Value registers (CCx) Write-protection is denoted by the Write-Protection property in the register description. When the CPU is halted in debug mode, all write-protection is automatically disabled. Write-protection does not apply for accesses through an external debugger. Refer to “PAC – Peripheral Access Controller” on page 31 for details. 28.5.8 Analog Connections Not applicable. 28.6 Functional Description 28.6.1 Principle of Operation The counter in the TC can be set to count on events from the Event System, or on the GCLK_TCx frequency. The pulses from GCLK_TCx will go through the prescaler, where it is possible to divide the frequency down. The value in the counter is passed to the compare/capture channels, where it can either be compared with user defined values or captured on a predefined event. The TC can be configured as an 8-, 16- or 32-bit counter. Which mode is chosen will determine the maximum range of the counter. The counter range combined with the operating frequency will determine the maximum time resolution achievable with the TC peripheral. The TC can be set to count up or down. By default, the counter will operate in a continuous mode, where the counter will wrap to the zero respectively top value it counts from when reaching the top respectively zero. When one of the compare/capture channels is used in compare mode, the TC can be used for waveform generation. Upon a match between the counter and the value in one or more of the Compare/Capture Value registers (CCx), one or more output pins on the device can be set to toggle. The CCx registers and the counter can thereby be used in frequency generation and PWM generation. Capture mode can be used to automatically capture the period and pulse width of signals. 28.6.2 Basic Operation 28.6.2.1 Initialization The following register is enable-protected, meaning that it can only be written when the TC is disabled (CTRLA.ENABLE is zero): z Control A register (CTRLA), except the Run Standby (RUNSTDBY), Enable (ENABLE) and Software Reset (SWRST) bits The following bits are enable-protected: z Event Action bits in the Event Control register (EVCTRL.EVACT) Enable-protected bits in the CTRLA register can be written at the same time as CTRLA.ENABLE is written to one, but not at the same time as CTRLA.ENABLE is written to zero. Before the TC is enabled, it must be configured, as outlined by the following steps: z The TC bus clock (CLK_TCx_APB) must be enabled z The mode (8, 16 or 32 bits) of the TC must be selected in the TC Mode bit group in the Control A register (CTRLA.MODE). The default mode is 16 bits Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 444 z One of the wavegen modes must be selected in the Waveform Generation Operation bit group in the Control A register (CTRLA.WAVEGEN) z If the GCLK_TCx frequency used should be prescaled, this can be selected in the Prescaler bit group in the Control A register (CTRLA.PRESCALER) z If the prescaler is used, one of the presync modes must be chosen in the Prescaler and Counter Synchronization bit group in the Control A register (CTRLA.PRESYNC) z One-shot mode can be selected by writing a one to the One-Shot bit in the Control B Set register (CTRLBSET.ONESHOT) z If the counter should count down from the top value, write a one to the Counter Direction bit in the Control B Set register (CTRLBSET.DIR) z If capture operations are to be used, the individual channels must be enabled for capture in the Capture Channel x Enable bit group in the Control C register (CTRLC.CPTEN) z The waveform output for individual channels can be inverted using the Output Waveform Invert Enable bit group in the Control C register (CTRLC.INVEN) 28.6.2.2 Enabling, Disabling and Resetting The TC is enabled by writing a one to the Enable bit in the Control A register (CTRLA.ENABLE). The TC is disabled by writing a zero to CTRLA.ENABLE. The TC is reset by writing a one to the Software Reset bit in the Control A register (CTRLA.SWRST). All registers in the TC, except DBGCTRL, will be reset to their initial state, and the TC will be disabled. Refer to the CTRLA register for details. The TC should be disabled before the TC is reset to avoid undefined behavior. 28.6.2.3 Prescaler Selection As seen in Figure 28-2, the GCLK_TC clock is fed into the internal prescaler. Prescaler output intervals from 1 to 1/1024 are available. For a complete list of available prescaler outputs, see the register description for the Prescaler bit group in the Control A register (CTRLA.PRESCALER). The prescaler consists of a counter that counts to the selected prescaler value, whereupon the output of the prescaler toggles. When the prescaler is set to a value greater than one, it is necessary to choose whether the prescaler should reset its value to zero or continue counting from its current value on the occurrence of an overflow or underflow. It is also necessary to choose whether the TC counter should wrap around on the next GCLK_TC clock pulse or the next prescaled clock pulse (CLK_TC_CNT of Figure 28-2). To do this, use the Prescaler and Counter Synchronization bit group in the Control A register (CTRLA.PRESYNC). If the counter is set to count events from the event system, these will not pass through the prescaler, as seen in Figure 28-2. Figure 28-2. Prescaler PRESCALER GCLK_TC Prescaler EVACT GCLK_TC / {1,2,4,8,64,256,1024} CLK_TC_CNT CNT EVENT 28.6.2.4 TC Mode The counter mode is selected with the TC Mode bit group in the Control A register (CTRLA.MODE). By default, the counter is enabled in the 16-bit counter mode. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 445 Three counter modes are available: z COUNT8: The 8-bit TC has its own Period register (PER). This register is used to store the period value that can be used as the top value for waveform generation. z COUNT16: This is the default counter mode. There is no dedicated period register in this mode. z COUNT32: This mode is achieved by pairing two 16-bit TC peripherals. This pairing is explained in “Clocks” on page 443. The even-numbered TC instance will act as master to the odd-numbered TC peripheral,which will act as a slave. The slave status of the slave is indicated by reading the Slave bit in the Status register (STATUS.SLAVE). The registers of the slave will not reflect the registers of the 32-bit counter. Writing to any of the slave registers will not affect the 32-bit counter. Normal access to the slave COUNT and CCx registers is not allowed. 28.6.2.5 Counter Operations The counter can be set to count up or down. When the counter is counting up and the top value is reached, the counter will wrap around to zero on the next clock cycle. When counting down, the counter will wrap around to the top value when zero is reached. For one-shot mode, the counter will continue to count after a wraparound occurs. To set the counter to count down, write a one to the Direction bit in the Control B Set register (CTRLBSET.DIR). To count up, write a one to the Direction bit in the Control B Clear register (CTRLBCLR.DIR). Each time the counter reaches the top value or zero, it will set the Overflow Interrupt flag in the Interrupt Flag Status and Clear register (INTFLAG.OVF). It is also possible to generate an event on overflow or underflow when the Overflow/Underflow Event Output Enable bit in the Event Control register (EVCTRL.OVFEO) is one. The counter value can be read from the Counter Value register (COUNT) or a new value can be written to the COUNT register. Figure 28-3 gives an example of writing a new counter value. The COUNT value will always be zero when starting the TC, unless some other value has been written to it or the TC has been stopped at some value other than zero. Figure 28-3. Counter Operation Period(T) Direction Change COUNT written "update " COUNT TOP BOT DIR Stop Command On the stop command, which can be evoked in the Command bit group in the Control B Set register (CTRLBSET.CMD), the counter will retain its current value. All waveforms are cleared. The counter stops counting, and the Stop bit in the Status register is set (STATUS.STOP). Retrigger Command and Event Action Retriggering can be evoked either as a software command, using the Retrigger command in the Control B Set register (CTRLBSET.CMD), or as a retrigger event action, using the Event Action bit group in the Event Control register (EVCTRL.EVACT). Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 446 When a retrigger is evoked while the counter is running, the counter will wrap to the top value or zero, depending on the counter direction.. When a retrigger is evoked with the counter stopped, the counter will continue counting from the value in the COUNT register. Note: When retrigger event action is configured and enabled as an event action, enabling the counter will not start the counter. The counter will start at the next incoming event and restart on any following event. Count Event Action When the count event action is configured, every new incoming event will make the counter increment or decrement, depending on the state of the direction bit (CTRLBSET.DIR). Start Event Action When the TC is configured with a start event action in the EVCTRL.EVACT bit group, enabling the TC does not make the counter start; the start is postponed until the next input event or software retrigger action. When the counter is running, an input event has not effect on the counter. 28.6.2.6 Compare Operations When using the TC with the Compare/Capture Value registers (CCx) configured for compare operation, the counter value is continuously compared to the values in the CCx registers. This can be used for timer or waveform operation. Waveform Output Operations The compare channels can be used for waveform generation on the corresponding I/O pins. To make the waveform visible on the connected pin, the following requirements must be fulfilled: 1. Choose a waveform generation operation 2. Optionally, invert the waveform output by writing the corresponding Output Waveform Invert Enable bit in the Control C register (CTRLC.INVx) 3. Enable the corresponding multiplexor in the PORT The counter value is continuously compared with each CCx available. When a compare match occurs, the Match or Capture Channel x interrupt flag in the Interrupt Flag Status and Clear register (INTFLAG.MCx) is set on the next zero-toone transition of CLK_TC_CNT (see Figure 28-4). An interrupt and/or event can be generated on such a condition when INTENSET.MCx and/or EVCTRL.MCEOx is one. One of four configurations in the Waveform Generation Operation bit group in the Control A register (CTRLA.WAVEGEN) must be chosen to perform waveform generation. This will influence how the waveform is generated and impose restrictions on the top value. The four configurations are: z Normal frequency (NFRQ) z Match frequency (MFRQ) z Normal PWM (NPWM) z Match PWM (MPWM) When using NPWM or NFRQ, the top value is determined by the counter mode. In 8-bit mode, the Period register (PER) is used as the top value and the top value can be changed by writing to the PER register. In 16- and 32-bit mode, the top value is fixed to the maximum value of the counter. z Frequency Operation When NFRQ is used, the output waveform (WO[x]) toggles every time CCx and the counter are equal, and the interrupt flag corresponding to that channel will be set. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 447 Figure 28-4. Normal Frequency Operation CNT written "wraparound " TOP COUNT CCx Zero WO[x] When MFRQ is used, the value in CC0 will be used as the top value and WO[0] will toggle on every overflow/underflow. Figure 28-5. Match Frequency Operation Period (T) Direction Change COUNT written " wraparound " COUNT TOP Zero WO[0] z PWM Operation In PWM operation, the CCx registers control the duty cycle of the waveform generator output. Figure 28-6 shows how the WO[x] output is set at a start or a compare match between the COUNT value and the top value, and cleared on the compare match between the COUNT value and CCx register value. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 448 Figure 28-6. Normal PWM Operation Period(T) CCn= BOT CCn= TOP "wraparound " "match " TOP COUNT CC n Zero WO[x] In match operation, Compare/Capture register CC0 is used as the top value, and in this case WO[0] will toggle on every overflow/underflow. The following equation is used to calculate the exact period for a single-slope PWM (RPWM_SS) waveform: log ( TOP + 1 ) R PWM_SS = ---------------------------------log ( 2 ) f CLK_TC f PWM_SS = ----------------------------N ( TOP + 1 ) where N represent the prescaler divider used (1, 2, 4, 8, 16, 64, 256, 1024). Changing the Top Value Changing the top value while the counter is running is possible. If a new top value is written when the counter value is close to zero and counting down, the counter can be reloaded with the previous top value, due to synchronization delays. If this happens, the counter will count one extra cycle before the new top value is used. Figure 28-7. Changing the Top Value when Counting Down MAX " reload" " write" COUNT ZERO New TOP value That is higher than Current COUNT New TOP value That is Lower than Current COUNT Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 449 When counting up a change from a top value that is lower relative to the old top value can make the counter miss this change if the counter value is larger than the new top value when the change occurred. This will make the counter count to the max value. An example of this can be seen in Figure 28-8. Figure 28-8. Changing the Top Value when Counting Up Counter Wraparound MAX " wraparound " " write " COUNT ZERO New TOP value That is higher than Current COUNT New TOP value That is Lower than Current COUNT 28.6.2.7 Capture Operations To enable and use capture operations, the event line into the TC must be enabled using the TC Event Input bit in the Event Control register (EVCTRL.TCEI). The capture channels to be used must also be enabled in the Capture Channel x Enable bit group in the Control C register (CTRLC.CPTENx) before capture can be performed. Event Capture Action The compare/capture channels can be used as input capture channels to capture any event from the Event System and give them a timestamp. Because all capture channels use the same event line, only one capture channel should be enabled at a time when performing event capture. Figure 28-9 shows four capture events for one capture channel. Figure 28-9. Input Capture Timing events TOP COUNT ZERO Capture 0 Capture 1 Capture 2 Capture 3 When the Capture Interrupt flag is set and a new capture event is detected, there is nowhere to store the new timestamp. As a result, the Error Interrupt flag in the Interrupt Flag Status and Clear register (INTFLAG.ERR) is set. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 450 Period and Pulse-Width Capture Action The TC can perform two input captures and restart the counter on one of the edges. This enables the TC to measure the pulse width and period. This can be used to characterize the frequency and duty cycle of an input signal: 1 f = --T tp dutyCycle = ----T When using PPW event action, the period (T) will be captured into CC0 and the pulse width (tp) in CC1. In PWP event action, the pulse width (tp) will be captured in CC0 and the period (T) in CC1. Selecting PWP (pulse-width, period) or PPW (period, pulse-width) in the Event Action bit group in the Event Control register (EVCTRL.EVACT) enables the TC to performs two capture actions, one on the rising edge and one on the falling edge. The TC Inverted Event Input in the Event Control register (EVCTRL.TCINV) is used to select whether the wraparound should occur on the rising edge or the falling edge. If EVCTRL.TCINV is written to one, the wraparound will happen on the falling edge. The event source to be captured must be an asynchronous event. To fully characterize the frequency and duty cycle of the input signal, activate capture on CC0 and CC1 by writing 0x3 to the Capture Channel x Enable bit group in the Control C register (CTRLC.CPTEN). When only one of these measurements is required, the second channel can be used for other purposes. The TC can detect capture overflow of the input capture channels. When the Capture Interrupt flag is set and a new capture event is detected, there is nowhere to store the new timestamp. Asa result, INTFLAG.ERR is set. 28.6.3 Additional Features 28.6.3.1 One-Shot Operation When one-shot operation is enabled, the counter automatically stops on the next counter overflow or underflow condition. When the counter is stopped, STATUS.STOP is automatically set by hardware and the waveform outputs are set to zero. One-shot operation can be enabled by writing a one into the One-Shot bit in the Control B Set register (CTRLBSET.ONESHOT) and disabled by writing a one to the One-Shot bit in the Control B Clear register (CTRLBCLR.ONESHOT). When enabled, it will count until an overflow or underflow occurs. The one-shot operation can be restarted with a retrigger command, a retrigger event or a start event. When the counter restarts its operation, the Stop bit in the Status register (STATUS.STOP) is automatically cleared by hardware. 28.6.4 Interrupts The TC has the following interrupt sources: z Overflow/Underflow: OVF z Compare or Capture Channels z Capture Overflow Error: ERR z Synchronization Ready: SYNCRDY Each interrupt source has an interrupt flag associated with it. The interrupt flag in the Interrupt Flag Status and Clear register (INTFLAG) is set when the interrupt condition occurs. Each interrupt can be individually enabled by writing a one to the corresponding bit in the Interrupt Enable Set register (INTENSET), and disabled by writing a one to the corresponding bit in the Interrupt Enable Clear register (INTENCLR). An interrupt request is generated when the interrupt flag is set and the corresponding interrupt is enabled. The interrupt request remains active until the interrupt flag is cleared, the interrupt is disabled or the TC is reset. See the INTFLAG register for details on how to clear interrupt flags. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 451 The TC has one common interrupt request line for all the interrupt sources. The user must read the INTFLAG register to determine which interrupt condition is present. Note that interrupts must be globally enabled for interrupt requests to be generated. Refer to “Nested Vector Interrupt Controller” on page 28 for details. 28.6.5 Events The TC can generate the following output events: z Overflow/Underflow (OVF) z Match or Capture (MC) Writing a one to an Event Output bit in the Event Control register (EVCTRL.MCEO) enables the corresponding output event. Writing a zero to this bit disables the corresponding output event. To enable one of the following event actions, write to the Event Action bit group (EVCTRL.EVACT). z Start the counter z Retrigger counter z Increment or decrement counter (depends on counter direction) z Capture event z Capture period z Capture pulse width Writing a one to the TC Event Input bit in the Event Control register (EVCTRL.TCEI) enables input events to the TC. Writing a zero to this bit disables input events to the TC. Refer to “EVSYS – Event System” on page 314 for details on configuring the Event System. 28.6.6 Sleep Mode Operation The TC can be configured to operate in any sleep mode. To be able to run in standby, the RUNSTDBY bit in the Control A register (CTRLA.RUNSTDBY) must be written to one. The TC can wake up the device using interrupts from any sleep mode or perform actions through the Event System. 28.6.7 Synchronization Due to the asynchronicity between CLK_TCx_APB and GCLK_TCx some registers must be synchronized when accessed. A register can require: z Synchronization when written z Synchronization when read z Synchronization when written and read z No synchronization When executing an operation that requires synchronization, the Synchronization Busy bit in the Status register(STATUS.SYNCBUSY) will be set immediately, and cleared when synchronization is complete. The synchronization Ready interrupt can be used to signal when sync is complete. This can be accessed via the Synchronization Ready Interrupt Flag in the Interrupt Flag Status and Clear register (INTFLAG.SYNCRDY). If an operation that requires synchronization is executed while STATUS.SYNCBUSY is one, the bus will be stalled. All operations will complete successfully, but the CPU will be stalled and interrupts will be pending as long as the bus is stalled. The following bits need synchronization when written: z Software Reset bit in the Control A register (CTRLA.SWRST) z Enable bit in the Control A register (CTRLA.ENABLE) Write-synchronization is denoted by the Write-Synchronized property in the register description. The following registers need synchronization when written: z Control B Clear register (CTRLBCLR) z Control B Set register (CTRLBSET) Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 452 z Control C register (CTRLC) z Count Value register (COUNT) z Period Value register (PERIOD) z Compare/Capture Value registers (CCx) Write-synchronization is denoted by the Write-Synchronized property in the register description. The following registers need synchronization when read: z Control B Clear register (CTRLBCLR) z Control B Set register (CTRLBSET) z Control C register (CTRLC) z Count Value register (COUNT) z Period Value register (PERIOD) z Compare/Capture Value registers (CCx) Read-synchronization is denoted by the Read-Synchronized property in the register description. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 453 28.7 Register Summary Table 28-1. Register Summary – 8-Bit Mode Registers Offset Name 0x00 Bit Pos. 7:0 WAVEGEN[1:0] MODE[1:0] ENABLE SWRST CTRLA 0x01 PRESCSYNC[1:0] 15:8 0x02 RUNSTDBY PRESCALER[2:0] ADDR[4:0] 7:0 READREQ 0x03 15:8 RREQ RCONT 0x04 CTRLBCLR 7:0 CMD[1:0] ONESHOT DIR 0x05 CTRLBSET 7:0 CMD[1:0] ONESHOT DIR 0x06 CTRLC 7:0 0x07 Reserved 0x08 DBGCTRL 0x09 Reserved 0x0A CPTEN1 CPTEN0 INVEN1 7:0 INVEN0 DBGRUN 7:0 TCEI TCINV EVACT[2:0] 15:8 MCEO1 MCEO0 EVCTRL 0x0B OVFEO 0x0C INTENCLR 7:0 MC1 MC0 SYNCRDY ERR OVF 0x0D INTENSET 7:0 MC1 MC0 SYNCRDY ERR OVF 0x0E INTFLAG 7:0 MC1 MC0 SYNCRDY ERR OVF 0x0F STATUS 7:0 SLAVE STOP 0x10 COUNT 7:0 COUNT[7:0] 0x11 Reserved 0x12 Reserved 0x13 Reserved 0x14 PER 7:0 PER[7:0] 0x15 Reserved 0x16 Reserved 0x17 Reserved 0x18 CC0 7:0 CC[7:0] 0x19 CC1 7:0 CC[7:0] 0x1A Reserved 0x1B Reserved 0x1C Reserved 0x1D Reserved 0x1E Reserved 0x1F Reserved SYNCBUSY Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 454 Table 28-2. Register Summary – 16-Bit Mode Registers Offset Name 0x00 Bit Pos. 7:0 WAVEGEN[1:0] MODE[1:0] ENABLE SWRST CTRLA 0x01 PRESCSYNC[1:0] 15:8 0x02 RUNSTDBY PRESCALER[2:0] ADDR[4:0] 7:0 READREQ 0x03 15:8 RREQ RCONT 0x04 CTRLBCLR 7:0 CMD[1:0] ONESHOT DIR 0x05 CTRLBSET 7:0 CMD[1:0] ONESHOT DIR 0x06 CTRLC 7:0 0x07 Reserved 0x08 DBGCTRL 0x09 Reserved 0x0A CPTEN1 CPTEN0 INVEN1 7:0 INVEN0 DBGRUN 7:0 TCEI TCINV EVACT[2:0] 15:8 MCEO1 MCEO0 EVCTRL 0x0B OVFEO 0x0C INTENCLR 7:0 MC1 MC0 SYNCRDY ERR OVF 0x0D INTENSET 7:0 MC1 MC0 SYNCRDY ERR OVF 0x0E INTFLAG 7:0 MC1 MC0 SYNCRDY ERR OVF 0x0F STATUS 7:0 SLAVE STOP 0x10 SYNCBUSY 7:0 COUNT[7:0] 15:8 COUNT[15:8] 7:0 CC[7:0] 15:8 CC[15:8] 7:0 CC[7:0] 15:8 CC[15:8] COUNT 0x11 0x12 Reserved 0x13 Reserved 0x14 Reserved 0x15 Reserved 0x16 Reserved 0x17 Reserved 0x18 CC0 0x19 0x1A CC1 0x1B 0x1C Reserved 0x1D Reserved 0x1E Reserved 0x1F Reserved Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 455 Table 28-3. Register Summary – 32-Bit Mode Registers Offset Name 0x00 Bit Pos. 7:0 WAVEGEN[1:0] MODE[1:0] ENABLE SWRST CTRLA 0x01 PRESCSYNC[1:0] 15:8 0x02 RUNSTDBY PRESCALER[2:0] ADDR[4:0] 7:0 READREQ 0x03 15:8 RREQ RCONT 0x04 CTRLBCLR 7:0 CMD[1:0] ONESHOT DIR 0x05 CTRLBSET 7:0 CMD[1:0] ONESHOT DIR 0x06 CTRLC 7:0 0x07 Reserved 0x08 DBGCTRL 0x09 Reserved 0x0A CPTEN1 CPTEN0 INVEN1 7:0 INVEN0 DBGRUN 7:0 TCEI TCINV EVACT[2:0] 15:8 MCEO1 MCEO0 EVCTRL 0x0B OVFEO 0x0C INTENCLR 7:0 MC1 MC0 SYNCRDY ERR OVF 0x0D INTENSET 7:0 MC1 MC0 SYNCRDY ERR OVF 0x0E INTFLAG 7:0 MC1 MC0 SYNCRDY ERR OVF 0x0F STATUS 7:0 SLAVE STOP 0x10 SYNCBUSY 7:0 COUNT[7:0] 15:8 COUNT[15:8] 0x12 23:16 COUNT[23:16] 0x13 31:24 COUNT[31:24] 7:0 CC[7:0] 15:8 CC[15:8] 0x1A 23:16 CC[23:16] 0x1B 31:24 CC[31:24] 0x1C 7:0 CC[7:0] 15:8 CC[15:8] 0x1E 23:16 CC[23:16] 0x1F 31:24 CC[31:24] 0x11 COUNT 0x14 Reserved 0x15 Reserved 0x16 Reserved 0x17 Reserved 0x18 0x19 CC0 0x1D CC1 Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 456 28.8 Register Description Registers can be 8, 16 or 32 bits wide. Atomic 8-, 16- and 32-bit accesses are supported. In addition, the 8-bit quarters and 16-bit halves of a 32-bit register and the 8-bit halves of a 16-bit register can be accessed directly. Some registers are optionally write-protected by the Peripheral Access Controller (PAC). Write-protection is denoted by the Write-Protected property in each individual register description. Please refer to the Register Access Protection section and the PAC chapter for details. Some registers require synchronization when read and/or written. Synchronization is denoted by the Write-Synchronized or Read-Synchronized property in each individual register description. Refer to the Synchronization section for details. Some registers are enable-protected, meaning they can only be written when the TC is disabled. Enable-protection is denoted by the Enable-Protected property in each individual register description. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 457 28.8.1 Control A Name: CTRLA Offset: 0x00 Reset: 0x0000 Property: Write-Protected, Enable-Protected, Write-Synchronized Bit 15 14 13 12 PRESCSYNC[1:0] 11 10 RUNSTDBY 9 8 PRESCALER[2:0] Access R R R/W R/W R/W R/W R/W R/W Reset 0 0 0 0 0 0 0 0 Bit 7 6 5 4 3 2 1 0 ENABLE SWRST WAVEGEN[1:0] MODE[1:0] Access R R/W R/W R R/W R/W R/W R/W Reset 0 0 0 0 0 0 0 0 z Bits 15:14 – 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. These bits will always return zero when read. z Bits 13:12 – PRESCSYNC[1:0]: Prescaler and Counter Synchronization These bits select whether the counter should wrap around on the next GCLK_TCx clock or the next prescaled GCLK_TCx clock. It also makes it possible to reset the prescaler. The options are as shown in Table 28-4. These bits are not synchronized. Table 28-4. Prescaler and Counter Synchronization z Value Name Description 0x0 GCLK Reload or reset the counter on next generic clock 0x1 PRESC Reload or reset the counter on next prescaler clock 0x2 RESYNC Reload or reset the counter on next generic clock. Reset the prescaler counter 0x3 - Reserved Bit 11 – RUNSTDBY: Run in Standby This bit is used to keep the TC running in standby mode: 0: The TC is halted in standby. 1: The TC continues to run in standby. This bit is not synchronized. z Bits 10:8 – PRESCALER[2:0]: Prescaler These bits select the counter prescaler factor, as shown in Table 28-5. These bits are not synchronized. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 458 Table 28-5. Prescaler Value Name Description 0x0 DIV1 Prescaler: GCLK_TC 0x1 DIV2 Prescaler: GCLK_TC/2 0x2 DIV4 Prescaler: GCLK_TC/4 0x3 DIV8 Prescaler: GCLK_TC/8 0x4 DIV16 Prescaler: GCLK_TC/16 0x5 DIV64 Prescaler: GCLK_TC/64 0x6 DIV256 Prescaler: GCLK_TC/256 0x7 DIV1024 Prescaler: GCLK_TC/1024 z 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. This bit will always return zero when read. z Bits 6:5 – WAVEGEN[1:0]: Waveform Generation Operation These bits select the waveform generation operation. They affect the top value, as shown in “Waveform Output Operations” on page 447. It also controls whether frequency or PWM waveform generation should be used. How these modes differ can also be seen from “Waveform Output Operations” on page 447. These bits are not synchronized. Table 28-6. Waveform Generation Operation Value Name Operation Top Value Output Waveform on Match Output Waveform on Wraparound 0x0 NFRQ Normal frequency PER(1)/Max Toggle No action 0x1 MFRQ Match frequency CC0 Toggle No action (1) 0x2 NPWM Normal PWM PER /Max Set Clear 0x3 MPWM Match PWM CC0 Set Clear Note: 1. This depends on the TC mode. In 8-bit mode, the top value is the Period Value register (PER). In 16- and 32-bit mode it is the maximum value. z Bit 4 – 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. This bit will always return zero when read. z Bits 3:2 – MODE[1:0]: TC Mode These bits select the TC mode, as shown in Table 28-7. These bits are not synchronized. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 459 Table 28-7. TC Mode Value Name Description 0x0 COUNT16 Counter in 16-bit mode 0x1 COUNT8 Counter in 8-bit mode 0x2 COUNT32 Counter in 32-bit mode 0x3 - Reserved z Bit 1 – ENABLE: Enable 0: The peripheral is disabled. 1: The peripheral is enabled. Due to synchronization, there is delay from writing CTRLA.ENABLE until the peripheral is enabled/disabled. The value written to CTRLA.ENABLE will read back immediately, and the Synchronization Busy bit in the Status register (STATUS.SYNCBUSY) will be set. STATUS.SYNCBUSY will be cleared when the operation is complete. z Bit 0 – SWRST: Software Reset 0: There is no reset operation ongoing. 1: The reset operation is ongoing. Writing a zero to this bit has no effect. Writing a one to this bit resets all registers in the TC, except DBGCTRL, to their initial state, and the TC will be disabled. Writing a one to CTRLA.SWRST will always take precedence; all other writes in the same write-operation will be discarded. Due to synchronization there is a delay from writing CTRLA.SWRST until the reset is complete. CTRLA.SWRST and STATUS.SYNCBUSY will both be cleared when the reset is complete. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 460 28.8.2 Read Request For a detailed description of this register and its use, refer to the“Synchronization” on page 452. Name: READREQ Offset: 0x02 Reset: 0x0000 Property: - Bit 15 14 13 12 11 10 9 8 RREQ RCONT Access W R/W R R R R R R Reset 0 0 0 0 0 0 0 0 Bit 7 6 5 4 3 2 1 0 ADDR[4:0] Access R R R R/W R/W R/W R/W R/W Reset 0 0 0 0 0 0 0 0 z Bit 15 – RREQ: Read Request Writing a zero to this bit has no effect. This bit will always read as zero. Writing a one to this bit requests synchronization of the register pointed to by the Address bit group (READREQ.ADDR) and sets the Synchronization Busy bit in the Status register (STATUS.SYNCBUSY). z Bit 14 – RCONT: Read Continuously 0: Continuous synchronization is disabled. 1: Continuous synchronization is enabled. When continuous synchronization is enabled, the register pointed to by the Address bit group (READREQ.ADDR) will be synchronized automatically every time the register is updated. z Bits 13: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. These bits will always return zero when read. z Bits 4:0 – ADDR[4:0]: Address These bits select the offset of the register that needs read synchronization. In the TC, only COUNT and CCx are available for read synchronization. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 461 28.8.3 Control B Clear This register allows the user to change this register without doing a read-modify-write operation. Changes in this register will also be reflected in the Control B Set (CTRLBSET) register. Name: CTRLBCLR Offset: 0x04 Reset: 0x00 Property: Write-Protected, Write-Synchronized, Read-Synchronized Bit 7 6 5 4 3 2 CMD[1:0] Access ONESHOT 0 DIR R/W R/W R R R R/W R R/W 0 0 0 0 0 0 0 0 Reset z 1 Bits 7:6 – CMD[1:0]: Command These bits are used for software control of retriggering and stopping the TC. When a command has been executed, the CMD bit group will read back as zero. The commands are executed on the next prescaled GCLK_TC clock cycle. Writing a zero to one of these bits has no effect. Writing a one to one of these bits will clear the pending command. Table 28-8. Command Value Name Description 0x0 NONE No action 0x1 RETRIGGER Force a start, restart or retrigger 0x2 STOP Force a stop 0x3 - Reserved z Bits 5:3 – 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. These bits will always return zero when read. z Bit 2 – ONESHOT: One-Shot This bit controls one-shot operation of the TC. When in one-shot mode, the TC will stop counting on the next overflow/underflow condition or a stop command. 0: The TC will wrap around and continue counting on an overflow/underflow condition. 1: The TC will wrap around and stop on the next underflow/overflow condition. Writing a zero to this bit has no effect Writing a one to this bit will disable one-shot operation. z Bit 1 – 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. This bit will always return zero when read. z Bit 0 – DIR: Counter Direction This bit is used to change the direction of the counter. 0: The timer/counter is counting up (incrementing). Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 462 1: The timer/counter is counting down (decrementing). Writing a zero to this bit has no effect. Writing a one to this bit will make the counter count up. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 463 28.8.4 Control B Set This register allows the user to change this register without doing a read-modify-write operation. Changes in this register will also be reflected in the Control B Set (CTRLBCLR) register. Name: CTRLBSET Offset: 0x05 Reset: 0x00 Property: Write-Protected, Write-Synchronized, Read-Synchronized Bit 7 6 5 4 3 CMD[1:0] Access 1 ONESHOT 0 DIR R/W R/W R R R R/W R R/W 0 0 0 0 0 0 0 0 Reset z 2 Bits 7:6 – CMD[1:0]: Command These bits is used for software control of retriggering and stopping the TC. When a command has been executed, the CMD bit group will be read back as zero. The commands are executed on the next prescaled GCLK_TC clock cycle. Writing a zero to one of these bits has no effect. Writing a one to one of these bits will set a command. Table 28-9. Command Value Name Description 0x0 NONE No action 0x1 RETRIGGER Force a start, restart or retrigger 0x2 STOP Force a stop 0x3 - Reserved z Bits 5:3 – 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. These bits will always return zero when read. z Bit 2 – ONESHOT: One-Shot This bit controls one-shot operation of the TC. When active, the TC will stop counting on the next overflow/underflow condition or a stop command. 0: The TC will wrap around and continue counting on an overflow/underflow condition. 1: The timer/counter will wrap around and stop on the next underflow/overflow condition. Writing a zero to this bit has no effect. Writing a one to this bit will enable one-shot operation. z Bit 1 – 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. This bit will always return zero when read. z Bit 0 – DIR: Counter Direction This bit is used to change the direction of the counter. 0: The timer/counter is counting up (incrementing). Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 464 1: The timer/counter is counting down (decrementing). Writing a zero to this bit has no effect Writing a one to this bit will make the counter count down. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 465 28.8.5 Control C Name: CTRLC Offset: 0x06 Reset: 0x00 Property: Write-Protected, Write-Synchronized, Read-Synchronized Bit 7 6 5 4 CPTEN1 CPTEN0 3 2 1 0 INVEN1 INVEN0 Access R R R/W R/W R R R/W R/W Reset 0 0 0 0 0 0 0 0 z Bits 7:6 – 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. These bits will always return zero when read. z Bits 5:4 – CPTENx: Capture Channel x Enable These bits are used to select whether channel x is a capture or a compare channel. Writing a one to CPTENx enables capture on channel x. Writing a zero to CPTENx disables capture on channel x. z Bits 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. These bits will always return zero when read. z Bits 1:0 – INVENx: Output Waveform x Invert Enable These bits are used to select inversion on the output of channel x. Writing a one to INVENx inverts the output from WO[x]. Writing a zero to INVENx disables inversion of the output from WO[x]. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 466 28.8.6 Debug Control Name: DBGCTRL Offset: 0x08 Reset: 0x00 Property: Write-Protected Bit 7 6 5 4 3 2 1 0 DBGRUN Access R R R R R R R R/W Reset 0 0 0 0 0 0 0 0 z Bits 7:1 – 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. These bits will always return zero when read. z Bit 0 – DBGRUN: Debug Run Mode This bit is not affected by a software reset, and should not be changed by software while the TC is enabled. 0: The TC is halted when the device is halted in debug mode. 1: The TC continues normal operation when the device is halted in debug mode. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 467 28.8.7 Event Control Name: EVCTRL Offset: 0x0A Reset: 0x0000 Property: Write-Protected, Enable-Protected Bit 15 14 13 12 MCEO1 MCEO0 11 10 9 8 OVFEO Access R R R/W R/W R R R R/W Reset 0 0 0 0 0 0 0 0 Bit 7 6 5 4 3 2 1 0 TCEI TCINV EVACT[2:0] Access R R R/W R/W R R/W R/W R/W Reset 0 0 0 0 0 0 0 0 z Bits 15:14 – 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. These bits will always return zero when read. z Bits 13:12 – MCEOx: Match or Capture Channel x Event Output Enable These bits control whether event match or capture on channel x is enabled or not and generated for every match or capture. 0: Match/Capture event on channel x is disabled and will not be generated. 1: Match/Capture event on channel x is enabled and will be generated for every compare/capture. These bits are not enable-protected. z Bits 11:9 – 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. These bits will always return zero when read. z Bit 8 – OVFEO: Overflow/Underflow Event Output Enable This bit is used to enable the Overflow/Underflow event. When enabled an event will be generated when the counter overflows/underflows. 0: Overflow/Underflow event is disabled and will not be generated. 1: Overflow/Underflow event is enabled and will be generated for every counter overflow/underflow. This bit is not enable-protected. z Bits 7:6 – 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. These bits will always return zero when read. z Bit 5 – TCEI: TC Event Input This bit is used to enable input events to the TC. 0: Incoming events are disabled. 1: Incoming events are enabled. This bit is not enable-protected. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 468 z Bit 4 – TCINV: TC Inverted Event Input This bit inverts the input event source when used in PWP or PPW measurement. 0: Input event source is not inverted. 1: Input event source is inverted. This bit is not enable-protected. z 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. This bit will always return zero when read. z Bits 2:0 – EVACT[2:0]: Event Action These bits define the event action the TC will perform on an event,as shown in Table 28-10. Table 28-10. Event Action Value Name Description 0x0 Off Event action disabled 0x1 Retrigger Start, restart or retrigger TC on event 0x2 Count Count on event 0x3 Start Start TC on event 0x4 - Reserved 0x5 PPW Period captured in CC0, pulse width in CC1 0x6 PWP Period captured in CC1, pulse width in CC0 0x7 - Reserved Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 469 28.8.8 Interrupt Enable Clear This register allows the user to enable an interrupt without doing a read-modify-write operation. Changes in this register will also be reflected in the Interrupt Enable Set register (INTENSET). Name: INTENCLR Offset: 0x0C Reset: 0x00 Property: Write-Protected Bit 7 6 5 4 3 MC1 MC0 SYNCRDY 2 1 0 ERR OVF Access R R/W R/W R/W R/W R R/W R/W Reset 0 0 0 0 0 0 0 0 z Bits 7:6 – 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. These bits will always return zero when read. z Bits 5:4 – MCx: Match or Capture Channel x Interrupt Enable 0: The Match or Capture Channel x interrupt is disabled. 1: The Match or Capture Channel x interrupt is enabled. Writing a zero to MCx has no effect. Writing a one to MCx will clear the corresponding Match or Capture Channel x Interrupt Disable/Enable bit, which disables the Match or Capture Channel x interrupt. z Bit 3 – SYNCRDY: Synchronization Ready Interrupt Enable 0: The Synchronization Ready interrupt is disabled. 1: The synchronization ready interrupt is enabled. Writing a zero to this bit has no effect. Writing a one to this bit will clear the Synchronization Ready Interrupt Disable/Enable bit, which disables the Synchronization Ready interrupt. z Bit 2 – 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. This bit will always return zero when read. z Bit 1 – ERR: Error Interrupt Enable 0: The Error interrupt is disabled. 1: The Error interrupt is enabled. Writing a zero to this bit has no effect. Writing a one to this bit will clear the Error Interrupt Disable/Enable bit, which disables the Compare interrupt. z Bit 0 – OVF: Overflow Interrupt Enable 0: The Overflow interrupt is disabled. 1: The Overflow interrupt is enabled. Writing a zero to this bit has no effect. Writing a one to this bit will clear the Overflow Interrupt Disable/Enable bit, which disables the Overflow interrupt. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 470 28.8.9 Interrupt Enable Set This register allows the user to enable an interrupt without doing a read-modify-write operation. Changes in this register will also be reflected in the Interrupt Enable Clear register (INTENCLR). Name: INTENSET Offset: 0x0D Reset: 0x00 Property: Write-Protected Bit 7 6 5 4 3 MC1 MC0 SYNCRDY 2 1 0 ERR OVF Access R R R/W R/W R/W R R/W R/W Reset 0 0 0 0 0 0 0 0 z Bits 7:6 – 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. These bits will always return zero when read. z Bits 5:4 – MCx: Match or Capture Channel x Interrupt Enable 0: The Match or Capture Channel x interrupt is disabled. 1: The Match or Capture Channel x interrupt is enabled. Writing a zero to MCx has no effect. Writing a one to MCx will set the corresponding Match or Capture Channel x Interrupt Enable bit, which enables the Match or Capture Channel x interrupt. z Bit 3 – SYNCRDY: Synchronization Ready Interrupt Enable 0: The Synchronization Ready interrupt is disabled. 1: The Synchronization Ready interrupt is enabled. Writing a zero to this bit has no effect. Writing a one to this bit will set the Synchronization Ready Interrupt Disable/Enable bit, which enables the Synchronization Ready interrupt. z Bit 2 – 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. This bit will always return zero when read. z Bit 1 – ERR: Error Interrupt Enable 0: The Error interrupt is disabled. 1: The Error interrupt is enabled. Writing a zero to this bit has no effect. Writing a one to this bit will set the Error Interrupt bit, which enables the Error interrupt. z Bit 0 – OVF: Overflow Interrupt Enable 0: The Overflow interrupt is disabled. 1: The Overflow interrupt is enabled. Writing a zero to this bit has no effect. Writing a one to this bit will set the Overflow Interrupt Enable bit, which enables the Overflow interrupt. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 471 28.8.10 Interrupt Flag Status and Clear Name: INTFLAG Offset: 0x0E Reset: 0x00 Property: Property: - Bit 7 6 5 4 3 MC1 MC0 SYNCRDY 2 1 0 ERR OVF Access R R R/W R/W R/W R R/W R/W Reset 0 0 0 0 0 0 0 0 z Bits 7:6 – 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. These bits will always return zero when read. z Bits 5:4 – MCx: Match or Capture Channel x This flag is set on the next CLK_TC_CNT cycle after a match with the compare condition or once CCx register contain a valid capture value, and will generate an interrupt request if the corresponding Match or Capture Channel x Interrupt Enable bit in the Interrupt Enable Set register (INTENSET.MCx) is one. Writing a zero to one of these bits has no effect. Writing a one to one of these bits will clear the corresponding Match or Capture Channel x interrupt flag In capture mode, this flag is automatically cleared on the read of the CCx register by the CPU. z Bit 3 – SYNCRDY: Synchronization Ready This flag is set on a 1-to-0 transition of the Synchronization Busy bit in the Status register (STATUS.SYNCBUSY), except when the transition is caused by an enable or software reset, and will generate an interrupt request if the Synchronization Ready Interrupt Enable bit in the Interrupt Enable Set register (INTENSET.SYNCRDY) is one. Writing a zero to this bit has no effect. Writing a one to this bit will clear the Synchronization Ready interrupt flag z Bit 2 – 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. This bit will always return zero when read. z Bit 1 – ERR: Error This flag is set if a new capture occurs on a channel when the corresponding Match or Capture Channel x interrupt flag is one, in which case there is nowhere to store the new capture. Writing a zero to this bit has no effect. Writing a one to this bit clears the Error interrupt flag. z Bit 0 – OVF: Overflow This flag is set on the next CLK_TC_CNT cycle after an overflow condition occurs, and will generate an interrupt if INTENCLR/SET.OVF is one. Writing a zero to this bit has no effect. Writing a one to this bit clears the Overflow interrupt flag. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 472 28.8.11 Status Name: STATUS Offset: 0x0F Reset: 0x08 Property: Property: - Bit 7 6 5 SYNCBUSY 4 3 SLAVE STOP 2 1 0 Access R R R R R R R R Reset 0 0 0 0 1 0 0 0 z Bit 7 – SYNCBUSY: Synchronization Busy This bit is cleared when the synchronization of registers between the clock domains is complete. This bit is set when the synchronization of registers between clock domains is started. z Bits 6: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. These bits will always return zero when read. z Bit 4 – SLAVE: Slave This bit is set when the even-numbered master TC is set to run in 32-bit mode. The odd-numbered TC will be the slave. z Bit 3 – STOP: Stop This bit is set when the TC is disabled, on a Stop command or on an overflow or underflow condition when the One-Shot bit in the Control B Set register (CTRLBSET.ONESHOT) is one. 0: Counter is running. 1: Counter is stopped. z Bits 2:0 – 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. These bits will always return zero when read. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 473 28.8.12 Counter Value 28.8.12.1 8-Bit Mode Name: COUNT Offset: 0x10 Reset: 0x00 Property: Write-Synchronized, Read-Synchronized Bit 7 6 5 4 3 2 1 0 COUNT[7:0] Access Reset z R/W R/W R/W R/W R/W R/W R/W R/W 0 0 0 0 0 0 0 0 Bits 7:0 – COUNT[7:0]: Counter Value These bits contain the current counter value. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 474 28.8.12.2 16-Bit Mode Name: COUNT Offset: 0x10 Reset: 0x0000 Property: Write-Synchronized, Read-Synchronized Bit 15 14 13 12 11 10 9 8 COUNT[15:8] Access R/W R/W R/W R/W R/W R/W R/W R/W Reset 0 0 0 0 0 0 0 0 Bit 7 6 5 4 3 2 1 0 COUNT[7:0] Access Reset z R/W R/W R/W R/W R/W R/W R/W R/W 0 0 0 0 0 0 0 0 Bits 15:0 – COUNT[15:0]: Counter Value These bits contain the current counter value. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 475 28.8.12.3 32-Bit Mode Name: COUNT Offset: 0x10 Reset: 0x00000000 Property: Write-Synchronized, Read-Synchronized Bit 31 30 29 28 27 26 25 24 COUNT[31:24] Access R/W R/W R/W R/W R/W R/W R/W R/W Reset 0 0 0 0 0 0 0 0 Bit 15 14 13 12 11 10 9 8 COUNT[15:8] Access Reset Bit R/W R/W R/W R/W R/W R/W R/W R/W 0 0 0 0 0 0 0 0 23 22 21 20 19 18 17 16 COUNT[23:16] Access R/W R/W R/W R/W R/W R/W R/W R/W Reset 0 0 0 0 0 0 0 0 Bit 7 6 5 4 3 2 1 0 COUNT[7:0] Access Reset z R/W R/W R/W R/W R/W R/W R/W R/W 0 0 0 0 0 0 0 0 Bits 31:0 – COUNT[31:0]: Counter Value These bits contain the current counter value. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 476 28.8.13 Period Value The Period Value register is available only in 8-bit TC mode. It is not available in 16-bit and 32-bit TC modes. 28.8.13.1 8-Bit Mode Name: PER Offset: 0x14 Reset: 0xFF Property: Write-Synchronized, Read-Synchronized Bit 7 6 5 4 3 2 1 0 PER[7:0] Access Reset z R/W R/W R/W R/W R/W R/W R/W R/W 1 1 1 1 1 1 1 1 Bits 7:0 – PER[7:0]: Period Value These bits contain the counter period value in 8-bitTC mode. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 477 28.8.14 Compare/Capture 28.8.14.1 8-Bit Mode Name: CCx Offset: 0x18+i*0x1 [i=0..3] Reset: 0x00 Property: Write-Synchronized, Read-Synchronized Bit 7 6 5 4 3 2 1 0 CC[7:0] Access Reset z R/W R/W R/W R/W R/W R/W R/W R/W 0 0 0 0 0 0 0 0 Bits 7:0 – CC[7:0]: Compare/Capture Value These bits contain the compare/capture value in 8-bit TC mode. In frequency or PWM waveform match operation (CTRLA.WAVEGEN), the CC0 register is used as a period register. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 478 28.8.14.2 16-Bit Mode Name: CCx Offset: 0x18+i*0x2 [i=0..3] Reset: 0x0000 Property: Write-Synchronized, Read-Synchronized Bit 15 14 13 12 11 10 9 8 CC[15:8] Access R/W R/W R/W R/W R/W R/W R/W R/W Reset 0 0 0 0 0 0 0 0 Bit 7 6 5 4 3 2 1 0 CC[7:0] Access Reset z R/W R/W R/W R/W R/W R/W R/W R/W 0 0 0 0 0 0 0 0 Bits 15:0 – CC[15:0]: Compare/Capture Value These bits contain the compare/capture value in 16-bit TC mode. In frequency or PWM waveform match operation (CTRLA.WAVEGEN), the CC0 register is used as a period register. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 479 28.8.14.3 32-Bit Mode Name: CCx Offset: 0x18+i*0x4 [i=0..3] Reset: 0x00000000 Property: Write-Synchronized, Read-Synchronized Bit 31 30 29 28 27 26 25 24 CC[31:24] Access Reset Bit R/W R/W R/W R/W R/W R/W R/W R/W 0 0 0 0 0 0 0 0 23 22 21 20 19 18 17 16 CC[23:16] Access R/W R/W R/W R/W R/W R/W R/W R/W Reset 0 0 0 0 0 0 0 0 Bit 15 14 13 12 11 10 9 8 CC[15:8] Access R/W R/W R/W R/W R/W R/W R/W R/W Reset 0 0 0 0 0 0 0 0 Bit 7 6 5 4 3 2 1 0 CC[7:0] Access Reset z R/W R/W R/W R/W R/W R/W R/W R/W 0 0 0 0 0 0 0 0 Bits 31:0 – CC[31:0]: Compare/Capture Value These bits contain the compare/capture value in 32-bit TC mode. In frequency or PWM waveform match operation (CTRLA.WAVEGEN), the CC0 register is used as a period register. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 480 29. 29.1 ADC – Analog-to-Digital Converter Overview The Analog-to-Digital Converter (ADC) converts analog signals to digital values. The ADC has 12-bit resolution, and is capable of converting up to 350ksps. The input selection is flexible, and both differential and single-ended measurements can be performed. 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. ADC measurements can be started by either application software or an incoming event from another peripheral in the device. ADC measurements can be started with predictable timing, and without software intervention. Both internal and external reference voltages can be used. An integrated temperature sensor is available for use with the ADC. The bandgap voltage as well as the scaled I/O and core voltages 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. The ADC may be configured for 8-, 10- or 12-bit results, reducing the conversion time. ADC conversion results are provided left- or right-adjusted, which eases calculation when the result is represented as a signed value. 29.2 Features z 8-, 10- or 12-bit resolution z Up to 350,000 samples per second (ksps) z Differential and single-ended inputs z Up to 32 analog inputs z 25 positive and 10 negative, including internal and external z Five internal inputs z Bandgap Temperature sensor z DAC z Scaled core supply z Scaled I/O supply z z 1/2x to 16x gain z Single, continuous and pin-scan conversion options z Windowing monitor with selectable channel z Conversion range: z z Vref [1v to VDDANA -0.6V] ADCx * GAIN [0V to -Vref ] z Built-in internal reference and external reference options z Four bits for reference selection Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 481 z Event-triggered conversion for accurate timing (one event input) z Hardware gain and offset compensation z Averaging and oversampling with decimation to support, up to 16-bit result z Selectable sampling time 29.3 Block Diagram Figure 29-1. ADC Block Diagram CTRLA WINCTRL AVGCTRL WINLT SAMPCTRL WINUT EVCTRL OFFSETCORR SWTRIG GAINCORR INPUTCTRL ADC0 ... ADCn INT.SIG ADC POST PROCESSING RESULT ADC0 ... ADCn INT.SIG INT1V CTRLB INTVCC AREFA AREFB PRESCALER REFCTRL 29.4 Signal Description Signal Name Type Description AREFA Analog input External reference voltage A Analog input External reference voltage B Analog input Analog input channels AREFB ADC[19..0] Note: 1. (1) Refer to “Configuration Summary” on page 3 for details on exact number of analog input channels. Refer to “I/O Multiplexing and Considerations” on page 15 for details on the pin mapping for this peripheral. One signal can be mapped on several pins. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 482 29.5 Product Dependencies In order to use this peripheral, other parts of the system must be configured correctly, as described below. 29.5.1 I/O Lines Using the ADC's I/O lines requires the I/O pins to be configured using the port configuration (PORT). Refer to “PORT” on page 289 for details. 29.5.2 Power Management The ADC will continue to operate in any sleep mode where the selected source clock is running. The ADC’s interrupts can be used to wake up the device from sleep modes. The events can trigger other operations in the system without exiting the sleep modes. Refer to “PM – Power Manager” on page 105 for details on the different sleep modes. 29.5.3 Clocks The ADC bus clock (CLK_ADC_APB) can be enabled and disabled in the Power Manager, and the default state of CLK_ADC_APB can be found in the Table 16-1. A generic clock (GCLK_ADC) is required to clock the ADC. This clock must be configured and enabled in the Generic Clock Controller (GCLK) before using the ADC. Refer “GCLK – Generic Clock Controller” on page 83 for details. This generic clock is asynchronous to the bus clock (CLK_ADC_APB). Due to this asynchronicity, writes to certain registers will require synchronization between the clock domains. Refer to “Synchronization” on page 491 for further details. 29.5.4 DMA Not applicable. 29.5.5 Interrupts The interrupt request line is connected to the interrupt controller. Using ADC interrupts requires the interrupt controller to be configured first. Refer to “Nested Vector Interrupt Controller” on page 28 for details. 29.5.6 Events Events are connected to the Event System. Refer to “EVSYS – Event System” on page 314 for details. 29.5.7 Debug Operation When the CPU is halted in debug mode, the ADC will halt normal operation. The ADC can be forced to continue operation during debugging. Refer to the Debug Control register (DBGCTRL) for details. 29.5.8 Register Access Protection All registers with write-access are optionally write-protected by the Peripheral Access Controller (PAC), except the following register: z Interrupt Flag Status and Clear register (INTFLAG) Write-protection is denoted by the Write-Protection property in the register description. When the CPU is halted in debug mode or the CPU reset is extended, all write-protection is automatically disabled. Write-protection does not apply for accesses through an external debugger. Refer to “PAC – Peripheral Access Controller” on page 31 for details. 29.5.9 Analog Connections I/O-pins AIN0 to AIN15 as well as the AREFA/AREFB reference voltage pin are analog inputs to the ADC. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 483 29.5.10 Calibration The values BIAS_CAL and LINEARITY_CAL from the production test must be loaded from the NVM Software Calibration Row into the ADC Calibration register (CALIB) by software to achieve specified accuracy. The gain and offset correction values from the production test can be loaded from the Software Calibration Row into the GAINCORR and OFFSETCORR registers by software to achieve specified accuracy. Refer to “NVM Software Calibration Row Mapping” on page 26 for more details. 29.6 Functional Description 29.6.1 Principle of Operation By default, the ADC provides results with 12-bit resolution. 8-bit or 10-bit results can be selected in order to reduce the conversion time. The ADC has an oversampling with decimation option that can extend the resolution to 16 bits. The input values can be either internal (e.g., internal temperature sensor) or external (connected I/O pins). The user can also configure whether the conversion should be single-ended or differential. 29.6.2 Basic Operation 29.6.2.1 Initialization Before enabling the ADC, the asynchronous clock source must be selected and enabled, and the ADC reference must be configured. The first conversion after the reference is changed must not be used. All other configuration registers must be stable during the conversion. The source for GCLK_ADC is selected and enabled in the System Controller (SYSCTRL). Refer to “SYSCTRL – System Controller” on page 132 for more details. When GCLK_ADC is enabled, the ADC can be enabled by writing a one to the Enable bit in the Control Register A (CTRLA.ENABLE). 29.6.2.2 Enabling, Disabling and Reset The ADC is enabled by writing a one to the Enable bit in the Control A register (CTRLA.ENABLE). The ADC is disabled by writing a zero to CTRLA.ENABLE. The ADC is reset by writing a one to the Software Reset bit in the Control A register (CTRLA.SWRST). All registers in the ADC, except DBGCTRL, will be reset to their initial state, and the ADC will be disabled. Refer to the CTRLA register for details. The ADC must be disabled before it is reset. 29.6.2.3 Basic Operation In the most basic configuration, the ADC sample values from the configured internal or external sources (INPUTCTRL register). The rate of the conversion is dependent on the combination of the GCLK_ADC frequency and the clock prescaler. To convert analog values to digital values, the ADC needs first to be initialized, as described in “Initialization” on page 484. Data conversion can started either manually, by writing a one to the Start bit in the Software Trigger register (SWTRIG.START), or automatically, by configuring an automatic trigger to initiate the conversions. A free-running mode could be used to continuously convert an input channel. There is no need for a trigger to start the conversion. It will start automatically at the end of previous conversion. The automatic trigger can be configured to trigger on many different conditions. The result of the conversion is stored in the Result register (RESULT) as it becomes available, overwriting the result from the previous conversion. To avoid data loss if more than one channel is enabled, the conversion result must be read as it becomes available (INTFLAG.RESRDY). Failing to do so will result in an overrun error condition, indicated by the OVERRUN bit in the Interrupt Flag Status and Clear register (INTFLAG.OVERRUN). Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 484 To use an interrupt handler, the corresponding bit in the Interrupt Enable Set register (INTENSET) must be written to one. 29.6.3 Prescaler The ADC is clocked by GCLK_ADC. There is also a prescaler in the ADC to enable conversion at lower clock rates. . Refer to for details on prescaler settings. Figure 29-2. ADC Prescaler DIV512 DIV256 DIV128 DIV64 DIV32 DIV16 DIV8 9-BIT PRESCALER DIV4 GCLK_ADC CTRLB.PRESCALER[2:0] CLK_ADC The propagation delay of an ADC measurement is given by: Resolution 1 + ---------------------------- + DelayGain 2 PropagationDelay = ------------------------------------------------------------------------f ADC Table 29-1. Delay Gain Delay Gain (in CLK_ADC Period) INTPUTCTRL.GAIN[3:0] Differential Mode Single-Ended Mode 0x0 0 0 0x1 0 1 0x2 1 1 0x3 1 2 0x4 2 2 0x5 ... 0xE Reserved Reserved 0xF 0 1 29.6.4 ADC Resolution The ADC supports 8-bit, 10-bit and 12-bit resolutions. Resolution can be changed by writing the Resolution bit group in the Control B register (CTRLB.RESSEL). After a reset, the resolution is set to 12 bits by default. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 485 29.6.5 Differential and Single-Ended Conversions The ADC has two conversion options: differential and single-ended. When measuring signals where the positive input is always at a higher voltage than the negative input, the single-ended conversion should be used in order to have full 12bit resolution in the conversion, which has only positive values. The negative input must be connected to ground. This ground could be the internal GND, IOGND or an external ground connected to a pin. Refer to for selection details. If the positive input may go below the negative input, creating some negative results, the differential mode should be used in order to get correct results. The configuration of the conversion is done in the Differential Mode bit in the Control B register (CTRLB.DIFFMODE). These two types of conversion could be run in single mode or in free-running mode. When set up in free-running mode, an ADC input will continuously sample and do new conversions. The INTFLAG.RESRDY bit will be set at the end of each conversion. 29.6.5.1 Conversion Timing Figure 29-3 shows the ADC timing for a single conversion without gain. The writing of the ADC Start Conversion bit (SWTRIG.START) or Start Conversion Event In bit (EVCTRL.STARTEI) must occur at least one CLK_ADC_APB cycle before the CLK_ADC cycle on which the conversion starts. The input channel is sampled in the first half CLK_ADC period. The sampling time can be increased by using the Sampling Time Length bit group in the Sampling Time Control register (SAMPCTRL.SAMPLEN). Refer to Figure 29-4 for example on increased sampling time. Figure 29-3. ADC Timing for One Conversion in Differential Mode without Gain 1 2 3 4 5 6 7 8 CLK_ ADC START SAMPLE INT Converting Bit MS B 10 9 8 7 6 5 4 3 2 1 LS B Figure 29-4. ADC Timing for One Conversion in Differential Mode without Gain, but with Increased Sampling Time 1 2 3 4 5 6 7 8 9 10 11 CLK_ ADC START SAMPLE INT Converting Bit MS B 10 9 8 7 6 5 4 3 2 1 LS B Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 486 Figure 29-5. ADC Timing for Free Running in Differential Mode without Gain 2 1 3 4 5 6 7 9 8 10 11 12 13 6 4 2 0 14 15 16 8 6 CLK_ ADC START SAMPLE INT Converting Bit 11 10 9 8 7 6 5 4 3 2 1 0 11 10 9 8 7 5 3 1 11 10 9 7 5 Figure 29-6. ADC Timing for One Conversion in Single-Ended Mode without Gain 1 2 3 4 5 6 7 8 9 10 11 CLK_ADC START SAMPLE AMPLIFY INT Converting Bit MS B 10 9 8 7 6 5 4 3 2 1 LS B Figure 29-7. ADC Timing for Free Running in Single-Ended Mode without Gain 2 1 3 4 5 6 7 9 8 10 11 12 13 14 9 7 5 3 1 15 16 CLK_ ADC START SAMPLE AMPLIFY INT Converting Bit 11 10 9 8 7 6 5 4 3 2 1 0 11 10 8 6 4 2 0 11 10 Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 487 29.6.6 Averaging Averaging is a feature that increases the sample accuracy, though at the cost of reduced sample rate. If enabled, the ADC automatically computes an average value of multiple consecutive conversions. This feature is suitable when operating in noisy conditions.The number of samples to be averaged is specified by the Number of Samples to be Collected bit group in the Average Control register (AVGCTRL.SAMPLENUM[3:0]), and the averaged output is available in the Result register (RESULT). Table 29-2 specifies the number of samples that will be accumulated. When averaging by the Number of Samples to be Collected bit group in the Average Control register (AVGCTRL.SAMPLENUM[3:0]), the effective ADC sample rate is reduced by that factor. When the required average is reached, the INTFLAG.RESRDY bit is set. Table 29-2. Averaging AVGCTRL.SAMPLENUM[3:0] Number of Samples Final Result Precision CTRLB.RESSEL[1:0] Factor Reduction 0x0 1 12 bits 0x0 0 0x1 2 13 bits 0x1 0 0x2 4 14 bits 0x1 0 0x3 8 15 bits 0x1 0 0x4 16 16 bits 0x1 0 0x5 32 16 bits 0x1 2 0x6 64 16 bits 0x1 4 0x7 128 16 bits 0x1 8 0x8 256 16 bits 0x1 16 0x9 512 16 bits 0x1 32 0xA 1024 16 bits 0x1 64 0xB –0xF Reserved 12 bits 0x0 0 29.6.7 Oversampling and Decimation In oversampling and decimation, the ADC resolution is increased from 12 bits to the programmed 13, 14, 15 or 16 bits. If the resolution is to be increased by n bits, 4n samples are accumulated, and the result is right shifted by the number of bits specified in the Adjusting Result/Division Coefficient bit group in the Average Control register (AVCTRL.ADJRES[2:0]). This method will result in n-bit extra LSB resolution. Table 29-3. Configuration Required for Oversampling and Decimation Increase Resolution by Number of Samples to Average AVGCTRL.SAMPLENUM[3:0] AVGCTRL.ADJRES[2:0] Final Result Precision 1 bit 41 = 4 0x2 0x1 13 bits 2 2 bits 4 = 16 0x4 0x2 14 bits 3 bits 43 = 64 0x6 0x3 15 bits 4 bits 44 = 256 0x8 0x4 16 bits Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 488 29.6.8 Window Monitor The window monitor allows the conversion result to be compared to some predefined threshold values. Supported modes are selected by writing the Window Monitor Mode bit group in the Window Monitor Control register (WINCTRL.WINMODE[2:0]). Thresholds are given by writing the Window Monitor Lower Threshold register (WINLT) and Window Monitor Upper Threshold register (WINUT). If differential input is selected, the WINLT and WINUT are evaluated as signed values. Otherwise they are evaluated as unsigned values. Another important point is that the significant WINLT and WINUT bits are given by the precision selected in the Conversion Result Resolution bit group in the Control B register (CTRLB.RESSEL). This means that if 8-bit mode is selected, only the eight lower bits will be considered. In addition, in differential mode, the eighth bit will be considered as the sign bit even if the ninth bit is zero. The INTFLAG.WINMON interrupt flag will be set if the conversion result matches the window monitor condition. 29.6.9 Offset and Gain Correction Inherent gain and offset errors affect the absolute accuracy of the ADC. The offset error is defined as the deviation of the actual ADC’s transfer function from an ideal straight line at zero input voltage. The offset error cancellation is handled by the Offset Correction register (OFFSETCORR). The offset correction value is subtracted from the converted data before writing the Result register (RESULT). The gain error is defined as the deviation of the last output step’s midpoint from the ideal straight line, after compensating for offset error. The gain error cancellation is handled by the Gain Correction register (GAINCORR). To correct these two errors, the Digital Correction Logic Enabled bit in the Control B register (CTRLB.CORREN) must be written to one. Offset and gain error compensation results are both calculated according to: Result = ( Conversion value – OFFSETCORR ) ⋅ GAINCORR In single conversion, a latency of 13 GCLK_ADC is added to the availability of the final result. Since the correction time is always less than the propagation delay, this latency appears in free-running mode only during the first conversion. After that, a new conversion will be initialized when a conversion completes. All other conversion results are available at the defined sampling rate. Figure 29-8. ADC Timing Correction Enabled START CONV0 CONV1 CORR0 CONV2 CORR1 CONV3 CORR2 CORR3 Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 489 29.6.10 Additional Features 29.6.10.1 Synchronization Due to the asynchronicity between CLK_ADC_APB and GCLK_ADC, some registers must be synchronized when accessed. A register can require: z Synchronization when written z Synchronization when read z Synchronization when written and read z No synchronization When executing an operation that requires synchronization, the Synchronization Busy bit in the Status register (STATUS.SYNCBUSY) will be set immediately, and cleared when synchronization is complete. The Synchronization Ready interrupt can be used to signal when synchronization is complete. This can be accessed via the Synchronization Ready interrupt flag in the Interrupt Flag Status and Clear register (INTFLAG.SYNCRDY). If an operation that requires synchronization is executed while STATUS.SYNCBUSY is one, the bus will be stalled. All operations will complete successfully, but the CPU will be stalled and interrupts will be pending as long as the bus is stalled. The following bits need synchronization when written: z Software Reset bit in the Control A register (CTRLA.SWRST) z Enable bit in the Control A register (CTRLA.ENABLE) Write-synchronization is denoted by the Write-Synchronized property in the register description. The following bits need synchronization when read: z All bits in the Count register (COUNT) z Prescaler bit in the Control A register (CTRLA.PRESCALER) Read-synchronization is denoted by the Read-Synchronized property in the register description. 29.6.11 Interrupts The ADC has the following interrupt sources: z Result Conversion Ready: RESRDY z Overrun: OVERRUN z Window Monitor: WINMON z Synchronization Ready: SYNCRDY Each interrupt source has an interrupt flag associated with it. The interrupt flag in the Interrupt Flag Status and Clear register (INTFLAG) is set when the interrupt condition occurs. Each interrupt can be individually enabled by writing a one to the corresponding bit in the Interrupt Enable Set register (INTENSET), and disabled by writing a one to the corresponding bit in the Interrupt Enable Clear register (INTENCLR) register. An interrupt request is generated when the interrupt flag is set and the corresponding interrupt is enabled. The interrupt request remains active until the interrupt flag is cleared, the interrupt is disabled or the peripheral is reset. An interrupt flag is cleared by writing a one to the corresponding bit in the INTFLAG register. Each peripheral can have one interrupt request line per interrupt source or one common interrupt request line for all the interrupt sources. This is device dependent. Refer to “Nested Vector Interrupt Controller” on page 28 for details. If the peripheral has one common interrupt request line for all the interrupt sources, the user must read the INTFLAG register to determine which interrupt condition is present. 29.6.12 Events The peripheral can generate the following output events: z Result Ready (RESRDY) Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 490 z Window Monitor (WINMON) Output events must be enabled to be generated. Writing a one to an Event Output bit in the Event Control register (EVCTRL.xxEO) enables the corresponding output event. Writing a zero to this bit disables the corresponding output event. The events must be correctly routed in the Event System. Refer to “EVSYS – Event System” on page 314 for details. The peripheral can take the following actions on an input event: z ADC start conversion (START) z ADC conversion flush (FLUSH) Input events must be enabled for the corresponding action to be taken on any input event. Writing a one to an Event Input bit in the Event Control register (EVCTRL.xxEI) enables the corresponding action on the input event. Writing a zero to this bit disables the corresponding action on the input event. Note that if several events are connected to the peripheral, the enabled action will be taken on any of the incoming events. The events must be correctly routed in the Event System. Refer to “EVSYS – Event System” on page 314 for details. 29.6.13 Sleep Mode Operation The Run in Standby bit in the Control A register (CTRLA.RUNSTDBY) controls the behavior of the ADC during standby sleep mode. When the bit is zero, the ADC is disabled during sleep, but maintains its current configuration. When the bit is one, the ADC continues to operate during sleep. Note that when RUNSTDBY is zero, the analog blocks are powered off for the lowest power consumption. This necessitates a start-up time delay when the system returns from sleep. When RUNSTDBY is one, any enabled ADC interrupt source can wake up the CPU. However, ADC conversion will be triggerable by events only while the CPU is idle. 29.6.14 Synchronization Due to the asynchronicity between CLK_ADC_APB and GCLK_ADC, some registers must be synchronized when accessed. A register can require: z Synchronization when written z Synchronization when read z Synchronization when written and read z No synchronization When executing an operation that requires synchronization, the Synchronization Busy bit in the Status register (STATUS.SYNCBUSY) will be set immediately, and cleared when synchronization is complete. The Synchronization Ready interrupt can be used to signal when synchronization is complete. If an operation that requires synchronization is executed while STATUS.SYNCBUSY is one, the bus will be stalled. All operations will complete successfully, but the CPU will be stalled and interrupts will be pending as long as the bus is stalled. The following bits need synchronization when written: z Software Reset bit in the Control A register (CTRLA.SWRST) z Enable bit in the Control A register (CTRLA.ENABLE) The following registers need synchronization when written: z Control B (CTRLB) z Software Trigger (SWTRIG) z Window Monitor Control (WINCTRL) z Input Control (INPUTCTRL) z Window Upper/Lower Threshold (WINUT/WINLT) Write-synchronization is denoted by the Write-Synchronized property in the register description. The following registers need synchronization when read: Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 491 z Software Trigger (SWTRIG) z Input Control (INPUTCTRL) z Result (RESULT) Read-synchronization is denoted by the Read-Synchronized property in the register description. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 492 29.7 Register Summary Offset Name Bit pos. 0x00 CTRLA 7:0 0x01 REFCTRL 7:0 0x02 AVGCTRL 7:0 0x03 SAMPCTRL 7:0 0x04 RUNSTDBY ENABLE SWRST REFSEL[3:0] REFCOMP ADJRES[2:0] SAMPLENUM[3:0] SAMPLEN[5:0] RESSEL[1:0] 7:0 CORREN FREERUN LEFTADJ DIFFMODE CTRLB 0x05 0x06 Reserved 0x07 Reserved 0x08 WINCTRL 0x09 Reserved 0x0A Reserved 0x0B Reserved 0x0C SWTRIG 0x0D Reserved 0x0E Reserved 0x0F Reserved 0x10 0x11 15:8 PRESCALER[2:0] 7:0 WINMODE[2:0] 7:0 START 7:0 MUXPOS[4:0] 15:8 MUXNEG[4:0] FLUSH INPUTCTRL 0x12 23:16 0x13 31:24 INPUTOFFSET[3:0] INPUTSCAN[3:0] GAIN[3:0] WINMONEO SYNCEI STARTEI WINMON OVERRUN RESRDY SYNCRDY WINMON OVERRUN RESRDY SYNCRDY WINMON OVERRUN RESRDY EVCTRL 0x15 Reserved 0x16 INTENCLR 7:0 SYNCRDY 0x17 INTENSET 7:0 0x18 INTFLAG 7:0 0x19 STATUS 7:0 0x1A 7:0 RESRDYEO 0x14 SYNCBUSY 7:0 RESULT[7:0] 15:8 RESULT[15:8] 7:0 WINLT[7:0] 15:8 WINLT[15:8] 7:0 WINUT[7:0] 15:8 WINUT[15:8] RESULT 0x1B 0x1C WINLT 0x1D 0x1E Reserved 0x1F Reserved 0x20 WINUT 0x21 0x22 Reserved 0x23 Reserved Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 493 Offset Name 0x24 Bit pos. 7:0 GAINCORR[7:0] GAINCORR 0x25 GAINCORR[11:8] 15:8 0x26 7:0 OFFSETCORR[7:0] OFFSETCORR 0x27 OFFSETCORR[11:8] 15:8 0x28 7:0 LINEARITY_CAL[7:0] CALIB 0x29 0x2A 15:8 DBGCTRL 7:0 BIAS_CAL[2:0] DBGRUN Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 494 29.8 Register Description Registers can be 8, 16 or 32 bits wide. Atomic 8-, 16- and 32-bit accesses are supported. In addition, the 8-bit quarters and 16-bit halves of a 32-bit register and the 8-bit halves of a 16-bit register can be accessed directly. Some registers are optionally write-protected by the Peripheral Access Controller (PAC). Write-protection is denoted by the Write-Protected property in each individual register description. Refer to “Register Access Protection” on page 483 for details. Some registers require synchronization when read and/or written. Synchronization is denoted by the Write-Synchronized or the Read-Synchronized property in each individual register description. Refer to “Synchronization” on page 491 for details. Some registers are enable-protected, meaning they can be written only when the ADC is disabled. Enable-protection is denoted by the Enable-Protected property in each individual register description. 29.8.1 Control A Name: CTRLA Offset: 0x00 Reset: 0x00 Property: Write-Protected Bit 7 6 5 4 3 2 1 0 RUNSTDBY ENABLE SWRST Access R R R R R R/W R/W R/W Reset 0 0 0 0 0 0 0 0 z Bits 7:3 – 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. These bits will always return zero when read. z Bit 2 – RUNSTDBY: Run in Standby This bit indicates whether the ADC willcontinue running in standby sleep mode or not: 0: The ADC is halted during standby sleep mode. 1: The ADC continues normal operation during standby sleep mode. z Bit 1 – ENABLE: Enable 0: The ADC is disabled. 1: The ADC is enabled. Due to synchronization, there is a delay from writing CTRLA.ENABLE until the peripheral is enabled/disabled. The value written to CTRL.ENABLE will read back immediately and the Synchronization Busy bit in the Status register (STATUS.SYNCBUSY) will be set. STATUS.SYNCBUSY will be cleared when the operation is complete. z Bit 0 – SWRST: Software Reset 0: There is no reset operation ongoing. 1: The reset operation is ongoing. Writing a zero to this bit has no effect. Writing a one to this bit resets all registers in the ADC, except DBGCTRL, to their initial state, and the ADC will be disabled. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 495 Writing a one to CTRL.SWRST will always take precedence, meaning that all other writes in the same write-operation will be discarded. Due to synchronization, there is a delay from writing CTRLA.SWRST until the reset is complete. CTRLA.SWRST and STATUS.SYNCBUSY will both be cleared when the reset is complete. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 496 29.8.2 Reference Control Name: REFCTRL Offset: 0x01 Reset: 0x00 Property: Write-Protected Bit 7 6 5 4 3 2 REFCOMP Access Reset z 1 0 REFSEL[3:0] R/W R R R R/W R/W R/W R/W 0 0 0 0 0 0 0 0 Bit 7 – REFCOMP: Reference Buffer Offset Compensation Enable The accuracy of the gain stage can be increased by enabling the reference buffer offset compensation. This will decrease the input impedance and thus increase the start-up time of the reference. 0: Reference buffer offset compensation is disabled. 1: Reference buffer offset compensation is enabled. z Bits 6:4 – 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. These bits will always return zero when read. z Bits 3:0 – REFSEL[3:0]: Reference Selection These bits select the reference for the ADC according to Table 29-4. Table 29-4. Reference Selection Value Name Description 0x0 INT1V 1.0V voltage reference 0x1 INTVCC0 1/1.48 VDDANA 0x2 INTVCC1 1/2 VDDANA (only for VDDANA > 2.0V) 0x3 AREFA External reference 0x4 AREFB External reference 0x5-0xF Reserved Reserved Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 497 29.8.3 Average Control Name: AVGCTRL Offset: 0x02 Reset: 0x00 Property: Write-Protected Bit 7 6 5 4 3 ADJRES[2:0] 2 1 0 SAMPLENUM[3:0] Access R R/W R/W R/W R/W R/W R/W R/W Reset 0 0 0 0 0 0 0 0 z 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. This bit will always return zero when read. z Bits 6:4 – ADJRES[2:0]: Adjusting Result / Division Coefficient These bits define the division coefficient in 2n steps. z Bits 3:0 – SAMPLENUM[3:0]: Number of Samples to be Collected These bits define how many samples should be added together.The result will be available in the Result register (RESULT). Note: if the result width increases, CTRLB.RESSEL must be changed. Table 29-5. Number of Samples to be Collected Value Name Description 0x0 1 sample 0x1 2 samples 0x2 4 samples 0x3 8 samples 0x4 16 samples 0x5 32 samples 0x6 64 samples 0x7 128 samples 0x8 256 samples 0x9 512 samples 0xA 1024 samples 0xB-0xF Reserved Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 498 29.8.4 Sampling Time Control Name: SAMPCTRL Offset: 0x03 Reset: 0x00 Property: Write-Protected Bit 7 6 5 4 3 2 1 0 SAMPLEN[5:0] Access R R R/W R/W R/W R/W R/W R/W Reset 0 0 0 0 0 0 0 0 z Bits 7:6 – 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. These bits will always return zero when read. z Bits 5:0 – SAMPLEN[5:0]: Sampling Time Length These bits control the ADC sampling time in number of half CLK_ADC cycles, depending of the prescaler value, thus controlling the ADC input impedance. Sampling time is set according to the equation: CLK ADC Sampling time = ( SAMPLEN + 1 ) ⋅ ⎛ ----------------------⎞ ⎝ ⎠ 2 Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 499 29.8.5 Control B Name: CTRLB Offset: 0x04 Reset: 0x0000 Property: Write-Synchronized, Write-Protected Bit 15 14 13 12 11 10 9 8 PRESCALER[2:0] Access R R R R R R/W R/W R/W Reset 0 0 0 0 0 0 0 0 Bit 7 6 5 4 3 2 1 0 CORREN FREERUN LEFTADJ DIFFMODE RESSEL[1:0] Access R R R/W R/W R/W R/W R/W R/W Reset 0 0 0 0 0 0 0 0 z Bits 15:11 – 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. These bits will always return zero when read. z Bits 10:8 – PRESCALER[2:0]: Prescaler Configuration These bits define the ADC clock relative to the peripheral clock according to Table 29-6. These bits can only be written while the ADC is disabled. Table 29-6. Prescaler Configuration Value Name Description 0x0 DIV4 Peripheral clock divided by 4 0x1 DIV8 Peripheral clock divided by 8 0x2 DIV16 Peripheral clock divided by 16 0x3 DIV32 Peripheral clock divided by 32 0x4 DIV64 Peripheral clock divided by 64 0x5 DIV128 Peripheral clock divided by 128 0x6 DIV256 Peripheral clock divided by 256 0x7 DIV512 Peripheral clock divided by 512 z Bits 7:6 – 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. These bits will always return zero when read. z Bits 5:4 – RESSEL[1:0]: Conversion Result Resolution These bits define whether the ADC completes the conversion at 12-, 10- or 8-bit result resolution. These bits can be written only while the ADC is disabled. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 500 Table 29-7. Conversion Result Resolution Value Name Description 0x0 12BIT 12-bit result 0x1 16BIT For averaging mode output 0x2 10BIT 10-bit result 0x3 8BIT 8-bit result z Bit 3 – CORREN: Digital Correction Logic Enabled 0: Disable the digital result correction. 1: Enable the digital result correction. The ADC conversion result in the RESULT register is then corrected for gain and offset based on the values in the GAINCAL and OFFSETCAL registers. Conversion time will be increased by X cycles according to the value in the Offset Correctioin Value bit group in the Offset Correction register. This bit can be changed only while the ADC is disabled. z Bit 2 – FREERUN: Free Running Mode 0: The ADC run is single conversion mode. 1: The ADC is in free running mode and a new conversion will be initiated when a previous conversion completes. This bit can be changed only while the ADC is disabled. z Bit 1 – LEFTADJ: Left Adjusted Result 0: The ADC convertion result is right-adjusted in the RESULT register. 1: The ADC conversion result is left-adjusted in the RESULT register. The high byte of the 12-bit result will be present in the upper part of the result register. Writing this bit to zero (default) will right-adjust the value in the RESULT register. This bit can be changed only while the ADC is disabled. z Bit 0 – DIFFMODE: Differential Mode 0: The ADC is running in singled-ended mode. 1: The ADC is running in differential mode. In this mode, the voltage difference between the MUXPOS and MUXNEG inputs will be converted by the ADC. This bit can be changed only while the ADC is disabled. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 501 29.8.6 Window Monitor Control Name: WINCTRL Offset: 0x08 Reset: 0x00 Property: Write-Synchronized, Write-Protected Bit 7 6 5 4 3 2 1 0 WINMODE[2:0] Access R R R R R R/W R/W R/W Reset 0 0 0 0 0 0 0 0 z Bits 7:3 – 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. These bits will always return zero when read. z Bits 2:0 – WINMODE[2:0]: Window Monitor Mode These bits enable and define the window monitor mode. Table 29-8 shows the mode selections. Table 29-8. Window Monitor Mode Value Name Description 0x0 No window mode (default) 0x1 Mode 1: RESULT > WINLT 0x2 Mode 2: RESULT < WINUT 0x3 Mode 3: WINLT < RESULT < WINUT 0x4 Mode 4: !(WINLT < RESULT < WINUT) 0x5-0x7 Reserved Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 502 29.8.7 Software Trigger Name: SWTRIG Offset: 0x0C Reset: 0x00 Property: Write-Synchronized, Write-Protected Bit 7 6 5 4 3 2 1 0 START FLUSH Access R R R R R R R/W R/W Reset 0 0 0 0 0 0 0 0 z Bits 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. These bits will always return zero when read. z Bit 1 – START: ADC Start Conversion 0: The ADC will not start a conversion. 1: The ADC will start a conversion. The bit is cleared by hardware when the conversion has started. Setting this bit when it is already set has no effect. Writing this bit to zero will have no effect. z Bit 0 – FLUSH: ADC Conversion Flush 0: No flush action. 1: The ADC pipeline will be flushed. A flush will restart the ADC clock on the next peripheral clock edge, and all conversions in progress will be aborted and lost. This bit is cleared until the ADC has been flushed. After the flush, the ADC will resume where it left off; i.e., if a conversion was pending, the ADC will start a new conversion. Writing this bit to zero will have no effect. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 503 29.8.8 Input Control Name: INPUTCTRL Offset: 0x10 Reset: 0x00000000 Property: Write-Synchronized, Write-Protected Bit 31 30 29 28 27 26 25 24 GAIN[3:0] Access R R R R R/W R/W R/W R/W Reset 0 0 0 0 0 0 0 0 23 22 21 20 19 18 17 16 Bit INPUTOFFSET[3:0] Access INPUTSCAN[3:0] R/W R/W R/W R/W R/W R/W R/W R/W Reset 0 0 0 0 0 0 0 0 Bit 15 14 13 12 11 10 9 8 MUXNEG[4:0] Access R R R R/W R/W R/W R/W R/W Reset 0 0 0 0 0 0 0 0 Bit 7 6 5 4 3 2 1 0 MUXPOS[4:0] Access R R R R/W R/W R/W R/W R/W Reset 0 0 0 0 0 0 0 0 z Bits 31:28 – 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. These bits will always return zero when read. z Bits 27:24 – GAIN[3:0]: Gain Factor Selection Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 504 These bits set the gain factor of the ADC gain stage according to the values shown in <table reference>. Table 29-9. Gain Factor Selection Value Name Description 0x0 1X 1x 0x1 2X 2x 0x2 4X 4x 0x3 8X 8x 0x4 16X 16x 0x5-0xE – Reserved 0xF DIV2 1/2x z Bits 23:20 – INPUTOFFSET[3:0]: Positive MUX Setting Offset The pin scan is enabled when INPUTSCAN != 0. Writing these bits to a value other than zero causes the first conversion triggered to be converted using a positive input equalto MUXPOS + INPUTOFFSET. Setting this register to zero causes the first conversion to use a positive input equal to MUXPOS. After a conversion, the INPUTOFFSET register will be incremented by one, causing the next conversion to be done with the positive inputequal to MUXPOS + INPUTOFFSET. The sum of MUXPOS and INPUTOFFSET gives the input that is actually converted. z Bits 19:16 – INPUTSCAN[3:0]: Number of Input Channels Included in Scan This register gives the number of input sources included in the pin scan. The number of input sources included is INPUTSCAN + 1. The input channels included are in the range from MUXPOS + INPUTOFFSET to MUXPOS + INPUTOFFSET + INPUTSCAN. The range of the scan mode must not exceded the number of input channels available on the device. z Bits 15:13 – 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. These bits will always return zero when read. z Bits 12:8 – MUXNEG[4:0]: Negative MUX Input Selection Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 505 These bits define the MUX selection for the negative ADC input. Table 29-10 shows the possible input selections. Table 29-10. Negative MUX Input Selection Value Name Description 0x00 PIN0 ADC AIN0 pin 0x01 PIN1 ADC AIN1 pin 0x02 PIN2 ADC AIN2 pin 0x03 PIN3 ADC AIN3 pin 0x04 PIN4 ADC AIN4 pin 0x05 PIN5 ADC AIN5 pin 0x06 PIN6 ADC AIN6 pin 0x07 PIN7 ADC AIN7 pin 0x08-0x17 – Reserved 0x18 GND Internal ground 0x19 IOGND I/O ground 0x1A-0x1F – Reserved z Bits 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. These bits will always return zero when read. z Bits 4:0 – MUXPOS[4:0]: Positive MUX Input Selection These bits define the MUX selection for the positive ADC input. Table 29-11 shows the possible input selections. Ifthe internal bandgapvoltage or temperature sensor input channel is selected, thenthe Sampling Time Length bit group in the SamplingControl register must be written with a corresponding value. Table 29-11. Positive MUX Input Selection MUXPOS[4:0] Group configuration Description 0x00 PIN0 ADC AIN0 pin 0x01 PIN1 ADC AIN1 pin 0x02 PIN2 ADC AIN2 pin 0x03 PIN3 ADC AIN3 pin 0x04 PIN4 ADC AIN4 pin 0x05 PIN5 ADC AIN5 pin 0x06 PIN6 ADC AIN6 pin 0x07 PIN7 ADC AIN7 pin 0x08 PIN8 ADC AIN8 pin 0x09 PIN9 ADC AIN9 pin 0x0A PIN10 ADC AIN10 pin Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 506 Table 29-11. Positive MUX Input Selection (Continued) MUXPOS[4:0] Group configuration Description 0x0B PIN11 ADC AIN11 pin 0x0C PIN12 ADC AIN12 pin 0x0D PIN13 ADC AIN13 pin 0x0E PIN14 ADC AIN14 pin 0x0F PIN15 ADC AIN15 pin 0x10 PIN16 ADC AIN16 pin 0x11 PIN17 ADC AIN17 pin 0x12 PIN18 ADC AIN18 pin 0x13 PIN19 ADC AIN19 pin 0x14-0x17 Reserved 0x18 TEMP Temperature peference 0x19 BANDGAP Bandgap voltage 0x1A SCALEDCOREVCC 1/4 scaled core supply 0x1B SCALEDIOVCC 1/4 scaled I/O supply 0x1C DAC DAC output 0x1D-0x1F Reserved Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 507 29.8.9 Event Control Name: EVCTRL Offset: 0x14 Reset: 0x00 Property: Write-Protected Bit 7 6 5 4 WINMONEO RESRDYEO 3 2 1 0 SYNCEI STARTEI Access R R R/W R/W R R R/W R/W Reset 0 0 0 0 0 0 0 0 z Bits 7:6 – 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. These bits will always return zero when read. z Bit 5 – WINMONEO: Window Monitor Event Out This bit indicates whether the Window Monitor event ouputt is enabled or not and an output event will be generated when the window monitor detects something. 0: Window Monitor event output is disabled and an event will not be generated. 1: Window Monitor event output is enabled and an event will be generated. z Bit 4 – RESRDYEO: Result Ready Event Out This bit indicates whether the Result Ready event output is enabled or not and an output event will be generated when the conversion result is available. 0: Result Ready eventoutputis disabled and an event will not be generated. 1: Result Ready event output is enabled and an event will be generated. z Bits 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. These bits will always return zero when read. z Bit 1 – SYNCEI: Synchronization Event In 0: A flush and new conversion will not be triggered on any incoming event. 1: A flush and new conversion will be triggered on any incoming event. z Bit 0 – STARTEI: Start Conversion Event In 0: A new conversion will not be triggered on any incoming event. 1: A new conversion will be triggered on any incoming event. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 508 29.8.10 Interrupt Enable Clear This register allows the user to disable an interrupt without doing a read-modify-write operation. Changes in this register will also be reflected in the Interrupt Enable Set register (INTENSET). Name: INTENCLR Offset: 0x16 Reset: 0x00 Property: Write-Protected Bit 7 6 5 4 3 2 1 0 SYNCRDY WINMON OVERRUN RESRDY Access R R R R R/W R/W R/W R/W Reset 0 0 0 0 0 0 0 0 z Bits 7:4 – 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. These bits will always return zero when read. z Bit 3 – SYNCRDY: Synchronization Ready Interrupt Enable 0: The Synchronization Ready interrupt is disabled. 1: The Synchronization Ready interrupt is enabled, and an interrupt request will be generated when the Synchronization Ready interrupt flag is set. Writing a zero to this bit has no effect. Writing a one to this bit will clear the Synchronization Ready Interrupt Enable bit and the corresponding interrupt request. z Bit 2 – WINMON: Window Monitor Interrupt Enable 0: The window monitor interrupt is disabled. 1: The window monitor interrupt is enabled, and an interrupt request will be generated when the Window Monitor interrupt flag is set. Writing a zero to this bit has no effect. Writing a one to this bit will clear the Window Monitor Interrupt Enable bit and the corresponding interrupt request. z Bit 1 – OVERRUN: Overrun Interrupt Enable 0: The Overrun interrupt is disabled. 1: The Overrun interrupt is enabled, and an interrupt request will be generated when the Overrun interrupt flag is set. Writing a zero to this bit has no effect. Writing a one to this bit will clear the Overrun Interrupt Enable bit and the corresponding interrupt request. z Bit 0 – RESRDY: Result Ready Interrupt Enable 0: The Result Ready interrupt is disabled. 1: The Result Ready interrupt is enabled, and an interrupt request will be generated when the Result Ready interrupt flag is set. Writing a zero to this bit has no effect. Writing a one to this bit will clear the Result Ready Interrupt Enable bit and the corresponding interrupt request. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 509 29.8.11 Interrupt Enable Set This register allows the user to enable an interrupt without doing a read-modify-write operation. Changes in this register will also be reflected in the Interrupt Enable Clear register (INTENCLR). Name: INTENSET Offset: 0x17 Reset: 0x00 Property: Write-Protected Bit 7 6 5 4 3 2 1 0 SYNCRDY WINMON OVERRUN RESRDY Access R R R R R/W R/W R/W R/W Reset 0 0 0 0 0 0 0 0 z Bits 7:4 – 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. These bits will always return zero when read. z Bit 3 – SYNCRDY: Synchronization Ready Interrupt Enable 0: The Synchronization Ready interrupt is disabled. 1: The Synchronization Ready interrupt is enabled. Writing a zero to this bit has no effect. Writing a one to this bit will set the Synchronization Ready Interrupt Enable bit, which enables the Synchronization Ready interrupt. z Bit 2 – WINMON: Window Monitor Interrupt Enable 0: The Window Monitor interrupt is disabled. 1: The Window Monitor interrupt is enabled. Writing a zero to this bit has no effect. Writing a one to this bit will set the Window Monitor Interrupt bit and enable the Window Monitor interrupt. z Bit 1 – OVERRUN: Overrun Interrupt Enable 0: The Overrun interrupt is disabled. 1: The Overrun interrupt is enabled. Writing a zero to this bit has no effect. Writing a one to this bit will set the Overrun Interrupt bit and enable the Overrun interrupt. z Bit 0 – RESRDY: Result Ready Interrupt Enable 0: The Result Ready interrupt is disabled. 1: The Result Ready interrupt is enabled. Writing a zero to this bit has no effect. Writing a one to this bit will set the Result Ready Interrupt bit and enable the Result Ready interrupt. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 510 29.8.12 Interrupt Flag Status and Clear Name: INTFLAG Offset: 0x18 Reset: 0x00 Property: – Bit 7 6 5 4 3 2 1 0 SYNCRDY WINMON OVERRUN RESRDY Access R R R R R/W R/W R/W R/W Reset 0 0 0 0 0 0 0 0 z Bits 7:4 – 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. These bits will always return zero when read. z Bit 3 – SYNCRDY: Synchronization Ready This flag is cleared by writing a one to the flag. This flag is set on a one-to-zero transition of the Synchronization Busy bit in the Status register (STATUS.SYNCBUSY), except when caused by an enable or software reset, and will generate an interrupt request if INTENCLR/SET.SYNCRDY is one. Writing a zero to this bit has no effect. Writing a one to this bit clears the Synchronization Ready interrupt flag. z Bit 2 – WINMON: Window Monitor This flag is cleared by writing a one to the flag. This flag is set on the next GCLK_ADC cycle after a match with the window monitor condition, and an interrupt request will be generated if INTENCLR/SET.WINMON is one. Writing a zero to this bit has no effect. Writing a one to this bit clears the Window Monitor interrupt flag. z Bit 1 – OVERRUN: Overrun This flag is cleared by writing a one to the flag. This flag is set if RESULT is written before the previous value has been read by CPU, and an interrupt request will be generated if INTENCLR/SET.OVERRUN is one. Writing a zero to this bit has no effect. Writing a one to this bit clears the Overrun interrupt flag. z Bit 0 – RESRDY: Result Ready This flag is cleared by writing a one to the flag. This flag is set when the conversion result is available, and an interrupt will be generated if INTENCLR/SET.RESRDY is one. Writing a zero to this bit has no effect. Writing a one to this bit clears the Result Ready interrupt flag. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 511 29.8.13 Status Name: STATUS Offset: 0x19 Reset: 0x00 Property: – Bit 7 6 5 4 3 2 1 0 SYNCBUSY Access R R R R R R R R Reset 0 0 0 0 0 0 0 0 z Bit 7 – SYNCBUSY: Synchronization Busy This bit is cleared when the synchronization of registers between the clock domains is complete. This bit is set when the synchronization of registers between clock domains is started. z Bits 6:0 – 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. These bits will always return zero when read. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 512 29.8.14 Result Name: RESULT Offset: 0x1A Reset: 0x0000 Property: Read-Synchronized Bit 15 14 13 12 11 10 9 8 RESULT[15:8] Access R R R R R R R R Reset 0 0 0 0 0 0 0 0 Bit 7 6 5 4 3 2 1 0 RESULT[7:0] Access R R R R R R R R Reset 0 0 0 0 0 0 0 0 z Bits 15:0 – RESULT[15:0]: Result Conversion Value These bits will hold up to a 16-bit ADC result, depending on the configuration. In single-ended without averaging mode, the ADC conversion will produce a 12-bit result, which can be left- or right-shifted, depending on the setting of CTRLB.LEFTADJ. If the result is left-adjusted (CTRLB.LEFTADJ), the high byte of the result will be in bit position [15:8], while the remaining 4 bits of the result will be placed in bit locations [7:4]. This can be used only if an 8-bit result is required; i.e., one can read only the high byte of the entire 16-bit register. If the result is not left-adjusted (CTRLB.LEFTADJ) and no oversampling is used, the result will be available in bit locations [11:0], and the result is then 12 bits long. If oversampling is used, the result will be located in bit locations [15:0], depending on the settings of the Average Control register (AVGCTRL). Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 513 29.8.15 Window Monitor Lower Threshold Name: WINLT Offset: 0x1C Reset: 0x0000 Property: Write-Synchronized, Write-Protected Bit 15 14 13 12 11 10 9 8 WINLT[15:8] Acces s R/W R/W R/W R/W R/W R/W R/W R/W Reset 0 0 0 0 0 0 0 0 Bit 7 6 5 4 3 2 1 0 WINLT[7:0] Acces s R/W R/W R/W R/W R/W R/W R/W R/W Reset 0 0 0 0 0 0 0 0 z Bits 15:0 – WINLT[15:0]: Window Lower Threshold If the window monitor is enabled, these bits define the lower threshold value. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 514 29.8.16 Window Monitor Upper Threshold Name: WINUT Offset: 0x20 Reset: 0x0000 Property: Write-Synchronized, Write-Protected Bit 15 14 13 12 11 10 9 8 WINUT[15:8] Access R/W R/W R/W R/W R/W R/W R/W R/W Reset 0 0 0 0 0 0 0 0 Bit 7 6 5 4 3 2 1 0 WINUT[7:0] Access Reset z R/W R/W R/W R/W R/W R/W R/W R/W 0 0 0 0 0 0 0 0 Bits 15:0 – WINUT[15:0]: Window Upper Threshold If the window monitor is enabled, these bits define the upper threshold value. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 515 29.8.17 Gain Correction Name: GAINCORR Offset: 0x24 Reset: 0x0000 Property: Write-Protected Bit 15 14 13 12 11 10 9 8 GAINCORR[11:8] Access R R R R R/W R/W R/W R/W Reset 0 0 0 0 0 0 0 0 Bit 7 6 5 4 3 2 1 0 GAINCORR[7:0] Access Reset R/W R/W R/W R/W R/W R/W R/W R/W 0 0 0 0 0 0 0 0 z Bits 15:12 – 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. These bits will always return zero when read. z Bits 11:0 – GAINCORR[11:0]: Gain Correction Value If the CTRLB.CORREN bit is one, these bits define how the ADC conversion result is compensated for gain error before being written to the result register. The gaincorrection is a fractional value, a 1-bit integer plusan 11-bit fraction, and therefore ½ <= GAINCORR < 2. GAINCORR values range from 0.10000000000 to 1.11111111111. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 516 29.8.18 Offset Correction Name: OFFSETCORR Offset: 0x26 Reset: 0x0000 Property: Write-Protected Bit 15 14 13 12 11 10 9 8 OFFSETCORR[11:8] Access R R R R R/W R/W R/W R/W Reset 0 0 0 0 0 0 0 0 Bit 7 6 5 4 3 2 1 0 OFFSETCORR[7:0] Access Reset R/W R/W R/W R/W R/W R/W R/W R/W 0 0 0 0 0 0 0 0 z Bits 15:12 – 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. These bits will always return zero when read. z Bits 11:0 – OFFSETCORR[11:0]: Offset Correction Value If the CTRLB.CORREN bit is one, these bits define how the ADC conversion result is compensated for offset error before being written to the Result register. This OFFSETCORR value is in two’s complement format. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 517 29.8.19 Calibration Name: CALIB Offset: 0x28 Reset: 0x0000 Property: Write-Protected Bit 15 14 13 12 11 10 9 8 BIAS_CAL[2:0] Access R R R R R R/W R/W R/W Reset 0 0 0 0 0 0 0 0 Bit 7 6 5 4 3 2 1 0 LINEARITY_CAL[7:0] Access Reset R/W R/W R/W R/W R/W R/W R/W R/W 0 0 0 0 0 0 0 0 z Bits 15:11 – 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. These bits will always return zero when read. z Bits 10:8 – BIAS_CAL[2:0]: Bias Calibration Value This value from production test must be loaded from the NVM software calibration row into the CALIB register by software to achieve the specified accuracy. Thevalue must be copied only, and must not be changed. z Bits 7:0 – LINEARITY_CAL[7:0]: Linearity Calibration Value This value from production test must be loaded from the NVM software calibration row into the CALIB register by software to achieve the specified accuracy. Thevalue must be copied only, and must not be changed. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 518 29.8.20 Debug Control Name: DBGCTRL Offset: 0x2A Reset: 0x00 Property: Write-Protected Bit 7 6 5 4 3 2 1 0 DBGRUN Access R R R R R R R R/W Reset 0 0 0 0 0 0 0 0 z Bits 7:1 – 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. These bits will always return zero when read. z Bit 0 – DBGRUN: Debug Run 0: The ADC is halted during debug mode. 1: The ADC continues normal operation during debug mode. This bit can be changed only while the ADC is disabled. This bit should be written only while a conversion is not ongoing. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 519 30. 30.1 AC – Analog Comparator Overview The Atmel® SAM D20 Analog Comparator (AC) supports two individual comparators. Each comparator (COMP) compares the voltage levels on two inputs, and provides a digital output based on this comparison. Each comparator may be configured to generate interrupt requests and/or peripheral events upon several different combinations of input change. Hysteresis and propagation delay are two important properties of the comparators; dynamic behavior. Both parameters may be adjusted to achieve the optimal operation for each application. The input selection includes four shared analog port pins and several internal signals. Each comparator output state can also be output on a pin for use by external devices. The comparators are always grouped in pairs on each port. The AC module may implement one pair. These are called Comparator 0 (COMP0) and Comparator 1 (COMP1). They have identical behaviors, but separate control registers. The pair can be set in window mode to compare a signal to a voltage range instead of a single voltage level. 30.2 Features z Two individual comparators z Selectable propagation delay versus current consumption z Selectable hysteresis z On/Off z Analog comparator outputs available on pins z Asynchronous or synchronous z Flexible input selection z Four pins selectable for positive or negative inputs Ground (for zero crossing) z Bandgap reference voltage z 64-level programmable VDD scaler per comparator z DAC z z Interrupt generation on: z Rising or falling edge Toggle z End of comparison z z Window function interrupt generation on: z Signal above window Signal inside window z Signal below window z Signal outside window z z Event generation on: z z Comparator output Window function inside/outside window z Optional digital filter on comparator output z Low-power option z Single-shot support Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 520 30.3 Block Diagram Figure 30-1. Analog Comparator Block Diagram AIN0 + CMP0 COMP0 AIN1 - HYSTERESIS VDD SCALER INTERRUPTS ENABLE INTERRUPT MODE DAC COMPCTRLn WINCTRL ENABLE BANDGAP EVENTS GCLK_AC HYSTERESIS + AIN2 INTERRUPT SENSITIVITY CONTROL & WINDOW FUNCTION CMP1 COMP1 AIN3 30.4 - Signal Description Signal Name Type Description AIN[3..0] Analog input Comparator inputs CMP[1..0] Digital output Comparator outputs Refer to “I/O Multiplexing and Considerations” on page 15 for details on the pin mapping for this peripheral. One signal can be mapped on several pins. 30.5 Product Dependencies In order to use this peripheral, other parts of the system must be configured correctly, as described below. 30.5.1 I/O Lines Using the AC’s I/O lines requires the I/O pins to be configured. Refer to the PORT chapter for details. Refer to “PORT” on page 289 for details. 30.5.2 Power Management The AC will continue to operate in any sleep mode where the selected source clock is running. The AC’s interrupts can be used to wake up the device from sleep modes. The events can trigger other operations in the system without exiting sleep modes. Refer to “PM – Power Manager” on page 105 for details on the different sleep modes. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 521 30.5.3 Clocks The AC bus clock (CLK_AC_APB) can be enabled and disabled in the Power Manager, and the default state of the CLK_AC_APB can be found in the Peripheral Clock Masking section of “PM – Power Manager” on page 105. Two generic clocks (GCLK_AC_DIG and GCLK_AC_ANA) are used by the AC. The digital clock (GCLK_AC_DIG) is required to provide the sampling rate for the comparators, while the analog clock (GCLK_AC_ANA) is required for lowvoltage operation (VDD < 2.5V) to ensure that the resistance of the analog input multiplexors remains low. These clocks must be configured and enabled in the Generic Clock Controller before using the peripheral. Refer to “GCLK – Generic Clock Controller” on page 83 for details. These generic clocks are asynchronous to the CLK_AC_APB clock. Due to this asynchronicity, writes to certain registers will require synchronization between the clock domains. Refer to “Synchronization” on page 530 for further details. 30.5.4 Interrupts The interrupt request line is connected to the Interrupt Controller. Using the AC interrupts requires the Interrupt Controller to be configured first. Refer to “Nested Vector Interrupt Controller” on page 28 for details. 30.5.5 Events The events are connected to the Event System. Using the events requires the Event System to be configured first. Refer to “EVSYS – Event System” on page 314 for details. 30.5.6 Debug Operation When the CPU is halted in debug mode, the peripheral continues normal operation. If the peripheral is configured in a way that requires it to be periodically serviced by the CPU through interrupts or similar, improper operation or data loss may result during debugging. 30.5.7 Register Access Protection All registers with write-access are optionally write-protected by the Peripheral Access Controller (PAC), except the following registers: z Control B register (CTRLB) z Interrupt Flag register (INTFLAG) Write-protection is denoted by the Write-Protected property in the register description. Write-protection does not apply for accesses through an external debugger. Refer to “PAC – Peripheral Access Controller” on page 31 for details. 30.5.8 Analog Connections Each comparator has up to four I/O pins that can be used as analog inputs. Each pair of comparators shares the same four pins. These pins must be configured for analog operation before using them as comparator inputs. Any internal reference source, such as a bandgap reference voltage or the DAC, must be configured and enabled prior to its use as a comparator input. 30.5.9 Other Dependencies Not applicable. 30.6 Functional Description 30.6.1 Principle of Operation Each comparator has one positive input and one negative input. Each positive input may be chosen from a selection of analog input pins. Each negative input may be chosen from a selection of analog input pins or internal inputs, such as a Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 522 bandgap reference voltage. The digital output from the comparator is one when the difference between the positive and the negative input voltage is positive, and zero otherwise. The individual comparators can be used independently (normal mode) or grouped in pairs to generate a window comparison (window mode). 30.6.2 Basic Operation 30.6.2.1 Initialization Before enabling the AC, the input and output events must be configured in the Event Control register (EVCTRL). These settings cannot be changed while the AC is enabled. Each individual comparator must also be configured by its respective Comparator Control register (COMPCTRLx) before that comparator is enabled. These settings cannot be changed while the comparator is enabled. z Select the desired measurement mode with COMPCTRLx.SINGLE. See “Basic Operation” on page 523 for more details z Select the desired hysteresis with COMPCTRLx.HYST. See “Input Hysteresis” on page 527 for more details z Select the comparator speed versus power with COMPCTRLx.SPEED. See “Propagation Delay vs. Power Consumption” on page 527 for more details z Select the interrupt source with COMPCTRLx.INTSEL z Select the positive and negative input sources with the COMPCTRLx.MUXPOS and COMPCTRLx.MUXNEG bits. See section “Selecting Comparator Inputs” on page 525 for more details z Select the filtering option with COMPCTRLx.FLEN 30.6.2.2 Enabling, Disabling and Resetting The AC is enabled by writing a one to the Enable bit in the Control A register (CTRLA.ENABLE). The individual comparators must be also enabled by writing a one to the Enable bit in the Comparator x Control registers (COMPCTRLx.ENABLE). The AC is disabled by writing a zero to CTRLA.ENABLE. This will also disable the individual comparators, but will not clear their COMPCTRLx.ENABLE bits. The AC is reset by writing a one to the Software Reset bit in the Control A register (CTRLA.SWRST). All registers in the AC, except DEBUG, will be reset to their initial state, and the AC will be disabled. Refer to the register for details. 30.6.2.3 Basic Operation Each comparator channel can be in one of two different measurement modes, determined by the Single bit in the Comparator x Control register (COMPCTRLx.SINGLE): z Continuous measurement z Single-shot After being enabled, a start-up delay is required before the result of the comparison is ready. This start-up time is measured automatically to account for environmental changes, such as temperature or voltage supply level, and is specified in <!!!CRs_ElChar_Top!!!>. During the start-up time, the COMP output is not available. If the supply voltage is below 2.5V, the start-up time is also dependent on the voltage doubler. If the supply voltage is guaranteed to be above 2.5V, the voltage doubler can be disabled by writing the Low-Power Mux bit in the Control A register (CTRLA.LPMUX) to one. The comparator can be configured to generate interrupts when the output toggles, when the output changes from zero to one (rising edge), when the output changes from one to zero (falling edge) or at the end of the comparison. An end-ofcomparison interrupt can be used with the single-shot mode to chain further events in the system, regardless of the state of the comparator outputs. The interrupt mode is set by the Interrupt Selection bit group in the Comparator Control register (COMPCTRLx.INTSEL). Events are generated using the comparator output state, regardless of whether the interrupt is enabled or not. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 523 Continuous Measurement Continuous measurement is selected by writing COMPCTRLx.SINGLE to zero. In continuous mode, the comparator is continuously enabled and performing comparisons. This ensures that the result of the latest comparison is always available in the Current State bit in the Status A register (STATUSA.STATEx). After the start-up time has passed, a comparison is done and STATUSA is updated. The Comparator x Ready bit in the Status B register (STATUSB.READYx) is set, and the appropriate peripheral events and interrupts are also generated. New comparisons are performed continuously until the COMPCTRLx.ENABLE bit is written to zero. The start-up time applies only to the first comparison. In continuous operation, edge detection of the comparator output for interrupts is done by comparing the current and previous sample. The sampling rate is the GCLK_AC_DIG frequency. An example of continuous measurement is shown in Figure 30-2. Figure 30-2. Continuous Measurement Example GCLK_AC Write ‘1’ COMPCTRLx.ENABLE 2-3 cycles tSTARTUP STATUSB.READYx Sampled Comparator Output For low-power operation, comparisons can be performed during sleep modes without a clock. The comparator is enabled continuously, and changes in the state of the comparator are detected asynchronously. When a toggle occurs, the Power Manager will start GCLK_AC_DIG to register the appropriate peripheral events and interrupts. The GCLK_AC_DIG clock is then disabled again automatically, unless configured to wake up the system from sleep. Single-Shot Single-shot operation is selected by writing COMPCTRLx.SINGLE to one. During single-shot operation, the comparator is normally idle. The user starts a single comparison by writing a one to the respective Start Comparison bit in the writeonly Control B register (CTRLB.STARTx). The comparator is enabled, and after the start-up time has passed, a single comparison is done and STATUSA is updated. Appropriate peripheral events and interrupts are also generated. No new comparisons will be performed. Writing a one to CTRLB.STARTx also clears the Comparator x Ready bit in the Status B register (STATUSB.READYx). STATUSB.READYx is set automatically by hardware when the single comparison has completed. To remove the need for polling, an additional means of starting the comparison is also available. A read of the Status C register (STATUSC) will start a comparison on all comparators currently configured for single-shot operation. The read will stall the bus until all enabled comparators are ready. If a comparator is already busy with a comparison, the read will stall until the current comparison is compete, and a new comparison will not be started. A single-shot measurement can also be triggered by the Event System. Writing a one to the Comparator x Event Input bit in the Event Control Register (EVCTRL.COMPEIx) enables triggering on incoming peripheral events. Each comparator can be triggered independently by separate events. Event-triggered operation is similar to user-triggered operation; the difference is that a peripheral event from another hardware module causes the hardware to automatically start the comparison and clear STATUSB.READYx. To detect an edge of the comparator output in single-shot operation for the purpose of interrupts, the result of the current measurement is compared with the result of the previous measurement (one sampling period earlier). An example of single-shot operation is shown in Figure 30-3. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 524 Figure 30-3. Single-Shot Example GCLK_AC Write ‘1’ CTRLB.STARTx Write ‘1’ 2-3 cycles 2-3 cycles tSTARTUP tSTARTUP STATUSB.READYx Sampled Comparator Output For low-power operation, event-triggered measurements can be performed during sleep modes. When the event occurs, the Power Manager will start GCLK_AC_DIG. The comparator is enabled, and after the startup time has passed, a comparison is done and appropriate peripheral events and interrupts are also generated. The comparator and GCLK_AC_DIG are then disabled again automatically, unless configured to wake up the system from sleep. 30.6.3 Selecting Comparator Inputs Each comparator has one positive and one negative input. The positive input is fed from an external input pin (AINx). The negative input can be fed either from an external input pin (AINx) or from one of the several internal reference voltage sources common to all comparators. The user selects the input source as follows: z The positive input is selected by the Positive Input MUX Select bit group in the Comparator Control register (COMPCTRLx.MUXPOS) z The negative input is selected by the Negative Input MUX Select bit group in the Comparator Control register (COMPCTRLx.MUXNEG) In the case of using an external I/O pin, the selected pin must be configured for analog usage in the PORT Controller by disabling the digital input and output. The switching of the analog input multiplexors is controlled to minimize crosstalk between the channels. The input selection must be changed only while the individual comparator is disabled. 30.6.4 Window Operation Each comparator pair can be configured to work together in window mode. In this mode, a voltage range is defined, and the comparators give information about whether an input signal is within this range or not. Window mode is enabled by the Window Enable x bit in the Window Control register (WINCTRL.WENx). Both comparators in a pair must have the same measurement mode setting in their respective Comparator Control Registers (COMPCTRLx.SINGLE). To physically configure the pair of comparators for window mode, the same I/O pin should be chosen for each comparator’s positive input to create the shared input signal. The negative inputs define the range for the window. In Figure 30-4, COMP0 defines the upper limit and COMP1 defines the lower limit of the window, as shown but the window will also work in the opposite configuration with COMP0 lower and COMP1 higher. The current state of the window function is available in the Window x State bit group of the Status register (STATUS.WSTATEx). Window mode can be configured to generate interrupts when the input voltage changes to below the window, when the input voltage changes to above the window, when the input voltage changes into the window or when the input voltage changes outside the window. The interrupt selections are set by the Window Interrupt Selection bit group in the Window Control register (WINCTRL.WINTSELx[1:0]). Events are generated using the inside/outside state of the window, regardless of whether the interrupt is enabled or not. Note that the individual comparator outputs, interrupts and events continue to function normally during window mode. When the comparators are configured for window mode and single-shot mode, measurements are performed simultaneously on both comparators. Writing a one to either Start Comparison bit in the Control B register (CTRLB.STARTx) starts a measurement. Likewise either peripheral event can start a measurement. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 525 Figure 30-4. Comparators in Window Mode + STATE0 COMP0 UPPER LIMIT OF WINDOW - WSTATE[1:0] INTERRUPT SENSITIVITY CONTROL & WINDOW FUNCTION INPUT SIGNAL INTERRUPTS EVENTS + STATE1 COMP1 LOWER LIMIT OF WINDOW - 30.6.5 Voltage Doubler The AC contains a voltage doubler that can reduce the resistance of the analog multiplexors when the supply voltage is below 2.5V. The voltage doubler is normally switched on/off automatically based on the supply level. When enabling the comparators, additional start-up time is required for the voltage doubler to settle. If the supply voltage is guaranteed to be above 2.5V, the voltage doubler can be disabled by writing the Low-Power Mux bit in the Control A register (CTRLA.LPMUX) to one. Disabling the voltage doubler saves power and reduces the start-up time. 30.6.6 VDD Scaler The VDD scaler generates a reference voltage that is a fraction of the device’s supply voltage, with 64 levels. One independent voltage channel is dedicated for each comparator. The scaler is enabled when a comparator’s Negative Input Mux bitgroup in its Comparator Control register (COMPCTRLx.MUXNEG) is set to five and the comparator is enabled. The voltage of each channel is selected by the Value bit group in the Scaler x registers (SCALERx.VALUE[5:0]). Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 526 Figure 30-5. VDD Scaler COMPCTRLx.MUXNEG == 5 SCALERx. VALUE 6 to COMPx 30.6.7 Input Hysteresis Application software can selectively enable/disable hysteresis for the comparison. Applying hysteresis will help prevent constant toggling of the output,which can be caused by noise when the input signals are close to each other. Hysteresis is enabled for each comparator individually by the Hysteresis Mode bit in the Comparator x Control register (COMPCTRLx.HYST). Hysteresis is available only in continuous mode (COMPCTRLx.SINGLE=0). 30.6.8 Propagation Delay vs. Power Consumption It is possible to trade off comparison speed for power efficiency to get the shortest possible propagation delay or the lowest power consumption. The speed setting is configured for each comparator individually by the Speed bit group in the Comparator x Control register (COMPCTRLx.SPEED). The Speed bits select the amount of bias current provided to the comparator, and as such will also affect the start-up time. 30.6.9 Filtering The output of the comparators can be digitally filtered to reduce noise using a simple digital filter. The filtering is determined by the Filter Length bits in the Comparator Control x register (COMPCTRLx.FLEN), and is independent for each comparator. Filtering is selectable from none, 3-bit majority (N=3) or 5-bit majority (N=5) functions. Any change in the comparator output is considered valid only if N/2+1 out of the last N samples agree. The filter sampling rate is the CLK_AC frequency scaled by the prescaler setting in the Control A register (CTRLA.PRESCALER). Note that filtering creates an additional delay of N-1 sampling cycles from when a comparison is started until the comparator output is validated. For continuous mode, the first valid output will occur when the required number of filter samples is taken. Subsequent outputs will be generated every cycle based on the current sample plus the previous N-1 samples, as shown in Figure 30-6. For single-shot mode, the comparison completes after the Nth filter sample, as shown in Figure 30-7. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 527 Figure 30-6. Continuous Mode Filtering Sampling Clock Sampled Comparator Output 3-bit Majority Filter Output 5-bit Majority Filter Output Figure 30-7. Single-Shot Filtering Sampling Clock Start t SUT 3-bit Sampled Comparator Output 3-bit Majority Filter Output 5-bit Sampled Comparator Output 5-bit Majority Filter Output During sleep modes, filtering is supported only for single-shot measurements. Filtering must be disabled if continuous measurements will be done during sleep modes, or the resulting interrupt/event may be generated incorrectly. 30.6.10 Comparator Output The output of each comparator can be routed to an I/O pin by setting the Output bit group in the Comparator Control x register (COMPCTRLx.OUT). This allows the comparator to be used by external circuitry. Either the raw, nonsynchronized output of the comparator or the CLK_AC-synchronized version, including filtering, can be used as the I/O signal source. The output appears on the corresponding CMP[x] pin. 30.6.11 Offset Compensation The Swap bit in the Comparator Control registers (COMPCTRLx.SWAP) controls switching of the input signals to a comparator's positive and negative terminals. When the comparator terminals are swapped, the output signal from the comparator is also inverted, as shown in Figure 30-8. This allows the user to measure or compensate for the comparator input offset voltage. As part of the input selection, COMPCTRLx.SWAP can be changed only while the comparator is disabled. Figure 30-8. Input Swapping for Offset Compensation + MUXPOS COMPx - CMPx HYSTERESIS ENABLE SWAP MUXNEG COMPCTRLx SWAP Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 528 30.6.12 Interrupts The peripheral has the following interrupt sources: z Comparator: COMP0, COMP1(INTENCLR, INTSET, INTFLAG) z Window: WIN0(INTENCLR, INTSET, INTFLAG) Comparator interrupts are generated based on the conditions selected by the Interrupt Selection bit group in the Comparator Control registers (COMPCTRLx.INTSEL). Window interrupts are generated based on the conditions selected by the Window Interrupt Selection bit group in the Window Control register (WINCTRL.WINTSEL[1:0]). Each interrupt source has an interrupt flag associated with it. The interrupt flag in the Interrupt Flag Status and Clear register (INTFLAG) is set when the interrupt condition occurs. Each interrupt can be individually enabled by writing a one to the corresponding bit in the Interrupt Enable Set register (INTENSET), and disabled by writing a one to the corresponding bit in the Interrupt Enable Clear register (INTENCLR). An interrupt request is generated when the interrupt flag is set and the corresponding interrupt is enabled. The interrupt request remains active until the interrupt flag is cleared, the interrupt is disabled or the peripheral is reset. An interrupt flag is cleared by writing a one to the corresponding bit in the INTFLAG register. Each peripheral can have one interrupt request line per interrupt source or one common interrupt request line for all the interrupt sources. If the peripheral has one common interrupt request line for all the interrupt sources, the user must read the INTFLAG register to determine which interrupt condition is present. For details on clearing interrupt flags, refer to the INTFLAG register description. Note that interrupts must be globally enabled for interrupt requests to be generated. Refer to “Nested Vector Interrupt Controller” on page 28 for details. 30.6.13 Events The peripheral can generate the following output events: z Comparator: COMPEO0, COMPEO1(EVCTRL) z Window: WINEO0(EVCTRL) Output events must be enabled to be generated. Writing a one to an Event Output bit in the Event Control register (EVCTRL.COMPEOx) enables the corresponding output event. Writing a zero to this bit disables the corresponding output event. The events must be correctly routed in the Event System. Refer to “EVSYS – Event System” on page 314 for details. The peripheral can take the following actions on an input event: z Single-shot measurement z Single-shot measurement in window mode Input events must be enabled for the corresponding action to be taken on any input event. Writing a one to an Event Input bit in the Event Control register (EVCTRL.COMPEIx) enables the corresponding action on input event. Writing a zero to a bit disables the corresponding action on input event. Note that if several events are connected to the peripheral, the enabled action will be taken on any of the incoming events. The events must be correctly routed in the Event System. Refer to “EVSYS – Event System” on page 314 for details. When EVCTRL.COMPEIx is one, the event will start a comparison on COMPx after the start-up time delay. In normal mode, each comparator responds to its corresponding input event independently. For a pair of comparators in window mode, either comparator event will trigger a comparison on both comparators simultaneously. 30.6.14 Sleep Mode Operation The Run in Standby bit in the Control A register (CTRLA.RUNSTDBY) controls the behavior of the AC during standby sleep mode. When the bit is zero, the comparator pair is disabled during sleep, but maintains its current configuration. When the bit is one, the comparator pair continues to operate during sleep. Note that when RUNSTDBY is zero, the analog blocks are powered off for the lowest power consumption. This necessitates a start-up time delay when the system returns from sleep. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 529 When RUNSTDBY is one, any enabled AC interrupt source can wake up the CPU. However, single-shot comparisons will be triggerable by events only while the CPU is idle. The AC can also be used during sleep modes where the clock used by the AC is disabled, provided that the AC is still powered (not in shutdown). In this case, the behavior is slightly different and depends on the measurement mode, as listed in Table 30-1. Table 30-1. Sleep Mode Operation COMPCTRLx.MODE RUNSTDBY=0 RUNSTDBY=1 0 (Continuous) COMPx disabled GCLK_AC_DIG stopped, COMPx enabled 1 (Single-shot) COMPx disabled GCLK_AC_DIG stopped, COMPx enabled only when triggered by an input event 30.6.14.1 Continuous Measurement during Sleep When a comparator is enabled in continuous measurement mode and GCLK_AC_DIG is disabled during sleep, the comparator will remain continuously enabled and will function asynchronously. The current state of the comparator is asynchronously monitored for changes. If an edge matching the interrupt condition is found, GCLK_AC_DIG is started to register the interrupt condition and generate events. If the interrupt is enabled in the Interrupt Enable registers (INTENCLR/SET), the AC can wake up the device; otherwise GCLK_AC_DIG is disabled until the next edge detection. Filtering is not possible with this configuration. Figure 30-9. Continuous Mode SleepWalking GCLK_AC Comparator State Comparator Output or Event 30.6.14.2 Single-Shot Measurement during Sleep For low-power operation, event-triggered measurements can be performed during sleep modes. When the event occurs, the Power Manager will start GCLK_AC_DIG. The comparator is enabled, and after the start-up time has passed, a comparison is done, with filtering if desired, and the appropriate peripheral events and interrupts are also generated, as shown in Figure 30-10 The comparator and GCLK_AC_DIG are then disabled again automatically, unless configured to wake the system from sleep. Filtering is allowed with this configuration. Figure 30-10.Single-Shot SleepWalking GCLK_AC tSTARTUP t STARTUP Input Event Comparator Output or Event 30.6.15 Synchronization Due to the asynchronicity between CLK_MODULE_APB and GCLK_MODULE, some registers must be synchronized when accessed. A register can require: z Synchronization when written z Synchronization when read Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 530 z Synchronization when written and read z No synchronization When executing an operation that requires synchronization, the Synchronization Busy bit in the Status register (STATUS.SYNCBUSY) will be set immediately, and cleared when synchronization is complete. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 531 30.7 Register Summary Offset Name Bit Pos. 0x00 CTRLA 7:0 0x01 CTRLB 7:0 0x02 RUNSTDBY WINEO0 7:0 ENABLE SWRST START1 START0 COMPEO1 COMPEO0 COMPEI1 COMPEI0 EVCTRL 0x03 15:8 0x04 INTENCLR 7:0 WIN0 COMP1 COMP0 0x05 INTENSET 7:0 WIN0 COMP1 COMP0 0x06 INTFLAG 7:0 WIN0 COMP1 COMP0 0x07 Reserved 0x08 STATUSA 7:0 STATE1 STATE0 0x09 STATUSB 7:0 READY1 READY0 0x0A STATUSC 7:0 STATE1 STATE0 0x0B Reserved 0x0C WINCTRL 0x0D Reserved 0x0E Reserved 0x0F Reserved 0x10 WSTATE0[1:0] SYNCBUSY WSTATE0[1:0] 7:0 WINTSEL0[1:0] 7:0 0x11 15:8 INTSEL[1:0] SPEED[1:0] MUXPOS[1:0] SWAP WEN0 SINGLE ENABLE MUXNEG[2:0] COMPCTRL0 0x12 23:16 0x13 31:24 0x14 7:0 0x15 15:8 HYST OUT[1:0] FLEN[2:0] INTSEL[1:0] SWAP SPEED[1:0] MUXPOS[1:0] SINGLE ENABLE MUXNEG[2:0] COMPCTRL1 0x16 23:16 0x17 31:24 HYST OUT[1:0] FLEN[2:0] 0x18 Reserved ... Reserved 0x1F Reserved 0x20 SCALER0 7:0 VALUE[5:0] 0x21 SCALER1 7:0 VALUE[5:0] Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 532 30.8 Register Description Registers can be 8, 16 or 32 bits wide. Atomic 8-, 16- and 32-bit accesses are supported. In addition, the 8-bit quarters and 16-bit halves of a 32-bit register and the 8-bit halves of a 16-bit register can be accessed directly. Some registers are optionally write-protected by the Peripheral Access Controller (PAC). Write-protection is denoted by the Write-Protected property in each individual register description. Refer to “Register Access Protection” on page 522 for details. Some registers require synchronization when read and/or written. Synchronization is denoted by the Write-Synchronized or the Read-Synchronized property in each individual register description. Refer to “Synchronization” on page 530 for details. Some registers are enable-protected, meaning they can be written only when the AC is disabled. Enable-protection is denoted by the Enable-Protected property in each individual register description. 30.8.1 Control A Name: CTRLA Offset: 0x00 Reset: 0x00 Property: Write-Protected Bit 7 6 5 4 3 2 1 0 RUNSTDBY ENABLE SWRST Access R R R R R R/W R/W R/W Reset 0 0 0 0 0 0 0 0 z -Bits 7:3 – 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. These bits will always return zero when read. z Bit 2 – RUNSTDBY: Run in Standby This bit controls the behavior of the comparators during standby sleep mode. 0: The comparator pair is disabled during sleep. 1: The comparator pair continues to operate during sleep. z Bit 1 – ENABLE: Enable 0: The AC is disabled. 1: The AC is enabled. Each comparator must also be enabled individually by the Enable bit in the Comparator Control register (COMPCTRLx.ENABLE). Due to synchronization, there is delay from updating the register until the peripheral is enabled/disabled. The value written to CTRL.ENABLE will read back immediately after being written. STATUS.SYNCBUSY is set. STATUS.SYNCBUSY is cleared when the peripheral is enabled/disabled. z Bit 0 – SWRST: Software Reset 0: There is no reset operation ongoing. 1: The reset operation is ongoing. Writing a zero to this bit has no effect. Writing a one to this bit resets all registers in the AC to their initial state, and the AC will be disabled. Writing a one to CTRL.SWRST will always take precedence, meaning that all other writes in the same write-operation will be discarded. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 533 Due to synchronization, there is a delay from writing CTRLA.SWRST until the reset is complete. CTRLA.SWRST and STATUS.SYNCBUSY will both be cleared when the reset is complete. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 534 30.8.2 Control B Name: CTRLB Offset: 0x01 Reset: 0x00 Property: – Bit 7 6 5 4 3 2 1 0 START1 START0 Access R R R R R R W W Reset 0 0 0 0 0 0 0 0 z Bits 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. These bits will always return zero when read. z Bits 1:0 – STARTx: Comparator x Start Comparison Writing a zero to this field has no effect. Writing a one to STARTx starts a single-shot comparison on COMPx if both the Single-Shot and Enable bits in the Comparator x Control Register are one (COMPCTRLx.SINGLE and COMPCTRLx.ENABLE). If comparator x is not implemented, or if it is not enabled in single-shot mode, writing a one has no effect. This bit always reads as zero. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 535 30.8.3 Event Control Name: EVCTRL Offset: 0x02 Reset: 0x0000 Property: Write-Protected, Enable-Protected Bit 15 14 13 12 11 10 9 8 COMPEI1 COMPEI0 Access R R R R R R R/W R/W Reset 0 0 0 0 0 0 0 0 Bit 7 6 5 4 3 2 1 0 COMPEO1 COMPEO0 WINEO0 Access R R R R/W R R R/W R/W Reset 0 0 0 0 0 0 0 0 z Bits 15:10 – 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. These bits will always return zero when read. z Bits 9:8 – COMPEIx: Comparator x Event Input Note that several actions can be enabled for incoming events. If several events are connected to the peripheral, the enabled action will be taken for any of the incoming events. There is no way to tell which of the incoming events caused the action. These bits indicate whether a comparison will start or not on any incoming event. 0: Comparison will not start on any incoming event. 1: Comparison will start on any incoming event. z Bits 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. These bits will always return zero when read. z Bit 4 – WINEO0: Window 0 Event Output Enable This bit indicates whether the window 0 function can generate a peripheral event or not. 0: Window 0 event is disabled. 1: Window 0 event is enabled. z Bits 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. These bits will always return zero when read. z Bits 1:0 – COMPEOx: Comparator x Event Output Enable These bits indicate whether the comparator x output can generate a peripheral event or not. 0: COMPx event generation is disabled. 1: COMPx event generation is enabled. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 536 30.8.4 Interrupt Enable Clear This register allows the user to disable an interrupt without doing a read-modify-write operation. Changes in this register will also be reflected in the Interrupt Enable Set register (INTENSET). Name: INTENCLR Offset: 0x04 Reset: 0x00 Property: Write-Protected Bit 7 6 5 4 3 2 WIN0 1 0 COMP1 COMP0 Access R R R R/W R R R/W R/W Reset 0 0 0 0 0 0 0 0 z Bits 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. These bits will always return zero when read. z Bit 4 – WIN0: Window 0 Interrupt Enable Reading this bit returns the state of the Window 0 interrupt enable. 0: The Window 0 interrupt is disabled. 1: The Window 0 interrupt is enabled. Writing a zero to this bit has no effect. Writing a one to this bit disables the Window 0 interrupt. z Bits 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. These bits will always return zero when read. z Bits 1:0 – COMPx: Comparator x Interrupt Enable Reading this bit returns the state of the Comparator x interrupt enable. 0: The Comparator x interrupt is disabled. 1: The Comparator x interrupt is enabled. Writing a zero to this bit has no effect. Writing a one to this bit disables the Comparator x interrupt. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 537 30.8.5 Interrupt Enable Set This register allows the user to enable an interrupt without doing a read-modify-write operation. Changes in this register will also be reflected in the Interrupt Enable Clear register (INTENCLR). Name: INTENSET Offset: 0x05 Reset: 0x00 Property: Write-Protected Bit 7 6 5 4 3 2 WIN0 1 0 COMP1 COMP0 Access R R R R/W R R R/W R/W Reset 0 0 0 0 0 0 0 0 z Bits 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. These bits will always return zero when read. z WBit 4 – WIN0: Window 0 Interrupt Enable Reading this bit returns the state of the Window 0 interrupt enable. 0: The Window 0 interrupt is disabled. 1: The Window 0 interrupt is enabled. Writing a zero to this bit has no effect. Writing a one to this bit enables the Window 0 interrupt. z Bits 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. These bits will always return zero when read. z Bits 1:0 – COMPx: Comparator x Interrupt Enable Reading this bit returns the state of the Comparator x interrupt enable. 0: The Comparator x interrupt is disabled. 1: The Comparator x interrupt is enabled. Writing a zero to this bit has no effect. Writing a one to this bit will set the Ready interrupt bit and enable the Ready interrupt. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 538 30.8.6 Interrupt Flag Status and Clear Name: INTFLAG Offset: 0x06 Reset: 0x00 Property: – Bit 7 6 5 4 3 2 WIN0 1 0 COMP1 COMP0 Access R R R R/W R R R/W R/W Reset 0 0 0 0 0 0 0 0 z Bits 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. These bits will always return zero when read. z Bit 4 – WIN0: Window 0 This flag is set according to the Window 0 Interrupt Selection bit group in the WINCTRL register (WINCTRL.WINTSEL0) and will generate an interrupt if INTENCLR/SET.WIN0 is also one. Writing a zero to this bit has no effect. Writing a one to this bit clears the Window 0 interrupt flag. z Bits 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. These bits will always return zero when read. z Bits 1:0 – COMPx: Comparator x Reading this bit returns the status of the Comparator x interrupt flag. If comparator x is not implemented, COMPx always reads as zero. This flag is set according to the Interrupt Selection bit group in the Comparator x Control register (COMPCTRLx.INTSEL) and will generate an interrupt if INTENCLR/SET.COMPx is also one. Writing a zero to this bit has no effect. Writing a one to this bit clears the Comparator x interrupt flag. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 539 30.8.7 Status A Name: STATUSA Offset: 0x08 Reset: 0x00 Property: – Bit 7 6 5 4 3 2 WSTATE0[1:0] 1 0 STATE1 STATE0 Access R R R R R R R R Reset 0 0 0 0 0 0 0 0 z Bits 7:6 – 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. These bits will always return zero when read. z Bits 5:4 – WSTATE0[1:0]: Window 0 Current State These bits show the current state of the signal if the window 0 mode is enabled, according to Table 30-2. If the window 0 function is not implemented, WSTATE0 always reads as zero. Table 30-2. Window Mode Current State Value Name Description 0x0 ABOVE Signal is above window 0x1 INSIDE Signal is inside window 0x2 BELOW Signal is below window 0x3 – Reserved z Bits 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. These bits will always return zero when read. z Bits 1:0 – STATEx: Comparator x Current State This bit shows the current state of the output signal from COMPx. STATEx is valid only when STATUSB.READYx is one. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 540 30.8.8 Status B Name: STATUSB Offset: 0x09 Reset: 0x00 Property: – Bit 7 6 5 4 3 2 SYNCBUSY 1 0 READY1 READY0 Access R R R R R R R R Reset 0 0 0 0 0 0 0 0 z Bit 7 – SYNCBUSY: Synchronization Busy This bit is cleared when the synchronization of registers between the clock domains is complete. This bit is set when the synchronization of registers between clock domains is started. z Bits 6: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. These bits will always return zero when read. z Bits 1:0 – READYx: Comparator x Ready This bit is cleared when the comparator x output is not ready. This bit is set when the comparator x output is ready. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 541 30.8.9 Status C STATUSC is a copy of STATUSA (see STATUSA register), with the additional feature of automatically starting singleshot comparisons. A read of STATUSC will start a comparison on all comparators currently configured for single-shot operation. The read will stall the bus until all enabled comparators are ready. If a comparator is already busy with a comparison, the read will stall until the current comparison is compete, and a new comparison will not be started. Name: STATUSC Offset: 0x0A Reset: 0x00 Property: – Bit 7 6 5 4 3 2 WSTATE0[1:0] 1 0 STATE1 STATE0 Access R R R R R R R R Reset 0 0 0 0 0 0 0 0 z Bits 7:6 – 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. These bits will always return zero when read. z Bits 5:4 – WSTATE0[1:0]: Window 0 Current State These bits show the current state of the signal if the window 0 mode is enabled. If the window 0 function is not implemented, WSTATE0 always reads as zero. Table 30-3. Window Mode Current State Value Name Description 0x0 ABOVE Signal is above window 0x1 INSIDE Signal is inside window 0x2 BELOW Signal is below window 0x3 – Reserved z Bits 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. These bits will always return zero when read. z Bits 1:0 – STATEx: Comparator x Current State This bit shows the current state of the output signal from COMPx. If comparator x is not implemented, STATEx always reads as zero. STATEx is only valid when STATUSB.READYx is one. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 542 30.8.10 Window Control Name: WINCTRL Offset: 0x0C Reset: 0x00 Property: Synchronized, Write-Protected Bit 7 6 5 4 3 2 1 WINTSEL0[1:0] 0 WEN0 Access R R R R R R/W R/W R/W Reset 0 0 0 0 0 0 0 0 z Bits 7:3 – 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. These bits will always return zero when read. z Bits 2:1 – WINTSEL0: Window 0 Interrupt Selection These bits configure the interrupt mode for the comparator window 0 mode. Table 30-4. Window 0 Interrupt Selection Value Name Description 0x0 ABOVE Interrupt on signal above window 0x1 INSIDE Interrupt on signal inside window 0x2 BELOW Interrupt on signal below window 0x3 OUTSIDE Interrupt on signal outside window z Bit 0 – WEN0: Window 0 Mode Enable 0: Window mode is disabled for comparators 0 and 1. 1: Window mode is enabled for comparators 0 and 1. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 543 30.8.11 Scaler x Name: SCALERx Offset: 0x20+x*0x1 [x=0..1] Reset: 0x00 Property: Write-Protected Bit 7 6 5 4 3 2 1 0 VALUE[5:0] Access R R R/W R/W R/W R/W R/W R/W Reset 0 0 0 0 0 0 0 0 z Bits 7:6 – 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. These bits will always return zero when read. z Bits 5:0 – VALUE[5:0]: Scaler Value These bits define the scaling factor for channel x of the VDD voltage scaler. The output voltage, VSCALE, is: V DD ⋅ ( VALUE + 1 ) V SCALE = ------------------------------------------------64 Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 544 30.8.12 Comparator Control x The configuration of comparator x is protected while comparator x is enabled (COMPCTRLx.ENABLE = 1). Changes to the other bits in COMPCTRLx can only occur when COMPCTRLx.ENABLE is zero. Name: COMPCTRLx Offset: 0x10+x*0x4 [x=0..1] Reset: 0x00000000 Property: Write-Protected Bit 31 30 29 28 27 26 25 24 FLEN[2:0] Access R R R R R R/W R/W R/W Reset 0 0 0 0 0 0 0 0 23 22 21 20 19 18 17 16 Bit HYST OUT[1:0] Access R R R R R/W R R/W R/W Reset 0 0 0 0 0 0 0 0 Bit 15 14 13 12 11 10 9 8 SWAP Access MUXPOS[1:0] MUXNEG[2:0] R/W R R/W R/W R R/W R/W R/W Reset 0 0 0 0 0 0 0 0 Bit 7 6 5 4 3 2 1 0 SINGLE ENABLE INTSEL[1:0] SPEED[1:0] Access R R/W R/W R R/W R/W R/W R/W Reset 0 0 0 0 0 0 0 0 z Bits 31:27 – 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. These bits will always return zero when read. z Bits 26:24 – FLEN[2:0]: Filter Length These bits configure the filtering for comparator x. COMPCTRLx.FLEN can only be written while COMPCTRLx.ENABLE is zero. Table 30-5. Filter Length Value Name Description 0x0 OFF No filtering Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 545 Value Name Description 0x1 MAJ3 3-bit majority function (2 of 3) 0x2 MAJ5 5-bit majority function (3 of 5) 0x3-0x7 N/A Reserved z Bits 23:20 – 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. These bits will always return zero when read. z Bit 19 – HYST: Hysteresis Enable This bit indicates the hysteresis mode of comparator x. Hysteresis is available only for continuous mode (COMPCTRLx.SINGLE=0). COMPCTRLx.HYST can be written only while COMPCTRLx.ENABLE is zero. 0: Hysteresis is disabled. 1: Hysteresis is enabled. z Bit 18 – 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. This bit will always return zero when read. z Bits 17:16 – OUT[1:0]: Output These bits configure the output selection for comparator x. COMPCTRLx.OUT can be written only while COMPCTRLx.ENABLE is zero. Table 30-6. Output Selection Value Name Description 0x0 OFF The output of CMPn is not routed to the CMPn I/O port 0x1 ASYNC The asynchronous output of CMPn is routed to the CMPn I/O port 0x2 SYNC The synchronous output (including filtering) of CMPn is routed to the CMPn I/O port 0x3 N/A Reserved z Bit 15 – SWAP: Swap Inputs and Invert This bit swaps the positive and negative inputs to CMPx and inverts the output. This function can be used for offset cancellation. COMPCTRLx.SWAP can be written only while COMPCTRLx.ENABLE is zero. 0: The output of MUXPOS connects to the positive input, and the output of MUXNEG connects to the negative input. 1: The output of MUXNEG connects to the positive input, and the output of MUXPOS connects to the negative input. z Bit 14 – 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. This bit will always return zero when read. z Bits 13:12 – MUXPOS[1:0]: Positive Input MUX Selection These bits select which input will be connected to the positive input of comparator x. COMPCTRLx.MUXPOS can be written only while COMPCTRLx.ENABLE is zero. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 546 Table 30-7. Positive Input MUX Selection Value Name Description 0x0 PIN0 I/O pin 0 0x1 PIN1 I/O pin 1 0x2 PIN2 I/O pin 2 0x3 PIN3 I/O pin 3 z Bit 11 – 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. This bit will always return zero when read. z Bits 10:8 – MUXNEG[2:0]: Negative Input MUX Selection These bits select which input will be connected to the negative input of comparator x. COMPCTRLx.MUXNEG can only be written while COMPCTRLx.ENABLE is zero. Table 30-8. Negative Input MUX Selection Value Name Description 0x0 PIN0 I/O pin 0 0x1 PIN1 I/O pin 1 0x2 PIN2 I/O pin 2 0x3 PIN3 I/O pin 3 0x4 GND Ground 0x5 VSCALE VDD scaler 0x6 BANDGAP Internal bandgap voltage 0x7 DAC DAC output z 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. This bit will always return zero when read. z Bits 6:5 – INTSEL[1:0]: Interrupt Selection These bits select the condition for comparator x to generate an interrupt or event. COMPCTRLx.INTSEL can be written only while COMPCTRLx.ENABLE is zero. Table 30-9. Interrupt Selection Value Name Description 0x0 TOGGLE Interrupt on comparator output toggle 0x1 RISING Interrupt on comparator output rising 0x2 FALLING Interrupt on comparator output falling 0x3 EOC Interrupt on end of comparison (single-shot mode only) z Bit 4 – Reserved Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 547 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. This bit will always return zero when read. z Bits 3:2 – SPEED[1:0]: Speed Selection This bit indicates the speed/propagation delay mode of comparator x. COMPCTRLx.SPEED can be written only while COMPCTRLx.ENABLE is zero. Table 30-10. Speed Selection Value Name Description 0x0 LOW Low speed 0x1 HIGH High speed 0x2-0x3 Reserved z Bit 1 – SINGLE: Single-Shot Mode This bit determines the operation of comparator x. COMPCTRLx.SINGLE can be written only while COMPCTRLx.ENABLE is zero. 0: Comparator x operates in continuous measurement mode. 1: Comparator x operates in single-shot mode. z Bit 0 – ENABLE: Enable Writing a zero to this bit disables comparator x. Writing a one to this bit enables comparator x. After writing to this bit, the value read back will not change until the action initiated by the writing is complete. Due to synchronization, there is a latency of at least two GCLK_AC_DIG clock cycles from updating the register until the comparator is enabled/disabled. The bit will continue to read the previous state while the change is in progress. Writing a one to COMPCTRLx.ENABLE will prevent further changes to the other bits in COMPCTRLx. These bits remain protected until COMPCTRLx.ENABLE is written to zero and the write is synchronized. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 548 31. 31.1 DAC – Digital-to-Analog Converter Overview The Digital-to-Analog Converter (DAC) converts a digital value to a voltage. The DAC has one channel with 10-bit resolution, and it is capable of converting up to 350,000 samples per second (ksps). 31.2 Features z DAC with 10-bit resolution z Up to 350ksps conversion rate z Multiple trigger sources z High-drive capabilities z Output can be used as input to the Analog Comparator (AC) 31.3 Block Diagram Figure 31-1. DAC Block Diagram EVCTRL EVENT CONTROL EMPTY START DATABUF DATA output driver DAC10 VOUT CTRLA ADC CTRLB AC AVCC INT1V STATUS 31.4 VREFP Signal Description Signal Name Type Description VOUT Analog output DAC output VREFP Analog input External reference Refer to “I/O Multiplexing and Considerations” on page 15 for the pin mapping of this peripheral. One signal can be mapped on several pins. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 549 31.5 Product Dependencies In order to use this peripheral, other parts of the system must be configured correctly, as described below. 31.5.1 I/O Lines Using the DAC’s I/O lines requires the I/O pins to be configured using the port configuration (PORT). Refer to “PORT” on page 289 for details. 31.5.2 Power Management The DAC will continue to operate in any sleep mode where the selected source clock is running. The DAC interrupts can be used to wake up the device from sleep modes. The events can trigger other operations in the system without exiting sleep modes. Refer to “PM – Power Manager” on page 105 for details on the different sleep modes. 31.5.3 Clocks The DAC bus clock (CLK_DAC_APB) can be enabled and disabled in the Power Manager, and the default state of CLK_DAC_APB can be found in the Peripheral Clock Masking section in “PM – Power Manager” on page 105. A generic clock (GCLK_DAC) is required to clock the DAC. This clock must be configured and enabled in the Generic Clock Controller before using the DAC. Refer to “GCLK – Generic Clock Controller” on page 83 for details. This generic clock is asynchronous to the bus clock (CLK_DAC). Due to this asynchronicity, writes to certain registers will require synchronization between the clock domains. Refer to “Synchronization” on page 553 for further details. 31.5.4 DMA Not applicable. 31.5.5 Interrupts The interrupt request line is connected to the Interrupt Controller. Using the DAC interrupts requires the Interrupt Controller to be configured first. Refer to “Nested Vector Interrupt Controller” on page 28 for details. 31.5.6 Events The events are connected to the Event System. Refer to “EVSYS – Event System” on page 314 for details on how to configure the Event System. 31.5.7 Debug Operation When the CPU is halted in debug mode the DAC continues normal operation. If the DAC is configured in a way that requires it to be periodically serviced by the CPU through interrupts or similar, improper operation or data loss may result during debugging. 31.5.8 Register Access Protection All registers with write-access are optionally write-protected by the Peripheral Access Controller (PAC), except the following register: z Interrupt Flag Status and Clear register (INTFLAG) Write-protection is denoted by the Write-Protection property in the register description. When the CPU is halted in debug mode, all write-protection is automatically disabled. Write-protection does not apply for accesses through an external debugger. Refer to “PAC – Peripheral Access Controller” on page 31 for details. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 550 31.5.9 Analog Connections Not applicable. 31.6 Functional Description 31.6.1 Principle of Operation The Digital-to-Analog Converter (DAC) converts the digital value written to the Data register (DATA) into an analog voltage on the DAC output. By default, a conversion is started when new data is written to DATA, and the corresponding voltage is available on the DAC output after the conversion time. It is also possible to enable events from the Event System to trigger the conversion. 31.6.2 Basic Operation 31.6.2.1 Initialization Before enabling the DAC, it must be configured by selecting the voltage reference using the Reference Selection bits in the Control B register (CTRLB.REFSEL). 31.6.2.2 Enabling, Disabling and Resetting The DAC is enabled by writing a one to the Enable bit in the Control A register (CTRLA.ENABLE). The DAC is disabled by writing a zero to CTRLA.ENABLE. The DAC is reset by writing a one to the Software Reset bit in the Control A register (CTRLA.SWRST). All registers in the DAC will be reset to their initial state, and the DAC will be disabled. Refer to the CTRLA register for details. 31.6.2.3 Enabling the Output Buffer To enable the DAC output on the VOUT pin, the output driver must be enabled by writing a one to the External Output Enable bit in the Control B register (CTRLB.EOEN). The DAC output buffer provides a high-drive-strength output, and is capable of driving both resistive and capacitive loads. To minimize power consumption, the output buffer should be enabled only when external output is needed. 31.6.3 Additional Features 31.6.3.1 Conversion Range The conversion range is between GND and the selected DAC voltage reference. The default voltage reference is the internal 1V (INT1V) reference voltage. The other voltage reference options are the 3.3V analog supply voltage (AVCC = VDDANA) and the external voltage reference (VREFP). The voltage reference is selected by writing to the Reference Selection bits in the Control B register (CTRLB.REFSEL). The output voltage from the DAC can be calculated using the following formula: DATA V DAC = ----------------- ⋅ VREF 0x3FF 31.6.3.2 DAC as an Internal Reference The DAC output can be internally enabled as input to the analog comparator. This is enabled by writing a one to the Internal Output Enable bit in the Control B register (CTRLB.IOEN). It is possible to have the internal and external output enabled simultaneously. The DAC output can also be enabled as input to the Analog-to-Digital Converter. In this case, the output buffer must be enabled. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 551 31.6.3.3 Data Buffer The Data Buffer register (DATABUF) and the Data register (DATA) are linked together to form a two-stage FIFO. The DAC uses the Start Conversion event to load data from DATABUF into DATA and start a new conversion. The Start Conversion event is enabled by writing a one to the Start Event Input bit in the Event Control register (EVCTRL.STARTEI). If a Start Conversion event occurs when DATABUF is empty, an Underrun interrupt request is generated if the Underrun interrupt is enabled. If data are written to DATABUF when EVCTRL.STARTEI is zero, the previous DATABUF value is automatically transferred to DATA, and a new conversion is started. The DAC can generate a Data Buffer Empty event when DATABUF becomes empty and new data can be loaded to the buffer. The Data Buffer Empty event is enabled by writing a one to the Empty Event Output bit in the Event Control register (EVCTRL.EMPTYEO). A Data Buffer Empty interrupt request is generated if the Data Buffer Empty interrupt is enabled. 31.6.3.4 Voltage Pump When the DAC is used at operating voltages lower than 2.5V, the voltage pump must be enabled. This enabling is done automatically, depending on operating voltage. The voltage pump can be disabled by writing a one to the Voltage Pump Disable bit in the Control B register (CTRLB.VPD). This can be used to reduce power consumption when the operating voltage is above 2.5V. The voltage pump uses the asynchronous GCLK_DAC clock, and requires that the clock frequency be at least four times higher than the sampling period. 31.6.3.5 Sampling Period As there is no automatic indication that a conversion is done, the sampling period must be greater than or equal to the specified conversion time. 31.6.4 DMA Operation Not applicable. 31.6.5 Interrupts The DAC has the following interrupt sources: z Data Buffer Empty z Underrun z Synchronization Ready Each interrupt source has an interrupt flag associated with it. The interrupt flag in the Interrupt Flag Status and Clear register (INTFLAG) is set when the interrupt condition occurs. Each interrupt can be individually enabled by writing a one to the corresponding bit in the Interrupt Enable Set register (INTENSET), and disabled by writing a one to the corresponding bit in the Interrupt Enable Clear register (INTENCLR). An interrupt request is generated when the interrupt flag is set and the corresponding interrupt is enabled. The interrupt request remains active until the interrupt flag is cleared, the interrupt is disabled or the DAC is reset. See the register description for details on how to clear interrupt flags. The DAC has one common interrupt request line for all the interrupt sources. The user must read the INTFLAG register to determine which interrupt condition is present. Note that interrupts must be globally enabled for interrupt requests to be generated. Refer to “Nested Vector Interrupt Controller” on page 28 for details. 31.6.6 Events The DAC can generate the following output events: z Data Buffer Empty (EMPTY) Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 552 Writing a one to an Event Output bit in the Event Control register (EVCTRL.xxEO) enables the corresponding output event. Writing a zero to this bit disables the corresponding output event. Refer to “EVSYS – Event System” on page 314 for details on configuring the event system. The DAC can take the following actions on an input event: z Start Conversion (START) Writing a one to an Event Input bit in the Event Control register (EVCTRL.xxEI) enables the corresponding action on an input event. Writing a zero to this bit disables the corresponding action on input event. Note that if several events are connected to the DAC, the enabled action will be taken on any of the incoming events. Refer to “EVSYS – Event System” on page 314 for details on configuring the event system. 31.6.7 Sleep Mode Operation The generic clock for the DAC is running in idle sleep mode. If the Run In Standby bit in the Control A register (CTRLA.RUNSTDBY) is one, the DAC output buffer will keep its value in standby sleep mode. If CTRLA.RUNSTDBY is zero, the DAC output buffer will be disabled in standby sleep mode. 31.6.8 Synchronization Due to the asynchronicity between CLK_DAC_APB and GCLK_DAC, some registers must be synchronized when accessed. A register can require: z Synchronization when written z Synchronization when read z Synchronization when written and read z No synchronization When executing an operation that requires synchronization, the Synchronization Busy bit in the Status register (STATUS.SYNCBUSY) will be set immediately, and cleared when synchronization is complete. The Synchronization Ready interrupt can be used to signal when synchronization is complete. If an operation that requires synchronization is executed while STATUS.SYNCBUSY is one, the bus will be stalled. All operations will complete successfully, but the CPU will be stalled and interrupts will be pending as long as the bus is stalled. The following bits need synchronization when written: z Software Reset bit in the Control A register (CTRLA.SWRST) z Enable bit in the Control A register (CTRLA.ENABLE) z All bits in the Data register (DATA) z All bits in the Data Buffer register (DATABUF) Synchronization is denoted by the Write-Synchronized property in the register description. The following bits need synchronization when read: z All bits in the Data register (DATA) Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 553 31.7 Register Summary Offset Name Bit Pos. 0x00 CTRLA 7:0 0x01 CTRLB 7:0 0x02 EVCTRL 7:0 0x03 TEST 7:0 0x04 INTENCLR 7:0 SYNCRDY EMPTY UNDERRUN 0x05 INTENSET 7:0 SYNCRDY EMPTY UNDERRUN 0x06 INTFLAG 7:0 SYNCRDY EMPTY UNDERRUN 0x07 STATUS 7:0 0x08 7:0 REFSEL[1:0] VPD RUNSTDBY ENABLE SWRST LEFTADJ IOEN EOEN EMPTYEO STARTEI TESTEN SYNCBUSY DATA[7:0] DATA (1) 0x09 15:8 0x0A Reserved 0x0B Reserved 0x0C 7:0 DATA[9:8] DATABUF[7:0] DATABUF (2) 0x0D 15:8 0x0E Reserved 0x0F Reserved DATABUF[9:8] 1. This register will have a different appearance depending on the value of CTRLB.LEFTADJ. Here, the right-adjusted form of DATA is shown. 2. This register will have a different appearance depending on the value of CTRLB.LEFTADJ. Here, the right-adjusted form of DATABUF is shown. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 554 31.8 Register Description Registers can be 8, 16 or 32 bits wide. Atomic 8-, 16- and 32-bit accesses are supported. In addition, the 8-bit quarters and 16-bit halves of a 32-bit register and the 8-bit halves of a 16-bit register can be accessed directly. Some registers are optionally write-protected by the Peripheral Access Controller (PAC). Write-protection is denoted by the Write-Protected property in each individual register description. Refer to “Register Access Protection” on page 550 for details. Some registers require synchronization when read and/or written. Synchronization is denoted by the Synchronized property in each individual register description. Refer to “Synchronization” on page 553 for details. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 555 31.8.1 Control A Name: CTRLA Offset: 0x0 Reset: 0x00 Property: Write-Protected, Write-Synchronized Bit 7 6 5 4 3 2 1 0 RUNSTDBY ENABLE SWRST Access R R R R R R/W R/W R/W Reset 0 0 0 0 0 0 0 0 z Bits 7:3 – 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. These bits will always return zero when read. z Bit 2 – RUNSTDBY: Run in Standby 0: The DAC output buffer is disabled in standby sleep mode. 1: The DAC output buffer can be enabled in standby sleep mode. This bit is not synchronized. z Bit 1 – ENABLE: Enable 0: The peripheral is disabled or being disabled. 1: The peripheral is enabled or being enabled. Due to synchronization, there is delay from writing CTRLA.ENABLE until the peripheral is enabled/disabled. The value written to CTRL.ENABLE will read back immediately and the Synchronization Busy bit in the Status register (STATUS.SYNCBUSY) will be set. STATUS.SYNCBUSY is cleared when the operation is complete. z Bit 0 – SWRST: Software Reset 0: There is no reset operation ongoing. 1: The reset operation is ongoing. Writing a zero to this bit has no effect. Writing a one to this bit resets the all registers in the DAC to their initial state, and the DAC will be disabled. Writing a one to CTRLA.SWRST will always take precedence, meaning that all other writes in the same write operation will be discarded. Due to synchronization, there is a delay from writing CTRLA.SWRST until the reset is complete. CTRLA.SWRST and STATUS.SYNCBUSY will both be cleared when the reset is complete. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 556 31.8.2 Control B Name: CTRLB Offset: 0x1 Reset: 0x00 Property: Write-Protected Bit 7 6 5 4 REFSEL[1:0] Access Reset z 3 2 1 0 VPD LEFTADJ IOEN EOEN R/W R/W R R R/W R/W R/W R/W 0 0 0 0 0 0 0 0 Bits 7:6 – REFSEL[1:0]: Reference Selection These bits select the reference voltage for the DAC according to Table 31-1. Table 31-1. Reference Selection REFSEL[1:0] Reference Selection Description 0x0 INT1V Internal 1.0V reference 0x1 AVCC AVCC 0x2 VREFP External reference 0x3 Reserved z Bits 5:4 – 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. These bits will always return zero when read. z Bit 3 – VPD: Voltage Pump Disable This bit controls the behavior of the voltage pump. 0: Voltage pump is turned on/off automatically. 1: Voltage pump is disabled. z Bit 2 – LEFTADJ: Left Adjusted Data This bit controls how the 10-bit conversion data is adjusted in the Data and Data Buffer registers. 0: DATA and DATABUF registers are right-adjusted. 1: DATA and DATABUF registers are left-adjusted. z Bit 1 – IOEN: Internal Output Enable 0: Internal DAC output not enabled. 1: Internal DAC output enabled to be used by the AC. z Bit 0 – EOEN: External Output Enable 0: The DAC output is turned off. 1: The high-drive output buffer drives the DAC output to the VOUT pin. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 557 31.8.3 Event Control Name: EVCTRL Offset: 0x2 Reset: 0x00 Property: Write-Protected Bit 7 6 5 4 3 2 1 0 EMPTYEO STARTEI Access R R R R R R R/W R/W Reset 0 0 0 0 0 0 0 0 z Bits 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. These bits will always return zero when read. z Bit 1 – EMPTYEO: Data Buffer Empty Event Output This bit indicates whether or not the Data Buffer Empty event is enabled and will be generated when the Data Buffer register is empty. 0: Data Buffer Empty event is disabled and will not be generated. 1: Data Buffer Empty event is enabled and will be generated. z Bit 0 – STARTEI: Start Conversion Event Input This bit indicates whether or not the Start Conversion event is enabled and data are loaded from the Data Buffer register to the Data register upon event reception. 0: A new conversion will not be triggered on an incoming event. 1: A new conversion will be triggered on an incoming event. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 558 31.8.4 Test Name: TEST Offset: 0x3 Reset: 0x00 Property: Write-Protected Bit 7 6 5 4 3 2 1 0 TESTEN Access R R R R R R R R/W Reset 0 0 0 0 0 0 0 0 z Bits 7:1 – 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. These bits will always return zero when read. z Bit 0 – TESTEN: Test Enable If the TESTEN bit in the test register is written to one, the DAC output buffer is bypassed and an unbuffered DAC output is connected to the VOUT pad. This bit can be written only in test mode. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 559 31.8.5 Interrupt Enable Clear This register allows the user to disable an interrupt without doing a read-modify-write operation. Changes in this register will also be reflected in the Interrupt Enable Set register (INTENSET). Name: INTENCLR Offset: 0x4 Reset: 0x00 Property: Write-Protected Bit 7 6 5 4 3 2 1 0 SYNCRDY EMPTY UNDERRUN Access R R R R R R/W R/W R/W Reset 0 0 0 0 0 0 0 0 z Bits 7:3 – 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. These bits will always return zero when read. z Bit 2 – SYNCRDY: Synchronization Ready Interrupt Enable 0: The Synchronization Ready interrupt is disabled. 1: The Synchronization Ready interrupt is enabled. Writing a zero to this bit has no effect. Writing a one to this bit will clear the Synchronization Ready Interrupt Enable bit, which disables the Synchronization Ready interrupt. z Bit 1 – EMPTY: Data Buffer Empty Interrupt Enable 0: The Data Buffer Empty interrupt is disabled. 1: The Data Buffer Empty interrupt is enabled. Writing a zero to this bit has no effect. Writing a one to this bit will clear the Data Buffer Empty Interrupt Enable bit, which disables the Data Buffer Empty interrupt. z Bit 0 – UNDERRUN: Underrun Interrupt Enable 0: The Underrun interrupt is disabled. 1: The Underrun interrupt is enabled. Writing a zero to this bit has no effect. Writing a one to this bit will clear the Underrun Interrupt Enable bit, which disables the Underrun interrupt. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 560 31.8.6 Interrupt Enable Set This register allows the user to enable an interrupt without doing a read-modify-write operation. Changes in this register will also be reflected in the Interrupt Enable Clear register (INTENCLR). Name: INTENSET Offset: 0x5 Reset: 0x00 Property: Write-Protected Bit 7 6 5 4 3 2 1 0 SYNCRDY EMPTY UNDERRUN Access R R R R R R/W R/W R/W Reset 0 0 0 0 0 0 0 0 z Bits 7:3 – 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. These bits will always return zero when read. z Bit 2 – SYNCRDY: Synchronization Ready Interrupt Enable 0: The Synchronization Ready interrupt is disabled. 1: The Synchronization Ready interrupt is enabled. Writing a zero to this bit has no effect. Writing a one to this bit will set the Synchronization Ready Interrupt Enable bit, which enables the Synchronization Ready interrupt. z Bit 1 – EMPTY: Data Buffer Empty Interrupt Enable 0: The Data Buffer Empty interrupt is disabled. 1: The Data Buffer Empty interrupt is enabled. Writing a zero to this bit has no effect. Writing a one to this bit will set the Data Buffer Empty Interrupt Enable bit, which enables the Data Buffer Empty interrupt. z Bit 0 – UNDERRUN: Underrun Interrupt Enable 0: The Underrun interrupt is disabled. 1: The Underrun interrupt is enabled. Writing a zero to this bit has no effect. Writing a one to this bit will set the Underrun Interrupt Enable bit, which enables the Underrun interrupt. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 561 31.8.7 Interrupt Flag Status and Clear Name: INTFLAG Offset: 0x6 Reset: 0x00 Property: Write-Protected Bit 7 6 5 4 3 2 1 0 SYNCRDY EMPTY UNDERRUN Access R R R R R R/W R/W R/W Reset 0 0 0 0 0 0 0 0 z Bits 7:3 – 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. These bits will always return zero when read. z Bit 2 – SYNCRDY: Synchronization Ready This flag is cleared by writing a one to the flag. This flag is set on a 1-to-0 transition of the Synchronization Busy bit in the Status register (STATUS.SYNCBUSY), except when the transition is caused by an enable or a software reset, and will generate an interrupt request if INTENCLR/SET.READY is one. Writing a zero to this bit has no effect. Writing a one to this bit will clear the Synchronization Ready interrupt flag. z Bit 1 – EMPTY: Data Buffer Empty This flag is cleared by writing a one to the flag or by writing new data to DATABUF. This flag is set when data is transferred from DATABUF to DATA, and the DAC is ready to receive new data in DATABUF, and will generate an interrupt request if INTENCLR/SET.EMPTY is one. Writing a zero to this bit has no effect. Writing a one to this bit will clear the Data Buffer Empty interrupt flag. z Bit 0 – UNDERRUN: Underrun This flag is cleared by writing a one to the flag. This flag is set when a start conversion event occurs when DATABUF is empty, and will generate an interrupt request if INTENCLR/SET.UNDERRUN is one. Writing a zero to this bit has no effect. Writing a one to this bit will clear the Underrun interrupt flag. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 562 31.8.8 Status Name: STATUS Offset: 0x7 Reset: 0x00 Property: Read-Synchronized Bit 7 6 5 4 3 2 1 0 SYNCBUSY Access R R R R R R R R Reset 0 0 0 0 0 0 0 0 z Bit 7 – SYNCBUSY: Synchronization Busy Status This bit is cleared when the synchronization of registers between the clock domains is complete. This bit is set when the synchronization of registers between clock domains is started. z Bits 6:0 – 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. These bits will always return zero when read. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 563 31.8.9 Data This register contains the 10-bit value that is converted to a voltage by the DAC. The adjustment of these 10 bits within the 16-bit register is controlled by CTRLB.LEFTADJ. Mode: Right Adjusted Name: DATA Offset: 0x8 Reset: 0x0000 Property: Write-Synchronized, Read-Synchronized, Write-Protected Bit 15 14 13 12 11 10 9 8 DATA[9:8] Access R R R R R R R/W R/W Reset 0 0 0 0 0 0 0 0 Bit 7 6 5 4 3 2 1 0 DATA[7:0] Access Reset R/W R/W R/W R/W R/W R/W R/W R/W 0 0 0 0 0 0 0 0 z Bits 15:10 – 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. These bits will always return zero when read. z Bits 9:0 – DATA[9:0]: Data These bits are the right-adjusted 10-bit value to convert (CTRLB.LEFTADJ is zero). Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 564 Mode: Left Adjusted Name: DATA Offset: 0x8 Reset: 0x0000 Property: Write-Synchronized, Read-Synchronized, Write-Protected Bit 15 14 13 12 11 10 9 8 DATA[9:2] Access R/W R/W R/W R/W R/W R/W R/W R/W Reset 0 0 0 0 0 0 0 0 Bit 7 6 5 4 3 2 1 0 R/W R/W R R R R R R 0 0 0 0 0 0 0 0 DATA[1:0] Access Reset z Bits 15:6 – DATA[9:0]: Data These bits are the left-adjusted 10-bit value to convert (CTRLB.LEFTADJ is one). z Bits 5:0 – 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. These bits will always return zero when read. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 565 31.8.10 Data Buffer This register contains the 10-bit value that is transferred to DATA and converted to a voltage by the DAC. The adjustment of these 10 bits within the 16-bit register is controlled by CTRLB.LEFTADJ. Mode: Right Adjusted Name: DATABUF Offset: 0xC Reset: 0x0000 Property: Write-Synchronized, Write-Protected Bit 15 14 13 12 11 10 9 8 DATABUF[9:8] Access R R R R R R R/W R/W Reset 0 0 0 0 0 0 0 0 Bit 7 6 5 4 3 2 1 0 DATABUF[7:0] Access Reset R/W R/W R/W R/W R/W R/W R/W R/W 0 0 0 0 0 0 0 0 z Bits 15:10 – 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. These bits will always return zero when read. z Bits 9:0 – DATABUF[9:0]: Data Buffer These bits are the right-adjusted 10-bit data buffer value (CTRLB.LEFTADJ is zero). Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 566 Mode: Left Adjusted Name: DATABUF Offset: 0xC Reset: 0x0000 Property: Write-Synchronized, Write-Protected Bit 15 14 13 12 11 10 9 8 DATABUF[9:2] Access R/W R/W R/W R/W R/W R/W R/W R/W Reset 0 0 0 0 0 0 0 0 Bit 7 6 5 4 3 2 1 0 R/W R/W R R R R R R 0 0 0 0 0 0 0 0 DATABUF[1:0] Access Reset z Bits 15:6 – DATABUF[9:0]: Data Buffer These bits are the left-adjusted 10-bit data buffer value (CTRLB.LEFTADJ is one). z Bits 5:0 – 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. These bits will always return zero when read. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 567 32. PTC - Peripheral Touch Controller 32.1 Overview The PTC is intended for acquiring capacitive touch sensor and capacitive proximity sensor signals. The external capacitive touch sensor is typically formed on a PCB, and the sensor electrodes are connected to the analog charge integrator of the PTC via device I/O pins. The PTC supports mutual capacitance sensors organized as capacitive touch matrices in different X-Y configurations, including indium tin oxide (ITO) sensor grids. The PTC requires one pin per X line and one pin per Y line. No external components are needed. In self-capacitance mode, the PTC requires just one pin with an X-line driver for each self-capacitance sensor. 32.2 Features z Implements low-power, high-sensitivity, environmentally robust capacitive touch buttons, sliders, wheels and proximity sensing z Supports mutual capacitance and self-capacitance sensing z z 16 buttons in self-capacitance mode 256 buttons in mutual-capacitance mode z One pin per electrode – no external components z Load compensating charge sensing z Parasitic capacitance compensation and adjustable gain for superior sensitivity z Zero drift over the temperature and VDD range z No need for temperature or VDD compensation z Single-shot and free-running charge measurement z Hardware noise filtering and noise signal desynchronization for high conducted immunity z Selectable channel change delay z Allows choosing the settling time on a new channel, as required z Acquisition-start triggered by command or interrupt event z Interrupt on acquisition-complete z To be used in combination with the Atmel® provided QTouch® Library firmware and QTouch Composer tool 32.3 Signal Description Name Type Description X[n:0] Analog input DAC output Y[m:0] Analog input External reference Note: 1. The number of X and Y lines are device dependent. Refer to “Configuration Summary” on page 3 for details. Refer to “I/O Multiplexing and Considerations” on page 15 for details on the pin mapping for this peripheral. One signal can be mapped on several pins. 32.4 Product Dependencies In order to access the PTC, the user must use the QTouch Composer tool to configure and link the QTouch Library firmware with the application code. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 568 33. Packaging Information 33.1 Thermal Considerations 33.1.1 Thermal Resistance Data Table 33-1 summarizes the thermal resistance data depending on the package. Table 33-1. Thermal Resistance Data Package Type θJA θJC 32-pin TQFP 68°C/W 25.8°C/W 48-pin TQFP 78.8°C/W 12.3°C/W 64-pin TQFP 66.7°C/W 11.9°C/W 32-pin QFN 37.2°C/W 3.1°C/W 48-pin QFN 33°C/W 11.4°C/W 64-pin QFN 33.5°C/W 11.2°C/W 33.1.2 Junction Temperature The average chip-junction temperature, TJ, in °C can be obtained from the following equations: Equation 1 T J = T A + ( P D × θ JA ) Equation 2 T J = T A + ( P D × ( θ HEATSINK + θ JC ) ) where: z θJA = package thermal resistance, Junction-to-ambient (°C/W), provided in Table 33-1 z θJC = package thermal resistance, Junction-to-case thermal resistance (°C/W), provided in Table 33-1 z θHEATSINK = cooling device thermal resistance (°C/W), provided in the device datasheet z PD = device power consumption (W) z TA = ambient temperature (°C) From “Equation 1” , the user can derive the estimated lifetime of the chip and decide if a cooling device is necessary or not. If a cooling device is to be fitted on the chip, “Equation 2” should be used to compute the resulting average chipjunction temperature TJ in °C. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 569 33.2 Package Drawings 33.2.1 64-pin TQFP Table 33-2. Device and Package Maximum Weight 300 mg Table 33-3. Package Characteristics Moisture Sensitivity Level MSL3 Table 33-4. Package Reference JEDEC Drawing Reference MS-026 JESD97 Classification E3 Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 570 33.2.2 64-pin QFN Table 33-5. Device and Package Maximum Weight 200 mg Table 33-6. Package Characteristics Moisture Sensitivity Level MSL3 Table 33-7. Package Reference JEDEC Drawing Reference MO-220 JESD97 Classification E3 Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 571 33.2.3 48-pin TQFP Table 33-8. Device and Package Maximum Weight 140 mg Table 33-9. Package Characteristics Moisture Sensitivity Level MSL3 Table 33-10. Package Reference JEDEC Drawing Reference MS-026 JESD97 Classification E3 Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 572 33.2.4 48-pin QFN Table 33-11. Device and Package Maximum Weight 140 mg Table 33-12. Package Characteristics Moisture Sensitivity Level MSL3 Table 33-13. Package Reference JEDEC Drawing Reference MO-220 JESD97 Classification E3 Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 573 33.2.5 32-pin TQFP Table 33-14. Device and Package Maximum Weight TBD mg Table 33-15. Package Characteristics Moisture Sensitivity Level MSL3 Table 33-16. Package Reference JEDEC Drawing Reference MS-026 JESD97 Classification E3 Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 574 33.2.6 32-pin QFN Table 33-17. Device and Package Maximum Weight TBD mg Table 33-18. Package Characteristics Moisture Sensitivity Level MSL3 Table 33-19. Package Reference JEDEC Drawing Reference MO-220 JESD97 Classification E3 Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 575 33.3 Soldering Profile Table Table 33-20 gives the recommended soldering profile from J-STD-20. Table 33-20. Soldering Profile Profile Feature Green Package Average Ramp-up Rate (217°C to peak) 3°C/s max. Preheat Temperature 175°C ±25°C 150-200°C Time Maintained Above 217°C Time within 5°C of Actual Peak Temperature Peak Temperature Range Ramp-down Rate Time 25°C to Peak Temperature 60-150s 30s 260°C 6°C/s max 8 minutes max. A maximum of three reflow passes is allowed per component. 177038 Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 576 34. Errata 34.1 Revision A 34.1.1 Device 1 - If APB clock is stopped and GCLK clock is running, APB read access to read-synchronized registers will freeze the system. The CPU and the DAP AHB-AP are stalled, as a consequence debug operation is impossible. 10416 Fix/Workaround: Do not make read access to read-synchronized registers when APB clock is stopped and GCLK is running. To recover from this situation, power cycle the device or reset the device using the RESETN pin. 34.1.2 GCLK 1 - When the GCLK generator is enabled(GENCTRL.GENEN=1), set as output (GENCTRL.OE=1) and use a division factor of one (GENDIV.DIV=1 or 0), the GCLK_IO can be not set as the expected GENCTRL.OOV value after disabling the GCLK generator (GENCTRL.GENEN=0). 10716 Fix/Workaround Disable the OE request of the GCLK generator (GENCTRL.OE=0) before disabling the GCLK generator (GENCTRL.GENEN=0). 2 - The GCLK Generator clock is stuck when disabling the generator and changing the division factor from one to a different value while the GCLK generator is set as output. 10686 When the GCLK generator is enabled(GENCTRL.GENEN=1), set as output (GENCTRL.OE=1) and use a division factor of one (GENDIV.DIV=1 or 0), if the division factor is written to a value different of one or zero after disabling the GCLK generator (GENCTRL.GENEN=0), the GCLK generator will be stuck. Fix/Workaround Disable the OE request of the GCLK generator (GENCTRL.OE=0) before disabling the GCLK generator (GENCTRL.GENEN=0). 3 - Lockup in GCLK Software Reset when a GCLK is locked 10645 When a GCLK is locked and the generator used by the locked GCLK is not the GCLK generator 1, issuing a GCLK software reset will lock up the GCLK with the SYNCBUSY flag always set. Fix/Workaround Do not issue a GCLK SWRST or map GCLK generator 1 to ""locked"" GCLKs. Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 577 34.1.3 DFLL48M 1 - The workaround for this issue would be to wait for lock before enabling the oob interrupt. This way we will still manage to track if the fine value goes out of bounds due to temperature changes. 10669 34.1.4 EVSYS 1 - Changing the selected generator of a channel can trigger a spurious interrupt/event. 10443 Fix/Workaround: To change the generator of a channel, first write with EDGESEL written to zero, then perform a second write with EDGESEL written to its target value. 34.1.5 SERCOM 1 - When the SERCOM is in slave SPI mode, the BUFOVF flag is not automatically cleared when CTRLB.RXEN is set to zero. 10563 Fix/Workaround: The flag must be manually cleared by SW. 34.1.6 ADC 1 - No automatic right shift over 16 samples. 10530 Fix/Workaround: To right shift more than 16 samples, one must use ADJRES bits to do a manual right shift. The ADJRES limit at 7 right shift. So, for 1024 samples you can obtain a result on 15 bits minimum. 34.1.7 Flash 1 - When cache read mode is set to deterministic (READMODE=2), setting CACHEDIS=1 doesn’t gives 0 wait state read time on NVM. This gives lower CPU performances. 10830 Fix/Workaround: When disabling the cache (CTRLB.CACHEDIS=1), the user must also set READMODE to 0 (CTRLB.CACHEDIS=0). 2 - When NVMCTRL issues erase or write commands CPU hardfault exception may occur. Fix/Workaround: Either turn off cache before issuing flash commands or write 0x1 to NVMCTRL CTRLB.READMODE to set the cache LOW_POWER mode. 10804 Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 578 35. Datasheet Revision History Please note that the referring page numbers in this section are referred to this document. The referring revision in this section are referring to the document revision. 35.1 Rev. A – 06/2013 1. Initial revision Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 579 Table of Contents Description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 Features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 1. Configuration Summary . . . . . . . . . . . . . . . . . 3 2. Ordering Information SAM D20 . . . . . . . . . . . 4 2.1 2.2 2.3 Ordering Information SAM D20E. . . . . . . . . . . . . . 4 Ordering Information SAM D20G . . . . . . . . . . . . . 5 Ordering Information SAM D20J . . . . . . . . . . . . . . 6 3. About This Document . . . . . . . . . . . . . . . . . . . 7 3.1 3.2 Conventions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 Acronyms and Abbreviations. . . . . . . . . . . . . . . . . 8 4. Block Diagram . . . . . . . . . . . . . . . . . . . . . . . 11 5. Pinout Diagrams . . . . . . . . . . . . . . . . . . . . . . 12 5.1 5.2 5.3 SAM D20J . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 SAM D20G . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 SAM D20E. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14 6. I/O Multiplexing and Considerations . . . . . . 15 6.1 6.2 Multiplexed Signals . . . . . . . . . . . . . . . . . . . . . . . 15 Other Functions. . . . . . . . . . . . . . . . . . . . . . . . . . 17 7. Signal Descriptions List . . . . . . . . . . . . . . . . 18 8. Power Supply and Start-Up Considerations . 20 8.1 8.2 8.3 8.4 9. Power Domain Overview. . . . . . . . . . . . . . . . . . . Power Supply Considerations . . . . . . . . . . . . . . . Start-Up Considerations . . . . . . . . . . . . . . . . . . . Power-On Reset and Brown-Out Detector . . . . . 20 20 22 22 . . . . . . . . . . . . . . . . . . . . . Product Mapping 23 10. Memories . . . . . . . . . . . . . . . . . . . . . . . . . . . 24 10.1 10.2 10.3 10.4 Embedded Memories . . . . . . . . . . . . . . . . . . . . . Physical Memory Map . . . . . . . . . . . . . . . . . . . . . Non-Volatile Memory (NVM) User Row Mapping NVM Software Calibration Row Mapping . . . . . . 24 24 25 26 11. Processor and Architecture . . . . . . . . . . . . . 27 11.1 11.2 11.3 11.4 11.5 Cortex-M0+ Processor . . . . . . . . . . . . . . . . . . . . Nested Vector Interrupt Controller. . . . . . . . . . . . High-Speed Bus Matrix . . . . . . . . . . . . . . . . . . . . AHB-APB Bridge . . . . . . . . . . . . . . . . . . . . . . . . . PAC – Peripheral Access Controller . . . . . . . . . . 27 28 29 31 31 12. Peripherals Configuration Overview . . . . . . . 39 Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 580 13. DSU – Device Service Unit . . . . . . . . . . . . . .41 13.1 13.2 13.3 13.4 13.5 13.6 13.7 13.8 13.9 13.10 13.11 13.12 13.13 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Features. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Block Diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . Signal Description. . . . . . . . . . . . . . . . . . . . . . . . Product Dependencies . . . . . . . . . . . . . . . . . . . . Debug Operation . . . . . . . . . . . . . . . . . . . . . . . . . Chip-Erase. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Programming . . . . . . . . . . . . . . . . . . . . . . . . . . . . Intellectual Property Protection . . . . . . . . . . . . . . Device Identification. . . . . . . . . . . . . . . . . . . . . . . Functional Description . . . . . . . . . . . . . . . . . . . . . Register Summary . . . . . . . . . . . . . . . . . . . . . . . . Register Description . . . . . . . . . . . . . . . . . . . . . . 41 41 41 42 42 43 44 44 45 46 47 52 55 14. Clock System . . . . . . . . . . . . . . . . . . . . . . . . .77 14.1 14.2 14.3 14.4 14.5 14.6 14.7 Clock Distribution. . . . . . . . . . . . . . . . . . . . . . . . . Synchronous and Asynchronous Clocks . . . . . . . Register Synchronization. . . . . . . . . . . . . . . . . . . Enabling a Peripheral . . . . . . . . . . . . . . . . . . . . . On-demand, Clock Requests. . . . . . . . . . . . . . . . Power Consumption vs Speed . . . . . . . . . . . . . . Clocks after Reset . . . . . . . . . . . . . . . . . . . . . . . . 77 78 78 81 81 82 82 15. GCLK – Generic Clock Controller . . . . . . . . .83 15.1 15.2 15.3 15.4 15.5 15.6 15.7 15.8 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Features. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Block Diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . Signal Description . . . . . . . . . . . . . . . . . . . . . . . . Product Dependencies . . . . . . . . . . . . . . . . . . . . Functional Description . . . . . . . . . . . . . . . . . . . . . Register Summary . . . . . . . . . . . . . . . . . . . . . . . . Register Description . . . . . . . . . . . . . . . . . . . . . . 83 83 83 84 84 85 90 91 16. PM – Power Manager . . . . . . . . . . . . . . . . .105 16.1 16.2 16.3 16.4 16.5 16.6 16.7 16.8 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Features. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Block Diagram . . . . . . . . . . . . . . . . . . . . . . . . . . Signal Description . . . . . . . . . . . . . . . . . . . . . . . Product Dependencies . . . . . . . . . . . . . . . . . . . Functional Description . . . . . . . . . . . . . . . . . . . . Register Summary . . . . . . . . . . . . . . . . . . . . . . . Register Description . . . . . . . . . . . . . . . . . . . . . 105 105 106 106 106 108 115 117 17. SYSCTRL – System Controller . . . . . . . . . .132 17.1 17.2 17.3 17.4 17.5 17.6 17.7 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Features. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Block Diagram . . . . . . . . . . . . . . . . . . . . . . . . . . Signal Description . . . . . . . . . . . . . . . . . . . . . . . Product Dependencies . . . . . . . . . . . . . . . . . . . Functional Description . . . . . . . . . . . . . . . . . . . . Register Summary . . . . . . . . . . . . . . . . . . . . . . . 132 132 133 134 134 135 144 Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 581 17.8 Register Description . . . . . . . . . . . . . . . . . . . . . 146 18. WDT – Watchdog Timer . . . . . . . . . . . . . . .184 18.1 18.2 18.3 18.4 18.5 18.6 18.7 18.8 18.9 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 184 Features. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 184 Block Diagram . . . . . . . . . . . . . . . . . . . . . . . . . . 184 Signal Description . . . . . . . . . . . . . . . . . . . . . . . 185 Product Dependencies . . . . . . . . . . . . . . . . . . . 185 Functional Description . . . . . . . . . . . . . . . . . . . . 186 Register Summary . . . . . . . . . . . . . . . . . . . . . . . 191 Register Description . . . . . . . . . . . . . . . . . . . . . 192 Asynchronous Watchdog Clock Characterization 202 19. RTC – Real-Time Counter . . . . . . . . . . . . .203 19.1 19.2 19.3 19.4 19.5 19.6 19.7 19.8 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Features. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Block Diagram . . . . . . . . . . . . . . . . . . . . . . . . . . Signal Description . . . . . . . . . . . . . . . . . . . . . . . Product Dependencies . . . . . . . . . . . . . . . . . . . Functional Description . . . . . . . . . . . . . . . . . . . . Register Summary . . . . . . . . . . . . . . . . . . . . . . . Register Description . . . . . . . . . . . . . . . . . . . . . 203 203 203 204 204 205 211 214 20. EIC – External Interrupt Controller . . . . . . . .247 20.1 20.2 20.3 20.4 20.5 20.6 20.7 20.8 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Features. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Block Diagram . . . . . . . . . . . . . . . . . . . . . . . . . . Signal Description . . . . . . . . . . . . . . . . . . . . . . . Product Dependencies . . . . . . . . . . . . . . . . . . . Functional Description . . . . . . . . . . . . . . . . . . . . Register Summary . . . . . . . . . . . . . . . . . . . . . . . Register Description . . . . . . . . . . . . . . . . . . . . . 247 247 247 248 248 249 253 254 21. NVMCTRL – Non-Volatile Memory Controller 266 21.1 21.2 21.3 21.4 21.5 21.6 21.7 21.8 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Features. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Block Diagram . . . . . . . . . . . . . . . . . . . . . . . . . . Signal Description . . . . . . . . . . . . . . . . . . . . . . . Product Dependencies . . . . . . . . . . . . . . . . . . . Functional Description . . . . . . . . . . . . . . . . . . . . Register Summary . . . . . . . . . . . . . . . . . . . . . . Register Description . . . . . . . . . . . . . . . . . . . . . 266 266 266 266 267 267 274 275 22. PORT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .289 22.1 22.2 22.3 22.4 22.5 22.6 22.7 22.8 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Features. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Block Diagram . . . . . . . . . . . . . . . . . . . . . . . . . . Signal Description . . . . . . . . . . . . . . . . . . . . . . . Product Dependencies . . . . . . . . . . . . . . . . . . . Functional Description . . . . . . . . . . . . . . . . . . . . Register Summary . . . . . . . . . . . . . . . . . . . . . . . Register Description . . . . . . . . . . . . . . . . . . . . . 289 289 290 290 290 292 297 299 Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 582 23. EVSYS – Event System . . . . . . . . . . . . . . . .314 23.1 23.2 23.3 23.4 23.5 23.6 23.7 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Features. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Block Diagram . . . . . . . . . . . . . . . . . . . . . . . . . . Signal Description . . . . . . . . . . . . . . . . . . . . . . . Product Dependencies . . . . . . . . . . . . . . . . . . . Functional Description . . . . . . . . . . . . . . . . . . . . Register Summary 314 314 315 315 315 316 23.8 321 Register Description . . . . . . . . . . . . . . . . . . . . . 322 24. SERCOM – Serial Communication Interface 337 24.1 24.2 24.3 24.4 24.5 24.6 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Features. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Block Diagram . . . . . . . . . . . . . . . . . . . . . . . . . . Signal Description . . . . . . . . . . . . . . . . . . . . . . . Product Dependencies . . . . . . . . . . . . . . . . . . . Functional Description . . . . . . . . . . . . . . . . . . . . 337 337 337 337 338 339 25. SERCOM USART – SERCOM Universal Synchronous and Asynchronous Receiver and Transmitter 345 25.1 25.2 25.3 25.4 25.5 25.6 25.7 25.8 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Features. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Block Diagram . . . . . . . . . . . . . . . . . . . . . . . . . . Signal Description . . . . . . . . . . . . . . . . . . . . . . . Product Dependencies . . . . . . . . . . . . . . . . . . . Functional Description . . . . . . . . . . . . . . . . . . . . Register Summary . . . . . . . . . . . . . . . . . . . . . . . Register Description . . . . . . . . . . . . . . . . . . . . . 345 345 346 346 346 348 354 355 26. SERCOM SPI – SERCOM Serial Peripheral Interface 369 26.1 26.2 26.3 26.4 26.5 26.6 26.7 26.8 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Features. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Block Diagram . . . . . . . . . . . . . . . . . . . . . . . . . . Signal Description . . . . . . . . . . . . . . . . . . . . . . . Product Dependencies . . . . . . . . . . . . . . . . . . . Functional Description . . . . . . . . . . . . . . . . . . . . Register Summary . . . . . . . . . . . . . . . . . . . . . . . Register Description . . . . . . . . . . . . . . . . . . . . . 369 369 369 369 370 371 378 379 27. SERCOM I2C – SERCOM Inter-Integrated Circuit 394 27.1 27.2 27.3 27.4 27.5 27.6 27.7 27.8 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Features. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Block Diagram . . . . . . . . . . . . . . . . . . . . . . . . . . Signal Description . . . . . . . . . . . . . . . . . . . . . . . Product Dependencies . . . . . . . . . . . . . . . . . . . Functional Description . . . . . . . . . . . . . . . . . . . . Register Summary . . . . . . . . . . . . . . . . . . . . . . . Register Description . . . . . . . . . . . . . . . . . . . . . 394 394 394 395 395 396 408 412 28. TC – Timer/Counter . . . . . . . . . . . . . . . . . . .441 28.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 441 Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 583 28.2 28.3 28.4 28.5 28.6 28.7 28.8 Features. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Block Diagram . . . . . . . . . . . . . . . . . . . . . . . . . . Signal Description . . . . . . . . . . . . . . . . . . . . . . . Product Dependencies . . . . . . . . . . . . . . . . . . . Functional Description . . . . . . . . . . . . . . . . . . . . Register Summary . . . . . . . . . . . . . . . . . . . . . . . Register Description . . . . . . . . . . . . . . . . . . . . . 441 442 443 443 444 454 457 29. ADC – Analog-to-Digital Converter . . . . . . .481 29.1 29.2 29.3 29.4 29.5 29.6 29.7 29.8 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Features. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Block Diagram . . . . . . . . . . . . . . . . . . . . . . . . . . Signal Description . . . . . . . . . . . . . . . . . . . . . . . Product Dependencies . . . . . . . . . . . . . . . . . . . Functional Description . . . . . . . . . . . . . . . . . . . . Register Summary . . . . . . . . . . . . . . . . . . . . . . . Register Description . . . . . . . . . . . . . . . . . . . . . 481 481 482 482 483 484 493 495 30. AC – Analog Comparator . . . . . . . . . . . . . .520 30.1 30.2 30.3 30.4 30.5 30.6 30.7 30.8 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Features. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Block Diagram . . . . . . . . . . . . . . . . . . . . . . . . . . Signal Description . . . . . . . . . . . . . . . . . . . . . . . Product Dependencies . . . . . . . . . . . . . . . . . . . Functional Description . . . . . . . . . . . . . . . . . . . . Register Summary . . . . . . . . . . . . . . . . . . . . . . . Register Description . . . . . . . . . . . . . . . . . . . . . 520 520 521 521 521 522 532 533 31. DAC – Digital-to-Analog Converter . . . . . . .549 31.1 31.2 31.3 31.4 31.5 31.6 31.7 31.8 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Features. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Block Diagram . . . . . . . . . . . . . . . . . . . . . . . . . . Signal Description . . . . . . . . . . . . . . . . . . . . . . . Product Dependencies . . . . . . . . . . . . . . . . . . . Functional Description . . . . . . . . . . . . . . . . . . . . Register Summary . . . . . . . . . . . . . . . . . . . . . . . Register Description . . . . . . . . . . . . . . . . . . . . . 549 549 549 549 550 551 554 555 32. PTC - Peripheral Touch Controller . . . . . . . .568 32.1 32.2 32.3 32.4 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Features. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Signal Description . . . . . . . . . . . . . . . . . . . . . . . Product Dependencies . . . . . . . . . . . . . . . . . . . 568 568 568 568 33. Packaging Information . . . . . . . . . . . . . . . . .569 33.1 33.2 33.3 Thermal Considerations. . . . . . . . . . . . . . . . . . . 569 Package Drawings. . . . . . . . . . . . . . . . . . . . . . . 570 Soldering Profile . . . . . . . . . . . . . . . . . . . . . . . . 576 34. Errata . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .577 34.1 Revision A . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 577 Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 584 35. Datasheet Revision History . . . . . . . . . . . . .579 35.1 Rev. A – 06/2013 . . . . . . . . . . . . . . . . . . . . . . . . 579 Table of Contents . . . . . . . . . . . . . . . . . . . . . . . .580 Atmel SAM D20 [Preliminary DATASHEET] 42129A–SAM–06/2013 585 Atmel Corporation 1600 Technology Drive Atmel Asia Limited Unit 01-5 & 16, 19F Atmel Munich GmbH Business Campus Atmel Japan G.K. 16F Shin-Osaki Kangyo Bldg San Jose, CA 95110 BEA Tower, Millennium City 5 Parkring 4 1-6-4 Osaki, Shinagawa-ku USA 418 Kwun Tong Roa D-85748 Garching b. Munich Tokyo 141-0032 Tel: (+1) (408) 441-0311 Kwun Tong, Kowloon GERMANY JAPAN Fax: (+1) (408) 487-2600 HONG KONG Tel: (+49) 89-31970-0 Tel: (+81) (3) 6417-0300 www.atmel.com Tel: (+852) 2245-6100 Fax: (+49) 89-3194621 Fax: (+81) (3) 6417-0370 Fax: (+852) 2722-1369 © 2013 Atmel Corporation. All rights reserved. / Rev.: 42129A–SAM–06/2013 Atmel®, Atmel logo and combinations thereof, Enabling Unlimited Possibilities®, QTouch®, and others are registered trademarks or trademarks of Atmel Corporation or its subsidiaries. ARM®, Cortex® and others are registered trademarks or trademarks of ARM Ltd. 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.