Features * High Performance, Low Power 32-bit AVR(R) Microcontroller - - - - * * * * * * * * * * * * Compact Single-cycle RISC Instruction Set Including DSP Instruction Set Built-in Floating-Point Processing Unit (FPU) Read-Modify-Write Instructions and Atomic Bit Manipulation Performing 1.49 DMIPS / MHz * Up to 91 DMIPS Running at 66 MHz from Flash (1 Wait-State) * Up to 49 DMIPS Running at 33 MHz from Flash (0 Wait-State) - Memory Protection Unit Multi-hierarchy Bus System - High-Performance Data Transfers on Separate Buses for Increased Performance - 16 Peripheral DMA Channels Improves Speed for Peripheral Communication Internal High-Speed Flash - 512 Kbytes, 256 Kbytes, 128 Kbytes, 64 Kbytes Versions - Single Cycle Access up to 33 MHz - FlashVaultTM Technology Allows Pre-programmed Secure Library Support for End User Applications - Prefetch Buffer Optimizing Instruction Execution at Maximum Speed - 4ms Page Programming Time and 8ms Full-Chip Erase Time - 100,000 Write Cycles, 15-year Data Retention Capability - Flash Security Locks and User Defined Configuration Area Internal High-Speed SRAM, Single-Cycle Access at Full Speed - 64 Kbytes (512 KB and 256 KB Flash), 32 Kbytes (128 KB Flash), 16 Kbytes (64 KB Flash) - 4 Kbytes on the Multi-Layer Bus System (HSB RAM) External Memory Interface on AT32UC3C0 Derivatives - SDRAM / SRAM Compatible Memory Bus (16-bit Data and 24-bit Address Buses) Interrupt Controller - Autovectored Low Latency Interrupt Service with Programmable Priority System Functions - Power and Clock Manager - Internal 115KHz (RCSYS) and 8MHz/1MHz (RC8M) RC Oscillators - One 32 KHz and Two Multipurpose Oscillators - Clock Failure detection - Two Phase-Lock-Loop (PLL) allowing Independent CPU Frequency from USB or CAN Frequency Windowed Watchdog Timer (WDT) Asynchronous Timer (AST) with Real-Time Clock Capability - Counter or Calendar Mode Supported Frequency Meter (FREQM) for Accurate Measuring of Clock Frequency Ethernet MAC 10/100 Mbps interface - 802.3 Ethernet Media Access Controller - Supports Media Independent Interface (MII) and Reduced MII (RMII) Universal Serial Bus (USB) - Device 2.0 and Embedded Host Low Speed and Full Speed - Flexible End-Point Configuration and Management with Dedicated DMA Channels - On-chip Transceivers Including Pull-Ups One 2-channel Controller Area Network (CAN) - CAN2A and CAN2B protocol compliant, with high-level mailbox system 32-bit AVR(R) Microcontroller AT32UC3C0512C AT32UC3C0256C AT32UC3C0128C AT32UC3C064C AT32UC3C1512C AT32UC3C1256C AT32UC3C1128C AT32UC3C164C AT32UC3C2512C AT32UC3C2256C AT32UC3C2128C AT32UC3C264C 32117A-10/2010 AT32UC3C - Two independent channels, 16 Message Objects per Channel * One 4-Channel 20-bit Pulse Width Modulation Controller (PWM) * * * * * * * * * * * * * * - Complementary outputs, with Dead Time Insertion - Output Override and Fault Protection Two Quadrature Decoders One 16-channel 12-bit Pipelined Analog-To-Digital Converter (ADC) - Dual Sample and Hold Capability Allowing 2 Synchronous Conversions - Single-Ended and Differential Channels, Window Function Two 12-bit Digital-To-Analog Converters (DAC), with Dual Output Sample System Four Analog Comparators Six 16-bit Timer/Counter (TC) Channels - External Clock Inputs, PWM, Capture and Various Counting Capabilities One Peripheral Event Controller - Trigger Actions in Peripherals Depending on Events Generated from Peripherals or from Input Pins - Deterministic Trigger - 34 Events and 22 Event Actions Five Universal Synchronous/Asynchronous Receiver/Transmitters (USART) - Independent Baudrate Generator, Support for SPI, LIN, IrDA and ISO7816 interfaces - Support for Hardware Handshaking, RS485 Interfaces and Modem Line Two Master/Slave Serial Peripheral Interfaces (SPI) with Chip Select Signals One Inter-IC Sound (I2S) Controller - Compliant with I2S Bus Specification - Time Division Multiplexed mode Three Master and Three Slave Two-Wire Interfaces (TWI), 400kbit/s I2C-compatible QTouch(R) Library Support - Capacitive Touch Buttons, Sliders, and Wheels - QTouch(R) and QMatrix(R) Acquisition On-Chip Non-intrusive Debug System - Nexus Class 2+, Runtime Control, Non-Intrusive Data and Program Trace - aWireTM single-pin programming trace and debug interface muxed with reset pin - NanoTraceTM provides trace capabilities through JTAG or aWire interface 3 package options - 64-pin QFN/TQFP (45 GPIO pins) - 100-pin TQFP (81 GPIO pins) - 144-pin LQFP (123 GPIO pins) Two operating voltage ranges: - Single 5V Power Supply - Single 3.3V Power Supply 2 32117A-10/2010 AT32UC3C 1. Description The AT32UC3C is a complete System-On-Chip microcontroller based on the AVR32UC RISC processor running at frequencies up to 66 MHz. AVR32UC is a high-performance 32-bit RISC microprocessor core, designed for cost-sensitive embedded applications, with particular emphasis on low power consumption, high code density and high performance. The processor implements a Memory Protection Unit (MPU) and a fast and flexible interrupt controller for supporting modern operating systems and real-time operating systems. Using the Secure Access Unit (SAU) together with the MPU provides the required security and integrity. Higher computation capabilities are achievable either using a rich set of DSP instructions or using the floating-point instructions. The AT32UC3C incorporates on-chip Flash and SRAM memories for secure and fast access. For applications requiring additional memory, an external memory interface is provided on AT32UC3C0 derivatives. The Memory Direct Memory Access controller (MDMA) enables transfers of block of data from memories to memories without processor involvement. The Peripheral Direct Memory Access (PDCA) controller enables data transfers between peripherals and memories without processor involvement. The PDCA drastically reduces processing overhead when transferring continuous and large data streams. The AT32UC3C incorporates on-chip Flash and SRAM memories for secure and fast access. The FlashVault technology allows secure libraries to be programmed into the device. The secure libraries can be executed while the CPU is in Secure State, but not read by non-secure software in the device. The device can thus be shipped to end custumers, who are able to program their own code into the device, accessing the secure libraries, without any risk of compromising the proprietary secure code. The Power Manager improves design flexibility and security. Power monitoring is supported by on-chip Power-On Reset (POR), Brown-Out Detectors (BOD18, BOD33, BOD50). The CPU runs from the on-chip RC oscillators, the PLLs, or the Multipurpose Oscillators. The Asynchronous Timer (AST) combined with the 32 KHz oscillator keeps track of the time. The AST can operate in counter or calendar mode. The device includes six identical 16-bit Timer/Counter (TC) channels. Each channel can be independently programmed to perform frequency measurement, event counting, interval measurement, pulse generation, delay timing, and pulse width modulation. The PWM module provides four channels with many configuration options including polarity, edge alignment and waveform non overlap control. The PWM channels can operate independently, with duty cycles set independently from each other, or in interlinked mode, with multiple channels updated at the same time. It also includes safety feature with fault inputs and the ability to lock the PWM configuration registers and the PWM pin assignment. The AT32UC3C also features many communication interfaces for communication intensive applications. In addition to standard serial interfaces like UART, SPI or TWI, other interfaces like flexible CAN, USB and Ethernet MAC are available. The USART supports different communication modes, like SPI mode and LIN mode. The Inter-IC Sound Controller (I2SC) provides a 5-bit wide, bidirectional, synchronous, digital audio link with off-chip audio devices. The controller is compliant with the I2S bus specification. 3 32117A-10/2010 AT32UC3C The Full-Speed USB 2.0 Device interface supports several USB Classes at the same time thanks to the rich End-Point configuration. The On-The-GO (OTG) Host interface allows device like a USB Flash disk or a USB printer to be directly connected to the processor. The media-independent interface (MII) and reduced MII (RMII) 10/100 Ethernet MAC module provides on-chip solutions for network-connected devices. The Peripheral Event Controller (PEVC) allows to redirect events from one peripheral or from input pins to another peripheral. It can then trigger, in a deterministic time, an action inside a peripheral without the need of CPU. For instance a PWM waveform can directly trigger an ADC capture, hence avoiding delays due to software interrupt processing. The AT32UC3C features analog functions like ADC, DAC, Analog comparators. The ADC interface is built around a 12-bit pipelined ADC core and is able to control two independent 8-channel or one 16-channel. The ADC block is able to measure two different voltages sampled at the same time. The analog comparators can be paired to detect when the sensing voltage is within or outside the defined reference window. Atmel offers the QTouch library for embedding capacitive touch buttons, sliders, and wheels functionality into AVR microcontrollers. The patented charge-transfer signal acquisition offers robust sensing and included fully debounced reporting of touch keys and includes Adjacent Key Suppression(R) (AKS(R)) technology for unambiguous detection of key events. The easy-to-use QTouch Suite toolchain allows you to explore, develop, and debug your own touch applications. AT32UC3C integrates a class 2+ Nexus 2.0 On-Chip Debug (OCD) System, with non-intrusive real-time trace, full-speed read/write memory access in addition to basic runtime control. The Nanotrace interface enables trace feature for aWire- or JTAG-based debuggers. The single-pin aWire interface allows all features available through the JTAG interface to be accessed through the RESET pin, allowing the JTAG pins to be used for GPIO or peripherals. 4 32117A-10/2010 AT32UC3C 2. Overview Block diagram Block diagram TDO TCK TDI TMS AVR32UC CPU JTAG INTERFACE NEXUS CLASS 2+ OCD MCKO MDO[5..0] MSEO[1..0] EVTI_N EVTO_N VBUS D+ DID VBOF USB INTERFACE M Flash Controller 512/ 256/ 128/64 KB Flash M S S M W M R M S M M PBB HSB PB S S CONFIGURATION PERIPHERAL DMA CONTROLLER REGISTERS HSB Memory DMA COL, CRS, RXD[3..0], RX_CLK, RX_DV, RX_ER, TX_CLK DMA BUS HSB PB HSB-PB BRIDGE B HSB-PB BRIDGE A DATA[15..0] ADDR[23..0] NCS[3..0] NRD NWAIT NWE0 NWE1 RAS CAS SDA10 SDCK SDCKE SDCS SDWE ETHERNET MAC PB MDC, TXD[3..0], TX_EN, TX_ER, SPEED DMA ANALOG TO DIGITAL CONVERTER 0/1 DMA SERIAL PERIPHERAL INTERFACE 1 SERIAL PERIPHERAL INTERFACE 0 DMA I2S INTERFACE TWO-WIRE INTERFACE 0/1 DMA USART0 USART2 USART3 DMA USART4 DMA RTS, CTS CLK TXD RXD PERIPHERAL EVENT CONTROLLER DMA USART1 PBA MDIO DSR, DTR, DCD, RI RTS, CTS CLK TXD RXD DMA PAD_EVT RXD TXD CLK RTS, CTS MISO, MOSI BCLK IWS ISDI ISDO MCLK supplied by VDDANA ADCREF0/1 ADCIN[15..0] ADCVREFP/N SCK MISO, MOSI NPCS[3..0] SCK NPCS[3..0] CLK[2..0] B[2..0] DMA TWO-WIRE INTERFACE 2 TWCK TWD PULSE WIDTH MODULATION CONTROLLER DMA TIMER/COUNTER 0 A[2..0] External Interrupt Controller EXTINT[8:1] NMI CLOCK CONTROLLER RESET CONTROLLER GCLK[1..0] TWD PWMH[3..0] PWML[3..0] EXT_FAULTS[1:0] PA PB PC PD supplied by VDDANA DMA POWER MANAGER SLEEP CONTROLLER TWCK TWALM GENERAL PURPOSE IOs GENERAL PURPOSE IOs M M 64/32/16 KB SRAM S HSB-PB BRIDGE C PA PB PC PD DATA INTERFACE HIGH SPEED BUS MATRIX CANIF RXLINE[1] TXCAN[1] INSTR INTERFACE LOCAL BUS S 4 KB HSB RAM RXLINE[0] TXLINE[0] MEMORY PROTECTION UNIT LOCAL BUS INTERFACE EXTERNAL BUS INTERFACE (SDRAM & STATIC MEMORY CONTROLLER) aWire RESET_N MEMORY INTERFACE Figure 2-1. PBC 2.1 DIGITAL TO ANALOG CONVERTER 0/1 DAC0A/B DAC1A/B DACREF ANALOG COMPARATOR 0A/0B/1A/1B AC0AP/N AC0BP/N AC1AP/N AC1BP/N AC0AOUT/AC0BOUT AC1AOUT/AC1BOUT TIMER/COUNTER 1 B[2..0] RCSYS A[2..0] RC8M CLK[2..0] RC120M XIN[1:0] XOUT[1:0] OSC0 / OSC1 SYSTEM CONTROL INTERFACE PLL0 / PLL1 XIN32 XOUT32 32 KHz OSC QUADRATURE DECODER 0/1 QEPA QEPB QEPI ASYNCHRONOUS TIMER BODs (1.8V, 3.3V, 5V) WATCHDOG TIMER FREQUENCY METER 5 32117A-10/2010 AT32UC3C 2.2 Configuration Summary Table 2-1. Configuration Summary AT32UC3C0512C/ AT32UC3C0256C/ AT32UC3C0128C/ AT32UC3C064C AT32UC3C1512C/ AT32UC3C1256C/ AT32UC3C1128C/ AT32UC3C164C AT32UC3C2512C/ AT32UC3C2256C/ AT32UC3C2128C/ AT32UC3C264C Flash 512/256/128/64 KB 512/256/128/64 KB 512/256/128/64 KB SRAM 64/64/32/16KB 64/64/32/16KB 64/64/32/16KB Feature HSB RAM EBI 4 KB 1 0 0 123 81 45 External Interrupts 8 8 8 TWI 3 3 2 USART 5 5 4 Peripheral DMA Channels 16 16 16 Peripheral Event System 1 1 1 SPI 2 2 1 CAN channels 2 2 2 USB 1 1 1 Ethernet MAC 10/100 1 1 1 I2S 1 1 1 Asynchronous Timers 1 1 1 Timer/Counter Channels 6 6 3 GPIO PWM channels QDEC 4x2 2 2 Frequency Meter 1 Watchdog Timer 1 Power Manager 1 1 PLL 80-240 MHz (PLL0/PLL1) Crystal Oscillator 0.4-20 MHz (OSC0) Crystal Oscillator 32 KHz (OSC32K) RC Oscillator 115 kHz (RCSYS) RC Oscillator 8 MHz (RC8M) RC Oscillator 120 MHz (RC120M) Oscillators 0.4-20 MHz (OSC1) - 12-bit ADC number of channels 1 16 1 16 1 11 12-bit DAC number of channels 1 4 1 4 1 2 6 32117A-10/2010 AT32UC3C Table 2-1. Configuration Summary Feature Analog Comparators AT32UC3C0512C/ AT32UC3C0256C/ AT32UC3C0128C/ AT32UC3C064C AT32UC3C1512C/ AT32UC3C1256C/ AT32UC3C1128C/ AT32UC3C164C AT32UC3C2512C/ AT32UC3C2256C/ AT32UC3C2128C/ AT32UC3C264C 4 4 2 JTAG 1 aWire 1 Max Frequency Package 66 MHz LQFP144 TQFP100 TQFP64/QFN64 7 32117A-10/2010 AT32UC3C 3. Package and Pinout 3.1 Package The device pins are multiplexed with peripheral functions as described in Table 3-1 on page 10. QFN64/TQFP64 Pinout 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 PD01 PD00 PC22 PC21 PC20 PC19 PC18 PC17 PC16 PC15 PC05 PC04 GNDIO VDDIO PC03 PC02 Figure 3-1. PD02 PD03 VDDIO GNDIO PD11 PD12 PD13 PD14 PD21 PD27 PD28 PD29 PD30 PB00 PB01 RESET_N 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 PB31 PB30 GNDCORE VDDCORE VDDIN_33 VDDIN_5 GNDPLL DP DM VBUS PA23 PA22 PA21 PA20 VDDANA GNDANA 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 PA19 ADCVREFN ADCVREFP PA16 PA09 PA08 PA07 PA06 PA05 PA04 GNDIO VDDIO PA03 PA02 PA01 PA00 Note: on QFN packages, the exposed pad is unconnected. 8 32117A-10/2010 AT32UC3C TQFP100 Pinout 75 74 73 72 71 70 69 68 67 66 65 64 63 62 61 60 59 58 57 56 55 54 53 52 51 PD01 PD00 PC31 PC24 PC23 PC22 PC21 PC20 PC19 PC18 PC17 PC16 PC15 PC14 PC13 PC12 PC11 PC07 PC06 PC05 PC04 GNDIO VDDIO PC03 PC02 Figure 3-2. PD02 PD03 PD07 PD08 PD09 PD10 VDDIO GNDIO PD11 PD12 PD13 PD14 PD21 PD22 PD23 PD24 PD27 PD28 PD29 PD30 PB00 PB01 RESET_N PB02 PB03 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 PC01 PC00 PB31 PB30 PB23 PB22 PB21 PB20 PB19 GNDCORE VDDCORE VDDIN_33 VDDIN_5 GNDPLL DP DM VBUS PA25 PA24 PA23 PA22 PA21 PA20 VDDANA GNDANA 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 PA19 ADCVREFN ADCVREFP PA16 PA15 PA14 PA13 PA12 PA11 PA10 PA09 PA08 PA07 PA06 PA05 PA04 PB06 PB05 PB04 GNDIO VDDIO PA03 PA02 PA01 PA00 9 32117A-10/2010 AT32UC3C LQFP144 Pinout 108 107 106 105 104 103 102 101 100 99 98 97 96 95 94 93 92 91 90 89 88 87 86 85 84 83 82 81 80 79 78 77 76 75 74 73 PD01 PD00 PC31 PC30 GNDIO VDDIO PC29 PC28 PC27 PC26 PC25 PC24 PC23 PC22 PC21 PC20 PC19 PC18 PC17 PC16 PC15 PC14 PC13 PC12 PC11 PC10 PC09 PC08 PC07 PC06 PC05 PC04 GNDIO VDDIO PC03 PC02 Figure 3-3. PD02 PD03 PD04 PD05 PD06 PD07 PD08 PD09 PD10 VDDIO GNDIO PD11 PD12 PD13 PD14 PD15 PD16 PD17 PD18 PD19 PD20 PD21 PD22 PD23 PD24 PD25 PD26 PD27 PD28 PD29 PD30 PB00 PB01 RESET_N PB02 PB03 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 72 71 70 69 68 67 66 65 64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 PC01 PC00 PB31 PB30 PB29 PB28 PB27 PB26 PB25 PB24 PB23 PB22 PB21 PB20 PB19 PB18 GNDCORE VDDCORE VDDIN_33 VDDIN_5 GNDPLL DP DM VBUS PA29 PA28 PA27 PA26 PA25 PA24 PA23 PA22 PA21 PA20 VDDANA GNDANA 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 PA19 ADCVREFN ADCVREFP PA16 PA15 PA14 PA13 PA12 PA11 PA10 PA09 PA08 PA07 PA06 PA05 PA04 PB17 PB16 PB15 PB14 PB13 PB12 PB11 PB10 PB09 PB08 PB07 PB06 PB05 PB04 GNDIO VDDIO PA03 PA02 PA01 PA00 3.2 Peripheral Multiplexing on I/O lines 3.2.1 Multiplexed signals Each GPIO line can be assigned to one of the peripheral functions.The following table describes the peripheral signals multiplexed to the GPIO lines. Table 3-1. GPIO Controller Function Multiplexing TQFP/ TQFP LQFP QFN64 100 1 1 GPIO function 144 Pad Type(1) PIN GPIO 1 x1/x2 PA00 0 A B C D E F CANIF TXLINE[1] 10 32117A-10/2010 AT32UC3C Table 3-1. 2 GPIO Controller Function Multiplexing 2 2 x1/x2 PA01 CANIF RXLINE[1] 1 PEVC PAD_EVT[ 0] PEVC PAD_EVT[ 1] 3 3 3 x1/x2 PA02 2 SCIF GCLK[0] 4 4 4 x1/x2 PA03 3 SCIF GCLK[1] EIC EXTINT[1] 7 10 21 x1/x2 PA04 4 ADCIN0 USBC - ID ACIFA0 ACAOUT 8 11 22 x1/x2 PA05 5 ADCIN1 USBC VBOF ACIFA0 ACBOUT AC1AP1 PEVC PAD_EVT[ 2] 9 12 23 x1/x2 PA06 6 ADCIN2 10 13 24 x1/x2 PA07 7 ADCIN3 AC1AN1 PEVC PAD_EVT[ 3] 11 14 25 x1/x2 PA08 8 ADCIN4 AC1BP1 EIC EXTINT[2] 12 15 26 x1/x2 PA09 9 ADCIN5 AC1BN1 ADCIN6 EIC EXTINT[4] PEVC PAD_EVT[ 13] 16 27 x1/x2 PA10 10 17 28 x1/x2 PA11 11 ADCIN7 ADCREF1 PEVC PAD_EVT[ 14] 18 29 x1/x2 PA12 12 AC1AP0 SPI0 NPCS[0] DAC1A 19 30 x1/x2 PA13 13 AC1AN0 SPI0 NPCS[1] ADCIN15 20 31 x1/x2 PA14 14 AC1BP0 SPI1 NPCS[0] 21 32 x1/x2 PA15 15 AC1BN0 SPI1 NPCS[1] 13 22 33 x1/x2 PA16 16 ADCREF0 14 23 34 ADC REFP 15 24 35 ADC REFN 16 25 36 x1/x2 PA19 19 ADCIN8 EIC EXTINT[1] 19 28 39 x1/x2 PA20 20 ADCIN9 AC0AP0 DAC0A 20 29 40 x1/x2 PA21 21 ADCIN10 AC0BN0 DAC0B AC0AN0 PEVC PAD_EVT[ 4] 21 30 41 x1/x2 PA22 22 ADCIN11 DAC1B DACREF MACB SPEED 11 32117A-10/2010 AT32UC3C Table 3-1. 22 62 63 GPIO Controller Function Multiplexing 31 42 x1/x2 PA23 23 ADCIN12 AC0BP0 32 43 x1/x2 PA24 24 ADCIN13 SPI1 NPCS[2] 33 44 x1/x2 PA25 25 ADCIN14 SPI1 NPCS[3] 45 x1/x2 PA26 26 AC0AP1 EIC EXTINT[1] 46 x1/x2 PA27 27 AC0AN1 EIC EXTINT[2] 47 x1/x2 PA28 28 AC0BP1 EIC EXTINT[3] 48 x1/x2 PA29 29 AC0BN1 EIC EXTINT[0] 32 USART0 CLK CANIF RXLINE[1] 96 97 99 140 141 143 x1 x1 x1 PB00 PB01 PB02 PEVC PAD_EVT[ 5] EIC EXTINT[0] EIC EXTINT[8] PEVC PAD_EVT[ 10] PEVC PAD_EVT[ 11] CANIF TXLINE[1] 33 MACB WOL 34 USBC - ID PEVC PAD_EVT[ 6] USBC VBOF PEVC PAD_EVT[ 7] TC1 - A1 100 144 x1 PB03 35 7 7 x1/x2 PB04 36 SPI1 MOSI CANIF RXLINE[0] QDEC1 QEPI CANIF TXLINE[0] PEVC PAD_EVT[ 12] USART3 CLK MACB TXD[3] QDEC1 QEPA USART1 CLK MACB TX_ER MACB TXD[2] 8 8 x1/x2 PB05 37 SPI1 MISO 9 9 x2/x4 PB06 38 SPI1 - SCK 10 x1/x2 PB07 39 SPI1 NPCS[0] EIC EXTINT[2] QDEC1 QEPB PEVC PAD_EVT[1 ] PWM PWML[0] EIC SCAN[0] MACB RXD[0] PWM PWMH[0] EIC SCAN[1] MACB RXD[1] MACB RX_DV 11 x1/x2 PB08 40 SPI1 NPCS[1] 12 x1/x2 PB09 41 SPI1 NPCS[2] 13 x1/x2 PB10 42 USART1 DTR SPI0 - MOSI PWM PWML[1] EIC SCAN[2] 14 x1/x2 PB11 43 USART1 DSR SPI0 - MISO PWM PWMH[1] EIC SCAN[3] 15 x1/x2 PB12 44 USART1 DCD SPI0 - SCK PWM PWML[2] EIC SCAN[4] 16 x1/x2 PB13 45 USART1 RI SPI0 NPCS[0] PWM PWMH[2] EIC SCAN[5] MACB RX_ER 12 32117A-10/2010 AT32UC3C Table 3-1. GPIO Controller Function Multiplexing 17 x1/x2 PB14 46 USART1 RTS SPI0 NPCS[1] PWM PWML[3] EIC SCAN[6] MACB MDC 18 x1/x2 PB15 47 USART1 CTS USART1 CLK PWM PWMH[3] EIC SCAN[7] MACB MDIO 48 USART1 RXD SPI0 NPCS[2] PWM EXT_FAUL TS[0] CANIF RXLINE[0] SPI0 NPCS[3] PWM EXT_FAUL TS[1] CANIF TXLINE[0] 19 x1/x2 PB16 20 x1/x2 PB17 49 USART1 TXD 57 x1/x2 PB18 50 TC0 CLK2 42 58 x1/x2 PB19 51 TC0 - A0 SPI1 - MOSI IISC - ISDO 43 59 x1/x2 PB20 52 TC0 - B0 SPI1 - MISO IISC - ISDI ACIFA1 ACAOUT MACB COL 44 60 x2/x4 PB21 53 TC0 CLK1 SPI1 - SCK IISC IMCK ACIFA1 ACBOUT MACB RXD[2] 45 61 x1/x2 PB22 54 TC0 - A1 SPI1 NPCS[3] IISC - ISCK SCIF GCLK[0] MACB RXD[3] 46 62 x1/x2 PB23 55 TC0 - B1 SPI1 NPCS[2] IISC - IWS SCIF GCLK[1] MACB RX_CLK 63 x1/x2 PB24 56 TC0 CLK0 SPI1 NPCS[1] TC0 - A2 SPI1 NPCS[0] PEVC PAD_EVT[ 8] SPI1 - SCK PEVC PAD_EVT[ 9] SPI1 - MISO PEVC PAD_EVT[ 10] TC1 CLK0 MACB TXD[0] TC1 - B0 MACB TXD[1] 64 65 66 67 x1/x2 x2/x4 x1/x2 x1/x2 PB25 PB26 PB27 PB28 57 EIC EXTINT[4] MACB CRS MACB TX_EN 58 TC0 - B2 59 QDEC0 QEPA 60 QDEC0 QEPB SPI1 - MOSI PEVC PAD_EVT[ 11] QDEC0 QEPI SPI0 NPCS[0] PEVC PAD_EVT[ 12] TC1 - A0 68 x1/x2 PB29 61 31 47 69 x1 PB30 62 32 48 70 x1 PB31 63 49 71 x1/x2 PC00 64 USBC - ID SPI0 NPCS[1] USART2 CTS TC1 - B2 CANIF TXLINE[1] 50 72 x1/x2 PC01 65 USBC VBOF SPI0 NPCS[2] USART2 RTS TC1 - A2 CANIF RXLINE[1] 33 51 73 x1 PC02 66 TWIMS0 TWD SPI0 NPCS[3] USART2 RXD TC1 CLK1 MACB MDC 34 52 74 x1 PC03 67 TWIMS0 TWCK EIC EXTINT[1] USART2 TXD TC1 - B1 MACB MDIO 13 32117A-10/2010 AT32UC3C Table 3-1. GPIO Controller Function Multiplexing 37 55 77 x1 PC04 68 TWIMS1 TWD EIC EXTINT[3] USART2 TXD TC0 - B1 38 56 78 x1 PC05 69 TWIMS1 TWCK EIC EXTINT[4] USART2 RXD TC0 - A2 70 PEVC PAD_EVT[ 15] USART2 CLK USART2 CTS TC0 CLK2 TWIMS2 TWD TWIMS0 TWALM 71 PEVC PAD_EVT[ 2] EBI NCS[3] USART2 RTS TC0 - B2 TWIMS2 TWCK TWIMS1 TWALM 72 PEVC PAD_EVT[ 13] SPI1 NPCS[1] EBI NCS[0] USART4 TXD 73 PEVC PAD_EVT[ 14] SPI1 NPCS[2] EBI ADDR[23] USART4 RXD SPI1 NPCS[3] EBI ADDR[22] 57 58 79 80 81 82 x1 x1 x1/x2 x1/x2 PC06 PC07 PC08 PC09 83 x1/x2 PC10 74 PEVC PAD_EVT[ 15] 59 84 x1/x2 PC11 75 PWM PWMH[3] CANIF RXLINE[1] EBI ADDR[21] TC0 CLK0 60 85 x1/x2 PC12 76 PWM PWML[3] CANIF TXLINE[1] EBI ADDR[20] USART2 CLK 61 86 x1/x2 PC13 77 PWM PWMH[2] EIC EXTINT[7] EBI - SDCS USART0 RTS 62 87 x1/x2 PC14 78 PWM PWML[2] USART0 CLK EBI SDCKE USART0 CTS 39 63 88 x1/x2 PC15 79 PWM PWMH[1] SPI0 NPCS[0] EBI SDWE USART0 RXD CANIF RXLINE[1] 40 64 89 x1/x2 PC16 80 PWM PWML[1] SPI0 NPCS[1] EBI - CAS USART0 TXD CANIF TXLINE[1] 41 65 90 x1/x2 PC17 81 PWM PWMH[0] SPI0 NPCS[2] EBI - RAS IISC - ISDO USART3 TXD 42 66 91 x1/x2 PC18 82 PWM PWML[0] EIC EXTINT[5] EBI SDA10 IISC - ISDI USART3 RXD 43 67 92 x1/x2 PC19 83 PWM PWML[2] SCIF GCLK[0] EBI DATA[0] IISC IMCK USART3 CTS 44 68 93 x1/x2 PC20 84 PWM PWMH[2] SCIF GCLK[1] EBI DATA[1] IISC - ISCK USART3 RTS 85 PWM EXT_FAUL TS[0] CANIF RXLINE[0] EBI DATA[2] IISC - IWS 86 PWM EXT_FAUL TS[1] CANIF TXLINE[0] EBI DATA[3] 87 QDEC1 QEPB CANIF RXLINE[1] EBI DATA[4] PEVC PAD_EVT[ 3] 88 QDEC1 QEPA CANIF TXLINE[1] EBI DATA[5] PEVC PAD_EVT[ 4] 45 46 69 70 71 72 94 95 96 97 x1/x2 x1/x2 x1/x2 x1/x2 PC21 PC22 PC23 PC24 USART3 CLK 14 32117A-10/2010 AT32UC3C Table 3-1. GPIO Controller Function Multiplexing TC1 - CLK2 EBI DATA[6] SCIF GCLK[0] USART4 TXD TC1 - B2 EBI DATA[7] SCIF GCLK[1] USART4 RXD TC1 - A2 EBI DATA[8] EIC EXTINT[0] USART4 CTS SPI1 NPCS[3] TC1 - CLK1 EBI DATA[9] 93 SPI0 NPCS[1] TC1 - B1 EBI DATA[10] 94 SPI0 NPCS[2] TC1 - A1 EBI DATA[11] TC1 - B0 EBI DATA[12] PEVC PAD_EVT[ 5] USART4 CLK 98 x1/x2 PC25 89 99 x1/x2 PC26 90 100 x1/x2 PC27 91 101 x1/x2 PC28 92 102 x1/x2 PC29 105 x1/x2 PC30 QDEC1 QEPI USART4 RTS 73 106 x1/x2 PC31 95 SPI0 NPCS[3] 47 74 107 x1/x2 PD00 96 SPI0 MOSI TC1 - CLK0 EBI DATA[13] QDEC0 QEPI USART0 TXD 48 75 108 x1/x2 PD01 97 SPI0 MISO TC1 - A0 EBI DATA[14] TC0 CLK1 USART0 RXD 49 76 109 x2/x4 PD02 98 SPI0 - SCK TC0 - CLK2 EBI DATA[15] QDEC0 QEPA 50 77 110 x1/x2 PD03 99 SPI0 NPCS[0] TC0 - B2 EBI ADDR[0] QDEC0 QEPB 111 x1/x2 PD04 100 SPI0 MOSI EBI ADDR[1] 112 x1/x2 PD05 101 SPI0 MISO EBI ADDR[2] 113 x2/x4 PD06 102 SPI0 - SCK EBI ADDR[3] 78 114 x1/x2 PD07 103 USART1 DTR EIC EXTINT[5] EBI ADDR[4] QDEC0 QEPI USART4 TXD 79 115 x1/x2 PD08 104 USART1 DSR EIC EXTINT[6] EBI ADDR[5] TC1 CLK2 USART4 RXD 80 116 x1/x2 PD09 105 USART1 DCD CANIF RXLINE[0] EBI ADDR[6] QDEC0 QEPA USART4 CTS 81 117 x1/x2 PD10 106 USART1 RI CANIF TXLINE[0] EBI ADDR[7] QDEC0 QEPB USART4 RTS 107 USART1 TXD USBC - ID EBI ADDR[8] PEVC PAD_EVT[ 6] MACB TXD[0] 108 USART1 RXD USBC VBOF EBI ADDR[9] PEVC PAD_EVT[ 7] MACB TXD[1] 109 USART1 CTS USART1 CLK EBI SDCK PEVC PAD_EVT[ 8] MACB RXD[0] 110 USART1 RTS EIC EXTINT[7] EBI ADDR[10] PEVC PAD_EVT[ 9] MACB RXD[1] 53 54 55 56 84 85 86 87 120 121 122 123 x1/x2 x1/x2 x2/x4 x1/x2 PD11 PD12 PD13 PD14 15 32117A-10/2010 AT32UC3C Table 3-1. 57 GPIO Controller Function Multiplexing 124 x1/x2 PD15 111 TC0 - A0 USART3 TXD EBI ADDR[11] 125 x1/x2 PD16 112 TC0 - B0 USART3 RXD EBI ADDR[12] 126 x1/x2 PD17 113 TC0 - A1 USART3 CTS EBI ADDR[13] 127 x1/x2 PD18 114 TC0 - B1 USART3 RTS EBI ADDR[14] 128 x1/x2 PD19 115 TC0 - A2 EBI ADDR[15] 129 x1/x2 PD20 116 TC0 - B2 EBI ADDR[16] 88 130 x1/x2 PD21 117 USART3 TXD EIC EXTINT[0] EBI ADDR[17] QDEC1 QEPI 89 131 x1/x2 PD22 118 USART3 RXD TC0 - A2 EBI ADDR[18] SCIF GCLK[0] 90 132 x1/x2 PD23 119 USART3 CTS USART3 CLK EBI ADDR[19] QDEC1 QEPA 91 133 x1/x2 PD24 120 USART3 RTS EIC EXTINT[8] EBI NWE1 QDEC1 QEPB 134 x1/x2 PD25 121 TC0 CLK0 USBC - ID EBI NWE0 135 x1/x2 PD26 122 TC0 CLK1 USBC VBOF EBI - NRD USART3 CLK USART4 CLK 58 92 136 x1/x2 PD27 123 USART0 TXD CANIF RXLINE[0] EBI NCS[1] TC0 - A0 MACB RX_ER 59 93 137 x1/x2 PD28 124 USART0 RXD CANIF TXLINE[0] EBI NCS[2] TC0 - B0 MACB RX_DV 60 94 138 x1/x2 PD29 125 USART0 CTS EIC EXTINT[6] USART0 CLK TC0 CLK0 MACB TX_CLK 61 95 139 x1/x2 PD30 126 USART0 RTS EIC EXTINT[3] EBI NWAIT TC0 - A1 MACB TX_EN Note: 1. Refer to "Electrical Characteristics" on page 1243 for a description of the electrical properties of the pad types used. See Section 3.3 for a description of the various peripheral signals. Signals are prioritized according to the function priority listed in Table 3-2 on page 17 if multiple functions are enabled simultaneously. 3.2.2 Peripheral Functions Each GPIO line can be assigned to one of several peripheral functions. The following table describes how the various peripheral functions are selected. The last listed function has priority in case multiple functions are enabled. 16 32117A-10/2010 AT32UC3C Table 3-2. 3.2.3 Peripheral Functions Function Description A GPIO peripheral selection A B GPIO peripheral selection B C GPIO peripheral selection C D GPIO peripheral selection D E GPIO peripheral selection E F GPIO peripheral selection F Oscillator Pinout The oscillators are not mapped to the normal GPIO functions and their muxings are controlled by registers in the System Control Interface (SCIF). Please refer to the SCIF chapter for more information about this. Table 3-3. Oscillator pinout QFN64/ TQFP64 pin TQFP100 pin LQFP144 pin Pad Oscillator pin 31 47 69 PB30 xin0 99 143 PB02 xin1 62 96 140 PB00 xin32 32 48 70 PB31 xout0 100 144 PB03 xout1 97 141 PB01 xout32 63 3.2.4 JTAG port connections If the JTAG is enabled, the JTAG will take control over a number of pins, irrespectively of the I/O Controller configuration. Table 3-4. 3.2.5 JTAG pinout QFN64/ TQFP64 pin TQFP100 pin LQFP144 pin Pin name JTAG pin 2 2 2 PA01 TDI 3 3 3 PA02 TDO 4 4 4 PA03 TMS 1 1 1 PA00 TCK Nexus OCD AUX port connections If the OCD trace system is enabled, the trace system will take control over a number of pins, irrespectively of the GPIO configuration. Two different OCD trace pin mappings are possible, 17 32117A-10/2010 AT32UC3C depending on the configuration of the OCD AXS register. For details, see the AVR32UC Technical Reference Manual. Table 3-5. 3.2.6 Pin AXS=0 AXS=1 AXS=2 EVTI_N PA08 PB19 PA10 MDO[5] PC05 PC31 PB06 MDO[4] PC04 PC12 PB15 MDO[3] PA23 PC11 PB14 MDO[2] PA22 PB23 PA27 MDO[1] PA19 PB22 PA26 MDO[0] PA09 PB20 PA19 EVTO_N PD29 PD29 PD29 MCKO PD13 PB21 PB26 MSEO[1] PD30 PD08 PB25 MSEO[0] PD14 PD07 PB18 Other Functions The functions listed in Table 3-6 are not mapped to the normal GPIO functions. The aWire DATA pin will only be active after the aWire is enabled. The aWire DATAOUT pin will only be active after the aWire is enabled and the 2_PIN_MODE command has been sent. Table 3-6. 3.3 Nexus OCD AUX port connections Other Functions QFN64/ TQFP64 pin TQFP100 pin LQFP144 pin Pad Oscillator pin 64 98 142 RESET_N aWire DATA 3 3 3 PA02 aWire DATAOUT Signals Description The following table give details on the signal name classified by peripherals. Table 3-7. Signal Name Signal Description List Function Type Active Level Comments Power VDDIO I/O Power Supply Power Input 4.5V to 5.5V or 3.0V to 3.6 V VDDANA Analog Power Supply Power Input 4.5V to 5.5V or 3.0V to 3.6 V 18 32117A-10/2010 AT32UC3C Table 3-7. Signal Description List Signal Name Active Level Function Type 1.8V Voltage Regulator Input Power Input Power Supply: 4.5V to 5.5V or 3.0V to 3.6 V VDDIN_33 USB I/O power supply Power Output/ Input Capacitor Connection for the 3.3V voltage regulator or power supply: 3.0V to 3.6 V VDDCORE 1.8V Voltage Regulator Output Power output Capacitor Connection for the 1.8V voltage regulator GNDIO I/O Ground Ground GNDANA Analog Ground Ground GNDCORE Ground of the core Ground GNDPLL Ground of the PLLs Ground VDDIN_5 Comments Analog Comparator Interface - ACIFA0/1 AC0AN1/AC0AN0 Negative inputs for comparator AC0A Analog AC0AP1/AC0AP0 Positive inputs for comparator AC0A Analog AC0BN1/AC0BN0 Negative inputs for comparator AC0B Analog AC0BP1/AC0BP0 Positive inputs for comparator AC0B Analog AC1AN1/AC1AN0 Negative inputs for comparator AC1A Analog AC1AP1/AC1AP0 Positive inputs for comparator AC1A Analog AC1BN1/AC1BN0 Negative inputs for comparator AC1B Analog AC1BP1/AC1BP0 Positive inputs for comparator AC1B Analog ACAOUT/ACBOUT analog comparator outputs output ADC Interface - ADCIFA ADCIN[15:0] ADC input pins Analog ADCREF0 Analog positive reference 0 voltage input Analog ADCREF1 Analog positive reference 1 voltage input Analog ADCVREFP Analog positive reference connected to external capacitor Analog ADCVREFN Analog negative reference connected to external capacitor Analog 19 32117A-10/2010 AT32UC3C Table 3-7. Signal Description List Signal Name Function Type Active Level Comments Auxiliary Port - AUX MCKO Trace Data Output Clock Output MDO[5:0] Trace Data Output Output MSEO[1:0] Trace Frame Control Output EVTI_N Event In Output Low EVTO_N Event Out Output Low aWire - AW DATA aWire data I/O DATAOUT aWire data output for 2-pin mode I/O Controller Area Network Interface - CANIF RXLINE[1:0] CAN channel rxline I/O TXLINE[1:0] CAN channel txline I/O DAC Interface - DACIFB0/1 DAC0A, DAC0B DAC0 output pins of S/H A Analog DAC1A, DAC1B DAC output pins of S/H B Analog DACREF Analog reference voltage input Analog External Bus Interface - EBI ADDR[23:0] Address Bus Output CAS Column Signal Output DATA[15:0] Data Bus NCS[3:0] Chip Select Output Low NRD Read Signal Output Low NWAIT External Wait Signal Input Low NWE0 Write Enable 0 Output Low NWE1 Write Enable 1 Output Low RAS Row Signal Output Low SDA10 SDRAM Address 10 Line Output SDCK SDRAM Clock Output Low I/O 20 32117A-10/2010 AT32UC3C Table 3-7. Signal Description List Type Active Level Signal Name Function SDCKE SDRAM Clock Enable Output SDCS SDRAM Chip Select Output Low SDWE SDRAM Write Enable Output Low Comments External Interrupt Controller - EIC EXTINT[8:1] External Interrupt Pins Input NMI_N = EXTINT[0] Non-Maskable Interrupt Pin Input Low General Purpose Input/Output - GPIOA, GPIOB, GPIOC, GPIOD PA[29:19] - PA[16:0] Parallel I/O Controller GPIOA I/O PB[31:0] Parallel I/O Controller GPIOB I/O PC[31:0] Parallel I/O Controller GPIOC I/O PD[30:0] Parallel I/O Controller GPIOD I/O Inter-IC Sound (I2S) Controller - IISC IMCK I2S Master Clock Output ISCK I2S Serial Clock I/O ISDI I2S Serial Data In ISDO I2S Serial Data Out IWS I2S Word Select Input Output I/O JTAG TCK Test Clock Input TDI Test Data In Input TDO Test Data Out TMS Test Mode Select Output Input Ethernet MAC - MACB COL Collision Detect Input CRS Carrier Sense and Data Valid Input MDC Management Data Clock MDIO Management Data Input/Output RXD[3:0] Receive Data Output I/O Input 21 32117A-10/2010 AT32UC3C Table 3-7. Signal Description List Signal Name Function Type RX_CLK Receive Clock Input RX_DV Receive Data Valid Input RX_ER Receive Coding Error Input SPEED Speed Output TXD[3:0] Transmit Data Output TX_CLK Transmit Clock or Reference Clock TX_EN Transmit Enable Output TX_ER Transmit Coding Error Output WOL Wake-On-LAN Output Active Level Comments Input Peripheral Event Controller - PEVC PAD_EVT[15:0] Event Input Pins Input Power Manager - PM RESET_N Reset Pin Input Low Pulse Width Modulator - PWM PWMH[3:0] PWML[3:0] PWM Output Pins EXT_FAULT[1:0] PWM Fault Input Pins Output Input Quadrature Decoder- QDEC0/QDEC1 QEPA QEPA quadrature input Input QEPB QEPB quadrature input Input QEPI Index input Input System Controller Interface- SCIF XIN0, XIN1, XIN32 Crystal 0, 1, 32K Inputs Analog XOUT0, XOUT1, XOUT32 Crystal 0, 1, 32K Output Analog GCLK0 - GCLK1 Generic Clock Pins Output Serial Peripheral Interface - SPI0, SPI1 MISO Master In Slave Out I/O MOSI Master Out Slave In I/O 22 32117A-10/2010 AT32UC3C Table 3-7. Signal Description List Signal Name Function NPCS[3:0] SPI Peripheral Chip Select SCK Clock Type Active Level I/O Low Comments Output Timer/Counter - TC0, TC1 A0 Channel 0 Line A I/O A1 Channel 1 Line A I/O A2 Channel 2 Line A I/O B0 Channel 0 Line B I/O B1 Channel 1 Line B I/O B2 Channel 2 Line B I/O CLK0 Channel 0 External Clock Input Input CLK1 Channel 1 External Clock Input Input CLK2 Channel 2 External Clock Input Input Two-wire Interface - TWIMS0, TWIMS1, TWIMS2 TWALM SMBus SMBALERT I/O TWCK Serial Clock I/O TWD Serial Data I/O Low Only on TWIMS0, TWIMS1 Universal Synchronous Asynchronous Receiver Transmitter - USART0, USART1, USART2, USART3, USART4 CLK Clock I/O CTS Clear To Send Input Low DCD Data Carrier Detect Input Low Only USART1 DSR Data Set Ready Input Low Only USART1 DTR Data Terminal Ready Output Low Only USART1 RI Ring Indicator Input Low Only USART1 RTS Request To Send Output Low RXD Receive Data Input TXD Transmit Data Output Universal Serial Bus Device - USB DM USB Device Port Data - Analog 23 32117A-10/2010 AT32UC3C Table 3-7. Signal Description List Signal Name Function DP USB Device Port Data + Analog VBUS USB VBUS Monitor and OTG Negociation Analog Input ID ID Pin of the USB Bus Input VBOF USB VBUS On/off: bus power control port output 3.4 3.4.1 Type Active Level Comments I/O Line Considerations JTAG pins The JTAG is enabled if TCK is low while the RESET_N pin is released. The TCK, TMS, and TDI pins have pull-up resistors when JTAG is enabled. The TCK pin always have pull-up enabled during reset. The TDO pin is an output, driven at VDDIO, and has no pull-up resistor. The JTAG pins can be used as GPIO pins and muxed with peripherals when the JTAG is disabled. Please refer to Section 3.2.4 for the JTAG port connections. 3.4.2 RESET_N pin The RESET_N pin integrates a pull-up resistor to VDDIO. As the product integrates a power-on reset cell, the RESET_N pin can be left unconnected in case no reset from the system needs to be applied to the product. The RESET_N pin is also used for the aWire debug protocol. When the pin is used for debugging, it must not be driven by external circuitry. 3.4.3 TWI pins When these pins are used for TWI, the pins are open-drain outputs with slew-rate limitation and inputs with inputs with spike-filtering. When used as GPIO-pins or used for other peripherals, the pins have the same characteristics as GPIO pins. 3.4.4 GPIO pins All I/O lines integrate programmable pull-up and pull-down resistors. Most I/O lines integrate drive strength control, see Table 3-1. Programming of this pull-up and pull-down resistor or this drive strength is performed independently for each I/O line through the GPIO Controllers. After reset, I/O lines default as inputs with pull-up/pull-down resistors disabled. After reset, output drive strength is configured to the lowest value to reduce global EMI of the device. When the I/O line is configured as analog function (ADC I/O, AC inputs, DAC I/O), the pull-up and pull-down resistors are automatically disabled. 24 32117A-10/2010 AT32UC3C 4. Processor and Architecture Rev: 2.1.2.0 This chapter gives an overview of the AVR32UC CPU. AVR32UC is an implementation of the AVR32 architecture. A summary of the programming model, instruction set, and MPU is presented. For further details, see the AVR32 Architecture Manual and the AVR32UC Technical Reference Manual. 4.1 Features * 32-bit load/store AVR32A RISC architecture - - - - - * * * * 4.2 15 general-purpose 32-bit registers 32-bit Stack Pointer, Program Counter and Link Register reside in register file Fully orthogonal instruction set Privileged and unprivileged modes enabling efficient and secure operating systems Innovative instruction set together with variable instruction length ensuring industry leading code density - DSP extension with saturating arithmetic, and a wide variety of multiply instructions 3-stage pipeline allowing one instruction per clock cycle for most instructions - Byte, halfword, word, and double word memory access - Multiple interrupt priority levels MPU allows for operating systems with memory protection FPU enables hardware accelerated floating point calculations Secure State for supporting FlashVaultTM technology AVR32 Architecture AVR32 is a new, high-performance 32-bit RISC microprocessor architecture, designed for costsensitive embedded applications, with particular emphasis on low power consumption and high code density. In addition, the instruction set architecture has been tuned to allow a variety of microarchitectures, enabling the AVR32 to be implemented as low-, mid-, or high-performance processors. AVR32 extends the AVR family into the world of 32- and 64-bit applications. Through a quantitative approach, a large set of industry recognized benchmarks has been compiled and analyzed to achieve the best code density in its class. In addition to lowering the memory requirements, a compact code size also contributes to the core's low power characteristics. The processor supports byte and halfword data types without penalty in code size and performance. Memory load and store operations are provided for byte, halfword, word, and double word data with automatic sign- or zero extension of halfword and byte data. The C-compiler is closely linked to the architecture and is able to exploit code optimization features, both for size and speed. In order to reduce code size to a minimum, some instructions have multiple addressing modes. As an example, instructions with immediates often have a compact format with a smaller immediate, and an extended format with a larger immediate. In this way, the compiler is able to use the format giving the smallest code size. Another feature of the instruction set is that frequently used instructions, like add, have a compact format with two operands as well as an extended format with three operands. The larger format increases performance, allowing an addition and a data move in the same instruction in a 25 32117A-10/2010 AT32UC3C single cycle. Load and store instructions have several different formats in order to reduce code size and speed up execution. The register file is organized as sixteen 32-bit registers and includes the Program Counter, the Link Register, and the Stack Pointer. In addition, register R12 is designed to hold return values from function calls and is used implicitly by some instructions. 4.3 The AVR32UC CPU The AVR32UC CPU targets low- and medium-performance applications, and provides an advanced On-Chip Debug (OCD) system, no caches, and a Memory Protection Unit (MPU). A hardware Floating Point Unit (FPU) is also provided through the coprocessor instruction space. Java acceleration hardware is not implemented. AVR32UC provides three memory interfaces, one High Speed Bus master for instruction fetch, one High Speed Bus master for data access, and one High Speed Bus slave interface allowing other bus masters to access data RAMs internal to the CPU. Keeping data RAMs internal to the CPU allows fast access to the RAMs, reduces latency, and guarantees deterministic timing. Also, power consumption is reduced by not needing a full High Speed Bus access for memory accesses. A dedicated data RAM interface is provided for communicating with the internal data RAMs. A local bus interface is provided for connecting the CPU to device-specific high-speed systems, such as floating-point units and I/O controller ports. This local bus has to be enabled by writing a one to the LOCEN bit in the CPUCR system register. The local bus is able to transfer data between the CPU and the local bus slave in a single clock cycle. The local bus has a dedicated memory range allocated to it, and data transfers are performed using regular load and store instructions. Details on which devices that are mapped into the local bus space is given in the CPU Local Bus section in the Memories chapter. Figure 4-1 on page 27 displays the contents of AVR32UC. 26 32117A-10/2010 AT32UC3C OCD interface Reset interface Overview of the AVR32UC CPU Interrupt controller interface Figure 4-1. OCD system Power/ Reset control AVR32UC CPU pipeline MPU 4.3.1 High Speed Bus slave CPU Local Bus master CPU Local Bus High Speed Bus master High Speed Bus High Speed Bus High Speed Bus master High Speed Bus Data memory controller Instruction memory controller CPU RAM Pipeline Overview AVR32UC has three pipeline stages, Instruction Fetch (IF), Instruction Decode (ID), and Instruction Execute (EX). The EX stage is split into three parallel subsections, one arithmetic/logic (ALU) section, one multiply (MUL) section, and one load/store (LS) section. Instructions are issued and complete in order. Certain operations require several clock cycles to complete, and in this case, the instruction resides in the ID and EX stages for the required number of clock cycles. Since there is only three pipeline stages, no internal data forwarding is required, and no data dependencies can arise in the pipeline. Figure 4-2 on page 28 shows an overview of the AVR32UC pipeline stages. 27 32117A-10/2010 AT32UC3C Figure 4-2. The AVR32UC Pipeline MUL IF ID Prefetch unit Decode unit Regfile Read ALU LS 4.3.2 Multiply unit Regfile write ALU unit Load-store unit AVR32A Microarchitecture Compliance AVR32UC implements an AVR32A microarchitecture. The AVR32A microarchitecture is targeted at cost-sensitive, lower-end applications like smaller microcontrollers. This microarchitecture does not provide dedicated hardware registers for shadowing of register file registers in interrupt contexts. Additionally, it does not provide hardware registers for the return address registers and return status registers. Instead, all this information is stored on the system stack. This saves chip area at the expense of slower interrupt handling. 4.3.2.1 Interrupt Handling Upon interrupt initiation, registers R8-R12 are automatically pushed to the system stack. These registers are pushed regardless of the priority level of the pending interrupt. The return address and status register are also automatically pushed to stack. The interrupt handler can therefore use R8-R12 freely. Upon interrupt completion, the old R8-R12 registers and status register are restored, and execution continues at the return address stored popped from stack. The stack is also used to store the status register and return address for exceptions and scall. Executing the rete or rets instruction at the completion of an exception or system call will pop this status register and continue execution at the popped return address. 4.3.2.2 Java Support AVR32UC does not provide Java hardware acceleration. 4.3.2.3 Floating Point Support A fused multiply-accumulate Floating Point Unit (FPU), performaing a multiply and accumulate as a single operation with no intermediate rounding, therby increasing precision is provided. The floating point hardware conforms to the requirements of the C standard, which is based on the IEEE 754 floating point standard. 4.3.2.4 Memory Protection The MPU allows the user to check all memory accesses for privilege violations. If an access is attempted to an illegal memory address, the access is aborted and an exception is taken. The MPU in AVR32UC is specified in the AVR32UC Technical Reference manual. 28 32117A-10/2010 AT32UC3C 4.3.2.5 Unaligned Reference Handling AVR32UC does not support unaligned accesses, except for doubleword accesses. AVR32UC is able to perform word-aligned st.d and ld.d. Any other unaligned memory access will cause an address exception. Doubleword-sized accesses with word-aligned pointers will automatically be performed as two word-sized accesses. The following table shows the instructions with support for unaligned addresses. All other instructions require aligned addresses. Table 4-1. 4.3.2.6 Instructions with Unaligned Reference Support Instruction Supported Alignment ld.d Word st.d Word Unimplemented Instructions The following instructions are unimplemented in AVR32UC, and will cause an Unimplemented Instruction Exception if executed: * All SIMD instructions * All coprocessor instructions if no coprocessors are present * retj, incjosp, popjc, pushjc * tlbr, tlbs, tlbw * cache 4.3.2.7 CPU and Architecture Revision Three major revisions of the AVR32UC CPU currently exist. The device described in this datasheet uses CPU revision 3. The Architecture Revision field in the CONFIG0 system register identifies which architecture revision is implemented in a specific device. AVR32UC CPU revision 3 is fully backward-compatible with revisions 1 and 2, ie. code compiled for revision 1 or 2 is binary-compatible with revision 3 CPUs. 29 32117A-10/2010 AT32UC3C 4.4 4.4.1 Programming Model Register File Configuration The AVR32UC register file is shown below. Figure 4-3. The AVR32UC Register File Application Supervisor INT0 Bit 31 Bit 31 Bit 31 Bit 0 Bit 0 INT1 Bit 0 INT2 Bit 31 Bit 0 INT3 Bit 31 Bit 0 Bit 31 Bit 0 Exception NMI Bit 31 Bit 31 Bit 0 Secure Bit 0 Bit 31 Bit 0 PC LR SP_APP R12 R11 R10 R9 R8 INT0PC R7 INT1PC R6 FINTPC R5 SMPC R4 R3 R2 R1 R0 PC LR SP_SYS R12 R11 R10 R9 R8 INT0PC R7 INT1PC R6 FINTPC R5 SMPC R4 R3 R2 R1 R0 PC LR SP_SYS R12 R11 R10 R9 R8 INT0PC R7 INT1PC R6 FINTPC R5 SMPC R4 R3 R2 R1 R0 PC LR SP_SYS R12 R11 R10 R9 R8 INT0PC R7 INT1PC R6 FINTPC R5 SMPC R4 R3 R2 R1 R0 PC LR SP_SYS R12 R11 R10 R9 R8 INT0PC R7 INT1PC R6 FINTPC R5 SMPC R4 R3 R2 R1 R0 PC LR SP_SYS R12 R11 R10 R9 R8 INT0PC R7 INT1PC R6 FINTPC R5 SMPC R4 R3 R2 R1 R0 PC LR SP_SYS R12 R11 R10 R9 R8 INT0PC R7 INT1PC R6 FINTPC R5 SMPC R4 R3 R2 R1 R0 PC LR SP_SYS R12 R11 R10 R9 R8 INT0PC R7 INT1PC R6 FINTPC R5 SMPC R4 R3 R2 R1 R0 PC LR SP_SEC R12 R11 R10 R9 R8 INT0PC R7 INT1PC R6 FINTPC R5 SMPC R4 R3 R2 R1 R0 SR SR SR SR SR SR SR SR SR SS_STATUS SS_ADRF SS_ADRR SS_ADR0 SS_ADR1 SS_SP_SYS SS_SP_APP SS_RAR SS_RSR 4.4.2 Status Register Configuration The Status Register (SR) is split into two halfwords, one upper and one lower, see Figure 4-4 and Figure 4-5. The lower word contains the C, Z, N, V, and Q condition code flags and the R, T, and L bits, while the upper halfword contains information about the mode and state the processor executes in. Refer to the AVR32 Architecture Manual for details. Figure 4-4. The Status Register High Halfword Bit 31 Bit 16 SS LC 1 - - DM D - M2 M1 M0 EM I3M I2M FE I1M I0M GM 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 1 Bit nam e Initial value G lobal Interrupt M ask Interrupt Level 0 M ask Interrupt Level 1 M ask Interrupt Level 2 M ask Interrupt Level 3 M ask Exception M ask M ode Bit 0 M ode Bit 1 M ode Bit 2 Reserved Debug State Debug State M ask Reserved Secure State 30 32117A-10/2010 AT32UC3C Figure 4-5. The Status Register Low Halfword Bit 15 Bit 0 - T - - - - - - - - L Q V N Z C Bit name 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Initial value Carry Zero Sign Overflow Saturation Lock Reserved Scratch Reserved 4.4.3 Processor States 4.4.3.1 Normal RISC State The AVR32 processor supports several different execution contexts as shown in Table 4-2. Table 4-2. Overview of Execution Modes, their Priorities and Privilege Levels. Priority Mode Security Description 1 Non Maskable Interrupt Privileged Non Maskable high priority interrupt mode 2 Exception Privileged Execute exceptions 3 Interrupt 3 Privileged General purpose interrupt mode 4 Interrupt 2 Privileged General purpose interrupt mode 5 Interrupt 1 Privileged General purpose interrupt mode 6 Interrupt 0 Privileged General purpose interrupt mode N/A Supervisor Privileged Runs supervisor calls N/A Application Unprivileged Normal program execution mode Mode changes can be made under software control, or can be caused by external interrupts or exception processing. A mode can be interrupted by a higher priority mode, but never by one with lower priority. Nested exceptions can be supported with a minimal software overhead. When running an operating system on the AVR32, user processes will typically execute in the application mode. The programs executed in this mode are restricted from executing certain instructions. Furthermore, most system registers together with the upper halfword of the status register cannot be accessed. Protected memory areas are also not available. All other operating modes are privileged and are collectively called System Modes. They have full access to all privileged and unprivileged resources. After a reset, the processor will be in supervisor mode. 4.4.3.2 Debug State The AVR32 can be set in a debug state, which allows implementation of software monitor routines that can read out and alter system information for use during application development. This implies that all system and application registers, including the status registers and program counters, are accessible in debug state. The privileged instructions are also available. All interrupt levels are by default disabled when debug state is entered, but they can individually be switched on by the monitor routine by clearing the respective mask bit in the status register. 31 32117A-10/2010 AT32UC3C Debug state can be entered as described in the AVR32UC Technical Reference Manual. Debug state is exited by the retd instruction. 4.4.3.3 4.4.4 Secure State The AVR32 can be set in a secure state, that allows a part of the code to execute in a state with higher security levels. The rest of the code can not access resources reserved for this secure code. Secure State is used to implement FlashVault technology. Refer to the AVR32UC Technical Reference Manual for details. System Registers The system registers are placed outside of the virtual memory space, and are only accessible using the privileged mfsr and mtsr instructions. The table below lists the system registers specified in the AVR32 architecture, some of which are unused in AVR32UC. The programmer is responsible for maintaining correct sequencing of any instructions following a mtsr instruction. For detail on the system registers, refer to the AVR32UC Technical Reference Manual. Table 4-3. System Registers Reg # Address Name Function 0 0 SR Status Register 1 4 EVBA Exception Vector Base Address 2 8 ACBA Application Call Base Address 3 12 CPUCR CPU Control Register 4 16 ECR Exception Cause Register 5 20 RSR_SUP Unused in AVR32UC 6 24 RSR_INT0 Unused in AVR32UC 7 28 RSR_INT1 Unused in AVR32UC 8 32 RSR_INT2 Unused in AVR32UC 9 36 RSR_INT3 Unused in AVR32UC 10 40 RSR_EX Unused in AVR32UC 11 44 RSR_NMI Unused in AVR32UC 12 48 RSR_DBG Return Status Register for Debug mode 13 52 RAR_SUP Unused in AVR32UC 14 56 RAR_INT0 Unused in AVR32UC 15 60 RAR_INT1 Unused in AVR32UC 16 64 RAR_INT2 Unused in AVR32UC 17 68 RAR_INT3 Unused in AVR32UC 18 72 RAR_EX Unused in AVR32UC 19 76 RAR_NMI Unused in AVR32UC 20 80 RAR_DBG Return Address Register for Debug mode 21 84 JECR Unused in AVR32UC 22 88 JOSP Unused in AVR32UC 23 92 JAVA_LV0 Unused in AVR32UC 32 32117A-10/2010 AT32UC3C Table 4-3. System Registers (Continued) Reg # Address Name Function 24 96 JAVA_LV1 Unused in AVR32UC 25 100 JAVA_LV2 Unused in AVR32UC 26 104 JAVA_LV3 Unused in AVR32UC 27 108 JAVA_LV4 Unused in AVR32UC 28 112 JAVA_LV5 Unused in AVR32UC 29 116 JAVA_LV6 Unused in AVR32UC 30 120 JAVA_LV7 Unused in AVR32UC 31 124 JTBA Unused in AVR32UC 32 128 JBCR Unused in AVR32UC 33-63 132-252 Reserved Reserved for future use 64 256 CONFIG0 Configuration register 0 65 260 CONFIG1 Configuration register 1 66 264 COUNT Cycle Counter register 67 268 COMPARE Compare register 68 272 TLBEHI Unused in AVR32UC 69 276 TLBELO Unused in AVR32UC 70 280 PTBR Unused in AVR32UC 71 284 TLBEAR Unused in AVR32UC 72 288 MMUCR Unused in AVR32UC 73 292 TLBARLO Unused in AVR32UC 74 296 TLBARHI Unused in AVR32UC 75 300 PCCNT Unused in AVR32UC 76 304 PCNT0 Unused in AVR32UC 77 308 PCNT1 Unused in AVR32UC 78 312 PCCR Unused in AVR32UC 79 316 BEAR Bus Error Address Register 80 320 MPUAR0 MPU Address Register region 0 81 324 MPUAR1 MPU Address Register region 1 82 328 MPUAR2 MPU Address Register region 2 83 332 MPUAR3 MPU Address Register region 3 84 336 MPUAR4 MPU Address Register region 4 85 340 MPUAR5 MPU Address Register region 5 86 344 MPUAR6 MPU Address Register region 6 87 348 MPUAR7 MPU Address Register region 7 88 352 MPUPSR0 MPU Privilege Select Register region 0 89 356 MPUPSR1 MPU Privilege Select Register region 1 33 32117A-10/2010 AT32UC3C Table 4-3. 4.5 System Registers (Continued) Reg # Address Name Function 90 360 MPUPSR2 MPU Privilege Select Register region 2 91 364 MPUPSR3 MPU Privilege Select Register region 3 92 368 MPUPSR4 MPU Privilege Select Register region 4 93 372 MPUPSR5 MPU Privilege Select Register region 5 94 376 MPUPSR6 MPU Privilege Select Register region 6 95 380 MPUPSR7 MPU Privilege Select Register region 7 96 384 MPUCRA Unused in this version of AVR32UC 97 388 MPUCRB Unused in this version of AVR32UC 98 392 MPUBRA Unused in this version of AVR32UC 99 396 MPUBRB Unused in this version of AVR32UC 100 400 MPUAPRA MPU Access Permission Register A 101 404 MPUAPRB MPU Access Permission Register B 102 408 MPUCR MPU Control Register 103 412 SS_STATUS Secure State Status Register 104 416 SS_ADRF Secure State Address Flash Register 105 420 SS_ADRR Secure State Address RAM Register 106 424 SS_ADR0 Secure State Address 0 Register 107 428 SS_ADR1 Secure State Address 1 Register 108 432 SS_SP_SYS Secure State Stack Pointer System Register 109 436 SS_SP_APP Secure State Stack Pointer Application Register 110 440 SS_RAR Secure State Return Address Register 111 444 SS_RSR Secure State Return Status Register 112-191 448-764 Reserved Reserved for future use 192-255 768-1020 IMPL IMPLEMENTATION DEFINED Exceptions and Interrupts In the AVR32 architecture, events are used as a common term for exceptions and interrupts. AVR32UC incorporates a powerful event handling scheme. The different event sources, like Illegal Op-code and interrupt requests, have different priority levels, ensuring a well-defined behavior when multiple events are received simultaneously. Additionally, pending events of a higher priority class may preempt handling of ongoing events of a lower priority class. When an event occurs, the execution of the instruction stream is halted, and execution is passed to an event handler at an address specified in Table 4-4 on page 38. Most of the handlers are placed sequentially in the code space starting at the address specified by EVBA, with four bytes between each handler. This gives ample space for a jump instruction to be placed there, jumping to the event routine itself. A few critical handlers have larger spacing between them, allowing the entire event routine to be placed directly at the address specified by the EVBA-relative offset generated by hardware. All interrupt sources have autovectored interrupt service routine (ISR) addresses. This allows the interrupt controller to directly specify the ISR address as an address 34 32117A-10/2010 AT32UC3C relative to EVBA. The autovector offset has 14 address bits, giving an offset of maximum 16384 bytes. The target address of the event handler is calculated as (EVBA | event_handler_offset), not (EVBA + event_handler_offset), so EVBA and exception code segments must be set up appropriately. The same mechanisms are used to service all different types of events, including interrupt requests, yielding a uniform event handling scheme. An interrupt controller does the priority handling of the interrupts and provides the autovector offset to the CPU. 4.5.1 System Stack Issues Event handling in AVR32UC uses the system stack pointed to by the system stack pointer, SP_SYS, for pushing and popping R8-R12, LR, status register, and return address. Since event code may be timing-critical, SP_SYS should point to memory addresses in the IRAM section, since the timing of accesses to this memory section is both fast and deterministic. The user must also make sure that the system stack is large enough so that any event is able to push the required registers to stack. If the system stack is full, and an event occurs, the system will enter an UNDEFINED state. 4.5.2 Exceptions and Interrupt Requests When an event other than scall or debug request is received by the core, the following actions are performed atomically: 1. The pending event will not be accepted if it is masked. The I3M, I2M, I1M, I0M, EM, and GM bits in the Status Register are used to mask different events. Not all events can be masked. A few critical events (NMI, Unrecoverable Exception, TLB Multiple Hit, and Bus Error) can not be masked. When an event is accepted, hardware automatically sets the mask bits corresponding to all sources with equal or lower priority. This inhibits acceptance of other events of the same or lower priority, except for the critical events listed above. Software may choose to clear some or all of these bits after saving the necessary state if other priority schemes are desired. It is the event source's responsability to ensure that their events are left pending until accepted by the CPU. 2. When a request is accepted, the Status Register and Program Counter of the current context is stored to the system stack. If the event is an INT0, INT1, INT2, or INT3, registers R8-R12 and LR are also automatically stored to stack. Storing the Status Register ensures that the core is returned to the previous execution mode when the current event handling is completed. When exceptions occur, both the EM and GM bits are set, and the application may manually enable nested exceptions if desired by clearing the appropriate bit. Each exception handler has a dedicated handler address, and this address uniquely identifies the exception source. 3. The Mode bits are set to reflect the priority of the accepted event, and the correct register file bank is selected. The address of the event handler, as shown in Table 4-4 on page 38, is loaded into the Program Counter. The execution of the event handler routine then continues from the effective address calculated. The rete instruction signals the end of the event. When encountered, the Return Status Register and Return Address Register are popped from the system stack and restored to the Status Register and Program Counter. If the rete instruction returns from INT0, INT1, INT2, or INT3, registers R8-R12 and LR are also popped from the system stack. The restored Status Register contains information allowing the core to resume operation in the previous execution mode. This concludes the event handling. 35 32117A-10/2010 AT32UC3C 4.5.3 Supervisor Calls The AVR32 instruction set provides a supervisor mode call instruction. The scall instruction is designed so that privileged routines can be called from any context. This facilitates sharing of code between different execution modes. The scall mechanism is designed so that a minimal execution cycle overhead is experienced when performing supervisor routine calls from timecritical event handlers. The scall instruction behaves differently depending on which mode it is called from. The behaviour is detailed in the instruction set reference. In order to allow the scall routine to return to the correct context, a return from supervisor call instruction, rets, is implemented. In the AVR32UC CPU, scall and rets uses the system stack to store the return address and the status register. 4.5.4 Debug Requests The AVR32 architecture defines a dedicated Debug mode. When a debug request is received by the core, Debug mode is entered. Entry into Debug mode can be masked by the DM bit in the status register. Upon entry into Debug mode, hardware sets the SR.D bit and jumps to the Debug Exception handler. By default, Debug mode executes in the exception context, but with dedicated Return Address Register and Return Status Register. These dedicated registers remove the need for storing this data to the system stack, thereby improving debuggability. The Mode bits in the Status Register can freely be manipulated in Debug mode, to observe registers in all contexts, while retaining full privileges. Debug mode is exited by executing the retd instruction. This returns to the previous context. 4.5.5 Entry Points for Events Several different event handler entry points exist. In AVR32UC, the reset address is 0x80000000. This places the reset address in the boot flash memory area. TLB miss exceptions and scall have a dedicated space relative to EVBA where their event handler can be placed. This speeds up execution by removing the need for a jump instruction placed at the program address jumped to by the event hardware. All other exceptions have a dedicated event routine entry point located relative to EVBA. The handler routine address identifies the exception source directly. AVR32UC uses the ITLB and DTLB protection exceptions to signal a MPU protection violation. ITLB and DTLB miss exceptions are used to signal that an access address did not map to any of the entries in the MPU. TLB multiple hit exception indicates that an access address did map to multiple TLB entries, signalling an error. All interrupt requests have entry points located at an offset relative to EVBA. This autovector offset is specified by an interrupt controller. The programmer must make sure that none of the autovector offsets interfere with the placement of other code. The autovector offset has 14 address bits, giving an offset of maximum 16384 bytes. Special considerations should be made when loading EVBA with a pointer. Due to security considerations, the event handlers should be located in non-writeable flash memory, or optionally in a privileged memory protection region if an MPU is present. If several events occur on the same instruction, they are handled in a prioritized way. The priority ordering is presented in Table 4-4 on page 38. If events occur on several instructions at different locations in the pipeline, the events on the oldest instruction are always handled before any events on any younger instruction, even if the younger instruction has events of higher priority 36 32117A-10/2010 AT32UC3C than the oldest instruction. An instruction B is younger than an instruction A if it was sent down the pipeline later than A. The addresses and priority of simultaneous events are shown in Table 4-4 on page 38. Some of the exceptions are unused in AVR32UC since it has no MMU, coprocessor interface, or floatingpoint unit. 37 32117A-10/2010 AT32UC3C Table 4-4. Priority and Handler Addresses for Events Priority Handler Address Name Event source Stored Return Address 1 0x80000000 Reset External input Undefined 2 Provided by OCD system OCD Stop CPU OCD system First non-completed instruction 3 EVBA+0x00 Unrecoverable exception Internal PC of offending instruction 4 EVBA+0x04 TLB multiple hit MPU PC of offending instruction 5 EVBA+0x08 Bus error data fetch Data bus First non-completed instruction 6 EVBA+0x0C Bus error instruction fetch Data bus First non-completed instruction 7 EVBA+0x10 NMI External input First non-completed instruction 8 Autovectored Interrupt 3 request External input First non-completed instruction 9 Autovectored Interrupt 2 request External input First non-completed instruction 10 Autovectored Interrupt 1 request External input First non-completed instruction 11 Autovectored Interrupt 0 request External input First non-completed instruction 12 EVBA+0x14 Instruction Address CPU PC of offending instruction 13 EVBA+0x50 ITLB Miss MPU PC of offending instruction 14 EVBA+0x18 ITLB Protection MPU PC of offending instruction 15 EVBA+0x1C Breakpoint OCD system First non-completed instruction 16 EVBA+0x20 Illegal Opcode Instruction PC of offending instruction 17 EVBA+0x24 Unimplemented instruction Instruction PC of offending instruction 18 EVBA+0x28 Privilege violation Instruction PC of offending instruction 19 EVBA+0x2C Floating-point UNUSED 20 EVBA+0x30 Coprocessor absent Instruction PC of offending instruction 21 EVBA+0x100 Supervisor call Instruction PC(Supervisor Call) +2 22 EVBA+0x34 Data Address (Read) CPU PC of offending instruction 23 EVBA+0x38 Data Address (Write) CPU PC of offending instruction 24 EVBA+0x60 DTLB Miss (Read) MPU PC of offending instruction 25 EVBA+0x70 DTLB Miss (Write) MPU PC of offending instruction 26 EVBA+0x3C DTLB Protection (Read) MPU PC of offending instruction 27 EVBA+0x40 DTLB Protection (Write) MPU PC of offending instruction 28 EVBA+0x44 DTLB Modified UNUSED 38 32117A-10/2010 AT32UC3C 5. Memories 5.1 Embedded Memories * Internal High-Speed Flash (See Table 5-1 on page 40) - - - - 512 Kbytes 256 Kbytes 128 Kbytes 64 Kbytes * 0 Wait State Access at up to 33 MHz in Worst Case Conditions * 1 Wait State Access at up to 66 MHz in Worst Case Conditions * Pipelined Flash Architecture, allowing burst reads from sequential Flash locations, hiding penalty of 1 wait state access * Pipelined Flash Architecture typically reduces the cycle penalty of 1 wait state operation to only 15% compared to 0 wait state operation * 100 000 Write Cycles, 15-year Data Retention Capability * 4ms Page Programming Time and 8ms Full-Chip Erase Time * Sector Lock Capabilities, Bootloader Protection, Security Bit * 64 Fuses, 32 Of Which Are Preserved During Chip Erase * User Page For Data To Be Preserved During Chip Erase * Internal High-Speed SRAM, Single-cycle access at full speed (See Table 5-1 on page 40) - 64 Kbytes - 32 Kbytes - 16 Kbytes * Supplementary Internal High-Speed System SRAM (HSB RAM), Single-cycle access at full speed - Memory space available on System Bus for peripherals data. - 4 Kbytes 39 32117A-10/2010 AT32UC3C 5.2 Physical Memory Map The system bus is implemented as a bus matrix. All system bus addresses are fixed, and they are never remapped in any way, not even in boot. Note that AVR32UC CPU uses unsegmented translation, as described in the AVR32 Architecture Manual. The 32-bit physical address space is mapped as follows: Table 5-1. AT32UC3C Physical Memory Map AT32UC3 Derivatives Device Start Address C0512C C1512C C2512C C0256C C1256C C2256C C0128C C1128C C2128C C064C C164C C264C Embedded SRAM 0x0000_0000 64 KB 64 KB 64 KB 64 KB 32 KB 32 KB 16 KB 16 KB Embedded Flash 0x8000_0000 512 KB 512 KB 256 KB 256 KB 128 KB 128 KB 64 KB 64 KB SAU 0x9000_0000 1 KB 1 KB 1 KB 1 KB 1 KB 1 KB 1 KB 1 KB HSB SRAM 0xA000_0000 4 KB 4 KB 4 KB 4 KB 4 KB 4 KB 4 KB 4 KB EBI SRAM CS0 0xC000_0000 16 MB - 16 MB - 16 MB - 16 MB - EBI SRAM CS2 0xC800_0000 16 MB - 16 MB - 16 MB - 16 MB - EBI SRAM CS3 0xCC00_0000 16 MB - 16 MB - 16 MB - 16 MB - EBI SRAM CS1 /SDRAM CS0 0xD000_0000 128 MB - 128 MB - 128 MB - 128 MB - HSB-PB Bridge C 0xFFFD_0000 64 KB 64 KB 64 KB 64 KB 64 KB 64 KB 64 KB 64 KB HSB-PB Bridge B 0xFFFE_0000 64 KB 64 KB 64 KB 64 KB 64 KB 64 KB 64 KB 64 KB HSB-PB Bridge A 0xFFFF_0000 64 KB 64 KB 64 KB 64 KB 64 KB 64 KB 64 KB 64 KB 40 32117A-10/2010 AT32UC3C Table 5-2. 5.3 Flash Memory Parameters Part Number Flash Size (FLASH_PW) Number of pages (FLASH_P) Page size (FLASH_W) AT32UC3C0512C AT32UC3C1512C AT32UC3C2512C 512 Kbytes 1024 128 words AT32UC3C0256C AT32UC3C1256C AT32UC3C2256C 256 Kbytes 512 128 words AT32UC3C0128C AT32UC3C1128C AT32UC3C2128C 128 Kbytes 256 128 words AT32UC3C064C AT32UC3C164C AT32UC3C264C 64 Kbytes 128 128 words Peripheral Address Map Table 5-3. Peripheral Address Mapping Address Peripheral Name 0xFFFD0000 PDCA Peripheral DMA Controller - PDCA MDMA Memory DMA - MDMA 0xFFFD1000 0xFFFD1400 USART1 Universal Synchronous/Asynchronous Receiver/Transmitter - USART1 0xFFFD1800 SPI0 Serial Peripheral Interface - SPI0 0xFFFD1C00 CANIF Control Area Network interface - CANIF 0xFFFD2000 TC0 0xFFFD2400 Timer/Counter - TC0 ADCIFA ADC controller interface with Touch Screen functionality - ADCIFA USART4 Universal Synchronous/Asynchronous Receiver/Transmitter - USART4 0xFFFD2800 0xFFFD2C00 TWIM2 Two-wire Master Interface - TWIM2 TWIS2 Two-wire Slave Interface - TWIS2 0xFFFD3000 41 32117A-10/2010 AT32UC3C Table 5-3. Peripheral Address Mapping 0xFFFE0000 HFLASHC Flash Controller - HFLASHC 0xFFFE1000 USBC USB 2.0 OTG Interface - USBC 0xFFFE2000 HMATRIX HSB Matrix - HMATRIX 0xFFFE2400 SAU Secure Access Unit - SAU SMC Static Memory Controller - SMC 0xFFFE2800 0xFFFE2C00 SDRAMC SDRAM Controller - SDRAMC 0xFFFE3000 MACB Ethernet MAC - MACB INTC Interrupt controller - INTC 0xFFFF0000 0xFFFF0400 PM Power Manager - PM 0xFFFF0800 SCIF System Control Interface - SCIF AST Asynchronous Timer - AST WDT Watchdog Timer - WDT EIC External Interrupt Controller - EIC 0xFFFF0C00 0xFFFF1000 0xFFFF1400 0xFFFF1800 FREQM Frequency Meter - FREQM 0xFFFF2000 GPIO 0xFFFF2800 General Purpose Input/Output Controller - GPIO USART0 Universal Synchronous/Asynchronous Receiver/Transmitter - USART0 USART2 Universal Synchronous/Asynchronous Receiver/Transmitter - USART2 USART3 Universal Synchronous/Asynchronous Receiver/Transmitter - USART3 0xFFFF2C00 0xFFFF3000 0xFFFF3400 SPI1 Serial Peripheral Interface - SPI1 42 32117A-10/2010 AT32UC3C Table 5-3. Peripheral Address Mapping 0xFFFF3800 TWIM0 Two-wire Master Interface - TWIM0 TWIM1 Two-wire Master Interface - TWIM1 TWIS0 Two-wire Slave Interface - TWIS0 TWIS1 Two-wire Slave Interface - TWIS1 0xFFFF3C00 0xFFFF4000 0xFFFF4400 0xFFFF4800 IISC Inter-IC Sound (I2S) Controller - IISC PWM Pulse Width Modulation Controller - PWM 0xFFFF4C00 0xFFFF5000 QDEC0 Quadrature Decoder - QDEC0 QDEC1 Quadrature Decoder - QDEC1 0xFFFF5400 0xFFFF5800 TC1 Timer/Counter - TC1 0xFFFF5C00 PEVC Peripheral Event Controller - PEVC 0xFFFF6000 ACIFA0 Analog Comparators Interface - ACIFA0 ACIFA1 Analog Comparators Interface - ACIFA1 0xFFFF6400 0xFFFF6800 DACIFB0 DAC interface - DACIFB0 DACIFB1 DAC interface - DACIFB1 0xFFFF6C00 0xFFFF7000 AW 5.4 aWire - AW CPU Local Bus Mapping Some of the registers in the GPIO module are mapped onto the CPU local bus, in addition to being mapped on the Peripheral Bus. These registers can therefore be reached both by accesses on the Peripheral Bus, and by accesses on the local bus. Mapping these registers on the local bus allows cycle-deterministic toggling of GPIO pins since the CPU and GPIO are the only modules connected to this bus. Also, since the local bus runs at CPU speed, one write or read operation can be performed per clock cycle to the local busmapped GPIO registers. 43 32117A-10/2010 AT32UC3C The following GPIO registers are mapped on the local bus: Table 5-4. Local bus mapped GPIO registers Port Register Mode Local Bus Address Access 0 Output Driver Enable Register (ODER) WRITE 0x4000_0040 Write-only SET 0x4000_0044 Write-only CLEAR 0x4000_0048 Write-only TOGGLE 0x4000_004C Write-only WRITE 0x4000_0050 Write-only SET 0x4000_0054 Write-only CLEAR 0x4000_0058 Write-only TOGGLE 0x4000_005C Write-only Pin Value Register (PVR) - 0x4000_0060 Read-only Output Driver Enable Register (ODER) WRITE 0x4000_0240 Write-only SET 0x4000_0244 Write-only CLEAR 0x4000_0248 Write-only TOGGLE 0x4000_024C Write-only WRITE 0x4000_0250 Write-only SET 0x4000_0254 Write-only CLEAR 0x4000_0258 Write-only TOGGLE 0x4000_025C Write-only Pin Value Register (PVR) - 0x4000_0460 Read-only Output Driver Enable Register (ODER) WRITE 0x4000_0440 Write-only SET 0x4000_0444 Write-only CLEAR 0x4000_0448 Write-only TOGGLE 0x4000_044C Write-only WRITE 0x4000_0450 Write-only SET 0x4000_0454 Write-only CLEAR 0x4000_0458 Write-only TOGGLE 0x4000_045C Write-only - 0x4000_0460 Read-only Output Value Register (OVR) 1 Output Value Register (OVR) 3 Output Value Register (OVR) Pin Value Register (PVR) 44 32117A-10/2010 AT32UC3C Table 5-4. Local bus mapped GPIO registers Port Register Mode Local Bus Address Access 4 Output Driver Enable Register (ODER) WRITE 0x4000_0640 Write-only SET 0x4000_0644 Write-only CLEAR 0x4000_0648 Write-only TOGGLE 0x4000_064C Write-only WRITE 0x4000_0650 Write-only SET 0x4000_0654 Write-only CLEAR 0x4000_0658 Write-only TOGGLE 0x4000_065C Write-only - 0x4000_0660 Read-only Output Value Register (OVR) Pin Value Register (PVR) 45 32117A-10/2010 AT32UC3C 6. Supply and Startup Considerations 6.1 6.1.1 Supply Considerations Power Supplies The AT32UC3C has several types of power supply pins: * VDDIO: Powers I/O lines and the flash. 2 Voltage ranges available: 5V or 3.3V nominal. * VDDANA: Powers the Analog part of the device (Analog I/Os, ADC, ACs, DACs). 2 voltage ranges available: 5V or 3.3V nominal. * VDDIN_5: Input voltage for the 1.8V and 3.3V regulators. 2 Voltage ranges available: 5V or 3.3V nominal. * VDDIN_33: * * * * * - USB I/O power supply - if the device is 3.3V powered: Input voltage, voltage is 3.3V nominal. - if the device is 5V powered: stabilization for the 3.3V voltage regulator, requires external capacitors VDDCORE: Stabilization for the 1.8V voltage regulator, requires external capacitors. GNDCORE: Ground pins for the voltage regulators and the core. GNDANA: Ground pin for Analog part of the design GNDPLL: Ground pin for the PLLs GNDIO: Ground pins for the I/O See "Electrical Characteristics" on page 1243 for power consumption on the various supply pins. For decoupling recommendations for the different power supplies, please refer to the schematic checklist. 6.1.2 Voltage Regulators The AT32UC3C embeds two voltage regulators: * One 1.8V internal regulator that converts from VDDIN_5 to 1.8V. The regulator supplies the output voltage on VDDCORE. * One 3.3V internal regulator that converts from VDDIN_5 to 3.3V. The regulator supplies the USB pads. If the USB is not used, the 3.3V regulator can be disabled through the VREG33CTL field of the VREGCTRL SCIF register. 6.1.3 Regulators Connection The AT32UC3C supports two power supply configurations. * 5V single supply mode * 3.3V single supply mode 6.1.3.1 5V Single Supply Mode In 5V single supply mode, the 1.8V internal regulator is connected to the 5V source (VDDIN_5 pin) and its output feeds VDDCORE. The 3.3V regulator is connected to the 5V source (VDDIN_5 pin) and its output feeds the USB pads. If the USB is not used, the 3.3V regulator can be disabled through the VREG33CTL field of the VREGCTRL SCIF register. 46 32117A-10/2010 AT32UC3C Figure 6-1 on page 47 shows the power schematics to be used for 5V single supply mode. All I/O lines and analog blocks will be powered by the same power (VDDIN_5 = VDDIO = VDDANA). Figure 6-1. 5V Single Power Supply mode + - VDDIO 4.5-5.5V VDDIN_5 VDDANA GNDANA BOD33 Analog: ADC, AC, DAC, ... BOD50 GNDIO VDDIN_33 C IN2 3.3V Reg C IN1 VDDCORE C CORE2 CPU Peripherals Memories 1.8V Reg C CORE1 SCIF, BOD, RCSYS GNDPLL PLL BOD18 GNDCORE POR 6.1.3.2 3.3V Single Supply Mode In 3.3V single supply mode, the VDDIN_5 and VDDIN_33 pins should be connected together externally. The 1.8V internal regulator is connected to the 3.3 V source (VDDIN_5 pin) and its output feeds VDDCORE. The 3.3V regulator should be disabled once the circuit is running through the VREG33CTL field of the VREGCTRL SCIF register. Figure 6-2 on page 48 shows the power schematics to be used for 3.3V single supply mode. All I/O lines and analog blocks will be powered by the same power (VDDIN_5 = VDDIN_33 = VDDIO = VDDANA). 47 32117A-10/2010 AT32UC3C Figure 6-2. 3 Single Power Supply Mode + - VDDIN_5 VDDIO 3.0-3.6V VDDANA GNDANA BOD33 Analog: ADC, AC, DAC, ... BOD50 GNDIO 3.3V Reg VDDIN_33 VDDCORE C CORE2 1.8V Reg CPU Peripherals Memories SCIF, BOD, RCSYS C CORE1 GNDPLL PLL BOD18 GNDCORE POR 6.1.4 Power-up Sequence 6.1.4.1 Maximum Rise Rate To avoid risk of latch-up, the rise rate of the power supplies must not exceed the values described in Table 40-2 on page 1244 . Recommended order for power supplies is also described in this table. 6.1.4.2 Minimum Rise Rate The integrated Power-Reset circuitry monitoring the powering supply requires a minimum rise rate for the VDDIN_5 power supply. See Table 40-2 on page 1244 for the minimum rise rate value. If the application can not ensure that the minimum rise rate condition for the VDDIN power supply is met, the following configuration can be used: * A logic "0" value is applied during power-up on pin RESET_N until: - VDDIN_5 rises above 4.5V in 5V single supply mode. - VDDIN_33 rises above 3V in 3.3V single supply mode. 48 32117A-10/2010 AT32UC3C 6.2 Startup Considerations This chapter summarizes the boot sequence of the AT32UC3C. The behavior after power-up is controlled by the Power Manager. For specific details, refer to the Power Manager chapter. 6.2.1 Starting of clocks At power-up, the BOD33 and the BOD18 are enabled. The device will be held in a reset state by the power-up circuitry, until the VDDIN_33 (resp. VDDCORE) has reached the reset threshold of the BOD33 (resp BOD18). Refer to the Electrical Characteristics for the BOD thresholds. Once the power has stabilized, the device will use the System RC Oscillator (RCSYS, 115KHz typical frequency) as clock source. The BOD18 and BOD33 are kept enabled or are disabled according to the fuse settings (See the Fuse Setting section in the Flash Controller chapter). On system start-up, the PLLs are disabled. All clocks to all modules are running. No clocks have a divided frequency, all parts of the system receive a clock with the same frequency as the internal RC Oscillator. 6.2.2 Fetching of initial instructions After reset has been released, the AVR32UC CPU starts fetching instructions from the reset address, which is 0x8000_0000. This address points to the first address in the internal Flash. The internal Flash uses VDDIO voltage during read and write operations. It is recommended to use the BOD33 to monitor this voltage and make sure the VDDIO is above the minimum level (3.0V). The code read from the internal Flash is free to configure the system to use for example the PLLs, to divide the frequency of the clock routed to some of the peripherals, and to gate the clocks to unused peripherals. 49 32117A-10/2010 AT32UC3C 7. Power Manager (PM) Rev: 4.1.2.1 7.1 Features * * * * * * 7.2 Generates clocks and resets for digital logic On-the-fly frequency change of CPU, HSB and PBx clocks Sleep modes allow simple disabling of logic clocks and clock sources Module-level clock gating through maskable peripheral clocks Wake-up from internal or external interrupts Automatic identification of reset sources Overview The Power Manager (PM) provides synchronous clocks used to clock the main digital logic in the device, namely the CPU, and the modules and peripherals connected to the High Speed Bus (HSB) and the Peripheral Buses (PBx). The PM also contains advanced power-saving features, allowing the user to optimize the power consumption for an application. The synchronous clocks are divided into a number of clock domains, one for the CPU and HSB and one for each PBx. The clocks can run at different speeds, so the user can save power by running peripherals at a relatively low clock, while maintaining a high CPU performance. Additionally, the clocks can be independently changed on-thefly, without halting any peripherals. This enables the user to adjust the speed of the CPU and memories to the dynamic load of the application, without disturbing or re-configuring active peripherals. Each module also has a separate clock, enabling the user to switch off the clock for inactive modules, to save further power. Additionally, clocks and oscillators can be automatically switched off during idle periods by using the sleep instruction on the CPU. The system will return to normal operation on occurrence of interrupts. The Power Manager also contains a Reset Controller, which collects all possible reset sources, generates hard and soft resets, and allows the reset source to be identified by software. 50 32117A-10/2010 AT32UC3C 7.3 Block Diagram Figure 7-1. PM Block Diagram Main Clock Sources Synchronous Clock Generator Synchronous clocks CPU, HSB, PBx Interrupts Sleep Controller Sleep Instruction Reset Controller Resets Reset Sources Power-On Detector External Reset Pad 7.4 I/O Lines Description Table 7-1. I/O Lines Description Name Description Type Active Level RESET_N Reset Input Low 7.5 7.5.1 Product Dependencies Interrupt The PM interrupt line is connected to one of the internal sources of the interrupt controller. Using the PM interrupt requires the interrupt controller to be programmed first. 7.5.2 Clock Implementation In AT32UC3C, the HSB shares the source clock with the CPU. This means that writing to the HSBSEL register has no effect. This register will always read the same value as CPUSEL. The clock for the PM bus interface (CLK_PM) is generated by the Power Manager. This clock is enabled at reset, and can be disabled in the Power Manager, whoever if disabled it can only be re-enabled by a reset. 51 32117A-10/2010 AT32UC3C 7.6 Functional Description 7.6.1 Synchronous Clocks The System RC Oscillator (RCSYS) or a set of other clock sources provide the source for the main clock, which is the common root for the synchronous clocks for the CPU/HSB and PBx modules. For details about the other main clock sources, please refer to the register description of the Main Clock Control Register (MCCTRL). The main clock is divided by an 8-bit prescaler, and each of these synchronous clocks can run from any tapping of this prescaler, or the undivided main clock, as long as fCPU fPBx,. The synchronous clock source can be changed on-the fly, responding to varying load in the application. The clock domains can be shut down in sleep mode, as described in Section 7.6.3. Additionally, the clocks for each module in each synchronous clock domain can be individually masked, to avoid power consumption in inactive modules. Figure 7-2. Synchronous Clock Generation Sleep Controller Sleep Instruction 0 Main Clock Main Clock Sources 1 Prescaler CPUDIV MCSEL Mask CPU Clocks HSB Clocks CPUMASK PBx Clocks CPUSEL 7.6.1.1 Selecting the main clock source The common main clock can be connected to RCSYS or a set of other clock sources. For details about the other main clock sources, please refer to the register description of the Main Clock Control Register (MCCTRL). By default, the main clock will be connected to RCSYS. The user can connect the main clock to an other source by writing the MCSEL field in the MCCTRL register. This must only be done after that unit has been enabled and is ready, otherwise a deadlock will occur. Care should also be taken that the new frequency of the synchronous clocks does not exceed the maximum frequency for each clock domain. 7.6.1.2 Selecting 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 CPUDIV in CPUSEL register to one and CPUSEL in CPUSEL register to the value, resulting in a CPU clock frequency: fCPU = fmain / 2(CPUSEL+1) 52 32117A-10/2010 AT32UC3C Similarly, the clock for the PBx can be divided by writing their respective registers. To ensure correct operation, frequencies must be selected so that fCPU fPBx. Also, frequencies must never exceed the specified maximum frequency for each clock domain. CPUSEL and PBxSEL can be written without halting or disabling peripheral modules. Writing CPUSEL and PBxSEL 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 by writing a one to the registers. This way, it is possible to, e.g., scale CPU and HSB speed according to the required performance, while keeping the PBx frequency constant. For modules connected to the HSB bus, the PB clock frequency must be set to the same frequency as the CPU clock. 7.6.1.3 7.6.2 Clock Ready flag There is a slight delay from CPUSEL and PBxSEL is written and the new clock setting becomes effective. During this interval, the Clock Ready (CKRDY) flag in ISR will read as zero. If CKRDY in the IER 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. Peripheral Clock Masking By default, the clock for all modules are enabled, regardless of which modules are actually being used. It is possible to disable the clock for a module in the CPU, HSB or PBx clock domain by writing the corresponding bit in the Clock Mask register (CPU/HSB/PBx) to zero. When a module is not clocked, it will cease operation, and its registers cannot be read or written. The module can be re-enabled later by writing the corresponding mask bit to one. A module may be connected to several clock domains, in which case it will have several mask bits. The Maskable Module Clocks table contains a list of implemented maskable clocks. 7.6.2.1 7.6.3 Cautionary note 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 flash controller will cause a problem if the CPU needs to read from the flash. Switching off the clock to the Power Manager (PM), which contains the mask registers, or the corresponding PBx bridge, will make it impossible to write the mask registers again. In this case, they can only be re-enabled by a system reset. Sleep Modes In normal operation, all clock domains are active, allowing software execution and peripheral operation. When the CPU is idle, it is possible to switch off the CPU clock and optionally other clock domains to save power. This is activated by the sleep instruction, which takes the sleep mode index number from Table 7-2 on page 54 as argument. 7.6.3.1 Entering and exiting sleep modes The sleep instruction will halt the CPU and all modules belonging to the stopped clock domains. The modules will be halted regardless of the bit settings of the mask registers. Clock sources can also be switched off to save power. Some of these have a relatively long start-up time, and are only switched off when very low power consumption is required. 53 32117A-10/2010 AT32UC3C The CPU and affected modules are restarted when the sleep mode is exited. This occurs when an interrupt triggers. Note that even if an interrupt is enabled in sleep mode, it may not trigger if the source module is not clocked. 7.6.3.2 Supported sleep modes The following sleep modes are supported. These are detailed in Table 7-2 on page 54. * Idle: The CPU is stopped, the rest of the chip is operating. Wake-up sources are any interrupts. * Frozen: The CPU and HSB modules are stopped, peripherals are operating. Wake-up sources are any interrupts from PB modules. * Standby: All synchronous clocks are stopped, but the clock sources are running, allowing quick wake-up to normal mode. Wake-up sources are AST, WDT, external interrupts, external reset or any asynchronous interrupts from PB modules. * Stop: As Standby, but oscillators, and other clock sources are stopped. 32KHz (if enabled), RC oscillators, AST and WDT will still operate. Wake-up sources are the same as for Standby mode. * DeepStop: All synchronous clocks and clock sources are stopped. 32KHz oscillator can run if enabled. RC oscillator still operates. Bandgap voltage reference and BOD is turned off. Wake-up sources are the same as for Standby mode. * Static: All clock sources, including RC oscillator are stopped. 32KHz oscillator can run if enabled. Bandgap voltage reference and BOD detector are turned off. Wake-up sources are AST, WDT (if clocked from the 32KHz oscillator), external interrupts, external reset or any asynchronous interrupts from PB modules. Table 7-2. Sleep Modes Sleep Mode CPU HSB PBx GCLK Clock sources Osc32 RCSYS BOD & Bandgap Voltage Regulator 0 Idle Stop Run Run Run Run Run On Normal mode 1 Frozen Stop Stop Run Run Run Run On Normal mode 2 Standby Stop Stop Stop Run Run Run On Normal mode 3 Stop Stop Stop Stop Stop Run Run On Low power mode 4 DeepStop Stop Stop Stop Stop Run Run Off Low power mode 5 Static Stop Stop Stop Stop Run Stop Off Low power mode Index(1) Note: 1. The sleep mode index corresponds to the argument to the sleep instruction. The power level of the internal voltage regulator is also adjusted according to the sleep mode to reduce the internal regulator power consumption. 7.6.3.3 Precautions when entering sleep mode Modules communicating with external circuits should normally be disabled before entering a sleep mode that will stop the module operation. This prevents erratic behavior when entering or exiting sleep mode. Please refer to the relevant module documentation for recommended actions. Communication between the synchronous clock domains is disturbed when entering and exiting sleep modes. This means that bus transactions are not allowed between clock domains affected 54 32117A-10/2010 AT32UC3C by the sleep mode. The system may hang if the bus clocks are stopped in the middle of a bus transaction. The CPU is automatically stopped in a safe state to ensure that all CPU bus operations are complete when the sleep mode goes into effect. Thus, when entering Idle mode, no further action is necessary. When entering a sleep mode (except Idle mode), all HSB masters must be stopped before entering the sleep mode. Also, if there is a chance that any PB write operations are incomplete, the CPU should perform a read operation from any register on the PB bus before executing the sleep instruction. This will stall the CPU while waiting for any pending PB operations to complete. 7.6.4 Divided PB Clocks The clock generator in the Power Manager provides divided PBx clocks for use by peripherals that require a prescaled PBx clock. This is described in the documentation for the relevant modules. The divided clocks are directly maskable, and are stopped in sleep modes where the PBx clocks are stopped. 7.6.5 Reset Controller The Reset Controller collects the various reset sources in the system and generates hard and soft resets for the digital logic. The device contains a Power-On 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. It is also possible to reset the device by asserting the RESET_N pin. This pin has an internal pull-up, and does not need to be driven externally when negated. Table 7-3 on page 56 lists these and other reset sources supported by the Reset Controller. 55 32117A-10/2010 AT32UC3C Figure 7-3. Reset Controller Block Diagram R C _R C A U SE R E S ET _N P ow er-O n D etector CPU, HSB, PBx B row nout D etector R eset C ontroller O C D , AST, W D T, C lock G enerator JTAG AW IR E OCD W atchdog R eset In addition to the listed reset types, the JTAG & AWIRE can keep parts of the device statically reset. See JTAG and AWIRE documentation for details. Table 7-3. Reset Description Reset source Description Power-on Reset Supply voltage below the power-on reset detector threshold voltage External Reset RESET_N pin asserted Brownout Reset Supply voltage on VDDCORE below the brownout reset detector threshold voltage CPU Error Caused by an illegal CPU access to external memory while in Supervisor mode Watchdog Timer See Watchdog Timer documentation. OCD See On-Chip Debug documentation When a Reset occurs, some parts of the chip are not necessarily reset, depending on the reset source. Only the Power On Reset (POR) will force a reset of the whole chip. Refer to the module configuration chapter to know the effect of the different reset events. The table located in the module configuration chapter lists parts of the device that are reset, depending on the reset source.The cause of the last reset can be read from the RCAUSE register. This register contains one bit for each reset source, and can be read during the boot sequence of an application to determine the proper action to be taken. 56 32117A-10/2010 AT32UC3C 7.6.5.1 Power-On Detector The Power-On Detector monitors the VDDCORE supply pin and generates a reset when the device is powered on. The reset is active until the supply voltage from the linear regulator is above the power-on threshold level. The reset will be re-activated if the voltage drops below the power-on threshold level. See Electrical Characteristics for parametric details. 7.6.5.2 External Reset The external reset detector monitors the state of the RESET_N pin. By default, a low level on this pin will generate a reset. 7.6.6 Clock Failure Detector This mechanism allows switching the main clock to the safe RCSYS clock, when the main clock source is considered off. This may happen when a external crystal is selected as the clock source of the main clock but the crystal is not mounted on the board. The mechanism is to detect, during a RCSYS period, at least one rising edge of the main clock. If no rising edge is seen the clock is considered failed. Example: * RCSYS = 115khz => Failure detected if the main clock is < 115 kHz As soon as the detector is enabled, the clock failure detector will monitor the divided main clock. Note that the detector does not monitor if the RCSYS is the source of the main clock, or if the main clock is temporarily not available (startup-time after a wake-up, switching timing etc.), or in sleep mode where the main clock is driven by the RCSYS (Stop and DeepStop mode). When a clock failure is detected, the main clock automatically switches to the RCSYS clock and the CFD interrupt is generated if enabled. The MCCTRL register that selects the source clock of the main clock is changed by hardware to indicate that the main clock comes from RCSYS. 7.6.7 Interrupts The PM has a number of interrupts: * AE: Access Error, set if a lock protected register is written without first being unlocked. * CKRDY: Clock Ready, set when new CKSEL settings are effective. * CFD: Clock Failure Detected, set if the system detects that the main clock is not running. 57 32117A-10/2010 AT32UC3C 7.7 User Interface Table 7-4. PM Register Memory Map Offset Register Name Access Reset State 0x0000 Main Clock Control MCCTRL Read/Write 0x00000000 0x0004 CPU Clock Select CPUSEL Read/Write 0x00000000 0x0008 HSB Clock Select HSBSEL Read Only 0x00000000 0x000C PBA Clock Select PBASEL Read/Write 0x00000000 0x00010 PBB Clock Select PBBSEL Read/Write 0x00000000 0x0014 PBC Clock Select PBCSEL Read/Write 0x00000000 0x0020 CPU Mask CPUMASK Read/Write 0x00000003 0x0024 HSB Mask HSBMASK Read/Write 0x00003FFF 0x0028 PBA Mask PBAMASK Read/Write 0x07FFFFFF 0x002C PBB Mask PBBMASK Read/Write 0x0000007F 0x0030 PBC Mask PBCMASK Read/Write 0x000003FF 0x0040 PBA Divided Mask PBADIVMASK Read/Write 0x0000007F 0x0044 PBB Divided Mask PBBDIVMASK Read/Write 0x0000007F 0x0048 PBC Divided Mask PBCDIVMASK Read/Write 0x0000007F 0x0054 Clock Failure Detector Control CFDCTRL Read/Write 0x00000000 0x0058 Unlock Register UNLOCK Write Only - 0x00C0 PM Interrupt Enable Register IER Write Only 0x00000000 0x00C4 PM Interrupt Disable Register IDR Write Only 0x00000000 0x00C8 PM Interrupt Mask Register IMR Read Only 0x00000000 0x00CC PM Interrupt Status Register ISR Read Only 0x00000000 0x00D0 PM Interrupt Clear Register ICR Write Only 0x00000000 0x00D4 Status Register SR Read Only 0x00000000 0x0180 Reset Cause Register RCAUSE Read Only Latest Reset Source 0x0184 Wake Cause Register WCAUSE Read Only Latest Wake Source 0x0188 Asynchronous Wake Enable AWEN Read/Write 0x00000000 0x03F8 Configuration Register CONFIG Read Only -(1) 0x03FC Version Register VERSION Read Only -(1) Note: 1. The reset value is device specific. Please refer to the Module Configuration section at the end of this chapter. 58 32117A-10/2010 AT32UC3C 7.7.1 Name: Main Clock Control MCCTRL Access Type: Read/Write Offset: 0x0000 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 - - - - - - - - 7 6 5 4 3 2 1 0 - - - - - MCSEL * MCSEL: Main Clock Select Table 7-5. Main clocks in AT32UC3C. MCSEL[1:0] Main clock source 0 System RC oscillator (RCSYS) 1 Oscillator 0 2 Oscillator 1 3 PLL0 4 PLL1 5 8 MHz RC oscillator (RC8M) others reserved Note that this register is protected by a lock. To write to this register the UNLOCK register has to be written first. Please refer to the UNLOCK register description for details. 59 32117A-10/2010 AT32UC3C 7.7.2 Name: CPU Clock Select CPUSEL Access Type: Read/Write Offset: 0x0004 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 - - - - - - - - 7 6 5 4 3 2 1 0 CPUDIV - - - - CPUSEL * CPUDIV, CPUSEL: CPU Division and Clock Select * CPUDIV = 0: CPU clock equals main clock. * CPUDIV = 1: CPU clock equals main clock divided by 2(CPUSEL+1). Note that if CPUDIV is written to 0, CPUSEL should also be written to 0 to ensure correct operation. Also note that writing this register clears POSCSR:CKRDY. The register must not be re-written until CKRDY goes high. Note that this register is protected by a lock. To write to this register the UNLOCK register has to be written first. Please refer to the UNLOCK register description for details. 60 32117A-10/2010 AT32UC3C 7.7.3 Name: HSB Clock Select HSBSEL Access Type: Read Only Offset: 0x0008 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 - - - - - - - - 7 6 5 4 3 2 1 0 HSBDIV - - - - HSBSEL This register is read-only and its content is always equal to CPU_SEL 61 32117A-10/2010 AT32UC3C 7.7.4 Name: PBx Clock Select PBxSEL Access Type: Read/Write Offset: 0x000C, 0x0010, 0x0014 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 - - - - - - - - 7 6 5 4 3 2 1 0 PBDIV - - - - PBSEL * PBDIV, PBSEL: PBx Division and Clock Select * PBDIV = 0: PBx clock equals main clock. * PBDIV = 1: PBx clock equals main clock divided by 2(PBSEL+1). Note that if PBDIV is written to 0, PBSEL should also be written to 0 to ensure correct operation. Also note that writing this register clears POSCSR:CKRDY. The register must not be re-written until CKRDY goes high. Note that this register is protected by a lock. To write to this register the UNLOCK register has to be written first. Please refer to the UNLOCK register description for details. 62 32117A-10/2010 AT32UC3C 7.7.5 Name: Clock Mask CPU/HSB/PBA/PBBMASK Access Type: Read/Write Offset: 0x0020, 0x0024, 0x0028, 0x002C, 0x0030 Reset Value: - 31 30 29 28 27 26 25 24 19 18 17 16 11 10 9 8 3 2 1 0 MASK[31:24] 23 22 21 20 MASK[23:16] 15 14 13 12 MASK[15:8] 7 6 5 4 MASK[7:0] * MASK: Clock Mask * If bit n is cleared, the clock for module n is stopped. If bit n is set, the clock for module n is enabled according to the current power mode. The number of implemented bits in each mask register, as well as which module clock is controlled by each bit, is shown in Table 7-6. Table 7-6. Maskable module clocks in AT32UC3C. Bit CPUMASK HSBMASK PBAMASK PBBMASK PBCMASK 0 - SAU INTC FLASHC PDCA 1 OCD PDCA PM USBC MDMA 2 - MDMA SCIF HMATRIX USART1 3 - USBC AST SAU SPI0 4 - CANIF WDT SMC CANIF 5 - HFLASHC EIC SDRAMC TC0 6 - PBA Bridge FREQM MACB ADCIFA 7 - PBB Bridge GPIO - USART4 8 - PBC Bridge USART0 - TWIM2 9 - HSB RAM USART2 - TWIS2 10 - EBI USART3 - - 11 - MACB SPI1 - - 12 - PEVC TWIM0 - - 63 32117A-10/2010 AT32UC3C Table 7-6. Maskable module clocks in AT32UC3C. Bit CPUMASK HSBMASK PBAMASK PBBMASK PBCMASK 13 - - TWIM1 - - 14 - - TWIS0 - - 15 - - TWIS1 - - 16 - - IISC - - 17 - - PWM - - 18 - - QDEC0 - - 19 - - QDEC1 - - 20 - - TC1 - - 21 - - PEVC - - 22 - - ACIFA0 - - 23 - - ACIFA1 - - 24 - - DACIFB0 - - 25 - - DACIFB1 - - 26 - - AW - - 31:27 - - - - - Note that this register is protected by a lock. To write to this register the UNLOCK register has to be written first. Please refer to the UNLOCK register description for details. 64 32117A-10/2010 AT32UC3C 7.7.6 Name: Divided Clock Mask PBADIVMASK/PBBDIVMASK/PBCDIVMASK Access Type: Read/Write Offset: 0x0040, 0x0044, 0x0048 Reset Value: - 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - 15 14 13 12 11 10 9 8 - - - - - - - - 7 6 5 4 3 2 1 0 - MASK[6:0] * MASK: Clock Mask If bit n is written to zero, the clock divided by 2(n+1) is stopped. If bit n is written to one, the clock divided by 2(n+1) is enabled according to the current power mode. Table 7-7 and Table 7-8 show what clocks are affected by the different MASK bits. Table 7-7. Bit PBA Divided Clock Mask USART0 USART2 USART3 TC1 0 - TIMER1_CLOCK2 1 - - 2 CLK_PBA_USART_DIV TIMER1_CLOCK3 3 - - 4 - TIMER1_CLOCK4 5 - - 6 - TIMER1_CLOCK5 Table 7-8. Bit PBC Divided Clock Mask USART1 USART4 TC0 0 - TIMER0_CLOCK2 1 - - 2 CLK_PBC_USART_DIV TIMER0_CLOCK3 3 - - 65 32117A-10/2010 AT32UC3C Table 7-8. Bit PBC Divided Clock Mask USART1 USART4 TC0 4 - TIMER0_CLOCK4 5 - - 6 - TIMER0_CLOCK5 Note that this register is protected by a lock. To write to this register the UNLOCK register has to be written first. Please refer to the UNLOCK register description for details. 66 32117A-10/2010 AT32UC3C 7.7.7 Name: Clock Failure Detector Control Register CFDCTRL Access Type: Read/Write Offset: 0x0054 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 SFV - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 - - - - - - - - 7 6 5 4 3 2 1 0 - - - - - - CFDEN * SFV: Store Final Value * 0: The register is read/write * 1: The register is read-only, to protect against further accidental writes. * CFDEN: Clock Failure Detection Enable * 0: Clock Failure Detector is disabled * 1: Clock Failure Detector is enabled Note that this register is protected by a lock. To write to this register the UNLOCK register has to be written first. Please refer to the UNLOCK register description for details. 67 32117A-10/2010 AT32UC3C 7.7.8 Name: PM Unlock Register UNLOCK Access Type: Write-Only Offset: 0x0058 Reset Value: - 31 30 29 28 27 26 25 24 KEY 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 - - - - - - 7 6 5 4 3 2 ADDR[9:8] 1 0 ADDR[7:0] To unlock a write protected register, first write to the UNLOCK register with the address of the register to unlock in the ADDR field and 0xAA in the KEY field. Then, in the next PB access write to the register specified in the ADDR field. * KEY: Unlock Key * Write this bit field to 0xAA to enable unlock. * ADDR: Unlock Address * Write the address of the register to unlock to this bit field. 68 32117A-10/2010 AT32UC3C 7.7.9 Interrupt Enable Register Name: IER Access Type: Write-only Offset: 0x0C0 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 AE - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 - - - - - - - - 7 6 5 4 3 2 1 0 - - CKRDY - - - - CFD Writing a zero to a bit in this register has no effect. Writing a one to a bit in this register will set the corresponding bit in IMR. 69 32117A-10/2010 AT32UC3C 7.7.10 Interrupt Disable Register Name: IDR Access Type: Write-only Offset: 0x0C4 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 AE - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 - - - - - - - - 7 6 5 4 3 2 1 0 - - CKRDY - - - - CFD Writing a zero to a bit in this register has no effect. Writing a one to a bit in this register will clear the corresponding bit in IMR. 70 32117A-10/2010 AT32UC3C 7.7.11 Interrupt Mask Register Name: IMR Access Type: Read-only Offset: 0x0C8 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 AE - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 - - - - - - - - 7 6 5 4 3 2 1 0 - - CKRDY - - - - CFD 0: The corresponding interrupt is disabled. 1: The corresponding interrupt is enabled. This bit is cleared when the corresponding bit in IDR is written to one. This bit is set when the corresponding bit in IER is written to one. 71 32117A-10/2010 AT32UC3C 7.7.12 Interrupt Status Register Name: ISR Access Type: Read-only Offset: 0x0CC Reset Value: 0x00000000 31 30 29 28 27 26 25 24 AE - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 - - - - - - - - 7 6 5 4 3 2 1 0 - - CKRDY - - - - CFD 0: The corresponding interrupt is cleared. 1: The corresponding interrupt is pending. This bit is cleared when the corresponding bit in ICR is written to one. This bit is set when the corresponding interrupt occurs. 72 32117A-10/2010 AT32UC3C 7.7.13 Interrupt Clear Register Name: ICR Access Type: Write-only Offset: 0x0D0 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 AE - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 - - - - - - - - 7 6 5 4 3 2 1 0 - - CKRDY - - - - CFD Writing a zero to a bit in this register has no effect. Writing a one to a bit in this register will clear the corresponding bit in ISR. 73 32117A-10/2010 AT32UC3C 7.7.14 Status Register Name: SR Access Type: Read-only Offset: 0x0D4 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 AE - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 - - - - - - - - 7 6 5 4 3 2 1 0 - - CKRDY - - - - CFD * AE: Access Error 0: No access error has occured. 1: A write to lock protected register without unlocking it has occured. * CKRDY: Clock Ready 0: The CKSEL register has been written, and the new clock setting is not yet effective. 1: The synchronous clocks have frequencies as indicated in the CKSEL register. * CFD: Clock Failure Detected 0: Main clock is running correctly. 1: Failure on main clock detected. Main clock is now running on RC osc. 74 32117A-10/2010 AT32UC3C 7.7.15 Name: Reset Cause RCAUSE Access Type: Read-only Offset: 0x0180 Reset Value: Latest Reset Source 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 - - BOD33 - AWIRE - - OCDRST 7 6 5 4 3 2 1 0 - JTAG WDT EXT BOD POR CPUERR * BOD33: Brown-out 3.3V reset The CPU was reset due to the supply voltage being lower than the 3.3V Supply Monitor (BOD33) threshold level. * AWIRE: AWIRE Reset The CPU was reset by the AWIRE * OCDRST: OCD Reset The CPU was reset because the RES strobe in the OCD Development Control register has been written to one. * CPUERR: CPU Error The CPU was reset because had detected an illegal access. * JTAG: JTAG Reset The chip was reset by the JTAG system reset. * WDT: Watchdog Reset The CPU was reset because of a watchdog time-out. * EXT: External Reset Pin The CPU was reset due to the RESET pin being asserted. * BOD: Brown-out Reset The CPU was reset due to the core supply voltage being lower than the brown-out threshold level. * POR: Power-on Reset The CPU was reset due to the core supply voltage being lower than the power-on threshold level, or due to the input voltage being lower than the minimum required input voltage for the voltage regulator. 75 32117A-10/2010 AT32UC3C 7.7.16 Wake Cause Register Register name WCAUSE Register access Read-only Offset: 0x0184 Reset Value: Latest Reset Source 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - 15 14 13 12 11 10 9 8 2 1 0 WCAUSE[17:16] WCAUSE[15:8] 7 6 5 4 3 WCAUSE[7:0] * A bit in this register is set on wake up caused by the peripheral referred to in Table 7-9. Table 7-9. Wake Cause Bit Wake Cause 1 USBC 1 CANIF-RXLINE[0] 2 CANIF-RXLINE[1] 3 - 4 TWI Slave 0 5 TWI Slave 1 6 TWI Slave 2 15:7 - 16 EIC 17 AST 31:18 - 76 32117A-10/2010 AT32UC3C 7.7.17 Asynchronous Wake Up Enable Register Register name AWEN Register access Read/Write Offset: 0x0188 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 19 18 17 16 11 10 9 8 3 2 1 0 AWEN[31:24] 23 22 21 20 AWEN[23:16] 15 14 13 12 AWEN[15:8] 7 6 5 4 AWEN[7:0] Each bit in this register corresponds to an asynchronous wake up, according to Table 7-10. 0: The corresponding wake up is disabled. 1: The corresponding wake up is enabled Table 7-10. Asynchronous Wake Up Bit Asynchronous Wake Up 0 USBWEN 1 CANIF0WEN 2 CANIF1WEN 3 - 4 TWIS0WEN 5 TWIS1WEN 6 TWIS2WEN 31:7 - 77 32117A-10/2010 AT32UC3C 7.7.18 Name: Configuration Register CONFIG Access Type: Read-Only Offset: 0x03F8 Reset Value: 0x000000C3 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 - - - - - - - - 7 6 5 4 3 2 1 0 - - PBD PBC PBB PBA HSBPEVC This register shows the configuration of the PM. * HSBPEVC:HSB PEVC Clock Implemented * * * * 0: HSBPEVC not implemented. 1: HSBPEVC implemented. PBD: PBD Implemented 0: PBD not implemented. 1: PBD implemented. PBC: PBC Implemented 0: PBC not implemented. 1: PBC implemented. PBB: PBB Implemented 0: PBB not implemented. 1: PBB implemented. PBA: PBA Implemented 0: PBA not implemented. 1: PBA implemented. 78 32117A-10/2010 AT32UC3C 7.7.19 Name: Version Register VERSION Access Type: Read-Only Offset: 0x03FC Reset Value: 0x00000410 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - 15 14 13 12 9 8 - - - - 7 6 5 4 VARIANT 11 10 VERSION[11:8] 3 2 1 0 VERSION[7:0] * VARIANT: Variant Number Reserved. No functionality associated. * VERSION: Version Number Version number of the module. No functionality associated. 79 32117A-10/2010 AT32UC3C 7.8 Module Configuration The specific configuration for each PM instance is listed in the following tables. The module bus clocks listed here are connected to the system bus clocks. Please refer to the Power Manager chapter for details. Table 7-11. Module name Clock name Description PM CLK_PM Peripheral Bus clock from the PBA clock domain Table 7-12. Table 7-13. Module clock name Register Reset Values Register Reset Value CONFIG 0x00000087 VERSION 0x00000412 Effect of the different Reset Events Power-On Reset External Reset Watchdog Reset 1.8V BOD Reset 3.3V BOD Reset CPU Error Reset OCD Reset JTAG Reset Awire Reset CPU/HSB/PBx (excluding Power Manager) Y Y Y Y Y Y Y Y Y 32 KHz oscillator Y N N N N N N N N AST control register Y N N N N N N N N GPLP registers Y N N N N N N N N Watchdog control register Y Y N Y Y Y Y Y Y Voltage Calibration register Y N N N N N N N N RC Oscillator Calibration register Y N N N N N N N N 1.8V BOD control register Y Y Y N Y Y Y Y Y 3.3V BOD control register Y Y Y Y N Y Y Y Y Bandgap control register Y Y Y N Y Y Y Y Y Clock control registers Y Y Y Y Y Y Y Y Y OSC control registers Y Y Y Y Y Y Y Y Y OCD system and OCD registers Y Y N Y Y Y N Y Y 80 32117A-10/2010 AT32UC3C 8. System Control Interface (SCIF) Rev: 1.0.2.0 8.1 Features * * * * * * * * * * * * 8.2 Controls integrated oscillators and PLLs Supports 2x General Purpose crystal oscillators, 0.4MHz-20MHz Supports 2x Phase-Locked-Loop, 80-240 MHz Supports 32 KHz low power oscillator (OSC32K) Integrated 115KHz RC Oscillator (RCSYS) Controls 8 MHz / 1 MHz integrated RC oscillator (RC8M) Controls 120 MHz integrated RC oscillator (RC120M) Generic clocks with wide frequency range provided Controls bandgap voltage reference through control and calibration registers Controls Brown-out detectors and supply monitors Controls Voltage Regulator behavior and calibration Two 32-bit general purpose low power registers Description The System Control Interface (SCIF) controls the Oscillators, PLL, Generic Clocks, BODs, the voltage regulators and general purpose low power registers. 8.3 I/O Lines Description Table 8-1. 8.4 8.4.1 I/O Lines Description Pin Name Pin Description Type XIN0 Crystal 0 Input Analog/Digital XIN1 Crystal 1 Input Analog/Digital XIN32 Crystal 32 Input Analog/Digital XOUT0 Crystal 0 Output Analog XOUT1 Crystal 1 Output Analog XOUT32 Crystal 32 Output Analog GCLK[1:0] Generic Clock Output Digital Product Dependencies I/O Lines The SCIF provides a number of generic clock outputs, which can be connected to output pins, multiplexed with GPIO lines. The programmer must first program the GPIO controller to assign these pins to their peripheral function. If the I/O pins of the SCIF are not used by the application, they can be used for other purposes by the GPIO controller. Oscillators pins are also multiplexed with GPIO. When oscillators are used, the related pins are controlled directly by the SCIF, overriding GPIO settings. 81 32117A-10/2010 AT32UC3C 8.4.2 Interrupt The SCIF interrupt line is connected to one of the internal sources of the interrupt controller. Using the SCIF interrupt requires the interrupt controller to be programmed first. 8.4.3 Debug Operation The SCIF module does not interact with debug operations. 8.4.4 Clocks The SCIF controls all oscillators on the part. Those oscillators can then be used as sources for for generic clocks (handled by the SCIF) and for the CPU and peripherals (in this case, selection of source is done by the Power Manager). 8.5 8.5.1 Functional Description Oscillator Operation The main oscillator is designed to be used with an external 0.4 to 20MHz crystal and two biasing capacitors, as shown in Figure 8-1. The oscillator can be used for the main clock in the device, as described in the Power Manager chapter. The oscillator can be used as source for the generic clocks, as described in "Generic Clocks" on page 84. The oscillator is disabled by default after reset. When the oscillator is disabled, the XIN and XOUT pins can be used as general purpose I/Os. When the oscillator is configured to use an external clock, the clock must be applied to the XIN pin while the XOUT pin can be used as a general purpose I/O. The oscillator can be enabled by writing a one to the OSCEN bit in OSCCTRLn. Operation mode (external clock or crystal) is chosen by writing to the MODE field in OSCCTRLn. The oscillator is automatically switched off in certain sleep modes to reduce power consumption, as described in the Power Manager chapter. After a hard reset, or when waking up from a sleep mode that disabled the oscillator, the oscillator may need a certain amount of time to stabilize on the correct frequency. This start-up time can be set in the OSCCTRLn register. The SCIF masks the oscillator outputs during the start-up time, to ensure that no unstable clocks propagate to the digital logic. The OSCnRDY bits in PCLKSR are automatically set and cleared according to the status of the oscillators. A zero to one transition on these bits can also be configured to generate an interrupt, as described in "Interrupts" on page 88. 82 32117A-10/2010 AT32UC3C Figure 8-1. Oscillator connections C LEXT XOUT Ci CL X IN 8.5.2 C LE X T 32KHz Oscillator (OSC32K) Operation The 32 KHz oscillator (OSC32K) operates as described for the Oscillator above. The 32 KHz oscillator is used as source clock for the Asynchronous Timer and the Watchdog Timer. The 32KHz oscillator can be used as source for the generic clocks, as described in "Generic Clocks" on page 84. The oscillator is disabled by default, but can be enabled by writing a one to the OSC32EN bit in OSCCTRL32. The oscillator is an ultra-low power design and remains enabled in all sleep modes. While the 32 KHz oscillator is disabled, the XIN32 and XOUT32 pins are available as general purpose I/Os. When the oscillator is configured to work with an external clock (MODE field in OSCCTRL32 register), the external clock must be connected to XIN32 while the XOUT32 pin can be used as a general purpose I/O. The startup time of the 32KHz oscillator can be set in the OSCCTRL32, after which OSC32RDY in PCLKSR is set. An interrupt can be generated on a zero to one transition of OSC32RDY. As a crystal oscillator usually requires a very long startup time (up to 1 second), the 32 KHz oscillator will keep running across resets, except Power-On-Reset. The 32KHz oscillator is not controlled by the sleep controller, and will run in all sleep modes if enabled. 8.5.3 PLL Operation The device contains two PLLs, PLL0 and PLL1. These are disabled by default, but can be enabled to provide high frequency source clocks for synchronous or generic clocks. The PLLs can take either Oscillator 0 or 1 as reference clock. The PLL output is divided by a multiplication factor, and the PLL compares the resulting clock to the reference clock. The PLL will adjust its output frequency until the two compared clocks are equal, thus locking the output frequency to a multiple of the reference clock frequency. When the PLL is switched on, or when changing the clock source or multiplication factor for the PLL, the PLL is unlocked and the output frequency is undefined. The PLL clock for the digital logic is automatically masked when the PLL is unlocked, to prevent connected digital logic from receiving a too high frequency and thus becoming unstable. 83 32117A-10/2010 AT32UC3C Figure 8-2. PLL with control logic and filters PLLMUL Output Divider Osc0 clock 0 Osc1 clock 1 Input Divider PLLOSC 8.5.3.1 PLLDIV fIN PLL Mask PLL clock LOCK PLLEN PLLOPT Enabling the PLL PLLn is enabled by writing a one to the PLLEN bit in the PLLn register. PLLOSC selects Oscillator 0 or 1 as clock source. The PLLMUL and PLLDIV bit fields must be written with the multiplication and division factors. The PLLn.PLLOPT field should be set to proper values according to the PLL operating frequency. The PLLOPT field can also be set to divide the output frequency of the PLLs by 2. The lock signal for each PLL is available as a LOCKn flag in POSCSR. An interrupt can be generated on a 0 to 1 transition of these bits. 8.5.4 Generic Clocks Timers, communication modules, and other modules connected to external circuitry may require specific clock frequencies to operate correctly. The SCIF contains an implementation defined number of generic clocks that can provide a wide range of accurate clock frequencies. Each generic clock module runs from either clock source listed in "Generic Clock Source" on page 117. The selected source can optionally be divided by any even integer up to 512. Each clock can be independently enabled and disabled, and is also automatically disabled along with peripheral clocks by the Sleep Controller in the Power Manager. 84 32117A-10/2010 AT32UC3C Figure 8-3. Generic clock generation Sleep Controller 0 Mask Divider OSCSEL 8.5.4.1 DIV Generic Clock 1 DIVEN CEN Enabling a generic clock A generic clock is enabled by writing a one to the CEN bit in GCCTRL to one. Each generic clock can individually select a clock source by setting the OSCSEL bits. The source clock can optionally be divided by writing a one to DIVEN and the division factor to DIV, resulting in the output frequency: fGCLK = fSRC / (2*(DIV+1)) 8.5.4.2 Disabling a generic clock The generic clock can be disabled by writing a zero to CEN or entering a sleep mode that disables the PB clocks. In either case, the generic clock will be switched off on the first falling edge after the disabling event, to ensure that no glitches occur. If CEN is written to zero, the bit will still read as one until the next falling edge occurs, and the clock is actually switched off. When writing a zero to CEN, the other bits in GCCTRL should not be changed until CEN reads as zero, to avoid glitches on the generic clock. When the clock is disabled, both the prescaler and output are reset. 8.5.4.3 Changing clock frequency When changing generic clock frequency by writing GCCTRL, the clock should be switched off by the procedure above, before being re-enabled with the new clock source or division setting. This prevents glitches during the transition. 8.5.4.4 Generic clock implementation In AT32UC3C, the generic clocks are allocated to different functions as shown in Table 8-2. Table 8-2. Generic clock allocation Clock number Function Name 0 USB clock (48 MHz) GCLK_USBC 1 CANIF GCLK_CANIF 2 AST GCLK_AST 85 32117A-10/2010 AT32UC3C Table 8-2. Generic clock allocation Clock number 8.5.5 Function Name 3 - 4 PWM GCLK_PWM 5 QDEC0 GCLK_QDEC0 6 QDEC1 GCLK_QDEC1 7 GCLK event, mapped to event number 16. See the Module Configuration of PEVC for more details. 8 GCLK event, mapped to event number 17. See the Module Configuration of PEVC for more details. 9 GCLK[0] output pin 10 GCLK[1] output pin 11 IISC GCLK_IISC 1.8V Brown Out Detection (BOD18) The 1.8V Brown-Out Detector (BOD18) monitors the VDDCORE supply pin and compares the supply voltage to the brown-out detection level, as set in BOD.LEVEL. The BOD18 is disabled by default, but can be enabled either by software or by flash fuses. The 1.8V Brown-Out Detector can either generate an interrupt or a reset when the supply voltage is below the brown-out detection level. In any case, the BOD18 output value is given by the PCLKSR.BODDET bit. Note that any change to the BOD.LEVEL field of the BOD register should be done with the BOD18 deactivated to avoid spurious reset or interrupt. When turned-on, the BOD18 output will be masked during one half of a RCSYS clock cycle and two main clocks cycles to avoid false results. If the JTAG or the AWIRE is enabled, the BOD18 reset and interrupt will be masked. See Electrical Characteristics for parametric details. Although it is not recommended, it is still possible to override the default factory settings by writing to those registers. To prevent unexpected writes due to software bugs, write access to this register is protected by a locking mechanism, for details please refer to the UNLOCK register description. 8.5.6 3.3V Brown Out Detection (BOD33) The 3.3V Brown-Out Detector (BOD33) monitors the VDDIN_5 supply pin and compares the supply voltage to the brown-out detection level, as set in BOD33.LEVEL. The BOD33 is disabled by default, but can be enabled by software or by flash fuses. The 3.3V Brown-Out Detector can generate an interrupt or a reset when the supply voltage is below the brown-out detection level. In any case, the BOD33 value is given by the PCLKSR.BOD33DET bit. Note that any change to the BOD33.LEVEL field of the BOD33 register should be done with the BOD33 deactivated to avoid spurious interrupt. When turned-on, the BOD33 output will be masked during one half of a RCSYS clock cycle and two main clocks cycles to avoid false results. 86 32117A-10/2010 AT32UC3C If the JTAG or the AWIRE is enabled, the BOD33 reset and interrupt will be masked. See Electrical Characteristics for parametric details. To prevent unexpected writes due to software bugs, write access to this register is protected by a locking mechanism, for details please refer to the UNLOCK register description. 8.5.7 5V Brown Out Detection (BOD50) The 5V Brown-Out Detector (BOD50) monitors the VDDIN_5 supply pin and compares the supply voltage to the brown-out detection level, as set in BOD50.LEVEL. The BOD50 is disabled by default, but can be enabled by software. The 5V Brown-Out Detector can generate an interrupt when the supply voltage is below the brown-out detection level. In any case, the BOD50 output value is given by the PCLKSR.BOD50DET bit. Note that any change to the BOD50.LEVEL field of the BOD50 register should be done with the BOD50 deactivated to avoid spurious interrupt. When turned-on, the BOD50 output will be masked during one half of a RCSYS clock cycle and two main clocks cycles to avoid false results. If the JTAG or the AWIRE is enabled, the BOD50 interrupt will be masked. See Electrical Characteristics for parametric details. To prevent unexpected writes due to software bugs, write access to this register is protected by a locking mechanism, for details please refer to the UNLOCK register description. 8.5.8 Bandgap The Flash memory, the Brown-Out Detectors need a stable voltage reference to operate. This reference voltage is provided by an internal Bandgap voltage reference. This reference is automatically turned on at startup and turned off during DEEPSTOP and STATIC sleep modes to save power. The Bandgap voltage reference is calibrated through the BGCR.CALIB field. This field is loaded after a Power On Reset with default values stored in factory-programmed flash fuses. It is not recommended to override default factory settings as it may prevent correct operation of the Flash and BODs. To prevent unexpected writes due to software bugs, write access to this register is protected by a locking mechanism, for details please refer to the UNLOCK register description. 8.5.9 Voltage Regulators The embedded 1.8V regulator provides the core supply. The embedded 3.3V voltage regulator is used to supply the USB pads. Both regulators are turned on at startup. If the application is supplied with a voltage range around 3.3V or the application does not use the USB interface, the 3.3V voltage regulator has to be turned off by writing 11 binary to VREGCTRL.VREG33CTL. The 1.8V voltage regulator has its own voltage reference that is calibrated through the VREGCR.CALIB field. This field is loaded after a Power On Reset with default values stored in factory-programmed flash fuses. Although it is not recommended, it is still possible to override the default factory settings by writing to those registers. To prevent unexpected writes due to software bugs, write access to this register is protected by a locking mechanism, for details please refer to the UNLOCK register description. 87 32117A-10/2010 AT32UC3C 8.5.10 System RC Oscillator (RCSYS) The system RC oscillator (RCSYS) has a 3 cycles startup time, and is always available except in the STATIC sleep mode. The system RC oscillator operates at a nominal frequency of 115 kHz, and is calibrated using the RCCR.CALIB Calibration field. After a Power On Reset, the RCCR.CALIB field is loaded with a factory defined value stored in the Flash fuses. Although it is not recommended, it is still possible to override the default factory settings by writing to the RCCR.CALIB field. To prevent unexpected writes due to software bugs, write access to this register is protected by a locking mechanism, for details please refer to the UNLOCK register description. 8.5.11 8MHz / 1MHz RC Oscillator (RC8M) The 8MHz / 1MHz RC oscillator (RC8M) operates at a nominal frequency of 8MHz or 1 MHz according to RCCR8.FREQMODE bit. It is calibrated using the RCCR8.CALIB Calibration field. After a Power On Reset, the RCCR8.CALIB field is automatically loaded with the RC8M_CALIB field of the Oscillator Calibration register, a factory defined value stored in the factory page of the Flash. If the user wants to run the oscillator at 1MHz or if the device operates at VDDIN_5 within the 5V range, it has to write the RCCR8.CALIB field with the corresponding field from the Oscillator Calibration register. Although it is not recommended, it is still possible to override the default factory settings by writing to the RCCR8.CALIB field. To prevent unexpected writes due to software bugs, write access to this register is protected by a locking mechanism, for details please refer to the UNLOCK register description. 8.5.12 RC120M The 120MHz RC Oscillator can be used for the main clock in the device, as described in the Power Manager chapter. To enable the clock, the user must write a one to the EN bit in the RC120MCR register, and read back the RC120MCR register until the EN bit reads one. The clock is disabled by writing a zero to the EN bit. The oscillator is automatically switched off in certain sleep modes to reduce power consumption, as described in the Power Manager chapter. 8.5.13 General Purpose Low Power Registers (GPLP) The GPLP registers are 32-bit registers that are reset only by power-on-reset. User software can use these registers to save context variables in a very low power mode. 8.5.14 Interrupts The SCIF has separate interrupt requests: * AE - Access Error: - Set when a protected SCIF register was accessed without first being correctly unlocked. * PLL1LOCKLOST - PLL1 lock lost: - Set when a 0 to 1 transition on the PCLKSR.PLL1LOCKLOST bit is detected. * PLL0LOCKLOST - PLL0 lock lost: - Set when a 0 to 1 transition on the PCLKSR.PLL0LOCKLOST bit is detected. 88 32117A-10/2010 AT32UC3C * BOD50DET - 5V Brown out detection: - Set when a 0 to 1 transition on the PCLKSR.BOD50DET bit is detected. * BOD33DET - 3.3V Brown out detection: - Set when a 0 to 1 transition on the PCLKSR.BOD33DET bit is detected. * BODDET - 1.8V Brown out detection: - Set when a 0 to 1 transition on the PCLKSR.BODDET bit is detected. * PLL1LOCK - PLL1 locked: - Set when a 0 to 1 transition on the PCLKSR.PLL1LOCK bit is detected. * PLL0LOCK - PLL0 locked: - Set when an 0 to 1 transition on the PCLKSR.PLL0LOCK bit is detected. * RCOSC8MRDY - 8MHz / 1MHz RCOSC Ready: - Set when a 0 to 1 transition on the PCLKSR.RCOSC8MRDY bit is detected. * OSC32RDY - 32KHz Oscillator Ready: - Set when a 0 to 1 transition on the PCLKSR.OSC32RDY bit is detected. * OSCR1DY - OSC1 Ready: - Set when a 0 to 1 transition on the PCLKSR.OSC1RDY bit is detected. * OSCR0DY - OSC0 Ready: - Set when a 0 to 1 transition on the PCLKSR.OSC0RDY bit is detected. This allows the user to allocate separate handlers and priorities to the different interrupt types. The interrupt request will be generated if the corresponding bit in the Interrupt Mask Register (IMR) is set. Bits in IMR are set by writing a one to the corresponding bit in the Interrupt Enable Register (IER), and cleared by writing a one to the corresponding bit in the Interrupt Disable Register (IDR). The interrupt request remains active until the corresponding bit in the Interrupt Status Register (ISR) is cleared by writing a one to the corresponding bit in the Interrupt Clear Register (ICR). 89 32117A-10/2010 AT32UC3C 8.6 User Interface Table 8-3. SCIF Register Memory Map Offset Register Register Name Access Reset 0x0000 Interrupt Enable Register IER Write-Only 0x00000000 0x0004 Interrupt Disable Register IDR Write-Only 0x00000000 0x0008 Interrupt Mask Register IMR Read-Only 0x00000000 0x000C Interrupt Status Register ISR Read-Only 0x00000000 0x0010 Interrupt Clear Register ICR Write-Only 0x00000000 0x0014 Power and Clocks Status Register PCLKSR Read-Only 0x00000000 0x0018 Unlock Register UNLOCK Write-Only 0x00000000 0x001C PLL0 Control Register PLL0 Read/Write 0x00000000 0x0020 PLL1 Control Register PLL1 Read/Write 0x00000000 0x0024 Oscillator0 Control Register OSCCTRL0 Read/Write 0x00000000 0x0028 Oscillator1 Control Register OSCCTRL1 Read/Write 0x00000000 0x002C 1.8V BOD Control Register BOD Read/Write 0x00000000 0x0030 Bandgap Calibration Register BGCR Read/Write 0x00000000 0x0034 3.3V BOD Control Register BOD33 Read/Write 0x00000000 0x0038 5V BOD Control Register BOD50 Read/Write 0x00000000 0x003C Voltage Regulator Calibration Register VREGCR Read/Write 0x00000000 0x0040 Voltage Regulator Control Register VREGCTRL Read/Write 0x00000000 0x0044 RCSYS Calibration Register RCCR Read/Write 0x00000000 0x0048 8MHz / 1 MHz RC Oscillator Control Register RCCR8 Read/Write 0x00000000 0x004C Oscillator 32 Control Register OSCCTRL32 Read/Write 0x00000000 0x0058 120MHz RC Oscillator Control Register RC120MCR Read/Write 0x00000000 0x005C General Purpose Low Power Register 0 GPLP0 Read/Write 0x00000000 0x0060 General Purpose Low Power Register 1 GPLP1 Read/Write 0x00000000 0x0064-0x008C Generic Clock Control GCCTRL Read/Write 0x00000000 0x03C8 PLL interface Version Register PLLVERSION Read-Only -(1) 0x03CC Oscillator 0/1 Interface Version Register OSCVERSION Read-Only -(1) 0x03D0 1.8V BOD Interface Version Register BODVERSION Read-Only -(1) 0x03D4 3.3/5.0V BOD Interface Version Register BODBVERSION Read-Only -(1) 0x03D8 Voltage Regulator interface Version Register VREGVERSION Read-Only -(1) 0x03DC RCSYS Interface Version Register RCCRVERSION Read-Only -(1) 0x03E0 8MHz/1MHz RCOSC Interface Version Register RCCR8VERSION Read-Only -(1) 0x03E4 32 KHz Oscillator Interface Version Register OSC32VERSION Read-Only -(1) 0x03F0 120MHz RC Oscillator Interface Version Register RC120MVERSION Read-Only -(1) 90 32117A-10/2010 AT32UC3C Table 8-3. SCIF Register Memory Map Offset Register Register Name Access Reset 0x03F4 GPLP Version Register GPLPVERSION Read-Only -(1) 0x03F8 Generic Clock Version Register GCLKVERSION Read-Only -(1) 0x03FC SCIF Version Register VERSION Read-Only -(1) Note: 1. The reset value is device specific. Please refer to the Module Configuration section at the end of this chapter. 91 32117A-10/2010 AT32UC3C 8.6.1 Name: Interrupt Enable Register IER Access Type: Write-only Offset: 0x0000 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 AE - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 - - - - - PLL1_LOCK LOST PLL0_LOCK LOST BOD50DET 7 6 5 4 3 2 1 0 BOD33DET BODDET PLL1_LOCK PLL0_LOCK RCOSC8MRDY OSC32RDY OSC1RDY OSC0RDY Writing a zero to a bit in this register has no effect. Writing a one to a bit in this register will set the corresponding bit in IMR. 92 32117A-10/2010 AT32UC3C 8.6.2 Name: Interrupt Disable Register IDR Access Type: Write-only Offset: 0x0004 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 AE - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 - - - - - PLL1_LOCK LOST PLL0_LOCK LOST BOD50DET 7 6 5 4 3 2 1 0 BOD33DET BODDET PLL1_LOCK PLL0_LOCK RCOSC8MR DY OSC32RDY OSC1RDY OSC0RDY Writing a zero to a bit in this register has no effect. Writing a one to a bit in this register will clear the corresponding bit in IMR. 93 32117A-10/2010 AT32UC3C 8.6.3 Name: Interrupt Mask Register IMR Access Type: Read-only Offset: 0x0008 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 AE - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 - - - - - PLL1_LOCK LOST PLL0_LOCK LOST BOD50DET 7 6 5 4 3 2 1 0 BOD33DET BODDET PLL1_LOCK PLL0_LOCK RCOSC8MR DY OSC32RDY OSC1RDY OSC0RDY 0: The corresponding interrupt is disabled. 1: The corresponding interrupt is enabled. This bit is cleared when the corresponding bit in IDR is written to one. This bit is set when the corresponding bit in IER is written to one. 94 32117A-10/2010 AT32UC3C 8.6.4 Name: Interrupt Status Register ISR Access Type: Read-only Offset: 0x000C Reset Value: 0x00000000 31 30 29 28 27 26 25 24 AE - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 - - - - - PLL1_LOCK LOST PLL0_LOCK LOST BOD50DET 7 6 5 4 3 2 1 0 BOD33DET BODDET PLL1_LOCK PLL0_LOCK RCOSC8MR DY OSC32RDY OSC1RDY OSC0RDY 0: The corresponding interrupt is cleared. 1: The corresponding interrupt is pending. This bit is cleared when the corresponding bit in ICR is written to one. This bit is set when the corresponding interrupt occurs. 95 32117A-10/2010 AT32UC3C 8.6.5 Name: Interrupt Clear Register ICR Access Type: Write-only Offset: 0x0010 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 AE - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 - - - - - PLL1_LOCK LOST PLL0_LOCK LOST BOD50DET 7 6 5 4 3 2 1 0 BOD33DET BODDET PLL1_LOCK PLL0_LOCK RCOSC8MR DY OSC32RDY OSC1RDY OSC0RDY Writing a zero to a bit in this register has no effect. Writing a one to a bit in this register will clear the corresponding bit in ISR. 96 32117A-10/2010 AT32UC3C 8.6.6 Name: Power and Clocks Status Register PCLKSR Access Type: Read-Only Offset: 0x0014 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 AE - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 - - - - - PLL1_LOCK LOST PLL0_LOCK LOST BOD50DET 7 6 5 4 3 2 1 0 BOD33DET BODDET PLL1_LOCK PLL0_LOCK RCOSC8MR DY OSC32RDY OSC1RDY OSC0RDY * AE: SCIF Access Error 0: No access error has occurred on the SCIF. 1: An access error has occurred on the SCIF. * PLLL1_LOCKLOST: PLL1 lock lost value 0: PLL1 has not lost its lock or has never been enabled. 1: PLL1 has lost its lock, either by disabling the PLL1 or due to faulty operation. * PLLL0_LOCKLOST: PLL0 lock lost value 0: PLL0 has not lost its lock or has never been enabled. 1: PLL0 has lost its lock, either by disabling the PLL0 or due to faulty operation. * BOD50DET: 5.0V Brown out detection 0: BOD50 not enabled or the 5.0V power supply is above the BOD50 threshold. 1: BOD50 enabled and the 5.0V power supply is going below BOD50 threshold. * BOD33DET: 3.3V Brown out detection 0: BOD33 not enabled or the 3.3V power supply is above the BOD33 threshold. 1: BOD33 enabled and the 3.3V power supply is going below BOD33 threshold. * BODDET: 1.8V Brown out detection 0: BOD18 not enabled or the 1.8V power supply is above the BOD18 threshold. 1: BOD18 enabled and the 1.8V power supply is going below BOD18 threshold. * PLL1_LOCK: PLL1 Locked on Accurate value 0: PLL1 is unlocked on accurate value. 1: PLL1 is locked on accurate value, and is ready to be selected as clock source with an accurate output clock. * PLL0_LOCK: PLL0 Locked on Accurate value 0: PLL0 is unlocked on accurate value. 1: PLL0 is locked on accurate value, and is ready to be selected as clock source with an accurate output clock. 97 32117A-10/2010 AT32UC3C * RCOSC8MRDY: 8MHz / 1MHz RCOSC Ready 0: 8MHz / 1MHz RC Oscillator not enabled or not ready. 1: 8MHz / 1MHz RC Oscillator is stable and ready to be used as clock source. * OSC32RDY: 32 KHz oscillator Ready 0: Oscillator 32 not enabled or not ready. 1: Oscillator 32 is stable and ready to be used as clock source. * OSC1RDY: OSC1Ready 0: Oscillator not enabled or not ready. 1: Oscillator is stable and ready to be used as clock source. * OSC0RDY: OSC0Ready 0: Oscillator not enabled or not ready. 1: Oscillator is stable and ready to be used as clock source. 98 32117A-10/2010 AT32UC3C 8.6.7 Name: Unlock Register UNLOCK Access Type: Write-Only Offset: 0x0018 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 KEY 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 - - - - - - 7 6 5 4 3 2 ADDR[9:8] 1 0 ADDR[7:0] To unlock a write protected register, first write to the UNLOCK register with the address of the register to unlock in the ADDR field and 0xAA in the KEY field. Then, in the next PB access write to the register specified in the ADDR field. * KEY: Unlock Key Write this bit field to 0xAA to enable unlock. * ADDR: Unlock Address Write the address of the register to unlock to this field. 99 32117A-10/2010 AT32UC3C 8.6.8 Name: PLL Control Register PLL0,1 Access Type: Read/Write Offset: 0x001C,0x0020 Reset Value: 0x00000000 31 30 29 28 - - 23 22 21 20 - - - - 15 14 13 12 - - - - 7 6 5 4 - - 27 26 25 24 18 17 16 9 8 1 0 PLLCOUNT PLLOPT 19 PLLMUL 11 10 PLLDIV 3 2 PLLOSC PLLEN * PLLCOUNT: PLL Count Specifies the number of slow clock cycles before ISR.LOCKn is set after PLLn has been written, or after PLLn has been automatically re-enabled after exiting a sleep mode. * PLLMUL: PLL Multiply Factor * PLLDIV: PLL Division Factor These fields determine the ratio of the output frequency of the internal VCO of the PLL (fvco) to the source oscillator frequency: fvco = (PLLMUL+1) / (PLLDIV) * fosc if PLLDIV > 0 fvco = 2 * (PLLMUL+1) * fosc if PLLDIV = 0 According to PLLOPT[1] bit, it gives the following PLL frequency value fPLL: if the PLLOPT[1] bit is set to 0: fPLL = fVCO if the PLLOPT[1] bit is set to 1: fPLL = fVCO / 2 Note that the PLLMUL field cannot be equal to 0 or 1, or the behavior of the PLL will be undefined. PLLDIV gives also the input frequency of the PLL (fIN): if the PLLDIV field is set to 0: fIN= fOSC if the PLLDIV field is greater than 0: fIN= fOSC / (2 * PLLDIV) * PLLOPT: PLL Option Select the operating range for the PLL. PLLOPT[0]: Select the VCO frequency range. PLLOPT[1]: Enable the extra output divider. PLLOPT[2]: Disable the Wide-Bandwidth mode (Wide-Bandwidth mode allows a faster startup time and out-of-lock time). 100 32117A-10/2010 AT32UC3C Table 8-4. PLLOPT Fields Description Description PLLOPT[0]: VCO frequency 0 160MHz 16 MHz * MODE: Oscillator Mode 0: External clock connected on XIN, XOUT can be used as an I/O (no crystal), Disable the Oscillator. 1: Enable the Oscillator. Note that this register is protected by a lock. To write to this register the UNLOCK register has to be written first. Please refer to the UNLOCK register description for details. 103 32117A-10/2010 AT32UC3C 8.6.10 Name: 1.8V BOD Control Register BOD Access Type: Read/Write Offset: 0x002C Reset Value: 0x00000000 31 30 29 28 27 26 25 24 SFV - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - FCD 15 14 13 12 11 10 9 8 - - - - - - 7 6 5 4 3 2 - HYST CTRL 1 0 LEVEL * SFV: Store Final Value 0: The register is read/write. 1: The register is read-only, to protect against further accidental writes. * FCD: BOD18 Fuse Calibration Done Set to 1 when the CTRL, HYST and LEVEL fields have been updated by the Flash fuses after a reset. 0: The flash calibration will be redone after any reset. 1: The flash calibration will not be redone after a BOD18 reset. * CTRL: BOD18 Control Table 8-7. Operation mode for BOD18 CTRL Description 0x0 BOD18 is off 0x1 BOD18 is enabled and can reset the chip 0x2 BOD18 is enabled, but cannot reset the chip. Only interrupt will be sent to interrupt controller, if enabled in the IMR register. 0x3 Reserved * HYST: BOD18 Hysteresis 0: No hysteresis. 1: Hysteresis on. * LEVEL: BOD18 Level This field sets the triggering threshold of the BOD18. See Electrical Characteristics for actual voltage levels. Note that any change to the LEVEL field of the BOD register should be done with the BOD18 deactivated to avoid spurious reset or interrupt. 104 32117A-10/2010 AT32UC3C Note that this register is protected by a lock. To write to this register the UNLOCK register has to be written first. Please refer to the UNLOCK register description for details. 105 32117A-10/2010 AT32UC3C 8.6.11 Name: Bandgap Calibration Register BGCR Access Type: Read/Write Offset: 0x0030 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 SFV - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - FCD 15 14 13 12 11 10 9 8 - - - - - - - - 7 6 5 4 3 2 1 - - - - - 0 CALIB * SFV: Store Final Value 0: The register is read/write. 1: The register is read-only, to protect against further accidental writes. * FCD: Flash Calibration Done Set to 1 when the CALIB field has been updated by the Flash fuses after a reset. 0: The flash calibration will be redone after any reset. 1: The flash calibration will not be redone after a BOD18 reset. * CALIB: Calibration value Calibration value for Bandgap. See Electrical Characteristics for voltage values. Note that this register is protected by a lock. To write to this register the UNLOCK register has to be written first. Please refer to the UNLOCK register description for details. 106 32117A-10/2010 AT32UC3C 8.6.12 Name: 3.3V BOD Control Register BOD33 Access Type: Read/Write Offset: 0x0034 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 SFV - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - FCD 15 14 13 12 11 10 9 8 - - - - - - 7 6 5 4 3 2 - HYST CTRL 1 0 LEVEL * SFV: Store Final Value 0: The register is read/write. 1: The register is read-only, to protect against further accidental writes. * FCD: Flash Calibration Done Set to 1 when the CTRL field has been updated by the Flash fuses after a reset. 0: The flash calibration will be redone after any reset. 1: The flash calibration will not be redone after a BOD33 reset. * CTRL: BOD33 Control Table 8-8. Operation mode for BOD33 CTRL Description 0x0 BOD33 is off 0x1 BOD33 is enabled and can reset the chip 0x2 BOD33 is enabled, but cannot reset the chip. Only interrupt will be sent to interrupt controller, if enabled in the IMR register. 0x3 Reserved * HYST: BOD33 Hysteresis 0: No hysteresis. 1: Hysteresis on. * LEVEL: BOD33 Level This field sets the triggering threshold of the BOD33. See Electrical Characteristics for actual voltage levels. Note that any change to the LEVEL field of the BOD33 register should be done with the BOD33 deactivated to avoid spurious reset or interrupt. 107 32117A-10/2010 AT32UC3C Note that this register is protected by a lock. To write to this register the UNLOCK register has to be written first. Please refer to the UNLOCK register description for details. 108 32117A-10/2010 AT32UC3C 8.6.13 Name: 5V BOD Control Register BOD50 Access Type: Read/Write Offset: 0x0038 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 SFV - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 - - - - - - - CTRL 7 6 5 4 3 2 1 0 - HYST LEVEL * SFV: Store Final Value 0: The register is read/write. 1: The register is read-only, to protect against further accidental writes. * CTRL: BOD50 Control 0: BOD50 is off. 1: BOD50 is enabled. * HYST: BOD50 Hysteresis 0: No hysteresis. 1: Hysteresis on. * LEVEL: BOD50 Level This field sets the triggering threshold of the BOD50. See Electrical Characteristics for actual voltage levels. Note that any change to the LEVEL field of the BOD50 register should be done with the BOD50 deactivated to avoid spurious reset or interrupt. Note that this register is protected by a lock. To write to this register the UNLOCK register has to be written first. Please refer to the UNLOCK register description for details. Set to 1 when the CALIB field has been updated by the Flash fuses after a reset. 0: The flash calibration will be redone after any reset. 1: The flash calibration will only be redone after a power-on reset. 109 32117A-10/2010 AT32UC3C 8.6.14 Name: Voltage Regulator Control Register VREGCTRL Access Type: Read/Write Offset: 0x0040 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 SFV - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 - - - - - - - - 7 6 5 4 3 2 1 0 - - - - VREG33CTL - * SFV: Store Final Value 0: The register is read/write. 1: The register is read-only, to protect against further accidental writes. * VREG33CTL: 3.3 Voltage Regulator Control Table 8-9. VREG33CTL Operation mode of 3.3V Voltage Regulator Description 0x0 3.3V Regulator is ON 0x1 Reserved 0x2 Reserved 0x3 3.3V Regulator is OFF Note that this register is protected by a lock. To write to this register the UNLOCK register has to be written first. Please refer to the UNLOCK register description for details. 110 32117A-10/2010 AT32UC3C 8.6.15 Name: RCSYS Calibration Register RCCR Access Type: Read/Write Offset: 0x0044 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - FCD 15 14 13 12 11 10 9 8 - - - - - - 7 6 5 4 3 2 CALIB[9:8] 1 0 CALIB[7:0] * FCD: Flash Calibration Done Set to 1 when CALIB field has been updated by the Flash fuses after a reset. 0: The flash calibration will be redone after any reset. 1: The flash calibration will only be redone after a power-on reset. * CALIB: Calibration Value Calibration Value for the RC oscillator. Note that this register is protected by a lock. To write to this register the UNLOCK register has to be written first. Please refer to the UNLOCK register description for details. 111 32117A-10/2010 AT32UC3C 8.6.16 Name: 8MHz / 1MHz RC Oscillator Control Register RCCR8 Access Type: Read/Write Offset: 0x0048 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - FREQMODE RCOSC8_EN 23 22 21 20 19 18 17 16 - - - - - - - FCD 15 14 13 12 11 10 9 8 - - - - - - - - 7 6 5 4 3 2 1 0 CALIB[7:0] * FREQMODE: Frequency Mode 0: the RC8M RC oscillator will run at 8 MHz. 1: the RC8M RC oscillator will run at 1 MHz. * RCOSC8_EN: RCOSC Enable 0: the RC8M RC oscillator is disabled. 1: the RC8M RC oscillator is enabled. * FCD: Flash Calibration Done Set to 1 when CALIB field has been updated by the Flash fuses after a reset. 0: The flash calibration will be redone after any reset. 1: The flash calibration will only be redone after a power-on reset. * CALIB: Calibration Value Calibration Value for the RC8M RC oscillator. Note that this register is protected by a lock. To write to this register the UNLOCK register has to be written first. Please refer to the UNLOCK register description for details. 112 32117A-10/2010 AT32UC3C 8.6.17 Name: 32KHz Oscillator Control Register OSCCTRL32 Access Type: Read/Write Offset: 0x004C Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - 15 14 13 12 11 10 - - - - - - 7 6 5 4 3 2 1 0 - - - - - - - OSC32EN STARTUP 9 8 MODE Note: This register is only reset by Power-On Reset. * STARTUP: Oscillator Startup Time Select startup time for 32 KHz oscillator. Table 8-10. Startup time for 32 KHz oscillator Number of RC oscillator clock cycle Approximative Equivalent time (RCSYS = 115 kHz) 0 0 0 1 128 1.1 ms 2 8192 72.3 ms 3 16384 143 ms 4 65536 570 ms 5 131072 1.1 s 6 262144 2.3 s 7 524288 4.6 s STARTUP 113 32117A-10/2010 AT32UC3C * MODE: Oscillator Mode Table 8-11. MODE Operation mode for 32 KHz oscillator Description 0 External clock connected to XIN32, XOUT32 can be used as I/O (no crystal) 1 2-pin crystal mode. Crystal is connected to XIN32/XOUT32 2 2-pin crystal and I-Current mode. Crystal is connected to XIN32/XOUT32 3 Reserved * OSC32EN: Enable the 32 KHz oscillator 0: 32 KHz Oscillator is disabled. 1: 32 KHz Oscillator is enabled. Note that this register is protected by a lock. To write to this register the UNLOCK register has to be written first. Please refer to the UNLOCK register description for details. 114 32117A-10/2010 AT32UC3C 8.6.18 Name: 120MHz RC Oscillator Control Register RC120MCR Access Type: Read/Write Offset: 0x0058 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 - - - - - - - - 7 6 5 4 3 2 1 0 - - - - - - - EN * EN: RC120M Enable 0: Clock is stopped. 1: Clock is running. Note that this register is protected by a lock. To write to this register the UNLOCK register has to be written first. Please refer to the UNLOCK register description for details. 115 32117A-10/2010 AT32UC3C 8.6.19 Name: General Purpose Low-power Register 0/1 GPLP0,1 Access Type: Read/Write Offset: 0x005C,0x0060 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 19 18 17 16 11 10 9 8 3 2 1 0 DATA[31:24] 23 22 21 20 DATA[23:16] 15 14 13 12 DATA[15:8] 7 6 5 4 DATA[7:0] These registers are general purpose 32-bit registers that are reset only by power-on-reset. Any other reset will keep the bits of these registers untouched. Note that this registers are protected by a lock. To write to these registers the UNLOCK register has to be written first. Please refer to the UNLOCK register description for details. 116 32117A-10/2010 AT32UC3C 8.6.20 Name: Generic Clock Control GCCTRL Access Type: Read/Write Offset: 0x0064-0x008C Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 11 10 9 8 DIV 15 14 13 12 OSCSEL 7 6 5 4 3 2 1 0 - - - - - - DIVEN CEN There is one GCCTRL register per generic clock in the device. * DIV: Division Factor * OSCSEL: Oscillator Select Table 8-12. Generic Clock Source OSCSEL Clock Description 0 RCSYS System RC oscillator clock 1 OSC32K Output clock from OSC32K 2 8MHz / 1MHz RCOSC Output clock from RC8M 3 OSC0 out Output clock from Oscillator 0 4 OSC1 out Output clock from Oscillator 1 5 PLL0 out Output from PLL 0 6 PLL1 out Output from PLL 1 7 CPU clock The clock the CPU runs on 8 HSB clock High Speed Bus clock 9 PBA clock Peripheral Bus A clock 10 PBB clock Peripheral Bus B clock 11 PBC clock Peripheral Bus C clock 12-15 Reserved 117 32117A-10/2010 AT32UC3C * DIVEN: Divide Enable 0: The generic clock equals the undivided source clock. 1: The generic clock equals the source clock divided by 2*(DIV+1). * CEN: Clock Enable 0: Clock is stopped. 1: Clock is running. 118 32117A-10/2010 AT32UC3C 8.6.21 Name: PLL Interface Version Register PLLVERSION Access Type: Read-Only Offset: 0x03C8 Reset Value: - 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - 15 14 13 12 9 8 - - - - 7 6 5 4 VARIANT 11 10 VERSION[11:8] 3 2 1 0 VERSION[7:0] * VARIANT: Variant number Reserved. No functionality associated. * VERSION: Version number Version number of the module. No functionality associated. 119 32117A-10/2010 AT32UC3C 8.6.22 Name: Oscillator Interface Version Register OSCVERSION Access Type: Read-Only Offset: 0x03CC Reset Value: - 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - 15 14 13 12 9 8 - - - - 7 6 5 4 VARIANT 11 10 VERSION[11:8] 3 2 1 0 VERSION[7:0] * VARIANT: Variant number Reserved. No functionality associated. * VERSION: Version number Version number of the module. No functionality associated. 120 32117A-10/2010 AT32UC3C 8.6.23 Name: 1.8V BOD Interface Version Register BODVERSION Access Type: Read-Only Offset: 0x03D0 Reset Value: - 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - 15 14 13 12 9 8 - - - - 7 6 5 4 VARIANT 11 10 VERSION[11:8] 3 2 1 0 VERSION[7:0] * VARIANT: Variant number Reserved. No functionality associated. * VERSION: Version number Version number of the module. No functionality associated. 121 32117A-10/2010 AT32UC3C 8.6.24 Name: 3.3V / 5V BOD Interface Version Register BODBVERSION Access Type: Read-Only Offset: 0x03D4 Reset Value: - 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - 15 14 13 12 9 8 - - - - 7 6 5 4 VARIANT 11 10 VERSION[11:8] 3 2 1 0 VERSION[7:0] * VARIANT: Variant number Reserved. No functionality associated. * VERSION: Version number Version number of the module. No functionality associated. 122 32117A-10/2010 AT32UC3C 8.6.25 Name: Voltage Regulator Interface Version Register VREGVERSION Access Type: Read-Only Offset: 0x03D8 Reset Value: - 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - 15 14 13 12 9 8 - - - - 7 6 5 4 VARIANT 11 10 VERSION[11:8] 3 2 1 0 VERSION[7:0] * VARIANT: Variant number Reserved. No functionality associated. * VERSION: Version number Version number of the module. No functionality associated. 123 32117A-10/2010 AT32UC3C 8.6.26 Name: RCSYS Interface Version Register RCCRVERSION Access Type: Read-Only Offset: 0x03DC Reset Value: - 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - 15 14 13 12 9 8 - - - - 7 6 5 4 VARIANT 11 10 VERSION[11:8] 3 2 1 0 VERSION[7:0] * VARIANT: Variant number Reserved. No functionality associated. * VERSION: Version number Version number of the module. No functionality associated. 124 32117A-10/2010 AT32UC3C 8.6.27 Name: 8MHz / 1MHz RCOSC Interface Version Register RCCR8VERSION Access Type: Read-Only Offset: 0x03E0 Reset Value: - 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - 15 14 13 12 9 8 - - - - 7 6 5 4 VARIANT 11 10 VERSION[11:8] 3 2 1 0 VERSION[7:0] * VARIANT: Variant number Reserved. No functionality associated. * VERSION: Version number Version number of the module. No functionality associated. 125 32117A-10/2010 AT32UC3C 8.6.28 Name: 32KHz Oscillator Interface Version Register OSC32VERSION Access Type: Read-Only Offset: 0x03E4 Reset Value: - 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - 15 14 13 12 9 8 - - - - 7 6 5 4 VARIANT 11 10 VERSION[11:8] 3 2 1 0 VERSION[7:0] * VARIANT: Variant number Reserved. No functionality associated. * VERSION: Version number Version number of the module. No functionality associated. 126 32117A-10/2010 AT32UC3C 8.6.29 Name: 120MHz RC Oscillator Version Register RC120MVERSION Access Type: Read-Only Offset: 0x03F0 Reset Value: - 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - 15 14 13 12 9 8 - - - - 7 6 5 4 VARIANT 11 10 VERSION[11:8] 3 2 1 0 VERSION[7:0] * VARIANT: Variant number Reserved. No functionality associated. * VERSION: Version number Version number of the module. No functionality associated. 127 32117A-10/2010 AT32UC3C 8.6.30 Name: GPLP Version Register GPLPVERSION Access Type: Read-Only Offset: 0x03F4 Reset Value: - 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - 15 14 13 12 9 8 - - - - 7 6 5 4 VARIANT 11 10 VERSION[11:8] 3 2 1 0 VERSION[7:0] * VARIANT: Variant number Reserved. No functionality associated. * VERSION: Version number Version number of the module. No functionality associated. 128 32117A-10/2010 AT32UC3C 8.6.31 Name: Generic Clock Version Register GCLKVERSION Access Type: Read-Only Offset: 0x03F8 Reset Value: - 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - 15 14 13 12 9 8 - - - - 7 6 5 4 VARIANT 11 10 VERSION[11:8] 3 2 1 0 VERSION[7:0] * VARIANT: Variant number Reserved. No functionality associated. * VERSION: Version number Version number of the module. No functionality associated. 129 32117A-10/2010 AT32UC3C 8.6.32 Name: SCIF Version Register VERSION Access Type: Read-Only Offset: 0x03FC Reset Value: - 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - 15 14 13 12 9 8 - - - - 7 6 5 4 VARIANT 11 10 VERSION[11:0] 3 2 1 0 VERSION[7:0] * VARIANT: Variant number Reserved. No functionality associated. * VERSION: Version number Version number of the module. No functionality associated. 130 32117A-10/2010 AT32UC3C 8.7 Module Configuration The specific configuration for each SCIF instance is listed in the following tables. The module bus clocks listed here are connected to the system bus clocks. Please refer to the Power Manager chapter for details. Table 8-13. SCIF Clock Name Module name Clock Name Description SCIF CLK_SCIF Peripheral Bus clock from the PBA clock domain Table 8-14. Register Reset Values Register Reset Value PLLVERSION 0x00000100 OSCVERSION 0x00000101 BODVERSION 0x00000101 BODBVERSION 0x00000100 VREGVERSION 0x00000100 RCCRVERSION 0x00000100 RCCR8VERSION 0x00000100 OSC32VERSION 0x00000100 TSENSVERSION 0x00000100 RC120MIFAVERSION 0x00000100 GPLPVERSION 0x00000110 GCLKVERSION 0x00000100 VERSION 0x00000101 131 32117A-10/2010 AT32UC3C 9. Asynchronous Timer (AST) Rev: 2.0.0.0 9.1 Features * 32-bit counter with 32-bit prescaler * Clocked Source * * * * 9.2 - System RC oscillator (RCSYS) - 32KHz crystal oscillator (OSC32K) - PB clock - Generic clock (GCLK) - 1KHz clock from 32KHz oscillator Optional calendar mode supported Digital prescaler tuning for increased accuracy Periodic interrupt(s) and peripheral event(s) supported Alarm interrupt(s) and peripheral event(s) supported - Optional clear on alarm Overview The Asynchronous Timer (AST) enables periodic interrupts and periodic peripheral events, as well as interrupts and peripheral events at a specified time in the future. The AST consists of a 32-bit prescaler which feeds a 32-bit up-counter. The prescaler can be clocked from four different clock sources, including the low-power 32KHz clock, which allows the AST to be used as a real-time timer with a maximum timeout of more than 100 years. Also, the PB clock or a generic clock can be used for high-speed operation, allowing the AST to be used as a general timer. The AST can generate periodic interrupts and peripheral events from output from the prescaler, as well as alarm 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 any alarm. This allows periodic interrupts and peripheral events at very long and accurate intervals. The AST has been designed to meet the system tick and Real Time Clock requirements of most embedded operating systems. 132 32117A-10/2010 AT32UC3C 9.3 Block Diagram Figure 9-1. Asynchronous Timer block diagram WAKE ENABLE REGISTER CLK_AST CLK_AST CONTROL REGISTER CLK_AST CSSEL EN Wake Control COUNTER VALUE Wake PSEL 32 KHz RC OSC CLK_AST_PRSC PB clock 32-bit Prescaler CLK_AST_CNT 32-bit counter OVF GCLK IRQs DIGITAL TUNER REGISTER 9.4 Periodic Interrupts Alarm Interrupts PERIODIC INTERVAL REGISTER ALARM REGISTER Interrupt Control Events Product Dependencies In order to use this module, other parts of the system must be configured correctly, as described below. 9.4.1 Power Management When the AST is enabled, it will remain clocked as long as its selected clock source is running. It can also wake the CPU from the currently active sleep mode. Refer to the Power Manager chapter for details on the different sleep modes. 9.4.2 Clocks The clock for the AST bus interface (CLK_AST) is generated by the Power Manager. This clock is turned on by default, and can be enabled and disabled in the Power Manager. A number of clocks can be selected as source for the internal prescaler clock CLK_AST_PRSC. The prescaler, counter, and interrupt will function as long as this selected clock source is active. The selected clock must be enabled in the System Control Interface (SCIF). The following clock sources are available: * System RC oscillator (RCSYS). This oscillator is always enabled, except in some sleep modes. Please refer to the Electrical Characteristics chapter for the characteristic frequency of this oscillator. * 32KHz crystal oscillator (OSC32K). This oscillator must be enabled before use. 133 32117A-10/2010 AT32UC3C * Peripheral Bus clock (PB clock). This is the clock of the peripheral bus the AST is connected to. * Generic clock (GCLK). One of the generic clocks is connected to the AST. This clock must be enabled before use, and remains enabled in sleep modes when the PB clock is active. 9.4.3 Interrupt The AST interrupt request lines are connected to the interrupt controller. Using the AST interrupts requires the interrupt controller to be programmed first. 9.4.4 Peripheral Events The AST peripheral events are connected via the Peripheral Event System. Refer to the Peripheral Event System chapter for details. 9.4.5 Debug Operation The AST prescaler and counter is frozen during debug operation, unless the Run In Debug bit in the Development Control Register is set and the bit corresponding to the AST is set in the Peripheral Debug Register (PDBG). Please refer to the On-Chip Debug chapter in the AVR32UC Technical Reference Manual, and the OCD Module Configuration section, for details. If the AST 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. 9.5 9.5.1 Functional Description Initialization Before enabling the AST, the internal AST clock CLK_AST_PRSC must be enabled, following the procedure specified in Section 9.5.1.1. The Clock Source Select field in the Clock register (CLOCK.CSSEL) selects the source for this clock. The Clock Enable bit in the Clock register (CLOCK.CEN) enables the CLK_AST_PRSC. When CLK_AST_PRSC is enabled, the AST can be enabled by writing a one to the Enable bit in the Control Register (CR.EN). 9.5.1.1 Enabling and disabling the AST clock The Clock Source Selection field (CLOCK.CSSEL) and the Clock Enable bit (CLOCK.CEN) cannot be changed simultaneously. Special procedures must be followed for enabling and disabling the CLK_AST_PRSC and for changing the source for this clock. To enable CLK_AST_PRSC: * Write the selected value to CLOCK.CSSEL * Wait until SR.CLKBUSY reads as zero * Write a one to CLOCK.CEN, without changing CLOCK.CSSEL * Wait until SR.CLKBUSY reads as zero To disable the clock: * Write a zero to CLOCK.CEN to disable the clock, without changing CLOCK.CSSEL * Wait until SR.CLKBUSY reads as zero 134 32117A-10/2010 AT32UC3C 9.5.1.2 Changing the source clock The CLK_AST_PRSC must be disabled before switching to another source clock. The Clock Busy bit in the Status Register (SR.CLKBUSY) indicates whether the clock is busy or not. This bit is set when the CEN bit in the CLOCK register is changed, and cleared when the CLOCK register can be changed. To change the clock: * Write a zero to CLOCK.CEN to disable the clock, without changing CLOCK.CSSEL * Wait until SR.CLKBUSY reads as zero * Write the selected value to CLOCK.CSSEL * Wait until SR.CLKBUSY reads as zero * Write a one to CLOCK.CEN to enable the clock, without changing CLOCK.CSSEL * Wait until SR.CLKBUSY reads as zero 9.5.2 Basic Operation 9.5.2.1 Prescaler When the AST is enabled, the 32-bit prescaler will increment on the rising edge of CLK_AST_PRSC. The prescaler value cannot be read or written, but it can be reset by writing a one to the Prescaler Clear bit in the Control Register (CR.PCLR). The Prescaler Select field in the Control Register (CR.PSEL) selects the prescaler bit PSEL as source clock for the counter (CLK_AST_CNT). This results in a counter frequency of: f PRSC f CNT = ---------------------PSEL + 1 2 where fPRSC is the frequency of the internal prescaler clock CLK_AST_PRSC. 9.5.2.2 Counter operation When enabled, the AST will increment on every 0-to-1 transition of the selected prescaler tapping. When the Calender bit in the Control Register (CR.CAL) is zero, the counter operates in counter mode. It will increment until it reaches the top value of 0xFFFFFFFF, and then wrap to 0x00000000. This sets the status bit Overflow in the Status Register (SR.OVF). Optionally, the counter can also be reset when a timer alarm occurs (see Section 9.5.3.2), which will also set the OVF bit. The AST counter value can be read from or written to the Counter Value (CV) register. Note that due to synchronization, continuous reading of the CV register with the lowest prescaler setting will skip every third value. In addition, if CLK_AST_PRSC is as fast as, or faster than, the CLK_AST, the prescaler value must be 3 or higher to be able to read the CV without skipping values. 135 32117A-10/2010 AT32UC3C 9.5.2.3 Calendar operation When the CAL bit in the Control Register is one, the counter operates in calendar mode. Before this mode is enabled, the prescaler should be set up to give a pulse every second. The date and time can then be read from or written to the Calendar Value (CALV) register. Time is reported as seconds, minutes, and hours according to the 24-hour clock format. Date is the numeral date of month (starting on 1). Month is the numeral month of the year (1 = January, 2 = February, etc). Year is a 6-bit field counting the offset from a software-defined leap year (e.g. 2000). The date is automatically compensated for leap years, assuming every year divisible by 4 is a leap year. All peripheral events and interrupts work the same way in calendar mode as in counter mode. However, the Alarm Register (AR) must be written in time/date format for the alarm to trigger correctly. 9.5.3 Interrupts The AST can generate five separate interrupt requests: * OVF: OVF * PER: PER0, PER1 * ALARM: ALARM0, ALARM1 * CLKREADY * READY This allows the user to allocate separate handlers and priorities to the different interrupt types. The generation of the PER interrupt is described in Section 9.5.3.1., and the generation of the ALARM interrupt is described in Section 9.5.3.2. The OVF interrupt is generated when the counter overflows, or when the alarm value is reached, if the Clear on Alarm bit in the Control Register is one. The CLKREADY interrupt is generated when SR.CLKBUSY has a 1-to-0 transition, and indicates that the clock synchronization is completed. The READY interrupt is generated when SR.BUSY has a 1-to-0 transition, and indicates that the synchronization described in Section 9.5.7 is completed. An interrupt request will be generated if the corresponding bit in the Interrupt Mask Register (IMR) is set. Bits in IMR are set by writing a one to the corresponding bit in the Interrupt Enable Register (IER), and cleared by writing a one to the corresponding bit in the Interrupt Disable Register (IDR). The interrupt request remains active until the corresponding bit in SR is cleared by writing a one to the corresponding bit in the Status Clear Register (SCR). The AST interrupts can wake the CPU from any sleep mode where the source clock and the interrupt controller is active. 9.5.3.1 Periodic interrupt The AST can generate periodic interrupts. If the PERn bit in the Interrupt Mask Register (IMR) is one, the AST will generate an interrupt request on the 0-to-1 transition of the selected bit in the 136 32117A-10/2010 AT32UC3C prescaler when the AST is enabled. The bit is selected by the Interval Select field in the corresponding Periodic Interval Register (PIRn.INSEL), resulting in a periodic interrupt frequency of f CS f PA = -----------------------INSEL + 1 2 where fCS is the frequency of the selected clock source. The corresponding PERn bit in the Status Register (SR) will be set when the selected bit in the the prescaler has a 0-to-1 transition. Because of synchronization, the transfer of the INSEL value will not happen immediately. When changing/setting the INSEL value, the user must make sure that the prescaler bit number INSEL will not have a 0-to-1 transition before the INSEL value is transferred to the register. In that case, the first periodic interrupt after the change will not be triggered. 9.5.3.2 Alarm interrupt The AST can also generate alarm interrupts. If the ALARMn bit in IMR is one, the AST will generate an interrupt request when the counter value matches the selected alarm value, when the AST is enabled. The alarm value is selected by writing the value to the VALUE field in the corresponding Alarm Register (ARn.VALUE). The corresponding ALARMn bit in SR will be set when the counter reaches the selected alarm value. Because of synchronization, the transfer of the alarm value will not happen immediately. When changing/setting the alarm value, the user must make sure that the counter will not count the selected alarm value before the value is transferred to the register. In that case, the first alarm interrupt after the change will not be triggered. If the Clear on Alarm bit in the Control Register (CR.CAn) is one, the corresponding alarm interrupt will clear the counter and set the OVF bit in the Status Register. This will generate an overflow interrupt if the OVF bit in IMR is set. 9.5.4 Peripheral events The AST can generate a number of peripheral events: * OVF * PER0 * PER1 * ALARM0 * ALARM1 The PERn peripheral event(s) is generated the same way as the PER interrupt, as described in Section 9.5.3.1. The ALARMn peripheral event(s) is generated the same way as the ALARM interrupt, as described in Section 9.5.3.2. The OVF peripheral event is generated the same way as the OVF interrupt, as described in Section 9.5.3- 137 32117A-10/2010 AT32UC3C The peripheral event will be generated if the corresponding bit in the Event Mask (EVM) register is set. Bits in EVM register are set by writing a one to the corresponding bit in the Event Enable (EVE) register, and cleared by writing a one to the corresponding bit in the Event Disable (EVD) register. 9.5.5 AST wakeup The AST can wake up the CPU directly, without the need to trigger an interrupt. A wakeup can be generated when the counter overflows, when the counter reaches the selected alarm value, or when the selected prescaler bit has a 0-to-1 transition. In this case, the CPU will continue executing from the instruction following the sleep instruction. The AST wakeup is enabled by writing a one to the corresponding bit in the Wake Enable Register (WER). When the CPU wakes from sleep, the wake signal must be cleared by writing a one to the corresponding bit in SCR to clear the internal wake signal to the sleep controller. If the wake signal is not cleared after waking from sleep, the next sleep instruction will have noe effect because the CPU will wake immediately after this sleep instruction. The AST wakeup can wake the CPU from any sleep mode where the source clock is active. The AST wakeup can be configured independently of the interrupt masking. 9.5.6 Digital tuner The digital tuner adds the possibility to compensate for a too slow or a too fast input clock. The ADD bit in the Digital Tuner Register (DTR.ADD) selects if the tuned frequency should be reduced or increased. The resulting frequency is 1 f TUNED = f 0 1 --------------------------------------------------------------------- 1 - ------------------ ( 2 ( EXP + 8 ) ) - 1 VALUE for VALUE > 0 , where f 0 is the original frequency of the prescaler. VALUE and EXP are chosen by writing the selected value to the corresponding filed in DTR. If VALUE = 0 , the frequency is unchanged. 9.5.7 Synchronization As the prescaler and counter operate asynchronously from the user interface, the AST needs a few clock cycles to synchronize values written to the CR, CV, SCR, WER, EVE, EVD, PIRx, ARx and DTR registers. The Busy bit in the Status Register (SR.BUSY) indicates that the synchronization is ongoing. During this time, writes to these registers will be discarded. Note that synchronization takes place also if the prescaler is clocked from CLK_AST. 138 32117A-10/2010 AT32UC3C 9.6 User Interface Table 9-1. Offset Register Register Name Access Reset 0x00 Control Register CR Read/Write 0x00000000 0x04 Counter Value CV Read/Write 0x00000000 0x08 Status Register SR Read-only 0x00000000 0x0C Status Clear Register SCR Write-only 0x00000000 0x10 Interrupt Enable Register IER Write-only 0x00000000 0x14 Interrupt Disable Register IDR Write-only 0x00000000 0x18 Interrupt Mask Register IMR Read-only 0x00000000 0x1C Wake Enable Register WER Read/write 0x00000000 AR0 Read/Write 0x00000000 0x20 Alarm Register 0 (2) Alarm Register 1 (2) AR1 Read/Write 0x00000000 0x30 (2) Periodic Interval Register 0 PIR0 Read/Write 0x00000000 0x34 Periodic Interval Register 1(2) PIR1 Read/Write 0x00000000 0x40 Clock Control Register CLOCK Read/Write 0x00000000 0x44 Digital Tuner Register DTR Read/Write 0x00000000 0x48 Event Enable EVE Write-only 0x00000000 0x4C Event Disable EVD Write-only 0x00000000 0x50 Event Mask EVM Read-only 0x00000000 0x54 Calendar Value CALV Read/Write 0x00000000 0xF0 Parameter Register PARAMETER Read-only -(1) 0xFC Version Register VERSION Read-only -(1) 0x24 Note: AST Register Memory Map 1. The reset values are device specific. Please refer to the Modue Configuration section at the end of this chapter. 2. The number of Alarm and Periodic Interval registers are device specific. Please refer to the Module Configuration section at the end of this chapter. 139 32117A-10/2010 AT32UC3C 9.6.1 Name: Control Register CR Access Type: Read/Write Offset: 0x00 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - 15 14 13 12 11 10 9 8 - - - - - - CA1 CA0 7 6 5 4 3 2 1 0 - - - - CAL PCLR EN PSEL * PSEL: Prescaler Select Selects prescaler bit PSEL as source clock for the counter. * CAn: Clear on Alarm n 0: The corresponding alarm will not clear the counter. 1: The corresponding alarm will clear the counter. * CAL: Calendar Mode 0: The AST operates in counter mode. 1: The AST operates in calendar mode. * PCLR: Prescaler Clear Writing a zero to this bit has no effect. Writing a one to this bit clears the prescaler. This bit always reads as zero. * EN: Enable 0: The AST is disabled. 1: The AST is enabled. 140 32117A-10/2010 AT32UC3C 9.6.2 Name: Counter Value CV Access Type: Read/Write Offset: 0x04 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 18 17 16 11 10 9 8 3 2 1 0 VALUE[31:24] 23 22 21 20 19 VALUE[23:16] 15 14 13 12 VALUE[15:8] 7 6 5 4 VALUE[7:0] * VALUE: AST Value * The current value of the AST counter. 141 32117A-10/2010 AT32UC3C 9.6.3 Name: Status Register SR Access Type: Read-only Offset: 0x08 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - CLKREADY CLKBUSY - - READY BUSY 23 22 21 20 19 18 17 16 - - - - - - PER1 PER0 15 14 13 12 11 10 9 8 - - - - - - ALARM1 ALARM0 7 6 5 4 3 2 1 0 - - - - - - - OVF * CLKREADY: Clock ready * * * * * * This bit is cleared when the corresponding bit in SCR is written to one. This bit is set when the SR.CLKBUSY bit has a 1-to-0 transition. CLKBUSY: Clock busy * 0: The clock is ready and can be changed. * 1: CLOCK.CEN has been written and the clock is busy. READY: AST ready This bit is cleared when the corresponding bit in SCR is written to one. This bit is set when the SR.BUSY bit has a 1-to-0 transition. BUSY: AST busy 0: The AST accepts writes to CR, CV, SCR, WER, EVE, EVD, ARn, and PIRn, and DTR. 1: The AST is busy and will discard writes to CR, CV, SCR, WER, EVE, EVD, ARn, and PIRn, and DTR. PERn: Periodic n This bit is cleared when the corresponding bit in SCR is written to one. This bit is set when the selected bit in the prescaler has a 0-to-1 transition. ALARMn: Alarm n This bit is cleared when the corresponding bit in SCR is written to one. This bit is set when the counter reaches the selected alarm value. OVF: Overflow This bit is cleared when the corresponding bit in SCR is written to one. This bit is set when an overflow has occurred. 142 32117A-10/2010 AT32UC3C 9.6.4 Name: Status Clear Register SCR Access Type: Write-only Offset: 0x0C Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - CLKREADY - - - READY - 23 22 21 20 19 18 17 16 - - - - - - PER1 PER0 15 14 13 12 11 10 9 8 - - - - - - ALARM1 ALARM0 7 6 5 4 3 2 1 0 - - - - - - - OVF Writing a zero to a bit in this register has no effect. Writing a one to a bit in this register will clear the corresponding bit in SR and the corresponding interrupt request. 143 32117A-10/2010 AT32UC3C 9.6.5 Name: Interrupt Enable Register IER Access Type: Write-only Offset: 0x10 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - CLKREADY - - - READY - 23 22 21 20 19 18 17 16 - - - - - - PER1 PER0 15 14 13 12 11 10 9 8 - - - - - - ALARM1 ALARM0 7 6 5 4 3 2 1 0 - - - - - - - OVF Writing a zero to a bit in this register has no effect. Writing a one to a bit in this register will set the corresponding bit in IMR. 144 32117A-10/2010 AT32UC3C 9.6.6 Name: Interrupt Disable Register IDR Access Type: Write-only Offset: 0x14 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - CLKREADY - - - READY - 23 22 21 20 19 18 17 16 - - - - - - PER1 PER0 15 14 13 12 11 10 9 8 - - - - - - ALARM1 ALARM0 7 6 5 4 3 2 1 0 - - - - - - - OVF Writing a zero to a bit in this register has no effect. Writing a one to a bit in this register will clear the corresponding bit in IMR. 145 32117A-10/2010 AT32UC3C 9.6.7 Name: Interrupt Mask Register IMR Access Type: Read-only Offset: 0x18 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - CLKREADY - - - READY - 23 22 21 20 19 18 17 16 - - - - - - PER1 PER0 15 14 13 12 11 10 9 8 - - - - - - ALARM1 ALARM0 7 6 5 4 3 2 1 0 - - - - - - - OVF 0: The corresponding interrupt is disabled. 1: The corresponding interrupt is enabled. A bit in this register is cleared when the corresponding bit in IDR is written to one. A bit in this register is set when the corresponding bit in IER is written to one. 146 32117A-10/2010 AT32UC3C 9.6.8 Name: Wake Enable Register WER Access Type: Read/Write Offset: 0x1C Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - PER1 PER0 15 14 13 12 11 10 9 8 - - - - - - ALARM1 ALARM0 7 6 5 4 3 2 1 0 - - - - - - - OVF This register enables the wakeup signal from the AST. * PERn: Periodic n 0: The CPU will not wake up from sleep mode when the selected bit in the prescaler has a 0-to-1 transition. 1: The CPU will wake up from sleep mode when the selected bit in the prescaler has a 0-to-1 transition. * ALARMn: Alarm n 0: The CPU will not wake up from sleep mode when the counter reaches the selected alarm value. 1: The CPU will wake up from sleep mode when the counter reaches the selected alarm value. * OVF: Overflow 0: A counter overflow will not wake up the CPU from sleep mode. 1: A counter overflow will wake up the CPU from sleep mode. 147 32117A-10/2010 AT32UC3C 9.6.9 Name: Alarm Register AR0/1 Access Type: Read/Write Offset: 0x20/0x24 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 18 17 16 11 10 9 8 3 2 1 0 VALUE[31:24] 23 22 21 20 19 VALUE[23:16] 15 14 13 12 VALUE[15:8] 7 6 5 4 VALUE[7:0] * VALUE: Alarm Value * When the counter reaches this value, an alarm is generated. 148 32117A-10/2010 AT32UC3C 9.6.10 Name: Periodic Interval Register PIR0/1 Access Type: Read/Write Offset: 0x30/0x34 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 - - - - - - - - 7 6 5 4 3 2 1 0 - - - INSEL * INSEL: Interval Select * The PERn bit in SR will be set when the INSEL bit in the prescaler has a 0-to-1 transition. 149 32117A-10/2010 AT32UC3C 9.6.11 Name: Clock Control Register CLOCK Access Type: Read/Write Offset: 0x40 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 - - - - - 7 6 5 4 3 2 1 0 - - - - - - - CEN CSSEL * CSSEL: Clock Source Selection This field defines the clock source CLK_AST_PRSC for the prescaler: Table 9-2. Clock Source Selection CSSEL Clock Source 0 System RC oscillator (RCSYS) 1 32KHz oscillator (OSC32K) 2 PB clock 3 Generic clock (GCLK) * CEN: Clock Enable 0: CLK_AST_PRSC is disabled. 1: CLK_AST_PRSC is enabled. 150 32117A-10/2010 AT32UC3C 9.6.12 Name: Digital Tuner Register DTR Access Type: Read/Write Offset: 0x44 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 3 2 1 0 VALUE 7 6 5 - - ADD 4 EXP * VALUE: 0: The frequency is unchanged. 1-255: The frequency will be adjusted according to the formula below. * ADD: 1 0: The resulting frequency is f = f0 1 - ---------------------------------------------------------------- 1 ( EXP + 8 ) ------------------for VALUE > 0 . - 2 - 1 VALUE 1 1: The resulting frequency is f = f0 1 + ---------------------------------------------------------------- 1 - ( EXP + 8 ) ------------------for VALUE > 0 . 2 - 1 VALUE * EXP: The frequency will be adjusted according to the formula above. 151 32117A-10/2010 AT32UC3C 9.6.13 Name: Event Enable Register EVE Access Type: Write-only Offset: 0x48 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - PER1 PER0 15 14 13 12 11 10 9 8 - - - - - - ALARM1 ALARM0 7 6 5 4 3 2 1 0 - - - - - - - OVF Writing a zero to a bit in this register has no effect. Writing a one to a bit in this register will set the corresponding bit in EVM. 152 32117A-10/2010 AT32UC3C 9.6.14 Name: Event Disable Register EVD Access Type: Write-only Offset: 0x4C Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - PER1 PER0 15 14 13 12 11 10 9 8 - - - - - - ALARM1 ALARM0 7 6 5 4 3 2 1 0 - - - - - - - OVF Writing a zero to a bit in this register has no effect. Writing a one to a bit in this register will clear the corresponding bit in EVM. 153 32117A-10/2010 AT32UC3C 9.6.15 Name: Event Mask Register EVM Access Type: Read-only Offset: 0x50 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - PER1 PER0 15 14 13 12 11 10 9 8 - - - - - - ALARM1 ALARM0 7 6 5 4 3 2 1 0 - - - - - - - OVF 0: The corresponding peripheral event is disabled. 1: The corresponding peripheral event is enabled. This bit is cleared when the corresponding bit in EVD is written to one. This bit is set when the corresponding bit in EVE is written to one. 154 32117A-10/2010 AT32UC3C 9.6.16 Name: Calendar Value CALV Access Type: Read/Write Offset: 0x54 Reset Value: 0x00000000 31 30 29 28 27 26 25 YEAR 23 22 21 MONTH[3:2] 20 MONTH[1:0] 15 19 18 13 12 6 16 HOUR[4] 11 10 HOUR[3:0] 7 17 DAY 14 24 9 8 1 0 MIN[5:2] 5 4 3 MIN[1:0] 2 SEC * YEAR: Year * Current year. The year is considered a leap year if YEAR[1:0] = 0. * MONTH: Month * * * * * 1 = January * 2 = February * ... * 12 = December DAY: Day * Day of month, starting with 1. HOUR: Hour * Hour of day, in 24-hour clock format. * Legal values are 0 through 23. MIN: Minute * Minutes, 0 through 59. SEC: Second * Seconds, 0 through 59. 155 32117A-10/2010 AT32UC3C 9.6.17 Name: Parameter Register PARAMETER Access Type: Read-only Offset: 0xF0 Reset Value: - 31 30 29 - - - 23 22 21 - - - 15 14 13 12 PIR1WA PIR0WA - NUMPIR 7 6 5 4 - * * * * * * * 28 27 26 25 24 17 16 9 8 PER1VALUE 20 19 18 PER0VALUE DTEXPVALUE 11 10 NUMAR 3 2 1 0 DTEXPWA DT This register gives the configuration used in the specific device. Also refer to the Module Configuration section. DT: Digital Tuner * 0: Digital tuner off * 1: Digital tuner on DTREXPWA: Digital Tuner Exponent Writeable * 0: Digital tuner exponent is a constant value. Writes to EXP bitfield in DTR will be discarded. * 1: Digital tuner exponent is chosen by writing to EXP bitfield in DTR DTREXPVALUE: Digital Tuner Exponent Value * Digital tuner exponent value if DT_EXP_WA is zero NUMAR: Number of Alarm Comparators 0: Zero alarm comparators. 1: One alarm comparator. 2: Two alarm comparators. NUMPIR: Number of Periodic Comparators 0: One periodic comparator. 1: Two periodic comparator. PIRnWA: Periodic Interval n Writeable 0: Periodic interval n prescaler tapping is a constant value. Writes to INSEL field in PIRn register will be discarded. 1: Periodic interval n prescaler tapping is chosen by writing to INSEL field in PIRn register. PERnVALUE: Periodic Interval n Value Periodic interval prescaler n tapping if PIRnWA is zero. 156 32117A-10/2010 AT32UC3C 9.6.18 Name: Version Register VERSION Access Type: Read-only Offset: 0xFC Reset Value: 0x00000300 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - 15 14 13 12 9 8 - - - - 7 6 5 4 VARIANT 11 10 VERSION[11:8] 3 2 1 0 VERSION[7:0] * VARIANT: Variant number * Reserved. No functionality associated. * VERSION: Version number * Version of the module. No functionality associated. 157 32117A-10/2010 AT32UC3C 9.7 Module configuration The specific configuration for each AST instance is listed in the following tables. The module bus clocks listed here are connected to the system bus clocks according to the table in the System Bus Clock Connections section. Table 9-3. Module configuration Feature AST Number of timer alarms 2 Number of periodic alarms 2 Digital tuner On Table 9-4. Module name AST Table 9-5. Module clock name Clock name Description CLK_AST Peripheral Bus clock from the PBA clock domain GCLK The generic clock used for the AST is GCLK2 PB clock Peripheral Bus clock from the PBA clock domain Register Reset Values Module name Clock name VERSION 0x00000200 PARAMETER 0x0000D203 158 32117A-10/2010 AT32UC3C 10. Watchdog Timer (WDT) Rev: 4.1.0.0 10.1 Features * * * * * 10.2 Watchdog Timer counter with 32-bit counter Timing window watchdog Clocked from system RC oscillator or the 32 KHz crystal oscillator Configuration lock WDT may be enabled at reset by a fuse Overview The Watchdog Timer (WDT) will reset the device unless it is periodically serviced by the software. This allows the device to recover from a condition that has caused the system to be unstable. The WDT has an internal counter clocked from the system RC oscillator or the 32 KHz crystal oscillator. The WDT counter must be periodically cleared by software to avoid a watchdog reset. If the WDT timer is not cleared correctly, the device will reset and start executing from the boot vector. 10.3 Block Diagram Figure 10-1. WDT Block Diagram PB PB Clock Domain CLR SR CTRL WDTCLR WINDOW, CLEARED EN, MODE, PSEL, TBAN SYNC RCSYS 0 OSC32K 1 CLK_CNT 32-bit Counter Watchdog Detector Watchdog Reset CEN CLK_CNT Domain CSSEL 10.4 Product Dependencies In order to use this module, other parts of the system must be configured correctly, as described below. 159 32117A-10/2010 AT32UC3C 10.4.1 Power Management When the WDT is enabled, the WDT remains clocked in all sleep modes. It is not possible to enter sleep modes where the source clock of CLK_CNT is stopped. Attempting to do so will result in the chip entering the lowest sleep mode where the source clock is running, leaving the WDT operational. Please refer to the Power Manager chapter for details about sleep modes. After a watchdog reset the WDT bit in the Reset Cause Register (RCAUSE) in the Power Manager will be set. 10.4.2 Clocks The clock for the WDT bus interface (CLK_WDT) is generated by the Power Manager. This clock is enabled at reset, and can be disabled in the Power Manager. It is recommended to disable the WDT before disabling the clock, to avoid freezing the WDT in an undefined state. There are two possible clock sources for the Watchdog Timer (CLK_CNT): * System RC oscillator (RCSYS): This oscillator is always enabled when selected as clock source for the WDT. Please refer to the Power Manager chapter for details about the RCSYS and sleep modes. Please refer to the Electrical Characteristics chapter for the characteristic frequency of this oscillator. * 32 KHz crystal oscillator (OSC32K): This oscillator has to be enabled in the System Control Interface before using it as clock source for the WDT. The WDT will not be able to detect if this clock is stopped. 10.4.3 Debug Operation The WDT counter is frozen during debug operation, unless the Run In Debug bit in the Development Control Register is set and the bit corresponding to the WDT is set in the Peripheral Debug Register (PDBG). Please refer to the On-Chip Debug chapter in the AVR32UC Technical Reference Manual, and the OCD Module Configuration section, for details. If the WDT counter is not frozen during debug operation it will need periodically clearing to avoid a watchdog reset. 10.4.4 Fuses The WDT can be enabled at reset. This is controlled by the WDTAUTO fuse, see Section 10.5.4 for details. Please refer to the Fuse Settings section in the Flash Controller chapter for details about WDTAUTO and how to program the fuses. 10.5 Functional Description 10.5.1 Basic Mode 10.5.1.1 WDT Control Register Access To avoid accidental disabling of the watchdog, the Control Register (CTRL) must be written twice, first with the KEY field set to 0x55, then 0xAA without changing the other bits. Failure to do so will cause the write operation to be ignored, and the value in the CTRL Register will not be changed. 10.5.1.2 Changing CLK_CNT Clock Source After any reset, except for watchdog reset, CLK_CNT will be enabled with the RCSYS as source. 160 32117A-10/2010 AT32UC3C To change the clock for the WDT the following steps need to be taken. Note that the WDT should always be disabled before changing the CLK_CNT source: 1. Write a zero to the Clock Enable (CEN) bit in the CTRL Register, leaving the other bits as they are in the CTRL Register. This will stop CLK_CNT. 2. Read back the CTRL Register until the CEN bit reads zero. The clock has now been stopped. 3. Modify the Clock Source Select (CSSEL) bit in the CTRL Register with your new clock selection and write it to the CTRL Register. 4. Write a one to the CEN bit, leaving the other bits as they are in the CTRL Register. This will enable the clock. 5. Read back the CTRL Register until the CEN bit reads one. The clock has now been enabled. 10.5.1.3 Configuring the WDT If the MODE bit in the CTRL Register is zero, the WDT is in basic mode. The Time Out Prescale Select (PSEL) field in the CTRL Register selects the WDT timeout period: Ttimeout = Tpsel = 2(PSEL+1) / fclk_cnt 10.5.1.4 Enabling the WDT To enable the WDT write a one to the Enable (EN) bit in the CTRL Register. Due to internal synchronization, it will take some time for the CTRL.EN bit to read back as one. 10.5.1.5 Clearing the WDT Counter The WDT counter is cleared by writing a one to the Watchdog Clear (WDTCLR) bit in the Clear (CLR) Register, at any correct write to the CTRL Register, or when the counter reaches Ttimeout and the chip is reset. In basic mode the CLR.WDTCLR can be written at any time when the WDT Counter Cleared (CLEARED) bit in the Status Register (SR) is one. Due to internal synchronization, clearing the WDT counter takes some time. The SR.CLEARED bit is cleared when writing to CLR.WDTCLR bit and set when the clearing is done. Any write to the CLR.WDTCLR bit while SR.CLEARED is zero will be ignored. Writing to the CLR.WDTCLR bit has to be done in a particular sequence to be valid. The CLR Register must be written twice, first with the KEY field set to 0x55 and WDTCLR set to one, then a second write with the KEY set to 0xAA without changing the WDTCLR bit. Writing to the CLR Register without the correct sequence has no effect. If the WDT counter is periodically cleared within Tpsel no watchdog reset will be issued, see Figure 10-2 on page 162. 161 32117A-10/2010 AT32UC3C Figure 10-2. Basic Mode WDT Timing Diagram, normal operation. t= t 0 T p se l T im e o u t W rite o n e to C L R .W D T C L R W a tc h d o g re s e t If the WDT counter is not cleared within Tpsel a watchdog reset will be issued at the end of Tpsel, see Figure 10-3 on page 162. Figure 10-3. Basic Mode WDT Timing Diagram, no clear within Tpsel. t=t 0 T p se l T im e o u t W rite o n e to C L R .W D T C L R W a tch d o g re se t 10.5.1.6 Watchdog Reset A watchdog reset will result in a reset and the code will start executing from the boot vector, please refer to the Power Manager chapter for details. If the Disable After Reset (DAR) bit in the CTRL Register is zero, the WDT counter will restart counting from zero when the watchdog reset is released. If the CTRL.DAR bit is one the WDT will be disabled after a watchdog reset. Only the CTRL.EN bit will be changed after the watchdog reset. However, if WDTAUTO fuse is configured to enable the WDT after a watchdog reset, and the CTRL.FCD bit is zero, writing a one to the CTRL.DAR bit will have no effect. 10.5.2 Window Mode The window mode can protect against tight loops of runaway code. This is obtained by adding a ban period to timeout period. During the ban period clearing the WDT counter is not allowed. If the WDT Mode (MODE) bit in the CTRL Register is one, the WDT is in window mode. Note that the CTRL.MODE bit can only be changed when the WDT is disabled (CTRL.EN=0). 162 32117A-10/2010 AT32UC3C The PSEL and Time Ban Prescale Select (TBAN) fields in the CTRL Register selects the WDT timeout period Ttimeout = Ttban + Tpsel = (2(TBAN+1) + 2(PSEL+1)) / fclk_cnt where Ttban sets the time period when clearing the WDT counter by writing to the CLR.WDTCLR bit is not allowed. Doing so will result in a watchdog reset, the device will receive a reset and the code will start executing form the boot vector, see Figure 10-5 on page 163. The WDT counter will be cleared. Writing a one to the CLR.WDTCLR bit within the Tpsel period will clear the WDT counter and the counter starts counting from zero (t=t0), entering Ttban, see Figure 10-4 on page 163. If the value in the CTRL Register is changed, the WDT counter will be cleared without a watchdog reset, regardless of if the value in the WDT counter and the TBAN value. If the WDT counter reaches Ttimeout, the counter will be cleared, the device will receive a reset and the code will start executing form the boot vector. Figure 10-4. Window Mode WDT Timing Diagram t= t 0 T tb a n T p se l T im e o u t W rite o n e to C L R .W D T C L R W a tch d o g re se t Figure 10-5. Window Mode WDT Timing Diagram, clearing within Ttban, resulting in watchdog reset. t= t 0 T tb a n T psel T im e o u t W rite o n e to C L R .W D T C L R W a tc h d o g re s e t 163 32117A-10/2010 AT32UC3C 10.5.3 Disabling the WDT The WDT is disabled by writing a zero to the CTRL.EN bit. When disabling the WDT no other bits in the CTRL Register should be changed until the CTRL.EN bit reads back as zero. If the CTRL.CEN bit is written to zero, the CTRL.EN bit will never read back as zero if changing the value from one to zero. 10.5.4 Flash Calibration The WDT can be enabled at reset. This is controlled by the WDTAUTO fuse. The WDT will be set in basic mode, RCSYS is set as source for CLK_CNT, and PSEL will be set to a value giving Tpsel above 100 ms. Please refer to the Fuse Settings chapter for details about WDTAUTO and how to program the fuses. If the Flash Calibration Done (FCD) bit in the CTRL Register is zero at a watchdog reset the flash calibration will be redone, and the CTRL.FCD bit will be set when the calibration is done. If CTRL.FCD is one at a watchdog reset, the configuration of the WDT will not be changed during flash calibration. After any other reset the flash calibration will always be done, and the CTRL.FCD bit will be set when the calibration is done. 10.5.5 Special Considerations Care must be taken when selecting the PSEL/TBAN values so that the timeout period is greater than the startup time of the chip. Otherwise a watchdog reset will reset the chip before any code has been run. This can also be avoided by writing the CTRL.DAR bit to one when configuring the WDT. If the Store Final Value (SFV) bit in the CTRL Register is one, the CTRL Register is locked for further write accesses. All writes to the CTRL Register will be ignored. Once the CTRL Register is locked, it can only be unlocked by a reset (e.g. POR, OCD, and WDT). The CTRL.MODE bit can only be changed when the WDT is disabled (CTRL.EN=0). 164 32117A-10/2010 AT32UC3C 10.6 User Interface Table 10-1. Note: WDT Register Memory Map Offset Register Register Name Access Reset 0x000 Control Register CTRL Read/Write 0x00010080 0x004 Clear Register CLR Write-only 0x00000000 0x008 Status Register SR Read-only 0x00000003 0x3FC Version Register VERSION Read-only -(1) 1. The reset value for this register is device specific. Please refer to the Module Configuration section at the end of this chapter. 165 32117A-10/2010 AT32UC3C 10.6.1 Name: Control Register CTRL Access Type: Read/Write Offset: 0x000 Reset Value: 0x00010080 31 30 29 28 27 26 25 24 19 18 17 16 CSSEL CEN 9 8 KEY 23 22 21 - 20 TBAN 15 14 13 12 11 10 - - - 7 6 5 4 3 2 1 0 FCD - - - SFV MODE DAR EN PSEL * KEY * * * * * * * This field must be written twice, first with key value 0x55, then 0xAA, for a write operation to be effective. This field always reads as zero. TBAN: Time Ban Prescale Select Counter bit TBAN is used as watchdog "banned" time frame. In this time frame clearing the WDT timer is forbidden, otherwise a watchdog reset is generated and the WDT timer is cleared. CSSEL: Clock Source Select 0: Select the system RC oscillator (RCSYS) as clock source. 1: Select the 32KHz crystal oscillator (OSC32K) as clock source. CEN: Clock Enable 0: The WDT clock is disabled. 1: The WDT clock is enabled. PSEL: Time Out Prescale Select Counter bit PSEL is used as watchdog timeout period. FCD: Flash Calibration Done This bit is set after any reset. 0: The flash calibration will be redone after a watchdog reset. 1: The flash calibration will not be redone after a watchdog reset. SFV: WDT Control Register Store Final Value 0: WDT Control Register is not locked. 1: WDT Control Register is locked. Once locked, the Control Register can not be re-written, only a reset unlocks the SFV bit. MODE: WDT Mode 0: The WDT is in basic mode, only PSEL time is used. 1: The WDT is in window mode. Total timeout period is now TBAN+PSEL. Writing to this bit when the WDT is enabled has no effect. 166 32117A-10/2010 AT32UC3C * DAR: WDT Disable After Reset 0: After a watchdog reset, the WDT will still be enabled. 1: After a watchdog reset, the WDT will be disabled. * EN: WDT Enable 0: WDT is disabled. 1: WDT is enabled. After writing to this bit the read back value will not change until the WDT is enabled/disabled. This due to internal synchronization. 167 32117A-10/2010 AT32UC3C 10.6.2 Name: Clear Register CLR Access Type: Write-only Offset: 0x004 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 KEY 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 - - - - - - - - 7 6 5 4 3 2 1 0 - - - - - - - WDTCLR When the Watchdog Timer is enabled, this Register must be periodically written within the window time frame or within the watchdog timeout period, to prevent a watchdog reset. * KEY This field must be written twice, first with key value 0x55, then 0xAA, for a write operation to be effective. * WDTCLR: Watchdog Clear Writing a zero to this bit has no effect. Writing a one to this bit clears the WDT counter. 168 32117A-10/2010 AT32UC3C 10.6.3 Name: Status Register SR Access Type: Read-only Offset: 0x008 Reset Value: 0x00000003 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 - - - - - - - - 7 6 5 4 3 2 1 0 - - - - - - CLEARED WINDOW * CLEARED: WDT Counter Cleared This bit is cleared when writing a one to the CLR.WDTCLR bit. This bit is set when clearing the WDT counter is done. * WINDOW: Within Window This bit is cleared when the WDT counter is inside the TBAN period. This bit is set when the WDT counter is inside the PSEL period. 169 32117A-10/2010 AT32UC3C 10.6.4 Name: Version Register VERSION Access Type: Read-only Offset: 0x3FC Reset Value: - 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - 15 14 13 12 9 8 - - - - 7 6 5 4 VARIANT 11 10 VERSION[11:8] 3 2 1 0 VERSION[7:0] * VARIANT: Variant number Reserved. No functionality associated. * VERSION: Version number Version number of the module. No functionality associated. 170 32117A-10/2010 AT32UC3C 10.7 Module Configuration The specific configuration for each WDT instance is listed in the following tables. The module bus clocks listed here are connected to the system bus clocks. Please refer to the Power Manager chapter for details. Table 10-2. Module clock name Module name Clock name Description WDT CLK_WDT Peripheral Bus clock from the PBA clock domain Table 10-3. Register Reset Values Register Reset Value VERSION 0x00000410 171 32117A-10/2010 AT32UC3C 11. Interrupt Controller (INTC) Rev: 1.0.2.5 11.1 Features * Autovectored low latency interrupt service with programmable priority - 4 priority levels for regular, maskable interrupts - One Non-Maskable Interrupt * Up to 64 groups of interrupts with up to 32 interrupt requests in each group 11.2 Overview The INTC collects interrupt requests from the peripherals, prioritizes them, and delivers an interrupt request and an autovector to the CPU. The AVR32 architecture supports 4 priority levels for regular, maskable interrupts, and a Non-Maskable Interrupt (NMI). The INTC supports up to 64 groups of interrupts. Each group can have up to 32 interrupt request lines, these lines are connected to the peripherals. Each group has an Interrupt Priority Register (IPR) and an Interrupt Request Register (IRR). The IPRs are used to assign a priority level and an autovector to each group, and the IRRs are used to identify the active interrupt request within each group. If a group has only one interrupt request line, an active interrupt group uniquely identifies the active interrupt request line, and the corresponding IRR is not needed. The INTC also provides one Interrupt Cause Register (ICR) per priority level. These registers identify the group that has a pending interrupt of the corresponding priority level. If several groups have a pending interrupt of the same level, the group with the lowest number takes priority. 11.3 Block Diagram Figure 11-1 gives an overview of the INTC. The grey boxes represent registers that can be accessed via the user interface. The interrupt requests from the peripherals (IREQn) and the NMI are input on the left side of the figure. Signals to and from the CPU are on the right side of the figure. 172 32117A-10/2010 AT32UC3C Figure 11-1. INTC Block Diagram Interrupt Controller CPU NMIREQ Masks OR IRRn GrpReqN IREQ63 IREQ34 IREQ33 IREQ32 OR GrpReq1 INT_level, offset IPRn . . . Request Masking ValReq1 INT_level, offset IPR1 . . . INTLEVEL Prioritizer . . . ValReqN SREG Masks I[3-0]M GM AUTOVECTOR IRR1 IREQ31 IREQ2 IREQ1 IREQ0 OR GrpReq0 ValReq0 IPR0 INT_level, offset IRR0 IRR Registers 11.4 IPR Registers ICR Registers Product Dependencies In order to use this module, other parts of the system must be configured correctly, as described below. 11.4.1 Power Management If the CPU enters a sleep mode that disables CLK_SYNC, the INTC will stop functioning and resume operation after the system wakes up from sleep mode. 11.4.2 Clocks The clock for the INTC bus interface (CLK_INTC) is generated by the Power Manager. This clock is enabled at reset, and can be disabled in the Power Manager. The INTC sampling logic runs on a clock which is stopped in any of the sleep modes where the system RC oscillator is not running. This clock is referred to as CLK_SYNC. This clock is enabled at reset, and only turned off in sleep modes where the system RC oscillator is stopped. 11.4.3 11.5 Debug Operation When an external debugger forces the CPU into debug mode, the INTC continues normal operation. Functional Description All of the incoming interrupt requests (IREQs) are sampled into the corresponding Interrupt Request Register (IRR). The IRRs must be accessed to identify which IREQ within a group that is active. If several IREQs within the same group are active, the interrupt service routine must prioritize between them. All of the input lines in each group are logically ORed together to form the GrpReqN lines, indicating if there is a pending interrupt in the corresponding group. The Request Masking hardware maps each of the GrpReq lines to a priority level from INT0 to INT3 by associating each group with the Interrupt Level (INTLEVEL) field in the corresponding 173 32117A-10/2010 AT32UC3C Interrupt Priority Register (IPR). The GrpReq inputs are then masked by the mask bits from the CPU status register. Any interrupt group that has a pending interrupt of a priority level that is not masked by the CPU status register, gets its corresponding ValReq line asserted. Masking of the interrupt requests is done based on five interrupt mask bits of the CPU status register, namely Interrupt Level 3 Mask (I3M) to Interrupt Level 0 Mask (I0M), and Global Interrupt Mask (GM). An interrupt request is masked if either the GM or the corresponding interrupt level mask bit is set. The Prioritizer hardware uses the ValReq lines and the INTLEVEL field in the IPRs to select the pending interrupt of the highest priority. If an NMI interrupt request is pending, it automatically gets the highest priority of any pending interrupt. If several interrupt groups of the highest pending interrupt level have pending interrupts, the interrupt group with the lowest number is selected. The INTLEVEL and handler autovector offset (AUTOVECTOR) of the selected interrupt are transmitted to the CPU for interrupt handling and context switching. The CPU does not need to know which interrupt is requesting handling, but only the level and the offset of the handler address. The IRR registers contain the interrupt request lines of the groups and can be read via user interface registers for checking which interrupts of the group are actually active. The delay through the INTC from the peripheral interrupt request is set until the interrupt request to the CPU is set is three cycles of CLK_SYNC. 11.5.1 Non-Maskable Interrupts A NMI request has priority over all other interrupt requests. NMI has a dedicated exception vector address defined by the AVR32 architecture, so AUTOVECTOR is undefined when INTLEVEL indicates that an NMI is pending. 11.5.2 CPU Response When the CPU receives an interrupt request it checks if any other exceptions are pending. If no exceptions of higher priority are pending, interrupt handling is initiated. When initiating interrupt handling, the corresponding interrupt mask bit is set automatically for this and lower levels in status register. E.g, if an interrupt of level 3 is approved for handling, the interrupt mask bits I3M, I2M, I1M, and I0M are set in status register. If an interrupt of level 1 is approved, the masking bits I1M and I0M are set in status register. The handler address is calculated by logical OR of the AUTOVECTOR to the CPU system register Exception Vector Base Address (EVBA). The CPU will then jump to the calculated address and start executing the interrupt handler. Setting the interrupt mask bits prevents the interrupts from the same and lower levels to be passed through the interrupt controller. Setting of the same level mask bit prevents also multiple requests of the same interrupt to happen. It is the responsibility of the handler software to clear the interrupt request that caused the interrupt before returning from the interrupt handler. If the conditions that caused the interrupt are not cleared, the interrupt request remains active. 11.5.3 Clearing an Interrupt Request Clearing of the interrupt request is done by writing to registers in the corresponding peripheral module, which then clears the corresponding NMIREQ/IREQ signal. The recommended way of clearing an interrupt request is a store operation to the controlling peripheral register, followed by a dummy load operation from the same register. This causes a 174 32117A-10/2010 AT32UC3C pipeline stall, which prevents the interrupt from accidentally re-triggering in case the handler is exited and the interrupt mask is cleared before the interrupt request is cleared. 175 32117A-10/2010 AT32UC3C 11.6 User Interface Table 11-1. INTC Register Memory Map Offset Register Register Name Access Reset 0x000 Interrupt Priority Register 0 IPR0 Read/Write 0x00000000 0x004 Interrupt Priority Register 1 IPR1 Read/Write 0x00000000 ... ... ... ... ... 0x0FC Interrupt Priority Register 63 IPR63 Read/Write 0x00000000 0x100 Interrupt Request Register 0 IRR0 Read-only N/A 0x104 Interrupt Request Register 1 IRR1 Read-only N/A ... ... ... ... ... 0x1FC Interrupt Request Register 63 IRR63 Read-only N/A 0x200 Interrupt Cause Register 3 ICR3 Read-only N/A 0x204 Interrupt Cause Register 2 ICR2 Read-only N/A 0x208 Interrupt Cause Register 1 ICR1 Read-only N/A 0x20C Interrupt Cause Register 0 ICR0 Read-only N/A 176 32117A-10/2010 AT32UC3C 11.6.1 Name: Interrupt Priority Registers IPR0...IPR63 Access Type: Read/Write Offset: 0x000 - 0x0FC Reset Value: 0x00000000 31 30 INTLEVEL[1:0] 29 28 27 26 25 24 - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 - - 7 6 1 0 AUTOVECTOR[13:8] 5 4 3 2 AUTOVECTOR[7:0] * INTLEVEL: Interrupt Level Indicates the EVBA-relative offset of the interrupt handler of the corresponding group: 00: INT0: Lowest priority 01: INT1 10: INT2 11: INT3: Highest priority * AUTOVECTOR: Autovector Address Handler offset is used to give the address of the interrupt handler. The least significant bit should be written to zero to give halfword alignment. 177 32117A-10/2010 AT32UC3C 11.6.2 Name: Interrupt Request Registers IRR0...IRR63 Access Type: Read-only Offset: 0x0FF - 0x1FC Reset Value: N/A 31 30 29 28 27 26 25 24 IRR[32*x+31] IRR[32*x+30] IRR[32*x+29] IRR[32*x+28] IRR[32*x+27] IRR[32*x+26] IRR[32*x+25] IRR[32*x+24] 23 22 21 20 19 18 17 16 IRR[32*x+23] IRR[32*x+22] IRR[32*x+21] IRR[32*x+20] IRR[32*x+19] IRR[32*x+18] IRR[32*x+17] IRR[32*x+16] 15 14 13 12 11 10 9 8 IRR[32*x+15] IRR[32*x+14] IRR[32*x+13] IRR[32*x+12] IRR[32*x+11] IRR[32*x+10] IRR[32*x+9] IRR[32*x+8] 7 6 5 4 3 2 1 0 IRR[32*x+7] IRR[32*x+6] IRR[32*x+5] IRR[32*x+4] IRR[32*x+3] IRR[32*x+2] IRR[32*x+1] IRR[32*x+0] * IRR: Interrupt Request line This bit is cleared when no interrupt request is pending on this input request line. This bit is set when an interrupt request is pending on this input request line. The are 64 IRRs, one for each group. Each IRR has 32 bits, one for each possible interrupt request, for a total of 2048 possible input lines. The IRRs are read by the software interrupt handler in order to determine which interrupt request is pending. The IRRs are sampled continuously, and are read-only. 178 32117A-10/2010 AT32UC3C 11.6.3 Name: Interrupt Cause Registers ICR0...ICR3 Access Type: Read-only Offset: 0x200 - 0x20C Reset Value: N/A 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 - - - - - - - - 7 6 5 4 3 2 1 0 - - CAUSE * CAUSE: Interrupt Group Causing Interrupt of Priority n ICRn identifies the group with the highest priority that has a pending interrupt of level n. This value is only defined when at least one interrupt of level n is pending. 179 32117A-10/2010 AT32UC3C 11.7 Interrupt Request Signal Map The various modules may output Interrupt request signals. These signals are routed to the Interrupt Controller (INTC), described in a later chapter. The Interrupt Controller supports up to 64 groups of interrupt requests. Each group can have up to 32 interrupt request signals. All interrupt signals in the same group share the same autovector address and priority level. Refer to the documentation for the individual submodules for a description of the semantics of the different interrupt requests. The interrupt request signals are connected to the INTC as follows. Table 11-2. Interrupt Request Signal Map Group Line Module Signal 0 0 AVR32UC3 CPU SYSBLOCK COMPARE 0 AVR32UC3 CPU OCD DCEMU DIRTY 1 AVR32UC3 CPU OCD DCCPU READ 0 Secure Access Unit 0 Peripheral DMA Controller PDCA 0 1 Peripheral DMA Controller PDCA 1 2 Peripheral DMA Controller PDCA 2 3 Peripheral DMA Controller PDCA 3 0 Peripheral DMA Controller PDCA 4 1 Peripheral DMA Controller PDCA 5 2 Peripheral DMA Controller PDCA 6 3 Peripheral DMA Controller PDCA 7 0 Peripheral DMA Controller PDCA 8 1 Peripheral DMA Controller PDCA 9 2 Peripheral DMA Controller PDCA 10 3 Peripheral DMA Controller PDCA 11 0 Peripheral DMA Controller PDCA 12 1 Peripheral DMA Controller PDCA 13 2 Peripheral DMA Controller PDCA 14 3 Peripheral DMA Controller PDCA 15 7 0 Memory DMA MDMA 8 0 USB 2.0 OTG Interface USBC 1 2 SAU 3 4 5 6 180 32117A-10/2010 AT32UC3C Table 11-2. Interrupt Request Signal Map 0 Control Area Network interface CANIF BOFF 0 1 Control Area Network interface CANIF ERROR 0 2 Control Area Network interface CANIF RXOK 0 3 Control Area Network interface CANIF TXOK 0 4 Control Area Network interface CANIF WAKEUP 0 5 Control Area Network interface CANIF BOFF 1 6 Control Area Network interface CANIF ERROR 1 7 Control Area Network interface CANIF RXOK 1 8 Control Area Network interface CANIF TXOK 1 9 Control Area Network interface CANIF WAKEUP 1 10 0 Flash Controller HFLASHC 11 0 SDRAM Controller SDRAMC 12 0 Power Manager 13 0 System Control Interface 0 Asynchronous Timer AST ALARM 1 Asynchronous Timer AST CLKREADY 2 Asynchronous Timer AST OVF 3 Asynchronous Timer AST PER 4 Asynchronous Timer AST READY 0 External Interrupt Controller EIC 1 1 External Interrupt Controller EIC 2 2 External Interrupt Controller EIC 3 3 External Interrupt Controller EIC 4 0 External Interrupt Controller EIC 5 1 External Interrupt Controller EIC 6 2 External Interrupt Controller EIC 7 3 External Interrupt Controller EIC 8 0 Frequency Meter 9 14 PM SCIF 15 16 17 FREQM 181 32117A-10/2010 AT32UC3C Table 11-2. Interrupt Request Signal Map 0 General Purpose Input/Output Controller GPIO 0 1 General Purpose Input/Output Controller GPIO 1 2 General Purpose Input/Output Controller GPIO 2 3 General Purpose Input/Output Controller GPIO 3 4 General Purpose Input/Output Controller GPIO 4 5 General Purpose Input/Output Controller GPIO 5 6 General Purpose Input/Output Controller GPIO 6 7 General Purpose Input/Output Controller GPIO 7 8 General Purpose Input/Output Controller GPIO 8 9 General Purpose Input/Output Controller GPIO 9 10 General Purpose Input/Output Controller GPIO 10 11 General Purpose Input/Output Controller GPIO 11 12 General Purpose Input/Output Controller GPIO 12 13 General Purpose Input/Output Controller GPIO 13 14 General Purpose Input/Output Controller GPIO 14 15 General Purpose Input/Output Controller GPIO 15 19 0 Universal Synchronous/Asynchronous Receiver/Transmitter USART0 20 0 Universal Synchronous/Asynchronous Receiver/Transmitter USART1 21 0 Universal Synchronous/Asynchronous Receiver/Transmitter USART2 22 0 Universal Synchronous/Asynchronous Receiver/Transmitter USART3 23 0 Serial Peripheral Interface SPI0 24 0 Serial Peripheral Interface SPI1 25 0 Two-wire Master Interface TWIM0 26 0 Two-wire Master Interface TWIM1 27 0 Two-wire Slave Interface TWIS0 28 0 Two-wire Slave Interface TWIS1 29 0 Inter-IC Sound (I2S) Controller IISC 30 0 Pulse Width Modulation Controller PWM 31 0 Quadrature Decoder QDEC0 32 0 Quadrature Decoder QDEC1 0 Timer/Counter TC00 1 Timer/Counter TC01 2 Timer/Counter TC02 18 33 182 32117A-10/2010 AT32UC3C Table 11-2. Interrupt Request Signal Map 0 Timer/Counter TC10 1 Timer/Counter TC11 2 Timer/Counter TC12 0 Peripheral Event Controller PEVC TR 1 Peripheral Event Controller PEVC OV 0 ADC controller interface with Touch Screen functionality ADCIFA SEQ0 1 ADC controller interface with Touch Screen functionality ADCIFA SEQ1 2 ADC controller interface with Touch Screen functionality ADCIFA SUTD 3 ADC controller interface with Touch Screen functionality ADCIFA WINDOW 4 ADC controller interface with Touch Screen functionality ADCIFA AWAKEUP 5 ADC controller interface with Touch Screen functionality ADCIFA PENDET 37 0 Analog Comparators Interface ACIFA0 38 0 Analog Comparators Interface ACIFA1 0 DAC interface DACIFB0 CHB UNDERRUN 1 DAC interface DACIFB0 CHB OVERRUN 2 DAC interface DACIFB0 CHB DATA EMPTY 3 DAC interface DACIFB0 CHA UNDERRUN 4 DAC interface DACIFB0 CHA OVERRUN 5 DAC interface DACIFB0 CHA DATA EMPTY 0 DAC interface DACIFB1 CHA DATA EMPTY 1 DAC interface DACIFB1 CHA OVERRUN 2 DAC interface DACIFB1 CHA UNDERRUN 3 DAC interface DACIFB1 CHB DATA EMPTY 4 DAC interface DACIFB1 CHB OVERRUN 5 DAC interface DACIFB1 CHB UNDERRUN 34 35 36 39 40 183 32117A-10/2010 AT32UC3C Table 11-2. Interrupt Request Signal Map 41 0 aWire AW 42 0 Ethernet MAC 44 0 Universal Synchronous/Asynchronous Receiver/Transmitter 45 0 Two-wire Master Interface TWIM2 46 0 Two-wire Slave Interface TWIS2 MACB USART4 184 32117A-10/2010 AT32UC3C 12. External Interrupt Controller (EIC) Rev: 3.0.2.0 12.1 Features * * * * * * * 12.2 Dedicated interrupt request for each interrupt Individually maskable interrupts Interrupt on rising or falling edge Interrupt on high or low level Asynchronous interrupts for sleep modes without clock Filtering of interrupt lines Non-Maskable NMI interrupt Overview The External Interrupt Controller (EIC) allows pins to be configured as external interrupts. Each external interrupt has its own interrupt request and can be individually masked. Each external interrupt can generate an interrupt on rising or falling edge, or high or low level. Every interrupt input has a configurable filter to remove spikes from the interrupt source. Every interrupt pin can also be configured to be asynchronous in order to wake up the part from sleep modes where the CLK_SYNC clock has been disabled. A Non-Maskable Interrupt (NMI) is also supported. This has the same properties as the other external interrupts, but is connected to the NMI request of the CPU, enabling it to interrupt any other interrupt mode. The EIC can wake up the part from sleep modes without triggering an interrupt. In this mode, code execution starts from the instruction following the sleep instruction. 12.3 Block Diagram Figure 12-1. EIC Block Diagram EN D IS E n a b le LEVEL MODE EDGE ASYNC P o la rity c o n tro l A s y n c h ro n u s d e te c to r F IL T E R LEVEL MODE EDGE F ilte r E d g e /L e v e l D e te c to r E X T IN T n NMI CTRL CLK_SYNC IC R CTRL IE R ID R IN T n M ask IS R IM R W ake d e te c t IR Q n E IC _ W A K E 185 32117A-10/2010 AT32UC3C 12.4 I/O Lines Description Table 12-1. 12.5 I/O Lines Description Pin Name Pin Description Type NMI Non-Maskable Interrupt Input EXTINTn External Interrupt Input Product Dependencies In order to use this module, other parts of the system must be configured correctly, as described below. 12.5.1 I/O Lines The external interrupt pins (EXTINTn and NMI) may be multiplexed with I/O Controller lines. The programmer must first program the I/O Controller to assign the desired EIC pins to their peripheral function. If I/O lines of the EIC are not used by the application, they can be used for other purposes by the I/O Controller. It is only required to enable the EIC inputs actually in use. If an application requires two external interrupts, then only two I/O lines will be assigned to EIC inputs. 12.5.2 Power Management All interrupts are available in all sleep modes as long as the EIC module is powered. However, in sleep modes where CLK_SYNC is stopped, the interrupt must be configured to asynchronous mode. 12.5.3 Clocks The clock for the EIC bus interface (CLK_EIC) is generated by the Power Manager. This clock is enabled at reset, and can be disabled in the Power Manager. The filter and synchronous edge/level detector runs on a clock which is stopped in any of the sleep modes where the system RC oscillator (RCSYS) is not running. This clock is referred to as CLK_SYNC. 12.5.4 Interrupts The external interrupt request lines are connected to the interrupt controller. Using the external interrupts requires the interrupt controller to be programmed first. Using the Non-Maskable Interrupt does not require the interrupt controller to be programmed. 12.5.5 Debug Operation When an external debugger forces the CPU into 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. 12.6 12.6.1 Functional Description External Interrupts The external interrupts are not enabled by default, allowing the proper interrupt vectors to be set up by the CPU before the interrupts are enabled. 186 32117A-10/2010 AT32UC3C Each external interrupt INTn can be configured to produce an interrupt on rising or falling edge, or high or low level. External interrupts are configured by the MODE, EDGE, and LEVEL registers. Each interrupt has a bit INTn in each of these registers. Writing a zero to the INTn bit in the MODE register enables edge triggered interrupts, while writing a one to the bit enables level triggered interrupts. If INTn is configured as an edge triggered interrupt, writing a zero to the INTn bit in the EDGE register will cause the interrupt to be triggered on a falling edge on EXTINTn, while writing a one to the bit will cause the interrupt to be triggered on a rising edge on EXTINTn. If INTn is configured as a level triggered interrupt, writing a zero to the INTn bit in the LEVEL register will cause the interrupt to be triggered on a low level on EXTINTn, while writing a one to the bit will cause the interrupt to be triggered on a high level on EXTINTn. Each interrupt has a corresponding bit in each of the interrupt control and status registers. Writing a one to the INTn bit in the Interrupt Enable Register (IER) enables the external interrupt from pin EXTINTn to propagate from the EIC to the interrupt controller, while writing a one to INTn bit in the Interrupt Disable Register (IDR) disables this propagation. The Interrupt Mask Register (IMR) can be read to check which interrupts are enabled. When an interrupt triggers, the corresponding bit in the Interrupt Status Register (ISR) will be set. This bit remains set until a one is written to the corresponding bit in the Interrupt Clear Register (ICR) or the interrupt is disabled. Writing a one to the INTn bit in the Enable Register (EN) enables the external interrupt on pin EXTINTn, while writing a one to INTn bit in the Disable Register (DIS) disables the external interrupt. The Control Register (CTRL) can be read to check which interrupts are enabled. If a bit in the CTRL register is set, but the corresponding bit in IMR is not set, an interrupt will not propagate to the interrupt controller. However, the corresponding bit in ISR will be set, and EIC_WAKE will be set. Note that an external interrupt should not be enabled before it has been configured correctly. If the CTRL.INTn bit is zero, the corresponding bit in ISR will always be zero. Disabling an external interrupt by writing a one to the DIS.INTn bit will clear the corresponding bit in ISR. Please refer to the Module Configuration section for the number of external interrupts. 12.6.2 Synchronization and Filtering of External Interrupts In synchronous mode the pin value of the EXTINTn pin is synchronized to CLK_SYNC, so spikes shorter than one CLK_SYNC cycle are not guaranteed to produce an interrupt. The synchronization of the EXTINTn to CLK_SYNC will delay the propagation of the interrupt to the interrupt controller by two cycles of CLK_SYNC, see Figure 12-2 and Figure 12-3 for examples (FILTER off). It is also possible to apply a filter on EXTINTn by writing a one to the INTn bit in the FILTER register. This filter is a majority voter, if the condition for an interrupt is true for more than one of the latest three cycles of CLK_SYNC the interrupt will be set. This will additionally delay the propagation of the interrupt to the interrupt controller by one or two cycles of CLK_SYNC, see Figure 12-2 and Figure 12-3 for examples (FILTER on). 187 32117A-10/2010 AT32UC3C Figure 12-2. Timing Diagram, Synchronous Interrupts, High Level or Rising Edge CLK_SYNC EXTINTn/NMI ISR.INTn: FILTER off ISR.INTn: FILTER on Figure 12-3. Timing Diagram, Synchronous Interrupts, Low Level or Falling Edge CLK_SYNC EXTINTn/NMI ISR.INTn: FILTER off ISR.INTn: FILTER on 12.6.3 Non-Maskable Interrupt The NMI supports the same features as the external interrupts, and is accessed through the same registers. The description in Section 12.6.1 should be followed, accessing the NMI bit instead of the INTn bits. The NMI is non-maskable within the CPU in the sense that it can interrupt any other execution mode. Still, as for the other external interrupts, the actual NMI input can be enabled and disabled by accessing the registers in the EIC. 12.6.4 Asynchronous Interrupts Each external interrupt can be made asynchronous by writing a one to INTn in the ASYNC register. This will route the interrupt signal through the asynchronous path of the module. All edge interrupts will be interpreted as level interrupts and the filter is disabled. If an interrupt is configured as edge triggered interrupt in asynchronous mode, a zero in EDGE.INTn will be interpreted as low level, and a one in EDGE.INTn will be interpreted as high level. EIC_WAKE will be set immediately after the source triggers the interrupt, while the corresponding bit in ISR and the interrupt to the interrupt controller will be set on the next rising edge of CLK_SYNC. Please refer to Figure 12-4 on page 189 for details. 188 32117A-10/2010 AT32UC3C When CLK_SYNC is stopped only asynchronous interrupts remain active, and any short spike on this interrupt will wake up the device. EIC_WAKE will restart CLK_SYNC and ISR will be updated on the first rising edge of CLK_SYNC. Figure 12-4. Timing Diagram, Asynchronous Interrupts CLK_SYNC CLK_SYNC E X T IN T n /N M I 12.6.5 E X T IN T n /N M I IS R .IN T n : r is in g E D G E o r h ig h LEVEL IS R .IN T n : r is in g E D G E o r h ig h LEVEL E IC _ W A K E : r is in g E D G E o r h ig h LEVEL E IC _ W A K E : r is in g E D G E o r h ig h LEVEL Wakeup The external interrupts can be used to wake up the part from sleep modes. The wakeup can be interpreted in two ways. If the corresponding bit in IMR is one, then the execution starts at the interrupt handler for this interrupt. If the bit in IMR is zero, then the execution starts from the next instruction after the sleep instruction. 189 32117A-10/2010 AT32UC3C 12.7 User Interface Table 12-2. Note: EIC Register Memory Map Offset Register Register Name Access Reset 0x000 Interrupt Enable Register IER Write-only 0x00000000 0x004 Interrupt Disable Register IDR Write-only 0x00000000 0x008 Interrupt Mask Register IMR Read-only 0x00000000 0x00C Interrupt Status Register ISR Read-only 0x00000000 0x010 Interrupt Clear Register ICR Write-only 0x00000000 0x014 Mode Register MODE Read/Write 0x00000000 0x018 Edge Register EDGE Read/Write 0x00000000 0x01C Level Register LEVEL Read/Write 0x00000000 0x020 Filter Register FILTER Read/Write 0x00000000 0x024 Test Register TEST Read/Write 0x00000000 0x028 Asynchronous Register ASYNC Read/Write 0x00000000 0x030 Enable Register EN Write-only 0x00000000 0x034 Disable Register DIS Write-only 0x00000000 0x038 Control Register CTRL Read-only 0x00000000 0x3FC Version Register VERSION Read-only - (1) 1. The reset value is device specific. Please refer to the Module Configuration section at the end of this chapter. 190 32117A-10/2010 AT32UC3C 12.7.1 Name: Interrupt Enable Register IER Access Type: Write-only Offset: 0x000 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - INT30 INT29 INT28 INT27 INT26 INT25 INT24 23 22 21 20 19 18 17 16 INT23 INT22 INT21 INT20 INT19 INT18 INT17 INT16 15 14 13 12 11 10 9 8 INT15 INT14 INT13 INT12 INT11 INT10 INT9 INT8 7 6 5 4 3 2 1 0 INT7 INT6 INT5 INT4 INT3 INT2 INT1 NMI * INTn: External Interrupt n Writing a zero to this bit has no effect. Writing a one to this bit will set the corresponding bit in IMR. Please refer to the Module Configuration section for the number of external interrupts. * NMI: Non-Maskable Interrupt Writing a zero to this bit has no effect. Wrting a one to this bit will set the corresponding bit in IMR. 191 32117A-10/2010 AT32UC3C 12.7.2 Name: Interrupt Disable Register IDR Access Type: Write-only Offset: 0x004 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - INT30 INT29 INT28 INT27 INT26 INT25 INT24 23 22 21 20 19 18 17 16 INT23 INT22 INT21 INT20 INT19 INT18 INT17 INT16 15 14 13 12 11 10 9 8 INT15 INT14 INT13 INT12 INT11 INT10 INT9 INT8 7 6 5 4 3 2 1 0 INT7 INT6 INT5 INT4 INT3 INT2 INT1 NMI * INTn: External Interrupt n Writing a zero to this bit has no effect. Writing a one to this bit will clear the corresponding bit in IMR. Please refer to the Module Configuration section for the number of external interrupts. * NMI: Non-Maskable Interrupt Writing a zero to this bit has no effect. Writing a one to this bit will clear the corresponding bit in IMR. 192 32117A-10/2010 AT32UC3C 12.7.3 Name: Interrupt Mask Register IMR Access Type: Read-only Offset: 0x008 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - INT30 INT29 INT28 INT27 INT26 INT25 INT24 23 22 21 20 19 18 17 16 INT23 INT22 INT21 INT20 INT19 INT18 INT17 INT16 15 14 13 12 11 10 9 8 INT15 INT14 INT13 INT12 INT11 INT10 INT9 INT8 7 6 5 4 3 2 1 0 INT7 INT6 INT5 INT4 INT3 INT2 INT1 NMI * INTn: External Interrupt n 0: The corresponding interrupt is disabled. 1: The corresponding interrupt is enabled. This bit is cleared when the corresponding bit in IDR is written to one. This bit is set when the corresponding bit in IER is written to one. Please refer to the Module Configuration section for the number of external interrupts. * NMI: Non-Maskable Interrupt 0: The Non-Maskable Interrupt is disabled. 1: The Non-Maskable Interrupt is enabled. This bit is cleared when the corresponding bit in IDR is written to one. This bit is set when the corresponding bit in IER is written to one. 193 32117A-10/2010 AT32UC3C 12.7.4 Name: Interrupt Status Register ISR Access Type: Read-only Offset: 0x00C Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - INT30 INT29 INT28 INT27 INT26 INT25 INT24 23 22 21 20 19 18 17 16 INT23 INT22 INT21 INT20 INT19 INT18 INT17 INT16 15 14 13 12 11 10 9 8 INT15 INT14 INT13 INT12 INT11 INT10 INT9 INT8 7 6 5 4 3 2 1 0 INT7 INT6 INT5 INT4 INT3 INT2 INT1 NMI * INTn: External Interrupt n 0: An interrupt event has not occurred. 1: An interrupt event has occurred. This bit is cleared by writing a one to the corresponding bit in ICR. Please refer to the Module Configuration section for the number of external interrupts. * NMI: Non-Maskable Interrupt 0: An interrupt event has not occurred. 1: An interrupt event has occurred. This bit is cleared by writing a one to the corresponding bit in ICR. 194 32117A-10/2010 AT32UC3C 12.7.5 Name: Interrupt Clear Register ICR Access Type: Write-only Offset: 0x010 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - INT30 INT29 INT28 INT27 INT26 INT25 INT24 23 22 21 20 19 18 17 16 INT23 INT22 INT21 INT20 INT19 INT18 INT17 INT16 15 14 13 12 11 10 9 8 INT15 INT14 INT13 INT12 INT11 INT10 INT9 INT8 7 6 5 4 3 2 1 0 INT7 INT6 INT5 INT4 INT3 INT2 INT1 NMI * INTn: External Interrupt n Writing a zero to this bit has no effect. Writing a one to this bit will clear the corresponding bit in ISR. Please refer to the Module Configuration section for the number of external interrupts. * NMI: Non-Maskable Interrupt Writing a zero to this bit has no effect. Writing a one to this bit will clear the corresponding bit in ISR. 195 32117A-10/2010 AT32UC3C 12.7.6 Name: Mode Register MODE Access Type: Read/Write Offset: 0x014 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - INT30 INT29 INT28 INT27 INT26 INT25 INT24 23 22 21 20 19 18 17 16 INT23 INT22 INT21 INT20 INT19 INT18 INT17 INT16 15 14 13 12 11 10 9 8 INT15 INT14 INT13 INT12 INT11 INT10 INT9 INT8 7 6 5 4 3 2 1 0 INT7 INT6 INT5 INT4 INT3 INT2 INT1 NMI * INTn: External Interrupt n 0: The external interrupt is edge triggered. 1: The external interrupt is level triggered. Please refer to the Module Configuration section for the number of external interrupts. * NMI: Non-Maskable Interrupt 0: The Non-Maskable Interrupt is edge triggered. 1: The Non-Maskable Interrupt is level triggered. 196 32117A-10/2010 AT32UC3C 12.7.7 Name: Edge Register EDGE Access Type: Read/Write Offset: 0x018 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - INT30 INT29 INT28 INT27 INT26 INT25 INT24 23 22 21 20 19 18 17 16 INT23 INT22 INT21 INT20 INT19 INT18 INT17 INT16 15 14 13 12 11 10 9 8 INT15 INT14 INT13 INT12 INT11 INT10 INT9 INT8 7 6 5 4 3 2 1 0 INT7 INT6 INT5 INT4 INT3 INT2 INT1 NMI * INTn: External Interrupt n 0: The external interrupt triggers on falling edge. 1: The external interrupt triggers on rising edge. Please refer to the Module Configuration section for the number of external interrupts. * NMI: Non-Maskable Interrupt 0: The Non-Maskable Interrupt triggers on falling edge. 1: The Non-Maskable Interrupt triggers on rising edge. 197 32117A-10/2010 AT32UC3C 12.7.8 Name: Level Register LEVEL Access Type: Read/Write Offset: 0x01C Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - INT30 INT29 INT28 INT27 INT26 INT25 INT24 23 22 21 20 19 18 17 16 INT23 INT22 INT21 INT20 INT19 INT18 INT17 INT16 15 14 13 12 11 10 9 8 INT15 INT14 INT13 INT12 INT11 INT10 INT9 INT8 7 6 5 4 3 2 1 0 INT7 INT6 INT5 INT4 INT3 INT2 INT1 NMI * INTn: External Interrupt n 0: The external interrupt triggers on low level. 1: The external interrupt triggers on high level. Please refer to the Module Configuration section for the number of external interrupts. * NMI: Non-Maskable Interrupt 0: The Non-Maskable Interrupt triggers on low level. 1: The Non-Maskable Interrupt triggers on high level. 198 32117A-10/2010 AT32UC3C 12.7.9 Filter Register Name: FILTER Access Type: Read/Write Offset: 0x020 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - INT30 INT29 INT28 INT27 INT26 INT25 INT24 23 22 21 20 19 18 17 16 INT23 INT22 INT21 INT20 INT19 INT18 INT17 INT16 15 14 13 12 11 10 9 8 INT15 INT14 INT13 INT12 INT11 INT10 INT9 INT8 7 6 5 4 3 2 1 0 INT7 INT6 INT5 INT4 INT3 INT2 INT1 NMI * INTn: External Interrupt n 0: The external interrupt is not filtered. 1: The external interrupt is filtered. Please refer to the Module Configuration section for the number of external interrupts. * NMI: Non-Maskable Interrupt 0: The Non-Maskable Interrupt is not filtered. 1: The Non-Maskable Interrupt is filtered. 199 32117A-10/2010 AT32UC3C 12.7.10 Test Register Name: TEST Access Type: Read/Write Offset: 0x024 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 TESTEN INT30 INT29 INT28 INT27 INT26 INT25 INT24 23 22 21 20 19 18 17 16 INT23 INT22 INT21 INT20 INT19 INT18 INT17 INT16 15 14 13 12 11 10 9 8 INT15 INT14 INT13 INT12 INT11 INT10 INT9 INT8 7 6 5 4 3 2 1 0 INT7 INT6 INT5 INT4 INT3 INT2 INT1 NMI * TESTEN: Test Enable 0: This bit disables external interrupt test mode. 1: This bit enables external interrupt test mode. * INTn: External Interrupt n Writing a zero to this bit will set the input value to INTn to zero, if test mode is enabled. Writing a one to this bit will set the input value to INTn to one, if test mode is enabled. Please refer to the Module Configuration section for the number of external interrupts. * NMI: Non-Maskable Interrupt Writing a zero to this bit will set the input value to NMI to zero, if test mode is enabled. Writing a one to this bit will set the input value to NMI to one, if test mode is enabled. If TESTEN is 1, the value written to this bit will be the value to the interrupt detector and the value on the pad will be ignored. 200 32117A-10/2010 AT32UC3C 12.7.11 Asynchronous Register Name: ASYNC Access Type: Read/Write Offset: 0x028 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - INT30 INT29 INT28 INT27 INT26 INT25 INT24 23 22 21 20 19 18 17 16 INT23 INT22 INT21 INT20 INT19 INT18 INT17 INT16 15 14 13 12 11 10 9 8 INT15 INT14 INT13 INT12 INT11 INT10 INT9 INT8 7 6 5 4 3 2 1 0 INT7 INT6 INT5 INT4 INT3 INT2 INT1 NMI * INTn: External Interrupt n 0: The external interrupt is synchronized to CLK_SYNC. 1: The external interrupt is asynchronous. Please refer to the Module Configuration section for the number of external interrupts. * NMI: Non-Maskable Interrupt 0: The Non-Maskable Interrupt is synchronized to CLK_SYNC. 1: The Non-Maskable Interrupt is asynchronous. 201 32117A-10/2010 AT32UC3C 12.7.12 Enable Register Name: EN Access Type: Write-only Offset: 0x030 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - INT30 INT29 INT28 INT27 INT26 INT25 INT24 23 22 21 20 19 18 17 16 INT23 INT22 INT21 INT20 INT19 INT18 INT17 INT16 15 14 13 12 11 10 9 8 INT15 INT14 INT13 INT12 INT11 INT10 INT9 INT8 7 6 5 4 3 2 1 0 INT7 INT6 INT5 INT4 INT3 INT2 INT1 NMI * INTn: External Interrupt n Writing a zero to this bit has no effect. Writing a one to this bit will enable the corresponding external interrupt. Please refer to the Module Configuration section for the number of external interrupts. * NMI: Non-Maskable Interrupt Writing a zero to this bit has no effect. Writing a one to this bit will enable the Non-Maskable Interrupt. 202 32117A-10/2010 AT32UC3C 12.7.13 Disable Register Name: DIS Access Type: Write-only Offset: 0x034 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - INT30 INT29 INT28 INT27 INT26 INT25 INT24 23 22 21 20 19 18 17 16 INT23 INT22 INT21 INT20 INT19 INT18 INT17 INT16 15 14 13 12 11 10 9 8 INT15 INT14 INT13 INT12 INT11 INT10 INT9 INT8 7 6 5 4 3 2 1 0 INT7 INT6 INT5 INT4 INT3 INT2 INT1 NMI * INTn: External Interrupt n Writing a zero to this bit has no effect. Writing a one to this bit will disable the corresponding external interrupt. Please refer to the Module Configuration section for the number of external interrupts. * NMI: Non-Maskable Interrupt Writing a zero to this bit has no effect. Writing a one to this bit will disable the Non-Maskable Interrupt. 203 32117A-10/2010 AT32UC3C 12.7.14 Control Register Name: CTRL Access Type: Read-only Offset: 0x038 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - INT30 INT29 INT28 INT27 INT26 INT25 INT24 23 22 21 20 19 18 17 16 INT23 INT22 INT21 INT20 INT19 INT18 INT17 INT16 15 14 13 12 11 10 9 8 INT15 INT14 INT13 INT12 INT11 INT10 INT9 INT8 7 6 5 4 3 2 1 0 INT7 INT6 INT5 INT4 INT3 INT2 INT1 NMI * INTn: External Interrupt n 0: The corresponding external interrupt is disabled. 1: The corresponding external interrupt is enabled. Please refer to the Module Configuration section for the number of external interrupts. * NMI: Non-Maskable Interrupt 0: The Non-Maskable Interrupt is disabled. 1: The Non-Maskable Interrupt is enabled. 204 32117A-10/2010 AT32UC3C 12.7.15 Name: Version Register VERSION Access Type: Read-only Offset: 0x3FC Reset Value: - 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 - - - - 7 6 5 4 VERSION[11:8] 3 2 1 0 VERSION[7:0] * VERSION: Version number Version number of the module. No functionality associated. 205 32117A-10/2010 AT32UC3C 12.8 Module Configuration The specific configuration for each EIC instance is listed in the following tables. The module bus clocks listed here are connected to the system bus clocks. Please refer to the Power Manager chapter for details. Table 12-3. Module Configuration Feature EIC Number of external interrupts, including NMI 9 Table 12-4. Module Clock Name Module name Clock Name Description EIC CLK_EIC Peripheral Bus clock from the PBA clock domain Table 12-5. Register Reset Values Register Reset Value VERSION 0x00000302 206 32117A-10/2010 AT32UC3C 13. Frequency Meter (FREQM) Rev: 3.1.0.1 13.1 Features * * * * 13.2 Accurately measures a clock frequency Selectable reference clock A selectable clock can be measured Ratio can be measured with 24-bit accuracy Overview The Frequency Meter (FREQM) can be used to accurately measure the frequency of a clock by comparing it to a known reference clock. 13.3 Block Diagram Figure 13-1. Frequency Meter Block Diagram CLKSEL START CLK_MSR Counter VALUE CLK_REF Timer Trigger REFSEL 13.4 ISR REFNUM, START Product Dependencies In order to use this module, other parts of the system must be configured correctly, as described below. 13.4.1 Power Management The device can enter a sleep mode while a measurement is ongoing. However, make sure that neither CLK_MSR nor CLK_REF is stopped in the actual sleep mode. FREQM interrupts can wake up the device from sleep modes when the measurement is done, but only from sleep modes where CLK_FREQM is running. Please refer to the Power Manager chapter for details. 207 32117A-10/2010 AT32UC3C 13.4.2 Clocks The clock for the FREQM bus interface (CLK_FREQM) is generated by the Power Manager. This clock is enabled at reset, and can be disabled in the Power Manager. It is recommended to disable the FREQM before disabling the clock, to avoid freezing the FREQM ia an undefined state. A set of clocks can be selected as reference (CLK_REF) and another set of clocks can be selected for measurement (CLK_MSR). Please refer to the CLKSEL and REFSEL tables in the Module Configuration section for details. 13.4.3 Debug Operation When an external debugger forces the CPU into debug mode, the FREQM continues normal operation. If the FREQM 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. 13.4.4 Interrupts The FREQM interrupt request line is connected to the internal source of the interrupt controller. Using the FREQM interrupt requires the interrupt controller to be programmed first. 13.5 Functional Description The FREQM accuratly measures the frequency of a clock by comparing the frequency to a known frequency: fCLK_MSR = (VALUE/REFNUM)*fCLK_REF 13.5.1 Reference Clock The Reference Clock Selection (REFSEL) field in the Mode Register (MODE) selects the clock source for CLK_REF. The reference clock is enabled by writing a one to the Reference Clock Enable (REFCEN) bit in the Mode Register. This clock should have a known frequency. CLK_REF needs to be disabled before switching to another clock. The RCLKBUSY bit in the Status Register (SR) indicates whether the clock is busy or not. This bit is set when the MODE.REFCEN bit is written. To change CLK_REF: * Write a zero to the MODE.REFCEN bit to disable the clock, without changing the other bits/fields in the Mode Register. * Wait until the SR.RCLKBUSY bit reads as zero. * Change the MODE.REFSEL field. * Write a one to the MODE.REFCEN bit to enable the clock, without changing the other bits/fields in the Mode Register. * Wait until the SR.RCLKBUSY bit reads as zero. To enable CLK_REF: * Write the correct value to the MODE.REFSEL field. * Write a one to the MODE.REFCEN to enable the clock, without changing the other bits/fields in the Mode Register. * Wait until the SR.RCLKBUSY bit reads as zero. To disable CLK_REF: 208 32117A-10/2010 AT32UC3C * Write a zero to the MODE.REFCEN to disable he clock, without changing the other bits/fields in the Mode register. * Wait until the SR.RCLKBUSY bit reads as zero. 13.5.1.1 13.5.2 Cautionary note Note that if clock selected as source for CLK_REF is stopped during a measurement, this will not be detected by the FREQM. The BUSY bit in the STATUS register will never be cleared, and the DONE interrupt will never be triggered. If the clock selected as soruce for CLK_REF is stopped, it will not be possible to change the source for the reference clock as long as the selected source is not running. Measurement In the Mode Register the Clock Source Selection (CLKSEL) field selects CLK_MSR and the Number of Reference Clock Cycles (REFNUM) field selects the duration of the measurement. The duration is given in number of CLK_REF periodes. Writing a one to the START bit in the Control Register (CTRL) starts the measurement. The BUSY bit in SR is cleared when the measurement is done. The result of the measurement can be read from the Value Register (VALUE). The frequency of the measured clock CLK_MSR is then: fCLK_MSR = (VALUE/REFNUM)*fCLK_REF 13.5.3 Interrupts The FREQM has two interrupt sources: * DONE: A frequency measurement is done * RCLKRDY: The reference clock is ready These will generate an interrupt request if the corresponding bit in the Interrupt Mask Register (IMR) is set. The interrupt sources are ORed together to form one interrupt request. The FREQM will generate an interrupt request if at least one of the bits in the Interrupt Mask Register (IMR) is set. Bits in IMR are set by writing a one to the corresponding bit in the Interrupt Enable Register (IER) and cleared by writing a one to this bit in the Interrupt Disable Register (IDR). The interrupt request remains active until the corresponding bit in the Interrupt Status Register (ISR) is cleared by writing a one to this bit in the Interrupt Clear Register (ICR). Because all the interrupt sources are ORed together, the interrupt request from the FREQM will remain active until all the bits in ISR are cleared. 209 32117A-10/2010 AT32UC3C 13.6 User Interface Table 13-1. Note: FREQM Register Memory Map Offset Register Register Name Access Reset 0x000 Control Register CTRL Write-only 0x00000000 0x004 Mode Register MODE Read/Write 0x00000000 0x008 Status Register STATUS Read-only 0x00000000 0x00C Value Register VALUE Read-only 0x00000000 0x010 Interrupt Enable Register IER Write-only 0x00000000 0x014 Interrupt Disable Register IDR Write-only 0x00000000 0x018 Interrupt Mask Register IMR Read-only 0x00000000 0x01C Interrupt Status Register ISR Read-only 0x00000000 0x020 Interrupt Clear Register ICR Write-only 0x00000000 0x3FC Version Register VERSION Read-only -(1) 1. The reset value for this register is device specific. Please refer to the Module Configuration section at the end of this chapter. 210 32117A-10/2010 AT32UC3C 13.6.1 Name: Control Register CTRL Access Type: Write-only Offset: 0x000 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 - - - - - - - - 7 6 5 4 3 2 1 0 - - - - - - - START * START Writing a zero to this bit has no effect. Writing a one to this bit will start a measurement. 211 32117A-10/2010 AT32UC3C 13.6.2 Name: Mode Register MODE Access Type: Read/Write Offset: 0x004 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 REFCEN - - - - - - - 23 22 21 20 19 18 17 16 - - - 15 14 13 CLKSEL 12 11 10 9 8 2 1 0 REFNUM 7 6 5 4 3 - - - - - REFSEL * REFCEN: Reference Clock Enable 0: The reference clock is disabled 1: The reference clock is enabled * CLKSEL: Clock Source Selection Selects the source for CLK_MSR. See table in Module Configuration chapter for details. * REFNUM: Number of Reference Clock Cycles Selects the duration of a measurement, given in number of CLK_REF cycles. * REFSEL: Reference Clock Selection Selects the source for CLK_REF. See table in Module Configuration chapter for details. 212 32117A-10/2010 AT32UC3C 13.6.3 Status Register Name: STATUS Access Type: Read-only Offset: 0x008 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 - - - - - - - - 7 6 5 4 3 2 1 0 - - - - - - RCLKBUSY BUSY * RCLKBUSY: FREQM Reference Clock Status 0: The FREQM ref clk is ready, so a measurement can start. 1: The FREQM ref clk is not ready, so a measurement should not be started. * BUSY: FREQM Status 0: The Frequency Meter is idle. 1: Frequency measurement is on-going. 213 32117A-10/2010 AT32UC3C 13.6.4 Value Register Name: VALUE Access Type: Read-only Offset: 0x00C Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 11 10 9 8 3 2 1 0 VALUE[23:16] 15 14 13 12 VALUE[15:8] 7 6 5 4 VALUE[7:0] * VALUE: Result from measurement. 214 32117A-10/2010 AT32UC3C 13.6.5 Interrupt Enable Register Name: IER Access Type: Write-only Offset: 0x010 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 - - - - - - - - 7 6 5 4 3 2 1 0 - - - - - - RCLKRDY DONE Writing a zero to a bit in this register has no effect. Writing a one to a bit in this register will set the corresponding bit in IMR. 215 32117A-10/2010 AT32UC3C 13.6.6 Interrupt Disable Register Name: IDR Access Type: Write-only Offset: 0x014 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 - - - - - - - - 7 6 5 4 3 2 1 0 - - - - - - RCLKRDY DONE Writing a zero to a bit in this register has no effect. Writing a one to a bit in this register will clear the corresponding bit in IMR. 216 32117A-10/2010 AT32UC3C 13.6.7 Interrupt Mask Register Name: IMR Access Type: Read-only Offset: 0x018 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 - - - - - - - - 7 6 5 4 3 2 1 0 - - - - - - RCLKRDY DONE 0: The corresponding interrupt is disabled. 1: The corresponding interrupt is enabled. A bit in this register is cleared when the corresponding bit in IDR is written to one. A bit in this register is set when the corresponding bit in IER is written to one. 217 32117A-10/2010 AT32UC3C 13.6.8 Interrupt Status Register Name: ISR Access Type: Read-only Offset: 0x01C Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 - - - - - - - - 7 6 5 4 3 2 1 0 - - - - - - RCLKRDY DONE 0: The corresponding interrupt is cleared. 1: The corresponding interrupt is pending. A bit in this register is set when the corresponding bit in STATUS has a one to zero transition. A bit in this register is cleared when the corresponding bit in ICR is written to one. 218 32117A-10/2010 AT32UC3C 13.6.9 Interrupt Clear Register Name: ICR Access Type: Write-only Offset: 0x020 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 - - - - - - - - 7 6 5 4 3 2 1 0 - - - - - - RCLKRDY DONE Writing a zero to a bit in this register has no effect. Writing a one to a bit in this register will clear the corresponding bit in ISR and the corresponding interrupt request. 219 32117A-10/2010 AT32UC3C 13.6.10 Name: Version Register VERSION Access Type: Read-only Offset: 0x3FC Reset Value: - 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - 15 14 13 12 9 8 - - - - 7 6 5 4 VARIANT 11 10 VERSION[11:8] 3 2 1 0 VERSION[7:0] * VARIANT: Variant number Reserved. No functionality associated. * VERSION: Version number Version number of the module. No functionality associated. 220 32117A-10/2010 AT32UC3C 13.7 Module Configuration The specific configuration for each FREQM instance is listed in the following tables. The module bus clocks listed here are connected to the system bus clocks. Please refer to the Power Manager chapter for details. Table 13-2. Module Clock Name Module Name FREQM Table 13-3. Clock Name Description CLK_FREQM Peripheral Bus clock from the PBA clock domain CLK_MSR Measured clock CLK_REF Reference clock Register Reset Values Register Reset Value VERSION 0x00000310 Table 13-4. Clock Sources for CLK_MSR CLKS EL Clock/Oscillator Description 0 CLK_CPU The clock the CPU runs on 1 CLK_HSB High Speed Bus clock 2 CLK_PBA Peripheral Bus A clock 3 CLK_PBB Peripheral Bus B clock 4 CLK_PBC Peripheral Bus C clock 5 OSC0 Output clock from Oscillator 0 6 OSC1 Output clock from Oscillator 1 7 OSC32K Output clock from OSC32K 8 RCSYS Output clock from RCSYS Oscillator 9 RC8M Output clock from 8MHz / 1MHz RC Oscillator 13-24 GCLK0-11 Generic clock 0 through 11 25 RC120M Output clock from RC120M 26-31 Reserved Table 13-5. Clock Sources for CLK_REF REFSEL Clock/Oscillator Description 0 RCSYS System 115 KHz RC oscillator clock 1 OSC32K Output clock from OSC32K 2 OSC0 Output clock from Oscillator 0 221 32117A-10/2010 AT32UC3C Table 13-5. Clock Sources for CLK_REF REFSEL Clock/Oscillator Description 3 OSC1 Output clock from Oscillator 1 4 RC8M Output clock from 8MHz / 1MHz RC Oscillator 5 GCLK9 Generic Clock 9 6-7 Reserved 222 32117A-10/2010 AT32UC3C 14. Peripheral Event Controller (PEVC) Rev: 1.0.0.0 14.1 Features * * * * 14.2 Direct peripheral to peripheral communication system Allows peripherals to receive, react to, and send peripheral events without CPU intervention Cycle deterministic event communication Asynchronous interrupts allow advanced peripheral operation in low power sleep modes Overview Many peripheral modules can be configured to emit or respond to signals known as peripheral events. The exact condition to trigger a peripheral event, or the action taken upon receiving a peripheral event, is specific to each module. Peripherals that respond to events are called users and peripherals that emit events are called generators. A module may be both a generator and user. The peripheral event generators and users are interconnected by a network known as the Peripheral Event System. The Peripheral Event Controller (PEVC) controls the interconnection parameters, such as generator-to-user multiplexing and peripheral event enable/disable. The Peripheral Event System allows low latency peripheral-to-peripheral signalling without CPU intervention, and without consuming system resources such as bus or RAM bandwidth. This offloads the CPU and system resources compared to a traditional interrupt-based software driven system. Figure 14-1. Peripheral Event System Overview Generator Generator User Peripheral Event System Generator/ User 223 32117A-10/2010 AT32UC3C 14.3 Block Diagram The main building blocks of the PEVC are: * Event Shapers (EVS): Instantiated for some generators, in case filtering and/or rising/falling edge detection is needed prior to peripheral event propagation * Channels: One channel per user, to propagate events and follow-up the user status To help distinguish the different signalling stages, these naming conventions are used: * Generators generate events * PEVC multiplexes these incoming events * PEVC outputs Triggers to users Figure 14-2. PEVC Block Diagram PEVC Generator 0 EVT0 EVS 0 Channel 0 TRIG0 User 0 RDY0 Generator ... EVT... EVS ... Channel ... Generator ... EVT... Generator ... EVT... TRIG... User ... RDY... Channel n TRIGn User n RDYn Generator m SEV CHMX EVTm RCSYS CLK_PEVC The maximum number of generators, Event Shapers, channels, and users supported by the Peripheral Event Controller is 64. Please refer to the Module Configuration section at the end of this chapter for the device-specific configuration. 224 32117A-10/2010 AT32UC3C 14.4 I/O Lines Description Table 14-1. 14.5 I/O Lines Description Pin Name Pin Description Type PAD_EVT[n] External Event Inputs Input Product Dependencies In order to use this module, other parts of the system must be configured correctly, as described below. 14.5.1 I/O Lines Multiplexed I/O lines can be used as event generators. To generate a peripheral event from an external source the source pin must be configured as an input pin by the I/O Controller. It is also possible to trigger a peripheral event by driving these pins from registers in the I/O Controller, or another peripheral output connected to the same pin. 14.5.2 Power Management If the CPU enters a sleep mode that disables clocks used by the PEVC, the PEVC will stop functioning and resume operation after the system wakes up from sleep mode. Peripheral events do not require CPU intervention, and are therefore available in sleep modes where the CPU sleeps. 14.5.3 Clocks The PEVC has two bus clocks connected: One Peripheral Bus clock (CLK_PEVC) and the system RC oscillator clock (CLK_RCSYS). These clocks are generated by the Power Manager. Both clocks are enabled at reset, and can be disabled by writing to the Power Manager. CLK_RCSYS is used for glitch filtering. 14.5.4 Interrupts PEVC can generate an interrupt request in case of trigger generation or trigger overrun. The PEVC interrupt request lines are connected to the interrupt controller. Using the PEVC interrupts requires the interrupt controller to be programmed first. 14.5.5 Debug Operation PEVC is frozen during debug operation, unless the Run In Debug bit in the Development Control Register is set and the bit corresponding to the PEVC is set in the Peripheral Debug Register (PDBG). Please refer to the On-Chip Debug chapter in the AVR32UC Technical Reference Manual, and the OCD Module Configuration section, for details. 225 32117A-10/2010 AT32UC3C 14.6 Functional Description 14.6.1 PEVC Channel Operation PEVC routes incoming events to users by means of one channel per user. Channels operate in parallel, allowing multiple users to listen to the same generator. 14.6.1.1 Channel Setup The Channel Multiplexer Register (CHMXn) is written to allocate a generator to a given channel. The Event Multiplexer field (EVMX) selects between the different generators, while the Software Event Multiplexer bit (SMX) selects Software Events. The channel is then enabled by writing a one to the appropriate bit in the Channel Enable Register (CHER). It is disabled by writing a one to the appropriate bit in the Channel Disable Register (CHDR). To safely program a channel, user software must: * disable the channel by writing a one to CHDR * program CHMXn * enable the channel by writing a one to CHER 14.6.1.2 Channel Operation When the channel is enabled, the user signals its busy/ready state to the channel, to determine how an incoming event will be handled: * If the user is ready, an incoming event is forwarded. The corresponding Trigger Status Register (TRISR) flag is set allowing an interrupt to be generated for tracking PEVC operations. * If the user is busy (because of a previous event, or for some other cause), the new event is not forwarded. The corresponding Overrun Status Register (OVSR) flag is set allowing an interrupt to be generated. The Busy Register (BUSY) is used to determine the current activity of a channel/user. A busy status has one of two causes: * A peripheral event is being relayed by the channel and handled by the user, * No event relayed, but user is not ready (e.g. not initialized, or handling some other request). 14.6.1.3 Software Event A Software Event can be initiated by software writing to the Software Event Register (SEV). This is intended for application debugging. The channel must first be programmed by writing a one to the Software Event Multiplexer bit (SMX) of CHMXn. Writing a one to the appropriate bit of SEV will then trigger a Software Event on the channel. 226 32117A-10/2010 AT32UC3C 14.6.2 Event Shaper (EVS) Operation PEVC contains Event Shapers (EVS) for certain types of generators: * Asynchronous generators and/or external input * General-purpose waveforms like timer outputs or Generic Clocks Each Event Shaper is responsible of shaping one input, prior to going through a PEVC channel: * Synchronize asynchronous external inputs * Apply any additional glich-filtering * Detect rise, fall, or both edges of the incoming signal 14.6.2.1 Input Glitch Filter (IGF) Input Glitch Filtering can be turned on or off by writing to the Input Glitch Filter (IGF) field of the corresponding Event Shaper Register (EVS). When IGF is on, the incoming event is sampled periodically. The sampling clock is divided from CLK_RCSYS by the value of the Input Glitch Filter Divider Register (IGFDR). IGF will filter out spikes and propagate only incoming events that respect one of the following two conditions : * rise event : 2 samples low, followed by 0+ changes, followed by 2 samples high * fall event : 2 samples high, followed by 0+ changes, followed by 2 samples low Both CLK_RCSYS and CLK_PEVC must be enabled to use Input Glitch Filtering. 14.6.3 Event Propagation Latency Once a channel is setup, incoming peripheral events are relayed by hardware. Event progation latency is therefore cycle deterministic. However, its value depends on the exact settings that apply to a given channel. When the channel multiplexer CHMXn.EVMX selects a generator without Event Shaper, event propagation latency is 0 cycle. Software event is a particular case of 0 cycle propagation. When the channel multiplexer CHMXn.EVMX selects a generator with Event Shaper, event propagation latency depends on Input Glitch Filter setting EVSm.IGF : * IGF off : event propagation latency is lesser or equal to 2 CLK_PEVC cycles * IGF on : event propagation latency is lesser or equal to 3 * 2IGFDR+1 * CLK_RCSYS cycles Table 14-2. Event Propagation Latency Generator CHMXn.EVMX Input Glitch Filter EVSm.IGF Latency Clock Generator without Event Shaper - 0 - Software event - 0 - Generator with Event Shaper Off 2 Generator with Event Shaper On 3*2 CLK_PEVC IGFDR+1 CLK_RCSYS Please refer to the Module Configuration section at the end of this chapter for the list of generators implementing Event Shapers. 227 32117A-10/2010 AT32UC3C 14.7 User Interface PEVC Register Memory Map Offset Register Register Name Access Reset 0x000 Version VERSION Read-only -(1) 0x004 Parameter PARAMETER Read-only -(1) 0x008 Input Glitch Filter Divider Register IGFDR Read/Write 0x00000000 0x010 - 0x014 Channel Status Register CHSRi(2) Read-only 0x00000000 0x020 - 0x024 Channel Enable Register CHERi(2) Write-only - Channel Disable Register (2) Write-only - Write-only - 0x030 - 0x034 CHDRi (2) 0x040 - 0x044 Software Event 0x050 - 0x054 Channel / User Busy BUSYi(2) Read-only -(1) 0x060 - 0x064 Trigger Status Register TRSRi(2) 0x070 - 0x074 Trigger Status Clear Register SEVi Read-only 0x00000000 (2) Write-only - (2) TRIMRi Read-only 0x00000000 TRSCRi 0x080 - 0x084 Trigger Interrupt Mask Register 0x090 - 0x094 Trigger Interrupt Mask Enable Register TRIERi(2) Write-only - Trigger Interrupt Mask Disable Register (2) Write-only - (2) 0x0A0 - 0x0A4 0x0B0 - 0x0B4 Overrun Status Register TRIDRi OVSRi 0x00000000 Write-only - 0x0C0 - 0x0C4 Overrun Status Clear Register 0x0D0 - 0x0D4 Overrun Interrupt Mask Register OVIMRi(2) Read-only 0x00000000 0x0E0 - 0x0E4 Overrun Interrupt Mask Enable Register OVIERi(2) Write-only - 0x0F0 - 0x0F4 Overrun Interrupt Mask Disable Register (2) Write-only - 0x100 Channel Multiplexer 0 CHMX0 Read/Write 0x00000000 0x100 + n*0x004 Channel Multiplexer n CHMXn Read/Write 0x00000000 0x1FC Channel Multiplexer 63 CHMX63 Read/Write 0x00000000 0x200 Event Shaper 0 EVS0 Read/Write 0x00000000 0x200 + m*0x004 Event Shaper m EVSm Read/Write 0x00000000 0x2FC Event Shaper 63 EVS63 Read/Write 0x00000000 Notes: OVSCRi Read-only (2) OVIDRi 1. The reset values for these registers are device specific. Please refer to the Module Configuration section at the end of this chapter. 2. i={0,1}, where i=0 contains the lowest 32 channels, and i=1 contains the highest 32 channels. The lowest address contains register 0, the highest address contains register 1. Register 1 is only implemented if the device has more than 32 channels implemented. Please refer to the Module Configuration section at the end of this chapter for details. 228 32117A-10/2010 AT32UC3C 14.7.1 Name: Version Register VERSION Access Type: Read-only Offset: 0x000 Reset Value: - 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - 15 14 13 12 9 8 - - - - 7 6 5 4 VARIANT 11 10 VERSION[11:8] 3 2 1 0 VERSION[7:0] * VARIANT: Variant Number Variant number of the module. No functionality associated. * VERSION: Version Number Version number of the module. No functionality associated. 229 32117A-10/2010 AT32UC3C 14.7.2 Name: Parameter Register PARAMETER Access Type: Read-only Offset: 0x004 Reset Value: - 31 30 29 28 27 26 25 24 19 18 17 16 11 10 9 8 3 2 1 0 TRIGOUT 23 22 21 20 EVMX 15 14 13 12 EVS 7 6 5 4 EVIN * TRIGOUT: Number of Trigger Outputs / Channels / Users Number of trigger outputs / channels implemented. No functionality associated. * EVMX: Number of Bits to control EVMX field in CHMXn Registers Number of Multiplexers control bits, derived from EVIN. No functionality associated. * EVS: Number of Event Shapers Number of Event Shapers implemented. No functionality associated. * EVIN: Number of Event Inputs / Generators Number of event inputs. No functionality associated. 230 32117A-10/2010 AT32UC3C 14.7.3 Name: Input Glitch Filter Divider Register IGFDR Access Type: Read/Write Offset: 0x008 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 - - - - - - - - 7 6 5 4 3 2 1 0 - - - - IGFDR * IGFDR: Input Glitch Filter Divider Selects prescaler division ratio for the system RC clock used for glitch filtering. IGFDR Division Ratio 0x0 2 0x1 4 0x2 8 0xn 2n+1 0xF 65536 231 32117A-10/2010 AT32UC3C 14.7.4 Name: Channel Status Register CHSR0 - CHSR1 Access Type: Read-only Offset: 0x010 - 0x014 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 19 18 17 16 11 10 9 8 3 2 1 0 CHS 23 22 21 20 CHS 15 14 13 12 CHS 7 6 5 4 CHS * CHS: Channel Status 0: The corresponding channel is disabled. 1: The corresponding channel is enabled. This bit is cleared when the corresponding bit in CHDR is written to one. This bit is set when the corresponding bit in CHER is written to one. Note: Channels 0 to 31 are controlled by CHSR0. Channels 32 to 63 are controlled by CHSR1. Please refer to the Module Configuration section at the end of this Chapter for device-specific channel mapping information. 232 32117A-10/2010 AT32UC3C 14.7.5 Name: Channel Enable Register CHER0 - CHER1 Access Type: Write-only Offset: 0x020 - 0x024 Reset Value: - 31 30 29 28 27 26 25 24 19 18 17 16 11 10 9 8 3 2 1 0 CHE 23 22 21 20 CHE 15 14 13 12 CHE 7 6 5 4 CHE * CHE: Channel Enable Writing a zero to this bit has no effect. Writing a one to this bit will set the corresponding bit in CHSR. Note: Channels 0 to 31 are controlled by CHER0. Channels 32 to 63 are controlled by CHER1. Please refer to the Module Configuration section at the end of this Chapter for device-specific channel mapping information. 233 32117A-10/2010 AT32UC3C 14.7.6 Name: Channel Disable Register CHDR0 - CHDR1 Access Type: Write-only Offset: 0x030 - 0x034 Reset Value: - 31 30 29 28 27 26 25 24 19 18 17 16 11 10 9 8 3 2 1 0 CHD 23 22 21 20 CHD 15 14 13 12 CHD 7 6 5 4 CHD * CHD: Channel Disable Writing a zero to this bit has no effect. Writing a one to this bit will clear the corresponding bit in CHSR. Note: Channels 0 to 31 are controlled by CHER0. Channels 32 to 63 are controlled by CHER1. Please refer to the Module Configuration section at the end of this Chapter for device-specific channel mapping information. 234 32117A-10/2010 AT32UC3C 14.7.7 Name: Software Event Register SEV0 - SEV1 Access Type: Write-only Offset: 0x040 - 0x044 Reset Value: - 31 30 29 28 27 26 25 24 19 18 17 16 11 10 9 8 3 2 1 0 SEV 23 22 21 20 SEV 15 14 13 12 SEV 7 6 5 4 SEV * SEV: Software Event Writing a zero to this bit has no effect. Writing a one to this bit will trigger a Software Event for the corresponding channel. Note: Channels 0 to 31 are controlled by SEV0. Channels 32 to 63 are controlled by SEV1. Please refer to the Module Configuration section at the end of this Chapter for device-specific channel mapping information. 235 32117A-10/2010 AT32UC3C 14.7.8 Name: Channel / User Busy BUSY0 - BUSY1 Access Type: Read-only Offset: 0x050 - 0x054 Reset Value: - 31 30 29 28 27 26 25 24 19 18 17 16 11 10 9 8 3 2 1 0 BUSY 23 22 21 20 BUSY 15 14 13 12 BUSY 7 6 5 4 BUSY * BUSY: Channel Status 0: The corresponding channel and user are idle. 1: The corresponding channel and user are busy. Note: Channels 0 to 31 are controlled by BUSY0. Channels 32 to 63 are controlled by BUSY1. Please refer to the Module Configuration section at the end of this Chapter for device-specific channel mapping information. 236 32117A-10/2010 AT32UC3C 14.7.9 Name: Trigger Status Register TRSR0 - TRSR1 Access Type: Read-only Offset: 0x060 - 0x064 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 19 18 17 16 11 10 9 8 3 2 1 0 TRS 23 22 21 20 TRS 15 14 13 12 TRS 7 6 5 4 TRS * TRS: Trigger Interrupt Status 0: An interrupt event has not occurred 1: An interrupt event has occurred This bit is cleared by writing a one to the corresponding bit in TRSCR. Note: Channels 0 to 31 are controlled by TRSR0. Channels 32 to 63 are controlled by TRSR1. Please refer to the Module Configuration section at the end of this Chapter for device-specific channel mapping information. 237 32117A-10/2010 AT32UC3C 14.7.10 Name: Trigger Status Clear Register TRSCR0 - TRSCR1 Access Type: Write-only Offset: 0x070 - 0x074 Reset Value: - 31 30 29 28 27 26 25 24 19 18 17 16 11 10 9 8 3 2 1 0 TRSC 23 22 21 20 TRSC 15 14 13 12 TRSC 7 6 5 4 TRSC * TRSC: Trigger Interrupt Status Clear Writing a zero to this bit has no effect. Writing a one to this bit will clear the corresponding bit in TRSR. Note: Channels 0 to 31 are controlled by TRSCR0. Channels 32 to 63 are controlled by TRSCR1. Please refer to the Module Configuration section at the end of this Chapter for device-specific channel mapping information. 238 32117A-10/2010 AT32UC3C 14.7.11 Name: Trigger Interrupt Mask Register TRIMR0 - TRIMR1 Access Type: Read-only Offset: 0x080 - 0x084 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 19 18 17 16 11 10 9 8 3 2 1 0 TRIM 23 22 21 20 TRIM 15 14 13 12 TRIM 7 6 5 4 TRIM * TRIM: Trigger Interrupt Mask 0: The corresponding interrupt is disabled. 1: The corresponding interrupt is enabled. This bit is cleared when the corresponding bit in TRIDR is written to one. This bit is set when the corresponding bit in TRIER is written to one. Note: Channels 0 to 31 are controlled by TRIMR0. Channels 32 to 63 are controlled by TRIMR1. Please refer to the Module Configuration section at the end of this Chapter for device-specific channel mapping information. 239 32117A-10/2010 AT32UC3C 14.7.12 Name: Trigger Interrupt Enable Register TRIER0 - TRIER1 Access Type: Write-only Offset: 0x090 - 0x094 Reset Value: - 31 30 29 28 27 26 25 24 19 18 17 16 11 10 9 8 3 2 1 0 TRIE 23 22 21 20 TRIE 15 14 13 12 TRIE 7 6 5 4 TRIE * TRIE: Trigger Interrupt Enable Writing a zero to this bit has no effect. Writing a one to this bit will set the corresponding bit in TRIMR. Note: Channels 0 to 31 are controlled by TRIER0. Channels 32 to 63 are controlled by TRIER1. Please refer to the Module Configuration section at the end of this Chapter for device-specific channel mapping information. 240 32117A-10/2010 AT32UC3C 14.7.13 Name: Trigger Interrupt Disable Register TRIDR0 - TRIDR1 Access Type: Write-only Offset: 0x0A0 - 0x0A4 Reset Value: - 31 30 29 28 27 26 25 24 19 18 17 16 11 10 9 8 3 2 1 0 TRID 23 22 21 20 TRID 15 14 13 12 TRID 7 6 5 4 TRID * TRID: Trigger Interrupt Disable Writing a zero to this bit has no effect. Writing a one to this bit will clear the corresponding bit in IMR. Note: Channels 0 to 31 are controlled by TRIDR0. Channels 32 to 63 are controlled by TRIDR1. Please refer to the Module Configuration section at the end of this Chapter for device-specific channel mapping information. 241 32117A-10/2010 AT32UC3C 14.7.14 Name: Overrun Status Register OVSR0 - OVSR1 Access Type: Read-only Offset: 0x0B0 - 0x0B4 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 19 18 17 16 11 10 9 8 3 2 1 0 OVS 23 22 21 20 OVS 15 14 13 12 OVS 7 6 5 4 OVS * OVS: Overrun Interrupt Status 0: An interrupt event has not occurred 1: An interrupt event has occurred This bit is cleared by writing a one to the corresponding bit in OVSCR. Note: Channels 0 to 31 are controlled by OVSR0. Channels 32 to 63 are controlled by OVSR1. Please refer to the Module Configuration section at the end of this Chapter for device-specific channel mapping information. 242 32117A-10/2010 AT32UC3C 14.7.15 Name: Overrun Status Clear Register OVSCR0 - OVSCR1 Access Type: Write-only Offset: 0x0C0 - 0x0C4 Reset Value: - 31 30 29 28 27 26 25 24 19 18 17 16 11 10 9 8 3 2 1 0 OVSC 23 22 21 20 OVSC 15 14 13 12 OVSC 7 6 5 4 OVSC * OVSC: Overrun Interrupt Status Clear Writing a zero to this bit has no effect. Writing a one to this bit will clear the corresponding bit in OVSR. Note: Channels 0 to 31 are controlled by OVSCR0. Channels 32 to 63 are controlled by OVSCR1. Please refer to the Module Configuration section at the end of this Chapter for device-specific channel mapping information. 243 32117A-10/2010 AT32UC3C 14.7.16 Name: Overrun Interrupt Mask Register OVIMR0 - OVIMR1 Access Type: Read-only Offset: 0x0D0 - 0x0D4 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 19 18 17 16 11 10 9 8 3 2 1 0 OVIM 23 22 21 20 OVIM 15 14 13 12 OVIM 7 6 5 4 OVIM * OVIM: Overrun Interrupt Mask 0: The corresponding interrupt is disabled. 1: The corresponding interrupt is enabled. This bit is cleared when the corresponding bit in OVIDR is written to one. This bit is set when the corresponding bit in OVIER is written to one. Note: Channels 0 to 31 are controlled by OVIMR0. Channels 32 to 63 are controlled by OVIMR1. Please refer to the Module Configuration section at the end of this Chapter for device-specific channel mapping information. 244 32117A-10/2010 AT32UC3C 14.7.17 Name: Overrun Interrupt Enable Register OVIER0 - OVIER1 Access Type: Write-only Offset: 0x0E0 - 0x0E4 Reset Value: - 31 30 29 28 27 26 25 24 19 18 17 16 11 10 9 8 3 2 1 0 OVIE 23 22 21 20 OVIE 15 14 13 12 OVIE 7 6 5 4 OVIE * OVIE: Overrun Interrupt Enable Writing a zero to this bit has no effect. Writing a one to this bit will set the corresponding bit in OVIMR. Note: Channels 0 to 31 are controlled by OVIER0. Channels 32 to 63 are controlled by OVIER1. Please refer to the Module Configuration section at the end of this Chapter for device-specific channel mapping information. 245 32117A-10/2010 AT32UC3C 14.7.18 Name: Overrun Interrupt Disable Register OVIDR0 - OVIDR1 Access Type: Write-only Offset: 0x0F0 - 0x0F4 Reset Value: - 31 30 29 28 27 26 25 24 19 18 17 16 11 10 9 8 3 2 1 0 OVID 23 22 21 20 OVID 15 14 13 12 OVID 7 6 5 4 OVID * OVID: Overrun Interrupt Disable Writing a zero to this bit has no effect. Writing a one to this bit will clear the corresponding bit in IMR. Note: Channels 0 to 31 are controlled by OVIDR0. Channels 32 to 63 are controlled by OVIDR1. Please refer to the Module Configuration section at the end of this Chapter for device-specific channel mapping information. 246 32117A-10/2010 AT32UC3C 14.7.19 Name: Channel Multiplexer Register CHMXn Access Type: Read/Write Offset: 0x100 + n*0x004 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 - - - - - - - SMX 7 6 5 4 3 2 1 0 - - EVMX * EVMX: Event Multiplexer Select input event / generator. * SMX: Software Event Multiplexer 0: The Software Event is not selected. Event / generator is selected by EVMX. 1: The Software Event is selected. EVMX is not considered. EVMX SMX Channel Input 0x00 0 EVT0 0x01 0 EVT1 0xm 0 EVTm > TRIGOUT 0 None Any 1 Software Event 247 32117A-10/2010 AT32UC3C 14.7.20 Name: Event Shaper Register EVSm Access Type: Read/Write Offset: 0x200 + m*0x004 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 - - - - - - - - 7 6 5 4 3 2 1 0 - - - - - IGF EVF EVR * EVR: Event Rise 0: No event detection on rising edge. 1: Event detection on rising edge. * EVF: Event Fall 0: No event detection on falling edge. 1: Event detection on falling edge. * IGF: Input Glitch Filter 0: Input glitch filter is off. 1: Input glitch filter is on. 248 32117A-10/2010 AT32UC3C 14.8 Module Configuration The specific configuration for each PEVC instance is listed in the following tables. The module bus clocks listed here are connected to the system bus clocks. Refer to the Power Manager chapter for details. Table 14-3. Module Configuration Feature Parameter PEVC Number of Generators EVIN 34 Number of Event Shapers EVS 24 Number of Channels / Users TRIGOUT 22 Table 14-4. Module Clock Name Module name Clock name Description PEVC CLK_PEVC HSB clock Table 14-5. Register Reset Values Register Reset Value BUSY0 0x0000FFFF VERSION 0x00000100 PARAMETER Refer to Table 14-3 The BUSY0[21:16] field will always be read as 0x3F. The PEVC routes events from event generator to trigger an action in the event user. The following tables defines the corresponding input event generator in EVMx registers and if an event shaper is implemented for this generator. Table 14-6. PEVC event numbers Event Number (EVMx) Event Generator - Event source Event Shaper [15:0] PAD_EVT[15:0] - change on input pins Yes 16 the generic clock GCLK7 Yes 17 the generic clock GCLK8 Yes 18 TC0 - A0 rising edge Yes 19 TC0 - A1 rising edge Yes 20 TC0 - A2 rising edge Yes 21 TC0 - B0 rising edge Yes 22 TC0 - B1 rising edge Yes 23 TC0 - B2 rising edge Yes 24 ACIFA0 - event 0 25 ACIFA0 - event 1 249 32117A-10/2010 AT32UC3C Table 14-6. PEVC event numbers Event Number (EVMx) Event Generator - Event source 26 ACIFA1 - event 0 27 ACIFA1 - event 1 28 AST - alarm event 0 29 AST - period event 0 30 PWM - compare match on event 0 31 PWM - compare match on event 1 32 QDEC0 - compare match 33 QDEC1 - compare match Event Shaper 14.9 The following tables defines the triggered action for each PEVC channel. Table 14-7. PEVC channel channel Number Event User - Triggered Event 0 ADCIFA - sequencer 0 start of conversion 1 ADCIFA - sequencer 1 start of conversion 2 DACIFB0 - start of conversion chA 3 DACIFB0 - start of conversion chB 4 DACIFB1 - start of conversion chA 5 DACIFB1 - start of conversion chB 6 PDCA - start of transfer channel 0 7 PDCA - start of transfer channel 1 8 PWM - fault input 0 9 PWM - fault input 1 10 QDEC0 - capture 11 QDEC0 - toggle direction of counting 12 QDEC0- trigger 13 QDEC1 - capture 14 QDEC1 - toggle direction of counting 15 QDEC1- trigger 16 TC0 - input capture A0 17 TC0 - input capture A1 18 TC0 - input capture A2 19 TC0 - input capture B0 20 TC0 - input capture B1 21 TC0 - input capture B2 250 32117A-10/2010 AT32UC3C 15. Flash Controller (FLASHC) Rev: 3.0.2.2 15.1 Features * Controls flash block with dual read ports allowing staggered reads. * Supports 0 and 1 wait state bus access. * Allows interleaved burst reads for systems with one wait state, outputting one 32-bit word per clock cycle. * 32-bit HSB interface for reads from flash array and writes to page buffer. * 32-bit PB interface for issuing commands to and configuration of the controller. * 16 lock bits, each protecting a region consisting of (total number of pages in the flash block / 16) * * * * * * 15.2 pages. Regions can be individually protected or unprotected. Additional protection of the Boot Loader pages. Supports reads and writes of general-purpose NVM bits. Supports reads and writes of additional NVM pages. Supports device protection through a security bit. Dedicated command for chip-erase, first erasing all on-chip volatile memories before erasing flash and clearing security bit. Overview The Flash Controller (FLASHC) interfaces the on-chip flash memory with the 32-bit internal HSB bus. The controller manages the reading, writing, erasing, locking, and unlocking sequences. 15.3 Product Dependencies In order to use this module, other parts of the system must be configured correctly, as described below. 15.3.1 Power Management If the CPU enters a sleep mode that disables clocks used by the FLASHC, the FLASHC will stop functioning and resume operation after the system wakes up from sleep mode. 15.3.2 Clocks The FLASHC has two bus clocks connected: One High Speed Bus clock (CLK_FLASHC_HSB) and one Peripheral Bus clock (CLK_FLASHC_PB). These clocks are generated by the Power Manager. Both clocks are enabled at reset, and can be disabled by writing to the Power Manager. The user has to ensure that CLK_FLASHC_HSB is not turned off before reading the flash or writing the pagebuffer and that CLK_FLASHC_PB is not turned off before accessing the FLASHC configuration and control registers. Failing to do so may deadlock the bus. 15.3.3 Interrupt The FLASHC interrupt request lines are connected to the interrupt controller. Using the FLASHC interrupts requires the interrupt controller to be programmed first. 251 32117A-10/2010 AT32UC3C 15.3.4 15.4 15.4.1 Debug Operation When an external debugger forces the CPU into debug mode, the FLASHC continues normal operation. If the FLASHC 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. Functional description Bus Interfaces The FLASHC has two bus interfaces, one High-Speed Bus (HSB) interface for reads from the flash memory and writes to the page buffer, and one Peripheral Bus (PB) interface for issuing commands and reading status from the controller. 15.4.2 Memory Organization The flash memory is divided into a set of pages. A page is the basic unit addressed when programming the flash. A page consists of several words. The pages are grouped into 16 regions of equal size. Each of these regions can be locked by a dedicated fuse bit, protecting it from accidental modification. * p pages (FLASH_P) * 512 bytes in each page and in the page buffer (FLASH_W) * pw bytes in total (FLASH_PW) * f general-purpose fuse bits (FLASH_F), used as region lock bits and for other device-specific purposes * 1 security fuse bit * 1 Factory Page * 1 User Page 15.4.3 User Page The User page is an additional page, outside the regular flash array, that can be used to store various data, such as calibration data and serial numbers. This page is not erased by regular chip erase. The User page can only be written and erased by a special set of commands. Read accesses to the User page are performed just as any other read accesses to the flash. The address map of the User page is given in Figure 15-1. 15.4.4 Factory page The Factory page is an additional page, outside the regular flash array, that can be used to store various data, such as calibration data and serial numbers. This page is not erased by regular chip erase. Read accesses to the Factory page is performed just as any other read access to the flash. The address map of the Factory page is given in Figure 15-1. 15.4.5 Read Operations The on-chip flash memory is typically used for storing instructions to be executed by the CPU. The CPU will address instructions using the HSB bus, and the FLASHC will access the flash memory and return the addressed 32-bit word. In systems where the HSB clock period is slower than the access time of the flash memory, the FLASHC can operate in 0 wait state mode, and output one 32-bit word on the bus per clock cycle. If the clock frequency allows, the user should use 0 wait state mode, because this gives the highest performance as no stall cycles are encountered. 252 32117A-10/2010 AT32UC3C The FLASHC can also operate in systems where the HSB bus clock period is faster than the access speed of the flash memory. Wait state support and a read granularity of 64 bits ensure efficiency in such systems. Performance for systems with high clock frequency is increased since the flash internally is configured as two separate banks of 32 bits. Each bank has its own read port. In 0ws mode, only one of the two flash read ports is accessed. The other flash read port is idle. In 1ws mode, both flash read ports are active. One read port reading the addressed word, and the other reading the next sequential word. The programmer can select the wait states required by writing to the FWS field in the Flash Control Register (FCR). It is the responsibility of the programmer to select a number of wait states compatible with the clock frequency and timing characteristics of the flash memory. In 0ws mode, no wait states are encountered on any flash read operations. In 1 ws mode, one stall cycle is encountered on the first access in a single or burst transfer. If the clock frequency allows, the user should use 0ws mode, because this gives the lowest power consumption for low-frequency systems as only one flash read port is read. Using 1ws mode has a power/performance ratio approaching 0ws mode as the clock frequency approaches twice the max frequency of 0ws mode. Using two flash read ports use twice the power, but also give twice the performance. The Flash Controller address space is displayed in Figure 15-1. The memory space between address pw and the User page is reserved, and reading addresses in this space returns an undefined result. The User page is permanently mapped to an offset of 0x0080 0000 from the start address of the flash memory. The Factory page is permanently mapped to an offset of 0x0080 0200 from the start address of the flash memory. Table 15-1. User page Addresses Memory type Start address, byte sized Size Main array 0 pw words = 4pw bytes User 0x0080 0000 128 words = 512 bytes Factory Page 0x0080 0200 128 words = 512 bytes 253 32117A-10/2010 AT32UC3C Figure 15-1. Memory Map for the Flash Memories2 Offset from base address 0x0080 0200 Factory Page User Page REserved 0x0080 0000 Flash data array pw 0 Flash base address Flash with extra pages All addresses are byte addresses 15.4.6 High Speed Read Mode The flash provides a High Speed Read Mode, offering slightly higher flash read speed at the cost of higher power consumption. Two dedicated commands, High Speed Read Mode Enable (HSEN) and High Speed Read Mode Disable (HSDIS) control the speed mode. The High Speed Mode (HSMODE) in Flash Status Register (FSR) shows which mode the flash is in. After reset, the High Speed Mode is disabled, and must be manually enabled if the user wants to. Refer to the Electrical Characteristics chapter at the end of this datasheet for details on the maximum clock frequencies in Normal and High Speed Read Mode. 254 32117A-10/2010 AT32UC3C Figure 15-2. High Speed Mode Frequency 1 wait state 0 wait state Frequency limit for 0 wait state operation Speed mode h ig H al m or N 15.4.7 Quick Page Read A dedicated command, Quick Page Read (QPR), is provided to read all words in an addressed page. All bits in all words in this page are AND'ed together, returning a 1-bit result. This result is placed in the Quick Page Read Result (QPRR) bit in Flash Status Register (FSR). The QPR command is useful to check that a page is in an erased state. The QPR instruction is much faster than performing the erased-page check using a regular software subroutine. 15.4.8 Page Buffer Operations The flash memory has a write and erase granularity of one page; data are written and erased in chunks of one page. When programming a page, the user must first write the new data into the Page Buffer. The contents of the entire Page Buffer is copied into the desired page in flash memory when the user issues the Write Page command, See Section "15.5.1" on page 257. In order to program data into flash page Y, write the desired data to locations Y0 to 63 in the regular flash memory map. Writing to an address A in the flash memory map will not update the flash memory, but will instead update location A%64 in the page buffer. The PAGEN field in the Flash Command (FCMD) register will at the same time be updated with the value A/64. 255 32117A-10/2010 AT32UC3C Figure 15-3. Mapping from Page Buffer to Flash F la s h A ll lo c a tio n s a re w o rd lo c a tio n s P a g e B u ffe r 3 2 -b it d a ta 63 59 55 51 47 43 39 35 31 27 23 19 15 11 7 3 62 58 54 50 46 42 38 34 30 26 22 18 14 10 6 2 61 57 53 49 45 41 37 33 29 25 21 17 13 9 5 1 60 56 52 48 44 40 36 32 28 24 20 16 12 8 4 0 Y63 Y59 Y55 Y51 Y47 Y43 Y39 Y35 Y31 Y27 Y23 Y19 Y15 Y11 Y7 Y3 X63 X59 X55 X51 X47 X43 X39 X35 X31 X27 X23 X19 X15 X11 X7 X3 Y62 Y61 Y58 Y57 Y54 Y53 Y50 Y49 Y46 Y45 Y42 Y41 Y38 Y37 Y34 Y33 Page Y Y30 Y29 Y26 Y25 Y22 Y21 Y18 Y17 Y14 Y13 Y10 Y9 Y6 Y5 Y2 Y1 X62 X61 X58 X57 X54 X53 X50 X49 X46 X45 X42 X41 X38 X37 X34 X33 Page X X30 X29 X26 X25 X22 X21 X18 X17 X14 X13 X10 X9 X6 X5 X2 X1 Y60 Y56 Y52 Y48 Y44 Y40 Y36 Y32 Y28 Y24 Y20 Y16 Y12 Y8 Y4 Y0 X60 X56 X52 X48 X44 X40 X36 X32 X28 X24 X20 X16 X12 X8 X4 X0 The page buffer is word-addressable and should only be written with aligned word transfers, never with byte or halfword transfers. The page buffer can not be read. The page buffer is also used for writes to the User page. Page buffer write operations are performed with 4 wait states. Any accesses attempted to the FLASHC on the HSB bus during these cycles will be automatically stalled. Writing to the page buffer can only change page buffer bits from one to zero, i.e. writing 0xAAAAAAAA to a page buffer location that has the value 0x00000000 will not change the page buffer value. The only way to change a bit from zero to one is to erase the entire page buffer with the Clear Page Buffer command. The page buffer is not automatically reset after a page write. The programmer should do this manually by issuing the Clear Page Buffer flash command. This can be done after a page write, or before the page buffer is loaded with data to be stored to the flash page. 15.4.9 Writing Words to a Page that is not Completely Erased This can be used for EEPROM emulation, i.e. writes with granularity of one word instead of an entire page. Only words that are in an completely erased state (0xFFFFFFFF) can be changed. The procedure is as follows: 256 32117A-10/2010 AT32UC3C 1. Clear page buffer 2. Write to the page buffer the result of the logical bitwise AND operation between the contents of the flash page and the new data to write. Only bits that were in an erased state can be changed from the original page. 3. Write Page. 15.5 Flash Commands The FLASHC offers a command set to manage programming of the flash memory, locking and unlocking of regions, and full flash erasing. See Section 15.8.2 for a complete list of commands. To run a command, the field CMD of the Flash Command Register (FCMD) has to be written with the command number. As soon as the FCMD register is written, the FRDY bit is automatically cleared. Once the current command is complete, the FRDY bit is automatically set. If an interrupt has been enabled by writing a one to FCR.FRDY, the interrupt request line of the Flash Controller is activated. All flash commands except for Quick Page Read (QPR) will generate an interrupt request upon completion if FRDY is written to one. Any HSB bus transfers attempting to read flash memory when the FLASHC is busy executing a flash command will be stalled, and allowed to continue when the flash command is complete. After a command has been written to FCMD, the programming algorithm should wait until the command has been executed before attempting to read instructions or data from the flash or writing to the page buffer, as the flash will be busy. The waiting can be performed either by polling the Flash Status Register (FSR) or by waiting for the flash ready interrupt. The command written to FCMD is initiated on the first clock cycle where the HSB bus interface in FLASHC is IDLE. The user must make sure that the access pattern to the FLASHC HSB interface contains an IDLE cycle so that the command is allowed to start. Make sure that no bus masters such as DMA controllers are performing endless burst transfers from the flash. Also, make sure that the CPU does not perform endless burst transfers from flash. This is done by letting the CPU enter sleep mode after writing to FCMD, or by polling FSR for command completion. This polling will result in an access pattern with IDLE HSB cycles. All the commands are protected by the same keyword, which has to be written in the eight highest bits of the FCMD register. Writing FCMD with data that does not contain the correct key and/or with an invalid command has no effect on the flash memory; however, the PROGE bit is set in the Flash Status Register (FSR). This bit is automatically cleared by a read access to the FSR register. Writing a command to FCMD while another command is being executed has no effect on the flash memory; however, the PROGE bit is set in the Flash Status Register (FSR). This bit is automatically cleared by a read access to the FSR register. If the current command writes or erases a page in a locked region, or a page protected by the BOOTPROT fuses, the command has no effect on the flash memory; however, the LOCKE bit is set in the FSR register. This bit is automatically cleared by a read access to the FSR register. 15.5.1 Write/Erase Page Operation Flash technology requires that an erase must be done before programming. The entire flash can be erased by an Erase All command. Alternatively, pages can be individually erased by the Erase Page command. The User page can be written and erased using the mechanisms described in this chapter. 257 32117A-10/2010 AT32UC3C After programming, the page can be locked to prevent miscellaneous write or erase sequences. Locking is performed on a per-region basis, so locking a region locks all pages inside the region. Additional protection is provided for the lowermost address space of the flash. This address space is allocated for the Boot Loader, and is protected both by the lock bit(s) corresponding to this address space, and the BOOTPROT[2:0] fuses. Data to be written are stored in an internal buffer called page buffer. The page buffer contains w words. The page buffer wraps around within the internal memory area address space and appears to be repeated by the number of pages in it. Writing of 8-bit and 16-bit data to the page buffer is not allowed and may lead to unpredictable data corruption. Data must be written to the page buffer before the programming command is written to the Flash Command Register FCMD. The sequence is as follows: * Reset the page buffer with the Clear Page Buffer command. * Fill the page buffer with the desired contents as described in Section 15.4.8 on page 255. * Programming starts as soon as the programming key and the programming command are written to the Flash Command Register. The PAGEN field in the Flash Command Register (FCMD) must contain the address of the page to write. PAGEN is automatically updated when writing to the page buffer, but can also be written to directly. The FRDY bit in the Flash Status Register (FSR) is automatically cleared when the page write operation starts. * When programming is completed, the bit FRDY in the Flash Status Register (FSR) is set. If an interrupt was enabled by writing a one to FCR.FRDY, the interrupt line of the Flash Controller is set. Two errors can be detected in the FSR register after a programming sequence: * Programming Error: A bad keyword and/or an invalid command have been written in the FCMD register. * Lock Error: Can have two different causes: - The page to be programmed belongs to a locked region. A command must be executed to unlock the corresponding region before programming can start. - A bus master without secure status attempted to program a page requiring secure privileges. 15.5.2 Erase All Operation The entire memory is erased if the Erase All command (EA) is written to the Flash Command Register (FCMD). Erase All erases all bits in the flash array. The User page is not erased. All flash memory locations, the general-purpose fuse bits, and the security bit are erased (reset to 0xFF) after an Erase All. The EA command also ensures that all volatile memories, such as register file and RAMs, are erased before the security bit is erased. Erase All operation is allowed only if no regions are locked, and the BOOTPROT fuses are configured with a BOOTPROT region size of 0. Thus, if at least one region is locked, the bit LOCKE in FSR is set and the command is cancelled. If the bit LOCKE has been written to 1 in FCR, the interrupt request line is set. When the command is complete, the FRDY bit in the Flash Status Register (FSR) is set. If an interrupt has been enabled by writing a one to FCR.FRDY, the interrupt line of the Flash Controller is set. Two errors can be detected in the FSR register after issuing the command: 258 32117A-10/2010 AT32UC3C * Programming Error: A bad keyword and/or an invalid command have been written in the FCMD register. * Lock Error: At least one lock region is protected, or BOOTPROT is different from 0. The erase command has been aborted and no page has been erased. A "Unlock region containing given page" (UP) command must be executed to unlock any locked regions. 15.5.3 Region Lock Bits The flash memory has p pages, and these pages are grouped into 16 lock regions, each region containing p/16 pages. Each region has a dedicated lock bit preventing writing and erasing pages in the region. After production, the device may have some regions locked. These locked regions are reserved for a boot or default application. Locked regions can be unlocked to be erased and then programmed with another application or other data. To lock or unlock a region, the commands Lock Region Containing Page (LP) and Unlock Region Containing Page (UP) are provided. Writing one of these commands, together with the number of the page whose region should be locked/unlocked, performs the desired operation. One error can be detected in the FSR register after issuing the command: * Programming Error: A bad keyword and/or an invalid command have been written in the FCMD register. The lock bits are implemented using the lowest 16 general-purpose fuse bits. This means that lock bits can also be set/cleared using the commands for writing/erasing general-purpose fuse bits, see Section 15.6. The general-purpose bit being in an erased (1) state means that the region is unlocked. The lowermost pages in the Flash can additionally be protected by the BOOTPROT fuses, see Section 15.6. 15.6 General-purpose fuse bits The flash memory has a number of general-purpose fuse bits that the application programmer can use freely. The fuse bits can be written and erased using dedicated commands, and read 259 32117A-10/2010 AT32UC3C through a dedicated Peripheral Bus address. Some of the general-purpose fuse bits are reserved for special purposes, and should not be used for other functions.: Table 15-2. General-purpose Fuses with Special Functions Generalpurpose fuse number Name Usage 15:0 LOCK Region lock bits. EPFL External Privileged Fetch Lock. Used to prevent the CPU from fetching instructions from external memories when in privileged mode. This bit can only be changed when the security bit is cleared. The address range corresponding to external memories is device-specific, and not known to the Flash Controller. This fuse bit is simply routed out of the CPU or bus system, the Flash Controller does not treat this fuse in any special way, except that it can not be altered when the security bit is set. If the security bit is set, only an external JTAG Chip Erase can clear EPFL. No internal commands can alter EPFL if the security bit is set. When the fuse is erased (i.e. "1"), the CPU can execute instructions fetched from external memories. When the fuse is programmed (i.e. "0"), instructions can not be executed from external memories. This fuse has no effect in devices with no External Memory Interface (EBI). 19:17 BOOTPROT Used to select one of eight different bootloader sizes. Pages included in the bootloader area can not be erased or programmed except by a JTAG chip erase. BOOTPROT can only be changed when the security bit is cleared. If the security bit is set, only an external JTAG Chip Erase can clear BOOTPROT, and thereby allow the pages protected by BOOTPROT to be programmed. No internal commands can alter BOOTPROT or the pages protected by BOOTPROT if the security bit is set. 21:20 SECURE Used to configure secure state and secure state debug capabilities. Refer to the AVR32 Architecture Manual and the AVR32UC Technical Reference Manual for more details. UPROT If programmed (i.e. "1"), the JTAG USER PROTECTION feature is enabled. If this fuse is programmed some HSB addresses will be accessible by JTAG access even if the flash security fuse is programmed. Refer to the JTAG documentation for more information on this functionality. This bit can only be changed when the security bit is cleared. 16 22 260 32117A-10/2010 AT32UC3C The BOOTPROT fuses protects the following address space for the Boot Loader: Table 15-3. Boot Loader Area Specified by BOOTPROT BOOTPROT Pages protected by BOOTPROT Size of protected memory 7 None 0 6 0-1 1kByte 5 0-3 2kByte 4 0-7 4kByte 3 0-15 8kByte 2 0-31 16kByte 1 0-63 32kByte 0 0-127 64kByte The SECURE fuses have the following functionality: Table 15-4. Secure state configuration SECURE Functionality 00 Secure state disabled 01 Secure enabled, secure state debug enabled 10 Secure enabled, secure state debug disabled 11 Secure state disabled To erase or write a general-purpose fuse bit, the commands Write General-Purpose Fuse Bit (WGPB) and Erase General-Purpose Fuse Bit (EGPB) are provided. Writing one of these commands, together with the number of the fuse to write/erase, performs the desired operation. An entire general-purpose fuse byte can be written at a time by using the Program GP Fuse Byte (PGPFB) instruction. A PGPFB to GP fuse byte 2 is not allowed if the flash is locked by the security bit. The PFB command is issued with a parameter in the PAGEN field: * PAGEN[2:0] - byte to write * PAGEN[10:3] - Fuse value to write All general-purpose fuses can be erased by the Erase All General-Purpose fuses (EAGP) command. An EAGP command is not allowed if the flash is locked by the security bit. Two errors can be detected in the FSR register after issuing these commands: * Programming Error: A bad keyword and/or an invalid command have been written in the FCMD register. * Lock Error: - A write or erase of the BOOTPROT or EPFL or UPROT fuse bits was attempted while the flash is locked by the security bit. - A write or erase of the SECURE fuse bits was attempted when SECURE mode was enabled. 261 32117A-10/2010 AT32UC3C The lock bits are implemented using the lowest 16 general-purpose fuse bits. This means that the 16 lowest general-purpose fuse bits can also be written/erased using the commands for locking/unlocking regions, see Section 15.5.3. 15.7 Security bit The security bit allows the entire chip to be locked from external JTAG or other debug 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 the JTAG Chip Erase command. Once the Security bit is set, the following Flash controller commands will be unavailable and return a lock error if attempted: * Write General-Purpose Fuse Bit (WGPB) to BOOTPROT or EPFL fuses * Erase General-Purpose Fuse Bit (EGPB) to BOOTPROT or EPFL fuses * Program General-Purpose Fuse Byte (PGPFB) of fuse byte 2 * Erase All General-Purpose Fuses (EAGPF) One error can be detected in the FSR register after issuing the command: * Programming Error: A bad keyword and/or an invalid command have been written in the FCMD register. 262 32117A-10/2010 AT32UC3C 15.8 User interface Table 15-5. FLASHC Register Memory Map Offset Register Register Name Access Reset 0x0 Flash Control Register FCR Read/Write 0x00000000 0x4 Flash Command Register FCMD Read/Write 0x00000000 0x8 Flash Status Register FSR Read/Write 0(1) 0xc Flash Parameter Register PR Read-only 0(2) 0x10 Flash Version Register VR Read-only 0(2) 0x14 Flash General Purpose Fuse Register Hi FGPFRHI Read-only NA(1) 0x18 Flash General Purpose Fuse Register Lo FGPFRLO Read-only NA(1) Note: 1. The value of the Lock bits is dependent of their programmed state. All other bits in FSR are 0. All bits in FGPFR are dependent on the programmed state of the fuses they map to. Any bits in these registers not mapped to a fuse read 0. 2. The reset values for these registers are device specific. Please refer to the Module Configuration section at the end of this chapter. 263 32117A-10/2010 AT32UC3C 15.8.1 Name: Flash Control Register FCR Access Type: Read/Write Offset: 0x00 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 - - - - - - - - 7 6 5 4 3 2 1 0 - FWS - - PROGE LOCKE - FRDY * FWS: Flash Wait State 0: The flash is read with 0 wait states. 1: The flash is read with 1 wait state. * PROGE: Programming Error Interrupt Enable 0: Programming Error does not generate an interrupt. 1: Programming Error generates an interrupt. * LOCKE: Lock Error Interrupt Enable 0: Lock Error does not generate an interrupt. 1: Lock Error generates an interrupt. * FRDY: Flash Ready Interrupt Enable 0: Flash Ready does not generate an interrupt. 1: Flash Ready generates an interrupt. 264 32117A-10/2010 AT32UC3C 15.8.2 Name: Flash Command Register FCMD Access Type: Read/Write Offset: 0x04 Reset Value: 0x00000000 The FCMD can not be written if the flash is in the process of performing a flash command. Doing so will cause the FCR write to be ignored, and the PROGE bit to be set. 31 30 29 28 27 26 25 24 19 18 17 16 11 10 9 8 3 2 1 0 KEY 23 22 21 20 PAGEN [15:8] 15 14 13 12 PAGEN [7:0] 7 6 - - 5 4 CMD * KEY: Write Protection Key This field should be written with the value 0xA5 to enable the command defined by the bits of the register. If the field is written with a different value, the write is not performed and no action is started. This field always reads as 0. * PAGEN: Page Number The PAGEN field is used to address a page or fuse bit for certain operations. In order to simplify programming, the PAGEN field is automatically updated every time the page buffer is written to. For every page buffer write, the PAGEN field is updated with the page number of the address being written to. Hardware automatically masks writes to the PAGEN field so that only bits representing valid page numbers can be written, all other bits in PAGEN are always 0. As an example, in a flash with 1024 pages (page 0 - page 1023), bits 15:10 will always be 0. Table 15-6. Semantic of PAGEN Field in Different Commands Command PAGEN description No operation Not used Write Page The number of the page to write Clear Page Buffer Not used Lock region containing given Page Page number whose region should be locked Unlock region containing given Page Page number whose region should be unlocked Erase All Not used Write General-Purpose Fuse Bit GPFUSE # Erase General-Purpose Fuse Bit GPFUSE # Set Security Bit Not used 265 32117A-10/2010 AT32UC3C Table 15-6. Semantic of PAGEN Field in Different Commands Command PAGEN description Program GP Fuse Byte WriteData[7:0], ByteAddress[2:0] Erase All GP Fuses Not used Quick Page Read Page number Write User Page Not used Erase User Page Not used Quick Page Read User Page Not used High Speed Mode Enable Not used High Speed Mode Disable Not used * CMD: Command This field defines the flash command. Issuing any unused command will cause the Programming Error bit to be set, and the corresponding interrupt to be requested if the PROGE bit in FCR is set. Table 15-7. Set of Commands Command Value Mnemonic No operation 0 NOP Write Page 1 WP Erase Page 2 EP Clear Page Buffer 3 CPB Lock region containing given Page 4 LP Unlock region containing given Page 5 UP Erase All 6 EA Write General-Purpose Fuse Bit 7 WGPB Erase General-Purpose Fuse Bit 8 EGPB Set Security Bit 9 SSB Program GP Fuse Byte 10 PGPFB Erase All GPFuses 11 EAGPF Quick Page Read 12 QPR Write User Page 13 WUP Erase User Page 14 EUP Quick Page Read User Page 15 QPRUP High Speed Mode Enable 16 HSEN High Speed Mode Disable 17 HSDIS 266 32117A-10/2010 AT32UC3C 15.8.3 Name: Flash Status Register FSR Access Type: Read-only Offset: 0x08 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 LOCK15 LOCK14 LOCK13 LOCK12 LOCK11 LOCK10 LOCK9 LOCK8 23 22 21 20 19 18 17 16 LOCK7 LOCK6 LOCK5 LOCK4 LOCK3 LOCK2 LOCK1 LOCK0 15 14 13 12 11 10 9 8 - - - - - - - - 7 6 5 4 3 2 1 0 - HSMODE QPRR SECURITY PROGE LOCKE - FRDY * LOCKx: Lock Region x Lock Status 0: The corresponding lock region is not locked. 1: The corresponding lock region is locked. * HSMODE: High-Speed Mode 0: High-speed mode disabled. 1: High-speed mode enabled. * QPRR: Quick Page Read Result 0: The result is zero, i.e. the page is not erased. 1: The result is one, i.e. the page is erased. * SECURITY: Security Bit Status 0: The security bit is inactive. 1: The security bit is active. * PROGE: Programming Error Status Automatically cleared when FSR is read. 0: No invalid commands and no bad keywords were written in the Flash Command Register FCMD. 1: An invalid command and/or a bad keyword was/were written in the Flash Command Register FCMD. * LOCKE: Lock Error Status Automatically cleared when FSR is read. 0: No programming of at least one locked lock region has happened since the last read of FSR. 1: Programming of at least one locked lock region has happened since the last read of FSR. * FRDY: Flash Ready Status 0: The Flash Controller is busy and the application must wait before running a new command. 1: The Flash Controller is ready to run a new command. 267 32117A-10/2010 AT32UC3C 15.8.4 Name: Parameter Register PR Access Type: Read-only Offset: 0x0C Reset Value: 0x00000000(*) 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 - - - - - 7 6 5 4 3 - - - - PSZ 2 1 0 FSZ * FSZ: Flash Size The size of the flash. Not all device families will provide all flash sizes indicated in the table. Table 15-8. Flash size FSZ Flash Size FSZ Flash Size 0 4 Kbyte 8 192 Kbyte 1 8 Kbyte 9 256 Kbyte 2 16 Kbyte 10 384 Kbyte 3 32 Kbyte 11 512 Kbyte 4 48 Kbyte 12 768 Kbyte 5 64 Kbyte 13 1024 Kbyte 6 96 Kbyte 14 2048 Kbyte 7 128 Kbyte 15 RESERVED 268 32117A-10/2010 AT32UC3C * PSZ: Page Size The size of a flash page. Table 15-9. Flash page size PSZ Page Size 0 32 words 1 64 words 2 128 words 3 256 words 4 512 words 5 1024 words 6 2048 words 7 4096 words 269 32117A-10/2010 AT32UC3C 15.8.5 Name: Version Register VR Access Type: Read-only Offset: 0x10 Reset Value: 0x00000000(*) 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - 15 14 13 12 9 8 - - - - 7 6 5 4 VARIANT 11 10 VERSION[11:8]- 3 2 1 0 VERSION[7:0] * VARIANT: Variant Number Reserved. No functionality associated. * VERSION: Version Number Version number of the module. No functionality associated. 270 32117A-10/2010 AT32UC3C 15.8.6 Name: Flash General Purpose Fuse Register High FGPFRHI Access Type: Read-only Offset: 0x14 Reset Value: NA(*) 31 30 29 28 27 26 25 24 GPF63 GPF62 GPF61 GPF60 GPF59 GPF58 GPF57 GPF56 23 22 21 20 19 18 17 16 GPF55 GPF54 GPF53 GPF52 GPF51 GPF50 GPF49 GPF48 15 14 13 12 11 10 9 8 GPF47 GPF46 GPF45 GPF44 GPF43 GPF42 GPF41 GPF40 7 6 5 4 3 2 1 0 GPF39 GPF38 GPF37 GPF36 GPF35 GPF34 GPF33 GPF32 This register is only used in systems with more than 32 GP fuses. * GPFxx: General Purpose Fuse xx 0: The fuse has a written/programmed state. 1: The fuse has an erased state. 271 32117A-10/2010 AT32UC3C 15.8.7 Name: Flash General Purpose Fuse Register Low FGPFRLO Access Type: Read-only Offset: 0x18 Reset Value: NA(*) 31 30 29 28 27 26 25 24 GPF31 GPF30 GPF29 GPF28 GPF27 GPF26 GPF25 GPF24 23 22 21 20 19 18 17 16 GPF23 GPF22 GPF21 GPF20 GPF19 GPF18 GPF17 GPF16 15 14 13 12 11 10 9 8 GPF15 GPF14 GPF13 GPF12 GPF11 GPF10 GPF09 GPF08 7 6 5 4 3 2 1 0 GPF07 GPF06 GPF05 GPF04 GPF03 GPF02 GPF01 GPF00 * GPFxx: General Purpose Fuse xx 0: The fuse has a written/programmed state. 1: The fuse has an erased state. 272 32117A-10/2010 AT32UC3C 15.9 Fuses Settings The flash block contains 32 general purpose fuses. These 32 fuses can be found in the Flash General Purpose Fuse Register Low. Some of these fuses have defined meanings outside the flash controller and are described in this section. In addition to the General Purpose fuses parts of the Flash, user page can have a defined meaning outside the flash controller and are described in this section. Note that after writing the user page, values will not be propagated to other modules internally on the device. Other modules will load these values after resetting the chip. The general purpose fuses are erased by a JTAG or aWire chip erase. 15.9.1 Flash General Purpose Fuse Register (FGPFRLO) Table 15-10. FGPFR Register Description 31 30 29 BOD33EN 28 BODEN 23 22 BODLEVEL[0] UPROT 15 14 21 27 BODHYST 20 19 SECURE 13 26 25 BODLEVEL[3:1] 18 17 BOOTPROT 12 24 16 EPFL 11 10 9 8 3 2 1 0 LOCK[15:8] 7 6 5 4 LOCK[7:0] * BOD33EN: 3.3V Brown Out Detector Enable Table 15-11. BOD33EN Field Description BOD33EN Description 0x0 BOD33 disabled 0x1 BOD33 enabled, BOD33 reset enabled 0x2 BOD33 enabled, BOD33 reset disabled 0x3 BOD33 disabled * BODEN: 1.8V Brown Out Detector Enable Table 15-12. BODEN Field Description BODEN Description 0x0 BOD18 disabled 0x1 BOD18 enabled, BOD18 reset enabled 0x2 BOD18 enabled, BOD18 reset disabled 0x3 BOD18 disabled 273 32117A-10/2010 AT32UC3C * BODHYST: 1.8V Brown Out Detector Hysteresis 0: The BOD18 hysteresis is disabled. 1: The BOD18 hysteresis is enabled. * BODLEVEL: 1.8V Brown Out Detector Trigger Level This controls the voltage trigger level for the BOD18. At power-up, if the BODLEVEL fuses are greater than 0xA, then the BOD.LEVEL field of the SCIF module will be loaded to 0x28, else the BODLEVEL fuses are multiplied by 2 and are loaded into the BOD.LEVEL. Refer to See "Electrical Characteristics" on page 1243. * UPROT, SECURE, BOOTPROT, EPFL, LOCK These are Flash controller fuses and are described in the FLASHC section. 15.9.2 Default Fuse Value The devices are shipped with the FGPFRLO register value: 0xF877FFFF: * BOD33EN fuses set to 11. BOD33 is disabled. * BODEN fuses set to 11. BOD18 is disabled. * BODHYST fuse set to 1. The BOD18 hysteresis is enabled. * BODLEVEL fuses set to 0000. This is the minimum voltage level for BOD18. * UPROT fuse set to 1 * SECURE fuses set to 11 * BOOTPROT fuses set to 011. The bootloader protected size is 8 KBytes. * EPFL fuse set to 1. External privileged fetch is not locked. * LOCK fuses set to 1111111111111111. No region locked. See also the AT32UC3C Bootloader user guide document. After the JTAG or aWire chip erase command, the FGPFRLO register value is 0xFFFFFFFF. 274 32117A-10/2010 AT32UC3C 15.9.3 Fuses in User Page (address 0x80800000) 15.9.3.1 First word (address 0x80800000) Table 15-13. User Page Fuse Description 31 30 29 28 27 WDTDISRV 23 26 25 24 19 18 17 16 11 10 9 8 2 1 0 SSADRR[14:8] 22 21 20 SSADRR[7:0] 15 14 13 12 SSADRF[15:8] 7 6 5 4 3 SSADRF[7:0] * SSADRR: Size of the CPU RAM controlled by the Secure State The section of the CPU RAM controlled by the Secure State is from address 0x00000000 to address (SSADRR << 10). * SSADRF: Size of the Flash controlled by the Secure State The section of the Flash controlled by the Secure State is from address 0x80000000 to address (SSADRF << 10). * WDTDISRV: WatchDog Timer auto disable at startup 0: The WDT is automatically enabled at startup, the WDTAUTO fuse of the WDT is set. 1: The WDT is not automatically enabled at startup, the WDTAUTO fuse of the watchdog timer is not set. Please refer to the WDT chapter for detail about time-out settings when the WDT is automatically enabled. The devices are shipped with the User page erased (all bits 1). 15.9.3.2 Bootloader words (0x808001F8 and 0x808001FC) The USB/USART bootloader uses two words in the flash user page to store its configuration: * the configuration word 1 at address 0x808001FC is read first at boot time to know if it should start the ISP process unconditionally and whether it should use the configuration word 2 where further configuration is stored. * the configuration word 2 at address 0x808001F8 stores the I/O conditions that determine which of the USB DFU ISP and the application to start at the end of the boot process. Please refer to the bootloader documentation for more information. 275 32117A-10/2010 AT32UC3C 15.10 Calibration Settings Some analog blocks require to be calibrated. The recommended calibration settings are written in the factory page. The base address of the factory page is 0x80800200. Table 15-14. Calibration Register Map Offset Register 0x0000 Oscillator Calibration 0x0004 ADC Core Calibration 0x0008 ADC S/H Calibration 0x000C DAC0A Channel Calibration 0x0010 DAC0B Channel Calibration 0x0014 DAC1A Channel Calibration 0x0018 DAC1B Channel Calibration 276 32117A-10/2010 AT32UC3C 15.10.0.3 Table 15-15. 31 Oscillator Calibration (offset 0x0000) Oscillator Calibration 30 29 28 27 26 25 24 18 17 16 10 9 8 2 1 0 RC1M_CALIB_5V[7:0] 23 22 21 20 19 RC8M_CALIB_5V[7:0] 15 14 13 12 11 RC1M_CALIB[7:0] 7 6 5 4 3 RC8M_CALIB[7:0] * RC1M_CALIB_5V: Calibration of RC8M operating at 1MHz and at 5V This calibration should be used when the RC8M is used at a frequency of 1 MHz and when the voltage of the VDDIN_5 pin is within [4.5V:5.5V]. This value should be written to RCCR8.CALIB field of the SCIF module. * RC8M_CALIB_5V: Calibration of RC8M operating at 8MHz and at 5V This calibration should be used when the RC8M is used at a frequency of 8 MHz and when the voltage of the VDDIN_5 pin is within [4.5V:5.5V]. This value should be written to RCCR8.CALIB. * RC1M_CALIB: Calibration of RC8M operating at 1MHz and at 3.3V This calibration should be used when the RC8M is used at a frequency of 1 MHz and when the voltage of the VDDIN_5 pin is within [3.0V:3.6V]. This value should be written to RCCR8.CALIB. * RC8M_CALIB: Calibration of RC8M operating at 8MHz and at 3.3V This calibration should be used when the RC8M is used at a frequency of 8 MHz and when the voltage of the VDDIN_5 pin is within [3.0V:3.6V]. This value is automatically loaded in RCCR8.CALIB at power-up. 277 32117A-10/2010 AT32UC3C 15.10.0.4 Table 15-16. ADC Core Calibration (offset 0x0004) ADC Core Calibration 31 30 29 28 27 - - 23 22 21 20 19 - - - - 15 14 13 12 26 25 24 18 17 16 - - - - 11 10 9 8 2 1 0 ADC_OCAL[5:0] ADC_GCAL[14:8] 7 6 5 4 3 ADC_GCAL[7:0] * ADC_OCAL: Offset Calibration of the ADC core This value should be written to the ADCCAL.OCAL field of the ADCIFA module. * ADC_GCAL: Gain Calibration of the ADC core This value should be written to the ADCCAL.GCAL field of the ADCIFA module. 278 32117A-10/2010 AT32UC3C 15.10.0.5 Table 15-17. ADC S/H Calibration (offset 0x0008) ADC S/H Calibration 31 30 29 28 27 26 25 24 - - - - - - 23 22 21 20 19 18 17 16 9 8 ADC_GAIN1[9:8] ADC_GAIN1[7:0] 15 14 13 12 11 10 - - - - - - ADC_GAIN0[9:8] 7 6 5 4 3 2 1 0 ADC_GAIN0[7:0] * ADC_GAIN1: Gain Calibration of the ADC S/H1 This value should be written to the SHCAL.GAIN1 field of the ADCIFA module. * ADC_GAIN0: Gain Calibration of the ADC S/H0 This value should be written to the SHCAL.GAIN0 field of the ADCIFA module. 279 32117A-10/2010 AT32UC3C 15.10.0.6 Table 15-18. DAC0 Channel Calibration (offset 0x000C (DAC0 Channel A), 0x0010 (DAC0 Channel B)), DAC0A and DAC0B Channel Calibration 31 30 29 28 27 26 25 24 - - - - - - - DAC_GCAL[8] 23 22 21 20 19 18 17 16 DAC_GCAL[7:0] 15 14 13 12 11 10 9 8 - - - - - - - DAC_OCAL[8] 7 6 5 4 3 2 1 0 DAC_OCAL[7:0] * DAC_GCAL: Gain Calibration of the DAC Channel This value should be written to the GOC.GCR field of the DACIFB0 module. * DAC_OCAL: Offset Calibration of the DAC Channel This value should be written to GOC.OCR field of the DACIFB0 module. 280 32117A-10/2010 AT32UC3C 15.10.0.7 Table 15-19. DAC1 Channel Calibration (offset 0x0014 (DAC1 Channel A), 0x0018 (DAC1 Channel B)), DAC1A and DAC1B Channel Calibration 31 30 29 28 27 26 25 24 - - - - - - - DAC_GCAL[8] 23 22 21 20 19 18 17 16 DAC_GCAL1[7:0] 15 14 13 12 11 10 9 8 - - - - - - - DAC_OCAL[8] 7 6 5 4 3 2 1 0 DAC_OCAL[7:0] * DAC_GCAL: Gain Calibration of the DAC Channel This value should be written to the GOC.GCR field of the DACIFB1 module. * DAC_OCAL: Offset Calibration of the DAC Channel This value should be written to GOC.OCR field of the DACIFB1 module. 281 32117A-10/2010 AT32UC3C 15.11 Serial Number Each device has a unique 120 bits serial number readable from address 0x80800284 to 0x80800292. 15.12 Module Configuration The specific configuration for each FLASHC instance is listed in the following tables. The module bus clocks listed here are connected to the system bus clocks. Please refer to the Power Manager chapter for details. Table 15-20. Module Configuration Flash Size Number of pages Page size AT32UC3C0512C AT32UC3C1512C AT32UC3C2512C 512Kbytes 1024 128 words AT32UC3C0256C AT32UC3C1256C AT32UC3C2256C 256Kbytes 512 128 words AT32UC3C0128C AT32UC3C1128C AT32UC3C2128C 128Kbytes 256 128 words AT32UC3C064C AT32UC3C164C AT32UC3C264C 64Kbytes 128 128 words Table 15-21. Module Clock Name Module name Clock Name Description CLK_FLASHC_HSB HSB clock CLK_FLASHC_PB Peripheral Bus clock from the PBB clock domain FLASHC Table 15-22. Register Reset Values Register Reset Value PR Refer to Table 15-20 VR 0x00000302 282 32117A-10/2010 AT32UC3C 16. HSB Bus Matrix (HMATRIXB) Rev: 1.3.0.3 16.1 Features * * * * * * * * * 16.2 User Interface on peripheral bus Configurable number of masters (up to 16) Configurable number of slaves (up to 16) One decoder for each master Programmable arbitration for each slave - Round-Robin - Fixed priority Programmable default master for each slave - No default master - Last accessed default master - Fixed default master One cycle latency for the first access of a burst Zero cycle latency for default master One special function register for each slave (not dedicated) Overview The Bus Matrix implements a multi-layer bus structure, that enables parallel access paths between multiple High Speed Bus (HSB) masters and slaves in a system, thus increasing the overall bandwidth. The Bus Matrix interconnects up to 16 HSB Masters to up to 16 HSB Slaves. The normal latency to connect a master to a slave is one cycle except for the default master of the accessed slave which is connected directly (zero cycle latency). The Bus Matrix provides 16 Special Function Registers (SFR) that allow the Bus Matrix to support application specific features. 16.3 Product Dependencies In order to configure this module by accessing the user registers, other parts of the system must be configured correctly, as described below. 16.3.1 Clocks The clock for the HMATRIX bus interface (CLK_HMATRIX) is generated by the Power Manager. This clock is enabled at reset, and can be disabled in the Power Manager. 16.4 16.4.1 Functional Description Special Bus Granting Mechanism The Bus Matrix provides some speculative bus granting techniques in order to anticipate access requests from some masters. This mechanism reduces latency at first access of a burst or single transfer. This bus granting mechanism sets a different default master for every slave. At the end of the current access, if no other request is pending, the slave remains connected to its associated default master. A slave can be associated with three kinds of default masters: no default master, last access master, and fixed default master. 283 32117A-10/2010 AT32UC3C To change from one kind of default master to another, the Bus Matrix user interface provides the Slave Configuration Registers, one for each slave, that set a default master for each slave. The Slave Configuration Register contains two fields: DEFMSTR_TYPE and FIXED_DEFMSTR. The 2-bit DEFMSTR_TYPE field selects the default master type (no default, last access master, fixed default master), whereas the 4-bit FIXED_DEFMSTR field selects a fixed default master provided that DEFMSTR_TYPE is set to fixed default master. Please refer to the Bus Matrix user interface description. 16.4.1.1 No Default Master At the end of the current access, if no other request is pending, the slave is disconnected from all masters. No Default Master suits low-power mode. 16.4.1.2 Last Access Master At the end of the current access, if no other request is pending, the slave remains connected to the last master that performed an access request. 16.4.1.3 Fixed Default Master At the end of the current access, if no other request is pending, the slave connects to its fixed default master. Unlike last access master, the fixed master does not change unless the user modifies it by a software action (field FIXED_DEFMSTR of the related SCFG). 16.4.2 Arbitration The Bus Matrix provides an arbitration mechanism that reduces latency when conflict cases occur, i.e. when two or more masters try to access the same slave at the same time. One arbiter per HSB slave is provided, thus arbitrating each slave differently. The Bus Matrix provides the user with the possibility of choosing between 2 arbitration types for each slave: 1. Round-Robin Arbitration (default) 2. Fixed Priority Arbitration This is selected by the ARBT field in the Slave Configuration Registers (SCFG). Each algorithm may be complemented by selecting a default master configuration for each slave. When a re-arbitration must be done, specific conditions apply. This is described in "Arbitration Rules" . 16.4.2.1 Arbitration Rules Each arbiter has the ability to arbitrate between two or more different master requests. In order to avoid burst breaking and also to provide the maximum throughput for slave interfaces, arbitration may only take place during the following cycles: 1. Idle Cycles: When a slave is not connected to any master or is connected to a master which is not currently accessing it. 2. Single Cycles: When a slave is currently doing a single access. 3. End of Burst Cycles: When the current cycle is the last cycle of a burst transfer. For defined length burst, predicted end of burst matches the size of the transfer but is managed differently for undefined length burst. This is described below. 4. Slot Cycle Limit: When the slot cycle counter has reached the limit value indicating that the current master access is too long and must be broken. This is described below. 284 32117A-10/2010 AT32UC3C * Undefined Length Burst Arbitration In order to avoid long slave handling during undefined length bursts (INCR), the Bus Matrix provides specific logic in order to re-arbitrate before the end of the INCR transfer. A predicted end of burst is used as a defined length burst transfer and can be selected among the following five possibilities: 1. Infinite: No predicted end of burst is generated and therefore INCR burst transfer will never be broken. 2. One beat bursts: Predicted end of burst is generated at each single transfer inside the INCP transfer. 3. Four beat bursts: Predicted end of burst is generated at the end of each four beat boundary inside INCR transfer. 4. Eight beat bursts: Predicted end of burst is generated at the end of each eight beat boundary inside INCR transfer. 5. Sixteen beat bursts: Predicted end of burst is generated at the end of each sixteen beat boundary inside INCR transfer. This selection can be done through the ULBT field in the Master Configuration Registers (MCFG). * Slot Cycle Limit Arbitration The Bus Matrix contains specific logic to break long accesses, such as very long bursts on a very slow slave (e.g., an external low speed memory). At the beginning of the burst access, a counter is loaded with the value previously written in the SLOT_CYCLE field of the related Slave Configuration Register (SCFG) and decreased at each clock cycle. When the counter reaches zero, the arbiter has the ability to re-arbitrate at the end of the current byte, halfword, or word transfer. 16.4.2.2 Round-Robin Arbitration This algorithm allows the Bus Matrix arbiters to dispatch the requests from different masters to the same slave in a round-robin manner. If two or more master requests arise at the same time, the master with the lowest number is first serviced, then the others are serviced in a round-robin manner. There are three round-robin algorithms implemented: 1. Round-Robin arbitration without default master 2. Round-Robin arbitration with last default master 3. Round-Robin arbitration with fixed default master * Round-Robin Arbitration without Default Master This is the main algorithm used by Bus Matrix arbiters. It allows the Bus Matrix to dispatch requests from different masters to the same slave in a pure round-robin manner. At the end of the current access, if no other request is pending, the slave is disconnected from all masters. This configuration incurs one latency cycle for the first access of a burst. Arbitration without default master can be used for masters that perform significant bursts. * Round-Robin Arbitration with Last Default Master This is a biased round-robin algorithm used by Bus Matrix arbiters. It allows the Bus Matrix to remove the one latency cycle for the last master that accessed the slave. At the end of the cur285 32117A-10/2010 AT32UC3C rent transfer, if no other master request is pending, the slave remains connected to the last master that performed the access. Other non privileged masters still get one latency cycle if they want to access the same slave. This technique can be used for masters that mainly perform single accesses. * Round-Robin Arbitration with Fixed Default Master This is another biased round-robin algorithm. It allows the Bus Matrix arbiters to remove the one latency cycle for the fixed default master per slave. At the end of the current access, the slave remains connected to its fixed default master. Every request attempted by this fixed default master will not cause any latency whereas other non privileged masters will still get one latency cycle. This technique can be used for masters that mainly perform single accesses. 16.4.2.3 Fixed Priority Arbitration This algorithm allows the Bus Matrix arbiters to dispatch the requests from different masters to the same slave by using the fixed priority defined by the user. If two or more master requests are active at the same time, the master with the highest priority number is serviced first. If two or more master requests with the same priority are active at the same time, the master with the highest number is serviced first. For each slave, the priority of each master may be defined through the Priority Registers for Slaves (PRAS and PRBS). 16.4.3 Slave and Master assignation The index number assigned to Bus Matrix slaves and masters are described in the Module Configuration section at the end of this chapter. 286 32117A-10/2010 AT32UC3C 16.5 User Interface Table 16-1. HMATRIX Register Memory Map Offset Register Name Access Reset Value 0x0000 Master Configuration Register 0 MCFG0 Read/Write 0x00000002 0x0004 Master Configuration Register 1 MCFG1 Read/Write 0x00000002 0x0008 Master Configuration Register 2 MCFG2 Read/Write 0x00000002 0x000C Master Configuration Register 3 MCFG3 Read/Write 0x00000002 0x0010 Master Configuration Register 4 MCFG4 Read/Write 0x00000002 0x0014 Master Configuration Register 5 MCFG5 Read/Write 0x00000002 0x0018 Master Configuration Register 6 MCFG6 Read/Write 0x00000002 0x001C Master Configuration Register 7 MCFG7 Read/Write 0x00000002 0x0020 Master Configuration Register 8 MCFG8 Read/Write 0x00000002 0x0024 Master Configuration Register 9 MCFG9 Read/Write 0x00000002 0x0028 Master Configuration Register 10 MCFG10 Read/Write 0x00000002 0x002C Master Configuration Register 11 MCFG11 Read/Write 0x00000002 0x0030 Master Configuration Register 12 MCFG12 Read/Write 0x00000002 0x0034 Master Configuration Register 13 MCFG13 Read/Write 0x00000002 0x0038 Master Configuration Register 14 MCFG14 Read/Write 0x00000002 0x003C Master Configuration Register 15 MCFG15 Read/Write 0x00000002 0x0040 Slave Configuration Register 0 SCFG0 Read/Write 0x00000010 0x0044 Slave Configuration Register 1 SCFG1 Read/Write 0x00000010 0x0048 Slave Configuration Register 2 SCFG2 Read/Write 0x00000010 0x004C Slave Configuration Register 3 SCFG3 Read/Write 0x00000010 0x0050 Slave Configuration Register 4 SCFG4 Read/Write 0x00000010 0x0054 Slave Configuration Register 5 SCFG5 Read/Write 0x00000010 0x0058 Slave Configuration Register 6 SCFG6 Read/Write 0x00000010 0x005C Slave Configuration Register 7 SCFG7 Read/Write 0x00000010 0x0060 Slave Configuration Register 8 SCFG8 Read/Write 0x00000010 0x0064 Slave Configuration Register 9 SCFG9 Read/Write 0x00000010 0x0068 Slave Configuration Register 10 SCFG10 Read/Write 0x00000010 0x006C Slave Configuration Register 11 SCFG11 Read/Write 0x00000010 0x0070 Slave Configuration Register 12 SCFG12 Read/Write 0x00000010 0x0074 Slave Configuration Register 13 SCFG13 Read/Write 0x00000010 0x0078 Slave Configuration Register 14 SCFG14 Read/Write 0x00000010 0x007C Slave Configuration Register 15 SCFG15 Read/Write 0x00000010 0x0080 Priority Register A for Slave 0 PRAS0 Read/Write 0x00000000 0x0084 Priority Register B for Slave 0 PRBS0 Read/Write 0x00000000 0x0088 Priority Register A for Slave 1 PRAS1 Read/Write 0x00000000 287 32117A-10/2010 AT32UC3C Table 16-1. HMATRIX Register Memory Map (Continued) Offset Register Name Access Reset Value 0x008C Priority Register B for Slave 1 PRBS1 Read/Write 0x00000000 0x0090 Priority Register A for Slave 2 PRAS2 Read/Write 0x00000000 0x0094 Priority Register B for Slave 2 PRBS2 Read/Write 0x00000000 0x0098 Priority Register A for Slave 3 PRAS3 Read/Write 0x00000000 0x009C Priority Register B for Slave 3 PRBS3 Read/Write 0x00000000 0x00A0 Priority Register A for Slave 4 PRAS4 Read/Write 0x00000000 0x00A4 Priority Register B for Slave 4 PRBS4 Read/Write 0x00000000 0x00A8 Priority Register A for Slave 5 PRAS5 Read/Write 0x00000000 0x00AC Priority Register B for Slave 5 PRBS5 Read/Write 0x00000000 0x00B0 Priority Register A for Slave 6 PRAS6 Read/Write 0x00000000 0x00B4 Priority Register B for Slave 6 PRBS6 Read/Write 0x00000000 0x00B8 Priority Register A for Slave 7 PRAS7 Read/Write 0x00000000 0x00BC Priority Register B for Slave 7 PRBS7 Read/Write 0x00000000 0x00C0 Priority Register A for Slave 8 PRAS8 Read/Write 0x00000000 0x00C4 Priority Register B for Slave 8 PRBS8 Read/Write 0x00000000 0x00C8 Priority Register A for Slave 9 PRAS9 Read/Write 0x00000000 0x00CC Priority Register B for Slave 9 PRBS9 Read/Write 0x00000000 0x00D0 Priority Register A for Slave 10 PRAS10 Read/Write 0x00000000 0x00D4 Priority Register B for Slave 10 PRBS10 Read/Write 0x00000000 0x00D8 Priority Register A for Slave 11 PRAS11 Read/Write 0x00000000 0x00DC Priority Register B for Slave 11 PRBS11 Read/Write 0x00000000 0x00E0 Priority Register A for Slave 12 PRAS12 Read/Write 0x00000000 0x00E4 Priority Register B for Slave 12 PRBS12 Read/Write 0x00000000 0x00E8 Priority Register A for Slave 13 PRAS13 Read/Write 0x00000000 0x00EC Priority Register B for Slave 13 PRBS13 Read/Write 0x00000000 0x00F0 Priority Register A for Slave 14 PRAS14 Read/Write 0x00000000 0x00F4 Priority Register B for Slave 14 PRBS14 Read/Write 0x00000000 0x00F8 Priority Register A for Slave 15 PRAS15 Read/Write 0x00000000 0x00FC Priority Register B for Slave 15 PRBS15 Read/Write 0x00000000 0x0110 Special Function Register 0 SFR0 Read/Write - 0x0114 Special Function Register 1 SFR1 Read/Write - 0x0118 Special Function Register 2 SFR2 Read/Write - 0x011C Special Function Register 3 SFR3 Read/Write - 0x0120 Special Function Register 4 SFR4 Read/Write - 0x0124 Special Function Register 5 SFR5 Read/Write - 0x0128 Special Function Register 6 SFR6 Read/Write - 288 32117A-10/2010 AT32UC3C Table 16-1. HMATRIX Register Memory Map (Continued) Offset Register Name Access Reset Value 0x012C Special Function Register 7 SFR7 Read/Write - 0x0130 Special Function Register 8 SFR8 Read/Write - 0x0134 Special Function Register 9 SFR9 Read/Write - 0x0138 Special Function Register 10 SFR10 Read/Write - 0x013C Special Function Register 11 SFR11 Read/Write - 0x0140 Special Function Register 12 SFR12 Read/Write - 0x0144 Special Function Register 13 SFR13 Read/Write - 0x0148 Special Function Register 14 SFR14 Read/Write - 0x014C Special Function Register 15 SFR15 Read/Write - 289 32117A-10/2010 AT32UC3C 16.5.1 Name: Master Configuration Registers MCFG0...MCFG15 Access Type: Read/Write Offset: 0x00 - 0x3C Reset Value: 0x00000002 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 - - - - - - - - 7 6 5 4 3 2 1 0 - - - - - ULBT * ULBT: Undefined Length Burst Type Table 16-2. Undefined Length Burst Type ULBT Undefined Length Burst Type Description 000 Inifinite Length Burst No predicted end of burst is generated and therefore INCR bursts coming from this master cannot be broken. 001 Single-Access The undefined length burst is treated as a succession of single accesses, allowing rearbitration at each beat of the INCR burst. 010 4 Beat Burst The undefined length burst is split into a four-beat burst, allowing re-arbitration at each four-beat burst end. 011 8 Beat Burst The undefined length burst is split into an eight-beat burst, allowing re-arbitration at each eight-beat burst end. 100 16 Beat Burst The undefined length burst is split into a sixteen-beat burst, allowing re-arbitration at each sixteen-beat burst end. 290 32117A-10/2010 AT32UC3C 16.5.2 Name: Slave Configuration Registers SCFG0...SCFG15 Access Type: Read/Write Offset: 0x40 - 0x7C Reset Value: 0x00000010 31 30 29 28 27 26 25 24 - - - - - - - ARBT 23 22 21 20 19 18 17 16 - - 15 14 13 12 11 10 9 8 - - - - - - - - 7 6 5 4 3 2 1 0 FIXED_DEFMSTR DEFMSTR_TYPE SLOT_CYCLE * ARBT: Arbitration Type 0: Round-Robin Arbitration 1: Fixed Priority Arbitration * FIXED_DEFMSTR: Fixed Default Master This is the number of the Default Master for this slave. Only used if DEFMSTR_TYPE is 2. Specifying the number of a master which is not connected to the selected slave is equivalent to setting DEFMSTR_TYPE to 0. * DEFMSTR_TYPE: Default Master Type 0: No Default Master At the end of the current slave access, if no other master request is pending, the slave is disconnected from all masters. This results in a one cycle latency for the first access of a burst transfer or for a single access. 1: Last Default Master At the end of the current slave access, if no other master request is pending, the slave stays connected to the last master having accessed it. This results in not having one cycle latency when the last master tries to access the slave again. 2: Fixed Default Master At the end of the current slave access, if no other master request is pending, the slave connects to the fixed master the number that has been written in the FIXED_DEFMSTR field. This results in not having one cycle latency when the fixed master tries to access the slave again. * SLOT_CYCLE: Maximum Number of Allowed Cycles for a Burst When the SLOT_CYCLE limit is reached for a burst, it may be broken by another master trying to access this slave. This limit has been placed to avoid locking a very slow slave when very long bursts are used. This limit must not be very small. Unreasonably small values break every burst and the Bus Matrix arbitrates without performing any data transfer. 16 cycles is a reasonable value for SLOT_CYCLE. 291 32117A-10/2010 AT32UC3C 16.5.3 Bus Matrix Priority Registers A For Slaves Register Name: PRAS0...PRAS15 Access Type: Read/Write Offset: - Reset Value: 0x00000000 31 30 - - 23 22 - - 15 14 - - 7 6 - - 29 28 M7PR 21 20 M5PR 13 12 M3PR 5 4 M1PR 27 26 - - 19 18 - - 11 10 - - 3 2 - - 25 24 M6PR 17 16 M4PR 9 8 M2PR 1 0 M0PR * MxPR: Master x Priority Fixed priority of Master x for accessing the selected slave. The higher the number, the higher the priority. 292 32117A-10/2010 AT32UC3C 16.5.4 Name: Priority Registers B For Slaves PRBS0...PRBS15 Access Type: Read/Write Offset: - Reset Value: 0x00000000 31 30 - - 23 22 - - 15 14 - - 7 6 - - 29 28 M15PR 21 20 M13PR 13 12 M11PR 5 4 M9PR 27 26 - - 19 18 - - 11 10 - - 3 2 - - 25 24 M14PR 17 16 M12PR 9 8 M10PR 1 0 M8PR * MxPR: Master x Priority Fixed priority of Master x for accessing the selected slave. The higher the number, the higher the priority. 293 32117A-10/2010 AT32UC3C 16.5.5 Name: Special Function Registers SFR0...SFR15 Access Type: Read/Write Offset: 0x110 - 0x14C Reset Value: - 31 30 29 28 27 26 25 24 19 18 17 16 11 10 9 8 3 2 1 0 SFR 23 22 21 20 SFR 15 14 13 12 SFR 7 6 5 4 SFR * SFR: Special Function Register Fields Those registers are not a HMATRIX specific register. The field of those will be defined where they are used. 294 32117A-10/2010 AT32UC3C 16.6 Bus Matrix Connections Accesses to unused areas returns an error result to the master requesting such an access. The bus matrix has the several masters and slaves. Each master has its own bus and its own decoder, thus allowing a different memory mapping per master. The master number in the table below can be used to index the HMATRIX control registers. For example, MCFG0 is associated with the CPU Data master interface. Table 16-3. High Speed Bus masters Master 0 CPU Data Master 1 CPU Instruction Master 2 CPU SAB Master 3 SAU Master 4 PDCA Master 5 MDMA Read Master 6 MDMA write Master 7 USBC Master 8 CANIF Master 9 MACB Each slave has its own arbiter, thus allowing a different arbitration per slave. The slave number in the table below can be used to index the HMATRIX control registers. For example, SCFG3 is associated with the Internal SRAM Slave Interface. Table 16-4. High Speed Bus slaves Slave 0 Internal Flash Slave 1 HSB-PB Bridge A Slave 2 HSB-PB Bridge B Slave 3 HSB-PB Bridge C Slave 4 Internal SRAM Slave 5 HSB RAM Slave 6 EBI Slave 7 SAU 295 32117A-10/2010 AT32UC3C HMATRIX MASTERS CPU Data 0 CPU Instruction 1 CPU SAB 2 SAU 3 PDCA 4 MDMA Read 5 MDMA Write 6 USBC 7 CANIF 8 MACB 9 Internal Flash HSB-PB Bridge A HSB-PB Bridge B HSB-PB Bridge C Internal SRAM HSB SRAM EBI SAU Figure 16-1. HMatrix Master / Slave Connections 0 1 2 3 4 5 6 7 296 32117A-10/2010 AT32UC3C 17. External Bus Interface (EBI) Rev.: 1.7.0.0 17.1 Features * Optimized for application memory space support * Integrates two external memory controllers: - Static Memory Controller (SMC) - SDRAM Controller (SDRAMC) * Optimized external bus:16-bit data bus - Up to 24-bit Address Bus, Up to 16-Mbytes Addressable - Optimized pin multiplexing to reduce latencies on external memories * Up to 4 Chip Selects, Configurable Assignment: - Static Memory Controller on Chip Select 0 - SDRAM Controller or Static Memory Controller on Chip Select 1 - Static Memory Controller on Chip Select 2 - Static Memory Controller on Chip Select 3 17.2 Overview The External Bus Interface (EBI) is designed to ensure the successful data transfer between several external devices and the embedded memory controller of a 32-bit AVR device. The Static Memory and SDRAM Controllers are all featured external memory controllers on the EBI. These external memory controllers are capable of handling several types of external memory and peripheral devices, such as SRAM, PROM, EPROM, EEPROM, Flash, and SDRAM. The EBI handles data transfers with up to four external devices, each assigned to four address spaces defined by the embedded memory controller. Data transfers are performed through a 16bit data bus, an address bus of up to 24 bits, up to four chip select lines (NCS[3:0]), and several control pins that are generally multiplexed between the different external memory controllers. 297 32117A-10/2010 AT32UC3C 17.3 Block Diagram Figure 17-1. EBI Block Diagram INTC SDRAMC_irq EBI HMATRIX HSB DATA[15:0] SDRAM Controller NWE1 NWE0 Static Memory Controller NRD NCS[3:0] ADDR[23:0] MUX Logic SFR registers I/O Controller SDCS CAS RAS SDA10 SDWE Address Decoders Chip Select Assignor SDCK SDCKE NWAIT HSB-PB Bridge Peripheral Bus 17.4 I/O Lines Description 298 32117A-10/2010 AT32UC3C Table 17-1. EBI I/O Lines Description Pin Name Alternate Name Pin Description Type Active Level EBI common lines DATA[15:0] Data Bus I/O SMC dedicated lines ADDR[1] SMC Address Bus Line 1 Output ADDR[12] SMC Address Bus Line 12 Output ADDR[15] SMC Address Bus Line 15 Output SMC Address Bus Line [23:18] Output NCS[0] SMC Chip Select Line 0 Output Low NCS[2] SMC Chip Select Line 2 Output Low NCS[3] SMC Chip Select Line 3 Output Low SMC Read Signal Output Low Input Low Output Low ADDR[23:18] NRD NWAIT NWE0 SMC External Wait Signal NWE0-NWE SMC Write Enable1 or Write enable SDRAMC dedicated lines SDCK SDRAM Clock Output SDCKE SDRAM Clock Enable Output High SDWE SDRAM Write Enable Output Low SDA10 SDRAM Address Bus Line 10 Output Low Row and Column Signal Output Low RAS - CAS SMC/SDRAMC shared lines ADDR[0] DQM0 ADDR[0]-NBS0 SDRAMC DQM1 SMC Address Bus Line 0 or Byte Select 0 Output ADDR[11:2] ADDR[9:0] ADDR[11:2] SDRAMC Address Bus Lines [9:0] SMC Address Bus Lines [11:2] Output ADDR[14:13] ADDR[9:0] ADDR[14:13] SDRAMC Address Bus Lines [12:11] SMC Address Bus Lines [14:13] Output ADDR[16] BA0 ADDR[16] SDRAMC Bank 0 SMC Address Bus Line 16 Output ADDR[17] BA1 ADDR[17] SDRAMC Bank 1 SMCAddress Bus Line 17 Output NCS[1] NCS[1] SDCS0 SMC Chip Select Line 1 SDRAMC Chip Select Line 0 Output NWE1 DQM1 NWE1-NBS1 SDRAMC DQM1 SMC Write Enable1 or Byte Select 1 Output Low 299 32117A-10/2010 AT32UC3C 17.5 Product Dependencies In order to use this module, other parts of the system must be configured correctly, as described below. 17.5.1 I/O Lines The pins used for interfacing the compliant external devices may be multiplexed with I/O Controller lines. The user must first configure the I/O Controller to assign the EBI pins to their peripheral functions. 17.5.2 Power Management To prevent bus errors EBI operation must be terminated before entering sleep mode. 17.5.3 Clocks A number of clocks can be selected as source for the EBI. The selected clock must be enabled by the Power Manager. The following clock sources are available: * CLK_EBI * CLK_SDRAMC * CLK_SMC Refer to Table 17-2 on page 300 to configure those clocks. Table 17-2. EBI Clocks Configuration Type of the Interfaced Device Clocks type SDRAM SRAM, PROM, EPROM, EEPROM, Flash CLK_EBI HSB X X CLK_SDRAMC PB X CLK_SMC PB Clocks name 17.5.4 X Interrupts The EBI interface has one interrupt line connected to the Interrupt Controller: * SDRAMC_IRQ: Interrupt signal coming from the SDRAMC Handling the EBI interrupt requires configuring the interrupt controller before configuring the EBI. 300 32117A-10/2010 AT32UC3C 17.5.5 HMATRIX The EBI interface is connected to the HMATRIX Special Function Register 6 (SFR6). The user must first write to this HMATRIX.SFR6 to configure the EBI correctly. Table 17-3. SFR6 Bit Number EBI Special Function Register Fields Description Bit name [31:2] 1 0 17.6 Description Reserved CS1A 0 = Chip Select 1 (NCS[1]) is connected to a Static Memory device. For each access to the NCS[1] memory space, all related pins act as SMC pins 1 = Chip Select 1 (NCS[1]) is connected to a SDRAM device. For each access to the NCS[1] memory space, all related pins act as SDRAM pins Reserved Functional Description The EBI transfers data between the internal HSB bus (handled by the HMATRIX) and the external memories or peripheral devices. It controls the waveforms and the parameters of the external address, data and control busses and is composed of the following elements: * The Static Memory Controller (SMC) * The SDRAM Controller (SDRAMC) * A chip select assignment feature that assigns an HSB address space to the external devices * A multiplex controller circuit that shares the pins between the different memory controllers 17.6.1 Bus Multiplexing The EBI offers a complete set of control signals that share the 16-bit data lines, the address lines of up to 24 bits and the control signals through a multiplex logic operating in function of the memory area requests. Multiplexing is specifically organized in order to guarantee the maintenance of the address and output control lines at a stable state while no external access is being performed. Multiplexing is also designed to respect the data float times defined in the Memory Controllers. Furthermore, refresh cycles of the SDRAM are executed independently by the SDRAMC without delaying the other external memory controller accesses. 17.6.2 Static Memory Controller For information on the Static Memory Controller, refer to the Static Memory Controller Section. 17.6.3 SDRAM Controller Writing a one to the HMATRIX.SFR6.CS1A bit enables the SDRAM logic. For information on the SDRAM Controller, refer to the SDRAM Section. 301 32117A-10/2010 AT32UC3C 17.7 17.7.1 Application Example Hardware Interface Table 17-4. EBI Pins and External Static Devices Connections Pins of the Interfaced Device 8-bit Static Device Pins name 2 x 8-bit Static Devices Controller 16-bit Static Device SMC DATA[7:0] D[7:0] D[7:0] D[7:0] DATA[15:0] - D[15:8] D[15:8] ADDR[0] A[0] - NBS0(2) ADDR[1] A[1] A[0] A[0] A[23:2] A[22:1] A[22:1] NCS[0] - NCS[3] CS CS CS NRD OE OE OE ADDR[23:2] NWE0 WE NWE1 Note: - WE (1) WE WE (1) NBS1(2) 1. NWE1 enables upper byte writes. NWE0 enables lower byte writes. 2. NBS1 enables upper byte writes. NBS0 enables lower byte writes. Table 17-5. EBI Pins and External Devices Connections Pins of the Interfaced Device Pins name SDRAM Controller SDRAMC DATA[7:0] D[7:0] DATA[15:8] D[15:8] ADDR[0] DQM0 ADDR[10:2] A[8:0] ADDR[11] A[9] SDA10 A[10] ADDR[14:13] A[12:11] ADDR[16] BA0 ADDR[17] BA1 NCS[1] SDCS[0] NWE1 DQM1 SDCK CLK SDCKE CKE 302 32117A-10/2010 AT32UC3C Table 17-5. EBI Pins and External Devices Connections (Continued) Pins of the Interfaced Device Pins name SDRAM Controller SDRAMC RAS RAS CAS CAS SDWE WE 303 32117A-10/2010 AT32UC3C 17.7.2 Connection Examples Figure 17-2 on page 304shows an example of connections between the EBI and external devices. Figure 17-2. EBI Connections to Memory Devices EBI DATA[15:0] RAS CAS SDCK SDCKE SDWE ADDR[0] NWE1 NRD NWE0 DATA[7:0] SDCK SDCKE SDWE RAS CAS ADDR[0] SDRAM 2Mx8 DATA[15:8] D[7:0] CS CLK CKE WE RAS CAS DQM A[9:0] A[10] A[11] BA0 BA1 ADDR[11:2] SDA10 ADDR[13] ADDR[16] ADDR[17] SDCK SDCKE SDWE RAS CAS NWE1 SDRAM 2Mx8 D[7:0] CS CLK CKE WE RAS CAS DQM A[9:0] A[10] A[11] BA0 BA1 ADDR[11:2] SDA10 ADDR[13] ADDR[16] ADDR[17] SDA10 ADDR[17:1] SDCS or NCS[1] SRAM 128Kx8 D[7:0] NCS[0] NRD NWE0 DATA[15:8] DATA[7:0] NCS[0] CS OE WE A[16:0] SRAM 128Kx8 D[7:0] ADDR[17:1] NCS[0] NRD NWE1 A[16:0] ADDR[17:1] CS OE WE 304 32117A-10/2010 AT32UC3C 18. Static Memory Controller (SMC) Rev. 1.0.6.5 18.1 Features * * * * * * * * * * * * 18.2 4 chip selects available 16-Mbytes address space per chip select 8- or 16-bit data bus Word, halfword, byte transfers Byte write or byte select lines Programmable setup, pulse and hold time for read signals per chip select Programmable setup, pulse and hold time for write signals per chip select Programmable data float time per chip select Compliant with LCD module External wait request Automatic switch to slow clock mode Asynchronous read in page mode supported: page size ranges from 4 to 32 bytes Overview The Static Memory Controller (SMC) generates the signals that control the access to the external memory devices or peripheral devices. It has 4 chip selects and a 24-bit address bus. The 16-bit data bus can be configured to interface with 8-16-bit external devices. Separate read and write control signals allow for direct memory and peripheral interfacing. Read and write signal waveforms are fully parametrizable. The SMC can manage wait requests from external devices to extend the current access. The SMC is provided with an automatic slow clock mode. In slow clock mode, it switches from userprogrammed waveforms to slow-rate specific waveforms on read and write signals. The SMC supports asynchronous burst read in page mode access for page size up to 32 bytes. 305 32117A-10/2010 AT32UC3C 18.3 Block Diagram Figure 18-1. SMC Block Diagram (AD_MSB=23) NCS[5:0] HMatrix NCS[5:0] NRD SMC Chip Select NRD NWR0/NWE NWE0 A0/NBS0 ADDR[0] NWR1/NBS1 SMC Power Manager A1/NWR2/NBS2 CLK_SMC NWE1 EBI Mux Logic A[AD_MSB:2] D[15:0] NWAIT I/O Controller ADDR[1] ADDR[AD_MSB:2] DATA[15:0] NWAIT User Interface Peripheral Bus 18.4 I/O Lines Description Table 18-1. 18.5 I/O Lines Description Pin Name Pin Description Type Active Level NCS[3:0] Chip Select Lines Output Low NRD Read Signal Output Low NWR0/NWE Write 0/Write Enable Signal Output Low A0/NBS0 Address Bit 0/Byte 0 Select Signal Output Low NWR1/NBS1 Write 1/Byte 1 Select Signal Output Low A[23:2] Address Bus Output D[15:0] Data Bus NWAIT External Wait Signal Input/Output Input Low Product Dependencies In order to use this module, other parts of the system must be configured correctly, as described below. 306 32117A-10/2010 AT32UC3C 18.5.1 I/O Lines The SMC signals pass through the External Bus Interface (EBI) module where they are multiplexed. The user must first configure the I/O Controller to assign the EBI pins corresponding to SMC signals to their peripheral function. If the I/O lines of the EBI corresponding to SMC signals are not used by the application, they can be used for other purposes by the I/O Controller. 18.5.2 Clocks The clock for the SMC bus interface (CLK_SMC) is generated by the Power Manager. This clock is enabled at reset, and can be disabled in the Power Manager. It is recommended to disable the SMC before disabling the clock, to avoid freezing the SMC in an undefined state. 18.6 18.6.1 Functional Description Application Example Figure 18-2. SMC Connections to Static Memory Devices D0-D15 A0/NBS0 NWR0/NWE NWR1/NBS1 D0-D7 128K x 8 SRAM D8-D15 D0-D7 A0-A16 NRD NWR0/NWE OE WE D0-D7 CS CS NCS0 NCS1 NCS2 NCS3 NCS4 NCS5 128K x 8 SRAM A2-A18 A0-A16 NRD NWR1/NBS1 A2-A18 OE WE Static Memory Controller A2-A18 18.6.2 External Memory Mapping The SMC provides up to 24 address lines, A[23:0]. This allows each chip select line to address up to 16Mbytes of memory. If the physical memory device connected on one chip select is smaller than 16Mbytes, it wraps around and appears to be repeated within this space. The SMC correctly handles any valid access to the memory device within the page (see Figure 18-3 on page 308). A[23:0] is only significant for 8-bit memory, A[23:1] is used for 16-bit memory23. 307 32117A-10/2010 AT32UC3C Figure 18-3. Memory Connections for Six External Devices NCS[0] - NCS[5] NRD SMC NWE NCS5 A[AD_MSB:0] NCS4 D[15:0] NCS3 NCS2 NCS1 NCS0 Memory Enable Memory Enable Memory Enable Memory Enable Memory Enable Memory Enable Output Enable Write Enable 8 or 16 18.6.3 A[AD_MSB:0] D[15:0] or D[7:0] Connection to External Devices 18.6.3.1 Data bus width A data bus width of 8 or 16 bits can be selected for each chip select. This option is controlled by the Data Bus Width field in the Mode Register (MODE.DBW) for the corresponding chip select. Figure 18-4 on page 308 shows how to connect a 512K x 8-bit memory on NCS2. Figure 18-5 on page 309 shows how to connect a 512K x 16-bit memory on NCS2. 18.6.3.2 Byte write or byte select access Each chip select with a 16-bit data bus can operate with one of two different types of write access: byte write or byte select access. This is controlled by the Byte Access Type bit in the MODE register (MODE.BAT) for the corresponding chip select. Figure 18-4. Memory Connection for an 8-bit Data Bus SMC D[7:0] D[7:0] A[18:2] A[18:2] A0 A0 A1 A1 NWE Write Enable NRD Output Enable NCS[2] Memory Enable 308 32117A-10/2010 AT32UC3C Figure 18-5. Memory Connection for a 16-bit Data Bus D[15:0] D[15:0] A[19:2] A[18:1] A1 SMC A[0] NBS0 Low Byte Enable NBS1 High Byte Enable NWE Write Enable NRD Output Enable NCS[2] Memory Enable *Byte write access The byte write access mode supports one byte write signal per byte of the data bus and a single read signal. Note that the SMC does not allow boot in byte write access mode. * For 16-bit devices: the SMC provides NWR0 and NWR1 write signals for respectively byte0 (lower byte) and byte1 (upper byte) of a 16-bit bus. One single read signal (NRD) is provided. The byte write access mode is used to connect two 8-bit devices as a 16-bit memory. The byte write option is illustrated on Figure 18-6 on page 310. *Byte select access In this mode, read/write operations can be enabled/disabled at a byte level. One byte select line per byte of the data bus is provided. One NRD and one NWE signal control read and write. * For 16-bit devices: the SMC provides NBS0 and NBS1 selection signals for respectively byte0 (lower byte) and byte1 (upper byte) of a 16-bit bus. The byte select access is used to connect one 16-bit device. 309 32117A-10/2010 AT32UC3C Figure 18-6. Connection of two 8-bit Devices on a 16-bit Bus: Byte Write Option D[7:0] D[7:0] D[15:8] A[24:2] SMC A[23:1] A[0] A1 NWR0 Write Enable NWR1 NRD Read Enable Memory Enable NCS[3] D[15:8] A[23:1] A[0] Write Enable Read Enable Memory Enable *Signal multiplexing Depending on the MODE.BAT bit, only the write signals or the byte select signals are used. To save I/Os at the external bus interface, control signals at the SMC interface are multiplexed. For 16-bit devices, bit A0 of address is unused. When byte select option is selected, NWR1 is unused. When byte write option is selected, NBS0 to NBS1 are unused. Table 18-3. SMC Multiplexed Signal Translation Signal Name Device Type Byte Access Type (BAT) 8-bit Bus 1 x 16-bit 2 x 8-bit Byte Select Byte Write NBS0_A0 NBS0 NWE_NWR0 NWE NWR0 NBS1_NWR1 NBS1 NWR1 A1 A1 NBS2_NWR2_A1 18.6.4 16-bit Bus 1 x 8-bit A0 NWE A1 Standard Read and Write Protocols In the following sections, the byte access type is not considered. Byte select lines (NBS0 to NBS1) always have the same timing as the address bus (A). NWE represents either the NWE signal in byte select access type or one of the byte write lines (NWR0 to NWR1) in byte write 310 32117A-10/2010 AT32UC3C access type. NWR0 to NWR1 have the same timings and protocol as NWE. In the same way, NCS represents one of the NCS[0..3] chip select lines. 18.6.4.1 Read waveforms The read cycle is shown on Figure 18-7 on page 311. The read cycle starts with the address setting on the memory address bus, i.e.: {A[23:2], A1, A0} for 8-bit devices {A[23:2], A1} for 16-bit devices Figure 18-7. Standard Read Cycle CLK_SMC A[AD_MSB:2] NBS0, NBS1, A0, A1 NRD NCS D[15:0] NRDSETUP NCSRDSETUP NRDPULSE NCSRDPULSE NRDHOLD NCSRDHOLD NRDCYCLE *NRD waveform The NRD signal is characterized by a setup timing, a pulse width, and a hold timing. 1. NRDSETUP: the NRD setup time is defined as the setup of address before the NRD falling edge. 2. NRDPULSE: the NRD pulse length is the time between NRD falling edge and NRD rising edge. 3. NRDHOLD: the NRD hold time is defined as the hold time of address after the NRD rising edge. *NCS waveform Similarly, the NCS signal can be divided into a setup time, pulse length and hold time. 311 32117A-10/2010 AT32UC3C 1. NCSRDSETUP: the NCS setup time is defined as the setup time of address before the NCS falling edge. 2. NCSRDPULSE: the NCS pulse length is the time between NCS falling edge and NCS rising edge. 3. NCSRDHOLD: the NCS hold time is defined as the hold time of address after the NCS rising edge. *Read cycle The NRDCYCLE time is defined as the total duration of the read cycle, i.e., from the time where address is set on the address bus to the point where address may change. The total read cycle time is equal to: NRDCYCLE = NRDSETUP + NRDPULSE + NRDHOLD Similarly, NRDCYCLE = NCSRDSETUP + NCSRDPULSE + NCSRDHOLD All NRD and NCS timings are defined separately for each chip select as an integer number of CLK_SMC cycles. To ensure that the NRD and NCS timings are coherent, the user must define the total read cycle instead of the hold timing. NRDCYCLE implicitly defines the NRD hold time and NCS hold time as: NRDHOLD = NRDCYCLE - NRDSETUP - NRDPULSE And, NCSRDHOLD = NRDCYCLE - NCSRDSETUP - NCSRDPULSE *Null delay setup and hold If null setup and hold parameters are programmed for NRD and/or NCS, NRD and NCS remain active continuously in case of consecutive read cycles in the same memory (see Figure 18-8 on page 313). 312 32117A-10/2010 AT32UC3C Figure 18-8. No Setup, No Hold on NRD, and NCS Read Signals CLK_SMC A[AD_MSB:2] NBS0, NBS1, A0, A1 NRD NCS D[15:0] NRDSETUP NRDPULSE NRDPULSE NCSRDPULSE NCSRDPULSE NCSRDPULSE NRDCYCLE NRDCYCLE NRDCYCLE * Null Pulse Programming null pulse is not permitted. Pulse must be at least written to one. A null value leads to unpredictable behavior. 18.6.4.2 Read mode As NCS and NRD waveforms are defined independently of one other, the SMC needs to know when the read data is available on the data bus. The SMC does not compare NCS and NRD timi n g s t o k n o w w h i c h s ig n a l r i s e s f i r s t . T h e R e a d M o d e b it i n t h e M O D E r e g i s t e r (MODE.READMODE) of the corresponding chip select indicates which signal of NRD and NCS controls the read operation. *Read is controlled by NRD (MODE.READMODE = 1) Figure 18-9 on page 314 shows the waveforms of a read operation of a typical asynchronous RAM. The read data is available tPACC after the falling edge of NRD, and turns to `Z' after the rising edge of NRD. In this case, the MODE.READMODE bit must be written to one (read is controlled by NRD), to indicate that data is available with the rising edge of NRD. The SMC samples the read data internally on the rising edge of CLK_SMC that generates the rising edge of NRD, whatever the programmed waveform of NCS may be. 313 32117A-10/2010 AT32UC3C Figure 18-9. READMODE = 1: Data Is Sampled by SMC Before the Rising Edge of NRD CLK_SMC A[AD_MSB:2] NBS0, NBS1, A0, A1 NRD NCS tPACC D[15:0] Data Sampling *Read is controlled by NCS (MODE.READMODE = 0) Figure 18-10 on page 315 shows the typical read cycle of an LCD module. The read data is valid tPACC after the falling edge of the NCS signal and remains valid until the rising edge of NCS. Data must be sampled when NCS is raised. In that case, the MODE.READMODE bit must be written to zero (read is controlled by NCS): the SMC internally samples the data on the rising edge of CML_SMC that generates the rising edge of NCS, whatever the programmed waveform of NRD may be. 314 32117A-10/2010 AT32UC3C Figure 18-10. READMODE = 0: Data Is Sampled by SMC Before the Rising Edge of NCS CLK_SMC A[AD_MSB:2] NBS0, NBS1, A0, A1 NRD NCS tPACC D[15:0] Data Sampling 18.6.4.3 Write waveforms The write protocol is similar to the read protocol. It is depicted in Figure 18-11 on page 316. The write cycle starts with the address setting on the memory address bus. *NWE waveforms The NWE signal is characterized by a setup timing, a pulse width and a hold timing. 1. NWESETUP: the NWE setup time is defined as the setup of address and data before the NWE falling edge. 2. NWEPULSE: the NWE pulse length is the time between NWE falling edge and NWE rising edge. 3. NWEHOLD: the NWE hold time is defined as the hold time of address and data after the NWE rising edge. The NWE waveforms apply to all byte-write lines in byte write access mode: NWR0 to NWR3. 18.6.4.4 NCS waveforms The NCS signal waveforms in write operation are not the same that those applied in read operations, but are separately defined. 1. NCSWRSETUP: the NCS setup time is defined as the setup time of address before the NCS falling edge. 2. NCSWRPULSE: the NCS pulse length is the time between NCS falling edge and NCS rising edge; 3. NCSWRHOLD: the NCS hold time is defined as the hold time of address after the NCS rising edge. 315 32117A-10/2010 AT32UC3C Figure 18-11. Write Cycle CLK_SMC A[AD_MSB:2] NBS0, NBS1, A0, A1 NWE NCS NWESETUP NCSWRSETUP NWEPULSE NCSWRPULSE NWEHOLD NCSWRHOLD NWECYCLE *Write cycle The write cycle time is defined as the total duration of the write cycle, that is, from the time where address is set on the address bus to the point where address may change. The total write cycle time is equal to: NWECYCLE = NWESETUP + NWEPULSE + NWEHOLD Similarly, NWECYCLE = NCSWRSETUP + NCSWRPULSE + NCSWRHOLD All NWE and NCS (write) timings are defined separately for each chip select as an integer number of CLK_SMC cycles. To ensure that the NWE and NCS timings are coherent, the user must define the total write cycle instead of the hold timing. This implicitly defines the NWE hold time and NCS (write) hold times as: NWEHOLD = NWECYCLE - NWESETUP - NWEPULSE And, NCSWRHOLD = NWECYCLE - NCSWRSETUP - NCSWRPULSE 316 32117A-10/2010 AT32UC3C *Null delay setup and hold If null setup parameters are programmed for NWE and/or NCS, NWE and/or NCS remain active continuously in case of consecutive write cycles in the same memory (see Figure 18-12 on page 317). However, for devices that perform write operations on the rising edge of NWE or NCS, such as SRAM, either a setup or a hold must be programmed. Figure 18-12. Null Setup and Hold Values of NCS and NWE in Write Cycle CLK_SMC A[AD_MSB:2] NBS0, NBS1, A0, A1 NWE, NWE0, NWE1 NCS D[15:0] NWESETUP NWEPULSE NWEPULSE NCSWRSETUP NCSWRPULSE NCSWRPULSE NWECYCLE NWECYCLE NWECYCLE *Null pulse Programming null pulse is not permitted. Pulse must be at least written to one. A null value leads to unpredictable behavior. 18.6.4.5 Write mode The Write Mode bit in the MODE register (MODE.WRITEMODE) of the corresponding chip select indicates which signal controls the write operation. *Write is controlled by NWE (MODE.WRITEMODE = 1) Figure 18-13 on page 318 shows the waveforms of a write operation with MODE.WRITEMODE equal to one. The data is put on the bus during the pulse and hold steps of the NWE signal. The internal data buffers are turned out after the NWESETUP time, and until the end of the write cycle, regardless of the programmed waveform on NCS. 317 32117A-10/2010 AT32UC3C Figure 18-13. WRITEMODE = 1. The Write Operation Is Controlled by NWE CLK_SMC A[AD_MSB:2] NBS0, NBS1, A0, A1 NWE, NWR0, NWR1 NCS D[15:0] *Write is controlled by NCS (MODE.WRITEMODE = 0) Figure 18-14 on page 318 shows the waveforms of a write operation with MODE.WRITEMODE written to zero. The data is put on the bus during the pulse and hold steps of the NCS signal. The internal data buffers are turned out after the NCSWRSETUP time, and until the end of the write cycle, regardless of the programmed waveform on NWE. Figure 18-14. WRITEMODE = 0. The Write Operation Is Controlled by NCS CLK_SMC A[AD_MSB:2] NBS0, NBS1, A0, A1 NWE, NWR0, NWR1 NCS D[15:0] 318 32117A-10/2010 AT32UC3C 18.6.4.6 Coding timing parameters All timing parameters are defined for one chip select and are grouped together in one register according to their type. The Setup register (SETUP) groups the definition of all setup parameters: * NRDSETUP, NCSRDSETUP, NWESETUP, and NCSWRSETUP. The Pulse register (PULSE) groups the definition of all pulse parameters: * NRDPULSE, NCSRDPULSE, NWEPULSE, and NCSWRPULSE. The Cycle register (CYCLE) groups the definition of all cycle parameters: * NRDCYCLE, NWECYCLE. Table 18-4 on page 319 shows how the timing parameters are coded and their permitted range. Table 18-4. Coding and Range of Timing Parameters Permitted Range Coded Value Number of Bits Effective Value Coded Value Effective Value setup [5:0] 6 128 x setup[5] + setup[4:0] 0 value 31 32 value 63 0 value 31 128 value 128+31 pulse [6:0] 7 256 x pulse[6] + pulse[5:0] 0 value 63 64 value 127 0 value 63 256 value 256+63 256 x cycle[8:7] + cycle[6:0] 0 value 127 128 value 255 256 value 383 384 value 511 0 value 127 256 value 256+127 512 value 512+127 768 value 768+127 cycle [8:0] 18.6.4.7 9 Usage restriction The SMC does not check the validity of the user-programmed parameters. If the sum of SETUP and PULSE parameters is larger than the corresponding CYCLE parameter, this leads to unpredictable behavior of the SMC. For read operations: Null but positive setup and hold of address and NRD and/or NCS can not be guaranteed at the memory interface because of the propagation delay of theses signals through external logic and pads. If positive setup and hold values must be verified, then it is strictly recommended to program non-null values so as to cover possible skews between address, NCS and NRD signals. For write operations: If a null hold value is programmed on NWE, the SMC can guarantee a positive hold of address, byte select lines, and NCS signal after the rising edge of NWE. This is true if the MODE.WRITEMODE bit is written to one. See Section 18.6.5.2. For read and write operations: a null value for pulse parameters is forbidden and may lead to unpredictable behavior. In read and write cycles, the setup and hold time parameters are defined in reference to the address bus. For external devices that require setup and hold time between NCS and NRD signals (read), or between NCS and NWE signals (write), these setup and hold times must be converted into setup and hold times in reference to the address bus. 319 32117A-10/2010 AT32UC3C 18.6.5 Automatic Wait States Under certain circumstances, the SMC automatically inserts idle cycles between accesses to avoid bus contention or operation conflict. 18.6.5.1 Chip select wait states The SMC always inserts an idle cycle between two transfers on separate chip selects. This idle cycle ensures that there is no bus contention between the deactivation of one device and the activation of the next one. During chip select wait state, all control lines are turned inactive: NBS0 to NBS3, NWR0 to NWR3, NCS[0..5], NRD lines are all set to high level. Figure 18-15 on page 320 illustrates a chip select wait state between access on Chip Select 0 (NCS0) and Chip Select 2 (NCS2). Figure 18-15. Chip Select Wait State Between a Read Access on NCS0 and a Write Access on NCS2 CLK_SMC _MSB:2] , NBS1, , A1 NRD NWE NCS0 NCS2 NRDCYCLE NWECYCLE D[15:0] Read to Write Wait State 18.6.5.2 Chip Select Wait State Early read wait state In some cases, the SMC inserts a wait state cycle between a write access and a read access to allow time for the write cycle to end before the subsequent read cycle begins. This wait state is not generated in addition to a chip select wait state. The early read cycle thus only occurs between a write and read access to the same memory device (same chip select). 320 32117A-10/2010 AT32UC3C An early read wait state is automatically inserted if at least one of the following conditions is valid: * if the write controlling signal has no hold time and the read controlling signal has no setup time (Figure 18-16 on page 321). * in NCS write controlled mode (MODE.WRITEMODE = 0), if there is no hold timing on the NCS signal and the NCSRDSETUP parameter is set to zero, regardless of the read mode (Figure 18-17 on page 322). The write operation must end with a NCS rising edge. Without an early read wait state, the write operation could not complete properly. * in NWE controlled mode (MODE.WRITEMODE = 1) and if there is no hold timing (NWEHOLD = 0), the feedback of the write control signal is used to control address, data, chip select, and byte select lines. If the external write control signal is not inactivated as expected due to load capacitances, an early read wait state is inserted and address, data and control signals are maintained one more cycle. See Figure 18-18 on page 323. Figure 18-16. Early Read Wait State: Write with No Hold Followed by Read with No Setup. CLK_SMC A[AD_MSB:2] NBS0, NBS1, A0, A1 NWE NRD No hold No setup D[15:0] Write cycle Early Read Wait state Read cycle 321 32117A-10/2010 AT32UC3C Figure 18-17. Early Read Wait State: NCS Controlled Write with No Hold Followed by a Read with No Setup. CLK_SMC A[AD_MSB:2] NBS0, NBS1, A0, A1 NWE NRD No hold No setup D[15:0] Write cycle (WRITEMODE=0) Read cycle Early Read Wait State (READMODE=0 or READMODE=1) 322 32117A-10/2010 AT32UC3C Figure 18-18. Early Read Wait State: NWE-controlled Write with No Hold Followed by a Read with one Set-up Cycle. CLK_SMC A[AD_MSB:2] NBS0, NBS1, A0, A1 Internal write controlling signal external write controlling signal(NWE) No hold Read setup=1 NRD D[15:0] Write cycle (WRITEMODE = 1) 18.6.5.3 Early Read Wait State Read cycle (READMODE=0 or READMODE=1) Reload user configuration wait state The user may change any of the configuration parameters by writing the SMC user interface. When detecting that a new user configuration has been written in the user interface, the SMC inserts a wait state before starting the next access. The so called "reload user configuration wait state" is used by the SMC to load the new set of parameters to apply to next accesses. The reload configuration wait state is not applied in addition to the chip select wait state. If accesses before and after reprogramming the user interface are made to different devices (different chip selects), then one single chip select wait state is applied. On the other hand, if accesses before and after writing the user interface are made to the same device, a reload configuration wait state is inserted, even if the change does not concern the current chip select. *User procedure To insert a reload configuration wait state, the SMC detects a write access to any MODE register of the user interface. If the user only modifies timing registers (SETUP, PULSE, CYCLE registers) in the user interface, he must validate the modification by writing the MODE register, even if no change was made on the mode parameters. 323 32117A-10/2010 AT32UC3C *Slow clock mode transition A reload configuration wait state is also inserted when the slow clock mode is entered or exited, after the end of the current transfer (see Section 18.6.8). 18.6.5.4 Read to write wait state Due to an internal mechanism, a wait cycle is always inserted between consecutive read and write SMC accesses. This wait cycle is referred to as a read to write wait state in this document. This wait cycle is applied in addition to chip select and reload user configuration wait states when they are to be inserted. See Figure 18-15 on page 320. 18.6.6 Data Float Wait States Some memory devices are slow to release the external bus. For such devices, it is necessary to add wait states (data float wait states) after a read access: * before starting a read access to a different external memory. * before starting a write access to the same device or to a different external one. The Data Float Output Time (tDF) for each external memory device is programmed in the Data Float Time field of the MODE register (MODE.TDFCYCLES) for the corresponding chip select. The value of MODE.TDFCYCLES indicates the number of data float wait cycles (between 0 and 15) before the external device releases the bus, and represents the time allowed for the data output to go to high impedance after the memory is disabled. Data float wait states do not delay internal memory accesses. Hence, a single access to an external memory with long t DF will not slow down the execution of a program from internal memory. The data float wait states management depends on the MODE.READMODE bit and the TDF Optimization bit of the MODE register (MODE.TDFMODE) for the corresponding chip select. 18.6.6.1 Read mode Writing a one to the MODE.READMODE bit indicates to the SMC that the NRD signal is responsible for turning off the tri-state buffers of the external memory device. The data float period then begins after the rising edge of the NRD signal and lasts MODE.TDFCYCLES cycles of the CLK_SMC clock. When the read operation is controlled by the NCS signal (MODE.READMODE = 0), the MODE.TDFCYCLES field gives the number of CLK_SMC cycles during which the data bus remains busy after the rising edge of NCS. Figure 18-19 on page 325 illustrates the data float period in NRD-controlled mode (MODE.READMODE =1), assuming a data float period of two cycles (MODE.TDFCYCLES = 2). Figure 18-20 on page 325 shows the read operation when controlled by NCS (MODE.READMODE = 0) and the MODE.TDFCYCLES field equals to three. 324 32117A-10/2010 AT32UC3C Figure 18-19. TDF Period in NRD Controlled Read Access (TDFCYCLES = 2) CLK_SMC A[AD_MSB:2] NBS0, NBS1, A0, A1 NRD NCS D[15:0] tPACC TDF = 2 clock cycles NRD controlled read operation Figure 18-20. TDF Period in NCS Controlled Read Operation (TDFCYCLES = 3) CLK_SMC A[AD_MSB:2] NBS0, NBS1, A0, A1 NRD NCS D[15:0] tPACC TDF = 3 clock cycles NCS controlled read operation 325 32117A-10/2010 AT32UC3C 18.6.6.2 TDF optimization enabled (MODE.TDFMODE = 1) When the MODE.TDFMODE bit is written to one (TDF optimization is enabled), the SMC takes advantage of the setup period of the next access to optimize the number of wait states cycle to insert. Figure 18-21 on page 326 shows a read access controlled by NRD, followed by a write access controlled by NWE, on Chip Select 0. Chip Select 0 has been programmed with: NRDHOLD = 4; READMODE = 1 (NRD controlled) NWESETUP = 3; WRITEMODE = 1 (NWE controlled) TDFCYCLES = 6; TDFMODE = 1 (optimization enabled). Figure 18-21. TDF Optimization: No TDF Wait States Are Inserted if the TDF Period Is over when the Next Access Begins CLK_SMC A[AD_MSB:2] NRD NRDHOLD = 4 NWE NWESETUP = 3 NCS0 TDFCYCLES = 6 D[15:0] Read access on NCS0 (NRD controlled) 18.6.6.3 Read to Write Wait State Write access on NCS0 (NWE controlled) TDF optimization disabled (MODE.TDFMODE = 0) When optimization is disabled, data float wait states are inserted at the end of the read transfer, so that the data float period is ended when the second access begins. If the hold period of the read1 controlling signal overlaps the data float period, no additional data float wait states will be inserted. Figure 18-22 on page 327, Figure 18-23 on page 327 and Figure 18-24 on page 328 illustrate the cases: * read access followed by a read access on another chip select. * read access followed by a write access on another chip select. 326 32117A-10/2010 AT32UC3C * read access followed by a write access on the same chip select. with no TDF optimization. Figure 18-22. TDF Optimization Disabled (MODE.TDFMODE = 0). TDF Wait States between Two Read Accesses on Different Chip Selects. CLK_SMC A[AD_MSB:2] NBS0, NBS1, A0, A1 Read1 controlling signal(NRD) Read1 hold = 1 Read2 controlling signal(NRD) Read2 setup = 1 TDFCYCLES = 6 D[15:0] 5 TDF WAIT STATES Read 2 cycle TDFMODE=0 (optimization disabled) Read1 cycle TDFCYCLES = 6 Chip Select Wait State Figure 18-23. TDF Optimization Disabled (MODE.TDFMODE= 0). TDF Wait States between a Read and a Write Access on Different Chip Selects. CLK_SMC A[AD_MSB:2] NBS0, NBS1, A0, A1 Read1 controlling signal(NRD) Read1 hold = 1 Write2 controlling signal(NWE) Write2 setup = 1 TDFCYCLES = 4 D[15:0] Read1 cycle TDFCYCLES = 4 2 TDF WAIT STATES Read to Write Chip Select Wait State Wait State Write 2 cycle TDFMODE=0 (optimization disabled) 327 32117A-10/2010 AT32UC3C Figure 18-24. TDF Optimization Disabled (MODE.TDFMODE = 0). TDF Wait States between Read and Write accesses on the Same Chip Select. CLK_SMC A[AD_MSB:2] NBS0, NBS1, A0, A1 Read1 controlling signal(NRD) Write2 setup = 1 Read1 hold = 1 Write2 controlling signal(NWE) TDFCYCLES = 5 D[15:0] 4 TDF WAIT STATES Read1 cycle TDFCYCLES = 5 18.6.7 Read to Write Wait State Write 2 cycle TDFMODE=0 (optimization disabled) External Wait Any access can be extended by an external device using the NWAIT input signal of the SMC. The External Wait Mode field of the MODE register (MODE.EXNWMODE) on the corresponding chip select must be written to either two (frozen mode) or three (ready mode). When the MODE.EXNWMODE field is written to zero (disabled), the NWAIT signal is simply ignored on the corresponding chip select. The NWAIT signal delays the read or write operation in regards to the read or write controlling signal, depending on the read and write modes of the corresponding chip select. 18.6.7.1 Restriction When one of the MODE.EXNWMODE is enabled, it is mandatory to program at least one hold cycle for the read/write controlling signal. For that reason, the NWAIT signal cannot be used in Page Mode (Section 18.6.9), or in Slow Clock Mode (Section 18.6.8). The NWAIT signal is assumed to be a response of the external device to the read/write request of the SMC. Then NWAIT is examined by the SMC only in the pulse state of the read or write controlling signal. The assertion of the NWAIT signal outside the expected period has no impact on SMC behavior. 18.6.7.2 Frozen mode When the external device asserts the NWAIT signal (active low), and after internal synchronization of this signal, the SMC state is frozen, i.e., SMC internal counters are frozen, and all control signals remain unchanged. When the synchronized NWAIT signal is deasserted, the SMC completes the access, resuming the access from the point where it was stopped. See Figure 18-25 on page 329. This mode must be selected when the external device uses the NWAIT signal to delay the access and to freeze the SMC. 328 32117A-10/2010 AT32UC3C The assertion of the NWAIT signal outside the expected period is ignored as illustrated in Figure 18-26 on page 330. Figure 18-25. Write Access with NWAIT Assertion in Frozen Mode (MODE.EXNWMODE = 2). CLK_SMC A[AD_MSB:2] NBS0, NBS1, A0, A1 FROZEN STATE 4 3 2 1 1 1 1 3 2 2 2 2 0 NWE 6 5 4 0 NCS D[15:0] NWAIT Internally synchronized NWAIT signal Write cycle EXNWMODE = 2 (Frozen) WRITEMODE = 1 (NWE controlled) NWEPULSE = 5 NCSWRPULSE = 7 329 32117A-10/2010 AT32UC3C Figure 18-26. Read Access with NWAIT Assertion in Frozen Mode (MODE.EXNWMODE = 2). CLK_SMC A[AD_MSB:2] NBS0, NBS1, A0, A1 FROZEN STATE NCS 4 1 NRD 3 2 2 2 1 0 2 1 0 2 1 0 0 5 5 5 4 3 NWAIT Internally synchronized NWAIT signal Read cycle EXNWMODE = 2 (Frozen) READMODE = 0 (NCS controlled) NRDPULSE = 2, NRDHOLD = 6 NCSRDPULSE = 5, NCSRDHOLD = 3 Assertion is ignored 330 32117A-10/2010 AT32UC3C 18.6.7.3 Ready mode In Ready mode (MODE.EXNWMODE = 3), the SMC behaves differently. Normally, the SMC begins the access by down counting the setup and pulse counters of the read/write controlling signal. In the last cycle of the pulse phase, the resynchronized NWAIT signal is examined. If asserted, the SMC suspends the access as shown in Figure 18-27 on page 331 and Figure 18-28 on page 332. After deassertion, the access is completed: the hold step of the access is performed. This mode must be selected when the external device uses deassertion of the NWAIT signal to indicate its ability to complete the read or write operation. If the NWAIT signal is deasserted before the end of the pulse, or asserted after the end of the pulse of the controlling read/write signal, it has no impact on the access length as shown in Figure 18-28 on page 332. Figure 18-27. NWAIT Assertion in Write Access: Ready Mode (MODE.EXNWMODE = 3). CLK _SM C A [A D _ M S B :2 ] NBS 0, NBS 1, A0, A1 FRO ZEN STATE 4 3 2 1 0 2 1 0 0 NW E 6 5 4 3 1 1 0 NCS D [1 5 :0 ] N W A IT In te rn a lly s y n c h ro n iz e d N W A IT s ig n a l W rite c y c le E X N W M O D E = 3 (R e a d y m o d e ) W R IT E M O D E = 1 (N W E _ c o n tro lle d ) NW EPULSE = 5 NCSW RPULSE = 7 331 32117A-10/2010 AT32UC3C Figure 18-28. NWAIT Assertion in Read Access: Ready Mode (EXNWMODE = 3). CLK_SMC A[AD_MSB:2] NBS0, NBS1, A0, A1 Wait STATE NCS NRD 6 5 4 3 2 6 5 4 3 1 2 0 0 1 1 0 NWAIT Internally synchronized NWAIT signal Read cycle Assertion is ignored EXNWMODE = 3 (Ready mode) READMODE = 0 (NCS_controlled) NRDPULSE = 7 NCSRDPULSE = 7 Assertion is ignored 332 32117A-10/2010 AT32UC3C 18.6.7.4 NWAIT latency and read/write timings There may be a latency between the assertion of the read/write controlling signal and the assertion of the NWAIT signal by the device. The programmed pulse length of the read/write controlling signal must be at least equal to this latency plus the two cycles of resynchronization plus one cycle. Otherwise, the SMC may enter the hold state of the access without detecting the NWAIT signal assertion. This is true in frozen mode as well as in ready mode. This is illustrated on Figure 18-29 on page 333. When the MODE.EXNWMODE field is enabled (ready or frozen), the user must program a pulse length of the read and write controlling signal of at least: minimal pulse length = NWAIT latency + 2 synchronization cycles + 1 cycle Figure 18-29. NWAIT Latency CLK_SMC A[AD_MSB:2] NBS0, NBS1, A0, A1 Wait STATE 4 3 2 1 0 0 0 NRD Minimal pulse length NWAIT nternally synchronized NWAIT signal NWAIT latency 2 cycle resynchronization Read cycle EXNWMODE = 2 or 3 READMODE = 1 (NRD controlled) NRDPULSE = 5 333 32117A-10/2010 AT32UC3C 18.6.8 Slow Clock Mode The SMC is able to automatically apply a set of "slow clock mode" read/write waveforms when an internal signal driven by the SMC's Power Management Controller is asserted because CLK_SMC has been turned to a very slow clock rate (typically 32 kHz clock rate). In this mode, the user-programmed waveforms are ignored and the slow clock mode waveforms are applied. This mode is provided so as to avoid reprogramming the User Interface with appropriate waveforms at very slow clock rate. When activated, the slow mode is active on all chip selects. 18.6.8.1 Slow clock mode waveforms Figure 18-30 on page 334 illustrates the read and write operations in slow clock mode. They are valid on all chip selects. Table 18-5 on page 334 indicates the value of read and write parameters in slow clock mode. Figure 18-30. Read and Write Cycles in Slow Clock Mode CLK_SMC CLK_SMC A[AD_MSB:2] A[AD_MSB:2] NBS0, NBS1, A0, A1 NWE NBS0, NBS1, A0, A1 1 NRD 1 1 1 1 NCS NCS NRDCYCLES = 2 NWECYCLES = 3 SLOW CLOCK MODE WRITE Table 18-5. SLOW CLOCK MODE READ Read and Write Timing Parameters in Slow Clock Mode Read Parameters Duration (cycles) Write Parameters Duration (cycles) NRDSETUP 1 NWESETUP 1 NRDPULSE 1 NWEPULSE 1 NCSRDSETUP 0 NCSWRSETUP 0 NCSRDPULSE 2 NCSWRPULSE 3 NRDCYCLE 2 NWECYCLE 3 334 32117A-10/2010 AT32UC3C 18.6.8.2 Switching from (to) slow clock mode to (from) normal mode When switching from slow clock mode to the normal mode, the current slow clock mode transfer is completed at high clock rate, with the set of slow clock mode parameters. See Figure 18-31 on page 335. The external device may not be fast enough to support such timings. Figure 18-32 on page 336 illustrates the recommended procedure to properly switch from one mode to the other. Figure 18-31. Clock Rate Transition Occurs while the SMC is Performing a Write Operation Slow Clock Mode Internal signal from PM CLK_SMC A[AD_MSB:2] NBS0, NBS1, A0, A1 NWE 1 1 1 1 1 1 2 3 2 NCS NWECYCLE = 3 NWECYCLE = 7 SLOW CLOCK MODE WRITE SLOW CLOCK MODE WRITE This write cycle finishes with the slow clock mode set of parameters after the clock rate transition NORMAL MODE WRITE Slow clock mode transition is detected: Reload Configuration Wait State 335 32117A-10/2010 AT32UC3C Figure 18-32. Recommended Procedure to Switch from Slow Clock Mode to Normal Mode or from Normal Mode to Slow Clock Mode Slow Clock Mode Internal signal from PM CLK_SMC A[AD_MSB:2] NBS0, NBS1, A0, A1 NWE 1 1 2 1 3 2 NCS SLOW CLOCK MODE WRITE IDLE STATE NORMAL MODE WRITE Reload Configuration Wait State 18.6.9 Asynchronous Page Mode The SMC supports asynchronous burst reads in page mode, providing that the Page Mode Enabled bit is written to one in the MODE register (MODE.PMEN). The page size must be configured in the Page Size field in the MODE register (MODE.PS) to 4, 8, 16, or 32 bytes. The page defines a set of consecutive bytes into memory. A 4-byte page (resp. 8-, 16-, 32-byte page) is always aligned to 4-byte boundaries (resp. 8-, 16-, 32-byte boundaries) of memory. The MSB of data address defines the address of the page in memory, the LSB of address define the address of the data in the page as detailed in Table 18-6 on page 336. With page mode memory devices, the first access to one page (tpa) takes longer than the subsequent accesses to the page (tsa) as shown in Figure 18-33 on page 337. When in page mode, the SMC enables the user to define different read timings for the first access within one page, and next accesses within the page. Table 18-6. Page Address and Data Address within a Page Page Size Page Address(1) Data Address in the Page(2) 4 bytes A[23:2] A[1:0] 8 bytes A[23:3] A[2:0] 16 bytes A[23:4] A[3:0] 32 bytes A[23:5] A[4:0] Notes: 1. A denotes the address bus of the memory device 2. For 16-bit devices, the bit 0 of address is ignored. 18.6.9.1 Protocol and timings in page mode Figure 18-33 on page 337 shows the NRD and NCS timings in page mode access. 336 32117A-10/2010 AT32UC3C Figure 18-33. Page Mode Read Protocol (Address MSB and LSB Are Defined in Table 18-6 on page 336) CLK_SMC A[MSB] A[LSB] NRD tpa tsa NCS tsa D[15:0] NCSRDPULSE NRDPULSE NRDPULSE The NRD and NCS signals are held low during all read transfers, whatever the programmed values of the setup and hold timings in the User Interface may be. Moreover, the NRD and NCS timings are identical. The pulse length of the first access to the page is defined with the PULSE.NCSRDPULSE field value. The pulse length of subsequent accesses within the page are defined using the PULSE.NRDPULSE field value. In page mode, the programming of the read timings is described in Table 18-7 on page 337: Table 18-7. Programming of Read Timings in Page Mode Parameter Value Definition READMODE `x' No impact NCSRDSETUP `x' No impact NCSRDPULSE tpa Access time of first access to the page NRDSETUP `x' No impact NRDPULSE tsa Access time of subsequent accesses in the page NRDCYCLE `x' No impact The SMC does not check the coherency of timings. It will always apply the NCSRDPULSE timings as page access timing (tpa) and the NRDPULSE for accesses to the page (tsa), even if the programmed value for tpa is shorter than the programmed value for tsa. 18.6.9.2 Byte access type in page mode The byte access type configuration remains active in page mode. For 16-bit or 32-bit page mode devices that require byte selection signals, configure the MODE.BAT bit to zero (byte select access type). 337 32117A-10/2010 AT32UC3C 18.6.9.3 Page mode restriction The page mode is not compatible with the use of the NWAIT signal. Using the page mode and the NWAIT signal may lead to unpredictable behavior. 18.6.9.4 Sequential and non-sequential accesses If the chip select and the MSB of addresses as defined in Table 18-6 on page 336 are identical, then the current access lies in the same page as the previous one, and no page break occurs. Using this information, all data within the same page, sequential or not sequential, are accessed with a minimum access time (tsa). Figure 18-34 on page 338 illustrates access to an 8-bit memory device in page mode, with 8-byte pages. Access to D1 causes a page access with a long access time (tpa). Accesses to D3 and D7, though they are not sequential accesses, only require a short access time (tsa). If the MSB of addresses are different, the SMC performs the access of a new page. In the same way, if the chip select is different from the previous access, a page break occurs. If two sequential accesses are made to the page mode memory, but separated by an other internal or external peripheral access, a page break occurs on the second access because the chip select of the device was deasserted between both accesses. Figure 18-34. Access to Non-sequential Data within the Same Page CLK_SMC Page address A[AD_MSB:3] A[2], A1, A0 A1 A3 A7 NRD NCS D[7:0] D1 NCSRDPULSE D3 NRDPULSE D7 NRDPULSE 338 32117A-10/2010 AT32UC3C 18.7 User Interface The SMC is programmed using the registers listed in Table 18-8 on page 339. For each chip select, a set of four registers is used to program the parameters of the external device connected on it. In Table 18-8 on page 339, "CS_number" denotes the chip select number. Sixteen bytes (0x10) are required per chip select. The user must complete writing the configuration by writing anyone of the Mode Registers. Table 18-8. SMC Register Memory Map Offset Register Register Name Access Reset 0x00 + CS_number*0x10 Setup Register SETUP Read/Write 0x01010101 0x04 + CS_number*0x10 Pulse Register PULSE Read/Write 0x01010101 0x08 + CS_number*0x10 Cycle Register CYCLE Read/Write 0x00030003 0x0C + CS_number*0x10 Mode Register MODE Read/Write 0x10002103 339 32117A-10/2010 AT32UC3C 18.7.1 Setup Register Register Name: SETUP Access Type: Read/Write Offset: 0x00 + CS_number*0x10 Reset Value: 0x01010101 31 30 - - 23 22 - - 15 14 - - 7 6 - - 29 28 27 26 25 24 18 17 16 10 9 8 1 0 NCSRDSETUP 21 20 19 NRDSETUP 13 12 11 NCSWRSETUP 5 4 3 2 NWESETUP * NCSRDSETUP: NCS Setup Length in READ Access In read access, the NCS signal setup length is defined as: NCS Setup Length in read access = ( 128 x NCSRDSETUP [ 5 ] + NCSRDSETUP [ 4:0 ] ) clock cycles * NRDSETUP: NRD Setup Length The NRD signal setup length is defined in clock cycles as: NRD Setup Length = ( 128 x NRDSETUP [ 5 ] + NRDSETUP [ 4:0 ] ) clock cycles * NCSWRSETUP: NCS Setup Length in WRITE Access In write access, the NCS signal setup length is defined as: NCS Setup Length in write access = ( 128 x NCSWRSETUP [ 5 ] + NCSWRSETUP [ 4:0 ] ) clock cycles * NWESETUP: NWE Setup Length The NWE signal setup length is defined as: NWE Setup Length = ( 128 x NWESETUP [ 5 ] + NWESETUP [ 4:0 ] ) clock cycles 340 32117A-10/2010 AT32UC3C 18.7.2 Pulse Register Register Name: PULSE Access Type: Read/Write Offset: 0x04 + CS_number*0x10 Reset Value: 0x01010101 31 30 29 28 27 26 25 24 18 17 16 10 9 8 2 1 0 NCSRDPULSE - 23 22 21 20 19 NRDPULSE - 15 14 13 12 11 NCSWRPULSE - 7 6 5 4 3 NWEPULSE - * NCSRDPULSE: NCS Pulse Length in READ Access In standard read access, the NCS signal pulse length is defined as: NCS Pulse Length in read access = ( 256 x NCSRDPULSE [ 6 ] + NCSRDPULSE [ 5:0 ] ) clock cycles The NCS pulse length must be at least one clock cycle. In page mode read access, the NCSRDPULSE field defines the duration of the first access to one page. * NRDPULSE: NRD Pulse Length In standard read access, the NRD signal pulse length is defined in clock cycles as: NRD Pulse Length = ( 256 x NRDPULSE [ 6 ] + NRDPULSE [ 5:0 ] ) clock cycles The NRD pulse length must be at least one clock cycle. In page mode read access, the NRDPULSE field defines the duration of the subsequent accesses in the page. * NCSWRPULSE: NCS Pulse Length in WRITE Access In write access, the NCS signal pulse length is defined as: NCS Pulse Length in write access = ( 256 x NCSWRPULSE [ 6 ] + NCSWRPULSE [ 5:0 ] ) clock cycles The NCS pulse length must be at least one clock cycle. * NWEPULSE: NWE Pulse Length The NWE signal pulse length is defined as: NWE Pulse Length = ( 256 x NWEPULSE [ 6 ] + NWEPULSE [ 5:0 ] ) clock cycles The NWE pulse length must be at least one clock cycle. 341 32117A-10/2010 AT32UC3C 18.7.3 Cycle Register Register Name: CYCLE Access Type: Read/Write Offset: 0x08 + CS_number*0x10 Reset Value: 0x00030003 31 30 29 28 27 26 25 24 - - - - - - - NRDCYCLE[8] 23 22 21 20 19 18 17 16 NRDCYCLE[7:0] 15 14 13 12 11 10 9 8 - - - - - - - NWECYCLE[8] 7 6 5 4 3 2 1 0 NWECYCLE[7:0] * NRDCYCLE[8:0]: Total Read Cycle Length The total read cycle length is the total duration in clock cycles of the read cycle. It is equal to the sum of the setup, pulse and hold steps of the NRD and NCS signals. It is defined as: Read Cycle Length = ( 256 x NRDCYCLE [ 8:7 ] + NRDCYCLE [ 6:0 ] ) clock cycles * NWECYCLE[8:0]: Total Write Cycle Length The total write cycle length is the total duration in clock cycles of the write cycle. It is equal to the sum of the setup, pulse and hold steps of the NWE and NCS signals. It is defined as: Write Cycle Length = ( 256 x NWECYCLE [ 8:7 ] + NWECYCLE [ 6:0 ] ) clock cycles 342 32117A-10/2010 AT32UC3C 18.7.4 Mode Register Register Name: MODE Access Type: Read/Write Offset: 0x0C + CS_number*0x10 Reset Value: 0x10002103 31 30 29 28 - - 23 22 21 20 - - - TDFMODE 15 14 13 12 - - 7 6 - - PS DBW 5 4 EXNWMODE 27 26 25 24 - - - PMEN 19 18 17 16 TDFCYCLES 11 10 9 8 - - - BAT 3 2 1 0 - - WRITEMODE READMODE * PS: Page Size If page mode is enabled, this field indicates the size of the page in bytes. PS Page Size 0 4-byte page 1 8-byte page 2 16-byte page 3 32-byte page * PMEN: Page Mode Enabled 1: Asynchronous burst read in page mode is applied on the corresponding chip select. 0: Standard read is applied. * TDFMODE: TDF Optimization 1: TDF optimization is enabled. The number of TDF wait states is optimized using the setup period of the next read/write access. 0: TDF optimization is disabled.The number of TDF wait states is inserted before the next access begins. * TDFCYCLES: Data Float Time This field gives the integer number of clock cycles required by the external device to release the data after the rising edge of the read controlling signal. The SMC always provide one full cycle of bus turnaround after the TDFCYCLES period. The external bus cannot be used by another chip select during TDFCYCLES plus one cycles. From 0 up to 15 TDFCYCLES can be set. 343 32117A-10/2010 AT32UC3C * DBW: Data Bus Width DBW Data Bus Width 0 8-bit bus 1 16-bit bus 2 Reserved 3 Reserved * BAT: Byte Access Type This field is used only if DBW defines a 16-bit data bus. BAT Byte Access Type 0 Byte select access type: Write operation is controlled using NCS, NWE, NBS0, NBS1 Read operation is controlled using NCS, NRD, NBS0, NBS1 1 Byte write access type: Write operation is controlled using NCS, NWR0, NWR1 Read operation is controlled using NCS and NRD * EXNWMODE: External WAIT Mode The NWAIT signal is used to extend the current read or write signal. It is only taken into account during the pulse phase of the read and write controlling signal. When the use of NWAIT is enabled, at least one cycle hold duration must be programmed for the read and write controlling signal. EXNWMODE External NWAIT Mode 0 Disabled: the NWAIT input signal is ignored on the corresponding chip select. 1 Reserved 2 Frozen Mode: if asserted, the NWAIT signal freezes the current read or write cycle. after deassertion, the read or write cycle is resumed from the point where it was stopped. 3 Ready Mode: the NWAIT signal indicates the availability of the external device at the end of the pulse of the controlling read or write signal, to complete the access. If high, the access normally completes. If low, the access is extended until NWAIT returns high. * WRITEMODE: Write Mode 1: The write operation is controlled by the NWE signal. If TDF optimization is enabled (TDFMODE =1), TDF wait states will be inserted after the setup of NWE. 0: The write operation is controlled by the NCS signal. If TDF optimization is enabled (TDFMODE =1), TDF wait states will be inserted after the setup of NCS. 344 32117A-10/2010 AT32UC3C * READMODE: Read Mode READMODE Read Access Mode 0 The read operation is controlled by the NCS signal. If TDF are programmed, the external bus is marked busy after the rising edge of NCS. If TDF optimization is enabled (TDFMODE = 1), TDF wait states are inserted after the setup of NCS. 1 The read operation is controlled by the NRD signal. If TDF cycles are programmed, the external bus is marked busy after the rising edge of NRD. If TDF optimization is enabled (TDFMODE =1), TDF wait states are inserted after the setup of NRD. 345 32117A-10/2010 AT32UC3C 19. SDRAM Controller (SDRAMC) Rev: 2.2.0.3 19.1 Features * 128-Mbytes address space * Numerous configurations supported * * * * * * 19.2 - 2K, 4K, 8K row address memory parts - SDRAM with two or four internal banks - SDRAM with 16-bit data path Programming facilities - Word, halfword, byte access - Automatic page break when memory boundary has been reached - Multibank ping-pong access - Timing parameters specified by software - Automatic refresh operation, refresh rate is programmable - Automatic update of DS, TCR and PASR parameters (mobile SDRAM devices) Energy-saving capabilities - Self-refresh, power-down, and deep power-down modes supported - Supports mobile SDRAM devices Error detection - Refresh error interrupt SDRAM power-up initialization by software CAS latency of one, two, and three supported Auto Precharge command not used Overview The SDRAM Controller (SDRAMC) extends the memory capabilities of a chip by providing the interface to an external 16-bit SDRAM device. The page size supports ranges from 2048 to 8192 and the number of columns from 256 to 2048. It supports byte (8-bit) and halfword (16-bit) accesses. The SDRAMC supports a read or write burst length of one location. It keeps track of the active row in each bank, thus maximizing SDRAM performance, e.g., the application may be placed in one bank and data in the other banks. So as to optimize performance, it is advisable to avoid accessing different rows in the same bank. The SDRAMC supports a CAS latency of one, two, or three and optimizes the read access depending on the frequency. The different modes available (self refresh, power-down, and deep power-down modes) minimize power consumption on the SDRAM device. 346 32117A-10/2010 AT32UC3C 19.3 Block Diagram Figure 19-1. SDRAM Controller Block Diagram SDCK SDCK SDCKE SDRAM C C h ip S elect SDCKE SDCS M e m ory C o ntro lle r SDCS B A [1:0 ] SDRAM C Inte rrup t A D D R [17:16 ] RAS RAS CAS CAS SDW E P ow er M a nag er SDW E SDRAMC C LK _ S D R A M C D Q M [0] EBI M U X L og ic I/O C o ntro lle r A D D R [0 ] D Q M [1] NW E1 S D R A M C _ A [9:0] A D D R [1 1:2] S D R A M C _A [10 ] SDA10 S D R A M C _A [12:11 ] U se r Interface A D D R [1 3:14] D [15:0] D A T A [15 :0] P erip he ral B u s 19.4 I/O Lines Description Table 19-1. I/O Lines Description Name Description Type Active Level SDCK SDRAM Clock Output SDCKE SDRAM Clock Enable Output BA[1:0] Bank Select Signals Output RAS Row Signal Output Low CAS Column Signal Output Low SDWE SDRAM Write Enable Output Low High 347 32117A-10/2010 AT32UC3C Table 19-1. 19.5 19.5.1 I/O Lines Description Name Description Type Active Level DQM[1:0] Data Mask Enable Signals Output High SDRAMC_A[12:0] Address Bus Output D[15:0] Data Bus Input/Output Application Example Hardware Interface Figure 19-2 on page 348 shows an example of SDRAM device connection using a 16-bit data bus width. It is important to note that this example is given for a direct connection of the devices to the SDRAMC, without External Bus Interface or I/O Controller multiplexing. Figure 19-2. SDRAM Controller Connections to SDRAM Devices: 16-bit Data Bus Width D0-D31 RAS CAS SDCK SDCKE SDWE DQM[0-1] SDRAM Controller D0-D7 DQM0 2Mx8 SDRAM D0-D7 CS CLK CKE A0-A9 A11 WE A10 RAS BA0 CAS BA1 DQM D8-D15 SDRAMC_A10 BA0 BA1 DQM1 2Mx8 SDRAM D0-D7 CS CLK CKE A0-A9 A11 WE A10 RAS BA0 CAS BA1 DQM SDRAMC_A10 BA0 BA1 SDRAMC_A[0-12] BA0 BA1 NCS[1] 19.5.2 Software Interface The SDRAM address space is organized into banks, rows, and columns. The SDRAMC allows mapping different memory types according to the values set in the SDRAMC Configuration Register (CR). The SDRAMC's function is to make the SDRAM device access protocol transparent to the user. Table 19-2 on page 349 to Table 19-4 on page 349 illustrate the SDRAM device memory mapping seen by the user in correlation with the device structure. Various configurations are illustrated. 348 32117A-10/2010 AT32UC3C 19.5.2.1 16-bit memory data bus width Table 19-2. SDRAM Configuration Mapping: 2K Rows, 256/512/1024/2048 Columns CPU Address Line 2 7 2 6 2 5 2 4 2 3 2 2 2 1 2 0 1 9 1 8 1 7 1 6 1 5 BA[1:0] 1 3 1 2 1 1 1 0 9 8 7 6 Row[10:0] BA[1:0] BA[1:0] 5 4 3 2 1 Column[7:0] Row[10:0] M0 Column[9:0] Row[10:0] 0 M0 Column[8:0] Row[10:0] BA[1:0] Table 19-3. 1 4 M0 Column[10:0] M0 SDRAM Configuration Mapping: 4K Rows, 256/512/1024/2048 Columns CPU Address Line 2 7 2 6 2 5 2 4 2 3 2 2 2 1 2 0 1 9 1 8 1 7 1 6 1 5 BA[1:0] 1 3 1 2 1 1 1 0 9 8 7 6 Row[11:0] BA[1:0] BA[1:0] 5 4 3 2 1 Column[7:0] Row[11:0] M0 Column[9:0] Row[11:0] 0 M0 Column[8:0] Row[11:0] BA[1:0] Table 19-4. 1 4 M0 Column[10:0] M0 SDRAM Configuration Mapping: 8K Rows, 256/512/1024/2048 Columns CPU Address Line 2 7 2 6 2 5 2 4 2 3 2 2 2 1 2 0 1 9 1 8 1 7 1 6 BA[1:0] 1 5 Row[12:0] BA[1:0] Row[12:0] BA[1:0] Row[12:0] BA[1:0] Row[12:0] Notes: 1. M0 is the byte address inside a 16-bit halfword. 19.6 Product Dependencies 1 4 1 3 1 2 1 1 1 0 9 8 7 6 5 4 Column[7:0] Column[8:0] Column[9:0] Column[10:0] 3 2 1 0 M0 M0 M0 M0 In order to use this module, other parts of the system must be configured correctly, as described below. 19.6.1 I/O Lines The SDRAMC module signals pass through the External Bus Interface (EBI) module where they are multiplexed. The user must first configure the I/O controller to assign the EBI pins corresponding to SDRAMC signals to their peripheral function. If I/O lines of the EBI corresponding to SDRAMC signals are not used by the application, they can be used for other purposes by the I/O Controller. 349 32117A-10/2010 AT32UC3C 19.6.2 Power Management The SDRAMC must be properly stopped before entering in reset mode, i.e., the user must issue a Deep power mode command in the Mode (MD) register and wait for the command to be completed. 19.6.3 Clocks The clock for the SDRAMC bus interface (CLK_SDRAMC) is generated by the Power Manager. This clock is enabled at reset, and can be disabled in the Power Manager. It is recommended to disable the SDRAMC before disabling the clock, to avoid freezing the SDRAMC in an undefined state. 19.6.4 Interrupts The SDRAMC interrupt request line is connected to the interrupt controller. Using the SDRAMC interrupt requires the interrupt controller to be programmed first. 19.7 19.7.1 Functional Description SDRAM Device Initialization The initialization sequence is generated by software. The SDRAM devices are initialized by the following sequence: 1. SDRAM features must be defined in the CR register by writing the following fields with the desired value: asynchronous timings (TXSR, TRAS, TRCD, TRP, TRC, and TWR), Number of Columns (NC), Number of Rows (NR), Number of Banks (NB), CAS Latency (CAS), and the Data Bus Width (DBW). 2. For mobile SDRAM devices, Temperature Compensated Self Refresh (TCSR), Drive Strength (DS) and Partial Array Self Refresh (PASR) fields must be defined in the Low Power Register (LPR). 3. The Memory Device Type field must be defined in the Memory Device Register (MDR.MD). 4. A No Operation (NOP) command must be issued to the SDRAM devices to start the SDRAM clock. The user must write the value one to the Command Mode field in the SDRAMC Mode Register (MR.MODE) and perform a write access to any SDRAM address. 5. A minimum pause of 200s is provided to precede any signal toggle. 6. An All Banks Precharge command must be issued to the SDRAM devices. The user must write the value two to the MR.MODE field and perform a write access to any SDRAM address. 7. Eight Auto Refresh commands are provided. The user must write the value four to the MR.MODE field and performs a write access to any SDRAM location eight times. 8. A Load Mode Register command must be issued to program the parameters of the SDRAM devices in its Mode Register, in particular CAS latency, burst type, and burst length. The user must write the value three to the MR.MODE field and perform a write access to the SDRAM. The write address must be chosen so that BA[1:0] are set to zero. See Section 19.8.1 for details about Load Mode Register command. 9. For mobile SDRAM initialization, an Extended Load Mode Register command must be issued to program the SDRAM devices parameters (TCSR, PASR, DS). The user must write the value five to the MR.MODE field and perform a write access to the SDRAM. The write address must be chosen so that BA[1] or BA[0] are equal to one. See Section 19.8.1 for details about Extended Load Mode Register command. 350 32117A-10/2010 AT32UC3C 10. The user must go into Normal Mode, writing the value 0 to the MR.MODE field and performing a write access at any location in the SDRAM. 11. Write the refresh rate into the Refresh Timer Count field in the Refresh Timer Register (TR.COUNT). The refresh rate is the delay between two successive refresh cycles. The SDRAM device requires a refresh every 15.625s or 7.81s. With a 100MHz frequency, the TR register must be written with the value 1562 (15.625 s x 100 MHz) or 781 (7.81 s x 100 MHz). After initialization, the SDRAM devices are fully functional. Figure 19-3. SDRAM Device Initialization Sequence SDCKE tRP tRC tMRD SDCK SDRAMC_A[9:0] A10 SDRAMC_A[12:11] NCS[1] RAS CAS SDWE DQM Inputs Stable for 200 usec 19.7.2 Precharge All Banks 1st Auto Refresh 8th Auto Refresh LMR Command Valid Command SDRAM Controller Write Cycle The SDRAMC allows burst access or single access. In both cases, the SDRAMC keeps track of the active row in each bank, thus maximizing performance. To initiate a burst access, the SDRAMC uses the transfer type signal provided by the master requesting the access. If the next access is a sequential write access, writing to the SDRAM device is carried out. If the next access is a write-sequential access, but the current access is to a boundary page, or if the next access is in another row, then the SDRAMC generates a precharge command, activates the new row and initiates a write command. To comply with SDRAM timing parameters, additional clock cycles are inserted between precharge and active (tRP) commands and between active and write (tRCD ) commands. For definition of these timing parameters, refer to the Section 19.8.3. This is described in Figure 19-4 on page 352. 351 32117A-10/2010 AT32UC3C Figure 19-4. Write Burst, 16-bit SDRAM Access tRCD = 3 NCS[1] SDCK SDRAMC_A[12:0] Row n Col a Col b Col c Col d Col e Col f Col g Col h Col i Col j Col k Col l Dnb Dnc Dnd Dne Dnf Dng Dnh Dni Dnj Dnk Dnl RAS CAS SDWE D[15:0] 19.7.3 Dna SDRAM Controller Read Cycle The SDRAMC allows burst access, incremental burst of unspecified length or single access. In all cases, the SDRAMC keeps track of the active row in each bank, thus maximizing performance of the SDRAM. If row and bank addresses do not match the previous row/bank address, then the SDRAMC automatically generates a precharge command, activates the new row and starts the read command. To comply with the SDRAM timing parameters, additional clock cycles on SDCK are inserted between precharge and active (tRP) commands and between active and read (tRCD) commands. These two parameters are set in the CR register of the SDRAMC. After a read command, additional wait states are generated to comply with the CAS latency (one, two, or three clock delays specified in the CR register). For a single access or an incremented burst of unspecified length, the SDRAMC anticipates the next access. While the last value of the column is returned by the SDRAMC on the bus, the SDRAMC anticipates the read to the next column and thus anticipates the CAS latency. This reduces the effect of the CAS latency on the internal bus. For burst access of specified length (4, 8, 16 words), access is not anticipated. This case leads to the best performance. If the burst is broken (border, busy mode, etc.), the next access is handled as an incrementing burst of unspecified length. 352 32117A-10/2010 AT32UC3C Figure 19-5. Read Burst, 16-bit SDRAM Access tRCD = 3 CAS = 2 NCS[1] SDCK SDRAMC_A[12:0] Row n Col a Col b Col c Col d Col e Col f RAS CAS SDWE D[15:0] (Input) 19.7.4 Dna Dnb Dnc Dnd Dne Dnf Border Management When the memory row boundary has been reached, an automatic page break is inserted. In this case, the SDRAMC generates a precharge command, activates the new row and initiates a read or write command. To comply with SDRAM timing parameters, an additional clock cycle is inserted between the precharge and active (tRP) commands and between the active and read (tRCD) commands. This is described in Figure 19-6 on page 354. 353 32117A-10/2010 AT32UC3C Figure 19-6. Read Burst with Boundary Row Access TRP = 3 CAS = 2 TRCD = 3 NCS[1] SDCK Row n SDRAMC_A[12:0] Col a Col b Col c Col d Row m Col a Col b Col c Col d Col e RAS CAS SDWE D[15:0] 19.7.5 Dna Dnb Dnc Dnd Dma Dmb Dmc Dmd Dme SDRAM Controller Refresh Cycles An auto refresh command is used to refresh the SDRAM device. Refresh addresses are generated internally by the SDRAM device and incremented after each auto refresh automatically. The SDRAMC generates these auto refresh commands periodically. An internal timer is loaded with the value in the Refresh Timer Register (TR) that indicates the number of clock cycles between successive refresh cycles. A refresh error interrupt is generated when the previous auto refresh command did not perform. In this case a Refresh Error Status bit is set in the Interrupt Status Register (ISR.RES). It is cleared by reading the ISR register. When the SDRAMC initiates a refresh of the SDRAM device, internal memory accesses are not delayed. However, if the CPU tries to access the SDRAM, the slave indicates that the device is busy and the master is held by a wait signal. See Figure 19-7 on page 355. 354 32117A-10/2010 AT32UC3C Figure 19-7. Refresh Cycle Followed by a Read Access tRP = 3 tRC = 8 tRCD = 3 CAS = 2 NCS[1] SDCK Row n SDRAMC_A[12:0] Col c Col d Row m Col a RAS CAS SDWE D[15:0] (input) 19.7.6 Dnb Dnc Dnd Dma Power Management Three low power modes are available: * Self refresh mode: the SDRAM executes its own auto refresh cycles without control of the SDRAMC. Current drained by the SDRAM is very low. * Power-down mode: auto refresh cycles are controlled by the SDRAMC. Between auto refresh cycles, the SDRAM is in power-down. Current drained in power-down mode is higher than in self refresh mode. * Deep power-down mode (only available with mobile SDRAM): the SDRAM contents are lost, but the SDRAM does not drain any current. The SDRAMC activates one low power mode as soon as the SDRAM device is not selected. It is possible to delay the entry in self refresh and power-down mode after the last access by configuring the Timeout field in the Low Power Register (LPR.TIMEOUT). 19.7.6.1 Self refresh mode This mode is selected by writing the value one to the Low Power Configuration Bits field in the SDRAMC Low Power Register (LPR.LPCB). In self refresh mode, the SDRAM device retains data without external clocking and provides its own internal clocking, thus performing its own auto refresh cycles. All the inputs to the SDRAM device become "don't care" except SDCKE, which remains low. As soon as the SDRAM device is selected, the SDRAMC provides a sequence of commands and exits self refresh mode. Some low power SDRAMs (e.g., mobile SDRAM) can refresh only one quarter or a half quarter or all banks of the SDRAM array. This feature reduces the self refresh current. To configure this feature, Temperature Compensated Self Refresh (TCSR), Partial Array Self Refresh (PASR) 355 32117A-10/2010 AT32UC3C and Drive Strength (DS) parameters must be set by writing the corresponding fields in the LPR register, and transmitted to the low power SDRAM device during initialization. After initialization, as soon as the LPR.PASR, LPR.DS, or LPR.TCSR fields are modified and self refresh mode is activated, the SDRAMC issues an Extended Load Mode Register command to the SDRAM and the Extended Mode Register of the SDRAM device is accessed automatically. The PASR/DS/TCSR parameters values are therefore updated before entry into self refresh mode. The SDRAM device must remain in self refresh mode for a minimum period of tRAS and may remain in self refresh mode for an indefinite period. This is described in Figure 19-8 on page 356. Figure 19-8. Self Refresh Mode Behavior Self Refresh Mode SDRAMC_A[12:0] TXSR = 3 Row SDCK SDCKE NCS[1] RAS CAS SDWE Access Request To the SDRAM Controller 19.7.6.2 Low power mode This mode is selected by writing the value two to the LPR.LPCB field. Power consumption is greater than in self refresh mode. All the input and output buffers of the SDRAM device are deactivated except SDCKE, which remains low. In contrast to self refresh mode, the SDRAM device cannot remain in low power mode longer than the refresh period (64 ms for a whole device refresh operation). As no auto refresh operations are performed by the SDRAM itself, the SDRAMC carries out the refresh operation. The exit procedure is faster than in self refresh mode. This is described in Figure 19-9 on page 357. 356 32117A-10/2010 AT32UC3C Figure 19-9. Low Power Mode Behavior TRCD = 3 CAS = 2 Low Power Mode NCS[1] SDCK SDRAMC_A[12:0] Row n Col a Col b Col c Col d Col e Col f RAS CAS SDCKE D[15:0] (input) 19.7.6.3 Dna Dnb Dnc Dnd Dne Dnf Deep power-down mode This mode is selected by writing the value three to the LPR.LPCB field. When this mode is activated, all internal voltage generators inside the SDRAM are stopped and all data is lost. When this mode is enabled, the user must not access to the SDRAM until a new initialization sequence is done (See Section 19.7.1). This is described in Figure 19-10 on page 358. 357 32117A-10/2010 AT32UC3C Figure 19-10. Deep Power-down Mode Behavior tRP = 3 NCS[1] SDCK Row n SDRAMC_A[12:0] Col c Col d RAS CAS SDWE SCKE D[15:0] (Input) Dnb Dnc Dnd 358 32117A-10/2010 AT32UC3C 19.8 User Interface Table 19-5. SDRAMC Register Memory Map Offset Register Register Name Access Reset 0x00 Mode Register MR Read/Write 0x00000000 0x04 Refresh Timer Register TR Read/Write 0x00000000 0x08 Configuration Register CR Read/Write 0x852372C0 0x0C High Speed Register HSR Read/Write 0x00000000 0x10 Low Power Register LPR Read/Write 0x00000000 0x14 Interrupt Enable Register IER Write-only 0x00000000 0x18 Interrupt Disable Register IDR Write-only 0x00000000 0x1C Interrupt Mask Register IMR Read-only 0x00000000 0x20 Interrupt Status Register ISR Read-only 0x00000000 0x24 Memory Device Register MDR Read/Write 0x00000000 359 32117A-10/2010 AT32UC3C 19.8.1 Mode Register Register Name: MR Access Type: Read/Write Offset: 0x00 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 - - - - - - - - 7 6 5 4 3 2 1 0 - - - - - MODE * MODE: Command Mode This field defines the command issued by the SDRAMC when the SDRAM device is accessed. MODE Description 0 Normal mode. Any access to the SDRAM is decoded normally. 1 The SDRAMC issues a "NOP" command when the SDRAM device is accessed regardless of the cycle. 2 The SDRAMC issues an "All Banks Precharge" command when the SDRAM device is accessed regardless of the cycle. 3 The SDRAMC issues a "Load Mode Register" command when the SDRAM device is accessed regardless of the cycle. This command will load the CR.CAS field into the SDRAM device Mode Register. All the other parameters of the SDRAM device Mode Register will be set to zero (burst length, burst type, operating mode, write burst mode...). 4 The SDRAMC issues an "Auto Refresh" command when the SDRAM device is accessed regardless of the cycle. Previously, an "All Banks Precharge" command must be issued. 5 The SDRAMC issues an "Extended Load Mode Register" command when the SDRAM device is accessed regardless of the cycle. This command will load the LPR.PASR, LPR.DS, and LPR.TCR fields into the SDRAM device Extended Mode Register. All the other bits of the SDRAM device Extended Mode Register will be set to zero. 6 Deep power-down mode. Enters deep power-down mode. 360 32117A-10/2010 AT32UC3C 19.8.2 Refresh Timer Register Register Name: TR Access Type: Read/Write Offset: 0x04 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 - - - - 7 6 5 4 1 0 COUNT[11:8] 3 2 COUNT[7:0] * COUNT[11:0]: Refresh Timer Count This 12-bit field is loaded into a timer that generates the refresh pulse. Each time the refresh pulse is generated, a refresh burst is initiated. The value to be loaded depends on the SDRAMC clock frequency (CLK_SDRAMC), the refresh rate of the SDRAM device and the refresh burst length where 15.6s per row is a typical value for a burst of length one. To refresh the SDRAM device, this 12-bit field must be written. If this condition is not satisfied, no refresh command is issued and no refresh of the SDRAM device is carried out. 361 32117A-10/2010 AT32UC3C 19.8.3 Configuration Register Register Name: CR Access Type: Read/Write Offset: 0x08 Reset Value: 0x852372C0 31 30 29 28 27 26 TXSR 23 22 21 14 20 19 18 13 DBW 6 16 12 11 10 9 8 1 0 TWR 5 CAS 17 TRP TRC 7 24 TRAS TRCD 15 25 4 NB 3 2 NR NC * TXSR: Exit Self Refresh to Active Delay Reset value is eight cycles. This field defines the delay between SCKE set high and an Activate command in number of cycles. Number of cycles is between 0 and 15. * TRAS: Active to Precharge Delay Reset value is five cycles. This field defines the delay between an Activate command and a Precharge command in number of cycles. Number of cycles is between 0 and 15. * TRCD: Row to Column Delay Reset value is two cycles. This field defines the delay between an Activate command and a Read/Write command in number of cycles. Number of cycles is between 0 and 15. * TRP: Row Precharge Delay Reset value is three cycles. This field defines the delay between a Precharge command and another command in number of cycles. Number of cycles is between 0 and 15. * TRC: Row Cycle Delay Reset value is seven cycles. This field defines the delay between a Refresh and an Activate Command in number of cycles. Number of cycles is between 0 and 15. * TWR: Write Recovery Delay Reset value is two cycles. This field defines the Write Recovery Time in number of cycles. Number of cycles is between 0 and 15. * DBW: Data Bus Width Reset value is 16 bits. 0: Reserved. 1: Data bus width is 16 bits. 362 32117A-10/2010 AT32UC3C * CAS: CAS Latency Reset value is two cycles. In the SDRAMC, only a CAS latency of one, two and three cycles is managed. CAS CAS Latency (Cycles) 0 Reserved 1 1 2 2 3 3 * NB: Number of Banks Reset value is two banks. NB Number of Banks 0 2 1 4 * NR: Number of Row Bits Reset value is 11 row bits. NR Row Bits 0 11 1 12 2 13 3 Reserved * NC: Number of Column Bits Reset value is 8 column bits. NC Column Bits 0 8 1 9 2 10 3 11 363 32117A-10/2010 AT32UC3C 19.8.4 High Speed Register Register Name: HSR Access Type: Read/Write Offset: 0x0C Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 - - - - - - - - 7 6 5 4 3 2 1 0 - - - - - - - DA * DA: Decode Cycle Enable A decode cycle can be added on the addresses as soon as a non-sequential access is performed on the HSB bus. The addition of the decode cycle allows the SDRAMC to gain time to access the SDRAM memory. 1: Decode cycle is enabled. 0: Decode cycle is disabled. 364 32117A-10/2010 AT32UC3C 19.8.5 Low Power Register Register Name: LPR Access Type: Read/Write Offset: 0x10 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 - - 7 6 - TIMEOUT 5 DS 4 PASR TCSR 3 2 - - 1 0 LPCB * TIMEOUT: Time to Define when Low Power Mode Is Enabled TIMEOUT Time to Define when Low Power Mode Is Enabled 0 The SDRAMC activates the SDRAM low power mode immediately after the end of the last transfer. 1 The SDRAMC activates the SDRAM low power mode 64 clock cycles after the end of the last transfer. 2 The SDRAMC activates the SDRAM low power mode 128 clock cycles after the end of the last transfer. 3 Reserved. * DS: Drive Strength (only for low power SDRAM) This field is transmitted to the SDRAM during initialization to select the SDRAM strength of data output. This parameter must be set according to the SDRAM device specification. After initialization, as soon as this field is modified and self refresh mode is activated, the Extended Mode Register of the SDRAM device is accessed automatically and its DS parameter value is updated before entry in self refresh mode. * TCSR: Temperature Compensated Self Refresh (only for low power SDRAM) This field is transmitted to the SDRAM during initialization to set the refresh interval during self refresh mode depending on the temperature of the low power SDRAM. This parameter must be set according to the SDRAM device specification. After initialization, as soon as this field is modified and self refresh mode is activated, the Extended Mode Register of the SDRAM device is accessed automatically and its TCSR parameter value is updated before entry in self refresh mode. * PASR: Partial Array Self Refresh (only for low power SDRAM) This field is transmitted to the SDRAM during initialization to specify whether only one quarter, one half or all banks of the SDRAM array are enabled. Disabled banks are not refreshed in self refresh mode. This parameter must be set according to the SDRAM device specification. After initialization, as soon as this field is modified and self refresh mode is activated, the Extended Mode Register of the SDRAM device is accessed automatically and its PASR parameter value is updated before entry in self refresh mode. 365 32117A-10/2010 AT32UC3C * LPCB: Low Power Configuration Bits LPCB Low Power Configuration 0 Low power feature is inhibited: no power-down, self refresh or deep power-down command is issued to the SDRAM device. 1 The SDRAMC issues a self refresh command to the SDRAM device, the SDCLK clock is deactivated and the SDCKE signal is set low. The SDRAM device leaves the self refresh mode when accessed and enters it after the access. 2 The SDRAMC issues a power-down command to the SDRAM device after each access, the SDCKE signal is set to low. The SDRAM device leaves the power-down mode when accessed and enters it after the access. 3 The SDRAMC issues a deep power-down command to the SDRAM device. This mode is unique to lowpower SDRAM. 366 32117A-10/2010 AT32UC3C 19.8.6 Interrupt Enable Register Register Name: IER Access Type: Write-only Offset: 0x14 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 - - - - - - - - 7 6 5 4 3 2 1 0 - - - - - - - RES Writing a zero to a bit in this register has no effect. Writing a one to a bit in this register will set the corresponding bit in IMR. 367 32117A-10/2010 AT32UC3C 19.8.7 Interrupt Disable Register Register Name: IDR Access Type: Write-only Offset: 0x18 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 - - - - - - - - 7 6 5 4 3 2 1 0 - - - - - - - RES Writing a zero to a bit in this register has no effect. Writing a one to a bit in this register will clear the corresponding bit in IMR. 368 32117A-10/2010 AT32UC3C 19.8.8 Interrupt Mask Register Register Name: IMR Access Type: Read-only Offset: 0x1C Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 - - - - - - - - 7 6 5 4 3 2 1 0 - - - - - - - RES 0: The corresponding interrupt is disabled. 1: The corresponding interrupt is enabled. A bit in this register is cleared when the corresponding bit in IDR is written to one. A bit in this register is set when the corresponding bit in IER is written to one. 369 32117A-10/2010 AT32UC3C 19.8.9 Interrupt Status Register Register Name: ISR Access Type: Read-only Offset: 0x20 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 - - - - - - - - 7 6 5 4 3 2 1 0 - - - - - - - RES * RES: Refresh Error Status This bit is set when a refresh error is detected. This bit is cleared when the register is read. 370 32117A-10/2010 AT32UC3C 19.8.10 Memory Device Register Register Name: MDR Access Type: Read/Write Offset: 0x24 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 - - - - - - - - 7 6 5 4 3 2 1 0 - - - - - - MD * MD: Memory Device Type MD Device Type 0 SDRAM 1 Low power SDRAM Other Reserved 371 32117A-10/2010 AT32UC3C 20. Peripheral DMA Controller (PDCA) Rev: 1.2.3.1 20.1 Features * * * * * * 20.2 Multiple channels Generates transfers between memories and peripherals such as USART and SPI Two address pointers/counters per channel allowing double buffering Performance monitors to measure average and maximum transfer latency Optional synchronizing of data transfers with extenal peripheral events Ring buffer functionality Overview The Peripheral DMA Controller (PDCA) transfers data between on-chip peripheral modules such as USART, SPI and memories (those memories may be on- and off-chip memories). Using the PDCA avoids CPU intervention for data transfers, improving the performance of the microcontroller. The PDCA can transfer data from memory to a peripheral or from a peripheral to memory. The PDCA consists of multiple DMA channels. Each channel has: * A Peripheral Select Register * A 32-bit memory pointer * A 16-bit transfer counter * A 32-bit memory pointer reload value * A 16-bit transfer counter reload value The PDCA communicates with the peripheral modules over a set of handshake interfaces. The peripheral signals the PDCA when it is ready to receive or transmit data. The PDCA acknowledges the request when the transmission has started. When a transmit buffer is empty or a receive buffer is full, an optional interrupt request can be generated. 372 32117A-10/2010 AT32UC3C 20.3 Block Diagram Figure 20-1. PDCA Block Diagram Peripheral 0 Memory HSB to PB Bridge HSB Peripheral Bus HSB High Speed Bus Matrix HSB Interrupt Controller IRQ Peripheral 2 ... Peripheral DMA Controller (PDCA) Peripheral 1 Peripheral (n-1) Handshake Interfaces 20.4 Product Dependencies In order to use this module, other parts of the system must be configured correctly, as described below. 20.4.1 Power Management If the CPU enters a sleep mode that disables the PDCA clocks, the PDCA will stop functioning and resume operation after the system wakes up from sleep mode. 20.4.2 Clocks The PDCA has two bus clocks connected: One High Speed Bus clock (CLK_PDCA_HSB) and one Peripheral Bus clock (CLK_PDCA_PB). These clocks are generated by the Power Manager. Both clocks are enabled at reset, and can be disabled by writing to the Power Manager. It is recommended to disable the PDCA before disabling the clocks, to avoid freezing the PDCA in an undefined state. 20.4.3 Interrupts The PDCA interrupt request lines are connected to the interrupt controller. Using the PDCA interrupts requires the interrupt controller to be programmed first. 373 32117A-10/2010 AT32UC3C 20.4.4 20.5 20.5.1 Peripheral Events The PDCA peripheral events are connected via the Peripheral Event System. Refer to the Peripheral Event System chapter for details. Functional Description Basic Operation The PDCA consists of multiple independent PDCA channels, each capable of handling DMA requests in parallel. Each PDCA channels contains a set of configuration registers which must be configured to start a DMA transfer. In this section the steps necessary to configure one PDCA channel is outlined. The peripheral to transfer data to or from must be configured correctly in the Peripheral Select Register (PSR). This is performed by writing the Peripheral Identity (PID) value for the corresponding peripheral to the PID field in the PSR register. The PID also encodes the transfer direction, i.e. memory to peripheral or peripheral to memory. See Section 20.5.6. The transfer size must be written to the Transfer Size field in the Mode Register (MR.SIZE). The size must match the data size produced or consumed by the selected peripheral. See Section 20.5.7. The memory address to transfer to or from, depending on the PSR, must be written to the Memory Address Register (MAR). For each transfer the memory address is increased by either a one, two or four, depending on the size set in MR. See Section 20.5.2. The number of data items to transfer is written to the TCR register. If the PDCA channel is enabled, a transfer will start immediately after writing a non-zero value to TCR or the reload version of TCR, TCRR. After each transfer the TCR value is decreased by one. Both MAR and TCR can be read while the PDCA channel is active to monitor the DMA progress. See Section 20.5.3. The channel must be enabled for a transfer to start. A channel is enable by writing a one to the EN bit in the Control Register (CR). 20.5.2 Memory Pointer Each channel has a 32-bit Memory Address Register (MAR). This register holds the memory address for the next transfer to be performed. The register is automatically updated after each transfer. The address will be increased by either one, two or four depending on the size of the DMA transfer (byte, halfword or word). The MAR can be read at any time during transfer. 20.5.3 Transfer Counter Each channel has a 16-bit Transfer Counter Register (TCR). This register must be programmed with the number of transfers to be performed. The TCR register should contain the number of data items to be transferred independently of the transfer size. The TCR can be read at any time during transfer to see the number of remaining transfers. 20.5.4 Reload Registers Both the MAR and the TCR have a reload register, respectively Memory Address Reload Register (MARR) and Transfer Counter Reload Register (TCRR). These registers provide the possibility for the PDCA to work on two memory buffers for each channel. When one buffer has completed, MAR and TCR will be reloaded with the values in MARR and TCRR. The reload logic is always enabled and will trigger if the TCR reaches zero while TCRR holds a non-zero value. After reload, the MARR and TCRR registers are cleared. 374 32117A-10/2010 AT32UC3C If TCR is zero when writing to TCRR, the TCR and MAR are automatically updated with the value written in TCRR and MARR. 20.5.5 Ring Buffer When Ring Buffer mode is enabled the TCRR and MARR registers will not be cleared when TCR and MAR registers reload. This allows the PDCA to read or write to the same memory region over and over again until the transfer is actively stopped by the user. Ring Buffer mode is enabled by writing a one to the Ring Buffer bit in the Mode Register (MR.RING). 20.5.6 Peripheral Selection The Peripheral Select Register (PSR) decides which peripheral should be connected to the PDCA channel. A peripheral is selected by writing the corresponding Peripheral Identity (PID) to the PID field in the PSR register. Writing the PID will both select the direction of the transfer (memory to peripheral or peripheral to memory), which handshake interface to use, and the address of the peripheral holding register. Refer to the Peripheral Identity (PID) table in the Module Configuration section for the peripheral PID values. 20.5.7 Transfer Size The transfer size can be set individually for each channel to be either byte, halfword or word (8bit, 16-bit or 32-bit respectively). Transfer size is set by writing the desired value to the Transfer Size field in the Mode Register (MR.SIZE). When the PDCA moves data between peripherals and memory, data is automatically sized and aligned. When memory is accessed, the size specified in MR.SIZE and system alignment is used. When a peripheral register is accessed the data to be transferred is converted to a word where bit n in the data corresponds to bit n in the peripheral register. If the transfer size is byte or halfword, bits greater than 8 and16 respectively are set to zero. Refer to the Module Configuration section for information regarding what peripheral registers are used for the different peripherals and then to the peripheral specific chapter for information about the size option available for the different registers. 20.5.8 Enabling and Disabling Each DMA channel is enabled by writing a one to the Transfer Enable bit in the Control Register (CR.TEN) and disabled by writing a one to the Transfer Disable bit (CR.TDIS). The current status can be read from the Status Register (SR). While the PDCA channel is enabled all DMA request will be handled as long the TCR and TCRR is not zero. 20.5.9 Interrupts Interrupts can be enabled by writing a one to the corresponding bit in the Interrupt Enable Register (IER) and disabled by writing a one to the corresponding bit in the Interrupt Disable Register (IDR). The Interrupt Mask Register (IMR) can be read to see whether an interrupt is enabled or not. The current status of an interrupt source can be read through the Interrupt Status Register (ISR). The PDCA has three interrupt sources: * Reload Counter Zero - The TCRR register is zero. * Transfer Finished - Both the TCR and TCRR registers are zero. * Transfer Error - An error has occurred in accessing memory. 375 32117A-10/2010 AT32UC3C 20.5.10 Priority If more than one PDCA channel is requesting transfer at a given time, the PDCA channels are prioritized by their channel number. Channels with lower numbers have priority over channels with higher numbers, giving channel zero the highest priority. 20.5.11 Error Handling If the Memory Address Register (MAR) is set to point to an invalid location in memory, an error will occur when the PDCA tries to perform a transfer. When an error occurs, the Transfer Error bit in the Interrupt Status Register (ISR.TERR) will be set and the DMA channel that caused the error will be stopped. In order to restart the channel, the user must program the Memory Address Register to a valid address and then write a one to the Error Clear bit in the Control Register (CR.ECLR). If the Transfer Error interrupt is enabled, an interrupt request will be generated when an transfer error occurs. 20.5.12 20.6 Peripheral Event Trigger Peripheral events can be used to trigger PDCA channel transfers. Peripheral Event synchronizations are enabled by writing a one to the Event Trigger bit in the Mode Register (MR.ETRIG). When set, all DMA requests will be blocked until an peripheral event is received. For each peripheral event received, only one data item is transferred. If no DMA requests are pending when a peripheral event is received, the PDCA will start a transfer as soon as a peripheral event is detected. If multiple events arrive while the PDCA channel is busy transferring data, an overflow condition will be signaled in the Peripheral Event System. Refer to the Peripheral Event System chapter for more information. Performance Monitors Up tp two performance monitors allow the user to measure the activity and stall cycles for PDCA transfers. To monitor a PDCA channel, the corresponding channel number must be written to one of the MONnCH fields in the Performance Control Register (PCONTROL) and a one must be written to the corresponding CHnEN bit in the same register. Due to performance monitor hardware resource sharing, the two monitor channels should NOT be programmed to monitor the same PDCA channel. This may result in UNDEFINED performance monitor behavior. 20.6.1 Measuring mechanisms Three different parameters can be measured by each channel: * The number of data transfer cycles since last channel reset, both for read and write * The number of stall cycles since last channel reset, both for read and write * The maximum latency since last channel reset, both for read and write These measurements can be extracted by software and used to generate indicators for bus latency, bus load, and maximum bus latency. Each of the counters has a fixed width, and may therefore overflow. When an overflow is encountered in either the Performance Channel Data Read/Write Cycle registers (PRDATAn and PWDATAn) or the Performance Channel Read/Write Stall Cycles registers (PRSTALLn and PWSTALLn) of a channel, all registers in the channel are reset. This behavior is altered if the Channel Overflow Freeze bit is one in the Performance Control register (PCONTROL.CHnOVF). If this bit is one, the channel registers are frozen when either DATA or STALL reaches its maximum value. This simplifies one-shot readout of the counter values. 376 32117A-10/2010 AT32UC3C The registers can also be manually reset by writing a one to the Channel Reset bit in the PCONTROL register (PCONTROL.CHnRES). The Performance Channel Read/Write Latency registers (PRLATn and PWLATn) are saturating when their maximum count value is reached. The PRLATn and PWLATn registers are reset only by writing a one to the CHnRES in PCONTROL. A counter must manually be enabled by writing a one to the Channel Enable bit in the Performance Control Register (PCONTROL.CHnEN). 377 32117A-10/2010 AT32UC3C 20.7 20.7.1 User Interface Memory Map Overview Table 20-1. PDCA Register Memory Map Address Range Contents 0x000 - 0x03F DMA channel 0 configuration registers 0x040 - 0x07F DMA channel 1 configuration registers ... ... (0x000 - 0x03F)+m*0x040 DMA channel m configuration registers 0x800-0x830 Performance Monitor registers 0x834 Version register The channels are mapped as shown in Table 20-1. Each channel has a set of configuration registers, shown in Table 20-2, where n is the channel number. 20.7.2 Channel Memory Map Table 20-2. PDCA Channel Configuration Registers Offset Register Register Name Access Reset 0x000 + n*0x040 Memory Address Register MAR Read/Write 0x00000000 0x004 + n*0x040 Peripheral Select Register PSR Read/Write - (1) 0x008 + n*0x040 Transfer Counter Register TCR Read/Write 0x00000000 0x00C + n*0x040 Memory Address Reload Register MARR Read/Write 0x00000000 0x010 + n*0x040 Transfer Counter Reload Register TCRR Read/Write 0x00000000 0x014 + n*0x040 Control Register CR Write-only 0x00000000 0x018 + n*0x040 Mode Register MR Read/Write 0x00000000 0x01C + n*0x040 Status Register SR Read-only 0x00000000 0x020 + n*0x040 Interrupt Enable Register IER Write-only 0x00000000 0x024 + n*0x040 Interrupt Disable Register IDR Write-only 0x00000000 0x028 + n*0x040 Interrupt Mask Register IMR Read-only 0x00000000 0x02C + n*0x040 Interrupt Status Register ISR Read-only 0x00000000 Note: 1. The reset values are device specific. Please refer to the Module Configuration section at the end of this chapter. 378 32117A-10/2010 AT32UC3C 20.7.3 Performance Monitor Memory Map Table 20-3. PDCA Performance Monitor Registers(1) Offset Register Register Name Access Reset 0x800 Performance Control Register PCONTROL Read/Write 0x00000000 0x804 Channel0 Read Data Cycles PRDATA0 Read-only 0x00000000 0x808 Channel0 Read Stall Cycles PRSTALL0 Read-only 0x00000000 0x80C Channel0 Read Max Latency PRLAT0 Read-only 0x00000000 0x810 Channel0 Write Data Cycles PWDATA0 Read-only 0x00000000 0x814 Channel0 Write Stall Cycles PWSTALL0 Read-only 0x00000000 0x818 Channel0 Write Max Latency PWLAT0 Read-only 0x00000000 0x81C Channel1 Read Data Cycles PRDATA1 Read-only 0x00000000 0x820 Channel1 Read Stall Cycles PRSTALL1 Read-only 0x00000000 0x824 Channel1 Read Max Latency PRLAT1 Read-only 0x00000000 0x828 Channel1 Write Data Cycles PWDATA1 Read-only 0x00000000 0x82C Channel1 Write Stall Cycles PWSTALL1 Read-only 0x00000000 0x830 Channel1 Write Max Latency PWLAT1 Read-only 0x00000000 Note: 20.7.4 Version Register Memory Map Table 20-4. Note: 1. The number of performance monitors is device specific. If the device has only one performance monitor, the Channel1 registers are not available. Please refer to the Module Configuration section at the end of this chapter for the number of performance monitors on this device. PDCA Version Register Memory Map Offset Register Register Name Access Reset 0x834 Version Register VERSION Read-only - (1) 1. The reset values are device specific. Please refer to the Module Configuration section at the end of this chapter. 379 32117A-10/2010 AT32UC3C 20.7.5 Name: Memory Address Register MAR Access Type: Read/Write Offset: 0x000 + n*0x040 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 18 17 16 11 10 9 8 3 2 1 0 MADDR[31:24] 23 22 21 20 19 MADDR[23:16] 15 14 13 12 MADDR[15:8] 7 6 5 4 MADDR[7:0] * MADDR: Memory Address Address of memory buffer. MADDR should be programmed to point to the start of the memory buffer when configuring the PDCA. During transfer, MADDR will point to the next memory location to be read/written. 380 32117A-10/2010 AT32UC3C 20.7.6 Name: Peripheral Select Register PSR Access Type: Read/Write Offset: 0x004 + n*0x040 Reset Value: - 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 - - - - - - - - 7 6 5 4 3 2 1 0 PID * PID: Peripheral Identifier The Peripheral Identifier selects which peripheral should be connected to the DMA channel. Writing a PID will select both which handshake interface to use, the direction of the transfer and also the address of the Receive/Transfer Holding Register for the peripheral. See the Module Configuration section of PDCA for details. The width of the PID field is device specific and dependent on the number of peripheral modules in the device. 381 32117A-10/2010 AT32UC3C 20.7.7 Name: Transfer Counter Register TCR Access Type: Read/Write Offset: 0x008 + n*0x040 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 3 2 1 0 TCV[15:8] 7 6 5 4 TCV[7:0] * TCV: Transfer Counter Value Number of data items to be transferred by the PDCA. TCV must be programmed with the total number of transfers to be made. During transfer, TCV contains the number of remaining transfers to be done. 382 32117A-10/2010 AT32UC3C 20.7.8 Name: Memory Address Reload Register MARR Access Type: Read/Write Offset: 0x00C + n*0x040 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 19 18 17 16 11 10 9 8 3 2 1 0 MARV[31:24] 23 22 21 20 MARV[23:16] 15 14 13 12 MARV[15:8] 7 6 5 4 MARV[7:0] * MARV: Memory Address Reload Value Reload Value for the MAR register. This value will be loaded into MAR when TCR reaches zero if the TCRR register has a nonzero value. 383 32117A-10/2010 AT32UC3C 20.7.9 Name: Transfer Counter Reload Register TCRR Access Type: Read/Write Offset: 0x010 + n*0x040 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 3 2 1 0 TCRV[15:8] 7 6 5 4 TCRV[7:0] * TCRV: Transfer Counter Reload Value Reload value for the TCR register. When TCR reaches zero, it will be reloaded with TCRV if TCRV has a positive value. If TCRV is zero, no more transfers will be performed for the channel. When TCR is reloaded, the TCRR register is cleared. 384 32117A-10/2010 AT32UC3C 20.7.10 Name: Control Register CR Access Type: Write-only Offset: 0x014 + n*0x040 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 - - - - - - - ECLR 7 6 5 4 3 2 1 0 - - - - - - TDIS TEN * ECLR: Transfer Error Clear Writing a zero to this bit has no effect. Writing a one to this bit will clear the Transfer Error bit in the Status Register (SR.TERR). Clearing the SR.TERR bit will allow the channel to transmit data. The memory address must first be set to point to a valid location. * TDIS: Transfer Disable Writing a zero to this bit has no effect. Writing a one to this bit will disable transfer for the DMA channel. * TEN: Transfer Enable Writing a zero to this bit has no effect. Writing a one to this bit will enable transfer for the DMA channel. 385 32117A-10/2010 AT32UC3C 20.7.11 Name: Mode Register MR Access Type: Read/Write Offset: 0x018 + n*0x040 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 - - - - - - - - 7 6 5 4 3 2 1 0 - - - - RING ETRIG SIZE * RING: Ring Buffer 0:The Ring buffer functionality is disabled. 1:The Ring buffer functionality is enabled. When enabled, the reload registers, MARR and TCRR will not be cleared after reload. * ETRIG: Event Trigger 0:Start transfer when the peripheral selected in Peripheral Select Register (PSR) requests a transfer. 1:Start transfer only when or after a peripheral event is received. * SIZE: Size of Transfer Table 20-5. Size of Transfer SIZE Size of Transfer 0 Byte 1 Halfword 2 Word 3 Reserved 386 32117A-10/2010 AT32UC3C 20.7.12 Name: Status Register SR Access Type: Read-only Offset: 0x01C + n*0x040 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 - - - - - - - - 7 6 5 4 3 2 1 0 - - - - - - - TEN * TEN: Transfer Enabled This bit is cleared when the TDIS bit in CR is written to one. This bit is set when the TEN bit in CR is written to one. 0: Transfer is disabled for the DMA channel. 1: Transfer is enabled for the DMA channel. 387 32117A-10/2010 AT32UC3C 20.7.13 Name: Interrupt Enable Register IER Access Type: Write-only Offset: 0x020 + n*0x040 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 - - - - - - - - 7 6 5 4 3 2 1 0 - - - - - TERR TRC RCZ Writing a zero to a bit in this register has no effect. Writing a one to a bit in this register will set the corresponding bit in IMR. 388 32117A-10/2010 AT32UC3C 20.7.14 Name: Interrupt Disable Register IDR Access Type: Write-only Offset: 0x024 + n*0x040 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 - - - - - - - - 7 6 5 4 3 2 1 0 - - - - - TERR TRC RCZ Writing a zero to a bit in this register has no effect. Writing a one to a bit in this register will clear the corresponding bit in IMR. 389 32117A-10/2010 AT32UC3C 20.7.15 Name: Interrupt Mask Register IMR Access Type: Read-only Offset: 0x028 + n*0x040 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 - - - - - - - - 7 6 5 4 3 2 1 0 - - - - - TERR TRC RCZ 0: The corresponding interrupt is disabled. 1: The corresponding interrupt is enabled. A bit in this register is cleared when the corresponding bit in IDR is written to one. A bit in this register is set when the corresponding bit in IER is written to one. 390 32117A-10/2010 AT32UC3C 20.7.16 Name: Interrupt Status Register ISR Access Type: Read-only Offset: 0x02C + n*0x040 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 - - - - - - - - 7 6 5 4 3 2 1 0 - - - - - TERR TRC RCZ * TERR: Transfer Error This bit is cleared when no transfer errors have occurred since the last write to CR.ECLR. This bit is set when one or more transfer errors has occurred since reset or the last write to CR.ECLR. * TRC: Transfer Complete This bit is cleared when the TCR and/or the TCRR holds a non-zero value. This bit is set when both the TCR and the TCRR are zero. * RCZ: Reload Counter Zero This bit is cleared when the TCRR holds a non-zero value. This bit is set when TCRR is zero. 391 32117A-10/2010 AT32UC3C 20.7.17 Name: Performance Control Register PCONTROL Access Type: Read/Write Offset: 0x800 Reset Value: 0x00000000 31 30 29 28 - - 23 22 - - 15 14 13 12 - - - 7 6 - - 27 26 25 24 18 17 16 11 10 9 8 - - - CH1RES CH0RES 5 4 3 2 1 0 CH1OF CH0OF - - CH1EN CH0EN MON1CH 21 20 19 MON0CH * MON1CH: Performance Monitor Channel 1 * MON0CH: Performance Monitor Channel 0 The PDCA channel number to monitor with counter n Due to performance monitor hardware resource sharing, the two performance monitor channels should NOT be programmed to monitor the same PDCA channel. This may result in UNDEFINED monitor behavior. * CH1RES: Performance Channel 1 Counter Reset Writing a zero to this bit has no effect. Writing a one to this bit will reset the counter in performance channel 1. This bit always reads as zero. * CH0RES: Performance Channel 0 Counter Reset Writing a zero to this bit has no effect. Writing a one to this bit will reset the counter in performance channel 0. This bit always reads as zero. * CH1OF: Performance Channel 1 Overflow Freeze 0: The performance channel registers are reset if DATA or STALL overflows. 1: All performance channel registers are frozen just before DATA or STALL overflows. * CH1OF: Performance Channel 0 Overflow Freeze 0: The performance channel registers are reset if DATA or STALL overflows. 1: All performance channel registers are frozen just before DATA or STALL overflows. * CH1EN: Performance Channel 1 Enable 0: Performance channel 1 is disabled. 1: Performance channel 1 is enabled. * CH0EN: Performance Channel 0 Enable 0: Performance channel 0 is disabled. 1: Performance channel 0 is enabled. 392 32117A-10/2010 AT32UC3C 20.7.18 Name: Performance Channel 0 Read Data Cycles PRDATA0 Access Type: Read-only Offset: 0x804 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 19 18 17 16 11 10 9 8 3 2 1 0 DATA[31:24] 23 22 21 20 DATA[23:16] 15 14 13 12 DATA[15:8] 7 6 5 4 DATA[7:0] * DATA: Data Cycles Counted Since Last Reset Clock cycles are counted using the CLK_PDCA_HSB clock 393 32117A-10/2010 AT32UC3C 20.7.19 Name: Performance Channel 0 Read Stall Cycles PRSTALL0 Access Type: Read-only Offset: 0x808 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 19 18 17 16 11 10 9 8 3 2 1 0 STALL[31:24] 23 22 21 20 STALL[23:16] 15 14 13 12 STALL[15:8] 7 6 5 4 STALL[7:0] * STALL: Stall Cycles Counted Since Last Reset Clock cycles are counted using the CLK_PDCA_HSB clock 394 32117A-10/2010 AT32UC3C 20.7.20 Name: Performance Channel 0 Read Max Latency PRLAT0 Access Type: Read/Write Offset: 0x80C Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 3 2 1 0 LAT[15:8] 7 6 5 4 LAT[7:0] * LAT: Maximum Transfer Initiation Cycles Counted Since Last Reset Clock cycles are counted using the CLK_PDCA_HSB clock This counter is saturating. The register is reset only when PCONTROL.CH0RES is written to one. 395 32117A-10/2010 AT32UC3C 20.7.21 Name: Performance Channel 0 Write Data Cycles PWDATA0 Access Type: Read-only Offset: 0x810 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 19 18 17 16 11 10 9 8 3 2 1 0 DATA[31:24] 23 22 21 20 DATA[23:16] 15 14 13 12 DATA[15:8] 7 6 5 4 DATA[7:0] * DATA: Data Cycles Counted Since Last Reset Clock cycles are counted using the CLK_PDCA_HSB clock 396 32117A-10/2010 AT32UC3C 20.7.22 Name: Performance Channel 0 Write Stall Cycles PWSTALL0 Access Type: Read-only Offset: 0x814 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 19 18 17 16 11 10 9 8 3 2 1 0 STALL[31:24] 23 22 21 20 STALL[23:16] 15 14 13 12 STALL[15:8] 7 6 5 4 STALL[7:0] * STALL: Stall Cycles Counted Since Last Reset Clock cycles are counted using the CLK_PDCA_HSB clock 397 32117A-10/2010 AT32UC3C 20.7.23 Name: Performance Channel 0 Write Max Latency PWLAT0 Access Type: Read/Write Offset: 0x818 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 3 2 1 0 LAT[15:8] 7 6 5 4 LAT[7:0] * LAT: Maximum Transfer Initiation Cycles Counted Since Last Reset Clock cycles are counted using the CLK_PDCA_HSB clock This counter is saturating. The register is reset only when PCONTROL.CH0RES is written to one. 398 32117A-10/2010 AT32UC3C 20.7.24 Name: Performance Channel 1 Read Data Cycles PRDATA1 Access Type: Read-only Offset: 0x81C Reset Value: 0x00000000 31 30 29 28 27 26 25 24 19 18 17 16 11 10 9 8 3 2 1 0 DATA[31:24] 23 22 21 20 DATA[23:16] 15 14 13 12 DATA[15:8] 7 6 5 4 DATA[7:0] * DATA: Data Cycles Counted Since Last Reset Clock cycles are counted using the CLK_PDCA_HSB clock 399 32117A-10/2010 AT32UC3C 20.7.25 Name: Performance Channel 1 Read Stall Cycles PRSTALL1 Access Type: Read-only Offset: 0x820 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 19 18 17 16 11 10 9 8 3 2 1 0 STALL[31:24] 23 22 21 20 STALL[23:16] 15 14 13 12 STALL[15:8] 7 6 5 4 STALL[7:0] * STALL: Stall Cycles Counted Since Last Reset Clock cycles are counted using the CLK_PDCA_HSB clock 400 32117A-10/2010 AT32UC3C 20.7.26 Name: Performance Channel 1 Read Max Latency PLATR1 Access Type: Read/Write Offset: 0x824 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 3 2 1 0 LAT[15:8] 7 6 5 4 LAT[7:0] * LAT: Maximum Transfer Initiation Cycles Counted Since Last Reset Clock cycles are counted using the CLK_PDCA_HSB clock This counter is saturating. The register is reset only when PCONTROL.CH1RES is written to one. 401 32117A-10/2010 AT32UC3C 20.7.27 Name: Performance Channel 1 Write Data Cycles PWDATA1 Access Type: Read-only Offset: 0x828 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 19 18 17 16 11 10 9 8 3 2 1 0 DATA[31:24] 23 22 21 20 DATA[23:16] 15 14 13 12 DATA[15:8] 7 6 5 4 DATA[7:0] * DATA: Data Cycles Counted Since Last Reset Clock cycles are counted using the CLK_PDCA_HSB clock 402 32117A-10/2010 AT32UC3C 20.7.28 Name: Performance Channel 1 Write Stall Cycles PWSTALL1 Access Type: Read-only Offset: 0x82C Reset Value: 0x00000000 31 30 29 28 27 26 25 24 19 18 17 16 11 10 9 8 3 2 1 0 STALL[31:24] 23 22 21 20 STALL[23:16] 15 14 13 12 STALL[15:8] 7 6 5 4 STALL[7:0] * STALL: Stall Cycles Counted Since Last Reset Clock cycles are counted using the CLK_PDCA_HSB clock 403 32117A-10/2010 AT32UC3C 20.7.29 Name: Performance Channel 1 Write Max Latency PWLAT1 Access Type: Read/Write Offset: 0x830 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 3 2 1 0 LAT[15:8] 7 6 5 4 LAT[7:0] * LAT: Maximum Transfer Initiation Cycles Counted Since Last Reset Clock cycles are counted using the CLK_PDCA_HSB clock This counter is saturating. The register is reset only when PCONTROL.CH1RES is written to one. 404 32117A-10/2010 AT32UC3C 20.7.30 Name: PDCA Version Register VERSION Access Type: Read-only Offset: 0x834 Reset Value: - 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - 15 14 13 12 9 8 - - - - 7 6 5 4 VARIANT 11 10 VERSION[11:8] 3 2 1 0 VERSION[7:0] * VARIANT: Variant Number Reserved. No functionality associated. * VERSION: Version Number Version number of the module. No functionality associated. 405 32117A-10/2010 AT32UC3C 20.8 Module Configuration The specific configuration for the PDCA instance is listed in the following tables. Table 20-6. PDCA Configuration Features PDCA Number of channels 16 Number of performance monitors 1 Table 20-7. Module Clock Name Module name Clock name Description CLK_PDCA_HSB HSB clock CLK_PDCA_PB Peripheral Bus clock from the PBC clock domain PDCA Table 20-8. Register Reset Values Register Reset Value PSRn n VERSION 0x123 The table below defines the valid Peripheral Identifiers (PIDs). The direction is specified as observed from the memory, so RX means transfers from peripheral to memory and TX means from memory to peripheral. Table 20-9. Peripheral Identity Values PID Direction Peripheral Instance Peripheral Register 0 RX ADCIFA LCV0 1 RX ADCIFA LCV1 2 RX USART0 RHR 3 RX USART1 RHR 4 RX USART2 RHR 5 RX USART3 RHR 6 RX TWIM0 RHR 7 RX TWIM1 RHR 8 RX TWIS0 RHR 9 RX TWIS1 RHR 10 RX SPI0 RDR 11 RX SPI1 RDR 12 RX AW RHR 13 TX USART0 THR 14 TX USART1 THR 15 TX USART2 THR 16 TX USART3 THR 406 32117A-10/2010 AT32UC3C Table 20-9. Peripheral Identity Values PID Direction Peripheral Instance Peripheral Register 17 TX TWIM0 THR 18 TX TWIM1 THR 19 TX TWIS0 THR 20 TX TWIS1 THR 21 TX SPI0 TDR 22 TX SPI1 TDR 23 TX DACIFB0 DR0 24 TX DACIFB0 DR1 25 TX DACIFB1 DR0 26 TX DACIFB1 DR1 27 TX PWM PWM PDCA register 28 TX AW THR 31 RX USART4 RHR 32 RX TWIM2 RHR 33 RX TWIS2 RHR 34 TX USART4 THR 35 TX TWIM2 THR 36 TX TWIS2 THR [44:37] RX IISC RHR [52:45] TX IISC THR 407 32117A-10/2010 AT32UC3C 21. Memory DMA Controller (MDMA) Rev 1.0.1.0 21.1 Features * * * * * * * * * 21.2 1-4 DMA channels, depending on implementation Chained (descriptor-list controlled) or unchained (single) transfers Descriptor read and writeback support Descriptors are placed in circular buffers of programmable length Programmable fixed or round-robin priority between channels Programmable burst length (1, 4, 8, or 16-beat) Byte/halfword/word transfers Optional endianess-conversion on transferred data Interrupt on transfer complete Overview The purpose of the MDMA is to perform memory-to-memory transfers. For peripheral-to-memory transfers, the Peripheral DMA Controller should be used instead. The MDMA has two HSB master interfaces. One interface is dedicated to reading data while the other is dedicated to writing. The MDMA is configured through a Peripheral Bus (PB) interface. A DMA transfer on a channel can be started manually by writing the MDMA configuration registers for that channel. This transfer mode is referred to as Single Transfer Mode. MDMA channels can also be controlled by a descriptor list in memory. The descriptor list contains all information needed to control a transfer. Once a transfer has been completed, the MDMA automatically reads the next descriptor, and if this descriptor is valid, starts the next DMA transfer. This transfer mode is referred to Descriptor Mode. 21.3 Product Dependencies In order to use this module, other parts of the system must be configured correctly, as described below. 21.3.1 Power Management If the CPU enters a sleep mode that disables clocks used by the MDMA, the MDMA will stop functioning and resume operation after the system wakes up from sleep mode. 21.3.2 Clocks The MDMA has two bus clocks connected: One High Speed Bus clock (CLK_MDMA_HSB) and one Peripheral Bus clock (CLK_MDMA_PB). These clocks are generated by the Power Manager. Both clocks are enabled at reset, and can be disabled in the Power Manager. The user has to ensure that CLK_MDMA_HSB is not turned off while performing MDMA transfers. Failing to do so may deadlock the HSB. 21.3.3 Interrupts The MDMA interrupt request lines are connected to the interrupt controller. Using the MDMA interrupts requires the interrupt controller to be programmed first. 408 32117A-10/2010 AT32UC3C 21.3.4 21.4 21.4.1 Debug Operation When an external debugger forces the CPU into debug mode, the MDMA continues normal operation. If the MDMA 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. Functional Description Bus Interfaces The MDMA has three bus interfaces, two High-Speed Bus interfaces for data and descriptor transfer, and one Peripheral Bus interface for writing control information to and reading status information from the controller. 21.4.2 Transferring Data Once a channel is selected by the arbiter, data of the size given by the SIZE field in the Channel Control Register (CCR.SIZE) will be transferred from consecutive addresses starting as specified in the Read Address Register (RAR) to consecutive addresses starting as specified in the Write Address Register (WAR). The number of data to be transferred is given by the Transfer Count field (CCR.TCNT). The MDMA will try to transfer data in bursts with burst length given by CCR.BURST. The MDMA is free to use bursts of shorter length if this is required by the bus semantics or if TCNT is not perfectly divisible by BURST. During transfers, TCNT is continuously decremented until it reaches zero, indicating that the transfer has completed. RAR and WAR are not changed by hardware during transfers. Data read from the bus is put into a FIFO before being written to the bus. The FIFO has wordsized entries, so any halfwords or bytes transferred from the bus will be zero-extended before being put in the FIFO. Words are not extended in any way. The Byte Swap (BSWP) field in CCR determines if any modifications are to be performed on the read data from the zero-extension unit. This allows data reformatting such as endianness-conversion. Figure 21-1. Byte Swapping the FIFO Inputs FIFO Write data 21.4.3 Byte swap Zeroextend Read data Arbitration Arbitration between the channels is performed at the end of each burst. If no other channels have pending transfers, the current channel continues uninterrupted. In Fixed Priority Mode, if a channel of higher priority is enabled when another channel is transferring data, the channel of higher priority will preempt the other channel. When the preempting channel has completed, the arbiter will grant control to the original channel so it can complete its transfer. 409 32117A-10/2010 AT32UC3C In Round-Robin Mode, other channels with transfers pending will preempt the current channel in a round-robin fashion. This eliminates the possibility of starvation. 21.4.4 Aborting Transfers Transfers on any channel can be gracefully aborted by writing a one to the corresponding Channel Disable bit in the Control Register (CR.CHxDIS). Note that in order to successfully write to CHxDIS, the same write operation must also write a one to the corresponding Channel Enable bit (CR.CHxEN). Successfully writing to CHxDIS will result in both CHxEN and CHxDIS being cleared. CHxEN can not be cleared by simply writing a zero to it. The hardware will disable the transfer as soon as possible. Since the transfer must terminate gracefully, the CHxEN bits may not be cleared immediately after writing CHxDIS. The user could poll CHxDIS to check when the channel has been disabled. 21.4.5 Interrupts The MDMA can generate an interrupts when a channel has completed a transfer or when a DMA transfer causes a bus error. Interrupts are only generated if enabled in the Interrupt Mask Register (IMR). IMR is read-only, but can be modified through the write-only Interrupt Enable Register (IER) and Interrupt Disable Register (IDR). An interrupt is enabled by writing a one to the corresponding bit in the IER. An interrupt is disabled by writing a one to the corresponding bit in the IDR. If an interrupt occurs, the corresponding bit in the Interrupt Status Register (ISR) is set and an interrupt request is generated. Bits in ISR and their corresponding interrupt request can be cleared by writing to the appropriate bits in the Interrupt Clear Register (ICR). 21.4.6 Bus Errors Any bus errors from transfers on a channel will automatically disable the channel. Other channels will not be affected by this. An interrupt is generated if not masked by the Interrupt Mask Register (IMR). 21.5 Single Transfer Mode The Single Transfer Mode (STM) is the simplest transfer mode. The software programs the registers controlling the channel, writes the correct enable bit (CR.CHxEN), and the transfer starts. The transfer can be preempted if a channel with higher priority is enabled before the transfer completes, or if we use Round-Robin Mode. When the transfer completes, the CR.CHxEN bit is automatically cleared. If the Channel Complete interrupt is enabled in IMR (IMR.CHxC is one), an interrupt request is generated. In order to perform a transfer in STM, the following steps must be performed: 1. Make sure that the channel is free by checking the CR.CHxEN bit, or by waiting for a Transfer Complete interrupt from the channel. 2. Set up the Read Address Register, Write Address Register and Channel Control Register associated with the channel. 3. Enable the desired interrupts by writing a one to the corresponding bits in the Interrupt Enable Register (IER). 4. Write a one to CR.CHxEN to start the transfer. Make sure the Channel Mode bit (CR.CHxM) for the channel is zero (channel is in Single Transfer Mode) 5. When the transfer completes, the CHxEN bit is automatically cleared. If the Channel Complete interrupt for the channel is enabled, the corresponding bit in the Interrupt Status Register (ISR.CHxC) is set. 410 32117A-10/2010 AT32UC3C 21.6 Descriptor Mode The Descriptor Mode (DM) performs a series of single transfers. Data describing the transfers to be performed are written to memory by software, forming a queue of descriptors, each descriptor describing a transfer to be performed. 21.6.1 Setting Up and Using the Descriptors Before being able to use the Descriptor Mode, the channel's Descriptor Start Address (DSAR) register must be initialized to point to the first descriptor in the queue. Thereafter, the Current Descriptor Address Register (CDAR) must be initialized to the same value. When the CR.CHxEN bit is written to one, hardware will read the first descriptor in the queue, and perform the transfer described therein. When this transfer has finished, the hardware will update the descriptor associated with the transfer, clearing the V bit in the descriptor data structure located in memory. Thereafter, the hardware will read the next descriptor in the queue. The address of this descriptor is dependent on the L bit of the descriptor that just completed, see Section 21.6.2. If the new descriptor has its V bit set, the transfer described by this descriptor will be performed. When the transfer is complete, the descriptor will be written back to memory, with the V bit cleared. Thereafter, the next descriptor will be read. This continues until a descriptor with a cleared V bit is read. The queue is then empty, and all transfers described in the queue have been performed. The CR.CHxEN bit will then be cleared, and the channel will become idle. In order to restart the channel, the descriptor pointed to by the Current Descriptor Address Register (CDAR) for the channel must be updated by writing to the appropriate memory locations. Thereafter, the CHxEN bit must be written to one. This will cause the descriptor to be read into the MDMA, and the transfer will start. 21.6.2 Descriptor Organization The descriptor list is implemented as a ring of descriptors placed in memory. The length of the descriptor ring is programmable; the last descriptor in the ring has its L bit set, indicating that the next element in the ring is at the address pointed to by the Descriptor Start Address Register (DSAR). Each descriptor consists of four words. When a descriptor is loaded into the MDMA, the first three of these words are read into the appropriate registers, while the fourth word is discarded. 411 32117A-10/2010 AT32UC3C Figure 21-2. Descriptors in Memory Descriptor 1 Descriptor n Dn RAR Dn WAR Dn CCR UNUSED DSAR Wrapping Addresses Descriptor 0 Growing Memory Addresses 21.6.3 D0 RAR D0 WAR D0 CCR UNUSED D1 RAR D1 WAR D1 CCR UNUSED Last bit set Adding Descriptors to a List In order to add descriptors to a list, the following actions must be performed: 1. Check if there are free entries in the list for the desired channel. Any entry with the V bit cleared is free. If no entries are free, wait until an entry becomes free. 2. Find the first free entry in the list. This can be done by scanning the descriptor list from the entry pointed to by CDAR downto the first descriptor with the V bit cleared. 3. Update the free entry by writing the desired values to the correct memory locations. 4. Make sure the CHxM bit for the channel is one (channel is in Descriptor Mode), and write a one to the CHxEN bit. Writing a one to CHxEN when the CHxEN bit is one has no effect, so the user does not need to check the state of CHxEN before adding descriptors to the list. 21.6.4 Interrupts in Descriptor Mode Interrupt on transfer complete and bus error can be enabled as described in Section 21.4.5. 412 32117A-10/2010 AT32UC3C 21.7 User interface Table 21-1. MDMA Register Memory Map Offset Register Register Name Channel Access Reset 0x00 Control Register CR - Read/Write 0x00000000 0x04 Interrupt Enable Register IER - Write-only 0x00000000 0x08 Interrupt Disable Register IDR - Write-only 0x00000000 0x0C Interrupt Mask Register IMR - Read-only 0x00000000 0x10 Interrupt Status Register ISR - Read-only 0x00000000 0x14 Interrupt Clear Register ICR - Write-only 0x00000000 0x18 Parameter Register PR - Read-only - (1) 0x1C Version Register VR - Read-only -(1) 0x20 Descriptor Start Address DSAR0 0 Read/Write 0x00000000 0x24 Descriptor Start Address DSAR1 1 Read/Write 0x00000000 0x28 Descriptor Start Address DSAR2 2 Read/Write 0x00000000 0x2C Descriptor Start Address DSAR3 3 Read/Write 0x00000000 0x30-3C RESERVED - - Read-only 0x00000000 0x40 Current Descriptor Address Register CDAR0 0 Read/Write 0x00000000 0x44 Read Address Register RAR0 0 Read/Write 0x00000000 0x48 Write Address Register WAR0 0 Read/Write 0x00000000 0x4C Channel Control Register CCR0 0 Read/Write 0x00000000 0x50 Current Descriptor Address Register CDAR1 1 Read/Write 0x00000000 0x54 Read Address Register RAR1 1 Read/Write 0x00000000 0x58 Write Address Register WAR1 1 Read/Write 0x00000000 0x5C Channel Control Register CCR1 1 Read/Write 0x00000000 0x60 Current Descriptor Address Register CDAR2 2 Read/Write 0x00000000 0x64 Read Address Register RAR2 2 Read/Write 0x00000000 0x68 Write Address Register WAR2 2 Read/Write 0x00000000 0x6C Channel Control Register CCR2 2 Read/Write 0x00000000 0x70 Current Descriptor Address Register CDAR3 3 Read/Write 0x00000000 0x74 Read Address Register RAR3 3 Read/Write 0x00000000 0x78 Write Address Register WAR3 3 Read/Write 0x00000000 0x7C Channel Control Register CCR3 3 Read/Write 0x00000000 1. The reset values for these registers are device specific. Please refer to the Module Configuration section at the end of this chapter. Note: The number of DMA channels is device-specific. Not all devices will implement all four channels. These devices will not implement all user interface registers. Unimplemented registers will always read as 0. 413 32117A-10/2010 AT32UC3C 21.7.1 Name: Control Register CR Access Type : Read/Write Offset: 0x00 Reset Value: 0x000000000 31 30 29 28 27 26 25 24 - - - - - - - ARB 23 22 21 20 19 18 17 16 - - - - CH3DIS CH2DIS CH1DIS CH0DIS 15 14 13 12 11 10 9 8 - - - - CH3M CH2M CH1M CH0M 7 6 5 4 3 2 1 0 - - - - CH3EN CH2EN CH1EN CH0EN * ARB: Arbitration Mode 0: The MDMA is in Fixed Priority Mode. 1: The MDMA is in Round-Robin Mode. * CHxDIS: Channel Disable Writing a zero to this bit has no effect. Writing a one to this bit disables the MDMA channel after the current transfer has completed. To avoid hazards, CHxDIS bits can only be changed by writing a value to CR where the corresponding CHxEN bit is set. This bit is automatically cleared by hardware when the corresponding channel has been disabled. * CHxM: Channel Mode 0: The channel is in Single Transfer Mode. 1: The channel is in Descriptor Mode. To avoid hazards, CHxM bits can only be changed by writing a value to CR where the corresponding CHxEN bit is set. * CHxEN: Channel Enable Writing a zero to this bit this bit has no effect. Writing a one to this bit enables the channel for DMA transfer. This bit is automatically cleared if the transfer completes when the channel is in single transfer mode. This bit is automatically cleared if the transfer completes when the channel is in descriptor mode, and the next descriptor read in has a cleared Valid bit. This bit is automatically cleared when the corresponding channel has been disabled by writing a one to CHxDIS. 414 32117A-10/2010 AT32UC3C 21.7.2 Name: Interrupt Enable Register IER Access Type: Write-only Offset: 0x04 Reset Value: 0x000000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 - - - - BERR3 BERR2 BERR1 BERR0 7 6 5 4 3 2 1 0 - - - - CH3C CH2C CH1C CH0C Writing a zero to a bit in this register has no effect. Writing a one to a bit in this register clears the corresponding bit in Interrupt Mask Register (IMR). 415 32117A-10/2010 AT32UC3C 21.7.3 Name: Interrupt Disable Register IDR Access Type: Write-only Offset: 0x08 Reset Value: 0x000000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 - - - - BERR3 BERR2 BERR1 BERR0 7 6 5 4 3 2 1 0 - - - - CH3C CH2C CH1C CH0C Writing a zero to a bit in this register has no effect. Writing a one to a bit in this register sets the corresponding bit in Interrupt Mask Register (IMR). 416 32117A-10/2010 AT32UC3C 21.7.4 Name: Interrupt Mask Register IMR Access Type: Read-only Offset: 0x0C Reset Value: 0x000000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 - - - - BERR3 BERR2 BERR1 BERR0 7 6 5 4 3 2 1 0 - - - - CH3C CH2C CH1C CH0C 0: The corresponding interrupt is disabled. 1: The corresponding interrupt is enabled. A bit in this register is cleared when the corresponding bit in IDR is written to one. A bit in this register is set when the corresponding bit in IER is written to one. 417 32117A-10/2010 AT32UC3C 21.7.5 Name: Interrupt Status Register ISR Access Type: Read-only Offset: 0x10 Reset Value: 0x000000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 - - - - BERR3 BERR2 BERR1 BERR0 7 6 5 4 3 2 1 0 - - - - CH3C CH2C CH1C CH0C * BERRx: Channel Bus Error This bit is cleared when the corresponding bit in ICR is written to one. This bit is set when the channel has encountered a bus error and has an interrupt request pending. Upon receiving a bus error, the affected channel is automatically disabled. * CHxC: Channel Complete This bit is cleared when the corresponding bit in ICR is written to one. This bit is set when the channel has completed a transfer and has an interrupt request pending. 418 32117A-10/2010 AT32UC3C 21.7.6 Name: Interrupt Clear Register ICR Access Type: Write-only Offset: 0x14 Reset Value: 0x000000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 - - - - BERR3 BERR2 BERR1 BERR0 7 6 5 4 3 2 1 0 - - - - CH3C CH2C CH1C CH0C Writing a zero to a bit in this register has no effect. Writing a one to a bit in this register clears the corresponding bit in ISR and the corresponding interrupt request. 419 32117A-10/2010 AT32UC3C 21.7.7 Name: Parameter Register PR Access Type: Read-only Offset: 0x18 Reset Value: - 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 - - - - - - 7 6 5 4 3 2 1 0 - - - - CH3I CH2I CH1I CH0I BURST * BURST: Maximum Burst Size The maximum burst size that can be used is a function of the FIFO size, which can be different in different devices. This field gives the largest burst size that is supported by the device. 0: Single transfer 1: 4-beat burst 2: 8-beat burst 3: 16-beat burst * CHxI: Channel Implemented 0: The channel is not implemented in the current device, and cannot be used. 1: The channel is implemented in the current device. 420 32117A-10/2010 AT32UC3C 21.7.8 Name: Version Register VR Access Type: Read-only Offset: 0x1C Reset Value: - 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 - - - - 7 6 5 4 VERSION[11:8] 3 2 1 0 VERSION[7:0] * VERSION: Version Number Version number of the module. No functionality associated. 421 32117A-10/2010 AT32UC3C 21.7.9 Name: Descriptor Start Address Register DSAR Access Type: Read/Write Offset: 0x20, 0x24, 0x28, 0x2C Reset Value: 0x000000000 31 30 29 28 27 26 25 24 19 18 17 16 11 10 9 8 3 2 1 0 DSAR[31:24] 23 22 21 20 DSAR[23:16] 15 14 13 12 DSAR[15:8] 7 6 5 4 DSAR[7:0] * DSAR: Descriptor Start Address Register The address of the first descriptor in the chain. When the hardware has read a descriptor with the CCR.L bit set, the next descriptor will be read from the address in DSAR. Must be aligned to word size. 422 32117A-10/2010 AT32UC3C 21.7.10 Name: Current Descriptor Address Register CDAR Access Type: Read/Write Offset: 0x40, 0x50, 0x60, 0x70 Reset Value: 0x000000000 31 30 29 28 27 26 25 24 19 18 17 16 11 10 9 8 3 2 1 0 CDAR[31:24] 23 22 21 20 CDAR[23:16] 15 14 13 12 CDAR[15:8] 7 6 5 4 CDAR[7:0] * CDAR: Current Descriptor Address Register The memory address pointing to the currently active descriptor. This is either the descriptor of the current access if the channel is enabled, or the address of the descriptor that will be loaded if the channel is not enabled. Must be word-aligned. Not used if the channel is not in Descriptor Mode. 423 32117A-10/2010 AT32UC3C 21.7.11 Name: Read Address Register RAR Access Type: Read/Write Offset: 0x44, 0x54, 0x64, 0x74 Reset Value: 0x000000000 31 30 29 28 27 26 25 24 19 18 17 16 11 10 9 8 3 2 1 0 RAR[31:24] 23 22 21 20 RAR[23:16] 15 14 13 12 RAR[15:8] 7 6 5 4 RAR[7:0] * RAR: Read Address Register The memory address that the next read access will be done from. Must be aligned according to the transfer size. 424 32117A-10/2010 AT32UC3C 21.7.12 Name: Write Address Register WAR Access Type: Read/Write Offset: 0x48, 0x58, 0x68, 0x78 Reset Value: 0x000000000 31 30 29 28 27 26 25 24 19 18 17 16 11 10 9 8 3 2 1 0 WAR[31:24] 23 22 21 20 WAR[23:16] 15 14 13 12 WAR[15:8] 7 6 5 4 WAR[7:0] * WAR: Write Address Register The memory address that the next write access will be done to. Must be aligned according to the transfer size. 425 32117A-10/2010 AT32UC3C 21.7.13 Name: Channel Control Register CCR Access Type: Read/Write Offset: 0x4C, 0x5C, 0x6C, 0x7C Reset Value: 0x000000000 31 30 29 28 27 26 - - - - - - 23 22 21 20 19 18 - L V TCIE 15 14 13 12 25 24 BSWP 17 BURST 16 SIZE 11 10 9 8 3 2 1 0 TCNT[15:8] 7 6 5 4 TCNT[7:0] * BSWP: Byte Swap Allows swapping of the transferred bytes, see Section 21.4.2. Assuming the word output from the zero-extension module contains the bytes {a, b, c, d}. The following will be put into the FIFO for transmission: 0: {a, b, c, d} 1: {d, c, b, a} 2: {c, d, a, b} 3: {b, a, d, c} * L: Last Descriptor in Chain Used only if the channel is in Descriptor Mode. 0: The descriptor read in is not the last descriptor in the chain. The next descriptor to be read is located at the address of the previously read descriptor + 4 words. 1: The descriptor read in is the last descriptor in the chain. The next descriptor to be read is located at the address in the Descriptor Start Address Register (DSAR) for the channel. * V: Descriptor Valid Used only if the channel is in Descriptor Mode. 0: The descriptor read in is not valid. 1: The descriptor read in is valid. * TCIE: Transfer Complete Interrupt Enable 0: Transfer Complete does not set the ISR.CHxC bit. 1: Transfer Complete sets the ISR.CHxC bit. * BURST: Transfer Burst Size Indicates the size of the burst used for data transfer. The MDMA will always try to use this burst size to perform transfers, but may be forced to use smaller sizes since the transfer count may not be perfectly divisible by the transfer data size. 0: Single transfer 1: 4-beat burst 2: 8-beat burst 3: 16-beat burst 426 32117A-10/2010 AT32UC3C * SIZE: Transfer Data Size Indicates the size of data to transfer. 0: Byte 1: Halfword 2: Word 3: Unused * TCNT: Transfer Count The number of data to transfer. The size of each data is given in the SIZE field. Configuring a transfer with a TCNT of 0 is illegal, and may result in UNDEFINED behavior. 427 32117A-10/2010 AT32UC3C 21.8 Module Configuration The specific configuration for each MDMA instance is listed in the following tables. The module bus clocks listed here are connected to the system bus clocks. Refer to the Power Manager chapter for details. Table 21-2. Module Configuration Feature MDMA Channels 1 Maximum burst size Single Transfer Table 21-3. Module name Module Clock Name Clock name Description CLK_MDMA_HSB HSB clock CLK_MDMA_PB Peripheral Bus clock from the PBC clock domain MDMA Table 21-4. Register Reset Values Register Reset Value VR 0x00000101 PR 0x00000001 428 32117A-10/2010 AT32UC3C 22. Secure Access Unit (SAU) Rev 1.1.1.2 22.1 Features * Remaps registers in memory regions protected by the MPU to regions not protected by the MPU * Programmable physical address for each channel * Two modes of operation: Locked and Open - In Locked Mode, access to a channel must be preceded by an unlock action * An unlocked channel remains open only for a specific amount of time, if no access is performed during this time, the channel is relocked * Only one channel can be open at a time, opening a channel while another one is open locks the first one * Access to a locked channel is denied, a bus error and optionally an interrupt is returned * If a channel is relocked due to an unlock timeout, an interrupt can optionally be generated - In Open Mode, all channels are permanently unlocked 22.2 Overview In many systems, erroneous access to peripherals can lead to catastrophic failure. An example of such a peripheral is the Pulse Width Modulator (PWM) used to control electric motors. The PWM outputs a pulse train that controls the motor. If the control registers of the PWM module are inadvertently updated with wrong values, the motor can start operating out of control, possibly causing damage to the application and the surrounding environment. However, sometimes the PWM control registers must be updated with new values, for example when modifying the pulse train to accelerate the motor. A mechanism must be used to protect the PWM control registers from inadvertent access caused by for example: * Errors in the software code * Transient errors in the CPU caused by for example electrical noise altering the execution path of the program To improve the security in a computer system, the AVR32UC implements a Memory Protection Unit (MPU). The MPU can be set up to limit the accesses that can be performed to specific memory addresses. The MPU divides the memory space into regions, and assigns a set of access restrictions on each region. Access restrictions can for example be read/write if the CPU is in supervisor mode, and read-only if the CPU is in application mode. The regions can be of different size, but each region is usually quite large, e.g. protecting 1 kilobyte of address space or more. Furthermore, access to each region is often controlled by the execution state of the CPU, i.e. supervisor or application mode. Such a simple control mechanism is often too inflexible (too coarse-grained chunks) and with too much overhead (often requiring system calls to access protected memory locations) for simple or real-time systems such as embedded microcontrollers. Usually, the Secure Access Unit (SAU) is used together with the MPU to provide the required security and integrity. The MPU is set up to protect regions of memory, while the SAU is set up to provide a secure channel into specific memory locations that are protected by the MPU. These specific locations can be thought of as fine-grained overrides of the general coarsegrained protection provided by the MPU. 429 32117A-10/2010 AT32UC3C 22.3 Block Diagram Figure 22-1 presents the SAU integrated in an example system with a CPU, some memories, some peripherals, and a bus system. The SAU is connected to both the Peripheral Bus (PB) and the High Speed Bus (HSB). Configuration of the SAU is done via the PB, while memory accesses are done via the HSB. The SAU receives an access on its HSB slave interface, remaps it, checks that the channel is unlocked, and if so, initiates a transfer on its HSB master interface to the remapped address. The thin arrows in Figure 22-1 exemplifies control flow when using the SAU. The CPU wants to read the RX Buffer in the USART. The MPU has been configured to protect all registers in the USART from user mode access, while the SAU has been configured to remap the RX Buffer into a memory space that is not protected by the MPU. This unprotected memory space is mapped into the SAU HSB slave space. When the CPU reads the appropriate address in the SAU, the SAU will perform an access to the desired RX buffer register in the USART, and thereafter return the read results to the CPU. The return data flow will follow the opposite direction of the control flow arrows in Figure 22-1. Figure 22-1. SAU Block Diagram CPU MPU Flash RAM Bus master Bus slave Bus slave High Speed Bus Bus slave Bus master Bus slave Bus bridge SAU Channel SAU Interrupt request USART PWM Peripheral Bus SAU Configuration 430 32117A-10/2010 AT32UC3C 22.4 Product Dependencies In order to use this module, other parts of the system must be configured correctly, as described below. 22.4.1 Power Management If the CPU enters a sleep mode that disables clocks used by the SAU, the SAU will stop functioning and resume operation after the system wakes up from sleep mode. 22.4.2 Clocks The SAU has two bus clocks connected: One High Speed Bus clock (CLK_SAU_HSB) and one Peripheral Bus clock (CLK_SAU_PB). These clocks are generated by the Power Manager. Both clocks are enabled at reset, and can be disabled by writing to the Power Manager. The user has to ensure that CLK_SAU_HSB is not turned off before accessing the SAU. Likewise, the user must ensure that no bus access is pending in the SAU before disabling CLK_SAU_HSB. Failing to do so may deadlock the High Speed Bus. 22.4.3 Interrupt The SAU interrupt request line is connected to the interrupt controller. Using the SAU interrupt requires the interrupt controller to be programmed first. 22.4.4 22.5 Debug Operation When an external debugger forces the CPU into debug mode, the SAU continues normal operation. If the SAU 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. Functional Description 22.5.1 Enabling the SAU The SAU is enabled by writing a one to the Enable (EN) bit in the Control Register (CR). This will set the SAU Enabled (EN) bit in the Status Register (SR). 22.5.2 Configuring the SAU Channels The SAU has a set of channels, mapped in the HSB memory space. These channels can be configured by a Remap Target Register (RTR), located at the same memory address. When the SAU is in normal mode, the SAU channel is addressed, and when the SAU is in setup mode, the RTR can be addressed. Before the SAU can be used, the channels must be configured and enabled. To configure a channel, the corresponding RTR must be programmed with the Remap Target Address. To do this, make sure the SAU is in setup mode by writing a one to the Setup Mode Enable (SEN) bit in CR. This makes sure that a write to the RTR address accesses the RTR, not the SAU channel. Thereafter, the RTR is written with the address to remap to, typically the address of a specific PB register. When all channels have been configured, return to normal mode by writing a one to the Setup Mode Disable (SDIS) in CR. The channels can now be enabled by writing ones to the corresponding bits in the Channel Enable Registers (CERH/L). The SAU is only able to remap addresses above 0xFFFC0000. 431 32117A-10/2010 AT32UC3C 22.5.2.1 22.5.3 Protecting SAU configuration registers In order to prevent the SAU configuration registers to be changed by malicious or runaway code, they should be protected by the MPU as soon as they have been configured. Maximum security is provided in the system if program memory does not contain any code to unprotect the configuration registers in the MPU. This guarantees that runaway code can not accidentally unprotect and thereafter change the SAU configuration registers. Lock Mechanism The SAU can be configured to use two different access mechanisms: Open and Locked. In Open Mode, SAU channels can be accessed freely after they have been configured and enabled. In order to prevent accidental accesses to remapped addresses, it is possible to configure the SAU in Locked Mode. Writing a one to the Open Mode bit in the CONFIG register (CONFIG.OPEN) will enable Open Mode. Writing a zero to CONFIG.OPEN will enable Locked Mode. When using Locked Mode, the lock mechanism must be configured by writing a user defined key value to the Unlock Key (UKEY) field in the Configuration Register (CONFIG). The number of CLK_SAU_HSB cycles the channel remains unlocked must be written to the Unlock Number of Clock Cycles (UCYC) field in CONFIG. Access control to the SAU channels is enabled by means of the Unlock Register (UR), which resides in the same address space as the SAU channels. Before a channel can be accessed, the unlock key value must be written to UR.KEY, and the channel number to UR.CHANNEL. Access to the channel is then permitted for the next CONFIG.UCYC clock cycles, or until a successful access to the unlocked channel has been made. Only one channel can be unlocked at a time. If any other channel is unlocked at the time of writing UR, this channel will be automatically locked before the channel addressed by the UR write is unlocked. An attempted access to a locked channel will be aborted, and the Channel Access Unsuccessful bit (SR.CAU) will be set. Any pending errors bits in SR must be cleared before it is possible to access UR. The following SR bits are defined as error bits: EXP, CAU, URREAD, URKEY, URES, MBERROR, RTRADR. If any of these bits are set while writing to UR, the write is aborted and the Unlock Register Error Status (URES) bit in SR is set. 22.5.4 Normal Operation The following sequence must be used in order to access a SAU channel in normal operation (CR.SEN=0): 1. If not in Open Mode, write the unlock key to UR.KEY and the channel number to UR.CHANNEL. 2. Perform the read or write operation to the SAU channel. If not in Open Mode, this must be done within CONFIG.UCYC clock cycles of unlocking the channel. The SAU will use its HSB master interface to remap the access to the target address pointed to by the corresponding RTR. 3. To confirm that the access was successful, wait for the IDLE transfer status bit (SR.IDLE) to indicate the operation is completed. Then check SR for possible error conditions. The SAU can be configured to generate interrupt requests or a Bus Error Exception if the access failed. 432 32117A-10/2010 AT32UC3C 22.5.4.1 Operation example Figure 22-2 shows a typical memory map, consisting of some memories, some simple peripherals, and a SAU with multiple channels and an Unlock Register (UR). Imagine that the MPU has been set up to disallow all accesses from the CPU to the grey modules. Thus the CPU has no way of accessing for example the Transmit Holding register in the UART, present on address X on the bus. Note that the SAU RTRs are not protected by the MPU, thus the RTRs can be accessed. If for example RTR0 is configured to point to address X, an access to RTR0 will be remapped by the SAU to address X according to the algorithm presented above. By programming the SAU RTRs, specific addresses in modules that have generally been protected by the MPU can be performed. Figure 22-2. Example Memory Map for a System with SAU SAU CONFIG UART Receive Holding Transmit Holding Baudrate Control Address X SAU CHANNEL 22.5.5 ... UR RTR62 Channel RTR1 1 RTR0 Address Z Interrupts The SAU can generate an interrupt request to signal different events. All events that can generate an interrupt request have dedicated bits in the Status Register (SR). An interrupt request will be generated if the corresponding bit in the Interrupt Mask Register (IMR) is set. Bits in IMR are set by writing a one to the corresponding bit in the Interrupt Enable Register (IER), and cleared by writing a one to the corresponding bit in the Interrupt Disable Register (IDR). The interrupt request remains active until the corresponding bit in SR is cleared by writing a one to the corresponding bit in the Interrupt Clear Register (ICR). The following SR bits are used for signalling the result of SAU accesses: * RTR Address Error (RTRADR) is set if an illegal address is written to the RTRs. Only addresses in the range 0xFFFC0000-0xFFFFFFFF are allowed. * Master Interface Bus Error (MBERROR) is set if any of the conditions listed in Section 22.5.7 occurred. 433 32117A-10/2010 AT32UC3C * Unlock Register Error Status (URES) is set if an attempt was made to unlock a channel by writing to the Unlock Register while one or more error bits in SR were set (see Section 22.5.6). The unlock operation was aborted. * Unlock Register Key Error (URKEY) is set if the Unlock Register was attempted written with an invalid key. * Unlock Register Read (URREAD) is set if the Unlock Register was attempted read. * Channel Access Unsuccessful (CAU) is set if the channel access was unsuccessful. * Channel Access Successful (CAS) is set if the channel access was successful. * Channel Unlock Expired (EXP) is set if the channel lock expired, with no channel being accessed after the channel was unlocked. 22.5.6 Error bits If error bits are set when attempting to unlock a channel, SR.URES will be set. The following SR bits are considered error bits: * EXP * CAU * URREAD * URKEY * URES * MBERROR * RTRADR 22.5.7 Bus Error Responses By writing a one to the Bus Error Response Enable bit (CR.BERREN), serious access errors will be configured to return a bus error to the CPU. This will cause the CPU to execute its Bus Error Data Fetch exception routine. The conditions that can generate a bus error response are: * Reading the Unlock Register * Trying to access a locked channel * The SAU HSB master receiving a bus error response from its addressed slave 22.5.8 Disabling the SAU To disable the SAU, the user must first ensure that no SAU bus operations are pending. This can be done by checking that the STATUS.IDLE bit is set. The SAU may then be disabled by writing a one to the Disable (DIS) bit in CR. 434 32117A-10/2010 AT32UC3C 22.6 User Interface The following addresses are used by SAU channel configuration registers. All offsets are relative to the SAU's PB base address. Table 22-1. SAU Configuration Register Memory Map Offset Register Register Name Access Reset 0x00 Control Register CR Write-only 0x00000000 0x04 Configuration Register CONFIG Write-only 0x00000000 0x08 Channel Enable Register High CERH Read/Write 0x00000000 0x0C Channel Enable Register Low CERL Read/Write 0x00000000 0x10 Status Register SR Read-only 0x00000000 0x14 Interrupt Enable Register IER Write-only 0x00000000 0x18 Interrupt Disable Register IDR Write-only 0x00000000 0x1C Interrupt Mask Register IMR Read-only 0x00000000 0x20 Interrupt Clear Register ICR Write-only 0x00000000 0x24 Parameter Register PARAMETER Read-only -(1) 0x28 Version Register VERSION Read-only -(1) 1. The reset values are device specific. Please refer to the Module Configuration section at the end of this chapter. Note: The following addresses are used by SAU channel registers. All offsets are relative to the SAU's HSB base address. The number of channels implemented is device specific, refer to the Module Configuration section at the end of this chapter. Table 22-2. SAU Channel Register Memory Map Offset Register Register Name Access Reset 0x00 Remap Target Register 0 RTR0 Read/Write N/A 0x04 Remap Target Register 1 RTR1 Read/Write N/A 0x08 Remap Target Register 2 RTR2 Read/Write N/A ... ... ... ... ... 0x04*n Remap Target Register n RTRn Read/Write N/A 0xFC Unlock Register UR Write-only N/A 435 32117A-10/2010 AT32UC3C 22.6.1 Name: Control Register CR Access Type: Write-only Offset: 0x00 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 - - - - - - - - 7 6 5 4 3 2 1 0 - - BERRDIS BERREN SDIS SEN DIS EN * BERRDIS: Bus Error Response Disable Writing a zero to this bit has no effect. Writing a one to this bit disables Bus Error Response from the SAU. * BERREN: Bus Error Response Enable Writing a zero to this bit has no effect. Writing a one to this bit enables Bus Error Response from the SAU. * SDIS: Setup Mode Disable Writing a zero to this bit has no effect. Writing a one to this bit exits setup mode. * SEN: Setup Mode Enable Writing a zero to this bit has no effect. Writing a one to this bit enters setup mode. * DIS: SAU Disable Writing a zero to this bit has no effect. Writing a one to this bit disables the SAU. * EN: SAU Enable Writing a zero to this bit has no effect. Writing a one to this bit enables the SAU. 436 32117A-10/2010 AT32UC3C 22.6.2 Name: Configuration Register CONFIG Access Type: Write-only Offset: 0x04 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - OPEN 15 14 13 12 11 10 9 8 3 2 1 0 UCYC 7 6 5 4 UKEY * OPEN: Open Mode Enable Writing a zero to this bit disables open mode. Writing a one to this bit enables open mode. * UCYC: Unlock Number of Clock Cycles Once a channel has been unlocked, it remains unlocked for this amount of CLK_SAU_HSB clock cycles or until one access to a channel has been made. * UKEY: Unlock Key The value in this register must be written into UR.KEY to unlock a channel. 437 32117A-10/2010 AT32UC3C 22.6.3 Name: Channel Enable Register High CERH Access Type: Read/Write Offset: 0x08 Reset Value: 0x00000000 31 30 29 28 - 23 27 26 25 24 19 18 17 16 11 10 9 8 3 2 1 0 CERH[30:24] 22 21 20 CERH[23:16] 15 14 13 12 CERH[15:8] 7 6 5 4 CERH[7:0] * CERH[n]: Channel Enable Register High 0: Channel (n+32) is not enabled. 1: Channel (n+32) is enabled. 438 32117A-10/2010 AT32UC3C 22.6.4 Name: Channel Enable Register Low CERL Access Type: Read/Write Offset: 0x0C Reset Value: 0x00000000 31 30 29 28 27 26 25 24 19 18 17 16 11 10 9 8 3 2 1 0 CERL[31:24] 23 22 21 20 CERL[23:16] 15 14 13 12 CERL[15:8] 7 6 5 4 CERL[7:0] * CERL[n]: Channel Enable Register Low 0: Channel n is not enabled. 1: Channel n is enabled. 439 32117A-10/2010 AT32UC3C 22.6.5 Name: Status Register SR Access Type: Read-only Offset: 0x10 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 - - - - - IDLE SEN EN 7 6 5 4 3 2 1 0 RTRADR MBERROR URES URKEY URREAD CAU CAS EXP * IDLE * * * * * * * This bit is cleared when the operation is completed and no SAU bus operations are pending. This bit is set when a read or write operation to the SAU channel is started. SEN: SAU Setup Mode Enable This bit is cleared when the SAU exits setup mode. This bit is set when the SAU enters setup mode. EN: SAU Enabled This bit is cleared when the SAU is disabled. This bit is set when the SAU is enabled. RTRADR: RTR Address Error This bit is cleared when the corresponding bit in ICR is written to one. This bit is set if, in the configuration phase, an RTR was written with an illegal address, i.e. the upper 16 bits in the address were different from 0xFFFC, 0xFFFD, 0xFFFE or 0xFFFF. MBERROR: Master Interface Bus Error This bit is cleared when the corresponding bit in ICR is written to one. This bit is set if a channel access generated a transfer on the master interface that received a bus error response from the addressed slave. URES: Unlock Register Error Status This bit is cleared when the corresponding bit in ICR is written to one. This bit is set if an attempt was made to unlock a channel by writing to the Unlock Register while one or more error bits were set in SR. The unlock operation was aborted. URKEY: Unlock Register Key Error This bit is cleared when the corresponding bit in ICR is written to one. This bit is set if the Unlock Register was attempted written with an invalid key. URREAD: Unlock Register Read This bit is cleared when the corresponding bit in ICR is written to one. This bit is set if the Unlock Register was read. 440 32117A-10/2010 AT32UC3C * CAU: Channel Access Unsuccessful This bit is cleared when the corresponding bit in ICR is written to one. This bit is set if channel access was unsuccessful, i.e. an access was attempted to a locked or disabled channel. * CAS: Channel Access Successful This bit is cleared when the corresponding bit in ICR is written to one. This bit is set if channel access successful, i.e. one access was made after the channel was unlocked. * EXP: Channel Unlock Expired This bit is cleared when the corresponding bit in ICR is written to one. This bit is set if channel unlock has expired, i.e. no access being made after the channel was unlocked. 441 32117A-10/2010 AT32UC3C 22.6.6 Name: Interrupt Enable Register IER Access Type: Write-only Offset: 0x14 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 - - - - - - - - 7 6 5 4 3 2 1 0 RTRADR MBERROR URES URKEY URREAD CAU CAS EXP Writing a zero to a bit in this register has no effect. Writing a one to a bit in this register will set the corresponding bit in IMR. 442 32117A-10/2010 AT32UC3C 22.6.7 Name: Interrupt Disable Register IDR Access Type: Write-only Offset: 0x18 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 - - - - - - - - 7 6 5 4 3 2 1 0 RTRADR MBERROR URES URKEY URREAD CAU CAS EXP Writing a zero to a bit in this register has no effect. Writing a one to a bit in this register will clear the corresponding bit in IMR. 443 32117A-10/2010 AT32UC3C 22.6.8 Name: Interrupt Mask Register IMR Access Type: Read-only Offset: 0x1C Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 - - - - - - - - 7 6 5 4 3 2 1 0 RTRADR MBERROR URES URKEY URREAD CAU CAS EXP 0: The corresponding interrupt is disabled. 1: The corresponding interrupt is enabled. A bit in this register is cleared when the corresponding bit in IDR is written to one. A bit in this register is set when the corresponding bit in IER is written to one. 444 32117A-10/2010 AT32UC3C 22.6.9 Name: Interrupt Clear Register ICR Access Type: Write-only Offset: 0x20 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 - - - - - - - - 7 6 5 4 3 2 1 0 RTRADR MBERROR URES URKEY URREAD CAU CAS EXP Writing a zero to a bit in this register has no effect. Writing a one to a bit in this register will clear the corresponding bit in SR and any corresponding interrupt request. 445 32117A-10/2010 AT32UC3C 22.6.10 Name: Parameter Register PARAMETER Access Type: Read-only Offset: 0x24 Reset Value: - 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 - - - - - - - - 7 6 5 4 3 2 1 0 - - CHANNELS * CHANNELS: Number of channels implemented 446 32117A-10/2010 AT32UC3C 22.6.11 Name: Version Register VERSION Access Type: Write-only Offset: 0x28 Reset Value: - 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - 15 14 13 12 9 8 - - - - 7 6 5 4 VARIANT 11 10 VERSION[11:8] 3 2 1 0 VERSION[7:0] * VARIANT: Variant Number Reserved. No functionality associated. * VERSION: Version Number Version number of the module. No functionality associated. 447 32117A-10/2010 AT32UC3C 22.6.12 Name: Remap Target Register n RTRn Access Type: Read/Write Offset: n*4 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 19 18 17 16 11 10 9 8 3 2 1 0 RTR[31:24] 23 22 21 20 RTR[23:16] 15 14 13 12 RTR[15:8] 7 6 5 4 RTR[7:0] * RTR: Remap Target Address for Channel n RTR[31:16] must have one of the following values, any other value will result in UNDEFINED behavior: 0xFFFC 0xFFFD 0xFFFE 0xFFFF RTR[1:0] must be written to 0, any other value will result in UNDEFINED behavior. 448 32117A-10/2010 AT32UC3C 22.6.13 Name: Unlock Register UR Access Type : Write-only Offset: 0xFC Reset Value: 0x00000000 31 30 29 28 27 26 25 24 19 18 17 16 11 10 9 8 3 2 1 0 - 23 22 21 20 - 15 14 13 12 KEY 7 6 - - 5 4 CHANNEL * KEY: Unlock Key The correct key must be written in order to unlock a channel. The key value written must correspond to the key value defined in CONFIG.UKEY. * CHANNEL: Channel Number Number of the channel to unlock. 449 32117A-10/2010 AT32UC3C 22.7 Module configuration The specific configuration for each SAU instance is listed in the following tables. The module bus clocks listed here are connected to the system bus clocks. Refer to the Power Manager chapter for details. Table 22-3. Module configuration Feature SAU SAU Channels 16 Table 22-4. Module name Module clock name Clock name Description CLK_SAU_HSB HSB clock CLK_SAU_PB Peripheral Bus clock from the PBB clock domain SAU Table 22-5. Register Reset Values Register Reset Value VERSION 0x111 PARAMETER 0x010 450 32117A-10/2010 AT32UC3C 23. General-Purpose Input/Output Controller (GPIO) Version: 2.1.2.5 23.1 Features * Each GPIO line features: - - - - - - - - 23.2 Configurable pin-change, rising-edge, or falling-edge interrupt Glitch filter providing rejection of pulses shorter than one clock cycle Input visibility and output control Multiplexing of peripheral functions on I/O pins Programmable internal pull-up resistor Programmable internal pull-down resistor Programmable output driver strength Optional locking of configuration to avoid accidental reconfiguration Overview The General Purpose Input/Output Controller (GPIO) controls the I/O pins of the microcontroller. Each GPIO pin may be used as a general-purpose I/O or be assigned to a function of an embedded peripheral. The GPIO is configured using the Peripheral Bus (PB). Some registers can also be configured using the low latency CPU Local Bus. See Section 23.6.2.8 for details. 23.3 Block Diagram Figure 23-1. GPIO Block Diagram Configuration Interface Interrupt Controller GPIO Interrupt Request PIN General Purpose Input/Output - GPIO Power Manager CLK_GPIO PIN PIN PIN MCU I/O Pins PIN Embedded Peripheral Pin Control Signals 451 32117A-10/2010 AT32UC3C 23.4 I/O Lines Description Pin Name Description Type GPIOn GPIO pin n Digital 23.5 Product Dependencies In order to use this module, other parts of the system must be configured correctly, as described below. 23.5.1 Power Management If the CPU enters a sleep mode that disables clocks used by the GPIO, the GPIO will stop functioning and resume operation after the system wakes up from sleep mode. If a peripheral function is configured for a GPIO pin, the peripheral will be able to control the GPIO pin even if the GPIO clock is stopped. 23.5.2 Clocks The GPIO is connected to a Peripheral Bus clock (CLK_GPIO). This clock is generated by the Power Manager. CLK_GPIO is enabled at reset, and can be disabled by writing to the Power Manager. CLK_GPIO must be enabled in order to access the configuration registers of the GPIO or to use the GPIO interrupts. After configuring the GPIO, the CLK_GPIO can be disabled by writing to the Power Manager if interrupts are not used. If the CPU Local Bus is used to access the configuration interface of the GPIO, the CLK_GPIO must be equal to the CPU clock to avoid data loss. 23.5.3 Interrupts The GPIO interrupt request lines are connected to the interrupt controller. Using the GPIO interrupts requires the interrupt controller to be programmed first. 23.5.4 Debug Operation When an external debugger forces the CPU into debug mode, the GPIO continues normal operation. If the GPIO 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. 452 32117A-10/2010 AT32UC3C 23.6 Functional Description The GPIO controls the I/O pins of the microcontroller. The control logic associated with each pin is shown in the figure below. Figure 23-2. Overview of the GPIO PDER* PUER* ODER 1 0 Periph. Func. A Output Pullup, Pulldown and buskeeper 0 Periph.Func. B Periph. Func. C 1 .... GPER PMRn GPIO_ODMER Output Enable 0 0 1 OVR PIN 1 OSRRn* Drive strength and slew rate control ODCRn* Input Schmitt trigger PVR STER* IER 0 Edge Detector 1 1 Glitch Filter IFR IMR1 GFER 0 Interrupt Request IMR0 *) Register value is overrided if a peripheral function that support this function is enabled 453 32117A-10/2010 AT32UC3C 23.6.1 Basic Operation 23.6.1.1 Module Configuration The GPIO user interface registers are organized into ports and each port controls 32 different GPIO pins. Most of the registers supports bit wise access operations such as set, clear and toggle in addition to the standard word access. For details regarding interface registers, refer to Section 23.7. 23.6.1.2 Available Features Most of the GPIO features are configurable for each product. The programmer must refer to the Module Configuration section and the GPIO Function Multiplexing section in the Package and Pinout chapter for the configuration used in this product. Product specific settings includes: * * * * 23.6.1.3 Number of GPIO pins Functions implemented on each pin Peripheral function(s) multiplexed on each GPIO pin Reset state of registers Inputs The level on each GPIO pin can be read through the Pin Value Register (PVR). This register indicates the level of the GPIO pins regardless of the pins being driven by the GPIO or by an external component. Note that due to power saving measures, the PVR register will only be updated when the corresponding bit in GPER is one or if an interrupt is enabled for the pin, i.e. IER is one for the corresponding pin. 23.6.1.4 Output Control When the GPIO pin is assigned to a peripheral function, i.e. the corresponding bit in GPER is zero, the peripheral determines whether the pin is driven or not. When the GPIO pin is controlled by the GPIO, the value of Output Driver Enable Register (ODER) determines whether the pin is driven or not. When a bit in this register is one, the corresponding GPIO pin is driven by the GPIO. When the bit is zero, the GPIO does not drive the pin. The level driven on a GPIO pin can be determined by writing the value to the corresponding bit in the Output Value Register (OVR). 23.6.1.5 Peripheral Muxing The GPIO allows a single GPIO pin to be shared by multiple peripheral pins and the GPIO itself. Peripheral pins sharing the same GPIO pin are arranged into peripheral functions that can be selected one at a time. Peripheral functions are configured by writing the selected function value to the Peripheral Mux Registers (PMRn). To allow a peripheral pin access to the shared GPIO pin, GPIO control must be disabled for that pin, i.e. the corresponding bit in GPER must read zero. A peripheral function value is set by writing bit zero to PMR0 and bit one to the same index position in PMR1 and so on. In a system with 4 peripheral functions A,B,C, and D, peripheral function C for GPIO pin four is selected by writing a zero to bit four in PMR0 and a one to the same bit index in PMR1. Refer to the GPIO Function Multiplexing chapter for details regarding pin function configuration for each GPIO pin. 454 32117A-10/2010 AT32UC3C 23.6.2 Advanced Operation 23.6.2.1 Peripheral I/O Pin Control When a GPIO pin is assigned to a peripheral function, i.e. the corresponding bit in GPER is zero, output and output enable is controlled by the selected peripheral pin. In addition the peripheral may control some or all of the other GPIO pin functions listed in Table 23-1, if the peripheral supports those features. All pin features not controlled by the selected peripheral is controlled by the GPIO. Refer to the Module Configuration section for details regarding implemented GPIO pin functions and to the Peripheral chapter for details regarding I/O pin function control. Table 23-1. 23.6.2.2 I/O Pin function Control Function name GPIO mode Peripheral mode Output OVR Peripheral Output enable ODER Peripheral Pull-up PUER Peripheral if supported, else GPIO Pull-down PDER Peripheral if supported, else GPIO Drive strength ODCRn Peripheral if supported, else GPIO Pull-up Resistor, Pull-down Resistor Control Pull-up and pull-down can be configured for each GPIO pin. Pull-up allows the pin and any connected net to be pulled up to VDD if the net is not driven. Pull-down pulls the net to GND. Pull-up and pull-down are useful for detecting if a pin is unconnected or if a mechanical button is pressed, for various communication protocols and to keep unconnected pins from floating. Pull-up can be enabled and disabled by writing a one and a zero respectively to the corresponding bit in the Pull-up Enable Register (PUER). Pull-down can be enabled and disabled by writing a one and a zero respectively to the corresponding bit in the Pull-down Enable Register (PDER). 23.6.2.3 Output Pin Timings Figure 23-3 shows the timing of the GPIO pin when writing to the Output Value Register (OVR). The same timing applies when performing a `set' or `clear' access, i.e. writing to OVRS or OVRC. The timing of PVR is also shown. Figure 23-3. Output Pin Timings CLK_GPIO Write OVR to 1 Write OVR to 0 PB Access PB Access OVR / I/O Line PVR 455 32117A-10/2010 AT32UC3C 23.6.2.4 Pin Output Driver Control The GPIO has registers for controlling output drive properties of each pin, such as output driving capability. The driving capability is controlled by the Output Driving Capability Registers (ODCRn). 23.6.2.5 Interrupts The GPIO can be configured to generate an interrupt when it detects a change on a GPIO pin. Interrupts on a pin are enabled by writing a one to the corresponding bit in the Interrupt Enable Register (IER). The module can be configured to generate an interrupt whenever a pin changes value, or only on rising or falling edges. This is controlled by the Interrupt Mode Registers (IMRn). Interrupts on a pin can be enabled regardless of the GPIO pin being controlled by the GPIO or assigned to a peripheral function. An interrupt can be generated on each GPIO pin. These interrupt generators are further grouped into groups of eight and connected to the interrupt controller. An interrupt request from any of the GPIO pin generators in the group will result in an interrupt request from that group to the interrupt controller if the corresponding bit for the GPIO pin in the IER is set. By grouping interrupt generators into groups of eight, four different interrupt handlers can be installed for each GPIO port. The Interrupt Flag Register (IFR) can be read by software to determine which pin(s) caused the interrupt. The interrupt flag must be manually cleared by writing a zero to the corresponding bit in IFR. GPIO interrupts will only be generated when CLK_GPIO is enabled. 23.6.2.6 Input Glitch Filter Input glitch filters can be enabled on each GPIO pin. When the glitch filter is enabled, a glitch with duration of less than 1 CLK_GPIO cycle is automatically rejected, while a pulse with duration of 2 CLK_GPIO cycles or more is accepted. For pulse durations between 1 and 2 CLK_GPIO cycles, the pulse may or may not be taken into account, depending on the precise timing of its occurrence. Thus for a pulse to be guaranteed visible it must exceed 2 CLK_GPIO cycles, whereas for a glitch to be reliably filtered out, its duration must not exceed 1 CLK_GPIO cycle. The filter introduces 2 clock cycles latency. The glitch filters are controlled by the Glitch Filter Enable Register (GFER). When a bit in GFER is one, the glitch filter on the corresponding pin is enabled. The glitch filter affects only interrupt inputs. Inputs to peripherals or the value read through PVR are not affected by the glitch filters. 23.6.2.7 Interrupt Timings Figure 23-4 shows the timing for rising edge (or pin-change) interrupts when the glitch filter is disabled. For the pulse to be registered, it must be sampled at the rising edge of the clock. In this example, this is not the case for the first pulse. The second pulse is sampled on a rising edge and will trigger an interrupt request. 456 32117A-10/2010 AT32UC3C Figure 23-4. Interrupt Timing with Glitch Filter Disabled CLK_GPIO Pin Level IFR Figure 23-5 shows the timing for rising edge (or pin-change) interrupts when the glitch filter is enabled. For the pulse to be registered, it must be sampled on two subsequent rising edges. In the example, the first pulse is rejected while the second pulse is accepted and causes an interrupt request. Figure 23-5. Interrupt Timing with Glitch Filter Enabled CLK_GPIO Pin Level IFR 23.6.2.8 CPU Local Bus The CPU Local Bus can be used for application where low latency read and write access to the Output Value Register (OVR) and Output Drive Enable Register (ODER) is required. The CPU Local Bus allows the CPU to configure the mentioned GPIO registers directly, bypassing the shared Peripheral Bus (PB). To avoid data loss when using the CPU Local Bus, the CLK_GPIO must run at the same frequency as the CLK_CPU. See Section 23.5.2 for details. The CPU Local Bus is mapped to a different base address than the GPIO but the OVER and ODER offsets are the same. See the CPU Local Bus Mapping section in the Memories chapter for details. 457 32117A-10/2010 AT32UC3C 23.7 User Interface The GPIO controller manages all the GPIO pins on the 32-bit AVR microcontroller. The pins are managed as 32-bit ports that are configurable through a Peripheral Bus (PB) interface. Each port has a set of configuration registers. The overall memory map of the GPIO is shown below. The number of pins and hence the number of ports is product specific. Figure 23-6. Port Configuration Registers 0x0000 Port 0 Configuration Registers 0x0200 Port 1 Configuration Registers 0x0400 .... Port 2 Configuration Registers n*0x200 Port n Configuration Registers In the peripheral muxing table in the Package and Pinout chapter each GPIO pin has a unique number. Note that the PA, PB, PC, and PX ports do not necessarily directly correspond to the GPIO ports. To find the corresponding port and pin the following formulas can be used: GPIO port = floor((GPIO number) / 32), example: floor((36)/32) = 1 GPIO pin = GPIO number % 32, example: 36 % 32 = 4 Table 23-2 shows the configuration registers for one port. Addresses shown are relative to the port address offset. The specific address of a configuration register is found by adding the register offset and the port offset to the GPIO start address. One bit in each of the configuration registers corresponds to a GPIO pin. 23.7.1 Access Types Most configuration register can be accessed in four different ways. The first address location can be used to write the register directly. This address can also be used to read the register value. The following addresses facilitate three different types of write access to the register. Performing a "set" access, all bits written to one will be set. Bits written to zero will be unchanged by the operation. Performing a "clear" access, all bits written to one will be cleared. Bits written to zero will be unchanged by the operation. Finally, a toggle access will toggle the value of all bits writ- 458 32117A-10/2010 AT32UC3C ten to one. Again all bits written to zero remain unchanged. Note that for some registers (e.g. IFR), not all access methods are permitted. Note that for ports with less than 32 bits, the corresponding control registers will have unused bits. This is also the case for features that are not implemented for a specific pin. Writing to an unused bit will have no effect. Reading unused bits will always return 0. 23.7.2 Configuration Protection In order to protect the configuration of individual GPIO pins from software failure, configuration bits for individual GPIO pins may be locked by writing a one to the corresponding bit in the LOCK register. While this bit is one, any write to the same bit position in any lockable GPIO register using the Peripheral Bus (PB) will not have an effect. The CPU Local Bus is not checked and thus allowed to write to all bits in a CPU Local Bus mapped register no mather the LOCK value. The registers required to clear bits in the LOCK register are protected by the access protection mechanism described in Section 23.7.3, ensuring the LOCK mechanism itself is robust against software failure. 23.7.3 Access Protection In order to protect critical registers from software failure, some registers are protected by a key protection mechanism. These registers can only be changed by first writing the UNLOCK register, then the protected register. Protected registers are indicated in Table 23-2. The UNLOCK register contains a key field which must always be written to 0xAA, and an OFFSET field corresponding to the offset of the register to be modified. The next write operation resets the UNLOCK register, so if the register is to be modified again, the UNLOCK register must be written again. Attempting to write to a protected register without first writing the UNLOCK register results in the write operation being discarded, and the Access Error bit in the Access Status Register (ASR.AE) will be set. Table 23-2. GPIO Register Memory Map Offset Register Function Register Name Access Reset Config. Protection Access Protection 0x000 GPIO Enable Register Read/Write GPER Read/Write -(1) Y N 0x004 GPIO Enable Register Set GPERS Write-only Y N 0x008 GPIO Enable Register Clear GPERC Write-only Y N 0x00C GPIO Enable Register Toggle GPERT Write-only Y N Y N - (1) 0x010 Peripheral Mux Register 0 Read/Write PMR0 Read/Write 0x014 Peripheral Mux Register 0 Set PMR0S Write-only Y N 0x018 Peripheral Mux Register 0 Clear PMR0C Write-only Y N 0x01C Peripheral Mux Register 0 Toggle PMR0T Write-only Y N Y N (1) 0x020 Peripheral Mux Register 1 Read/Write PMR1 Read/Write - 0x024 Peripheral Mux Register 1 Set PMR1S Write-only Y N 0x028 Peripheral Mux Register 1 Clear PMR1C Write-only Y N 459 32117A-10/2010 AT32UC3C Table 23-2. GPIO Register Memory Map Offset Register Function Register Name Access 0x02C Peripheral Mux Register 1 Toggle PMR1T Write-only Reset - (1) Config. Protection Access Protection Y N Y N 0x030 Peripheral Mux Register 2 Read/Write PMR2 Read/Write 0x034 Peripheral Mux Register 2 Set PMR2S Write-only Y N 0x038 Peripheral Mux Register 2 Clear PMR2C Write-only Y N 0x03C Peripheral Mux Register 2 Toggle PMR2T Write-only Y N Y N (1) 0x040 Output Driver Enable Register Read/Write ODER Read/Write - 0x044 Output Driver Enable Register Set ODERS Write-only Y N 0x048 Output Driver Enable Register Clear ODERC Write-only Y N 0x04C Output Driver Enable Register Toggle ODERT Write-only Y N N N - (1) 0x050 Output Value Register Read/Write OVR Read/Write 0x054 Output Value Register Set OVRS Write-only N N 0x058 Output Value Register Clear OVRC Write-only N N 0x05c Output Value Register Toggle OVRT Write-only N N N N Depe nding on pin states 0x060 Pin Value Register Read PVR Read-only 0x064 Pin Value Register - - - N N 0x068 Pin Value Register - - - N N 0x06c Pin Value Register - - - N N 0x070 Pull-up Enable Register Read/Write PUER Read/Write Y N 0x074 Pull-up Enable Register Set PUERS Write-only Y N 0x078 Pull-up Enable Register Clear PUERC Write-only Y N 0x07C Pull-up Enable Register Toggle PUERT Write-only Y N 0x080 Pull-down Enable Register Read/Write PDER Read/Write Y N 0x084 Pull-down Enable Register Set PDERS Write-only Y N 0x088 Pull-down Enable Register Clear PDERC Write-only Y N 0x08C Pull-down Enable Register Toggle PDERT Write-only Y N 0x090 Interrupt Enable Register Read/Write IER Read/Write N N 0x094 Interrupt Enable Register Set IERS Write-only N N 0x098 Interrupt Enable Register Clear IERC Write-only N N 0x09C Interrupt Enable Register Toggle IERT Write-only N N 0x0A0 Interrupt Mode Register 0 Read/Write IMR0 Read/Write N N 0x0A4 Interrupt Mode Register 0 Set IMR0S Write-only N N 0x0A8 Interrupt Mode Register 0 Clear IMR0C Write-only N N 0x0AC Interrupt Mode Register 0 Toggle IMR0T Write-only N N -(1) (1) -(1) -(1) 460 32117A-10/2010 AT32UC3C Table 23-2. GPIO Register Memory Map Offset Register Function Register Name Access Reset Config. Protection Access Protection 0x0B0 Interrupt Mode Register 1 Read/Write IMR1 Read/Write -(1) N N 0x0B4 Interrupt Mode Register 1 Set IMR1S Write-only N N 0x0B8 Interrupt Mode Register 1 Clear IMR1C Write-only N N 0x0BC Interrupt Mode Register 1 Toggle IMR1T Write-only N N N N (1) 0x0C0 Glitch Filter Enable Register Read/Write GFER Read/Write - 0x0C4 Glitch Filter Enable Register Set GFERS Write-only N N 0x0C8 Glitch Filter Enable Register Clear GFERC Write-only N N 0x0CC Glitch Filter Enable Register Toggle GFERT Write-only N N N N - (1) 0x0D0 Interrupt Flag Register Read IFR Read-only 0x0D4 Interrupt Flag Register - - - N N 0x0D8 Interrupt Flag Register Clear IFRC Write-only N N 0x0DC Interrupt Flag Register - - - N N Y N (1) 0x100 Output Driving Capability Register 0 Read/Write ODCR0 Read/Write - 0x104 Output Driving Capability Register 0 Set ODCR0S Write-only Y N 0x108 Output Driving Capability Register 0 Clear ODCR0C Write-only Y N 0x10C Output Driving Capability Register 0 Toggle ODCR0T Write-only Y N Y N - (1) 0x110 Output Driving Capability Register 1 Read ODCR1 Read/Write 0x114 Output Driving Capability Register 1 Set ODCR1S Write-only Y N 0x118 Output Driving Capability Register 1 Clear ODCR1C Write-only Y N 0x11C Output Driving Capability Register 1 Toggle ODCR1T Write-only Y N N Y 0x1A0 Lock Register Read/Write LOCK Read/Write 0x1A4 Lock Register Set LOCKS Write-only N N 0x1A8 Lock Register Clear LOCKC Write-only N Y 0x1AC Lock Register Toggle LOCKT Write-only N Y 0x1E0 Unlock Register Read/Write UNLOCK Write-only N N 0x1E4 Access Status Register Read/Write ASR Read/Write 0x1F8 Parameter Register Read PARAMETER Read-only -(1) N N Read-only (1) N N 0x1FC Note: Version Register Read VERSION - (1) N - 1. The reset values for these registers are device specific. Please refer to the Module Configuration section at the end of this chapter. 461 32117A-10/2010 AT32UC3C 23.7.4 Name: GPIO Enable Register GPER Access: Read/Write, Set, Clear, Toggle Offset: 0x000, 0x004, 0x008, 0x00C Reset Value: - 31 30 29 28 27 26 25 24 P31 P30 P29 P28 P27 P26 P25 P24 23 22 21 20 19 18 17 16 P23 P22 P21 P20 P19 P18 P17 P16 15 14 13 12 11 10 9 8 P15 P14 P13 P12 P11 P10 P9 P8 7 6 5 4 3 2 1 0 P7 P6 P5 P4 P3 P2 P1 P0 * P0-P31: GPIO Enable 0: A peripheral function controls the corresponding pin. 1: The GPIO controls the corresponding pin. 462 32117A-10/2010 AT32UC3C 23.7.5 Name: Peripheral Mux Register 0 PMR0 Access: Read/Write, Set, Clear, Toggle Offset: 0x010, 0x014, 0x018, 0x01C Reset Value: - 31 30 29 28 27 26 25 24 P31 P30 P29 P28 P27 P26 P25 P24 23 22 21 20 19 18 17 16 P23 P22 P21 P20 P19 P18 P17 P16 15 14 13 12 11 10 9 8 P15 P14 P13 P12 P11 P10 P9 P8 7 6 5 4 3 2 1 0 P7 P6 P5 P4 P3 P2 P1 P0 * P0-31: Peripheral Multiplexer Select bit 0 463 32117A-10/2010 AT32UC3C 23.7.6 Name: Peripheral Mux Register 1 PMR1 Access: Read/Write, Set, Clear, Toggle Offset: 0x020, 0x024, 0x028, 0x02C Reset Value: - 31 30 29 28 27 26 25 24 P31 P30 P29 P28 P27 P26 P25 P24 23 22 21 20 19 18 17 16 P23 P22 P21 P20 P19 P18 P17 P16 15 14 13 12 11 10 9 8 P15 P14 P13 P12 P11 P10 P9 P8 7 6 5 4 3 2 1 0 P7 P6 P5 P4 P3 P2 P1 P0 * P0-31: Peripheral Multiplexer Select bit 1 464 32117A-10/2010 AT32UC3C 23.7.7 Name: Peripheral Mux Register 2 PMR2 Access: Read/Write, Set, Clear, Toggle Offset: 0x030, 0x034, 0x038, 0x03C Reset Value: - 31 30 29 28 27 26 25 24 P31 P30 P29 P28 P27 P26 P25 P24 23 22 21 20 19 18 17 16 P23 P22 P21 P20 P19 P18 P17 P16 15 14 13 12 11 10 9 8 P15 P14 P13 P12 P11 P10 P9 P8 7 6 5 4 3 2 1 0 P7 P6 P5 P4 P3 P2 P1 P0 * P0-31: Peripheral Multiplexer Select bit 2 {PMR2, PMR1, PMR0} 000 001 010 011 100 101 110 111 Selected Peripheral Function A B C D E F G H 465 32117A-10/2010 AT32UC3C 23.7.8 Name: Output Driver Enable Register ODER Access: Read/Write, Set, Clear, Toggle Offset: 0x040, 0x044, 0x048, 0x04C Reset Value: - 31 30 29 28 27 26 25 24 P31 P30 P29 P28 P27 P26 P25 P24 23 22 21 20 19 18 17 16 P23 P22 P21 P20 P19 P18 P17 P16 15 14 13 12 11 10 9 8 P15 P14 P13 P12 P11 P10 P9 P8 7 6 5 4 3 2 1 0 P7 P6 P5 P4 P3 P2 P1 P0 * P0-31: Output Driver Enable 0: The output driver is disabled for the corresponding pin. 1: The output driver is enabled for the corresponding pin. 466 32117A-10/2010 AT32UC3C 23.7.9 Name: Output Value Register OVR Access: Read/Write, Set, Clear, Toggle Offset: 0x050, 0x054, 0x058, 0x05C Reset Value: - 31 30 29 28 27 26 25 24 P31 P30 P29 P28 P27 P26 P25 P24 23 22 21 20 19 18 17 16 P23 P22 P21 P20 P19 P18 P17 P16 15 14 13 12 11 10 9 8 P15 P14 P13 P12 P11 P10 P9 P8 7 6 5 4 3 2 1 0 P7 P6 P5 P4 P3 P2 P1 P0 * P0-31: Output Value 0: The value to be driven on the GPIO pin is 0. 1: The value to be driven on the GPIO pin is 1. 467 32117A-10/2010 AT32UC3C 23.7.10 Name: Pin Value Register PVR Access: Read-only Offset: 0x060, 0x064, 0x068, 0x06C Reset Value: Depending on pin states 31 30 29 28 27 26 25 24 P31 P30 P29 P28 P27 P26 P25 P24 23 22 21 20 19 18 17 16 P23 P22 P21 P20 P19 P18 P17 P16 15 14 13 12 11 10 9 8 P15 P14 P13 P12 P11 P10 P9 P8 7 6 5 4 3 2 1 0 P7 P6 P5 P4 P3 P2 P1 P0 * P0-31: Pin Value 0: The GPIO pin is at level zero. 1: The GPIO pin is at level one. Note that the level of a pin can only be read when the corresponding pin in GPER is one or interrupt is enabled for the pin. 468 32117A-10/2010 AT32UC3C 23.7.11 Name: Pull-up Enable Register PUER Access: Read/Write, Set, Clear, Toggle Offset: 0x070, 0x074, 0x078, 0x07C Reset Value: - 31 30 29 28 27 26 25 24 P31 P30 P29 P28 P27 P26 P25 P24 23 22 21 20 19 18 17 16 P23 P22 P21 P20 P19 P18 P17 P16 15 14 13 12 11 10 9 8 P15 P14 P13 P12 P11 P10 P9 P8 7 6 5 4 3 2 1 0 P7 P6 P5 P4 P3 P2 P1 P0 * P0-31: Pull-up Enable Writing a zero to a bit in this register will disable pull-up on the corresponding pin. Writing a one to a bit in this register will enable pull-up on the corresponding pin. 469 32117A-10/2010 AT32UC3C 23.7.12 Name: Pull-down Enable Register PDER Access: Read/Write, Set, Clear, Toggle Offset: 0x080, 0x084, 0x088, 0x08C Reset Value: - 31 30 29 28 27 26 25 24 P31 P30 P29 P28 P27 P26 P25 P24 23 22 21 20 19 18 17 16 P23 P22 P21 P20 P19 P18 P17 P16 15 14 13 12 11 10 9 8 P15 P14 P13 P12 P11 P10 P9 P8 7 6 5 4 3 2 1 0 P7 P6 P5 P4 P3 P2 P1 P0 * P0-31: Pull-down Enable {PUER, PDER} 00 01 10 11 Selected Function Disabled Pull-down enabled Pull-up enabled Buskeeper enabled 470 32117A-10/2010 AT32UC3C 23.7.13 Name: Interrupt Enable Register IER Access: Read/Write, Set, Clear, Toggle Offset: 0x090, 0x094, 0x098, 0x09C Reset Value: - 31 30 29 28 27 26 25 24 P31 P30 P29 P28 P27 P26 P25 P24 23 22 21 20 19 18 17 16 P23 P22 P21 P20 P19 P18 P17 P16 15 14 13 12 11 10 9 8 P15 P14 P13 P12 P11 P10 P9 P8 7 6 5 4 3 2 1 0 P7 P6 P5 P4 P3 P2 P1 P0 * P0-31: Interrupt Enable 0: Interrupt is disabled for the corresponding pin. 1; Interrupt is enabled for the corresponding pin. 471 32117A-10/2010 AT32UC3C 23.7.14 Name: Interrupt Mode Register 0 IMR0 Access: Read/Write, Set, Clear, Toggle Offset: 0x0A0, 0x0A4, 0x0A8, 0x0AC Reset Value: - 31 30 29 28 27 26 25 24 P31 P30 P29 P28 P27 P26 P25 P24 23 22 21 20 19 18 17 16 P23 P22 P21 P20 P19 P18 P17 P16 15 14 13 12 11 10 9 8 P15 P14 P13 P12 P11 P10 P9 P8 7 6 5 4 3 2 1 0 P7 P6 P5 P4 P3 P2 P1 P0 * P0-31: Interrupt Mode Bit 0 472 32117A-10/2010 AT32UC3C 23.7.15 Name: Interrupt Mode Register 1 IMR1 Access: Read/Write, Set, Clear, Toggle Offset: 0x0B0, 0x0B4, 0x0B8, 0x0BC Reset Value: - 31 30 29 28 27 26 25 24 P31 P30 P29 P28 P27 P26 P25 P24 23 22 21 20 19 18 17 16 P23 P22 P21 P20 P19 P18 P17 P16 15 14 13 12 11 10 9 8 P15 P14 P13 P12 P11 P10 P9 P8 7 6 5 4 3 2 1 0 P7 P6 P5 P4 P3 P2 P1 P0 * P0-31: Interrupt Mode Bit 1 {IMR1, IMR0} 00 01 10 11 Interrupt Mode Pin Change Rising Edge Falling Edge Reserved 473 32117A-10/2010 AT32UC3C 23.7.16 Name: Glitch Filter Enable Register GFER Access: Read/Write, Set, Clear, Toggle Offset: 0x0C0, 0x0C4, 0x0C8, 0x0CC Reset Value: - 31 30 29 28 27 26 25 24 P31 P30 P29 P28 P27 P26 P25 P24 23 22 21 20 19 18 17 16 P23 P22 P21 P20 P19 P18 P17 P16 15 14 13 12 11 10 9 8 P15 P14 P13 P12 P11 P10 P9 P8 7 6 5 4 3 2 1 0 P7 P6 P5 P4 P3 P2 P1 P0 * P0-31: Glitch Filter Enable 0: Glitch filter is disabled for the corresponding pin. 1: Glitch filter is enabled for the corresponding pin. NOTE! The value of this register should only be changed when the corresponding bit in IER is zero. Updating GFER while interrupt on the corresponding pin is enabled can cause an unintentional interrupt to be triggered. 474 32117A-10/2010 AT32UC3C 23.7.17 Name: Interrupt Flag Register IFR Access: Read, Clear Offset: 0x0D0, 0x0D8 Reset Value: - 31 30 29 28 27 26 25 24 P31 P30 P29 P28 P27 P26 P25 P24 23 22 21 20 19 18 17 16 P23 P22 P21 P20 P19 P18 P17 P16 15 14 13 12 11 10 9 8 P15 P14 P13 P12 P11 P10 P9 P8 7 6 5 4 3 2 1 0 P7 P6 P5 P4 P3 P2 P1 P0 * P0-31: Interrupt Flag 0: No interrupt condition has been detected on the corresponding pin. 1: An interrupt condition has been detected on the corresponding pin. The number of interrupt request lines depends on the number of GPIO pins on the MCU. Refer to the product specific data for details. Note also that a bit in the Interrupt Flag register is only valid if the corresponding bit in IER is one. 475 32117A-10/2010 AT32UC3C 23.7.18 Name: Output Driving Capability Register 0 ODCR0 Access: Read/Write, Set, Clear, Toggle Offset: 0x100, 0x104, 0x108, 0x10C Reset Value: - 31 30 29 28 27 26 25 24 P31 P30 P29 P28 P27 P26 P25 P24 23 22 21 20 19 18 17 16 P23 P22 P21 P20 P19 P18 P17 P16 15 14 13 12 11 10 9 8 P15 P14 P13 P12 P11 P10 P9 P8 7 6 5 4 3 2 1 0 P7 P6 P5 P4 P3 P2 P1 P0 * P0-31: Output Driving Capability Register Bit 0 476 32117A-10/2010 AT32UC3C 23.7.19 Name: Output Driving Capability Register 1 ODCR1 Access: Read/Write, Set, Clear, Toggle Offset: 0x110, 0x114, 0x118, 0x11C Reset Value: - 31 30 29 28 27 26 25 24 P31 P30 P29 P28 P27 P26 P25 P24 23 22 21 20 19 18 17 16 P23 P22 P21 P20 P19 P18 P17 P16 15 14 13 12 11 10 9 8 P15 P14 P13 P12 P11 P10 P9 P8 7 6 5 4 3 2 1 0 P7 P6 P5 P4 P3 P2 P1 P0 * P0-31: Output Driving Capability Bit 1 {ODCR1, ODCR0} 00 01 10 11 Interrupt Mode Lowest drive strength ... ... Highest drive strength For the actual drive strength of the pin, please refer to the Electrical Characteristics chapter. 477 32117A-10/2010 AT32UC3C 23.7.20 Name: Lock Register LOCK Access: Read/Write, Set, Clear, Toggle Offset: 0x1A0, 0x1A4, 0x1A8, 0x1AC Reset Value: - 31 30 29 28 27 26 25 24 P31 P30 P29 P28 P27 P26 P25 P24 23 22 21 20 19 18 17 16 P23 P22 P21 P20 P19 P18 P17 P16 15 14 13 12 11 10 9 8 P15 P14 P13 P12 P11 P10 P9 P8 7 6 5 4 3 2 1 0 P7 P6 P5 P4 P3 P2 P1 P0 * P0-31: Lock State 0: Pin is unlocked. The corresponding bit can be changed in any GPIO register for this port. 1: Pin is locked. The corresponding bit can not be changed in any GPIO register for this port. The value of LOCK determines which bits are locked in the lockable registers. The LOCK, LOCKC, and LOCKT registers are protected, which means they can only be written immediately after a write to the UNLOCK register with the proper KEY and OFFSET. LOCKS is not protected, and can be written at any time. 478 32117A-10/2010 AT32UC3C 23.7.21 Name: Unlock Register UNLOCK Access: Write-only Offset: 0x1E0 Reset Value: - 31 30 29 28 27 26 25 24 KEY 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 - - - - - - 7 6 5 4 3 2 8 OFFSET 1 0 OFFSET * OFFSET: Register Offset This field must be written with the offset value of the LOCK, LOCKC or LOCKT register to unlock. This offset must also include the port offset for the register to unlock. LOCKS can not be locked so no unlock is required before writing to this register. * KEY: Unlocking Key This bitfield must be written to 0xAA for a write to this register to have an effect. This register always reads as zero. 479 32117A-10/2010 AT32UC3C 23.7.22 Name: Access Status Register ASR Access: Read/Write Offset: 0x1E4 Reset Value: - 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 - - - - - - - - 7 6 5 4 3 2 1 0 - - - - - - - AE * AE: Access Error This bit is set when a write to a locked register occurs. This bit can be written to 0 by software. 480 32117A-10/2010 AT32UC3C 23.7.23 Name: Parameter Register PARAMETER Access Type: Read-only Offset: 0x1F8 Reset Value: - 31 30 29 28 27 26 25 24 19 18 17 16 11 10 9 8 3 2 1 0 PARAMETER 23 22 21 20 PARAMETER 15 14 13 12 PARAMETER 7 6 5 4 PARAMETER * PARAMETER: 0: The corresponding pin is not implemented in this GPIO port. 1: The corresponding pin is implemented in this GPIO port. There is one PARAMETER register per GPIO port. Each bit in the Parameter Register indicates whether the corresponding GPER bit is implemented. 481 32117A-10/2010 AT32UC3C 23.7.24 Name: Version Register VERSION Access Type: Read-only Offset: 0x1FC Reset Value: - 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - 15 14 13 12 9 8 - - - - 7 6 5 4 1 0 VARIANT 11 10 VERSION[11:8] 3 2 VERSION[7:0] * VARIANT: Variant Number Reserved. No functionality associated. * VERSION: Version Number Version number of the module. No functionality associated. 482 32117A-10/2010 AT32UC3C 23.8 Module Configuration The specific configuration for each GPIO instance is listed in the following tables. The module bus clocks listed here are connected to the system bus clocks. Refer to the Power Manager chapter for details. Table 23-3. Module Configuration Feature GPIO Number of GPIO ports 4 Number of peripheral functions 4 Table 23-4. Implemented Pin Functions Pin Function Implemented Notes Pull-up Yes Controlled by PUER or peripheral Pull-down Yes Controlled by PDER Drive strength Yes Writing to ODCR0 control the drive strength of the pads Writing to ODCR1 has no effect Slew rate No OSRRn registers are not implemented Open Drain No ODMERn registers are not implemented Bus keeper No Setting {PUER, PDER} to 0x3 in a pin does not enable the bus keeper on this pin Table 23-5. Module Clock Name Module name Clock Name Description GPIO CLK_GPIO Peripheral Bus clock from the PBA clock domain The reset values for all GPIO registers are zero, with the following exceptions: Table 23-6. Register Reset Values Port Register Reset Value 0 GPER 0x3FF9FFFF 0 PMR0 0x00000001 0 PMR1 - PMR2 0x00000000 0 ODER - OVR 0x00000000 0 PUER 0x00000001 0 PDER 0x00000000 0 IER - IMR0 - IMR1 - IFR 0x00000000 0 GFER 0x3FF9FFFF 0 ODCR0 0x00000000 0 LOCK 0x00000000 0 PARAMETER 0x3FF9FFFF 483 32117A-10/2010 AT32UC3C Table 23-6. Register Reset Values Port Register Reset Value 0 VERSION 0x00000212 1 GPER 0xFFFFFFFF 1 PMR0 0x00000002 1 PMR1 - PMR2 0x00000000 1 ODER - OVR 0x00000000 1 PUER - PDER 0x00000000 1 IER - IMR0 - IMR1 - IFR 0x00000000 1 GFER 0xFFFFFFFF 1 ODCR0 0x00000000 1 LOCK 0x00000000 1 PARAMETER 0x3FFFFFFF 1 VERSION 0x00000212 2 GPER 0xFFFFFFFF 2 PMR0 - PMR1 - PMR2 0x00000000 2 ODER - OVR 0x00000000 2 PUER - PDER 0x00000000 2 IER - IMR0 - IMR1 - IFR 0x00000000 2 GFER 0xFFFFFFFF 2 ODCR0 0x00000000 2 LOCK 0x00000000 2 PARAMETER 0xFFFFFFFF 2 VERSION 0x00000212 3 GPER 0x7FFFFFFF 3 PMR0 - PMR1 - PMR2 0x00000000 3 ODER - OVR 0x00000000 3 PUER - PDER 0x00000000 3 IER - IMR0 - IMR1 - IFR 0x00000000 3 GFER 0x7FFFFFFF 3 ODCR0 0x00000000 3 LOCK 0x00000000 3 PARAMETER 0x7FFFFFFF 3 VERSION 0x00000212 484 32117A-10/2010 AT32UC3C 24. Ethernet MAC (MACB) Rev: 1.1.2.0 24.1 Features * * * * * * * * * * * * * * * * * * * * * 24.2 Compatible with IEEE Standard 802.3 10 and 100 Mbit/s Operation Full- and Half-duplex Operation Statistics Counter Registers MII/RMII Interface to the Physical Layer Interrupt Generation to Signal Receive and Transmit Completion DMA Master on Receive and Transmit Channels Transmit and Receive FIFOs Automatic Pad and CRC Generation on Transmitted Frames Automatic Discard of Frames Received with Errors Address Checking Logic Supports Up to Four Specific 48-bit Addresses Supports Promiscuous Mode Where All Valid Received Frames are Copied to Memory Hash Matching of Unicast and Multicast Destination Addresses External Address Matching of Received Frames Physical Layer Management through MDIO Interface Half-duplex Flow Control by Forcing Collisions on Incoming Frames Full-duplex Flow Control with Recognition of Incoming Pause Frames and Hardware Generation of Transmitted Pause Frames Support for 802.1Q VLAN Tagging with Recognition of Incoming VLAN and Priority Tagged Frames Multiple Buffers per Receive and Transmit Frame Wake-on-LAN Support Jumbo Frames Up to 10240 bytes Supported Overview The MACB module implements a 10/100 Ethernet MAC compatible with the IEEE 802.3 standard using an address checker, statistics and control registers, receive and transmit submodules, and a DMA interface. The address checker recognizes four specific 48-bit addresses and contains a 64-bit hash register for matching multicast and unicast addresses. It can recognize the broadcast address of all ones, copy all frames, and act on an external address match signal. The statistics register sub-module contains registers for counting various types of events associated with transmit and receive operations. These registers, along with the status words stored in the receive buffer list, enable software to generate network management statistics compatible with IEEE 802.3. 485 32117A-10/2010 AT32UC3C 24.3 Block Diagram Figure 24-1. MACB Block Diagram Address Checker Peripheral Bus Slave Register Interface Statistics Registers MDIO Control Registers DMA Interface RX FIFO TX FIFO Ethernet Receive High Speed Bus Master 24.4 MII/RMII Ethernet Transmit Product Dependencies In order to use this module, other parts of the system must be configured correctly, as described below. 24.4.1 I/O Lines The pins used for interfacing the MACB may be multiplexed with the I/O Controller lines. The programmer must first program the I/O Controller to assign the desired MACB pins to their peripheral function. If I/O lines of the MACB are not used by the application, they can be used for other purposes by the I/O Controller. 24.4.2 Power Management If the CPU enters a sleep mode that disables clocks used by the MACB, the MACB will stop functioning and resume operation after the system wakes up from sleep mode. To prevent bus errors the MACB operation must be terminated before entering sleep mode. 24.4.3 Clocks The clocks for the MACB bus interface (CLK_MACB_PB/CLK_MACB_HSB) are generated by the Power Manager. These clocks are enabled at reset, and can be disabled in the Power Man- 486 32117A-10/2010 AT32UC3C ager. It is recommended to disable the MACB before disabling the clocks, to avoid freezing the MACB in an undefined state. The synchronization module in the MACB requires that the bus clock (CLK_MACB_HSB) runs on at least the speed of the macb_tx/RX_CLK, which is 25MHz in 100Mbps, and 2.5MHZ in 10Mbps in MII mode and 50MHz in 100Mbps, and 5MHZ in 10Mbps in RMII mode. 24.4.4 Interrupt The MACB interrupt request line is connected to the interrupt controller. Using the MACB interrupt requires the interrupt controller to be programmed first. 24.4.5 24.5 Debug Operation When an external debugger forces the CPU into debug mode, the MACB continues normal operation. If the MACB 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. Functional Description The control registers drive the MDIO interface, setup DMA activity, start frame transmission and select modes of operation such as full or half-duplex. The receive sub-module checks for valid preamble, Frame Check Sequence (FCS), alignment and length, and presents received frames to the address checking sub-module and DMA interface. The transmit sub-module takes data from the DMA interface, adds preamble and, if necessary, pad and FCS, and transmits data according to the Carrier Sense Multiple Access with Collision Detect (CSMA/CD) protocol. The start of transmission is deferred if Carrier Sense (CRS) is active. If Collision (COL) becomes active during transmission, a jam sequence is asserted and the transmission is retried after a random back off. CRS and COL have no effect in full duplex mode. The DMA interface can access external memory through its High Speed Bus (HSB). It contains receive and transmit FIFOs for buffering frame data. It loads the transmit FIFO and empties the receive FIFO using HSB bus master operations. Received data is not sent to memory until the address checking logic has determined that the frame should be copied. Received or transmitted frames are stored in one or more buffers. Receive buffers have a fixed length of 128 bytes. Transmit buffers range in length between 0 and 2047 bytes, and up to 128 buffers are allowed per frame. The DMA interface manages the transmit and receive frame buffer queues. These queues can hold multiple frames. 24.5.1 Memory Interface Frame data is transferred to and from the MACB by the DMA interface. All transfers are 32-bit words and may be single accesses or bursts of 2, 3 or 4 words. Burst accesses do not cross sixteen-byte boundaries. Bursts of 4 words are the default data transfer; single accesses or bursts of less than four words may be used to transfer data at the beginning or the end of a buffer. The DMA interface performs six types of operation on the bus. In order of priority, these are: 1. Receive buffer manager write 2. Receive buffer manager read 487 32117A-10/2010 AT32UC3C 3. Transmit data DMA read 4. Receive data DMA write 5. Transmit buffer manager read 6. Transmit buffer manager write 24.5.2 FIFO FIFO depths are 124 bytes. Data is typically transferred in and out of the FIFOs in bursts of four words. In reception, a bus request is asserted when the FIFO contains four words and has space for three more. For transmission, a bus request is generated when there is space for four words, or when there is space for two words if the next transfer is only one or two words. Thus the bus latency is less than the time it takes to load the FIFO and transmit or receive three words (12 bytes) of data. At 100 Mbit/s, it takes 960 ns to transmit or receive 12 bytes of data. In addition, six PB clock cycles should be allowed for data to be loaded from the bus and to propagate through the FIFOs. For a 60 MHz PB clock this takes 100 ns, making the bus latency requirement 860 ns. 24.5.3 Receive Buffers Received frames, optionally including CRC/FCS, are written to receive buffers stored in memory. Each receive buffer size is 128 bytes. The start location for each receive buffer is stored in memory in a list of receive buffer descriptors at a location pointed to by the receive buffer queue pointer register. The receive buffer start location is a word address. For the first buffer of a frame, the start location can be offset by up to three bytes depending on the value written to bits 14 and 15 of the network configuration register. If the start location of the buffer is offset the available length of the first buffer of a frame is reduced by the corresponding number of bytes. Each list entry consists of two words, the first being the address of the receive buffer and the second being the receive status. If the length of a receive frame exceeds the buffer length, the status word for the used buffer is written with zeroes except for the "start of frame" bit and the offset field, if appropriate. Bit zero of the address field is written to one to show the buffer has been used. The receive buffer manager then reads the location of the next receive buffer and fills that with receive frame data. The final buffer descriptor status word contains the complete frame status. Refer to Table 24-1 for details of the receive buffer descriptor list. Table 24-1. Receive Buffer Descriptor Entry Bit Function Word 0 31:2 Address of beginning of buffer 1 Wrap - marks last descriptor in receive buffer descriptor list. 0 Ownership - needs to be zero for the MACB to write data to the receive buffer. The MACB sets this to one once it has successfully written a frame to memory. Software has to clear this bit before the buffer can be used again. Word 1 31 Global all ones broadcast address detected 30 Multicast hash match 29 Unicast hash match 488 32117A-10/2010 AT32UC3C Table 24-1. Receive Buffer Descriptor Entry (Continued) Bit Function 28 External address match 27 Reserved for future use 26 Specific address register 1 match 25 Specific address register 2 match 24 Specific address register 3 match 23 Specific address register 4 match 22 Type ID match 21 VLAN tag detected (i.e., type id of 0x8100) 20 Priority tag detected (i.e., type id of 0x8100 and null VLAN identifier) 19:17 VLAN priority (only valid if bit 21 is set) 16 Concatenation format indicator (CFI) bit (only valid if bit 21 is set) 15 End of frame - when set the buffer contains the end of a frame. If end of frame is not set, then the only other valid status are bits 12, 13 and 14. 14 Start of frame - when set the buffer contains the start of a frame. If both bits 15 and 14 are set, then the buffer contains a whole frame. 13:12 Receive buffer offset - indicates the number of bytes by which the data in the first buffer is offset from the word address. Updated with the current values of the network configuration register. If jumbo frame mode is enabled through bit 3 of the network configuration register, then bits 12 and 13 of the receive buffer descriptor entry are used to indicate bits 12 and 13 of the frame length. 11:0 Length of frame including FCS (if selected). Bits 12 and 13 are also used if jumbo frame mode is selected. To receive frames, the buffer descriptors must be initialized by writing the right address to bits 2 through 31in the first word of each list entry. Bit zero must be written with zero. Bit one is the wrap bit and indicates the last entry in the list. The start location of the receive buffer descriptor list must be written to the receive buffer queue pointer register before setting the receive enable bit in the network control register to enable receive. As soon as the receive sub-module starts writing received frame data to the receive FIFO, the receive buffer manager reads the first receive buffer location pointed to by the receive buffer queue pointer register. If the filter sub-module indicates that the frame should be copied to memory, the receive data DMA operation starts writing data into the receive buffer. If an error occurs, the buffer is recovered. If the current buffer pointer has its wrap bit set or is the 1024th descriptor, the next receive buffer location is read from the beginning of the receive descriptor list. Otherwise, the next receive buffer location is read from the next word in memory. There is an 11-bit counter to count out the 2048 word locations of a maximum length, receive buffer descriptor list. This is added with the value originally written to the receive buffer queue pointer register to produce a pointer into the list. A read of the receive buffer queue pointer register returns the pointer value, which is the queue entry currently being accessed. The counter is reset after receive status is written to a descriptor that has its wrap bit set or rolls over to zero after 1024 descriptors have been accessed. The value written to the receive buffer pointer register may be any word-aligned address, provided that there are at least 2048 word locations available between the pointer and the top of the memory. 489 32117A-10/2010 AT32UC3C The System Bus specification requires that bursts should not cross 1K boundaries. As receive buffer manager writes are bursts of two words, to ensure that this does not occur, it is best to write the pointer register with the least three significant bits set to zero. As receive buffers are used, the receive buffer manager sets bit zero of the first word of the descriptor to indicate used. If a receive error is detected the receive buffer currently being written is recovered. Previous buffers are not recovered. Software should search through the used bits in the buffer descriptors to find out how many frames have been received. It should be checking the start-of-frame and endof-frame bits, and not rely on the value returned by the receive buffer queue pointer register which changes continuously as more buffers are used. For CRC errored frames, excessive length frames or length field mismatched frames, all of which are counted in the statistics registers, it is possible that a frame fragment might be stored in a sequence of receive buffers. Software can detect this by looking for start of frame bit set in a buffer following a buffer with no end of frame bit set. For a properly working Ethernet system, there should be no excessively long frames or frames greater than 128 bytes with CRC/FCS errors. Collision fragments are less than 128 bytes long. Therefore, it is a rare occurrence to find a frame fragment in a receive buffer. If bit zero is set when the receive buffer manager reads the location of the receive buffer, then the buffer has already been used and cannot be used again until software has processed the frame and cleared bit zero. In this case, the DMA interface sets the buffer not available bit in the receive status register and triggers an interrupt. If bit zero is set when the receive buffer manager reads the location of the receive buffer and a frame is being received, the frame is discarded and the receive resource error statistics register is incremented. A receive overrun condition occurs when bus was not granted in time or because HRESP was not OK (bus error). In a receive overrun condition, the receive overrun interrupt is asserted and the buffer currently being written is recovered. The next frame received with an address that is recognized reuses the buffer. If bit 17 of the network configuration register is set, the FCS of received frames shall not be copied to memory. The frame length indicated in the receive status field shall be reduced by four bytes in this case. 24.5.4 Transmit Buffer Frames to be transmitted are stored in one or more transmit buffers. Transmit buffers can be between 0 and 2047 bytes long, so it is possible to transmit frames longer than the maximum length specified in IEEE Standard 802.3. Zero length buffers are allowed. The maximum number of buffers permitted for each transmit frame is 128. The start location for each transmit buffer is stored in memory in a list of transmit buffer descriptors at a location pointed to by the transmit buffer queue pointer register. Each list entry consists of two words, the first being the byte address of the transmit buffer and the second containing the transmit control and status. Frames can be transmitted with or without automatic CRC generation. If CRC is automatically generated, padding is also automatically generated to take frames to a minimum length of 64 bytes. Table 24-2 on page 491 defines an entry in the transmit buffer descriptor list. To transmit frames, the buffer descriptors must be initialized by writing the right byte address to bits 0 through 31 in the first word of each list entry. The second transmit buffer descriptor is initialized with control information that indicates the length of the buffer, 490 32117A-10/2010 AT32UC3C whether or not it is to be transmitted with CRC and whether the buffer is the last buffer in the frame. After transmission, the control bits are written back to the second word of the first buffer along with the "used" bit and other status information. Before a transmission, bit 31 is the "used" bit which must be zero when the control word is read. It is written to one when a frame has been transmitted. Bits 27, 28 and 29 indicate various transmit error conditions. Bit 30 is the "wrap" bit which can be set for any buffer within a frame. If no wrap bit is encountered after 1024 descriptors, the queue pointer rolls over to the start. The transmit buffer queue pointer register must not be written while transmit is active. If a new value is written to the transmit buffer queue pointer register, the queue pointer resets itself to point to the beginning of the new queue. If transmit is disabled by writing to bit 3 of the network control, the transmit buffer queue pointer register resets to point to the beginning of the transmit queue. Note that disabling receive does not have the same effect on the receive queue pointer. Once the transmit queue is initialized, transmit is activated by writing to bit 9, the Transmit Start bit of the network control register. Transmit is halted when a buffer descriptor with its used bit set is read, or if a transmit error occurs, or by writing to the transmit halt bit of the network control register. (Transmission is suspended if a pause frame is received while the pause enable bit is set in the network configuration register.) Rewriting the start bit while transmission is active is allowed. Transmission control is implemented with a Tx_go variable which is readable in the transmit status register at bit location 3. The Tx_go variable is reset when: - transmit is disabled - a buffer descriptor with its ownership bit set is read - a new value is written to the transmit buffer queue pointer register - bit 10, tx_halt, of the network control register is written - there is a transmit error such as too many retries or a transmit underrun. To set tx_go, write to bit 9, tx_start, of the network control register. Transmit halt does not take effect until any ongoing transmit finishes. If a collision occurs during transmission of a multi-buffer frame, transmission automatically restarts from the first buffer of the frame. If a "used" bit is read midway through transmission of a multi-buffer frame, this is treated as a transmit error. Transmission stops, TX_ER is asserted and the FCS is bad. If transmission stops due to a transmit error, the transmit queue pointer resets to point to the beginning of the transmit queue. Software needs to re-initialize the transmit queue after a transmit error. If transmission stops due to a "used" bit being read at the start of the frame, the transmission queue pointer is not reset and transmit starts from the same transmit buffer descriptor when the transmit start bit is written Table 24-2. Transmit Buffer Descriptor Entry Bit Function Word 0 31:0 Byte Address of buffer Word 1 491 32117A-10/2010 AT32UC3C Table 24-2. Transmit Buffer Descriptor Entry (Continued) Bit Function Used. Needs to be zero for the MACB to read data from the transmit buffer. The MACB sets this to one for the first buffer of a frame once it has been successfully transmitted. Software has to clear this bit before the buffer can be used again. 31 Note: This bit is only set for the first buffer in a frame unlike receive where all buffers have the Used bit set once used. 30 Wrap. Marks last descriptor in transmit buffer descriptor list. 29 Retry limit exceeded, transmit error detected 28 Transmit underrun, occurs either when hresp is not OK (bus error) or the transmit data could not be fetched in time or when buffers are exhausted in mid frame. 27 Buffers exhausted in mid frame 26:17 Reserved 16 No CRC. When set, no CRC is appended to the current frame. This bit only needs to be set for the last buffer of a frame. 15 Last buffer. When set, this bit indicates the last buffer in the current frame has been reached. 14:11 Reserved 10:0 Length of buffer 24.5.5 Transmit Sub-module This sub-module transmits frames in accordance with the Ethernet IEEE 802.3 CSMA/CD protocol. Frame assembly starts by adding preamble and the start frame delimiter. Data is taken from the transmit FIFO a word at a time. Data is transmitted least significant nibble first. If necessary, padding is added to increase the frame length to 60 bytes. CRC is calculated as a 32-bit polynomial. This is inverted and appended to the end of the frame, taking the frame length to a minimum of 64 bytes. If the No CRC bit is set in the second word of the last buffer descriptor of a transmit frame, neither pad nor CRC are appended. In full-duplex mode, frames are transmitted immediately. Back-to-back frames are transmitted at least 96 bit times apart to guarantee the interframe gap. In half-duplex mode, the transmitter checks carrier sense. If asserted, it waits for it to de-assert and then starts transmission after the interframe gap of 96 bit times. If the collision signal is asserted during transmission, the transmitter transmits a jam sequence of 32 bits taken from the data register and retries transmission after the back off time has elapsed. The back-off time is based on an XOR of the 10 least significant bits of the data coming from the transmit FIFO and a 10-bit pseudo random number. The number of bits used depends on the number of collisions seen. After the first collision, 1 bit is used, after the second 2, and so on up to 10. Above 10, all 10 bits are used. An error is indicated and no further attempts are made if 16 attempts cause collisions. If transmit DMA underruns, bad CRC is automatically appended using the same mechanism as jam insertion and TX_ER is asserted. In a properly configured system, this should never happen. If the back pressure bit is set in the network control register in half duplex mode, the transmit sub-module transmits 64 bits of data, which can consist of 16 nibbles of 1011 or in bit-rate mode 492 32117A-10/2010 AT32UC3C 64 1s, whenever it sees an incoming frame to force a collision. This provides a way of implementing flow control in half-duplex mode. 24.5.6 Pause Frame Support The start of an 802.3 pause frame is as follows: Table 24-3. Start of an 802.3 Pause Frame Destination Address Source Address Type (Mac Control Frame) Pause Opcode Pause Time 0x0180C2000001 6 bytes 0x8808 0x0001 2 bytes The network configuration register contains a receive pause enable bit (13). If a valid pause frame is received, the pause time register is updated with the frame's pause time, regardless of its current contents and regardless of the state of the configuration register bit 13. An interrupt (12) is triggered when a pause frame is received, assuming it is enabled in the interrupt mask register. If bit 13 is set in the network configuration register and the value of the pause time register is non-zero, no new frame is transmitted until the pause time register has decremented to zero. The loading of a new pause time, and hence the pausing of transmission, only occurs when the MACB is configured for full-duplex operation. If the MACB is configured for half-duplex, there is no transmission pause, but the pause frame received interrupt is still triggered. A valid pause frame is defined as having a destination address that matches either the address stored in specific address register 1 or matches 0x0180C2000001 and has the MAC control frame type ID of 0x8808 and the pause opcode of 0x0001. Pause frames that have FCS or other errors are treated as invalid and are discarded. Valid pause frames received increment the Pause Frame Received statistic register. The pause time register decrements every 512 bit times (i.e., 128 RX_CLK in nibble mode) once transmission has stopped. For test purposes, the register decrements every RX_CLK cycle once transmission has stopped if bit 12 (retry test) is set in the network configuration register. If the pause enable bit (13) is not set in the network configuration register, then the decrementing occurs regardless of whether transmission has stopped or not. An interrupt (13) is asserted whenever the pause time register decrements to zero (assuming it is enabled in the interrupt mask register). Automatic transmission of pause frames is supported through the transmit pause frame bits of the network control register and the tx_pause and tx_pause_zero inputs. If either bit 11 or bit 12 of the network control register is written to with a 1, or if the input signal tx_pause is toggled, a pause frame is transmitted only if full duplex is selected in the network configuration register and transmit is enabled in the network control register. Pause frame transmission occurs immediately if transmit is inactive or if transmit is active between the current frame and the next frame due to be transmitted. The transmitted pause frame is comprised of the items in the following list: * a destination address of 01-80-C2-00-00-01 * a source address taken from the specific address 1 register * a type ID of 88-08 (MAC control frame) * a pause opcode of 00-01 * a pause quantum 493 32117A-10/2010 AT32UC3C * fill of 00 to take the frame to minimum frame length * valid FCS The pause quantum used in the generated frame depends on the trigger source for the frame as follows: 1. If bit 11 is written with a one, the pause quantum comes from the transmit pause quantum register. The Transmit Pause Quantum register resets to a value of 0xFFFF giving a maximum pause quantum as a default. 2. If bit 12 is written with a one, the pause quantum is zero. 3. If the tx_pause input is toggled and the tx_pause_zero input is held low until the next toggle, the pause quantum comes from the transmit pause quantum register. 4. If the tx_pause input is toggled and the tx_pause_zero input is held high until the next toggle, the pause quantum is zero. After transmission, no interrupts are generated and the only statistics register that is incremented is the pause frames transmitted register. 24.5.7 Receive Sub-module The receive sub-module checks for valid preamble, FCS, alignment and length, presents received frames to the DMA interface and stores the frames destination address for use by the address checking sub-module. If, during frame reception, the frame is found to be too long or RX_ER is asserted, a bad frame indication is sent to the DMA interface. The DMA interface then stops sending data to memory. At the end of frame reception, the receive sub-module indicates to the DMA interface whether the frame is good or bad. The DMA interface recovers the current receive buffer if the frame was bad. The receive sub-module signals the register sub-module to increment the alignment error, the CRC (FCS) error, the short frame, long frame, jabber error, the receive symbol error statistics and the length field mismatch statistics. The enable bit for jumbo frames in the network configuration register allows the MACB to receive jumbo frames of up to 10240 bytes in size. This operation does not form part of the IEEE802.3 specification and is disabled by default. When jumbo frames are enabled, frames received with a frame size greater than 10240 bytes are discarded. 24.5.8 Address Checking Sub-module The address checking (or filter) sub-module indicates to the DMA interface which receive frames should be copied to memory. Whether a frame is copied depends on what is enabled in the network configuration register, the state of the external match pin, the contents of the specific address and hash registers and the frame's destination address. In this implementation of the MACB, the frame's source address is not checked. If bit 18 of the Network Configuration register is not set, a frame is not copied to memory if the MACB is transmitting in half duplex mode at the time a destination address is received. If bit 18 of the Network Configuration register is set, frames can be received while transmitting in half-duplex mode. Ethernet frames are transmitted a byte at a time, least significant bit first. The first six bytes (48 bits) of an Ethernet frame make up the destination address. The first bit of the destination address, the LSB of the first byte of the frame, is the group/individual bit: this is One for multicast addresses and Zero for unicast. The All Ones address is the broadcast address, and a special case of multicast. The MACB supports recognition of four specific addresses. Each specific address requires two registers, specific address register bottom and specific address register top. Specific address 494 32117A-10/2010 AT32UC3C register bottom stores the first four bytes of the destination address and specific address register top contains the last two bytes. The addresses stored can be specific, group, local or universal. The destination address of received frames is compared against the data stored in the specific address registers once they have been activated. The addresses are deactivated at reset or when their corresponding specific address register bottom is written. They are activated when specific address register top is written. If a receive frame address matches an active address, the frame is copied to memory. The following example illustrates the use of the address match registers for a MAC address of 21:43:65:87:A9:CB. Preamble 55 SFD D5 DA (Octet0 - LSB) 21 DA(Octet 1) 43 DA(Octet 2) 65 DA(Octet 3) 87 DA(Octet 4) A9 DA (Octet5 - MSB) CB SA (LSB) 00 SA 00 SA 00 SA 00 SA 00 SA (MSB) 43 SA (LSB) 21 The sequence above shows the beginning of an Ethernet frame. Byte order of transmission is from top to bottom as shown. For a successful match to specific address 1, the following address matching registers must be set up: * Base address + 0x98 0x87654321 (Bottom) * Base address + 0x9C 0x0000CBA9 (Top) And for a successful match to the Type ID register, the following should be set up: * Base address + 0xB8 0x00004321 24.5.9 Broadcast Address The broadcast address of 0xFFFFFFFFFFFF is recognized unless the `no broadcast' bit in the network configuration register is set. 24.5.10 Hash Addressing The hash address register is 64 bits long and takes up two locations in the memory map. The least significant bits are stored in hash register bottom and the most significant bits in hash register top. 495 32117A-10/2010 AT32UC3C The unicast hash enable and the multicast hash enable bits in the network configuration register enable the reception of hash matched frames. The destination address is reduced to a 6-bit index into the 64-bit hash register using the following hash function. The hash function is an exclusive or of every sixth bit of the destination address. hash_index[5] = da[5] ^ da[11] ^ da[17] ^ da[23] ^ da[29] ^ da[35] ^ da[41] ^ da[47] hash_index[4] = da[4] ^ da[10] ^ da[16] ^ da[22] ^ da[28] ^ da[34] ^ da[40] ^ da[46] hash_index[3] = da[3] ^ da[09] ^ da[15] ^ da[21] ^ da[27] ^ da[33] ^ da[39] ^ da[45] hash_index[2] = da[2] ^ da[08] ^ da[14] ^ da[20] ^ da[26] ^ da[32] ^ da[38] ^ da[44] hash_index[1] = da[1] ^ da[07] ^ da[13] ^ da[19] ^ da[25] ^ da[31] ^ da[37] ^ da[43] hash_index[0] = da[0] ^ da[06] ^ da[12] ^ da[18] ^ da[24] ^ da[30] ^ da[36] ^ da[42] da[0] represents the least significant bit of the first byte received, that is, the multicast/unicast indicator, and da[47] represents the most significant bit of the last byte received. If the hash index points to a bit that is set in the hash register, then the frame is matched according to whether the frame is multicast or unicast. A multicast match is signalled if the multicast hash enable bit is set. da[0] is 1 and the hash index points to a bit set in the hash register. A unicast match is signalled if the unicast hash enable bit is set. da[0] is 0 and the hash index points to a bit set in the hash register. To receive all multicast frames, the hash register should be set with all ones and the multicast hash enable bit should be set in the network configuration register. 24.5.11 External Address Matching The external address signal (eam) is enabled by bit 9 in the network configuration register. When enabled, the filter sub-module sends the store frame and the external address match status signal to the DMA interface if the external address match signal is asserted (from a source external to the MACB) and the destination address has been received and the frame has not completed. For the DMA interface to be able to copy the frame to memory, the external address signal must be asserted before four words have been loaded into the receive FIFO. 24.5.12 Copy All Frames (or Promiscuous Mode) If the copy all frames bit is set in the network configuration register, then all non-errored frames are copied to memory. For example, frames that are too long, too short, or have FCS errors or RX_ER asserted during reception are discarded and all others are received. Frames with FCS errors are copied to memory if bit 19 in the network configuration register is set. 24.5.13 Type ID Checking The contents of the type_id register are compared against the length/type ID of received frames (i.e., bytes 13 and 14). Bit 22 in the receive buffer descriptor status is set if there is a match. The reset state of this register is zero which is unlikely to match the length/type ID of any valid Ethernet frame. Note: A type ID match does not affect whether a frame is copied to memory. 496 32117A-10/2010 AT32UC3C 24.5.14 VLAN Support An Ethernet encoded 802.1Q VLAN tag looks like this: Table 24-4. 802.1Q VLAN Tag TPID (Tag Protocol Identifier) 16 bits TCI (Tag Control Information) 16 bits 0x8100 First 3 bits priority, then CFI bit, last 12 bits VID The VLAN tag is inserted at the 13th byte of the frame, adding an extra four bytes to the frame. If the VID (VLAN identifier) is null (0x000), this indicates a priority-tagged frame. The MAC can support frame lengths up to 1536 bytes, 18 bytes more than the original Ethernet maximum frame length of 1518 bytes. This is achieved by setting bit 8 in the network configuration register. The following bits in the receive buffer descriptor status word give information about VLAN tagged frames: * Bit 21 set if receive frame is VLAN tagged (i.e. type id of 0x8100) * Bit 20 set if receive frame is priority tagged (i.e. type id of 0x8100 and null VID). (If bit 20 is set bit 21 is set also.) * Bit 19, 18 and 17 set to priority if bit 21 is set * Bit 16 set to CFI if bit 21 is set 24.5.15 Wake-on LAN Support The receive module supports wake-on LAN by detecting the following events on incoming receive frames: * Magic packet * ARP request to the device IP address * Specific address 1 filter match * Multicast hash filter match If one of these events occurs wake-on LAN detection is indicated by asserting WOL output pin for 64 RX_CLK cycles. These events can be individually enabled by bits MAG, ARP, SA1 & MTI in wake-on LAN register (WOL). Also, for wake-on LAN detection to occur, receive enable must be set in the network control register (NCR), however a receive buffer does not have to be available. WOL assertion due to ARP request, specific address 1 or multicast filter events will occur even if the frame is errored. For magic packet event, the frame must be correctly formed and error free. A magic packet event is detected if all of the following are true: * magic packet events are enabled by WOL.MAG bit * the frame's destination address matches specific address 1 * the frame is correctly formed with no errors * the frame contains at least 6 bytes of 0xFF for synchronization * there are 16 repetitions of the contents of specific address 1 register immediately following the synchronization An ARP packet event is detected if all of the following are true: * ARP request are enabled by WOL.ARP bit * broadcasts are allowed by NCFG.CAF 497 32117A-10/2010 AT32UC3C * the frame has a broadcast destination address (bytes 1 to 6) * the frame has a typeID field of 0x0806 (bytes 13 and 14) * the frame has an ARP operation field of 0x0001 (bytes 21 and 22) * the least significant 16 bits of the frame ARP target protocol (bytes 41 and 42) match the value written in WOL.IP. The decoding of the ARP fields adjusts automatically if a VLAN tag is detected within the frame. The reserved value of 0x0000 for wake-on LAN target address value will not cause an ARP request event, even if matched by the frame. A specific address 1 filter match event will occur if all of the following are true: * specific address 1 events are enabled by WOL.SA1 bit * the frame destination address matches the value programmed in the specific address 1 registers A multicast filter match event will occur if all of the following are true: * multicast hash events are enabled by WOL.MTI bit * multicast hash filtering is enabled by NCFG.MTI bit * the frame destination address matches against the multicast hash filter * the frame destination address is not a broadcast 24.5.16 PHY Maintenance The register MAN enables the MACB to communicate with a PHY by means of the MDIO interface. It is used during auto-negotiation to ensure that the MACB and the PHY are configured for the same speed and duplex configuration. The PHY maintenance register is implemented as a shift register. Writing to the register starts a shift operation which is signalled as complete when bit two is set in the network status register (about 2000 MCK cycles later when bit ten is set to zero, and bit eleven is set to one in the network configuration register). An interrupt is generated as this bit is set. During this time, the MSB of the register is output on the MDIO pin and the LSB updated from the MDIO pin with each Divided PB Clock (DPC) cycle. This causes transmission of a PHY management frame on MDIO. Reading during the shift operation returns the current contents of the shift register. At the end of management operation, the bits have shifted back to their original locations. For a read operation, the data bits are updated with data read from the PHY. It is important to write the correct values to the register to ensure a valid PHY management frame is produced. The MDIO interface can read IEEE 802.3 clause 45 PHYs as well as clause 22 PHYs. To read clause 45 PHYs, bits [31:28] should be written to 0x0011. For a description of DPC generation, see the network configuration register in section "Network Configuration Register" on page 507. 24.5.17 Media Independent Interface The Ethernet MAC is capable of interfacing to both RMII and MII Interfaces. The RMII bit in the USRIO register controls the interface that is selected. When this bit is set, the RMII interface is selected, else the MII interface is selected. 498 32117A-10/2010 AT32UC3C The MII and RMII interface are capable of both 10Mb/s and 100Mb/s data rates as described in the IEEE 802.3u standard. The signals used by the MII and RMII interfaces are described in Table 24-5. Table 24-5. Pin Configuration Pin Name MII RMII TX_CLK Transmit Clock Reference Clock CRS Carrier Sense COL Collision Detect RX_DV Data Valid Carrier Sense/Data Valid RXD[3:0] RXS[3:0] 4-bit Receive Data RXD[1:0] 2-bit Receive Data RX_ER Receive Error Receive Error RX_CLK Receive Clock TX_EN Transmit Enable Transmit Enable TXD[3:0] TXD[3:0] 4-bit Transmit Data TXD[1:0] 2-bit Transmit Data TX_ER Transmit Error The intent of the RMII is to provide a reduced pin count alternative to the IEEE 802.3u MII. It uses 2 bits for transmission (TXD[1:0]) and two bits for reception (RXD[1:0]). There are Transmit Enable (TX_EN), a Receive Error (RX_ER), a Carrier Sense (CRS), and a 50 MHz Reference Clock (TX_CLK) for 100Mb/s data rate. 24.5.17.1 RMII Transmit and Receive Operation The same signals are used internally for both the RMII and the MII operations. The RMII maps these signals in a more pin-efficient manner. The transmit and receive bits are converted from a 4-bit parallel format to a 2-bit parallel scheme that is clocked at twice the rate. The carrier sense and data valid signals are combined into the RX_DV signal. This signal contains information on carrier sense, FIFO status, and validity of the data. Transmit error bit (TX_ER) and collision detect (COL) are not used in RMII mode. 499 32117A-10/2010 AT32UC3C 24.6 24.6.1 Programming Interface Configuration Initialization of the MACB configuration (e.g. frequency ratios) must be done while the transmit and receive circuits are disabled. Network control register and network configuration register are described below. 24.6.2 Receive Buffer List Receive data is written to areas of data (i.e., buffers) in system memory. These buffers are listed in another data structure that also resides in main memory. This data structure (receive buffer queue) is a sequence of descriptor entries as defined in "Receive Buffer Descriptor Entry" on page 488. It points to this data structure. Figure 24-2. Receive Buffer List Receive Buffer 0 Receive Buffer Queue Pointer (MAC Register) Receive Buffer 1 Receive Buffer N Receive Buffer Description List (In Memory) (In Memory) To create the list of buffers: 1. Allocate a number (n) of buffers of 128 bytes in system memory. 2. Allocate an area 2n words for the receive buffer descriptor entry in system memory and create n entries in this list. Mark all entries in this list as owned by MACB, i.e., bit 0 of word 0 set to 0. 3. If less than 1024 buffers are defined, the last descriptor must be marked with the wrap bit (bit 1 in word 0 set to 1). 4. Write address of receive buffer descriptor entry to MACB register receive buffer queue pointer. 5. The receive circuits can then be enabled by writing to the address recognition registers and then to the network control register. 500 32117A-10/2010 AT32UC3C 24.6.3 Transmit Buffer List Transmit data is read from the system memory These buffers are listed in another data structure that also resides in main memory. This data structure (Transmit Buffer Queue) is a sequence of descriptor entries (as defined in Table 24-2 on page 491) that points to this data structure. To create this list of buffers: 1. Allocate a number (n) of buffers of between 1 and 2047 bytes of data to be transmitted in system memory. Up to 128 buffers per frame are allowed. 2. Allocate an area 2n words for the transmit buffer descriptor entry in system memory and create N entries in this list. Mark all entries in this list as owned by MACB, i.e. bit 31 of word 1 set to 0. 3. If fewer than 1024 buffers are defined, the last descriptor must be marked with the wrap bit (bit 30 in word 1 set to 1). 4. Write address of transmit buffer descriptor entry to MACB register transmit buffer queue pointer. 5. The transmit circuits can then be enabled by writing to the network control register. 24.6.4 Address Matching The MACB register-pair hash address and the four specific address register-pairs must be written with the required values. Each register-pair comprises a bottom register and top register, with the bottom register being written first. The address matching is disabled for a particular register-pair after the bottom-register has been written and re-enabled when the top register is written. See Section "24.5.8" on page 494. for details of address matching. Each register-pair may be written at any time, regardless of whether the receive circuits are enabled or disabled. 24.6.5 Interrupts There are 14 interrupt conditions that are detected within the MACB. These are ORed to make a single interrupt. This interrupt is handled by the interrupt controller. On receipt of the interrupt signal, the CPU enters the interrupt handler. To ascertain which interrupt has been generated, read the interrupt status register. Note that this register clears itself when read. At reset, all interrupts are disabled. To enable an interrupt, write to interrupt enable register with the pertinent interrupt bit set to 1. To disable an interrupt, write to interrupt disable register with the pertinent interrupt bit set to 1. To check whether an interrupt is enabled or disabled, read interrupt mask register: if the bit is set to 1, the interrupt is disabled. 24.6.6 Transmitting Frames To set up a frame for transmission: 1. Enable transmit in the network control register. 2. Allocate an area of system memory for transmit data. This does not have to be contiguous, varying byte lengths can be used as long as they conclude on byte borders. 3. Set-up the transmit buffer list. 4. Set the network control register to enable transmission and enable interrupts. 5. Write data for transmission into these buffers. 6. Write the address to transmit buffer descriptor queue pointer. 7. Write control and length to word one of the transmit buffer descriptor entry. 8. Write to the transmit start bit in the network control register. 501 32117A-10/2010 AT32UC3C 24.6.7 Receiving Frames When a frame is received and the receive circuits are enabled, the MACB checks the address and, in the following cases, the frame is written to system memory: * if it matches one of the four specific address registers. * if it matches the hash address function. * if it is a broadcast address (0xFFFFFFFFFFFF) and broadcasts are allowed. * if the MACB is configured to copy all frames. * if the EAM is asserted before four words have been loaded into the receive FIFO. The register receive buffer queue pointer points to the next entry (see Table 24-1 on page 488) and the MACB uses this as the address in system memory to write the frame to. Once the frame has been completely and successfully received and written to system memory, the MACB then updates the receive buffer descriptor entry with the reason for the address match and marks the area as being owned by software. Once this is complete an interrupt receive complete is set. Software is then responsible for handling the data in the buffer and then releasing the buffer by writing the ownership bit back to 0. If the MACB is unable to write the data at a rate to match the incoming frame, then an interrupt receive overrun is set. If there is no receive buffer available, i.e., the next buffer is still owned by software, the interrupt receive buffer not available is set. If the frame is not successfully received, a statistic register is incremented and the frame is discarded without informing software. 502 32117A-10/2010 AT32UC3C 24.7 User Interface Table 24-6. MACB Register Memory Map Offset Register Register Name Access Reset 0x00 Network Control Register NCR Read/Write 0x00000000 0x04 Network Configuration Register NCFG Read/Write 0x00008000 0x08 Network Status Register NSR Read-only - 0x14 Transmit Status Register TSR Read/Write 0x00000000 0x18 Receive Buffer Queue Pointer Register RBQP Read/Write 0x00000000 0x1C Transmit Buffer Queue Pointer Register TBQP Read/Write 0x00000000 0x20 Receive Status Register RSR Read/Write 0x00000000 0x24 Interrupt Status Register ISR Read/Write 0x00000000 0x28 Interrupt Enable Register IER Write-only 0x00000000 0x2C Interrupt Disable Register IDR Write-only 0x00000000 0x30 Interrupt Mask Register IMR Read-only 0x00003FFF 0x34 Phy Maintenance Register MAN Read/Write 0x00000000 0x38 Pause Time Register PTR Read/Write 0x00000000 0x3C Pause Frames Received Register PFR Read/Write 0x00000000 0x40 Frames Transmitted Ok Register FTO Read/Write 0x00000000 0x44 Single Collision Frames Register SCF Read/Write 0x00000000 0x48 Multiple Collision Frames Register MCF Read/Write 0x00000000 0x4C Frames Received Ok Register FRO Read/Write 0x00000000 0x50 Frame Check Sequence Errors Register FCSE Read/Write 0x00000000 0x54 Alignment Errors Register ALE Read/Write 0x00000000 0x58 Deferred Transmission Frames Register DTF Read/Write 0x00000000 0x5C Late Collisions Register LCOL Read/Write 0x00000000 0x60 Excessive Collisions Register EXCOL Read/Write 0x00000000 0x64 Transmit Underrun Errors Register TUND Read/Write 0x00000000 0x68 Carrier Sense Errors Register CSE Read/Write 0x00000000 0x6C Receive Resource Errors Register RRE Read/Write 0x00000000 0x70 Receive Overrun Errors Register ROV Read/Write 0x00000000 0x74 Receive Symbol Errors Register RSE Read/Write 0x00000000 0x78 Excessive Length Errors Register ELE Read/Write 0x00000000 0x7C Receive Jabbers Register RJA Read/Write 0x00000000 0x80 Undersize Frames Register USF Read/Write 0x00000000 0x84 SQE Test Errors Register STE Read/Write 0x00000000 0x88 Received Length Field Mismatch Register RLE Read/Write 0x00000000 0x8C Transmitted Pause Frames Register TPF Read/Write 0x00000000 0x90 Hash Register Bottom HRB Read/Write 0x00000000 503 32117A-10/2010 AT32UC3C Table 24-6. 1. MACB Register Memory Map (Continued) Offset Register Register Name Access Reset 0x94 Hash Register Top HRT Read/Write 0x00000000 0x98 Specific Address 1 Bottom Register SA1B Read/Write 0x00000000 0x9C Specific Address 1 Top Register SA1T Read/Write 0x00000000 0xA0 Specific Address 2 Bottom Register SA2B Read/Write 0x00000000 0xA4 Specific Address 2 Top Register SA2T Read/Write 0x00000000 0xA8 Specific Address 3 Bottom Register SA3B Read/Write 0x00000000 0xAC Specific Address 3 Top Register SA3T Read/Write 0x00000000 0xB0 Specific Address 4 Bottom Register SA4B Read/Write 0x00000000 0xB4 Specific Address 4 Top Register SA4T Read/Write 0x00000000 0xB8 Type ID Checking Register TID Read/Write 0x00000000 0xBC Transmit Pause Quantum Register TPQ Read/Write 0x0000FFFF 0xC0 User Input/output Register USRIO Read/Write 0x00000000 0xC4 Wake on LAN Register WOL Read/Write 0x00000000 0xFC Version Register VERSION Read-only - (1) The reset values are device specific. Please refer to the Module Configuration section at the end of this chapter. Statistics registers (PFR to TPF) should be read frequently enough to prevent loss of data. The receive statistics registers are only incremented when the receive enable bit is set in the network control register (NCR.RE). Write access to statistics registers is allowed if NCR.WESTAT is set. Statistic registers are cleared on a read and stick at all ones when they count to their maximum value. 504 32117A-10/2010 AT32UC3C 24.7.1 Name: Network Control Register NCR Access Type: Read/Write Offset: 0x00 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 - - - TZQ TPF THALT TSTART BP 7 6 5 4 3 2 1 0 WESTAT INCSTAT CLRSTAT MPE TE RE LLB LB * TZQ: Transmit Zero Quantum Pause Frame Writing a one to this bit sends a pause frame with zero pause quantum at the next available transmitter idle time. * TPF: Transmit Pause Frame Writing a one to this bit sends a pause frame with the pause quantum from the transmit pause quantum register at the next available transmitter idle time. * THALT: Transmit Halt Writing a one to this bit halts transmission as soon as any ongoing frame transmission ends. * TSTART: Start Transmission Writing a one to this bit starts transmission. * BP: Back Pressure 0: No collision are forced. 1: In half duplex mode, forces collisions on all received frames. * WESTAT: Write Enable for Statistics Registers 0: Statistics registers are read-only. 1: Statistics registers are writable for functional test purposes. * INCSTAT: Increment Statistics Registers Writing a one increments all the statistics registers by one for test purposes. * CLRSTAT: Clear Statistics Registers Writing a one clears the statistics registers. * MPE: Management Port Enable 0: Forces MDIO to high impedance state and DPC low. 1: Enables the management port. * TE: Transmit Enable 0: Transmission stops immediately, the transmit FIFO and control registers are cleared and the transmit queue pointer register resets to point to the start of the transmit descriptor list. 1: Enables the Ethernet transmitter to send data. 505 32117A-10/2010 AT32UC3C * RE: Receive Enable 0: Frame reception stops immediately and the receive FIFO is cleared. The receive queue pointer register is unaffected. 1: Enables the MACB to receive data. * LLB: Local Loopback 0: Local loopback is disabled. 1: Local loopback is enabled. It connects TXD to RXD, TX_EN to RX_DV, forces full duplex and drives RX_CLK and TX_CLK with CLK_MACB_PB divided by 4. RX_CLK and TX_CLK may glitch as the MACB is switched into and out of internal loop back. It is important that receive and transmit circuits have already been disabled when making the switch into and out of internal loop back. This function may not be supported by some instantiations of the MACB. * LB: Loopback 0: Loopback is disabled. 1: Loopback is enabled. Asserts the loopback signal to the PHY. 506 32117A-10/2010 AT32UC3C 24.7.2 Name: Network Configuration Register NCFGR Access Type: Read/Write Offset: 0x04 Reset Value: 0x00008000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - IRXFCS EFRHD DRFCS RLCE 15 14 13 12 11 10 9 8 PAE RTY EAE FS RBOF CLK 7 6 5 4 3 2 1 0 UNI MTI NBC CAF JFRAME BR FD SPD * IRXFCS: Ignore RX FCS 0: Normal operation. 1: Frames with FCS/CRC errors are not rejected and no FCS error statistics are counted. * EFRHD: Enable Frames to be Received in Half-Duplex mode 0: Disabled. 1: Enabled (while transmitting). * DRFCS: Discard Receive FCS 0: FCS field of received frames are copied to memory. 1: FCS field of received frames are not copied to memory. * RLCE: Receive Length field Checking Enable 0: Disabled. 1: Frames with measured lengths shorter than their length fields are discarded. Frames containing a type ID in bytes 13 and 14 (length/type ID = 0600) are not be counted as length errors. * RBOF: Receive Buffer Offset Indicates the number of bytes by which the received data is offset from the start of the first receive buffer. RBOF Offset 00 No offset from start of receive buffer 01 One-byte offset from start of receive buffer 10 Two-byte offset from start of receive buffer 11 Three-byte offset from start of receive buffer * PAE: Pause Enable 0: Pause disabled. 1: Pause enabled. Transmission pauses when a valid pause frame is received. 507 32117A-10/2010 AT32UC3C * RTY: Retry Test 0: Normal operation. 1: The back off between collisions is always one slot time. It helps testing the too many retries condition. Also used in the pause frame tests to reduce the pause counters decrement time from 512 bit times, to every RX_CLK cycle. * CLK: PB Clock Divider Determines by what number system clock is divided to generate Divided PB Clock (DPC). For conformance with 802.3, DPC must not exceed 2.5MHz (DPC is only active during MDIO read and write operations). CLK DPC 00 PB clock divided by 8 (PB clock up to 20 MHz) 01 PB clock divided by 16 (PB clock up to 40 MHz) 10 PB clock divided by 32 (PB clock up to 80 MHz) 11 PB clock divided by 64 (PB clock up to 160 MHz) * EAE: External Address Match Enable 0: External address match is disabled. 1: External address match is enabled. Eam pin can be used to copy frames to memory. * FS: Frame Size 0: Reject any frames above 1518 bytes. 1: Accept frames up to 1536 bytes. * UNI: Unicast Hash Enable 0: Unicast hash is disabled. 1: Unicast hash is enabled. Unicast frames are received when the 6-bit hash function of the destination address points to a bit that is set in the hash register. * MTI: Multicast Hash Enable 0: Multicast hash is disabled. 1: Multicast hash is enabled. Multicast frames are received when the 6-bit hash function of the destination address points to a bit that is set in the hash register. * NBC: No Broadcast 0: Frames addressed to the broadcast address of all ones are received. 1: Frames addressed to the broadcast address of all ones are not received. * JFRAME: Jumbo Frames 0: Jumbo frames are disabled. 1: Enable jumbo frames of up to 10240 bytes to be accepted. * CAF: Copy All Frames 0: Copy all frames is disabled. 1: All valid frames are received. * BR: Bitrate 0: Data is transmitted least significant nibble first. 1: Data is serialized and transmitted least significant bit first (10Mbps). Must be written before receive and transmit enable in the network control register. Serial interface is configured with transmit and receive data being driven out on TXD[0] and received on RXD[0] serially. Also the CRS and RX_DV are logically ORed together so either may be used as the data valid signal. * FD: Full Duplex 0: Full duplex mode is disabled. 1: Full duplex mode is enabled. Transmit sub-module ignores the state of collision and carrier sense and allows receive while transmitting. Also controls the half duplex pin. * SPD: Speed 0: 10 Mbit/s speed. 1: 100 Mbit/s speed. Bit value is reflected on the SPEED pin. 508 32117A-10/2010 AT32UC3C 24.7.3 Name: Network Status Register NSR Access Type: Read-only Offset: 0x08 Reset Value: - 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 - - - - - - - - 7 6 5 4 3 2 1 0 - - - - - IDLE MDIO - * IDLE: IDLE Status 0: PHY management logic is idle (i.e., has completed). 1: PHY management logic is running. * MDIO: MDIO Pin Status Use the PHY maintenance register for reading managed frames rather than this bit. 509 32117A-10/2010 AT32UC3C 24.7.4 Name: Transmit Status Register TSR Access Type: Read/Write Offset: 0x14 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 - - - - - - - - 7 6 5 4 3 2 1 0 - UND COMP BEX TGO RLE COL UBR This register, when read, returns details of the status of a transmit. Once read, individual bits may be cleared by writing a one to them. It is not possible to write a bit to one by writing to the register. * UND: Transmit Underrun This bit is set when transmit DMA was not able to read data from memory, either because the bus was not granted in time or because a used bit was read midway through frame transmission. If this occurs, the transmitter forces bad CRC. Write a one to clear this bit. 0: No transmit underrun. 1: Transmit underrun. * COMP: Transmit Complete This bit is set when a frame has been transmitted. Write a one to clear this bit. 0: Transmit is not completed. 1: Transmit is completed. * BEX: Buffers Exhausted Mid Frame This bit is set if the buffers run out during transmission of a frame. Then transmission stops, FCS shall be bad and TX_ER is asserted. Write a one to clear to this bit. 0: Buffer is not exhausted. 1: Buffer is exhausted. * TGO: Transmit Go 0: Transmit is inactive. 1: Transmit is active. * RLE: Retry Limit Exceeded This bit is set when retry limit has exceeded. Write a one to clear this bit. 0: Retry limit is not exceeded. 510 32117A-10/2010 AT32UC3C 1: Retry limit is exceeded. * COL: Collision Occurred This bit is set by the assertion of collision. Write a one to clear this bit. 0: No collision detected. 1: Collision detected. * UBR: Used Bit Read This bit is set when a transmit buffer descriptor is read with its used bit set. Write a one to clear this bit. 0: Used bit is not set. 1: Used bit set. 511 32117A-10/2010 AT32UC3C 24.7.5 Name: Receive Buffer Queue Pointer Register RBQP Access Type: Read/Write Offset: 0x18 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 19 18 17 16 11 10 9 8 3 2 1 0 - - ADDR[29:22] 23 22 21 20 ADDR[21:14] 15 14 13 12 ADDR[13:6] 7 6 5 4 ADDR[5:0] This register points to the entry in the receive buffer queue (descriptor list) currently being used. It is written with the start location of the receive buffer descriptor list. The lower order bits increment as buffers are used up and wrap to their original values after either 1024 buffers or when the wrap bit of the entry is set. Reading this register returns the location of the descriptor currently being accessed. This value is incremented as buffers are used. User should not use this register to determine where to remove received frames from the queue as it constantly changes when new frames are received. User should instead use the buffer descriptor queue checking the used bits. Receive buffer writes can be bursts of two words and, as with transmit buffer reads, it is recommended that bit 2 is always written to zero to prevent a burst crossing a 1K boundary, in violation of the System Bus specification. * ADDR: Receive Buffer Queue Pointer Address Write this field to set the start address of the receive queue. Read this field to get the address of the current buffer being used. 512 32117A-10/2010 AT32UC3C 24.7.6 Name: Transmit Buffer Queue Pointer Register TBQP Access Type: Read/Write Offset: 0x1C Reset Value: 0x00000000 31 30 29 28 27 26 25 24 19 18 17 16 11 10 9 8 3 2 1 0 - - ADDR[29:22] 23 22 21 20 ADDR[21:14] 15 14 13 12 ADDR[13:6] 7 6 5 4 ADDR[5:0] This register points to the entry in the transmit buffer queue (descriptor list) currently being used. It is written with the start location of the transmit buffer descriptor list. The lower order bits increment as buffers are used up and wrap to their original values after either 1024 buffers or when the wrap bit of the entry is set. This register can only be written when bit TSR.TGO is low. As transmit buffer reads can be bursts of two words, it is recommended that bit 2 is always written to zero to prevent a burst crossing a 1K boundary, in violation of the System Bus specification. * ADDR: Transmit buffer queue pointer address Write this field to set the start address of the transmit queue. Read this field to get the address of the first buffer of the frame being transmitted or about to be transmitted. 513 32117A-10/2010 AT32UC3C 24.7.7 Name: Receive Status Register RSR Access Type: Read/Write Offset: 0x20 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 - - - - - - - - 7 6 5 4 3 2 1 0 - - - - - OVR REC BNA This register, when read, returns details of the status of a receive. Once read, individual bits may be cleared by writing a one to them. It is not possible to write a bit to one by writing to the register. * OVR: Receive Overrun This bit is set when the DMA interface is unable to store the receive frame to memory, either because the bus was not granted in time or because a bus error was returned. The buffer is recovered if this happens. Write a one to clear this bit. 0: No receive overrun detected. 1: Receive overrun detected. * REC: Frame Received This bit is set when one or more frames have been received and placed in memory. Write a one to clear this bit. 0: No frame received. 1: Frame received. * BNA: Buffer Not Available The DMA reads the pointer each time a new frame starts, until a valid pointer is found. This bit is set at each attempt that fails even if it has not had a successful pointer read since it has been cleared. Write a one to clear this bit. 0: Buffer is available. 1: Buffer is not available because an attempt was made to get a new buffer and the pointer indicated that it was owned by the processor. 514 32117A-10/2010 AT32UC3C 24.7.8 Name: Interrupt Status Register ISR Access Type: Read/Write Offset: 0x24 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 - - PTZ PFR HRESP ROVR - - 7 6 5 4 3 2 1 0 TCOMP TXERR RLE TUND TXUBR RXUBR RCOMP MFD * PTZ: Pause Time Zero This bit is set when the pause time register (PTR) decrements to zero. This bit is cleared after read. 0: PTR > 0. 1: PTR = 0. * PFR: Pause Frame Received This bit is cleared after read. 0: No valid pause frame received. 1: Valid pause frame received. * HRESP: Hresp Not OK This bit is set when the DMA interface detects a bus error. This bit is cleared after read. 0: HRESP is OK. 1: HRESP is not OK. * ROVR: Receive Overrun This bit is set when the receive overrun status bit is set (RSR.OVR). This bit is cleared after read. 0: RSR.OVR is not set. 1: RSR.OVR has been set. * TCOMP: Transmit Complete This bit is set when a frame has been transmitted. This bit is cleared after read. 0: Transmit is not completed. 1: Transmit is completed. * TXERR: Transmit Error This bit is set when transmit buffers exhausted in mid-frame. 515 32117A-10/2010 AT32UC3C * * * * * * This bit is cleared after read. 0: No transmit error. 1: Transmit error detected. RLE: Retry Limit Exceeded This bit is cleared after read. 0: Retry limit is not exceeded. 1: Retry limit is exceeded. TUND: Ethernet Transmit Buffer Underrun This bit is set if the DMA did not fetch frame data to transmit in time or HRESP returned not OK. It is also set if a used bit is read mid-frame or when a new transmit queue pointer is written. This bit is cleared after read. 0: No underrun detected for transmit buffer. 1: Underrun detected for transmit buffer. TXUBR: Transmit Used Bit Read This bit is cleared after read. 0: Normal operation. 1: Transmit buffer descriptor is read with its used bit set. RXUBR: Receive Used Bit Read This bit is cleared after read. 0: Normal operation. 1: Receive buffer descriptor is read with its used bit set. RCOMP: Receive Complete This bit is set when a frame has been stored in memory. This bit is cleared after read. 0: Receive is not completed. 1: Receive is completed. MFD: Management Frame Done This bit is cleared after read. 0: Management frame is not done. 1: Management frame is done. PHY maintenance register has completed its operation. 516 32117A-10/2010 AT32UC3C 24.7.9 Name: Interrupt Enable Register IER Access Type: Write-only Offset: 0x28 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 - - PTZ PFR HRESP ROVR - - 7 6 5 4 3 2 1 0 TCOMP TXERR RLE TUND TXUBR RXUBR RCOMP MFD Writing a zero to a bit in this register has no effect. Writing a one to a bit in this register will set the corresponding bit in IMR. 517 32117A-10/2010 AT32UC3C 24.7.10 Name: Interrupt Disable Register IDR Access Type: Write-only Offset: 0x2C Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 - - PTZ PFR HRESP ROVR - - 7 6 5 4 3 2 1 0 TCOMP TXERR RLE TUND TXUBR RXUBR RCOMP MFD Writing a zero to a bit in this register has no effect. Writing a one to a bit in this register will clear the corresponding bit in IMR. 518 32117A-10/2010 AT32UC3C 24.7.11 Name: Interrupt Mask Register IMR Access Type: Read-only Offset: 0x30 Reset Value: 0x00003FFF 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 - - PTZ PFR HRESP ROVR - - 7 6 5 4 3 2 1 0 TCOMP TXERR RLE TUND TXUBR RXUBR RCOMP MFD 0: The corresponding interrupt is disabled. 1: The corresponding interrupt is enabled. A bit in this register is cleared when the corresponding bit in IDR is written to one. A bit in this register is set when the corresponding bit in IER is written to one. 519 32117A-10/2010 AT32UC3C 24.7.12 Name: PHY Maintenance Register MAN Access Type: Read/Write Offset: 0x34 Reset Value: 0x00000000 31 30 29 SOF 23 27 26 RW 22 21 PHYA 15 28 25 24 17 16 PHYA[4:1] 20 19 18 REGA 14 13 CODE 12 11 10 9 8 3 2 1 0 DATA[15:8] 7 6 5 4 DATA[7:0] * SOF: Start Of Frame Must be written to 01 for a valid frame. * RW: Read/Write 10: Read operation 01: Write operation. Any other value is an invalid PHY management frame * PHYA: PHY Address PHY address. * REGA: Register Address PHY register address to access. * CODE: Code value Must be written to 10. * DATA: PHY Data For a write operation, write the data to be written to the PHY. After a read operation, contains the data read from the PHY. 520 32117A-10/2010 AT32UC3C 24.7.13 Name: Pause Time Register PTR Access Type: Read/Write Offset: 0x38 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 3 2 1 0 PTIME[15:8] 7 6 5 4 PTIME[7:0] * PTIME: Pause Time Current value of the pause time register which is decremented every 512 bit times. 521 32117A-10/2010 AT32UC3C 24.7.14 Name: Pause Frames Received Register PFR Access Type: Read/Write Offset: 0x3C Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 3 2 1 0 PFROK[15:8] 7 6 5 4 PFROK[7:0] * PFROK: Pauses Frames Received OK Number of good pause frames received. A good frame has a length of 64 to 1518 bytes (1536 if bit NCFGR.FS is set, 10240 if bit NCFGR.JFRAME is set) and has no FCS, alignment or receive symbol errors. 522 32117A-10/2010 AT32UC3C 24.7.15 Name: Frames Transmitted OK Register FTO Access Type: Read/Write Offset: 0x40 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 11 10 9 8 3 2 1 0 FTOK[23:16] 15 14 13 12 FTOK[15:8] 7 6 5 4 FTOK[7:0] * FTOK: Frames Transmitted OK Number of frames successfully transmitted, i.e., no underrun and not too many retries. 523 32117A-10/2010 AT32UC3C 24.7.16 Name: Single Collision Frames Register SCF Access Type: Read/Write Offset: 0x44 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 3 2 1 0 SCF[15:8] 7 6 5 4 SCF[7:0] * SCF: Single Collision Frames Number of frames experiencing a single collision before being successfully transmitted, i.e., no underrun. 524 32117A-10/2010 AT32UC3C 24.7.17 Name: Multicollision Frames Register MCF Access Type: Read/Write Offset: 0x48 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 3 2 1 0 MCF[15:8] 7 6 5 4 MCF[7:0] * MCF: Multicollision Frames Number of frames experiencing between 2 and 15 collisions prior to being successfully transmitted, i.e., no underrun and not too many retries. 525 32117A-10/2010 AT32UC3C 24.7.18 Name: Frames Received OK Register FRO Access Type: Read/Write Offset: 0x4C Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 11 10 9 8 3 2 1 0 FROK[23:16] 15 14 13 12 FROK[15:8] 7 6 5 4 FROK[7:0] * FROK: Frames Received OK Number of frames successfully received, i.e., address recognized and successfully copied to memory. A good frame has a length of 64 to 1518 bytes (1536 if bit NCFGR.FS is set, 10240 if bit NCFGR.JFRAME is set) and has no FCS, alignment or receive symbol errors. 526 32117A-10/2010 AT32UC3C 24.7.19 Name: Frames Check Sequence Errors Register FCSE Access Type: Read/Write Offset: 0x50 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 - - - - - - - - 7 6 5 4 3 2 1 0 FCSE * FCSE: Frame Check Sequence Errors Number of frames which have an integral number of bytes, have bad CRC and are between 64 and 1518 bytes in length (1536 if bit NCFGR.FS is set, 10240 if bit NCFGR.JFRAME is set). This register is also incremented if a symbol error is detected and the frame is of valid length and has an integral number of bytes. 527 32117A-10/2010 AT32UC3C 24.7.20 Name: Alignment Errors Register ALE Access Type: Read/Write Offset: 0x54 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 - - - - - - - - 7 6 5 4 3 2 1 0 ALE * ALE: Alignment Errors Number of frames which have not an integral number of bytes and have bad CRC when their length is truncated to an integral number of bytes and are between 64 and 1518 bytes in length (1536 if bit NCFGR.FS is set, 10240 if bit NCFGR.JFRAME is set). This register is also incremented if a symbol error is detected and the frame is of valid length and does not have an integral number of bytes. 528 32117A-10/2010 AT32UC3C 24.7.21 Name: Deferred Transmission Frames Register DTF Access Type: Read/Write Offset: 0x58 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 3 2 1 0 DTF[15:8] 7 6 5 4 DTF[7:0] * DTF: Deferred Transmission Frames Number of frames experiencing deferral due to carrier sense being active on their first attempt at transmission. Frames involved in any collision are not counted nor are frames that experienced a transmit underrun. 529 32117A-10/2010 AT32UC3C 24.7.22 Name: Late Collisions Register LCOL Access Type: Read/Write Offset: 0x5C Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 - - - - - - - - 7 6 5 4 3 2 1 0 LCOL * LCOL: Late Collisions Number of frames that experience a collision after the slot time (512 bits) has expired. A late collision is counted twice; i.e., both as a collision and a late collision. 530 32117A-10/2010 AT32UC3C 24.7.23 Name: Excessive Collisions Register EXCOL Access Type: Read/Write Offset: 0x60 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 - - - - - - - - 7 6 5 4 3 2 1 0 EXCOL * EXCOL: Excessive Collisions Number of frames that failed to be transmitted because they experienced 16 collisions. 531 32117A-10/2010 AT32UC3C 24.7.24 Name: Transmit Underrun Errors Register TUND Access Type: Read/Write Offset: 0x64 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 - - - - - - - - 7 6 5 4 3 2 1 0 TUND * TUND: Transmit Underruns Number of frames not transmitted due to a transmit DMA underrun. If this register is incremented, then no other statistics register is incremented. 532 32117A-10/2010 AT32UC3C 24.7.25 Name: Carrier Sense Errors Register CSE Access Type: Read/Write Offset: 0x68 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 - - - - - - - - 7 6 5 4 3 2 1 0 CSE * CSE: Carrier Sense Errors Number of frames transmitted where carrier sense was not seen during transmission or where carrier sense was deasserted after being asserted in a transmit frame without collision (no underrun). Only incremented in half-duplex mode. The only effect of a carrier sense error is to increment this register. The behavior of the other statistics registers is unaffected by the detection of a carrier sense error. 533 32117A-10/2010 AT32UC3C 24.7.26 Name: Received Resource Errors Register RRE Access Type: Read/Write Offset: 0x6C Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 3 2 1 0 RRE[15:8] 7 6 5 4 RRE[7:0] * RRE: Received Resource Errors Number of frames that address matched but could not be copied to memory because no receive buffer was available. 534 32117A-10/2010 AT32UC3C 24.7.27 Name: Received Overrun Errors Register ROVR Access Type: Read/Write Offset: 0x70 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 - - - - - - - - 7 6 5 4 3 2 1 0 ROVR * ROVR: Received Overrun Errors Number of frames that are address recognized but were not copied to memory because of receive DMA overrun. 535 32117A-10/2010 AT32UC3C 24.7.28 Name: Received Symbol Errors Register RSE Access Type: Read/Write Offset: 0x74 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 - - - - - - - - 7 6 5 4 3 2 1 0 RSE * RSE: Received Symbol Errors Number of frames that had RX_ER asserted during reception. Receive symbol errors are also counted as an FCS or alignment error if the frame length is between 64 and 1518 bytes (1536 if bit NCFGR.FS is set, 10240 if bit NCFGR.JFRAME is set). If the frame is larger, it is recorded as a jabber error. 536 32117A-10/2010 AT32UC3C 24.7.29 Name: Excessive Length Errors Register ELE Access Type: Read/Write Offset: 0x78 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 - - - - - - - - 7 6 5 4 3 2 1 0 EXL * EXL: Excessive Length Errors Number of frames received exceeding 1518 bytes (1536 if bit NCFGR.FS is set, 10240 if bit NCFGR.JFRAME is set) in length but do not have either a CRC error, an alignment error nor a receive symbol error. 537 32117A-10/2010 AT32UC3C 24.7.30 Name: Receive Jabbers Register RJA Access Type: Read/Write Offset: 0x7C Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 - - - - - - - - 7 6 5 4 3 2 1 0 RJB * RJB: Receive Jabbers Number of frames received exceeding 1518 bytes (1536 if bit NCFGR.FS is set, 10240 if bit NCFGR.JFRAME is set) in length and have either a CRC error, an alignment error or a receive symbol error. 538 32117A-10/2010 AT32UC3C 24.7.31 Name: Undersize Frames Register USF Access Type: Read/Write Offset: 0x80 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 - - - - - - - - 7 6 5 4 3 2 1 0 USF * USF: Undersize Frames Number of frames received less than 64 bytes in length but do not have either a CRC error, an alignment error or a receive symbol error. 539 32117A-10/2010 AT32UC3C 24.7.32 Name: SQE Test Errors Register STE Access Type: Read/Write Offset: 0x84 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 - - - - - - - - 7 6 5 4 3 2 1 0 SQER * SQER: SQE Test Errors Number of frames where COL was not asserted within 96 bit times (interframe gap) of TX_EN being deasserted in half duplex mode. 540 32117A-10/2010 AT32UC3C 24.7.33 Name: Received Length Field Mismatch Register RLE Access Type: Read/Write Offset: 0x88 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 - - - - - - - - 7 6 5 4 3 2 1 0 RLFM * RLFM: Receive Length Field Mismatch Number of frames received that have a measured length shorter than extracted from its length field. Checking is enabled by bit NCFGR.RLCE. Frames containing a type ID in bytes 13 and 14 (i.e., length/type ID 0x0600) are not counted as length field errors, neither are excessive length frames. 541 32117A-10/2010 AT32UC3C 24.7.34 Name: Transmitted Pause Frames Register TPF Access Type: Read/Write Offset: 0x8C Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 3 2 1 0 TPF[15:8] 7 6 5 4 TPF[7:0] * TPF: Transmitted Pause Frames Number of pause frames transmitted. 542 32117A-10/2010 AT32UC3C 24.7.35 Name: Hash Register Bottom HRB Access Type: Read/Write Offset: 0x90 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 19 18 17 16 11 10 9 8 3 2 1 0 ADDR[31:24] 23 22 21 20 ADDR[23:16] 15 14 13 12 ADDR[15:8] 7 6 5 4 ADDR[7:0] * ADDR: Hash Address Low Low value of the hash address register. See "Hash Addressing" on page 495. 543 32117A-10/2010 AT32UC3C 24.7.36 Name: Hash Register Top HRT Access Type: Read/Write Offset: 0x94 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 19 18 17 16 11 10 9 8 3 2 1 0 ADDR[31:24] 23 22 21 20 ADDR[23:16] 15 14 13 12 ADDR[15:8] 7 6 5 4 ADDR[7:0] * ADDR: Hash Address High High value of the hash address register. See "Hash Addressing" on page 495. 544 32117A-10/2010 AT32UC3C 24.7.37 Name: Specific Address 1 Bottom Register SA1B Access Type: Read/Write Offset: 0x98 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 19 18 17 16 11 10 9 8 3 2 1 0 ADDR[31:24] 23 22 21 20 ADDR[23:16] 15 14 13 12 ADDR[15:8] 7 6 5 4 ADDR[7:0] * ADDR: Destination Address Low Low value of the destination address. Bit zero indicates whether the address is multicast or unicast and corresponds to the least significant bit of the first byte received. 545 32117A-10/2010 AT32UC3C 24.7.38 Name: Specific Address 1 Top Register SA1T Access Type: Read/Write Offset: 0x9C Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 3 2 1 0 ADDR[15:8] 7 6 5 4 ADDR[7:0] * ADDR: Destination Address High High value of the destination address (bits 32 to 47). 546 32117A-10/2010 AT32UC3C 24.7.39 Name: Specific Address 2 Bottom Register SA2B Access Type: Read/Write Offset: 0xA0 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 19 18 17 16 11 10 9 8 3 2 1 0 ADDR[31:24] 23 22 21 20 ADDR[23:16] 15 14 13 12 ADDR[15:8] 7 6 5 4 ADDR[7:0] * ADDR: Destination Address Low Low value of the destination address. Bit zero indicates whether the address is multicast or unicast and corresponds to the least significant bit of the first byte received. 547 32117A-10/2010 AT32UC3C 24.7.40 Name: Specific Address 2 Top Register SA2T Access Type: Read/Write Offset: 0xA4 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 3 2 1 0 ADDR[15:8] 7 6 5 4 ADDR[7:0] * ADDR: Destination Address High High value of the destination address (bits 32 to 47). 548 32117A-10/2010 AT32UC3C 24.7.41 Name: Specific Address 3 Bottom Register SA3B Access Type: Read/Write Offset: 0xA8 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 19 18 17 16 11 10 9 8 3 2 1 0 ADDR[31:24] 23 22 21 20 ADDR[23:16] 15 14 13 12 ADDR[15:8] 7 6 5 4 ADDR[7:0] * ADDR: Destination Address Low Low value of the destination address. Bit zero indicates whether the address is multicast or unicast and corresponds to the least significant bit of the first byte received. 549 32117A-10/2010 AT32UC3C 24.7.42 Name: Specific Address 3 Top Register SA3T Access Type: Read/Write Offset: 0xAC Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 3 2 1 0 ADDR[15:8] 7 6 5 4 ADDR[7:0] * ADDR: Destination Address High High value of the destination address (bits 32 to 47). 550 32117A-10/2010 AT32UC3C 24.7.43 Name: Specific Address 4 Bottom Register SA4B Access Type: Read/Write Offset: 0xB0 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 19 18 17 16 11 10 9 8 3 2 1 0 ADDR[31:24] 23 22 21 20 ADDR[23:16] 15 14 13 12 ADDR[15:8] 7 6 5 4 ADDR[7:0] * ADDR: Destination Address Low Low value of the destination address. Bit zero indicates whether the address is multicast or unicast and corresponds to the least significant bit of the first byte received. 551 32117A-10/2010 AT32UC3C 24.7.44 Name: Specific Address 4 Top Register SA4T Access Type: Read/Write Offset: 0xB4 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 3 2 1 0 ADDR[15:8] 7 6 5 4 ADDR[7:0] * ADDR: Destination Address High High value of the destination address (bits 32 to 47). 552 32117A-10/2010 AT32UC3C 24.7.45 Name: Type ID Checking Register TID Access Type: Read/Write Offset: 0xB8 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 3 2 1 0 TID[15:8] 7 6 5 4 TID[7:0] * TID: Type ID Checking Comparison value for received frames (TypeID/Length field). 553 32117A-10/2010 AT32UC3C 24.7.46 Name: Transmit Pause Quantum Register TPQ Access Type: Read/Write Offset: 0xBC Reset Value: 0x0000FFFF 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 3 2 1 0 TPQ[15:8] 7 6 5 4 TPQ[7:0] * TPQ: Transmit Pause Quantum Used in hardware generation of transmitted pause frames as value for pause quantum. 554 32117A-10/2010 AT32UC3C 24.7.47 Name: User Input/Output Register USRIO Access Type: Read/Write Offset: 0xC0 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - WOL SPD BR HD LB 15 14 13 12 11 10 9 8 - - - - - - - - 7 6 5 4 3 2 1 0 - - - - TPZ TP EAM RMII This register, when read, returns details of the status of a receive. Once read, individual bits may be cleared by writing a one to them. It is not possible to write a bit to one by writing to the register. * WOL: Wake-On LAN 0: Wake-on LAN not detected. 1: Wake-on LAN detected (read-only). * SPD: Speed Image of NCFGR.SPD bit (read-only). * BR: Bitrate Image of NCFGR.BR bit (read-only). * HD: Half Duplex Inversion of NCFGR.FD bit (read-only). * LB: Loopback Image of NCR.LB bit (read-only). * TPZ: Transmit Pause Frame Zero Quantum 0: Pause frame is TPQ register value quantum length. 1: Pause frame is zero quantum length. * TP: Transmit Pause Frame Toggle this bit to send a Pause frame. * EAM: External Address Match 0: No frame is copied to memory. 1: Frame is copied to memory if NCFGR.EAE is set. * RMII: RMII mode 0: MII operation mode. 1: RMII operation mode. 555 32117A-10/2010 AT32UC3C 24.7.48 Name: Wake-On-LAN Register WOL Access Type: Read/Write Offset: 0xC4 Reset Value: 0x0000FFFF 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - MTI SA1 ARP MAG 15 14 13 12 11 10 9 8 3 2 1 0 IP[15:8] 7 6 5 4 IP[7:0] * MTI: Multicast Hash Event Enable * * * * 0: Multicast hash events are disabled. 1:Multicast hash events assert WOL pin. SA1: Specific Address Register 1 Event Enable 0: SAR1 events are disabled. 1: SAR1 events assert WOL pin. ARP: ARP Request Event Enable 0: ARP request events are disabled. 1: ARP request events assert WOL pin. MAG: Magic Packet Event Enable 0: Magic packet events are disabled. 1: Magic packet events assert WOL pin. IP: ARP request IP address 16 LSB bits of target IP. When matched, a wake-on-LAN event is generated. Zero value does not generate an event, even if it is matched by the received frame. 556 32117A-10/2010 AT32UC3C 24.7.49 Name: Version Register VERSION Access Type: Read-only Offset: 0xFC Reset Value: - 31 30 29 28 27 26 25 24 19 18 17 16 11 10 9 8 2 1 0 PR[15:8] 23 22 21 20 PR[7:0] 15 14 13 12 VERSION[15:8] 7 6 5 4 3 VERSION[7:0] * PR: Part Reference Reserved. No functionality associated. * VERSION: Version Number Version number of the module. No functionality associated. 557 32117A-10/2010 AT32UC3C 24.8 Module Configuration The specific configuration for each MACB instance is listed in the following tables. The module bus clocks listed here are connected to the system bus clocks. Please refer to the Power Manager chapter for details. Table 24-7. Module name Module Clock Name Clock Name Description CLK_MACB_HSB HSB clock CLK_MACB_PB Peripheral Bus clock from the PBB clock domain MACB Table 24-8. Register Reset Values Module name Clock name VERSION 0x0000101D 558 32117A-10/2010 AT32UC3C 25. Universal Synchronous Asynchronous Receiver Transmitter (USART) Rev.6.0.2.0 25.1 Features * Programmable Baud Rate Generator * 5- to 9-bit Full-duplex Synchronous or Asynchronous Serial Communications * * * * * * * 25.2 - 1, 1.5 or 2 Stop Bits in Asynchronous Mode or 1 or 2 Stop Bits in Synchronous Mode - Parity Generation and Error Detection - Framing Error Detection, Overrun Error Detection - MSB- or LSB-first - Optional Break Generation and Detection - By 8 or by 16 Over-sampling Receiver Frequency - Optional Hardware Handshaking RTS-CTS - Optional Modem Signal Management DTR-DSR-DCD-RI - Receiver Time-out and Transmitter Timeguard - Optional Multidrop Mode with Address Generation and Detection RS485 with Driver Control Signal ISO7816, T = 0 or T = 1 Protocols for Interfacing with Smart Cards - NACK Handling, Error Counter with Repetition and Iteration Limit IrDA Modulation and Demodulation - Communication at up to 115.2 Kbps SPI Mode - Master or Slave - Serial Clock Programmable Phase and Polarity - SPI Serial Clock (CLK) Frequency up to Internal Clock Frequency CLK_USART/4 LIN Mode - Compliant with LIN 1.3 and LIN 2.0 specifications - Master or Slave - Processing of frames with up to 256 data bytes - Response Data length can be configurable or defined automatically by the Identifier - Self synchronization in Slave node configuration - Automatic processing and verification of the "Synch Break" and the "Synch Field" - The "Synch Break" is detected even if it is partially superimposed with a data byte - Automatic Identifier parity calculation/sending and verification - Parity sending and verification can be disabled - Automatic Checksum calculation/sending and verification - Checksum sending and verification can be disabled - Support both "Classic" and "Enhanced" checksum types - Full LIN error checking and reporting - Frame Slot Mode: the Master allocates slots to the scheduled frames automatically. - Generation of the Wakeup signal Test Modes - Remote Loopback, Local Loopback, Automatic Echo Supports Connection of Two Peripheral DMA Controller Channels (PDCA) - Offers Buffer Transfer without Processor Intervention Overview The Universal Synchronous Asynchronous Receiver Transceiver (USART) provides one full duplex universal synchronous asynchronous serial link. Data frame format is widely programma559 32117A-10/2010 AT32UC3C ble (data length, parity, number of stop bits) to support a maximum of standards. The receiver implements parity error, framing error and overrun error detection. The receiver time-out enables handling variable-length frames and the transmitter timeguard facilitates communications with slow remote devices. Multidrop communications are also supported through address bit handling in reception and transmission. The USART features three test modes: remote loopback, local loopback and automatic echo. The USART supports specific operating modes providing interfaces on RS485, LIN and SPI buses, with ISO7816 T = 0 or T = 1 smart card slots, infrared transceivers and connection to modem ports. The hardware handshaking feature enables an out-of-band flow control by automatic management of the pins RTS and CTS. The USART supports the connection to the Peripheral DMA Controller, which enables data transfers to the transmitter and from the receiver. The Peripheral DMA Controller provides chained buffer management without any intervention of the processor. 560 32117A-10/2010 AT32UC3C 25.3 Block Diagram Figure 25-1. USART Block Diagram Peripheral DMA Controller Channel Channel I/O Controller USART RXD Receiver RTS INTC USART Interrupt TXD Transmitter CTS DTR CLK_USART Power Manager DIV DSR Modem Signals Control CLK_USART/DIV DCD RI CLK BaudRate Generator User Interface Peripheral bus Table 25-1. SPI Operating Mode PIN USART SPI Slave SPI Master RXD RXD MOSI MISO TXD TXD MISO MOSI RTS RTS - CS CTS CTS CS - 561 32117A-10/2010 AT32UC3C 25.4 I/O Lines Description Table 25-2. I/O Lines Description Name Description Type Active Level CLK Serial Clock I/O TXD Transmit Serial Data or Master Out Slave In (MOSI) in SPI Master Mode or Master In Slave Out (MISO) in SPI Slave Mode Output RXD Receive Serial Data or Master In Slave Out (MISO) in SPI Master Mode or Master Out Slave In (MOSI) in SPI Slave Mode Input RI Ring Indicator Input Low DSR Data Set Ready Input Low DCD Data Carrier Detect Input Low DTR Data Terminal Ready Output Low CTS Clear to Send or Slave Select (NSS) in SPI Slave Mode Input Low RTS Request to Send or Slave Select (NSS) in SPI Master Mode Output Low 562 32117A-10/2010 AT32UC3C 25.5 25.5.1 Product Dependencies I/O Lines The pins used for interfacing the USART may be multiplexed with the I/O Controller lines. The programmer must first program the I/O Controller to assign the desired USART pins to their peripheral function. If I/O lines of the USART are not used by the application, they can be used for other purposes by the I/O Controller. To prevent the TXD line from falling when the USART is disabled, the use of an internal pull up is mandatory. If the hardware handshaking feature or Modem mode is used, the internal pull up on TXD must also be enabled. All the pins of the modems may or may not be implemented on the USART. On USARTs not equipped with the corresponding pins, the associated control bits and statuses have no effect on the behavior of the USART. 25.5.2 Clocks The clock for the USART bus interface (CLK_USART) is generated by the Power Manager. This clock is enabled at reset, and can be disabled in the Power Manager. It is recommended to disable the USART before disabling the clock, to avoid freezing the USART in an undefined state. 25.5.3 Interrupts The USART interrupt request line is connected to the interrupt controller. Using the USART interrupt requires the interrupt controller to be programmed first. 563 32117A-10/2010 AT32UC3C 25.6 Functional Description The USART is capable of managing several types of serial synchronous or asynchronous communications. It supports the following communication modes: * 5- to 9-bit full-duplex asynchronous serial communication - MSB- or LSB-first - 1, 1.5 or 2 stop bits - Parity even, odd, marked, space or none - By 8 or by 16 over-sampling receiver frequency - Optional hardware handshaking - Optional modem signals management - Optional break management - Optional multidrop serial communication * High-speed 5- to 9-bit full-duplex synchronous serial communication - MSB- or LSB-first - 1 or 2 stop bits - Parity even, odd, marked, space or none - By 8 or by 16 over-sampling frequency - Optional hardware handshaking - Optional modem signals management - Optional break management - Optional multidrop serial communication * RS485 with driver control signal * ISO7816, T0 or T1 protocols for interfacing with smart cards - NACK handling, error counter with repetition and iteration limit, inverted data * InfraRed IrDA Modulation and Demodulation * SPI Mode - Master or Slave - Serial Clock Programmable Phase and Polarity - SPI Serial Clock (CLK) Frequency up to Internal Clock Frequency CLK_USART/4 * LIN Mode - Compliant with LIN 1.3 and LIN 2.0 specifications - Master or Slave - Processing of frames with up to 256 data bytes - Response Data length can be configurable or defined automatically by the Identifier - Self synchronization in Slave node configuration - Automatic processing and verification of the "Synch Break" and the "Synch Field" - The "Synch Break" is detected even if it is partially superimposed with a data byte - Automatic Identifier parity calculation/sending and verification - Parity sending and verification can be disabled - Automatic Checksum calculation/sending and verification - Checksum sending and verification can be disabled - Support both "Classic" and "Enhanced" checksum types 564 32117A-10/2010 AT32UC3C - Full LIN error checking and reporting - Frame Slot Mode: the Master allocates slots to the scheduled frames automatically. - Generation of the Wakeup signal * Test modes - Remote loopback, local loopback, automatic echo 25.6.1 Baud Rate Generator The Baud Rate Generator provides the bit period clock named the Baud Rate Clock to both the receiver and the transmitter. The Baud Rate Generator clock source can be selected by setting the USCLKS field in the Mode Register (MR) between: * CLK_USART * a division of CLK_USART, the divider being product dependent, but generally set to 8 * the external clock, available on the CLK pin The Baud Rate Generator is based upon a 16-bit divider, which is programmed with the CD field of the Baud Rate Generator Register (BRGR). If CD is programmed at 0, the Baud Rate Generator does not generate any clock. If CD is programmed at 1, the divider is bypassed and becomes inactive. If the external CLK clock is selected, the duration of the low and high levels of the signal provided on the CLK pin must be longer than a CLK_USART period. The frequency of the signal provided on CLK must be at least 3 times lower than CLK_USART. Figure 25-2. Baud Rate Generator USCLKS CLK_USART CLK_USART/DIV CLK Reserved CD CD 0 1 2 CLK 16-bit Counter FIDI >1 3 1 0 SYNC OVER 0 Sampling Divider 0 0 BaudRate Clock 1 1 SYNC USCLKS= 3 25.6.1.1 Sampling Clock Baud Rate in Asynchronous Mode If the USART is programmed to operate in asynchronous mode, the selected clock is first divided by CD, which is field programmed in the Baud Rate Generator Register (BRGR). The resulting clock is provided to the receiver as a sampling clock and then divided by 16 or 8, depending on the programming of the OVER bit in MR. If OVER is set to 1, the receiver sampling is 8 times higher than the baud rate clock. If OVER is cleared, the sampling is performed at 16 times the baud rate clock. 565 32117A-10/2010 AT32UC3C The following formula performs the calculation of the Baud Rate. SelectedClock Baudrate = -------------------------------------------( 8 ( 2 - Over )CD ) This gives a maximum baud rate of CLK_USART divided by 8, assuming that CLK_USART is the highest possible clock and that OVER is programmed at 1. 25.6.1.2 Baud Rate Calculation Example Table 25-3 shows calculations of CD to obtain a baud rate at 38400 bauds for different source clock frequencies. This table also shows the actual resulting baud rate and the error. Table 25-3. Baud Rate Example (OVER = 0) Source Clock Expected Baud Rate MHz Bit/s 3 686 400 38 400 6.00 6 38 400.00 0.00% 4 915 200 38 400 8.00 8 38 400.00 0.00% 5 000 000 38 400 8.14 8 39 062.50 1.70% 7 372 800 38 400 12.00 12 38 400.00 0.00% 8 000 000 38 400 13.02 13 38 461.54 0.16% 12 000 000 38 400 19.53 20 37 500.00 2.40% 12 288 000 38 400 20.00 20 38 400.00 0.00% 14 318 180 38 400 23.30 23 38 908.10 1.31% 14 745 600 38 400 24.00 24 38 400.00 0.00% 18 432 000 38 400 30.00 30 38 400.00 0.00% 24 000 000 38 400 39.06 39 38 461.54 0.16% 24 576 000 38 400 40.00 40 38 400.00 0.00% 25 000 000 38 400 40.69 40 38 109.76 0.76% 32 000 000 38 400 52.08 52 38 461.54 0.16% 32 768 000 38 400 53.33 53 38 641.51 0.63% 33 000 000 38 400 53.71 54 38 194.44 0.54% 40 000 000 38 400 65.10 65 38 461.54 0.16% 50 000 000 38 400 81.38 81 38 580.25 0.47% 60 000 000 38 400 97.66 98 38 265.31 0.35% Calculation Result CD Actual Baud Rate Error Bit/s The baud rate is calculated with the following formula: BaudRate = ( CLKUSART ) ( CD x 16 ) The baud rate error is calculated with the following formula. It is not recommended to work with an error higher than 5%. 566 32117A-10/2010 AT32UC3C ExpectedBaudRate Error = 1 - --------------------------------------------------- ActualBaudRate 25.6.1.3 Fractional Baud Rate in Asynchronous Mode The Baud Rate generator previously defined is subject to the following limitation: the output frequency changes by only integer multiples of the reference frequency. An approach to this problem is to integrate a fractional N clock generator that has a high resolution. The generator architecture is modified to obtain Baud Rate changes by a fraction of the reference source clock. This fractional part is programmed with the FP field in the Baud Rate Generator Register (BRGR). If FP is not 0, the fractional part is activated. The resolution is one eighth of the clock divider. This feature is only available when using USART normal mode. The fractional Baud Rate is calculated using the following formula: SelectedClock Baudrate = --------------------------------------------------------------- 8 ( 2 - Over ) CD + FP ------- 8 The modified architecture is presented below: Figure 25-3. Fractional Baud Rate Generator FP USCLKS CLK_USART CLK_USART/DIV CLK Reserved 0 1 2 3 CD Modulus Control FP CD 16-bit Counter glitch-free logic FIDI >1 1 0 CLK 0 OVER Sampling Divider 0 SYNC 0 BaudRate Clock 1 1 SYNC USCLKS = 3 25.6.1.4 Sampling Clock Baud Rate in Synchronous Mode or SPI Mode If the USART is programmed to operate in synchronous mode, the selected clock is simply divided by the field CD in BRGR. BaudRate = SelectedClock -------------------------------------CD 567 32117A-10/2010 AT32UC3C In synchronous mode, if the external clock is selected (USCLKS = 3), the clock is provided directly by the signal on the USART CLK pin. No division is active. The value written in BRGR has no effect. The external clock frequency must be at least 3 times lower than the system clock. In synchronous mode master (USCLKS = 0 or 1, CLK0 set to 1), the receive part limits the SCK maximum frequency to MCK/3 or MCK/6 in SPI mode. When either the external clock CLK or the internal clock divided (CLK_USART/DIV) is selected, the value programmed in CD must be even if the user has to ensure a 50:50 mark/space ratio on the CLK pin. If the internal clock CLK_USART is selected, the Baud Rate Generator ensures a 50:50 duty cycle on the CLK pin, even if the value programmed in CD is odd. 25.6.1.5 Baud Rate in ISO 7816 Mode The ISO7816 specification defines the bit rate with the following formula: Di B = ------ x f Fi where: * B is the bit rate * Di is the bit-rate adjustment factor * Fi is the clock frequency division factor * f is the ISO7816 clock frequency (Hz) Di is a binary value encoded on a 4-bit field, named DI, as represented in Table 25-4. Table 25-4. Binary and Decimal Values for Di DI field 0001 0010 0011 0100 0101 0110 1000 1001 1 2 4 8 16 32 12 20 Di (decimal) Fi is a binary value encoded on a 4-bit field, named FI, as represented in Table 25-5. Table 25-5. Binary and Decimal Values for Fi FI field 0000 0001 0010 0011 0100 0101 0110 1001 1010 1011 1100 1101 Fi (decimal 372 372 558 744 1116 1488 1860 512 768 1024 1536 2048 Table 25-6 shows the resulting Fi/Di Ratio, which is the ratio between the ISO7816 clock and the baud rate clock. Table 25-6. Possible Values for the Fi/Di Ratio Fi/Di 372 558 774 1116 1488 1806 512 768 1024 1536 2048 1 372 558 744 1116 1488 1860 512 768 1024 1536 2048 2 186 279 372 558 744 930 256 384 512 768 1024 4 93 139.5 186 279 372 465 128 192 256 384 512 8 46.5 69.75 93 139.5 186 232.5 64 96 128 192 256 16 23.25 34.87 46.5 69.75 93 116.2 32 48 64 96 128 32 11.62 17.43 23.25 34.87 46.5 58.13 16 24 32 48 64 12 31 46.5 62 93 124 155 42.66 64 85.33 128 170.6 20 18.6 27.9 37.2 55.8 74.4 93 25.6 38.4 51.2 76.8 102.4 568 32117A-10/2010 AT32UC3C If the USART is configured in ISO7816 Mode, the clock selected by the USCLKS field in the Mode Register (MR) is first divided by the value programmed in the field CD in the Baud Rate Generator Register (BRGR). The resulting clock can be provided to the CLK pin to feed the smart card clock inputs. This means that the CLKO bit can be set in MR. This clock is then divided by the value programmed in the FI_DI_RATIO field in the FI_DI_Ratio register (FIDI). This is performed by the Sampling Divider, which performs a division by up to 2047 in ISO7816 Mode. The non-integer values of the Fi/Di Ratio are not supported and the user must program the FI_DI_RATIO field to a value as close as possible to the expected value. The FI_DI_RATIO field resets to the value 0x174 (372 in decimal) and is the most common divider between the ISO7816 clock and the bit rate (Fi = 372, Di = 1). Figure 25-4 shows the relation between the Elementary Time Unit, corresponding to a bit time, and the ISO 7816 clock. Figure 25-4. Elementary Time Unit (ETU) FI_DI_RATIO ISO7816 Clock Cycles ISO7816 Clock on CLK ISO7816 I/O Line on TXD 1 ETU 25.6.2 Receiver and Transmitter Control After reset, the receiver is disabled. The user must enable the receiver by setting the RXEN bit in the Control Register (CR). However, the receiver registers can be programmed before the receiver clock is enabled. After reset, the transmitter is disabled. The user must enable it by setting the TXEN bit in the Control Register (CR). However, the transmitter registers can be programmed before being enabled. The Receiver and the Transmitter can be enabled together or independently. At any time, the software can perform a reset on the receiver or the transmitter of the USART by setting the corresponding bit, RSTRX and RSTTX respectively, in the Control Register (CR). The software resets clear the status flag and reset internal state machines but the user interface configuration registers hold the value configured prior to software reset. Regardless of what the receiver or the transmitter is performing, the communication is immediately stopped. The user can also independently disable the receiver or the transmitter by setting RXDIS and TXDIS respectively in CR. If the receiver is disabled during a character reception, the USART waits until the end of reception of the current character, then the reception is stopped. If the transmitter is disabled while it is operating, the USART waits the end of transmission of both the current character and character being stored in the Transmit Holding Register (THR). If a timeguard is programmed, it is handled normally. 569 32117A-10/2010 AT32UC3C 25.6.3 Synchronous and Asynchronous Modes 25.6.3.1 Transmitter Operations The transmitter performs the same in both synchronous and asynchronous operating modes (SYNC = 0 or SYNC = 1). One start bit, up to 9 data bits, one optional parity bit and up to two stop bits are successively shifted out on the TXD pin at each falling edge of the programmed serial clock. The number of data bits is selected by the CHRL field and the MODE 9 bit in the Mode Register (MR). Nine bits are selected by setting the MODE 9 bit regardless of the CHRL field. The parity bit is set according to the PAR field in MR. The even, odd, space, marked or none parity bit can be configured. The MSBF field in MR configures which data bit is sent first. If written at 1, the most significant bit is sent first. At 0, the less significant bit is sent first. The number of stop bits is selected by the NBSTOP field in MR. The 1.5 stop bit is supported in asynchronous mode only. Figure 25-5. Character Transmit Example: 8-bit, Parity Enabled One Stop Baud Rate Clock TXD Start Bit D0 D1 D2 D3 D4 D5 D6 D7 Parity Bit Stop Bit The characters are sent by writing in the Transmit Holding Register (THR). The transmitter reports two status bits in the Channel Status Register (CSR): TXRDY (Transmitter Ready), which indicates that THR is empty and TXEMPTY, which indicates that all the characters written in THR have been processed. When the current character processing is completed, the last character written in THR is transferred into the Shift Register of the transmitter and THR becomes empty, thus TXRDY rises. Both TXRDY and TXEMPTY bits are low when the transmitter is disabled. Writing a character in THR while TXRDY is low has no effect and the written character is lost. Figure 25-6. Transmitter Status Baud Rate Clock TXD Start D0 Bit D1 D2 D3 D4 D5 D6 D7 Parity Stop Start D0 Bit Bit Bit D1 D2 D3 D4 D5 D6 D7 Parity Stop Bit Bit Write THR TXRDY TXEMPTY 570 32117A-10/2010 AT32UC3C 25.6.3.2 Manchester Encoder When the Manchester encoder is in use, characters transmitted through the USART are encoded based on biphase Manchester II format. To enable this mode, set the MAN field in the MR register to 1. Depending on polarity configuration, a logic level (zero or one), is transmitted as a coded signal one-to-zero or zero-to-one. Thus, a transition always occurs at the midpoint of each bit time. It consumes more bandwidth than the original NRZ signal (2x) but the receiver has more error control since the expected input must show a change at the center of a bit cell. An example of Manchester encoded sequence is: the byte 0xB1 or 10110001 encodes to 10 01 10 10 01 01 01 10, assuming the default polarity of the encoder. Figure 25-7 illustrates this coding scheme. Figure 25-7. NRZ to Manchester Encoding NRZ encoded data Manchester encoded data 1 0 1 1 0 0 0 1 Txd The Manchester encoded character can also be encapsulated by adding both a configurable preamble and a start frame delimiter pattern. Depending on the configuration, the preamble is a training sequence, composed of a pre-defined pattern with a programmable length from 1 to 15 bit times. If the preamble length is set to 0, the preamble waveform is not generated prior to any character. The preamble pattern is chosen among the following sequences: ALL_ONE, ALL_ZERO, ONE_ZERO or ZERO_ONE, writing the field TX_PP in the MAN register, the field TX_PL is used to configure the preamble length. Figure 25-8 illustrates and defines the valid patterns. To improve flexibility, the encoding scheme can be configured using the TX_MPOL field in the MAN register. If the TX_MPOL field is set to zero (default), a logic zero is encoded with a zero-to-one transition and a logic one is encoded with a one-to-zero transition. If the TX_MPOL field is set to one, a logic one is encoded with a one-to-zero transition and a logic zero is encoded with a zero-to-one transition. 571 32117A-10/2010 AT32UC3C Figure 25-8. Preamble Patterns, Default Polarity Assumed Manchester encoded data Txd SFD DATA SFD DATA SFD DATA SFD DATA 8 bit width "ALL_ONE" Preamble Manchester encoded data Txd 8 bit width "ALL_ZERO" Preamble Manchester encoded data Txd 8 bit width "ZERO_ONE" Preamble Manchester encoded data Txd 8 bit width "ONE_ZERO" Preamble A start frame delimiter is to be configured using the ONEBIT field in the MR register. It consists of a user-defined pattern that indicates the beginning of a valid data. Figure 25-9 illustrates these patterns. If the start frame delimiter, also known as start bit, is one bit, (ONEBIT at 1), a logic zero is Manchester encoded and indicates that a new character is being sent serially on the line. If the start frame delimiter is a synchronization pattern also referred to as sync (ONEBIT at 0), a sequence of 3 bit times is sent serially on the line to indicate the start of a new character. The sync waveform is in itself an invalid Manchester waveform as the transition occurs at the middle of the second bit time. Two distinct sync patterns are used: the command sync and the data sync. The command sync has a logic one level for one and a half bit times, then a transition to logic zero for the second one and a half bit times. If the MODSYNC field in the MR register is set to 1, the next character is a command. If it is set to 0, the next character is a data. When direct memory access is used, the MODSYNC field can be immediately updated with a modified character located in memory. To enable this mode, VAR_SYNC field in MR register must be set to 1. In this case, the MODSYNC field in MR is bypassed and the sync configuration is held in the TXSYNH in the THR register. The USART character format is modified and includes sync information. 572 32117A-10/2010 AT32UC3C Figure 25-9. Start Frame Delimiter Preamble Length is set to 0 SFD Manchester encoded data DATA Txd One bit start frame delimiter SFD Manchester encoded data DATA Txd Command Sync start frame delimiter SFD Manchester encoded data DATA Txd Data Sync start frame delimiter Drift Compensation Drift compensation is available only in 16X oversampling mode. An hardware recovery system allows a larger clock drift. To enable the hardware system, the bit in the MAN register must be set. If the RXD edge is one 16X clock cycle from the expected edge, this is considered as normal jitter and no corrective actions is taken. If the RXD event is between 4 and 2 clock cycles before the expected edge, then the current period is shortened by one clock cycle. If the RXD event is between 2 and 3 clock cycles after the expected edge, then the current period is lengthened by one clock cycle. These intervals are considered to be drift and so corrective actions are automatically taken. Figure 25-10. Bit Resynchronization Oversampling 16x Clock RXD Sampling point Expected edge Synchro. Error 25.6.3.3 Synchro. Jump Tolerance Sync Jump Synchro. Error Asynchronous Receiver If the USART is programmed in asynchronous operating mode (SYNC = 0), the receiver oversamples the RXD input line. The oversampling is either 16 or 8 times the Baud Rate clock, depending on the OVER bit in the Mode Register (MR). 573 32117A-10/2010 AT32UC3C The receiver samples the RXD line. If the line is sampled during one half of a bit time at 0, a start bit is detected and data, parity and stop bits are successively sampled on the bit rate clock. If the oversampling is 16, (OVER at 0), a start is detected at the eighth sample at 0. Then, data bits, parity bit and stop bit are sampled on each 16 sampling clock cycle. If the oversampling is 8 (OVER at 1), a start bit is detected at the fourth sample at 0. Then, data bits, parity bit and stop bit are sampled on each 8 sampling clock cycle. The number of data bits, first bit sent and parity mode are selected by the same fields and bits as the transmitter, i.e. respectively CHRL, MODE9, MSBF and PAR. For the synchronization mechanism only, the number of stop bits has no effect on the receiver as it considers only one stop bit, regardless of the field NBSTOP, so that resynchronization between the receiver and the transmitter can occur. Moreover, as soon as the stop bit is sampled, the receiver starts looking for a new start bit so that resynchronization can also be accomplished when the transmitter is operating with one stop bit. Figure 25-11 and Figure 25-12 illustrate start detection and character reception when USART operates in asynchronous mode. Figure 25-11. Asynchronous Start Detection Baud Rate Clock Sampling Clock (x16) RXD Sampling 1 2 3 4 5 6 7 8 1 2 3 4 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 D0 Sampling Start Detection RXD Sampling 1 2 3 4 5 6 7 0 1 Start Rejection Figure 25-12. Asynchronous Character Reception Example: 8-bit, Parity Enabled Baud Rate Clock RXD Start Detection 16 16 16 16 16 16 16 16 16 16 samples samples samples samples samples samples samples samples samples samples D0 D1 D2 D3 D4 D5 D6 D7 Parity Bit Stop Bit 574 32117A-10/2010 AT32UC3C 25.6.3.4 Manchester Decoder When the MAN field in MR register is set to 1, the Manchester decoder is enabled. The decoder performs both preamble and start frame delimiter detection. One input line is dedicated to Manchester encoded input data. An optional preamble sequence can be defined, its length is user-defined and totally independent of the emitter side. Use RX_PL in MAN register to configure the length of the preamble sequence. If the length is set to 0, no preamble is detected and the function is disabled. In addition, the polarity of the input stream is programmable with RX_MPOL field in MAN register. Depending on the desired application the preamble pattern matching is to be defined via the RX_PP field in MAN. See Figure 25-8 for available preamble patterns. Unlike preamble, the start frame delimiter is shared between Manchester Encoder and Decoder. So, if ONEBIT field is set to 1, only a zero encoded Manchester can be detected as a valid start frame delimiter. If ONEBIT is set to 0, only a sync pattern is detected as a valid start frame delimiter. Decoder operates by detecting transition on incoming stream. If RXD is sampled during one quarter of a bit time at zero, a start bit is detected. See Figure 25-13. The sample pulse rejection mechanism applies. Figure 25-13. Asynchronous Start Bit Detection Sampling Clock (16 x) Manchester encoded data Txd Start Detection 1 2 3 4 The receiver is activated and starts Preamble and Frame Delimiter detection, sampling the data at one quarter and then three quarters. If a valid preamble pattern or start frame delimiter is detected, the receiver continues decoding with the same synchronization. If the stream does not match a valid pattern or a valid start frame delimiter, the receiver re-synchronizes on the next valid edge.The minimum time threshold to estimate the bit value is three quarters of a bit time. If a valid preamble (if used) followed with a valid start frame delimiter is detected, the incoming stream is decoded into NRZ data and passed to USART for processing. Figure 25-14 illustrates Manchester pattern mismatch. When incoming data stream is passed to the USART, the receiver is also able to detect Manchester code violation. A code violation is a lack of transition in the middle of a bit cell. In this case, MANE flag in CSR register is raised. It is cleared by writing the Control Register (CR) with the RSTSTA bit at 1. See Figure 25-15 for an example of Manchester error detection during data phase. 575 32117A-10/2010 AT32UC3C Figure 25-14. Preamble Pattern Mismatch Preamble Mismatch Manchester coding error Manchester encoded data Preamble Mismatch invalid pattern SFD Txd DATA Preamble Length is set to 8 Figure 25-15. Manchester Error Flag Preamble Length is set to 4 Elementary character bit time SFD Manchester encoded data Txd Entering USART character area sampling points Preamble subpacket and Start Frame Delimiter were successfully decoded Manchester Coding Error detected When the start frame delimiter is a sync pattern (ONEBIT field at 0), both command and data delimiter are supported. If a valid sync is detected, the received character is written as RXCHR field in the RHR register and the RXSYNH is updated. RXCHR is set to 1 when the received character is a command, and it is set to 0 if the received character is a data. This mechanism alleviates and simplifies the direct memory access as the character contains its own sync field in the same register. As the decoder is setup to be used in unipolar mode, the first bit of the frame has to be a zero-toone transition. 25.6.3.5 Radio Interface: Manchester Encoded USART Application This section describes low data rate RF transmission systems and their integration with a Manchester encoded USART. These systems are based on transmitter and receiver ICs that support ASK and FSK modulation schemes. The goal is to perform full duplex radio transmission of characters using two different frequency carriers. See the configuration in Figure 25-16. 576 32117A-10/2010 AT32UC3C Figure 25-16. Manchester Encoded Characters RF Transmission Fup frequency Carrier ASK/FSK Upstream Receiver Upstream Emitter LNA VCO RF filter Demod Serial Configuration Interface control Fdown frequency Carrier bi-dir line Manchester decoder USART Receiver Manchester encoder USART Emitter ASK/FSK downstream transmitter Downstream Receiver PA RF filter Mod VCO control The USART module is configured as a Manchester encoder/decoder. Looking at the downstream communication channel, Manchester encoded characters are serially sent to the RF emitter. This may also include a user defined preamble and a start frame delimiter. Mostly, preamble is used in the RF receiver to distinguish between a valid data from a transmitter and signals due to noise. The Manchester stream is then modulated. See Figure 25-17 for an example of ASK modulation scheme. When a logic one is sent to the ASK modulator, the power amplifier, referred to as PA, is enabled and transmits an RF signal at downstream frequency. When a logic zero is transmitted, the RF signal is turned off. If the FSK modulator is activated, two different frequencies are used to transmit data. When a logic 1 is sent, the modulator outputs an RF signal at frequency F0 and switches to F1 if the data sent is a 0. See Figure 25-18. From the receiver side, another carrier frequency is used. The RF receiver performs a bit check operation examining demodulated data stream. If a valid pattern is detected, the receiver switches to receiving mode. The demodulated stream is sent to the Manchester decoder. Because of bit checking inside RF IC, the data transferred to the microcontroller is reduced by a user-defined number of bits. The Manchester preamble length is to be defined in accordance with the RF IC configuration. Figure 25-17. ASK Modulator Output 1 0 0 1 NRZ stream Manchester encoded data default polarity unipolar output Txd ASK Modulator Output Uptstream Frequency F0 577 32117A-10/2010 AT32UC3C Figure 25-18. FSK Modulator Output 1 0 0 1 NRZ stream Manchester encoded data default polarity unipolar output Txd FSK Modulator Output Uptstream Frequencies [F0, F0+offset] 25.6.3.6 Synchronous Receiver In synchronous mode (SYNC = 1), the receiver samples the RXD signal on each rising edge of the Baud Rate Clock. If a low level is detected, it is considered as a start. All data bits, the parity bit and the stop bits are sampled and the receiver waits for the next start bit. Synchronous mode operations provide a high speed transfer capability. Configuration fields and bits are the same as in asynchronous mode. Figure 25-19 illustrates a character reception in synchronous mode. Figure 25-19. Synchronous Mode Character Reception Example: 8-bit, Parity Enabled 1 Stop Baud Rate Clock RXD Sampling Start D0 D1 D2 D3 D4 D5 D6 Stop Bit D7 Parity Bit 25.6.3.7 Receiver Operations When a character reception is completed, it is transferred to the Receive Holding Register (RHR) and the RXRDY bit in the Status Register (CSR) rises. If a character is completed while the RXRDY is set, the OVRE (Overrun Error) bit is set. The last character is transferred into RHR and overwrites the previous one. The OVRE bit is cleared by writing the Control Register (CR) with the RSTSTA (Reset Status) bit at 1. 578 32117A-10/2010 AT32UC3C Figure 25-20. Receiver Status Baud Rate Clock RXD Start D0 Bit D1 D2 D3 D4 D5 D6 D7 Parity Stop Start D0 Bit Bit Bit D1 D2 D3 D4 D5 D6 D7 Parity Stop Bit Bit RSTSTA = 1 Write CR Read RHR RXRDY OVRE 579 32117A-10/2010 AT32UC3C 25.6.3.8 Parity The USART supports five parity modes selected by programming the PAR field in the Mode Register (MR). The PAR field also enables the Multidrop mode, see "Multidrop Mode" on page 581. Even and odd parity bit generation and error detection are supported. If even parity is selected, the parity generator of the transmitter drives the parity bit at 0 if a number of 1s in the character data bit is even, and at 1 if the number of 1s is odd. Accordingly, the receiver parity checker counts the number of received 1s and reports a parity error if the sampled parity bit does not correspond. If odd parity is selected, the parity generator of the transmitter drives the parity bit at 1 if a number of 1s in the character data bit is even, and at 0 if the number of 1s is odd. Accordingly, the receiver parity checker counts the number of received 1s and reports a parity error if the sampled parity bit does not correspond. If the mark parity is used, the parity generator of the transmitter drives the parity bit at 1 for all characters. The receiver parity checker reports an error if the parity bit is sampled at 0. If the space parity is used, the parity generator of the transmitter drives the parity bit at 0 for all characters. The receiver parity checker reports an error if the parity bit is sampled at 1. If parity is disabled, the transmitter does not generate any parity bit and the receiver does not report any parity error. Table 25-7 shows an example of the parity bit for the character 0x41 (character ASCII "A") depending on the configuration of the USART. Because there are two bits at 1, 1 bit is added when a parity is odd, or 0 is added when a parity is even. Table 25-7. Parity Bit Examples Character Hexa Binary Parity Bit Parity Mode A 0x41 0100 0001 1 Odd A 0x41 0100 0001 0 Even A 0x41 0100 0001 1 Mark A 0x41 0100 0001 0 Space A 0x41 0100 0001 None None When the receiver detects a parity error, it sets the PARE (Parity Error) bit in the Channel Status Register (CSR). The PARE bit can be cleared by writing the Control Register (CR) with the RSTSTA bit at 1. Figure 25-21 illustrates the parity bit status setting and clearing. 580 32117A-10/2010 AT32UC3C Figure 25-21. Parity Error Baud Rate Clock RXD Start D0 Bit D1 D2 D3 D4 D5 D6 D7 Bad Stop Parity Bit Bit RSTSTA = 1 Write CR PARE RXRDY 25.6.3.9 Multidrop Mode If the PAR field in the Mode Register (MR) is programmed to the value 0x6 or 0x07, the USART runs in Multidrop Mode. This mode differentiates the data characters and the address characters. Data is transmitted with the parity bit at 0 and addresses are transmitted with the parity bit at 1. If the USART is configured in multidrop mode, the receiver sets the PARE parity error bit when the parity bit is high and the transmitter is able to send a character with the parity bit high when the Control Register is written with the SENDA bit at 1. To handle parity error, the PARE bit is cleared when the Control Register is written with the bit RSTSTA at 1. The transmitter sends an address byte (parity bit set) when SENDA is written to CR. In this case, the next byte written to THR is transmitted as an address. Any character written in THR without having written the command SENDA is transmitted normally with the parity at 0. 25.6.3.10 Transmitter Timeguard The timeguard feature enables the USART interface with slow remote devices. The timeguard function enables the transmitter to insert an idle state on the TXD line between two characters. This idle state actually acts as a long stop bit. The duration of the idle state is programmed in the TG field of the Transmitter Timeguard Register (TTGR). When this field is programmed at zero no timeguard is generated. Otherwise, the transmitter holds a high level on TXD after each transmitted byte during the number of bit periods programmed in TG in addition to the number of stop bits. As illustrated in Figure 25-22, the behavior of TXRDY and TXEMPTY status bits is modified by the programming of a timeguard. TXRDY rises only when the start bit of the next character is sent, and thus remains at 0 during the timeguard transmission if a character has been written in THR. TXEMPTY remains low until the timeguard transmission is completed as the timeguard is part of the current character being transmitted. 581 32117A-10/2010 AT32UC3C Figure 25-22. Timeguard Operations TG = 4 TG = 4 Baud Rate Clock TXD Start D0 Bit D1 D2 D3 D4 D5 D6 D7 Parity Stop Bit Bit Start D0 Bit D1 D2 D3 D4 D5 D6 D7 Parity Stop Bit Bit Write THR TXRDY TXEMPTY Table 25-8 indicates the maximum length of a timeguard period that the transmitter can handle in relation to the function of the Baud Rate. Table 25-8. 25.6.3.11 Maximum Timeguard Length Depending on Baud Rate Baud Rate Bit time Timeguard Bit/sec s ms 1 200 833 212.50 9 600 104 26.56 14400 69.4 17.71 19200 52.1 13.28 28800 34.7 8.85 33400 29.9 7.63 56000 17.9 4.55 57600 17.4 4.43 115200 8.7 2.21 Receiver Time-out The Receiver Time-out provides support in handling variable-length frames. This feature detects an idle condition on the RXD line. When a time-out is detected, the bit TIMEOUT in the Channel Status Register (CSR) rises and can generate an interrupt, thus indicating to the driver an end of frame. The time-out delay period (during which the receiver waits for a new character) is programmed in the TO field of the Receiver Time-out Register (RTOR). If the TO field is programmed at 0, the Receiver Time-out is disabled and no time-out is detected. The TIMEOUT bit in CSR remains at 0. Otherwise, the receiver loads a counter with the value programmed in TO. This counter is decremented at each bit period and reloaded each time a new character is received. If the counter reaches 0, the TIMEOUT bit in the Status Register rises. Then, the user can either: * Stop the counter clock until a new character is received. This is performed by writing the Control Register (CR) with the STTTO (Start Time-out) bit at 1. In this case, the idle state on RXD before a new character is received will not provide a time-out. This prevents having to 582 32117A-10/2010 AT32UC3C handle an interrupt before a character is received and allows waiting for the next idle state on RXD after a frame is received. * Obtain an interrupt while no character is received. This is performed by writing CR with the RETTO (Reload and Start Time-out) bit at 1. If RETTO is performed, the counter starts counting down immediately from the value TO. This enables generation of a periodic interrupt so that a user time-out can be handled, for example when no key is pressed on a keyboard. If STTTO is performed, the counter clock is stopped until a first character is received. The idle state on RXD before the start of the frame does not provide a time-out. This prevents having to obtain a periodic interrupt and enables a wait of the end of frame when the idle state on RXD is detected. If RETTO is performed, the counter starts counting down immediately from the value TO. This enables generation of a periodic interrupt so that a user time-out can be handled, for example when no key is pressed on a keyboard. Figure 25-23 shows the block diagram of the Receiver Time-out feature. Figure 25-23. Receiver Time-out Block Diagram TO Baud Rate Clock 1 D Q Clock 16-bit Time-out Counter 16-bit Value = STTTO Character Received Load Clear TIMEOUT 0 RETTO Table 25-9 gives the maximum time-out period for some standard baud rates. Table 25-9. Maximum Time-out Period Baud Rate Bit Time Time-out bit/sec s ms 600 1 667 109 225 1 200 833 54 613 2 400 417 27 306 4 800 208 13 653 9 600 104 6 827 14400 69 4 551 19200 52 3 413 28800 35 2 276 33400 30 1 962 583 32117A-10/2010 AT32UC3C Table 25-9. 25.6.3.12 Maximum Time-out Period (Continued) Baud Rate Bit Time Time-out 56000 18 1 170 57600 17 1 138 200000 5 328 Framing Error The receiver is capable of detecting framing errors. A framing error happens when the stop bit of a received character is detected at level 0. This can occur if the receiver and the transmitter are fully desynchronized. A framing error is reported on the FRAME bit of the Channel Status Register (CSR). The FRAME bit is asserted in the middle of the stop bit as soon as the framing error is detected. It is cleared by writing the Control Register (CR) with the RSTSTA bit at 1. Figure 25-24. Framing Error Status Baud Rate Clock RXD Start D0 Bit D1 D2 D3 D4 D5 D6 D7 Parity Stop Bit Bit RSTSTA = 1 Write CR FRAME RXRDY 25.6.3.13 Transmit Break The user can request the transmitter to generate a break condition on the TXD line. A break condition drives the TXD line low during at least one complete character. It appears the same as a 0x00 character sent with the parity and the stop bits at 0. However, the transmitter holds the TXD line at least during one character until the user requests the break condition to be removed. A break is transmitted by writing the Control Register (CR) with the STTBRK bit at 1. This can be performed at any time, either while the transmitter is empty (no character in either the Shift Register or in THR) or when a character is being transmitted. If a break is requested while a character is being shifted out, the character is first completed before the TXD line is held low. Once STTBRK command is requested further STTBRK commands are ignored until the end of the break is completed. The break condition is removed by writing CR with the STPBRK bit at 1. If the STPBRK is requested before the end of the minimum break duration (one character, including start, data, parity and stop bits), the transmitter ensures that the break condition completes. 584 32117A-10/2010 AT32UC3C The transmitter considers the break as though it is a character, i.e. the STTBRK and STPBRK commands are taken into account only if the TXRDY bit in CSR is at 1 and the start of the break condition clears the TXRDY and TXEMPTY bits as if a character is processed. Writing CR with the both STTBRK and STPBRK bits at 1 can lead to an unpredictable result. All STPBRK commands requested without a previous STTBRK command are ignored. A byte written into the Transmit Holding Register while a break is pending, but not started, is ignored. After the break condition, the transmitter returns the TXD line to 1 for a minimum of 12 bit times. Thus, the transmitter ensures that the remote receiver detects correctly the end of break and the start of the next character. If the timeguard is programmed with a value higher than 12, the TXD line is held high for the timeguard period. After holding the TXD line for this period, the transmitter resumes normal operations. Figure 25-25 illustrates the effect of both the Start Break (STTBRK) and Stop Break (STPBRK) commands on the TXD line. Figure 25-25. Break Transmission Baud Rate Clock TXD Start D0 Bit D1 D2 D3 D4 D5 STTBRK = 1 D6 D7 Parity Stop Bit Bit Break Transmission End of Break STPBRK = 1 Write CR TXRDY TXEMPTY 25.6.3.14 Receive Break The receiver detects a break condition when all data, parity and stop bits are low. This corresponds to detecting a framing error with data at 0x00, but FRAME remains low. When the low stop bit is detected, the receiver asserts the RXBRK bit in CSR. This bit may be cleared by writing the Control Register (CR) with the bit RSTSTA at 1. An end of receive break is detected by a high level for at least 2/16 of a bit period in asynchronous operating mode or one sample at high level in synchronous operating mode. The end of break detection also asserts the RXBRK bit. 25.6.3.15 Hardware Handshaking The USART features a hardware handshaking out-of-band flow control. The RTS and CTS pins are used to connect with the remote device, as shown in Figure 25-26. 585 32117A-10/2010 AT32UC3C Figure 25-26. Connection with a Remote Device for Hardware Handshaking USART Remote Device TXD RXD RXD TXD CTS RTS RTS CTS Setting the USART to operate with hardware handshaking is performed by writing the MODE field in the Mode Register (MR) to the value 0x2. The USART behavior when hardware handshaking is enabled is the same as the behavior in standard synchronous or asynchronous mode, except that the receiver drives the RTS pin as described below and the level on the CTS pin modifies the behavior of the transmitter as described below. Using this mode requires using the Peripheral DMA Controller channel for reception. The transmitter can handle hardware handshaking in any case. Figure 25-27 shows how the receiver operates if hardware handshaking is enabled. The RTS pin is driven high if the receiver is disabled and if the status RXBUFF (Receive Buffer Full) coming from the Peripheral DMA Controller channel is high. Normally, the remote device does not start transmitting while its CTS pin (driven by RTS) is high. As soon as the Receiver is enabled, the RTS falls, indicating to the remote device that it can start transmitting. Defining a new buffer to the Peripheral DMA Controller clears the status bit RXBUFF and, as a result, asserts the pin RTS low. Figure 25-27. Receiver Behavior when Operating with Hardware Handshaking RXD RXEN = 1 RXDIS = 1 Write CR RTS RXBUFF Figure 25-28 shows how the transmitter operates if hardware handshaking is enabled. The CTS pin disables the transmitter. If a character is being processing, the transmitter is disabled only after the completion of the current character and transmission of the next character happens as soon as the pin CTS falls. Figure 25-28. Transmitter Behavior when Operating with Hardware Handshaking CTS TXD 586 32117A-10/2010 AT32UC3C 25.6.4 ISO7816 Mode The USART features an ISO7816-compatible operating mode. This mode permits interfacing with smart cards and Security Access Modules (SAM) communicating through an ISO7816 link. Both T = 0 and T = 1 protocols defined by the ISO7816 specification are supported. Setting the USART in ISO7816 mode is performed by writing the MODE field in the Mode Register (MR) to the value 0x4 for protocol T = 0 and to the value 0x6 for protocol T = 1. 25.6.4.1 ISO7816 Mode Overview The ISO7816 is a half duplex communication on only one bidirectional line. The baud rate is determined by a division of the clock provided to the remote device (see "Baud Rate Generator" on page 565). The USART connects to a smart card as shown in Figure 25-29. The TXD line becomes bidirectional and the Baud Rate Generator feeds the ISO7816 clock on the CLK pin. As the TXD pin becomes bidirectional, its output remains driven by the output of the transmitter but only when the transmitter is active while its input is directed to the input of the receiver. The USART is considered as the master of the communication as it generates the clock. Figure 25-29. Connection of a Smart Card to the USART USART CLK TXD CLK I/O Smart Card When operating in ISO7816, either in T = 0 or T = 1 modes, the character format is fixed. The configuration is 8 data bits, even parity and 1 or 2 stop bits, regardless of the values programmed in the CHRL, MODE9, PAR and CHMODE fields. MSBF can be used to transmit LSB or MSB first. Parity Bit (PAR) can be used to transmit in normal or inverse mode. Refer to "Mode Register" on page 625 and "PAR: Parity Type" on page 627. The USART cannot operate concurrently in both receiver and transmitter modes as the communication is unidirectional at a time. It has to be configured according to the required mode by enabling or disabling either the receiver or the transmitter as desired. Enabling both the receiver and the transmitter at the same time in ISO7816 mode may lead to unpredictable results. The ISO7816 specification defines an inverse transmission format. Data bits of the character must be transmitted on the I/O line at their negative value. The USART does not support this format and the user has to perform an exclusive OR on the data before writing it in the Transmit Holding Register (THR) or after reading it in the Receive Holding Register (RHR). 25.6.4.2 Protocol T = 0 In T = 0 protocol, a character is made up of one start bit, eight data bits, one parity bit and one guard time, which lasts two bit times. The transmitter shifts out the bits and does not drive the I/O line during the guard time. If no parity error is detected, the I/O line remains at 1 during the guard time and the transmitter can continue with the transmission of the next character, as shown in Figure 25-30. 587 32117A-10/2010 AT32UC3C If a parity error is detected by the receiver, it drives the I/O line at 0 during the guard time, as shown in Figure 25-31. This error bit is also named NACK, for Non Acknowledge. In this case, the character lasts 1 bit time more, as the guard time length is the same and is added to the error bit time which lasts 1 bit time. When the USART is the receiver and it detects an error, it does not load the erroneous character in the Receive Holding Register (RHR). It appropriately sets the PARE bit in the Status Register (SR) so that the software can handle the error. Figure 25-30. T = 0 Protocol without Parity Error Baud Rate Clock RXD Start Bit D0 D2 D1 D4 D3 D5 D6 D7 Parity Guard Guard Next Bit Time 1 Time 2 Start Bit Figure 25-31. T = 0 Protocol with Parity Error Baud Rate Clock Error I/O Start Bit D0 D1 D2 D3 D4 D5 D6 D7 Parity Guard Bit Time 1 Guard Start Time 2 Bit D0 D1 Repetition 25.6.4.3 Receive Error Counter The USART receiver also records the total number of errors. This can be read in the Number of Error (NER) register. The NB_ERRORS field can record up to 255 errors. Reading NER automatically clears the NB_ERRORS field. 25.6.4.4 Receive NACK Inhibit The USART can also be configured to inhibit an error. This can be achieved by setting the INACK bit in the Mode Register (MR). If INACK is at 1, no error signal is driven on the I/O line even if a parity bit is detected. Moreover, if INACK is set, the erroneous received character is stored in the Receive Holding Register, as if no error occurred. However, the RXRDY bit does raise. 25.6.4.5 Transmit Character Repetition When the USART is transmitting a character and gets a NACK, it can automatically repeat the character before moving on to the next one. Repetition is enabled by writing the MAX_ITERATION field in the Mode Register (MR) at a value higher than 0. Each character can be transmitted up to eight times; the first transmission plus seven repetitions. If MAX_ITERATION does not equal zero, the USART repeats the character as many times as the value loaded in MAX_ITERATION. When the USART repetition number reaches MAX_ITERATION, the ITERATION bit is set in the Channel Status Register (CSR). If the repetition of the character is acknowledged by the receiver, the repetitions are stopped and the iteration counter is cleared. 588 32117A-10/2010 AT32UC3C The ITERATION bit in CSR can be cleared by writing the Control Register with the RSIT bit at 1. 25.6.4.6 Disable Successive Receive NACK The receiver can limit the number of successive NACKs sent back to the remote transmitter. This is programmed by setting the bit DSNACK in the Mode Register (MR). The maximum number of NACK transmitted is programmed in the MAX_ITERATION field. As soon as MAX_ITERATION is reached, the character is considered as correct, an acknowledge is sent on the line and the ITERATION bit in the Channel Status Register is set. 25.6.4.7 Protocol T = 1 When operating in ISO7816 protocol T = 1, the transmission is similar to an asynchronous format with only one stop bit. The parity is generated when transmitting and checked when receiving. Parity error detection sets the PARE bit in the Channel Status Register (CSR). 25.6.5 IrDA Mode The USART features an IrDA mode supplying half-duplex point-to-point wireless communication. It embeds the modulator and demodulator which allows a glueless connection to the infrared transceivers, as shown in Figure 25-32. The modulator and demodulator are compliant with the IrDA specification version 1.1 and support data transfer speeds ranging from 2.4 Kb/s to 115.2 Kb/s. The USART IrDA mode is enabled by setting the MODE field in the Mode Register (MR) to the value 0x8. The IrDA Filter Register (IFR) allows configuring the demodulator filter. The USART transmitter and receiver operate in a normal asynchronous mode and all parameters are accessible (except those fixed by IrDA specification : one start bit , 8 data bits and one stop bit). Note that the modulator and the demodulator are activated. Figure 25-32. Connection to IrDA Transceivers USART IrDA Transceivers Receiver Demodulator RXD Transmitter Modulator TXD RX TX The receiver and the transmitter must be enabled or disabled according to the direction of the transmission to be managed. To receive IrDA signals, the following needs to be done: * Disable TX and Enable RX * Configure the TXD pin as I/O and set it as an output at 0 (to avoid LED emission). Disable the internal pull-up (better for power consumption). * Receive data 589 32117A-10/2010 AT32UC3C 25.6.5.1 IrDA Modulation For baud rates up to and including 115.2 Kbits/sec, the RZI modulation scheme is used. "0" is represented by a light pulse of 3/16th of a bit time. Some examples of signal pulse duration are shown in Table 25-10. Table 25-10. IrDA Pulse Duration Baud Rate Pulse Duration (3/16) 2.4 Kb/s 78.13 s 9.6 Kb/s 19.53 s 19.2 Kb/s 9.77 s 38.4 Kb/s 4.88 s 57.6 Kb/s 3.26 s 115.2 Kb/s 1.63 s Figure 25-33 shows an example of character transmission. Figure 25-33. IrDA Modulation Start Bit Transmitter Output 0 Stop Bit Data Bits 1 0 1 0 0 1 1 0 1 TXD 3 16 Bit Period Bit Period 25.6.5.2 IrDA Baud Rate Table 25-11 gives some examples of CD values, baud rate error and pulse duration. Note that the requirement on the maximum acceptable error of 1.87% must be met. Table 25-11. IrDA Baud Rate Error Peripheral Clock Baud Rate CD Baud Rate Error Pulse Time 3 686 400 115 200 2 0.00% 1.63 20 000 000 115 200 11 1.38% 1.63 32 768 000 115 200 18 1.25% 1.63 40 000 000 115 200 22 1.38% 1.63 3 686 400 57 600 4 0.00% 3.26 20 000 000 57 600 22 1.38% 3.26 32 768 000 57 600 36 1.25% 3.26 40 000 000 57 600 43 0.93% 3.26 3 686 400 38 400 6 0.00% 4.88 20 000 000 38 400 33 1.38% 4.88 590 32117A-10/2010 AT32UC3C Table 25-11. IrDA Baud Rate Error (Continued) Peripheral Clock 25.6.5.3 Baud Rate CD Baud Rate Error Pulse Time 32 768 000 38 400 53 0.63% 4.88 40 000 000 38 400 65 0.16% 4.88 3 686 400 19 200 12 0.00% 9.77 20 000 000 19 200 65 0.16% 9.77 32 768 000 19 200 107 0.31% 9.77 40 000 000 19 200 130 0.16% 9.77 3 686 400 9 600 24 0.00% 19.53 20 000 000 9 600 130 0.16% 19.53 32 768 000 9 600 213 0.16% 19.53 40 000 000 9 600 260 0.16% 19.53 3 686 400 2 400 96 0.00% 78.13 20 000 000 2 400 521 0.03% 78.13 32 768 000 2 400 853 0.04% 78.13 IrDA Demodulator The demodulator is based on the IrDA Receive filter comprised of an 8-bit down counter which is loaded with the value programmed in IFR. When a falling edge is detected on the RXD pin, the Filter Counter starts counting down at the CLK_USART speed. If a rising edge is detected on the RXD pin, the counter stops and is reloaded with IFR. If no rising edge is detected when the counter reaches 0, the input of the receiver is driven low during one bit time. Figure 25-34 illustrates the operations of the IrDA demodulator. Figure 25-34. IrDA Demodulator Operations CLK_USART RXD Counter Value Receiver Input 6 5 4 3 2 6 6 5 4 3 2 1 0 Pulse Accepted Pulse Rejected Driven Low During 16 Baud Rate Clock Cycles As the IrDA mode uses the same logic as the ISO7816, note that the FI_DI_RATIO field in FIDI must be set to a value higher than 0 in order to assure IrDA communications operate correctly. 591 32117A-10/2010 AT32UC3C 25.6.6 RS485 Mode The USART features the RS485 mode to enable line driver control. While operating in RS485 mode, the USART behaves as though in asynchronous or synchronous mode and configuration of all the parameters is possible. The difference is that the RTS pin is driven high when the transmitter is operating. The behavior of the RTS pin is controlled by the TXEMPTY bit. A typical connection of the USART to a RS485 bus is shown in Figure 25-35. Figure 25-35. Typical Connection to a RS485 Bus USART RXD Differential Bus TXD RTS The USART is set in RS485 mode by programming the MODE field in the Mode Register (MR) to the value 0x1. The RTS pin is at a level inverse to the TXEMPTY bit. Significantly, the RTS pin remains high when a timeguard is programmed so that the line can remain driven after the last character completion. Figure 25-36 gives an example of the RTS waveform during a character transmission when the timeguard is enabled. Figure 25-36. Example of RTS Drive with Timeguard TG = 4 Baud Rate Clock TXD Start D0 Bit D1 D2 D3 D4 D5 D6 D7 Parity Stop Bit Bit Write THR TXRDY TXEMPTY RTS 592 32117A-10/2010 AT32UC3C 25.6.7 Modem Mode The USART features modem mode, which enables control of the signals: DTR (Data Terminal Ready), DSR (Data Set Ready), RTS (Request to Send), CTS (Clear to Send), DCD (Data Carrier Detect) and RI (Ring Indicator). While operating in modem mode, the USART behaves as a DTE (Data Terminal Equipment) as it drives DTR and RTS and can detect level change on DSR, DCD, CTS and RI. Setting the USART in modem mode is performed by writing the MODE field in the Mode Register (MR) to the value 0x3. While operating in modem mode the USART behaves as though in asynchronous mode and all the parameter configurations are available. Table 25-12 gives the correspondence of the USART signals with modem connection standards. Table 25-12. Circuit References USART Pin V24 CCITT Direction TXD 2 103 From terminal to modem RTS 4 105 From terminal to modem DTR 20 108.2 From terminal to modem RXD 3 104 From modem to terminal CTS 5 106 From terminal to modem DSR 6 107 From terminal to modem DCD 8 109 From terminal to modem RI 22 125 From terminal to modem The control of the DTR output pin is performed by writing the Control Register (CR) with the DTRDIS and DTREN bits respectively at 1. The disable command forces the corresponding pin to its inactive level, i.e. high. The enable command forces the corresponding pin to its active level, i.e. low. RTS output pin is automatically controlled in this mode The level changes are detected on the RI, DSR, DCD and CTS pins. If an input change is detected, the RIIC, DSRIC, DCDIC and CTSIC bits in the Channel Status Register (CSR) are set respectively and can trigger an interrupt. The status is automatically cleared when CSR is read. Furthermore, the CTS automatically disables the transmitter when it is detected at its inactive state. If a character is being transmitted when the CTS rises, the character transmission is completed before the transmitter is actually disabled. 593 32117A-10/2010 AT32UC3C 25.6.8 SPI Mode The Serial Peripheral Interface (SPI) Mode is a synchronous serial data link that provides communication with external devices in Master or Slave Mode. It also enables communication between processors if an external processor is connected to the system. The Serial Peripheral Interface is essentially a shift register that serially transmits data bits to other SPIs. During a data transfer, one SPI system acts as the "master" which controls the data flow, while the other devices act as "slaves'' which have data shifted into and out by the master. Different CPUs can take turns being masters and one master may simultaneously shift data into multiple slaves. (Multiple Master Protocol is the opposite of Single Master Protocol, where one CPU is always the master while all of the others are always slaves.) However, only one slave may drive its output to write data back to the master at any given time. A slave device is selected when its NSS signal is asserted by the master. The USART in SPI Master mode can address only one SPI Slave because it can generate only one NSS signal. The SPI system consists of two data lines and two control lines: * Master Out Slave In (MOSI): This data line supplies the output data from the master shifted into the input of the slave. * Master In Slave Out (MISO): This data line supplies the output data from a slave to the input of the master. * Serial Clock (CLK): This control line is driven by the master and regulates the flow of the data bits. The master may transmit data at a variety of baud rates. The CLK line cycles once for each bit that is transmitted. * Slave Select (NSS): This control line allows the master to select or deselect the slave. 25.6.8.1 Modes of Operation The USART can operate in Master Mode or in Slave Mode. Operation in SPI Master Mode is programmed by writing at 0xE the MODE field in the Mode Register. In this case the SPI lines must be connected as described below: * the MOSI line is driven by the output pin TXD * the MISO line drives the input pin RXD * the CLK line is driven by the output pin CLK * the NSS line is driven by the output pin RTS Operation in SPI Slave Mode is programmed by writing at 0xF the MODE field in the Mode Register. In this case the SPI lines must be connected as described below: * the MOSI line drives the input pin RXD * the MISO line is driven by the output pin TXD * the CLK line drives the input pin CLK * the NSS line drives the input pin CTS In order to avoid unpredicted behavior, any change of the SPI Mode must be followed by a software reset of the transmitter and of the receiver (except the initial configuration after a hardware reset). 25.6.8.2 Baud Rate In SPI Mode, the baudrate generator operates in the same way as in USART synchronous mode: See Section "25.6.1.4" on page 567. However, there are some restrictions: 594 32117A-10/2010 AT32UC3C In SPI Master Mode: * the external clock CLK must not be selected (USCLKS ... 0x3), and the bit CLKO must be set to "1" in the Mode Register (MR), in order to generate correctly the serial clock on the CLK pin. * to obtain correct behavior of the receiver and the transmitter, the value programmed in CD of must be superior or equal to 4. * if the internal clock divided (CLK_USART/DIV) is selected, the value programmed in CD must be even to ensure a 50:50 mark/space ratio on the CLK pin, this value can be odd if the internal clock is selected (CLK_USART). In SPI Slave Mode: * the external clock (CLK) selection is forced regardless of the value of the USCLKS field in the Mode Register (MR). Likewise, the value written in BRGR has no effect, because the clock is provided directly by the signal on the USART CLK pin. * to obtain correct behavior of the receiver and the transmitter, the external clock (CLK) frequency must be at least 4 times lower than the system clock. 595 32117A-10/2010 AT32UC3C 25.6.8.3 Data Transfer Up to 9 data bits are successively shifted out on the TXD pin at each rising or falling edge (depending of CPOL and CPHA) of the programmed serial clock. There is no Start bit, no Parity bit and no Stop bit. The number of data bits is selected by the CHRL field and the MODE 9 bit in the Mode Register (MR). The 9 bits are selected by setting the MODE 9 bit regardless of the CHRL field. The MSB data bit is always sent first in SPI Mode (Master or Slave). Four combinations of polarity and phase are available for data transfers. The clock polarity is programmed with the CPOL bit in the Mode Register. The clock phase is programmed with the CPHA bit. These two parameters determine the edges of the clock signal upon which data is driven and sampled. Each of the two parameters has two possible states, resulting in four possible combinations that are incompatible with one another. Thus, a master/slave pair must use the same parameter pair values to communicate. If multiple slaves are used and fixed in different configurations, the master must reconfigure itself each time it needs to communicate with a different slave. Table 25-13. SPI Bus Protocol Mode SPI Bus Protocol Mode CPOL CPHA 0 0 1 1 0 0 2 1 1 3 1 0 596 32117A-10/2010 AT32UC3C Figure 25-37. SPI Transfer Format (CPHA=1, 8 bits per transfer) CLK cycle (for reference) 2 1 4 3 5 7 6 8 CLK (CPOL= 0) CLK (CPOL= 1) MOSI SPI Master ->TXD SPI Slave ->RXD MISO SPI Master ->RXD SPI Slave ->TXD MSB MSB 6 5 4 3 2 1 LSB 6 5 4 3 2 1 LSB NSS SPI Master ->RTS SPI Slave ->CTS Figure 25-38. SPI Transfer Format (CPHA=0, 8 bits per transfer) CLK cycle (for reference) 1 2 3 4 5 6 7 8 CLK (CPOL= 0) CLK (CPOL= 1) MOSI SPI Master -> TXD SPI Slave -> RXD MSB 6 5 4 3 2 1 LSB MISO SPI Master -> RXD SPI Slave -> TXD MSB 6 5 4 3 2 1 LSB NSS SPI Master -> RTS SPI Slave -> CTS 597 32117A-10/2010 AT32UC3C 25.6.8.4 Receiver and Transmitter Control See Section "25.6.2" on page 569. 25.6.8.5 Character Transmission The characters are sent by writing in the Transmit Holding Register (THR). An additional condition for transmitting a character can be added when the USART is configured in SPI master mode. In the MR register, the value configured on INACK field can prevent any character transmission (even if THR has been written) while the receiver side is not ready (character not read). When INACK equals 0, the character is transmitted whatever the receiver status. If INACK is set to 1, the transmitter waits for the receiver holding register to be read before transmitting the character (RXRDY flag cleared), thus preventing any overflow (character loss) on the receiver side. The transmitter reports two status bits in the Channel Status Register (CSR): TXRDY (Transmitter Ready), which indicates that THR is empty and TXEMPTY, which indicates that all the characters written in THR have been processed. When the current character processing is completed, the last character written in THR is transferred into the Shift Register of the transmitter and THR becomes empty, thus TXRDY rises. Both TXRDY and TXEMPTY bits are low when the transmitter is disabled. Writing a character in THR while TXRDY is low has no effect and the written character is lost. If the USART is in SPI Slave Mode and if a character must be sent while the Transmit Holding Register (THR) is empty, the UNRE (Underrun Error) bit is set. The TXD transmission line stays at high level during all this time. The UNRE bit is cleared by writing the Control Register (CR) with the RSTSTA (Reset Status) bit at 1. In SPI Master Mode, the slave select line (NSS) is asserted at low level 1 Tbit before the transmission of the MSB bit and released at high level 1 Tbit after the transmission of the LSB bit. So, the slave select line (NSS) is always released between each character transmission and a minimum delay of 3 Tbits always inserted. However, in order to address slave devices supporting the CSAAT mode (Chip Select Active After Transfer), the slave select line (NSS) can be forced at low level by writing the Control Register (CR) with the RTSEN bit at 1. The slave select line (NSS) can be released at high level only by writing the Control Register (CR) with the RTSDIS bit at 1 (for example, when all data have been transferred to the slave device). In SPI Slave Mode, the transmitter does not require a falling edge of the slave select line (NSS) to initiate a character transmission but only a low level. However, this low level must be present on the slave select line (NSS) at least 1 Tbit before the first serial clock cycle corresponding to the MSB bit. 25.6.8.6 Character Reception When a character reception is completed, it is transferred to the Receive Holding Register (RHR) and the RXRDY bit in the Status Register (CSR) rises. If a character is completed while RXRDY is set, the OVRE (Overrun Error) bit is set. The last character is transferred into RHR and overwrites the previous one. The OVRE bit is cleared by writing the Control Register (CR) with the RSTSTA (Reset Status) bit at 1. To ensure correct behavior of the receiver in SPI Slave Mode, the master device sending the frame must ensure a minimum delay of 1 Tbit between each character transmission. The receiver does not require a falling edge of the slave select line (NSS) to initiate a character reception but only a low level. However, this low level must be present on the slave select line (NSS) at least 1 Tbit before the first serial clock cycle corresponding to the MSB bit. 598 32117A-10/2010 AT32UC3C 25.6.8.7 Receiver Timeout Because the receiver baudrate clock is active only during data transfers in SPI Mode, a receiver timeout is impossible in this mode, whatever the Time-out value is (field TO) in the Time-out Register (RTOR). 599 32117A-10/2010 AT32UC3C 25.6.9 LIN Mode The LIN Mode provides Master node and Slave node connectivity on a LIN bus. The LIN (Local Interconnect Network) is a serial communication protocol which efficiently supports the control of mechatronic nodes in distributed automotive applications. The main properties of the LIN bus are: * Single Master/Multiple Slaves concept * Low cost silicon implementation based on common UART/SCI interface hardware, an equivalent in software, or as a pure state machine. * Self synchronization without quartz or ceramic resonator in the slave nodes * Deterministic signal transmission * Low cost single-wire implementation * Speed up to 20 kbit/s LIN provides cost efficient bus communication where the bandwidth and versatility of CAN are not required. The LIN Mode enables processing LIN frames with a minimum of action from the microprocessor. 25.6.9.1 Modes of operation The USART can act either as a LIN Master node or as a LIN Slave node. The node configuration is chosen by setting the MODE field in the Mode Register (MR): * LIN Master Node (MODE=0xA) * LIN Slave Node (MODE=0xB) In order to avoid unpredicted behavior, any change of the LIN node configuration must be followed by a software reset of the transmitter and of the receiver (except the initial node configuration after a hardware reset). (See Section 25.6.9.3) 25.6.9.2 Baud Rate Configuration See Section "25.6.1.1" on page 565. * LIN Master Node: the baud rate is configured in the Baud Rate Generator Register (BRGR). * LIN Slave Node: the initial baud rate is configured in BRGR, this configuration is automatically copied in the LIN Baud Rate Register (LINBRR) when writing BRGR. After synchronization procedure, the baud rate is updated in LINBRR. 25.6.9.3 Receiver and Transmitter Control See Section "25.6.2" on page 569. 25.6.9.4 Character Transmission See Section "25.6.3.1" on page 570. 25.6.9.5 Character Reception See Section "25.6.3.7" on page 578. 600 32117A-10/2010 AT32UC3C 25.6.9.6 Header Transmission (Master Node Configuration) All the LIN Frames start with a header which is sent by the master node and consists of a Synch Break Field, Synch Field and Identifier Field. So in Master node configuration, the frame handling starts with the sending of the header. The header is transmitted as soon as the identifier is written in the LIN Identifier register (LINIR). At this moment the flag TXRDY falls. The Break Field, the Synch Field and the Identifier Field are sent automatically one after the other. The Break Field consists of 13 dominant bits and 1 recessive bit, the Synch Field is the character 0x55 and the Identifier corresponds to the character written in the LIN Identifier Register (LINIR). The Identifier parity bits can be automatically computed and sent (see Section 25.6.9.9). The flag TXRDY rises when the identifier character is transferred into the Shift Register of the transmitter. Figure 25-39. Header Transmission Baud Rate Clock TXD Break Field 13 dominant bits (at 0) Write LINIR LINIR Break Delimiter 1 recessive bit (at 1) Start 1 Bit 0 1 0 1 0 Synch Byte = 0x55 1 0 Stop Start Stop ID0 ID1 ID2 ID3 ID4 ID5 ID6 ID7 Bit Bit Bit ID TXRDY 601 32117A-10/2010 AT32UC3C 25.6.9.7 Header Reception (Slave Node Configuration) All the LIN Frames start with a header which is sent by the master node and consists of a Synch Break Field, Synch Field and Identifier Field. In Slave node configuration, the frame handling starts with the reception of the header. The USART uses a break detection threshold of 11 nominal bit times at the actual baud rate. At any time, if 11 consecutive recessive bits are detected on the bus, the USART detects a Break Field. As long as a Break Field has not been detected, the USART stays idle and the received data are not taken in account. When a Break Field has been detected, the USART expects the Synch Field character to be 0x55. This field is used to update the actual baud rate in order to stay synchronized (see Section 25.6.9.8). If the received Synch character is not 0x55, an Inconsistent Synch Field error is generated (see Section 25.6.10). After receiving the Synch Field, the USART expects to receive the Identifier Field. When the Identifier has been received, the flag LINID is set to "1". At this moment the field IDCHR in the LIN Identifier register (LINIR) is updated with the received character. The Identifier parity bits can be automatically computed and checked (see Section 25.6.9.9). If the header is not entirely received within the time given by the maximum length of the header THeader_Maximum, the error bit LINHTE in the Channel Status register (CSR) is set to 1. The bits LINID, LINBK and LINHTE are reset by writing the bit RSTSTA to 1 in the Control register (CR). Figure 25-40. Header Reception Baud Rate Clock RXD Break Field 13 dominant bits (at 0) LINID Break Delimiter 1 recessive bit (at 1) Start 1 Bit 0 1 0 1 0 1 0 Synch Byte = 0x55 Stop Start Stop ID0 ID1 ID2 ID3 ID4 ID5 ID6 ID7 Bit Bit Bit US_LINIR Write US_CR With RSTSTA=1 25.6.9.8 Slave Node Synchronization The synchronization is done only in Slave node configuration. The procedure is based on time measurement between falling edges of the Synch Field. The falling edges are available in distances of 2, 4, 6 and 8 bit times. Figure 25-41. Synch Field Synch Field 8 Tbit 2 Tbit Start bit 2 Tbit 2 Tbit 2 Tbit Stop bit 602 32117A-10/2010 AT32UC3C The time measurement is made by a 19-bit counter clocked by the sampling clock (see Section 25.6.1). When the start bit of the Synch Field is detected the counter is reset. Then during the next 8 Tbits of the Synch Field, the counter is incremented. At the end of these 8 Tbits, the counter is stopped. At this moment, the 16 most significant bits of the counter (value divided by 8) gives the new clock divider (LINCD) and the 3 least significant bits of this value (the remainder) gives the new fractional part (LINFP). Once the Synch Field has been entirely received, the clock divider (LINCD) and the fractional part (LINFP) are updated in the LIN Baud Rate register (LINBRR) with the computed values, if the synchronization is not disabled by the bit SYNCDIS in the LIN Mode register (LINMR). If after reception of the Synch Field, it appears that the computed baudrate deviation compared to the initial baud rate is superior to the maximum tolerance FToI_Unsynch (+/- 15%) then the clock divider (LINCD) and the fractional part (LINFP) are not updated and the error bit STE in the Channel Status register CSR is set to 1. If after reception of the Synch Field, it appears that the sampled Synch character is not equal to 0x55 then the clock divider (LINCD) and the fractional part (LINFP) are not updated, and the error bit ISFE in the Channel Status register (CSR) is set to 1. The bits LINSTE and LINISFE are reset by writing the bit RSTSTA at 1 in the Control register (CR). Figure 25-42. Slave Node Synchronization Baud Rate Clock RXD Break Field 13 dominant bits (at 0) Break Delimiter 1 recessive bit (at 1) Start 1 Bit 0 1 0 1 0 Synch Byte = 0x55 1 0 Stop Start Stop ID0 ID1 ID2 ID3 ID4 ID5 ID6 ID7 Bit Bit Bit LINIDRX Reset Synchro Counter 000_0011_0001_0110_1101 BRGR Clcok Divider (CD) Initial CD 0000_0110_0010_1101 BRGR Fractional Part (FP) Initial FP 101 The accuracy of the synchronization depends on several parameters: * The nominal clock frequency (FNom) (the theoretical slave node clock frequency) * The Baudrate * The oversampling (Over=0 => 16X or Over=0 => 8X) The following formula is used to compute the deviation of the slave bit rate relative to the master bit rate after synchronization (FSLAVE is the real slave node clock frequency). [ x 8 x ( 2 - Over ) + ] x Baudrate Baudrate_deviation = 100 x --------------------------------------------------------------------------------------------- % 8 x F SLAVE 603 32117A-10/2010 AT32UC3C [ x 8 x ( 2 - Over ) + ] x Baudrate -------------------------------------------------------------------------------------------Baudrate_deviation = 100 x % F TOL_UNSYNCH -------------------------------------8x xF Nom 100 - 0.5 +0.5 -1 < < +1 FTOL_UNSYNCH is the deviation of the real slave node clock from the nominal clock frequency. The LIN Standard imposes that it must not exceed 15%. The LIN Standard imposes also that for communication between two nodes, their bit rate must not differ by more than 2%. This means that the Baudrate_deviation must not exceed 1%. It follows from that, a minimum value for the nominal clock frequency: [----------------------------------------------------------------------------------------------0.5 x 8 x ( 2 - Over ) + 1 ] x Baudrate- F NOM ( min ) = 100 x Hz - 15 -------- x 1% 8 x + 1 100 Examples: * Baudrate = 20 kbit/s, Over=0 (Oversampling 16X) => FNom(min) = 2.64 MHz * Baudrate = 20 kbit/s, Over=1 (Oversampling 8X) => FNom(min) = 1.47 MHz * Baudrate = 1 kbit/s, Over=0 (Oversampling 16X) => FNom(min) = 132 kHz * Baudrate = 1 kbit/s, Over=1 (Oversampling 8X) => FNom(min) = 74 kHz If the fractional baud rate is not used, the accuracy of the synchronization becomes much lower. When the counter is stopped, the 16 most significant bits of the counter (value divided by 8) gives the new clock divider (CD). This value is rounded by adding the first insignificant bit. The equation of the Baudrate deviation is the same as given above, but the constants are as follows: - 4 +4 -1 < < +1 It follows from that, a minimum value for the nominal clock frequency: [-----------------------------------------------------------------------------------------4 x 8 x ( 2 - Over ) + 1 ] x Baudrate- F (min) = 100 x Hz NOM - 15- + 1 x 1% --------8 x 100 Examples: * Baudrate = 20 kbit/s, Over=0 (Oversampling 16X) => FNom(min) = 19.12 MHz * Baudrate = 20 kbit/s, Over=1 (Oversampling 8X) => FNom(min) = 9.71 MHz * Baudrate = 1 kbit/s, Over=0 (Oversampling 16X) => FNom(min) = 956 kHz * Baudrate = 1 kbit/s, Over=1 (Oversampling 8X) => FNom(min) = 485 kHz 25.6.9.9 Identifier Parity A protected identifier consists of two sub-fields; the identifier and the identifier parity. Bits 0 to 5 are assigned to the identifier and bits 6 and 7 are assigned to the parity. The USART interface can generate/check these parity bits, but this feature can also be disabled. The user can choose between two modes by the PARDIS bit of the LIN Mode register (LINMR): 604 32117A-10/2010 AT32UC3C * PARDIS = 0: During header transmission, the parity bits are computed and sent with the 6 least significant bits of the IDCHR field of the LIN Identifier register (LINIR). The bits 6 and 7 of this register are discarded. During header reception, the parity bits of the identifier are checked. If the parity bits are wrong, an Identifier Parity error occurs (see Section 25.6.3.8). Only the 6 least significant bits of the IDCHR field are updated with the received Identifier. The bits 6 and 7 are stuck at 0. * PARDIS = 1: During header transmission, all the bits of the IDCHR field of the LIN Identifier register (LINIR) are sent on the bus. During header reception, all the bits of the IDCHR field are updated with the received Identifier. 25.6.9.10 Node Action In function of the identifier, the node is concerned, or not, by the LIN response. Consequently, after sending or receiving the identifier, the USART must be configured. There are three possible configurations: * PUBLISH: the node sends the response. * SUBSCRIBE: the node receives the response. * IGNORE: the node is not concerned by the response, it does not send and does not receive the response. This configuration is made by the field, Node Action (NACT), in the LINMR register (see Section 25.7.16). Example: a LIN cluster that contains a Master and two Slaves: * Data transfer from the Master to the Slave 1 and to the Slave 2: NACT(Master)=PUBLISH NACT(Slave1)=SUBSCRIBE NACT(Slave2)=SUBSCRIBE * Data transfer from the Master to the Slave 1 only: NACT(Master)=PUBLISH NACT(Slave1)=SUBSCRIBE NACT(Slave2)=IGNORE * Data transfer from the Slave 1 to the Master: NACT(Master)=SUBSCRIBE NACT(Slave1)=PUBLISH NACT(Slave2)=IGNORE * Data transfer from the Slave1 to the Slave2: NACT(Master)=IGNORE NACT(Slave1)=PUBLISH NACT(Slave2)=SUBSCRIBE 605 32117A-10/2010 AT32UC3C * Data transfer from the Slave2 to the Master and to the Slave1: NACT(Master)=SUBSCRIBE NACT(Slave1)=SUBSCRIBE NACT(Slave2)=PUBLISH 606 32117A-10/2010 AT32UC3C 25.6.9.11 Response Data Length The LIN response data length is the number of data fields (bytes) of the response excluding the checksum. The response data length can either be configured by the user or be defined automatically by bits 4 and 5 of the Identifier (compatibility to LIN Specification 1.1). The user can choose between these two modes by the DLM bit of the LIN Mode register (LINMR): * DLM = 0: the response data length is configured by the user via the DLC field of the LIN Mode register (LINMR). The response data length is equal to (DLC + 1) bytes. DLC can be programmed from 0 to 255, so the response can contain from 1 data byte up to 256 data bytes. * DLM = 1: the response data length is defined by the Identifier (IDCHR in LINIR) according to the table below. The DLC field of the LIN Mode register (LINMR) is discarded. The response can contain 2 or 4 or 8 data bytes. Table 25-14. Response Data Length if DLM = 1 IDCHR[5] IDCHR[4] Response Data Length [bytes] 0 0 2 0 1 2 1 0 4 1 1 8 Figure 25-43. Response Data Length User configuration: 1 - 256 data fields (DLC+1) Identifier configuration: 2/4/8 data fields Sync Break Sync Field Identifier Field Data Field Data Field Data Field Data Field Checksum Field 607 32117A-10/2010 AT32UC3C 25.6.9.12 Checksum The last field of a frame is the checksum. The checksum contains the inverted 8- bit sum with carry, over all data bytes or all data bytes and the protected identifier. Checksum calculation over the data bytes only is called classic checksum and it is used for communication with LIN 1.3 slaves. Checksum calculation over the data bytes and the protected identifier byte is called enhanced checksum and it is used for communication with LIN 2.0 slaves. The USART can be configured to: * Send/Check an Enhanced checksum automatically (CHKDIS = 0 & CHKTYP = 0) * Send/Check a Classic checksum automatically (CHKDIS = 0 & CHKTYP = 1) * Not send/check a checksum (CHKDIS = 1) This configuration is made by the Checksum Type (CHKTYP) and Checksum Disable (CHKDIS) fields of the LIN Mode register (LINMR). If the checksum feature is disabled, the user can send it manually all the same, by considering the checksum as a normal data byte and by adding 1 to the response data length (see Section 25.6.9.11). 608 32117A-10/2010 AT32UC3C 25.6.9.13 Frame Slot Mode This mode is useful only for Master nodes. It respects the following rule: each frame slot shall be longer than or equal to TFrame_Maximum. If the Frame Slot Mode is enabled (FSDIS = 0) and a frame transfer has been completed, the TXRDY flag is set again only after TFrame_Maximum delay, from the start of frame. So the Master node cannot send a new header if the frame slot duration of the previous frame is inferior to TFrame_Maximum. If the Frame Slot Mode is disabled (FSDIS = 1) and a frame transfer has been completed, the TXRDY flag is set again immediately. The TFrame_Maximum is calculated as below: If the Checksum is sent (CHKDIS = 0): * THeader_Nominal = 34 x TBit * TResponse_Nominal = 10 x (NData + 1) x TBit * TFrame_Maximum = 1.4 x (THeader_Nominal + TResponse_Nominal + 1)(Note:) * TFrame_Maximum = 1.4 x (34 + 10 x (DLC + 1 + 1) + 1) x TBIT * TFrame_Maximum = (77 + 14 x DLC) x TBIT If the Checksum is not sent (CHKDIS = 1): * THeader_Nominal = 34 x TBit * TResponse_Nominal = 10 x NData x TBit * TFrame_Maximum = 1.4 x (THeader_Nominal + TResponse_Nominal + 1(Note:)) * TFrame_Maximum = 1.4 x (34 + 10 x (DLC + 1) + 1) x TBIT * TFrame_Maximum = (63 + 14 x DLC) x TBIT Note: The term "+1" leads to an integer result for TFrame_Max (LIN Specification 1.3) Figure 25-44. Frame Slot Mode Frame slot = TFrame_Maximum Frame Header Break Synch Data3 Interframe space Response space Protected Identifier Response Data 1 Data N-1 Data N Checksum TXRDY Frame Slot Mode Frame Slot Mode Disabled Enabled Write LINID Write THR Data 1 Data 2 Data 3 Data N LINTC 609 32117A-10/2010 AT32UC3C 25.6.10 LIN Errors 25.6.10.1 Bit Error This error is generated in Master of Slave node configuration when USART is transmitting and if the transmitted value on the Tx line is different from the value sampled on the Rx line. If a bit error is detected, the transmission is aborted at the next byte border. This error is reported by the bit LINBE ins the Channel Status register (CSR). 25.6.10.2 Inconsistent Synch Field Error This error is generated in Slave node configuration if the Synch Field character received is other than 0x55. This error is reported by bit LINISFE in CSR register. 25.6.10.3 Identifier Parity Error This error is generated in Slave node configuration if the parity of the identifier is wrong. This error can be generated only if the parity feature is enabled (PARDIS = 0). This error is reported by bit LINIPE in CSR register. 25.6.10.4 Checksum Error This error is generated in Master of Slave node configuration if the received checksum is wrong. Error bit is set to 1 only if the checksum feature is enabled (CHKDIS = 0). This error is reported by bit LINCE in CSR register. 25.6.10.5 Slave Not Responding Error This error is generated in Master of Slave node configurationt when the USART expects a response from another node (NACT = SUBSCRIBE) but no valid message appears on the bus within the time frame given by the maximum length of the message frame, TFrame_Maximum (see Section 25.6.9.13). This error is disabled if the USART does not expect any message (NACT = PUBLISH or NACT = IGNORE). This error is reported by bit LINSNRE in CSR register. 25.6.10.6 Synch Tolerance Error This error is generated in Slave node configuration if after the clock synchronization procedure it appears that the computed baudrate deviation compared to the initial baudrate is superior to the maximum tolerance FToI_Unsynch (+/- 15%). This error is reported by bit LINSTE in CSR register. 25.6.10.7 Header Timeout Error This error is generated in Slave node configuration if the Header is not entirely received within the time given by the maximum length of the Header, THeader_Maximum. This error is reported by bit LINHTE in CSR register. 610 32117A-10/2010 AT32UC3C 25.6.11 LIN Frame Handling 25.6.11.1 Master Node Configuration * Write TXEN and RXEN in CR to enable both the transmitter and the receiver. * Write MODE in MR to select the LIN mode and the Master Node configuration. * Write CD and FP in BRGR to configure the baud rate. * Write NACT, PARDIS, CHKDIS, CHKTYPE, DLCM, FSDIS and DLC in LINMR to configure the frame transfer. * Check that TXRDY in CSR is set to "1" * Write IDCHR in LINIR to send the header What comes next depends on the NACT configuration: * Case 1: NACT = PUBLISH, the USART sends the response - Wait until TXRDY in CSR rises - Write TCHR in THR to send a byte - If all the data have not been written, redo the two previous steps - Wait until LINTC in CSR rises - Check the LIN errors * Case 2: NACT = SUBSCRIBE, the USART receives the response - Wait until RXRDY in CSR rises - Read RCHR in RHR - If all the data have not been read, redo the two previous steps - Wait until LINTC in CSR rises - Check the LIN errors * Case 3: NACT = IGNORE, the USART is not concerned by the response - Wait until LINTC in CSR rises - Check the LIN errors 611 32117A-10/2010 AT32UC3C Figure 25-45. Master Node Configuration, NACT = PUBLISH Frame slot = TFrame_Maximum Frame Header Break Synch Data3 Interframe space Response space Protected Identifier Response Data 1 Data N-1 Data N Checksum TXRDY FSDIS=1 FSDIS=0 RXRDY Write LINIR Write THR Data 1 Data 2 Data 3 Data N LINTC Figure 25-46. Master Node Configuration, NACT=SUBSCRIBE Frame slot = TFrame_Maximum Frame Header Break Synch Data3 Interframe space Response space Protected Identifier Response Data 1 Data N-1 Data N Checksum TXRDY FSDIS=1 FSDIS=0 RXRDY Write LINIR Read RHR Data 1 Data N-2 Data N-1 Data N LINTC 612 32117A-10/2010 AT32UC3C Figure 25-47. Master Node Configuration, NACT=IGNORE Frame slot = TFrame_Maximum Frame Break Response space Header Data3 Synch Protected Identifier Interframe space Response Data 1 Data N-1 Data N Checksum TXRDY FSDIS=1 FSDIS=0 RXRDY Write LINIR LINTC 25.6.11.2 Slave Node Configuration * Write TXEN and RXEN in CR to enable both the transmitter and the receiver. * Write MODE in MR to select the LIN mode and the Slave Node configuration. * Write CD and FP in BRGR to configure the baud rate. * Wait until LINID in CSR rises * Check LINISFE and LINPE errors * Read IDCHR in RHR * Write NACT, PARDIS, CHKDIS, CHKTYPE, DLCM and DLC in LINMR to configure the frame transfer. IMPORTANT: if the NACT configuration for this frame is PUBLISH, the US_LINMR register, must be write with NACT=PUBLISH even if this field is already correctly configured, that in order to set the TXREADY flag and the corresponding Peripheral DMA Controller write transfer request. What comes next depends on the NACT configuration: * Case 1: NACT = PUBLISH, the USART sends the response - Wait until TXRDY in CSR rises - Write TCHR in THR to send a byte - If all the data have not been written, redo the two previous steps - Wait until LINTC in CSR rises - Check the LIN errors * Case 2: NACT = SUBSCRIBE, the USART receives the response - Wait until RXRDY in CSR rises - Read RCHR in RHR - If all the data have not been read, redo the two previous steps - Wait until LINTC in CSR rises - Check the LIN errors 613 32117A-10/2010 AT32UC3C * Case 3: NACT = IGNORE, the USART is not concerned by the response - Wait until LINTC in CSR rises - Check the LIN errors Figure 25-48. Slave Node Configuration, NACT = PUBLISH Break Synch Protected Identifier Data 1 Data N-1 Data N Checksum Data N Checksum TXRDY RXRDY LINIDRX Read LINID Write THR Data 1 Data 2 Data 3 Data N LINTC Figure 25-49. Slave Node Configuration, NACT = SUBSCRIBE Break Synch Protected Identifier Data 1 Data N-1 TXRDY RXRDY LINIDRX Read LINID Read RHR Data 1 Data N-2 Data N-1 Data N LINTC Figure 25-50. Slave Node Configuration, NACT = IGNORE Break Synch Protected Identifier Data 1 Data N-1 Data N Checksum TXRDY RXRDY LINIDRX Read LINID Read RHR LINTC 614 32117A-10/2010 AT32UC3C 25.6.12 LIN Frame Handling With The Peripheral DMA Controller The USART can be used in association with the Peripheral DMA Controller in order to transfer data directly into/from the on- and off-chip memories without any processor intervention. The Peripheral DMA Controller uses the trigger flags, TXRDY and RXRDY, to write or read into the USART. The Peripheral DMA Controller always writes in the Transmit Holding register (THR) and it always reads in the Receive Holding register (RHR). The size of the data written or read by the Peripheral DMA Controller in the USART is always a byte. 25.6.12.1 Master Node Configuration The user can choose between two Peripheral DMA Controller modes by the PDCM bit in the LIN Mode register (LINMR): * PDCM = 1: the LIN configuration is stored in the WRITE buffer and it is written by the Peripheral DMA Controller in the Transmit Holding register THR (instead of the LIN Mode register LINMR). Because the Peripheral DMA Controller transfer size is limited to a byte, the transfer is split into two accesses. During the first access the bits, NACT, PARDIS, CHKDIS, CHKTYP, DLM and FSDIS are written. During the second access the 8-bit DLC field is written. * PDCM = 0: the LIN configuration is not stored in the WRITE buffer and it must be written by the user in the LIN Mode register (LINMR). The WRITE buffer also contains the Identifier and the DATA, if the USART sends the response (NACT = PUBLISH). The READ buffer contains the DATA if the USART receives the response (NACT = SUBSCRIBE). Figure 25-51. Master Node with Peripheral DMA Controller (PDCM=1) WRITE BUFFER WRITE BUFFER NACT PARDIS CHKDIS CHKTYP DLM FSDIS NACT PARDIS CHKDIS CHKTYP DLM FSDIS DLC DLC Peripheral bus NODE ACTION = PUBLISH Peripheral bus IDENTIFIER IDENTIFIER USART LIN CONTROLLER Peripheral DMA Controller DATA 0 | | | | DATA N READ BUFFER Peripheral DMA Controller RXRDY NODE ACTION = SUBSCRIBE USART LIN CONTROLLER RXRDY DATA 0 TXRDY | | | | DATA N 615 32117A-10/2010 AT32UC3C Figure 25-52. Master Node with Peripheral DMA Controller (PDCM=0) WRITE BUFFER DATA 0 Peripheral bus DATA 1 NODE ACTION = SUBSCRIBE Peripheral bus READ BUFFER Peripheral DMA Controller | | | | NODE ACTION = PUBLISH USART LIN CONTROLLER DATA 0 RXRDY Peripheral DMA Controller RXRDY USART LIN CONTROLLER TXRDY | | | | DATA N DATA N 25.6.12.2 Slave Node Configuration In this configuration, the Peripheral DMA Controller transfers only the DATA. The Identifier must be read by the user in the LIN Identifier register (LINIR). The LIN mode must be written by the user in the LIN Mode register (LINMR). The WRITE buffer contains the DATA if the USART sends the response (NACT=PUBLISH). The READ buffer contains the DATA if the USART receives the response (NACT=SUBSCRIBE). IMPORTANT: if the NACT configuration for a frame is PUBLISH, the US_LINMR register, must be write with NACT=PUBLISH even if this field is already correctly configured, that in order to set the TXREADY flag and the corresponding Peripheral DMA Controller write transfer request. Figure 25-53. Slave Node with Peripheral DMA Controller WRITE BUFFER READ BUFFER DATA 0 | | | | DATA N DATA 0 Peripheral bus Peripheral Bus USART LIN CONTROLLER Peripheral DMA Controller TXRDY | | | | Peripheral DMA Controller NACT = SUBSCRIBE USART LIN CONTROLLER RXRDY DATA N 616 32117A-10/2010 AT32UC3C 25.6.13 Wake-up Request Any node in a sleeping LIN cluster may request a wake-up. In the LIN 2.0 specification, the wakeup request is issued by forcing the bus to the dominant state from 250 s to 5 ms. For this, it is necessary to send the character 0xF0 in order to impose 5 successive dominant bits. Whatever the baud rate is, this character respects the specified timings. * Baud rate min = 1 kbit/s -> Tbit = 1ms -> 5 Tbits = 5 ms * Baud rate max = 20 kbit/s -> Tbi t= 50 s -> 5 Tbits = 250 s In the LIN 1.3 specification, the wakeup request should be generated with the character 0x80 in order to impose 8 successive dominant bits. The user can choose by the WKUPTYP bit in the LIN Mode register (LINMR) either to send a LIN 2.0 wakeup request (WKUPTYP=0) or to send a LIN 1.3 wakeup request (WKUPTYP=1). A wake-up request is transmitted by writing the Control Register (CR) with the LINWKUP bit at 1. Once the transfer is completed, the LINTC flag is asserted in the Status Register (SR). It is cleared by writing the Control Register (CR) with the RSTSTA bit at 1. 617 32117A-10/2010 AT32UC3C 25.6.14 Bus Idle Time-out If the LIN bus is inactive for a certain duration, the slave nodes shall automatically enter in sleep mode. In the LIN 2.0 specification, this time-out is fixed at 4 seconds. In the LIN 1.3 specification, it is fixed at 25000 Tbits. In Slave Node configuration, the Receiver Time-out detects an idle condition on the RXD line. When a time-out is detected, the bit TIMEOUT in the Channel Status Register (CSR) rises and can generate an interrupt, thus indicating to the driver to go into sleep mode. The time-out delay period (during which the receiver waits for a new character) is programmed in the TO field of the Receiver Time-out Register (RTOR). If the TO field is programmed at 0, the Receiver Time-out is disabled and no time-out is detected. The TIMEOUT bit in CSR remains at 0. Otherwise, the receiver loads a 17-bit counter with the value programmed in TO. This counter is decremented at each bit period and reloaded each time a new character is received. If the counter reaches 0, the TIMEOUT bit in the Status Register rises. If STTTO is performed, the counter clock is stopped until a first character is received. If RETTO is performed, the counter starts counting down immediately from the value TO. Table 25-15. Receiver Time-out programming LIN Specification 2.0 1.3 Baud Rate Time-out period TO 1 000 bit/s 4 000 2 400 bit/s 9 600 9 600 bit/s 4s 38 400 19 200 bit/s 76 800 20 000 bit/s 80 000 - 25 000 Tbits 25 000 618 32117A-10/2010 AT32UC3C 25.6.15 Test Modes The USART can be programmed to operate in three different test modes. The internal loopback capability allows on-board diagnostics. In the loopback mode the USART interface pins are disconnected or not and reconfigured for loopback internally or externally. 25.6.15.1 Normal Mode Normal mode connects the RXD pin on the receiver input and the transmitter output on the TXD pin. Figure 25-54. Normal Mode Configuration RXD Receiver TXD Transmitter 25.6.15.2 Automatic Echo Mode Automatic echo mode allows bit-by-bit retransmission. When a bit is received on the RXD pin, it is sent to the TXD pin, as shown in Figure 25-55. Programming the transmitter has no effect on the TXD pin. The RXD pin is still connected to the receiver input, thus the receiver remains active. Figure 25-55. Automatic Echo Mode Configuration RXD Receiver TXD Transmitter 25.6.15.3 Local Loopback Mode Local loopback mode connects the output of the transmitter directly to the input of the receiver, as shown in Figure 25-56. The TXD and RXD pins are not used. The RXD pin has no effect on the receiver and the TXD pin is continuously driven high, as in idle state. Figure 25-56. Local Loopback Mode Configuration RXD Receiver Transmitter 1 TXD 619 32117A-10/2010 AT32UC3C 25.6.15.4 Remote Loopback Mode Remote loopback mode directly connects the RXD pin to the TXD pin, as shown in Figure 25-57. The transmitter and the receiver are disabled and have no effect. This mode allows bit-by-bit retransmission. Figure 25-57. Remote Loopback Mode Configuration Receiver 1 RXD TXD Transmitter 620 32117A-10/2010 AT32UC3C 25.6.16 Write Protection Registers To prevent any single software error that may corrupt USART behavior, certain address spaces can be write-protected by setting the WPEN bit in the USART Write Protect Mode Register (WPMR). If a write access to the protected registers is detected, then the WPVS flag in the USART Write Protect Status Register (WPSR) is set and the field WPVSRC indicates in which register the write access has been attempted. The WPVS flag is reset by writing the USART Write Protect Mode Register (WPMR) with the appropriate access key, WPKEY. The protected registers are: * "Mode Register" on page 625 * "Baud Rate Generator Register" on page 637 * "Receiver Time-out Register" on page 638 * "Transmitter Timeguard Register" on page 639 * "FI DI RATIO Register" on page 640 * "IrDA FILTER Register" on page 642 * "Manchester Configuration Register" on page 643 621 32117A-10/2010 AT32UC3C 25.7 User Interface Table 25-16. USART Register Memory Map Offset Register Name Access Reset 0x0000 Control Register CR Write-only - 0x0004 Mode Register MR Read-write 0x00000000 0x0008 Interrupt Enable Register IER Write-only - 0x000C Interrupt Disable Register IDR Write-only - 0x0010 Interrupt Mask Register IMR Read-only 0x00000000 0x0014 Channel Status Register CSR Read-only 0x00000000 0x0018 Receiver Holding Register RHR Read-only 0x00000000 0x001C Transmitter Holding Register THR Write-only - 0x0020 Baud Rate Generator Register BRGR Read-write 0x00000000 0x0024 Receiver Time-out Register RTOR Read-write 0x00000000 0x0028 Transmitter Timeguard Register TTGR Read-write 0x00000000 0x0040 FI DI Ratio Register FIDI Read-write 0x00000174 0x0044 Number of Errors Register NER Read-only 0x00000000 0x004C IrDA Filter Register IFR Read-write 0x00000000 0x0050 Manchester Encoder Decoder Register MAN Read-write 0x30011004 0x0054 LIN Mode Register LINMR Read-write 0x00000000 0x0058 LIN Identifier Register LINIR Read-write 0x00000000 0x005C LIN Baud Rate Register LINBRR Read-only 0x00000000 0x00E4 Write Protect Mode Register WPMR Read-write 0x00000000 0x00E8 Write Protect Status Register WPSR Read-only 0x00000000 0x00FC Version Register VERSION Read-only 0x-(1) Note: 1. Values in the Version Register vary with the version of the IP block implementation. 622 32117A-10/2010 AT32UC3C 25.7.1 Name: Control Register CR Access Type: Write-only Offset: 0x0 Reset Value: - 31 - 30 - 29 - 28 - 27 - 26 - 25 - 24 - 23 - 22 - 21 LINWKUP 20 LINABT 19 RTSDIS/RCS 18 RTSEN/FCS 17 DTRDIS 16 DTREN 15 RETTO 14 RSTNACK 13 RSTIT 12 SENDA 11 STTTO 10 STPBRK 9 STTBRK 8 RSTSTA 7 TXDIS 6 TXEN 5 RXDIS 4 RXEN 3 RSTTX 2 RSTRX 1 - 0 - * LINWKUP: Send LIN Wakeup Signal * * * * * * 0: No effect: 1: Sends a wakeup signal on the LIN bus. LINABT: Abort LIN Transmission 0: No effect. 1: Abort the current LIN transmission. RTSDIS/RCS: Request to Send Disable/Release SPI Chip Select If USART does not operate in SPI Master Mode (MODE ... 0xE): 0: No effect. 1: Drives the pin RTS to 1. If USART operates in SPI Master Mode (MODE = 0xE): RCS = 0: No effect. RCS = 1: Releases the Slave Select Line NSS (RTS pin). RTSEN/FCS: Request to Send Enable/Force SPI Chip Select If USART does not operate in SPI Master Mode (MODE ... 0xE): 0: No effect. 1: Drives the pin RTS to 0. If USART operates in SPI Master Mode (MODE = 0xE): FCS = 0: No effect. FCS = 1: Forces the Slave Select Line NSS (RTS pin) to 0, even if USART is no transmitting, in order to address SPI slave devices supporting the CSAAT Mode (Chip Select Active After Transfer). DTRDIS: Data Terminal Ready Disable 0: No effect. 1: Drives the pin DTR to 1. DTREN: Data Terminal Ready Enable 0: No effect. 1: Drives the pin DTR at 0. RETTO: Rearm Time-out 0: No effect 1: Restart Time-out 623 32117A-10/2010 AT32UC3C * RSTNACK: Reset Non Acknowledge * * * * * * * * * * * * 0: No effect 1: Resets NACK in CSR. RSTIT: Reset Iterations 0: No effect. 1: Resets ITERATION in CSR. No effect if the ISO7816 is not enabled. SENDA: Send Address 0: No effect. 1: In Multidrop Mode only, the next character written to the THR is sent with the address bit set. STTTO: Start Time-out 0: No effect. 1: Starts waiting for a character before clocking the time-out counter. Resets the status bit TIMEOUT in CSR. STPBRK: Stop Break 0: No effect. 1: Stops transmission of the break after a minimum of one character length and transmits a high level during 12-bit periods. No effect if no break is being transmitted. STTBRK: Start Break 0: No effect. 1: Starts transmission of a break after the characters present in THR and the Transmit Shift Register have been transmitted. No effect if a break is already being transmitted. RSTSTA: Reset Status Bits 0: No effect. 1: Resets the status bits PARE, FRAME, OVRE, MANERR, LINBE, LINSFE, LINIPE, LINCE, LINSNRE and RXBRK in CSR. TXDIS: Transmitter Disable 0: No effect. 1: Disables the transmitter. TXEN: Transmitter Enable 0: No effect. 1: Enables the transmitter if TXDIS is 0. RXDIS: Receiver Disable 0: No effect. 1: Disables the receiver. RXEN: Receiver Enable 0: No effect. 1: Enables the receiver, if RXDIS is 0. RSTTX: Reset Transmitter 0: No effect. 1: Resets the transmitter. RSTRX: Reset Receiver 0: No effect. 1: Resets the receiver. 624 32117A-10/2010 AT32UC3C 25.7.2 Name: Mode Register MR Access Type: Read-write Offset: 0x4 Reset Value: - 31 ONEBIT 30 MODSYNC 29 MAN 28 FILTER 27 - 26 25 MAX_ITERATION 24 23 INVDATA 22 VAR_SYNC 21 DSNACK 20 INACK 19 OVER 18 CLKO 17 MODE9 16 MSBF/CPOL 15 14 13 12 11 10 PAR 9 8 SYNC/CPHA 4 3 2 1 0 CHMODE 7 NBSTOP 6 5 CHRL USCLKS MODE This register can only be written if the WPEN bit is cleared in the Write Protect Mode Register(if exists). * ONEBIT: Start Frame Delimiter Selector * * * * * * * 0: Start Frame delimiter is COMMAND or DATA SYNC. 1: Start Frame delimiter is One Bit. MODSYNC: Manchester Synchronization Mode 0:The Manchester Start bit is a 0 to 1 transition 1: The Manchester Start bit is a 1 to 0 transition. MAN: Manchester Encoder/Decoder Enable 0: Manchester Encoder/Decoder are disabled. 1: Manchester Encoder/Decoder are enabled. FILTER: Infrared Receive Line Filter 0: The USART does not filter the receive line. 1: The USART filters the receive line using a three-sample filter (1/16-bit clock) (2 over 3 majority). MAX_ITERATION Defines the maximum number of iterations in mode ISO7816, protocol T= 0. INVDATA: Inverted Data 0: The data field transmitted on TXD line is the same as the one written in THR register or the content read in RHR is the same as RXD line. Normal mode of operation. 1: The data field transmitted on TXD line is inverted (voltage polarity) compared to the value written in THR register or the content read in RHR is inverted compared to RXD line (or ISO7816 IO line). Inverted Mode of operation, useful for contactless card application. To be used with configuration bit MSBF. VAR_SYNC: Variable Synchronization of Command/Data Sync Start Frame Delimiter 0: User defined configuration of command or data sync field depending on SYNC value. 1: The sync field is updated when a character is written into THR register. DSNACK: Disable Successive NACK 0: NACK is sent on the ISO line as soon as a parity error occurs in the received character (unless INACK is set). 1: Successive parity errors are counted up to the value specified in the MAX_ITERATION field. These parity errors generate a NACK on the ISO line. As soon as this value is reached, no additional NACK is sent on the ISO line. The flag ITERATION is asserted. 625 32117A-10/2010 AT32UC3C * INACK: Inhibit Non Acknowledge * * * * 0: The NACK is generated. 1: The NACK is not generated. Note: in SPI master mode, if INACK = 0 the character transmission starts as soon as character is written into THR register (assuming TXRDY was set). When INACK = 1, an additional condition must be met. The character transmission starts when a character is written and only if RXRDY bit is cleared (RHR has been read). OVER: Oversampling Mode 0: 16x Oversampling. 1: 8x Oversampling. CLKO: Clock Output Select 0: The USART does not drive the CLK pin. 1: The USART drives the CLK pin if USCLKS does not select the external clock CLK. MODE9: 9-bit Character Length 0: CHRL defines character length. 1: 9-bit character length. MSBF/CPOL: Bit Order or SPI Clock Polarity If USART does not operate in SPI Mode (MODE ... 0xE and 0xF): MSBF = 0: Least Significant Bit is sent/received first. MSBF = 1: Most Significant Bit is sent/received first. If USART operates in SPI Mode (Slave or Master, MODE = 0xE or 0xF): CPOL = 0: The inactive state value of SPCK is logic level zero. CPOL = 1: The inactive state value of SPCK is logic level one. CPOL is used to determine the inactive state value of the serial clock (SPCK). It is used with CPHA to produce the required clock/data relationship between master and slave devices. 626 32117A-10/2010 AT32UC3C * CHMODE: Channel Mode Table 25-17. CHMODE Mode Description 0 0 Normal Mode 0 1 Automatic Echo. Receiver input is connected to the TXD pin. 1 0 Local Loopback. Transmitter output is connected to the Receiver Input. 1 1 Remote Loopback. RXD pin is internally connected to the TXD pin. * NBSTOP: Number of Stop Bits Table 25-18. NBSTOP Asynchronous (SYNC = 0) Synchronous (SYNC = 1) 0 0 1 stop bit 1 stop bit 0 1 1.5 stop bits Reserved 1 0 2 stop bits 2 stop bits 1 1 Reserved Reserved * PAR: Parity Type Table 25-19. PAR Parity Type 0 0 0 Even parity 0 0 1 Odd parity 0 1 0 Parity forced to 0 (Space) 0 1 1 Parity forced to 1 (Mark) 1 0 x No parity 1 1 x Multidrop mode * SYNC/CPHA: Synchronous Mode Select or SPI Clock Phase If USART does not operate in SPI Mode (MODE is ... 0xE and 0xF): SYNC = 0: USART operates in Asynchronous Mode. SYNC = 1: USART operates in Synchronous Mode. If USART operates in SPI Mode (MODE = 0xE or 0xF): CPHA = 0: Data is changed on the leading edge of SPCK and captured on the following edge of SPCK. CPHA = 1: Data is captured on the leading edge of SPCK and changed on the following edge of SPCK. CPHA determines which edge of SPCK causes data to change and which edge causes data to be captured. CPHA is used with CPOL to produce the required clock/data relationship between master and slave devices. 627 32117A-10/2010 AT32UC3C * CHRL: Character Length. Table 25-20. CHRL Character Length 0 0 5 bits 0 1 6 bits 1 0 7 bits 1 1 8 bits * USCLKS: Clock Selection Table 25-21. USCLKS Selected Clock 0 0 CLK_USART 0 1 CLK_USART/DIV(1) 1 0 Reserved 1 1 CLK Note: 1. The value of DIV is device dependent. Please refer to the Module Configuration section at the end of this chapter. * MODE Table 25-22. MODE Mode of the USART 0 0 0 0 Normal 0 0 0 1 RS485 0 0 1 0 Hardware Handshaking 0 0 1 1 Modem 0 1 0 0 IS07816 Protocol: T = 0 0 1 1 0 IS07816 Protocol: T = 1 1 0 0 0 IrDA 1 0 1 0 LIN Master 1 0 1 1 LIN Slave 1 1 1 0 SPI Master 1 1 1 1 SPI Slave Others Reserved 628 32117A-10/2010 AT32UC3C 25.7.3 Name: Interrupt Enable Register IER Access Type: Write-only Offset: 0x8 Reset Value: - 31 LINHTE 30 LINSTE 29 LINSNRE 28 LINCE 27 LINIPE 26 LINISFE 25 LINBE 24 MANEA 23 - 22 - 21 - 20 MANE 19 CTSIC 18 DCDIC 17 DSRIC 16 RIIC 15 LINTC 14 LINiD 13 NACK/LINBK 12 RXBUFF 11 - 10 ITER/UNRE 9 TXEMPTY 8 TIMEOUT 7 PARE 6 FRAME 5 OVRE 4 - 3 - 2 RXBRK 1 TXRDY 0 RXRDY Writing a zero to a bit in this register has no effect. Writing a one to a bit in this register will set the corresponding bit in IMR. For backward compatibility the MANE bit has been duplicated to the MANEA bit position. Writing either one or the other has the same effect. 629 32117A-10/2010 AT32UC3C 25.7.4 Name: Interrupt Disable Register IDR Access Type: Write-only Offset: 0xC Reset Value: - 31 LINHTE 30 LINSTE 29 LINSNRE 28 LINCE 27 LINIPE 26 LINISFE 25 LINBE 24 MANEA 23 - 22 - 21 - 20 MANE 19 CTSIC 18 DCDIC 17 DSRIC 16 RIIC 15 LINTC 14 LINID 13 NACK/LINBK 12 RXBUFF 11 - 10 ITER/UNRE 9 TXEMPTY 8 TIMEOUT 7 PARE 6 FRAME 5 OVRE 4 - 3 - 2 RXBRK 1 TXRDY 0 RXRDY Writing a zero to a bit in this register has no effect. Writing a one to a bit in this register will clear the corresponding bit in IMR. For backward compatibility the MANE bit has been duplicated to the MANEA bit position. Writing either one or the other has the same effect. 630 32117A-10/2010 AT32UC3C 25.7.5 Name: Interrupt Mask Register IMR Access Type: Read-only Offset: 0x10 Reset Value: - 31 LINHTE 30 LINSTE 29 LINSNRE 28 LINCE 27 LINIPE 26 LINISFE 25 LINBE 24 MANEA 23 - 22 - 21 - 20 MANE 19 CTSIC 18 DCDIC 17 DSRIC 16 RIIC 15 LINTC 14 LINID 13 NACK/LINBK 12 RXBUFF 11 - 10 ITER/UNRE 9 TXEMPTY 8 TIMEOUT 7 PARE 6 FRAME 5 OVRE 4 - 3 - 2 RXBRK 1 TXRDY 0 RXRDY 0: The corresponding interrupt is disabled. 1: The corresponding interrupt is enabled. A bit in this register is cleared when the corresponding bit in IDR is written to one. A bit in this register is set when the corresponding bit in IER is written to one. For backward compatibility the MANE bit has been duplicated to the MANEA bit position. Reading either one or the other has the same effect. 631 32117A-10/2010 AT32UC3C 25.7.6 Name: Channel Status Register CSR Access Type: Read-only Offset: 0x14 Reset Value: - 31 LINHTE 30 LINSTE 29 LINSNRE 28 LINCE 27 LINIPE 26 LINISFE 25 LINBE 24 MANERR 23 CTS/LINBLS 22 DCD 21 DSR 20 RI 19 CTSIC 18 DCDIC 17 DSRIC 16 RIIC 15 LINTC 14 LINID 13 NACK/LINBK 12 RXBUFF 11 - 10 ITER/UNRE 9 TXEMPTY 8 TIMEOUT 7 PARE 6 FRAME 5 OVRE 4 - 3 - 2 RXBRK 1 TXRDY 0 RXRDY * LINHTE: LIN Header Timeout Error * * * * * * * * 0: No LIN Header Timeout error has been detected since the last RSTSTA. 1: A LIN Header Timeout error has been detected since the last RSTSTA. LINSTE: LIN Synch Tolerance Error 0: No LIN Synch Tolerance error has been detected since the last RSTSTA. 1: A LIN Synch Tolerance error has been detected since the last RSTSTA. LINSNRE: LIN Slave Not Responding Error 0: No LIN Slave Not Responding Error has been detected since the last RSTSTA. 1: A LIN Slave Not Responding Error has been detected since the last RSTSTA. LINCE: LIN Checksum Error 0: No LIN Checksum Error has been detected since the last RSTSTA. 1: A LIN Checksum Error has been detected since the last RSTSTA. LINIPE: LIN Identifier Parity Error 0: No LIN Identifier Parity Error has been detected since the last RSTSTA. 1: A LIN Identifier Parity Error has been detected since the last RSTSTA. LINISFE: LIN Inconsistent Synch Field Error 0: No LIN Inconsistent Synch Field Error has been detected since the last RSTSTA 1: The USART is configured as a Slave node and a LIN Inconsistent Synch Field Error has been detected since the last RSTSTA. LINBE: LIN Bit Error 0: No Bit Error has been detected since the last RSTSTA. 1: A Bit Error has been detected since the last RSTSTA. MANERR: Manchester Error 0: No Manchester error has been detected since the last RSTSTA. 1: At least one Manchester error has been detected since the last RSTSTA. CTS/LINBLS: Image of CTS Input or LIN Bus Line Status - If USART does not operate in LIN Mode (Master or Slave): 0: CTS is at 0. 1: CTS is at 1. - If USART operates in LIN Mode (Master or Slave): 632 32117A-10/2010 AT32UC3C * * * * * * * * * * * * * * 0: LIN Bus Line is at 0. 1: LIN Bus Line is at 1. DCD: Image of DCD Input 0: DCD is at 0. 1: DCD is at 1. DSR: Image of DSR Input 0: DSR is at 0. 1: DSR is at 1. RI: Image of RI Input 0: RI is at 0. 1: RI is at 1. CTSIC: Clear to Send Input Change Flag 0: No input change has been detected on the CTS pin since the last read of CSR. 1: At least one input change has been detected on the CTS pin since the last read of CSR. DCDIC: Data Carrier Detect Input Change Flag 0: No input change has been detected on the DCD pin since the last read of CSR. 1: At least one input change has been detected on the DCD pin since the last read of CSR. DSRIC: Data Set Ready Input Change Flag 0: No input change has been detected on the DSR pin since the last read of CSR. 1: At least one input change has been detected on the DSR pin since the last read of CSR. RIIC: Ring Indicator Input Change Flag 0: No input change has been detected on the RI pin since the last read of CSR. 1: At least one input change has been detected on the RI pin since the last read of CSR. LINTC: LIN Transfer Completed 0: The USART is idle or a LIN transfer is ongoing. 1: A LIN transfer has been completed since the last RSTSTA. LINID: LIN Identifier 0: No LIN Identifier received or sent 1: The USART is configured as a Slave node and a LIN Identifier has been received or the USART is configured as a Master node and a LIN Identifier has been sent since the last RSTSTA. NACK: Non Acknowledge 0: No Non Acknowledge has not been detected since the last RSTNACK. 1: At least one Non Acknowledge has been detected since the last RSTNACK. RXBUFF: Reception Buffer Full 0: The signal Buffer Full from the Receive Peripheral DMA Controller channel is inactive. 1: The signal Buffer Full from the Receive Peripheral DMA Controller channel is active. ITER/UNRE: Max number of Repetitions Reached or SPI Underrun Error If USART does not operate in SPI Slave Mode (MODE ... 0xF): ITER = 0: Maximum number of repetitions has not been reached since the last RSTSTA. ITER = 1: Maximum number of repetitions has been reached since the last RSTSTA. If USART operates in SPI Slave Mode (MODE = 0xF): UNRE = 0: No SPI underrun error has occurred since the last RSTSTA. UNRE = 1: At least one SPI underrun error has occurred since the last RSTSTA. TXEMPTY: Transmitter Empty 0: There are characters in either THR or the Transmit Shift Register, or the transmitter is disabled. 1: There are no characters in THR, nor in the Transmit Shift Register. TIMEOUT: Receiver Time-out 0: There has not been a time-out since the last Start Time-out command (STTTO in CR) or the Time-out Register is 0. 1: There has been a time-out since the last Start Time-out command (STTTO in CR). 633 32117A-10/2010 AT32UC3C * PARE: Parity Error * * * * * 0: No parity error has been detected since the last RSTSTA. 1: At least one parity error has been detected since the last RSTSTA. FRAME: Framing Error 0: No stop bit has been detected low since the last RSTSTA. 1: At least one stop bit has been detected low since the last RSTSTA. OVRE: Overrun Error 0: No overrun error has occurred since the last RSTSTA. 1: At least one overrun error has occurred since the last RSTSTA. RXBRK: Break Received/End of Break 0: No Break received or End of Break detected since the last RSTSTA. 1: Break Received or End of Break detected since the last RSTSTA. TXRDY: Transmitter Ready 0: A character is in the THR waiting to be transferred to the Transmit Shift Register, or an STTBRK command has been requested, or the transmitter is disabled. As soon as the transmitter is enabled, TXRDY becomes 1. 1: There is no character in the THR. RXRDY: Receiver Ready 0: No complete character has been received since the last read of RHR or the receiver is disabled. If characters were being received when the receiver was disabled, RXRDY changes to 1 when the receiver is enabled. 1: At least one complete character has been received and RHR has not yet been read. 634 32117A-10/2010 AT32UC3C 25.7.7 Name: Receive Holding Register RHR Access Type: Read-only Offset: 0x18 Reset Value: 0x00000000 31 - 30 - 29 - 28 - 27 - 26 - 25 - 24 - 23 - 22 - 21 - 20 - 19 - 18 - 17 - 16 - 15 RXSYNH 14 - 13 - 12 - 11 - 10 - 9 - 8 RXCHR 7 6 5 4 3 2 1 0 RXCHR * RXSYNH: Received Sync 0: Last Character received is a Data. 1: Last Character received is a Command. * RXCHR: Received Character Last character received if RXRDY is set. 635 32117A-10/2010 AT32UC3C 25.7.8 Name: USART Transmit Holding Register THR Access Type: Write-only Offset: 0x1C Reset Value: - 31 - 30 - 29 - 28 - 27 - 26 - 25 - 24 - 23 - 22 - 21 - 20 - 19 - 18 - 17 - 16 - 15 TXSYNH 14 - 13 - 12 - 11 - 10 - 9 - 8 TXCHR 7 6 5 4 3 2 1 0 TXCHR * TXSYNH: Sync Field to be transmitted 0: The next character sent is encoded as a data. Start Frame Delimiter is DATA SYNC. 1: The next character sent is encoded as a command. Start Frame Delimiter is COMMAND SYNC. * TXCHR: Character to be Transmitted Next character to be transmitted after the current character if TXRDY is not set. 636 32117A-10/2010 AT32UC3C 25.7.9 Name: Baud Rate Generator Register BRGR Access Type: Read-write Offset: 0x20 Reset Value: 0x00000000 31 - 30 - 29 - 28 - 27 - 26 - 25 - 24 - 23 - 22 - 21 - 20 - 19 - 18 17 FP 16 15 14 13 12 11 10 9 8 3 2 1 0 CD 7 6 5 4 CD This register can only be written if the WPEN bit is cleared in the Write Protect Mode Register. * FP: Fractional Part 0: Fractional divider is disabled. 1 - 7: Baudrate resolution, defined by FP x 1/8. * CD: Clock Divider Table 25-23. MODE ISO7816 SYNC = 1 or MODE = SPI (Master or Slave) SYNC = 0 CD OVER = 0 0 1 to 65535 MODE = ISO7816 OVER = 1 Baud Rate Clock Disabled Baud Rate = Selected Clock/16/CD Baud Rate = Selected Clock/8/CD Baud Rate = Selected Clock /CD Baud Rate = Selected Clock/CD/FI_DI_RATIO 637 32117A-10/2010 AT32UC3C 25.7.10 Name: Receiver Time-out Register RTOR Access Type: Read-write Offset: 0x24 Reset Value: 0x00000000 31 - 30 - 29 - 28 - 27 - 26 - 25 - 24 - 23 - 22 - 21 - 20 - 19 - 18 - 17 - 16 TO 15 14 13 12 11 10 9 8 3 2 1 0 TO 7 6 5 4 TO This register can only be written if the WPEN bit is cleared in the Write Protect Mode Register. * TO: Time-out Value 0: The Receiver Time-out is disabled. 1 - 131071: The Receiver Time-out is enabled and the Time-out delay is TO x Bit Period. Note that the size of the TO counter can change depending of implementation. See the Module Configuration section. 638 32117A-10/2010 AT32UC3C 25.7.11 Name: Transmitter Timeguard Register TTGR Access Type: Read-write Offset: 0x28 Reset Value: 0x00000000 31 - 30 - 29 - 28 - 27 - 26 - 25 - 24 - 23 - 22 - 21 - 20 - 19 - 18 - 17 - 16 - 15 - 14 - 13 - 12 - 11 - 10 - 9 - 8 - 7 6 5 4 3 2 1 0 TG This register can only be written if the WPEN bit is cleared in the Write Protect Mode Register. * TG: Timeguard Value 0: The Transmitter Timeguard is disabled. 1 - 255: The Transmitter timeguard is enabled and the timeguard delay is TG x Bit Period. 639 32117A-10/2010 AT32UC3C 25.7.12 Name: FI DI RATIO Register FIDI Access Type: Read-write Offset: 0x40 Reset Value: 0x00000174 31 - 30 - 29 - 28 - 27 - 26 - 25 - 24 - 23 - 22 - 21 - 20 - 19 - 18 - 17 - 16 - 15 - 14 - 13 - 12 - 11 - 10 9 FI_DI_RATIO 8 7 6 5 4 3 2 1 0 FI_DI_RATIO This register can only be written if the WPEN bit is cleared in the Write Protect Mode Register. * FI_DI_RATIO: FI Over DI Ratio Value 0: If ISO7816 mode is selected, the Baud Rate Generator generates no signal. 1 - 2047: If ISO7816 mode is selected, the Baud Rate is the clock provided on CLK divided by FI_DI_RATIO. 640 32117A-10/2010 AT32UC3C 25.7.13 Name: Number of Errors Register NER Access Type: Read-only Offset: 0x44 Reset Value: - 31 - 30 - 29 - 28 - 27 - 26 - 25 - 24 - 23 - 22 - 21 - 20 - 19 - 18 - 17 - 16 - 15 - 14 - 13 - 12 - 11 - 10 - 9 - 8 - 7 6 5 4 3 2 1 0 NB_ERRORS * NB_ERRORS: Number of Errors Total number of errors that occurred during an ISO7816 transfer. This register automatically clears when read. 641 32117A-10/2010 AT32UC3C 25.7.14 Name: IrDA FILTER Register IFR Access Type: Read-write Offset: 0x4C Reset Value: 0x00000000 31 - 30 - 29 - 28 - 27 - 26 - 25 - 24 - 23 - 22 - 21 - 20 - 19 - 18 - 17 - 16 - 15 - 14 - 13 - 12 - 11 - 10 - 9 - 8 - 7 6 5 4 3 2 1 0 IRDA_FILTER This register can only be written if the WPEN bit is cleared in the Write Protect Mode Register(if exists). IRDA_FILTER: IrDA Filter Sets the filter of the IrDA demodulator. 642 32117A-10/2010 AT32UC3C 25.7.15 Name: Manchester Configuration Register MAN Access Type: Read-write Offset: 0x50 Reset Value: 0x30011004 31 - 30 DRIFT 29 1 28 RX_MPOL 27 - 26 - 25 23 - 22 - 21 - 20 - 19 18 17 15 - 14 - 13 - 12 TX_MPOL 11 - 10 - 7 - 6 - 5 - 4 - 3 2 24 RX_PP 16 RX_PL 9 8 TX_PP 1 0 TX_PL This register can only be written if the WPEN bit is cleared in the Write Protect Mode Register(if exists). * DRIFT: Drift compensation 0: The USART can not recover from an important clock drift 1: The USART can recover from clock drift. The 16X clock mode must be enabled. * RX_MPOL: Receiver Manchester Polarity 0: Logic Zero is coded as a zero-to-one transition, Logic One is coded as a one-to-zero transition. 1: Logic Zero is coded as a one-to-zero transition, Logic One is coded as a zero-to-one transition. * RX_PP: Receiver Preamble Pattern detected Table 25-24. RX_PP Preamble Pattern default polarity assumed (RX_MPOL field not set) 0 0 ALL_ONE 0 1 ALL_ZERO 1 0 ZERO_ONE 1 1 ONE_ZERO * RX_PL: Receiver Preamble Length 0: The receiver preamble pattern detection is disabled 1 - 15: The detected preamble length is RX_PL x Bit Period * TX_MPOL: Transmitter Manchester Polarity 0: Logic Zero is coded as a zero-to-one transition, Logic One is coded as a one-to-zero transition. 1: Logic Zero is coded as a one-to-zero transition, Logic One is coded as a zero-to-one transition. 643 32117A-10/2010 AT32UC3C * TX_PP: Transmitter Preamble Pattern Table 25-25. TX_PP Preamble Pattern default polarity assumed (TX_MPOL field not set) 0 0 ALL_ONE 0 1 ALL_ZERO 1 0 ZERO_ONE 1 1 ONE_ZERO * TX_PL: Transmitter Preamble Length 0: The Transmitter Preamble pattern generation is disabled 1 - 15: The Preamble Length is TX_PL x Bit Period 644 32117A-10/2010 AT32UC3C 25.7.16 Name: LIN Mode Register LINMR Access Type: Read-write Offset: 0x54 Reset Value: 0x00000000 31 - 30 - 29 - 28 - 27 - 26 - 25 - 24 - 23 - 22 - 21 - 20 - 19 - 18 - 17 SYNCDIS 16 PDCM 15 14 13 12 11 10 9 8 3 CHKDIS 2 PARDIS 1 DLC 7 WKUPTYP 6 FSDIS 5 DLM 4 CHKTYP 0 NACT * SYNCDIS: Synchronization Disable * * * * * * * * 0: The Synchronization procedure is performed in LIN Slave node configuration. 1: The Synchronization procedure is not performed. PDCM: Peripheral DMA Controller Mode 0: The LIN mode register LINMR is not written by the Peripheral DMA Controller. 1: The LIN mode register LINMR (excepting that bit) is written by the Peripheral DMA Controller. DLC: Data Length Control 0 - 255: Defines the response data length if DLM=0,in that case the response data length is equal to DLC+1 bytes. WKUPTYP: Wakeup Signal Type 0: setting the bit LINWKUP in the control register sends a LIN 2.0 wakeup signal. 1: setting the bit LINWKUP in the control register sends a LIN 1.3 wakeup signal. FSDIS: Frame Slot Mode Disable 0: The Frame Slot Mode is enabled. 1: The Frame Slot Mode is disabled. DLM: Data Length Mode 0: The response data length is defined by the field DLC of this register. 1: The response data length is defined by the bits 4 and 5 of the Identifier (IDCHR in LINIR). CHKTYP: Checksum Type 0: LIN 2.0 "Enhanced" Checksum 1: LIN 1.3 "Classic" Checksum CHKDIS: Checksum Disable 0: In Master node configuration, the checksum is computed and sent automatically. In Slave node configuration, the checksum is checked automatically. 1: Whatever the node configuration is, the checksum is not computed/sent and it is not checked. PARDIS: Parity Disable 0: In Master node configuration, the Identifier Parity is computed and sent automatically. In Master node and Slave node configuration, the parity is checked automatically. 1:Whatever the node configuration is, the Identifier parity is not computed/sent and it is not checked. 645 32117A-10/2010 AT32UC3C * NACT: LIN Node Action Table 1. NACT Mode Description 0 0 PUBLISH: The USART transmits the response. 0 1 SUBSCRIBE: The USART receives the response. 1 0 IGNORE: The USART does not transmit and does not receive the response. 1 1 Reserved 646 32117A-10/2010 AT32UC3C 25.7.17 Name: LIN Identifier Register LINIR Access Type: Read-write or Read-only Offset: 0x58 Reset Value: 0x00000000 31 - 30 - 29 - 28 - 27 - 26 - 25 - 24 - 23 - 22 - 21 - 20 - 19 - 18 - 17 - 16 - 15 - 14 - 13 - 12 - 11 - 10 - 9 - 8 - 7 6 5 4 3 2 1 0 IDCHR * IDCHR: Identifier Character If MODE=0xA (Master node configuration): IDCHR is Read-write and its value is the Identifier character to be transmitted. if MODE=0xB (Slave node configuration): IDCHR is Read-only and its value is the last Identifier character that has been received. 647 32117A-10/2010 AT32UC3C 25.7.18 Name: LIN Baud Rate Register LINBRR Access Type: Read-only Offset: 0x5C Reset Value: 0x00000000 31 - 30 - 29 - 28 - 27 - 26 - 25 - 24 - 23 - 22 - 21 - 20 - 19 - 18 17 LINFP 16 15 14 13 12 11 10 9 8 3 2 1 0 LINCD 7 6 5 4 LINCD * LINFP: LIN Fractional Part after Synchronization * LINCD: LIN Clock Divider after Synchronization 648 32117A-10/2010 AT32UC3C 25.7.19 Write Protect Mode Register Register Name: WPMR Access Type: Read-write Offset: 0xE4 Reset Value: See Table 25-16 31 30 29 28 27 26 25 24 19 18 17 16 11 10 9 8 3 -- 2 -- 1 -- 0 WPEN WPKEY 23 22 21 20 WPKEY 15 14 13 12 WPKEY 7 -- 6 -- 5 -- 4 -- * WPKEY: Write Protect KEY Should be written at value 0x555341 ("USA" in ASCII). Writing any other value in this field aborts the write operation of the WPEN bit. Always reads as 0. * WPEN: Write Protect Enable 0 = Disables the Write Protect if WPKEY corresponds to 0x555341 ("USA" in ASCII). 1 = Enables the Write Protect if WPKEY corresponds to 0x555341 ("USA" in ASCII). Protects the registers: * "Mode Register" on page 625 * "Baud Rate Generator Register" on page 637 * "Receiver Time-out Register" on page 638 * "Transmitter Timeguard Register" on page 639 * "FI DI RATIO Register" on page 640 * "IrDA FILTER Register" on page 642 * "Manchester Configuration Register" on page 643 649 32117A-10/2010 AT32UC3C 25.7.20 Write Protect Status Register Register Name: WPSR Access Type: Read-only Offset: 0xE8 Reset Value: See Table 25-16 31 -- 30 -- 29 -- 28 -- 27 -- 26 -- 25 -- 24 -- 23 22 21 20 19 18 17 16 11 10 9 8 3 -- 2 -- 1 -- 0 WPVS WPVSRC 15 14 13 12 WPVSRC 7 -- 6 -- 5 -- 4 -- * WPVSRC: Write Protect Violation Source When WPVS is active, this field indicates the write-protected register (through address offset or code) in which a write access has been attempted. * WPVS: Write Protect Violation Status 0 = No Write Protect Violation has occurred since the last read of the WPSR register. 1 = A Write Protect Violation has occurred since the last read of the WPSR register. If this violation is an unauthorized attempt to write a protected register, the associated violation is reported into field WPVSRC. Note: Reading WPSR automatically clears all fields. 650 32117A-10/2010 AT32UC3C 25.7.21 Name: Version Register VERSION Access Type: Read-only Offset: 0xFC Reset Value: - 31 - 30 - 29 - 28 - 27 - 26 - 25 - 24 - 23 - 22 - 21 - 20 - 19 18 17 16 15 - 14 - 13 - 12 - 11 9 8 7 6 5 4 1 0 MFN 10 VERSION 3 2 VERSION * MFN Reserved. No functionality associated. * VERSION Version of the module. No functionality associated. 651 32117A-10/2010 AT32UC3C 25.8 Module Configuration The specific configuration for each USART instance is listed in the following tables. The module bus clocks listed here are connected to the system bus clocks according to the table in the System Bus Clock Connections section. Table 25-26. Module Configuration Feature USART0 USART2 USART3 USART4 USART1 ISO7816 Not Implemented Implemented IRDA Logic Not Implemented Implemented RS485 Logic Not Implemented Implemented Modem Logic Not Implemented Implemented SPI Logic Implemented Implemented LIN Logic Implemented Implemented Manchester Logic Not Implemented Implemented Fractional Baudrate Implemented Implemented DIV 8 8 Receiver Time-out Counter Size 17-bits 17-bits Table 25-27. Module Clock Name 25.8.1 Module name Clock name Description USART0 CLK_USART0 Peripheral Bus clock from the PBA clock domain USART1 CLK_USART1 Peripheral Bus clock from the PBC clock domain USART2 CLK_USART2 Peripheral Bus clock from the PBA clock domain USART3 CLK_USART3 Peripheral Bus clock from the PBA clock domain USART4 CLK_USART4 Peripheral Bus clock from the PBC clock domain Clock Connections Each USART can be connected to an internally divided clock: Table 25-28. USART Clock Connections USART Source Name Connection 0 PBA Clock / 8 (CLK_PBA_USART_DIV) 1 PBC Clock / 8 (CLK_PBC_USART_DIV) 2 Internal CLK_DIV PBA Clock / 8 (CLK_PBA_USART_DIV) 3 PBA Clock / 8 (CLK_PBA_USART_DIV) 4 PBC Clock / 8 (CLK_PBC_USART_DIV) 652 32117A-10/2010 AT32UC3C 25.8.2 Register Reset Values Table 25-29. Register Reset Values Register Reset Value VERSION 0x00000602 653 32117A-10/2010 AT32UC3C 26. Serial Peripheral Interface (SPI) Rev. 2.1.1.3 26.1 Features * Compatible with an embedded 32-bit microcontroller * Supports communication with serial external devices - Four chip selects with external decoder support allow communication with up to 15 peripherals - Serial memories, such as DataFlash and 3-wire EEPROMs - Serial peripherals, such as ADCs, DACs, LCD controllers, CAN controllers and Sensors - External co-processors * Master or Slave Serial Peripheral Bus Interface - 4 - to 16-bit programmable data length per chip select - Programmable phase and polarity per chip select - Programmable transfer delays between consecutive transfers and between clock and data per chip select - Programmable delay between consecutive transfers - Selectable mode fault detection * Connection to Peripheral DMA Controller channel capabilities optimizes data transfers - One channel for the receiver, one channel for the transmitter - Next buffer support - Four character FIFO in reception 26.2 Overview The Serial Peripheral Interface (SPI) circuit is a synchronous serial data link that provides communication with external devices in Master or Slave mode. It also enables communication between processors if an external processor is connected to the system. The Serial Peripheral Interface is essentially a shift register that serially transmits data bits to other SPIs. During a data transfer, one SPI system acts as the "master"' which controls the data flow, while the other devices act as "slaves'' which have data shifted into and out by the master. Different CPUs can take turn being masters (Multiple Master Protocol opposite to Single Master Protocol where one CPU is always the master while all of the others are always slaves) and one master may simultaneously shift data into multiple slaves. However, only one slave may drive its output to write data back to the master at any given time. A slave device is selected when the master asserts its NSS signal. If multiple slave devices exist, the master generates a separate slave select signal for each slave (NPCS). The SPI system consists of two data lines and two control lines: * Master Out Slave In (MOSI): this data line supplies the output data from the master shifted into the input(s) of the slave(s). * Master In Slave Out (MISO): this data line supplies the output data from a slave to the input of the master. There may be no more than one slave transmitting data during any particular transfer. * Serial Clock (SPCK): this control line is driven by the master and regulates the flow of the data bits. The master may transmit data at a variety of baud rates; the SPCK line cycles once for each bit that is transmitted. * Slave Select (NSS): this control line allows slaves to be turned on and off by hardware. 654 32117A-10/2010 AT32UC3C 26.3 Block Diagram Figure 26-1. SPI Block Diagram Peripheral DMA Controller Peripheral Bus SPCK MISO CLK_SPI MOSI Spi Interface I/O Controller NPCS0/NSS NPCS1 NPCS2 Interrupt Control NPCS3 SPI Interrupt 26.4 Application Block Diagram Figure 26-2. Application Block Diagram: Single Master/Multiple Slave Implementation Spi Master SPCK SPCK MISO MISO MOSI MOSI NPCS0 Slave 0 NSS NPCS1 NPCS2 NPCS3 NC SPCK MISO MOSI Slave 1 NSS SPCK MISO MOSI Slave 2 NSS 655 32117A-10/2010 AT32UC3C 26.5 I/O Lines Description Table 26-1. I/O Lines Description Type 26.6 Pin Name Pin Description Master Slave MISO Master In Slave Out Input Output MOSI Master Out Slave In Output Input SPCK Serial Clock Output Input NPCS1-NPCS3 Peripheral Chip Selects Output Unused NPCS0/NSS Peripheral Chip Select/Slave Select Output Input Product Dependencies In order to use this module, other parts of the system must be configured correctly, as described below. 26.6.1 I/O Lines The pins used for interfacing the compliant external devices may be multiplexed with I/O lines. The user must first configure the I/O Controller to assign the SPI pins to their peripheral functions. 26.6.2 Clocks The clock for the SPI bus interface (CLK_SPI) is generated by the Power Manager. This clock is enabled at reset, and can be disabled in the Power Manager. It is recommended to disable the SPI before disabling the clock, to avoid freezing the SPI in an undefined state. 26.6.3 Interrupts The SPI interrupt request line is connected to the interrupt controller. Using the SPI interrupt requires the interrupt controller to be programmed first. 26.7 26.7.1 Functional Description Modes of Operation The SPI operates in master mode or in slave mode. Operation in master mode is configured by writing a one to the Master/Slave Mode bit in the Mode Register (MR.MSTR). The pins NPCS0 to NPCS3 are all configured as outputs, the SPCK pin is driven, the MISO line is wired on the receiver input and the MOSI line driven as an output by the transmitter. If the MR.MSTR bit is written to zero, the SPI operates in slave mode. The MISO line is driven by the transmitter output, the MOSI line is wired on the receiver input, the SPCK pin is driven by the transmitter to synchronize the receiver. The NPCS0 pin becomes an input, and is used as a Slave Select signal (NSS). The pins NPCS1 to NPCS3 are not driven and can be used for other purposes. The data transfers are identically programmable for both modes of operations. The baud rate generator is activated only in master mode. 656 32117A-10/2010 AT32UC3C 26.7.2 Data Transfer Four combinations of polarity and phase are available for data transfers. The clock polarity is configured with the Clock Polarity bit in the Chip Select Registers (CSRn.CPOL). The clock phase is configured with the Clock Phase bit in the CSRn registers (CSRn.NCPHA). These two bits determine the edges of the clock signal on which data is driven and sampled. Each of the two bits has two possible states, resulting in four possible combinations that are incompatible with one another. Thus, a master/slave pair must use the same parameter pair values to communicate. If multiple slaves are used and fixed in different configurations, the master must reconfigure itself each time it needs to communicate with a different slave. Table 26-2 on page 657 shows the four modes and corresponding parameter settings. Table 26-2. SPI modes SPI Mode CPOL NCPHA 0 0 1 1 0 0 2 1 1 3 1 0 Figure 26-3 on page 657 and Figure 26-4 on page 658 show examples of data transfers. Figure 26-3. SPI Transfer Format (NCPHA = 1, 8 bits per transfer) SPCK cycle (for reference) 2 1 3 4 5 6 7 8 SPCK (CPOL = 0) SPCK (CPOL = 1) MOSI (from master) MISO (from slave) MSB MSB 6 5 4 3 2 1 LSB 6 5 4 3 2 1 LSB *** NSS (to slave) *** Not Defined, but normaly MSB of previous character received 657 32117A-10/2010 AT32UC3C Figure 26-4. SPI Transfer Format (NCPHA = 0, 8 bits per transfer) SPCK cycle (for reference) 1 2 3 4 5 6 7 8 SPCK (CPOL = 0) SPCK (CPOL = 1) MOSI (from master) MISO (from slave) *** MSB 6 5 4 3 2 1 MSB 6 5 4 3 2 1 LSB LSB NSS (to slave) *** Not Defined, but normaly LSB of previous character transmitted 26.7.3 Master Mode Operations When configured in master mode, the SPI uses the internal programmable baud rate generator as clock source. It fully controls the data transfers to and from the slave(s) connected to the SPI bus. The SPI drives the chip select line to the slave and the serial clock signal (SPCK). The SPI features two holding registers, the Transmit Data Register (TDR) and the Receive Data Register (RDR), and a single Shift Register. The holding registers maintain the data flow at a constant rate. After enabling the SPI, a data transfer begins when the processor writes to the TDR register. The written data is immediately transferred in the Shift Register and transfer on the SPI bus starts. While the data in the Shift Register is shifted on the MOSI line, the MISO line is sampled and shifted in the Shift Register. Transmission cannot occur without reception. Before writing to the TDR, the Peripheral Chip Select field in TDR (TDR.PCS) must be written in order to select a slave. If new data is written to TDR during the transfer, it stays in it until the current transfer is completed. Then, the received data is transferred from the Shift Register to RDR, the data in TDR is loaded in the Shift Register and a new transfer starts. The transfer of a data written in TDR in the Shift Register is indicated by the Transmit Data Register Empty bit in the Status Register (SR.TDRE). When new data is written in TDR, this bit is cleared. The SR.TDRE bit is used to trigger the Transmit Peripheral DMA Controller channel. The end of transfer is indicated by the Transmission Registers Empty bit in the SR register (SR.TXEMPTY). If a transfer delay (CSRn.DLYBCT) is greater than zero for the last transfer, SR.TXEMPTY is set after the completion of said delay. The CLK_SPI can be switched off at this time. During reception, received data are transferred from the Shift Register to the reception FIFO. The FIFO can contain up to 4 characters (both Receive Data and Peripheral Chip Select fields). While a character of the FIFO is unread, the Receive Data Register Full bit in SR remains high (SR.RDRF). Characters are read through the RDR register. If the four characters stored in the FIFO are not read and if a new character is stored, this sets the Overrun Error Status bit in the SR register (SR.OVRES). The procedure to follow in such a case is described in Section 26.7.3.8. 658 32117A-10/2010 AT32UC3C Figure 26-5 on page 659shows a block diagram of the SPI when operating in master mode. Figure 26-6 on page 660 shows a flow chart describing how transfers are handled. 26.7.3.1 Master mode block diagram Figure 26-5. Master Mode Block Diagram CSR0..3 SCBR CLK_SPI Baud Rate Generator SPCK SPI Clock CSR0..3 RXFIFOEN BITS NCPHA 0 1 CPOL LSB MISO RDR TDR 4 - Character FIFO MSB Shift Register RDRF OVRES RD TD MOSI TDRE RXFIFOEN RDR CSR0..3 CSNAAT CSAAT PS MR 0 1 4 - Character FIFO NPCS3 PCSDEC PCS 0 TDR NPCS2 Current Peripheral NPCS1 PCS NPCS0 1 MSTR MODF NPCS0 MODFDIS 659 32117A-10/2010 AT32UC3C 26.7.3.2 Master mode flow diagram Figure 26-6. Master Mode Flow Diagram SPI Enable - NPCS defines the current Chip Select - CSAAT, DLYBS, DLYBCT refer to the fields of the Chip Select Register corresponding to the Current Chip Select - When NPCS is 0xF, CSAAT is 0. 1 TDRE ? 0 1 CSAAT ? PS ? 0 1 0 Fixed peripheral PS ? 1 Fixed peripheral 0 Variable peripheral Variable peripheral TDR(PCS) = NPCS ? no NPCS = TDR(PCS) NPCS = MR(PCS) yes MR(PCS) = NPCS ? no NPCS = 0xF NPCS = 0xF Delay DLYBCS Delay DLYBCS NPCS = TDR(PCS) NPCS = MR(PCS), TDR(PCS) Delay DLYBS Serializer = TDR(TD) TDRE = 1 Data Transfer RDR(RD) = Serializer RDRF = 1 Delay DLYBCT 0 TDRE ? 1 1 CSAAT ? 0 NPCS = 0xF Delay DLYBCS 660 32117A-10/2010 AT32UC3C 26.7.3.3 Clock generation The SPI Baud rate clock is generated by dividing the CLK_SPI , by a value between 1 and 255. This allows a maximum operating baud rate at up to CLK_SPI and a minimum operating baud rate of CLK_SPI divided by 255. Writing the Serial Clock Baud Rate field in the CSRn registers (CSRn.SCBR) to zero is forbidden. Triggering a transfer while CSRn.SCBR is zero can lead to unpredictable results. At reset, CSRn.SCBR is zero and the user has to configure it at a valid value before performing the first transfer. The divisor can be defined independently for each chip select, as it has to be configured in the CSRn.SCBR field. This allows the SPI to automatically adapt the baud rate for each interfaced peripheral without reprogramming. 26.7.3.4 Transfer delays Figure 26-7 on page 661 shows a chip select transfer change and consecutive transfers on the same chip select. Three delays can be configured to modify the transfer waveforms: * The delay between chip selects, programmable only once for all the chip selects by writing to the Delay Between Chip Selects field in the MR register (MR.DLYBCS). Allows insertion of a delay between release of one chip select and before assertion of a new one. * The delay before SPCK, independently programmable for each chip select by writing the Delay Before SPCK field in the CSRn registers (CSRn.DLYBS). Allows the start of SPCK to be delayed after the chip select has been asserted. * The delay between consecutive transfers, independently programmable for each chip select by writing the Delay Between Consecutive Transfers field in the CSRn registers (CSRn.DLYBCT). Allows insertion of a delay between two transfers occurring on the same chip select These delays allow the SPI to be adapted to the interfaced peripherals and their speed and bus release time. Figure 26-7. Programmable Delays Chip Select 1 Chip Select 2 SPCK DLYBCS DLYBS DLYBCT DLYBCT 661 32117A-10/2010 AT32UC3C 26.7.3.5 Peripheral selection The serial peripherals are selected through the assertion of the NPCS0 to NPCS3 signals. By default, all the NPCS signals are high before and after each transfer. The peripheral selection can be performed in two different ways: * Fixed Peripheral Select: SPI exchanges data with only one peripheral * Variable Peripheral Select: Data can be exchanged with more than one peripheral Fixed Peripheral Select is activated by writing a zero to the Peripheral Select bit in MR (MR.PS). In this case, the current peripheral is defined by the MR.PCS field and the TDR.PCS field has no effect. Variable Peripheral Select is activated by writing a one to the MR.PS bit . The TDR.PCS field is used to select the current peripheral. This means that the peripheral selection can be defined for each new data. The Fixed Peripheral Selection allows buffer transfers with a single peripheral. Using the Peripheral DMA Controller is an optimal means, as the size of the data transfer between the memory and the SPI is either 4 bits or 16 bits. However, changing the peripheral selection requires the Mode Register to be reprogrammed. The Variable Peripheral Selection allows buffer transfers with multiple peripherals without reprogramming the MR register. Data written to TDR is 32-bits wide and defines the real data to be transmitted and the peripheral it is destined to. Using the Peripheral DMA Controller in this mode requires 32-bit wide buffers, with the data in the LSBs and the PCS and LASTXFER fields in the MSBs, however the SPI still controls the number of bits (8 to16) to be transferred through MISO and MOSI lines with the CSRn registers. This is not the optimal means in term of memory size for the buffers, but it provides a very effective means to exchange data with several peripherals without any intervention of the processor. 26.7.3.6 Peripheral chip select decoding The user can configure the SPI to operate with up to 15 peripherals by decoding the four Chip Select lines, NPCS0 to NPCS3 with an external logic. This can be enabled by writing a one to the Chip Select Decode bit in the MR register (MR.PCSDEC). When operating without decoding, the SPI makes sure that in any case only one chip select line is activated, i.e. driven low at a time. If two bits are defined low in a PCS field, only the lowest numbered chip select is driven low. When operating with decoding, the SPI directly outputs the value defined by the PCS field of either the MR register or the TDR register (depending on PS). As the SPI sets a default value of 0xF on the chip select lines (i.e. all chip select lines at one) when not processing any transfer, only 15 peripherals can be decoded. The SPI has only four Chip Select Registers, not 15. As a result, when decoding is activated, each chip select defines the characteristics of up to four peripherals. As an example, the CRS0 register defines the characteristics of the externally decoded peripherals 0 to 3, corresponding to the PCS values 0x0 to 0x3. Thus, the user has to make sure to connect compatible peripherals on the decoded chip select lines 0 to 3, 4 to 7, 8 to 11 and 12 to 14. 26.7.3.7 Peripheral deselection When operating normally, as soon as the transfer of the last data written in TDR is completed, the NPCS lines all rise. This might lead to runtime error if the processor is too long in responding 662 32117A-10/2010 AT32UC3C to an interrupt, and thus might lead to difficulties for interfacing with some serial peripherals requiring the chip select line to remain active during a full set of transfers. To facilitate interfacing with such devices, the CSRn registers can be configured with the Chip Select Active After Transfer bit written to one (CSRn.CSAAT) . This allows the chip select lines to remain in their current state (low = active) until transfer to another peripheral is required. When the CSRn.CSAAT bit is written to qero, the NPCS does not rise in all cases between two transfers on the same peripheral. During a transfer on a Chip Select, the SR.TDRE bit rises as soon as the content of the TDR is transferred into the internal shifter. When this bit is detected the TDR can be reloaded. If this reload occurs before the end of the current transfer and if the next transfer is performed on the same chip select as the current transfer, the Chip Select is not de-asserted between the two transfers. This might lead to difficulties for interfacing with some serial peripherals requiring the chip select to be de-asserted after each transfer. To facilitate interfacing with such devices, the CSRn registers can be configured with the Chip Select Not Active After Transfer bit (CSRn.CSNAAT) written to one. This allows to de-assert systematically the chip select lines during a time DLYBCS. (The value of the CSRn.CSNAAT bit is taken into account only if the CSRn.CSAAT bit is written to zero for the same Chip Select). Figure 26-8 on page 664 shows different peripheral deselection cases and the effect of the CSRn.CSAAT and CSRn.CSNAAT bits. 26.7.3.8 FIFO management A FIFO has been implemented in Reception FIFO (both in master and in slave mode), in order to be able to store up to 4 characters without causing an overrun error. If an attempt is made to store a fifth character, an overrun error rises. If such an event occurs, the FIFO must be flushed. There are two ways to Flush the FIFO: * By performing four read accesses of the RDR (the data read must be ignored) * By writing a one to the Flush Fifo Command bit in the CR register (CR.FLUSHFIFO). After that, the SPI is able to receive new data. 663 32117A-10/2010 AT32UC3C Figure 26-8. Peripheral Deselection CSAAT = 0 and CSNAAT = 0 TDRE NPCS[0..3] CSAAT = 1 and CSNAAT= 0 / 1 DLYBCT DLYBCT A A A A DLYBCS A DLYBCS PCS = A PCS = A Write TDR TDRE NPCS[0..3] DLYBCT DLYBCT A A A A DLYBCS A DLYBCS PCS=A PCS = A Write TDR TDRE NPCS[0..3] DLYBCT DLYBCT A B B A DLYBCS DLYBCS PCS = B PCS = B Write TDR CSAAT = 0 and CSNAAT = 0 CSAAT = 0 and CSNAAT = 1 DLYBCT DLYBCT TDRE NPCS[0..3] A A A A DLYBCS PCS = A PCS = A Write TDR Figure 26-8 on page 664 shows different peripheral deselection cases and the effect of the CSRn.CSAAT and CSRn.CSNAAT bits. 26.7.3.9 Mode fault detection The SPI is capable of detecting a mode fault when it is configured in master mode and NPCS0, MOSI, MISO, and SPCK are configured as open drain through the I/O Controller with either internal or external pullup resistors. If the I/O Controller does not have open-drain capability, mode fault detection must be disabled by writing a one to the Mode Fault Detection bit in the MR 664 32117A-10/2010 AT32UC3C register (MR.MODFDIS). In systems with open-drain I/O lines, a mode fault is detected when a low level is driven by an external master on the NPCS0/NSS signal. When a mode fault is detected, the Mode Fault Error bit in the SR (SR.MODF) is set until the SR is read and the SPI is automatically disabled until re-enabled by writing a one to the SPI Enable bit in the CR register (CR.SPIEN). By default, the mode fault detection circuitry is enabled. The user can disable mode fault detection by writing a one to the Mode Fault Detection bit in the MR register (MR.MODFDIS). 26.7.4 SPI Slave Mode When operating in slave mode, the SPI processes data bits on the clock provided on the SPI clock pin (SPCK). The SPI waits for NSS to go active before receiving the serial clock from an external master. When NSS falls, the clock is validated on the serializer, which processes the number of bits defined by the Bits Per Transfer field of the Chip Select Register 0 (CSR0.BITS). These bits are processed following a phase and a polarity defined respectively by the CSR0.NCPHA and CSR0.CPOL bits. Note that the BITS, CPOL, and NCPHA bits of the other Chip Select Registers have no effect when the SPI is configured in Slave Mode. The bits are shifted out on the MISO line and sampled on the MOSI line. When all the bits are processed, the received data is transferred in the Receive Data Register and the SR.RDRF bit rises. If the RDR register has not been read before new data is received, the SR.OVRES bit is set. Data is loaded in RDR even if this flag is set. The user has to read the SR register to clear the SR.OVRES bit. When a transfer starts, the data shifted out is the data present in the Shift Register. If no data has been written in the TDR register, the last data received is transferred. If no data has been received since the last reset, all bits are transmitted low, as the Shift Register resets to zero. When a first data is written in TDR, it is transferred immediately in the Shift Register and the SR.TDRE bit rises. If new data is written, it remains in TDR until a transfer occurs, i.e. NSS falls and there is a valid clock on the SPCK pin. When the transfer occurs, the last data written in TDR is transferred in the Shift Register and the SR.TDRE bit rises. This enables frequent updates of critical variables with single transfers. Then, a new data is loaded in the Shift Register from the TDR. In case no character is ready to be transmitted, i.e. no character has been written in TDR since the last load from TDR to the Shift Register, the Shift Register is not modified and the last received character is retransmitted. In this case the Underrun Error Status bit is set in SR (SR.UNDES). Figure 26-9 on page 666 shows a block diagram of the SPI when operating in slave mode. 665 32117A-10/2010 AT32UC3C Figure 26-9. Slave Mode Functional Block Diagram SPCK SPI Clock NSS SPIEN RXFIFOEN SPIENS RDR SPIDIS RDRF OVRES RD CSR0 BITS NCPHA CPOL MOSI LSB 0 1 4 - Character FIFO MSB Shift Register MISO UNDES TDR TD TDRE 666 32117A-10/2010 AT32UC3C 26.8 User Interface Table 26-3. Note: SPI Register Memory Map Offset Register Register Name Access Reset 0x00 Control Register CR Write-only 0x00000000 0x04 Mode Register MR Read/Write 0x00000000 0x08 Receive Data Register RDR Read-only 0x00000000 0x0C Transmit Data Register TDR Write-only 0x00000000 0x10 Status Register SR Read-only 0x00000000 0x14 Interrupt Enable Register IER Write-only 0x00000000 0x18 Interrupt Disable Register IDR Write-only 0x00000000 0x1C Interrupt Mask Register IMR Read-only 0x00000000 0x30 Chip Select Register 0 CSR0 Read/Write 0x00000000 0x34 Chip Select Register 1 CSR1 Read/Write 0x00000000 0x38 Chip Select Register 2 CSR2 Read/Write 0x00000000 0x3C Chip Select Register 3 CSR3 Read/Write 0x00000000 0x E4 Write Protection Control Register WPCR Read/Write 0X00000000 0xE8 Write Protection Status Register WPSR Read-only 0x00000000 0xF8 Features Register FEATURES Read-only - (1) 0xFC Version Register VERSION Read-only - (1) 1. The reset values are device specific. Please refer to the Module Configuration section at the end of this chapter. 667 32117A-10/2010 AT32UC3C 26.8.1 Name: Control Register CR Access Type: Write-only Offset: 0x00 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - LASTXFER 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 - - - - - - - FLUSHFIFO 7 6 5 4 3 2 1 0 SWRST - - - - - SPIDIS SPIEN * LASTXFER: Last Transfer 1: The current NPCS will be deasserted after the character written in TD has been transferred. When CSRn.CSAAT is one, this allows to close the communication with the current serial peripheral by raising the corresponding NPCS line as soon as TD transfer has completed. 0: Writing a zero to this bit has no effect. * FLUSHFIFO: Flush Fifo Command 1: If The FIFO Mode is enabled (MR.FIFOEN written to one) and if an overrun error has been detected, this command allows to empty the FIFO. 0: Writing a zero to this bit has no effect. * SWRST: SPI Software Reset 1: Writing a one to this bit will reset the SPI. A software-triggered hardware reset of the SPI interface is performed. The SPI is in slave mode after software reset. Peripheral DMA Controller channels are not affected by software reset. 0: Writing a zero to this bit has no effect. * SPIDIS: SPI Disable 1: Writing a one to this bit will disable the SPI. As soon as SPIDIS is written to one, the SPI finishes its transfer, all pins are set in input mode and no data is received or transmitted. If a transfer is in progress, the transfer is finished before the SPI is disabled. If both SPIEN and SPIDIS are equal to one when the CR register is written, the SPI is disabled. 0: Writing a zero to this bit has no effect. * SPIEN: SPI Enable 1: Writing a one to this bit will enable the SPI to transfer and receive data. 0: Writing a zero to this bit has no effect. 668 32117A-10/2010 AT32UC3C 26.8.2 Name: Mode Register MR Access Type: Read/Write Offset: 0x04 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 19 18 17 16 DLYBCS 23 22 21 20 - - - - 15 14 13 12 11 10 9 8 - - - - - - - - 7 6 5 4 3 2 1 0 LLB RXFIFOEN - MODFDIS - PCSDEC PS MSTR PCS * DLYBCS: Delay Between Chip Selects This field defines the delay from NPCS inactive to the activation of another NPCS. The DLYBCS time guarantees nonoverlapping chip selects and solves bus contentions in case of peripherals having long data float times. If DLYBCS is less than or equal to six, six CLK_SPI periods will be inserted by default. Otherwise, the following equation determines the delay: Delay Between Chip Selects = DLYBCS ----------------------CLKSPI * PCS: Peripheral Chip Select This field is only used if Fixed Peripheral Select is active (PS = 0). If PCSDEC = 0: PCS = xxx0NPCS[3:0] = 1110 PCS = xx01NPCS[3:0] = 1101 PCS = x011NPCS[3:0] = 1011 PCS = 0111NPCS[3:0] = 0111 PCS = 1111forbidden (no peripheral is selected) (x = don't care) If PCSDEC = 1: NPCS[3:0] output signals = PCS. * LLB: Local Loopback Enable 1: Local loopback path enabled. LLB controls the local loopback on the data serializer for testing in master mode only (MISO is internally connected on MOSI). 0: Local loopback path disabled. * RXFIFOEN: FIFO in Reception Enable 1: The FIFO is used in reception (four characters can be stored in the SPI). 669 32117A-10/2010 AT32UC3C 0: The FIFO is not used in reception (only one character can be stored in the SPI). * MODFDIS: Mode Fault Detection 1: Mode fault detection is disabled. If the I/O controller does not have open-drain capability, mode fault detection must be disabled for proper operation of the SPI. 0: Mode fault detection is enabled. * PCSDEC: Chip Select Decode 0: The chip selects are directly connected to a peripheral device. 1: The four chip select lines are connected to a 4- to 16-bit decoder. When PCSDEC equals one, up to 15 Chip Select signals can be generated with the four lines using an external 4- to 16-bit decoder. The CSRn registers define the characteristics of the 15 chip selects according to the following rules: CSR0 defines peripheral chip select signals 0 to 3. CSR1 defines peripheral chip select signals 4 to 7. CSR2 defines peripheral chip select signals 8 to 11. CSR3 defines peripheral chip select signals 12 to 14. * PS: Peripheral Select 1: Variable Peripheral Select. 0: Fixed Peripheral Select. * MSTR: Master/Slave Mode 1: SPI is in master mode. 0: SPI is in slave mode. 670 32117A-10/2010 AT32UC3C 26.8.3 Name: Receive Data Register RDR Access Type: Read-only Offset: 0x08 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 3 2 1 0 RD[15:8] 7 6 5 4 RD[7:0] * RD: Receive Data Data received by the SPI Interface is stored in this register right-justified. Unused bits read zero. 671 32117A-10/2010 AT32UC3C 26.8.4 Name: Transmit Data Register TDR Access Type: Write-only Offset: 0x0C Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - LASTXFER 23 22 21 20 19 18 17 16 - - - - 15 14 13 12 PCS 11 10 9 8 3 2 1 0 TD[15:8] 7 6 5 4 TD[7:0] * LASTXFER: Last Transfer 1: The current NPCS will be deasserted after the character written in TD has been transferred. When CSRn.CSAAT is one, this allows to close the communication with the current serial peripheral by raising the corresponding NPCS line as soon as TD transfer has completed. 0: Writing a zero to this bit has no effect. This field is only used if Variable Peripheral Select is active (MR.PS = 1). * PCS: Peripheral Chip Select If PCSDEC = 0: PCS = xxx0NPCS[3:0] = 1110 PCS = xx01NPCS[3:0] = 1101 PCS = x011NPCS[3:0] = 1011 PCS = 0111NPCS[3:0] = 0111 PCS = 1111forbidden (no peripheral is selected) (x = don't care) If PCSDEC = 1: NPCS[3:0] output signals = PCS This field is only used if Variable Peripheral Select is active (MR.PS = 1). * TD: Transmit Data Data to be transmitted by the SPI Interface is stored in this register. Information to be transmitted must be written to the TDR register in a right-justified format. 672 32117A-10/2010 AT32UC3C 26.8.5 Name: Status Register SR Access Type: Read-only Offset: 0x10 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - SPIENS 15 14 13 12 11 10 9 8 - - - - - UNDES TXEMPTY NSSR 7 6 5 4 3 2 1 0 - - - - OVRES MODF TDRE RDRF * SPIENS: SPI Enable Status 1: This bit is set when the SPI is enabled. 0: This bit is cleared when the SPI is disabled. * UNDES: Underrun Error Status (Slave Mode Only) 1: This bit is set when a transfer begins whereas no data has been loaded in the TDR register. 0: This bit is cleared when the SR register is read. * TXEMPTY: Transmission Registers Empty 1: This bit is set when TDR and internal shifter are empty. If a transfer delay has been defined, TXEMPTY is set after the completion of such delay. 0: This bit is cleared as soon as data is written in TDR. * NSSR: NSS Rising 1: A rising edge occurred on NSS pin since last read. 0: This bit is cleared when the SR register is read. * OVRES: Overrun Error Status 1: This bit is set when an overrun has occurred. An overrun occurs when RDR is loaded at least twice from the serializer since the last read of the RDR. 0: This bit is cleared when the SR register is read. * MODF: Mode Fault Error 1: This bit is set when a Mode Fault occurred. 0: This bit is cleared when the SR register is read. * TDRE: Transmit Data Register Empty 1: This bit is set when the last data written in the TDR register has been transferred to the serializer. 0: This bit is cleared when data has been written to TDR and not yet transferred to the serializer. TDRE equals zero when the SPI is disabled or at reset. The SPI enable command sets this bit to one. * RDRF: Receive Data Register Full 1: Data has been received and the received data has been transferred from the serializer to RDR since the last read of RDR. 0: No data has been received since the last read of RDR 673 32117A-10/2010 AT32UC3C 26.8.6 Name: Interrupt Enable Register IER Access Type: Write-only Offset: 0x14 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 - - - - - UNDES TXEMPTY NSSR 7 6 5 4 3 2 1 0 - - - - OVRES MODF TDRE RDRF Writing a zero to a bit in this register has no effect. Writing a one to a bit in this register will set the corresponding bit in IMR. 674 32117A-10/2010 AT32UC3C 26.8.7 Name: Interrupt Disable Register IDR Access Type: Write-only Offset: 0x18 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 - - - - - UNDES TXEMPTY NSSR 7 6 5 4 3 2 1 0 - - - - OVRES MODF TDRE RDRF Writing a zero to a bit in this register has no effect. Writing a one to a bit in this register will clear the corresponding bit in IMR. 675 32117A-10/2010 AT32UC3C 26.8.8 Name: Interrupt Mask Register IMR Access Type: Read-only Offset: 0x1C Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 - - - - - UNDES TXEMPTY NSSR 7 6 5 4 3 2 1 0 - - - - OVRES MODF TDRE RDRF 0: The corresponding interrupt is disabled. 1: The corresponding interrupt is enabled. A bit in this register is cleared when the corresponding bit in IDR is written to one. A bit in this register is set when the corresponding bit in IER is written to one. 676 32117A-10/2010 AT32UC3C 26.8.9 Name: Chip Select Register 0 CSR0 Access Type: Read/Write Offset: 0x30 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 19 18 17 16 11 10 9 8 3 2 1 0 CSAAT CSNAAT NCPHA CPOL DLYBCT 23 22 21 20 DLYBS 15 14 13 12 SCBR 7 6 5 BITS 4 * DLYBCT: Delay Between Consecutive Transfers This field defines the delay between two consecutive transfers with the same peripheral without removing the chip select. The delay is always inserted after each transfer and before removing the chip select if needed. When DLYBCT equals zero, no delay between consecutive transfers is inserted and the clock keeps its duty cycle over the character transfers. Otherwise, the following equation determines the delay: 32 x DLYBCT Delay Between Consecutive Transfers = -----------------------------------CLKSPI * DLYBS: Delay Before SPCK This field defines the delay from NPCS valid to the first valid SPCK transition. When DLYBS equals zero, the NPCS valid to SPCK transition is 1/2 the SPCK clock period. Otherwise, the following equations determine the delay: DLYBSDelay Before SPCK = -------------------CLKSPI * SCBR: Serial Clock Baud Rate In Master Mode, the SPI Interface uses a modulus counter to derive the SPCK baud rate from the CLK_SPI. The Baud rate is selected by writing a value from 1 to 255 in the SCBR field. The following equations determine the SPCK baud rate: CLKSPI SPCK Baudrate = --------------------SCBR Writing the SCBR field to zero is forbidden. Triggering a transfer while SCBR is zero can lead to unpredictable results. At reset, SCBR is zero and the user has to write it to a valid value before performing the first transfer. If a clock divider (SCBRn) field is set to one and the other SCBR fields differ from one, access on CSn is correct but no correct access will be possible on other CS. 677 32117A-10/2010 AT32UC3C * BITS: Bits Per Transfer The BITS field determines the number of data bits transferred. Reserved values should not be used. BITS Bits Per Transfer 0000 8 0001 9 0010 10 0011 11 0100 12 0101 13 0110 14 0111 15 1000 16 1001 4 1010 5 1011 6 1100 7 1101 Reserved 1110 Reserved 1111 Reserved * CSAAT: Chip Select Active After Transfer 1: The Peripheral Chip Select does not rise after the last transfer is achieved. It remains active until a new transfer is requested on a different chip select. 0: The Peripheral Chip Select Line rises as soon as the last transfer is achieved. * CSNAAT: Chip Select Not Active After Transfer (Ignored if CSAAT = 1) 0: The Peripheral Chip Select does not rise between two transfers if the TDR is reloaded before the end of the first transfer and if the two transfers occur on the same Chip Select. 1: The Peripheral Chip Select rises systematically between each transfer performed on the same slave for a minimal duration of: DLYBCS ----------------------- (if DLYBCT field is different from 0) CLKSPI DLYBCS + 1- (if DLYBCT field equals 0) -------------------------------CLKSPI * NCPHA: Clock Phase 1: Data is captured after the leading (inactive-to-active) edge of SPCK and changed on the trailing (active-to-inactive) edge of SPCK. 0: Data is changed on the leading (inactive-to-active) edge of SPCK and captured after the trailing (active-to-inactive) edge of SPCK. NCPHA determines which edge of SPCK causes data to change and which edge causes data to be captured. NCPHA is used with CPOL to produce the required clock/data relationship between master and slave devices. * CPOL: Clock Polarity 1: The inactive state value of SPCK is logic level one. 0: The inactive state value of SPCK is logic level zero. 678 32117A-10/2010 AT32UC3C CPOL is used to determine the inactive state value of the serial clock (SPCK). It is used with NCPHA to produce the required clock/data relationship between master and slave devices. 679 32117A-10/2010 AT32UC3C 26.8.10 Name: Chip Select Register 1 CSR1 Access Type: Read/Write Offset: 0x34 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 19 18 17 16 11 10 9 8 3 2 1 0 CSAAT CSNAAT NCPHA CPOL DLYBCT 23 22 21 20 DLYBS 15 14 13 12 SCBR 7 6 5 BITS 4 * DLYBCT: Delay Between Consecutive Transfers This field defines the delay between two consecutive transfers with the same peripheral without removing the chip select. The delay is always inserted after each transfer and before removing the chip select if needed. When DLYBCT equals zero, no delay between consecutive transfers is inserted and the clock keeps its duty cycle over the character transfers. Otherwise, the following equation determines the delay: 32 x DLYBCT Delay Between Consecutive Transfers = -----------------------------------CLKSPI * DLYBS: Delay Before SPCK This field defines the delay from NPCS valid to the first valid SPCK transition. When DLYBS equals zero, the NPCS valid to SPCK transition is 1/2 the SPCK clock period. Otherwise, the following equations determine the delay: DLYBSDelay Before SPCK = -------------------CLKSPI * SCBR: Serial Clock Baud Rate In Master Mode, the SPI Interface uses a modulus counter to derive the SPCK baud rate from the CLK_SPI. The Baud rate is selected by writing a value from 1 to 255 in the SCBR field. The following equations determine the SPCK baud rate: CLKSPI SPCK Baudrate = --------------------SCBR Writing the SCBR field to zero is forbidden. Triggering a transfer while SCBR is zero can lead to unpredictable results. At reset, SCBR is zero and the user has to write it to a valid value before performing the first transfer. If a clock divider (SCBRn) field is set to one and the other SCBR fields differ from one, access on CSn is correct but no correct access will be possible on other CS. 680 32117A-10/2010 AT32UC3C * BITS: Bits Per Transfer The BITS field determines the number of data bits transferred. Reserved values should not be used. BITS Bits Per Transfer 0000 8 0001 9 0010 10 0011 11 0100 12 0101 13 0110 14 0111 15 1000 16 1001 4 1010 5 1011 6 1100 7 1101 Reserved 1110 Reserved 1111 Reserved * CSAAT: Chip Select Active After Transfer 1: The Peripheral Chip Select does not rise after the last transfer is achieved. It remains active until a new transfer is requested on a different chip select. 0: The Peripheral Chip Select Line rises as soon as the last transfer is achieved. * CSNAAT: Chip Select Not Active After Transfer (Ignored if CSAAT = 1) 0: The Peripheral Chip Select does not rise between two transfers if the TDR is reloaded before the end of the first transfer and if the two transfers occur on the same Chip Select. 1: The Peripheral Chip Select rises systematically between each transfer performed on the same slave for a minimal duration of: DLYBCS ----------------------- (if DLYBCT field is different from 0) CLKSPI DLYBCS + 1- (if DLYBCT field equals 0) -------------------------------CLKSPI * NCPHA: Clock Phase 1: Data is captured after the leading (inactive-to-active) edge of SPCK and changed on the trailing (active-to-inactive) edge of SPCK. 0: Data is changed on the leading (inactive-to-active) edge of SPCK and captured after the trailing (active-to-inactive) edge of SPCK. NCPHA determines which edge of SPCK causes data to change and which edge causes data to be captured. NCPHA is used with CPOL to produce the required clock/data relationship between master and slave devices. * CPOL: Clock Polarity 1: The inactive state value of SPCK is logic level one. 0: The inactive state value of SPCK is logic level zero. 681 32117A-10/2010 AT32UC3C CPOL is used to determine the inactive state value of the serial clock (SPCK). It is used with NCPHA to produce the required clock/data relationship between master and slave devices. 682 32117A-10/2010 AT32UC3C 26.8.11 Name: Chip Select Register 2 CSR2 Access Type: Read/Write Offset: 0x38 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 19 18 17 16 11 10 9 8 3 2 1 0 CSAAT CSNAAT NCPHA CPOL DLYBCT 23 22 21 20 DLYBS 15 14 13 12 SCBR 7 6 5 BITS 4 * DLYBCT: Delay Between Consecutive Transfers This field defines the delay between two consecutive transfers with the same peripheral without removing the chip select. The delay is always inserted after each transfer and before removing the chip select if needed. When DLYBCT equals zero, no delay between consecutive transfers is inserted and the clock keeps its duty cycle over the character transfers. Otherwise, the following equation determines the delay: 32 x DLYBCT Delay Between Consecutive Transfers = -----------------------------------CLKSPI * DLYBS: Delay Before SPCK This field defines the delay from NPCS valid to the first valid SPCK transition. When DLYBS equals zero, the NPCS valid to SPCK transition is 1/2 the SPCK clock period. Otherwise, the following equations determine the delay: DLYBSDelay Before SPCK = -------------------CLKSPI * SCBR: Serial Clock Baud Rate In Master Mode, the SPI Interface uses a modulus counter to derive the SPCK baud rate from the CLK_SPI. The Baud rate is selected by writing a value from 1 to 255 in the SCBR field. The following equations determine the SPCK baud rate: CLKSPI SPCK Baudrate = --------------------SCBR Writing the SCBR field to zero is forbidden. Triggering a transfer while SCBR is zero can lead to unpredictable results. At reset, SCBR is zero and the user has to write it to a valid value before performing the first transfer. If a clock divider (SCBRn) field is set to one and the other SCBR fields differ from one, access on CSn is correct but no correct access will be possible on other CS. 683 32117A-10/2010 AT32UC3C * BITS: Bits Per Transfer The BITS field determines the number of data bits transferred. Reserved values should not be used. BITS Bits Per Transfer 0000 8 0001 9 0010 10 0011 11 0100 12 0101 13 0110 14 0111 15 1000 16 1001 4 1010 5 1011 6 1100 7 1101 Reserved 1110 Reserved 1111 Reserved * CSAAT: Chip Select Active After Transfer 1: The Peripheral Chip Select does not rise after the last transfer is achieved. It remains active until a new transfer is requested on a different chip select. 0: The Peripheral Chip Select Line rises as soon as the last transfer is achieved. * CSNAAT: Chip Select Not Active After Transfer (Ignored if CSAAT = 1) 0: The Peripheral Chip Select does not rise between two transfers if the TDR is reloaded before the end of the first transfer and if the two transfers occur on the same Chip Select. 1: The Peripheral Chip Select rises systematically between each transfer performed on the same slave for a minimal duration of: DLYBCS ----------------------- (if DLYBCT field is different from 0) CLKSPI DLYBCS + 1- (if DLYBCT field equals 0) -------------------------------CLKSPI * NCPHA: Clock Phase 1: Data is captured after the leading (inactive-to-active) edge of SPCK and changed on the trailing (active-to-inactive) edge of SPCK. 0: Data is changed on the leading (inactive-to-active) edge of SPCK and captured after the trailing (active-to-inactive) edge of SPCK. NCPHA determines which edge of SPCK causes data to change and which edge causes data to be captured. NCPHA is used with CPOL to produce the required clock/data relationship between master and slave devices. * CPOL: Clock Polarity 1: The inactive state value of SPCK is logic level one. 0: The inactive state value of SPCK is logic level zero. 684 32117A-10/2010 AT32UC3C CPOL is used to determine the inactive state value of the serial clock (SPCK). It is used with NCPHA to produce the required clock/data relationship between master and slave devices. 685 32117A-10/2010 AT32UC3C 26.8.12 Name: Chip Select Register 3 CSR3 Access Type: Read/Write Offset: 0x3C Reset Value: 0x00000000 31 30 29 28 27 26 25 24 19 18 17 16 11 10 9 8 3 2 1 0 CSAAT CSNAAT NCPHA CPOL DLYBCT 23 22 21 20 DLYBS 15 14 13 12 SCBR 7 6 5 BITS 4 * DLYBCT: Delay Between Consecutive Transfers This field defines the delay between two consecutive transfers with the same peripheral without removing the chip select. The delay is always inserted after each transfer and before removing the chip select if needed. When DLYBCT equals zero, no delay between consecutive transfers is inserted and the clock keeps its duty cycle over the character transfers. Otherwise, the following equation determines the delay: 32 x DLYBCT Delay Between Consecutive Transfers = -----------------------------------CLKSPI * DLYBS: Delay Before SPCK This field defines the delay from NPCS valid to the first valid SPCK transition. When DLYBS equals zero, the NPCS valid to SPCK transition is 1/2 the SPCK clock period. Otherwise, the following equations determine the delay: DLYBSDelay Before SPCK = -------------------CLKSPI * SCBR: Serial Clock Baud Rate In Master Mode, the SPI Interface uses a modulus counter to derive the SPCK baud rate from the CLK_SPI. The Baud rate is selected by writing a value from 1 to 255 in the SCBR field. The following equations determine the SPCK baud rate: CLKSPI SPCK Baudrate = --------------------SCBR Writing the SCBR field to zero is forbidden. Triggering a transfer while SCBR is zero can lead to unpredictable results. At reset, SCBR is zero and the user has to write it to a valid value before performing the first transfer. If a clock divider (SCBRn) field is set to one and the other SCBR fields differ from one, access on CSn is correct but no correct access will be possible on other CS. 686 32117A-10/2010 AT32UC3C * BITS: Bits Per Transfer The BITS field determines the number of data bits transferred. Reserved values should not be used. BITS Bits Per Transfer 0000 8 0001 9 0010 10 0011 11 0100 12 0101 13 0110 14 0111 15 1000 16 1001 4 1010 5 1011 6 1100 7 1101 Reserved 1110 Reserved 1111 Reserved * CSAAT: Chip Select Active After Transfer 1: The Peripheral Chip Select does not rise after the last transfer is achieved. It remains active until a new transfer is requested on a different chip select. 0: The Peripheral Chip Select Line rises as soon as the last transfer is achieved. * CSNAAT: Chip Select Not Active After Transfer (Ignored if CSAAT = 1) 0: The Peripheral Chip Select does not rise between two transfers if the TDR is reloaded before the end of the first transfer and if the two transfers occur on the same Chip Select. 1: The Peripheral Chip Select rises systematically between each transfer performed on the same slave for a minimal duration of: DLYBCS ----------------------- (if DLYBCT field is different from 0) CLKSPI DLYBCS + 1- (if DLYBCT field equals 0) -------------------------------CLKSPI * NCPHA: Clock Phase 1: Data is captured after the leading (inactive-to-active) edge of SPCK and changed on the trailing (active-to-inactive) edge of SPCK. 0: Data is changed on the leading (inactive-to-active) edge of SPCK and captured after the trailing (active-to-inactive) edge of SPCK. NCPHA determines which edge of SPCK causes data to change and which edge causes data to be captured. NCPHA is used with CPOL to produce the required clock/data relationship between master and slave devices. * CPOL: Clock Polarity 1: The inactive state value of SPCK is logic level one. 0: The inactive state value of SPCK is logic level zero. 687 32117A-10/2010 AT32UC3C CPOL is used to determine the inactive state value of the serial clock (SPCK). It is used with NCPHA to produce the required clock/data relationship between master and slave devices. 688 32117A-10/2010 AT32UC3C 26.8.13 Write Protection Control Register Register Name: WPCR Access Type: Read-write Offset: 0xE4 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 18 17 16 10 9 8 SPIWPKEY[23:16] 23 22 21 20 19 SPIWPKEY[15:8] 15 14 13 12 11 SPIWPKEY[7:0] 7 6 5 4 3 2 1 0 - - - - - - - SPIWPEN * SPIWPKEY: SPI Write Protection Key Password If a value is written in SPIWPEN, the value is taken into account only if SPIWPKEY is written with "SPI" (SPI written in ASCII Code, i.e. 0x535049 in hexadecimal). * SPIWPEN: SPI Write Protection Enable 1: The Write Protection is Enabled 0: The Write Protection is Disabled 689 32117A-10/2010 AT32UC3C 26.8.14 Write Protection Status Register Register Name: WPSR Access Type: Read-only Offset: 0xE8 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 2 1 0 SPIWPVSRC 7 6 5 4 3 - - - - - SPIWPVS * SPIWPVSRC: SPI Write Protection Violation Source This Field indicates the Peripheral Bus Offset of the register concerned by the violation (MR or CSRx) * SPIWPVS: SPI Write Protection Violation Status SPIWPVS value Violation Type 1 The Write Protection has blocked a Write access to a protected register (since the last read). 2 Software Reset has been performed while Write Protection was enabled (since the last read or since the last write access on MR, IER, IDR or CSRx). 3 Both Write Protection violation and software reset with Write Protection enabled have occurred since the last read. 4 Write accesses have been detected on MR (while a chip select was active) or on CSRi (while the Chip Select "i" was active) since the last read. 5 The Write Protection has blocked a Write access to a protected register and write accesses have been detected on MR (while a chip select was active) or on CSRi (while the Chip Select "i" was active) since the last read. 6 Software Reset has been performed while Write Protection was enabled (since the last read or since the last write access on MR, IER, IDR or CSRx) and some write accesses have been detected on MR (while a chip select was active) or on CSRi (while the Chip Select "i" was active) since the last read. 7 - The Write Protection has blocked a Write access to a protected register. and - Software Reset has been performed while Write Protection was enabled. and - Write accesses have been detected on MR (while a chip select was active) or on CSRi (while the Chip Select "i" was active) since the last read. 690 32117A-10/2010 AT32UC3C 26.8.15 Features Register Register Name: FEATURES Access Type: Read-only Offset: 0xF8 Reset Value: - 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - SWIMPL FIFORIMPL BRPBHSB CSNAATIMPL EXTDEC 15 14 13 12 11 10 9 8 LENNCONF 7 6 5 4 PHZNCONF PHCONF PPNCONF PCONF LENCONF 3 2 1 0 NCS * SWIMPL: Spurious Write Protection Implemented * * * * * * * * 0: Spurious write protection is not implemented. 1: Spurious write protection is implemented. FIFORIMPL: FIFO in Reception Implemented 0: FIFO in reception is not implemented. 1: FIFO in reception is implemented. BRPBHSB: Bridge Type is PB to HSB 0: Bridge type is not PB to HSB. 1: Bridge type is PB to HSB. CSNAATIMPL: CSNAAT Features Implemented 0: CSNAAT (Chip select not active after transfer) features are not implemented. 1: CSNAAT features are implemented. EXTDEC: External Decoder True 0: External decoder capability is not implemented. 1: External decoder capability is implemented. LENNCONF: Character Length if not Configurable If the character length is not configurable, this field specifies the fixed character length. LENCONF: Character Length Configurable 0: The character length is not configurable. 1: The character length is configurable. PHZNCONF: Phase is Zero if Phase not Configurable 0: If phase is not configurable, phase is non-zero. 1: If phase is not configurable, phase is zero. PHCONF: Phase Configurable 0: Phase is not configurable. 1: Phase is configurable. 691 32117A-10/2010 AT32UC3C * PPNCONF: Polarity Positive if Polarity not Configurable 0: If polarity is not configurable, polarity is negative. 1: If polarity is not configurable, polarity is positive. * PCONF: Polarity Configurable 0: Polarity is not configurable. 1: Polarity is configurable. * NCS: Number of Chip Selects This field indicates the number of chip selects implemented. 692 32117A-10/2010 AT32UC3C 26.8.16 Version Register Register Name: VERSION Access Type: Read-only Offset: 0xFC Reset Value: - 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - 15 14 13 12 9 8 MFN 11 10 VERSION[11:8] 7 6 5 4 3 2 1 0 VERSION[7:0] * MFN Reserved. No functionality associated. * VERSION Version number of the module. No functionality associated. 693 32117A-10/2010 AT32UC3C 26.9 Module Configuration The specific configuration for each SPI instance is listed in the following tables. The module bus clocks listed here are connected to the system bus clocks. Please refer to the Power Manager chapter for details. Table 26-4. SPI Clock Name Module Name Clock Name Description SPI0 CLK_SPI0 Peripheral Bus clock from the PBC clock domain SPI1 CLK_SPI1 Peripheral Bus clock from the PBA clock domain Table 26-5. Register Reset Values Register Reset Value FEATURES 0x001F0154 VERSION 0x00000211 694 32117A-10/2010 AT32UC3C 27. Two-Wire Master Interface (TWIM) Rev 1.1.0.1 27.1 Features * Compatible with IC standard * * * * * * 27.2 - Multi-master support - 100 and 400 kbit/s transfer speeds - 7- and 10-bit and General Call addressing Compatible with SMBus standard - Hardware Packet Error Checking (CRC) generation and verification with ACK control - SMBus ALERT interface - 25 ms clock low timeout delay - 10 ms master cumulative clock low extend time - 25 ms slave cumulative clock low extend time Compatible with PMBus Compatible with Atmel Two-Wire Interface Serial Memories DMA interface for reducing CPU load Arbitrary transfer lengths, including 0 data bytes Optional clock stretching if transmit or receive buffers not ready for data transfer Overview The Atmel Two-wire Interface Master (TWIM) interconnects components on a unique two-wire bus, made up of one clock line and one data line with speeds of up to 400 kbit/s, based on a byte-oriented transfer format. It can be used with any Atmel Two-wire Interface bus serial EEPROM and IC compatible device such as a real rime clock (RTC), dot matrix/graphic LCD controller and temperature sensor, to name a few. TWIM is always a bus master and can transfer sequential or single bytes. Multiple master capability is supported. Arbitration of the bus is performed internally and relinquishes the bus automatically if the bus arbitration is lost. A configurable baud rate generator permits the output data rate to be adapted to a wide range of core clock frequencies.Table 27-1 on page 695 lists the compatibility level of the Atmel Two-wire Interface in Master Mode and a full IC compatible device. Table 27-1. Atmel TWIM Compatibility with IC Standard IC Standard Atmel TWIM Standard Mode Speed (100 KHz) Supported Fast Mode Speed (400 KHz) Supported 7- or 10-bits Slave Addressing Supported (1) START BYTE Not Supported Repeated Start (Sr) Condition Supported ACK and NACK Management Supported Slope Control and Input Filtering (Fast mode) Supported Clock Stretching Supported Note: 1. START + b000000001 + Ack + Sr 695 32117A-10/2010 AT32UC3C Table 27-2 on page 696 lists the compatibility level of the Atmel Two-wire Master Interface and a full SMBus compatible master. Table 27-2. 27.3 SMBus Standard Atmel TWIM Bus Timeouts Supported Address Resolution Protocol Supported Alert Supported Host Functionality Supported Packet Error Checking Supported List of Abbreviations Table 27-3. 27.4 Atmel TWIM Compatibility with SMBus Standard Abbreviations Abbreviation Description TWI Two-wire Interface A Acknowledge NA Non Acknowledge P Stop S Start Sr Repeated Start SADR Slave Address ADR Any address except SADR R Read W Write Block Diagram Figure 27-1. Block Diagram Peripheral Bus Bridge TWCK I/O controller Two-wire Interface Power Manager TWD TWALM CLK_TWIM INTC TWI Interrupt 696 32117A-10/2010 AT32UC3C 27.5 Application Block Diagram Figure 27-2. Application Block Diagram VDD Rp Rp TWD TWI Master TWCK Atmel TWI serial EEPROM Slave 1 IC RTC IC LCD controller IC temp. sensor Slave 2 Slave 3 Slave 4 Rp: Pull up value as given by the IC Standard 27.6 I/O Lines Description Table 27-4. I/O Lines Description Pin Name Pin Description TWD Two-wire Serial Data Input/Output TWCK Two-wire Serial Clock Input/Output TWALM SMBus SMBALERT Input/Output 27.7 Type Product Dependencies In order to use this module, other parts of the system must be configured correctly, as described below. 27.7.1 I/O Lines Both TWD and TWCK are bidirectional lines, connected to a positive supply voltage via a current source or pull-up resistor (see Figure 27-2 on page 697). When the bus is free, both lines are high. The output stages of devices connected to the bus must have an open-drain or open-collector to perform the wired-AND function. TWALM is used to implement the optional SMBus SMBALERT signal. The TWALM, TWD, and TWCK pins may be multiplexed with I/O Controller lines. To enable the TWIM, the programmer must perform the following steps: * Program the I/O Controller to: - Dedicate TWD, TWCK and optionally TWALM as peripheral lines. - Define TWD, TWCK and optionally TWALM as open-drain. 27.7.2 Power Management If the CPU enters a sleep mode that disables clocks used by the TWIM, the TWIM will stop functioning and resume operation after the system wakes up from sleep mode. 697 32117A-10/2010 AT32UC3C 27.7.3 Clocks The clock for the TWIM bus interface (CLK_TWIM) is generated by the Power Manager. This clock is enabled at reset, and can be disabled in the Power Manager. It is recommended to disable the TWIM before disabling the clock, to avoid freezing the TWIM in an undefined state. 27.7.4 Interrupts The TWIM interrupt request lines are connected to the interrupt controller. Using the TWIM interrupts requires the interrupt controller to be programmed first. 27.7.5 Debug Operation When an external debugger forces the CPU into debug mode, the TWIM continues normal operation. If the TWIM 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. 698 32117A-10/2010 AT32UC3C 27.8 27.8.1 Functional Description Transfer Format The data put on the TWD line must be 8 bits long. Data is transferred MSB first; each byte must be followed by an acknowledgement. The number of bytes per transfer is unlimited (see Figure 27-4 on page 699). Each transfer begins with a START condition and terminates with a STOP condition (see Figure 27-4 on page 699). * A high-to-low transition on the TWD line while TWCK is high defines the START condition. * A low-to-high transition on the TWD line while TWCK is high defines a STOP condition. Figure 27-3. START and STOP Conditions TWD TWCK Start Stop Figure 27-4. Transfer Format TWD TWCK Start 27.8.2 Address R/W Ack Data Ack Data Ack Stop Operation The TWIM has two modes of operation: * Master transmitter mode * Master receiver mode The master is the device which starts and stops a transfer and generates the TWCK clock. These modes are described in the following chapters. 699 32117A-10/2010 AT32UC3C 27.8.2.1 Clock Generation The Clock Waveform Generator Register (CWGR) is used to control the waveform of the TWCK clock. CWGR must be programmed so that the desired TWI bus timings are generated. CWGR describes bus timings as a function of cycles of a prescaled clock. The clock prescaling can be selected through the EXP field in CWGR. f clkpb f prescaled = ------------------------( EXP + 1 ) ) 2 CWGR has the following fields: LOW: Prescaled clock cycles in clock low count. Used to time TLOW. and TBUF. HIGH: Prescaled clock cycles in clock high count. Used to time THIGH. STASTO: Prescaled clock cycles in clock high count. Used to time THD_STA, TSU_STA, TSU_STO. DATA: Prescaled clock cycles for data setup and hold count. Used to time THD_DAT, TSU_DAT. EXP: Specifies the clock prescaler setting. Note that the total clock low time generated is the sum of THD_DAT + TSU_DAT + TLOW. Any slave or other bus master taking part in the transfer may extend the TWCK low period at any time. The TWIM hardware monitors the state of the TWCK line as required by the IC specification. The clock generation counters are started when a high/low level is detected on the TWCK line, not when the TWIM hardware releases/drives the TWCK line. This means that the CWGR settings alone do not determine the TWCK frequency. The CWGR settings determine the clock low time and the clock high time, but the TWCK rise and fall times are determined by the external circuitry (capacitive load, etc.). Figure 27-5. Bus Timing Diagram t HIGH t LOW S t HD:STA t LOW t SU:DAT t HD:DAT t t 27.8.2.2 t SU:DAT SU:STA SU:STO P Sr Setting up and Performing a Transfer Operation of TWIM is mainly controlled by the Control Register (CR) and the Command Register (CMDR). The following list presents the main steps in a typical communication: 700 32117A-10/2010 AT32UC3C 1. Before any transfers can be performed, bus timings must be configured by programming the Clock Waveform Generator Register (CWGR). If operating in SMBus mode, the SMBus Timing Register (SMBTR) register must also be configured. 2. If a DMA controller is to be used for the transfers, it must be set up. 3. CMDR or NCMDR must be programmed with a value describing the transfer to be performed. The interrupt system can be set up to give interrupt request on specific events or error conditions, for example when the transfer is complete or if arbitration is lost. The controller will refuse to start a new transfer while ANAK, DNAK or ARBLST is set in the Status Register (SR). This is necessary to avoid a race when the software issues a continuation of the current transfer at the same time as one of these errors happen. Also, if ANAK or DNAK occur, a STOP condition is sent automatically. The programmer will have to restart the transmission by clearing the errors bit in SR after resolving the cause for the NACK. After a data or address NACK from the slave, a STOP will be transmitted automatically. Note that the VALID bit in CMDR is NOT cleared in this case. If this transfer is to be discarded, the VALID bit can be cleared manually allowing any command in NCMDR to be copied into CMDR. When a data or address NACK is returned by the slave while the master is transmitting, it is possible that new data has already been written to the THR register. This data will be transferred out as the first data byte of the next transfer. If this behavior is to be avoided, the safest approach is to perform a software reset of the TWIM. 27.8.3 Master Transmitter Mode A START condition is transmitted and master transmitter mode is initiated when the bus is free and CMDR has been written with START=1 and READ=0. START and SADR+W will then be transmitted. During the address acknowledge clock pulse (9th pulse), the master releases the data line (HIGH), enabling the slave to pull it down in order to acknowledge the address. The master polls the data line during this clock pulse and sets the Address Not Acknowledged bit (ANAK) in the Status Register if no slave acknowledges the address. After the address phase, the following is repeated: while (NBYTES>0) 1. Wait until THR contains a valid data byte, stretching low period of TWCK. SR.TXRDY indicates the state of THR. Software or a DMA controller must write the data byte to THR. 2. Transmit this data byte 3. Decrement NBYTES 4. If (NBYTES==0) and STOP=1, transmit STOP condition Programming CMDR with START=STOP=1 and NBYTES=0 will generate a transmission with no data bytes, ie START, SADR+W, STOP. TWI transfers require the slave to acknowledge each received data byte. During the acknowledge clock pulse (9th pulse), the master releases the data line (HIGH), enabling the slave to pull it down in order to generate the acknowledge. The master polls the data line during this clock pulse and sets the Data Acknowledge bit (DNACK) in the Status Register if the slave does not acknowledge the data byte. As with the other status bits, an interrupt can be generated if enabled in the Interrupt Enable Register (TWIM_IER). TXRDY is used as Transmit Ready for the Peripheral DMA Controller transmit channel. 701 32117A-10/2010 AT32UC3C The end of a command is marked by setting the SR.CCOMP bit to one. See Figure 27-6 on page 702 and Figure 27-7 on page 702. Figure 27-6. Master Write with One Data Byte TWD S DADR W A DATA A P SR.IDLE TXRDY Write THR (DATA) NBYTES set to 1 STOP sent automatically (ACK received and NBYTES=0) Figure 27-7. Master Write with Multiple Data Bytes TWD S DADR W A DATAn A DATAn+5 A DATAn+m A P SR.IDLE TXRDY Write THR (DATAn) NBYTES set to n 27.8.4 Write THR (DATAn+1) Write THR (DATAn+m) Last data sent STOP sent automatically (ACK received and NBYTES=0) Master Receiver Mode A START condition is transmitted and master receiver mode is initiated when the bus is free and CMDR has been written with START=1 and READ=1. START and SADR+R will then be transmitted. During the address acknowledge clock pulse (9th pulse), the master releases the data line (HIGH), enabling the slave to pull it down in order to acknowledge the address. The master polls the data line during this clock pulse and sets the Address Not Acknowledged bit (ANAK) in the Status Register if no slave acknowledges the address. After the address phase, the following is repeated: while (NBYTES>0) 1. Wait until RHR is empty, stretching low period of TWCK. SR.RXRDY indicates the state of RHR. Software or a DMA controller must read any data byte present in RHR. 2. Release TWCK generating a clock that the slave uses to transmit a data byte. 3. Place the received data byte in RHR, set RXRDY. 4. If NBYTES=0, generate a NAK after the data byte, otherwise generate an ACK. 5. Decrement NBYTES 6. If (NBYTES==0) and STOP=1, transmit STOP condition. Programming CMDR with START=STOP=1 and NBYTES=0 will generate a transmission with no data bytes, ie START, DADR+R, STOP 702 32117A-10/2010 AT32UC3C The TWI transfers require the master to acknowledge each received data byte. During the acknowledge clock pulse (9th pulse), the slave releases the data line (HIGH), enabling the master to pull it down in order to generate the acknowledge. All data bytes except the last are acknowledged by the master. Not acknowledging the last byte informs the slave that the transfer is finished. RXRDY is used as Receive Ready for the Peripheral DMA Controller receive channel. Figure 27-8. Master Read with One Data Byte TWD S DADR R A DATA N P SR.IDLE RXRDY Write START & STOP bit NBYTES set to 1 Read RHR Figure 27-9. Master Read with Multiple Data Bytes TWD S DADR R A DATAn A DATAn+1 DATAn+m-1 A DATAn+m N P SR.IDLE RXRDY Write START + STOP bit NBYTES set to m Read RHR DATAn Read RHR DATAn+m-2 Read RHR DATAn+m-1 Read RHR DATAn+m Send STOP When NBYTES=0 27.8.5 Using the Peripheral DMA Controller The use of the Peripheral DMA Controller significantly reduces the CPU load. The programmer can set up ring buffers for the DMA controller, containing data to transmit or free buffer space to place received data. To assure correct behavior, respect the following programming sequences: 27.8.5.1 Data Transmit with the Peripheral DMA Controller 1. Initialize the transmit Peripheral DMA Controller (memory pointers, size, etc.). 2. Configure the TWIM (ADR, NBYTES, etc.). 3. Start the transfer by setting the Peripheral DMA Controller TXTEN bit. 4. Wait for the Peripheral DMA Controller end TX flag. 703 32117A-10/2010 AT32UC3C 5. Disable the Peripheral DMA Controller by setting the Peripheral DMA Controller TXDIS bit. 27.8.5.2 Data Receive with the Peripheral DMA Controller 1. Initialize the receive Peripheral DMA Controller (memory pointers, size, etc.). 2. Configure the TWIM (ADR, NBYTES, etc.). 3. Start the transfer by setting the Peripheral DMA Controller RXTEN bit. 4. Wait for the Peripheral DMA Controller end RX flag. 5. Disable the Peripheral DMA Controller by setting the Peripheral DMA Controller RXDIS bit. 27.8.6 Multi-master Mode More than one master may access the bus at the same time without data corruption by using arbitration. Arbitration starts as soon as two or more masters place information on the bus at the same time, and stops (arbitration is lost) for the master that intends to send a logical one while the other master sends a logical zero. As soon as arbitration is lost by a master, it stops sending data and listens to the bus in order to detect a STOP. The SR.ARBLST flag will be set. When the STOP is detected, the master who lost arbitration may reinitiate the data transfer. Arbitration is illustrated in Figure 27-11 on page 705. If the user starts a transfer and if the bus is busy, TWIM automatically waits for a STOP condition on the bus before initiating the transfer (see Figure 27-10 on page 704). Note: The state of the bus (busy or free) is not indicated in the user interface. Figure 27-10. Programmer Sends Data While the Bus is Busy TWCK START sent by the TWI STOP sent by the master TWD DATA sent by a master DATA sent by the TWI Bus is busy Bus is free TWI DATA transfer A transfer is programmed (DADR + W + START + Write THR) Transfer is kept Bus is considered as free Transfer is initiated 704 32117A-10/2010 AT32UC3C Figure 27-11. Arbitration Cases TWCK TWD TWCK Data from a Master S 1 0 0 1 1 Data from TWI S 1 0 TWD S 1 0 0 1 P Arbitration is lost TWI stops sending data Data from the master 1 1 P Arbitration is lost S 1 0 S 1 0 0 1 1 S 1 0 1 1 The master stops sending data 0 1 Data from the TWI ARBLST Bus is busy Transfer is kept TWI DATA transfer A transfer is programmed (DADR + W + START + Write THR) 27.8.7 Bus is free Transfer is stopped Transfer is programmed again (DADR + W + START + Write THR) Bus is considered as free Transfer is initiated Combined Transfers CMDR and NCMDR may be used to generate longer sequences of connected transfers, since generation of START and/or STOP conditions is programmable on a per-command basis. Programming NCMDR with START=1 when the previous transfer was programmed with STOP=0 will cause a REPEATED START on the bus. The ability to generate such connected transfers allows arbitrary transfer lengths, since it is legal to program CMDR with both START=0 and STOP=0. If this is done in master receiver mode, the CMDR.ACKLAST bit must also be controlled. As for single data transfers, the TXRDY and RXRDY bits in the Status Register indicates when data to transmit can be written to the THR, or when received data can be read from RHR. Transfer of data to THR and from RHR can also be done automatically by DMA, see "Using the Peripheral DMA Controller" on page 703 27.8.7.1 Write Followed by Write Consider the following transfer: START, DADR+W, DATA+A, DATA+A, REPSTART, DADR+W, DATA+A, DATA+A, STOP. To generate this transfer: 1. Program CMDR with START=1, STOP=0, DADR, NBYTES=2 and READ=0. 2. Program NCMDR with START=1, STOP=1, DADR, NBYTES=2 and READ=0. 3. Wait until SR.TXRDY==1, then write first data byte to transfer to THR. 4. Wait until SR.TXRDY==1, then write second data byte to transfer to THR. 705 32117A-10/2010 AT32UC3C 5. Wait until SR.TXRDY==1, then write third data byte to transfer to THR. 6. Wait until SR.TXRDY==1, then write fourth data byte to transfer to THR. 27.8.7.2 Read Followed by Read Consider the following transfer: START, DADR+R, DATA+A, DATA+NA, REPSTART, DADR+R, DATA+A, DATA+NA, STOP. To generate this transfer: 1. Program CMDR with START=1, STOP=0, DADR, NBYTES=2 and READ=1. 2. Program NCMDR with START=1, STOP=1, DADR, NBYTES=2 and READ=1. 3. Wait until SR.RXRDY==1, then read first data byte received from RHR. 4. Wait until SR.RXRDY==1, then read second data byte received from RHR. 5. Wait until SR.RXRDY==1, then read third data byte received from RHR. 6. Wait until SR.RXRDY==1, then read fourth data byte received from RHR. If combining several transfers, without any STOP or REPEATED START between them, remember to set the ACKLAST bit in CMDR to keep from ending each of the partial transfers with a NACK. 27.8.7.3 Write Followed by Read Consider the following transfer: START, DADR+W, DATA+A, DATA+A, REPSTART, DADR+R, DATA+A, DATA+NA, STOP. Figure 27-12. Combining a Write and Read Transfer THR DATA0 DATA1 RHR TWD DATA2 S DADR W A DATA0 A DATA1 NA Sr DADR R A DATA2 A DATA3 DATA3 A P SR.IDLE 1 TXRDY RXRDY To generate this transfer: 1. Program CMDR with START=1, STOP=0, DADR, NBYTES=2 and READ=0. 2. Program NCMDR with START=1, STOP=1, DADR, NBYTES=2 and READ=1. 3. Wait until SR.TXRDY==1, then write first data byte to transfer to THR. 4. Wait until SR.TXRDY==1, then write second data byte to transfer to THR. 5. Wait until SR.RXRDY==1, then read first data byte received from RHR. 6. Wait until SR.RXRDY==1, then read second data byte received from RHR. 27.8.7.4 Read Followed by Write Consider the following transfer: START, DADR+R, DATA+A, DATA+NA, REPSTART, DADR+W, DATA+A, DATA+A, STOP. 706 32117A-10/2010 AT32UC3C Figure 27-13. Combining a Read and Write Transfer THR DATA2 RHR TWD DATA0 S SADR R A A DATA0 DATA3 DATA1 A DATA3 1 Sr DADR W A DATA2 A DATA3 NA P SR.IDLE 2 TXRDY Read TWI_RHR RXRDY To generate this transfer: 1. Program CMDR with START=1, STOP=0, DADR, NBYTES=2 and READ=1. 2. Program NCMDR with START=1, STOP=1, DADR, NBYTES=2 and READ=0. 3. Wait until SR.RXRDY==1, then read first data byte received from RHR. 4. Wait until SR.RXRDY==1, then read second data byte received from RHR. 5. Wait until SR.TXRDY==1, then write first data byte to transfer to THR. 6. Wait until SR.TXRDY==1, then write second data byte to transfer to THR. 27.8.8 Ten Bit Addressing Setting CMDR.TENBIT enables 10-bit addressing in hardware. Performing transfers with 10-bit addressing is similar to transfers with 7-bit addresses, except that bits 10:7 of CMDR.ADR must be set appropriately. In Figure 27-14 on page 707 and Figure 27-15 on page 708, the grey boxes represent signals driven by the master, the white boxes are driven by the slave. 27.8.8.1 Master Transmitter To perform a master transmitter transfer, 1. Program CMDR with TENBIT=1, REPSAME=0, READ=0, START=1, STOP=1 and the desired address and NBYTES value. Figure 27-14. A Write Transfer with 10-bit Addressing 1 S 27.8.8.2 1 1 1 0 X SLAVE ADDRESS 1st 7 bits X 0 RW A1 SLAVE ADDRESS 2nd byte A2 DATA A DATA AA P Master Receiver When using master receiver mode with 10-bit addressing, CMDR.REPSAME must also be controlled. CMDR.REPSAME must be written to one when the address phase of the transfer should consist of only 1 address byte (the 11110xx byte) and not 2 address bytes. The IC standard specifies that such addressing is required when addressing a slave for reads using 10-bit addressing. To perform a master receiver transfer, 707 32117A-10/2010 AT32UC3C 1. Program CMDR with TENBIT=1, REPSAME=0, READ=0, START=1, STOP=0, NBYTES=0 and the desired address. 2. Program NCMDR with TENBIT=1, REPSAME=1, READ=1, START=1, STOP=1 and the desired address and NBYTES value. Figure 27-15. A Read Transfer with 10-bit Addressing 1 S 27.8.9 1 1 1 0 X X SLAVE ADDRESS 1st 7 bits 1 0 RW A1 SLAVE ADDRESS 2nd byte A2 Sr 1 1 1 0 X SLAVE ADDRESS 1st 7 bits X 1 RW A3 DATA A DATA A P SMBus Mode SMBus mode is enabled and disabled by the SMEN and SMDIS bits in CR. SMBus mode operation is similar to IC operation with the following exceptions: * Only 7-bit addressing can be used. * The SMBus standard describes a set of timeout values to ensure progress and throughput on the bus. These timeout values must be programmed into SMBTR. * Transmissions can optionally include a CRC byte, called Packet Error Check (PEC). * A dedicated bus line, SMBALERT, allows a slave to get a master's attention. * A set of addresses have been reserved for protocol handling, such as Alert Response Address (ARA) and Host Header (HH) Address. 27.8.9.1 Packet Error Checking Each SMBus transfer can optionally end with a CRC byte, called the PEC byte. Writing CMDR.PECEN to one enables automatic PEC handling in the current transfer. Transfers with and without PEC can freely be intermixed in the same system, since some slaves may not support PEC. The PEC LFSR is always updated on every bit transmitted or received, so that PEC handling on combined transfers will be correct. In master transmitter mode, the master calculates a PEC value and transmits it to the slave after all data bytes have been transmitted. Upon reception of this PEC byte, the slave will compare it to the PEC value it has computed itself. If the values match, the data was received correctly, and the slave will return an ACK to the master. If the PEC values differ, data was corrupted, and the slave will return a NACK value. The DNAK bit in SR reflects the state of the last received ACK/NACK value. Some slaves may not be able to check the received PEC in time to return a NACK if an error occurred. In this case, the slave should always return an ACK after the PEC byte, and some other mechanism must be implemented to verify that the transmission was received correctly. In master receiver mode, the slave calculates a PEC value and transmits it to the master after all data bytes have been transmitted. Upon reception of this PEC byte, the master will compare it to the PEC value it has computed itself. If the values match, the data was received correctly. If the PEC values differ, data was corrupted, and the PECERR bit in SR is set. In master receiver mode, the PEC byte is always followed by a NACK transmitted by the master, since it is the last byte in the transfer. The PEC byte is automatically inserted in a master transmitter transmission if PEC is enabled when NBYTES reaches zero. The PEC byte is identified in a master receiver transmission if PEC is enabled when NBYTES reaches zero. NBYTES must therefore be set to the total number of data bytes in the transmission, including the PEC byte. 708 32117A-10/2010 AT32UC3C In combined transfers, the PECEN bit should only be set in the last of the combined transfers. Consider the following transfer: S, ADR+W, COMMAND_BYTE, ACK, SR, ADR+R, DATA_BYTE, ACK, PEC_BYTE, NACK, P This transfer is generated by writing two commands to the command registers. The first command is a write with NBYTES=1 and PECEN=0, and the second is a read with NBYTES=2 and PECEN=1. Writing a one to the STOP bit in CR will place a STOP condition on the bus after the current byte. No PEC byte will be sent in this case. 27.8.9.2 Timeouts The TLOWS and TLOWM fields in SMBTR configure the SMBus timeout values. If a timeout occurs, the master will transmit a STOP condition and leave the bus. The SR.TOUT bit is also set. 27.8.9.3 SMBus ALERT Signal A slave can get the master's attention by pulling the TWALM line low. SR.SMBAL will then be set. This can be set up to trigger an interrupt, and software can then take the appropriate action, as defined in the SMBus standard. 27.8.10 Identifying Bus Events This chapter lists the different bus events, and how these affects bits in the TWIM registers. This is intended to help writing drivers for the TWIM. Table 27-5. Bus Events Event Effect Master transmitter has sent a data byte SR.THR is cleared. Master receiver has received a data byte SR.RHR is set. Start+Sadr sent, no ack received from slave SR.ANAK is set. SR.CCOMP not set. CMDR.VALID remains set. STOP automatically transmitted on bus. Data byte sent to slave, no ack received from slave SR.DNAK is set. SR.CCOMP not set. CMDR.VALID remains set. STOP automatically transmitted on bus. Arbitration lost SR.ARBLST is set. SR.CCOMP not set. CMDR.VALID remains set. TWCK and TWD immediately released to a pulled-up state. SMBus Alert received SR.SMBAL is set. SMBus timeout received SR.SMBTOUT is set. SR.CCOMP not set. CMDR.VALID remains set. STOP automatically transmitted on bus. 709 32117A-10/2010 AT32UC3C Table 27-5. Bus Events Event Effect Master transmitter receives SMBus PEC Error SR.DNAK is set. SR.CCOMP not set. CMDR.VALID remains set. STOP automatically transmitted on bus. Master receiver discovers SMBus PEC Error SR.PECERR is set. SR.CCOMP not set. CMDR.VALID remains set. STOP automatically transmitted on bus. CR.STOP is written by user SR.STOP is set. SR.CCOMP set. CMDR.VALID remains set. STOP transmitted on bus after current byte transfer has finished. 710 32117A-10/2010 AT32UC3C 27.9 User Interface Table 27-6. Note: TWIM Register Memory Map Offset Register Register Name Access Reset 0x00 Control CR Write-only 0x00000000 0x04 Clock Waveform Generator CWGR Read/Write 0x00000000 0x08 SMBus Timing SMBTR Read/Write 0x00000000 0x0C Command CMDR Read/Write 0x00000000 0x10 Next Command NCMDR Read/Write 0x00000000 0x14 Receive Holding RHR Read-only 0x00000000 0x18 Transmit Holding THR Write-only 0x00000000 0x1C Status SR Read-only 0x00000002 0x20 Interrupt Enable Register IER Write-only 0x00000000 0x24 Interrupt Disable Register IDR Write-only 0x00000000 0x28 Interrupt Mask Register IMR Read-only 0x00000000 0x2C Status Clear Register SCR Write-only 0x00000000 0x30 Parameter Register PR Read-only (1) 0x34 Version Register VR Read-only (1) 1. The reset values for these registers are device specific. Please refer to the Module Configuration section at the end of this chapter. 711 32117A-10/2010 AT32UC3C 27.9.1 Name: Control Register (CR) CR Access Type: Write-only Offset: 0x00 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 - - - - - - - STOP 7 6 5 4 3 2 1 0 SWRST - SMDIS SMEN - - MDIS MEN * STOP: Stop the current transfer Writing a one to this bit terminates the current transfer, sending a STOP condition after the shifter has become idle. If there are additional pending transfers, they will have to be explicitly restarted by software after the STOP condition has been successfully sent. Writing a zero to this bit has no effect. * SWRST: Software Reset If the TWIM master interface is enabled, writing a one to this bit resets the TWIM. All transfers are halted immediately, possibly violating the bus semantics. If the TWIM master interface is not enabled, it must first be enabled before writing a one to this bit. Writing a zero to this bit has no effect. * SMDIS: SMBus Disable Writing a one to this bit disables SMBus mode. Writing a zero to this bit has no effect. * SMEN: SMBus Enable Writing a one to this bit enables SMBus mode. Writing a zero to this bit has no effect. * MDIS: Master Disable Writing a one to this bit disables the master interface. Writing a zero to this bit has no effect. * MEN: Master enable Writing a one to this bit enables the master interface. Writing a zero to this bit has no effect. 712 32117A-10/2010 AT32UC3C 27.9.2 Name: Clock Waveform Generator Register (CWGR) CWGR Access Type: Read/Write Offset: 0x04 Reset Value: 0x00000000 31 30 - 29 28 27 26 EXP 23 22 21 25 24 DATA 20 19 18 17 16 11 10 9 8 3 2 1 0 STASTO 15 14 13 12 HIGH 7 6 5 4 LOW * EXP: Clock Prescaler Used to specify how to prescale the TWCK clock. Counters are prescaled according to the following formula f clkpb f prescaled = ----------------------( EXP + 1 ) 2 * DATA: Data Setup and Hold Cycles Clock cycles for data setup and hold count. Prescaled by CWGR.EXP. Used to time THD_DAT, TSU_DAT. * STASTO: START and STOP Cycles Clock cycles in clock high count. Prescaled by CWGR.EXP. Used to time THD_STA, TSU_STA, TSU_STO * HIGH: Clock High Cycles Clock cycles in clock high count. Prescaled by CWGR.EXP. Used to time THIGH. * LOW: Clock Low Cycles Clock cycles in clock low count. Prescaled by CWGR.EXP. Used to time TLOW, TBUF. 713 32117A-10/2010 AT32UC3C 27.9.3 Name: SMBus Timing Register (SMBTR) SMBTR Access Type: Read/Write Offset: 0x08 Reset Value: 0x00000000 31 30 29 28 EXP 23 22 21 20 27 26 25 24 - - - - 19 18 17 16 11 10 9 8 3 2 1 0 THMAX 15 14 13 12 TLOWM 7 6 5 4 TLOWS * EXP: SMBus Timeout Clock prescaler Used to specify how to prescale the TIM and TLOWM counters in SMBTR. Counters are prescaled according to the following formula f clkpb f prescaled, SMBus = ----------------------( EXP + 1 ) 2 * THMAX: Clock High maximum cycles Clock cycles in clock high maximum count. Prescaled by SMBTR.EXP. Used for bus free detection. Used to time THIGH:MAX. NOTE: Uses the prescaler specified by CWGR, NOT the prescaler specified by SMBTR. * TLOWM: Master Clock stretch maximum cycles Clock cycles in master maximum clock stretch count. Prescaled by SMBTR.EXP. Used to time TLOW:MEXT * TLOWS: Slave Clock stretch maximum cycles Clock cycles in slave maximum clock stretch count. Prescaled by SMBTR.EXP. Used to time TLOW:SEXT. 714 32117A-10/2010 AT32UC3C 27.9.4 Name: Command Register (CMDR) CMDR Access Type: Read/Write Offset: 0x0C Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - ACKLAST PECEN 23 22 21 20 19 18 17 16 10 9 8 NBYTES 15 14 13 12 11 VALID STOP START REPSAME TENBIT 7 6 5 4 3 SADR[6:0] SADR[9:7] 2 1 0 READ * ACKLAST: ACK Last Master RX Byte Writing this bit to zero causes the last byte in master receive mode (when NBYTES has reached 0) to be NACKed. This is the standard way of ending a master receiver transfer. Writing this bit to one causes the last byte in master receive mode (when NBYTES has reached 0) to be ACKed. Used for performing linked transfers in master receiver mode with no STOP or REPEATED START between the subtransfers. This is needed when more than 255 bytes are to be received in one single transmission. * PECEN: Packet Error Checking Enable Writing this bit to zero causes the transfer not to use PEC byte verification. The PEC LFSR is still updated for every bit transmitted or received. Must be used if SMBus mode is disabled. Writing this bit to one causes the transfer to use PEC. PEC byte generation (if master transmitter) or PEC byte verification (if master receiver) will be performed. * NBYTES: Number of data bytes in transfer The number of data bytes in the transfer. After the specified number of bytes have been transferred, a STOP condition is transmitted if CMDR.STOP is set. In SMBus mode, if PEC is used, NBYTES includes the PEC byte, ie there are NBYTES-1 data bytes and a PEC byte. * VALID: CMDR Valid Writing this to zero indicates that CMDR does not contain a valid command. Writing this to one indicates that CMDR contains a valid command. This bit is cleared when the command is finished. * STOP: Send STOP condition Write this bit to zero to not transmit a STOP condition after the data bytes have been transmitted. Write this bit to one to transmit a STOP condition after the data bytes have been transmitted. * START: Send START condition Write this bit to zero if the transfer in CMDR should not commence with a START or REPEATED START condition. Write this bit to one if the transfer in CMDR should commence with a START or REPEATED START condition. If the bus is free when the command is executed, a START condition is used, if the bus is busy, a REPEATED START is used. * REPSAME: Transfer is to same address as previous address Only used in 10-bit addressing mode, always write to 0 in 7-bit addressing mode. 715 32117A-10/2010 AT32UC3C Write this bit to one if the command in CMDR performs a repeated start to the same slave address as addressed in the previous transfer in order to enter master receiver mode. Write this bit to zero otherwise. * TENBIT: Ten Bit Addressing Mode Write this bit to zero to use 7-bit addressing mode. Write this bit to one to use 10-bit addressing mode. Must not be used when TWIM is in SMBus mode. * SADR: Slave Address Address of the slave involved in the transfer. Bits 9-7 are don't care if 7-bit addressing is used. * READ: Transfer Direction Write this bit to zero to let the master transmit data. Write this bit to one to let the master receive data. 716 32117A-10/2010 AT32UC3C 27.9.5 Name: Next Command Register (NCMDR) NCMDR Access Type: Read/Write Offset: 0x10 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - ACKLAST PECEN 23 22 21 20 19 18 17 16 10 9 8 NBYTES 15 14 13 12 11 VALID STOP START REPSAME TENBIT 7 6 5 4 3 SADR[6:0] SADR[9:7] 2 1 0 READ This register is identical to CMDR. When the VALID bit in CMDR becomes 0, the contents of NCMDR is copied into CMDR, clearing the VALID bit in NCMDR. If the VALID bit in CMDR is cleared when NCMDR is written, the contents are copied immediately. 717 32117A-10/2010 AT32UC3C 27.9.6 Name: Receive Holding Register (RHR) RHR Access Type: Read-only Offset: 0x14 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 - - - - - - - - 7 6 5 4 3 2 1 0 RXDATA * RXDATA: Received Data When the RXRDY bit in the Status Register (SR) is set, this field contains a byte received from the TWI bus. 718 32117A-10/2010 AT32UC3C 27.9.7 Name: Transmit Holding Register (THR) THR Access Type: Write-only Offset: 0x18 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 - - - - - - - - 7 6 5 4 3 2 1 0 TXDATA * TXDATA: Data to Transmit Write data to be transferred on the TWI bus here. 719 32117A-10/2010 AT32UC3C 27.9.8 Name: Status Register (SR) SR Access Type: Read-only Offset: 0x1C Reset Value: 0x00000002 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - MENB 15 14 13 12 11 10 9 8 - STOP PECERR TOUT SMBALERT ARBLST DNAK ANAK 7 6 5 4 3 2 1 0 - - BUSFREE IDLE CCOMP CRDY TXRDY RXRDY * MENB: Master Interface Enable 0: Master interface is disabled. 1: Master interface is enabled. * STOP: Stop Request Accepted This bit is set when STOP request caused by setting CR STOP has been accepted, and transfer has stopped. This bit is cleared by writing 1 to the corresponding bit in the Status Clear Register (SCR). * PECERR: PEC Error This bit is set when a SMBus PEC error occurred. This bit is cleared by writing 1 to the corresponding bit in the Status Clear Register (SCR). * TOUT: Timeout This bit is set when a SMBus timeout occurred. This bit is cleared by writing 1 to the corresponding bit in the Status Clear Register (SCR). * SMBALERT: SMBus Alert This bit is set when an SMBus Alert was received. This bit is cleared by writing 1 to the corresponding bit in the Status Clear Register (SCR). * ARBLST: Arbitration Lost This bit is set when the actual state of the SDA line did not correspond to the data driven onto it, indicating a higher-priority transmission in progress by a different master. This bit is cleared by writing 1 to the corresponding bit in the Status Clear Register (SCR). * DNAK: NAK in Data Phase Received This bit is set when no ACK was received form slave during data transmission. This bit is cleared by writing 1 to the corresponding bit in the Status Clear Register (SCR). * ANAK: NAK in Address Phase Received This bit is set when no ACK was received from slave during address phase This bit is cleared by writing 1 to the corresponding bit in the Status Clear Register (SCR). * BUSFREE: Two-wire Bus is Free This bit is set when activity has completed on the two-wire bus. Otherwise, this bit is cleared. 720 32117A-10/2010 AT32UC3C * IDLE: Master Interface is Idle This bit is set when no command is in progress, and no command waiting to be issued. Otherwise, this bit is cleared. * CCOMP: Command Complete This bit is set when the current command has completed successfully. Not set if the command failed due to conditions such as a NAK receved from slave. This bit is cleared by writing 1 to the corresponding bit in the Status Clear Register (SCR). * CRDY: Ready for More Commands This bit is set when CMDR and/or NCMDR is ready to receive one or more commands. This bit is cleared when this is no longer true. * TXRDY: THR Data Ready This bit is set when THR is ready for one or more data bytes. This bit is cleared when this is no longer true (i.e. THR is full or transmission has stopped). * RXRDY: RHR Data Ready This bit is set when RX data are ready to be read from RHR. This bit is cleared when this is no longer true. 721 32117A-10/2010 AT32UC3C 27.9.9 Name: Interrupt Enable Register (IER) IER Access Type: Write-only Offset: 0x20 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 - STOP PECERR TOUT SMBALERT ARBLST DNAK ANAK 7 6 5 4 3 2 1 0 - - BUSFREE IDLE CCOMP CRDY TXRDY RXRDY Writing a zero to a bit in this register has no effect. Writing a one to a bit in this register will set the corresponding bit in IMR 722 32117A-10/2010 AT32UC3C 27.9.10 Name: Interrupt Disable Register (IDR) IDR Access Type: Write-only Offset: 0x24 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 - STOP PECERR TOUT SMBALERT ARBLST DNAK ANAK 7 6 5 4 3 2 1 0 - - BUSFREE IDLE CCOMP CRDY TXRDY RXRDY Writing a zero to a bit in this register has no effect. Writing a one to a bit in this register will clear the corresponding bit in IMR 723 32117A-10/2010 AT32UC3C 27.9.11 Name: Interrupt Mask Register (IMR) IMR Access Type: Read-only Offset: 0x28 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 - STOP PECERR TOUT SMBALERT ARBLST DNAK ANAK 7 6 5 4 3 2 1 0 - - BUSFREE IDLE CCOMP CRDY TXRDY RXRDY 0: The corresponding interrupt is disabled. 1: The corresponding interrupt is enabled. This bit is cleared when the corresponding bit in IDR is written to one. This bit is set when the corresponding bit in IER is written to one. 724 32117A-10/2010 AT32UC3C 27.9.12 Name: Status Clear Register (SCR) SCR Access Type : Write-only Offset: 0x2C Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 - STOP PECERR TOUT SMBALERT ARBLST DNAK ANAK 7 6 5 4 3 2 1 0 - - - - CCOMP - - - Writing a zero to a bit in this register has no effect. Writing a one to a bit in this register will clear the corresponding bit in SR and the corresponding interrupt request. 725 32117A-10/2010 AT32UC3C 27.9.13 Name: Parameter Register (PR) PR Access Type: Read-only Offset: 0x30 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 - - - - - - - - 7 6 5 4 3 2 1 0 - - - - - - - - 726 32117A-10/2010 AT32UC3C 27.9.14 Name: Version Register (VR) VR Access Type: Read-only Offset: 0x34 Reset Value: Device-specific 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - 15 14 13 12 9 8 - - - - 7 6 5 4 VARIANT 11 10 VERSION [11:8] 3 2 1 0 VERSION [7:0] * VARIANT: Variant number Reserved. No functionality associated. * VERSION: Version number Version number of the module. No functionality associated. 727 32117A-10/2010 AT32UC3C 27.10 Module Configuration The specific configuration for each TWIM instance is listed in the following tables. The module bus clocks listed here are connected to the system bus clocks. Please refer to the Power Manager chapter for details. Table 27-7. Module Configuration Feature TWIM0 TWIM1 TWIM2 SMBus ALERT interface Implemented Implemented Not Implemented Table 27-8. Module Clock Name Module Name Clock Name Description TWIM0 CLK_TWIM0 Peripheral Bus clock from the PBA clock domain TWIM1 CLK_TWIM1 Peripheral Bus clock from the PBA clock domain TWIM2 CLK_TWIM2 Peripheral Bus clock from the PBC clock domain Table 27-9. Register Reset Values Register Reset Value VR 0x0000 0101 PR 0x0000 0000 728 32117A-10/2010 AT32UC3C 28. Two-Wire Slave Interface (TWIS) Rev 1.2.0.1 28.1 Features * Compatible with IC standard * * * * * * 28.2 - 100 kbit/s400 kbit/s transfer speeds - 7 and 10-bit and General Call addressing Compatible with SMBus standard - Hardware Packet Error Checking (CRC) generation and verification with ACK response - SMBALERT interface - 25 ms clock low timeout delay - 25 ms slave cumulative clock low extend time Compatible with PMBus DMA interface for reducing CPU load Arbitrary transfer lengths, including 0 data bytes Optional clock stretching if transmit or receive buffers not ready for data transfer 32-bit Peripheral Bus interface for configuration of the interface Overview The Atmel Two-wire Interface Slave (TWIS) interconnects components on a unique two-wire bus, made up of one clock line and one data line with speeds of up to 400 kbit/s, based on a byte-oriented transfer format. It can be used with any Atmel Two-wire Interface bus IC or SMBus compatible master. TWIS is always a bus slave and can transfer sequential or single bytes. Below, Table 28-1 on page 729 lists the compatibility level of the Atmel Two-wire Slave Interface and a full IC compatible device. Table 28-1. Atmel TWIS Compatibility with IC Standard IC Standard Atmel TWIS Standard Mode Speed (100 KHz) Supported Fast Mode Speed (400 KHz) Supported 7 or 10 bits Slave Addressing Supported START BYTE(1) Not Supported Repeated Start (Sr) Condition Supported ACK and NAK Management Supported Slope control and input filtering (Fast mode) Supported Clock stretching Supported Note: 1. START + b000000001 + Ack + Sr 729 32117A-10/2010 AT32UC3C Below, Table 28-2 on page 730 lists the compatibility level of the Atmel Two-wire Slave Interface and a full SMBus compatible device. Table 28-2. 28.3 SMBus Standard Atmel TWIS Bus Timeouts Supported Address Resolution Protocol Supported Alert Supported Packet Error Checking Supported List of Abbreviations Table 28-3. 28.4 Atmel TWIS Compatibility with SMBus Standard Abbreviations Abbreviation Description TWI Two-wire Interface A Acknowledge NA Non Acknowledge P Stop S Start Sr Repeated Start SADR Slave Address ADR Any address except SADR R Read W Write Block Diagram Figure 28-1. Block Diagram Peripheral Bus Bridge TWCK I/O controller Two-wire Interface Power Manager TWD TWALM Interrupt Controller CLK_TWIS TWI Interrupt 730 32117A-10/2010 AT32UC3C 28.5 Application Block Diagram Figure 28-2. Application Block Diagram VDD Rp Host with TWI Interface Rp TWD TWCK Atmel TWI serial EEPROM Slave 1 IC RTC IC LCD controller IC temp. sensor Slave 2 Slave 3 Slave 4 Rp: Pull up value as given by the IC Standard 28.6 I/O Lines Description Table 28-4. I/O Lines Description Pin Name Pin Description TWD Two-wire Serial Data Input/Output TWCK Two-wire Serial Clock Input/Output TWALM SMBus SMBALERT Input/Output 28.7 Type Product Dependencies In order to use this module, other parts of the system must be configured correctly, as described below. 28.7.1 I/O Lines Both TWD and TWCK are bidirectional lines, connected to a positive supply voltage via a current source or pull-up resistor (see Figure 28-2 on page 731). When the bus is free, both lines are high. The output stages of devices connected to the bus must have an open-drain or open-collector to perform the wired-AND function. TWALM is used to implement the optional SMBus SMBALERT signal. TWALM, TWD, and TWCK pins may be multiplexed with I/O Controller lines. To enable the TWIS, the programmer must perform the following steps: * Program the I/O Controller to: - Dedicate TWD, TWCK and optionally TWALM as peripheral lines. - Define TWD, TWCK and optionally TWALM as open-drain. 731 32117A-10/2010 AT32UC3C 28.7.2 Power Management If the CPU enters a sleep mode that disables clocks used by the TWIS, the TWIS will stop functioning and resume operation after the system wakes up from sleep mode. TWIS is able to wake the system from sleep mode upon address match, see Section 28.8.8 on page 739. 28.7.3 Clocks The clock for the TWIS bus interface (CLK_TWIS) is generated by the Power Manager. This clock is enabled at reset, and can be disabled in the Power Manager. It is recommended to disable the TWIS before disabling the clock, to avoid freezing the TWIS in an undefined state. 28.7.4 Interrupts The TWIS interrupt request lines are connected to the interrupt controller. Using the TWIS interrupts requires the interrupt controller to be programmed first. 28.7.5 28.8 28.8.1 Debug Operation When an external debugger forces the CPU into debug mode, the TWIS continues normal operation. If the TWIS 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. Functional Description Transfer Format The data put on the TWD line must be 8 bits long. Data is transferred MSB first; each byte must be followed by an acknowledgement. The number of bytes per transfer is unlimited (see Figure 28-4 on page 732). Each transfer begins with a START condition and terminates with a STOP condition (see Figure 28-3 on page 732). * A high-to-low transition on the TWD line while TWCK is high defines the START condition. * A low-to-high transition on the TWD line while TWCK is high defines a STOP condition. Figure 28-3. START and STOP Conditions TWD TWCK Start Stop Figure 28-4. Transfer Format TWD TWCK Start Address R/W Ack Data Ack Data Ack Stop 732 32117A-10/2010 AT32UC3C 28.8.2 Operation TWIS has two modes of operation: * Slave transmitter mode * Slave receiver mode A master is a device which starts and stops a transfer and generates the TWCK clock. A slave is assigned an address and responds to requests from the master. These modes are described in the following chapters. Figure 28-5. Typical Application Block Diagram VDD Rp Host with TWI Interface Rp TWD TWCK Atmel TWI Serial EEPROM Slave 1 IC RTC IC LCD Controller IC Temp. Sensor Slave 2 Slave 3 Slave 4 Rp: Pull up value as given by the IC Standard 28.8.2.1 Bus Timing The Timing Register (TR) is used to control the timing of bus signals driven by TWIS. TR describes bus timings as a function of cycles of the prescaled CLK_TWIS. The clock prescaling can be selected through TR.EXP. f CLK - TWIS f prescaled = -------------------------( EXP + 1 ) ) 2 TR has the following fields: TLOWS: Prescaled clock cycles used to time SMBUS timeout TLOW:SEXT. TTOUT: Prescaled clock cycles used to time SMBUS timeout TTIMEOUT. SUDAT: Non-prescaled clock cycles for data setup and hold count. Used to time TSU_DAT. EXP: Specifies the clock prescaler setting used for the SMBUS timeouts. 733 32117A-10/2010 AT32UC3C Figure 28-6. Bus Timing Diagram t HIGH t LOW S t HD:STA t LOW t SU:DAT t HD:DAT t t 28.8.2.2 t SU:DAT SU:STA SU:STO P Sr Setting Up and Performing a Transfer Operation of TWIS is mainly controlled by the Control Register (CR). The following list presents the main steps in a typical communication: 1. Before any transfers can be performed, bus timings must be configured by programming the Timing Register (TR). 2. If a DMA controller is to be used for the transfers, it must be set up. 3. The Control Register (CR) must be configured with information such as the slave address, SMBus mode, Packet Error Checking (PEC), number of bytes to transfer, and which addresses to match. The interrupt system can be set up to give interrupt request on specific events or error conditions, for example when a byte has been received. The NBYTES register is only used in SMBus mode, when PEC is enabled. In IC mode or in SMBus mode when PEC is disabled, the NBYTES register is not used, and should be written to 0. NBYTES is updated by hardware, so in order to avoid hazards, software updates of NBYTES can only be done through writes to the NBYTES register. 28.8.2.3 Address Matching TWIS can be set up to match several different addresses. More than one address match may be enabled simultaneously, allowing TWIS to be assigned to several addresses. The address matching phase is initiated after a START or REPEATED START condition. When TWIS receives an address that generates an address match, an ACK is automatically returned to the master. In IC mode: * The address in CR.ADR is checked for address match if CR.SMATCH is set. * The General Call address is checked for address match if CR.GCMATCH is set. In SMBus mode: 734 32117A-10/2010 AT32UC3C * The address in CR.ADR is checked for address match if CR.SMATCH is set. * The Alert Response Address is checked for address match if CR.SMAL is set. * The Default Address is checked for address match if CR.SMDA is set. * The Host Header Address is checked for address match if CR.SMHH is set. 28.8.2.4 Clock Stretching Any slave or bus master taking part in a transfer may extend the TWCK low period at any time. TWIS may extend the TWCK low period after each byte transfer if CR.STREN=1 and: * Module is in slave transmitter mode, data should be transmitted, but THR is empty, or * Module is in slave receiver mode, a byte has been received and placed into the internal shifter, but RHR is full, or * Stretch-on-address-match bit CR.SOAM=1 and slave was addressed. Bus clock remains stretched until all address match bits in SR have been cleared. If CR.STREN=0 and: * Module is in slave transmitter mode, data should be transmitted but THR is empty: Transmit the value present in THR (the last transmitted byte or reset value), and set SR.URUN. * Module is in slave receiver mode, a byte has been received and placed into the internal shifter, but RHR is full: Discard the received byte and set SR.ORUN. 28.8.2.5 Bus Errors If a bus error (misplaced START or STOP) condition is detected, the SR.BUSERR bit is set and TWIS waits for a new START condition. 28.8.3 Slave Transmitter Mode If TWIS matches an address in which the R/W bit in the TWI address phase transfer is set, it will enter slave transmitter mode and set the SR.TRA bit. After the address phase, the following actions are performed: 1. If SMBus mode and PEC is used, NBYTES must be set up with the number of bytes to transmit. This is necessary in order to know when to transmit PEC byte. NBYTES can also be used to count the number of bytes received if using DMA. 2. Byte to transmit depends on IC/SMBus mode and CR.PEC: - If in IC mode or CR.PEC=0 or NBYTES!=0: TWIS waits until THR contains a valid data byte, possibly stretching the low period of TWCK. After THR contains a valid data byte, the data byte is transferred to a shifter, and then SR.TXRDY is changed to one because the THR is empty again. - SMBus mode and CR.PEC=1: If NBYTES=0, the generated PEC byte is automatically transmitted instead of a data byte from THR. TWCK will not be stretched by TWIS. 3. The data byte in the shifter is transmitted. 4. NBYTES is updated. If CR.CUP is set, NBYTES is incremented, otherwise NBYTES is decremented. 5. After each data byte has been transmitted, the master transmits an ACK (Acknowledge) or NAK (Not Acknowledge) bit. If a NAK bit is received by the TWIS, the SR.NAK bit is changed to one, then the SR.BTF (Byte Transfer Finished) bit is changed to one. The NAK indicates that the transfer is finished, and TWIS will wait for a STOP or REPEATED START. If an ACK bit is received, the SR.NAK bit remains at zero, and the 735 32117A-10/2010 AT32UC3C SR.BTF bit is changed to one. The ACK indicates that more data should be transmitted, so jump to step 2. 6. If STOP is received, SR.TCOMP and SR.STO will be set. 7. If REPEATED START is received, SR.REP will be set. The TWI transfers require the receiver to acknowledge each received data byte. During the acknowledge clock pulse (9th pulse), the slave releases the data line (HIGH), enabling the master to pull it down in order to generate the acknowledge. The slave polls the data line during this clock pulse and sets the NAK bit in the Status Register if the master does not acknowledge the data byte. A NAK means that the master does not wish to receive additional data bytes. As with the other status bits, an interrupt can be generated if enabled in the Interrupt Enable Register (IER). TXRDY is used as Transmit Ready for the Peripheral DMA Controller transmit channel. The end of the complete transfer is marked by the SR.TCOMP bit set to one. See Figure 28-7 on page 736 and Figure 28-8 on page 736. Figure 28-7. Slave Transmitter with One Data Byte TWD S DADR R A DATA N P TCOMP TXRDY STOP sent by master Write THR (DATA) NBYTES set to 1 Figure 28-8. Slave Transmitter with Multiple Data Bytes TWD S DADR R A DATA n A DATA n+5 A DATA n+m N P TCOMP TXRDY Write THR (Data n) NBYTES set to m 28.8.4 Write THR (Data n+1) Write THR (Data n+m) Last data sent STOP sent by master Slave Receiver Mode If TWIS matches an address in which the R/W bit in the TWI address phase transfer is cleared, it will enter slave receiver mode and clear SR.TRA. After the address phase, the following is repeated: 736 32117A-10/2010 AT32UC3C 1. If SMBus mode and PEC is used, NBYTES must be set up with the number of bytes to receive. This is necessary in order to know which of the received bytes is the PEC byte. NBYTES can also be used to count the number of bytes received if using DMA. 2. Receive a byte. Set SR.BTF when done. 3. Update NBYTES. If CR.CUP is written to one, NBYTES is incremented, otherwise NBYTES is decremented. NBYTES is usually configured to count downwards if PEC is used. 4. After a data byte has been received, the slave transmits an ACK or NAK bit. For ordinary data bytes, the CR.ACK field controls if an ACK or NAK should be returned. If PEC is enabled and the last byte received was a PEC byte (indicated by NBYTES=0), TWIS will automatically return an ACK if the PEC value was correct, otherwise a NAK will be returned. 5. If STOP is received, SR.TCOMP will be set. 6. If REPEATED START is received, SR.REP will be set. The TWI transfers require the receiver to acknowledge each received data byte. During the acknowledge clock pulse (9th pulse), the master releases the data line (HIGH), enabling the slave to pull it down in order to generate the acknowledge. The master polls the data line during this clock pulse. RXRDY is used as Receive Ready for the Peripheral DMA Controller receive channel. Figure 28-9. Slave Receiver with One Data Byte TWD S DADR W A DATA A P TCOMP RXRDY Read RHR Figure 28-10. Slave Receiver with Multiple Data Bytes TWD S DADR W A DATA n A DATA (n+1) A DAT A (n+m)-1 A DATA (n+m) A P TCOMP RXRDY Read RHR DATA n Read RHR DATA (n+1) Read RHR DAT A (n+m)-1 Read RHR DATA (n+m) 737 32117A-10/2010 AT32UC3C 28.8.5 Interactive ACKing Received Data Bytes When implementing a register interface over TWI, it may sometimes be necessary or just useful to report reads and writes to invalid register addresses by sending a NAK to the host. To be able to do this, one must first receive the register address from the TWI bus, and then tell the TWIS whether to ACK or NAK it. In normal operation of the TWIS, this is not possible because the controller will automatically ACK the byte at about the same time as the RXRDY interrupt flag is set. Writing a one to the Stretch on Data Byte Received bit (CR[SODR]) will stretch the clock allowing the user to update CR[ACK] bit before returning the desired value. After the last bit in the data byte is received, the TWI bus clock is stretched, the received data byte is transferred to the RHR register, and SR[BTF] is set. At this time, the user can examine the received byte and write the desired ACK or NACK value to CR[ACK]. When the user clears SR[BTF], the desired ACK value is transferred on the TWI bus. This makes it possible to look at the byte received, determine if it's valid, and then decide to ACK or NAK it. 28.8.6 Using the Peripheral DMA Controller The use of the Peripheral DMA Controller significantly reduces the CPU load. The programmer can set up ring buffers for the DMA controller, containing data to transmit or free buffer space to place received data. By initializing NBYTES to 0 before a transfer, and setting CR.CUP, NBYTES is incremented by 1 each time a data has been transmitted or received. This allows the programmer to detect how much data was actually transferred by the DMA system. To assure correct behavior, respect the following programming sequences: 28.8.6.1 Data Transmit with the Peripheral DMA Controller 1. Initialize the transmit Peripheral DMA Controller (memory pointers, size, etc.). 2. Configure the TWIS (ADR, NBYTES, etc.). 3. Start the transfer by setting the Peripheral DMA Controller TXTEN bit. 4. Wait for the Peripheral DMA Controller end TX flag. 5. Disable the Peripheral DMA Controller by setting the Peripheral DMA Controller TXDIS bit. 28.8.6.2 Data Receive with the Peripheral DMA Controller 1. Initialize the receive Peripheral DMA Controller (memory pointers, size - 1, etc.). 2. Configure the TWIS (ADR, NBYTES, etc.). 3. Start the transfer by setting the Peripheral DMA Controller RXTEN bit. 4. Wait for the Peripheral DMA Controller end RX flag. 5. Disable the Peripheral DMA Controller by setting the Peripheral DMA Controller RXDIS bit. 28.8.7 SMBus Mode SMBus mode is enabled when CR.SMEN is written to one. SMBus mode operation is similar to IC operation with the following exceptions: * Only 7-bit addressing can be used. * The SMBus standard describes a set of timeout values to ensure progress and throughput on the bus. These timeout values must be programmed into TR. * Transmissions can optionally include a CRC byte, called Packet Error Check (PEC). * A dedicated bus line, SMBALERT, allows a slave to get a master's attention. 738 32117A-10/2010 AT32UC3C * A set of addresses have been reserved for protocol handling, such as Alert Response Address (ARA) and Host Header (HH) Address. Address matching on these addresses can be enabled by configuring CR appropriately. 28.8.7.1 Packet Error Checking Each SMBus transfer can optionally end with a CRC byte, called the PEC byte. Writing a one to CR.PECEN enables automatic PEC handling in the current transfer. The PEC generator is always updated on every bit transmitted or received, so that PEC handling on following linked transfers will be correct. In slave receiver mode, the master calculates a PEC value and transmits it to the slave after all data bytes have been transmitted. Upon reception of this PEC byte, the slave will compare it to the PEC value it has computed itself. If the values match, the data was received correctly, and the slave will return an ACK to the master. If the PEC values differ, data was corrupted, and the slave will return a NAK value. The SR.SMBPECERR bit is set automatically if a PEC error occurred. In slave transmitter mode, the slave calculates a PEC value and transmits it to the master after all data bytes have been transmitted. Upon reception of this PEC byte, the master will compare it to the PEC value it has computed itself. If the values match, the data was received correctly. If the PEC values differ, data was corrupted, and the master must take appropriate action. The PEC byte is automatically inserted in a slave transmitter transmission if PEC enabled when NBYTES reaches zero. The PEC byte is identified in a slave receiver transmission if PEC enabled when NBYTES reaches zero. NBYTES must therefore be set to the total number of data bytes in the transmission, including the PEC byte. 28.8.7.2 Timeouts The Timing Register (TR) configures the SMBus timeout values. If a timeout occurs, the slave will leave the bus. The SR.SMBTOUT bit is also set. 28.8.7.3 SMBALERT A slave can get the master's attention by pulling the SMBALERT line low. This is done by setting the CR.SMBAL bit. This will also enable address match on the Alert Response Address (ARA). 28.8.8 Wakeup from Sleep Modes by TWI Address Match The TWIS is able to wake the device up from sleep modes upon an address match, including modes where CLK_TWIS is stopped. If a TWI Start condition is received in a sleep mode where CLK_TWIS is stopped, TWIS will stretch TWCK until CLK_TWIS has started. The time required for restarting CLK_TWIS depends on which sleep mode the system was in. When CLK_TWIS has been restarted, the TWCK stretching is released and the slave address will be received on the TWI bus. To save power, only a limited part of the device including TWIS receives a clock at this time. If the address phase causes a TWIS address match, the entire device will be wakened and normal TWIS address match actions performed. Normal TWI transfer will then follow. If the TWIS was not addressed by the transfer, CLK_TWIS will automatically be stopped and the system will go back to the original sleep mode. 739 32117A-10/2010 AT32UC3C 28.8.9 Identifying Bus Events This chapter lists the different bus events, and how these affects bits in the TWIS registers. This is intended to help writing drivers for the TWIS. Table 28-5. Bus Events Event Effect Slave transmitter has sent a data byte SR.THR is cleared. SR.BTF is set. The value of the ACK bit sent immediately after the data byte is given by CR.ACK. Slave receiver has received a data byte SR.RHR is set. SR.BTF is set. SR.NAK updated according to value of ACK bit received from master. Start+Sadr on bus, but address is to another slave None. Start+Sadr on bus, current slave is addressed, but address match enable bit in CR is not set None. Start+Sadr on bus, current slave is addressed, corresponding address match enable bit in CR set Correct address match bit in SR is set. SR.TRA updated according to transfer direction. Slave enters appropriate transfer direction mode and data transfer can commence. Start+Sadr on bus, current slave is addressed, corresponding address match enable bit in CR set, SR.STREN and SR.SOAM are set. Correct address match bit in SR is set. SR.TRA updated according to transfer direction. Slave stretches TWCK immediately after transmitting the address ACK bit. TWCK remains stretched until all address match bits in SR have been cleared. Slave the enters appropriate transfer direction mode and data transfer can commence. Repeated Start received after being addressed SR.REP set. SR.TCOMP unchanged. Stop received after being addressed SR.STO set. SR.TCOMP set. Start, Repeated Start or Stop received in illegal position on bus SR.BUSERR set. Data is to be received in slave receiver mode, SR.STREN is set, and RHR is full TWCK is stretched until RHR has been read. Data is to be transmitted in slave receiver mode, SR.STREN is set, and THR is empty TWCK is stretched until THR has been written. Data is to be received in slave receiver mode, SR.STREN is cleared, and RHR is full TWCK is not stretched, read data is discarded. SR.ORUN is set. 740 32117A-10/2010 AT32UC3C Table 28-5. Bus Events Event Effect Data is to be transmitted in slave receiver mode, SR.STREN is cleared, and THR is empty TWCK is not stretched, previous contents of THR is written to bus. SR.URUN is set. SMBus timeout received SR.SMBTOUT is set. TWCK and TWD are immediately released. Slave transmitter in SMBus PEC mode has transmitted a PEC byte, that was not identical to the PEC calculated by the master receiver. Slave receiver discovers SMBus PEC Error Master receiver will transmit a NAK as usual after the last byte of a master receiver transfer. Master receiver will retry the transfer at a later time. SR.SMBPECERR is set. NAK returned after the data byte. 741 32117A-10/2010 AT32UC3C 28.9 User Interface Table 28-6. TWIS Register Memory Map Offset Register Register Name Access Reset 0x00 Control Register CR Read/Write 0x00000000 0x04 NBYTES Register NBYTES Read/Write 0x00000000 0x08 Timing Register TR Read/Write 0x00000000 0x0C Receive Holding Register RHR Read-only 0x00000000 0x10 Transmit Holding Register THR Write-only 0x00000000 0x14 Packet Error Check Register PECR Read-only 0x00000000 0x18 Status Register SR Read-only 0x00000002 0x1c Interrupt Enable Register IER Write-only 0x00000000 0x20 Interrupt Disable Register IDR Write-only 0x00000000 0x24 Interrupt Mask Register IMR Read-only 0x00000000 0x28 Status Clear Register SCR Write-only 0x00000000 0x2C Parameter Register PR Read-only (1) 0x30 Version Register VR Read-only (1) Note: 1. The reset values for these registers are device specific. Please refer to the Module Configuration section at the end of this chapter. 742 32117A-10/2010 AT32UC3C 28.9.1 Name: Control Register CR Access Type: Read/Write Offset: 0x00 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - TENBIT 23 22 21 20 19 18 17 16 ADR[9:8] ADR[7:0] 15 14 13 12 11 10 9 8 SODR SOAM CUP ACK PECEN SMHH SMDA SMBALERT 7 6 5 4 3 2 1 0 SWRST - - STREN GCMATCH SMATCH SMEN SEN * TENBIT: Ten Bit Address Match Write this bit to zero to disable Ten Bit Address Match. Write this bit to one to enable Ten Bit Address Match. * ADR: Slave Address Slave address used in slave address match. Bits 9:0 are used if in 10-bit mode, bits 6:0 otherwise. * SODR: Stretch Clock on Data Byte Reception Writing this bit to zero will not stretch bus clock immediately before ACKing a received data byte. Writing this bit to one will strech bus clock immediately before ACKing a received data byte. * SOAM: Stretch Clock on Address Match Writing this bit to zero will not strech bus clock after address match. Writing this bit to one will strech bus clock after address match. * CUP: NBYTES Count Up Writing this bit to zero causes NBYTES to count down (decrement) per byte transferred. Writing this bit to one causes NBYTES to count up (increment) per byte transferred. * ACK: Slave Receiver Data Phase ACK Value Writing this bit to zero causes a low value to be returned in the ACK cycle of the data phase in slave receiver mode. Writing this bit to one causes a high value to be returned in the ACK cycle of the data phase in slave receiver mode. * PECEN: Packet Error Checking Enable Writing this bit to zero disables SMBus PEC (CRC) generation and check. Writing this bit to one enables SMBus PEC (CRC) generation and check. * SMHH: SMBus Host Header Writing this bit to zero causes TWIS not to acknowledge the SMBus Host Header. Writing this bit to one causes TWIS to acknowledge the SMBus Host Header. * SMDA: SMBus Default Address Writing this bit to zero causes TWIS not to acknowledge the SMBus Default Address. Writing this bit to one causes TWIS to acknowledge the SMBus Default Address. * SMBALERT: SMBus Alert Writing this bit to zero causes TWIS to release the SMBALERT line and not to acknowledge the SMBus Alert Response Address (ARA). 743 32117A-10/2010 AT32UC3C * * * * * * Writing this bit to one causes TWIS to pull down the SMBALERT line and to acknowledge the SMBus Alert Response Address (ARA). SWRST: Software Reset This bit will always read as 0. Writing a zero to this bit has no effect. Writing a one to this bit resets the TWIS. STREN: Clock Stretch Enable Writing this bit to zero disables clock stretching if RHR/THR buffer full/empty. May cause over/underrun. Writing this bit to one enables clock stretching if RHR/THR buffer full/empty. GCMATCH: General Call Address Match Writing this bit to zero causes TWIS not to acknowledge the General Call Address. Writing this bit to one causes TWIS to acknowledge the General Call Address. SMATCH: Slave Address Match Writing this bit to zero causes TWIS not to acknowledge the Slave Address. Writing this bit to one causes TWIS to acknowledge the Slave Address. SMEN: SMBus Mode Enable Writing this bit to zero disables SMBus mode. Writing this bit to one enables SMBus mode. SEN: Slave Enable Writing this bit to zero disables the slave interface. Writing this bit to one enables the slave interface. 744 32117A-10/2010 AT32UC3C 28.9.2 Name: NBYTES Register NBYTES Access Type: Read/Write Offset: 0x04 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 19 18 17 16 11 10 9 8 3 2 1 0 - 23 22 21 20 - 15 14 13 12 - 7 6 5 4 NBYTES * NBYTES: Number of Bytes to Transfer Writing to this field updates the NBYTES counter. Can also be read to to learn the progress of the transfer. Can be incremented or decremented automatically by hardware. 745 32117A-10/2010 AT32UC3C 28.9.3 Name: Timing Register TR Access Type: Read/Write Offset: 0x08 Reset Value: 0x00000000 31 30 29 28 27 26 EXP 23 22 25 24 - 21 20 19 18 17 16 11 10 9 8 3 2 1 0 SUDAT 15 14 13 12 TTOUT 7 6 5 4 TLOWS * EXP: Clock Prescaler Used to specify how to prescale the SMBus TLOWS counter. The counter is prescaled according to the following formula: f clkpb f prescaled = ----------------------( EXP + 1 ) 2 * SUDAT: Data Setup Cycles Non-prescaled clock cycles for data setup count. Used to time TSU_DAT. Data is driven SUDAT cycles after TWCK low detected. This timing is used for timing the ACK/NAK bits, and any data bits driven in slave transmitter mode. * TTOUT: SMBus Ttimeout Cycles Prescaled clock cycles used to time SMBus TTIMEOUT. * TLOWS: SMBus Tlow:sext Cycles Prescaled clock cycles used to time SMBus TLOW:SEXT. 746 32117A-10/2010 AT32UC3C 28.9.4 Name: Receive Holding Register RHR Access Type: Read-only Offset: 0x0C Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 - - - - - - - - 7 6 5 4 3 2 1 0 RXDATA * RXDATA: Received Data Byte When the RXRDY bit in the Status Register (SR) is set, this field contains a byte received from the TWI bus. 747 32117A-10/2010 AT32UC3C 28.9.5 Name: Transmit Holding Register THR Access Type: Write-only Offset: 0x10 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 - - - - - - - - 7 6 5 4 3 2 1 0 TXDATA * TXDATA: Data Byte to Transmit Write data to be transferred on the TWI bus here. 748 32117A-10/2010 AT32UC3C 28.9.6 Name: Packet Error Check Register PECR Access Type: Read-only Offset: 0x14 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 - - - - - - - - 7 6 5 4 3 2 1 0 PEC * PEC: Calculated PEC Value The calculated PEC value. Updated automatically by hardware after each byte has been transferred. Reset by hardware after a STOP condition. Provided if the user manually wishes to control when the PEC byte is transmitted, or wishes to access the PEC value for other reasons. In ordinary operation, the PEC handling is done automatically by hardware. 749 32117A-10/2010 AT32UC3C 28.9.7 Name: Status Register SR Access Type: Read-only Offset: 0x18 Reset Value: 0x000000002 31 30 29 28 27 26 25 24 - 23 22 21 20 19 18 17 16 BTF REP STO SMBDAM SMBHHM SMBALERTM GCM SAM 15 14 13 12 11 10 9 8 - BUSERR SMBPECERR SMBTOUT - - - NAK 7 6 5 4 3 2 1 0 ORUN URUN TRA - TCOMP SEN TXRDY RXRDY * BTF: Byte Transfer Finished This bit is set when byte transfer has completed. This bit is cleared when the corresponding bit in SCR is written to one. * REP: Repeated Start Received This bit is set when REPEATED START condition received. This bit is cleared when the corresponding bit in SCR is written to one. * STO: Stop Received This bit is set when STOP condition received. This bit is cleared when the corresponding bit in SCR is written to one. * SMBDAM: SMBus Default Address Match This bit is set when received address matched SMBus Default Address. This bit is cleared when the corresponding bit in SCR is written to one. * SMBHHM: SMBus Host Header Address Match This bit is set when received address matched SMBus Host Header Address. This bit is cleared when the corresponding bit in SCR is written to one. * SMBALERTM: SMBus Alert Response Address Match This bit is set when received address matched SMBus Alert Response Address. This bit is cleared when the corresponding bit in SCR is written to one. * GCM: General Call Match This bit is set when received address matched General Call Address. This bit is cleared when the corresponding bit in SCR is written to one. * SAM: Slave Address Match This bit is set when received address matched Slave Address. This bit is cleared when the corresponding bit in SCR is written to one. * BUSERR: Bus Error This bit is set when a misplaced start or stop condition has occurred. This bit is cleared when the corresponding bit in SCR is written to one. 750 32117A-10/2010 AT32UC3C * SMBPECERR: SMBus PEC Error This bit is set when SMBus PEC error has occurred. This bit is cleared when the corresponding bit in SCR is written to one. * SMBTOUT: SMBus Timeout This bit is set when SMBus timeout has occurred. This bit is cleared when the corresponding bit in SCR is written to one. * NAK: NAK Received This bit is set when NAK was received from master during slave transmitter operation. This bit is cleared when the corresponding bit in SCR is written to one. * ORUN: Overrun This bit is set when overrun has occurred in slave receiver mode. Can only occur if CR.STREN=0. This bit is cleared when the corresponding bit in SCR is written to one. * URUN: Underrun This bit is set when underrun has occurred in slave transmitter mode. Can only occur if CR.STREN=0. This bit is cleared when the corresponding bit in SCR is written to one. * TRA: Transmitter Mode 0: The slave is in slave receiver mode. 1: The slave is in slave transmitter mode. * TCOMP: Transmission Complete This bit is set when transmission is complete. Set after receiving a STOP after being addressed. This bit is cleared when the corresponding bit in SCR is written to one. * SEN: Slave Enabled 0: The slave interface is disabled. 1: The slave interface is enabled. * TXRDY: TX Buffer Ready 0: The TX buffer is full and should not be written to. 1: The TX buffer is empty, and can accept new data. * RXRDY: RX Buffer Ready 0: No RX data ready in RHR. 1: RX data is ready to be read from RHR. 751 32117A-10/2010 AT32UC3C 28.9.8 Name: Interrupt Enable Register IER Access Type: Write-only Offset: 0x1C Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 BTF REP STO SMBDAM SMBHHM SMBALERTM GCM SAM 15 14 13 12 11 10 9 8 - BUSERR SMBPECERR SMBTOUT - - - NAK 7 6 5 4 3 2 1 0 ORUN URUN - - TCOMP - TXRDY RXRDY Writing a zero to a bit in this register has no effect. Writing a one to a bit in this register will set the corresponding bit in IMR. 752 32117A-10/2010 AT32UC3C 28.9.9 Name: Interrupt Disable Register IDR Access Type: Write-only Offset: 0x20 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 BTF REP STO SMBDAM SMBHHM SMBALERTM GCM SAM 15 14 13 12 11 10 9 8 - BUSERR SMBPECERR SMBTOUT - - - NAK 7 6 5 4 3 2 1 0 ORUN URUN - - TCOMP - TXRDY RXRDY Writing a zero to a bit in this register has no effect. Writing a one to a bit in this register will clear the corresponding bit in IMR. 753 32117A-10/2010 AT32UC3C 28.9.10 Name: Interrupt Mask Register IMR Access Type: Read-only Offset: 0x24 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 BTF REP STO SMBDAM SMBHHM SMBALERTM GCM SAM 15 14 13 12 11 10 9 8 - BUSERR SMBPECERR SMBTOUT - - - NAK 7 6 5 4 3 2 1 0 ORUN URUN - - TCOMP - TXRDY RXRDY 0: The corresponding interrupt is disabled. 1: The corresponding interrupt is enabled. This bit is cleared when the corresponding bit in IDR is written to one. This bit is set when the corresponding bit in IER is written to one. 754 32117A-10/2010 AT32UC3C 28.9.11 Name: Status Clear Register SCR Access Type: Write-only Offset: 0x28 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - 23 22 21 20 19 18 17 16 BTF REP STO SMBDAM SMBHHM SMBALERTM GCM SAM 15 14 13 12 11 10 9 8 - BUSERR SMBPECERR SMBTOUT - - - NAK 7 6 5 4 3 2 1 0 ORUN URUN - - TCOMP - - - Writing a zero to a bit in this register has no effect. Writing a one to a bit in this register will clear the corresponding bit in SR and the corresponding interrupt request. 755 32117A-10/2010 28.9.12 Name: Parameter Register PR Access Type: Read-only Offset: 0x2C Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 - - - - - - - - 7 6 5 4 3 2 1 0 - - - - - - - - This register always reads as zero. No functionality associated. AT32UC3C 28.9.13 Name: Version Register (VR) VR Access Type: Read-only Offset: 0x30 Reset Value: Device-specific 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - 15 14 13 12 9 8 - - - - 7 6 5 4 VARIANT 11 10 VERSION [11:8] 3 2 1 0 VERSION [7:0] * VARIANT: Variant Number Reserved. No functionality associated. * VERSION: Version Number Version number of the module. No functionality associated. 757 32117A-10/2010 AT32UC3C 28.10 Module Configuration The specific configuration for each TWIS instance is listed in the following tables. The module bus clocks listed here are connected to the system bus clocks. Please refer to the Power Manager chapter for details. Table 28-7. Module Configuration Feature TWIM0 TWIM1 TWIM2 SMBus ALERT interface Implemented Implemented Not Implemented Table 28-8. Module Clock Name Module Name Clock Name Description TWIS0 CLK_TWIS0 Peripheral Bus clock from the PBA clock domain TWIS1 CLK_TWIS1 Peripheral Bus clock from the PBA clock domain TWIS2 CLK_TWIS2 Peripheral Bus clock from the PBC clock domain Table 28-9. Register Reset Values Register Reset Value VR 0x00000120 PR 0x00000000 758 32117A-10/2010 AT32UC3C 29. CAN Interface (CANIF) Version 1.1.0.2 29.1 Features * * * * * * * * * * * 29.2 Supports CAN 2.0A and 2.0B protocol specifications 1 Mb/s maximum bitrate 2 CAN channels 16 Message Objects per CAN channel 1 identifier (11 or 29 bits), 1 identifier mask and 8 bytes buffer per MOb Single shot and automatic transmit/receive modes Overrun mode Loop-back mode for bit rate detection Listen mode for bus monitoring System sleep mode support with wake-up on bus activity Programmable CAN clock source Overview Control Area Network (CAN) is a serial communication protocol with high level of security. Each node is master on the bus but only one at a time is able to send a message. CANIF is a 32-bit interface for CAN channels. Each channel provides the following services: * Message filtering * Message and status handling * Fault confinement * Error detection and signalling * Message validation and acknowledgement * Bus arbitration * Message framing * Transfer rate and timing These services, with the exception of message filtering and message handling, are described in the CAN protocol, please refer to Bosch - CAN Specification for more details. 759 32117A-10/2010 AT32UC3C 29.3 Block Diagram Figure 29-1. CANIF Block Diagram PB TXLINE(0) RXLINE(0) Msg Handling & Filtering RAM Protocol Engine . . . TXLINE(n) RXLINE(n) CANIF CAN clock HSB 29.4 I/O Lines Description Table 29-1. 29.5 I/O Lines Description Pin Name Pin Description Type TXLINE(n) Transmission line of channel n Output RXLINE(n) Reception line of channel n Input Product Dependencies In order to use this module, other parts of the system must be configured correctly, as described below. 29.5.1 I/O Lines CANIF pins are multiplexed with other peripherals. User must first program the I/O Controller to give control of the pins to the CANIF. 29.5.2 Power Management If the CPU enters a sleep mode that disables clocks used by CANIF, it will stop functioning and resume operation after the system wakes up from sleep mode. 29.5.3 Clocks CANIF is connected to both the HSB and the PB, and therefore uses a HSB clock (CLK_CANIF_HSB) and a PB clock (CLK_CANIF_PB). These clocks are generated by the Power Manager. These clocks are enabled at reset, and can be disabled in the Power Manager. CANIF uses a GCLK as clock source (CAN clock) for the CAN bus communication (GCLK_CANIF). User must make sure this clock is running and frequency is correct before any operation. 29.5.4 Memory Messages can be stored in CPU or HSB RAM, so user must allocate RAM space for CAN messages. 760 32117A-10/2010 AT32UC3C 29.5.5 Interrupts CANIF interrupt request line is connected to the interrupt controller. Using the CANIF interrupt requires the interrupt controller to be programmed first. 29.5.6 29.6 Debug Operation All CAN channels are disabled when the CPU enters Debug mode. Communication in progress is not stopped. Please refer to the On-Chip Debug chapter in the AVR32UC Technical Reference Manual, and the OCD Module Configuration section, for details. Functional Description 29.6.1 Channel Configuration Channel configuration is done via the Configuration Register (CANCFG). This register is not write accessible once the channels have been enabled. 29.6.1.1 Bit timing This section refers to chapter 8 (Bit timing requirements) of the CAN Specification. The CAN bit rate is defined by the nominal bit time. Nominal bit time is divided into 4 time segments. Figure 29-2. Partition of the Bit Time Nominal bit time SYNC_SEG PROP_SEG PHASE_SEG1 PHASE_SEG2 Sample Point The duration of each time segment is divided into time quanta (TQ). The total number of TQ in a bit time must be in the range [8..25]. The Time Quantum is a fixed unit of time derived from the GCLK_CANIF clock period: TQ = Prescaler x PGCLK_CANIF = (CANCFG.PRES+1) x PGCLK_CANIF Re-synchronization may lengthen or shorten the bit time, the upper bound is given by Synchronization Jump Width field in the Configuration Register (CANCFG.SJW). The value of all previous parameters are defined in CANCFG register. Table 29-2. CAN Parameter Settings Parameter Range CANCFG field SYNC_SEG 1 - PROP_SEG [1..8]TQ PRS + 1 PHASE_SEG1 [1..8]TQ PHS1 + 1 761 32117A-10/2010 AT32UC3C Table 29-2. CAN Parameter Settings Parameter Range CANCFG field PHASE_SEG2 [1..8]TQ PHS2 + 1 Prescaler [2..32] PRES + 1 Sync Jump Width [1..4] SJW + 1 The bit duration is given by the formula: Tbit = (PRS + PHS1 + PHS2 + 4) x (PRES + 1) x PGCLK_CANIF Note: PRES should not be set to 0, therefore CAN clock is at least divided by 2. 29.6.1.2 Sampling method Bits are sampled between PHASE_SEG1 and PHASE_SEG2. By writing the Sampling Method bit (CANCFG.SM) to one, three samples are taken and a majority vote is performed. Figure 29-3. Sampling by Majority Voting CAN clock Bit Samples PHASE_SEG1 S1 S2 PHASE_SEG2 SP Majority voting must not be used when the Prescaler field (CANCFG.PRES) is equal to zero. 29.6.1.3 Operating modes CANIF has three operating modes, selectable by the Channel Mode field (CANCFG.CMODE): - Normal mode (CANCFG.CMODE=00) Default mode, TX and RX lines are connected to the transceiver. This mode is used to communicate with other nodes on the bus. - Listening mode (CANCFG.CMODE=01) The TX line is disconnected from the transceiver. The CAN channel cannot send any message nor acknowledge when a message has been received. The channel is in Error Passive mode and Transmit/Receive Error Counters (TEC/REC) are frozen. This mode is used to listen to CAN bus. - Loop back mode (CANCFG.CMODE=10) The TX line is internally connected to the RX line and disconnected from the transceiver. The CAN channel can only send messages or acknowledges to itself. The channel is in Error Passive mode and TEC/REC are frozen. This mode is used to detect the bit rate of the CAN bus by successive configuration of bit timing. 29.6.1.4 Overrun mode When Overrun Mode is disabled, the MOb is disabled after successfully receiving a message. This prevents overwriting the received message if a second message is received. Overrun Mode is disabled by writing a zero to CANCFG.OVRM. Overrun Mode is disabled by default. 762 32117A-10/2010 AT32UC3C When Overrun Mode is enabled, the MOb is not disabled after a successful reception. Overrun Mode is enabled by writing a one to CANCFG.OVRM. The Overwrite bit in the MOb Status Register (MObSR.OVW) is set if a previously received message has been overwritten. The mode configured by CANCFG.OVRM is used by all MObs configured for reception. 29.6.1.5 Memory pointer Each channel uses a section of RAM for storing messages. User must allocate RAM space for the channels and store the base address of this space into the Channel RAM Base Address Register (CANRAMB). Four words per MOb in use must be allocated. Channels operate independently so the allocated memory spaces do not need to be consecutive. Make sure that the memory spaces do not overlap. 29.6.2 Channel Handling 29.6.2.1 Initialization CAN channels are initialized by writing a one to the Initialization bit in the Control Register (CANCTRL.INIT). Initialization resets all internal state machines and clears all user interface registers except CANRAMB, CANCFG and CANCTRL.INIT. CANCTRL.INIT should not be cleared until the channel has been disabled. The channel is disabled by writing the Channel Enable bit (CANCTRL.CEN) to zero. When the Channel Enable status bit (CANSR.CEN) is zero, the channel has been disabled and CANCTRL.INIT can be written to zero. Thereafter the channel can be restarted by writing a one to CANCTRL.CEN. See Figure 29-4 for details. It is not possible to write to other CANCTRL bits when CANCTRL.INIT is one. User must write a zero to CANCTRL.INIT before writing a new value to CANCTRL. Figure 29-4. Initialization Sequence CANCTRL.INIT CANCTRL.CEN CANSR.CES init. request (user write) release init. (user write) restart (user write) Note: Initialization requires all clocks to be running. 29.6.2.2 Enabling / Disabling A channel is enabled and ready to communicate on the bus when it has detected a bus idle condition (i.e. 11 consecutive recessive bits). The channel is enabled by writing a one to CANCTRL.CEN and disabled by writing a zero to this bit. The enable status of channel can be read in CANSR.CES bit. 763 32117A-10/2010 AT32UC3C The channel mode is not changed when the channel is disabled, i.e. the Fault Confinement Register (CANFC) is not cleared. Therefore, if the channel was in error passive mode before being disabled, it stays in error passive mode when re-enabled. Figure 29-5. Enable and Disable Sequences CAN bus data frame bus idle data frame CANCTRL.CEN CANSR.CES enable request (user write) 29.6.2.3 disable request (user write) Overload frames The CAN protocol allows nodes to send overload frames to provide extra delay between two messages. User can at any time request to send overload frames by writing the Overload Request bit (CANCTRL.OVRQ) to one. A single overload frame will then be sent at the end of the next message. When transission of the overload frame starts, CANSR.OVS is set and CANCTRL.OVRQ is cleared. At this time, user can write CANCTRL.OVRQ to one again to send a second overload frame at the end of the first one. The CAN protocol specifies that maximum two overload frames can be sent. Figure 29-6. Overload Frame Request CAN bus data or remote frame overload frame 1 overload frame 2 data or remote frame CANSR.OVS CANCTRL.OVRQ user write 29.6.2.4 user write Errors and fault confinement This section refers to chapter 6 (Error handling) and chapter 7 (Fault confinement) of the CAN Specification. There are 5 different error types which are not mutually exclusive. Error status can be read in the Interrupt Status Register (CANISR). Error status bits are set by hardware and can only be cleared by user. When the channel enters bus off state, the Bus Off Status bit (CANISR.BOFF) is set. In this state the channel can no longer communicate on the bus. The channel can leave bus off state if it detects 128 occurrences of 11 consecutive recessive bits on the bus. The Last Selected MOb Status field (CANISR.LSMOB) identifies the MOb that was selected when the error occurred. For some error types, a MOb has not been selected yet when the error occurs. In this case, CANISR.LSMOB returns NONE. 764 32117A-10/2010 AT32UC3C According to the CAN specification, a channel can be in error active, error passive or bus off state. The bus state can be read in the CANFC.EMODE field: Table 29-3. Bus State Coding EMODE State 0 error active state 1 error passive state 2 or 3 bus off state This state depends on both transmit and receive counters value (TEC/REC), also available in the CANFC register (see CAN specification for more details). 29.6.2.5 Wake-up mode In this mode the CAN channel is a wake-up source for the CPU. Detection of a falling edge on the CAN bus is interpreted as the start of frame (SOF) bit of the wake-up frame and will wake the CPU. In order to use this mode, execute the following steps: - Disable CAN channel by writing CANCTRL.CEN to zero - Wait for channel disabled (CANSR.CES is cleared) - Enable wake-up mode by writing CANCTRL.WKEN to one - Optionally mask wake-up interrupt source by writing CANIMR.WKUPIM - Enter sleep mode, stopping PB and CAN clocks - Sleep - Wake-up frame is detected, CANISR.WKUP is set and CPU is woken-up - Clear CANISR.WKUP by writing it to zero - Disable wake-up mode and enable CAN channel Note 1: when channel is disabled PB registers are not cleared, user can resume current application by enabling channel again. Note 2: wake-up frame cannot be received. Moreover next frames cannot be received until CPU is woken-up. Wake-up time depends on sleep modes (see sleep modes section). 29.6.3 Message Handling 29.6.3.1 Message object structure Message Objects (MOb) are message descriptors, used to store and handle CAN frames. User configures and gets status of MObs via user interface registers and writing and reading frames into allocated RAM space (Section 29.6.1.5). MObs are independent and are allocated to one channel. 765 32117A-10/2010 AT32UC3C Figure 29-7. Message Object Structure MOb(i) Registers (PB) RAM (HSB) CONTROL (6 bits) MOBCTRL STATUS (4 bits) MOBSCR/ MOBSR RTR + IDE + ID (31 bits) IDT RTRM + IDEM + IDM (31 bits) IDM Data[31:0] DATA BYTES (64 bits) Data[63:32] Where: * RTR is the Remote Transmission Request, 0 means data frame and 1 remote frame * IDE is the Identifier Extension Bit, 0 means standard format and 1 means extended format * ID is the CAN identifier of message (11 bits in standard format and 29 bits in extended format) * RTRM is the RTR bit Mask * IDEM is the IDE bit Mask * IDM are the ID bits Mask The length of the message (DLC) is stored in the MOb Control Register (MOBCTRL). The data stored in RAM should have the following format: Figure 29-8. Identifier Tag (IDT) 31 30 29 - RTR IDE 31 30 29 - RTR IDE 28 11 10 - 0 Standard format ID (11 bits) 28 0 ID (29 bits) Extended format 766 32117A-10/2010 AT32UC3C Figure 29-9. Identifier Mask (IDM) 31 - 31 - 30 29 28 RTRM IDEM 30 29 11 10 - 0 Standard format IDM (11 bits) 28 0 RTRM IDEM Extended format IDM (29 bits) Figure 29-10. Data Fields (64 bits) 31 29.6.3.2 24 23 16 15 8 7 0 DB3 DB2 DB1 DB0 @ DB7 DB6 DB5 DB4 @+4 Transmission Once a message has been written into RAM at the address corresponding to the selected MOb, user controls transmission through the MOBCTRL register: * DLC[3:0] field: Data length code i.e. the number of byte to send, from 0 to 8 * DIR bit: MOb direction, 1 stands for transmission Once MOb is enabled (by writing to MOBER), transmission starts as soon as bus idle is detected on the CAN bus. User can check if channel is sending a frame by reading CANSR.TS bit. At the end of the successful transmission bit MOBESR.MENn is cleared and MOBSR.TXOK is set. To acknowledge interrupt and to free the MOb user must clear this status bit by writing a one to the associated bit in MOb Status Clear Register (MOBSCR). CAN errors detected during transmission are reported in CANISR. Message will not be transmitted but the MOb remains enabled. The message will be automatically re-transmitted until successfully transmitted. Several MObs can be enabled/disabled in one operation by writing to the MOBER/MOBDR registers: * MOBER: Each bit correspond to an enable bit for a single MOb. Write 1 to set a bit and 0 to keep it unchanged. * MOBDR: Each bit correspond to an enable bit for a single MOb. Write 1 to clear a bit and 0 to keep it unchanged. If several MObs are enabled, the MOb with the lowest number is transmitted first. This rule is also used in case of a re-transmission (due to transmission error or contention). 29.6.3.3 Reception Once the expected message has been written into RAM at the address corresponding to the selected MOb, user controls reception through the MOBCTRL register: * DLC[3:0] field: Data length code i.e. the number of byte to receive, from 0 to 8 767 32117A-10/2010 AT32UC3C * DIR bit: MOb direction, 0 stands for reception Once a MOb is enabled (by writing to MOBER), an incoming frame is compared (Section 29.6.4) with every MOb enabled for reception in order to select the MOb for storing the frame. User can check if the channel is receiving a frame by reading the CANSR.RS bit. At the end of the successful reception, the complete message (ID + RTR + IDE + DATA bits) is stored in RAM, the MOBESR.MENn bit is cleared and MOBSR.RXOK is set. To acknowledge any interrupt and to free the MOb user must clear this status bit by writing a one to the associated bit in MOBSCR. The MOBSR.DLCW bit indicates if the received DLC does not correspond to MOBCTRL.DLC. Any such status should also be cleared by user. CAN errors detected during reception are reported in CANISR register. A corrupted message is not stored to RAM but the selected MOb remains enabled. User can enable/disable several MObs in one operation, by writing to MOBER/MOBDR registers (Section 29.6.3.2). If several MObs are enabled, the MOb priority is given by the filtering order which is from low to high MOb number. 29.6.3.4 Automatic mode All MObs are configured in automatic mode if the Automatic Mode (MOBCTRL.AM) bit is set. The main configurations are: * Remote frame reception - Data frame transmission MOb configuration: MOBCTRL.AM = 1, MOBCTRL.DIR = 0, IDT.RTR = 1 IDT/IDM can be set to receive any identifier but transmission will be done with identifier received. * Remote frame transmission - Data frame reception MOb configuration: MOBCTRL.AM = 1, MOBCTRL.DIR = 1, IDT.RTR = 1 Remote frame is sent with IDT value. Reception uses current IDT value but IDM can be set to filter data frame. Other configurations (IDT.RTR = 0) are possible but does not make sense. Properties: - MOb handling is identical to single configuration (priority, access,...) but: - Bits MOBCTRL.AM and IDT.RTR are inverted at the end of first reception/transmission - Bit MOBSR.TXOK (or RXOK) is only set at the end of the transmission (or reception) 29.6.4 Message Filtering The filtering process uses the ID tag (IDT) and ID mask (IDM) values defined in RAM. Comparison is done on the bits IDENTIFIER, RTR and IDE. Messages can therefore be filtered according to the identifier value, frame type (remote or data frame) and the format (standard or extended). Each received bit is compared with the corresponding bit in the ID tag only if the corresponding bit in ID mask is set. Otherwise the received bit is considered as don't care. The filtering result is true if all comparisons are true. Examples with 11 bits of identifier ( `-` means don't care): 768 32117A-10/2010 AT32UC3C ID received: IDT: IDM: Comparison: Accepted: 000.0010.1001 b 000.0010.1010 b 111.1111.0000 b 111.1111.- - - - b Y 000.0010.1001 b 000.0100.1000 b 111.1111.0000 b 111.1001.- - - - b N The filtering process scans each MOb enabled and configured for reception, from MOb 0, in order to find the MOb that matches the conditions. The first MOb to match is selected for storing the message once received successfully. If no MOb matches, the message is discarded. 29.6.5 Channel Interrupts There are several sources of interrupts and user can mask each of them. Some sources are grouped into a single interrupt request line. There are 5 interrupt request lines per channel. * Wake-up interrupt: Wake-up condition detected * Error interrupt: Any CAN error detected during a communication * Bus off interrupt: The CAN protocol engine entered in bus off state * Took interrupt: At least one MOb completed a transmission * Waxed interrupt: At least one MOb completed a reception The CANIMR and MOBIMR are used for masking interrupts. These registers are read-only. In order to set or clear interrupt mask bits, user must write to the following registers: * CANIER / MOBIER: Writing a bit to one sets the corresponding bit in CANIMR / MOBIMR. Writing a bit to 0 has no effect. * CANIDR / MOBIDR: Writing a bit to one clears the corresponding bit in CANIMR / MOBIMR. Writing a bit to 0 has no effect. To acknowledge an interrupt request, user must clear the corresponding bit in the corresponding status register (CANISR, MTXISR or MRXISR). To clear status bits, user must access the following write-only registers: * CANISCR / MTXISCR / MRXISCR: Writing a bit to one clears the corresponding bit in CANISR / MTXISR / MRXISR. Writing a bit to 0 has no effect. For each MOb, the bits TXOK and RXOK are also accessible in MOBSCR register for clear access and MOBSR register for read access. 769 32117A-10/2010 AT32UC3C Figure 29-11. Interrupt Channel Structure CANIMR WKUPIM BERRI M SERRIM CERRI M FERRIM AERRIM BOFFIM WAKE-UP IRQ WKUP AERR FERR CANISR OR CERR ERROR IRQ SERR BERR BUS OFF IRQ BOFF MOBIMR MIM0 CANIMR TXOKIM RXOKIM .. . OR .. . ... OR ... MTXISR ... ... TXOKi MIMi TXOK IRQ TXOK0 RXOKi ... MRXISR RXOK IRQ RXOK0 770 32117A-10/2010 AT32UC3C 29.7 User Interface Offsets are relative to the base address allocated to CANIF and the channel number. Figure 29-12. Channel Address Map Overview PB registers offset Table 29-4. 0x00 VERSION 0x04 PARAMETER 0x08 CANRAMB 0x0C CANCFG RAM space offset 0x0 ID 0x4 IDM ... 0x8 Data[31:0] 0x58 MTXISR 0xC Data[63:32] 0x5C MOBCTRL 0x10 ID 0x60 MOBSCR 0x14 IDM 0x64 MOBSR 0x18 Data[31:0] 0x68 MOBCTRL 0x1C Data[63:32] 0x6C MOBSCR 0x70 MOBSR CAN registers MOb0 MOb1 MOb0 MOb1 ... (i*0x10) ID ... (i*0x10)+0x4 IDM (i*0xC)+0x5C MOBCTRL (i*0x10)+0x8 ... (i*0xC)+0x60 MOBSCR (i*0xC)+0x64 MOBSR MOb(i) MOb(i) CANIF Register Memory Map Offset Register Register Name Access Reset 0x00 Version Register VERSION Read-only -(Note:) 0x04 Parameter Register PARAMETER Read-only -(Note:) 0x08 RAM Base Address Register CANRAMB Read/Write 0x00000000 0x0C Configuration Register CANCFG Read/Write 0x00000001 0x10 Control Register CANCTRL Read/Write 0x00000000 0x14 Status Register CANSR Read-only 0x00000000 0x18 Fault Confinement Register CANFC Read-only 0x00000000 0x1C Interrupt Enable Register CANIER Write-only 0x00000000 0x20 Interrupt Disable Register CANIDR Write-only 0x00000000 0x24 Interrupt Mask Register CANIMR Read-only 0x00000000 771 32117A-10/2010 AT32UC3C Table 29-4. Note: CANIF Register Memory Map 0x28 Interrupt Status Clear Register CANISCR Write-only 0x00200000 0x2C Interrupt Status Register CANISR Read-only 0x00200000 0x30 MOb Search Register MOBSCH Read-only 0x00202020 0x34 MOb Enable Register MOBER Write-only 0x00000000 0x38 MOb Disable Register MOBDR Write-only 0x00000000 0x3C MOb Enable Status Register MOBESR Read-only 0x00000000 0x40 MOb Interrupt Enable Register MOBIER Write-only 0x00000000 0x44 MOb Interrupt Disable Register MOBIDR Write-only 0x00000000 0x48 MOb Interrupt Mask Register MOBIMR Read-only 0x00000000 0x4C MOb RX Interrupt Status Clear Register MRXISCR Write-only 0x00000000 0x50 MOb RX Interrupt Status Register MRXISR Read-only 0x00000000 0x54 MOb TX Interrupt Status Clear Register MTXISCR Write-only 0x00000000 0x58 MOb TX Interrupt Status Register MTXISR Read-only 0x00000000 0x5C MOb Control Register MOBCTRL Read/Write 0x00000000 0x60 MOb Status Clear Register MOBSCR Write-only 0x00000000 0x64 MOb Status Register MOBSR Read-only 0x00000000 The reset values for these registers are device specific. Please refer to the Module Configuration section at the end of this chapter. 772 32117A-10/2010 AT32UC3C 29.7.1 Name: Version Register VERSION Access type: Read-only Offset: 0x00 Reset Value: - 31 30 - - 23 22 - 29 28 27 26 25 24 18 17 16 9 8 MNCH0 21 20 19 CHNO VARIANT 15 14 13 12 - - - - 7 6 5 4 11 10 VERSION[11:8] 3 2 1 0 VERSION[7:0] * MNCH0: MOb Number Channel #0 Number of MOb for channel 0 (1..32). * CHNO: Channel Number Number of CAN channels (1..5). * Variant: Variant Number Reserved. No functionality associated. * VERSION: Version Number Version number of the module. No functionality associated. 773 32117A-10/2010 AT32UC3C 29.7.2 Name: Parameter Register PARAMETER Access type: Read-only Offset: 0x04 Reset Value: - 31 30 - - 23 22 - - 15 14 - - 7 6 - - 29 28 27 26 25 24 18 17 16 10 9 8 2 1 0 MNCH4 21 20 19 MNCH3 13 12 11 MNCH2 5 4 3 MNCH1 * MNCH4: MOb Number Channel #4 Number of MOb for channel 4 (0..32). * MNCH3: MOb Number Channel #3 Number of MOb for channel 3 (0..32). * MNCH2: MOb Number Channel #2 Number of MOb for channel 2 (0..32). * MNCH1: MOb Number Channel #1 Number of MOb for channel 1 (0..32). 774 32117A-10/2010 AT32UC3C 29.7.3 Name: RAM Base Address Register CANRAMB Access type: Read/Write Offset: 0x08 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 18 17 16 10 9 8 2 1 0 RAMBASE[31:24] 23 22 21 20 19 RAMBASE[23:16] 15 14 13 12 11 RAMBASE[15:8] 7 6 5 4 3 RAMBASE[7:0] * RAMBASE: RAM Base Address CAN channel RAM base address. 775 32117A-10/2010 AT32UC3C 29.7.4 Name: Configuration Register CANCFG Access type: Read/Write Offset: 0x0C Reset Value: 0x00000001 31 30 29 28 27 26 - - - - - OVRM 23 22 21 20 19 18 - - SM 15 14 13 - - 7 6 - - SJW 12 4 24 CMODE 17 16 PRS 11 10 PHS2 5 25 9 8 PHS1 3 2 1 0 PRES * OVRM: Overrun Mode Overrun mode (MOb is not disabled after successful reception, therefore overwrite is possible). * CMODE: Channel Mode 00: Normal mode. 01: Listening mode. 10: Loop back mode. * SM: Sampling Method 0: Once. 1: Three times. * SJW: Synchronization Jump Width Maximum number of time quanta for resynchronization. * PRS: Propagation Segment Number of time quanta for propagation segment. * PHS2: Phase Segment 2 Number of time quanta for phase segment 2. * PHS1: Phase Segment 1 Number of time quanta for phase segment 1. * PRES: Prescaler CAN clock prescaler. Defines time quantum duration. Should not be set to 0. 776 32117A-10/2010 AT32UC3C 29.7.5 Name: Control Register CANCTRL Access type: Read/Write Offset: 0x10 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 - - - - - - - - 7 6 5 4 3 2 1 0 - - - - WKEN OVRQ CEN INIT * WKEN: Wake-up Enable 0: Wake-up mode disabled. 1: Wake-up mode enabled, any bus activity will set CANISR.WKUP. * OVRQ: Overload Request 0: No overload frame request pending. 1: Overload frame request pending, overload frame will be sent at the end of next received frame. * CEN: Channel Enable 0: No CAN channel enable request pending. 1: CAN channel enable request pending. * INIT: Initialization 0: CAN channel not initialized. 1: Initialize CAN channel. 777 32117A-10/2010 AT32UC3C 29.7.6 Name: Status Register CANSR Access type: Read-only Offset: 0x14 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 - - - - - - - - 7 6 5 4 3 2 1 0 - - - - RS TS OVS CES * RS: Reception Status 0: No frame is being received 1: Frame is being received * TS: Transmission Status 0: No frame is being transmitted 1: Frame is being transmitted * OVS: Overload Status 0: No overload frame is being transmitted 1: Overload frame is being transmitted * CES: Channel Enable Status 0: Channel disabled 1: Channel ready 778 32117A-10/2010 AT32UC3C 29.7.7 Name: Fault Confinement Register CANFC Access type: Read-only Offset: 0x18 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - 15 14 13 12 11 10 9 8 3 2 1 0 EMODE TEC 7 6 5 4 REC * EMODE: Error Mode 00: Error active 01: Error passive 1X: Bus off * TEC: Transmit Error Counter * REC: Reception Error Counter 779 32117A-10/2010 AT32UC3C 29.7.8 Name: Interrupt Enable Register CANIER Access type: Write-only Offset: 0x1C Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 - - - - - - - TXOKIM 7 6 5 4 3 2 1 0 RXOKIM WKUPIM BERRIM SERRIM CERRIM FERRIM AERRIM BOFFIM Writing a zero to a bit in this register has no effect. Writing a one to a bit in this register will set the corresponding bit in IMR. 780 32117A-10/2010 AT32UC3C 29.7.9 Name: Interrupt Disable Register CANIDR Access type: Write-only Offset: 0x20 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 - - - - - - - TXOKIM 7 6 5 4 3 2 1 0 RXOKIM WKUPIM BERRIM SERRIM CERRIM FERRIM AERRIM BOFFIM Writing a zero to a bit in this register has no effect. Writing a one to a bit in this register will clear the corresponding bit in IMR. 781 32117A-10/2010 AT32UC3C 29.7.10 Name: Interrupt Mask Register CANIMR Access type: Read-only Offset: 0x24 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 - - - - - - - TXOKIM 7 6 5 4 3 2 1 0 RXOKIM WKUPIM BERRIM SERRIM CERRIM FERRIM AERRIM BOFFIM 0: The corresponding interrupt is disabled. 1: The corresponding interrupt is enabled. A bit in this register is cleared when the corresponding bit in IDR is written to one. A bit in this register is set when the corresponding bit in IER is written to one. 782 32117A-10/2010 AT32UC3C 29.7.11 Name: Interrupt Status Clear Register CANISCR Access type: Write-only Offset: 0x28 Reset Value: 0x00200000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - 15 14 13 12 11 10 9 8 - - - - - - - - 7 6 5 4 3 2 1 0 - WKUP BERR SERR CERR FERR AERR BOFF LSMOB * LSMOB: Last Selected MOb Status Clear Write all bits to one to clear Last Selected MOb number. Writing these bits to any other value has no effect. * WKUP: Wake-up Status Clear Write to one to clear Wake-up status. Writing this bit to zero has no effect. * BERR: Bit Error Status Clear Write to one to clear Bit Error status. Writing this bit to zero has no effect. * SERR: Stuff Error Status Clear Write to one to clear Stuffing Error status. Writing this bit to zero has no effect. * CERR: CRC Error Status Clear Write to one to clear CRC Error status. Writing this bit to zero has no effect. * FERR: Form Error Status Clear Write to one to clear Form Error status. Writing this bit to zero has no effect. * AERR: Acknowledge Error Status Clear Write to one to clear Acknowledge Error status. Writing this bit to zero has no effect. * BOFF: Bus Off Status Clear Write to one to clear Bus Off status. Writing this bit to zero has no effect. 783 32117A-10/2010 AT32UC3C 29.7.12 Name: Interrupt Status Register CANISR Access type: Read-only Offset: 0x2C Reset Value: 0x00200000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - 15 14 13 12 11 10 9 8 - - - - - - - - 7 6 5 4 3 2 1 0 - WKUP BERR SERR CERR FERR AERR BOFF LSMOB * LSMOB: Last Selected MOb Status Last selected MOB number (1X: none, 0X: MOb X selected). * WKUP: Wake-up Status 0: No wake-up request detected. 1: Wake-up request (bus activity detected while CANCTRL.WKEN=1). * BERR: Bit Error Status 0: No bit error detected in current frame. 1: Bit error detected in current frame. * SERR: Stuff Error Status 0: No stuffing error detected in current frame. 1: Stuffing error detected in current frame. * CERR: CRC ERror Status 0: No CRC error detected in current frame. 1: CRC error detected in current frame. * FERR: Form Error Status 0: No form error detected in current frame. 1: Form error detected in current frame. * AERR: Acknowledge Error Status 0: No acknowledge error detected in current frame. 1: Acknowledge error detected in current frame. * BOFF: Bus Off Status 0: CAN channel not in Bus Off state. 1: CAN channel switched to Bus Off state. 784 32117A-10/2010 AT32UC3C 29.7.13 Name: MOb Search Register MOSCH Access type: Read-only Offset: 0x30 Reset Value: 0x00202020 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - 15 14 10 9 8 - - 7 6 2 1 0 - - MTXOK 13 12 11 MRXOK 5 4 3 MAV * MTXOK: MOb TxOK MOB TXOK number, with highest priority 1XXXXX: No MOb found 0XXXXX: MOb X found * MRXOK: MOb RxOK MOB RXOK number, with highest priority 1XXXXX: No MOb found 0XXXXX: MOb X found * MAV: MOb Available MOB available number, with highest priority 1XXXXX: No MOb found 0XXXXX: MOb X found 785 32117A-10/2010 AT32UC3C 29.7.14 Name: MOb Enable Register MOBER Access type: Write-only Offset: 0x34 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 19 18 17 16 11 10 9 8 3 2 1 0 MEN[31:24] 23 22 21 20 MEN[23:16] 15 14 13 12 MEN[15:8] 7 6 5 4 MEN[7:0] * MEN: MOb Enable Writing a bit to zero has no effect. Writing a bit to one will enable the corresponding MOb. 786 32117A-10/2010 AT32UC3C 29.7.15 Name: MOb Disable Register MOBDR Access type: Write-only Offset: 0x38 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 19 18 17 16 11 10 9 8 3 2 1 0 MDIS[31:24] 23 22 21 20 MDIS[23:16] 15 14 13 12 MDIS[15:8] 7 6 5 4 MDIS[7:0] * MDIS: MOb Disable Writing a bit to zero has no effect. Writing a bit to one will disable the corresponding MOb. 787 32117A-10/2010 AT32UC3C 29.7.16 Name: MOb Enable Status Register MOBESR Access type: Read-only Offset: 0x3C Reset Value: 0x00000000 31 30 29 28 27 26 25 24 19 18 17 16 11 10 9 8 3 2 1 0 MEN[31:24] 23 22 21 20 MEN[23:16] 15 14 13 12 MEN[15:8] 7 6 5 4 MEN[7:0] * MEN: MOb Enable 0: The corresponding MOb is disabled 1: The corresponding MOb is enabled This bit is cleared when the corresponding bit in MOBDR is written to one. This bit is set when the corresponding bit in MOBER is written to one. 788 32117A-10/2010 AT32UC3C 29.7.17 Name: MOb Interrupt Enable Register MOBIER Access type: Write-only Offset: 0x40 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 19 18 17 16 11 10 9 8 3 2 1 0 MIM[31:24] 23 22 21 20 MIM[23:16] 15 14 13 12 MIM[15:8] 7 6 5 4 MIM[7:0] * MIM: MOb Interrupt Mask Writing a bit to zero has no effect. Writing a bit to one will set the corresponding bit in MOBIMR. 789 32117A-10/2010 AT32UC3C 29.7.18 Name: MOb Interrupt Disable Register MOBIDR Access type: Write-only Offset: 0x44 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 19 18 17 16 11 10 9 8 3 2 1 0 MIM[31:24] 23 22 21 20 MIM[23:16] 15 14 13 12 MIM[15:8] 7 6 5 4 MIM[7:0] * MIM: MOb Interrupt Mask Writing a bit to zero has no effect. Writing a bit to one will set the corresponding bit in MOBIMR. 790 32117A-10/2010 AT32UC3C 29.7.19 Name: MOb Interrupt Mask Register MOBIMR Access type: Read-only Offset: 0x48 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 19 18 17 16 11 10 9 8 3 2 1 0 MIM[31:24] 23 22 21 20 MIM[23:16] 15 14 13 12 MIM[15:8] 7 6 5 4 MIM[7:0] * MIM: MOb Interrupt Mask 0: The corresponding MOb interrupt is disabled. 1: The corresponding MOb interrupt is enabled. This bit is cleared when the corresponding bit in MOBIDR is written to one. This bit is set when the corresponding bit in MOBIER is written to one. 791 32117A-10/2010 AT32UC3C 29.7.20 Name: MOb RX Interrupt Status Clear Register MRXISCR Access type: Write-only Offset: 0x4C Reset Value: 0x00000000 31 30 29 28 27 26 25 24 19 18 17 16 11 10 9 8 3 2 1 0 RXOK[31:24] 23 22 21 20 RXOK[23:16] 15 14 13 12 RXOK[15:8] 7 6 5 4 RXOK[7:0] * RXOK: Reception Successful Writing a bit to zero has no effect. Writing a bit to one will clear the corresponding bit in MRXISR. 792 32117A-10/2010 AT32UC3C 29.7.21 Name: MOb RX Interrupt Status Register MRXISR Access type: Read-only Offset: 0x50 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 19 18 17 16 11 10 9 8 3 2 1 0 RXOK[31:24] 23 22 21 20 RXOK[23:16] 15 14 13 12 RXOK[15:8] 7 6 5 4 RXOK[7:0] * RXOK: Reception Successful 0: The corresponding MOb has not completed a reception. 1: The corresponding MOb has completed a reception (same bit as MOBSRn.RXOK). This bit is cleared when the corresponding bit in MRXISCR is written to one. This bit is set when the corresponding MOb has completed a reception. 793 32117A-10/2010 AT32UC3C 29.7.22 Name: MOb TX Interrupt Status Clear Register MTXISCR Access type: Write-only Offset: 0x54 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 19 18 17 16 11 10 9 8 3 2 1 0 TXOK[31:24] 23 22 21 20 TXOK[23:16] 15 14 13 12 TXOK[15:8] 7 6 5 4 TXOK[7:0] * TXOK: Transmission successful Writing a bit to zero has no effect. Writing a bit to one will clear the corresponding bit in MTXISR. 794 32117A-10/2010 AT32UC3C 29.7.23 Name: MOb TX Interrupt Status Register MTXISR Access type: Read-only Offset: 0x58 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 19 18 17 16 11 10 9 8 3 2 1 0 TXOK[31:24] 23 22 21 20 TXOK[23:16] 15 14 13 12 TXOK[15:8] 7 6 5 4 TXOK[7:0] * TXOK: Transmission Successful 0: The corresponding MOb has not completed a transmission. 1: The corresponding MOb has completed a transmission (same bit as MOBSRn.TXOK). This bit is cleared when the corresponding bit in MTXISCR is written to one. This bit is set when the corresponding MOb has completed a transmission. 795 32117A-10/2010 AT32UC3C 29.7.24 Name: MOb Control Register MOBCTRLn Access type: Read/Write Offset: 0x5C + [n * 0xC] Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 - - - - - - - - 7 6 5 4 3 2 1 0 - - AM DIR DLC * AM: Automatic Mode 0: Automatic transmit mode 1: Automatic receive mode * DIR: Transfer Direction 0: Reception 1: Transmission * DLC: Data Length Code Valid data length code is from 0 to 8. 796 32117A-10/2010 AT32UC3C 29.7.25 Name: MOb Status Clear Register MOBSCRn Access type: Write-only Offset: 0x60 + [n * 0xC] Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 - - - - - - - - 7 6 5 4 3 2 1 0 - - - - OVW DLCW TXOK RXOK * OVW: Overwrite Writing this bit to zero has no effect. Writing this bit to one clears the OVW status in MOBSR. * DLCW: DLC Warning Writing this bit to zero has no effect. Writing this bit to one clears DLCW status in MOBSR. * TXOK: Transmission successful Writing this bit to zero has no effect. Writing this bit to one clears TXOK status in MOBSR. * RXOK: Reception successful Writing this bit to zero has no effect. Writing this bit to one clears RXOK status in MOBSR. 797 32117A-10/2010 AT32UC3C 29.7.26 Name: MOb Status Register MOBSRn Access type: Read-only Offset: 0x64 + [n * 0xC] Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 - - - - - - - - 7 6 5 4 3 2 1 0 - - - - OVW DLCW TXOK RXOK * OVW: Overwrite 0: Previous message has not been overwritten. 1: A new message has been received and overwritten previous one (if CANCFG.OVRM is set). * DLCW: DLC Warning 0: Received DLC matches MOBCTRL.DLC. 1: Received DLC is different from MOBCTRL.DLC. * TXOK: Transmission Successful 0: Transmission not completed or not successful. 1: Transmission completed and successful. * RXOK: Reception Successful 0: Reception not completed or not successful. 1: Reception completed and successful. 798 32117A-10/2010 AT32UC3C 29.8 Module Configuration The specific configuration for each CANIF instance is listed in the following tables. The module bus clocks listed here are connected to the system bus clocks. Refer to the Power Manager chapter for details. Table 29-5. Module Configuration Feature CANIF CANIF channels 2 Table 29-6. Module name CANIF Table 29-7. Module Clock Name Clock name Description CLK_CANIF_HSB HSB clock CLK_CANIF_PB Peripheral Bus clock from the PBC clock domain GCLK The generic clock used for the CANIF is GCLK1 Register Reset Values Register Reset Value VERSION 0x10200110 PARAMETER 0x00000010 799 32117A-10/2010 AT32UC3C 30. Inter-IC Sound Controller (IISC) Rev. 2.0.0.0 30.1 Features * Compliant with Inter-IC Sound (I2S) bus specification * Master, slave and controller modes * * * * * * 30.2 - Slave: only data received/transmitted - Master: data received/transmitted and clocks generated - Controller: only clocks generated Individual enable and disable of receiver, transmitter, and clocks Configurable clock generator common to receiver and transmitter: - suitable for a wide range of sample rates, including 32kHz, 44.1kHz, 48kHz, 88.2kHz, 96kHz, and 192kHz - 16 to 1024 fs Master Clock generated for external oversampling ADCs Several data format supported: - 32-, 24-, 20-, 18-, 16-, and 8-bit mono or stereo format - 16- and 8-bit compact stereo format, with left and right samples packed in the same word to reduce data transfers Several data frame formats supported: - 2-channel I2S with Word Select - 1- to 8-channel Time Division Multiplexed (TDM) with Frame Sync DMA interfaces for receiver and transmitter to reduce processor overhead - either one DMA channel for all audio channels - or one DMA channel per audio channel Smart holding registers management to avoid audio channels mix after overrun or underrun Overview The Inter-IC Sound Controller (IISC) provides a 5-wire, bidirectional, synchronous, digital audio link with off-chip audio devices: ISDI, ISDO, IWS, ISCK and IMCK pins. This controller is compliant with the Inter-IC Sound (I2S) bus specification and also supports TDM interface with multi-channel codecs. The IISC consists of a receiver, a transmitter, and a common clock divider, that can be enabled separately, to provide master, slave or controller modes with receiver, transmitter, or both active. Peripheral DMA channels, separate for receiver and for transmitter, allow a continuous high bit rate data transfer without processor intervention to the following: * CODECs in master, slave, or controller mode * Stereo DAC or ADC through dedicated I2S serial interface * Multi-channel or multiple stereo DACs or ADCs, using the TDM format If audio samples from all channels data are handled in the system within the same data flow, a single DMA channel can be used for the receiver or for the transmitter. Else, one DMA channel can be used for each audio channel. For mono bitstream, each audio sample is duplicated on left and right channels within the IISC. The 8- and 16-bit compact stereo format allows dividing by 2 the required DMA bandwidth by transferring the left and right samples within the same data word. 800 32117A-10/2010 AT32UC3C In Master mode, the IISC allows outputting a 16 fs to 1024 fs Master Clock, e.g. to oversampling DACs or DSP. This Master Clock is a generic clock from the System Control Interface (SCIF), with a frequency equal to the desired audio sample rate times the desired Master Clock ratio. 30.3 Block Diagram Figure 30-1. IISC Block Diagram IISC Generic clock IMCK Clocks ISDI Transmitter ISDO 30.4 Rx Tx IRQ Peripheral Bus Bridge Peripheral DMA Interrupt Controller I/O Lines Description Pin Name 30.5.1 PB I/O Lines Description Table 30-1. 30.5 Receiver PB clock Peripheral Bus interface IWS I/O Controller ISCK SCIF Power Manager Pin Description Type IMCK Master Clock (often at 256 fs) Output ISCK Serial Clock Input/Output IWS I2S Word Select or TDM Frame Sync Input/Output ISDI Serial Data Input ISDO Serial Data Output Input Output Product Dependencies I/O lines The pins used for interfacing the IISC may be multiplexed with I/O lines. The programmer must first program the I/O Controller to assign the desired IISC pins to their peripheral function. If I/O lines of the IISC are not used by the application, they can be used for other purposes by the I/O Controller. 801 32117A-10/2010 AT32UC3C Not all IISC I/Os need to be enabled. If an application does not require IMCK, uses the IISC in Controller mode, or does not use both receiver and transmitter, then less IISC lines will be assigned to IISC I/Os. 30.5.2 Power Management If the CPU enters a sleep mode that disables clocks used by the IISC, the IISC will stop functioning and resume operation after the system wakes up from sleep mode. Before entering a sleep mode where the clock to the IISC is stopped, make sure the IISC is disabled. 30.5.3 Clocks The clock for the IISC peripheral bus interface (CLK_IISC) is generated by the Power Manager. This clock is enabled at reset, and can be disabled in the Power Manager. It is recommended to disable the IISC before disabling the clock, to avoid freezing the IISC in an undefined state. Additionally, the IISC depends on a dedicated Generic Clock (GCLK). The GCLK can be set to a wide range of frequencies and clock sources, and must be enabled by the System Control Interface (SCIF) before the IISC can be used. 30.5.4 Interrupts The IISC interrupt line is connected on one of the internal sources of the Interrupt Controller. Using the IISC requires the Interrupt Controller to be programmed first. 30.5.5 30.6 Debug Operation When an external debugger forces the CPU into debug mode, this module continues normal operation. If this module is configured in a way that requires it to be periodically serviced by the CPU through interrupt requests or similar, improper operation or data loss may result during debugging. Functional Description The I2S controller features a Receiver, a Transmitter, and, for Master and Controller modes, a Clock generator. They can be enabled or disabled independently by writing a one to the RXEN, RXDIS, TXEN, TXDIS, CKEN, CKDIS bits of the Control Register (CR). Receiver and Transmitter share the same Serial Clock and Word Select. 30.6.1 Master, Slave and Controller modes In Master and Controller modes, the IISC provides the master clock, the Serial Clock and the Word Select. IMCK, ISCK and IWS pads are outputs. In Controller mode, the IISC Receiver and Transmitter are disabled. Only the clocks are enabled and used by off-chip receiver and transmitter. In Slave mode, the IISC receives the Serial Clock and the Word Select from an external master. ISCK and IWS pads are inputs. The mode is selected by writing the MODE field of the Mode Register (MR). Since the MODE field changes the direction of the IWS and ISCK pads, the Mode Register should only be written when the IISC is stopped, for instance before writing to the RXEN, TXEN and CKEN bits of the Control Register, in order to avoid unwanted glitches on the IWS and ISCK pads. 802 32117A-10/2010 AT32UC3C 30.6.2 I2S Reception and Transmission Sequence As specified in the I2S protocol, data bits are left-adjusted in the Word Select time slot, with the MSB transmitted first, starting one clock period after the transition on the Word Select line. Figure 30-2. I2S Reception and Transmission Sequence Serial Clock ISCK Word Select IWS Data ISDI/ISDO MSB LSB MSB Right Channel Left Channel Data bits are sent on the falling edge of the Serial Clock and sampled on the rising edge of the Serial Clock. The Word Select line indicates the channel in transmission, a low level for the left channel and a high level for the right channel. The length of transmitted words can be chosen among 8, 16, 18, 20, 24, and 32 bits by writing the MR.DATALENGTH field. If the time slot allows for more data bits than programmed in the MR.DATALENGTH field, zero bits are appended to the transmitted data word or extra received bits are discarded. If the time slot allows for less data bits than programmed, the extra bits to be transmitted are not sent or the missing bits are set to zero in the received data word. 30.6.3 TDM Reception and Transmission Sequence In TDM format, 1 to 8 data words are sent or received within each frame, As in the I2S protocol, data bits are left-adjusted in the channel time slot, with the MSB transmitted first, starting one clock period after the transition on the Word Select line. Each time slot is 32-bit long. Figure 30-3. TDM Reception and Transmission Sequence Frame sync (IWS) Serial Clock (ISCK) Data (ISDI/ISDO) MSB LSB Channel 1 MSB LSB Channel 2 MSB LSB Channel 3 MSB LSB Channel 4 Data bits are sent on the falling edge of the Serial Clock and sampled on the rising edge of the Serial Clock. The IWS pin provides a frame synchronization signal, starting one ISCK period before the MSB of channel 1. The Time Division Multiplexed (TDM) format is selected by writing a one in the MR.FORMAT field. The Frame Sync pulse can be either one ISCK period or one 32-bit time slot. This selection is done by writing the MR.TDMFS bit. The number of channels is selected by writing the MR.CHANNELS field. 803 32117A-10/2010 AT32UC3C The length of transmitted words can be chosen among 8, 16, 18, 20, 24, and 32 bits by writing the MR.DATALENGTH field. If the time slot allows for more data bits than programmed in the MR.DATALENGTH field, zero bits are appended to the transmitted data word or extra received bits are discarded. If the time slot allows for less data bits than programmed, the extra bits to be transmitted are not sent or the missing bits are set to zero in the received data word. 30.6.4 Serial Clock and Word Select Generation In Slave mode, the Serial Clock and Word Select Clock are driven by an off-chip master. So, ISCK and IWS pins are inputs and no generic clock is required by the IISC. In Master mode, the user can configure the Master Clock, Serial Clock, and Word Select Clock through the Mode Register (MR). So, IMCK, ISCK, and IWS pins are outputs and a generic clock is used to derive the IISC clocks. Figure 30-4. IISC Clocks Generation CR.CKEN/CKDIS MR.IMCKMODE enable clk_gen_iisc IMCK pad output divider MR.IMCKMODE 0 MR.IMCKFS MR.DATALENGTH 1 ISCK pad output CR.CKEN/CKDIS 0 clk_isck enable ISCK pad input 1 divider MR.MODE = SLAVE MR.DATALENGTH IWS pad output 0 iws IWS pad input 1 If a Master Clock output is required on IMCK pin, the generic clock is used as IMCK, by writing a one to MR.IMCKMODE and the IMCK to sample rate (fs) ratio is selected by writing the MR.IMCKFS field. If a Master Clock output is not required, the generic clock is used as ISCK, by writing a zero to MR.IMCKMODE. Alternatively, if the frequency of the generic clock used is a multiple of the required ISCK frequency, the IMCK to ISCK divider can be used with the ratio defined by writing the MR.IMCKFS field. In this case, the I/O Controller can be configured to use the IMCK pin for other purposes. The IWS pin is used as Word Select in I2S format and as Frame Synchronization in TDM format, as described in Section 30.6.2 and Section 30.6.3 respectively. 804 32117A-10/2010 AT32UC3C 30.6.5 Holding Registers The user interface includes a Receive Holding Register (RHR) and a Transmit Holding Register (THR). RHR and THR are used to access audio samples for all audio channels. When a new data word is available in the RHR register, the Receive Ready bit (RXRDY) of the Status Register (SR) is set. Reading the RHR register will clear this bit. When the THR register is empty, the Transmit Ready bit (TXRDY) of the Status Register (SR) is set. Writing into the THR register will clear this bit. Data words are right-justified in RHR and THR registers. For 16-bit compact stereo, the left sample uses bits 15 through 0 and the right sample uses bits 31 through 16 of the same data word. For 8-bit compact stereo, the left sample uses bits 7 through 0 and the right sample uses bits 15 through 8 of the same data word. 30.6.6 Peripheral DMA Channels Connection The receiver and transmitter can each be connected either to one single Peripheral DMA channel or to one Peripheral DMA channel per data channel. This is selected by writing the MR.RXDMA and MR.TXDMA bits. If a single Peripheral DMA channel is selected, all data samples use IISC Peripheral DMA channel 0. The RHR and THR registers are accessed by the Peripheral DMA to read the received data words or to write the data words to be transmitted by the IISC. The Peripheral DMA transfers may use 32-bit words, 16-bit halfwords or 8-bit bytes according to the value of the MR.DATALENGTH field. 30.6.7 Loop-back Mode The IISC can be configured to loop back the transmitter to the receiver. Writing a one to the MR.LOOP bit will internally connect ISDO to ISDI, so that the transmitted data is also received. Writing a zero to MR.LOOP will restore the normal behavior with independent receiver and transmitter. The IISC shall be first disabled before writing the MR register. 30.6.8 Interrupts Most bits in SR register have a corresponding bit in interrupt management registers. The IISC can be programmed to generate an interrupt when it detects an event. The interrupt is controlled by writing to the Interrupt Enable Register (IER) and Interrupt Disable Register (IDR). These registers enable and disable, respectively, the corresponding interrupt by setting and clearing the corresponding bit in the Interrupt Mask Register (IMR), which controls the generation of interrupts by asserting the SSC interrupt line connected to the interrupt controller. 805 32117A-10/2010 AT32UC3C Figure 30-5. Interrupt Block Diagram IMR IER IDR Clear Set Transmitter TXRDY TXUR Interrupt Control IISC Interrupt Receiver RXRDY RXOR 30.7 IISC Application Examples The IISC can support several serial communication modes used in audio or high speed serial links. Some standard applications are shown in the following figures. All serial link applications supported by the IISC are not listed here. Figure 30-6. Audio Application Block Diagram Serial Clock ISCK Word Select IWS IISC I2S RECEIVER Serial Data Out ISDO ISDI Serial Clock Word Select Serial Data Out MSB LSB Left Channel MSB Right Channel 806 32117A-10/2010 AT32UC3C Figure 30-7. Codec Application Block Diagram IMCK ISCK IISC IWS ISDO ISDI Master Clock Serial Clock Frame Sync CODEC Serial Data Out Serial Data In Serial Clock Frame Sync First Time Slot Dstart Dend Serial Data Out Serial Data In Figure 30-8. Time Slot Application Block Diagram IMCK ISCK IISC IWS ISDO ISDI Master Clock Serial Clock CODEC First Time Slot Frame Sync Serial Data Out Serial Data In CODEC Second Time Slot Serial Clock Frame Sync First Time Slot Dstart Second Time Slot Dend Serial Data Out Serial Data In 807 32117A-10/2010 AT32UC3C 30.8 User Interface Table 30-2. Offset IISC Register Memory Map Register Name Access Reset State 0x00 Control Register CR Write Only 0x00000000 0x04 Mode Register MR Read/Write 0x00000000 0x08 Status Register SR Read Only 0x00000000 0x0C Status Clear Register SCR Write Only 0x10 Status Set Register SSR Write Only 0x14 IER register IER Write Only 0x18 IDR register IDR Write Only 0x1C IMR register IMR Read Only 0x00000000 0x20 Receiver Holding Register RHR Read Only 0x00000000 0x24 Transmitter Holding Register THR Write Only 0x00000000 0x28 Version Register VERSION Read Only (1) 0x2C Parameter Register PARAMETER Read Only (1) 1) The reset values for these registers is device specific. Please refer to the Module Configuration section at the end of this chapter. 808 32117A-10/2010 AT32UC3C 30.8.1 Name: Control Register CR Access Type: Write Only Offset: 0x00 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 - - - - - - - - 7 6 5 4 3 2 1 0 SWRST - TXDIS TXEN CKDIS CKEN RXDIS RXEN The Control Register should only be written to enable the IISC after the chosen configuration has been written to the Mode Register, in order to avoid unwanted glitches on the IWS, ISCK and ISDO outputs. The proper sequence is to write the MR register, then write the CR register to enable the IISC, or to disable the IISC before writing a new value into MR. * SWRST: Software Reset Writing a zero to this bit has no effect. Writing a one to this bit resets the IISC, simulating a hardware reset. This bit has priority on all other CR bits. * TXDIS: Transmitter Disable Writing a zero to this bit has no effect. Writing a one to this bit disables the IISC transmitter. Bit TXEN in the Status Register will be cleared when the transmitter is effectively stopped. * TXEN: Transmitter Enable Writing a zero to this bit has no effect. Writing a one to this bit enables the IISC transmitter, if the TXDIS bit is not one. Bit TXEN in the Status Register will be set when the transmitter is effectively started. * CKDIS: Clocks Disable Writing a zero to this bit has no effect. Writing a one to this bit disables the IISC clocks generation. * CKEN: Clocks Enable Writing a zero to this bit has no effect. Writing a one to this bit enables the IISC clocks generation, if the CKDIS bit is not one. * RXDIS: Receiver Disable Writing a zero to this bit has no effect. Writing a one to this bit disables the IISC receiver. Bit TXEN in the Status Register will be cleared when the transmitter is effectively stopped. * RXEN: Receiver Enable Writing a zero to this bit has no effect. Writing a one to this bit enables the IISC receiver, if the RXDIS bit is not one. Bit RXEN in the Status Register will be set when the receiver is effectively started. 809 32117A-10/2010 AT32UC3C 30.8.2 Name: Mode Register MR Access Type: Read/Write Offset: 0x04 Reset Value: 0x00000000 31 30 IWS24 IMCKMODE 23 22 TDMFS 29 28 26 25 24 18 17 16 IMCKFS 21 20 19 - - - 11 15 14 13 12 - TXSAME TXDMA TXMONO 7 6 5 4 FORMAT 27 - 3 NBCHAN 10 9 8 RXLOOP RXDMA RXMONO 2 1 0 - MODE DATALENGTH The Mode Register should only be written when the IISC is stopped, in order to avoid unwanted glitches on the IWS, ISCK and ISDO outputs. The proper sequence is to write the MR register, then write the CR register to enable the IISC, or to disable the IISC before writing a new value into MR. * IWS24: IWS TDM Slot Width 0: IWS slot is 32-bit wide for DATALENGTH=18/20/24-bit 1: IWS slot is 24-bit wide for DATALENGTH=18/20/24-bit * IMCKMODE: Master Clock Mode 0: No Master Clock generated (generic clock is used for ISCK output) 1: Master Clock generated (generic clock is used for IMCK output) * IMCKFS: Master Clock to fs Ratio Master Clock frequency is 16*(IMCKFS+1) times the sample rate, i.e. IWS frequency: IMCKFS fs Ratio 0 16 fs 1 32 fs 3 64 fs 7 128 fs 15 256 fs 23 384 fs 31 512 fs 47 768 fs 63 1024 fs 810 32117A-10/2010 AT32UC3C * TDMFS: TDM Frame Sync 0: SLOT: IWS pulse is high for one time slot at beginning of frame 1: HALF: IWS pulse is high for the half time slots at beginning of frame, i.e. half the IWS period 2: BIT: IWS pulse is high for one bit period at beginning of frame, i.e. one ISCK period * NBCHAN: Number of TDM Channels - 1 * TXSAME: Transmit Data when Underrun 0: Zero sample transmitted when underrun 1: Previous sample transmitted when underrun (in I2S mode only) * TXDMA: Single or multiple DMA Channels for Transmitter 0: Transmitter uses a single DMA channel for allboth audio channels 1: Transmitter uses one DMA channel per audio channel * TXMONO: Transmit Mono 0: Stereo 1: Mono, with left audio samples duplicated to right audio channel by the IISC * RXLOOP: Loop-back Test Mode 0: Normal mode 1: ISDO output of IISC is internally connected to ISDI input * RXMONO: Receive Mono 0: Stereo 1: Mono, with left audio samples duplicated to right audio channel by the IISC * RXDMA: Single or multiple DMA Channels for Receiver 0: Receiver uses a single DMA channel for allboth audio channels 1: Receiver uses one DMA channel per audio channel * FORMAT: I2S or TDM Format 0: I2S format, stereo with IWS low for left channel, and MSB of sample starting one ISCK period after IWS edge 1: Left-Justified format, stereo with IWS high for left channel, and MSB of sample starting on IWS edge 1: TDM format, with (CHANNELS+1) channels, IWS high at beginning of first channel, and MSB of sample starting one ISCK period after IWS edge 1: TDM Left-Justified format, with (CHANNELS+1) channels, IWS high at beginning of first channel, and MSB of sample starting on IWS edge * DATALENGTH: Data Word Length DATALENGTH Word length 0 32 bits 1 24 bits 2 20 bits 3 18 bits 4 16 bits 5 16 bits compact stereo 6 8 bits 7 8 bits compact stereo Comments left sample in bits 15 through 0 and right sample in bits 31 through 16 of the same word left sample in bits 7 through 0 and right sample in bits 15 through 8 of the same word * MODE: Master/Slave/Controller Mode 0: Slave mode (only serial data handled, clocks received from external master or controller) 1: Master mode (serial data handled if CR.RXEN and/or CR.TXEN is/are written to 1, clocks generated and output by IISC) 811 32117A-10/2010 AT32UC3C 30.8.3 Name: Status Register SR Access Type: Read Only Offset: 0x08 Reset Value: 0x00000000 31 30 29 28 - - - - 23 22 21 20 27 14 13 25 24 TXURCH[7:4] TXURCH[3:0] 15 26 12 19 18 17 16 - - - - 11 10 9 8 RXORCH 7 6 5 4 3 2 1 0 - TXUR TXRDY TXEN - RXOR RXRDY RXEN * TXURCH: Transmit Underrun Channel Bit i of this field is set when a transmit underrun error occured in channel i (i=0 for first channel) This entire field is cleared when SCR.TXUR bit is written to one * RXORCH: Receive Overrun Channel Bit i of this field is set when a receive overrun error occured in channel i (i=0 for first channel) This entire field is cleared when SCR.RXOR bit is written to one * TXUR: Transmit Underrun This bit is set when an underrun error occurs on the THR register or when the corresponding bit in SSR is written to one This bit is cleared when the corresponding bit in SCR is written to one * TXRDY: Transmit Ready This bit is set when the THR register is empty and can be written with new data to be transmitted This bit is cleared when data is written to THR and is being transmitted * TXEN: Transmitter Enabled This bit is set when the transmitter is effectively enabled, following a CR.TXEN request This bit is cleared when the transmitter is effectively disabled, following a CR.TXDIS or CR.SWRST request * RXOR: Receive Overrun This bit is set when an overrun error occurs on the RHR register or when the corresponding bit in SSR is written to one This bit is cleared when the corresponding bit in SCR is written to one * RXRDY: Receive Ready This bit is set when received data is present in the RHR register This bit is cleared when the RHR register is read and no more received data is present * RXEN: Receiver Enabled This bit is set when the receiver is effectively enabled, following a CR.RXEN request This bit is cleared when the receiver is effectively disabled, following a CR.RXDIS or CR.SWRST request 812 32117A-10/2010 AT32UC3C 30.8.4 Name: Status Clear Register SCR Access Type: Write Only Offset: 0x0C Reset Value: 0x00000000 31 30 29 28 - - - - 23 22 21 20 27 14 13 25 24 TXURCH[7:4] TXURCH[3:0] 15 26 12 19 18 17 16 - - - - 11 10 9 8 RXORCH 7 6 5 4 3 2 1 0 - TXUR - - - RXOR - - Writing a zero to a bit in this register has no effect. Writing a one to a bit in this register will clear the corresponding bit in SR register. * * * * TXURCH: Transmit Underrun Channels RXORCH: Receive Overrun Channels TXUR: Transmit Underrun RXOR: Receive Overrun 813 32117A-10/2010 AT32UC3C 30.8.5 Name: Status Set Register SSR Access Type: Write Only Offset: 0x10 Reset Value: 0x00000000 31 30 29 28 - - - - 23 22 21 20 27 14 13 25 24 TXURCH[7:4] TXURCH[3:0] 15 26 12 19 18 17 16 - - - - 11 10 9 8 RXORCH 7 6 5 4 3 2 1 0 - TXUR - - - RXOR - - Writing a zero to a bit in this register has no effect. Writing a one to a bit in this register will clear the corresponding bit in SR register. * * * * TXURCH: Transmit Underrun Channels RXORCH: Receive Overrun Channels TXUR: Transmit Underrun RXOR: Receive Overrun 814 32117A-10/2010 AT32UC3C 30.8.6 Name: Interrupt Enable Register IER Access Type: Write Offset: 0x14 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 - - - - - - - - 7 6 5 4 3 2 1 0 - TXUR TXRDY - - RXOR RXRDY - Writing a zero to a bit in this register has no effect. Writing a one to a bit in this register will set the corresponding bit in IMR. * * * * TXUR: Transmit Underrun TXRDY: Transmit Ready RXOR: Receive Overrun RXRDY: Receive Ready 815 32117A-10/2010 AT32UC3C 30.8.7 Name: Interrupt Disable Register IDR Access Type: Write Offset: 0x18 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 - - - - - - - - 7 6 5 4 3 2 1 0 - TXUR TXRDY - - RXOR RXRDY - Writing a zero to a bit in this register has no effect. Writing a one to a bit in this register will clear the corresponding bit in IMR. * * * * TXUR: Transmit Underrun TXRDY: Transmit Ready RXOR: Receive Overrun RXRDY: Receive Ready 816 32117A-10/2010 AT32UC3C 30.8.8 Name: Interrupt Mask Register IMR Access Type: Read Offset: 0x1C Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 - - - - - - - - 7 6 5 4 3 2 1 0 - TXUR TXRDY - - RXOR RXRDY - 0: The corresponding interrupt is disabled. 1: The corresponding interrupt is enabled. A bit in this register is cleared when the corresponding bit in IDR is written to one. A bit in this register is set when the corresponding bit in IER is written to one. * * * * TXUR: Transmit Underrun TXRDY: Transmit Ready RXOR: Receive Overrun RXRDY: Receive Ready 817 32117A-10/2010 AT32UC3C 30.8.9 Name: Receive Holding Register RHR Access Type: Read Only Offset: 0x20 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 19 18 17 16 11 10 9 8 3 2 1 0 RHR[31:24] 23 22 21 20 RHR[23:16] 15 14 13 12 RHR[15:8] 7 6 5 4 RHR[7:0] * RHR: Received Word This field is set by hardware to the last received data word, with bits beyond the size specified in MR.DATALENGTH set to 0. 818 32117A-10/2010 AT32UC3C 30.8.10 Name: Transmit Holding Register THR Access Type: Write Only Offset: 0x24 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 19 18 17 16 11 10 9 8 3 2 1 0 THR[31:24] 23 22 21 20 THR[23:16] 15 14 13 12 THR[15:8] 7 6 5 4 THR[7:0] * THR: Data Word to Be Transmitted Next data word to be transmitted after the current word if TXRDY is not set. If MR.DATALENGTH specifies less than 32 bits, data shall be right-justified into the THR field. 819 32117A-10/2010 AT32UC3C 30.8.11 Name: Module Version VERSION Access Type: Read Only Offset: 0x28 Reset Value: 0x00000200 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - 15 14 13 12 9 8 - - - - 7 6 5 4 1 0 VARIANT 11 10 VERSION[11:8] 3 2 VERSION[7:0] * VARIANT: Variant number Reserved. No functionality associated. * VERSION: Version number Version number of the module. No functionality associated. 820 32117A-10/2010 AT32UC3C 30.8.12 Name: Module Parameters PARAMETER Access Type: Read Only Offset: 0x2C Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 - - - - - - - - 7 6 5 4 3 2 1 0 - - - - - - - - Reserved. No functionality associated. 821 32117A-10/2010 AT32UC3C 30.9 Module configuration The specific configuration for each IISC instance is listed in the following tables. The module bus clocks listed here are connected to the system bus clocks according to the table in the System Bus Clock Connections section. Table 30-3. Module configuration Feature IISC Number of TDM channels 8 channels Number of Peripheral DMA channels 8 channels Table 30-4. Module name Module clock name Clock name Clock name CLK_IISC Peripheral Bus clock from the PBA clock domain GCLK The generic clock used for the IISC is GCLK11 IISC Table 30-5. Register Reset Values Register Reset Value VERSION 0x00000200 822 32117A-10/2010 AT32UC3C 31. Timer/Counter (TC) Rev: 2.2.3.2 31.1 Features * Three 16-bit Timer Counter channels * A wide range of functions including: - Frequency measurement - Event counting - Interval measurement - Pulse generation - Delay timing - Pulse width modulation - Up/down capabilities * Each channel is user-configurable and contains: - Three external clock inputs - Five internal clock inputs - Two multi-purpose input/output signals * Internal interrupt signal * Two global registers that act on all three TC channels 31.2 Overview The Timer Counter (TC) includes three identical 16-bit Timer Counter channels. Each channel can be independently programmed to perform a wide range of functions including frequency measurement, event counting, interval measurement, pulse generation, delay timing, and pulse width modulation. Each channel has three external clock inputs, five internal clock inputs, and two multi-purpose input/output signals which can be configured by the user. Each channel drives an internal interrupt signal which can be programmed to generate processor interrupts. The TC block has two global registers which act upon all three TC channels. The Block Control Register (BCR) allows the three channels to be started simultaneously with the same instruction. The Block Mode Register (BMR) defines the external clock inputs for each channel, allowing them to be chained. 823 32117A-10/2010 AT32UC3C 31.3 Block Diagram Figure 31-1. TC Block Diagram I/O Contr oller TIMER_CLOCK1 TCLK0 TIMER_CLOCK2 TIOA1 TIMER_CLOCK4 XC0 TIOA2 TIMER_CLOCK3 TCLK1 XC1 TCLK2 XC2 TIMER_CLOCK5 Timer/Counter Channel 0 TIOA TIOB TC0XC0S SYNC CLK0 CLK1 CLK2 A0 TIOA0 B0 TIOB0 INT0 TCLK0 XC0 TCLK1 TIOA0 XC1 TIOA2 XC2 TCLK2 Timer/Counter Channel 1 XC0 TCLK1 XC1 TCLK2 XC2 TIOA0 TIOA1 TC2XC2S TIOB A1 TIOA1 B1 TIOB1 SYNC TC1XC1S TCLK0 TIOA Timer/Counter Channel 2 INT1 TIOA TIOB A2 TIOA2 B2 TIOB2 SYNC INT2 Timer Count er Interrupt Controller 31.4 I/O Lines Description Table 31-1. 31.5 I/O Lines Description Pin Name Description Type CLK0-CLK2 External Clock Input Input A0-A2 I/O Line A Input/Output B0-B2 I/O Line B Input/Output Product Dependencies In order to use this module, other parts of the system must be configured correctly, as described below. 31.5.1 I/O Lines The pins used for interfacing the compliant external devices may be multiplexed with I/O lines. The user must first program the I/O Controller to assign the TC pins to their peripheral functions. 824 32117A-10/2010 AT32UC3C 31.5.2 Power Management If the CPU enters a sleep mode that disables clocks used by the TC, the TC will stop functioning and resume operation after the system wakes up from sleep mode. 31.5.3 Clocks The clock for the TC bus interface (CLK_TC) is generated by the Power Manager. This clock is enabled at reset, and can be disabled in the Power Manager. It is recommended to disable the TC before disabling the clock, to avoid freezing the TC in an undefined state. 31.5.4 Interrupts The TC interrupt request line is connected to the interrupt controller. Using the TC interrupt requires the interrupt controller to be programmed first. 31.5.5 31.6 Debug Operation The Timer Counter clocks are frozen during debug operation, unless the OCD system keeps peripherals running in debug operation. Functional Description 31.6.1 TC Description The three channels of the Timer Counter are independent and identical in operation. The registers for channel programming are listed in Figure 31-3 on page 840. 31.6.1.1 Channel I/O Signals As described in Figure 31-1 on page 824, each Channel has the following I/O signals. Table 31-2. Channel I/O Signals Description Block/Channel Signal Name XC0, XC1, XC2 Channel Signal External Clock Inputs TIOA Capture mode: Timer Counter Input Waveform mode: Timer Counter Output TIOB Capture mode: Timer Counter Input Waveform mode: Timer Counter Input/Output INT SYNC 31.6.1.2 Description Interrupt Signal Output Synchronization Input Signal 16-bit counter Each channel is organized around a 16-bit counter. The value of the counter is incremented at each positive edge of the selected clock. When the counter has reached the value 0xFFFF and passes to 0x0000, an overflow occurs and the Counter Overflow Status bit in the Channel n Status Register (SRn.COVFS) is set. The current value of the counter is accessible in real time by reading the Channel n Counter Value Register (CVn). The counter can be reset by a trigger. In this case, the counter value passes to 0x0000 on the next valid edge of the selected clock. 825 32117A-10/2010 AT32UC3C 31.6.1.3 Clock selection At block level, input clock signals of each channel can either be connected to the external inputs TCLK0, TCLK1 or TCLK2, or be connected to the configurable I/O signals A0, A1 or A2 for chaining by writing to the BMR register. See Figure 31-2 on page 826. Each channel can independently select an internal or external clock source for its counter: * Internal clock signals: TIMER_CLOCK1, TIMER_CLOCK2, TIMER_CLOCK3, TIMER_CLOCK4, TIMER_CLOCK5. See the Module Configuration Chapter for details about the connection of these clock sources. * External clock signals: XC0, XC1 or XC2. See the Module Configuration Chapter for details about the connection of these clock sources. This selection is made by the Clock Selection field in the Channel n Mode Register (CMRn.TCCLKS). The selected clock can be inverted with the Clock Invert bit in CMRn (CMRn.CLKI). This allows counting on the opposite edges of the clock. The burst function allows the clock to be validated when an external signal is high. The Burst Signal Selection field in the CMRn register (CMRn.BURST) defines this signal. Note: In all cases, if an external clock is used, the duration of each of its levels must be longer than the CLK_TC period. The external clock frequency must be at least 2.5 times lower than the CLK_TC. Figure 31-2. Clock Selection TCCLKS TIMER_CLOCK1 TIMER_CLOCK2 CLKI TIMER_CLOCK3 TIMER_CLOCK4 TIMER_CLOCK5 Selected Clock XC0 XC1 XC2 BURST 1 31.6.1.4 Clock control The clock of each counter can be controlled in two different ways: it can be enabled/disabled and started/stopped. See Figure 31-3 on page 827. 826 32117A-10/2010 AT32UC3C * The clock can be enabled or disabled by the user by writing to the Counter Clock Enable/Disable Command bits in the Channel n Clock Control Register (CCRn.CLKEN and CCRn.CLKDIS). In Capture mode it can be disabled by an RB load event if the Counter Clock Disable with RB Loading bit in CMRn is written to one (CMRn.LDBDIS). In Waveform mode, it can be disabled by an RC Compare event if the Counter Clock Disable with RC Compare bit in CMRn is written to one (CMRn.CPCDIS). When disabled, the start or the stop actions have no effect: only a CLKEN command in CCRn can re-enable the clock. When the clock is enabled, the Clock Enabling Status bit is set in SRn (SRn.CLKSTA). * The clock can also be started or stopped: a trigger (software, synchro, external or compare) always starts the clock. In Capture mode the clock can be stopped by an RB load event if the Counter Clock Stopped with RB Loading bit in CMRn is written to one (CMRn.LDBSTOP). In Waveform mode it can be stopped by an RC compare event if the Counter Clock Stopped with RC Compare bit in CMRn is written to one (CMRn.CPCSTOP). The start and the stop commands have effect only if the clock is enabled. Figure 31-3. Clock Control Selected Clock Trigger CLKSTA Q Q S CLKEN CLKDIS S R R Counter Clock 31.6.1.5 Stop Event Disable Event TC operating modes Each channel can independently operate in two different modes: * Capture mode provides measurement on signals. * Waveform mode provides wave generation. The TC operating mode selection is done by writing to the Wave bit in the CCRn register (CCRn.WAVE). In Capture mode, TIOA and TIOB are configured as inputs. In Waveform mode, TIOA is always configured to be an output and TIOB is an output if it is not selected to be the external trigger. 827 32117A-10/2010 AT32UC3C 31.6.1.6 Trigger A trigger resets the counter and starts the counter clock. Three types of triggers are common to both modes, and a fourth external trigger is available to each mode. The following triggers are common to both modes: * Software Trigger: each channel has a software trigger, available by writing a one to the Software Trigger Command bit in CCRn (CCRn.SWTRG). * SYNC: each channel has a synchronization signal SYNC. When asserted, this signal has the same effect as a software trigger. The SYNC signals of all channels are asserted simultaneously by writing a one to the Synchro Command bit in the BCR register (BCR.SYNC). * Compare RC Trigger: RC is implemented in each channel and can provide a trigger when the counter value matches the RC value if the RC Compare Trigger Enable bit in CMRn (CMRn.CPCTRG) is written to one. The channel can also be configured to have an external trigger. In Capture mode, the external trigger signal can be selected between TIOA and TIOB. In Waveform mode, an external event can be programmed to be one of the following signals: TIOB, XC0, XC1, or XC2. This external event can then be programmed to perform a trigger by writing a one to the External Event Trigger Enable bit in CMRn (CMRn.ENETRG). If an external trigger is used, the duration of the pulses must be longer than the CLK_TC period in order to be detected. Regardless of the trigger used, it will be taken into account at the following active edge of the selected clock. This means that the counter value can be read differently from zero just after a trigger, especially when a low frequency signal is selected as the clock. 31.6.2 Capture Operating Mode This mode is entered by writing a zero to the CMRn.WAVE bit. Capture mode allows the TC channel to perform measurements such as pulse timing, frequency, period, duty cycle and phase on TIOA and TIOB signals which are considered as inputs. Figure 31-4 on page 830 shows the configuration of the TC channel when programmed in Capture mode. 31.6.2.1 Capture registers A and B Registers A and B (RA and RB) are used as capture registers. This means that they can be loaded with the counter value when a programmable event occurs on the signal TIOA. The RA Loading Selection field in CMRn (CMRn.LDRA) defines the TIOA edge for the loading of the RA register, and the RB Loading Selection field in CMRn (CMRn.LDRB) defines the TIOA edge for the loading of the RB register. RA is loaded only if it has not been loaded since the last trigger or if RB has been loaded since the last loading of RA. RB is loaded only if RA has been loaded since the last trigger or the last loading of RB. Loading RA or RB before the read of the last value loaded sets the Load Overrun Status bit in SRn (SRn.LOVRS). In this case, the old value is overwritten. 828 32117A-10/2010 AT32UC3C 31.6.2.2 Trigger conditions In addition to the SYNC signal, the software trigger and the RC compare trigger, an external trigger can be defined. The TIOA or TIOB External Trigger Selection bit in CMRn (CMRn.ABETRG) selects TIOA or TIOB input signal as an external trigger. The External Trigger Edge Selection bit in CMRn (CMRn.ETREDG) defines the edge (rising, falling or both) detected to generate an external trigger. If CMRn.ETRGEDG is zero (none), the external trigger is disabled. 829 32117A-10/2010 32117A-10/2010 TIOA TIOB SYNC MTIOA MTIOB TIMER_CLOCK2 TIMER_CLOCK3 TIMER_CLOCK4 TIMER_CLOCK5 XC0 XC1 XC2 TIMER_CLOCK1 1 Edge Detector ETRGEDG SWTRG CLKI Edge Detector LDRA CLK Trig S R OVF If RA is Loaded CPCTRG 16-bit Counter RESET Q LDBSTOP R S CLKEN Edge Detector LDRB Capture Register A Q CLKSTA LDBDIS Capture Register B CLKDIS SR Timer/Counter Channel If RA is not Loaded or RB is Loaded ABETRG BURST TCCLKS Compare RC = Register C COVFS LDRBS INT AT32UC3C Figure 31-4. Capture Mode LOVRS CPCS LDRAS ETRGS IMR 830 AT32UC3C 31.6.3 Waveform Operating Mode Waveform operating mode is entered by writing a one to the CMRn.WAVE bit. In Waveform operating mode the TC channel generates one or two PWM signals with the same frequency and independently programmable duty cycles, or generates different types of oneshot or repetitive pulses. In this mode, TIOA is configured as an output and TIOB is defined as an output if it is not used as an external event. Figure 31-5 on page 832 shows the configuration of the TC channel when programmed in Waveform operating mode. 31.6.3.1 Waveform selection Depending on the Waveform Selection field in CMRn (CMRn.WAVSEL), the behavior of CVn varies. With any selection, RA, RB and RC can all be used as compare registers. RA Compare is used to control the TIOA output, RB Compare is used to control the TIOB output (if correctly configured) and RC Compare is used to control TIOA and/or TIOB outputs. 831 32117A-10/2010 32117A-10/2010 TIOB SYNC XC2 XC1 TIMER_CLOCK5 XC0 TIMER_CLOCK4 TIMER_CLOCK3 TIMER_CLOCK2 TIMER_CLOCK1 EEVT Edge Detector EEVTEDG SWTRG ENETRG Trig CLK R S WAVSEL RESET 16-bit Counter WAVSEL Q OVF Compare RA = Q CLKSTA Register A SR Timer/Counter Channel 1 BURST CLKI Compare RC = Compare RB = CPCSTOP CPCDIS Register C CLKDIS Register B R S CLKEN CPAS INT BSWTRG BEEVT BCPB BCPC ASWTRG AEEVT ACPA ACPC O utput Contr oller O utput Cont r oller TCCLKS TIOB MTIOB TIOA MTIOA AT32UC3C Figure 31-5. Waveform Mode CPCS CPBS COVFS ETRGS IMR 832 AT32UC3C 31.6.3.2 WAVSEL = 0 When CMRn.WAVSEL is zero, the value of CVn is incremented from 0 to 0xFFFF. Once 0xFFFF has been reached, the value of CVn is reset. Incrementation of CVn starts again and the cycle continues. See Figure 31-6 on page 833. An external event trigger or a software trigger can reset the value of CVn. It is important to note that the trigger may occur at any time. See Figure 31-7 on page 834. RC Compare cannot be programmed to generate a trigger in this configuration. At the same time, RC Compare can stop the counter clock (CMRn.CPCSTOP = 1) and/or disable the counter clock (CMRn.CPCDIS = 1). Figure 31-6. WAVSEL= 0 Without Trigger Counter Value Counter cleared by compare match with 0xFFFF 0xFFFF RC RB RA Waveform Examples Time TIOB TIOA 833 32117A-10/2010 AT32UC3C Figure 31-7. WAVSEL= 0 With Trigger Counter Value Counter cleared by compare match with 0xFFFF 0xFFFF RC Counter cleared by trigger RB RA Waveform Examples Time TIOB TIOA 31.6.3.3 WAVSEL = 2 When CMRn.WAVSEL is two, the value of CVn is incremented from zero to the value of RC, then automatically reset on a RC Compare. Once the value of CVn has been reset, it is then incremented and so on. See Figure 31-8 on page 835. It is important to note that CVn can be reset at any time by an external event or a software trigger if both are programmed correctly. See Figure 31-9 on page 835. In addition, RC Compare can stop the counter clock (CMRn.CPCSTOP) and/or disable the counter clock (CMRn.CPCDIS = 1). 834 32117A-10/2010 AT32UC3C Figure 31-8. WAVSEL = 2 Without Trigger Counter Value 0xFFFF Counter cleared by compare match with RC RC RB RA Waveform Examples Time TIOB TIOA Figure 31-9. WAVSEL = 2 With Trigger Counter Value 0xFFFF Counter cleared by compare match with RC Counter cleared by trigger RC RB RA Waveform Examples Time TIOB TIOA 31.6.3.4 WAVSEL = 1 When CMRn.WAVSEL is one, the value of CVn is incremented from 0 to 0xFFFF. Once 0xFFFF is reached, the value of CVn is decremented to 0, then re-incremented to 0xFFFF and so on. See Figure 31-10 on page 836. 835 32117A-10/2010 AT32UC3C A trigger such as an external event or a software trigger can modify CVn at any time. If a trigger occurs while CVn is incrementing, CVn then decrements. If a trigger is received while CVn is decrementing, CVn then increments. See Figure 31-11 on page 836. RC Compare cannot be programmed to generate a trigger in this configuration. At the same time, RC Compare can stop the counter clock (CMRn.CPCSTOP = 1) and/or disable the counter clock (CMRn.CPCDIS = 1). Figure 31-10. WAVSEL = 1 Without Trigger Counter Value Counter decremented by compare match with 0xFFFF 0xFFFF RC RB RA Time Waveform Examples TIOB TIOA Figure 31-11. WAVSEL = 1 With Trigger Counter Value Counter decremented by compare match with 0xFFFF 0xFFFF Counter decremented by trigger RC RB Counter incremented by trigger RA Waveform Examples Time TIOB TIOA 836 32117A-10/2010 AT32UC3C 31.6.3.5 WAVSEL = 3 When CMRn.WAVSEL is three, the value of CVn is incremented from zero to RC. Once RC is reached, the value of CVn is decremented to zero, then re-incremented to RC and so on. See Figure 31-12 on page 837. A trigger such as an external event or a software trigger can modify CVn at any time. If a trigger occurs while CVn is incrementing, CVn then decrements. If a trigger is received while CVn is decrementing, CVn then increments. See Figure 31-13 on page 838. RC Compare can stop the counter clock (CMRn.CPCSTOP = 1) and/or disable the counter clock (CMRn.CPCDIS = 1). Figure 31-12. WAVSEL = 3 Without Trigger Counter Value 0xFFFF Counter cleared by compare match with RC RC RB RA Waveform Examples Time TIOB TIOA 837 32117A-10/2010 AT32UC3C Figure 31-13. WAVSEL = 3 With Trigger Counter Value 0xFFFF Counter decremented by compare match with RC RC Counter decremented by trigger RB Counter incremented by trigger RA Waveform Examples TIOB Time TIOA 31.6.3.6 External event/trigger conditions An external event can be programmed to be detected on one of the clock sources (XC0, XC1, XC2) or TIOB. The external event selected can then be used as a trigger. The External Event Selection field in CMRn (CMRn.EEVT) selects the external trigger. The External Event Edge Selection field in CMRn (CMRn.EEVTEDG) defines the trigger edge for each of the possible external triggers (rising, falling or both). If CMRn.EEVTEDG is written to zero, no external event is defined. If TIOB is defined as an external event signal (CMRn.EEVT = 0), TIOB is no longer used as an output and the compare register B is not used to generate waveforms and subsequently no IRQs. In this case the TC channel can only generate a waveform on TIOA. When an external event is defined, it can be used as a trigger by writing a one to the CMRn.ENETRG bit. As in Capture mode, the SYNC signal and the software trigger are also available as triggers. RC Compare can also be used as a trigger depending on the CMRn.WAVSEL field. 31.6.3.7 Output controller The output controller defines the output level changes on TIOA and TIOB following an event. TIOB control is used only if TIOB is defined as output (not as an external event). The following events control TIOA and TIOB: * software trigger * external event * RC compare RA compare controls TIOA and RB compare controls TIOB. Each of these events can be programmed to set, clear or toggle the output as defined in the following fields in CMRn: * RC Compare Effect on TIOB (CMRn.BCPC) 838 32117A-10/2010 AT32UC3C * RB Compare Effect on TIOB (CMRn.BCPB) * RC Compare Effect on TIOA (CMRn.ACPC) * RA Compare Effect on TIOA (CMRn.ACPA) 839 32117A-10/2010 AT32UC3C 31.7 User Interface Table 31-3. TC Register Memory Map Offset Register Register Name Access Reset 0x00 Channel 0 Control Register CCR0 Write-only 0x00000000 0x04 Channel 0 Mode Register CMR0 Read/Write 0x00000000 0x10 Channel 0 Counter Value CV0 Read-only 0x00000000 0x14 Channel 0 Register A RA0 Read/Write(1) 0x00000000 0x18 Channel 0 Register B RB0 Read/Write(1) 0x00000000 0x1C Channel 0 Register C RC0 Read/Write 0x00000000 0x20 Channel 0 Status Register SR0 Read-only 0x00000000 0x24 Interrupt Enable Register IER0 Write-only 0x00000000 0x28 Channel 0 Interrupt Disable Register IDR0 Write-only 0x00000000 0x2C Channel 0 Interrupt Mask Register IMR0 Read-only 0x00000000 0x40 Channel 1 Control Register CCR1 Write-only 0x00000000 0x44 Channel 1 Mode Register CMR1 Read/Write 0x00000000 0x50 Channel 1 Counter Value CV1 Read-only 0x00000000 0x54 Channel 1 Register A RA1 (1) 0x00000000 (1) 0x00000000 Read/Write 0x58 Channel 1 Register B RB1 Read/Write 0x5C Channel 1 Register C RC1 Read/Write 0x00000000 0x60 Channel 1 Status Register SR1 Read-only 0x00000000 0x64 Channel 1 Interrupt Enable Register IER1 Write-only 0x00000000 0x68 Channel 1 Interrupt Disable Register IDR1 Write-only 0x00000000 0x6C Channel 1 Interrupt Mask Register IMR1 Read-only 0x00000000 0x80 Channel 2 Control Register CCR2 Write-only 0x00000000 0x84 Channel 2 Mode Register CMR2 Read/Write 0x00000000 0x90 Channel 2 Counter Value CV2 Read-only 0x00000000 0x94 Channel 2 Register A RA2 Read/Write(1) 0x00000000 0x98 Channel 2 Register B RB2 Read/Write(1) 0x00000000 0x9C Channel 2 Register C RC2 Read/Write 0x00000000 0xA0 Channel 2 Status Register SR2 Read-only 0x00000000 0xA4 Channel 2 Interrupt Enable Register IER2 Write-only 0x00000000 0xA8 Channel 2 Interrupt Disable Register IDR2 Write-only 0x00000000 0xAC Channel 2 Interrupt Mask Register IMR2 Read-only 0x00000000 0xC0 Block Control Register BCR Write-only 0x00000000 0xC4 Block Mode Register BMR Read/Write 0x00000000 0xF8 Features Register FEATURES Read-only -(2) 0xFC Version Register VERSION Read-only -(2) 840 32117A-10/2010 AT32UC3C Notes: 1. Read-only if CMRn.WAVE is zero. 2. The reset values are device specific. Please refer to the Module Configuration section at the end of this chapter. 841 32117A-10/2010 AT32UC3C 31.7.1 Name: Channel Control Register CCR Access Type: Write-only Offset: 0x00 + n * 0x40 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 - - - - - - - - 7 6 5 4 3 2 1 0 - - - - - SWTRG CLKDIS CLKEN * SWTRG: Software Trigger Command 1: Writing a one to this bit will perform a software trigger: the counter is reset and the clock is started. 0: Writing a zero to this bit has no effect. * CLKDIS: Counter Clock Disable Command 1: Writing a one to this bit will disable the clock. 0: Writing a zero to this bit has no effect. * CLKEN: Counter Clock Enable Command 1: Writing a one to this bit will enable the clock if CLKDIS is not one. 0: Writing a zero to this bit has no effect. 842 32117A-10/2010 AT32UC3C 31.7.2 Name: Channel Mode Register: Capture Mode CMR Access Type: Read/Write Offset: 0x04 + n * 0x40 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - 15 14 13 12 11 10 WAVE CPCTRG - - - ABETRG 7 6 5 4 3 2 LDBDIS LDBSTOP BURST LDRB CLKI LDRA 9 8 ETRGEDG 1 0 TCCLKS * LDRB: RB Loading Selection LDRB Edge 0 none 1 rising edge of TIOA 2 falling edge of TIOA 3 each edge of TIOA * LDRA: RA Loading Selection LDRA Edge 0 none 1 rising edge of TIOA 2 falling edge of TIOA 3 each edge of TIOA * WAVE 1: Capture mode is disabled (Waveform mode is enabled). 0: Capture mode is enabled. * CPCTRG: RC Compare Trigger Enable 1: RC Compare resets the counter and starts the counter clock. 0: RC Compare has no effect on the counter and its clock. * ABETRG: TIOA or TIOB External Trigger Selection 1: TIOA is used as an external trigger. 843 32117A-10/2010 AT32UC3C 0: TIOB is used as an external trigger. * ETRGEDG: External Trigger Edge Selection ETRGEDG Edge 0 none 1 rising edge 2 falling edge 3 each edge * LDBDIS: Counter Clock Disable with RB Loading 1: Counter clock is disabled when RB loading occurs. 0: Counter clock is not disabled when RB loading occurs. * LDBSTOP: Counter Clock Stopped with RB Loading 1: Counter clock is stopped when RB loading occurs. 0: Counter clock is not stopped when RB loading occurs. * BURST: Burst Signal Selection BURST Burst Signal Selection 0 The clock is not gated by an external signal 1 XC0 is ANDed with the selected clock 2 XC1 is ANDed with the selected clock 3 XC2 is ANDed with the selected clock * CLKI: Clock Invert 1: The counter is incremented on falling edge of the clock. 0: The counter is incremented on rising edge of the clock. * TCCLKS: Clock Selection TCCLKS Clock Selected 0 TIMER_CLOCK1 1 TIMER_CLOCK2 2 TIMER_CLOCK3 3 TIMER_CLOCK4 4 TIMER_CLOCK5 5 XC0 6 XC1 7 XC2 844 32117A-10/2010 AT32UC3C 31.7.3 Name: Channel Mode Register: Waveform Mode CMR Access Type: Read/Write Offset: 0x04 + n * 0x40 Reset Value: 0x00000000 31 30 29 BSWTRG 23 27 BEEVT 22 21 ASWTRG 15 28 20 WAVE 13 7 6 19 CPCDIS CPCSTOP 4 BURST BCPB 18 11 ENETRG 5 24 17 16 ACPC 12 WAVSEL 25 BCPC AEEVT 14 26 ACPA 10 9 EEVT 3 CLKI 8 EEVTEDG 2 1 0 TCCLKS * BSWTRG: Software Trigger Effect on TIOB BSWTRG Effect 0 none 1 set 2 clear 3 toggle * BEEVT: External Event Effect on TIOB BEEVT Effect 0 none 1 set 2 clear 3 toggle 845 32117A-10/2010 AT32UC3C * BCPC: RC Compare Effect on TIOB BCPC Effect 0 none 1 set 2 clear 3 toggle * BCPB: RB Compare Effect on TIOB BCPB Effect 0 none 1 set 2 clear 3 toggle * ASWTRG: Software Trigger Effect on TIOA ASWTRG Effect 0 none 1 set 2 clear 3 toggle * AEEVT: External Event Effect on TIOA AEEVT Effect 0 none 1 set 2 clear 3 toggle * ACPC: RC Compare Effect on TIOA ACPC Effect 0 none 1 set 2 clear 3 toggle 846 32117A-10/2010 AT32UC3C * ACPA: RA Compare Effect on TIOA ACPA Effect 0 none 1 set 2 clear 3 toggle * WAVE 1: Waveform mode is enabled. 0: Waveform mode is disabled (Capture mode is enabled). * WAVSEL: Waveform Selection WAVSEL Effect 0 UP mode without automatic trigger on RC Compare 1 UPDOWN mode without automatic trigger on RC Compare 2 UP mode with automatic trigger on RC Compare 3 UPDOWN mode with automatic trigger on RC Compare * ENETRG: External Event Trigger Enable 1: The external event resets the counter and starts the counter clock. 0: The external event has no effect on the counter and its clock. In this case, the selected external event only controls the TIOA output. * EEVT: External Event Selection EEVT Note: Signal selected as external event TIOB Direction 0 TIOB input(1) 1 XC0 output 2 XC1 output 3 XC2 output 1. If TIOB is chosen as the external event signal, it is configured as an input and no longer generates waveforms and subsequently no IRQs. * EEVTEDG: External Event Edge Selection EEVTEDG Edge 0 none 1 rising edge 2 falling edge 3 each edge * CPCDIS: Counter Clock Disable with RC Compare 1: Counter clock is disabled when counter reaches RC. 0: Counter clock is not disabled when counter reaches RC. * CPCSTOP: Counter Clock Stopped with RC Compare 1: Counter clock is stopped when counter reaches RC. 847 32117A-10/2010 AT32UC3C 0: Counter clock is not stopped when counter reaches RC. * BURST: Burst Signal Selection BURST Burst Signal Selection 0 The clock is not gated by an external signal. 1 XC0 is ANDed with the selected clock. 2 XC1 is ANDed with the selected clock. 3 XC2 is ANDed with the selected clock. * CLKI: Clock Invert 1: Counter is incremented on falling edge of the clock. 0: Counter is incremented on rising edge of the clock. * TCCLKS: Clock Selection TCCLKS Clock Selected 0 TIMER_CLOCK1 1 TIMER_CLOCK2 2 TIMER_CLOCK3 3 TIMER_CLOCK4 4 TIMER_CLOCK5 5 XC0 6 XC1 7 XC2 848 32117A-10/2010 AT32UC3C 31.7.4 Name: Channel Counter Value Register CV Access Type: Read-only Offset: 0x10 + n * 0x40 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 3 2 1 0 CV[15:8] 7 6 5 4 CV[7:0] * CV: Counter Value CV contains the counter value in real time. 849 32117A-10/2010 AT32UC3C 31.7.5 Name: Channel Register A RA Access Type: Read-only if CMRn.WAVE = 0, Read/Write if CMRn.WAVE = 1 Offset: 0x14 + n * 0X40 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 3 2 1 0 RA[15:8] 7 6 5 4 RA[7:0] * RA: Register A RA contains the Register A value in real time. 850 32117A-10/2010 AT32UC3C 31.7.6 Name: Channel Register B RB Access Type: Read-only if CMRn.WAVE = 0, Read/Write if CMRn.WAVE = 1 Offset: 0x18 + n * 0x40 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 3 2 1 0 RB[15:8] 7 6 5 4 RB[7:0] * RB: Register B RB contains the Register B value in real time. 851 32117A-10/2010 AT32UC3C 31.7.7 Name: Channel Register C RC Access Type: Read/Write Offset: 0x1C + n * 0x40 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 3 2 1 0 RC[15:8] 7 6 5 4 RC[7:0] * RC: Register C RC contains the Register C value in real time. 852 32117A-10/2010 AT32UC3C 31.7.8 Name: Channel Status Register SR Access Type: Read-only Offset: 0x20 + n * 0x40 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - MTIOB MTIOA CLKSTA 15 14 13 12 11 10 9 8 - - - - - - - - 7 6 5 4 3 2 1 0 ETRGS LDRBS LDRAS CPCS CPBS CPAS LOVRS COVFS Note: Reading the Status Register will also clear the interrupt bit for the corresponding interrupts. * MTIOB: TIOB Mirror 1: TIOB is high. If CMRn.WAVE is zero, this means that TIOB pin is high. If CMRn.WAVE is one, this means that TIOB is driven high. 0: TIOB is low. If CMRn.WAVE is zero, this means that TIOB pin is low. If CMRn.WAVE is one, this means that TIOB is driven low. * MTIOA: TIOA Mirror 1: TIOA is high. If CMRn.WAVE is zero, this means that TIOA pin is high. If CMRn.WAVE is one, this means that TIOA is driven high. 0: TIOA is low. If CMRn.WAVE is zero, this means that TIOA pin is low. If CMRn.WAVE is one, this means that TIOA is driven low. * CLKSTA: Clock Enabling Status 1: This bit is set when the clock is enabled. 0: This bit is cleared when the clock is disabled. * ETRGS: External Trigger Status 1: This bit is set when an external trigger has occurred. 0: This bit is cleared when the SR register is read. * LDRBS: RB Loading Status 1: This bit is set when an RB Load has occurred and CMRn.WAVE is zero. 0: This bit is cleared when the SR register is read. * LDRAS: RA Loading Status 1: This bit is set when an RA Load has occurred and CMRn.WAVE is zero. 0: This bit is cleared when the SR register is read. * CPCS: RC Compare Status 1: This bit is set when an RC Compare has occurred. 0: This bit is cleared when the SR register is read. 853 32117A-10/2010 AT32UC3C * CPBS: RB Compare Status 1: This bit is set when an RB Compare has occurred and CMRn.WAVE is one. 0: This bit is cleared when the SR register is read. * CPAS: RA Compare Status 1: This bit is set when an RA Compare has occurred and CMRn.WAVE is one. 0: This bit is cleared when the SR register is read. * LOVRS: Load Overrun Status 1: This bit is set when RA or RB have been loaded at least twice without any read of the corresponding register and CMRn.WAVE is zero. 0: This bit is cleared when the SR register is read. * COVFS: Counter Overflow Status 1: This bit is set when a counter overflow has occurred. 0: This bit is cleared when the SR register is read. 854 32117A-10/2010 AT32UC3C 31.7.9 Name: Channel Interrupt Enable Register IER Access Type: Write-only Offset: 0x24 + n * 0x40 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 - - - - - - - - 7 6 5 4 3 2 1 0 ETRGS LDRBS LDRAS CPCS CPBS CPAS LOVRS COVFS Writing a zero to a bit in this register has no effect. Writing a one to a bit in this register will set the corresponding bit in IMR. 855 32117A-10/2010 AT32UC3C 31.7.10 Name: Channel Interrupt Disable Register IDR Access Type: Write-only Offset: 0x28 + n * 0x40 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 - - - - - - - - 7 6 5 4 3 2 1 0 ETRGS LDRBS LDRAS CPCS CPBS CPAS LOVRS COVFS Writing a zero to a bit in this register has no effect. Writing a one to a bit in this register will clear the corresponding bit in IMR. 856 32117A-10/2010 AT32UC3C 31.7.11 Name: Channel Interrupt Mask Register IMR Access Type: Read-only Offset: 0x2C + n * 0x40 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 - - - - - - - - 7 6 5 4 3 2 1 0 ETRGS LDRBS LDRAS CPCS CPBS CPAS LOVRS COVFS 0: The corresponding interrupt is disabled. 1: The corresponding interrupt is enabled. A bit in this register is cleared when the corresponding bit in IDR is written to one. A bit in this register is set when the corresponding bit in IER is written to one. 857 32117A-10/2010 AT32UC3C 31.7.12 Name: Block Control Register BCR Access Type: Write-only Offset: 0xC0 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 - - - - - - - - 7 6 5 4 3 2 1 0 - - - - - - - SYNC * SYNC: Synchro Command 1: Writing a one to this bit asserts the SYNC signal which generates a software trigger simultaneously for each of the channels. 0: Writing a zero to this bit has no effect. 858 32117A-10/2010 AT32UC3C 31.7.13 Name: Block Mode Register BMR Access Type: Read/Write Offset: 0xC4 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 - - - - - - - - 7 6 5 4 3 2 1 0 - - TC2XC2S TC1XC1S TC0XC0S * TC2XC2S: External Clock Signal 2 Selection TC2XC2S Signal Connected to XC2 0 TCLK2 1 none 2 TIOA0 3 TIOA1 * TC1XC1S: External Clock Signal 1 Selection TC1XC1S Signal Connected to XC1 0 TCLK1 1 none 2 TIOA0 3 TIOA2 859 32117A-10/2010 AT32UC3C * TC0XC0S: External Clock Signal 0 Selection TC0XC0S Signal Connected to XC0 0 TCLK0 1 none 2 TIOA1 3 TIOA2 860 32117A-10/2010 AT32UC3C 31.7.14 Name: Features Register FEATURES Access Type: Read-only Offset: 0xF8 Reset Value: - 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - 15 14 13 12 11 10 9 8 - - - - - - BRPBHSB UPDNIMPL 7 6 5 4 3 2 1 0 CTRSIZE * BRPBHSB: Bridge type is PB to HSB 1: Bridge type is PB to HSB. 0: Bridge type is not PB to HSB. * UPDNIMPL: Up/down is implemented 1: Up/down counter capability is implemented. 0: Up/down counter capability is not implemented. * CTRSIZE: Counter size This field indicates the size of the counter in bits. 861 32117A-10/2010 AT32UC3C 31.7.15 Name: Version Register VERSION Access Type: Read-only Offset: 0xFC Reset Value: - 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - 15 14 13 12 9 8 - - - - 7 6 5 4 VARIANT 11 10 VERSION[11:8] 3 2 1 0 VERSION[7:0] * VARIANT: Variant number Reserved. No functionality associated. * VERSION: Version number Version number of the module. No functionality associated. 862 32117A-10/2010 AT32UC3C 31.8 Module Configuration The specific configuration for each TC instance is listed in the following tables. The module bus clocks listed here are connected to the system bus clocks according to the table in the Power Manager section. Table 31-4. 31.8.1 Module Clock Name Module name Clock name Description TC0 CLK_TC0 Peripheral Bus clock from the PBC clock domain TC1 CLK_TC1 Peripheral Bus clock from the PBA clock domain Clock Connections Each Timer/Counter channel can independently select an internal or external clock source for its counter: Table 31-5. Timer/Counter clock connections Module Source Name Connection TC0 Internal TIMER_CLOCK1 32 KHz oscillator clock (OSC32K) TIMER_CLOCK2 PBC clock / 2 (TIMER0_CLOCK2) TIMER_CLOCK3 PBC clock / 8 (TIMER0_CLOCK3) TIMER_CLOCK4 PBC clock / 32 (TIMER0_CLOCK4) TIMER_CLOCK5 PBC clock / 128 (TIMER0_CLOCK5) TC0 - CLK0 See Peripheral Multiplexing on I/O line chapter External TC0 - CLK1 TC0 - CLK2 TC1 Internal External TIMER_CLOCK1 32 KHz oscillator clock (OSC32K) TIMER_CLOCK2 PBA clock / 2 (TIMER1_CLOCK2) TIMER_CLOCK3 PBA clock / 8 (TIMER1_CLOCK3) TIMER_CLOCK4 PBA clock / 32 (TIMER1_CLOCK4) TIMER_CLOCK5 PBA clock / 128 (TIMER1_CLOCK5) TC1 - CLK0 See Peripheral Multiplexing on I/O line chapter TC1 - CLK1 TC1 - CLK2 863 32117A-10/2010 AT32UC3C 32. USB Interface (USBC) Rev: 2.1.0.6 32.1 Features * * * * * * * * * * 32.2 Compatible with the USB 2.0 specification Supports full (12Mbit/s) and low (1.5Mbit/s) speed communication Support embedded Host 7 pipes/endpoints in ping-pong mode Flexible pipe/endpoint configuration and reallocate of data buffers in embedded RAM Alternate pipe to support infinite number of aperiodic pipe Up to two memory banks per pipe/endpoint (not for Control pipe/endpoint) Built-in DMA with multi-packet support through ping-pong feature On-chip transceivers including pull-ups/pull-downs On-chip Device and embedded Host pad including VBUS analog comparator Overview The Universal Serial Bus interface (USBC) device complies with the Universal Serial Bus (USB) 2.0 specification, . Each pipe/endpoint can be configured in one of several transfer types. It can be associated with one or more banks (located inside the embedded system or CPU RAM) used to store the current data payload. If two banks are used ( "ping-pong" mode), then one RAM bank is read or written by the CPU or the DMA while the other is read or written by the USBC core. Table 32-1 on page 864 describes the hardware configuration of the USB MCU device. Table 32-1. Description of USB pipes/endpoints pipe/endpoint Mnemonic Max. Size Max. Nb. Banks Type 0 PEP0 1023 bytes 1 Control/Isochronous/Bulk/Interrupt 1 PEP1 1023 bytes 2 Control/Isochronous/Bulk/Interrupt 2 PEP2 1023 bytes 2 Control/Isochronous/Bulk/Interrupt ... ... ... ... ... 6 PEP6 1023 bytes 2 Control/Isochronous/Bulk/Interrupt 32.3 Block Diagram The USBC provides a hardware device to interface a USB link to a data flow stored in the embedded ram (CPU or HSB). The USBC requires a 48MHz 0.25% reference clock, which is the USB generic clock generated from one of the power manager oscillators, optionally through one of the power manager PLLs. The 48MHz clock is used to generate a 12MHz full-speed (or 1.5 MHz low-speed) bit clock from the received USB differential data and to transmit data according to full- or low-speed USB device tolerance. Clock recovery is achieved by a digital phase-locked loop (a DPLL, not represented), which complies with the USB jitter specifications. 864 32117A-10/2010 AT32UC3C Figure 32-1. USBC Block Diagram USB HSB HSB Master USB_VBUS PB DM User Interface USB 2.0 Core DP USB Interrupts Interrupt Controller I/O Controller USB_VBOF USB_ID SCIF GCLK_USBC @ 48 MHz System clock USB clock domain domain 865 32117A-10/2010 AT32UC3C 32.4 Application Block Diagram Depending on the USB operating mode (device-only, reduced-host) and the power source (buspowered or self-powered), there are different typical hardware implementations. 32.4.1 Device Mode 32.4.1.1 Bus-Powered device Figure 32-2. Bus-Powered Device Application Block Diagram 32.4.1.2 Self-Powered device Figure 32-3. Self-Powered Device Application Block Diagram 32.4.2 Host Modes Figure 32-4. Host Application Block Diagram VDD 5V DC/DC Generator USB Connector USB_VBUS USB 2.0 Core USB_VBUS USB_ID USB_VBOF ID DM 39 ohms DP 39 ohms DM DP GND 866 32117A-10/2010 AT32UC3C 32.5 I/O Lines Description Table 32-2. I/O Lines Description PIn Name Pin Description Type Active Level USB_VBOF USB VBus On/Off: Bus Power Control Port Output USBCON.VBUSPO USB_VBUS VBus: Bus Power Measurement Port DM Data -: Differential Data Line - Port Input/Output DP Data +: Differential Data Line + Port Input/Output USB_ID USB Identification: Mini Connector Identification Port Input Input Low: Mini-A plug High Z: Mini-B plug 867 32117A-10/2010 AT32UC3C 32.6 Product Dependencies In order to use this module, other parts of the system must be configured correctly, as described below. 32.6.1 I/O Lines The USB_VBOF,USB_VBUS and USB_ID pins are multiplexed with I/O Controller lines and may also be multiplexed with lines of other peripherals. In order to use them with the USBC, the user must first configure the I/O Controller to assign them to their USBC peripheral functions. If USB_ID is used, the I/O Controller must be configured to enable the internal pull-up resistor of its pin. If USB_VBOF or USB_ID is not used by the application, the corresponding pin can be used for other purposes by the I/O Controller or by other peripherals. 32.6.2 Clocks The USBC has two bus clocks connected: One High Speed Bus clock (CLK_USBC_HSB) and one Peripheral Bus clock (CLK_USBC_PB). These clocks are generated by the Power Manager. Both clocks are enabled at reset, and can be disabled by the Power Manager. It is recommended to disable the USBC before disabling the clocks, to avoid freezing the USBC in an undefined state. The 48MHz USB clock is generated by a dedicated generic clock from the SCIF module. Before using the USB, the user must ensure that the USB generic clock (GCLK_USBC) is enabled at 48MHz in the SCIF module. 32.6.3 Interrupts The USBC interrupt request line is connected to the interrupt controller. Using the USBC interrupt requires the interrupt controller to be programmed first. 868 32117A-10/2010 AT32UC3C 32.7 Functional Description 32.7.1 USB General Operation 32.7.1.1 Introduction After a hardware reset, the USBC is disabled. When enabled, the USBC runs in either device mode or in host mode according to the ID detection. If the USB_ID pin is not connected to ground, the USB_ID Pin State bit in the General Status register (USBSTA.ID) is set (the internal pull-up resistor of the USB_ID pin must be enabled by the I/O Controller) and device mode is enabled. The USBSTA.ID bit is cleared when a low level has been detected on the USB_ID pin. Host mode is then enabled. 32.7.1.2 Power-On and reset Figure 32-5. General States Macro off: USBE = 0 Clock stopped: FRZCLK = 1 USBE = 0 Reset HW RESET USBE = 1 ID = 1 USBE = 0 Device USBE = 1 ID = 0 USBE = 0 Host After a hardware reset, the USBC is in the Reset state. In this state: * The macro is disabled. The USBC Enable bit in the General Control register (USBCON.USBE) is zero. * The macro clock is stopped in order to minimize power consumption. The Freeze USB Clock bit in USBCON (USBON.FRZCLK) is one. * The pad is in suspend mode. * The internal states and registers of the device and host modes are reset. * The USBSTA.ID bit and the VBus Level bit in USBSTA (USBSTA.VBUS) reflect the states of the USB_ID and USB_VBUS input pins. * The VBus Level bit in UBSTA (UBSTA.VBUS) reflect the states of the USB_VBUS input pins. * The OTG Pad Enable (OTGPADE) bit, the VBus Polarity (VBUSPO) bit, the FRZCLK bit, the USBE bit, the USB_ID Pin Enable (UIDE) bit, the USBC Mode (UIMOD) bit in USBCON, and the low-speed Mode Force bit in the Device General Control register (UDCON.LS) can be written by software, so that the user can program pads and speed before enabling the macro, but their value is only taken into account once the macro is enabled and unfrozen. After writing a one to USBCON.USBE, the USBC enters Device or Host mode (according to the ID detection) in idle state. 869 32117A-10/2010 AT32UC3C The USBC can be disabled at any time by writing a zero to USBCON.USBE. Writing a zero to USBCON.USBE acts as a hardware reset, except that the OTGPADE, VBUSPO, FRZCLK, UIDE, UIMOD and LS bits are not reset. 32.7.1.3 Interrupts One interrupt vector is assigned to the USBC. See Section 32.7.2.19 and Section 32.7.3.16 for further details about device and host interrupts. There are two kinds of general interrupts: processing, i.e. their generation is part of the normal processing, and exception, i.e. errors (not related to CPU exceptions). The processing general interrupts are: * The ID Transition Interrupt (IDTI) * The VBus Transition Interrupt (VBUSTI) * The SRP Interrupt (SRPI) * The Role Exchange Interrupt (ROLEEXI) The exception general interrupts are: * The VBus Error Interrupt (VBERRI) * The B-Connection Error Interrupt (BCERRI) * The HNP Error Interrupt (HNPERRI) * The Suspend Time-Out Interrupt (STOI) 32.7.1.4 MCU Power modes *Run mode In this mode, all MCU clocks can run, including the USBC clock. *Idle mode In this mode, the CPU is halted, i.e. the CPU clock is stopped. The Idle mode is entered whatever the state of the USBC. The MCU wakes up on any USB interrupt. *Frozen mode Same as the Idle mode, except that the HSB module is stopped, so the USB Built-in DMA, which is an HSB master, can not be used. Moreover, the USB Built-in DMA must be stopped before entering this sleep mode in order to avoid erratic behavior. The MCU wakes up on any USBC interrupt. *Standby, Stop, DeepStop and Static modes Same as Frozen mode, except that the USBC generic clock and other clocks are stopped, so the USB macro is frozen. Only the asynchronous USBC interrupt sources can wake up the MCU in these modes. The Power Manager (PM) may have to be configured to enable asynchronous wake up from USBC. The USBC module must be frozen by writing a one to the FRZCLK bit. 870 32117A-10/2010 AT32UC3C *USB clock frozen In the run, idle and frozen MCU modes, the USBC can be frozen when the USB line is in suspend mode, by writing a one to the FRZCLK bit. This reduces power consumption. In deeper MCU power modes (from Standby mode), the USBC must be frozen. In this case, it is still possible to access the following elements, but only in Run mode: * The OTGPADE, VBUSPO, FRZCLK, USBE, UIDE, UIMOD and LS bits in the USBCON register Moreover, when FRZCLK is written to one, only the asynchronous interrupt sources may trigger the USB interrupt: * The ID Transition Interrupt (IDTI) * The VBus Transition Interrupt (VBUSTI) * The Wake-up Interrupt (WAKEUP) * The Host Wake-up Interrupt (HWUPI) *USB Suspend mode In peripheral mode, the Suspend Interrupt bit in the Device Global Interrupt register (UDINT.SUSP) indicates that the USB line is in suspend mode. In this case, the transceiver is automatically set in suspend mode to reduce the consumption. 32.7.1.5 Speed control *Device mode When the USBC interface is in device mode, the speed selection (full-speed or low-speed) depends on which of DP and DM is pulled up. The LS bit allows to connect an internal pull-up resistor either on DP (full-speed mode) or on DM (low-speed mode). The LS bit shall be written before attaching the device, what can be done by clearing the DETACH bit in UDCON. Figure 32-6. Speed Selection in Device Mode RPU VBUS UDCON.DETACH UDCON.LS DP DM 871 32117A-10/2010 AT32UC3C *Host mode When the USBC interface is in host mode, internal pull-down resistors are connected on both DP and DM and the interface detects the speed of the connected device, which is reflected by the Speed Status (SPEED) field in USBSTA. 32.7.1.6 Data management Endpoints and pipe buffers can be allocated anywhere in the embedded memory (CPU RAM or HSB RAM). See "RAM management" on page 877. 32.7.1.7 Pad Suspend Figure 32-7. Pad Behavior USBE = 1 & DETACH = 0 & Suspend Idle USBE = 0 | DETACH = 1 | Suspend Active * In Idle state, the pad is in low power consumption mode. * In Active state, the pad is working. Figure 32-8 on page 872 illustrates the pad events leading to a PAD state change. Figure 32-8. Pad events SUSP Suspend detected WAKEUP Cleared on wake-up Wake-up detected Cleared by software to acknowledge the interrupt PAD State Active Idle Active 872 32117A-10/2010 AT32UC3C The SUSP bit is set and the Wake-Up Interrupt (WAKEUP) bit in UDINT is cleared when a USB Suspend state has been detected on the USB bus. This event automatically puts the USB pad in the Idle state. The detection of a non-idle event sets WAKEUP, clears SUSP, and wakes up the USB pad. The pad goes to the Idle state if the macro is disabled or if the DETACH bit is written to one. It returns to the Active state when USBE is written to one and DETACH is written to zero. 32.7.1.8 Table 32-3. Customizing of embedded Host timers It is possible to refine some timers thanks to the Timer Page (TIMPAGE) and Timer Value (TIMVALUE) fields in USBCON, as shown in Table 32-3 on page 873. Customizing of OTG Timers TIMVALUE TIMPAGE 0b00 AWaitVrise Time-Out 0b01 VbBusPulsing Time-Out 0b10 PdTmOutCnt Time-Out 0b11 SRPDetTmOut Time-Out 00b 20 ms 15 ms 93 ms 10 s 01b 50 ms 23 ms 105 ms 100 s 10b 70 ms 31 ms 118 ms 1 ms 11b 100 ms 40 ms 131 ms 11 ms TIMPAGE is used to select the timer to access while TIMVALUE indicates the time-out value of the selected timer. TIMPAGE and TIMVALUE can be read or written. Before writing them, the user shall unlock write accesses by writing a one to the Timer Access Unlock (UNLOCK) bit in USBCON. This is not required for read accesses, except before accessing TIMPAGE if it has to be written in order to read the TIMVALUE field of another timer. 32.7.1.9 Plug-In detection The USB connection is detected from the USB_VBUS pad. Figure 32-9 on page 873 shows the architecture of the plug-in detector. Figure 32-9. Plug-In Detection Input Block Diagram VDD RPU VBus_pulsing USB_VBUS Session_valid RPD Va_Vbus_valid Logic VBUS VBUSTI USBSTA VBus_discharge GND Pad Logic The control logic of the USB_VBUS pad outputs two signals: 873 32117A-10/2010 AT32UC3C * The Session_valid signal is high when the voltage on the USB_VBUS pad is higher than or equal to 1.4V. * The Va_Vbus_valid signal is high when the voltage on the USB_VBUS pad is higher than or equal to 4.4V. In device mode, the USBSTA.VBUS bit follows the Session_valid comparator output: * It is set when the voltage on the USB_VBUS pad is higher than or equal to 1.4V. * It is cleared when the voltage on the VBUS pad is lower than 1.4V. In host mode, the USBSTA.VBUS bit follows an hysteresis based on Session_valid and Va_Vbus_valid: * It is set when the voltage on the USB_VBUS pad is higher than or equal to 4.4V. * It is cleared when the voltage on the USB_VBUS pad is lower than 1.4V. The VBus Transition interrupt (VBUSTI) bit in USBSTA is set on each transition of the USBSTA.VBUS bit. The USBSTA.VBUS bit is effective whether the USBC is enabled or not. 32.7.1.10 ID detection Figure 32-10 on page 874 shows how the ID transitions are detected. Figure 32-10. ID Detection Input Block Diagram RPU VDD 1 USB_ID 0 UIMOD ID IDTI USBSTA USBSTA USBCON UIDE USBCON I/O Controller The USBC mode (device or host) can be detected either from the USB_ID pin or software selected by writing to the UIMOD bit, according to the UIDE bit. This allows the USB_ID pin to be used as a general purpose I/O pin even when the USBC interface is enabled. By default, the USB_ID pin is selected (UIDE is written to one) and the USBC is in device mode (UBSTA.ID is one), this corresponds to the case where no Mini-A plug is connected, i.e. no plug or a Mini-B plug is connected and the USB_ID pin is kept high by the internal pull-up resistor from the I/O Controller (which must be enabled if USB_ID is used). The ID Transition Interrupt (IDTI) bit in USBSTA is set on each transition of the ID bit, i.e. when a Mini-A plug (host mode) is connected or disconnected. This does not occur when a Mini-B plug (device mode) is connected or disconnected. The USBSTA.ID bit is effective whether the USBC is enabled or not. 874 32117A-10/2010 AT32UC3C 32.7.2 USBC Device Operation 32.7.2.1 Introduction In device mode, the USBC supports full- and low-speed data transfers. In addition to the default control endpoint, 6 endpoints are provided; They can be configured with the types isochronous, bulk or interrupt, as described in Table 32-1 on page 864 The device mode starts in Idle state, so the pad consumption is reduced to the minimum. 32.7.2.2 Power-On and reset Figure 32-11 on page 875 describes the USBC device mode main states. Figure 32-11. Device Mode States USBE = 0 | ID = 0 USBE = 0 | ID = 0 Reset Idle USBE = 1 & ID = 1 HW RESET After a hardware reset, the USBC device mode is in Reset state. In this state: * The macro clock is stopped in order to minimize power consumption (FRZCLK is one). * The internal registers of the device mode are reset. * The endpoint banks are disabled. * Neither D+ nor D- is pulled up (DETACH is one). D+ or D- will be pulled up according to the selected speed as soon as the DETACH bit is written to zero and VBus is present. See "Device mode" for further details. When the USBC is enabled (USBE is one) in device mode (ID is one), its device mode state goes to the Idle state with minimal power consumption. This does not require the USBC clocks to be activated. The USBC device mode can be disabled and reset at any time by disabling the USBC (by writing a zero to USBE) or when host mode is enabled (ID is zero). 32.7.2.3 USB reset The USB bus reset is managed by hardware. It is initiated by a connected host. When a USB reset is detected on the USB line, the following operations are performed by the controller: * UDCON register is reset except DETACH and SPDCONF bits. * UDFNUM and UECFGn and UECONn registers are cleared. 875 32117A-10/2010 AT32UC3C * The data toggle sequences of all the endpoints are cleared. * At the end of the reset process, the End of Reset (EORST) bit in UDINT is set. 32.7.2.4 Endpoint activation An endpoint is maintained inactive as long as it is disabled (EPENn = 0). The data toggle sequence, the UESTAn and UECONn registers are also reset. As long as the endpoint is inactive, the controller ignores any transaction to this endpoint. To complete the endpoint activation, the user should fill the endpoint descriptor: see Figure 3212 on page 878. 32.7.2.5 Data toggle sequence initialization Sometimes, one wants to clear the data toggle sequence as an answer to the CLEAR_FEATURE USB request without disabling this endpoint. This can be achieved by writing a one to the Reset Data Toggle Set bit in the Endpoint n Control Set register (UECONnSET.RSTDTS). This will set the Reset Data Toggle (RSTD) bit in UECONn. 32.7.2.6 Busy Bank Enable Sometimes, one wants to "make busy" the endpoint bank whatever is its actual status. This can be achieved by writing a one to the Busy Bank Enable bits in the Endpoint n Control Register (UECONnSET.BUSY0/1ES). For instance, if the UECONn.BUSY1 bit is set, any transaction to the bank1 of the endpoint n will be rejected (NAK answer). 32.7.2.7 Address setup The USB device address is set up according to the USB protocol. * After all kinds of resets, the USB device address is 0. * The host starts a SETUP transaction with a SET_ADDRESS(addr) request. * The user writes this address to the USB Address (UADD) field in UDCON, and write a zero to the Address Enable (ADDEN) bit in UDCON, so the actual address is still 0. * The user sends a zero-length IN packet from the control endpoint. * The user enables the recorded USB device address by writing a one to ADDEN. Once the USB device address is configured, the controller filters the packets to only accept those targeting the address stored in UADD. UADD and ADDEN shall not be written all at once. UADD and ADDEN are cleared: * On a hardware reset. * When the USBC is disabled (USBE written to zero). * When a USB reset is detected. When UADD or ADDEN is cleared, the default device address 0 is used. 32.7.2.8 Suspend and wake-up When an idle USB bus state has been detected for 3 ms, the controller set the Suspend (SUSP) interrupt bit in UDINT. The user may then write a one to the FRZCLK bit to reduce power con- 876 32117A-10/2010 AT32UC3C sumption. The MCU can also enter the Idle or Frozen sleep mode to lower again power consumption. To recover from the Suspend mode, the user shall wait for the Wake-Up (WAKEUP) interrupt bit, which is set when a non-idle event is detected, then write a zero to FRZCLK. As the WAKEUP interrupt bit in UDINT is set when a non-idle event is detected, it can occur whether the controller is in the Suspend mode or not. The SUSP and WAKEUP interrupts are thus independent of each other except that one bit is cleared when the other is set. 32.7.2.9 Detach The reset value of the DETACH bit is one. It is possible to initiate a device re-enumeration simply by writing a one then a zero to DETACH. DETACH acts on the pull-up connections of the D+ and D- pads. See "Device mode" for further details. 32.7.2.10 Remote wake-up The Remote Wake-Up request (also known as Upstream Resume) is the only one the device may send on its own initiative, but the device should have beforehand been allowed to by a DEVICE_REMOTE_WAKEUP request from the host. * First, the USBC must have detected a "Suspend" state on the bus, i.e. the Remote Wake-Up request can only be sent after a SUSP interrupt has been set. * The user may then write a one to the Remote Wake-Up (RMWKUP) bit in UDCON to send an upstream resume to the host for a remote wake-up. This will automatically be done by the controller after 5ms of inactivity on the USB bus. * When the controller sends the upstream resume, the Upstream Resume (UPRSM) interrupt is set and SUSP is cleared. * RMWKUP is cleared at the end of the upstream resume. * If the controller detects a valid "End of Resume" signal from the host, the End of Resume (EORSM) interrupt is set. 32.7.2.11 RAM management The data of each endpoints can be physically allocated anywhere in the embedded ram. The USBC controller directly access to these endpoints through its HSB master (built-in DMA). The USBC controller reads the USBC descriptors to know the location of each endpoint. The base address of this USBC descriptor (UDESC) should be written by the user. The descriptors can also be allocated anywhere in the embedded RAM. Before using an endpoint, the user should write the endpoint address for each bank. Depending on the direction, the type and the packet-mode (single or multi-packet), the user should initialize the endpoint packet size and the endpoint control and status field, so that the usb controller does not compute random value from the RAM. When using an endpoint, the user should read the UESTAX.CURRBK field to know the current bank that should be processed. 877 32117A-10/2010 AT32UC3C Figure 32-12. Memory organization U S B B u ffe rs D a ta E p tn B K 1 D a ta E p tn B K 0 U S B d e s c r ip to r s R e s e rv e d Descriptor Epn B a n k 1 E P n _ C T R _ S T A _ B K 1 E P n _ P C K S IZ E _ B K 1 E P n _ A D D R _ B K 1 R e s e rv e d B a n k0 E P n _ C T R _ S T A _ B K 0 E P n _ P C K S IZ E _ B K 0 E P n _ A D D R _ B K 0 R e s e rv e d E P 1 _ C T R _ S T A _ B K 1 E P 1 _ P C K S IZ E _ B K 1 E P 1 _ A D D R _ B K 1 R e s e rv e d B a n k0 E P 1 _ C T R _ S T A _ B K 0 E P 1 _ P C K S IZ E _ B K 0 E P 1 _ A D D R _ B K 0 R e s e rv e d Descriptor Ep0 B a n k 1 E P 0 _ C T R _ S T A _ B K 1 E P 0 _ P C K S IZ E _ B K 1 E P 0 _ A D D R _ B K 1 R e s e rv e d B a n k0 E P 0 _ C T R _ S T A _ B K 0 E P 0 _ P C K S IZ E _ B K 0 E P 0 _ A D D R _ B K 0 + + + + + + + + + + + + + + + + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 x x x x x x x x x x x x x x x x 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 3 3 3 3 2 2 2 2 1 1 1 1 0 0 0 0 C 8 4 0 C 8 4 0 C 8 4 0 C 8 4 0 Growing Memory Addresses Descriptor Ep1 B a n k 1 U D E S C A Each descriptors of endpoint (n) consists of four words. * The address of endpoint n and bank 0/1 (EPn_ADDR_BK0/1) to indicate the address of the bank0/1 of the endpoint n. * The packet size information of endpoint n and bank 0/1 (EPn_PCKSIZE_BK0/1): Figure 32-13. EP0_PCKSIZE_BK0/1 structure: 31 AUTO_ZLP 30:16 MULTI_PACKET_SIZE 15 14:0 - BYTE_COUNT - AUTO ZLP: Auto zero length packet, see "Multi packet mode for IN endpoints" on page 884. - MULTI_PACKET_SIZE size: see "Multi packet mode and single packet mode." on page 880. - BYTE_COUNT: see"Multi packet mode and single packet mode." on page 880. 878 32117A-10/2010 AT32UC3C * The control and status of endpoint n and bank 0/1 (EPn_CTR_STA_BK0/1): Figure 32-14. EPn_CTR_STA_BK0/1 structure: 31:19 18 17 16 15:1 Status - UNDERF OVERF 0 Control CRCERR - STALLRQ_NEXT - UNDERF: Underflow status for isochronous IN transfer. See "Errorflow" on page 886. - OVERF: Overflow status for isochronous OUT transfer. See "Errorflow" on page 886. - CRCERR: CRC error status for isochronous OUT transfer. See "CRC error" on page 886. - STALLRQ_NEXT: Stall request for the next transfer. See "STALL request" on page 879. 32.7.2.12 STALL request For each endpoint, the STALL management is performed using: * The STALL Request (STALLRQ) bit in UECONn to initiate a STALL request. * The STALLed Interrupt (STALLEDI) bit in UESTAn is set when a STALL handshake has been sent. To answer the next request with a STALL handshake, STALLRQ has to be set by writing a one to the STALL Request Set (STALLRQS) bit. All following requests will be discarded (RXOUTI, etc. will not be set) and handshaked with a STALL until the STALLRQ bit is cleared, what is done when a new SETUP packet is received (for control endpoints) or when the STALL Request Clear (STALLRQC) bit is written to one. Each time a STALL handshake is sent, the STALLEDI bit is set by the USBC and the EPnINT interrupt is set. The user can also set the EPn_CTR_STA_BK0/1.STALLRQ_NEXT bit in the descriptor to prepare a STALL request for the next transaction once the descriptor is successfully completed. The USBC controller reads the EPn_CTR_STA_BK0/1.STALLRQ_NEXTafter a successful transaction. If set, the USBC controller sets the STALLRQ bit in UECONn register. Upon receiving a SETUP transaction, the EPn_CTR_STA_BK0/1.STALLRQ_NEXT is cleared by USBC and thus, the STALLRQ bit in UECONn register is not set. *Special considerations for control endpoints If a SETUP packet is received into a control endpoint for which a STALL is requested, the Received SETUP Interrupt (RXSTPI) bit in UESTAn is set and STALLRQ and STALLEDI are cleared. The SETUP has to be ACKed. This management simplifies the enumeration process management. If a command is not supported or contains an error, the user requests a STALL and can return to the main task, waiting for the next SETUP request. 879 32117A-10/2010 AT32UC3C *STALL handshake and retry mechanism The retry mechanism has priority over the STALL handshake. A STALL handshake is sent if the STALLRQ bit is set and if there is no retry required. 32.7.2.13 Multi packet mode and single packet mode. The multi-packet mode allows the user to manage data exceeding the maximum packet size (EPSIZE) for an endpoint bank across multiple packet without software intervention. This mode can also be coupled with the ping-pong mode. * For OUT endpoint, the EPn_PCKSIZE_BK0/1.MULTI_PACKET_SIZE field should be configured correctly to enable the multi-packet mode. See "Multi packet mode for OUT endpoints" on page 886. For single packet mode, the MULTI_PACKET_SIZE should be initialize to 0. * For IN endpoint, the EPn_PCKSIZE_BK0/1.BYTE_COUNT field should be configured correctly to enable the multi-packet mode. See"Multi packet mode for IN endpoints" on page 884. For single packet mode, the BYTE_COUNT should be inferior to the endpoint size (EPSIZE). 32.7.2.14 Management of control endpoints *Overview A SETUP request is always ACKed. When a new SETUP packet is received, the RXSTPI is set, but not the Received OUT Data Interrupt (RXOUTI) bit. The FIFO Control (FIFOCON) bit in UECONn is irrelevant for control endpoints. The user shall therefore never use it on these endpoints. When read, its value are always zero. Control endpoints are managed using: * The RXSTPI bit which is set when a new SETUP packet is received and which shall be cleared by firmware to acknowledge the packet and to free the bank. * The RXOUTI bit which is set when a new OUT packet is received and which shall be cleared by firmware to acknowledge the packet and to free the bank. * The Transmitted IN Data Interrupt (TXINI) bit which is set when the current bank is ready to accept a new IN packet and which shall be cleared by firmware to send the packet. *Control write Figure 32-15 on page 881 shows a control write transaction. During the status stage, the controller will not necessarily send a NAK on the first IN token: * If the user knows the exact number of descriptor bytes that must be read, it can then anticipate the status stage and send a zero-length packet after the next IN token. * Or it can read the bytes and wait for the NAKed IN Interrupt (NAKINI) which tells that all the bytes have been sent by the host and that the transaction is now in the status stage. 880 32117A-10/2010 AT32UC3C Figure 32-15. Control Write SETUP USB Bus DATA SETUP OUT STATUS OUT IN IN NAK RXSTPI HW SW RXOUTI HW SW HW SW TXINI SW *Control read Figure 32-16 on page 881 shows a control read transaction. The USBC has to manage the simultaneous write requests from the CPU and the USB host. Figure 32-16. Control Read SETUP USB Bus RXSTPI DATA SETUP IN STATUS IN OUT OUT NAK HW SW RXOUTI HW TXINI SW HW SW SW Wr Enable HOST Wr Enable CPU A NAK handshake is always generated on the first status stage command. When the controller detects the status stage, all the data written by the CPU are lost and clearing TXINI has no effect. The user checks if the transmission or the reception is complete. The OUT retry is always ACKed. This reception sets RXOUTI and TXINI. Handle this with the following software algorithm: set TXINI wait for RXOUTI OR TXINI if RXOUTI, then clear bit and return if TXINI, then continue Once the OUT status stage has been received, the USBC waits for a SETUP request. The SETUP request has priority over any other request and has to be ACKed. This means that any other bit should be cleared and the FIFO reset when a SETUP is received.Management of IN endpoints 881 32117A-10/2010 AT32UC3C 32.7.2.15 Management of IN endpoints *Overview IN packets are sent by the USBC device controller upon IN requests from the host. The endpoint and its descriptor in RAM must be configured first. The TXINI bit is set at the same time as FIFOCON when the current bank is free. This triggers an EPnINT interrupt if the Transmitted IN Data Interrupt Enable (TXINE) bit in UECONn is one. TXINI shall be cleared by software (by writing a one to the Transmitted IN Data Interrupt Enable Clear bit in the Endpoint n Control Clear register (UECONnCLR.TXINIC)) to acknowledge the interrupt, which has no effect on the endpoint FIFO. The user then writes into the Bank (at the location given by the EPn descriptor) and writes a one to the FIFO Control Clear (FIFOCONC) bit in UECONnCLR to clear the FIFOCON bit. This allows the USBC to send the data. If the IN endpoint is composed of multiple banks, this also switches to the next bank. The TXINI and FIFOCON bits are updated in accordance with the status of the next bank. TXINI shall always be cleared before clearing FIFOCON. Figure 32-17. Example of an IN endpoint with 1 Data Bank NAK IN DATA (bank 0) ACK IN HW TXINI SW SW write data to CPU BANK 0 FIFOCON write data to CPU BANK 0 SW SW Figure 32-18. Example of an IN endpoint with 2 Data Banks DATA (bank 0) IN ACK IN DATA (bank 1) ACK HW TXINI FIFOCON SW write data to CPU BANK 0 SW SW write data to CPU BANK 1 SW SW write data to CPU BANK0 882 32117A-10/2010 AT32UC3C *Detailed description Before using the IN endpoint, one should properly initialize its descriptor for each bank. See Figure 32-12 on page 878. The data is written, following the next flow: * When the bank is empty, TXINI and FIFOCON are set, what triggers an EPnINT interrupt if TXINE is one. * The user acknowledges the interrupt by clearing TXINI. * The user reads the UESTAX.CURRBK field to know the current bank number. * The user writes the data into the current bank directly into the embedded RAM at the location described in its descriptor: EPn_ADDR_BK0/1. * The user should write the size of the IN packet into the USB descriptor: EPn_PCKSIZE_BK0/1.BYTE_COUNT. * The user allows the controller to send the bank and switches to the next bank (if any) by clearing FIFOCON. If the endpoint uses several banks, the current one can be written while the previous one is being read by the host. Then, when the user clears FIFOCON, the following bank may already be free and TXINI is set immediately. An "Abort" stage can be produced when a zero-length OUT packet is received during an IN stage of a control or isochronous IN transaction. The Kill IN Bank (KILLBK) bit in UECONn is used to kill the last written bank. The best way to manage this abort is to apply the algorithm represented on Figure 32-19 on page 883. See "Endpoint n Control Register" on page 932 to have more details about the KILLBK bit. Figure 32-19. Abort Algorithm Endpoint Abort Disable the TXINI interrupt. TXINEC = 1 NBUSYBK == 0? Yes Abort is based on the fact that no bank is busy, i.e., that nothing has to be sent No EPRSTn = 1 KILLBKS = 1 Yes KILLBK == 1? Kill the last written bank. Wait for the end of the procedure No Abort Done 883 32117A-10/2010 AT32UC3C *Multi packet mode for IN endpoints In multi packet mode, the user can prepare n usb packet in the bank, to be sent on multiple IN transaction. The size of each packet will be equal to UECFGn.EPSIZE, except the last packet that should be a short packet if the total byte count is not an integral multiple of EPSIZE or if the AUTO_ZLP option is set. To enable the multi packet mode, the user should configured the endpoint descriptor (EPn_PCKSIZE_BK0/1.BYTE_COUNT) to the size of the multiple packet that should be superior to the endpoint size (EPSIZE). However, since the EPn_PCKSIZE_BK0/1.MULTI_PACKET_SIZE is incremented (by the transmitted packet size) after each successful transaction, it should be set to zero when setting a new multi packet transfer. The EPn_PCKSIZE_BK0/1.MULTI_PACKET_SIZE is cleared by hardware when the bank is completely sent. The, the bank is considered as "free" and the TX_IN flag is set if: * A short packet (inferior to EPSIZE) is transmitted. * A successful packet is transmitted and the updated MULTI_PACKET_SIZE is equal to BYTE_COUNT and the AUTO_ZLP field is not set. If BYTE_COUNT is an integral multiple of EPSIZE and AUTO_ZLP is set, then an extra zero length packet is automatically sent for the last transfer of the current bank. 32.7.2.16 Management of OUT endpoints *Overview OUT packets are sent by the host. All the data can be read which acknowledges or not the bank when it is empty. The endpoint and its descriptor in RAM must be configured first. The RXOUTI bit is set at the same time as FIFOCON when the current bank is full. This triggers an EPnINT interrupt if the Received OUT Data Interrupt Enable (RXOUTE) bit in UECONn is one. RXOUTI shall be cleared by software (by writing a one to the Received OUT Data Interrupt Clear (RXOUTIC) bit) to acknowledge the interrupt, what has no effect on the endpoint FIFO. The user then reads from the RAM and clears the FIFOCON bit to free the bank. If the OUT endpoint is composed of multiple banks, this also switches to the next bank. The RXOUTI and FIFOCON bits are updated in accordance with the status of the next bank. RXOUTI shall always be cleared before clearing FIFOCON. 884 32117A-10/2010 AT32UC3C Figure 32-20. Example of an OUT endpoint with one Data Bank OUT DATA (bank 0) NAK ACK OUT DATA (bank 0) ACK HW RXOUTI HW SW SW read data from CPU BANK 0 FIFOCON read data from CPU BANK 0 SW Figure 32-21. Example of an OUT endpoint with two Data Banks OUT DATA (bank 0) ACK OUT DATA (bank 1) HW RXOUTI ACK HW SW SW read data from CPU BANK 0 FIFOCON SW read data from CPU BANK 1 *Detailed description Before using the OUT endpoint, one should properly initialize its descriptor for each bank. See Figure 32-12 on page 878. The data is read, following the next flow: * When the bank is full, RXOUTI and FIFOCON are set, which triggers an EPnINT interrupt if RXOUTE is one. * The user acknowledges the interrupt by writing a one to RXOUTIC in order to clear RXOUTI. * The user reads the UESTAX.CURRBK field to know the current bank number. * The user reads the byte count of the current bank from the descriptor in RAM (EPn_PCKSIZE_BK0/1.BYTE_COUNT) to know how many bytes to read. * The user reads the data from the current bank from the embedded RAM at the location described in its descriptor: EPn_ADDR_BK0/1. * The user frees the bank and switches to the next bank (if any) by clearing FIFOCON. If the endpoint uses several banks, the current one can be read while the following one is being written by the host. Then, when the user clears FIFOCON, the following bank may already be ready and RXOUTI is set immediately. 885 32117A-10/2010 AT32UC3C *Multi packet mode for OUT endpoints In multi packet mode, the user can extend the size of the bank, to allow the storage of N usb packet in the bank. To enable the multi packet mode, the user should configured the endpoint descriptor (EP0_PCKSIZE_BK0/1.MULTI_PACKET_SIZE) to the size of the multiple packet.This value should be an integral multiple of the endpoint size (UECFGn.EPSIZE). However, since the EP0_PCKSIZE_BK0/1.BYTE_COUNT is incremented (by the received packet size) after each successful transaction, it should be set to zero when setting a new multi packet transfer. As for single packet mode, the number of received data bytes is stored in BYTE_CNT field. The bank is considered as "valid" and then the RX_OUT flag is set if: * A successful packet is received and the updated BYTE_COUNT is equal to MULTI_PACKET_SIZE. * A short packet (inferior to EPSIZE) is received. 32.7.2.17 Errorflow This error exists only for isochronous IN/OUT endpoints. It set the errorflow Interrupt (ERRORFI) bit in UESTAn, which triggers an EPnINT interrupt if the errorflow Interrupt Enable (ERRORFE) bit is one. The user can also check the endpoint descriptor to know the current bank impacted by the errorflow by reading the EPn_CTR_STA_BK0/1.UNDERF and OVERF bit. * An underflow can occur during IN stage if the host attempts to read from an empty bank. A zero-length packet is then automatically sent by the USBC. The endpoint descriptor EPn_CTR_STA_BK0/1.UNDERF is set for the bank where the IN data should have been come from. If a new successful transaction occurs, this UNDERF bit is overwritten to 0 only if the UESTAn.ERRORFI flag is cleared. * An overflow can occur during OUT stage if the host sends a packet while the bank is already full. Typically, the CPU is not fast enough. The packet is lost (is not written in the bank). The endpoint descriptor EPn_CTR_STA_BK0/1.OVERF is set for the bank where the OUT data should have been written. If a new successful transaction occurs, this bit is overwritten to 0 only if the UESTAn.ERRORFI is cleared. 32.7.2.18 CRC error This error exists only for isochronous OUT endpoints. It set the CRC Error Interrupt (CRCERRI) bit in UESTAn, what triggers an EPnINT interrupt if the CRC Error Interrupt Enable (CRCERRE) bit is one. A CRC error can occur during isochronous OUT stage if the USBC detects a corrupted received packet. The OUT packet is stored in the bank as if no CRC error had occurred (RXOUTI is set). The user can also check the endpoint descriptor to know the current bank impacted by the crc error by reading the EPn_CTR_STA_BK0/1.CRCERR. 32.7.2.19 Interrupts There are two kinds of device interrupts: processing, i.e. their generation is part of the normal processing, and exception, i.e. errors (not related to CPU exceptions). 886 32117A-10/2010 AT32UC3C *Global interrupts The processing device global interrupts are: * The Suspend (SUSP) interrupt * The Start of Frame (SOF) interrupt with no frame number CRC error (the Frame Number CRC Error (FNCERR) bit in the Device Frame Number (UDFNUM) register is zero) * The End of Reset (EORST) interrupt * The Wake-Up (WAKEUP) interrupt * The End of Resume (EORSM) interrupt * The Upstream Resume (UPRSM) interrupt * The Endpoint n (EPnINT) interrupt The exception device global interrupts are: * The Start of Frame (SOF) interrupt with a frame number CRC error (FNCERR is one) *Endpoint interrupts The processing device endpoint interrupts are: * The Transmitted IN Data Interrupt (TXINI) * The Received OUT Data Interrupt (RXOUTI) * The Received SETUP Interrupt (RXSTPI) * The Number of Busy Banks (NBUSYBK) interrupt The exception device endpoint interrupts are: * The Underflow Interrupt (ERRORFI) * The NAKed OUT Interrupt (NAKOUTI) * The NAKed IN Interrupt (NAKINI) * The STALLed Interrupt (STALLEDI) * The CRC Error Interrupt (CRCERRI) 887 32117A-10/2010 AT32UC3C 32.7.3 USB Host Operation 32.7.3.1 Description of pipes For the USBC in host mode, the term "pipe" is used instead of "endpoint" (used in device mode). A host pipe corresponds to a device endpoint, as described by the Figure 32-22 on page 888 from the USB specification. Figure 32-22. USB Communication Flow In host mode, the USBC associates a pipe to a device endpoint, considering the device configuration descriptors. 32.7.3.2 Power-On and reset Figure 32-23 on page 888 describes the USBC host mode main states. Figure 32-23. Host Mode States Device Disconnection Macro off Clock stopped Idle Device Connection Device Disconnection Ready SOFE = 0 SOFE = 1 Suspend After a hardware reset, the USBC host mode is in the Reset state. When the USBC is enabled (USBE is one) in host mode (ID is zero), its host mode state goes to the Idle state. In this state, the controller waits for device connection with minimal power con- 888 32117A-10/2010 AT32UC3C sumption. The USB pad should be in the Idle state. Once a device is connected, the macro enters the Ready state, what does not require the USB clock to be activated. The controller enters the Suspend state when the USB bus is in a "Suspend" state, i.e., when the host mode does not generate the "Start of Frame (SOF)". In this state, the USB consumption is minimal. The host mode exits the Suspend state when starting to generate the SOF over the USB line. 32.7.3.3 Device detection A device is detected by the USBC host mode when D+ or D- is no longer tied low, i.e., when the device D+ or D- pull-up resistor is connected. To enable this detection, the host controller has to provide the VBus power supply to the device by setting the VBUSRQ bit (by writing a one to the VBUSRQS bit). The device disconnection is detected by the host controller when both D+ and D- are pulled down. 32.7.3.4 USB reset The USBC sends a USB bus reset when the user write a one to the Send USB Reset bit in the Host General Control register (UHCON.RESET). The USB Reset Sent Interrupt bit in the Host Global Interrupt register (UHINT.RSTI) is set when the USB reset has been sent. In this case, all the pipes are disabled. If the bus was previously in a "Suspend" state (the Start of Frame Generation Enable (SOFE) bit in UHCON is zero), the USBC automatically switches it to the "Resume" state, the Host WakeUp Interrupt (HWUPI) bit in UHINT is set and the SOFE bit is set in order to generate SOFs immediately after the USB reset. 32.7.3.5 Pipe activation The pipe is maintained inactive and reset as long as it is disabled (PENn is zero). The context pipe is reset (UPCONn, UPSTAn, UPINRQn, UPCFGn). When starting an enumeration, the user gets the device descriptor by sending a GET_DESCRIPTOR USB request. This descriptor contains the maximal packet size of the device default control endpoint (bMaxPacketSize0) and the user re-configures the size of the default control pipe with its size parameter. 32.7.3.6 Address setup Once the device has answered the first host requests with the default device address 0, the host assigns a new address to the device. The host controller has to send an USB reset to the device and to send a SET_ADDRESS(addr) SETUP request with the new address to be used by the device. Once this SETUP transaction is over, the user writes the new address into the USB Host Address for pipe n field in the USB Host Descriptor table. All following requests of this pipe will be performed using this new address. 32.7.3.7 Remote wake-up The controller host mode enters the Suspend state when the UHCON.SOFE bit is written to zero. No more "Start of Frame" is sent on the USB bus and the USB device enters the Suspend state 3ms later. The device awakes the host by sending an Upstream Resume (Remote Wake-Up feature). When the host controller detects a non-idle state on the USB bus, it set the Host Wake-Up inter- 889 32117A-10/2010 AT32UC3C rupt (HWUPI) bit in UHINT. If the non-idle bus state corresponds to an Upstream Resume (K state), the Upstream Resume Received Interrupt (RXRSMI) bit in UHINT is set. The user has to generate a Downstream Resume within 1ms and for at least 20ms by writing a one to the Send USB Resume (RESUME) bit in UHCON. It is mandatory to write a one to UHCON.SOFE before writing a one to UHCON.RESUME to enter the Ready state, else UHCON.RESUME will have no effect. 32.7.3.8 RAM management The data of each pipe can be physically allocated anywhere in the embedded ram. The USBC controller directly access to these pipes through its HSB master (built-in DMA). The USBC controller reads the USBC descriptors to know the location of each pipe. The base address of this USBC descriptor (UDESC) should be written by the user. The descriptors can also be allocated anywhere in the embedded RAM. Before using a pipe, the user should write the data address for each bank. Depending on the direction, the pipe type, the targeted device address, the targeted endpoint number, and the packet-mode (single or multi-packet), the user should initialize the pipe packet size and the pipe control and status field, so that the usb controller does not compute random value from the RAM. When using a pipe, the user should read the UPSTAX.CURRBK field to know the current bank that should be processed. 890 32117A-10/2010 AT32UC3C Figure 32-24. Memory organization U S B B u ffe rs D a ta P n B K 1 D a ta P n B K 0 U S B d e s c r ip to r s R e s e rv e d Descriptor Pn B a n k 1 P n _ C T R _ S T A _ B K 1 P n _ P C K S IZ E _ B K 1 P n _ A D D R _ B K 1 P n _ C T R _ S T A 1 B a n k0 P n _ C T R _ S T A _ B K 0 P n _ P C K S IZ E _ B K 0 P n _ A D D R _ B K 0 R e s e rv e d P 1 _ C T R _ S T A _ B K 1 P 1 _ P C K S IZ E _ B K 1 P 1 _ A D D R _ B K 1 P 1 _ C T R _ S T A 1 B a n k0 P 1 _ C T R _ S T A _ B K 0 P 1 _ P C K S IZ E _ B K 0 P 1 _ A D D R _ B K 0 R e s e rv e d Descriptor P0 B a n k 1 P 0 _ C T R _ S T A _ B K 1 P 0 _ P C K S IZ E _ B K 1 P 0 _ A D D R _ B K 1 P 0 _ C T R _ S T A 1 B a n k0 P 0 _ C T R _ S T A _ B K 0 P 0 _ P C K S IZ E _ B K 0 P 0 _ A D D R _ B K 0 + + + + + + + + + + + + + + + + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 x x x x x x x x x x x x x x x x 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 3 3 3 3 2 2 2 2 1 1 1 1 0 0 0 0 C 8 4 0 C 8 4 0 C 8 4 0 C 8 4 0 Growing Memory Addresses Descriptor P1 B a n k 1 U D E S C A Each descriptors of pipe (n) consists of four words. * The address of pipe n and bank 0/1 (Pn_ADDR_BK0/1) to indicate the address of the bank0/1 of the endpoint n. * The packet size information of pipe n and bank 0/1 (Pn_PCKSIZE_BK0/1): Figure 32-25. P0_PCKSIZE_BK0/1 structure: 31 AUTO_ZLP 30:16 MULTI_PACKET_SIZE 15 14:0 - BYTE_COUNT - AUTO ZLP: Auto zero length packet, see "Multi packet mode for OUT pipes" on page 896. - MULTI_PACKET_SIZE size: see "Multi packet mode and single packet mode." on page 880. - BYTE_COUNT: see"Multi packet mode and single packet mode." on page 880. 891 32117A-10/2010 AT32UC3C * The control and status of endpoint n and bank 0/1 (Pn_CTR_STA_BK0/1): Figure 32-26. EPn_CTR_STA_BK0/1 structure: 31:19 18 17 16 15:0 Status - UNDERF Control OVERF CRCERR - - UNDERF: Underflow status for isochronous/Interrupt IN transfer. This status bit is set by hardware at the current bank (where the IN packet should have been stored). When a new successfull transaction occurs, this bit is overwritten to 0 only if the UPSTAX.ERRORFI flag is cleared by software. See "Errorflow" on page 896. - OVERF: Overflow status for isochronous/interrupt OUT transfer. This status bit is set by hardware at the current bank (where the OUT packet should have been come from). When a new successfull transaction occurs, this bit is overwritten to 0 only if the UPSTAX.ERRORFI flag is cleared by software. See "Errorflow" on page 896. - CRCERR: CRC error status for isochronous IN transfer. See "CRC error" on page 896. * The control and status 1 of endpoint n (Pn_CTR_STA1): Figure 32-27. EPn_CTR_STA1 structure: 31:24 23:16 15:12 Status - 11:8 7 6:0 Control PERSTA PERMAX PEPNUM - PDADDR - PERSTA: Pipe Error Status. - PERMAX: Should be set by the user. If the Pipe Error Counter (see Figure 32-28 on page 892) is superior to PERMAX, the UPSTAX.PERRI flag is set. - PEPNUM: Should be set by the user. Endpoint number of this pipe. - PDADDR : Should be set by the user. Device address of this pipe. Figure 32-28. PERSTA structure: 23:21 20 ERCNT CRC16ER 19 TOUTER 18 17 16 PIDER DAPIDER DTGLER This field can be cleared by software by the user. To avoid read-modify-write issue, the user should : freeze the pipe, wait until the UPSTAX.PFREEZE is one, clear the PERSTA field in memory, and then unfreeze the pipe. - ERCNT: Pipe Error Counter. - CRC16ER: Is set if a CRC16 error occurs during isochronous IN transaction. - TOUTER: Is set if a Timeout error occurs during usb transaction. - PIDER: Is set if a PID error occurs during usb transaction. - DAPIDER: Is set if a Data PID error occurs during usb transaction. 892 32117A-10/2010 AT32UC3C - DTGLER: Is set if a Data toggle error occurs during usb transaction. 32.7.3.9 Multi packet mode and single packet mode. See section Figure 32.7.2.13 on page 880 and just consider that OUT pipe corresponds to IN endpoint and IN pipe corresponds to OUT endpoint. 32.7.3.10 Management of control pipes A control transaction is composed of three stages: * SETUP * Data (IN or OUT) * Status (OUT or IN) The user has to change the pipe token according to each stage. For the control pipe, and only for it, each token is assigned a specific initial data toggle sequence: * SETUP: Data0 * IN: Data1 * OUT: Data1 32.7.3.11 Management of IN pipes *Overview IN packets are sent by the USB device controller upon IN requests from the host. All the data can be read which acknowledges or not the bank when it is empty. *Detailed description The pipe and its descriptor in RAM must be configured first. When the host requires data from the device, the user has to select beforehand the IN request mode with the IN Request Mode bit in the Pipe n IN Request register (UPINRQn.INMODE): * When INMODE is written to zero, the USBC will perform INRQ IN requests before freezing the pipe. * When INMODE is written to one, the USBC will perform IN requests endlessly when the pipe is not frozen by the user. The generation of IN requests starts when the pipe is unfrozen (the PFREEZE field in UPCONn is zero). The Received IN Data Interrupt (RXINI) bit in UPSTAn is set at the same time as the FIFO Control (FIFOCON) bit in UPCONn when the current bank is full. This triggers a PnINT interrupt if the Received IN Data Interrupt Enable (RXINE) bit in UPCONn is one. RXINI shall be cleared by software (by writing a one to the Received IN Data Interrupt Clear bit in the Pipe n Control Clear register(UPCONnCLR.RXINIC)) to acknowledge the interrupt, what has no effect on the pipe FIFO. The user reads the byte count of the current bank from the descriptor in RAM (Pn_PCKSIZE_BK0/1.BYTE_COUNT) to know how many bytes to read. 893 32117A-10/2010 AT32UC3C The user then reads from the RAM and clears the FIFOCON bit (by writing a one to the FIFO Control Clear (FIFOCONC) bit in UPCONnCLR) to free the bank. If the IN pipe is composed of multiple banks, this also switches to the next bank. The RXINI and FIFOCON bits are updated in accordance with the status of the next bank. RXINI shall always be cleared before clearing FIFOCON. Figure 32-29. Example of an IN pipe with 1 Data Bank IN DATA (bank 0) ACK IN DATA (bank 0) HW ACK HW SW RXINI SW read data from CPU BANK 0 FIFOCON read data from CPU BANK 0 SW Figure 32-30. Example of an IN pipe with 2 Data Banks IN DATA (bank 0) ACK IN DATA (bank 1) HW RXINI FIFOCON ACK HW SW SW read data from CPU BANK 0 SW read data from CPU BANK 1 *Multi packet mode for IN pipes See section "Multi packet mode for OUT endpoints" on page 886 and just replace OUT endpoints by IN pipe. 32.7.3.12 Management of OUT pipes *Overview OUT packets are sent by the host. All the data can be written which acknowledges or not the bank when it is full. *Detailed description The pipe and its descriptor in RAM must be configured first. 894 32117A-10/2010 AT32UC3C The Transmitted OUT Data Interrupt (TXOUTI) bit in UPSTAn is set at the same time as FIFOCON when the current bank is free. This triggers a PnINT interrupt if the Transmitted OUT Data Interrupt Enable (TXOUTE) bit in UPCONn is one. TXOUTI shall be cleared by software (by writing a one to the Transmitted OUT Data Interrupt Clear (TXOUTIC) bit in UPCONnCLR) to acknowledge the interrupt, what has no effect on the pipe FIFO. The user then writes into the Bank (at the location given by the PEPn descriptor), programs the number of data to send into the PEPn descriptor, and clears the FIFOCON bit to allow the USBC to send the data. If the OUT pipe is composed of multiple banks, this also switches to the next bank. The TXOUTI and FIFOCON bits are updated in accordance with the status of the next bank. TXOUTI shall always be cleared before clearing FIFOCON. Note that if the user decides to switch to the Suspend state (by writing a zero to the UHCON.SOFE bit) while a bank is ready to be sent, the USBC automatically exits this state and the bank is sent. Figure 32-31. Example of an OUT pipe with one Data Bank DATA (bank 0) OUT ACK OUT HW TXOUTI SW SW write data to CPU BANK 0 FIFOCON write data to CPU BANK 0 SW SW Figure 32-32. Example of an OUT pipe with two Data Banks and no Bank Switching Delay OUT DATA (bank 0) ACK OUT DATA (bank 1) ACK HW TXOUTI FIFOCON SW SW write data to CPU SW BANK 0 SW write data to CPU BANK 1 SW write data to CPU BANK0 895 32117A-10/2010 AT32UC3C Figure 32-33. Example of an OUT pipe with two Data Banks and a Bank Switching Delay OUT DATA (bank 0) ACK OUT DATA (bank 1) ACK HW TXOUTI SW FIFOCON SW write data to CPU BANK 0 SW SW write data to CPU BANK 1 SW write data to CPU BANK0 *Multi packet mode for OUT pipes See section "Multi packet mode for IN endpoints" on page 884 and just replace IN endpoints by OUT pipe. 32.7.3.13 Alternate pipe The user has the possibility to run sequentially several logical pipes on the same physical pipe. Before switching pipe, the user should save the pipe context (UPCFGn, UPCONn, UPSTAn and the pipe descritpor table). After switching pipe, the user should restore the pipe context (UPCFGn, UPCONn, UPSTAn and the pipe descriptor table). The user should also properly restore the current bank number and the current data toggle by using the UPCONn.INITDTGL and UPCONn.INITBK bit. 32.7.3.14 Errorflow This error exists only for isochronous and interrupt IN/OUT pipes. It set the errorflow Interrupt (ERRORFI) bit in UPSTAn, which triggers an PnINT interrupt if the errorflow Interrupt Enable (ERRORFE) bit is one. The user can also check the pipe descriptor to know the current bank impacted by the errorflow by reading the Pn_CTR_STA_BK0/1.UNDERF and OVERF bit. * An overflow can occur during OUT stage if the host attempts to send data from an empty bank. The pipe descriptor Pn_CTR_STA_BK0/1.OVERF is set for the bank where the OUT data should have been come from. If a new successful transaction occurs, this OVERF bit is overwritten to 0 only if the UPSTAn.ERRORFI flag is cleared. * An underflow can occur during IN stage if the device sends a packet while the bank is already full. Typically, the CPU is not fast enough. The packet is lost (is not written in the bank). The endpoint descriptor Pn_CTR_STA_BK0/1.UNDERF is set for the bank where the OUT data should have been written. If a new successful transaction occurs, this bit is overwritten to 0 only if the UESTAn.UNDERFI is cleared. 32.7.3.15 CRC error This error exists only for isochronous IN pipes. It set the CRC Error Interrupt (CRCERRI) bit, which triggers a PnINT interrupt if the CRC Error Interrupt Enable (CRCERRE) bit in UPCONn is one. 896 32117A-10/2010 AT32UC3C A CRC error can occur during IN stage if the USBC detects a corrupted received packet. The IN packet is stored in the bank as if no CRC error had occurred (RXINI is set). The user can also check the pipe descriptor to know the current bank impacted by the crc error by reading the Pn_CTR_STA_BK0/1.CRCERR. 32.7.3.16 Interrupts There are two kinds of host interrupts: processing, i.e. their generation is part of the normal processing, and exception, i.e. errors (not related to CPU exceptions). *Global interrupts The processing host global interrupts are: * The Device Connection Interrupt (DCONNI) * The Device Disconnection Interrupt (DDISCI) * The USB Reset Sent Interrupt (RSTI) * The Downstream Resume Sent Interrupt (RSMEDI) * The Upstream Resume Received Interrupt (RXRSMI) * The Host Start of Frame Interrupt (HSOFI) * The Host Wake-Up Interrupt (HWUPI) * The Pipe n Interrupt (PnINT) There is no exception host global interrupt. *Pipe interrupts The processing host pipe interrupts are: * The Received IN Data Interrupt (RXINI) * The Transmitted OUT Data Interrupt (TXOUTI) * The Transmitted SETUP Interrupt (TXSTPI) * The Number of Busy Banks (NBUSYBK) interrupt The exception host pipe interrupts are: * The Errorflow Interrupt (ERRORFI) * The Pipe Error Interrupt (PERRI) * The NAKed Interrupt (NAKEDI) * The Received STALLed Interrupt (RXSTALLDI) * The CRC Error Interrupt (CRCERRI) 897 32117A-10/2010 AT32UC3C 32.8 User Interface Table 32-4. USBC Register Memory Map Offset Register Name Access Reset Value 0x0000 Device General Control Register UDCON Read/Write 0x00000100 0x0004 Device Global Interrupt Register UDINT Read-Only 0x00000000 0x0008 Device Global Interrupt Clear Register UDINTCLR Write-Only 0x00000000 0x000C Device Global Interrupt Set Register UDINTSET Write-Only 0x00000000 0x0010 Device Global Interrupt Enable Register UDINTE Read-Only 0x00000000 0x0014 Device Global Interrupt Enable Clear Register UDINTECLR Write-Only 0x00000000 0x0018 Device Global Interrupt Enable Set Register UDINTESET Write-Only 0x00000000 0x001C Endpoint Enable/Reset Register UERST Read/Write 0x00000000 0x0020 Device Frame Number Register UDFNUM Read-Only 0x00000000 0x0100 + n*4 Endpoint n Configuration Register UECFGn Read/Write 0x00000000 0x0130 + n*4 Endpoint n Status Register UESTAn Read-Only 0x00000100 0x0160 + n*4 Endpoint nStatus Clear Register UESTAnCLR Write-Only 0x00000000 0x0190 + n*4 Endpoint nStatus Set Register UESTAnSET Write-Only 0x00000000 0x01C0 + n*4 Endpoint nControl Register UECONn Read-Only 0x00000000 0x01F0 + n*4 Endpoint nControl Set Register UECONnSET Write-Only 0x00000000 0x0220 + n*4 Endpoint n Control Clear Register UECONnCLR Write-Only 0x00000000 0x0400 Host General Control Register UHCON Read/Write 0x00000000 0x0404 Host Global Interrupt Register UHINT Read-Only 0x00000000 0x0408 Host Global Interrupt Clear Register UHINTCLR Write-Only 0x00000000 0x040C Host Global Interrupt Set Register UHINTSET Write-Only 0x00000000 0x0410 Host Global Interrupt Enable Register UHINTE Read-Only 0x00000000 0x0414 Host Global Interrupt Enable Clear Register UHINTECLR Write-Only 0x00000000 0x0418 Host Global Interrupt Enable Set Register UHINTESET Write-Only 0x00000000 0x0041C Pipe Enable/Reset Register UPRST Read/Write 0x00000000 0x0420 Host Frame Number Register UHFNUM Read/Write 0x00000000 0x0500 + n*4 Pipe n Configuration Register UPCFGn Read/Write 0x00000000 0x0530 + n*4 Pipe nStatus Register UPSTAn Read-Only 0x00000000 0x0560 + n*4 Pipe n Status Clear Register UPSTAnCLR Write-Only 0x00000000 0x0590 + n*4 Pipe n Status Set Register UPSTAnSET Write-Only 0x00000000 0x05C0 + n*4 Pipe n Control Register UPCONn Read-Only 0x00000000 0x05F0 +n*4 Pipe nControl Set Register UPCONnSET Write-Only 0x00000000 0x0620 + n*4 Pipe n Control Clear Register UPCONnCLR Write-Only 0x00000000 0x0650 + n*4 Pipe n IN Request Register UPINRQn Read/Write 0x00000001 0x0800 General Control Register USBCON Read/Write 0x03004000 0x0804 General Status Register USBSTA Read-Only 0x00000000 898 32117A-10/2010 AT32UC3C Table 32-4. Note: USBC Register Memory Map Offset Register Name Access Reset Value 0x0808 General Status Clear Register USBSTACLR Write-Only 0x00000000 0x080C General Status Set Register USBSTASET Write-Only 0x00000000 0x0818 IP Version Register UVERS Read-Only -(1) 0x081C IP Features Register UFEATURES Read-Only -(1) 0x0820 IP PB Address Size Register UADDRSIZE Read-Only -(1) 0x0824 IP Name Register 1 UNAME1 Read-Only -(1) 0x0828 IP Name Register 2 UNAME2 Read-Only -(1) 0x082C USB Finite State Machine Status Register USBFSM Read-Only 0x00000009 0x0830 USB Descriptor address UDESC Read/Write 0x00000000 1. The reset values are device specific. Please refer to the Module Configuration section at the end of this chapter. 899 32117A-10/2010 AT32UC3C 32.8.1 USB General Registers 32.8.1.1 Name: General Control Register USBCON Access Type: Read/Write Offset: 0x0800 Reset Value: 0x03004000 31 30 29 28 27 26 25 24 - - - - - - UIMOD UIDE 23 22 21 20 19 18 17 16 - UNLOCK - - 15 14 13 12 11 10 9 8 USBE FRZCLK VBUSPO OTGPADE HNPREQ SRPREQ SRPSEL VBUSHWC 7 6 5 4 3 2 1 0 STOE HNPERRE ROLEEXE BCERRE VBERRE SRPE VBUSTE IDTE TIMPAGE TIMVALUE * UIMOD: USBC Mode This bit has no effect when UIDE is one (USB_ID input pin activated). 0: The module is in USB host mode. 1: The module is in USB device mode. This bit can be written even if USBE is zero or FRZCLK is one. Disabling the USBC (by writing a zero to the USBE bit) does not reset this bit. * UIDE: USB_ID Pin Enable 0: The USB mode (device/host) is selected from the UIMOD bit. 1: The USB mode (device/host) is selected from the USB_ID input pin. This bit can be written even if USBE is zero or FRZCLK is one. Disabling the USBC (by writing a zero to the USBE bit) does not reset this bit. * UNLOCK: Timer Access Unlock 1: The TIMPAGE and TIMVALUE fields are unlocked. 0: The TIMPAGE and TIMVALUE fields are locked. The TIMPAGE and TIMVALUE fields can always be read, whatever the value of UNLOCK. * TIMPAGE: Timer Page This field contains the page value to access a special timer register. * TIMVALUE: Timer Value This field selects the timer value that is written to the special time register selected by TIMPAGE. See Section 32.7.1.8 for details. * USBE: USBC Enable Writing a zero to this bit will reset the USBC, disable the USB transceiver and, disable the USBC clock inputs. Unless explicitly stated, all registers then will become read-only and will be reset. 1: The USBC is enabled. 0: The USBC is disabled. 900 32117A-10/2010 AT32UC3C This bit can be written even if FRZCLK is one. * FRZCLK: Freeze USB Clock 1: The clock input are disabled (the resume detection is still active).This reduces power consumption. Unless explicitly stated, all registers then become read-only. 0: The clock inputs are enabled. This bit can be written even if USBE is zero. Disabling the USBC (by writing a zero to the USBE bit) does not reset this bit, but this freezes the clock inputs whatever its value. * VBUSPO: VBus Polarity 1: The USB_VBOF output signal is inverted (active low). 0: The USB_VBOF output signal is in its default mode (active high). To be generic. May be useful to control an external VBus power module. This bit can be written even if USBE is zero or FRZCLK is one. Disabling the USBC (by writing a zero to the USBE bit) does not reset this bit. * OTGPADE: OTG Pad Enable 1: The OTG pad is enabled. 0: The OTG pad is disabled. This bit can be written even if USBE is zero or FRZCLK is one. Disabling the USBC (by writing a zero to the USBE bit) does not reset this bit. * HNPREQ: HNP Request When the controller is in device mode: Writing a one to this bit will initiate a HNP (Host Negotiation Protocol). Writing a zero to this bit has no effect. This bit is cleared when the controller has initiated an HNP. * * * * * * * * When the controller is in host mode: Writing a one to this bit will accept a HNP. Writing a zero to this bit will reject a HNP. SRPREQ: SRP Request Writing a one to this bit will initiate an SRP when the controller is in device mode. Writing a zero to this bit has no effect. This bit is cleared when the controller has initiated an SRP. SRPSEL: SRP Selection 1: VBus pulsing is selected as SRP method. 0: Data line pulsing is selected as SRP method. VBUSHWC: VBus Hardware Control 1: The hardware control over the USB_VBOF output pin is disabled. 0: The hardware control over the USB_VBOF output pin is enabled. The USBC resets the USB_VBOF output pin when a VBUS problem occurs. STOE: Suspend Time-Out Interrupt Enable 1: The Suspend Time-Out Interrupt (STOI) is enabled. 0: The Suspend Time-Out Interrupt (STOI) is disabled. HNPERRE: HNP Error Interrupt Enable 1: The HNP Error Interrupt (HNPERRI) is enabled. 0: The HNP Error Interrupt (HNPERRI) is disabled. ROLEEXE: Role Exchange Interrupt Enable 1: The Role Exchange Interrupt (ROLEEXI) is enabled. 0: The Role Exchange Interrupt (ROLEEXI) is disabled. BCERRE: B-Connection Error Interrupt Enable 1: The B-Connection Error Interrupt (BCERRI) is enabled. 0: The B-Connection Error Interrupt (BCERRI) is disabled. VBERRE: VBus Error Interrupt Enable 1: The VBus Error Interrupt (VBERRI) is enabled. 901 32117A-10/2010 AT32UC3C 0: The VBus Error Interrupt (VBERRI) is disabled. * SRPE: SRP Interrupt Enable 1: The SRP Interrupt (SRPI) is enabled. 0: The SRP Interrupt (SRPI) is disabled. * VBUSTE: VBus Transition Interrupt Enable 1: The VBus Transition Interrupt (VBUSTI) is enabled. 0: The VBus Transition Interrupt (VBUSTI) is disabled. * IDTE: ID Transition Interrupt Enable 1: The ID Transition interrupt (IDTI) is enabled. 0: The ID Transition interrupt (IDTI) is disabled. 902 32117A-10/2010 AT32UC3C 32.8.1.2 General Status Register Register Name: USBSTA Access Type: Read-Only Offset: 0x0804 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 - CLKUSABLE VBUS ID VBUSRQ - 7 6 5 4 3 2 1 0 STOI HNPERRI ROLEEXI BCERRI VBERRI SRPI VBUSTI IDTI SPEED * CLKUSABLE: Generic Clock Usable This bit is set when the usb generic clock (that should be 48 Mhz) is usable. This bit is cleared when the usb generic clock is not usable. * SPEED: Speed Status This field is set according to the controller speed mode. This field shall only be used in device mode. SPEED Speed Status 0 0 full-speed mode 1 0 low-speed mode X 1 Reserved * VBUS: VBus Level This bit is set when the VBus line level is high, even if USBE is zero. This bit is cleared when the VBus line level is low, even if USBE is zero. This bit can be used in device mode to monitor the USB bus connection state of the application. * ID: USB_ID Pin State This bit is cleared when the USB_ID level is low, even if USBE is zero. This bit is set when the USB_ID level is high, event if USBE is zero. * VBUSRQ: VBus Request This bit is set when the USBSTASET.VBUSRQS bit is written to one. This bit is cleared when the USBSTACLR.VBUSRQC bit is written to one or when a VBus error occurs and VBUSHWC is zero. 1: The USB_VBOF output pin is driven high to enable the VBUS power supply generation. 0: The USB_VBOF output pin is driven low to disable the VBUS power supply generation. This bit shall only be used in host mode. 903 32117A-10/2010 AT32UC3C * STOI: Suspend Time-Out Interrupt This bit is set when a time-out error (more than 200ms) has been detected after a suspend. This triggers a USB interrupt if STOE is one. This bit is cleared when the UBSTACLR.STOIC bit is written to one. This bit shall only be used in host mode. * HNPERRI: HNP Error Interrupt This bit is set when an error has been detected during a HNP negotiation. This triggers a USB interrupt if HNPERRE is one. This bit is cleared when the UBSTACLR.HNPERRIC bit is written to one. This bit shall only be used in device mode. * ROLEEXI: Role Exchange Interrupt This bit is set when the USBC has successfully switched its mode because of an HNP negotiation (host to device or device to host). This triggers a USB interrupt if ROLEEXE is one. This bit is cleared when the UBSTACLR.ROLEEXIC bit is written to one. * BCERRI: B-Connection Error Interrupt This bit is set when an error occurs during the B-connection. This triggers a USB interrupt if BCERRE is one. This bit is cleared when the UBSTACLR.BCERRIC bit is written to one. This bit shall only be used in host mode. * VBERRI: VBus Error Interrupt This bit is set when a VBus drop has been detected. This triggers a USB interrupt if VBERRE is one. This bit is cleared when the UBSTACLR.VBERRIC bit is written to one. This bit shall only be used in host mode. If a VBus problem occurs, then the VBERRI interrupt is generated even if the USBC does not go to an error state because of VBUSHWC is one. * SRPI: SRP Interrupt This bit is set when an SRP has been detected. This triggers a USB interrupt if SRPE is one. This bit is cleared when the UBSTACLR.SRPIC bit is written to one. This bit shall only be used in host mode. * VBUSTI: VBus Transition Interrupt This bit is set when a transition (high to low, low to high) has been detected on the USB_VBUS pad. This triggers an USB interrupt if VBUSTE is one. This bit is cleared when the UBSTACLR.VBUSTIC bit is written to one. This interrupt is generated even if the clock is frozen by the FRZCLK bit. * IDTI: ID Transition Interrupt This bit is set when a transition (high to low, low to high) has been detected on the USB_ID input pin. This triggers an USB interrupt if IDTE is one. This bit is cleared when the UBSTACLR.IDTIC bit is written to one. This interrupt is generated even if the clock is frozen by the FRZCLK bit. 904 32117A-10/2010 AT32UC3C 32.8.1.3 General Status Clear Register Register Name: USBSTACLR Access Type: Write-Only Offset: 0x0808 Read Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 - - - - - - VBUSRQC - 7 6 5 4 3 2 1 0 STOIC HNPERRIC ROLEEXIC BCERRIC VBERRIC SRPIC VBUSTIC IDTIC Writing a one to a bit in this register will clear the corresponding bit in UBSTA. Writing a zero to a bit in this register has no effect. This bit always reads as zero. 905 32117A-10/2010 AT32UC3C 32.8.1.4 General Status Set Register Register Name: USBSTASET Access Type: Write-Only Offset: 0x080C Read Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 - - - - - - VBUSRQS - 7 6 5 4 3 2 1 0 STOIS HNPERRIS ROLEEXIS BCERRIS VBERRIS SRPIS VBUSTIS IDTIS Writing a one to a bit in this register will set the corresponding bit in UBSTA, what may be useful for test or debug purposes. Writing a zero to a bit in this register has no effect. This bit always reads as zero. 906 32117A-10/2010 AT32UC3C 32.8.1.5 Version Register Register Name: UVERS Access Type: Read-Only Offset: 0x0818 Read Value: - 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - 15 14 13 12 9 8 - - - - 7 6 5 4 VARIANT 11 10 VERSION[11:8] 3 2 1 0 VERSION[7:0] * VARIANT: Variant Number Reserved. No functionality associated. * VERSION: Version Number Version number of the module. No functionality associated. 907 32117A-10/2010 AT32UC3C 32.8.1.6 Features Register Register Name: UFEATURES Access Type: Read-Only Offset: 0x081C Read Value: - 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 - - - - - - - - 7 6 5 4 3 2 1 0 - - - - EPTNBRMAX * EPTNBRMAX: Maximal Number of pipes/endpoints This field indicates the number of hardware-implemented pipes/endpoints: 908 32117A-10/2010 AT32UC3C 32.8.1.7 Address Size Register Register Name: UADDRSIZE Access Type: Read-Only Offset: 0x0820 Read Value: - 31 30 29 28 27 26 25 24 18 17 16 10 9 8 2 1 0 UADDRSIZE[31:24] 23 22 21 20 19 UADDRSIZE[23:16] 15 14 13 12 11 UADDRSIZE[15:8] 7 6 5 4 3 UADDRSIZE[7:0] * UADDRSIZE: IP PB Address Size This field indicates the size of the PB address space reserved for the USBC IP interface. 909 32117A-10/2010 AT32UC3C 32.8.1.8 Name Register 1 Register Name: UNAME1 Access Type: Read-Only Offset: 0x0824 Read Value: - 31 30 29 28 27 26 25 24 18 17 16 10 9 8 2 1 0 UNAME1[31:24] 23 22 21 20 19 UNAME1[23:16] 15 14 13 12 11 UNAME1[15:8] 7 6 5 4 3 UNAME1[7:0] * UNAME1: IP Name Part One This field indicates the first part of the ASCII-encoded name of the USBC IP. 910 32117A-10/2010 AT32UC3C 32.8.1.9 Name Register 2 Register Name: UNAME2 Access Type: Read-Only Offset: 0x0828 Read Value: 31 30 29 28 27 26 25 24 18 17 16 10 9 8 2 1 0 UNAME2[31:24] 23 22 21 20 19 UNAME2[23:16] 15 14 13 12 11 UNAME2[15:8] 7 6 5 4 3 UNAME2[7:0] * UNAME2: IP Name Part Two This field indicates the second part of the ASCII-encoded name of the USBC IP. 911 32117A-10/2010 AT32UC3C 32.8.1.10 Finite State Machine Status Register Register Name: USBFSM Access Type: Read-Only Offset: 0x082C Read Value: 0x00000009 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 - - - - - - - - 7 6 5 4 3 2 1 0 - - - - DRDSTATE * DRDSTATE: Dual Role Device State This field indicates the state of the USBC. DRDSTATE Description 0 a_idle state: this is the start state for A-devices (when the ID pin is 0) 1 a_wait_vrise: In this state, the A-device waits for the voltage on VBus to rise above the Adevice VBus Valid threshold (4.4 V). 2 a_wait_bcon: In this state, the A-device waits for the B-device to signal a connection. 3 a_host: In this state, the A-device that operates in Host mode is operational. 4 a_suspend: The A-device operating as a host is in the suspend mode. 5 a_peripheral: The A-device operates as a peripheral. 6 a_wait_vfall: In this state, the A-device waits for the voltage on VBus to drop below the Adevice Session Valid threshold (1.4 V). 7 a_vbus_err: In this state, the A-device waits for recovery of the over-current condition that caused it to enter this state. 8 a_wait_discharge: In this state, the A-device waits for the data usb line to discharge (100 us). 9 b_idle: this is the start state for B-device (when the ID pin is 1). The USBC controller operates in device mode. 10 b_peripheral: In this state, the B-device acts as the peripheral. 11 b_wait_begin_hnp: In this state, the B-device is in suspend mode and waits until 3 ms before initiating the HNP protocol if requested. 912 32117A-10/2010 AT32UC3C DRDSTATE Description 12 b_wait_discharge: In this state, the B-device waits for the data usb line to discharge (100 us) before becoming Host. 13 b_wait_acon: In this state, the B-device waits for the A-device to signal a connect before becoming B-Host. 14 b_host: In this state, the B-device acts as the Host. 15 b_srp_init: In this state, the B-device attempts to start a session using the SRP protocol. 913 32117A-10/2010 AT32UC3C 32.8.1.11 USB Descriptor Address Register Name: UDESC Access Type: Read-Write Offset: 0x0830 Read Value: - 31 30 29 28 27 26 25 24 18 17 16 10 9 8 2 1 0 UDESCA[31:24] 23 22 21 20 19 UDESCA[23:16] 15 14 13 12 11 UDESCA[15:8] 7 6 5 4 3 UDESCA[7:0] * UDESCA: USB Descriptor Address This field contains the address of the usb descriptor. The 3 less significant bits are always 0. 914 32117A-10/2010 AT32UC3C 32.8.2 USB Device Registers 32.8.2.1 Device General Control Register Register Name: UDCON Access Type: Read/Write Offset: 0x0000 Reset Value: 0x00000100 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - GNAK - 15 14 13 12 11 10 9 8 - - - LS - - RMWKUP DETACH 7 6 5 4 3 2 1 0 ADDEN UADD * GNAK: Global NAK 1: A NAK handshake is sent for each transaction whatever is the bank status of the current endpoint. 0: Normal mode. * LS: low-speed Mode Force 1: The low-speed mode is active. 0: The full-speed mode is active. This bit can be written even if USBE is zero or FRZCLK is one. Disabling the USBC (by writing a zero to the USBE bit) does not reset this bit. * RMWKUP: Remote Wake-Up Writing a one to this bit will send an upstream resume to the host for a remote wake-up. Writing a zero to this bit has no effect. This bit is cleared when the USBC receive a USB reset or once the upstream resume has been sent. * DETACH: Detach Writing a one to this bit will physically detach the device (disconnect internal pull-up resistor from D+ and D-). Writing a zero to this bit will reconnect the device. * ADDEN: Address Enable Writing a one to this bit will activate the UADD field (USB address). Writing a zero to this bit has no effect. This bit is cleared when a USB reset is received. * UADD: USB Address This field contains the device address. This field is cleared when a USB reset is received. 915 32117A-10/2010 AT32UC3C 32.8.2.2 Device Global Interrupt Register Register Name: UDINT Access Type: Read-Only Offset: 0x0004 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 18 (1) EP7INT EP6INT 17 (1) EP5INT 16 (1) EP4INT(1) - - - 15 14 13 12 11 10 9 8 EP3INT(1) EP2INT(1) EP1INT(1) EP0INT - - - - 7 6 5 4 3 2 1 0 - UPRSM EORSM WAKEUP EORST SOF - SUSP Note: EP8INT 19 (1) 1. EPnINT bits are within the range from EP0INT to EP6INT. * EPnINT: Endpoint n Interrupt This bit is set when an interrupt is triggered by the endpoint n (UESTAn, UECONn). This triggers a USB interrupt if EPnINTE is one. This bit is cleared when the interrupt source is serviced. * UPRSM: Upstream Resume Interrupt This bit is set when the USBC sends a resume signal called "Upstream Resume". This triggers a USB interrupt if UPRSME is one. This bit is cleared when the UDINTCLR.UPRSMC bit is written to one to acknowledge the interrupt (USB clock inputs must be enabled before). * EORSM: End of Resume Interrupt This bit is set when the USBC detects a valid "End of Resume" signal initiated by the host. This triggers a USB interrupt if EORSME is one. This bit is cleared when the UDINTCLR.EORSMC bit is written to one to acknowledge the interrupt. * WAKEUP: Wake-Up Interrupt This bit is set when the USBC is reactivated by a filtered non-idle signal from the lines (not by an upstream resume). This triggers an interrupt if WAKEUPE is one. This bit is cleared when the UDINTCLR.WAKEUPC bit is written to one to acknowledge the interrupt (USB clock inputs must be enabled before). This bit is cleared when the Suspend (SUSP) interrupt bit is set. This interrupt is generated even if the clock is frozen by the FRZCLK bit. * EORST: End of Reset Interrupt This bit is set when a USB "End of Reset" has been detected. This triggers a USB interrupt if EORSTE is one. This bit is cleared when the UDINTCLR.EORSTC bit is written to one to acknowledge the interrupt. 916 32117A-10/2010 AT32UC3C * SOF: Start of Frame Interrupt This bit is set when a USB "Start of Frame" PID (SOF) has been detected (every 1 ms). This triggers a USB interrupt if SOFE is one. The FNUM field is updated. This bit is cleared when the UDINTCLR.SOFC bit is written to one to acknowledge the interrupt. * SUSP: Suspend Interrupt This bit is set when a USB "Suspend" idle bus state has been detected for 3 frame periods (J state for 3 ms). This triggers a USB interrupt if SUSPE is one. This bit is cleared when the UDINTCLR.SUSPC bit is written to one to acknowledge the interrupt. This bit is cleared when the Wake-Up (WAKEUP) interrupt bit is set. 917 32117A-10/2010 AT32UC3C 32.8.2.3 Device Global Interrupt Clear Register Register Name: UDINTCLR Access Type: Write-Only Offset: 0x0008 Read Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 - - - - - - - - 7 6 5 4 3 2 1 0 - UPRSMC EORSMC WAKEUPC EORSTC SOFC - SUSPC Writing a one to a bit in this register will clear the corresponding bit in UDINT. Writing a zero to a bit in this register has no effect. This bit always reads as zero. 918 32117A-10/2010 AT32UC3C 32.8.2.4 Device Global Interrupt Set Register Register Name: UDINTSET Access Type: Write-Only Offset: 0x000C Read Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 - - - - - - - - 7 6 5 4 3 2 1 0 - UPRSMS EORSMS WAKEUPS EORSTS SOFS - SUSPS Writing a one to a bit in this register will set the corresponding bit in UDINT, what may be useful for test or debug purposes. Writing a zero to a bit in this register has no effect. This bit always reads as zero. 919 32117A-10/2010 AT32UC3C 32.8.2.5 Device Global Interrupt Enable Register Register Name: UDINTE Access Type: Read-Only Offset: 0x0010 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 (1) EP8INTE EP7INTE 18 (1) 17 (1) EP6INTE 16 (1) EP5INTE EP4INTE(1) - - - 15 14 13 12 11 10 9 8 EP3INTE(1) EP2INTE(1) EP1INTE(1) EP0INTE - - - - 7 6 5 4 3 2 1 0 - UPRSME EORSME WAKEUPE EORSTE SOFE - SUSPE 1: The corresponding interrupt is enabled. 0: The corresponding interrupt is disabled. A bit in this register is set when the corresponding bit in UDINTESET is written to one. A bit in this register is cleared when the corresponding bit in UDINTECLR is written to one. Note: 1. EPnINTE bits are within the range from EP0INTE to EP6INTE. 920 32117A-10/2010 AT32UC3C 32.8.2.6 Device Global Interrupt Enable Clear Register Register Name: UDINTECLR Access Type: Write-Only Offset: 0x0014 Read Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 (1) EP8INTEC 18 (1) EP7INTEC 17 (1) EP6INTEC EP5INTEC 16 (1) EP4INTEC(1) - - - 15 14 13 12 11 10 9 8 EP3INTEC(1) EP2INTEC(1) EP1INTEC(1) EP0INTEC - - - - 7 6 5 4 3 2 1 0 - UPRSMEC EORSMEC WAKEUPEC EORSTEC SOFEC - SUSPEC Writing a one to a bit in this register will clear the corresponding bit in UDINTE. Writing a zero to a bit in this register has no effect. This bit always reads as zero. Note: 1. EPnINTEC bits are within the range from EP0INTEC to EP6INTEC. 921 32117A-10/2010 AT32UC3C 32.8.2.7 Device Global Interrupt Enable Set Register Register Name: UDINTESET Access Type: Write-Only Offset: 0x0018 Read Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 (1) EP8INTES 18 (1) EP7INTES 17 (1) EP6INTES 16 (1) EP5INTES EP4INTES(1) - - - 15 14 13 12 11 10 9 8 EP3INTES(1) EP2INTES(1) EP1INTES(1) EP0INTES - - - - 7 6 5 4 3 2 1 0 - UPRSMES EORSMES WAKEUPES EORSTES SOFES - SUSPES Writing a one to a bit in this register will set the corresponding bit in UDINTE. Writing a zero to a bit in this register has no effect. This bit always reads as zero. Note: 1. EPnINTES bits are within the range from EP0INTES to EP6INTES. 922 32117A-10/2010 AT32UC3C 32.8.2.8 Endpoint Enable/Reset Register Register Name: UERST Access Type: Read/Write Offset: 0x001C Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 - - - - - - - EPEN8(1) 7 6 5 4 3 2 1 0 EPEN7(1) EPEN6(1) EPEN5(1) EPEN4(1) EPEN3(1) EPEN2(1) EPEN1(1) EPEN0 * EPENn: Endpoint n Enable 1: The endpoint n is enabled. 0: The endpoint n is disabled, what forces the endpoint n state to inactive (no answer to USB requests) and resets the endpoint n registers (UECFGn, UESTAn, UECONn) but not the endpoint configuration (EPBK, EPSIZE, EPDIR, EPTYPE). Note: 1. EPENn bits are within the range from EPEN0 to EPEN6. 923 32117A-10/2010 AT32UC3C 32.8.2.9 Device Frame Number Register Register Name: UDFNUM Access Type: Read-Only Offset: 0x0020 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 FNCERR - 7 6 2 1 0 - - - FNUM[10:5] 5 FNUM[4:0] 4 3 * FNCERR: Frame Number CRC Error This bit is set when a corrupted frame number is received. This bit and the SOF interrupt bit are updated at the same time. This bit is cleared upon receiving a USB reset. * FNUM: Frame Number This field contains the 11-bit frame number information. It is provided in the last received SOF packet. This field is cleared upon receiving a USB reset. FNUM is updated even if a corrupted SOF is received. 924 32117A-10/2010 AT32UC3C 32.8.2.10 Endpoint n Configuration Register Register Name: UECFGn, n in [0..6] Access Type: Read/Write Offset: 0x0100 + (n * 0x04) Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 - - - - - EPDIR 7 6 5 3 2 1 0 - EPBK - - - EPTYPE 4 EPSIZE * EPTYPE: Endpoint Type This field shall be written to select the endpoint type: EPTYPE Endpoint Type 0 0 Control 0 1 Isochronous 1 0 Bulk 1 1 Interrupt This field is cleared upon receiving a USB reset. * EPDIR: Endpoint Direction This bit is cleared upon receiving a USB reset. 1: The endpoint direction is IN (nor for control endpoints). 0: The endpoint direction is OUT. * EPSIZE: Endpoint Size This field shall be written to select the size of each endpoint bank: EPSIZE Endpoint Size 0 0 0 8 bytes 0 0 1 16 bytes 0 1 0 32 bytes 0 1 1 64 bytes 925 32117A-10/2010 AT32UC3C EPSIZE Endpoint Size 1 0 0 128 bytes 1 0 1 256 bytes 1 1 0 512 bytes 1 1 1 1024 bytes This field is cleared upon receiving a USB reset (except for the endpoint 0). * EPBK: Endpoint Banks This field shall be written to select the number of banks for the endpoint: EPBK Endpoint Banks 0 1 (single-bank endpoint) 1 2 (double-bank endpoint) For control endpoints, a single-bank endpoint (0) shall be selected. This field is cleared upon receiving a USB reset (except for the endpoint 0). 926 32117A-10/2010 AT32UC3C 32.8.2.11 Endpoint n Status Register Register Name: UESTAn, n in [0..6] Access Type: Read-Only 0x0100 Offset: 0x0130 + (n * 0x04) Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - CTRLDIR - 15 14 13 12 11 10 9 8 RAMACERI - CURRBK NBUSYBK DTSEQ 7 6 5 4 3 2 1 0 - STALLEDI/ CRCERRI - NAKINI NAKOUTI RXSTPI/ ERRORFI RXOUTI TXINI * CTRLDIR: Control Direction This bit is set after a SETUP packet to indicate that the following packet is an IN packet. This bit is cleared after a SETUP packet to indicate that the following packet is an OUT packet. Writing a zero or a one to this bit has no effect. * CURRBK: Current Bank This bit is set for non-control endpoints, to indicate the current bank: CURRBK Current Bank 0 0 Bank0 0 1 Bank1 1 0 Reserved 1 1 Reserved This field may be updated one clock cycle after the RWALL bit changes, so the user should not poll this field as an interrupt bit. * NBUSYBK: Number of Busy Banks This field is set to indicate the number of busy banks: NBUSYBK Number of Busy Banks 0 0 0 (all banks free) 0 1 1 1 0 2 1 1 Reserved 927 32117A-10/2010 AT32UC3C For IN endpoints, it indicates the number of banks filled by the user and ready for IN transfer. When all banks are free, this triggers an EPnINT interrupt if NBUSYBKE is one. For OUT endpoints, it indicates the number of banks filled by OUT transactions from the host. When all banks are busy, this triggers an EPnINT interrupt if NBUSYBKE is one. When the FIFOCON bit is cleared (by writing a one to the FIFOCONC bit) to validate a new bank, this field is updated two or three clock cycles later to calculate the address of the next bank. An EPnINT interrupt is triggered if: - for IN endpoint, NBUSYBKE is one and all the banks are free. - for OUT endpoint, NBUSYBKE is one and all the banks are busy. * RAMACERI: Ram Access Error Interrupt This bit is set when a RAM access underflow error occurs during IN data stage. This bit is cleared when the RAMACERIC bit is written to one. This will acknowledge the interrupt. * DTSEQ: Data Toggle Sequence This field is set to indicate the PID of the current bank: DTSEQ * * * * * Data Toggle Sequence 0 0 Data0 0 1 Data1 1 X Reserved For IN transfers, it indicates the data toggle sequence that will be used for the next packet to be sent. This is not relative to the current bank. For OUT transfers, this value indicates the last data toggle sequence received on the current bank. STALLEDI: STALLed Interrupt This bit is set to signal that a STALL handshake has been sent. To do that, the software has to set the STALLRQ bit (by writing a one to the STALLRQS bit). This triggers an EPnINT interrupt if STALLEDE is one. This bit is cleared when the STALLEDIC bit is written to one. This will acknowledge the interrupt. CRCERRI: CRC Error Interrupt This bit is set to signal that a CRC error has been detected in an isochronous OUT endpoint. The OUT packet is stored in the bank as if no CRC error had occurred. This triggers an EPnINT interrupt if CRCERRE is one. This bit is cleared when the CRCERRIC bit is written to one. This will acknowledge the interrupt. NAKINI: NAKed IN Interrupt This bit is set when a NAK handshake has been sent in response to an IN request from the host. This triggers an EPnINT interrupt if NAKINE is one. This bit is cleared when the NAKINIC bit is written to one. This will acknowledge the interrupt. NAKOUTI: NAKed OUT Interrupt This bit is set when a NAK handshake has been sent in response to an OUT request from the host. This triggers an EPnINT interrupt if NAKOUTE is one. This bit is cleared when the NAKOUTIC bit is written to one. This will acknowledge the interrupt. ERRORFI: Isochronous Error flow Interrupt This bit is set, for isochronous IN/OUT endpoints, when an errorflow error occurs. This triggers an EPnINT interrupt if UNDERFE is one. An underflow can occur during IN stage if the host attempts to read from an empty bank. A zero-length packet is then automatically sent by the USBC. An overflow can also occur during OUT stage if the host sends a packet while the bank is already full. Typically, the CPU is not fast enough. The packet is lost. Shall be cleared by writing a one to the ERRORFIC bit. This will acknowledge the interrupt. This bit is inactive (cleared) for bulk and interrupt IN/OUT endpoints and it means RXSTPI for control endpoints. 928 32117A-10/2010 AT32UC3C * RXSTPI: Received SETUP Interrupt This bit is set, for control endpoints, to signal that the current bank contains a new valid SETUP packet. This triggers an EPnINT interrupt if RXSTPE is one. Shall be cleared by writing a one to the RXSTPIC bit. This will acknowledge the interrupt and free the bank. This bit is inactive (cleared) for bulk and interrupt IN/OUT endpoints and it means UNDERFI for isochronous IN/OUT endpoints. * RXOUTI: Received OUT Data Interrupt This bit is set, for control endpoints, when the current bank contains a bulk OUT packet (data or status stage). This triggers an EPnINT interrupt if RXOUTE is one. Shall be cleared for control end points, by writing a one to the RXOUTIC bit. This will acknowledge the interrupt and free the bank. This bit is set for isochronous, bulk and, interrupt OUT endpoints, at the same time as FIFOCON when the current bank is full. This triggers an EPnINT interrupt if RXOUTE is one. Shall be cleared for isochronous, bulk and, interrupt OUT endpoints, by writing a one to the RXOUTIC bit. This will acknowledge the interrupt, what has no effect on the endpoint FIFO. The user then reads from the FIFO and clears the FIFOCON bit to free the bank. If the OUT endpoint is composed of multiple banks, this also switches to the next bank. The RXOUTI and FIFOCON bits are set/cleared in accordance with the status of the next bank. RXOUTI shall always be cleared before clearing FIFOCON. This bit is inactive (cleared) for isochronous, bulk and interrupt IN endpoints. * TXINI: Transmitted IN Data Interrupt This bit is set for control endpoints, when the current bank is ready to accept a new IN packet. This triggers an EPnINT interrupt if TXINE is one. This bit is cleared when the TXINIC bit is written to one. This will acknowledge the interrupt and send the packet. This bit is set for isochronous, bulk and interrupt IN endpoints, at the same time as FIFOCON when the current bank is free. This triggers an EPnINT interrupt if TXINE is one. This bit is cleared when the TXINIC bit is written to one. This will acknowledge the interrupt, what has no effect on the endpoint FIFO. The user then writes into the FIFO and clears the FIFOCON bit to allow the USBC to send the data. If the IN endpoint is composed of multiple banks, this also switches to the next bank. The TXINI and FIFOCON bits are set/cleared in accordance with the status of the next bank. TXINI shall always be cleared before clearing FIFOCON. This bit is inactive (cleared) for isochronous, bulk and interrupt OUT endpoints. 929 32117A-10/2010 AT32UC3C 32.8.2.12 Endpoint n Status Clear Register Register Name: UESTAnCLR, n in [0..6] Access Type: Write-Only Offset: 0x0160 + (n * 0x04) Read Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 - - - - RAMACERIC - - - 7 6 5 4 3 2 1 0 - STALLEDIC/ CRCERRIC - NAKINIC NAKOUTIC RXSTPIC/ ERRORFIC RXOUTIC TXINIC Writing a one to a bit in this register will clear the corresponding bit in UESTA. Writing a zero to a bit in this register has no effect. This bit always reads as zero. 930 32117A-10/2010 AT32UC3C 32.8.2.13 Endpoint n Status Set Register Register Name: UESTAnSET, n in [0..6] Access Type: Write-Only Offset: 0x0190 + (n * 0x04) Read Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 - - - NBUSYBKS RAMACERIS - 7 6 5 4 3 2 1 0 - STALLEDIS/ CRCERRIS - NAKINIS NAKOUTIS RXSTPIS/ ERRORFIS RXOUTIS TXINIS - Writing a one to a bit in this register will set the corresponding bit in UESTA, what may be useful for test or debug purposes. Writing a zero to a bit in this register has no effect. This bit always reads as zero. 931 32117A-10/2010 AT32UC3C 32.8.2.14 Endpoint n Control Register Register Name: UECONn, n in [0..6] Access Type: Read-Only Offset: 0x01C0 + (n * 0x04) Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - BUSY1E BUSY0E 23 22 21 20 19 18 17 16 - - - - STALLRQ RSTDT - - 15 14 13 12 11 10 9 8 - FIFOCON KILLBK NBUSYBKE RAMACERE - - 7 6 5 4 3 2 1 0 - STALLEDE/ CRCERRE - NAKINE NAKOUTE RXSTPE/ ERRORFE RXOUTE TXINE * BUSY0E: Busy Bank0 Enable This bit is set when the BUSY0ES bit is written to one. This will set the bank 0 as "busy". Then, any transaction destined to the bank0 will not be accepted (. i.e: NAK token will be answered) except SETUP transaction that should always be acknowledged. This bit is cleared when the BUSY0C bit is written to one. * BUSY1E: Busy Bank1 Enable This bit is set when the BUSY1ES bit is written to one. This will set the bank 1 as "busy". Then, any transaction destined to the bank1 will not be accepted (. i.e: NAK token will be answered) except SETUP transaction that should always be acknowledged. This bit is cleared when the BUSY0C bit is written to one. * STALLRQ: STALL Request This bit is set when the STALLRQS bit is written to one. This will request to send a STALL handshake to the host. This bit is cleared when a new SETUP packet is received or when the STALLRQC bit is written to zero. * RSTDT: Reset Data Toggle This bit is set when the RSTDTS bit is written to one. This will clear the data toggle sequence, i.e., set to Data0 the data toggle sequence of the next sent (IN endpoints) or received (OUT endpoints) packet. This bit is cleared instantaneously. The user does not have to wait for this bit to be cleared. * FIFOCON: FIFO Control For control endpoints: The FIFOCON and RWALL bits are irrelevant. The software shall therefore never use them on these endpoints. When read, their value is always 0. For IN endpoints: This bit is set when the current bank is free, at the same time as TXINI. This bit is cleared (by writing a one to the FIFOCONC bit) to send the FIFO data and to switch to the next bank. For OUT endpoints: This bit is set when the current bank is full, at the same time as RXOUTI. This bit is cleared (by writing a one to the FIFOCONC bit) to free the current bank and to switch to the next bank. 932 32117A-10/2010 AT32UC3C * KILLBK: Kill IN Bank * * * * * * * * * * This bit is set when the KILLBKS bit is written to one. This will kill the last written bank. This bit is cleared by hardware after the completion of the "kill packet procedure". The user shall wait for this bit to be cleared before trying to process another IN packet. Caution: The bank is cleared when the "kill packet" procedure is completed by the USBC core : If the bank is really killed, the NBUSYBK field is decremented. If the bank is not "killed" but sent (IN transfer), the NBUSYBK field is decremented and the TXINI flag is set. This specific case can occur if at the same time an IN token is coming and the user wants to kill this bank. Note : If two banks are ready to be sent, the above specific case can not occur, because the first bank is sent (IN transfer) while the last bank is killed. NBUSYBKE: Number of Busy Banks Interrupt Enable This bit is set when the NBUSYBKES bit is written to one. This will enable the Number of Busy Banks interrupt (NBUSYBK). This bit is cleared when the NBUSYBKEC bit is written to zero. This will disable the Number of Busy Banks interrupt (NBUSYBK). RAMACERE: RAMACER Interrupt Enable This bit is set when the RAMACERES bit is written to one. This will enable the RAMACER interrupt (RAMACERI). This bit is cleared when the RAMACEREC bit is written to one. This will disable the RAMACER interrupt (RAMACERI). STALLEDE: STALLed Interrupt Enable This bit is set when the STALLEDES bit is written to one. This will enable the STALLed interrupt (STALLEDI). This bit is cleared when the STALLEDEC bit is written to one. This will disable the STALLed interrupt (STALLEDI). CRCERRE: CRC Error Interrupt Enable This bit is set when the CRCERRES bit is written to one. This will enable the CRC Error interrupt (CRCERRI). This bit is cleared when the CRCERREC bit is written to one. This will disable the CRC Error interrupt (CRCERRI). NAKINE: NAKed IN Interrupt Enable This bit is set when the NAKINES bit is written to one. This will enable the NAKed IN interrupt (NAKINI). This bit is cleared when the NAKINEC bit is written to one. This will disable the NAKed IN interrupt (NAKINI). NAKOUTE: NAKed OUT Interrupt Enable This bit is set when the NAKOUTES bit is written to one. This will enable the NAKed OUT interrupt (NAKOUTI). This bit is cleared when the NAKOUTEC bit is written to one. This will disable the NAKed OUT interrupt (NAKOUTI). RXSTPE: Received SETUP Interrupt Enable This bit is set when the RXSTPES bit is written to one. This will enable the Received SETUP interrupt (RXSTPI). This bit is cleared when the RXSTPEC bit is written to one. This will disable the Received SETUP interrupt (RXSTPI). ERRORFE: Errorflow Interrupt Enable This bit is set when the ERRORFES bit is written to one. This will enable the Underflow interrupt (ERRORFFI). This bit is cleared when the ERRORFEC bit is written to one. This will disable the Underflow interrupt (ERRORFI). RXOUTE: Received OUT Data Interrupt Enable This bit is set when the RXOUTES bit is written to one. This will enable the Received OUT Data interrupt (RXOUT). This bit is cleared when the RXOUTEC bit is written to one. This will disable the Received OUT Data interrupt (RXOUT). TXINE: Transmitted IN Data Interrupt Enable This bit is set when the TXINES bit is written to one. This will enable the Transmitted IN Data interrupt (TXINI). This bit is cleared when the TXINEC bit is written to one. This will disable the Transmitted IN Data interrupt (TXINI). 933 32117A-10/2010 AT32UC3C 32.8.2.15 Endpoint n Control Clear Register Register Name: UECONnCLR, n in [0..6] Access Type: Write-Only Offset: 0x0220 + (n * 0x04) Read Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - BUSY1EC BUSY0EC 23 22 21 20 19 18 17 16 - - - - STALLRQC - - - 15 14 13 12 11 10 9 8 - FIFOCONC - NBUSYBKEC RAMACEREC - - - 7 6 5 4 3 2 1 0 - STALLEDEC/ CRCERREC - NAKINEC NAKOUTEC RXSTPEC/ ERRORFEC RXOUTEC TXINEC Writing a one to a bit in this register will clear the corresponding bit in UECONn. Writing a zero to a bit in this register has no effect. This bit always reads as zero. 934 32117A-10/2010 AT32UC3C 32.8.2.16 Endpoint n Control Set Register Register Name: UECONnSET, n in [0..6] Access Type: Write-Only Offset: 0x01F0 + (n * 0x04) Read Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - BUSY1ES BUSY0ES 23 22 21 20 19 18 17 16 - - - - STALLRQS RSTDTS - - 15 14 13 12 11 10 9 8 - - KILLBKS NBUSYBKES RAMACERES - - - 7 6 5 4 3 2 1 0 - STALLEDES/ CRCERRES - NAKINES NAKOUTES RXSTPES/ ERRORFES RXOUTES TXINES Writing a one to a bit in this register will set the corresponding bit in UECONn. Writing a zero to a bit in this register has no effect. This bit always reads as zero. 935 32117A-10/2010 AT32UC3C 32.8.3 USB Host Registers 32.8.3.1 Host General Control Register Register Name: UHCON Access Type: Read/Write Offset: 0x0400 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 - - - - - RESUME RESET SOFE 7 6 5 4 3 2 1 0 - - - - - - - - * RESUME: Send USB Resume Writing a one to this bit will generate a USB Resume on the USB bus. This bit is cleared when the USB Resume has been sent or when a USB reset is requested. Writing a zero to this bit has no effect. This bit should be written to one only when the start of frame generation is enable. (SOFE bit is one). * RESET: Send USB Reset Writing a one to this bit will generate a USB Reset on the USB bus. This bit is cleared when the USB Reset has been sent. It may be useful to write a zero to this bit when a device disconnection is detected (UHINT.DDISCI is one) whereas a USB Reset is being sent. * SOFE: Start of Frame Generation Enable Writing a one to this bit will generate SOF on the USB bus in full speed mode and keep alive in low speed mode. Writing a zero to this bit will disable the SOF generation and to leave the USB bus in idle state. This bit is set when a USB reset is requested or an upstream resume interrupt is detected (UHINT.TXRSMI). 936 32117A-10/2010 AT32UC3C 32.8.3.2 Host Global Interrupt Register Register Name: UHINT Access Type: Read-Only Offset: 0x0404 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - P8INT(1) 15 14 13 12 11 10 9 8 P7INT(1) P6INT(1) P5INT(1) P4INT(1) P3INT(1) P2INT(1) P1INT(1) P0INT 7 6 5 4 3 2 1 0 - HWUPI HSOFI RXRSMI RSMEDI RSTI DDISCI DCONNI Note: 1. PnINT bits are within the range from P0INT to P6INT. * PnINT: Pipe n Interrupt This bit is set when an interrupt is triggered by the endpoint n (UPSTAn). This triggers a USB interrupt if the corresponding pipe interrupt enable bit is one (UHINTE register). This bit is cleared when the interrupt source is served. * HWUPI: Host Wake-Up Interrupt This bit is set when the host controller is in the suspend mode (SOFE is zero) and an upstream resume from the peripheral is detected. This bit is set when the host controller is in the suspend mode (SOFE is zero) and a peripheral disconnection is detected. This bit is set when the host controller is in the Idle state (VBUSRQ is zero, no VBus is generated), and an SRP event initiated by the peripheral is detected (USBSTA.SRPI is one). This interrupt is generated even if the clock is frozen by the FRZCLK bit. * HSOFI: Host Start of Frame Interrupt This bit is set when a SOF is issued by the Host controller. This triggers a USB interrupt when HSOFE is one. When using the host controller in low speed mode, this bit is also set when a keep-alive is sent. This bit is cleared when the HSOFIC bit is written to one. * RXRSMI: Upstream Resume Received Interrupt This bit is set when an Upstream Resume has been received from the Device. This bit is cleared when the RXRSMIC is written to one. * RSMEDI: Downstream Resume Sent Interrupt This bit set when a Downstream Resume has been sent to the Device. This bit is cleared when the RSMEDIC bit is written to one. * RSTI: USB Reset Sent Interrupt This bit is set when a USB Reset has been sent to the device. This bit is cleared when the RSTIC bit is written to one. * DDISCI: Device Disconnection Interrupt This bit is set when the device has been removed from the USB bus. 937 32117A-10/2010 AT32UC3C This bit is cleared when the DDISCIC bit is written to one. * DCONNI: Device Connection Interrupt This bit is set when a new device has been connected to the USB bus. This bit is cleared when the DCONNIC bit is written to one. 938 32117A-10/2010 AT32UC3C 32.8.3.3 Host Global Interrupt Clear Register Register Name: UHINTCLR Access Type: Write-Only Offset: 0x0408 Read Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 - - - - - - - - 7 6 5 4 3 2 1 0 - HWUPIC HSOFIC RXRSMIC RSMEDIC RSTIC DDISCIC DCONNIC Writing a one to a bit in this register will clear the corresponding bit in UHINT. Writing a zero to a bit in this register has no effect. This bit always reads as zero. 939 32117A-10/2010 AT32UC3C 32.8.3.4 Host Global Interrupt Set Register Register Name: UHINTSET Access Type: Write-Only Offset: 0x040C Read Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 - - - - - - - - 7 6 5 4 3 2 1 0 - HWUPIS HSOFIS RXRSMIS RSMEDIS RSTIS DDISCIS DCONNIS - Writing a one to a bit in this register will set the corresponding bit in UHINT, what may be useful for test or debug purposes. Writing a zero to a bit in this register has no effect. This bit always reads as zero. 940 32117A-10/2010 AT32UC3C 32.8.3.5 Host Global Interrupt Enable Register Register Name: UHINTE Access Type: Read-Only Offset: 0x0410 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - P8INTE(1) 15 14 13 12 11 10 9 8 P7INTE(1) P6INTE(1) P5INTE(1) P4INTE(1) P3INTE(1) P2INTE(1) P1INTE(1) P0INTE 7 6 5 4 3 2 1 0 - HWUPIE HSOFIE RXRSMIE RSMEDIE RSTIE DDISCIE DCONNIE Note: 1. PnINTE bits are within the range from P0INTE to P6INTE. * PnINTE: Pipe n Interrupt Enable This bit is set when the PnINTES bit is written to one. This will enable the Pipe n Interrupt (PnINT). This bit is cleared when the PnINTEC bit is written to one. This will disable the Pipe n Interrupt (PnINT). * HWUPIE: Host Wake-Up Interrupt Enable This bit is set when the HWUPIES bit is written to one. This will enable the Host Wake-up Interrupt (HWUPI). This bit is cleared when the HWUPIEC bit is written to one. This will disable the Host Wake-up Interrupt (HWUPI). * HSOFIE: Host Start of Frame Interrupt Enable This bit is set when the HSOFIES bit is written to one. This will enable the Host Start of Frame interrupt (HSOFI). This bit is cleared when the HSOFIEC bit is written to one. This will disable the Host Start of Frame interrupt (HSOFI). * RXRSMIE: Upstream Resume Received Interrupt Enable This bit is set when the RXRSMIES bit is written to one. This will enable the Upstream Resume Received interrupt (RXRSMI). This bit is cleared when the RXRSMIEC bit is written to one. This will disable the Downstream Resume interrupt (RXRSMI). * RSMEDIE: Downstream Resume Sent Interrupt Enable This bit is set when the RSMEDIES bit is written to one. This will enable the Downstream Resume interrupt (RSMEDI). This bit is cleared when the RSMEDIEC bit is written to one. This will disable the Downstream Resume interrupt (RSMEDI). * RSTIE: USB Reset Sent Interrupt Enable This bit is set when the RSTIES bit is written to one. This will enable the USB Reset Sent interrupt (RSTI). This bit is cleared when the RSTIEC bit is written to one. This will disable the USB Reset Sent interrupt (RSTI). * DDISCIE: Device Disconnection Interrupt Enable This bit is set when the DDISCIES bit is written to one. This will enable the Device Disconnection interrupt (DDISCI). This bit is cleared when the DDISCIEC bit is written to one. This will disable the Device Disconnection interrupt (DDISCI). * DCONNIE: Device Connection Interrupt Enable This bit is set when the DCONNIES bit is written to one. This will enable the Device Connection interrupt (DCONNI). This bit is cleared when the DCONNIEC bit is written to one. This will disable the Device Connection interrupt (DCONNI). 941 32117A-10/2010 AT32UC3C 32.8.3.6 Host Global Interrupt Enable Clear Register Register Name: UHINTECLR Access Type: Write-Only Offset: 0x0414 Read Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - P8INTEC(1) 15 14 13 12 11 10 9 8 P7INTEC(1) P6INTEC(1) P5INTEC(1) P4INTEC(1) P3INTEC(1) P2INTEC(1) P1INTEC(1) P0INTEC 7 6 5 4 3 2 1 0 - HWUPIEC HSOFIEC RXRSMIEC RSMEDIEC RSTIEC DDISCIEC DCONNIEC Writing a one to a bit in this register will clear the corresponding bit in UHINTE. Writing a zero to a bit in this register has no effect. This bit always reads as zero. Note: 1. PnINTEC bits are within the range from P0INTEC to P6INTEC. 942 32117A-10/2010 AT32UC3C 32.8.3.7 Host Global Interrupt Enable Set Register Register Name: UHINTESET Access Type: Write-Only Offset: 0x0418 Read Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - P8INTES(1) 15 14 13 12 11 10 9 8 P7INTES(1) P6INTES(1) P5INTES(1) P4INTES(1) P3INTES(1) P2INTES(1) P1INTES(1) P0INTES 7 6 5 4 3 2 1 0 - HWUPIES HSOFIES RXRSMIES RSMEDIES RSTIES DDISCIES DCONNIES Writing a one to a bit in this register will set the corresponding bit in UHINT. Writing a zero to a bit in this register has no effect. This bit always reads as zero. Notes: 1. PnINTES bits are within the range from P0INTES to P6INTES. 943 32117A-10/2010 AT32UC3C 32.8.3.8 Pipe Enable/Reset Register Register Name: UPRST Access Type: Read/Write Offset: 0x0041C Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 - - - - - - - PEN8(1) 7 6 5 4 3 2 1 0 PEN7(1) PEN6(1) PEN5(1) PEN4(1) PEN3(1) PEN2(1) PEN1(1) PEN0 * PENn: Pipe n Enable Writing a one to this bit will enable the pipe n. Writing a zero to this bit will disable the pipe n, what forces the pipe n state to inactive and resets the pipe n registers (UPCFGn, UPSTAn, UPCONn). Note: 1. PENn bits are within the range from PEN0 to PEN6. 944 32117A-10/2010 AT32UC3C 32.8.3.9 Host Frame Number Register Register Name: UHFNUM Access Type: Read/Write Offset: 0x0420 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 11 10 9 8 2 1 0 - - - FLENHIGH 15 14 - - 7 6 13 12 FNUM[10:5] 5 FNUM[4:0] 4 3 * FLENHIGH: Frame Length This field contains the 8 high-order bits of the 14-bits internal frame counter (frame counter at 12MHz, counter length is 12000 to ensure a SOF generation every 1 ms). * FNUM: Frame Number This field contains the current SOF number. This field can be written by software to initialize a new frame number value. In this case, at the next SOF, the FNUM field takes its new value 945 32117A-10/2010 AT32UC3C 32.8.3.10 Pipe n Configuration Register Register Name: UPCFGn, n in [0..6] Access Type: Read/Write Offset: 0x0500 + (n * 0x04) Reset Value: 0x00000000 31 30 29 28 27 26 25 24 BINTERVAL 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 - - - - 7 6 3 2 1 0 - PBK - - PTYPE 5 - 4 PSIZE PTOKEN * BINTERVAL: bInterval parameter This field corresponds to the bus access period of the pipe. For Interrupt pipe, this field corresponds to the desired period from 1 ms to 255 ms. For isochronous pipe, this field corresponds to the desired period calculated as this : 2(BInterval) * 1 ms. For bulk or control pipe, this field corresponds to the desired period from 1 ms to 255 ms. This field is cleared upon sending a USB reset. * PTYPE: Pipe Type This field contains the pipe type. PTYPE Pipe Type 0 0 Control 0 1 Isochronous 1 0 Bulk 1 1 Interrupt This field is cleared upon sending a USB reset. * PTOKEN: Pipe Token This field contains the endpoint token. PTOKEN Endpoint Direction 00 SETUP 01 IN 10 OUT 11 reserved 946 32117A-10/2010 AT32UC3C * PSIZE: Pipe Size This field contains the size of each pipe bank. PSIZE Endpoint Size 0 0 0 8 bytes 0 0 1 16 bytes 0 1 0 32 bytes 0 1 1 64 bytes 1 0 0 128 bytes 1 0 1 256 bytes 1 1 0 512 bytes 1 1 1 1024 bytes This field is cleared upon sending a USB reset. * PBK: Pipe Banks This field contains the number of banks for the pipe. BK Endpoint Banks 0 1 (single-bank pipe) 1 2 (double-bank pipe) For control endpoints, a single-bank pipe (0b00) should be selected. This field is cleared upon sending a USB reset. 947 32117A-10/2010 AT32UC3C 32.8.3.11 Pipe n Status Register Register Name: UPSTAn, n in [0..6] Access Type: Read-Only Offset: 0x0530 + (n * 0x04) Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 - CURRBK - RAMACERI 7 6 5 4 3 2 1 0 - RXSTALLDI/ CRCERRI ERRORFI NAKEDI PERRI TXSTPI TXOUTI RXINI NBUSYBK DTSEQ * CURRBK: Current Bank For non-control pipe, this field indicates the number of the current bank. CURRBK Current Bank 0 0 Bank0 0 1 Bank1 This field may be updated 1 clock cycle after the RWALL bit changes, so the user shall not poll this field as an interrupt bit. * NBUSYBK: Number of Busy Banks This field indicates the number of busy bank. For OUT pipe, this field indicates the number of busy bank(s), filled by the user, ready for OUT transfer. When all banks are busy, this triggers an PnINT interrupt if UPCONn.NBUSYBKE is one. For IN pipe, this field indicates the number of busy bank(s) filled by IN transaction from the Device. When all banks are free, this triggers an PnINT interrupt if UPCONn.NBUSYBKE is one. NBUSYBK Number of busy bank 0 0 All banks are free. 0 1 1 busy bank 1 0 2 busy banks 1 1 reserved * RAMACERI: Ram Access Error Interrupt This bit is set when a RAM access underflow error occurs during IN data stage. 948 32117A-10/2010 AT32UC3C * DTSEQ: Data Toggle Sequence This field indicates the data PID of the current bank. DTSEQ * * * * * * * * Data toggle sequence 0 0 Data0 0 1 Data1 1 0 reserved 1 1 reserved For OUT pipe, this field indicates the data toggle of the next packet that will be sent. For IN pipe, this field indicates the data toggle of the received packet stored in the current bank. RXSTALLDI: Received STALLed Interrupt This bit is set, for all endpoints but isochronous, when a STALL handshake has been received on the current bank of the pipe. The pipe is automatically frozen. This triggers an interrupt if the RXSTALLE bit is one. This bit is cleared when the RXSTALLDIC bit is written to one. CRCERRI: CRC Error Interrupt This bit is set, for isochronous endpoint, when a CRC error occurs on the current bank of the pipe. This triggers an interrupt if the TXSTPE bit is one. This bit is cleared when the CRCERRIC bit is written to one. ERRORFI: Errorflow Interrupt This bit is set, for isochronous and Interrupt IN/OUT pipe, when an error flow occurs. This triggers an interrupt if the ERRORFIE bit is one. This bit is set, for Isochronous or interrupt OUT pipe, when a transaction underflow occurs in the current pipe. (the pipe can't send the OUT data packet in time because the current bank is not ready). This bit is set, for Isochronous or interrupt IN pipe, when a transaction flow error occurs in the current pipe. i.e, the current bank of the pipe is not free whereas a new IN USB packet is received. This packet is not stored in the bank. For Interrupt pipe, the overflowed packet is ACKed to respect the USB standard. This bit is cleared when the ERRORFIC bit is written to one. NAKEDI: NAKed Interrupt This bit is set when a NAK has been received on the current bank of the pipe. This triggers an interrupt if the NAKEDE bit is one. This bit is cleared when the NAKEDIC bit written to one. PERRI: Pipe Error Interrupt This bit is set when an error occurs on the current bank of the pipe. This triggers an interrupt if the PERRE bit is set. Refers to the UPERRn register to determine the source of the error. This bit is cleared when the error source bit is cleared. TXSTPI: Transmitted SETUP Interrupt This bit is set, for Control endpoints, when the current SETUP bank is free and can be filled. This triggers an interrupt if the TXSTPE bit is one. This bit is cleared when the TXSTPIC bit is written to one. TXOUTI: Transmitted OUT Data Interrupt This bit is set when the current OUT bank is free and can be filled. This triggers an interrupt if the TXOUTE bit is one. This bit is cleared when the TXOUTIC bit is written to one. RXINI: Received IN Data Interrupt This bit is set when a new USB message is stored in the current bank of the pipe. This triggers an interrupt if the RXINE bit is one. This bit is cleared when the RXINIC bit is written to one. 949 32117A-10/2010 AT32UC3C 32.8.3.12 Pipe n Status Clear Register Register Name: UPSTAnCLR, n in [0..6] Access Type: Write-Only Offset: 0x0560 + (n * 0x04) Read Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 - - - - - RAMACERIC - - 7 6 5 4 3 2 1 0 - RXSTALLDI C/ CRCERRIC ERRORFIC NAKEDIC - TXSTPIC TXOUTIC RXINIC Writing a one to a bit in this register will clear the corresponding bit in UPSTAn. Writing a zero to a bit in this register has no effect. This bit always reads as zero. 950 32117A-10/2010 AT32UC3C 32.8.3.13 Pipe n Status Set Register Register Name: UPSTAnSET, n in [0..6] Access Type: Write-Only Offset: 0x0590 + (n * 0x04) Read Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 - - - - - RAMACERIS - - 7 6 5 4 3 2 1 0 ERRORFIC NAKEDIS PERRIS TXSTPIS TXOUTIS RXINIS RXSTALLDIS/ - CRCERRIS Writing a one to a bit in this register will set the corresponding bit in UPSTAn, what may be useful for test or debug purposes. Writing a zero to a bit in this register has no effect. This bit always reads as zero. 951 32117A-10/2010 AT32UC3C 32.8.3.14 Pipe n Control Register Register Name: UPCONn, n in [0..6] Access Type: Read-Only Offset: 0x05C0 + (n * 0x04) Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - INITBK INITDTGL PFREEZE - 15 14 13 12 11 10 9 8 - FIFOCON - NBUSYBKE - RAMACERE - - 7 6 5 4 3 2 1 0 - RXSTALLDE/ CRCERRE ERRORFIE NAKEDE PERRE TXSTPE TXOUTE RXINE * INITBK: Bank Initialization This bit is always read as zero. If the user sets the INITBKS bit, this will set the Current Bank to Bank1 value for the current pipe. If the user sets the INITBKC bit, this will set the Current Bank to Bank0 value for the current pipe. This may be useful to restore a pipe to manage alternate pipes on the same physical pipe. * INITTGL: Data Toggle Initialization This bit is always read as zero. If the user sets the INITTGLS bit, this will set the Data toggle to Data1 value for the current pipe. If the user sets the INITTGLC bit, this will set the Data toggle to Data0 value for the current pipe. This may be useful to restore a pipe to manage alternate pipes on the same physical pipe. * PFREEZE: Pipe Freeze This bit is set when the PFREEZES bit is written to one or when the pipe is not configured or when a STALL handshake has been received on this pipe or when INRQ In requests have been processed or when after a pipe reset (UPRST.PRSTn rising) or a pipe Enable (UPRST.PEN rising). This will freeze the pipe requests generation. This bit is cleared when the PFREEZEC bit is written to one. This will enable the pipe request generation. If the user clears the PFRFEEZEC bit whereas a transaction is on going on the usb bus, the transaction will be properly completed and then the PFREEZE bit will be cleared hereafter. * FIFOCON: FIFO Control For OUT and SETUP pipes: This bit is set when the current bank is free, at the same time than TXOUTI or TXSTPI. This bit is cleared when the FIFOCONC bit is written to one. This will send the FIFO data and switch the bank. For IN pipe: This bit is set when a new IN message is stored in the current bank, at the same time than RXINI. This bit is cleared when the FIFOCONC bit is written to one. This will free the current bank and switch to the next bank. * NBUSYBKE: Number of Busy Banks Interrupt Enable This bit is set when the NBUSYBKES bit is written to one.This will enable the Transmitted IN Data interrupt (NBUSYBKE). 952 32117A-10/2010 AT32UC3C This bit is cleared when the NBUSYBKEC bit is written to one. This will disable the Transmitted IN Data interrupt (NBUSYBKE). * RAMACERE: Ram Access Error Interrupt Enable This bit is set when the NBUSYBKES bit is written to one.This will enable the Transmitted IN Data interrupt (NBUSYBKE). This bit is cleared when the NBUSYBKEC bit is written to one. This will disable the Transmitted IN Data interrupt (NBUSYBKE). * RXSTALLDE: Received STALLed Interrupt Enable This bit is set when the RXSTALLDES bit is written to one. This will enable the Transmitted IN Data interrupt (RXSTALLDE). This bit is cleared when the RXSTALLDEC bit is written to one. This will disable the Transmitted IN Data interrupt (RXSTALLDE). * CRCERRE: CRC Error Interrupt Enable This bit is set when the CRCERRES bit is written to one. This will enable the Transmitted IN Data interrupt (CRCERRE). This bit is cleared when the CRCERREC bit is written to one. This will disable the Transmitted IN Data interrupt (CRCERRE). * ERRORFIE: Errorflow Interrupt Enable This bit is set when the ERRORFIES bit is written to one. This will enable the Transmitted IN Data interrupt (OVERFIE). This bit is cleared when the ERRORFIEC bit is written to one. This will disable the Transmitted IN Data interrupt (OVERFIE). * NAKEDE: NAKed Interrupt Enable This bit is set when the NAKEDES bit is written to one. This will enable the Transmitted IN Data interrupt (NAKEDE). This bit is cleared when the NAKEDEC bit is written to one. This will disable the Transmitted IN Data interrupt (NAKEDE). * PERRE: Pipe Error Interrupt Enable This bit is set when the PERRES bit is written to one. This will enable the Transmitted IN Data interrupt (PERRE). This bit is cleared when the PERREC bit is written to one. This will disable the Transmitted IN Data interrupt (PERRE). * TXSTPE: Transmitted SETUP Interrupt Enable This bit is set when the TXSTPES bit is written to one. This will enable the Transmitted IN Data interrupt (TXSTPE). This bit is cleared when the TXSTPEC bit is written to one. This will disable the Transmitted IN Data interrupt (TXSTPE). * TXOUTE: Transmitted OUT Data Interrupt Enable This bit is set when the TXOUTES bit is written to one. This will enable the Transmitted IN Data interrupt (TXOUTE). This bit is cleared when the TXOUTEC bit is written to one. This will disable the Transmitted IN Data interrupt (TXOUTE). * RXINE: Received IN Data Interrupt Enable This bit is set when the RXINES bit is written to one. This will enable the Transmitted IN Data interrupt (RXINE). This bit is cleared when the RXINEC bit is written to one. This will disable the Transmitted IN Data interrupt (RXINE). 953 32117A-10/2010 AT32UC3C 32.8.3.15 Pipe n Control Set Register Register Name: UPCONnSET, n in [0..6] Access Type: Write-Only Offset: 0x05F0 + (n * 0x04) Read Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - INITBKS INITDTGLS PFREEZES - 15 14 13 12 11 10 9 8 - - - NBUSYBKES - - - - 7 6 5 4 3 2 1 0 ERRORFIES NAKEDES PERRES TXSTPES TXOUTES RXINES RXSTALLDES/ - CRCERRES Writing a one to a bit in this register will set the corresponding bit in UPCONn. Writing a zero to a bit in this register has no effect. This bit always reads as zero. 954 32117A-10/2010 AT32UC3C 32.8.3.16 Pipe n Control Clear Register Register Name: UPCONnCLR, n in [0..6] Access Type: Write-Only Offset: 0x0620 + (n * 0x04) Read Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - INITBKC INITDTGLC PFREEZEC - 15 14 13 12 11 10 9 8 - FIFOCONC - NBUSYBKEC - - - - 7 6 5 4 3 2 1 0 ERRORFIEC NAKEDEC PERREC TXSTPEC TXOUTEC RXINEC RXSTALLDEC/ - CRCERREC Writing a one to a bit in this register will clear the corresponding bit in UPCONn. Writing a zero to a bit in this register has no effect. This bit always reads as zero. 955 32117A-10/2010 AT32UC3C 32.8.3.17 Pipe n IN Request Register Register Name: UPINRQn, n in [0..6] Access Type: Read/Write Offset: 0x0650 + (n * 0x04) Reset Value: 0x00000001 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 - - - - - - - INMODE 7 6 5 4 3 2 1 0 INRQ * INMODE: IN Request Mode Writing a one to this bit will allow the USBC to perform infinite IN requests when the pipe is not frozen. Writing a zero to this bit will perform a pre-defined number of IN requests. This number is the INRQ field. * INRQ: IN Request Number before Freeze This field contains the number of IN transactions before the USBC freezes the pipe. The USBC will perform INRQ IN requests before to freeze the pipe. This counter is automatically decreased by 1 each time a IN request has been successfully performed. This register has no effect when the INMODE bit is 0 (infinite IN requests generation till the pipe is not frozen). 956 32117A-10/2010 AT32UC3C 32.9 Module Configuration The specific configuration for each USBC instance is listed in the following tables. The module bus clocks listed here are connected to the system bus clocks. Please refer to the Power Manager chapter for details. Table 32-5. Module name USBC Table 32-6. MODULE Clock Name Clock Name Description CLK_USBC_HSB HSB clock CLK_USBC_PB Peripheral Bus clock from the PBB clock domain GCLK_USBC The generic clock used for the USBC is GCLK0 Register Reset Values Register Reset Value UVERS 0x00000210 UFEATURES 7 UADDRSIZE 0x1000 UNAME1 0x48555342 UNAME2 0x004F5447 957 32117A-10/2010 AT32UC3C 33. Pulse Width Modulation Controller (PWM) Rev. 5.0.1.0 33.1 Features * 4 channels * Common clock generator providing thirteen different clocks * * * * * * * 33.2 - A modulo n counter providing eleven clocks - Two independent linear dividers working on modulo n counter outputs - High frequency asynchronous clocking mode Independent channels - Independent 20-bit counter for each channel - Independent complementary outputs with 16-bit dead-time generator (also called dead-band or non-overlapping time) for each channel - Independent enable disable command for each channel - Independent clock selection for each channel - Independent period, duty-cycle and dead-time for each channel - Independent double buffering of period, duty-cycle and dead-times for each channel - Independent programmable selection of the output waveform polarity for each channel - Independent programmable center or left aligned output waveform for each channel - Independent output override for each channel 2 2-bit Gray up/down channels for stepper motor control Synchronous channel mode - Synchronous channels share the same counter - Mode to update the synchronous channels registers after a programmable number of periods - Synchronous channels supports connection with peripheral DMA controller which offers buffer transfer without processor intervention to update duty-cycle values 2 independent events lines intended to synchonize ADC conversions 8 comparison units intended to generate interrupts, pulses on event lines and PDC tranfer requests 5 programmable fault inputs providing an asynchronous protection of PWM outputs Write-Protect registers Overview The PWM Controller (PWM) controls 4 channels independently. Each channel controls two complementary square output waveforms. Characteristics of the output waveforms such as period, duty-cycle, polarity and dead-times (also called dead-bands or non-overlapping times) are configured through the user interface. Each channel selects and uses one of the clocks provided by the clock generator. The clock generator provides several clocks resulting from the division of the PWM internal clock (CCK). This internal clock can be driven either by the master clock (CLK_PWM) or by the generic clock (GCLK). All PWM accesses are made through registers mapped on the peripheral bus. All channels integrate a double buffering system in order to prevent an unexpected output waveform while modifying the period, the duty-cycle or the dead-times. Channels can be linked together as synchronous channels to be able to update their duty-cycle or dead-times at the same time. The update of duty-cycles of synchronous channels can be performed by the Peripheral DMA Controller Channel (PDCA) which offers buffer transfer without processor Intervention. 958 32117A-10/2010 AT32UC3C The PWM provides 8 independent comparison units capable to compare a programmed value to the counter of the synchronous channels (counter of channel 0). These comparisons are intended to generate software interrupts, to trigger pulses on the 2 independent event lines (in order to synchronize ADC conversions with a lot of flexibility independently of the PWM outputs), and to trigger PDCA transfer requests. The PWM outputs can be overridden synchronously or asynchronously to their channel counter. The PWM Controller provide a fault protection mechanism with 5 fault inputs, capable to detect a fault condition and to override the PWM outputs asynchronously. For safety usage, some control registers are write-protected. 959 32117A-10/2010 AT32UC3C 33.3 Block Diagram Figure 33-1. Pulse Width Modulation Controller Block Diagram PWM Channel x update period dutycycle MUX comp arator OCx dead-time generator DTOHx DTOLx output override OOOHx OOOLx PWMH[x] fault protection PWML[x] MUX counter channel x SYNCx EXT_ FAULTS[i] clock selector EXT_ FAULTS[i] Channel y (=x+1) update period dutycycle MUX comp arator OCy dead-time generator DTOHy DTOLy output override OOOHy OOOLy fault protection I/O controller PWMH[y] PWML[y] MUX counter channel y SYNCy clock selector PWMH[0] Channel 0 counter channel 0 PWML[0] z=0 (x=0, y=1) z=1 (x=2, y=3) z=2 (x=4, y=5) 2-bit gray counter z event 0 Comparison Units Event Generator event 1 PEVC User Interface Peripheral Bus Clock generator CLK_PWM GCLK PDCA 960 32117A-10/2010 AT32UC3C 33.4 I/O Lines Description Each channel outputs two complementary external I/O lines. Table 33-1. I/O Line Description Name Description Type PWMHx PWM Waveform Output High for channel x Output PWMLx PWM Waveform Output Low for channel x Output EXT_FAULTSx PWM Fault Input x Input 961 32117A-10/2010 AT32UC3C 33.5 33.5.1 Product Dependencies I/O Lines The pins used for interfacing the PWM may be multiplexed with the I/O Controller lines. The programmer must first program the I/O controller to assign the desired PWM pins to their peripheral function. If I/O lines of the PWM are not used by the application, they can be used for other purposes by the I/O controller. 33.5.2 Clocks The clock of the PWM (CLK_PWM) is generated by the Power Manager. This clock is enabled at reset, and can be disabled in the Power Manager. It is recommended to disable the PWM before disabling the clock, to avoid freezing the PWM in an undefined state. The PWM counters can be fed by a Generic Clock (GCLK). This is a high frequency clock which is asynchronous to CLK_PWM. 33.5.3 Interrupts The PWM interrupt line is connected to the Interrupt Controller. Using the PWM interrupt requires the interrupt controller to be programmed first. 962 32117A-10/2010 AT32UC3C 33.6 Functional Description The PWM Controller is primarily composed of a clock generator module and 4 channels. * The clock generator module provides 13 clocks. Its source clock is chosen according to the CLKSEL bit in the Clock Register (CLK). It allows to select: - CLK_PWM: the master clock (clock of the peripheral bus to which the PWM is connected) - GCLK: the generic clock (high frequency clock which is asynchronous to CLK_PWM) * Each channel can independently choose one of the clock generator outputs. * Each channel generates an output waveform with attributes that can be defined independently for each channel through the user interface registers. 33.6.1 PWM Clock Generator Figure 33-2. Functional View of the Clock Generator Block Diagram CLK_PWM CCK GCLK CLKSEL modulo n counter CCK CCK/2 CCK/4 CCK/8 CCK/16 CCK/32 CCK/64 CCK/128 CCK/256 CCK/512 CCK/1024 Divider A PREA DIVA Divider B PREB clkA clkB DIVB 963 32117A-10/2010 AT32UC3C The PWM internal clock (named CCK and driven either by CLK_PWM or by GCLK) is divided in the clock generator module to provide different clocks available for all channels. Each channel can independently select one of the divided clocks. The selection of the source clock of the PWM counters is made by the CLKSEL bit in the CLK Register. In asynchronous clocking mode (CLKSEL=1, GCLK selected), the PWM counters and the prescaler allow running the CPU from any clock source while the prescaler is operating on a faster clock (GCLK). The clock generator is divided in three blocks: - a modulo n counter which provides 11 clocks: FCCK, FCCK/2, FCCK/4, FCCK/8, FCCK/16, FCCK/32, FCCK/64, FCCK/128, FCCK/256, FCCK/512, FCCK/1024 - two linear dividers (1, 1/2, 1/3,... 1/255) that provide two separate clocks: clkA and clkB Each linear divider can independently divide one of the clocks of the modulo n counter. The selection of the clock to be divided is made according to the PREA (PREB) field of the PWM Clock register (PWM_CLK). The resulting clock clkA (clkB) is the clock selected divided by DIVA (DIVB) field value. After a reset of the PWM controller, DIVA (DIVB) and PREA (PREB) are set to 0. This implies that after reset clkA (clkB) are turned off. At reset, all clocks provided by the modulo n counter are turned off except clock "CCK". This situation is also true when the PWM master clock is turned off through the Power Management Controller. CAUTION: * Before using the PWM, the programmer must first enable the PWM clock in the Power Manager (PM). * The master clock frequency (CLK_PWM) must be lower than half of the generic clock frequency (GCLK) due to the synchronization mechanism between both clock domains. * After selecting a new PWM input clock (written CLKSEL to a new value), no write in any PWM registers must be attempted before a delay of 2 master clock periods (CLK_PWM). This is the time needed by the PWM to switch the source of the internal clock (CCK). 964 32117A-10/2010 AT32UC3C 33.6.2 PWM Channel 33.6.2.1 Block Diagram Figure 33-3. Functional View of the Channel Block Diagram Channel x update period MUX dutycycle comp arator OCx dead-time generator DTOHx DTOLx output override OOOHx OOOLx fault protection PWMHx PWMLx MUX counter channel x SYNCx clock selector counter channel 0 2-bit gray counter z z=0 (x=0, y=1) z=1 (x=2, y=3) z=2 (x=4, y=5) Each of the 4 channels is composed of six blocks: * A clock selector which selects one of the clocks provided by the clock generator (described in Section 33.6.1 on page 963). * A counter clocked by the output of the clock selector. This counter is incremented or decremented according to the channel configuration and comparators matches. The size of the counter is 20 bits. * A comparator used to compute the OCx output waveform according to the counter value and the configuration. The counter value can be the one of the channel counter or the one of the channel 0 counter according to SYNCx bit in the "Sync Channels Mode Register" on page 1001 (SCM). * A 2-bit configurable gray counter enables the stepper motor driver. One gray counter drives 2 channels. * A dead-time generator providing two complementary outputs (DTOHx/DTOLx) which allows to drive external power control switches safely. * An output override block that can force the two complementary outputs to a programmed value (OOOHx/OOOLx). * An asynchronous fault protection mechanism that has the highest priority to override the two complementary outputs in case of fault detection (PWMHx/PWMLx). 965 32117A-10/2010 AT32UC3C 33.6.2.2 Comparator The comparator continuously compares its counter value with the channel period defined by CPRD in the "Channel Period Register" on page 1035 (CPRDx) and the duty-cycle defined by CDTY in the "Channel Duty Cycle Register" on page 1033 (CDTYx) to generate an output signal OCx accordingly. The different properties of the waveform of the output OCx are: * the clock selection. The channel counter is clocked by one of the clocks provided by the clock generator described in the previous section. This channel parameter is defined in the CPRE field of the "Channel Mode Register" on page 1031 (CMRx). This field is reset at 0. * the waveform period. This channel parameter is defined in the CPRD field of the CPRDx register. - If the waveform is left aligned, then the output waveform period depends on the counter source clock and can be calculated: By using the PWM internal clock (CCK) divided by an X given prescaler value (with X being 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, or 1024), the resulting period formula will be: (-----------------------------X x CPRD )CCK By using the PWM internal clock (CCK) divided by one of both DIVA or DIVB divider, the formula becomes, respectively: (----------------------------------------CRPD x DIVA )( CRPD x DIVB ) or -----------------------------------------CCK CCK If the waveform is center aligned then the output waveform period depends on the counter source clock and can be calculated: By using the PWM internal clock (CCK) divided by an X given prescaler value (with X being 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, or 1024). The resulting period formula will be: (---------------------------------------2 x X x CPRD )CCK By using the PWM internal clock (CCK) divided by one of both DIVA or DIVB divider, the formula becomes, respectively: (--------------------------------------------------2 x CPRD x DIVA )( 2 x CPRD x DIVB ) or ---------------------------------------------------CCK CCK * the waveform duty-cycle. This channel parameter is defined in the CDTY field of the CDTYx register. If the waveform is left aligned then: ( period - 1 fchannel_x_clock x CDTY ) duty cycle = -------------------------------------------------------------------------------------------------------period If the waveform is center aligned, then: ( ( period 2 ) - 1 fchannel_x_clock x CDTY ) -) duty cycle = ---------------------------------------------------------------------------------------------------------------------( period 2 ) 966 32117A-10/2010 AT32UC3C * the waveform polarity. At the beginning of the period, the signal can be at high or low level. This property is defined in the CPOL field of the CMRx register. By default the signal starts by a low level. * the waveform alignment. The output waveform can be left or center aligned. Center aligned waveforms can be used to generate non overlapped waveforms. This property is defined in the CALG field of the CMRx register. The default mode is left aligned. Figure 33-4. Non Overlapped Center Aligned Waveforms No overlap OC0 OC1 Period Note: 1. See Figure 33-5 on page 968 for a detailed description of center aligned waveforms. When center aligned, the channel counter increases up to CPRD and decreases down to 0. This ends the period. When left aligned, the channel counter increases up to CPRD and is reset. This ends the period. Thus, for the same CPRD value, the period for a center aligned channel is twice the period for a left aligned channel. Waveforms are fixed at 0 when: * CDTY = CPRD and CPOL = 0 * CDTY = 0 and CPOL = 1 Waveforms are fixed at 1 (once the channel is enabled) when: * CDTY = 0 and CPOL = 0 * CDTY = CPRD and CPOL = 1 The waveform polarity must be written before enabling the channel. This immediately affects the channel output level. Changes on channel polarity are not taken into account while the channel is enabled. Besides generating output signals OCx, the comparator generates interrupts in function of the counter value. When the output waveform is left aligned, the interrupt occurs at the end of the counter period. When the output waveform is center aligned, the CES bit of the CMRx register defines when the channel counter interrupt occurs. If CES is set to 0, the interrupt occurs at the end of the counter period. If CES is set to 1, the interrupt occurs at the end of the counter period and at half of the counter period. Figure 33-5 on page 968 illustrates the counter interrupts in function of the configuration. 967 32117A-10/2010 AT32UC3C Figure 33-5. Waveform Properties Channel x slected clock CHIDx(PWM_SR) CHIDx(PWM_ENA) CHIDx(PWM_DIS) Center Aligned CALG(PWM_CMRx) = 1 PWM_CCNTx CPRD(PWM_CPRDx) CDTY(PWM_CDTYx) Period Output Waveform OCx CPOL(PWM_CMRx) = 0 Output Waveform OCx CPOL(PWM_CMRx) = 1 Counter Event CHIDx(PWM_ISR) CES(PWM_CMRx) = 0 Counter Event CHIDx(PWM_ISR) CES(PWM_CMRx) = 1 Left Aligned CALG(PWM_CMRx) = 0 PWM_CCNTx CPRD(PWM_CPRDx) CDTY(PWM_CDTYx) Period Output Waveform OCx CPOL(PWM_CMRx) = 0 Output Waveform OCx CPOL(PWM_CMRx) = 1 Counter Event CHIDx(PWM_ISR) 968 32117A-10/2010 AT32UC3C 33.6.2.3 2-bit Gray Up/Down Counter for Stepper Motor It is possible to configure a couple of channels to provide a 2-bit gray count waveform on 2 outputs. Dead-Time generator and other downstream logic can be configured on these channels. Up or down count mode can be configured on-the-fly by the SMMR register. When GCEN0 is written to 1, channels 0 and 1 outputs are driven with gray counter. Figure 33-6. 2-bit Gray Up/Down Counter GCEN0 = 1 PWMH0 PWML0 PWMH1 PWML1 DOWNx 33.6.2.4 Dead-Time Generator The dead-time generator uses the comparator output OCx to provide the two complementary outputs DTOHx and DTOLx, which allows the PWM to drive external power control switches safely. When the dead-time generator is enabled by writing a one to the DTE bit in the "Channel Mode Register" on page 1031 (CMRx), dead-times (also called dead-bands or non-overlapping times) are inserted between the edges of the two complementary outputs DTOHx and DTOLx. Note that enabling or disabling the dead-time generator is allowed only if the channel is disabled. The dead-time is adjustable by the "Channel Dead Time Register" on page 1040 (DTx), both outputs of the dead-time generator can be adjusted separately by DTH and DTL. The dead-time values can be updated synchronously to the PWM period by using the "Channel Dead Time Update Register" on page 1041 (DTUPDx). The dead-time is based on a specific counter which uses the same selected clock that feeds the channel counter of the comparator. Depending on the edge and the configuration of the deadtime, DTOHx and DTOLx are delayed until the counter has reached the value defined by DTH or DTL. An inverted configuration bit (DTHI and DTLI bits in the CMRx register) is provided for each outputs to invert the dead-times outputs. The following figure shows the waveform of the deadtime generator. 969 32117A-10/2010 AT32UC3C Figure 33-7. Complementary Output Waveforms output waveform OCx CPOLx = 0 output waveform DTOHx DTHIx = 0 output waveform DTOLx DTLIx = 0 output waveform DTOHx DTHIx = 1 output waveform DTOLx DTLIx = 1 DTHx DTLx DTHx DTLx output waveform OCx CPOLx = 1 output waveform DTOHx DTHIx = 0 output waveform DTOLx DTLIx = 0 output waveform DTOHx DTHIx = 1 output waveform DTOLx DTLIx = 1 970 32117A-10/2010 AT32UC3C 33.6.2.5 Output Override The two complementary outputs DTOHx and DTOLx of the dead-time generator can be forced to a value defined by the software. Figure 33-8. Override Output Selection DTOHx 0 OOOHx OOVHx 1 OSHx DTOLx 0 OOOLx OOVLx 1 OSLx The OSHx and OSLx fields in the "Output Selection Register" on page 1011 (OS) allow the outputs of the dead-time generator DTOHx and DTOLx to be overridden by the value defined in the OOVHx and OOVLx fields in the"Output Override Value Register" on page 1010 (OOV). The set registers "Output Selection Set Register" on page 1012 and "Output Selection Set Update Register" on page 1014 (OSS and OSSUPD) enable the override of the outputs of a channel regardless of other channels. In the same way, the clear registers "Output Selection Clear Register" on page 1013 and "Output Selection Clear Update Register" on page 1015 (OSC and OSCUPD) disable the override of the outputs of a channel regardless of other channels. By using buffer OSSUPD and OSCUPD registers, the output selection of PWM outputs is done synchronously to the channel counter, at the beginning of the next PWM period. By using OSS and OSC registers, the output selection of PWM outputs is done asynchronously to the channel counter, as soon as the register is written. The value of the current output selection can be read in OS. While overriding PWM outputs, the channel counters continue to run, only the PWM outputs are forced to user defined values. 971 32117A-10/2010 AT32UC3C 33.6.2.6 Fault Protection 5 inputs provide fault protection which can force any of the PWM output pair to a programmable value. This mechanism has priority over output overriding. Figure 33-9. Fault Protection 0 fault input 0 Glitch Filter FIV0 1 = 0 FMOD0 SET OUT Fault 0 Status FS0 FPEx[0] CLR FPE0[0] FFIL0 0 fault input 1 Glitch Filter FIV1 1 Write FCLR0 at 1 FPOL0 = FMOD0 0 FMOD1 SET OUT Fault 1 Status FS1 FPEx[1] FPE0[1] FPOL1 Write FCLR1 at 1 0 1 SYNCx from fault 1 1 CLR FFIL1 from fault 0 1 FMOD1 From Output Override OOHx 0 FPVHx 1 PWMHx 0 Fault protection on PWM channel x 1 from fault y SYNCx fault input y FPVLx 1 OOLx From Output Override 0 PWMLx The polarity level of the faults inputs are configured by the FPOL field in the "Fault Mode Register" on page 1016 (FMR). The fault inputs can be glitch filtered or not in function of the FFIL field in the FMR register. When the filter is enabled, glitches on fault inputs with a width inferior to the PWM internal clock (CCK) period are rejected. A fault becomes active as soon as its corresponding fault input has a transition to the programmed polarity level. If the corresponding FMOD bit is written to zero in the FMR register, the fault remains active as long as the fault input is at this polarity level. If the corresponding bit FMOD is written to one, the fault remains active until the fault input is not at this polarity level anymore AND until it is cleared by writing the corresponding FCLR bit in the "Fault Clear Register" on page 1018 (FSCR). By reading the "Fault Status ReSister" on page 1017 (FSR), the user can read the current level of the fault inputs thanks to the FIV field, and can know which fault is currently active thanks to the FS field. Each fault can be taken into account or not by the fault protection mechanism in each channel. To be taken into account in the channel x, the fault y must be enabled by the FPEx[y] bit in the "PWM Fault Protection Enable Registers" (FPE1). However the synchronous channels (see Section 33.6.2.7 on page 974) don't use their own fault enable bits, but those of the channel 0 (FPE0[y] bits). The fault protection on a channel is triggered when this channel is enabled AND when any one of the faults that are enabled for this channel is active. It can be triggered even if the PWM internal clock (CCK) is not running but only by a fault input that is not glitch filtered. When the fault protection is triggered on a channel, the fault protection mechanism forces the channel outputs to the values defined by the FPVHx and FPVLx fields in the "Fault Protection Value Register" on page 1019 (FPV) and leads to a reset of the counter of this channel. The output forcing is made asynchronously to the channel counter. CAUTION: 972 32117A-10/2010 AT32UC3C * To prevent an unexpected activation of the status FSy bit in the FSR register, the FMODy bit can be written to one only if the FPOLy bit has been previously configured to its final value. * To prevent an unexpected activation of the Fault Protection on the channel x, the FPEx[y] bit can be written to one only if the FPOLy bit has been previously configured to its final value. If a comparison unit is enabled (see Section 33.6.3 on page 982) and if a fault is triggered in the channel 0, in this case the comparison cannot match. As soon as the fault protection is triggered on a channel, an interrupt (different from the interrupt generated at the end of the PWM period) can be generated but only if it is enabled and not masked. The interrupt is reset by reading the interrupt status register, even if the fault which has caused the trigger of the fault protection is kept active. 973 32117A-10/2010 AT32UC3C 33.6.2.7 Synchronous Channels Some channels can be linked together as synchronous channels. They have the same source clock, the same period, the same alignment and are started together. In this way, their counters are synchronized together. The synchronous channels are defined by the SYNCx bits in the "Sync Channels Mode Register" on page 1001 (SCM). Only one group of synchronous channels is allowed. When a channel is defined as a synchronous channel, the channel 0 is automatically defined as a synchronous channel too, because the channel 0 counter configuration is used by all the synchronous channels. If a channel x is defined as a synchronous channel, it uses the following configuration fields of the channel 0 instead of its own: * CPRE0 field in CMR0 register instead of CPREx field in CMRx register (same source clock) * CPRD0 field in CMR0 register instead of CPRDx field in CMRx register (same period) * CALG0 field in CMR0 register instead of CALGx field in CMRx register (same alignment) Thus writing these fields of a synchronous channel has no effect on the output waveform of this channel (except channel 0 of course). Because counters of synchronous channels must start at the same time, they are all enabled together by enabling the channel 0 (by the CHID0 bit in the ENA register). In the same way, they are all disabled together by disabling the channel 0 (by the CHID0 bit in the DIS register). However, a synchronous channel x different from channel 0 can be enabled or disabled independently from others (by the CHIDx bit in the ENA and DIS registers). Defining a channel as a synchronous channel while it is an asynchronous channel (by writing the SYNCx bit to one while it was at zero) is allowed only if the channel is disabled at this time (CHIDx=0 in SR register). In the same way, defining a channel as an asynchronous channel while it is a synchronous channel (by writing the SYNCx bit to zero while it was at one) is allowed only if the channel is disabled at this time. The UPDM (Update Mode) field in the SCM register allow to select one of the three methods to update the registers of the synchronous channels: * Method 1 (UPDM=0): the period value, the duty-cycle values and the dead-time values must be written by the CPU in their respective update registers (respectively CPRDUPDx, CDTYUPDx and DTUPDx).The update is triggered at the next PWM period as soon as the UPDULOCK bit in the "Sync Channels Update Control Register" on page 1003 (SCUC) is set to 1 (see Section 33.6.2.8 on page 976). * Method 2 (UPDM=1): the period value, the duty-cycle values, the dead-time values and the update period value must be written by the CPU in their respective update registers (respectively CPRDUPDx, CDTYUPDx and DTUPD). The update of the period value and of the dead-time values is triggered at the next PWM period as soon as the UPDULOCK bit in the "Sync Channels Update Control Register" on page 1003 (SCUC) is set to 1. The update of the duty-cycle values and the update period value is triggered automatically after an update period defined by the UPR field in the "Sync Channels Update Period Register" on page 1004 (SCUP) (see Section 33.6.2.9 on page 977). * Method 3 (UPDM=2): same as Method 2 apart from the fact that the duty-cycle values of ALL synchronous channels are written by the Peripheral DMA Controller (PDCA) (see Section 974 32117A-10/2010 AT32UC3C 33.6.2.10 on page 979). The user can choose to synchronize the PDCA transfer request with a comparison match (see Section 33.6.3 on page 982), by the PTRM and PTRCS fields in the SCM register. Table 33-2. Summary of the update of registers of Synchronous Channels UPDM=0 UPDM=1 UPDM=2 Write by the CPU Period Value (CPRDUPDx) Update is triggered at the next PWM period as soon as the UPDULOCK bit is set to 1 Write by the CPU Dead-Time Values (DTUPDx) Update is triggered at the next PWM period as soon as the UPDULOCK bit is set to 1 Write by the CPU Duty-Cycle Values (CDTYUPDx) Update Period Value (SCUPUPD) Write by the CPU Write by the PDCA Update is triggered at the next PWM period as soon as the UPDULOCK bit is set to 1 Update is triggered at the next PWM period as soon as the update period counter has reached the value UPR Not applicable Write by the CPU Not applicable Update is triggered at the next PWM period as soon as the update period counter has reached the value UPR 975 32117A-10/2010 AT32UC3C 33.6.2.8 Method 1: Manual write of duty-cycle values and manual trigger of the update In this mode, the update of the period value, the duty-cycle values and the dead-time values must be made by writing in their respective update registers with the CPU (respectively CPRDUPDx, CDTYUPDx and DTUPDx). To trigger the update, the user must use the UPDULOCK bit of the "Sync Channels Update Control Register" on page 1003 (SCUC) which allows to update synchronously (at the same PWM period) the synchronous channels: * If the UPDULOCK bit is set to 1, the update is done at the next PWM period of the synchronous channels. * If the UPDULOCK bit is not set to 1, the update is locked and cannot be performed. After writing the UPDULOCK bit to 1, it is held at this value until the update occurs, then it is read 0. Sequence for the Method 1: 1. Select the manual write of duty-cycle values and the manual update by writing the UPDM field to zero in the SCM register 2. Define the synchronous channels by the SYNCx bits in the SCM register. 3. Enable the synchronous channels by writing CHID0 in the ENA register. 4. If an update of the period value and/or the duty-cycle values and/or the dead-time values is required, write registers that need to be updated (CPRDUPDx, CDTYUPDx and DTUPDx). 5. Write UPDULOCK to one in SCUC. 6. The update of the registers will occur at the beginning of the next PWM period. At this time the UPDULOCK bit is reset, go to step 4) for new values. Figure 33-10. Method 1 (UPDM=0) CCNT0 CDTYUPD 0x20 0x40 0x20 0x40 0x60 UPDULOCK CDTY 0x60 976 32117A-10/2010 AT32UC3C 33.6.2.9 Method 2: Manual write of duty-cycle values and automatic trigger of the update In this mode, the update of the period value, the duty-cycle values, the dead-time values and the update period value must be made by writing in their respective update registers with the CPU (respectively CPRDUPDx, CDTYUPDx, DTUPDx and SCUPUPD). To trigger the update of the period value and the dead-time values, the user must use the UPDULOCK bit of the "Sync Channels Update Control Register" on page 1003 (SCUC) which allows to update synchronously (at the same PWM period) the synchronous channels: * If the UPDULOCK bit is set to 1, the update is done at the next PWM period of the synchronous channels. * If the UPDULOCK bit is not set to 1, the update is locked and cannot be performed. After writing the UPDULOCK bit to one, it is held at this value until the update occurs, then it is read 0. The update of the duty-cycle values and the update period is triggered automatically after an update period. To configure the automatic update, the user must define a value for the Update Period by the UPR field in the "Sync Channels Update Period Register" on page 1004 (SCUP). The PWM controller waits UPR+1 periods of synchronous channels before updating automatically the duty values and the update period value. The status of the duty-cycle value write is reported in the "Interrupt Status Register 2" on page 1009 (ISR2) by the following bits: * WRDY: this bit is set to 1 when the PWM Controller is ready to receive new duty-cycle values and a new update period value. It is reset to 0 when the ISR2 register is read. Depending on the interrupt mask in the IMR2 register, an interrupt can be generated by these bits. Sequence for the Method 2: 1. Select the manual write of duty-cycle values and the automatic update by writing the UPDM field to one in the SCM register 2. Define the synchronous channels by the SYNCx bits in the SCM register. 3. Define the update period by the UPR field in the SCUP register. 4. Enable the synchronous channels by writing CHID0 in the ENA register. 5. If an update of the period value and/or of the dead-time values is required, write registers that need to be updated (CPRDUPDx, DTUPDx), else go to Step 8. 6. Write UPDULOCK to one in SCUC. 7. The update of these registers will occur at the beginning of the next PWM period. At this moment the UPDULOCK bit is reset, go to Step 5. for new values. 8. If an update of the duty-cycle values and/or the update period is required, check first that write of new update values is possible by polling the WRDY bit (or by waiting for the corresponding interrupt) in the ISR2 register. 9. Write registers that need to be updated (CDTYUPDx, SCUPUPD). 10. The update of these registers will occur at the next PWM period of the synchronous channels when the Update Period is elapsed. Go to Step 8. for new values. 977 32117A-10/2010 AT32UC3C Figure 33-11. Method 2 (UPDM=1) CCNT0 CDTYUPD UPRUPD 0x1 UPR 0x1 UPRCNT 0x0 CDTY 0x20 0x60 0x40 0x20 0x3 0x3 0x1 0x0 0x1 0x0 0x40 0x1 0x0 0x1 0x2 0x3 0x0 0x1 0x2 0x60 WRDY 978 32117A-10/2010 AT32UC3C 33.6.2.10 Method 3: Automatic write of duty-cycle values and automatic trigger of the update In this mode, the update of the duty cycle values is made automatically by the Peripheral DMA Controller (PDCA). The update of the period value, the dead-time values and the update period value must be made by writing in their respective update registers with the CPU (respectively CPRDUPDx, DTUPDx and SCUPUPD). To trigger the update of the period value and the dead-time values, the user must use the UPDULOCK bit which allows to update synchronously (at the same PWM period) the synchronous channels: * If the UPDULOCK bit is set to 1, the update is done at the next PWM period of the synchronous channels. * If the UPDULOCK bit is not set to 1, the update is locked and cannot be performed. After writing the UPDULOCK bit to one, it is held at this value until the update occurs, then it is read 0. The update of the duty-cycle values and the update period value is triggered automatically after an update period. To configure the automatic update, the user must define a value for the Update Period by the UPR field in the "Sync Channels Update Period Register" on page 1004 (SCUP). The PWM controller waits UPR+1 periods of synchronous channels before updating automatically the duty values and the update period value. Using the PDCA removes processor overhead by reducing its intervention during the transfer. This significantly reduces the number of clock cycles required for a data transfer, which improves micro controller performance. The PDCA must write the duty-cycle values in the synchronous channels index order. For example if the channels 0, 1 and 3 are synchronous channels, the PDCA must write the duty-cycle of the channel 0 first, then the duty-cycle of the channel 1, and finally the duty-cycle of the channel 3. The following status are reported in the "Interrupt Status Register 2" on page 1009 (ISR2): * WRDY: this bit is set to 1 when the PWM Controller is ready to receive new duty-cycle values and a new update period value. It is reset to 0 when the ISR2 register is read. The user can choose to synchronize the WRDY bit and the PDCA transfer request with a comparison match (see Section 33.6.3 on page 982), by the PTRM and PTRCS fields in the SCM register. * UNRE: this bit is set to 1 when the update period defined by the UPR field is elapsed while the whole data has not been written by the PDCA. It is reset to 0 when the ISR2 register is read. Depending on the interrupt mask in the IMR2 register, an interrupt can be generated by these bits. 979 32117A-10/2010 AT32UC3C Sequence for Method 3: 1. Select the automatic write of duty-cycle values and automatically update by setting the UPDM field to 2 in the SCM register. 2. Define the synchronous channels by the SYNCx bits in the SCM register. 3. Define the update period by the UPR field in the SCUP register. 4. Define when the WRDY bit and the corresponding PDCA transfer request must be set in the update period by the PTRM bit and the PTRCS field in the SCM register (at the end of the update period or when a comparison matches). 5. Define the PDCA transfer settings for the duty-cycle values and enable it in the PDCA registers 6. Enable the synchronous channels by writing CHID0 in the ENA register. 7. If an update of the period value and/or of the dead-time values is required, write registers that need to be updated (CPRDUPDx, DTUPDx), else go to Step 10. 8. Write UPDULOCK to one in SCUC. 9. The update of these registers will occur at the beginning of the next PWM period. At this moment the UPDULOCK bit is reset, go to Step 7. for new values. 10. If an update of the update period value is required, check first that write of a new update value is possible by polling the WRDY bit (or by waiting for the corresponding interrupt) in the ISR2 register, else go to Step 13. 11. Write register that need to be updated (SCUPUPD). 12. The update of this registers will occur at the next PWM period of the synchronous channels when the Update Period is elapsed. Go to Step 10. for new values. 13. Check the end of the PDCA transfer with the Transfer Complete bit in the PDCA status register. If the transfer is ended define a new PDCA transfer in the PDCA registers, for new duty-cycle values. Go to Step 5. 980 32117A-10/2010 AT32UC3C Figure 33-12. Method 3 (UPDM=2 and PTRM=0) CCNT0 CDTYUPD UPRUPD 0x1 UPR 0x1 UPRCNT 0x0 CDTY 0x60 0x40 0x20 0x80 0xB0 0xA0 0x3 0x3 0x1 0x0 0x1 0x0 0x1 0x1 0x2 0x3 0x0 0x1 0x80 0x60 0x40 0x20 0x0 0x2 0xA0 PDC transfer request WRDY Figure 33-13. Method 3 (UPDM=2 and PTRM=1 and PTRCS=0) CCNT0 CDTYUPD 0x20 UPRUPD 0x1 UPR 0x1 UPRCNT 0x0 CDTY 0x20 0x60 0x40 0x80 0xB0 0xA0 0x3 0x3 0x1 0x0 0x40 0x1 0x0 0x60 0x1 0x0 0x80 0x1 0x2 0x3 0x0 0x1 0x2 0xA0 CMP0 match PDC transfer request WRDY 981 32117A-10/2010 AT32UC3C 33.6.3 PWM Comparison Units The PWM provides 8 independent comparison units able to compare a programmed value with the current value of the channel 0 counter (which is the channel counter of all synchronous channels, Section 33.6.2.7 on page 974). These comparisons are intended to generate pulses on the event lines (used to synchronize ADC, see Section 33.6.4 on page 984), to generate software interrupts and to trigger PDCA transfer requests for the synchronous channels (see Section 33.6.2.10 on page 979). Figure 33-14. Comparison Unit Block Diagram CEN [PWM_CMPxM] fault on channel 0 CV [PWM_CMPxV] CNT [PWM_CCNT0] Comparison x = 1 CNT [PWM_CCNT0] is decrementing = 0 1 CVM [PWM_CMPxV] CALG [PWM_CMR0] CPRCNT [PWM_CMPxM] CTR [PWM_CMPxM] = The comparison x matches when it is enabled by the CEN bit in the "Comparison x Mode Register" on page 1029 (CMPxM for the comparison x) and when the counter of the channel 0 reaches the comparison value defined by the CV field in "Comparison x Value Register" on page 1027 (CMPxV for the comparison x). If the counter of the channel 0 is center aligned (CALG=1 in "Channel Mode Register" on page 1031), the CVM bit (in CMPxV) defines if the comparison is made when the counter is counting up or counting down (in left alignment mode CALG=0, this bit is useless). If a fault is active on the channel 0, the comparison is disabled and cannot match (see Section 33.6.2.6 on page 972). The user can define the periodicity of the comparison x by the CTR and CPR fields (in CMPxV). The comparison is performed periodically once every CPR+1 periods of the counter of the channel 0, when the value of the comparison period counter CPRCNT (in CMPxM) reaches the value defined by CTR. CPR is the maximum value of the comparison period counter CPRCNT. If CPR=CTR=0, the comparison is performed at each period of the counter of the channel 0. The comparison x configuration can be modified while the channel 0 is enabled by using the "PWM Comparison x Mode Update Register" on page 1030 (CMPxMUPD registers for the comparison x). In the same way, the comparison x value can be modified while the channel 0 is enabled by using the "Comparison x Value Update Register" on page 1028 (CMPxVUPD registers for the comparison x). 982 32117A-10/2010 AT32UC3C The update of the comparison x configuration and the comparison x value is triggered periodically after the comparison x update period. It is defined by the CUPR field in the CMPxM. The comparison unit has an update period counter independent from the period counter to trigger this update. When the value of the comparison update period counter CUPRCNT (in CMPxM) reaches the value defined by CUPR, the update is triggered. The comparison x update period CUPR itself can be updated while the channel 0 is enabled by using the CMPxMUPD register. CAUTION: to be taken into account, writing in the CMPxVUPD register must be followed by a write in the CMPxMUPD register. The comparison match and the comparison update can be a source of an interrupt, but only if it is enabled and not masked. These interrupts can be enabled by the "Interrupt Enable Register 2" on page 1006 and disabled by the "Interrupt Disable Register 2" on page 1007. The comparison match interrupt and the comparison update interrupt are reset by reading the "Interrupt Status Register 2" on page 1009. Figure 33-15. Comparison Waveform CCNT0 CVUPD 0x6 0x2 0x6 CVMVUPD CTRUPD 0x1 0x2 CPRUPD 0x1 0x3 CUPRUPD 0x3 0x2 CV 0x6 0x2 CTR 0x1 0x2 CPR 0x1 0x3 CUPR 0x3 0x2 CUPRCNT 0x0 0x1 0x2 0x3 0x0 0x1 0x2 0x0 0x1 0x2 0x0 0x1 CPRCNT 0x0 0x1 0x0 0x1 0x0 0x1 0x2 0x3 0x0 0x1 0x2 0x3 0x6 CVM Comparison Update CMPU Comparison Match CMPM 983 32117A-10/2010 AT32UC3C 33.6.4 PWM Event Lines The PWM provides 2 independent event lines intended to trigger actions in other peripherals (in particular for ADC (Analog to Digital Converter)). A pulse (one cycle of the master clock (CLK_PWM))is generated on an event line, when at least one of the selected comparisons is matching. The comparisons can be selected independently by the CSEL bits in the "Event Line x Register" on page 1021 (ELxMR for the Event Line x). Figure 33-16. Event Line Block Diagram CMPS0 (PWM_ISR2) CSEL0 (PWM_ELxMR) CMPS1 (PWM_ISR2) CSEL1 (PWM_ELxMR) CMPS2 (PWM_ISR2) CSEL2 (PWM_ELxMR) PULSE GENERATOR Event Line x CMPS7 (PWM_ISR2) CSEL7 (PWM_ELxMR) 984 32117A-10/2010 AT32UC3C 33.6.5 PWM Controller Operations 33.6.5.1 Initialization Before enabling the channels, they must have been configured by the software application: * Unlock user interface by writing the WPCMD field in the WPCR Register. * Configuration of the clock generator (DIVA, PREA, DIVB, PREB, CLKSEL in the CLK register if required). After writing CLKSEL to a new value, no write in any PWM registers must be attempted before a delay of 2 master clock periods (CLK_PWM). This is the time needed by the PWM to switch the internal clock (CCK). * Selection of the clock for each channel (CPRE field in the CMRx register) * Configuration of the waveform alignment for each channel (CALG field in the CMRx register) * Selection of the counter event selection (if CALG=1) for each channel (CES field in the CMRx register) * Configuration of the output waveform polarity for each channel (CPOL in the CMRx register) * Configuration of the period for each channel (CPRD in the CPRDx register). Writing in CPRDx register is possible while the channel is disabled. After validation of the channel, the user must use CPRDUPDx register to update CPRDx as explained below. * Configuration of the duty-cycle for each channel (CDTY in the CDTYx register). Writing in CDTYx register is possible while the channel is disabled. After validation of the channel, the user must use CDTYUPDx register to update CDTYx as explained below. * Configuration of the dead-time generator for each channel (DTH and DTL in DTx) if enabled (DTE bit in the CMRx register). Writing in the DTx register is possible while the channel is disabled. After validation of the channel, the user must use DTUPDx register to update DTx * Selection of the synchronous channels (SYNCx in the SCM register) * Selection of the moment when the WRDY bit and the corresponding PDCA transfer request are set (PTRM and PTRCS in the SCM register) * Configuration of the update mode (UPDM in the SCM register) * Configuration of the update period (UPR in the SCUP register) if needed. * Configuration of the comparisons (CMPxV and CMPxM). * Configuration of the event lines (ELxMR). * Configuration of the fault inputs polarity (FPOL in FMR) * Configuration of the fault protection (FMOD and FFIL in FMR, FPV and FPE1) * Enable of the interrupts (writing CHIDx and FCHIDx in IER1 register, and writing WRDYE, UNRE, CMPMx and CMPUx in IER2 register) * Enable of the channels (writing CHIDx in the ENA register) 985 32117A-10/2010 AT32UC3C 33.6.5.2 Source Clock Selection Criteria The large number of source clocks can make selection difficult. The relationship between the value in the "Channel Period Register" on page 1035 (CPRDx) and the "Channel Duty Cycle Register" on page 1033 (CDTYx) can help the user. The event number written in the Period Register gives the PWM accuracy. The Duty-Cycle quantum cannot be lower than 1/CPRDx value. The higher the value of CPRDx, the greater the PWM accuracy. For example, if the user writes 15 (in decimal) in CPRDx, the user is able to write a value between 1 up to 14 in CDTYx Register. The resulting duty-cycle quantum cannot be lower than 1/15 of the PWM period. 33.6.5.3 Changing the Duty-Cycle, the Period and the Dead-Times It is possible to modulate the output waveform duty-cycle, period and dead-times. To prevent unexpected output waveform, the user must use the "Channel Duty Cycle Update Register" on page 1034, the "Channel Period Update Register" on page 1037 and the "Channel Dead Time Update Register" on page 1041 (CDTYUPDx, CPRDUPDx and DTUPDx) to change waveform parameters while the channel is still enabled. * If the channel is an asynchronous channel (SYNCx=0 in "Sync Channels Mode Register" on page 1001 (SCM)), these registers hold the new period, duty-cycle and dead-times values until the end of the current PWM period and update the values for the next period. * If the channel is a synchronous channel and update method 0 is selected (SYNCx=1 and UPDM=0 in SCM register), these registers hold the new period, duty-cycle and dead-times values until the UPDULOCK bit is written to one (in "Sync Channels Update Control Register" on page 1003 (SCUC)) and the end of the current PWM period, then update the values for the next period. * If the channel is a synchronous channel and update method 1 or 2 is selected (SYNCx=1 and UPDM=1 or 2 in SCM register): - these CPRDUPDx and DTUPDx registers hold the new period and dead-times values until the UPDULOCK bit is written to one (in SCUC register) and the end of the current PWM period, then update the values for the next period. - the CDTYUPDx register holds the new duty-cycle value until the end of the update period of synchronous channels (when UPRCNT is equal to UPR in "Sync Channels Update Period Register" on page 1004 (SCUP)) and the end of the current PWM period, then updates the value for the next period Note: 33.6.5.4 If the update registers (CDTYUPDx, CPRDUPDx and DTUPDx) are written several times between two updates, only the last written value is taken into account. Changing the Synchronous Channels Update Period It is possible to change the update period of synchronous channels (see Section 33.6.2.9 on page 977 and Section 33.6.2.10 on page 979) while they are enabled. To prevent an unexpected update of the synchronous channels registers, the user must use the "Sync Channels Update Period Update Register" on page 1005 (SCUPUPD) to change the update period of synchronous channels while they are still enabled. This register holds the new value until the end of the update period of synchronous channels (when UPRCNT is equal to 986 32117A-10/2010 AT32UC3C UPR in "Sync Channels Update Period Register" on page 1004 (SCUP)) and the end of the current PWM period, then updates the value for the next period. 33.6.5.5 Note: If the SCUPUPD update register is written several times between two updates, only the last written value is taken into account. Note: Changing the update period does make sense only if there is one or more synchronous channels and if the update method 1 or 2 is selected (UPDM=1 or 2 in "Sync Channels Mode Register" on page 1001). Changing the Comparison Value and the Comparison Configuration It is possible to change the comparison values and the comparison configurations while the channel 0 is enabled (see Section 33.6.3 on page 982). To prevent unexpected comparison match, the user must use the "Comparison x Value Update Register" on page 1028 and the "PWM Comparison x Mode Update Register" on page 1030 (CMPxVUPD and CMPxMUPD) to change respectively the comparison values and the comparison configurations while the channel 0 is still enabled. These registers hold the new values until the end of the comparison update period (when CUPRCNT is equal to CUPR in "Comparison x Mode Register" on page 1029 (CMPxM)) and the end of the current PWM period, then update the values for the next period. CAUTION: to be taken into account, the write of the CMPxVUPD register must be followed by a write of the CMPxMUPD register. Note: 33.6.5.6 If the update registers CMPxVUPD and CMPxMUPD are written several times between two updates, only the last written value are taken into account. Interrupts Depending on the interrupt mask in the IMR1 and IMR2 registers, an interrupt can be generated at the end of the corresponding channel period (CHIDx in the ISR1 register), after a fault event (FCHIDx in the ISR1 register), after a comparison match (CMPMx in the ISR2 register), after a comparison update (CMPUx in the ISR2 register) or according to the transfer mode of the synchronous channels (WRDY and UNRE in the ISR2 register). If the interrupt is generated by the CHIDx or FCHIDx bits, the interrupt remains active until a read operation in the ISR1 register occurs. If the interrupt is generated by the WRDY, UNRE, CMPMx or CMPUx bits, the interrupt remains active until a read operation in the ISR2 register occurs. A channel interrupt is enabled by setting the corresponding bit in the IER1 and IER2 registers. A channel interrupt is disabled by setting the corresponding bit in the IDR1 and IDR2 registers. 987 32117A-10/2010 AT32UC3C 33.6.5.7 Write Protect Registers To prevent any single software error that may corrupt PWM behavior, the registers listed below can be write-protected by writing the WPCMD field in the "Write Protect Control Register" on page 1023 (WPCR). They are divided into 6 groups: * Register group 0: - "Clock Register" on page 992 * Register group 1: - "Disable Register" on page 995 * Register group 2: - "Sync Channels Mode Register" on page 1001 - "Channel Mode Register" on page 1031 - "Stepper Motor Mode Register" on page 1022 * Register group 3: - "Channel Period Register" on page 1035 - "Channel Period Update Register" on page 1037 * Register group 4: - "Channel Dead Time Register" on page 1040 - "Channel Dead Time Update Register" on page 1041 * Register group 5: - "Fault Mode Register" on page 1016 - "Fault Protection Value Register" on page 1019 There are two types of Write Protect: * the Write Protect SW, which can be enabled or disabled. * the Write Protect HW, which can just be enabled, only a hardware reset of the PWM controller can disable it. Both Write Protect can be applied independently to a particular register group thanks to the WPCMD and WPRG fields in WPCR register. If at least one of the Write Protect is active, the register group is write-protected. The WPCMD field allows to perform the following actions depending on its value: * 0: Disabling the Write Protect SW of the register groups of which the WPRG bit is at 1. * 1: Enabling the Write Protect SW of the register groups of which the WPRG bit is at 1. * 2: Enabling the Write Protect HW of the register groups of which the WPRG bit is at 1. At any time, the user can know which Write Protect is active in which register group by the WPSWS and WPHWS fields in the "Write Protect Status Register" on page 1025 (WPSR). If a write access in a write-protected register is detected, then the WPVS bit in the WPSR register is set and the WPVSRC field indicates in which register the write access has been attempted, through its address offset without the two LSBs. The WPVS and WPSR fields are automatically reset after reading the WPSR register. 988 32117A-10/2010 AT32UC3C 33.7 User Interface Table 33-3. PWM Register Memory Map(2) Offset Register Register Name 0x000 Clock Register 0x004 Access Reset CLK Read/write 0x00000000 Enable Register ENA Write-only - 0x008 Disable Register DIS Write-only - 0x00C Status Register SR Read-only 0x00000000 0x010 Interrupt Enable Register 1 IER1 Write-only - 0x014 Interrupt Disable Register 1 IDR1 Write-only - 0x018 Interrupt Mask Register 1 IMR1 Read-only 0x00000000 0x01C Interrupt Status Register 1 ISR1 Read-only 0x00000000 0x020 Sync Channels Mode Register SCM Read/write 0x00000000 0x024 Reserved - - 0x028 Sync Channels Update Control Register SCUC Read/Write 0x00000000 0x02C Sync Channels Update Period Register SCUP Read/Write 0x00000000 0x030 Sync Channels Update Period Update Register SCUPUPD Write-only 0x00000000 0x034 Interrupt Enable Register 2 IER2 Write-only - 0x038 Interrupt Disable Register 2 IDR2 Write-only - 0x03C Interrupt Mask Register 2 IMR2 Read-only 0x00000000 0x040 Interrupt Status Register 2 ISR2 Read-only 0x00000000 0x044 Output Override Value Register OOV Read/Write 0x00000000 0x048 Output Selection Register OS Read/Write 0x00000000 0x04C Output Selection Set Register OSS Write-only - 0x050 Output Selection Clear Register OSC Write-only - 0x054 Output Selection Set Update Register OSSUPD Write-only - 0x058 Output Selection Clear Update Register OSCUPD Write-only - 0x05C Fault Mode Register FMR Read/Write 0x00000000 0x060 Fault Status Register FSR Read-only 0x00000000 0x064 Fault Clear Register FCR Write-only - 0x068 Fault Protection Value Register FPV Read/Write 0x00000000 0x6C Fault Protection Enable Register FPE Read/Write 0x00000000 0x070-0x078 Reserved - - 0x07C Event Line 0 Mode Register EL0MR Read/Write 0x00000000 0x080 Event Line 1 Mode Register EL1MR Read/Write 0x00000000 0x084 - 0x0E0 Reserved - - 0x0B0 PWM Stepper Motor Mode Register Read/Write 0x000000000 0x0B4 - 0x0E0 Reserved - - - - - SMMR - 989 32117A-10/2010 AT32UC3C Table 33-3. PWM Register Memory Map(2) Offset Register Register Name 0x0E4 Write Protect Control Register 0x0E8 Write Protect Status Register 0x0EC - 0x0F8 Reserved 0x0FC Version Register 0x100 - 0x12C Reserved 0x130 Comparison 0 Value Register 0x134 Access Reset WPCR Write-only - WPSR Read-only 0x000000000 - - Read-only 0x- (1) - - CMP0V Read/Write 0x000000000 Comparison 0 Value Update Register CMP0VUPD Write-only - 0x138 Comparison 0 Mode Register CMP0M Read/Write 0x000000000 0x13C Comparison 0 Mode Update Register CMP0MUPD Write-only - 0x140 Comparison 1 Value Register CMP1V Read/Write 0x000000000 0x144 Comparison 1 Value Update Register CMP1VUPD Write-only - 0x148 Comparison 1 Mode Register CMP1M Read/Write 0x000000000 0x14C Comparison 1 Mode Update Register CMP1MUPD Write-only - 0x150 Comparison 2 Value Register CMP2V Read/Write 0x000000000 0x154 Comparison 2 Value Update Register CMP2VUPD Write-only - 0x158 Comparison 2 Mode Register CMP2M Read/Write 0x000000000 0x15C Comparison 2 Mode Update Register CMP2MUPD Write-only - 0x160 Comparison 3 Value Register CMP3V Read/Write 0x000000000 0x164 Comparison 3 Value Update Register CMP3VUPD Write-only - 0x168 Comparison 3 Mode Register CMP3M Read/Write 0x000000000 0x16C Comparison 3 Mode Update Register CMP3MUPD Write-only - 0x170 Comparison 4 Value Register CMP4V Read/Write 0x000000000 0x174 Comparison 4 Value Update Register CMP4VUPD Write-only - 0x178 Comparison 4 Mode Register CMP4M Read/Write 0x000000000 0x17C Comparison 4 Mode Update Register CMP4MUPD Write-only - 0x180 Comparison 5 Value Register CMP5V Read/Write 0x000000000 0x184 Comparison 5 Value Update Register CMP5VUPD Write-only - 0x188 Comparison 5 Mode Register CMP5M Read/Write 0x000000000 0x18C Comparison 5 Mode Update Register CMP5MUPD Write-only - 0x190 Comparison 6 Value Register CMP6V Read/Write 0x000000000 0x194 Comparison 6 Value Update Register CMP6VUPD Write-only - 0x198 Comparison 6 Mode Register CMP6M Read/Write 0x000000000 0x19C Comparison 6 Mode Update Register CMP6MUPD Write-only - 0x1A0 Comparison 7 Value Register CMP7V Read/Write 0x000000000 0x1A4 Comparison 7 Value Update Register CMP7VUPD Write-only - - VERSION - 990 32117A-10/2010 AT32UC3C Table 33-3. PWM Register Memory Map(2) Offset Register Register Name Access Reset 0x1A8 Comparison 7 Mode Register CMP7M Read/Write 0x000000000 0x1AC Comparison 7 Mode Update Register CMP7MUPD Write-only - 0x1B0 - 0x1FC Reserved - - - 0x200 + ch_num * 0x20 + 0x00 Channel Mode Register CMR Read/Write 0x000000000 0x200 + ch_num * 0x20 + 0x04 Channel Duty Cycle Register CDTY Read/Write 0x000000000 0x200 + ch_num * 0x20 + 0x08 Channel Duty Cycle Update Register CDTYUPD Write-only - 0x200 + ch_num * 0x20 + 0x0C Channel Period Register CPRD Read/Write 0x000000000 0x200 + ch_num * 0x20 + 0x10 Channel Period Update Register CPRDUPD Write-only - 0x200 + ch_num * 0x20 + 0x14 Channel Counter Register CCNT Read-only 0x000000000 0x200 + ch_num * 0x20 + 0x18 Channel Dead Time Register DT Read/Write 0x000000000 0x200 + ch_num * 0x20 + 0x1C Channel Dead Time Update Register DTUPD Write-only - Note: 1. The reset values are device specific. Please refer to the Module Configuration section at the end of this chapter. 2. Some registers are indexed with "ch_num" index ranging from 0 to 3. 991 32117A-10/2010 AT32UC3C 33.7.1 Name: Clock Register CLK Access Type: Read/Write Offset: 0x000 Reset Value: 0x00000000 31 30 29 28 CLKSEL - - - 23 22 21 20 27 26 25 24 PREB 19 18 17 16 11 10 9 8 1 0 DIVB 15 14 13 12 - - - - 7 6 5 4 PREA 3 2 DIVA This register can only be written if the WPSWS0 and WPHWS0 bits are cleared in "Write Protect Status Register" on page 1025. * CLKSEL: CCK Source Clock Selection 0: The PWM internal clock CCK is driven by the master clock CLK_PWM. 1: The PWM internal clock CCK is driven by the generic clock GCLK. CAUTION: After writing CLKSEL to a new value, no write to any PWM registers must be attempted before a delay of 2 master clock periods (CLK_PWM). This is the time needed by the PWM to switch the internal clock CCK. 992 32117A-10/2010 AT32UC3C * PREA, PREB: CLKA, CLKB Source Clock Selection Table 33-4. Source Clock Selection PREA, PREB Divider Input Clock 0 CCK 1 CCK/2 2 CCK/4 3 CCK/8 4 CCK/16 5 CCK/32 6 CCK/64 7 CCK/128 8 CCK/256 9 CCK/512 10 CCK/1024 Other Reserved * DIVA, DIVB: CLKA, CLKB Divide Factor Table 33-5. Divide Factor DIVA/DIVB CLKA/CLKB 0 CLKA/CLKB clock is turned off 1 CLKA/CLKB clock is selected by PREA/PREB 2 - 255 CLKA/CLKB clock is selected by PREA/PREB divided by DIVA/DIVB factor 993 32117A-10/2010 AT32UC3C 33.7.2 Name: Enable Register ENA Access Type: Write-only Offset: 0x004 Reset Value: - 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 - - - - - - - - 7 6 5 4 3 2 1 0 - - - - CHID3 CHID2 CHID1 CHID0 * CHIDx: Channel ID Writing a zero to this bit has no effect. Writing a one to this bit will enable the PWM output for channel x. 994 32117A-10/2010 AT32UC3C 33.7.3 Name: Disable Register DIS Access Type: Write-only Offset: 0x008 Reset Value: - 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 - - - - - - - - 7 6 5 4 3 2 1 0 - - - - CHID3 CHID2 CHID1 CHID0 This register can only be written if the WPSWS1 and WPHWS1 bits are cleared in "Write Protect Status Register" on page 1025. * CHIDx: Channel ID Writing a zero to this bit has no effect. Writing a one to this bit will disable the PWM output for channel x. 995 32117A-10/2010 AT32UC3C 33.7.4 Name: Status Register SR Access Type: Read-only Offset: 0x00C Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 - - - - - - - - 7 6 5 4 3 2 1 0 - - - - CHID3 CHID2 CHID1 CHID0 * CHIDx: Channel ID 0: PWM output for channel x is disabled. 1: PWM output for channel x is enabled. 996 32117A-10/2010 AT32UC3C 33.7.5 Name: Interrupt Enable Register 1 IER1 Access Type: Write-only Offset: 0x010 Reset Value: - 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - FCHID3 FCHID2 FCHID1 FCHID0 15 14 13 12 11 10 9 8 - - - - - - - - 7 6 5 4 3 2 1 0 - - - - CHID3 CHID2 CHID1 CHID0 Writing a zero to a bit in this register has no effect. Writing a one to a bit in this register will set the corresponding bit in IMR. 997 32117A-10/2010 AT32UC3C 33.7.6 Name: Interrupt Disable Register 1 IDR1 Access Type: Write-only Offset: 0x014 Reset Value: - 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - FCHID3 FCHID2 FCHID1 FCHID0 15 14 13 12 11 10 9 8 - - - - - - - - 7 6 5 4 3 2 1 0 - - - - CHID3 CHID2 CHID1 CHID0 Writing a zero to a bit in this register has no effect. Writing a one to a bit in this register will clear the corresponding bit in IMR. 998 32117A-10/2010 AT32UC3C 33.7.7 Name: Interrupt Mask Register 1 IMR1 Access Type: Read-only Offset: 0x018 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - FCHID3 FCHID2 FCHID1 FCHID0 15 14 13 12 11 10 9 8 - - - - - - - - 7 6 5 4 3 2 1 0 - - - - CHID3 CHID2 CHID1 CHID0 0: The corresponding interrupt is disabled. 1: The corresponding interrupt is enabled. A bit in this register is cleared when the corresponding bit in IDR is written to one. A bit in this register is set when the corresponding bit in IER is written to one. 999 32117A-10/2010 AT32UC3C 33.7.8 Name: Interrupt Status Register 1 ISR1 Access Type: Read-only Offset: 0x01C Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - FCHID3 FCHID2 FCHID1 FCHID0 15 14 13 12 11 10 9 8 - - - - - - - - 7 6 5 4 3 2 1 0 - - - - CHID3 CHID2 CHID1 CHID0 * FCHIDx: Fault Protection Trigger on Channel x 0: No new trigger of the fault protection since the last read of the ISR1 register. 1: At least one trigger of the fault protection since the last read of the ISR1 register. * CHIDx: Counter Event on Channel x 0: No new counter event has occurred since the last read of the ISR1 register. 1: At least one counter event has occurred since the last read of the ISR1 register. Note: Reading ISR1 automatically clears CHIDx and FCHIDx. 1000 32117A-10/2010 AT32UC3C 33.7.9 Name: Sync Channels Mode Register SCM Access Type: Read/Write Offset: 0x020 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 PTRM - - PTRCS UPDM 15 14 13 12 11 10 9 8 - - - - - - - - 7 6 5 4 3 2 1 0 - - - - SYNC3 SYNC2 SYNC1 SYNC0 This register can only be written if the WPSWS2 and WPHWS2 bits are cleared in "Write Protect Status Register" on page 1025. * PTRCS: PDCA Transfer Request Comparison Selection Selection of the comparison used to set the WRDY bit and the corresponding PDCA transfer request. * PTRM: PDCA Transfer Request Mode Table 33-6. WRDY bit and PDCA Transfer Request UPDM PTRM WRDY bit and PDCA Transfer Request 0 x The WRDY bit in "Interrupt Status Register 2" on page 1009 and the PDCA transfer request are never set to 1. 1 x The WRDY bit in "Interrupt Status Register 2" on page 1009 is set to 1 as soon as the update period is elapsed, the PDCA transfer is never requested. 0 The WRDY bit in "Interrupt Status Register 2" on page 1009 and the PDCA transfer is requested as soon as the update period is elapsed. 1 The WRDY bit in "Interrupt Status Register 2" on page 1009 and the PDCA transfer is requested as soon as the selected comparison matches. 2 * UPDM: Synchronous Channels Update Mode 0: Manual write of double buffer registers and manual update of synchronous channels. The update occurs at the beginning of the next PWM period, when the UPDULOCK bit in "Sync Channels Update Control Register" on page 1003 is set. 1: Manual write of double buffer registers and automatic update of synchronous channels. The update occurs when the Update Period is elapsed. 2: Automatic write of duty-cycle update registers by the PDCA and automatic update of synchronous channels. The update occurs when the Update Period is elapsed. 3: Reserved. 1001 32117A-10/2010 AT32UC3C * SYNCx: Synchronous Channel x 0: Channel x is not a synchronous channel. 1: Channel x is a synchronous channel. 1002 32117A-10/2010 AT32UC3C 33.7.10 Name: Sync Channels Update Control Register SCUC Access Type: Read/Write Offset: 0x028 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 - - - - - - - - 7 6 5 4 3 2 1 0 - - - - - - - UPDULOCK * UPDULOCK: Synchronous Channels Update Unlock 0: No effect 1: If the UPDM field is set to "0" in "Sync Channels Mode Register" on page 1001, writing the UPDULOCK bit to one will trigger the update of the period value, the duty-cycle and the dead-time values of synchronous channels at the beginning of the next PWM period. If the UPDM field is set to "1" or "2", writing the UPDULOCK bit to one will trigger only the update of the period value and the dead-time values of synchronous channels. This bit is automatically reset when the update is done. 1003 32117A-10/2010 AT32UC3C 33.7.11 Name: Sync Channels Update Period Register SCUP Access Type: Read/Write Offset: 0x02C Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 - - - - - - - - 7 6 5 4 3 2 1 0 UPRCNT UPR * UPRCNT: Update Period Counter Reports the value of the Update Period Counter. * UPR: Update Period Defines the time between each update of the synchronous channels if automatic trigger of the update is activated (UPDM=1 of UPDM=2 in "Sync Channels Mode Register" on page 1001). This time is equal to UPR+1 periods of the synchronous channels. 1004 32117A-10/2010 AT32UC3C 33.7.12 Name: Sync Channels Update Period Update Register SCUPUPD Access Type: Write-only Offset: 0x030 Reset Value: - 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 - - - - - - - - 7 6 5 4 3 2 1 0 - - - - UPRUPD This register acts as a double buffer for the UPR value. This prevents an unexpected automatic trigger of the update of synchronous channels. * UPRUPD: Update Period Update Defines the requested time between each update of the synchronous channels if automatic trigger of the update is activated (UPDM=1 of UPDM=2 in "Sync Channels Mode Register" on page 1001). This time is equal to UPR+1 periods of the synchronous channels. 1005 32117A-10/2010 AT32UC3C 33.7.13 Name: Interrupt Enable Register 2 IER2 Access Type: Write-only Offset: 0x034 Reset Value: - 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 CMPU7 CMPU6 CMPU5 CMPU4 CMPU3 CMPU2 CMPU1 CMPU0 15 14 13 12 11 10 9 8 CMPM7 CMPM6 CMPM5 CMPM4 CMPM3 CMPM2 CMPM1 CMPM0 7 6 5 4 3 2 1 0 - - - - UNRE - - WRDY Writing a zero to a bit in this register has no effect. Writing a one to a bit in this register will set the corresponding bit in IMR. 1006 32117A-10/2010 AT32UC3C 33.7.14 Name: Interrupt Disable Register 2 IDR2 Access Type: Write-only Offset: 0x038 Reset Value: - 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 CMPU7 CMPU6 CMPU5 CMPU4 CMPU3 CMPU2 CMPU1 CMPU0 15 14 13 12 11 10 9 8 CMPM7 CMPM6 CMPM5 CMPM4 CMPM3 CMPM2 CMPM1 CMPM0 7 6 5 4 3 2 1 0 - - - - UNRE - - WRDY Writing a zero to a bit in this register has no effect. Writing a one to a bit in this register will clear the corresponding bit in IMR. 1007 32117A-10/2010 AT32UC3C 33.7.15 Name: Interrupt Mask Register 2 IMR2 Access Type: Read-only Offset: 0x03C Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 CMPU7 CMPU6 CMPU5 CMPU4 CMPU3 CMPU2 CMPU1 CMPU0 15 14 13 12 11 10 9 8 CMPM7 CMPM6 CMPM5 CMPM4 CMPM3 CMPM2 CMPM1 CMPM0 7 6 5 4 3 2 1 0 - - - - UNRE - - WRDY 0: The corresponding interrupt is disabled. 1: The corresponding interrupt is enabled. A bit in this register is cleared when the corresponding bit in IDR is written to one. A bit in this register is set when the corresponding bit in IER is written to one. 1008 32117A-10/2010 AT32UC3C 33.7.16 Name: Interrupt Status Register 2 ISR2 Access Type: Read-only Offset: 0x040 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 CMPU7 CMPU6 CMPU5 CMPU4 CMPU3 CMPU2 CMPU1 CMPU0 15 14 13 12 11 10 9 8 CMPM7 CMPM6 CMPM5 CMPM4 CMPM3 CMPM2 CMPM1 CMPM0 7 6 5 4 3 2 1 0 - - - - UNRE - - WRDY * CMPUx: Comparison x Update 0: The comparison x has not been updated since the last read of the ISR2 register. 1: The comparison x has been updated at least one time since the last read of the ISR2 register. * CMPMx: Comparison x Match 0: The comparison x has not matched since the last read of the ISR2 register. 1: The comparison x has matched at least one time since the last read of the ISR2 register. * UNRE: Synchronous Channels Update Underrun Error 0: No Synchronous Channels Update Underrun has occurred since the last read of the ISR2 register. 1: At least one Synchronous Channels Update Underrun has occurred since the last read of the ISR2 register. * WRDY: Write Ready for Synchronous Channels Update 0: New duty-cycle and dead-time values for the synchronous channels cannot be written. 1: New duty-cycle and dead-time values for the synchronous channels can be written. Note: Reading ISR2 automatically clears WRDY, UNRE and CMPSx. 1009 32117A-10/2010 AT32UC3C 33.7.17 Name: Output Override Value Register OOV Access Type: Read/Write Offset: 0x044 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - OOVL3 OOVL2 OOVL1 OOVL0 15 14 13 12 11 10 9 8 - - - - - - - - 7 6 5 4 3 2 1 0 - - - - OOVH3 OOVH2 OOVH1 OOVH0 * OOVLx: Output Override Value for PWML output of the channel x 0: Override value is 0 for PWML output of channel x. 1: Override value is 1 for PWML output of channel x. * OOVHx: Output Override Value for PWMH output of the channel x 0: Override value is 0 for PWMH output of channel x. 1: Override value is 1 for PWMH output of channel x. 1010 32117A-10/2010 AT32UC3C 33.7.18 Name: Output Selection Register OS Access Type: Read/Write Offset: 0x048 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - OSL3 OSL2 OSL1 OSL0 15 14 13 12 11 10 9 8 - - - - - - - - 7 6 5 4 3 2 1 0 - - - - OSH3 OSH2 OSH1 OSH0 * OSLx: Output Selection for PWML output of the channel x 0: Dead-time generator output DTOLx selected as PWML output of channel x. 1: Output override value OOVLx selected as PWML output of channel x. * OSHx: Output Selection for PWMH output of the channel x 0: Dead-time generator output DTOHx selected as PWMH output of channel x. 1: Output override value OOVHx selected as PWMH output of channel x. 1011 32117A-10/2010 AT32UC3C 33.7.19 Name: Output Selection Set Register OSS Access Type: Write-only Offset: 0x04C Reset Value: - 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - OSSL3 OSSL2 OSSL1 OSSL0 15 14 13 12 11 10 9 8 - - - - - - - - 7 6 5 4 3 2 1 0 - - - - OSSH3 OSSH2 OSSH1 OSSH0 * OSSLx: Output Selection Set for PWML output of the channel x Writing a zero to this bit has no effect. Writing a one to this bit will override the PWML output of channel x with the OOVLx value. * OSSHx: Output Selection Set for PWMH output of the channel x Writing a zero to this bit has no effect. Writing a one to this bit will override the PWMH output of channel x with the OOVHx value. 1012 32117A-10/2010 AT32UC3C 33.7.20 Name: Output Selection Clear Register OSC Access Type: Write-only Offset: 0x050 Reset Value: - 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - OSCL3 OSCL2 OSCL1 OSCL0 15 14 13 12 11 10 9 8 - - - - - - - - 7 6 5 4 3 2 1 0 - - - - OSCH3 OSCH2 OSCH1 OSCH0 * OSCLx: Output Selection Clear for PWML output of the channel x Writing a zero to this bit has no effect. Writing a one to this bit will override the PWML output of channel x with the DTOLx value. * OSCHx: Output Selection Clear for PWMH output of the channel x Writing a zero to this bit has no effect. Writing a one to this bit will override the PWMH output of channel x with the DTOHx value. 1013 32117A-10/2010 AT32UC3C 33.7.21 Name: Output Selection Set Update Register OSSUPD Access Type: Write-only Offset: 0x054 Reset Value: - 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - OSSUPL3 OSSUPL2 OSSUPL1 OSSUPL0 15 14 13 12 11 10 9 8 - - - - - - - - 7 6 5 4 3 2 1 0 - - - - OSSUPH3 OSSUPH2 OSSUPH1 OSSUPH0 * OSSUPLx: Output Selection Set for PWML output of the channel x Writing a zero to this bit has no effect. Writing a one to this bit will override the PWML output of channel x with the OOVLx value at the beginning of the next channel x PWM period. * OSSUPHx: Output Selection Set for PWMH output of the channel x Writing a zero to this bit has no effect. Writing a one to this bit will override the PWMH output of channel x with the OOVHx value at the beginning of the next channel x PWM period. 1014 32117A-10/2010 AT32UC3C 33.7.22 Name: Output Selection Clear Update Register OSCUPD Access Type: Write-only Offset: 0x058 Reset Value: - 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - OSCUPL3 OSCUPL2 OSCUPL1 OSCUPL0 15 14 13 12 11 10 9 8 - - - - - - - - 7 6 5 4 3 2 1 0 - - - - OSCUPH3 OSCUPH2 OSCUPH1 OSCUPH0 * OSCUPLx: Output Selection Clear for PWML output of the channel x Writing a zero to this bit has no effect. Writing a one to this bit will override the PWML output of channel x with the DTOLx value at the beginning of the next channel x PWM period. * OSCUPHx: Output Selection Clear for PWMH output of the channel x Writing a zero to this bit has no effect. Writing a one to this bit will override the PWMH output of channel x with the DTOHx value at the beginning of the next channel x PWM period. 1015 32117A-10/2010 AT32UC3C 33.7.23 Name: Fault Mode Register FMR Access Type: Read/Write Offset: 0x05C Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 FFIL7 FFIL6 FFIL5 FFIL4 FFIL3 FFIL2 FFIL1 FFIL0 15 14 13 12 11 10 9 8 FMOD7 FMOD6 FMOD5 FMOD4 FMOD3 FMOD2 FMOD1 FMOD0 7 6 5 4 3 2 1 0 FPOL7 FPOL6 FPOL5 FPOL4 FPOL3 FPOL2 FPOL1 FPOL0 This register can only be written if the WPSWS5 and WPHWS5 bits are cleared in "Write Protect Status Register" on page 1025. * FFILy: Fault y Filtering 0: The fault input y is not filtered. 1: The fault input y is filtered. * FMODy: Fault y Activation Mode 0: The fault y is active as long as the fault input x is at FPOLy. 1: The fault y becomes active as soon as the fault input y is at FPOLy level. The fault y stays active until the fault input y is not at FPOLy level AND until it is cleared in "Fault Clear Register" on page 1018. * FPOLy: Fault y Polarity 0: The fault y becomes active when the fault input y is set to 0. 1: The fault y becomes active when the fault input y is set to 1. CAUTION: To prevent an unexpected activation of the FSy bit in the "Fault Status ReSister" on page 1017, the FMODy bit can be set to one only if the FPOLy bit has been previously configured to its final value. 1016 32117A-10/2010 AT32UC3C 33.7.24 Name: Fault Status ReSister FMR Access Type: Read/Write Offset: 0x060 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 FS7 FS6 FS5 FS4 FS3 FS2 FS1 FS0 7 6 5 4 3 2 1 0 FIV7 FIV6 FIV5 FIV4 FIV3 FIV2 FIV1 FIV0 * FSy: Fault y Status 0: The fault y is not currently active. 1: The fault y is currently active. * FIVy: Fault Input y Value 0: The current sampled value of the fault input y is zero (after filtering if enabled). 1: The current sampled value of the fault input y is one (after filtering if enabled). 1017 32117A-10/2010 AT32UC3C 33.7.25 Name: Fault Clear Register FCR Access Type: Write-only Offset: 0x064 Reset Value: - 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 - - - - - - - - 7 6 5 4 3 2 1 0 FCLR7 FCLR6 FCLR5 FCLR4 FCLR3 FCLR2 FCLR1 FCLR0 * FCLRy: Fault y Clear Writing a zero to this bit has no effect. If the FMODy bit is set to one and if the fault input y is not at the level defined by the FPOLy bit, then writing a one to this bit will clear the fault and the fault becomes inactive (FMODy and FPOLy bits are located in "Fault Mode Register" on page 1016), else writing a one to this bit has no effect. 1018 32117A-10/2010 AT32UC3C 33.7.26 Name: Fault Protection Value Register FPV Access Type: Read/Write Offset: 0x068 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - FPVL3 FPVL2 FPVL1 FPVL0 15 14 13 12 11 10 9 8 - - - - - - - - 7 6 5 4 3 2 1 0 - - - - FPVH3 FPVH2 FPVH1 FPVH0 This register can only be written if the WPSWS5 and WPHWS5 bits are cleared in "Write Protect Status Register" on page 1025. * FPVLx: Fault Protection Value for PWML output on channel x 0: PWML output of channel x is forced to 0 when fault occurs. 1: PWML output of channel x is forced to 1 when fault occurs. * FPVHx: Fault Protection Value for PWMH output on channel x 0: PWMH output of channel x is forced to 0 when fault occurs. 1: PWMH output of channel x is forced to 1 when fault occurs. 1019 32117A-10/2010 AT32UC3C 33.7.27 Name: Fault Protection Enable Register FPE Access Type: Read/Write Offset: 0x06C Reset Value: 0x00000000 31 30 29 28 27 26 25 24 19 18 17 16 11 10 9 8 3 2 1 0 FPE3 23 22 21 20 FPE2 15 14 13 12 FPE1 7 6 5 4 FPE0 This register can only be written if the WPSWS5 and WPHWS5 bits are cleared in "Write Protect Status Register" on page 1025. Only the first 5 bits (number of fault input pins) of FPE0, FPE1, FPE2 and FPE3 are significant. * FPEx[y]: Fault Protection Enable with Fault y for channel x 0: Fault y is not used for the Fault Protection of the channel x. 1: Fault y is used for the Fault Protection of the channel x. CAUTION: To prevent an unexpected activation of the Fault Protection, the FPEx[y] bit can be written to one only if the FPOLy bit has been previously configured to its final value in "Fault Mode Register" on page 1016. 1020 32117A-10/2010 AT32UC3C 33.7.28 Name: Event Line x Register ELxMR Access Type: Read/Write Offset: 0x080 + [x * 0x04] Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 - - - - - - - - 7 6 5 4 3 2 1 0 CSEL7 CSEL6 CSEL5 CSEL4 CSEL3 CSEL2 CSEL1 CSEL0 * CSELy: Comparison y Selection 0: A pulse is not generated on the event line x when the comparison y matches. 1: A pulse is generated on the event line x when the comparison y matches. 1021 32117A-10/2010 AT32UC3C 33.7.29 Name: Stepper Motor Mode Register SMMR Access Type: Read/Write Offset: 0x0B0 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - DOWN1 DOWN0 15 14 13 12 11 10 9 8 - - - - - - - - 7 6 5 4 3 2 1 0 - - - - - - GCEN1 GCEN0 * GCENx: Gray Count Enable 0: Disable gray count on PWML[2*x], PWMH[2*x], PWML[2*x+1], PWMH[2*x+1]. 1: Enable gray count on PWML[2*x], PWMH[2*x], PWML[2*x+1], PWMH[2*x+1]. * DOWNx: Down Count 0: Up counter. 1: Down counter. 1022 32117A-10/2010 AT32UC3C 33.7.30 Name: Write Protect Control Register WPCR Access Type: Write-only Offset: 0x0E4 Reset Value: - 31 30 29 28 27 26 25 24 19 18 17 16 11 10 9 8 1 0 WPKEY 23 22 21 20 WPKEY 15 14 13 12 WPKEY 7 6 5 4 3 2 WPRG5 WPRG4 WPRG3 WPRG2 WPRG1 WPRG0 WPCMD * WPKEY: Write Protect Key Should be written at value 0x50574D ("PWM" in ASCII). Writing any other value in this field aborts the write operation of the WPCMD field. Always reads as 0. * WPRGx: Write Protect Register Group x Writing a zero to this bit has no effect. Writing a one to this bit will allow to set the WPCMD command to the register group x. * WPCMD: Write Protect Command This command is performed only if the WPKEY value is correct. 0: Disable the Write Protect SW of the register groups of which the WPRGx bit is set to 1. 1: Enable the Write Protect SW of the register groups of which the WPRGx bit is set to 1. 2: Enable the Write Protect HW of the register groups of which the WPRGx bit is set to 1. 3: No effect. Note: Only a hardware reset of the PWM controller can disable the Write Protect HW. List of register groups: * Register group 0: - "Clock Register" on page 992 * Register group 1: - "Disable Register" on page 995 * Register group 2: - "Sync Channels Mode Register" on page 1001 - "Channel Mode Register" on page 1031 - "Stepper Motor Mode Register" on page 1022 * Register group 3: 1023 32117A-10/2010 AT32UC3C - "Channel Period Register" on page 1035 - "Channel Period Update Register" on page 1037 * Register group 4: - "Channel Dead Time Register" on page 1040 - "Channel Dead Time Update Register" on page 1041 * Register group 5: - "Fault Mode Register" on page 1016 - "Fault Protection Value Register" on page 1019 - 1024 32117A-10/2010 AT32UC3C 33.7.31 Name: Write Protect Status Register WPSR Access Type: Read-only Offset: 0x0E8 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 19 18 17 16 WPVSRC 23 22 21 20 WPVSRC 15 14 13 12 11 10 9 8 - - WPHWS5 WPHWS4 WPHWS3 WPHWS2 WPHWS1 WPHWS0 7 6 5 4 3 2 1 0 WPVS - WPSWS5 WPSWS4 WPSWS3 WPSWS2 WPSWS1 WPSWS0 * WPVSRC: Write Protect Violation Source When WPVS is active, this field indicates the write-protected register (through address offset divided by four) in which a write access has been attempted. * WPHWSx: Write Protect HW Status 0: The Write Protect HW x of the register group x is disabled. 1: The Write Protect HW x of the register group x is enabled. * WPVS: Write Protect Violation Status 0: No Write Protect violation has occurred since the last read of the WPSR register. 1: At least one Write Protect violation has occurred since the last read of the WPSR register. If this violation is an unauthorized attempt to write a protected register, the associated violation is reported into WPVSRC field. * WPSWSx: Write Protect SW Status 0: The Write Protect SW x of the register group x is disabled. 1: The Write Protect SW x of the register group x is enabled. Note: Reading WPSR automatically clears WPVS and WPVSRC fields. 1025 32117A-10/2010 AT32UC3C 33.7.32 Version Register Register Name: VERSION Access Type: Read-only Offset: 0x0FC Reset Value: - 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - 15 14 13 12 11 - - - - 7 6 5 4 MFN 10 9 8 1 0 VERSION 3 2 VERSION * MFN Reserved. No functionality associated. * VERSION Version number of the module. No functionality associated. 1026 32117A-10/2010 AT32UC3C 33.7.33 Name: Comparison x Value Register CMPxV Access Type: Read/Write Offset: 0x130 + [x * 0x10] Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - CVM 23 22 21 20 19 18 17 16 11 10 9 8 3 2 1 0 CV 15 14 13 12 CV 7 6 5 4 CV Only the first 20 bits (channel counter size) of CV field are significant. * CVM: Comparison x Value Mode 0: The comparison x between the counter of the channel 0 and the comparison x value is performed when this counter is incrementing. 1: The comparison x between the counter of the channel 0 and the comparison x value is performed when this counter is decrementing. Note: This bit is useless if the counter of the channel 0 is left aligned (CALG=0 in "Channel Mode Register" on page 1031) * CV: Comparison x Value Defines the comparison x value to be compared with the counter of the channel 0. 1027 32117A-10/2010 AT32UC3C 33.7.34 Name: Comparison x Value Update Register CMPxVUPD Access Type: Write-only Offset: 0x134 + [x * 0x10] Reset Value: - 31 30 29 28 27 26 25 24 - - - - - - - CVMUPD 23 22 21 20 19 18 17 16 11 10 9 8 3 2 1 0 CVUPD 15 14 13 12 CVUPD 7 6 5 4 CVUPD This register acts as a double buffer for the CV and CVM values. This prevents an unexpected comparison x match. Only the first 20 bits (channel counter size) of CVUPD field are significant. * CVMUPD: Comparison x Value Mode Update 0: The comparison x between the counter of the channel 0 and the comparison x value is performed when this counter is incrementing. 1: The comparison x between the counter of the channel 0 and the comparison x value is performed when this counter is decremented. Note: This bit is useless if the counter of the channel 0 is left aligned (CALG=0 in "Channel Mode Register" on page 1031) * CVUPD: Comparison x Value Update Defines the comparison x value to be compared with the counter of the channel 0. CAUTION: to be taken into account, the write of the CMPxVUPD register must be followed by a write of the CMPxMUPD register. 1028 32117A-10/2010 AT32UC3C 33.7.35 Name: Comparison x Mode Register CMPxM Access Type: Read/Write Offset: 0x138 + [x * 0x10] Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 9 8 CUPRCNT 15 14 CUPR 13 12 11 10 CPRCNT 7 6 CPR 5 4 CTR 3 2 1 0 - - - CEN * CUPRCNT: Comparison x Update Period Counter Reports the value of the comparison x update period counter. Note: The CUPRCNT field is read-only. * CUPR: Comparison x Update Period Defines the time between each update of the comparison x mode and the comparison x value. This time is equal to CUPR+1 periods of the channel 0 counter. * CPRCNT: Comparison x Period Counter Reports the value of the comparison x period counter. Note: The CPRCNT field is read-only. * CPR: Comparison x Period Defines the maximum value of the comparison x period counter (CPRCNT). The comparison x value is performed periodically once every CPR+1 periods of the channel 0 counter. * CTR: Comparison x Trigger The comparison x is performed when the value of the comparison x period counter (CPRCNT) reaches the value defined by CTR. * CEN: Comparison x Enable 0: The comparison x is disabled and can not match. 1: The comparison x is enabled and can match. 1029 32117A-10/2010 AT32UC3C 33.7.36 Name: PWM Comparison x Mode Update Register CMPxMUPD Access Type: Write-only Offset: 0x13C + [x * 0x10] Reset Value: - 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - 15 14 13 12 9 8 - - - - 7 6 5 4 CTRUPD CUPRUPD 11 10 CPRUPD 3 2 1 0 - - - CENUPD This register acts as a double buffer for the CEN, CTR, CPR and CUPR values. This prevents an unexpected comparison x match. * CUPRUPD: Comparison x Update Period Update Defines the time between each update of the comparison x mode and the comparison x value. This time is equal to CUPR+1 periods of the channel 0 counter. * CPRUPD: Comparison x Period Update Defines the maximum value of the comparison x period counter (CPRCNT). The comparison x value is performed periodically once every CPR+1 periods of the channel 0 counter. * CTRUPD: Comparison x Trigger Update The comparison x is performed when the value of the comparison x period counter (CPRCNT) reaches the value defined by CTR. * CENUPD: Comparison x Enable Update 0: The comparison x is disabled and can not match. 1: The comparison x is enabled and can match. 1030 32117A-10/2010 AT32UC3C 33.7.37 Name: Channel Mode Register CMR Access Type: Read/Write Offset: 0x200 + [ch_num * 0x20] Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - DTLI DTHI DTE 15 14 13 12 11 10 9 8 - - - - - CES CPOL CALG 7 6 5 4 3 2 1 0 - - - - CPRE This register can only be written if the WPSWS2 and WPHWS2 bits are cleared in "Write Protect Status Register" on page 1025. * DTLI: Dead-Time PWMLx Output Inverted 0: The dead-time PWMLx output is not inverted. 1: The dead-time PWMLx output is inverted. * DTHI: Dead-Time PWMHx Output Inverted 0: The dead-time PWMHx output is not inverted. 1: The dead-time PWMHx output is inverted. * DTE: Dead-Time Generator Enable 0: The dead-time generator is disabled. 1: The dead-time generator is enabled. * CES: Counter Event Selection The CES bit defines when the channel counter event occurs when the period is center aligned (CHIDx in the "Interrupt Status Register 1" on page 1000). CALG=0 (Left Alignment): 0/1: The channel counter event occurs at the end of the PWM period. CALG=1 (Center Alignment): 0: The channel counter event occurs at the end of the PWM period. 1: The channel counter event occurs at the end of the PWM period and at half the PWM period. * CPOL: Channel Polarity 0: The OCx output waveform (output from the comparator) starts at a low level. 1: The OCx output waveform (output from the comparator) starts at a high level. * CALG: Channel Alignment 0: The period is left aligned. 1: The period is center aligned. 1031 32117A-10/2010 AT32UC3C * CPRE: Channel Pre-scaler Table 33-7. Channel Pre-scaler CPRE Channel Pre-scaler 0 CCK 1 CCK/2 2 CCK/4 3 CCK/8 4 CCK/16 5 CCK/32 6 CCK/64 7 CCK/128 8 CCK/256 9 CCK/512 10 CCK/1024 11 CLKA 12 CLKB Other Reserved 1032 32117A-10/2010 AT32UC3C 33.7.38 Name: Channel Duty Cycle Register CDTY Access Type: Read/Write Offset: 0x204 + [ch_num * 0x20] Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 11 10 9 8 3 2 1 0 CDTY 15 14 13 12 CDTY 7 6 5 4 CDTY Only the first 20 bits (channel counter size) are significant. * CDTY: Channel Duty-Cycle Defines the waveform duty-cycle. This value must be defined between 0 and CPRD (CPRx). 1033 32117A-10/2010 AT32UC3C 33.7.39 Name: Channel Duty Cycle Update Register CDTYUPD Access Type: Write-only Offset: 0x208 + [ch_num * 0x20] Reset Value: - 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 11 10 9 8 3 2 1 0 CDTYUPD 15 14 13 12 CDTYUPD 7 6 5 4 CDTYUPD This register acts as a double buffer for the CDTY value. This prevents an unexpected waveform when modifying the waveform duty-cycle. Only the first 20 bits (channel counter size) are significant. * CDTYUPD: Channel Duty-Cycle Update Defines the waveform duty-cycle. This value must be defined between 0 and CPRD (CPRx). 1034 32117A-10/2010 AT32UC3C 33.7.40 Name: Channel Period Register CPRD Access Type: Read/Write Offset: 0x20C + [ch_num * 0x20] Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 11 10 9 8 3 2 1 0 CPRD 15 14 13 12 CPRD 7 6 5 4 CPRD This register can only be written if the WPSWS3 and WPHWS3 bits are cleared in "Write Protect Status Register" on page 1025. Only the first 20 bits (channel counter size) are significant. * CPRD: Channel Period If the waveform is left-aligned, then the output waveform period depends on the channel counter source clock and can be calculated: - By using the PWM internal clock (CCK) divided by an X given prescaler value (with X being 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, or 1024). The resulting period formula will be: (-----------------------------X x CPRD )CCK - By using the PWM internal clock (CCK) divided by one of both DIVA or DIVB divider, the formula becomes, respectively: (----------------------------------------CRPD x DIVA )( CRPD x DIVB ) or -----------------------------------------CCK CCK If the waveform is center-aligned, then the output waveform period depends on the channel counter source clock and can be calculated: - By using the PWM internal clock (CCK) divided by an X given prescaler value (with X being 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, or 1024). The resulting period formula will be: (---------------------------------------2 x X x CPRD )CCK 1035 32117A-10/2010 AT32UC3C - By using the PWM internal clock (CCK) divided by one of both DIVA or DIVB divider, the formula becomes, respectively: (--------------------------------------------------2 x CPRD x DIVA )( 2 x CPRD x DIVB ) or ---------------------------------------------------CCK CCK 1036 32117A-10/2010 AT32UC3C 33.7.41 Name: Channel Period Update Register CPRDUPD Access Type: Write-only Offset: 0x210 + [ch_num * 0x20] Reset Value: - 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 11 10 9 8 3 2 1 0 CPRDUPD 15 14 13 12 CPRDUPD 7 6 5 4 CPRDUPD This register can only be written if the WPSWS3 and WPHWS3 bits are cleared in "Write Protect Status Register" on page 1025. This register acts as a double buffer for the CPRD value. This prevents an unexpected waveform when modifying the waveform period. Only the first 20 bits (channel counter size) are significant. * CPRDUPD: Channel Period Update If the waveform is left-aligned, then the output waveform period depends on the channel counter source clock and can be calculated: - By using the PWM internal clock (CCK) divided by an X given prescaler value (with X being 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, or 1024). The resulting period formula will be: (-------------------------------------------X x CPRDUPD ) CCK - By using the PWM internal clock (CCK) divided by one of both DIVA or DIVB divider, the formula becomes, respectively: (------------------------------------------------------CRPDUPD x DIVA )( CRPDUPD x DIVB ) or -------------------------------------------------------CCK CCK If the waveform is center-aligned, then the output waveform period depends on the channel counter source clock and can be calculated: - By using the PWM internal clock (CCK) divided by an X given prescaler value (with X being 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, or 1024). The resulting period formula will be: 1037 32117A-10/2010 AT32UC3C (----------------------------------------------------2 x X x CPRDUPD )CCK - By using the PWM internal clock (CCK) divided by one of both DIVA or DIVB divider, the formula becomes, respectively: (---------------------------------------------------------------2 x CPRDUPD x DIVA )( 2 x CPRDUPD x DIVB ) or ----------------------------------------------------------------CCK CCK 1038 32117A-10/2010 AT32UC3C 33.7.42 Name: Channel Counter Register CCNT Access Type: Read-only Offset: 0x214 + [ch_num * 0x20] Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 11 10 9 8 3 2 1 0 CNT 15 14 13 12 CNT 7 6 5 4 CNT Only the first 20 bits (channel counter size) are significant. * CNT: Channel Counter Register Gives the channel counter value. This register is reset when the channel counter reaches the CPRD value defined in the CPRDx register if the waveform is left aligned. 1039 32117A-10/2010 AT32UC3C 33.7.43 Name: Channel Dead Time Register DT Access Type: Read/Write Offset: 0x218 + [ch_num * 0x20] Reset Value: 0x00000000 31 30 29 28 27 26 25 24 19 18 17 16 11 10 9 8 3 2 1 0 DTL 23 22 21 20 DTL 15 14 13 12 DTH 7 6 5 4 DTH This register can only be written if the WPSWS4 and WPHWS4 bits are cleared in "Write Protect Status Register" on page 1025. Only the first 16 bits (dead-time counter size) of DTH and DTL fields are significant. * DTL: Dead-Time Value for PWMLx Output Defines the dead-time value for PWMLx output. This value must be defined between 0 and CDTY (CDTYx). * DTH: Dead-Time Value for PWMHx Output Defines the dead-time value for PWMHx output. This value must be defined between 0 and CPRD-CDTY (CPRx and CDTYx). 1040 32117A-10/2010 AT32UC3C 33.7.44 Name: Channel Dead Time Update Register DTUPD Access Type: Write-only Offset: 0x21C + [ch_num * 0x20] Reset Value: - 31 30 29 28 27 26 25 24 19 18 17 16 11 10 9 8 3 2 1 0 DTLUPD 23 22 21 20 DTLUPD 15 14 13 12 DTHUPD 7 6 5 4 DTHUPD This register can only be written if the WPSWS4 and WPHWS4 bits are cleared in "Write Protect Status Register" on page 1025. This register acts as a double buffer for the DTH and DTL values. This prevents an unexpected waveform when modifying the dead-time values. Only the first 16 bits (dead-time counter size) of DTHUPD and DTLUPD fields are significant. * DTLUPD: Dead-Time Value Update for PWMLx Output Defines the dead-time value for PWMLx output. This value must be defined between 0 and CDTY (CDTYx). This value is applied only at the beginning of the next channel x PWM period. * DTHUPD: Dead-Time Value Update for PWMHx Output Defines the dead-time value for PWMHx output. This value must be defined between 0 and CPRD-CDTY (CPRx and CDTYx). This value is applied only at the beginning of the next channel x PWM period. 1041 32117A-10/2010 AT32UC3C 33.8 Module Configuration The specific configuration for each PWM instance is listed in the following tables. The module bus clocks listed here are connected to the system bus clocks. Please refer to the Power Manager chapter for details. Table 33-8. Module name Clock Name Description PWM CLK_PWM Peripheral Bus clock from the PBA clock domain GCLK The generic clock used for the PWM is GCLK4 Table 33-9. 33.8.1 PWM Clock Name Register Reset Values Register Reset Value VERSION 0x00000501 PWM fault sources The following table define the mapping of the PWM fault sources. For details on PWM faults, see Fault Protection paragraph in the PWM chapter. Table 33-10. PWM fault sources fault input number Description 0 PEVC channel output 8, this fault is only usable when the FMR.FMODy is set to 1. 1 PEVC channel output 9, this fault is only usable when the FMR.FMODy is set to 1. 2 EXT_FAULTS[0] input pin, See Peripheral Multiplexing on I/O line chapter. 3 EXT_FAULTS[1] input pin, See Peripheral Multiplexing on I/O line chapter. 4 clock failure detector of PM, See PM chapter for details. 1042 32117A-10/2010 AT32UC3C 34. Quadrature Decoder (QDEC) Rev.: 1.0.0.0 34.1 Features * Handles three input channels: * * * * * * 34.2 - Two phase signals (QEPA, QEPB) - One index pulse (QEPI) Optional digital filter on inputs 16-bit position counter and 16-bit revolution counter 32-bit timer/counter mode Software trigger or peripheral event trigger Compare function with peripheral event generation Capture function on peripheral event Overview The QDEC is used in rotating motion systems for position and speed detection. It decodes quadrature signals, normally two 90 degrees out-of-phases pulses, into count and direction informations. The quadrature signals are usually generated by a wheel with periodic transparent gaps (a.k.a. lines) and an optical system composed of one light source and 2 sensors. Figure 34-1. Quadrature Signals Description QEPA QEPB QEPI The phase signals are labelled QEPA and QEPB. If QEPA leads QEPB, the rotation direction is defined as positive. If QEPB leads QEPA, the rotation direction is defined as negative. Each time a line passes the sensor, a counter register (CNT.PC) is incremented or decremented depending of the rotation direction. A third input signal, QEPI, can be used to reset CNT.PC. QDEC can count the total number of revolutions. A top value of CNT.PC is written to the Position Counter Top Value in the Top Value register (TOP.PCTOP). When CNT.PC counts up to this value, it wraps around to zero and the Revolution Counter field (CNT.RC) is incremented. CNT.RC is decremented when CNT.PC counts down and crosses the zero value. CNT.PC will then be reset to the value in TOP.PCTOP. 1043 32117A-10/2010 AT32UC3C 34.3 Block Diagram Figure 34-2. QDEC Block Diagram compare event CMP register QCF.FILTEN QEPI QEPB Filter QPulse Filter Advanced filter Filter quadrature decoder DIR CNT = position counter/ revolution counter PB QEPA TOP register CLK_QDEC_INT CAP register Clock Control GCLK_QDEC trigger event 34.4 I/O Lines Description Table 34-1. 34.5 capture event I/O Lines Description Pin Name Pin Description Type QEPA Quadrature phase signal A Input QEPB Quadrature phase signal B Input QEPI Quadrature index signal Input Product Dependencies In order to use this module, other parts of the system must be configured correctly, as described below. 34.5.1 I/O Lines The QDEC pins are multiplexed with other peripherals. The user must first program the I/O Controller to give control of the pins to the QDEC. 1044 32117A-10/2010 AT32UC3C 34.5.2 Power Management If the CPU enters a sleep mode that disables clocks used by the QDEC, the QDEC will stop functioning and resume operation after the system wakes up from sleep mode. 34.5.3 Clocks The QDEC has two clocks connected: One Peripheral Bus clock (CLK_QDEC) and one generic clock (GCLK_QDEC). These clocks are generated by the Power Manager. CLK_QDEC is enabled at reset, and can be disabled in the Power Manager. GCLK_QDEC is used for filtering in QDEC mode and is the timer clock in Timer Mode. It is a generic clock generated by the Power Manager. The programmer must configure the Power Manager to enable GCLK_QDEC. The GCLK_QDEC frequency must less than half the CLK_QDEC clock frequency. 34.5.4 Interrupts The QDEC interrupt request line is connected to the interrupt controller. Using the QDEC interrupt requires the interrupt controller to be programmed first. 34.5.5 Peripheral Events The QDEC peripheral events are connected via the Peripheral Event System. Refer to the Peripheral Event System chapter for details. 34.5.6 Debug Operation When an external debugger forces the CPU into debug mode, the QDEC continues normal operation; the timer is not frozen, but peripheral events are masked. In OCD mode, the timer is not frozen and the events are masked. Reading the CAP register does not clear the reminding of last capture event for the OVR interrupt. If the QDEC 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 QDEC peripheral events are masked during debug operation, unless the Run In Debug bit in the Development Control Register is written to one and the bit corresponding to the QDEC is written to one in the Peripheral Debug Register (PDBG). Please refer to the On-Chip Debug chapter in the AVR32UC Technical Reference Manual, and the OCD Module Configuration section, for details. 34.6 Functional Description 34.6.1 Basic Operation 34.6.1.1 Enabling the QDEC The QDEC is enabled by writing a one to the Clock Enable bit in the Control Register (CTRL.CLKEN). This will also enable the internal CLK_QDEC_INT. This clock is generated from GCLK_QDEC. CLK_QDEC_INT is used in the filter blocks and for clocking the counter in Timer Mode. A software trigger or peripheral event trigger is needed for CLK_QDEC_INT to start. The Clock Enable bit in the Status Register (SR.CLKEN) indicates if the clock is running. 1045 32117A-10/2010 AT32UC3C Figure 34-3. Clock Control PEVC trigger A N D CTRL[CLKEN]= 1 Set Q CTRL[CLKEN]=0 SR[CLKEN] Reset A N D GCLK_QDEC 34.6.1.2 CLK_QDEC_INT Trigger A trigger resets the QDEC counter and starts CLK_QDEC_INT. Two triggers are possible: * * A software trigger, by writing a one to the Software Trigger bit in CTRL (CTRL.SWTRG). Trigger peripheral event from the PEVC: If enabled by writing a one to the Event Trigger Enable bit in the Configuration Register (CF.EVTRGE). The QDEC counter is reset when the peripheral trigger event occurs. 34.6.1.3 Quadrature decoder logic and digital filter The quadrature decoder logic converts the 2-phase signals QEPA and QEPB in a count pulse signal (QPulse) for each transition and a DIR signal to indicate the rotation direction. Figure 34-4. Quadrature Description Increment counter Increment counter {A,B} = 01 (0,0) (1,1) (0,1) Decrement counter (1,0) QEPA 00 QEPB Decrement counter Decrement counter 11 Decrement counter 10 Increment counter Increment counter The QEPI signal may be used to detect a reference position once per revolution. The 3 inputs (QEPA/QEPB/QEPI) can be inverted by writing to appropriate bits in CF. 1046 32117A-10/2010 AT32UC3C 34.6.1.4 Position counter The 16-bit position counter is incremented or decremented on every count pulse, generated by the quadrature decoder module. The counting direction is displayed in SR.CNTDIR. If the position counter reaches the TOP.PCTOP value when counting up or the 0 value when counting down, the counter wraps around. The Position Counter Roll Over (PCRO) interrupt is generated. Usually, the TOP.PCTOP value should always be set to the total number of quadrature states minus one, which is (quadrature_encoder_lines_count *4) -1. 34.6.1.5 Index detection The optional index signal QEPI may be used to correct the position counter if quadrature states have been missed due to noise. If the Index Enable bit (CF.IDXE) is written to one, detection of the QEPI signal will reset the position counter to 0 on a selected phase of quadrature signals. This selected phase is configured via the Detection Phase field (CF.IDXPHS). The Index Error (IDXERR) interrupt is triggered if the index detection occurs and the position counter value is not 0. 34.6.1.6 Revolution counter The revolution counter is incremented/decremented each time the position counter rolls over. It rolls over when it reaches the TOP.RCTOP value. 34.6.1.7 Waveforms Figure 34-5. Quadrature Clock and Direction Decoding (TOP.PCTOP = 4) QEPA QEPB CNTDIR QPulse PC RC 0 1 2 0 3 4 0 1 2 1 1 0 4 3 2 1 0 1047 32117A-10/2010 AT32UC3C Figure 34-6. PC reset by QEPI signal (TOP.PCTOP = 79, CF.IDXPHS ="00", CF.IDXE = "1") QEPA QEPB QEPI QPulse PC RC 72 73 74 0 75 0 1 2 3 2 1 0 1 79 78 77 0 IDXERR 34.6.1.8 Quadrature frequency The CLK_QDEC clock frequency must be at least two times the QEPA and QEPB frequency as these signals are synchronized to the CLK_QDEC clock. To get the maximum available frequency on QEPA/QEPB signals, the filter on inputs should be bypassed. For a 33 MHz peripheral bus clock the maximum QEPA frequency is 16.5 MHz. For a wheel with 8192 lines the maximum rotational speed supported by QDEC is 16.5MHz / 8192 = 2014 rps = 120 849 rpm. 34.6.1.9 34.6.2 Disabling the QDEC The QDEC is disabled by writing a zero to CTRL.CLKEN. Advanced Operation 34.6.2.1 Compare register The Compare register (CMP) is used to generate an interrupt and a peripheral event when the CNT register reaches the value defined in CMP. If RC compare is enabled (CF.RCCE is one), a compare match occurs when RC is equal to RCCMP. A peripheral event is generated and the CMP interrupt line is set if enabled. If the PC compare is enabled (CF.PCCE is one), a compare match occurs when the PC is equal to PCCMP. A peripheral event is generated and the CMP interrupt line is set if enabled. If both RC compare and PC compare are enabled, a compare match occurs when CNT is equal to CMP. A peripheral event is generated and the CMP interrupt line is set if enabled. The compare peripheral event should be mapped through the PEVC to another peripheral. 1048 32117A-10/2010 AT32UC3C 34.6.2.2 Capture register The capture function saves the QDEC counter value in the Capture register (CAP) when a capture event has occurred. The capture function is enabled if the QDEC counter is running. The CAP register will not be updated with a new value if the previous value has not been read. If a capture event occurs and the previous value has not been read, the SR.OVR bit is set. 34.6.2.3 Glitch filter The QDEC inputs (QEPA/QEPB/QEPI) are passed through a glitch filter that is enabled by writing a one to the CF.FILTEN bit. The input sent to the QDEC counter will toggle if the input is stable for three CLK_QDEC_INT periods. 34.6.2.4 Timer/Counter mode QDEC can be used as a 32-bit/counter with compare/capture capabilities. This timer includes an up/down (UPD) mode where the timer counts up or down according to a toggle direction event from the PEVC. The timer/counter is available by writing a zero to the CF.QDEC bit. Timer/Counter mode uses the same resources as QDEC mode: * The CNT QDEC counter * The TOP register to reload the CNT value * The CMP register to generate a compare peripheral event/interrupt * The CAP register to save the CNT value in case of a capture peripheral event occurs * The clock selection * The trigger mechanism It does not use the input filters and the index pulse control. The timer/counter includes an up/down mode that is enabled by writing a one to the CF.UPD bit. 1049 32117A-10/2010 AT32UC3C Figure 34-7. Timer Block Diagram compare event CMP TOP CF.UPD CF.TSDIR CNT DIR up/down control PB toggle direction event CLK_QDEC_INT CAP Clock Control GCLK_QDEC trigger event capture event The user can set the timer count direction by writing to the CF.TSDIR bit. The counting direction is taken into account when a trigger occurs. The counting direction is shown in SR.CNTDIR. The user has to set the initial direction of counting by writing to CF.TSDIR. When the timer is triggered, i.e. each time a toggle direction event occurs, the counter changes counting direction. If the counter reaches 0, it will be stuck at 0 as long as the counting direction is down. 34.6.3 Interrupts The QDEC has one interrupt request line connected to the interrupt controller. The sources of this interrupt are: * The QEPI interrupt to detect the index signal. * The CMP interrupt to detect a compare match. * The CAP interrupt to detect that the QDEC counter value has been saved in the CAP register due to the capture event. * The OVR interrupt to detect that a capture event was received without the CAP register having been read since the last capture event. In OCD mode, reading the CAP register does not clear the memory of the last capture event. * The PCRO interrupt to detect a roll-over of the position counter. In Timer/Counter mode, the roll over occurs when (PC = 0xFFFF and RC != RCTOP), when PC = TOP.PCTOP or when RC = RCTOP. 1050 32117A-10/2010 AT32UC3C * The RCRO interrupt to detect a roll-over of the revolution counter. * The IDXERR interrupt to detect that the index signal (QEPI) is detected and the position counter does not have the expected value (TOP.PCTOP if the counter counts up, 1 if the counter counts down). * The DIRINV interrupt occurs when the count direction changes. * The QDERR interrupt occurs when a bad transition in the quadrature signals is detected (for example, from "00" to "11"). This could be caused by erroneous programming of the GCLK_QDEC frequency. * The TRIGGER interrupt occurs when a trigger event from PEVC is detected. It could be used by software to detect a reset of the counters. * Each interrupt source can be enabled by writing a one to the corresponding bit in the Interrupt Enable Register (IER) and disabled by writing a one to the corresponding bit in the Interrupt Disable Register (IDR). The enable status can be read from the Interrupt Mask Register (IMR). The status of the interrupt sources, even if the interrupt is masked, can be read in SR. When an interrupt has occurred, it is reset by writing a one to the corresponding bit in the Status Clear Register (SCR). 34.6.4 Peripheral Events The QDEC can receive three peripheral events from the Peripheral Event Controller (PEVC): * The trigger peripheral event starts CLK_QDEC_INT and enables the counter. * The capture peripheral event captures CNT in the Capture register (CAP). * The toggle_dir peripheral event toggles the count direction when the QDEC works in Timer mode with UPD mode active. The QDEC can send one event to the PEVC: * The compare peripheral event when the CNT register reaches the Compare register (CMP) value. The PEVC must be programmed to enable QDEC peripheral events. 1051 32117A-10/2010 AT32UC3C 34.7 User Interface Table 34-2. 1. QDEC Register Memory Map Offset Register Register Name Access Reset 0x00 Control Register CTRL Read/Write 0x00000000 0x04 Configuration Register CF Read/Write 0x00000000 0x08 Counter Register CNT Read/Write 0x00000000 0x0C Top Value Register TOP Read/Write 0x00000000 0x10 Compare Register CMP Read/Write 0x00000000 0x14 Capture Register CAP Read-only 0x00000000 0x18 Status Register SR Read-only 0x00000000 0x1C Status Clear Register SCR Write-only 0x00000000 0x20 Interrupt Mask Register IMR Read-only 0x00000000 0x24 Interrupt Enable Register IER Write-only 0x00000000 0x28 Interrupt Disable Register IDR Write-only 0x00000000 0x2C Parameter Register PARAMETER Read-only - (1) 0x30 Version Register VERSION Read-only - (1) The reset values for this register is device specific. Please refer to the Module Configuration section at the end of this chapter. 1052 32117A-10/2010 AT32UC3C 34.7.1 Name: Control Register CTRL Access Type: Read/Write Offset: 0x00 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 - - - - - - - - 7 6 5 4 3 2 1 0 - - - - - - SWTRG CLKEN * SWTRG: Software Trigger Writing a one to this bit generates a software trigger if CTRL.CLKEN is one. This bit always reads as 0. * CLKEN: QDEC Module and Clock Enable Writing a zero to this bit disables the QDEC and CLK_QDEC_INT clock. Writing a one to this bit enables the QDEC and CLK_QDEC_INT clock. 1053 32117A-10/2010 AT32UC3C 34.7.2 Configuration Register Name: CF Access Type: Read/Write Offset: 0x04 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - UPD TSDIR 15 14 13 12 11 10 9 8 - - FILTEN IDXINV PHSINVB PHSINVA 7 6 5 4 3 2 1 0 - - - EVTRGE RCCE PCCE IDXE QDEC IDXPHS * UPD: Up/Down Timer Mode 0: Up/Down functionality in Timer Mode is disabled 1: Up/Down functionality in Timer Mode is ensabled * TSDIR: Timer Set Direction 0: The counters count up in Timer Mode 1: The counters count down in Timer Mode The count direction is updated when a trigger (software or hardware) occurs * FILTEN: Input Digital Filter Enable 0: The input digital filter is disabled 1: The input digital filter is enabled * IDXPHS: QEPI Detection Phase 0: QEPI detection enabled when QEPA signal equals 0 and QEPB signal equals 0 1: QEPI detection enabled when QEPA signal equals 0 and QEPB signal equals 1 2: QEPI detection enabled when QEPA signal equals 1 and QEPB signal equals 0 3: QEPI detection enabled when QEPA signal equals 1 and QEPB signal equals 1 * IDXINV: QEPI Phase 0: QEPI will not be inverted 1: QEPI will be inverted * PHSINVB: QEPB Phase 0: QEPB will not be inverted 1: QEPB will be inverted * PHSINVA: QEPA Phase 0: QEPA will not be inverted 1: QEPA will be inverted * EVTRGE: Event Trigger Enable 0: The event trigger function is disabled 1: The event trigger function is enabled 1054 32117A-10/2010 AT32UC3C * RCCE: Revolution Counter Compare Enable 0: The revolution counter compare is disabled 1: The revolution counter compare is enabled * PCCE: Position Counter Compare Enable 0: The position counter compare is disabled 1: The position counter compare is enabled * IDXE: Index Enable 0: The index signal detection is disabled 1: The index signal detection is enabled * QDEC: QDEC Mode 0: QDEC is in Timer Mode 1: QDEC is in Quadrature Decoder Mode 1055 32117A-10/2010 AT32UC3C 34.7.3 Name: Counter Register CNT Access Type: Read/Write Offset: 0x08 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 19 18 17 16 11 10 9 8 3 2 1 0 RC[15:8] 23 22 21 20 RC[7:0] 15 14 13 12 PC[15:8] 7 6 5 4 PC[7:0] * RC: Revolution Counter The current value of the revolution counter * PC: Position Counter The current value of the position counter 1056 32117A-10/2010 AT32UC3C 34.7.4 Name: Top Register TOP Access Type: Read/Write Offset: 0x10 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 19 18 17 16 11 10 9 8 3 2 1 0 RCTOP[15:8] 23 22 21 20 RCTOP[7:0] 15 14 13 12 PCTOP[15:8] 7 6 5 4 PCTOP[7:0] * RCTOP: Revolution Counter Top Value The top value of the revolution counter * PCTOP: Position Counter Top Value The top value of the position counter 1057 32117A-10/2010 AT32UC3C 34.7.5 Compare Register Name: CMP Access Type: Read/Write Offset: 0x14 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 19 18 17 16 11 10 9 8 3 2 1 0 RCCMP[15:8] 23 22 21 20 RCCMP[7:0] 15 14 13 12 PCCMP[15:8] 7 6 5 4 PCCMP[7:0] * RCCMP: Revolution Counter Compare Value The Revolution Counter value that generates a compare event * PCCMP: Position Counter Compare Value The Position Counter value that generates a compare event 1058 32117A-10/2010 AT32UC3C 34.7.6 Capture Register Name: CAP Access Type: Read-only Offset: 0x18 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 19 18 17 16 11 10 9 8 3 2 1 0 RCCAP[15:8] 23 22 21 20 RCCAP[7:0] 15 14 13 12 PCCAP[15:8] 7 6 5 4 PCCAP[7:0] * RCCAP: Revolution Capture The last capture value of the revolution counter * PCCAP: Position Capture The last capture value of the position counter 1059 32117A-10/2010 AT32UC3C 34.7.7 Status Register Name: SR Access Type: Read-only Offset: 0x1C Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - CLKEN CNTDIR 15 14 13 12 11 10 9 8 - - - - - - TRIGGER QDERR 7 6 5 4 3 2 1 0 OVR DIRINV IDXERR RCRO PCRO CAP CMP QEPI * CLKEN: QDEC Counter Clock Status This bit is cleared when the QDEC and CLK_QDEC_INT has been disabled This bit is set when the QDEC and CLK_QDEC_INT has been enabled * CNTDIR: Counter Direction This bit is cleared when the counter counts up This bit is set when the counter counts down * TRIGGER: Trigger Event Occurrence This bit is cleared when the corresponding bit in SCR is written to one This bit is set when the trigger event has occurred * QDERR: Illegal Quadrature Signals Transition This bit is cleared when the corresponding bit in SCR is written to one This bit is set when an illegal transition of quadrature signals has occurred * OVR: Overrun Capture This bit is cleared when the corresponding bit in SCR is written to one This bit is set when the overrun capture event has occurred * DIRINV: Count Direction Inversion This bit is cleared when the corresponding bit in SCR is written to one This bit is set when the count direction has changed * IDXERR: Index Error This bit is cleared when the corresponding bit in SCR is written to one This bit is set when an index error has occurred * RCRO: Revolution Counter Roll Over This bit is cleared when the corresponding bit in SCR is written to one This bit is set when the revolution counter has rolled over * PCRO: Position Counter Roll Over This bit is cleared when the corresponding bit in SCR is written to one This bit is set when the position counter has rolled over 1060 32117A-10/2010 AT32UC3C * CAP: Counter Capture This bit is cleared when the corresponding bit in SCR is written to one This bit is set when a capture event has occurred * CMP: Counter Compare This bit is cleared when the corresponding bit in SCR is written to one This bit is set when compare match occurred * QEPI: Index Signal Detection This bit is cleared when the corresponding bit in SCR is written to one This bit is set when an index detection has occurred 1061 32117A-10/2010 AT32UC3C 34.7.8 Status Clear Register Name: SCR Access Type: Write-only Offset: 0x20 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 - - - - - - TRIGGER QDERR 7 6 5 4 3 2 1 0 OVR DIRINV IDXERR RCRO PCRO CAP CMP QEPI Writing a zero to a bit in this register has no effect. Writing a one to a bit in this register will clear the corresponding bit in SR and the corresponding interrupt request. 1062 32117A-10/2010 AT32UC3C 34.7.9 Interrupt Mask Register Name: IMR Access Type: Read-only Offset: 0x24 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 - - - - - - TRIGGER QDERR 7 6 5 4 3 2 1 0 OVR DIRINV IDXERR RCRO PCRO CAP CMP QEPI 0: The corresponding interrupt is disabled. 1: The corresponding interrupt is enabled. A bit in this register is cleared when the corresponding bit in IDR is written to one. A bit in this register is set when the corresponding bit in IER is written to one. 1063 32117A-10/2010 AT32UC3C 34.7.10 Interrupt Enable Register Name: IER Access Type: Write-only Offset: 0x28 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 - - - - - - TRIGGER QDERR 7 6 5 4 3 2 1 0 OVR DIRINV IDXERR RCRO PCRO CAP CMP QEPI Writing a zero to a bit in this register has no effect. Writing a one to a bit in this register will set the corresponding bit in IMR. 1064 32117A-10/2010 AT32UC3C 34.7.11 Interrupt Disable Register Name: IDR Access Type: Write-only Offset: 0x2C Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 - - - - - - TRIGGER QDERR 7 6 5 4 3 2 1 0 OVR DIRINV IDXERR RCRO PCRO CAP CMP QEPI Writing a zero to a bit in this register has no effect. Writing a one to a bit in this register will clear the corresponding bit in IMR. 1065 32117A-10/2010 AT32UC3C 34.7.12 Parameter Register Name: PARAMETER Access Type: Read-only Offset: 0x30 Reset Value: - 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 - - - - - - - - 7 6 5 4 3 2 1 0 RCSIZE PCSIZE * RCSIZE: Number of bits -1 in CNT.RC registers * PCSIZE: Number of bits -1 in CNT.PC registers 1066 32117A-10/2010 AT32UC3C 34.7.13 Version Register Name: VERSION Access Type: Read-only Offset: 0x34 Reset Value: - 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - 15 14 13 12 9 8 - - - - 7 6 5 4 VARIANT 11 10 VERSION[11:8] 3 2 1 0 VERSION[7:0] * VARIANT: Variant number Reserved. No functionality associated. * VERSION: Version number Version number of the module. No functionality associated. 1067 32117A-10/2010 AT32UC3C 34.8 Module Configuration The specific configuration for each QDEC instance is listed in the following tables. The module bus clocks listed here are connected to the system bus clocks. Please refer to the Power Manager chapter for details. Table 34-3. QDEC Clock Name Module Name Clock Name Description QDEC0 CLK_QDEC0 Peripheral Bus clock from the PBA clock domain GCLK_QDEC0 The generic clock used for the QDEC0 is GCLK5 CLK_QDEC1 Peripheral Bus clock from the PBA clock domain GCLK_QDEC1 The generic clock used for the QDEC1 is GCLK6 QDEC1 Table 34-4. Register Reset Values Register Reset Value VERSION 0x00000100 PARAMETER 0x000000FF 1068 32117A-10/2010 AT32UC3C 35. Analog Comparator Interface (ACIFA) Rev: 1.0.0.0 35.1 Features * Control one set of two analog comparators * High speed option versus low power option * * * * * 35.2 - shortest propagation delay/highest current consumption - longest propagation delay/lowest current consumption Selectable input hysteresis: - 0mV, 20mV, 50mV Input selection between external input pin and internal inputs Window function Interrupt on: - Rising edge, Falling edge, toggle - Signal above/below window, signal inside/outside window - startup time Two Analog comparators interface events available on pin through PEVC Overview The Analog Comparator Interface (ACIFA) is able to control two Analog Comparators (AC) with identical behavior. An Analog Comparator compares two voltages and gives a compare output depending on this comparison. The ACIFA can be configured in normal mode (see Figure 35-1 on page 1070) or in window mode (see Figure 35-2 on page 1070 ). The AC's Inputs are programmable between internal inputs (DAC, voltage reference, ...) and external input pins. According to the comparison result, each comparator can trigger a separate interrupt in normal mode. In window function, an additional interrupt can be triggered, depending if the voltage to be compared is inside or outside the window. The ACIFA is able to generate two output events that can be used through PEVC to trigger a hardware process. 1069 32117A-10/2010 AT32UC3C 35.3 Block Diagram Figure 35-1. Analog Comparator Interface Overview in normal mode ACIFA CONFA.INSELP ACAOUT SR.ACACS ACAP internal inputs vipA EVSRC0.EVSRC] + ACA ACAN internal inputs vinA acoutA event generator 0 PEVC - Vcc Scale CONFA.INSELN Interrupt Controller interrupt generator CONFA.INSELP ACBP internal inputs vipB + Vcc Scale ACB ACBN internal inputs vinB event generator 1 acoutB SR.ACBCS EVSRC1.EVSRC ACBOUT CONFB.INSELN Figure 35-2. Analog Comparator Interface in window mode C O N F A .IN S E L P u p p e r lim it o f w in d o w V H c o m m o n in p u t v o lta g e v co m m o n in te rn a l in p u ts A C IF A S R .A C A C S ACAP ACAOUT E V S R C 0 .E V S R C v ip A + ACAN in te rn a l in p u ts V c c S c a le ACA v in A a c o u tA e v e n t g e n e ra to r 0 - ACBP W C O N F .W IN S E L w in d o w fu n c tio n in te rru p t g e n e ra to r acw out In te rru p t C o n tro lle r S R .W F C S v ip B + ACB ACBN lo w e r lim it o f w in d o w V L v in B a c o u tB S R .A C B C S in te rn a l in p u ts C O N F B .IN S E L N e v e n t g e n e ra to r 1 PEVC E V S R C 1 .E V S R C ACBOUT 1070 32117A-10/2010 AT32UC3C 35.4 Product Dependencies In order to use this module, other parts of the system must be configured correctly, as described below. 35.4.1 Power Management When the ACIFA is enabled it will remain clocked as long as its selected clock source is running. It can also wake the CPU from the currently active sleep mode. Refer to the Power Manager chapter for details on the different sleep modes. 35.4.2 Clocks The clock for the ACIFA bus interface (CLK_ACIFA) is generated by the Power Manager. this clock is turned on by default, and can be enabled and disabled in the Power Manager. 35.4.3 Interrupts The ACIFA interrupt request lines are connected to the interrupt controller. Using the ACIFA interrupts requires the Interrupt Controller to be programmed first. 35.4.4 Peripheral Events The ACIFA peripheral events are connected via the Peripheral Event System. Refer to the Peripheral Event System chapter for details. 35.4.5 Debug Operation The ACIFA is frozen during debug operation, unless the Run In Debug bit in the Development Control Register is set and the bit corresponding to the ACIFA is set in the Peripheral Debug Register (PDBG). Please refer to the On-Chip Debug chapter in the AVR32UC Technical Reference Manual, and the OCD Module Configuration section, for details. 35.5 Functional Description 35.5.1 Normal mode In normal mode, both analog comparators are independent. 35.5.1.1 ACIFA Output An analog comparator generates one output acout[i] (with i = a or b) according to the input voltages vipi (AC positive input) and vini (AC negative input): * acout[i] = 1 if vipi > vini * acout[i] = 0 if vipi < vini * acout[i] = 0 if the AC output is not available (ie. The AC Ready bit in the Status Register (SR.ACRDYi) is still zero) The ACIFA generates two independent events according to the configuration of the Event Source Selection field in the Event Configuration register (EVSRC0.EVSRC and EVSRC1.EVSRC): * as soon as vipA > vinA or * as soon as vipA < vinA or * as soon as vipB > vinB or 1071 32117A-10/2010 AT32UC3C * as soon as vipB < vinB or * on toggle of the ACA output (acoutA) or * on toggle of the ACB output (acoutB) 35.5.1.2 ACIFA Interrupt Each AC has one source of interrupt. The configuration of the source of the interruption is done by writing in the Interrupt Settings field in the Configuration Register (CONF0.IS and CONF1.IS). The interrupt can be triggered: * as soon as vip > vin * as soon as vip < vin * on toggle of the AC output (acout[i]) 35.5.2 Window Mode In window mode, the two ACs are grouped. The negative input of ACA and the positive input of ACB are the same and are defined in the Window Common Input Selection field in the Window Configuration register (WCONF.WINSEL). The positive input of ACA and the negative input of ACB are still configured by CONF0.INSELP and CONF1.INSELN. 35.5.2.1 ACIFA Output Like in normal mode, the ACs generate the acout[i] outputs according to the input voltages vipi (AC positive input) and vini (AC negative input): * acout[i] = 1 if vipi > vini * acout[i] = 0 if vipi < vini * acout[i] = 0 if the AC output is not available (ie. SR.ACRDYi is still 0) The ACIFA generates a window function signal (acwout) according to the common input voltage to be compared: * acwout = 1 if the common input voltage is inside the window, vinB < vcommon < vipA * acwout = 0 if the common input voltage is outside the window, vcommon < vin1 or vcommon > vip0 * acwout = 0 if the window mode output is not available (ie. The Window Function Ready bit in the Status Register (SR.WFRDY) is still 0) The ACIFA generates two independent events (like in normal mode) according to the configuration of EVSRC0 and EVSRC1: * as soon as vipA > vinA or * as soon as vipA < vinA or * as soon as vipB > vinB or * as soon as vipB < vinB or * as soon as vinB < vcommon < VipA or * as soon as vcommon < vinB or vcommon > vipA or * on toggle of the ACA output (acoutA) or * on toggle of the ACB output (acoutB) or * on toggle of the window compare output (acwout) 1072 32117A-10/2010 AT32UC3C 35.5.2.2 ACIFA Interrupt Like in normal mode, each AC has one source of interrupt. The configuration of the source of interruption is set in CONF0.IS and CONF1.IS. The interrupt can be triggered: * as soon as vip > vin * as soon as vip < vin * on toggle of the AC output (acout[i]) An additional source of interrupt can be generated in window mode. Its configuration is set in the Window Interrupt Settings field in the Window Configuration register (WCONF.WIS). The source of interrupt can be triggered: * as soon as the common input voltage is inside the window * as soon as the common input voltage is outside the window * on toggle of the window compare output (acwout) 35.5.3 Input Channels Each Analog Comparator has one positive and one negative input. Each input may be chosen among one external input pin in addition to some internal signals. The user writes the input selection: * in normal mode by writing in the Positive Input Selection field (CONFi.INSELP) and in the Negative Input Selection field in the Configuration register (CONFi.INSELN) * in window mode by writing in the CONF0.INSELP, WCONF.WINSEL and CONF1.INSELN fields. In this case the WCONF.WINSEL field overrides the CONF0.INSELN and CONF1.INSELP fields. 35.5.4 Internal Inputs Three internal inputs are available for the Analog Comparator. 35.5.5 High-speed vs Low Power Modes It is possible to enable High-speed mode by writing a one to the Speed Selection bit in the CONF register (CONFi.SS) to get the shortest possible propagation delay. This mode consumes more power than the default low power mode (when CONFi.SS is written to zero) that has a longer propagation delay. 35.5.6 Input Hysteresis The user can select between no, low, and high hysteresis, by writing in the Hysteresis Selection field in the CONF register (CONFi.HS). Adding hysteresis can avoid constant toggling of the compare output if the input signals are very close to each other. 35.5.7 Startup Time After enabling an Analog Comparator, the comparison is available after a start-up time defined in the Start Up Time field in the Start Up Time register (SUT.SUT). During this time the AC output is not available. The status bit SR.ACRDYi gives the information that the ACi has its output available or not. In window mode the window mode output is available (SR.WFRDY is one) if both comparator outputs are available (SR.ACARDY and SR.ACBRDY are both one). 1073 32117A-10/2010 AT32UC3C When the start-up time is finished, the comparison can be disabled/enabled, by writing a one to the corresponding AC Comparison Enable bit in the Enable register (EN.ACCPEN), without waiting anymore. 35.5.8 Starting Signal Compare In order to start a voltage comparison, the Analog Comparator must be configured with the preferred properties and the inputs to be used. After enabling the Analog Comparator, it should wait for the startup time. When the startup time is over, the result of the comparison is available. It can be read at all times in the SR register. 1074 32117A-10/2010 AT32UC3C 35.6 User Interface Table 35-1. ACIFA Register Memory Map Offset Register Register Name Access Reset 0x00 ACA Configuration Register CONFA Read/Write 0x80000000 0x04 ACB Configuration Register CONFB Read/Write 0x80000000 0x08 AC Window Function Configuration Register WCONF Read/Write 0x00000000 0x0C AC Event 0 source Configuration EVSRC0 Read/Write 0x00000000 0x10 AC Event 1 source Configuration EVSRC1 Read/Write 0x00000000 0x14 ACA Scale factor selection SCFA Read/Write 0x00000000 0x18 ACB Scale factor selection SCFB Read/Write 0x00000000 0x1C AC Enable Register EN Write-only 0x00000000 0x20 AC Disable Register DIS Write-only 0x00000000 0x24 AC Startup Timer Register SUT Read/Write 0x00000000 0x28 AC Interrupt Enable Register IER Write-Only 0x00000000 0x2C AC Interrupt Disable Register IDR Write-Only 0x00000000 0x30 AC Interrupt Mask Register IMR Read-Only 0x00000000 0x34 AC Event Enable Register EVE Write-Only 0x00000000 0x38 AC Event Disable Register EVD Write-Only 0x00000000 0x3C AC Event Mask Register EVM Read-Only 0x00000000 0x40 AC Status Register SR Read-Only 0x00000000 0x44 AC Status Clear Register SCR Write-only 0x00000000 0x48 Version Register VERSION Read-Only -(1) Notes: 1. The reset values for this register is device specific. Please refer to the Module Configuration section at the end of this chapter. 1075 32117A-10/2010 AT32UC3C 35.6.1 Name: ACA Configuration Register CONFA Access Type: Read/Write Offset: 0x00 Reset Value: 0x80000000 31 30 29 28 27 26 OEN - - SS - - 23 22 21 20 19 18 - - - - 15 14 13 12 - - - - 7 6 5 4 3 2 - - - - - - 25 24 HS 17 16 9 8 1 0 INSELN 11 10 INSELP IS * OEN: Output Enable "0": Enable the redirection of the output of AC on pad "1": The output redirection is disabled * SS: Speed select 0: The low power mode is selected (longest propagation delay, lowest current consumption) 1: The high-speed mode is selected (shortest propagation delay, highest current consumption) * HS: Hysteresis select "00" or "11": no hysteresis "01": small hysteresis, 20 mV "10": high hysteresis, 50 mv * INSELN: Negative input select i: select the ith input of the mux * INSELP: Positive input select i: select the ith input of the mux * IS: Interrupt settings "00": The comparator interrupt is set as soon as vip > vin "01": The comparator interrupt is set as soon as vip < vin "10": The comparator interrupt is set on toggle of analog comparator output 1076 32117A-10/2010 AT32UC3C 35.6.2 Name: ACB Configuration Register CONFB Access Type: Read/Write Offset: 0x04 Reset Value: 0x80000000 31 30 29 28 27 26 OEN - - SS - - 23 22 21 20 19 18 - - - - 15 14 13 12 - - - - 7 6 5 4 3 2 - - - - - - 25 24 HS 17 16 9 8 1 0 INSELN 11 10 INSELP IS * OEN: Output Enable "0": Enable the redirection of the output of AC on pad "1": The output redirection is disabled * SS: Speed select 0: The low power mode is selected (longest propagation delay, lowest current consumption) 1: The high-speed mode is selected (shortest propagation delay, highest current consumption) * HS: Hysteresis select "00" or "11": no hysteresis "01": small hysteresis, 20 mV "10": high hysteresis, 50 mv * INSELN: Negative input select i: select the ith input of the mux * INSELP: Positive input select i: select the ith input of the mux * IS: Interrupt settings "00": The comparator interrupt is set as soon as vip > vin "01": The comparator interrupt is set as soon as vip < vin "10": The comparator interrupt is set on toggle of analog comparator output 1077 32117A-10/2010 AT32UC3C 35.6.3 Name: AC Window Function Configuration Register WCONF Access Type: Read/Write Offset: 0x08 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 - - - - 7 6 5 4 3 2 1 0 - - - - - - WINSEL WIS * WINSEL: Window function common input select i: select the ith input of the mux * WIS: Window mode Interrupt settings "00": The window interrupt is set as soon as the input voltage is inside the window "01": The window interrupt is set as soon as the input voltage is outside the window "10": The window interrupt is set on toggle of window compare output 1078 32117A-10/2010 AT32UC3C 35.6.4 Name: AC Event 0/1 Configuration Register EVSRC0-EVSRC1 Access Type: Read/Write Offset: 0x0C-0X10 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 - - - - - - - - 7 6 5 4 3 2 1 0 - - - - EVSRC * EVSRC: Event source selection "0000": The event is set on ACA.acout rising edge "0001": The event is set on ACA.acout falling edge "0010": The event is set on ACA.acout rising or falling edge "0011": The event is set on ACB.acout rising edge "0100": The event is set on ACB.acout falling edge "0101": The event is set on ACB.acout rising or falling edge "0110": The event is set on acwout rising edge "0111": The event is set on acwout falling edge "1000": The event is set on acwout rising or falling edge "1001","1010","1011","1100","1101","1110","1111": no effect 1079 32117A-10/2010 AT32UC3C 35.6.5 Name: ACA/B Scale Factor Selection Register SCFA-SCFB Access Type: Read/Write Offset: 0x14-0x18 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 - - - - - - - - 7 6 5 4 3 2 1 0 - EN SCF * SCF: Scale Factor selection for Supply divider VCC Scale = (64 -SCF) * VDDANA / 65 * EN : Supply divider enable 0: The supply divider is disabled 1: The supply divider is enabled 1080 32117A-10/2010 AT32UC3C 35.6.6 Name: AC Enable Register EN Access Type: Write-Only Offset: 0x1C Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 - - - - - - - - 7 6 5 4 3 2 1 0 - - - ACBCPEN ACACPEN WFEN ACBEN ACAEN * ACBCPEN: ACB Comparison enable Writing a zero to this bit has no effect Writing a one to this bit will enable the comparison of the Analog Comparator B * ACACPEN: ACA Comparison enable Writing a zero to this bit has no effect Writing a one to this bit will enable the comparison of the Analog Comparator A * WFEN: Window function enable Writing a zero to this bit has no effect Writing a one to this bit will enable the window function. Enabling the window function automatically enable both comparators if they are not already enabled, and also the two comparison (SR.ACAEN, SR.ACBEN, SR.ACACPEN,and SR.ACBCPEN are set) * ACBEN: ACB enable Writing a zero to this bit will has no effect Writing a one to this bit will enable the Analog Comparator B * ACAEN: ACA enable Writing a zero to this bit will has no effect Writing a one to this bit will enable the Analog Comparator A 1081 32117A-10/2010 AT32UC3C 35.6.7 Name: AC Disable Register DIS Access Type: Write-Only Offset: 0x20 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 - - - - - - - - 7 6 5 4 3 2 1 0 - - - ACBCPDIS ACACPDIS WFDIS ACBDIS ACADIS * ACBCPEN: ACB Comparison enable Writing a zero to this bit has no effect Writing a one to this bit will disable the comparison of the Analog Comparator B * ACACPEN: ACA Comparison enable Writing a zero to this bit has no effect Writing a one to this bit will disable the comparison of the Analog Comparator A * WFEN: Window function enable Writing a zero to this bit has no effect Writing a one to this bit will disable the window function. Disabling the window function automatically disable both comparison (ACACPEN and ACBCPEN are cleared) * ACBEN: ACB enable Writing a zero to this bit has no effect Writing a one to this bit will disable the Analog Comparator B * ACAEN: ACA enable Writing a zero to this bit has no effect Writing a one to this bit will disable the Analog Comparator A 1082 32117A-10/2010 AT32UC3C 35.6.8 Name: AC Startup Time Register SUT Access Type: Read/Write Offset: 0x24 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 - - - - - - 7 6 5 4 3 2 SUT 1 0 SUT * SUT: Startup Time Analog comparator startup time = 1/freq(ACIFA) x SUT Each time, an AC is enabled, the AC comparison will be enabled after the startup time due to the startup time of the AC 1083 32117A-10/2010 AT32UC3C 35.6.9 Name: AC Interrupt Enable Register IER Access Type: Write-Only Offset: 0x28 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 - - - - - - - - 7 6 5 4 3 2 1 0 - - - SUTBINT SUTAINT WFINT ACBINT ACAINT * SUTBINT: ACB startup time interrupt enable writing a zero to this bit has no effect Writing a one to this bit will enable the ACB startup interrupt * SUTAINT: ACA startup time interrupt enable writing a zero to this bit has no effect Writing a one to this bit will enable the ACA startup interrupt * WFINT: Window function interrupt enable writing a zero to this bit has no effect Writing a one to this bit will enable the window function interrupt defined in the WCONF.WIS field * ACBINT: ACB interrupt enable writing a zero to this bit has no effect Writing a one to this bit will enable the ACB interrupt defined in the CONFB.IS field * ACAINT: ACA interrupt enable writing a zero to this bit has no effect Writing a one to this bit will enable the ACA interrupt defined in the CONFA.IS field 1084 32117A-10/2010 AT32UC3C 35.6.10 Name: AC Interrupt Disable Register IDR Access Type: Write-Only Offset: 0x2C Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 - - - - - - - - 7 6 5 4 3 2 1 0 - - - SUTBINT SUTAINT WFINT ACBINT ACAINT * SUTBINT: ACB startup time interrupt enable writing a zero to this bit has no effect Writing a one to this bit will disable the ACB startup interrupt * SUTAINT: ACA startup time interrupt enable writing a zero to this bit has no effect Writing a one to this bit will disable the ACA startup interrupt * WFINT: Window function interrupt enable writing a zero to this bit has no effect Writing a one to this bit will disable the window function interrupt defined in the WCONF.WIS field * ACBINT: ACB interrupt enable writing a zero to this bit has no effect Writing a one to this bit will disable the ACB interrupt defined in the CONFB.IS field * ACAINT: ACA interrupt enable writing a zero to this bit has no effect Writing a one to this bit will disable the ACA interrupt defined in the CONFA.IS field 1085 32117A-10/2010 AT32UC3C 35.6.11 Name: AC Interrupt Mask Register IMR Access Type: Read-Only Offset: 0x30 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 - - - - - - - - 7 6 5 4 3 2 1 0 - - - SUTBINT SUTAINT WFINT ACBNT ACAINT 0: The corresponding interrupt is disabled. 1: The corresponding interrupt is enabled. A bit in this register is cleared when the corresponding bit in IDR is written to one. A bit in this register is set when the corresponding bit in IER is written to one. 1086 32117A-10/2010 AT32UC3C 35.6.12 Name: AC Event Enable Register EVE Access Type: Write-Only Offset: 0x34 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 - - - - - - - - 7 6 5 4 3 2 1 0 - - - - - - ACEV1 ACEV0 * ACEV1: Event 1 enable Writing a zero to this bit has no effect Writing a one to this bit will enable the event zero defined in the EVSRC1.EVSCR field * ACEV0: Event 0 enable Writing a zero to this bit has no effect Writing a one to this bit will enable the event one defined in the EVSRC0.EVSCR field 1087 32117A-10/2010 AT32UC3C 35.6.13 Name: AC Event Disable Register EVD Access Type: Write-Only Offset: 0x38 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 - - - - - - - - 7 6 5 4 3 2 1 0 - - - - - - ACEV1 ACEV0 * ACEV1: Event 1 enable Writing a zero to this bit has no effect Writing a one to this bit will disable the event one defined in the EVSRC1.EVSCR field * ACEV0: Event 0 enable Writing a zero to this bit has no effect Writing a one to this bit will disable the event one defined in the EVSRC0.EVSCR field 1088 32117A-10/2010 AT32UC3C 35.6.14 Name: AC Event Mask Register EVM Access Type: Read-Only Offset: 0x3C Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 - - - - - - - - 7 6 5 4 3 2 1 0 - - - - - - ACEV1 ACEV0 0: The corresponding peripheral event is disabled 1: The corresponding peripheral event is enabled Theses bits are cleared when the corresponding bit in EVD is written to zero These bits are cleared when the corresponding bit in EVE is written to one 1089 32117A-10/2010 AT32UC3C 35.6.15 Name: AC Status Register SR Access Type: Read-Only Offset: 0x40 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - WFRDY ACBRDY ACARDY 23 22 21 20 19 18 17 16 - - - - - WFCS ACBCS ACACS 15 14 13 12 11 10 9 8 - - - ACBCPEN ACACPEN WFEN ACBEN ACAEN 7 6 5 4 3 2 1 0 - - - SUTBINT SUTAINT WFINT ACBNT ACAINT * WFRDY: Window function ready this bit is cleared when the window function output (wout) is not ready (one or both ACA or ACB comparison outputs is not ready) This bit is set when the window function output (wout) is ready (both ACA and ACB comparison outputs are ready) * ACBRDY: ACB ready This bit is cleared when the ACB output (acoutB) is not ready This bit is set when the ACB output (acoutB) is ready (ACB is enabled and its SUT is over) * ACARDY: ACA ready This bit is cleared when the ACA output (acoutA) is not ready This bit is set when the ACA output (acoutA) is ready (ACA is enabled and its SUT is over) * WFCS: Window function current status This bit is cleared when the common input voltage is currently outside the window This bit is set when the common input voltage is currently inside the window * ACBCS: ACB current status of comparison This bit is cleared when vipB is currently lower than vinB This bit is set when vipB is currently greater than vinB * ACACS: ACA current status of comparison This bit is cleared when vipA is currently lower than vinA This bit is set when vipA is currently greater than vinA * ACBCPEN: ACB Comparison enable This bit is cleared when the ACB comparison is disabled This bit is set when the ACB comparison is enabled * ACACPEN: ACA Comparison enable This bit is cleared when the ACA comparison is disabled This bit is set when the ACA comparison is enabled 1090 32117A-10/2010 AT32UC3C * WFEN: Window function enable This bit is cleared when the window function is disabled This bit is set when the window function is enabled * ACBEN: ACB enable This bit is cleared when the ACB is disabled This bit is set when the ACB is enabled * ACAEN: ACA enable This bit is cleared when the ACA is disabled This bit is set when the ACA is enabled * SUTBINT: ACB startup time interrupt status This bit is cleared when the ACB interrupt is not pending This bit is set when the ACB interrupt is pending ( the ACB has reached its startup time (SUT), the ACB comparison is valid) * SUTAINT: ACA startup time interrupt status This bit is cleared when the ACA interrupt is not pending This bit is set when the ACA interrupt is pending ( the ACA has reached its startup time (SUT), the ACA comparison is valid) * WFINT: Window function interrupt status This bit is cleared when the interrupt is not pending This bit is set when the interrupt is pending * ACBINT: ACB Interrupt Status This bit is cleared when the interrupt is not pending This bit is set when the interrupt is pending * ACAINT: ACA Interrupt Status This bit is cleared when the interrupt is not pending This bit is set when the interrupt is pending 1091 32117A-10/2010 AT32UC3C 35.6.16 Name: AC Status Clear Register SCR Access Type: Write-Only Offset: 0x44 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 - - - - - - - - 7 6 5 4 3 2 1 0 - - - SUT1INT SUT0INT WFINT ACBNT ACAINT Writing a zero to a bit in this register has no effect. Writing a one to a bit in this register will clear the corresponding bit in SR and the corresponding interrupt request. 1092 32117A-10/2010 AT32UC3C 35.6.17 Name: Version Register VERSION Access Type: Read-Only Offset: 0x48 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - 15 14 13 12 9 8 - - - - 7 6 5 4 1 0 VARIANT 11 10 VERSION[11:8] 3 2 VERSION[7:0] * VARIANT: Variant Number Reserved. No functionality associated. * VERSION: Version Number Version number of the module. No functionality associated. 1093 32117A-10/2010 AT32UC3C 35.7 Module configuration The specific configuration for each ACIFA instance is listed in the following tables. The module bus clocks listed here are connected to the system bus clocks according to the table in the System Bus Clock Connections section. Table 35-2. Module clock name Module name Clock name Description ACIFA0 CLK_ACIFA0 Peripheral Bus clock from the PBA clock domain ACIFA1 CLK_ACIFA1 Peripheral Bus clock from the PBA clock domain Table 35-3. Register Reset Values Register Reset Value VERSION 0x00000100 The following table gives which ACIFA module controls the analog comparators. Table 35-4. Analog comparators controlled by ACIFA Module name Analog comparator name ACIFA0 AC0A and AC0B ACIFA1 AC1A and AC1B The inputs of the AC are configured through the CONFA and CONFB registers. The configuration allows to select pin or internal voltage from the DACs. The following table defines the valid settings for the CONFA and CONFB registers for each ACIFA instance. This setting defines the mapping of the AC input voltage. Table 35-5. vip of AC0A selection CONFA[INSELP] Name Connection 0 AC0AP0 1 AC0AP1 See Peripheral Multiplexing on I/O line chapter 2 DAC0_int Internal output of the DAC0 1094 32117A-10/2010 AT32UC3C Table 35-6. vin of AC0A selection CONFA[INSELN] Name Connection 0 AC0AN0 1 AC0AN1 See Peripheral Multiplexing on I/O line chapter 2 AC0BP0 3 AC0BP1 4 VDDANA_SCALED VDDANA scaled 5 DAC1_int Internal output of the DAC1 Table 35-7. vip of AC0B selection CONFB[INSELP] Name Connection 0 AC0AN0 1 AC0AN1 See Peripheral Multiplexing on I/O line chapter 2 AC0BP0 3 AC0BP1 4 DAC0_int Internal output of the DAC0 5 VDDANA_SCALED VDDANA scaled Table 35-8. vin of AC0B selection CONFB[INSELN] Description Connection 0 AC0BN0 1 AC0BN1 See Peripheral Multiplexing on I/O line chapter 2 DAC1_int Table 35-9. Internal output of the DAC1 vip of AC1A selection CONFA[INSELP] Description Connection 0 AC1AP0 1 AC1AP1 See Peripheral Multiplexing on I/O line chapter 2 DAC0_int Internal output of the DAC0 Table 35-10. vin of AC1A selection CONFA[INSELN] Description Connection 0 AC1AN0 1 AC1AN1 See Peripheral Multiplexing on I/O line chapter 2 AC1BP0 3 AC1BP1 4 VDDANA_SCALED VDDANA scaled 5 DAC1_int Internal output of the DAC1 1095 32117A-10/2010 AT32UC3C Table 35-11. vip of AC1B selection CONFB[INSELP] Description Connection 0 AC1AN0 1 AC1AN1 See Peripheral Multiplexing on I/O line chapter 2 AC1BP0 3 AC1BP1 4 DAC0_int Internal output of the DAC0 5 VDDANA_SCALED VDDANA scaled Table 35-12. vin of AC1B selection CONFB[INSELN] Description Connection 0 AC1BN0 1 AC1BN1 See Peripheral Multiplexing on I/O line chapter 2 DAC1_int Internal output of the DAC1 In window mode, the window common input is configured through WCONF register. Table 35-13. common input voltage of AC0 selection WCONF[WINSEL] Description Connection 0 AC0AN0 1 AC0AN1 See Peripheral Multiplexing on I/O line chapter 2 AC0BP0 3 AC0BP1 Table 35-14. common input voltage of AC1 selection WCONF[WINSEL] Description Connection 0 AC1AN0 1 AC1AN1 See Peripheral Multiplexing on I/O line chapter 2 AC1BP0 3 AC1BP1 1096 32117A-10/2010 AT32UC3C 36. ADC Interface (ADCIFA) Rev. 1.1.0.2 36.1 Features * 8/10/12-bit ADC core with built-in dual sample and hold (S/H) * 16 channels * Up to 1.5 mega-samples per second conversion rate for 12 bits resolution - Conversion time near to 5.3s (12 bits resolution at 1.5 Msps) * Up to 2 mega-samples per second conversion for lower resolution * * * * * * * * * * * * * - Conversion time near to 3.5s (10 bits resolution at 2 Msps) - Conversion time near to 3s (8 bits resolution at 2 Msps) Multiple reference sources - 1V internal voltage reference - 0.6 * VDDANA internal - Two external reference voltage Direct measures or sampled with sample-and-hold Sample-and-hold (S/H) acquisition time window has separate prescale control (gain: 1, 2, 4, 8, 16, 32, 64). Sequencer can be operated as two independent 8-state sequencers operating on its own S/H (dual sequencer mode) or as one large 16-state sequencer (single sequencer mode) 16 result registers Source selection for the start-of-conversion (SOC) - Software - Embedded timer - Peripheral Event Controller - Continuous Two sequencer modes: - Run the whole sequence on a start-of-conversion - Run a single conversion on a start-of-conversion Flexible interrupt control allows interrupt request on every end-of-sequence or on every single conversion. Windowing mechanism, with selectable channel Free running mode 2 PDCA channels (one per sequencer) Power reduction modes Programmable ADC timings 1097 32117A-10/2010 AT32UC3C 36.2 Overview The Analog-to-Digital Converter (ADC) is fully differential and based on a 12-bit pipelined topology using switched capacitors circuitry. Two sample and hold (S/H) running simultaneously with 1, 2, 4, 8, 16, 32, 64 gain factors are feeding a single ADC analog block so that the system acts as if there were two conversion running in parallel. It can be configured as a 8-bit 10-bit or 12-bit ADC and is capable of converting 1.5 million samples per second thanks to its pipeline topology. 10-bit and 8-bit conversion resolution can be achieved at higher conversion rates. Note that results are always signed in 2's complement. Note: The pipelined topology implies a latency between the sampling event and the update of the result register of: (Resolution(SRES)/2 + 3 - SHD) * T(CkADC) The ADC has an internal defined conversion range of 1.0V. An additional internal reference mode allows conversion range of 0.6*VDDANA. In addition, the ADC may operate with external references for different conversion ranges. 1098 32117A-10/2010 AT32UC3C 36.3 Block Diagram Figure 36-1. ADCIFA Block Diagram PB PDC ADC Window0 RES0 . . . RES7 GNDANA PDC ADC Window1 VDDANA SEQUENCER0 ADCINx PREAMP0 S/H 12-bit ADC CORE ADCINx PREAMP1 S/H Arbiter ADC_Event_Ctrl ADC Timer ADC result1 RES8 . . . RES15 SEQUENCER1 ADC result0 CKdiv clkADC CLK_ADCIFA ADCREFP ADCREFN ADCREF0 ADCREF1 1099 32117A-10/2010 AT32UC3C 36.4 I/O Lines Description Table 36-1. 36.5 36.5.1 I/O Lines Description Name Description ADCINx ADC analog input ADCREFP CFG.EXREF= 0: Normal operation, this pin is used to decouple ADC internal reference. ADCREFP should be connected to a 100nF external decoupling capacitor. CFG.EXREF= 1: Forcing reference using ADCREFP/ADCREFN differential pin pair voltage Please refer to the Section 36.6.10 for more information. ADCREFN CFG.EXREF= 0: Normal operation, this pin is used to decouple ADC internal reference. ADCREFN should be connected to a 100nF external decoupling capacitor. CFG.EXREF= 1: Forcing reference using ADCREFP/ADCREFN differential pin pair voltage Please refer to the Section 36.6.10 for more information. ADCREF0 External reference input (with respect to analog ground) bypassed when CFG.RS is enabled ADCREF1 External reference input (with respect to analog ground) bypassed when CFG.RS is enabled VDDANA Analog power supply GNDANA Analog ground Product Dependencies I/O Lines The pins used for interfacing the ADCIFA may be multiplexed with the I/O Controller lines. The programmer must first program the I/O Controller to assign the desired ADCIFA pins to their peripheral function. If I/O lines of the ADCIFA are not used by the application, they can be used for other purposes by the I/O Controller. Not all ADCIFA inputs may be enabled. If an application requires only four channels, then only four ADCIFA lines need to be assigned to ADCIFA inputs. 36.5.2 Power Management If the CPU enters a sleep mode that disables clocks used by the ADCIFA, the ADCIFA will stop functioning and resume operation after the system wakes up from sleep mode. Before entering a sleep mode where the clock to the ADCIFA is stopped, make sure the Analog-to-Digital Converter cell is put in an inactive state. Refer to Section 36.6.3 for more information. 36.5.3 Clocks The clock for the ADCIFA bus interface (CLK_ADICFA) is generated by the Power Manager. This clock is turned on by default, and can be enabled and disabled in the Power Manager. It is recommended to disable the ADCIFA before disabling the clock, to avoid freezing the ADCIFA in an undefined state. 36.5.4 Interrupts The ADCIFA interrupt line is connected to one of the internal sources of the Interrupt Controller (INTC). Using the ADCIFA requires the INTC to be configured first. 36.5.5 Event System The event controller provides the ADCIFA two trigger sources. 1100 32117A-10/2010 AT32UC3C 36.5.6 Debug Operation When an external debugger forces the CPU into debug mode: * the ADCIFA continues normal operation if the bit related to ADCIFA in PDBG register is `0'. PDCA access continues normal operation and may interfere with debug operation. * the ADCIFA is frozen if the bit related to ADCIFA in PDBG register is `1'. When the ADCIFA is frozen, ADCIFA PB registers can still be accessed. Then, reading registers may modify status bits (OVRx, LOVRx) like in normal operation. PDCA access are pending. 36.6 Functional Description 36.6.1 ADC Resolution The ADC supports 8-bit, 10-bit or 12 bits resolutions. Precision can be set differently for each sequencer by setting the SRES bits in the SEQCFGx register. By default, after a reset, the resolution is set to 12 bits. To get full resolution, the user should first calibrate the ADC as detailed in Section 36.6.16. 36.6.2 ADC Conversion Modes 36.6.2.1 Differential / single ended The ADC is fully differential. To perform single ended measures, the user can perform pseudo unipolar conversions by connecting ground onto the negative input. User can connect it to an external ground through pads or internal ground depending on if there's one connected onto the negative input multiplexer. Since conversion results are always 12 bits in 2's complement representation, the sign bit will not change, and then the resulting resolution is 11 bits max. 36.6.2.2 S/H versus DIRECT conversions By default S/H are enabled, to change that setting, set the Sample and Hold disable bit (SHD) located in the CFG register. Maximum accuracy is achieved when disabling S/H but setting this bit forbids dual sequencer mode, Sequencer 1 is then switched off. Furthermore, in this mode S/H are switched off to lower power consumption. Table 36-2. Mode S/H versus DIRECT Conversions Characteristics Pros Gain setting (1, 2, 4, 8, 16, 32, 64) Dual sequencer mode Cons Reduced accuracy Dynamic limitation (fixed with over-sampling) 1 ADC clock period spent to propagate into S/H Pros No dynamic limitation due to S/H Full accuracy Saves 1 ADC clock period compared to the features list timings Cons No gain Single sequencer mode only S/H DIRECT 1101 32117A-10/2010 AT32UC3C 36.6.3 Power Reduction Modes Configuration bits acting on the power consumption of the digital and analog blocks are ADC enable (ADCEN) and Sleep Mode Selection (SLEEP) bits located in the CFG register: Table 36-3. ADCEN Power Reduction Mode over the ADCEN Setting Behavior 0 Digital controller dynamic activity is stopped (gated clocks) All analog is powered off (reference sources, ADC, sample & hold) 1 Digital controller enabled Analog references are switched on The ADC block is powered on depending on the SLEEP bit Table 36-4. SLEEP Power Reduction Mode Behavior 0 Analog ADC block always powered on 1 Analog ADC block powered off after each conversion Depending on the Start Of Conversion Behavior (SOCB) bit in the Sequencer Configuration (SEQCFGx) register, the HOT start-up sequence will be performed before each conversion or before each new conversion sequence. The ADC analog block is powered off when not used, it needs 24 ADC clock cycles to wake-up. If start of conversion frequency is lower than 1/25.f(CkADC) then no conversion will be lost. 36.6.4 ADC Sequencer Operating Modes 36.6.4.1 General The ADC sequencer consists in two independent 8-state sequencers (SEQ0 and SEQ1) that can also be cascaded together to form one 16-state sequencer (SEQ). The word "state" represents the number of auto-conversions that can be performed with the sequencer. In both cases, the ADC has the ability to auto-sequence a series of conversions. This means that each time a sequencer receives a start-of-conversion request, it can perform multiple conversions automatically. For every sequencer conversion in dual-sequencer mode, any one of the available sequencer 16 input channels can be selected through the analog MUX. In the same way, in single-sequencer mode, any of the SEQ0 input channels can be selected. After conversion, the digital value of the selected channel is stored in the appropriate result register (RESn). It is also possible to sample the same channel multiple times, allowing the user to perform "over-sampling", which gives increased resolution over traditional single-sampled conversion results. 36.6.4.2 Single-sequencer mode (cascaded mode) By setting the Single Sequencer Mode (SSMQ) bit in the CFG register, the two sequencers are cascaded allowing a maximum of 16 successive measures among the SEQ0 16 analog inputs. Figure 36-2 shows a sequence of 4 differential measures, initiated by the Start Of Conversion (SOC) request. The sequence of analog inputs to be measured is determined by the values of (INPSEL0x, INNSEL0x) and (INPSEL1x, INNSEL1x) couples of registers. Each analog input is selected by the analog multiplexer then sampled one by one every ADC clock cycle. In addition, the conversion lasts (SRES / 2 + 3 - SHD) ADC clock cycles due to the ADC pipelined topology. 1102 32117A-10/2010 AT32UC3C Figure 36-2. Single Sequencer Chronogram (assuming SRES=8, SHD=0) 36.6.4.3 Dual-sequencer mode (simultaneous sampling) The ADC has the ability to sample two pairs of ADCINx inputs simultaneously (see Figure 36-3), provided that one pair is from the inputs available on the sequencer 0 and the other is from the inputs available on the sequencer 1 (see Figure 36-1). To put the ADC into simultaneous sampling mode, the SSMQ bit needs to be set in the CFG register. Figure 36-3. Dual Sequencer Chronogram (assuming SRES=8, SHD=0) In this chronogram, ADCCONV signal represents the value being sampled by the ADC 36.6.4.4 Sequencer behavior on a Start Of Conversion Thanks to the SOCB bit in the SEQCFGx register, 2 different sequencer behaviors are possible: Table 36-5. SOCB SOCB Behavior Comment 0 All sequence conversions are performed on a SOC event. 1 A single conversion belonging to the sequence is performed on a SOC event. 1103 32117A-10/2010 AT32UC3C 36.6.4.5 Sequencer start/stop mode Thanks to the Software Acknowledge bit (SA) in the SEQCFGx register, the behavior of sequencer x at the end of a sequence can be configured. Table 36-6. SA Sequencer Start/Stop Mode Comment 0 The sequencer waits for software acknowledge. Acknowledge is done by writing a 1 in the SEOSx bit of the SCR register. 1 The sequencer will restart automatically a new sequence on a new SOC. Results will be overwritten if not processed. The Sequencer x Overrun Error bit (OVRx) in SR register indicates that an overrun error occurred in the sequencer x. This means that the RES0 register has not been read while a new sequence is starting. Events such as end-of-sequence or end-of-conversion can be caught by interrupt servicing or polling routines thanks to the SEOSx and SEOCx bits in the SR register. 36.6.4.6 Sequencer free running-mode Only SEQ0 has the free-running mode capability. In free-running mode the ADC continuously converts analog values configured in the sequencer. In this mode, the sequence restarts automatically after each end of sequence without waiting for the last conversion to finish. This mode is configured by setting the Free Running Mode (FRM) bit in the CFG register. The conversion sequence will start on the first SOC defined by the Trigger Selection (TRGSEL) field in the SEQCFG0 register. In this mode only SEQ0 is running once triggered. When converting at full speed the sequencer always wait for the last conversion to be finished to rise the sequencer end of sequence status bit (EOS). Figure 36-4 shows a 3 conversions sequence running. When the third channel is sampled the sequencer has to wait for the pipeline to be flushed. This takes SRES/2+3-SHD clock cycles. To avoid this you can run that sequence in free running mode. Please refer to Figure 36-5. The sequencer will run the sequence without waiting for the pipeline to be flushed but the user will have to read the converted value before it is overwritten by a new conversion. Please note that if the number of conversions in a sequence is equal or greater that SRES/2+3-SHD, then the first converted code is available at the same time or before the end of sequence event. Thus if not using the end of sequence acknowledge mecanisme (SEQCFGx.SA) it is possible to achieve the same conversion rate performances as the free running mode. 1104 32117A-10/2010 AT32UC3C Figure 36-4. Not Using FRM and Converting at Full Speed Figure 36-5. Using FRM and Converting at Full Speed 36.6.5 ADC Clock Configuration (CKDIV) The clock frequency range for the ADC is [1.5 MHz - 32 KHz]. Since the ADC interface uses the system clock up to the PB maximum frequency, a clock downscale must be done if a higher frequency system clock is used. This scaling may also be done in order to slow down the ADC conversions or increase the S/H time, without affecting the system clock. The downscale is done by writing the maximum counter value in the Counter Value (CNT) field of the CKDIV register, with a possible division factor from 1 to 512 giving the following transfer function: T(CkADC)= T(CkPB) * ((CNT + 1) * 2). The divider is enabled as soon as the ADC is enabled by setting the ADCEN bit in the CFG register. 1105 32117A-10/2010 AT32UC3C Figure 36-6. Clock Generator Block Diagram CkPB ADCIFA [115 KHz - PB max frequency] CKDIV : DIVIDE BY CNT /2 CkADC [32 KHz - 2 MHz] In addition when CKDIV is written, the internal counter is reset to avoid rollover phenomena: DO NOT WRITE CKDIV WHEN PERFORMING CONVERSIONS. F(CkPB) should at least be 4 times greater than F(CkADC) to make the ADC controller work properly. 36.6.6 ADC Multiplexers Settle Time By default, channel multiplexers settle time is set to half a PB clock period. If operating with a high PB clock frequency, then MUX settle time can be increased to achieve a 1.5 PB clock periods settle time by writing a one in the MUXSET field in the CFG register. For more information, please refer to the ADC electrical characteristics. Figure 36-7. Multiplexers Settle Time Depending on the CFG.MUXSET Configuration Bit The chronogram above shows that for the same start of conversion (SOC) event, CkADC rises one PB clock period later. The ADC and S/H are sampling when CkADC is high, so setting the CFG.MUXSET bit will delay the sampling phase by one PB clock period. 1106 32117A-10/2010 AT32UC3C 36.6.7 Oversampling Mode To improve conversion accuracy, it is recommended to perform oversampling. This is particularly useful for high impedance sources. This mode can be used whether the ADC is used in direct mode or not. Please note that it behaves as if a sequence of 2 consecutive conversions had been programmed with the first conversion ignored. The consequence is a conversion rate divided by 2. Also note that this mode cannot be used in conjonction with the Dynamic mode. If dynamic and oversampling modes are both enabled, dynamic mode will be applied. Figure 36-8. Oversampling 36.6.8 Sample & Hold (S/H) with Gain The ADC preamplifiers are made of two cascaded switched-capacitors amplifiers stages. They are used to sample analog voltages and provide it to the ADC block when it has a time slot to make the conversion. It also amplifies the input voltage. 1107 32117A-10/2010 AT32UC3C 36.6.8.1 Dynamic mode Dynamic mode aims at improving conversion accuracy when performing channel sweeping or measures on high frequency input signals. It is then recommended using the SHDYN (sample and hold dynamic mode) bit control in the SEQCFGx register. Doing this causes the insertion of a supplementary sampling cycle of one CkADC clock period used to reset the sample and hold. As a consequence, conversion rate is divided by two. Please note that it is useless performing oversampling when using that mode since the S/H are reseted before actually sampling. Figure 36-9. SH Dynamic Mode 36.6.8.2 Gain factor S/H allows the amplification of very small signals or buffering of very high impedance signal sources. The gain factor may be configured from 1x to 64x by writing to the Sequencer Conversion n Sample and Hold Gain (GCNVn) field of the SHGx register. The gain can be changed from sample to sample by writing the SHGx registers. Table 36-7. Gain Factor GCNVn Gain 0 0 0 1 0 0 1 2 0 1 0 4 0 1 1 8 1 0 0 16 1 0 1 32 1 1 0 64 1 1 1 Reserved 1108 32117A-10/2010 AT32UC3C 36.6.9 Power-up and Startup Time To convert correct values, both references and ADC have to be powered-up correctly, otherwise wrong values will be converted until the end of the start-up time. * Cold start-up: References needs 1 ms max to establish. * Hot start-up: Once references are up, 24 CkADC clock periods are needed. When in sleep mode, the HOT start-up sequence is performed each time a conversion or a sequence is triggered thanks to the SOCB bit in the SEQCFGx register. Indeed, the ADC analog block is powered off while not used. The end of the power-up sequence can be read from the Start-Up Time Done (SUTD) bit of the SR register. This bit is set by hardware at the end of the start-up sequence and cleared by software by writing a '1' in the SUTD bit of the SCR register. It is also cleared by hardware when the ADCIFA is turned off then on by clearing and setting the ADCEN bit of the CFG register. Figure 36-10. Power-Up Sequence START-UP not done No ADC is enabled? Yes Wait for COLD start-up time No DONE and Seq Request? Yes Wait for HOT start-up time No DONE? Yes START-UP done No Yes ADC turned off? Yes SLEEP mode? 1109 32117A-10/2010 AT32UC3C 36.6.10 Analog Reference The following sources are available as analog reference (AREF) in the ADC. They are selected through the Reference Source (RS) field in the CFG register: * 1V internal voltage reference * 0.6*VDDANA internal voltage reference * Two external reference voltage (ADCREF0 or ADCREF1 over chip analog ground) When using an internal reference, it is recommended inserting a decoupling capacitor between ADCREFP and ADCREFN externally (mandatory to get the full 12-bits precision). This means that two pins will be dedicated to reference decoupling. If the pins are needed for other purposes, the decoupling may be skipped giving a conversion accuracy of 10 bits. It is also possible to force a differential reference by setting the CFG.EXREF bit. This will bypass the CFG.RS selection setting and make the ADC use the differential ADCREFP/ADCREFN pin pair voltage as reference. 36.6.11 Conversion Range The conversion amplitude range is given by the ADC acquisition mode and the reference source: Table 36-8. Conversion Range vs. Reference Reference 36.6.12 Conversion range Internal reference 1 1V Internal reference 2 0.6 * VDDANA External reference 1 min(3.5 V, VDDANA - 0.7) External reference 2 min(3.5 V, VDDANA - 0.7) Conversion Results If the Half Word Left Adjust (HWLA) bit in the SEQCFGx register is set, then the result will be left adjusted on the 16 lower bits of the RESn register. Otherwise, results will be right-adjusted. ADC transfer function: GAIN x ( V ( ADCIN ( p ) - V ( ADCIN ( n ) ) ) ) SRES + HWLA x ( 16 - SRES ) RESn = --------------------------------------------------------------------------------------------------------- x 2 ( V ( VREFP ) - V ( VREFN ) ) All conversion results are signed in two's complement representation. Extra bits depending on resolution and left adjust settings are padded with the sign bit. It means that if you read RESn registers as a 32 bits register, the result will be correct. 36.6.13 Start Of Conversion (SOC) ADC sequencers conversions can be triggered for each sequencer with the following sources: Table 36-9. Trigger of Start Of Conversion Source Sequencer Internal timer (SOCx) Internal Timer Event controller Event controller re-synchronized SEQ0 * * * * SEQ1 * * * * 1110 32117A-10/2010 AT32UC3C The sources must be configured through the Trigger Selection (TRGSEL) field of the SEQCFGxregister. Selecting the event controller source allows any event controller source to generate SOC. The ADC can serve a maximum of one SOC per ADC clock cycle. Extra SOC will be ignored and the Missed Start-Of-Conversion (MSOCx) bit in the SR register will be set. If the SOC frequency provided by the event controller exceeds the ADC capability, the event controller will generate an underrun status. 36.6.14 Internal Timer The ADCIFA embeds an internal timer used as a trigger source for SEQ0, SEQ1 and TSSEQ which can be configured by setting the ITMC fields of the ITIMER register. Internal Timer Trigger Period= (ITMC+1)*T(CkADC) The 17 bits counter allows SOC period up to 174ms when CkADC clock frequency is set to 1.5 MHz. Once set as a SOC source, the internal timer as to be started by writing a '1' in the Internal Timer Start (TSTART) bit of the CR register. It can be stopped in the same way by writing a '1' in the TSTOP bit of the CR register. The current status of the internal timer can be read from the Running timer status (RUN) field of the SR register: 0 means stopped, 1 means running. In addition when the internal timer is running, if ITIMER register is written to change its frequency, the internal counter is cleared to avoid rollover phenomena. Note: It is possible to generate an internal timer event each CkADC time slot by writing 0x0 to the ITIMER register ITMC field and by selecting the internal timer as a SOC source. 36.6.15 Peripheral DMA There are two Peripheral DMA Controller (PDC) channels corresponding to the maximum number of sequencers that can be run at the same time. The Sequencer x Last Converted Value (LCVx) register contains the last converted value of the sequencer x according to the conversion result format. The LCV register is updated each time the sequencer ends a conversion. If the last converted value has not been read when a new one is available, the previous data is overwritten. This overrun status is signalled by the Sequencer x Last Converted Value Overrun (LOVRx) bit in the SR register indicating that at least one overrun error occurred concerning sequencer x. The OVRx and LOVRx bits of the SR register are cleared by writing a `1' respectively in the OVRx and LOVRx fields of the SCR register. Note: PDC transfers are 16 bits wide. 36.6.16 Calibration Accuracy of the conversion is based on calibration of switched capacitors and operational amplifiers offset cancellation. Gain correction is done by writing a calibration word into the ADCCAL and SHCAL registers since it is temperature and operating voltage independent. 36.6.16.1 ADC gain error calibration The ADC is gain-calibrated during production, but to take advantage of this the calibration value must be read from the factory page in flash and written to the Gain Calibration (GCAL) field of the ADCCAL register. 1111 32117A-10/2010 AT32UC3C 36.6.16.2 ADC offset error calibration Offset cancellation has to be performed by the user due to temperature and operating voltage conditions dependence. The offset can be obtained by converting a null differential value. That offset has to be negated and written into the Offset Calibration (OCAL) field of the ADCCAL register. Then, for each conversion result, the controller will return the converted value added with the signed OCAL value. For instance, if the offset value obtained is 0x3, then the value 0xFD must be written to OCAL. Please note that OCAL is a 6 bits register, if the MSB is high then the value will be considered negative. A saturation mechanism avoids flipping phenomena. OCAL stores a signed number of LSB assuming the calibration has been performed in 12 bits resolution. If converting at a lower resolution, correction will only take into account the appropriate most significant bits. 36.6.16.3 Sample and hold gain error calibration S/H are gain-calibrated during production, but to take advantage of this the calibration value must be read from the factory page in flash and written to the Sample and Hold Gain Calibration (GAIN0 and GAIN1) fields of the SHCAL register. 36.6.17 Window Monitor There are 2 window monitors that allow to compare two of the result registers to some predefined threshold values. The Window Mode (WM) field in WCFGy register (see Table 36-10) allows the user to configure operating mode in order to generate interrupts. The High Threshold (HT) and Low Threshold (LT) fields in WCFGy register give the threshold voltage values of the comparators. The result register to monitor is selected by the Source (SRC) field in WCFGy register. Table 36-10. Window Modes WM Modes 0 0 0 No window mode (default) 0 0 1 Mode 1: active when result < HT 0 1 0 Mode 2: active when result > LT 0 1 1 Mode 3: active when LT < result < HT 1 0 0 Mode 4: active when result >= LT or result >= HT 1 0 1 reserved 1 1 0 reserved 1 1 1 reserved Note: Comparisons are performed regardless with the HWLA setting (half word left adjust). 36.6.18 Arbitration In dual sequencer mode, SEQ0 has priority over SEQ 1. Due to the ADC pipeline topology, the arbiter is implemented in order to allocate optimal time slots to each sequencer in order to pipe requests. When all analog voltages have been taken into account in the ADC pipeline, an other sequencer can drive the analog blocs without waiting for the end of the whole conversion process. The ADC result will be sampled by another process when getting the wanted precision. 1112 32117A-10/2010 AT32UC3C 36.6.19 Interrupts Table 36-11. ADCIFA Interrupt Group Line Line Description Related Status Sequencer 0 Sequencer 0 end of sequence Sequencer 0 end of conversion Sequencer 0 overrun Sequencer 0 (last converted value) overrun Sequencer 0 missed start-of-conversion 1 Sequencer 1 Sequencer 1 end of sequence Sequencer 1 end of conversion Sequencer 1 overrun Sequencer 1 (last converted value) overrun Sequencer 1 missed start-of-conversion 2 Start-up done Start-up done 3 Window Window 0 Window 1 0 1113 32117A-10/2010 AT32UC3C 36.7 User Interface Table 36-12. ADCIFA Register Memory Map Note: Offset Register Name Access Reset State 0x0000 CR register CR Write-only 0x00000000 0x0004 CFG register CFG Read/Write 0x00000000 0x0008 SR register SR Read-only 0x00000000 0x000C SCR register SCR Write-only 0x00000000 0x0010 SSR register SSR Write-only 0x00000000 0x0014 SEQCFG0 register SEQCFG0 Read/Write 0x00000000 0x0018 SEQCFG1 register SEQCFG1 Read/Write 0x00000000 0x001C SHG0 register SHG0 Read/Write 0x00000000 0x0020 SHG1 register SHG1 Read/Write 0x00000000 0x0024 INPSEL00 register INPSEL00 Read/Write 0x00000000 0x0028 INPSEL01 register INPSEL01 Read/Write 0x00000000 0x002C INPSEL10 register INPSEL10 Read/Write 0x00000000 0x0030 INPSEL11 register INPSEL11 Read/Write 0x00000000 0x0034 INNSEL00 register INNSEL00 Read/Write 0x00000000 0x0038 INNSEL01 register INNSEL01 Read/Write 0x00000000 0x003C INNSEL10 register INNSEL10 Read/Write 0x00000000 0x0040 INNSEL11 register INNSEL11 Read/Write 0x00000000 0x0044 CKDIV register CKDIV Read/Write 0x00000000 0x0048 ITIMER register ITIMER Read/Write 0x00000000 0x0058 WCFG0 register WCFG0 Read/Write 0x00000000 0x005C WCFG1 register WCFG1 Read/Write 0x00000000 0x0060 LCV0 register LCV0 Read-only 0x00000000 0x0064 LCV1 register LCV1 Read-only 0x00000000 0x0068 ADCCAL register ADCCAL Read/Write 0x00000000 0x006C SHCAL register SHCAL Read/Write 0x00000000 0x0070 IER register IER Write-only 0x00000000 0x0074 IDR register IDR Write-only 0x00000000 0x0078 IMR register IMR Read-only 0x00000000 0x007C VERSION register VERSION Read-only -(1) 0x0080 PARAMETER register PARAMETER Read-only -(1) 0x0084 RES register RES Read-only - 1. The reset values are device specific. Please refer to the Modue Configuration section at the end of this chapter. 1114 32117A-10/2010 AT32UC3C 36.7.1 Name: Control Register CR Access Type: Write-only Offset: 0x00 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 - - - - - - - - 7 6 5 4 3 2 1 0 - - - - TSTART TSTOP SOC1 SOC0 * TSTART: Internal Timer Start Bit Writing a zero to this bit has no effect. Writing a one to this bit starts the internal timer. This bit always reads as zero. The internal timer status can be read in the RUNT field of the SR register. * TSTOP: Internal Timer Stop Bit Writing a zero to this bit has no effect. Writing a one to this bit stops the internal timer. This bit always reads as zero. The internal timer status can be read in the RUNT field of the SR register. * SOC1: Sequencer 1 Start of Conversion Writing a zero to this bit has no effect. Writing a one to this bit makes the sequencer 1 to start a conversion. This bit always reads as zero. * SOC0: Sequencer 0 Start Of Conversion Writing a zero to this bit has no effect. Writing a one to this bit makes the sequencer 0 to start a conversion. This bit always reads as zero. 1115 32117A-10/2010 AT32UC3C 36.7.2 Name: Configuration Register CFG Access Type: Read/Write Offset: 0x04 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - 15 14 13 12 11 10 9 8 - - - - - MUXSET EXREF - 7 6 5 4 3 2 1 0 FRM SSMQ SLEEP - ADCEN SHD SUT RS * SUT: Start-up Time Number of ADC clock cycles to wait for: (STARTUP + 1) * 32. * MUXSET: Mux Settle Time 1: The multiplexers settle time is set to 0.5 PB clock periods. 0: The multiplexers settle time is set to 1.5 PB clock periods. * EXREF: External Reference 1: The external forcing of references is enabled, ADC references are the ADCREFN and ADCREFP pads. 0: The external forcing of references is disabled, ADC reference is given by the RS field. * SHD: Sample-and-Hold Disabled 1: The Sample and Hold is disabled. 0: The Sample and Hold is enabled. note: when set to one, sequencer 1 is turned off, as a consequence the ADC pipeline latency is decreased by one ADC clock period. * RS: Reference Source 0: Internal 1V reference. 1: Internal 0.6 *VDDANA reference. 2: External reference ADCREF0 over chip analog ground. 3: External reference ADCREF1 over chip analog ground. * FRM: Free Running Mode 1: The free running mode is enabled, sequencer 0 performs conversions continuously. 0: The free running modeis disabled. note: once in this mode, sequencer 1 requests cannot be serviced. 1116 32117A-10/2010 AT32UC3C * SSMQ: Single Sequencer Mode 1: The single sequencer mode is enabled, sequencers 0 and 1 are merged, increasing the number of conversions per sequence. 0: The single sequencer mode is disabled, SEQ0 and SEQ1 are in simultaneous mode. * SLEEP: Sleep Mode Selection 1: The power saving mode is enabled. The analog ADC block is powered off after each conversion. 0: The power saving mode is disabled. note: when enabled, start-up time is required before each new conversion. * ADCEN: ADC Enable 1: The ADC controller is enabled, the analog ADC block is powered-on according to SLEEP mode. 0: The ADC controller is disabled, the analog ADC block is powered-off. 1117 32117A-10/2010 AT32UC3C 36.7.3 Name: Status Register SR Access Type: Read-only Offset: 0x08 Reset Value: 0x00000000 31 30 29 28 27 - - - - 23 22 21 20 - - - 15 14 13 12 11 RUNT SUTD MSOC1 MSOC0 7 6 5 LOVR1 OVR1 SEOC1 26 25 24 17 16 10 9 8 WM1 WM0 - - 4 3 2 1 0 SEOS1 LOVR0 OVR0 SEOC0 SEOS0 STATE1 19 18 STATE0 * STATE1: Sequencer 1 State Register This field is set to the current conversion identifier. * STATE0: Sequencer 0 State Register This field is set to the current conversion identifier. * RUNT: Running Timer Status This bit is set when the internal timer is started. This bit is cleared when the internal timer is stopped. * SUTD: Start-up Time Done This bit is set when a start-up done event occurs. This bit is cleared when the corresponding bit in SCR is written to one. * MSOC1: Sequencer 1 Missed Start-Of-Conversion This bit is set when a start-of-conversion is missed. This bit is cleared when the corresponding bit in SCR is written to one. * MSOC0: Sequencer 0 Missed Start-Of-Conversion This bit is set when a start-of-conversion is missed. This bit is cleared when the corresponding bit in SCR is written to one. * WM1: Window Monitor 1 This bit is set when the watched result value goes to the defined window. This bit is cleared when the corresponding bit in SCR is written to one. 1118 32117A-10/2010 AT32UC3C * WM0: Window Monitor 0 This bit is set when the watched result value goes to the defined window. This bit is cleared when the corresponding bit in SCR is written to one. * LOVR1: Sequencer 1 Last Converted Value Overrun This bit is set when an overrun error occurs on the LCV register. This bit is cleared when the corresponding bit in SCR is written to one. * OVR1: Sequencer 1 Overrun Error This bit is set when an overrun error occurs. This bit is cleared when the corresponding bit in SCR is written to one. * SEOC1: Sequencer 1 End Of Conversion This bit is set when an end of conversion occurs. This bit is cleared when the corresponding bit in SCR is written to one. * SEOS1: Sequencer 1 End Of Sequence This bit is set when an end of sequence occurs. This bit is cleared when the corresponding bit in SCR is written to one. * LOVR0: Sequencer 0 Last Converted Value Overrun This bit is set when an overrun error occurs on the LCV register. This bit is cleared when the corresponding bit in SCR is written to one. * OVR0: Sequencer 0 Overrun Error This bit is set when an overrun error occurs. This bit is cleared when the corresponding bit in SCR is written to one. * SEOC0: Sequencer 0 End Of Conversion This bit is set when an end of conversion occurs. This bit is cleared when the corresponding bit in SCR is written to one. * SEOS0: Sequencer 0 End Of Sequence This bit is set when an end of sequence occurs. This bit is cleared when the corresponding bit in SCR is written to one. 1119 32117A-10/2010 AT32UC3C 36.7.4 Name: Status Clear Register SCR Access Type: Write-only Offset: 0x0C Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - 15 14 13 12 11 10 9 8 - SUTD MSOC1 MSOC0 WM1 WM0 - - 7 6 5 4 3 2 1 0 LOVR1 OVR1 SEOC1 SEOS1 LOVR0 OVR0 SEOC0 SEOS0 Writing a zero to a bit in this register has no effect. Writing a one to a bit in this register clears the corresponding bit in SR. 1120 32117A-10/2010 AT32UC3C 36.7.5 Name: Status Set Register SSR Access Type: Write-only Offset: 0x10 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - 15 14 13 12 11 10 9 8 - SUTD MSOC1 MSOC0 WM1 WM0 - - 7 6 5 4 3 2 1 0 LOVR1 OVR1 SEOC1 SEOS1 LOVR0 OVR0 SEOC0 SEOS0 Writing a zero to a bit in this register has no effect. Writing a one to a bit in this register sets the corresponding bit in SR. 1121 32117A-10/2010 AT32UC3C 36.7.6 Name: Sequencer n Configuration Register SEQCFGn Access Type: Read/Write Offset: 0x14 + n * 0x04 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - 15 14 13 9 8 - - 7 6 5 - - - CNVNB 12 11 10 - - 4 3 2 1 0 SHDYN OVSX2 SOCB HWLA SA SRES TRGSEL * CNVNB: Number of Conversions in a Sequence The number of conversions to perform in the sequence is (CNVNB+1). * SRES: Resolution 0: 12 bits. 1: 10 bits. 2: 8 bits. 3: Reserved. * TRGSEL: Trigger Selection 0: Software. 1: Internal ADC timer. 2: Event controller source. 3: Continuous. * SHDYN: Sample and Hold Dynamic Mode 1: The SH dynamic mode,is enabled, a conversion takes two ADC clock cycles, SH is reseted on the first cycle. 0: The SH dynamic mode is disabled, a conversion takes a single ADC clock cycle. * OVSX2: Oversampling X2 1: The oversampling mode is enabled, a conversion takes two ADC clock cycles. 0: The oversampling mode is disabled, a conversion takes a single ADC clock cycle. * SOCB: Start of Conversion Behavior 1: The SOCB mode is enabled, a single conversion is performed on a SOC event. 0: The SOCB mode is disabled, a complete sequence is performed on a SOC event. 1122 32117A-10/2010 AT32UC3C * HWLA: Half Word Left Adjust 1: The HWLA mode is enabled. 0: The HWLA mode is disabled. * SA: Software Acknowledge 1: The SA mode is enabled. 0: The SA mode is disabled. 1123 32117A-10/2010 AT32UC3C 36.7.7 Name: Sequencer n Sample and Hold Gain for Each Conversion SHGn Access Type: Read/Write Offset: 0x1C+ n * 0x04 Reset Value: 0x00000000 31 30 23 22 - 21 14 13 20 5 26 19 12 11 18 GCNV1 3 - 24 17 16 GCNV4 10 4 25 GCNV6 - GCNV3 6 27 - GCNV5 7 28 GCNV7 15 29 9 8 GCNV2 2 1 0 GCNV0 * GCNV7: Sequencer n Conversion 7 Sample and Hold Gain * GCNV6: Sequencer n Conversion 6 Sample and Hold Gain * GCNV5: Sequencer n Conversion 5 Sample and Hold Gain * GCNV4: Sequencer n Conversion 4 Sample and Hold Gain * GCNV3: Sequencer n Conversion 3 Sample and Hold Gain * GCNV2: Sequencer n Conversion 2 Sample and Hold Gain * GCNV1: Sequencer n Conversion 1 Sample and Hold Gain * GCNV0: Sequencer n Conversion 0 Sample and Hold Gain 1124 32117A-10/2010 AT32UC3C 36.7.8 Name: Sequencer n INP Conversions 0 to 3 Selection INPSEL0n Access Type: Read/Write Offset: 0x24+ n * 0x04 Reset Value: 0x00000000 31 30 29 28 - - - - 23 22 21 20 - - - - 15 14 13 12 - - - - 7 6 5 4 - - - - 27 26 25 24 17 16 9 8 1 0 CNV3 19 18 CNV2 11 10 CNV1 3 2 CNV0 * CNV3: Sequencer n INP Identifier of the 4th Conversion to Perform * CNV2: Sequencer n INP Identifier of the 3rd Conversion to Perform * CNV1: Sequencer n INP Identifier of the 2nd Conversion to Perform * CNV0: Sequencer n INP Identifier of the 1st Conversion to Perform 1125 32117A-10/2010 AT32UC3C 36.7.9 Name: Sequencer n INP Conversions 4 to 7 Selection INPSEL1n Access Type: Read/Write Offset: 0x2C+ n * 0x04 Reset Value: 0x00000000 31 30 29 28 - - - - 23 22 21 20 - - - - 15 14 13 12 - - - - 7 6 5 4 - - - - 27 26 25 24 17 16 9 8 1 0 CNV7 19 18 CNV6 11 10 CNV5 3 2 CNV4 * CNV7: Sequencer 0 INP Identifier of the 8th Conversion to Perform * CNV6: Sequencer 0 INP Identifier of the 7th Conversion to Perform * CNV5: Sequencer 0 INP Identifier of the 6th Conversion to Perform * CNV4: Sequencer 0 INP Identifier of the 5th Conversion to Perform 1126 32117A-10/2010 AT32UC3C 36.7.10 Name: Sequencer n INN Conversions 0 to 3 Selection INNSEL0n Access Type: Read/Write Offset: 0x34+ n * 0x04 Reset Value: 0x00000000 31 30 29 28 - - - - 23 22 21 20 - - - - 15 14 13 12 - - - - 7 6 5 4 - - - - 27 26 25 24 17 16 9 8 1 0 CNV3 19 18 CNV2 11 10 CNV1 3 2 CNV0 * CNV3: Sequencer n INN Identifier of the 4th Conversion to Perform * CNV2: Sequencer n INN Identifier of the 3rd Conversion to Perform * CNV1: Sequencer n INN Identifier of the 2nd Conversion to Perform * CNV0: Sequencer n INN Identifier of the 1st Conversion to Perform 1127 32117A-10/2010 AT32UC3C 36.7.11 Name: Sequencer n INN Conversions 4 to 7 Selection INNSEL1n Access Type: Read/Write Offset: 0x3C+ n * 0x04 Reset Value: 0x00000000 31 30 29 28 - - - - 23 22 21 20 - - - - 15 14 13 12 - - - - 7 6 5 4 - - - - 27 26 25 24 17 16 9 8 1 0 CNV7 19 18 CNV6 11 10 CNV5 3 2 CNV4 * CNV7: Sequencer n INN Identifier of the 8th Conversion to Perform * CNV6: Sequencer n INN Identifier of the 7th Conversion to Perform * CNV5: Sequencer n INN Identifier of the 6th Conversion to Perform * CNV4: Sequencer n INN Identifier of the 5th conversion to Perform 1128 32117A-10/2010 AT32UC3C 36.7.12 Name: Clock Divider Register CKDIV Access Type: Read/Write Offset: 0x44 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 - - - - - - - CNT[8] 7 6 5 4 3 2 1 0 CNT[7:0] * CNT: Max Counter Value Number of ADC clock cycles to count: (CNT + 1) * 2. 1129 32117A-10/2010 AT32UC3C 36.7.13 Name: Internal Timer Register ITIMER Access Type: Read/Write Offset: 0x48 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - ITMC[16] 15 14 13 12 11 10 9 8 3 2 1 0 ITMC[15:8] 7 6 5 4 ITMC[7:0] * ITMC: Internal Timer Max Counter Number of ADC clock cycles to wait for is (ITMC + 1). note: This allows SOC period up to 167 ms when CkADC clock is running at 1.5 MHz. 1130 32117A-10/2010 AT32UC3C 36.7.14 Name: Window Monitor n Configuration Register WCFGn Access Type: Read/Write Offset: 0x58+ n * 0x04 Reset Value: 0x00000000 31 30 29 - 28 27 26 25 SRC 23 22 21 24 WM 20 19 18 17 16 11 10 9 8 1 0 HT[11:4] 15 14 13 12 HT[3:0] 7 6 LT[11:8] 5 4 3 2 LT[7:0] * SRC: Index of the result register to monitor (0 to 16). * WM: Window Mode 0: No window mode. 1: Mode 1: RES(SRC) < HT. 2: Mode 2: RES(SRC) > LT. 3: Mode 3: LT< RES(SRC) < HT. 4: Mode 4: (LT >= RES(SRC)) || (RES(SRC) >= HT). 5: Reserved. 6: Reserved. 7: Reserved. * HT: High Threshold * LT: Low Threshold 1131 32117A-10/2010 AT32UC3C 36.7.15 Name: Sequencer n Last Converted Value LCVn Access Type: Read-only Offset: 0x60+ n * 0x04 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 19 18 17 16 11 10 9 8 3 2 1 0 LCV[31:24] 23 22 21 20 LCV[23:16] 15 14 13 12 LCV[15:8] 7 6 5 4 LCV[7:0] * LCV: Last Converted Value This field is set by hardware to the last sequencer converted value. Depending on precision, the higher bits are padded with the sign bit. 1132 32117A-10/2010 AT32UC3C 36.7.16 Name: ADC calibration register ADCCAL Access Type: Read/Write Offset: 0x68 Reset Value: 0x00000000 31 30 29 28 27 - 26 25 24 OCAL 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 2 1 0 7 GCAL[14:8] 6 5 4 3 GCAL[7:0] * OCAL: Offset Calibration * GCAL: Gain Calibration 1133 32117A-10/2010 AT32UC3C 36.7.17 Name: SH Calibration Register SHCAL Access Type: Read/Write Offset: 0x6C Reset Value: 0x00000000 31 30 23 22 29 28 27 26 25 24 - - - - 21 20 19 18 17 16 11 10 9 8 GAIN1[9:8] GAIN1[7:0] 15 14 - - 7 6 13 12 GAIN0[9:8] 5 4 3 2 1 0 GAIN0[7:0] * GAIN1: Sample and Hold 1 Gain Calibration * GAIN0: Sample and Hold 0 Gain Calibration 1134 32117A-10/2010 AT32UC3C 36.7.18 Name: Interrupt Enable Register IER Access Type: Write-only Offset: 0x70 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - 15 14 13 12 11 10 9 8 - SUTD MSOC1 MSOC0 WM1 WM0 - - 7 6 5 4 3 2 1 0 LOVR1 OVR1 SEOC1 SEOS1 LOVR0 OVR0 SEOC0 SEOS0 Writing a zero to a bit in this register has no effect. Writing a one to a bit in this register will set the corresponding bit in IMR. 1135 32117A-10/2010 AT32UC3C 36.7.19 Name: Interrupt Disable Register IDR Access Type: Write-only Offset: 0x74 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - 15 14 13 12 11 10 9 8 - SUTD MSOC1 MSOC0 WM1 WM0 - - 7 6 5 4 3 2 1 0 LOVR1 OVR1 SEOC1 SEOS1 LOVR0 OVR0 SEOC0 SEOS0 Writing a zero to a bit in this register has no effect. Writing a one to a bit in this register will clear the corresponding bit in IMR. 1136 32117A-10/2010 AT32UC3C 36.7.20 Name: Interrupt Mask Register IMR Access Type: Read-only Offset: 0x78 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - 15 14 13 12 11 10 9 8 - SUTD MSOC1 MSOC0 WM1 WM0 - - 7 6 5 4 3 2 1 0 LOVR1 OVR1 SEOC1 SEOS1 LOVR0 OVR0 SEOC0 SEOS0 0: The corresponding interrupt is disabled. 1: The corresponding interrupt is enabled. A bit in this register is cleared when the corresponding bit in IDR is written to one. A bit in this register is set when the corresponding bit in IER is written to one. 1137 32117A-10/2010 AT32UC3C 36.7.21 Name: Version Register VERSION Access Type: Read-only Offset: 0x7C Reset Value: - 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - 15 14 13 12 9 8 - - - - 7 6 5 4 VARIANT 11 10 VERSION[11:8] 3 2 1 0 VERSION[7:0] * VARIANT: Variant Number Reserved. No functionality associated. * VERSION: Version Number Version number of the module. No functionality associated. 1138 32117A-10/2010 AT32UC3C 36.7.22 Name: Parameter Register PARAMETER Access Type: Read-only Offset: 0x80 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 3 2 1 0 N 7 6 5 4 M * N: Number of Channels * M: Number of States per Sequencer 1139 32117A-10/2010 AT32UC3C 36.7.23 Name: Result Register RESn Access Type: Read-only Offset: 0x84+ n * 0x04 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 19 18 17 16 11 10 9 8 3 2 1 0 RES[31:24] 23 22 21 20 RES[23:16] 15 14 13 12 RES[15:8] 7 6 5 4 RES[7:0] * RES: Result register Contains value of conversion n. 1140 32117A-10/2010 AT32UC3C 36.8 Module configuration The specific configuration for each ADC instance is listed in the following tables. The module bus clocks listed here are connected to the system bus clocks according to the table in the System Bus Clock Connections section. Table 36-13. Module configuration Feature ADCIFA NBCONV 8 Table 36-14. Module clock name Module name Clock name Description ADCIFA CLK_ADCIFA Peripheral Bus clock from the PBC clock domain Table 36-15. Register Reset Values Register Reset Value VERSION 0x00000110 PARAMETER 0X00000808 The differential inputs of the ADC are configured through the following registers of the ADCIFA: * INPSEL00, INPSEL01, INNSEL00 and INNSEL01 for the sequencer 0 * INPSEL10, INPSEL11, INNSEL10 and INNSEL11 for the sequencer 1 The configuration allows to select pin or internal voltage. The ADC voltage reference can be selected as external reference through the RS register of the ADCIFA. For detail, see the ADCIFA chapter. 1141 32117A-10/2010 AT32UC3C The following table defines the valid settings for the CONV field of the INPSELxy and INNSELxy registers in the ADCIFA. This setting defines the mapping of the ADC input voltage. Table 36-16. INP0/1 selection INPSEL00[CONVi], INPSEL10[CONVi], INPSEL01[CONVi], INPSEL11[CONVi] Name Connection 0 ADCIN0 1 ADCIN1 See Peripheral Multiplexing on I/O line chapter 2 ADCIN2 3 ADCIN3 4 ADCIN4 5 ADCIN5 6 ADCIN6 7 ADCIN7 8 DAC0_int Internal output of the DAC0 10 GNDANA Analog Ground Table 36-17. INN0/1 selection INNSEL00[CONVi], INNSEL10[CONVi], INNSEL01[CONVi], INNSEL11[CONVi] Name Connection 0 ADCIN8 1 ADCIN9 See Peripheral Multiplexing on I/O line chapter 2 ADCIN10 3 ADCIN11 4 ADCIN12 5 ADCIN13 6 ADCIN14 7 ADCIN15 8 DAC1_int Internal output of the DAC1 9 GNDANA Analog Ground Table 36-18. External Reference selection RS Name 0 Internal 1V reference 1 Internal 0.6*VDDANA reference 2 ADCREF0 3 ADCREF1 Connection See Peripheral Multiplexing on I/O line chapter 1142 32117A-10/2010 AT32UC3C 37. DACIFB Interface (DACIFB) Rev.: 1.1.0.0 37.1 Features * * * * * * * * * 37.2 12-bit resolution Up to 1 mega-samples per second conversion rate in single channel mode Flexible conversion range Multiple trigger sources for each channel 1 continuous time or 2 Sample/Hold (S/H) outputs Built-in offset and gain calibration Can be used as input to analog comparator or ADC (as an internal wire and without S/H stage) Two PDCA channels Low-power mode Overview The DAC converts digital values to analog voltages. The DAC has 12-bit resolution and is capable of converting 1 million samples per second. The output from the DAC can either be continuous to one pin, or fed to two different pins using a sample and hold circuitry. Options like low power mode and gain and offset calibration are available. The output signal swing is defined by the reference voltage AREF. The DAC operates in unipolar mode, i.e. output voltage shifts within the 0V to AREF range. The following sources are available as AREF in the DAC: * VDDANA * An external reference applied to the DACREF input pin. 1143 32117A-10/2010 AT32UC3C 37.3 Block Diagram Figure 37-1. DACIFB Block Diagram DAC INTERFACE I N T P D C A Timer Channel A Timer Channel B PEVC Ch A data empty Ch B data empty Ch A data underrun Ch B data underrun Ch A data overrun Ch B data overrun C O N T R O L Prescaler Channel B Trigger MUX Channel A Trigger MUX Trig select B DAC CTRL Analog DAC Trig select A DAC Channel S/H Output A/B Select Arbiter Enable Output Control and Driver (S/H) Data Alignment P B Data Channel A I/O Controller DAC Channel S/H Output 16 bits Ch A Data Alignment 12 bits Ch B DAC 12 bits Data Channel B 16 bits DAC CALIBRATION CTRL Gain Calibration Internal Output to Analog Comparator or ADC Offset Calibration 1144 32117A-10/2010 AT32UC3C 37.4 I/O Lines Description Table 37-1. 37.5 37.5.1 I/O Lines Description Pin Name Pin Description Type Active Level DACxA DACx channel A analog output Output N/A DACxB DACx channel B analog output Output N/A DACREF DAC voltage reference Input N/A Product Dependencies I/O Lines The pins used for interfacing the DAC may be multiplexed with GPIO lines. The programmer must first program the GPIO controller to assign the desired DAC pins to their peripheral function. If I/O lines of the DAC are not used by the application, they can be used for other purposes by the GPIO controller. 37.5.2 Power Management If the CPU enters a sleep mode that disables CLK_DACIFB used by the DACIFB, the DACIFB will stop functioning and resume operation after the system wakes up from sleep mode. 37.5.3 Clocks The DACIFB is clocked through the Power Manager (PM), thus the programmer must first configure the PM to enable the CLK_DACIFB clock. This clock is enabled at reset, and can be disabled in the Power Manager. It is recommended to disable the DACIFB before disabling the clock, to avoid freezing the DACIFB in an undefined state. 37.5.4 Interrupts The DACIFB interrupt lines are connected to the internal sources of the interrupt controller. Using the DACIFB interrupts requires the interrupt controller to be programmed first. 37.5.5 Peripheral Events The DACIFB peripheral events are connected via the Peripheral Event Controller. Refer to the Peripheral Event Controller chapter for details. 37.5.6 Debug Operation The DACIDFB is disabled during debug operation, unless the Run In Debug bit in the Development Control Register is set and the bit corresponding to the DACIFB is set in the Peripheral Debug Register (PDBG). Please refer to the On-Chip Debug chapter in the AVR32UC Technical Reference Manual, and the OCD Module Configuration section, for details. The DACIFB is debug-mode aware. When the CPU is in debug mode, all the incoming triggers are blocked, therefore the DMA based conversions stop upon debug mode activation. The auto refresh functionality is kept active so that the last converted value remains visible on both channels outputs. However, if the autotrig mode is not set it is still possible to perform "one shot" conversions (triggered by write accesses to the data register). 1145 32117A-10/2010 AT32UC3C 37.6 Functional Description 37.6.1 Basic Operation 37.6.1.1 Timing constraints Some timing constraints must be observed in order to make sure the S/H circuitry operates correctly. These are relative to the frequency of the peripheral clock of the DACIFB, as this will affect the charging/discharging periods of the S/H circuitry. Not meeting the timing constraints may reduce the accuracy of the DAC conversions. - The DAC sampling time is the time interval between two conversions. This should not be less than 1s (without S/H operating) or 1.5s (with S/H operating). Enabling the refresh mode is relevant only if the DAC conversions are triggered using a low sampling frequency (i.e. with a period equal or above 30s). In this case, without any refresh, the S/H circuitry lets the analog value decay significantly between two conversions. - The DAC refresh time is the time interval between two channel data updates. This should not be more than 30s. - Also, the refresh frequency should not be lower than the sampling frequency. The analog DAC has a startup time of 2s. This means that if the DAC clock has a frequency of 33MHz, software has to wait for roughly 70 DAC clock cycles before considering conversion of the first data. See Figure 37-2 for a detailed view of the timing constraints. Please note that even if the programmed channel interval is equivalent to 1s, the actual channel interval will be 1.5s if the S/H circuitry is enabled and used. 1146 32117A-10/2010 AT32UC3C Figure 37-2. DAC Conversion and S/H Command Timing Constraints 37.6.1.2 Starting a conversion Conversions are either performed upon writes to the data registers or timed by an incoming event (this is "auto-trig mode"). Both application software and the Peripheral DMA controller may write to the data registers. Using the Peripheral DMA Controller to write data to the DACIFB, together with an event input to trigger conversions, gives the most accurate timing for conversions. The Peripheral DMA Controller data transfer rate depends on the sampling frequency imposed by the event line. The DACIFB sends a request to the Peripheral DMA Controller, and once the request is granted (Peripheral DMA Controller acknowledge) the conversion is performed upon reception of a trigger event. 37.6.1.3 Data Registers Data to be converted are taken from two registers, one for each channel: Data Register 0 (DR0) for channel A and Data Register 1 (DR1) for channel B. 1147 32117A-10/2010 AT32UC3C Alternatively both samples to be converted can be written to DR0 in a single write cycle, in this configuration the value for channel B and A are written to the upper and the lower half words of DR0, respectively. This operation is possible only if the DAC Dual Data in Data Register A bit of the Configuration register (CFR.DDA) is enabled. While the field reserved for the data to be converted is 16 bits wide, only the 12 lower bits are considered for conversion. In order to match the expected data alignment, rounded right and left shifts are programmable within a separate register for each data channel. 37.6.1.4 Output channels The output from the DAC can either be continuous to one pin (DAC channel A only), or fed to two different pins using a sample and hold circuitry (S/H). With S/H these two outputs can act independently and create two different analog signals, different in both voltage and frequency. The two S/H outputs have individual data and conversion control registers. The DAC output may be used as internal input signal to other peripherals, such as the Analog Comparator or the ADC. Only the DAC internal output can be used as internal input, the S/H outputs can not be used. 37.6.2 Advanced Operation 37.6.2.1 Prescaler Within the DACIFB a programmable prescaler generates a down-sampled signal from the system clock. This signal is then fed to the programmable counters handling channel interval (i.e. sample rate period), S/H refresh frequency as well as trigger event timers for both channels. This allows fine tuning of the DAC timings. As shown on Figure 37-3, the PrescalerClock provides a time base (Figure 37-4) to the Channel Interval Counter, each Channel Refresh Counter and DACIFB internal timers, see Timing Register Channel A (TRA) and Timing Register Channel B (TRB). The timers are decremented at each clock tick of PrescalerClock. The following constraints must always be respected: * The channel interval time must always be greater or equal to 1s (without S/H) or 1.5s (with S/H), to ensure that conversion of the next channel data is not started until the conversion to the first channel has settled. * The channel refresh period must always be less than or equal to 30s. * Also, the refresh frequency should not be lower than the sampling frequency. * When both channels are in use, make sure channel X refresh rate is not significantly higher than channel Y sample rate as this might cause unexpected behavior on channel Y. 1148 32117A-10/2010 AT32UC3C Figure 37-3. DAC Timing Counters Channel Interval Counter TCR.CHI[6:0] Prescaler Refresh Counter Prescaler Clock TCR.PRESC[2:0] TCR.CHRA[3:0] Refresh Counter clk_dac TCR.CHRB[3:0] Timing Counter Timing Counter TRA.TCD[7:0] TRB.TCD[7:0] Figure 37-4. DAC Prescaler Output Clock Signal 37.6.2.2 Low Power mode In order to reduce the power consumption during DAC conversions, the DAC Low Power mode may be enabled. In low power mode, the DAC is turned off between each conversion. Conversion time will be longer if new conversions are started in this mode: the DAC output's settling time increases fourfold which means single channel sample rate will peak at 250 Ksamples/s (without S/H). 37.6.2.3 Calibration To achieve optimal accuracy, it is possible to calibrate both gain and offset error in the DAC. There is a 7-bit calibration value for gain adjustment and a 7-bit calibration value for offset adjustment. Gain and Offset are not calibrated automatically and this must be done by software. To perform this operation, the DAC internal output must be routed to the ADC using the CR.IE bit. 1149 32117A-10/2010 AT32UC3C The test values converted by the DAC are sampled by the ADC which returns a measure of the output. Knowing the difference between a series of input values and their measured images after conversion, it is possible to compute both gain and offset biases. To get the best calibration result, it is recommended to use the same AREF voltage, output channel selection, sampling time, and refresh interval when calibrating as in normal DAC operation. Including errors, the DAC output value can be expressed as: VDACxX = gain x (DATACHx / 0xFFF) + offset In an ideal DAC, gain is 1 and offset 0. 37.6.3 Interrupts An interrupt request will be generated if the corresponding bit in the Interrupt Mask Register (IMR) is set. Bits in IMR are set by writing a one to the corresponding bit in the Interrupt Enable Register (IER), and cleared by writing a one to the corresponding bit in the Interrupt Disable Register (IDR). The interrupt request remains active until the corresponding bit in SR is cleared by writing a one to the corresponding bit in the Status Clear Register (SCR). When a data is completely processed, and if the data input buffer is empty, the DACIFB signals a data empty interrupt to the interrupt controller. An underrun interrupt may be generated when two consecutive trigger events are issued without any data delivered to the DACIFB in the meantime. An overrun interrupt may be generated when two consecutive data are delivered without any trigger event. Figure 37-5, Figure 37-6 and Figure 37-7 show the conditions generating interrupts. Figure 37-5. Data Empty Interrupt Generation Figure 37-6. Data Underrun Interrupt Generation 1150 32117A-10/2010 AT32UC3C Figure 37-7. Data Overrun Interrupt Generation 37.6.4 Peripheral Events Channel conversions can be triggered by an independent event source. A simple arbiter prioritizes trigger event requests if the two channels are activated at the same time. Trigger events for both channels are taken either from the PEVC input or from the DACIFB internal timers. These two timers are set up separately and both use PrescalerClock as their reference clock. 1151 32117A-10/2010 AT32UC3C 37.7 User Interface Table 37-2. 1. DACIFB Register Memory Map Offset Register Register Name Access Reset 0x00 Control Register CR Read/Write 0x00000000 0x04 Configuration Register CFR Read/Write 0x00000000 0x08 Event Input Control Register ECR Read/Write 0x00000000 0x0C Timing Control Register TCR Read/Write 0x00000000 0x10 Interrupt Enable Register IER Write-only - 0x14 Interrupt Disable Register IDR Write-only - 0x18 Interrupt Mask Register IMR Read-only 0x00000000 0x1C Status Register SR Read-only 0x00000000 0x20 Status Clear Register SCR Write-only - 0x24 Data Register Control Channel A DRCA Read/Write 0x00000001 0x28 Data Register Control Channel B DRCB Read/Write 0x00000001 0x2C Data Register 0 DR0 Read/Write 0x00000000 0x30 Data Register 1 DR1 Read/Write 0x00000000 0x34 Gain and Offset Calibration Register GOC Read/Write 0x00000000 0x38 Timer Register Channel A TRA Read/Write 0x00000000 0x3C Timer Register Channel B TRB Read/Write 0x00000000 0x40 Version Register VERSION Read-only - (1) The reset value for this register is device specific. Please refer to the Module Configuration section at the end of this chapter. 1152 32117A-10/2010 AT32UC3C 37.7.1 Name: Control Register CR Access Type: Read/Write Offset: 0x00 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - ARBE ARAE TRBE TRAE 23 22 21 20 19 18 17 16 - - - - - - BOE AOE 15 14 13 12 11 10 9 8 - - - - - - - - 7 6 5 4 3 2 1 0 - - - - - - - EN * ARBE: DAC Auto Refresh Channel B Enable Write this bit to zero to disable the auto refresh on channel B. Write this bit to one to enable the auto refresh on channel B. * ARAE: DAC Auto Refresh Channel A Enable Write this bit to zero to disable the auto refresh on channel A. Write this bit to one to enable the auto refresh on channel A. * TRBE: DAC Timer Register Channel B Enable Write this bit to zero to disable the timer generating a clocked trigger on channel B. Write this bit to one to enable the timer generating a clocked trigger on channel B. * TRAE: DAC Timer Register Channel A Enable Write this bit to zero to disable the timer generating a clocked trigger on channel A. Write this bit to one to enable the timer generating a clocked trigger on channel A. * BOE: DAC Channel B Output Enable Write this bit to zero to disable the channel B analog output. Write this bit to one to enable channel B analog output. * AOE: DAC Channel A Output Enable Write this bit to zero to disable the channel A analog output. Write this bit to one to enable channel A analog output. * EN: DAC Enable Write this bit to zero to disable the DAC. Write this bit to one to enable the DAC. 1153 32117A-10/2010 AT32UC3C 37.7.2 Name: Configuration Register CFR Access Type: Read/Write Offset: 0x04 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - 23 22 21 20 19 18 17 16 - - - - - - ABE AAE 15 14 13 12 11 10 9 8 - - - - - - - REF 7 6 5 4 3 2 1 0 - - - - - DSE DDA LP CHC * CHC: DAC Channel Configuration These bits control whether the DAC should operate with sample and hold on outputs or not. CHC Description 0 Both channel's S/H modules deactivated. Internal routing only. 1 Both channel's S/H modules activated in analog DAC, but no dac_sample_ch_b signal and no refresh on channel B. 2 Both channel's S/H modules activated in analog DAC, but no dac_sample_ch_a signal and no refresh on channel A. 3 Both channel's S/H modules activated in analog DAC. dac_sample_ch_x and refresh active on both channels. * ABE: DAC Auto Triggered Mode Enable Channel B 0: The conversion is triggered by the data register write access. 1: the incoming event (from the event line selected in the ECR Register) triggers the conversion once a new value is written to the data register CHB_DATA. * AAE: DAC Auto Triggered Mode Enable Channel A 0: The conversion is triggered by the data register write access. 1: the incoming event (from the event line selected in the ECR Register) triggers the conversion once a new value is written to the data register CHA_DATA. 1154 32117A-10/2010 AT32UC3C * REF: DAC Reference Selection This bit controls the voltage reference selection and thus the conversion range of the DAC. REF Voltage Reference Selection 0 External Reference (VREF+ pin) 1 VDDANA * DSE: DAC Data Setup Extra Clock Cycle 0: No extra clock latency. 1: Add an extra clock cycle latency between data written and start of conversion. This is useful when the DAC clock is running too fast. Adding an extra clock cycle latency might help meeting the data setup constraint. * DDA: DAC Dual Data in Data Register A 0:No dual data in DR0. 1:Dual data in DR0. It enables writing two 16-bit data words in a single write operation to the DR0 register. In this case the 16 upper bits are assigned to the channel B data word while the lower 16 bits remain assigned to the channel A data word. * LP: DAC Low Power Reduction Mode 0: DAC low power mode disabled. 1: DAC low power mode enabled. 1155 32117A-10/2010 AT32UC3C 37.7.3 Name: Event Input Control Register ECR Access Type: Read/Write Offset: 0x08 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 - - - - - - - ESLB 7 6 5 4 3 2 1 0 - - - - - - - ESLA * ESLB: DAC Event Input Selection Channel B 0: the channel B trigger timer is used 1: the peripheral event controller input is used * ESLA: DAC Event Input Selection Channel A 0: the channel A trigger timer is used 1: the peripheral event controller input is used 1156 32117A-10/2010 AT32UC3C 37.7.4 Name: Timing Control Register TCR Access Type: Read/Write Offset: 0x0C Reset Value: 0x00000000 31 30 29 28 27 - - - - - 23 22 21 20 19 - 26 25 24 PRESC 18 17 16 10 9 8 1 0 CHI 15 14 13 12 - - - - 7 6 5 4 - - - - 11 CHRB 3 2 CHRA * PRESC: DAC Timer Prescaler The prescaling ratio between PrescalerClock and CLK_DACIFB. PRESC Description 0 clk_dacifb / 1 1 clk_dacifb / 2 2 clk_dacifb / 4 3 clk_dacifb / 8 4 clk_dacifb / 16 5 clk_dacifb / 32 6 clk_dacifb / 64 7 clk_dacifb / 128 * CHI: DAC Channel Interval Control The minimum time between two consecutive conversions in number of prescaler clock ticks to be counted during the interval. * CHRn : DAC Channel Refresh Timing Control Channel n The time interval between each channel n output refresh. This interval avoids losing accuracy of the converted value before conversion of the next data. CHRn Description 0 PrescalerClock / 2 1 PrescalerClock / 4 2 PrescalerClock / 8 1157 32117A-10/2010 AT32UC3C CHRn Description 3 PrescalerClock / 16 4 PrescalerClock / 32 5 PrescalerClock / 64 6 PrescalerClock / 128 7 PrescalerClock / 256 8 PrescalerClock / 512 9 PrescalerClock / 1024 others Reserved 1158 32117A-10/2010 AT32UC3C 37.7.5 Name: Interrupt Enable Register IER Access Type: Write-only Offset: 0x10 Reset Value: - 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - DEB DEA 15 14 13 12 11 10 9 8 - - - - - - UA UA 7 6 5 4 3 2 1 0 - - - - - - OB OA Writing a zero to a bit in this register has no effect. Writing a one to a bit in this register will set the corresponding bit in IMR. 1159 32117A-10/2010 AT32UC3C 37.7.6 Name: Interrupt Disable Register IDR Access Type: Write-only Offset: 0x14 Reset Value: - 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - DEB DEA 15 14 13 12 11 10 9 8 - - - - - - UB UA 7 6 5 4 3 2 1 0 - - - - - - OB OA Writing a zero to a bit in this register has no effect. Writing a one to a bit in this register will clear the corresponding bit in IMR. 1160 32117A-10/2010 AT32UC3C 37.7.7 Name: Interrupt Mask Register IMR Access Type: Read-only Offset: 0x18 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - DEB DEA 15 14 13 12 11 10 9 8 - - - - - - UB UA 7 6 5 4 3 2 1 0 - - - - - - OB OA 0: The corresponding interrupt is disabled. 1: The corresponding interrupt is enabled. A bit in this register is cleared when the corresponding bit in IDR is written to one. A bit in this register is set when the corresponding bit in IER is written to one. 1161 32117A-10/2010 AT32UC3C 37.7.8 Name: Status Register SR Access Type: Read-only Offset: 0x1C Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - DEB DEA 15 14 13 12 11 10 9 8 - - - - - - UB UA 7 6 5 4 3 2 1 0 - - - - - - OB OA * DEB: DAC Data Register Empty Channel B Flag 0: Data register not empty, writing to the data register may cause losing a conversion value. 1: Data register for channel B is empty, meaning that a new conversion value may be written. * DEA: DAC Data Register Empty Channel A Flag 0: Data register not empty, writing to the data register may cause losing a conversion value. 1: Data register for channel A is empty, meaning that a new conversion value may be written. * UB: DAC Underrun Interrupt Channel B Flag 0: No underrun in channel B has occurred. 1: Underrun has occurred, at least two consecutive trigger events were received without any new incoming data on channel B in the meantime. * UA: DAC Underrun Interrupt Channel A Flag 0: No underrun in channel A has occurred. 1: Underrun has occurred, at least two consecutive trigger events were received without any new incoming data on channel A in the meantime. * OB: DAC Overrun Interrupt Channel B Flag 0: No overrun in channel B has occurred. 1: Overrun has occurred, at least two consecutive incoming data values are written on channel B without any trigger event in the meantime. * OA: DAC Overrun Interrupt Channel A Flag 0: No overrun in channel A has occurred. 1: Overrun has occurred, at least two consecutive incoming data values are written on channel A without any trigger event in the meantime. 1162 32117A-10/2010 AT32UC3C 37.7.9 Name: Status Clear Register SCR Access Type: Write-only Offset: 0x20 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - DEB DEA 15 14 13 12 11 10 9 8 - - - - - - UB UA 7 6 5 4 3 2 1 0 - - - - - - OB OA Writing a bit to one will clear the corresponding bit in ISR. Writing a bit to zero has no effect. 1163 32117A-10/2010 AT32UC3C 37.7.10 Name: Data Register Control Channel A DRCA Access Type: Read/Write Offset: 0x24 Reset Value: 0x00000001 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 - - - - DSD 7 6 5 4 3 2 1 0 - - - - - - - DRN DSV * DSD: DAC Data Shift Direction 0: DAC data is right aligned 1: DAC data is left aligned. * DSV: DAC Data Shift Value The number of left or right shifts to be performed on the 16-bits data word before being fed to the DAC. Up to 4 left shifts and 4 right shifts are possible. Set bit 3 to obtain a left shift, leave it de-asserted to perform a right shift. * DRN: DAC Data Rounding Enable 0: No rounding 1: rounding with right shifting is enabled. This adds the integer value "1" to the data value before the last right shift. This feature is enabled by default. 1164 32117A-10/2010 AT32UC3C 37.7.11 Name: Data Register Control Channel B DRCB Access Type: Read/Write Offset: 0x28 Reset Value: 0x00000001 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 - - - - DSD 7 6 5 4 3 2 1 0 - - - - - - - DRN DSV * DSD: DAC Data Shift Direction 0: DAC data is right aligned 1: DAC data is left aligned. * DSV: DAC Data Shift Value The number of left or right shifts to be performed on the 16-bits data word before being fed to the DAC. Up to 4 left shifts and 4 right shifts are possible. Set bit 3 to obtain a left shift, leave it de-asserted to perform a right shift. * DRN: DAC Data Rounding Enable 0: No rounding 1: rounding with right shifting is enabled. This adds the integer value "1" to the data value before the last right shift. This feature is enabled by default. 1165 32117A-10/2010 AT32UC3C 37.7.12 Name: Data Register Channel 0 DR0 Access Type: Read/Write Offset: 0x2C Reset Value: 0x00000000 31 30 29 28 27 26 25 24 19 18 17 16 11 10 9 8 3 2 1 0 DCB 23 22 21 20 DCB 15 14 13 12 DCA 7 6 5 4 DCA * DCB: DAC Data Channel B When the DDA bit within the CFR register is activated, you can use this field to write the 12-bit data to be converted on channel B. However when the DDA bit within the CFR register is deactivated, use the DR1 register instead, as anything written in the DCB field will be ignored. * DCA: DAC Data Channel A The 12-bit value to be converted on channel A (right aligned). 1166 32117A-10/2010 AT32UC3C 37.7.13 Name: Data Register Channel 1 DR1 Access Type: Read/Write Offset: 0x30 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 3 2 1 0 DCB 7 6 5 4 DCB * DCB: DAC Data Channel B This field represents the 12-bit value to be converted on channel B (right aligned). 1167 32117A-10/2010 AT32UC3C 37.7.14 Name: Gain and Offset Calibration Register GOC Access Type: Read/Write Offset: 0x34 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - GCR 23 22 21 20 19 18 17 16 GCR 15 14 13 12 11 10 9 8 - - - - - - - OCR 7 6 5 4 3 2 1 0 OCR * GCR: DAC Gain Calibration Value These bits are used to compensate the gain error in the DAC. * OCR: DAC Offset Calibration Value These bits are used to compensate the offset error in the DAC. 1168 32117A-10/2010 AT32UC3C 37.7.15 Name: Timer Register Channel A TRA Access Type: Read/Write Offset: 0x38 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 TRL - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 - - - - - - - - 7 6 5 4 3 2 1 0 TCD * TRL: DAC Timer Reload Write this bit to one to re-initialize the countdown. * TCD: DAC Timer Count Down Value These bits are used to program the countdown value. The timer counts down from this value to zero and then outputs a pulse before reloading the count register. 1169 32117A-10/2010 AT32UC3C 37.7.16 Name: Timer Register Channel B TRB Access Type: Read/Write Offset: 0x3C Reset Value: 0x00000000 31 30 29 28 27 26 25 24 TRL - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 - - - - - - - - 7 6 5 4 3 2 1 0 TCD * TRL: DAC Timer Reload Write this bit to one to re-initialize the countdown. * TCD: DAC Timer Count Down Value These bits are used to program the countdown value. The timer counts down from this value to zero and then outputs a pulse before reloading the count register. 1170 32117A-10/2010 AT32UC3C 37.7.17 Name: Version Register VERSION Access Type: Read-only Offset: 0x40 Reset Value: - 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - 15 14 13 12 9 8 - - - - 7 6 5 4 1 0 VARIANT 11 10 VERSION 3 2 VERSION * VARIANT: Variant Number Reserved. No functionality associated. * VERSION: Version Number Version number of the module. No functionality associated. 1171 32117A-10/2010 AT32UC3C 37.8 Module Configuration The specific configuration for each DACIFB instance is listed in the following tables. The module bus clocks listed here are connected to the system bus clocks. Please refer to the Power Manager chapter for details. Table 37-3. DACIFB Clock Name Module Name Clock Name Description DACIFB0 CLK_DACIFB0 Peripheral Bus clock from the PBA clock domain DACIFB1 CLK_DACIFB1 Peripheral Bus clock from the PBA clock domain Table 37-4. Register Reset Values Register Reset Value VERSION 0x00000110 1172 32117A-10/2010 AT32UC3C 38. aWire UART (AW) Rev.: 2.3.0.0 38.1 Features * Asynchronous receiver or transmitter when the aWire system is not used for debugging. * One- or two-pin operation supported. 38.2 Overview If the AW is not used for debugging, the aWire UART can be used by the user to send or receive data with one start bit, eight data bits, no parity bits, and one stop bit. This can be controlled through the aWire UART user interface. This chapter only describes the aWire UART user interface. For a description of the aWire Debug Interface, please see the Programming and Debugging chapter. 38.3 Block Diagram Figure 38-1. aWire Debug Interface Block Diagram PB aWire Debug Interface Flash Controller CHIP_ERASE command AW User Interface CPU HALT command RESET command Power Manager External reset AW_ENABLE AW CONTROL Reset filter RESET_N Baudrate Detector SAB interface UART RW SZ ADDR DATA CRC SAB 1173 32117A-10/2010 AT32UC3C 38.4 I/O Lines Description Table 38-1. I/O Lines Description Name Description Type DATA aWire data multiplexed with the RESET_N pin. Input/Output 38.5 Product Dependencies In order to use this module, other parts of the system must be configured correctly, as described below. 38.5.1 I/O Lines The pin used by AW is multiplexed with the RESET_N pin. The reset functionality is the default function of this pin. To enable the aWire functionality on the RESET_N pin the user must enable the aWire UART user interface. 38.5.2 Power Management If the CPU enters a sleep mode that disables clocks used by the aWire UART user interface, the aWire UART user interface will stop functioning and resume operation after the system wakes up from sleep mode. 38.5.3 Clocks The aWire UART uses the internal 120 MHz RC oscillator (RC120M) as clock source for its operation. When using the aWire UART user interface RC120M must enabled using the Clock Request Register (see Section 38.6.1). The clock for the aWire UART user interface (CLK_AW) is generated by the Power Manager. This clock is enabled at reset, and can be disabled in the Power Manager. It is recommended to disable the aWire UART user interface before disabling the clock, to avoid freezing the aWire UART user interface in an undefined state. 38.5.4 Interrupts The aWire UART user interface interrupt request line is connected to the interrupt controller. Using the aWire UART user interface interrupt requires the interrupt controller to be programmed first. 38.5.5 Debug Operation If the AW is used for debugging the aWire UART user interface will not be usable. When an external debugger forces the CPU into debug mode, the aWire UART user interface continues normal operation. If the aWire UART user 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. 38.6 Functional Description The aWire UART user interface can be used as a spare Asynchronous Receiver or Transmitter when AW is not used for debugging. 1174 32117A-10/2010 AT32UC3C 38.6.1 How to Initialize The Module To initialize the aWire UART user interface the user must first enable the clock by writing a one to the Clock Enable bit in the Clock Request Register (CLKR.CLKEN) and wait for the Clock Enable bit in the Status Register (SR.CENABLED) to be set. After doing this either receive, transmit or receive with resync must be selected by writing the corresponding value into the Mode field of the Control (CTRL.MODE) Register. Due to the RC120M being asynchronous with the system clock values must be allowed to propagate in the system. During this time the aWire master will set the Busy bit in the Status Register (SR.BUSY). After the SR.BUSY bit is cleared the Baud Rate field in the Baud Rate Register (BRR.BR) can be written with the wanted baudrate ( f br ) according to the following formula ( f aw is the RC120M clock frequency): 8f aw f br = ---------BR After this operation the user must wait until the SR.BUSY is cleared. The interface is now ready to be used. 38.6.2 Basic Asynchronous Receiver Operation The aWire UART user interface must be initialized according to the sequence above, but the CTRL.MODE field must be written to one (Receive mode). When a data byte arrives the aWire UART user interface will indicate this by setting the Data Ready Interrupt bit in the Status Register (SR.DREADYINT). The user must read the Data in the Receive Holding Register (RHR.RXDATA) and clear the Interrupt bit by writing a one to the Data Ready Interrupt Clear bit in the Status Clear Register (SCR.DREADYINT). The interface is now ready to receive another byte. 38.6.3 Basic Asynchronous Transmitter Operation The aWire UART user interface must be initialized according to the sequence above, but the CTRL.MODE field must be written to two (Transmit mode). To transmit a data byte the user must write the data to the Transmit Holding Register (THE.TXDATA). Before the next byte can be written the SR.BUSY must be cleared. 38.6.4 Basic Asynchronous Receiver with Resynchronization By writing three into CTRL.MODE the aWire UART user interface will assume that the first byte it receives is a sync byte (0x55) and set BRR.BR according to this. All subsequent transfers will assume this baudrate, unless BRR.BR is rewritten by the user. To make the aWire UART user interface accept a new sync resynchronization the aWire UART user interface must be disabled by writing zero to CTRL.MODE and then reenable the interface. 38.6.5 Overrun In Receive mode an overrun can occur if the user has not read the previous received data from the RHR.RXDATA when the newest data should be placed there. Such a condition is flagged by setting the Overrun bit in the Status Register (SR.OVERRUN). If SR.OVERRUN is set the newest data received is placed in RHR.RXDATA and the data that was there before is overwritten. 1175 32117A-10/2010 AT32UC3C 38.6.6 Interrupts To make the CPU able to do other things while waiting for the aWire UART user interface to finish its operations the aWire UART user interface supports generating interrupts. All status bits in the Status Register can be used as interrupt sources, except the SR.BUSY and SR.CENABLED bits. To enable an interrupt the user must write a one to the corresponding bit in the Interrupt Enable Register (IER). Upon the next zero to one transition of this SR bit the aWire UART user interface will flag this interrupt to the CPU. To clear the interrupt the user must write a one to the corresponding bit in the Status Clear Register (SCR). Interrupts can be disabled by writing a one to the corresponding bit in the Interrupt Disable Register (IDR). The interrupt Mask Register (IMR) can be read to check if an interrupt is enabled or disabled. 38.6.7 Using the Peripheral DMA Controller To relieve the CPU of data transfers the aWire UART user interface support using the Peripheral DMA controller. To transmit using the Peripheral DMA Controller do the following: 1. Setup the aWire UART user interface in transmit mode. 2. Setup the Peripheral DMA Controller with buffer address and length, use byte as transfer size. 3. Enable the Peripheral DMA Controller. 4. Wait until the Peripheral DMA Controller is done. To receive using the Peripheral DMA Controller do the following: 1. Setup the aWire UART user interface in receive mode 2. Setup the Peripheral DMA Controller with buffer address and length, use byte as transfer size. 3. Enable the Peripheral DMA Controller. 4. Wait until the Peripheral DMA Controller is ready. 1176 32117A-10/2010 AT32UC3C 38.7 User Interface Table 38-2. Note: aWire UART user interface Register Memory Map Offset Register Register Name Access Reset 0x00 Control Register CTRL Read/Write 0x00000000 0x04 Status Register SR Read-only 0x00000000 0x08 Status Clear Register SCR Write-only - 0x0C Interrupt Enable Register IER Write-only - 0x10 Interrupt Disable Register IDR Write-only - 0x14 Interrupt Mask Register IMR Read-only 0x00000000 0x18 Receive Holding Register RHR Read-only 0x00000000 0x1C Transmit Holding Register THR Read/Write 0x00000000 0x20 Baud Rate Register BRR Read/Write 0x00000000 0x24 Version Register VERSION Read-only -(1) 0x28 Clock Request Register CLKR Read/Write 0x00000000 1. The reset values are device specific. Please refer to the Module Configuration section at the end of this chapter. 1177 32117A-10/2010 AT32UC3C 38.7.1 Name: Control Register CTRL Access Type: Read/Write Offset: 0x00 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 - - - - - - - - 7 6 5 4 3 2 1 0 - - - - - - MODE * MODE: aWire UART user interface mode Table 38-3. aWire UART user interface Modes MODE Mode Description 0 Disabled 1 Receive 2 Transmit 3 Receive with resync. 1178 32117A-10/2010 AT32UC3C 38.7.2 Name: Status Register SR Access Type: Read-only Offset: 0x04 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 - - TRMIS - - OVERRUN DREADYINT READYINT 7 6 5 4 3 2 1 0 - - - - - CENABLED - BUSY * TRMIS: Transmit Mismatch 0: No transfers mismatches. 1: The transceiver was active when receiving. This bit is set when the transceiver is active when receiving. This bit is cleared when corresponding bit in SCR is written to one. * OVERRUN: Data Overrun 0: No data overwritten in RHR. 1: Data in RHR has been overwritten before it has been read. This bit is set when data in RHR is overwritten before it has been read. This bit is cleared when corresponding bit in SCR is written to one. * DREADYINT: Data Ready Interrupt 0: No new data in the RHR. 1: New data received and placed in the RHR. This bit is set when new data is received and placed in the RHR. This bit is cleared when corresponding bit in SCR is written to one. * READYINT: Ready Interrupt 0: The interface has not generated an ready interrupt. 1: The interface has had a transition from busy to not busy. This bit is set when the interface has transition from busy to not busy. This bit is cleared when corresponding bit in SCR is written to one. * CENABLED: Clock Enabled 0: The aWire clock is not enabled. 1: The aWire clock is enabled. 1179 32117A-10/2010 AT32UC3C This bit is set when the clock is disabled. This bit is cleared when the clock is enabled. * BUSY: Synchronizer Busy 0: The asynchronous interface is ready to accept more data. 1: The asynchronous interface is busy and will block writes to CTRL, BRR, and THR. This bit is set when the asynchronous interface becomes busy. This bit is cleared when the asynchronous interface becomes ready. 1180 32117A-10/2010 AT32UC3C 38.7.3 Name: Status Clear Register SCR Access Type: Write-only Offset: 0x08 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 - - TRMIS - - OVERRUN DREADYINT READYINT 7 6 5 4 3 2 1 0 - - - - - - - - Writing a zero to a bit in this register has no effect. Writing a one to a bit in this register will clear the corresponding bit in SR and the corresponding interrupt request. 1181 32117A-10/2010 AT32UC3C 38.7.4 Name: Interrupt Enable Register IER Access Type: Write-only Offset: 0x0C Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 - - TRMIS - - OVERRUN DREADYINT READYINT 7 6 5 4 3 2 1 0 - - - - - - - - Writing a zero to a bit in this register has no effect. Writing a one to a bit in this register will set the corresponding bit in IMR. 1182 32117A-10/2010 AT32UC3C 38.7.5 Name: Interrupt Disable Register IDR Access Type: Write-only Offset: 0x10 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 - - TRMIS - - OVERRUN DREADYINT READYINT 7 6 5 4 3 2 1 0 - - - - - - - - Writing a zero to a bit in this register has no effect. Writing a one to a bit in this register will clear the corresponding bit in IMR. 1183 32117A-10/2010 AT32UC3C 38.7.6 Name: Interrupt Mask Register IMR Access Type: Read-only Offset: 0x14 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 - - TRMIS - - OVERRUN DREADYINT READYINT 7 6 5 4 3 2 1 0 - - - - - - - - 0: The corresponding interrupt is disabled. 1: The corresponding interrupt is enabled. A bit in this register is cleared when the corresponding bit in IDR is written to one. A bit in this register is set when the corresponding bit in IER is written to one. 1184 32117A-10/2010 AT32UC3C 38.7.7 Name: Receive Holding Register RHR Access Type: Read-only Offset: 0x18 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 - - - - - - - - 7 6 5 4 3 2 1 0 RXDATA * RXDATA: Received Data The last byte received. 1185 32117A-10/2010 AT32UC3C 38.7.8 Name: Transmit Holding Register THR Access Type: Read/Write Offset: 0x1C Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 - - - - - - - - 7 6 5 4 3 2 1 0 TXDATA * TXDATA: Transmit Data The data to send. 1186 32117A-10/2010 AT32UC3C 38.7.9 Name: Baud Rate Register BRR Access Type: Read/Write Offset: 0x20 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 3 2 1 0 BR[15:8] 7 6 5 4 BR[7:0] * BR: Baud Rate The baud rate ( f br ) of the transmission, calculated using the following formula ( f aw is the RC120M frequency): 8f aw f br = ---------BR BR should not be set to a value smaller than 32. Writing a value to this field will update the baud rate of the transmission. Reading this field will give the current baud rate of the transmission. 1187 32117A-10/2010 AT32UC3C 38.7.10 Name: Version Register VERSION Access Type: Read-only Offset: 0x24 Reset Value: 0x00000200 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 - - - - 7 6 5 4 VERSION[11:8] 3 2 1 0 VERSION[7:0] * VERSION: Version Number Version number of the module. No functionality associated. 1188 32117A-10/2010 AT32UC3C 38.7.11 Name: Clock Request Register CLKR Access Type: Read/Write Offset: 0x28 Reset Value: 0x00000000 31 30 29 28 27 26 25 24 - - - - - - - - 23 22 21 20 19 18 17 16 - - - - - - - - 15 14 13 12 11 10 9 8 - - - - - - - - 7 6 5 4 3 2 1 0 - - - - - - - CLKEN * CLKEN: Clock Enable 0: The aWire clock is disabled. 1: The aWire clock is enabled. Writing a zero to this bit will disable the aWire clock. Writing a one to this bit will enable the aWire clock. 1189 32117A-10/2010 AT32UC3C 38.8 Module Configuration The specific configuration for each aWire instance is listed in the following tables. The module bus clocks listed here are connected to the system bus clocks. Please refer to the Power Manager chapter for details. Table 38-4. Module clock name Module name Clock name Description aWire CLK_AW Peripheral Bus clock from the PBA clock domain Table 38-5. Register Reset Values Register Reset Value VERSION 0x00000230 1190 32117A-10/2010 AT32UC3C 39. Programming and Debugging 39.1 Overview The AT32UC3C supports programming and debugging through two interfaces, JTAG or aWireTM. JTAG is an industry standard interface and allows boundary scan for PCB testing, as well as daisy-chaining of multiple devices on the PCB. aWire is an Atmel proprietary protocol which offers higher throughput and robust communication, and does not require application pins to be reserved. Either interface provides access to the internal Service Access Bus (SAB), which offers a bridge to the High Speed Bus, giving access to memories and peripherals in the device. By using this bridge to the bus system, the flash and fuses can thus be programmed by accessing the Flash Controller in the same manner as the CPU. The SAB also provides access to the Nexus-compliant On-Chip Debug (OCD) system in the device, which gives the user non-intrusive run-time control of the program execution. Additionally, trace information can be output on the Auxiliary (AUX) debug port or buffered in internal RAM for later retrieval by JTAG or aWire. 39.2 Service Access Bus The AVR32 architecture offers a common interface for access to On-Chip Debug, programming, and test functions. These are mapped on a common bus called the Service Access Bus (SAB), which is linked to the JTAG and aWire port through a bus master module, which also handles synchronization between the debugger and SAB clocks. When accessing the SAB through the debugger there are no limitations on debugger frequency compared to chip frequency, although there must be an active system clock in order for the SAB accesses to complete. If the system clock is switched off in sleep mode, activity on the debugger will restart the system clock automatically, without waking the device from sleep. Debuggers may optimize the transfer rate by adjusting the frequency in relation to the system clock. This ratio can be measured with debug protocol specific instructions. The Service Access Bus uses 36 address bits to address memory or registers in any of the slaves on the bus. The bus supports sized accesses of bytes (8 bits), halfwords (16 bits), or words (32 bits). All accesses must be aligned to the size of the access, i.e. halfword accesses must have the lowest address bit cleared, and word accesses must have the two lowest address bits cleared. 39.2.1 SAB address map The Service Access Bus (SAB) gives the user access to the internal address space and other features through a 36 bits address space. The 4 MSBs identify the slave number, while the 32 LSBs are decoded within the slave's address space. The SAB slaves are shown in Table 39-1 on page 1191. Table 39-1. SAB Slaves, addresses and descriptions. Slave Address [35:32] Description Unallocated 0x0 Intentionally unallocated OCD 0x1 OCD registers HSB 0x4 HSB memory space, as seen by the CPU 1191 32117A-10/2010 AT32UC3C Table 39-1. 39.2.2 SAB Slaves, addresses and descriptions. Slave Address [35:32] Description HSB 0x5 Alternative mapping for HSB space, for compatibility with other 32-bit AVR devices. Memory Service Unit 0x6 Memory Service Unit registers Reserved Other Unused SAB security restrictions The Service Access bus can be restricted by internal security measures. A short description of the security measures are found in the table below. 39.2.2.1 Security measure and control location A security measure is a mechanism to either block or allow SAB access to a certain address or address range. A security measure is enabled or disabled by one or several control signals. This is called the control location for the security measure. These security measures can be used to prevent an end user from reading out the code programmed in the flash, for instance. Table 39-2. SAB Security Measures Security Measure Control Location Description Security bit FLASHC security bit set Programming and debugging not possible, very restricted access. User code programming FLASHC UPROT + security bit set Restricts all access except parts of the flash and the flash controller for programming user code. Debugging is not possible unless an OS running from the secure part of the flash supports it. Below follows a more in depth description of what locations are accessible when the security measures are active. Table 39-3. Security Bit SAB Restrictions Name Address start Address end Access OCD DCCPU, OCD DCEMU, OCD DCSR 0x100000110 0x100000118 Read/Write User page 0x580800000 0x581000000 Read Other accesses - - Blocked 1192 32117A-10/2010 AT32UC3C Table 39-4. User Code Programming SAB Restrictions Name Address start Address end Access OCD DCCPU, OCD DCEMU, OCD DCSR 0x100000110 0x100000118 Read/Write User page 0x580800000 0x581000000 Read FLASHCDW PB interface 0x5FFFE0000 0x5FFFE0400 Read/Write FLASH pages outside BOOTPROT 0x580000000 + BOOTPROT size 0x580000000 + Flash size Read/Write Other accesses - - Blocked 1193 32117A-10/2010 AT32UC3C 39.3 On-Chip Debug Rev: 2.0.0.0 39.3.1 Features * * * * * * * * 39.3.2 Debug interface in compliance with IEEE-ISTO 5001-2003 (Nexus 2.0) Class 2+ JTAG or aWire access to all on-chip debug functions Advanced Program, Data, Ownership, and Watchpoint trace supported NanoTrace aWire- or JTAG-based trace access Auxiliary port for high-speed trace information Hardware support for 6 Program and 2 Data breakpoints Unlimited number of software breakpoints supported Automatic CRC check of memory regions Overview Debugging on the AT32UC3C is facilitated by a powerful On-Chip Debug (OCD) system. The user accesses this through an external debug tool which connects to the JTAG or aWire port and the Auxiliary (AUX) port if implemented. The AUX port is primarily used for trace functions, and an aWire- or JTAG-based debugger is sufficient for basic debugging. The debug system is based on the Nexus 2.0 standard, class 2+, which includes: * Basic run-time control * Program breakpoints * Data breakpoints * Program trace * Ownership trace * Data trace In addition to the mandatory Nexus debug features, the AT32UC3C implements several useful OCD features, such as: * Debug Communication Channel between CPU and debugger * Run-time PC monitoring * CRC checking * NanoTrace * Software Quality Assurance (SQA) support The OCD features are controlled by OCD registers, which can be accessed by the debugger, for instance when the NEXUS_ACCESS JTAG instruction is loaded. The CPU can also access OCD registers directly using mtdr/mfdr instructions in any privileged mode. The OCD registers are implemented based on the recommendations in the Nexus 2.0 standard, and are detailed in the AVR32UC Technical Reference Manual. 39.3.3 I/O Lines Description The OCD AUX trace port contains a number of pins, as shown in Table 39-5 on page 1195. These are multiplexed with I/O Controller lines, and must explicitly be enabled by writing OCD registers before the debug session starts. The AUX port is mapped to two different locations, 1194 32117A-10/2010 AT32UC3C selectable by OCD Registers, minimizing the chance that the AUX port will need to be shared with an application. Table 39-5. 39.3.4 Auxiliary Port Signals Pin Name Pin Description Direction Active Level Type MCKO Trace data output clock Output Digital MDO[5:0] Trace data output Output Digital MSEO[1:0] Trace frame control Output Digital EVTI_N Event In EVTO_N Event Out Input Low Digital Output Low Digital Product Dependencies In order to use this module, other parts of the system must be configured correctly, as described below. 39.3.4.1 Power Management The OCD clock operates independently of the CPU clock. If enabled in the Power Manager, the OCD clock (CLK_OCD) will continue running even if the CPU enters a sleep mode that disables the CPU clock. 39.3.4.2 Clocks The OCD has a clock (CLK_OCD) running synchronously with the CPU clock. This clock is generated by the Power Manager. The clock is enabled at reset, and can be disabled by writing to the Power Manager. 39.3.4.3 Interrupt The OCD system interrupt request lines are connected to the interrupt controller. Using the OCD interrupts requires the interrupt controller to be programmed first. 1195 32117A-10/2010 AT32UC3C 39.3.5 Block Diagram Figure 39-1. On-Chip Debug Block Diagram aWire JTAG aWire JTAG AUX On-Chip Debug Memory Service Unit Service Access Bus Transmit Queue Watchpoints Debug PC Debug Instruction Breakpoints CPU 39.3.6 Program Trace Internal SRAM HSB Bus Matrix Data Trace Ownership Trace Memories and peripherals SAB-based Debug Features A debugger can control all OCD features by writing OCD registers over the SAB interface. Many of these do not depend on output on the AUX port, allowing an aWire- or JTAG-based debugger to be used. A JTAG-based debugger should connect to the device through a standard 10-pin IDC connector as described in the AVR32UC Technical Reference Manual. An aWire-based debugger should connect to the device through the RESET_N pin. 1196 32117A-10/2010 AT32UC3C Figure 39-2. JTAG-based Debugger PC JTA G -based debug tool 10-pin ID C JTAG 32-bit A VR Figure 39-3. aWire-based Debugger PC aWire-based debug tool aWire 32-bit AVR 39.3.6.1 Debug Communication Channel The Debug Communication Channel (DCC) consists of a pair OCD registers with associated handshake logic, accessible to both CPU and debugger. The registers can be used to exchange data between the CPU and the debugmaster, both runtime as well as in debug mode. 1197 32117A-10/2010 AT32UC3C The OCD system can generate an interrupt to the CPU when DCCPU is read and when DCEMU is written. This enables the user to build a custum debug protocol using only these registers. The DCCPU and DCEMU registers are available even when the security bit in the flash is active. For more information refer to the AVR32UC Technical Reference Manual. 39.3.6.2 Breakpoints One of the most fundamental debug features is the ability to halt the CPU, to examine registers and the state of the system. This is accomplished by breakpoints, of which many types are available: * Unconditional breakpoints are set by writing OCD registers by the debugger, halting the CPU immediately. * Program breakpoints halt the CPU when a specific address in the program is executed. * Data breakpoints halt the CPU when a specific memory address is read or written, allowing variables to be watched. * Software breakpoints halt the CPU when the breakpoint instruction is executed. When a breakpoint triggers, the CPU enters debug mode, and the D bit in the status register is set. This is a privileged mode with dedicated return address and return status registers. All privileged instructions are permitted. Debug mode can be entered as either OCD Mode, running instructions from the debugger, or Monitor Mode, running instructions from program memory. 39.3.6.3 OCD Mode When a breakpoint triggers, the CPU enters OCD mode, and instructions are fetched from the Debug Instruction OCD register. Each time this register is written by the debugger, the instruction is executed, allowing the debugger to execute CPU instructions directly. The debug master can e.g. read out the register file by issuing mtdr instructions to the CPU, writing each register to the Debug Communication Channel OCD registers. 39.3.6.4 Monitor Mode Since the OCD registers are directly accessible by the CPU, it is possible to build a softwarebased debugger that runs on the CPU itself. Setting the Monitor Mode bit in the Development Control register causes the CPU to enter Monitor Mode instead of OCD mode when a breakpoint triggers. Monitor Mode is similar to OCD mode, except that instructions are fetched from the debug exception vector in regular program memory, instead of issued by the debug master. 39.3.6.5 Program Counter Monitoring Normally, the CPU would need to be halted for a debugger to examine the current PC value. However, the AT32UC3C also proves a Debug Program Counter OCD register, where the debugger can continuously read the current PC without affecting the CPU. This allows the debugger to generate a simple statistic of the time spent in various areas of the code, easing code optimization. 39.3.7 Memory Service Unit The Memory Service Unit (MSU) is a block dedicated to test and debug functionality. It is controlled through a dedicated set of registers addressed through the Service Access Bus. 1198 32117A-10/2010 AT32UC3C 39.3.7.1 Cyclic Redundancy Check (CRC) The MSU can be used to automatically calculate the CRC of a block of data in memory. The MSU will then read out each word in the specified memory block and report the CRC32-value in an MSU register. 39.3.7.2 NanoTrace The MSU additionally supports NanoTrace. This is a 32-bit AVR-specific feature, in which trace data is output to memory instead of the AUX port. This allows the trace data to be extracted by the debugger through the SAB, enabling trace features for aWire- or JTAG-based debuggers. The user must write MSU registers to configure the address and size of the memory block to be used for NanoTrace. The NanoTrace buffer can be anywhere in the physical address range, including internal and external RAM, through an EBI, if present. This area may not be used by the application running on the CPU. 39.3.8 AUX-based Debug Features Utilizing the Auxiliary (AUX) port gives access to a wide range of advanced debug features. Of prime importance are the trace features, which allow an external debugger to receive continuous information on the program execution in the CPU. Additionally, Event In and Event Out pins allow external events to be correlated with the program flow. Debug tools utilizing the AUX port should connect to the device through a Nexus-compliant Mictor-38 connector, as described in the AVR32UC Technical Reference manual. This connector includes the JTAG signals and the RESET_N pin, giving full access to the programming and debug features in the device. 1199 32117A-10/2010 AT32UC3C Figure 39-4. AUX+JTAG Based Debugger PC T ra c e b u ffe r AU X +JTAG d e b u g to o l M ic to r3 8 AUX h ig h s p e e d JTAG AVR32 39.3.8.1 Trace Operation Trace features are enabled by writing OCD registers by the debugger. The OCD extracts the trace information from the CPU, compresses this information and formats it into variable-length messages according to the Nexus standard. The messages are buffered in a 16-frame transmit queue, and are output on the AUX port one frame at a time. The trace features can be configured to be very selective, to reduce the bandwidth on the AUX port. In case the transmit queue overflows, error messages are produced to indicate loss of data. The transmit queue module can optionally be configured to halt the CPU when an overflow occurs, to prevent the loss of messages, at the expense of longer run-time for the program. 39.3.8.2 Program Trace Program trace allows the debugger to continuously monitor the program execution in the CPU. Program trace messages are generated for every branch in the program, and contains compressed information, which allows the debugger to correlate the message with the source code to identify the branch instruction and target address. 39.3.8.3 Data Trace Data trace outputs a message every time a specific location is read or written. The message contains information about the type (read/write) and size of the access, as well as the address and data of the accessed location. The AT32UC3C contains two data trace channels, each of 1200 32117A-10/2010 AT32UC3C which are controlled by a pair of OCD registers which determine the range of addresses (or single address) which should produce data trace messages. 39.3.8.4 Ownership Trace Program and data trace operate on virtual addresses. In cases where an operating system runs several processes in overlapping virtual memory segments, the Ownership Trace feature can be used to identify the process switch. When the O/S activates a process, it will write the process ID number to an OCD register, which produces an Ownership Trace Message, allowing the debugger to switch context for the subsequent program and data trace messages. As the use of this feature depends on the software running on the CPU, it can also be used to extract other types of information from the system. 39.3.8.5 Watchpoint Messages The breakpoint modules normally used to generate program and data breakpoints can also be used to generate Watchpoint messages, allowing a debugger to monitor program and data events without halting the CPU. Watchpoints can be enabled independently of breakpoints, so a breakpoint module can optionally halt the CPU when the trigger condition occurs. Data trace modules can also be configured to produce watchpoint messages instead of regular data trace messages. 39.3.8.6 Event In and Event Out Pins The AUX port also contains an Event In pin (EVTI_N) and an Event Out pin (EVTO_N). EVTI_N can be used to trigger a breakpoint when an external event occurs. It can also be used to trigger specific program and data trace synchronization messages, allowing an external event to be correlated to the program flow. When the CPU enters debug mode, a Debug Status message is transmitted on the trace port. All trace messages can be timestamped when they are received by the debug tool. However, due to the latency of the transmit queue buffering, the timestamp will not be 100% accurate. To improve this, EVTO_N can toggle every time a message is inserted into the transmit queue, allowing trace messages to be timestamped precisely. EVTO_N can also toggle when a breakpoint module triggers, or when the CPU enters debug mode, for any reason. This can be used to measure precisely when the respective internal event occurs. 39.3.8.7 Software Quality Analysis (SQA) Software Quality Analysis (SQA) deals with two important issues regarding embedded software development. Code coverage involves identifying untested parts of the embedded code, to improve test procedures and thus the quality of the released software. Performance analysis allows the developer to precisely quantify the time spent in various parts of the code, allowing bottlenecks to be identified and optimized. Program trace must be used to accomplish these tasks without instrumenting (altering) the code to be examined. However, traditional program trace cannot reconstruct the current PC value without correlating the trace information with the source code, which cannot be done on-the-fly. This limits program trace to a relatively short time segment, determined by the size of the trace buffer in the debug tool. The OCD system in AT32UC3C extends program trace with SQA capabilities, allowing the debug tool to reconstruct the PC value on-the-fly. Code coverage and performance analysis can thus be reported for an unlimited execution sequence. 1201 32117A-10/2010 AT32UC3C 39.4 JTAG and Boundary-Scan (JTAG) Rev: 2.3.0.4 39.4.1 Features * IEEE1149.1 compliant JTAG Interface * Boundary-Scan Chain for board-level testing * Direct memory access and programming capabilities through JTAG Interface 39.4.2 Overview The JTAG Interface offers a four pin programming and debug solution, including boundary-scan support for board-level testing. Figure 39-5 on page 1203 shows how the JTAG is connected in an 32-bit AVR device. The TAP Controller is a state machine controlled by the TCK and TMS signals. The TAP Controller selects either the JTAG Instruction Register or one of several Data Registers as the scan chain (shift register) between the TDI-input and TDO-output. The Instruction Register holds JTAG instructions controlling the behavior of a Data Register. The Device Identification Register, Bypass Register, and the boundary-scan chain are the Data Registers used for board-level testing. The Reset Register can be used to keep the device reset during test or programming. The Service Access Bus (SAB) interface contains address and data registers for the Service Access Bus, which gives access to On-Chip Debug, programming, and other functions in the device. The SAB offers several modes of access to the address and data registers, as described in Section 39.4.11. Section 39.5 lists the supported JTAG instructions, with references to the description in this document. 1202 32117A-10/2010 AT32UC3C 39.4.3 Block Diagram Figure 39-5. JTAG and Boundary-Scan Access 32-bit AVR device JTAG JTAG master Boundary scan enable TAP Controller TDO TDI JTAG Pins TMS TCK TCK TMS TDI TDO Instruction register scan enable Data register scan enable Instruction Register TMS TCK TDO TDI JTAG data registers 2nd JTAG device Device Identification Register Boundary Scan Chain Pins and analog blocks By-pass Register Reset Register Part specific registers ... Service Access Bus interface SAB 39.4.4 Internal I/O lines I/O Lines Description Table 39-6. I/O Line Description Pin Name Pin Description Type Active Level RESET_N External reset pin. Used when enabling and disabling the JTAG. Input Low TCK Test Clock Input. Fully asynchronous to system clock frequency. Input TMS Test Mode Select, sampled on rising TCK. Input TDI Test Data In, sampled on rising TCK. Input TDO Test Data Out, driven on falling TCK. Output 39.4.5 Product Dependencies In order to use this module, other parts of the system must be configured correctly, as described below. 1203 32117A-10/2010 AT32UC3C 39.4.5.1 I/O Lines The TMS, TDI, TDO, and TCK pins are multiplexed with I/O lines. When the JTAG is used the associated pins must be enabled. To enable the JTAG pins, refer to Section 39.4.7. While using the multiplexed JTAG lines all normal peripheral activity on these lines is disabled. The user must make sure that no external peripheral is blocking the JTAG lines while debugging. 39.4.5.2 Power Management When an instruction that accesses the SAB is loaded in the instruction register, before entering a sleep mode, the system clocks are not switched off to allow debugging in sleep modes. This can lead to a program behaving differently when debugging. 39.4.5.3 Clocks The JTAG Interface uses the external TCK pin as clock source. This clock must be provided by the JTAG master. Instructions that use the SAB bus requires the internal main clock to be running. 39.4.6 JTAG Interface The JTAG Interface is accessed through the dedicated JTAG pins shown in Table 39-6 on page 1203. The TMS control line navigates the TAP controller, as shown in Figure 39-6 on page 1205. The TAP controller manages the serial access to the JTAG Instruction and Data registers. Data is scanned into the selected instruction or data register on TDI, and out of the register on TDO, in the Shift-IR and Shift-DR states, respectively. The LSB is shifted in and out first. TDO is highZ in other states than Shift-IR and Shift-DR. The device implements a 5-bit Instruction Register (IR). A number of public JTAG instructions defined by the JTAG standard are supported, as described in Section 39.5.2, as well as a number of 32-bit AVR-specific private JTAG instructions described in Section 39.5.3. Each instruction selects a specific data register for the Shift-DR path, as described for each instruction. 1204 32117A-10/2010 AT32UC3C Figure 39-6. TAP Controller State Diagram 1 Test-LogicReset 0 0 Run-Test/ Idle 1 Select-DR Scan 1 Select-IR Scan 1 0 1 0 Capture-DR 1 0 Shift-DR 0 0 Shift-IR 1 1 Exit1-DR Exit1-IR 0 0 Pause-DR 1 0 Exit2-DR 0 Pause-IR 1 1 0 1 1 Capture-IR Update-DR 0 0 0 1 Exit2-IR 1 1 Update-IR 0 1205 32117A-10/2010 AT32UC3C 39.4.7 How to Initialize the Module To enable the JTAG pins the TCK pin must be held low while the RESET_N pin is released. After enabling the JTAG interface the halt bit is set automatically to prevent the system from running code after the interface is enabled. To make the CPU run again set halt to zero using the HALT command.. JTAG operation when RESET_N is pulled low is not possible. Independent of the initial state of the TAP Controller, the Test-Logic-Reset state can always be entered by holding TMS high for 5 TCK clock periods. This sequence should always be applied at the start of a JTAG session and after enabling the JTAG pins to bring the TAP Controller into a defined state before applying JTAG commands. Applying a 0 on TMS for 1 TCK period brings the TAP Controller to the Run-Test/Idle state, which is the starting point for JTAG operations. 39.4.8 How to disable the module To disable the JTAG pins the TCK pin must be held high while RESET_N pin is released. 39.4.9 Typical Sequence Assuming Run-Test/Idle is the present state, a typical scenario for using the JTAG Interface follows. 39.4.9.1 Scanning in JTAG Instruction At the TMS input, apply the sequence 1, 1, 0, 0 at the rising edges of TCK to enter the Shift Instruction Register (Shift-IR) state. While in this state, shift the 5 bits of the JTAG instructions into the JTAG instruction register from the TDI input at the rising edge of TCK. During shifting, the JTAG outputs status bits on TDO, refer to Section 39.5 for a description of these. The TMS input must be held low during input of the 4 LSBs in order to remain in the Shift-IR state. The JTAG Instruction selects a particular Data Register as path between TDI and TDO and controls the circuitry surrounding the selected Data Register. Apply the TMS sequence 1, 1, 0 to re-enter the Run-Test/Idle state. The instruction is latched onto the parallel output from the shift register path in the Update-IR state. The Exit-IR, Pause-IR, and Exit2-IR states are only used for navigating the state machine. Figure 39-7. Scanning in JTAG Instruction TCK TAP State TLR RTI SelDR SelIR CapIR ShIR Ex1IR UpdIR RTI TMS TDI TDO 39.4.9.2 Instruction ImplDefined Scanning in/out Data At the TMS input, apply the sequence 1, 0, 0 at the rising edges of TCK to enter the Shift Data Register (Shift-DR) state. While in this state, upload the selected Data Register (selected by the present JTAG instruction in the JTAG Instruction Register) from the TDI input at the rising edge 1206 32117A-10/2010 AT32UC3C of TCK. In order to remain in the Shift-DR state, the TMS input must be held low. While the Data Register is shifted in from the TDI pin, the parallel inputs to the Data Register captured in the Capture-DR state is shifted out on the TDO pin. Apply the TMS sequence 1, 1, 0 to re-enter the Run-Test/Idle state. If the selected Data Register has a latched parallel-output, the latching takes place in the Update-DR state. The Exit-DR, Pause-DR, and Exit2-DR states are only used for navigating the state machine. As shown in the state diagram, the Run-Test/Idle state need not be entered between selecting JTAG instruction and using Data Registers. 39.4.10 Boundary-Scan The boundary-scan chain has the capability of driving and observing the logic levels on the digital I/O pins, as well as the boundary between digital and analog logic for analog circuitry having off-chip connections. At system level, all ICs having JTAG capabilities are connected serially by the TDI/TDO signals to form a long shift register. An external controller sets up the devices to drive values at their output pins, and observe the input values received from other devices. The controller compares the received data with the expected result. In this way, boundary-scan provides a mechanism for testing interconnections and integrity of components on Printed Circuits Boards by using the 4 TAP signals only. The four IEEE 1149.1 defined mandatory JTAG instructions IDCODE, BYPASS, SAMPLE/PRELOAD, and EXTEST can be used for testing the Printed Circuit Board. Initial scanning of the data register path will show the ID-code of the device, since IDCODE is the default JTAG instruction. It may be desirable to have the 32-bit AVR device in reset during test mode. If not reset, inputs to the device may be determined by the scan operations, and the internal software may be in an undetermined state when exiting the test mode. If needed, the BYPASS instruction can be issued to make the shortest possible scan chain through the device. The device can be set in the reset state either by pulling the external RESETn pin low, or issuing the AVR_RESET instruction with appropriate setting of the Reset Data Register. The EXTEST instruction is used for sampling external pins and loading output pins with data. The data from the output latch will be driven out on the pins as soon as the EXTEST instruction is loaded into the JTAG IR-register. Therefore, the SAMPLE/PRELOAD should also be used for setting initial values to the scan ring, to avoid damaging the board when issuing the EXTEST instruction for the first time. SAMPLE/PRELOAD can also be used for taking a snapshot of the external pins during normal operation of the part. When using the JTAG Interface for boundary-scan, the JTAG TCK clock is independent of the internal chip clock. The internal chip clock is not required to run during boundary-scan operations. NOTE: For pins connected to 5V lines care should be taken to not drive the pins to a logic one using boundary-scan, as this will create a current flowing from the 3,3V driver to the 5V pull-up on the line. Optionally a series resistor can be added between the line and the pin to reduce the current. Details about the boundary-scan chain can be found in the BSDL file for the device. This can be found on the Atmel website. 39.4.11 Service Access Bus The AVR32 architecture offers a common interface for access to On-Chip Debug, programming, and test functions. These are mapped on a common bus called the Service Access Bus (SAB), 1207 32117A-10/2010 AT32UC3C which is linked to the JTAG through a bus master module, which also handles synchronization between the TCK and SAB clocks. For more information about the SAB and a list of SAB slaves see the Service Access Bus chapter. 39.4.11.1 SAB Address Mode The MEMORY_SIZED_ACCESS instruction allows a sized read or write to any 36-bit address on the bus. MEMORY_WORD_ACCESS is a shorthand instruction for 32-bit accesses to any 36-bit address, while the NEXUS_ACCESS instruction is a Nexus-compliant shorthand instruction for accessing the 32-bit OCD registers in the 7-bit address space reserved for these. These instructions require two passes through the Shift-DR TAP state: one for the address and control information, and one for data. 39.4.11.2 Block Transfer To increase the transfer rate, consecutive memory accesses can be accomplished by the MEMORY_BLOCK_ACCESS instruction, which only requires a single pass through Shift-DR for data transfer only. The address is automatically incremented according to the size of the last SAB transfer. 39.4.11.3 Canceling a SAB Access It is possible to abort an ongoing SAB access by the CANCEL_ACCESS instruction, to avoid hanging the bus due to an extremely slow slave. 39.4.11.4 Busy Reporting As the time taken to perform an access may vary depending on system activity and current chip frequency, all the SAB access JTAG instructions can return a busy indicator. This indicates whether a delay needs to be inserted, or an operation needs to be repeated in order to be successful. If a new access is requested while the SAB is busy, the request is ignored. The SAB becomes busy when: * Entering Update-DR in the address phase of any read operation, e.g., after scanning in a NEXUS_ACCESS address with the read bit set. * Entering Update-DR in the data phase of any write operation, e.g., after scanning in data for a NEXUS_ACCESS write. * Entering Update-DR during a MEMORY_BLOCK_ACCESS. * Entering Update-DR after scanning in a counter value for SYNC. * Entering Update-IR after scanning in a MEMORY_BLOCK_ACCESS if the previous access was a read and data was scanned after scanning the address. The SAB becomes ready again when: * A read or write operation completes. * A SYNC countdown completed. * A operation is cancelled by the CANCEL_ACCESS instruction. What to do if the busy bit is set: * During Shift-IR: The new instruction is selected, but the previous operation has not yet completed and will continue (unless the new instruction is CANCEL_ACCESS). You may 1208 32117A-10/2010 AT32UC3C continue shifting the same instruction until the busy bit clears, or start shifting data. If shifting data, you must be prepared that the data shift may also report busy. * During Shift-DR of an address: The new address is ignored. The SAB stays in address mode, so no data must be shifted. Repeat the address until the busy bit clears. * During Shift-DR of read data: The read data is invalid. The SAB stays in data mode. Repeat scanning until the busy bit clears. * During Shift-DR of write data: The write data is ignored. The SAB stays in data mode. Repeat scanning until the busy bit clears. 39.4.11.5 Error Reporting The Service Access Bus may not be able to complete all accesses as requested. This may be because the address is invalid, the addressed area is read-only or cannot handle byte/halfword accesses, or because the chip is set in a protected mode where only limited accesses are allowed. The error bit is updated when an access completes, and is cleared when a new access starts. What to do if the error bit is set: * During Shift-IR: The new instruction is selected. The last operation performed using the old instruction did not complete successfully. * During Shift-DR of an address: The previous operation failed. The new address is accepted. If the read bit is set, a read operation is started. * During Shift-DR of read data: The read operation failed, and the read data is invalid. * During Shift-DR of write data: The previous write operation failed. The new data is accepted and a write operation started. This should only occur during block writes or stream writes. No error can occur between scanning a write address and the following write data. * While polling with CANCEL_ACCESS: The previous access was cancelled. It may or may not have actually completed. * After power-up: The error bit is set after power up, but there has been no previous SAB instruction so this error can be discarded. 39.4.11.6 Protected Reporting A protected status may be reported during Shift-IR or Shift-DR. This indicates that the security bit in the Flash Controller is set and that the chip is locked for access, according to Section 39.5.1. The protected state is reported when: * The Flash Controller is under reset. This can be due to the AVR_RESET command or the RESET_N line. * The Flash Controller has not read the security bit from the flash yet (This will take a a few ms). Happens after the Flash Controller reset has been released. * The security bit in the Flash Controller is set. What to do if the protected bit is set: * Release all active AVR_RESET domains, if any. * Release the RESET_N line. * Wait a few ms for the security bit to clear. It can be set temporarily due to a reset. 1209 32117A-10/2010 AT32UC3C * Perform a CHIP_ERASE to clear the security bit. NOTE: This will erase all the contents of the non-volatile memory. 39.5 JTAG Instruction Summary The implemented JTAG instructions in the 32-bit AVR are shown in the table below. Table 39-7. Instruction OPCODE JTAG Instruction Summary Instruction Description 0x01 IDCODE Select the 32-bit Device Identification register as data register. 0x02 SAMPLE_PRELOAD Take a snapshot of external pin values without affecting system operation. 0x03 EXTEST Select boundary-scan chain as data register for testing circuitry external to the device. 0x04 INTEST Select boundary-scan chain for internal testing of the device. 0x06 CLAMP Bypass device through Bypass register, while driving outputs from boundaryscan register. 0x0C AVR_RESET Apply or remove a static reset to the device 0x0F CHIP_ERASE Erase the device 0x10 NEXUS_ACCESS Select the SAB Address and Data registers as data register for the TAP. The registers are accessed in Nexus mode. 0x11 MEMORY_WORD_ACCESS Select the SAB Address and Data registers as data register for the TAP. 0x12 MEMORY_BLOCK_ACCESS Select the SAB Data register as data register for the TAP. The address is auto-incremented. 0x13 CANCEL_ACCESS Cancel an ongoing Nexus or Memory access. 0x14 MEMORY_SERVICE Select the SAB Address and Data registers as data register for the TAP. The registers are accessed in Memory Service mode. 0x15 MEMORY_SIZED_ACCESS Select the SAB Address and Data registers as data register for the TAP. 0x17 SYNC Synchronization counter 0x1C HALT Halt the CPU for safe programming. 0x1F BYPASS Bypass this device through the bypass register. N/A Acts as BYPASS Others 39.5.1 Security Restrictions When the security fuse in the Flash is programmed, the following JTAG instructions are restricted: * NEXUS_ACCESS * MEMORY_WORD_ACCESS * MEMORY_BLOCK_ACCESS * MEMORY_SIZED_ACCESS For description of what memory locations remain accessible, please refer to the SAB address map. Full access to these instructions is re-enabled when the security fuse is erased by the CHIP_ERASE JTAG instruction. 1210 32117A-10/2010 AT32UC3C Note that the security bit will read as programmed and block these instructions also if the Flash Controller is statically reset. Other security mechanisms can also restrict these functions. If such mechanisms are present they are listed in the SAB address map section. 39.5.1.1 Notation Table 39-9 on page 1211 shows bit patterns to be shifted in a format like "peb01". Each character corresponds to one bit, and eight bits are grouped together for readability. The least significantbit is always shifted first, and the most significant bit shifted last. The symbols used are shown in Table 39-8. Table 39-8. Symbol Symbol Description Description 0 Constant low value - always reads as zero. 1 Constant high value - always reads as one. a An address bit - always scanned with the least significant bit first b A busy bit. Reads as one if the SAB was busy, or zero if it was not. See Section 39.4.11.4 for details on how the busy reporting works. d A data bit - always scanned with the least significant bit first. e An error bit. Reads as one if an error occurred, or zero if not. See Section 39.4.11.5 for details on how the error reporting works. p The chip protected bit. Some devices may be set in a protected state where access to chip internals are severely restricted. See the documentation for the specific device for details. On devices without this possibility, this bit always reads as zero. r A direction bit. Set to one to request a read, set to zero to request a write. s A size bit. The size encoding is described where used. x A don't care bit. Any value can be shifted in, and output data should be ignored. In many cases, it is not required to shift all bits through the data register. Bit patterns are shown using the full width of the shift register, but the suggested or required bits are emphasized using bold text. I.e. given the pattern "aaaaaaar xxxxxxxx xxxxxxxx xxxxxxxx xx", the shift register is 34 bits, but the test or debug unit may choose to shift only 8 bits "aaaaaaar". The following describes how to interpret the fields in the instruction description tables: Table 39-9. Instruction Description Instruction Description IR input value Shows the bit pattern to shift into IR in the Shift-IR state in order to select this instruction. The pattern is show both in binary and in hexadecimal form for convenience. Example: 10000 (0x10) IR output value Shows the bit pattern shifted out of IR in the Shift-IR state when this instruction is active. Example: peb01 1211 32117A-10/2010 AT32UC3C Table 39-9. 39.5.2 Instruction Description (Continued) Instruction Description DR Size Shows the number of bits in the data register chain when this instruction is active. Example: 34 bits DR input value Shows which bit pattern to shift into the data register in the Shift-DR state when this instruction is active. Multiple such lines may exist, e.g., to distinguish between reads and writes. Example: aaaaaaar xxxxxxxx xxxxxxxx xxxxxxxx xx DR output value Shows the bit pattern shifted out of the data register in the Shift-DR state when this instruction is active. Multiple such lines may exist, e.g., to distinguish between reads and writes. Example: xx xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxeb Public JTAG Instructions The JTAG standard defines a number of public JTAG instructions. These instructions are described in the sections below. 39.5.2.1 IDCODE This instruction selects the 32 bit Device Identification register (DID) as Data Register. The DID register consists of a version number, a device number, and the manufacturer code chosen by JEDEC. This is the default instruction after a JTAG reset. Details about the DID register can be found in the module configuration section at the end of this chapter. Starting in Run-Test/Idle, the Device Identification register is accessed in the following way: 1. Select the IR Scan path. 2. In Capture-IR: The IR output value is latched into the shift register. 3. In Shift-IR: The instruction register is shifted by the TCK input. 4. Return to Run-Test/Idle. 5. Select the DR Scan path. 6. In Capture-DR: The IDCODE value is latched into the shift register. 7. In Shift-DR: The IDCODE scan chain is shifted by the TCK input. 8. Return to Run-Test/Idle. Table 39-10. IDCODE Details 39.5.2.2 Instructions Details IR input value 00001 (0x01) IR output value p0001 DR Size 32 DR input value xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx DR output value Device Identification Register SAMPLE_PRELOAD This instruction takes a snap-shot of the input/output pins without affecting the system operation, and pre-loading the scan chain without updating the DR-latch. The boundary-scan chain is selected as Data Register. Starting in Run-Test/Idle, the Device Identification register is accessed in the following way: 1212 32117A-10/2010 AT32UC3C 1. Select the IR Scan path. 2. In Capture-IR: The IR output value is latched into the shift register. 3. In Shift-IR: The instruction register is shifted by the TCK input. 4. Return to Run-Test/Idle. 5. Select the DR Scan path. 6. In Capture-DR: The Data on the external pins are sampled into the boundary-scan chain. 7. In Shift-DR: The boundary-scan chain is shifted by the TCK input. 8. Return to Run-Test/Idle. Table 39-11. SAMPLE_PRELOAD Details 39.5.2.3 Instructions Details IR input value 00010 (0x02) IR output value p0001 DR Size Depending on boundary-scan chain, see BSDL-file. DR input value Depending on boundary-scan chain, see BSDL-file. DR output value Depending on boundary-scan chain, see BSDL-file. EXTEST This instruction selects the boundary-scan chain as Data Register for testing circuitry external to the 32-bit AVR package. The contents of the latched outputs of the boundary-scan chain is driven out as soon as the JTAG IR-register is loaded with the EXTEST instruction. Starting in Run-Test/Idle, the EXTEST instruction is accessed the following way: 1. Select the IR Scan path. 2. In Capture-IR: The IR output value is latched into the shift register. 3. In Shift-IR: The instruction register is shifted by the TCK input. 4. In Update-IR: The data from the boundary-scan chain is applied to the output pins. 5. Return to Run-Test/Idle. 6. Select the DR Scan path. 7. In Capture-DR: The data on the external pins is sampled into the boundary-scan chain. 8. In Shift-DR: The boundary-scan chain is shifted by the TCK input. 9. In Update-DR: The data from the scan chain is applied to the output pins. 10. Return to Run-Test/Idle. Table 39-12. EXTEST Details Instructions Details IR input value 00011 (0x03) IR output value p0001 DR Size Depending on boundary-scan chain, see BSDL-file. DR input value Depending on boundary-scan chain, see BSDL-file. DR output value Depending on boundary-scan chain, see BSDL-file. 1213 32117A-10/2010 AT32UC3C 39.5.2.4 INTEST This instruction selects the boundary-scan chain as Data Register for testing internal logic in the device. The logic inputs are determined by the boundary-scan chain, and the logic outputs are captured by the boundary-scan chain. The device output pins are driven from the boundary-scan chain. Starting in Run-Test/Idle, the INTEST instruction is accessed the following way: 1. Select the IR Scan path. 2. In Capture-IR: The IR output value is latched into the shift register. 3. In Shift-IR: The instruction register is shifted by the TCK input. 4. In Update-IR: The data from the boundary-scan chain is applied to the internal logic inputs. 5. Return to Run-Test/Idle. 6. Select the DR Scan path. 7. In Capture-DR: The data on the internal logic is sampled into the boundary-scan chain. 8. In Shift-DR: The boundary-scan chain is shifted by the TCK input. 9. In Update-DR: The data from the boundary-scan chain is applied to internal logic inputs. 10. Return to Run-Test/Idle. Table 39-13. INTEST Details 39.5.2.5 Instructions Details IR input value 00100 (0x04) IR output value p0001 DR Size Depending on boundary-scan chain, see BSDL-file. DR input value Depending on boundary-scan chain, see BSDL-file. DR output value Depending on boundary-scan chain, see BSDL-file. CLAMP This instruction selects the Bypass register as Data Register. The device output pins are driven from the boundary-scan chain. Starting in Run-Test/Idle, the CLAMP instruction is accessed the following way: 1. Select the IR Scan path. 2. In Capture-IR: The IR output value is latched into the shift register. 3. In Shift-IR: The instruction register is shifted by the TCK input. 4. In Update-IR: The data from the boundary-scan chain is applied to the output pins. 5. Return to Run-Test/Idle. 6. Select the DR Scan path. 7. In Capture-DR: A logic `0' is loaded into the Bypass Register. 8. In Shift-DR: Data is scanned from TDI to TDO through the Bypass register. 1214 32117A-10/2010 AT32UC3C 9. Return to Run-Test/Idle. Table 39-14. CLAMP Details 39.5.2.6 Instructions Details IR input value 00110 (0x06) IR output value p0001 DR Size 1 DR input value x DR output value x BYPASS This instruction selects the 1-bit Bypass Register as Data Register. Starting in Run-Test/Idle, the CLAMP instruction is accessed the following way: 1. Select the IR Scan path. 2. In Capture-IR: The IR output value is latched into the shift register. 3. In Shift-IR: The instruction register is shifted by the TCK input. 4. Return to Run-Test/Idle. 5. Select the DR Scan path. 6. In Capture-DR: A logic `0' is loaded into the Bypass Register. 7. In Shift-DR: Data is scanned from TDI to TDO through the Bypass register. 8. Return to Run-Test/Idle. Table 39-15. BYPASS Details 39.5.3 Instructions Details IR input value 11111 (0x1F) IR output value p0001 DR Size 1 DR input value x DR output value x Private JTAG Instructions The 32-bit AVR defines a number of private JTAG instructions, not defined by the JTAG standard. Each instruction is briefly described in text, with details following in table form. 39.5.3.1 NEXUS_ACCESS This instruction allows Nexus-compliant access to the On-Chip Debug registers through the SAB. The 7-bit register index, a read/write control bit, and the 32-bit data is accessed through the JTAG port. The data register is alternately interpreted by the SAB as an address register and a data register. The SAB starts in address mode after the NEXUS_ACCESS instruction is selected, and toggles between address and data mode each time a data scan completes with the busy bit cleared. NOTE: The polarity of the direction bit is inverse of the Nexus standard. 1215 32117A-10/2010 AT32UC3C Starting in Run-Test/Idle, OCD registers are accessed in the following way: 1. Select the IR Scan path. 2. In Capture-IR: The IR output value is latched into the shift register. 3. In Shift-IR: The instruction register is shifted by the TCK input. 4. Return to Run-Test/Idle. 5. Select the DR Scan path. 6. In Shift-DR: Scan in the direction bit (1=read, 0=write) and the 7-bit address for the OCD register. 7. Go to Update-DR and re-enter Select-DR Scan. 8. In Shift-DR: For a read operation, scan out the contents of the addressed register. For a write operation, scan in the new contents of the register. 9. Return to Run-Test/Idle. For any operation, the full 7 bits of the address must be provided. For write operations, 32 data bits must be provided, or the result will be undefined. For read operations, shifting may be terminated once the required number of bits have been acquired. Table 39-16. NEXUS_ACCESS Details 39.5.3.2 Instructions Details IR input value 10000 (0x10) IR output value peb01 DR Size 34 bits DR input value (Address phase) aaaaaaar xxxxxxxx xxxxxxxx xxxxxxxx xx DR input value (Data read phase) xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xx DR input value (Data write phase) dddddddd dddddddd dddddddd dddddddd xx DR output value (Address phase) xx xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxeb DR output value (Data read phase) eb dddddddd dddddddd dddddddd dddddddd DR output value (Data write phase) xx xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxeb MEMORY_SERVICE This instruction allows access to registers in an optional Memory Service Unit. The 7-bit register index, a read/write control bit, and the 32-bit data is accessed through the JTAG port. The data register is alternately interpreted by the SAB as an address register and a data register. The SAB starts in address mode after the MEMORY_SERVICE instruction is selected, and toggles between address and data mode each time a data scan completes with the busy bit cleared. Starting in Run-Test/Idle, Memory Service registers are accessed in the following way: 1. Select the IR Scan path. 2. In Capture-IR: The IR output value is latched into the shift register. 3. In Shift-IR: The instruction register is shifted by the TCK input. 4. Return to Run-Test/Idle. 5. Select the DR Scan path. 6. In Shift-DR: Scan in the direction bit (1=read, 0=write) and the 7-bit address for the Memory Service register. 1216 32117A-10/2010 AT32UC3C 7. Go to Update-DR and re-enter Select-DR Scan. 8. In Shift-DR: For a read operation, scan out the contents of the addressed register. For a write operation, scan in the new contents of the register. 9. Return to Run-Test/Idle. For any operation, the full 7 bits of the address must be provided. For write operations, 32 data bits must be provided, or the result will be undefined. For read operations, shifting may be terminated once the required number of bits have been acquired. Table 39-17. MEMORY_SERVICE Details 39.5.3.3 Instructions Details IR input value 10100 (0x14) IR output value peb01 DR Size 34 bits DR input value (Address phase) aaaaaaar xxxxxxxx xxxxxxxx xxxxxxxx xx DR input value (Data read phase) xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xx DR input value (Data write phase) dddddddd dddddddd dddddddd dddddddd xx DR output value (Address phase) xx xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxeb DR output value (Data read phase) eb dddddddd dddddddd dddddddd dddddddd DR output value (Data write phase) xx xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxeb MEMORY_SIZED_ACCESS This instruction allows access to the entire Service Access Bus data area. Data is accessed through a 36-bit byte index, a 2-bit size, a direction bit, and 8, 16, or 32 bits of data. Not all units mapped on the SAB bus may support all sizes of accesses, e.g., some may only support word accesses. The data register is alternately interpreted by the SAB as an address register and a data register. The SAB starts in address mode after the MEMORY_SIZED_ACCESS instruction is selected, and toggles between address and data mode each time a data scan completes with the busy bit cleared. 1217 32117A-10/2010 AT32UC3C The size field is encoded as i Table 39-18. Table 39-18. Size Field Semantics Size field value Access size Data alignment Byte (8 bits) Address modulo 4 : data alignment 0: dddddddd xxxxxxxx xxxxxxxx xxxxxxxx 1: xxxxxxxx dddddddd xxxxxxxx xxxxxxxx 2: xxxxxxxx xxxxxxxx dddddddd xxxxxxxx 3: xxxxxxxx xxxxxxxx xxxxxxxx dddddddd Halfword (16 bits) Address modulo 4 : data alignment 0: dddddddd dddddddd xxxxxxxx xxxxxxxx 1: Not allowed 2: xxxxxxxx xxxxxxxx dddddddd dddddddd 3: Not allowed 10 Word (32 bits) Address modulo 4 : data alignment 0: dddddddd dddddddd dddddddd dddddddd 1: Not allowed 2: Not allowed 3: Not allowed 11 Reserved N/A 00 01 Starting in Run-Test/Idle, SAB data is accessed in the following way: 1. Select the IR Scan path. 2. In Capture-IR: The IR output value is latched into the shift register. 3. In Shift-IR: The instruction register is shifted by the TCK input. 4. Return to Run-Test/Idle. 5. Select the DR Scan path. 6. In Shift-DR: Scan in the direction bit (1=read, 0=write), 2-bit access size, and the 36-bit address of the data to access. 7. Go to Update-DR and re-enter Select-DR Scan. 8. In Shift-DR: For a read operation, scan out the contents of the addressed area. For a write operation, scan in the new contents of the area. 9. Return to Run-Test/Idle. For any operation, the full 36 bits of the address must be provided. For write operations, 32 data bits must be provided, or the result will be undefined. For read operations, shifting may be terminated once the required number of bits have been acquired. Table 39-19. MEMORY_SIZED_ACCESS Details Instructions Details IR input value 10101 (0x15) IR output value peb01 DR Size 39 bits DR input value (Address phase) aaaaaaaa aaaaaaaa aaaaaaaa aaaaaaaa aaaassr DR input value (Data read phase) xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxx DR input value (Data write phase) dddddddd dddddddd dddddddd dddddddd xxxxxxx 1218 32117A-10/2010 AT32UC3C Table 39-19. MEMORY_SIZED_ACCESS Details (Continued) 39.5.3.4 Instructions Details DR output value (Address phase) xxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxeb DR output value (Data read phase) xxxxxeb dddddddd dddddddd dddddddd dddddddd DR output value (Data write phase) xxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxeb MEMORY_WORD_ACCESS This instruction allows access to the entire Service Access Bus data area. Data is accessed through the 34 MSB of the SAB address, a direction bit, and 32 bits of data. This instruction is identical to MEMORY_SIZED_ACCESS except that it always does word sized accesses. The size field is implied, and the two lowest address bits are removed and not scanned in. Note: This instruction was previously known as MEMORY_ACCESS, and is provided for backwards compatibility. The data register is alternately interpreted by the SAB as an address register and a data register. The SAB starts in address mode after the MEMORY_WORD_ACCESS instruction is selected, and toggles between address and data mode each time a data scan completes with the busy bit cleared. Starting in Run-Test/Idle, SAB data is accessed in the following way: 1. Select the IR Scan path. 2. In Capture-IR: The IR output value is latched into the shift register. 3. In Shift-IR: The instruction register is shifted by the TCK input. 4. Return to Run-Test/Idle. 5. Select the DR Scan path. 6. In Shift-DR: Scan in the direction bit (1=read, 0=write) and the 34-bit address of the data to access. 7. Go to Update-DR and re-enter Select-DR Scan. 8. In Shift-DR: For a read operation, scan out the contents of the addressed area. For a write operation, scan in the new contents of the area. 9. Return to Run-Test/Idle. For any operation, the full 34 bits of the address must be provided. For write operations, 32 data bits must be provided, or the result will be undefined. For read operations, shifting may be terminated once the required number of bits have been acquired. Table 39-20. MEMORY_WORD_ACCESS Details Instructions Details IR input value 10001 (0x11) IR output value peb01 DR Size 35 bits DR input value (Address phase) aaaaaaaa aaaaaaaa aaaaaaaa aaaaaaaa aar DR input value (Data read phase) xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxx DR input value (Data write phase) dddddddd dddddddd dddddddd dddddddd xxx 1219 32117A-10/2010 AT32UC3C Table 39-20. MEMORY_WORD_ACCESS Details (Continued) 39.5.3.5 Instructions Details DR output value (Address phase) xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xeb DR output value (Data read phase) xeb dddddddd dddddddd dddddddd dddddddd DR output value (Data write phase) xxx xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxeb MEMORY_BLOCK_ACCESS This instruction allows access to the entire SAB data area. Up to 32 bits of data is accessed at a time, while the address is sequentially incremented from the previously used address. In this mode, the SAB address, size, and access direction is not provided with each access. Instead, the previous address is auto-incremented depending on the specified size and the previous operation repeated. The address must be set up in advance with MEMORY_SIZE_ACCESS or MEMORY_WORD_ACCESS. It is allowed, but not required, to shift data after shifting the address. This instruction is primarily intended to speed up large quantities of sequential word accesses. It is possible to use it also for byte and halfword accesses, but the overhead in this is case much larger as 32 bits must still be shifted for each access. The following sequence should be used: 1. Use the MEMORY_SIZE_ACCESS or MEMORY_WORD_ACCESS to read or write the first location. 2. Return to Run-Test/Idle. 3. Select the IR Scan path. 4. In Capture-IR: The IR output value is latched into the shift register. 5. In Shift-IR: The instruction register is shifted by the TCK input. 6. Return to Run-Test/Idle. 7. Select the DR Scan path. The address will now have incremented by 1, 2, or 4 (corresponding to the next byte, halfword, or word location). 8. In Shift-DR: For a read operation, scan out the contents of the next addressed location. For a write operation, scan in the new contents of the next addressed location. 9. Go to Update-DR. 10. If the block access is not complete, return to Select-DR Scan and repeat the access. 11. If the block access is complete, return to Run-Test/Idle. For write operations, 32 data bits must be provided, or the result will be undefined. For read operations, shifting may be terminated once the required number of bits have been acquired. Table 39-21. MEMORY_BLOCK_ACCESS Details Instructions Details IR input value 10010 (0x12) IR output value peb01 DR Size 34 bits DR input value (Data read phase) xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xx 1220 32117A-10/2010 AT32UC3C Table 39-21. MEMORY_BLOCK_ACCESS Details (Continued) Instructions Details DR input value (Data write phase) dddddddd dddddddd dddddddd dddddddd xx DR output value (Data read phase) eb dddddddd dddddddd dddddddd dddddddd DR output value (Data write phase) xx xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxeb The overhead using block word access is 4 cycles per 32 bits of data, resulting in an 88% transfer efficiency, or 2.1 MBytes per second with a 20 MHz TCK frequency. 39.5.3.6 CANCEL_ACCESS If a very slow memory location is accessed during a SAB memory access, it could take a very long time until the busy bit is cleared, and the SAB becomes ready for the next operation. The CANCEL_ACCESS instruction provides a possibility to abort an ongoing transfer and report a timeout to the JTAG master. When the CANCEL_ACCESS instruction is selected, the current access will be terminated as soon as possible. There are no guarantees about how long this will take, as the hardware may not always be able to cancel the access immediately. The SAB is ready to respond to a new command when the busy bit clears. Starting in Run-Test/Idle, CANCEL_ACCESS is accessed in the following way: 1. Select the IR Scan path. 2. In Capture-IR: The IR output value is latched into the shift register. 3. In Shift-IR: The instruction register is shifted by the TCK input. 4. Return to Run-Test/Idle. Table 39-22. CANCEL_ACCESS Details 39.5.3.7 Instructions Details IR input value 10011 (0x13) IR output value peb01 DR Size 1 DR input value x DR output value 0 SYNC This instruction allows external debuggers and testers to measure the ratio between the external JTAG clock and the internal system clock. The SYNC data register is a 16-bit counter that counts down to zero using the internal system clock. The busy bit stays high until the counter reaches zero. Starting in Run-Test/Idle, SYNC instruction is used in the following way: 1. Select the IR Scan path. 2. In Capture-IR: The IR output value is latched into the shift register. 3. In Shift-IR: The instruction register is shifted by the TCK input. 4. Return to Run-Test/Idle. 5. Select the DR Scan path. 1221 32117A-10/2010 AT32UC3C 6. Scan in an 16-bit counter value. 7. Go to Update-DR and re-enter Select-DR Scan. 8. In Shift-DR: Scan out the busy bit, and until the busy bit clears goto 7. 9. Calculate an approximation to the internal clock speed using the elapsed time and the counter value. 10. Return to Run-Test/Idle. The full 16-bit counter value must be provided when starting the synch operation, or the result will be undefined. When reading status, shifting may be terminated once the required number of bits have been acquired. Table 39-23. SYNC_ACCESS Details 39.5.3.8 Instructions Details IR input value 10111 (0x17) IR output value peb01 DR Size 16 bits DR input value dddddddd dddddddd DR output value xxxxxxxx xxxxxxeb AVR_RESET This instruction allows a debugger or tester to directly control separate reset domains inside the chip. The shift register contains one bit for each controllable reset domain. Setting a bit to one resets that domain and holds it in reset. Setting a bit to zero releases the reset for that domain. The AVR_RESET instruction can be used in the following way: 1. Select the IR Scan path. 2. In Capture-IR: The IR output value is latched into the shift register. 3. In Shift-IR: The instruction register is shifted by the TCK input. 4. Return to Run-Test/Idle. 5. Select the DR Scan path. 6. In Shift-DR: Scan in the value corresponding to the reset domains the JTAG master wants to reset into the data register. 7. Return to Run-Test/Idle. 8. Stay in run test idle for at least 10 TCK clock cycles to let the reset propagate to the system. See the device specific documentation for the number of reset domains, and what these domains are. For any operation, all bits must be provided or the result will be undefined. Table 39-24. AVR_RESET Details Instructions Details IR input value 01100 (0x0C) IR output value p0001 1222 32117A-10/2010 AT32UC3C Table 39-24. AVR_RESET Details (Continued) 39.5.3.9 Instructions Details DR Size Device specific. DR input value Device specific. DR output value Device specific. CHIP_ERASE This instruction allows a programmer to completely erase all nonvolatile memories in a chip. This will also clear any security bits that are set, so the device can be accessed normally. In devices without non-volatile memories this instruction does nothing, and appears to complete immediately. The erasing of non-volatile memories starts as soon as the CHIP_ERASE instruction is selected. The CHIP_ERASE instruction selects a 1 bit bypass data register. A chip erase operation should be performed as: 1. Reset the system and stop the CPU from executing. 2. Select the IR Scan path. 3. In Capture-IR: The IR output value is latched into the shift register. 4. In Shift-IR: The instruction register is shifted by the TCK input. 5. Check the busy bit that was scanned out during Shift-IR. If the busy bit was set goto 2. 6. Return to Run-Test/Idle. Table 39-25. CHIP_ERASE Details 39.5.3.10 Instructions Details IR input value 01111 (0x0F) IR output value p0b01 Where b is the busy bit. DR Size 1 bit DR input value x DR output value 0 HALT This instruction allows a programmer to easily stop the CPU to ensure that it does not execute invalid code during programming. This instruction selects a 1-bit halt register. Setting this bit to one resets the device and halts the CPU. Setting this bit to zero resets the device and releases the CPU to run normally. The value shifted out from the data register is one if the CPU is halted. The HALT instruction can be used in the following way: 1. Select the IR Scan path. 2. In Capture-IR: The IR output value is latched into the shift register. 3. In Shift-IR: The instruction register is shifted by the TCK input. 4. Return to Run-Test/Idle. 5. Select the DR Scan path. 1223 32117A-10/2010 AT32UC3C 6. In Shift-DR: Scan in the value 1 to halt the CPU, 0 to start CPU execution. 7. Return to Run-Test/Idle. Table 39-26. HALT Details Instructions Details IR input value 11100 (0x1C) IR output value p0001 DR Size 1 bit DR input value d DR output value d 1224 32117A-10/2010 AT32UC3C 39.6 aWire Debug Interface (AW) Rev.: 2.3.0.1 39.6.1 Features * * * * * * * * 39.6.2 Single pin debug system. Half Duplex asynchronous communication (UART compatible). Full duplex mode for direct UART connection. Compatible with JTAG functionality, except boundary scan. Failsafe packet-oriented protocol. Read and write on-chip memory and program on-chip flash and fuses through SAB interface. On-Chip Debug access through SAB interface. Asynchronous receiver or transmitter when the aWire system is not used for debugging. Overview The aWire Debug Interface (AW) offers a single pin debug solution that is fully compatible with the functionality offered by the JTAG interface, except boundary scan. This functionality includes memory access, programming capabilities, and On-Chip Debug access. Figure 39-8 on page 1226 shows how the AW is connected in a 32-bit AVR device. The RESET_N pin is used both as reset and debug pin. A special sequence on RESET_N is needed to block the normal reset functionality and enable the AW. The Service Access Bus (SAB) interface contains address and data registers for the Service Access Bus, which gives access to On-Chip Debug, programming, and other functions in the device. The SAB offers several modes of access to the address and data registers, as discussed in Section 39.6.6.8. Section 39.6.7 lists the supported aWire commands and responses, with references to the description in this document. If the AW is not used for debugging, the aWire UART can be used by the user to send or receive data with one stop bit, eight data bits, no parity bits, and one stop bit. This can be controlled through the aWire user interface. 1225 32117A-10/2010 AT32UC3C 39.6.3 Block Diagram Figure 39-8. aWire Debug Interface Block Diagram PB aWire Debug Interface Flash Controller CHIP_ERASE command AW User Interface CPU HALT command RESET command Power Manager External reset AW_ENABLE AW CONTROL Reset filter RESET_N Baudrate Detector SAB interface UART RW SZ ADDR DATA CRC SAB 39.6.4 I/O Lines Description Table 39-27. I/O Lines Description Name Description Type DATA aWire data multiplexed with the RESET_N pin. Input/Output DATAOUT aWire data output in 2-pin mode. Output 39.6.5 Product Dependencies In order to use this module, other parts of the system must be configured correctly, as described below. 1226 32117A-10/2010 AT32UC3C 39.6.5.1 I/O Lines The pin used by AW is multiplexed with the RESET_N pin. The reset functionality is the default function of this pin. To enable the aWire functionality on the RESET_N pin the user must enable the AW either by sending the enable sequence over the RESET_N pin from an external aWire master or by enabling the aWire user interface. In 2-pin mode data is received on the RESET_N line, but transmitted on the DATAOUT line. After sending the 2_PIN_MODE command the DATAOUT line is automatically enabled. All other peripheral functions on this pin is disabled. 39.6.5.2 Power Management When debugging through AW the system clocks are automatically turned on to allow debugging in sleep modes. 39.6.5.3 Clocks The aWire UART uses the internal 120 MHz RC oscillator (RC120M) as clock source for its operation. When enabling the AW the RC120M is automatically started. 39.6.6 Functional Description 39.6.6.1 aWire Communication Protocol The AW is accessed through the RESET_N pin shown in Table 39-27 on page 1226. The AW communicates through a UART operating at variable baud rate (depending on a sync pattern) with one start bit, 8 data bits (LSB first), one stop bit, and no parity bits. The aWire protocol is based upon command packets from an externalmaster and response packets from the slave (AW). The master always initiates communication and decides the baud rate. The packet contains a sync byte (0x55), a command/response byte, two length bytes (optional), a number of data bytes as defined in the length field (optional), and two CRC bytes. If the command/response has the most significant bit set, the command/response also carries the optional length and data fields. The CRC field is not checked if the CRC value transmitted is 0x0000. Table 39-28. aWire Packet Format Field Number of bytes Description Comment 1 Sync pattern (0x55). Used by the receiver to set the baud rate clock. No COMMAND/ RESPONSE 1 Command from the master or response from the slave. When the most significant bit is set the command/response has a length field. A response has the next most significant bit set. A command does not have this bit set. No LENGTH 2 The number of bytes in the DATA field. Yes DATA LENGTH Data according to command/ response. Yes CRC 2 CRC calculated with the FCS16 polynomial. SYNC CRC value of 0x0000 makes the aWire disregard the CRC if the master does not support it. Optional No CRC calculation 1227 32117A-10/2010 AT32UC3C The CRC is calculated from the command/response, length, and data fields. The polynomial used is the FCS16 (or CRC-16-CCIT) in reverse mode (0x8408) and the starting value is 0x0000. Example command Below is an example command from the master with additional data. Figure 39-9. Example Command baud_rate_clk data_pin field ... sync(0x55) command(0x81) length(MSB) length(lsb) data(MSB) data(LSB) CRC(MSB) CRC(lsb) ... Example response Below is an example response from the slave with additional data. Figure 39-10. Example Response baud_rate_clk data_pin field ... sync(0x55) response(0xC1) length(MSB) length(lsb) data(MSB) data(LSB) CRC(MSB) CRC(lsb) ... Avoiding drive contention when changing direction The aWire debug protocol uses one dataline in both directions. To avoid both the master and the slave to drive this line when changing direction the AW has a built in guard time before it starts to drive the line. At reset this guard time is set to maximum (128 bit cycles), but can be lowered by the master upon command. The AW will release the line immediately after the stop character has been transmitted. 1228 32117A-10/2010 AT32UC3C 39.6.6.2 During the direction change there can be a period when the line is not driven. The internal pullup of the RESET_N pin keeps the signal stable when neither master or slave is actively driving the line. The RESET_N pin Normal reset functionality on the RESET_N pin is disabled when using aWire. However, the user can reset the system through the RESET aWire command. During aWire operation the RESET_N pin should not be connected to an external reset circuitry, but disconnected via a switch or a jumper to avoid drive contention and speed problems. Figure 39-11. Reset Circuitry and aWire. MCU aWire master connector Board Reset Circuitry 39.6.6.3 Jumper AW Debug Interface RESET_N Power Manager Initializing the AW To enable AW, the user has to send a 0x55 pattern with a baudrate of 1 kHz on the RESET_N pin. The AW is enabled after transmitting this pattern and the user can start transmitting commands. This pattern is not the sync pattern for the first command. After enabling the awire debug interface the halt bit is set automatically to prevent the system from running code after the interface is enabled. To make the CPU run again set halt to zero using the HALT command. 39.6.6.4 Disabling the AW To disable AW, the user can keep the RESET_N pin low for 100 ms. This will disable the AW, return RESET_N to its normal function, and reset the device. An aWire master can also disable aWire by sending the DISABLE command. After acking the command the AW will be disabled and RESET_N returns to its normal function. 39.6.6.5 Resetting the AW The aWire master can reset the AW slave by pulling the RESET_N pin low for 20 ms. This is equivalent to disabling and then enabling AW. 39.6.6.6 2-pin Mode To avoid using special hardware when using a normal UART device as aWire master, the aWire slave has a 2-pin mode where one pin is used as input and on pin is used as output. To enable this mode the 2_PIN_MODE command must be sent. After sending the command, all responses will be sent on the DATAOUT pin instead of the RESET_N pin. Commands are still received on the RESET_N pin. 1229 32117A-10/2010 AT32UC3C 39.6.6.7 Baud Rate Clock The communication speed is set by the master in the sync field of the command. The AW will use this to resynchronize its baud rate clock and reply on this frequency. The minimum frequency of the communication is 1 kHz. The maximum frequency depends on the internal clock source for the AW (RC120M). The baud rate clock is generated by AW with the following formula: TUNE x f br f aw = ---------------------------8 Where f br is the baud rate frequency and f aw is the frequency of the internal RC120M. TUNE is the value returned by the BAUD_RATE response. To find the max frequency the user can issue the TUNE command to the AW to make it return the TUNE value. This value can be used to compute the f aw . The maximum operational frequency ( f brmax ) is then: f aw f brmax = ------4 39.6.6.8 Service Access Bus The AVR32 architecture offers a common interface for access to On-Chip Debug, programming, and test functions. These are mapped on a common bus called the Service Access Bus (SAB), which is linked to the aWire through a bus master module, which also handles synchronization between the aWire and SAB clocks. For more information about the SAB and a list of SAB slaves see the Service Access Bus chapter. SAB Clock When accessing the SAB through the aWire there are no limitations on baud rate frequency compared to chip frequency, although there must be an active system clock in order for the SAB accesses to complete. If the system clock (CLK_SYS) is switched off in sleep mode, activity on the aWire pin will restart the CLK_SYS automatically, without waking the device from sleep. aWire masters may optimize the transfer rate by adjusting the baud rate frequency in relation to the CLK_SYS. This ratio can be measured with the MEMORY_SPEED_REQUEST command. When issuing the MEMORY_SPEED_REQUEST command a counter value CV is returned. CV can be used to calculate the SAB speed ( f sab ) using this formula: 3f aw f sab = ---------------CV - 3 SAB Address Mode The Service Access Bus uses 36 address bits to address memory or registers in any of the slaves on the bus. The bus supports sized accesses of bytes (8 bits), halfwords (16 bits), or words (32 bits). All accesses must be aligned to the size of the access, i.e. halfword accesses must have the lowest address bit cleared, and word accesses must have the two lowest address bits cleared. 1230 32117A-10/2010 AT32UC3C Two instructions exist to access the SAB: MEMORY_WRITE and MEMORY_READ. These two instructions write and read words, halfwords, and bytes from the SAB. Busy Reporting If the aWire master, during a MEMORY_WRITE or a MEMORY_READ command, transmit another byte when the aWire is still busy sending the previous byte to the SAB, the AW will respond with a MEMORY_READ_WRITE_STATUS error. See chapter Section 39.6.8.5 for more details. The aWire master should adjust its baudrate or delay between bytes when doing SAB accesses to ensure that the SAB is not overwhelmed with data. Error Reporting If a write is performed on a non-existing memory location the SAB interface will respond with an error. If this happens, all further writes in this command will not be performed and the error and number of bytes written is reported in the MEMORY_READWRITE_STATUS message from the AW after the write. If a read is performed on a non-existing memory location, the SAB interface will respond with an error. If this happens, the data bytes read after this event are not valid. The AW will include three extra bytes at the end of the transfer to indicate if the transfer was successful, or in the case of an error, how many valid bytes were received. 39.6.6.9 CRC Errors/NACK Response The AW will calculate a CRC value when receiving the command, length, and data fields of the command packets. If this value differs from the value from the CRC field of the packet, the AW will reply with a NACK response. Otherwise the command is carried out normally. An unknown command will be replied with a NACK response. In worst case a transmission error can happen in the length or command field of the packet. This can lead to the aWire slave trying to receive a command with or without length (opposite of what the master intended) or receive an incorrect number of bytes. The aWire slave will then either wait for more data when the master has finished or already have transmitted the NACK response in congestion with the master. The master can implement a timeout on every command and reset the slave if no response is returned after the timeout period has ended. 39.6.7 aWire Command Summary The implemented aWire commands are shown in the table below. The responses from the AW are listed in Section 39.6.8. Table 39-29. aWire Command Summary COMMAND Instruction Description 0x01 AYA "Are you alive". 0x02 JTAG_ID Asks AW to return the JTAG IDCODE. 0x03 STATUS_REQUEST Request a status message from the AW. 0x04 TUNE Tell the AW to report the current baud rate. 0x05 MEMORY_SPEED_REQUEST Reports the speed difference between the aWire control and the SAB clock domains. 0x06 CHIP_ERASE Erases the flash and all volatile memories. 1231 32117A-10/2010 AT32UC3C Table 39-29. aWire Command Summary COMMAND Instruction Description 0x07 DISABLE Disables the AW. 0x08 2_PIN_MODE Enables the DATAOUT pin and puts the aWire in 2-pin mode, where all responses are sent on the DATAOUT pin. 0x80 MEMORY_WRITE Writes words, halfwords, or bytes to the SAB. 0x81 MEMORY_READ Reads words, halfwords, or bytes from the SAB. 0x82 HALT Issues a halt command to the device. 0x83 RESET Issues a reset to the Reset Controller. 0x84 SET_GUARD_TIME Sets the guard time for the AW. All aWire commands are described below, with a summary in table form. Table 39-30. Command/Response Description Notation Command/Response Description Command/Response value Shows the command/response value to put into the command/response field of the packet. Additional data Shows the format of the optional data field if applicable. Possible responses Shows the possible responses for this command. 39.6.7.1 AYA This command asks the AW: "Are you alive", where the AW should respond with an acknowledge. Table 39-31. AYA Details 39.6.7.2 Command Details Command value 0x01 Additional data N/A Possible responses 0x40: ACK (Section 39.6.8.1) 0x41: NACK (Section 39.6.8.2) JTAG_ID This command instructs the AW to output the JTAG idcode in the following response. Table 39-32. JTAG_ID Details Command Details Command value 0x02 Additional data N/A Possible responses 0xC0: IDCODE (Section 39.6.8.3) 0x41: NACK (Section 39.6.8.2) 1232 32117A-10/2010 AT32UC3C 39.6.7.3 STATUS_REQUEST Asks the AW for a status message. Table 39-33. STATUS_REQUEST Details 39.6.7.4 Command Details Command value 0x03 Additional data N/A Possible responses 0xC4: STATUS_INFO (Section 39.6.8.7) 0x41: NACK (Section 39.6.8.2) TUNE Asks the AW for the current baud rate counter value. Table 39-34. TUNE Details 39.6.7.5 Command Details Command value 0x04 Additional data N/A Possible responses 0xC3: BAUD_RATE (Section 39.6.8.6) 0x41: NACK (Section 39.6.8.2) MEMORY_SPEED_REQUEST Asks the AW for the relative speed between the aWire clock (RC120M) and the SAB interface. Table 39-35. MEMORY_SPEED_REQUEST Details 39.6.7.6 Command Details Command value 0x05 Additional data N/A Possible responses 0xC5: MEMORY_SPEED (Section 39.6.8.8) 0x41: NACK (Section 39.6.8.2) CHIP_ERASE This instruction allows a programmer to completely erase all nonvolatile memories in the chip. This will also clear any security bits that are set, so the device can be accessed normally. The command is acked immediately, but the status of the command can be monitored by checking the Chip Erase ongoing bit in the status bytes received after the STATUS_REQUEST command. Table 39-36. CHIP_ERASE Details Command Details Command value 0x06 Additional data N/A Possible responses 0x40: ACK (Section 39.6.8.1) 0x41: NACK (Section 39.6.8.2) 1233 32117A-10/2010 AT32UC3C 39.6.7.7 DISABLE Disables the AW. The AW will respond with an ACK response and then disable itself. Table 39-37. DISABLE Details 39.6.7.8 Command Details Command value 0x07 Additional data N/A Possible responses 0x40: ACK (Section 39.6.8.1) 0x41: NACK (Section 39.6.8.2) 2_PIN_MODE Enables the DATAOUT pin as an output pin. All responses sent from the aWire slave will be sent on this pin, instead of the RESET_N pin, starting with the ACK for the 2_PIN_MODE command. Table 39-38. DISABLE Details 39.6.7.9 Command Details Command value 0x07 Additional data N/A Possible responses 0x40: ACK (Section 39.6.8.1) 0x41: NACK (Section 39.6.8.2) MEMORY_WRITE This command enables programming of memory/writing to registers on the SAB. The MEMORY_WRITE command allows words, halfwords, and bytes to be programmed to a continuous sequence of addresses in one operation. Before transferring the data, the user must supply: 1. The number of data bytes to write + 5 (size and starting address) in the length field. 2. The size of the transfer: words, halfwords, or bytes. 3. The starting address of the transfer. The 4 MSB of the 36 bit SAB address are submitted together with the size field (2 bits). Then follows the 4 remaining address bytes and finally the data bytes. The size of the transfer is specified using the values from the following table: Table 39-39. Size Field Decoding Size field Description 00 Byte transfer 01 Halfword transfer 10 Word transfer 11 Reserved Below is an example write command: 1. 0x55 (sync) 2. 0x80 (command) 3. 0x00 (length MSB) 1234 32117A-10/2010 AT32UC3C 4. 0x09 (length LSB) 5. 0x25 (size and address MSB, the two MSB of this byte are unused and set to zero) 6. 0x00 7. 0x00 8. 0x00 9. 0x04 (address LSB) 10. 0xCA 11. 0xFE 12. 0xBA 13. 0xBE 14. 0xXX (CRC MSB) 15. 0xXX (CRC LSB) The length field is set to 0x0009 because there are 9 bytes of additional data: 5 address and size bytes and 4 bytes of data. The address and size field indicates that words should be written to address 0x500000004. The data written to 0x500000004 is 0xCAFEBABE. Table 39-40. MEMORY_WRITE Details 39.6.7.10 Command Details Command value 0x80 Additional data Size, Address and Data Possible responses 0xC2: MEMORY_READWRITE_STATUS (Section 39.6.8.5) 0x41: NACK (Section 39.6.8.2) MEMORY_READ This command enables reading of memory/registers on the Service Access Bus (SAB). The MEMORY_READ command allows words, halfwords, and bytes to be read from a continuous sequence of addresses in one operation. The user must supply: 1. The size of the data field: 7 (size and starting address + read length indicator) in the length field. 2. The size of the transfer: Words, halfwords, or bytes. 3. The starting address of the transfer. 4. The number of bytes to read (max 65532). The 4 MSB of the 36 bit SAB address are submitted together with the size field (2 bits). The 4 remaining address bytes are submitted before the number of bytes to read. The size of the transfer is specified using the values from the following table: Table 39-41. Size Field Decoding Size field Description 00 Byte transfer 01 Halfword transfer 10 Word transfer 11 Reserved Below is an example read command: 1235 32117A-10/2010 AT32UC3C 1. 0x55 (sync) 2. 0x81 (command) 3. 0x00 (length MSB) 4. 0x07 (length LSB) 5. 0x25 (size and address MSB, the two MSB of this byte are unused and set to zero) 6. 0x00 7. 0x00 8. 0x00 9. 0x04 (address LSB) 10. 0x00 11. 0x04 12. 0xXX (CRC MSB) 13. 0xXX (CRC LSB) The length field is set to 0x0007 because there are 7 bytes of additional data: 5 bytes of address and size and 2 bytes with the number of bytes to read. The address and size field indicates one word (four bytes) should be read from address 0x500000004. Table 39-42. MEMORY_READ Details 39.6.7.11 Command Details Command value 0x81 Additional data Size, Address and Length Possible responses 0xC1: MEMDATA (Section 39.6.8.4) 0xC2: MEMORY_READWRITE_STATUS (Section 39.6.8.5) 0x41: NACK (Section 39.6.8.2) HALT This command tells the CPU to halt code execution for safe programming. If the CPU is not halted during programming it can start executing partially loaded programs. To halt the processor, the aWire master should send 0x01 in the data field of the command. After programming the halting can be released by sending 0x00 in the data field of the command. Table 39-43. HALT Details 39.6.7.12 Command Details Command value 0x82 Additional data 0x01 to halt the CPU 0x00 to release the halt and reset the device. Possible responses 0x40: ACK (Section 39.6.8.1) 0x41: NACK (Section 39.6.8.2) RESET This command resets different domains in the part. The aWire master sends a byte with the reset value. Each bit in the reset value byte corresponds to a reset domain in the chip. If a bit is set the reset is activated and if a bit is not set the reset is released. The number of reset domains 1236 32117A-10/2010 AT32UC3C and their destinations are identical to the resets described in the JTAG data registers chapter under reset register. Table 39-44. RESET Details 39.6.7.13 Command Details Command value 0x83 Additional data Reset value for each reset domain. The number of reset domains is part specific. Possible responses 0x40: ACK (Section 39.6.8.1) 0x41: NACK (Section 39.6.8.2) SET_GUARD_TIME Sets the guard time value in the AW, i.e. how long the AW will wait before starting its transfer after the master has finished. The guard time can be either 0x00 (128 bit lengths), 0x01 (16 bit lengths), 0x2 (4 bit lengths) or 0x3 (1 bit length). Table 39-45. SET_GUARD_TIME Details 39.6.8 Command Details Command value 0x84 Additional data Guard time Possible responses 0x40: ACK (Section 39.6.8.1) 0x41: NACK (Section 39.6.8.2) aWire Response Summary The implemented aWire responses are shown in the table below. Table 39-46. aWire Response Summary RESPONSE Instruction Description 0x40 ACK Acknowledge. 0x41 NACK Not acknowledge. Sent after CRC errors and after unknown commands. 0xC0 IDCODE The JTAG idcode. 0xC1 MEMDATA Values read from memory. 0xC2 MEMORY_READWRITE_STATUS Status after a MEMORY_WRITE or a MEMORY_READ command. OK, busy, error. 0xC3 BAUD_RATE The current baudrate. 0xC4 STATUS_INFO Status information. 0xC5 MEMORY_SPEED SAB to aWire speed information. 1237 32117A-10/2010 AT32UC3C 39.6.8.1 ACK The AW has received the command successfully and performed the operation. Table 39-47. ACK Details 39.6.8.2 Response Details Response value 0x40 Additional data N/A NACK The AW has received the command, but got a CRC mismatch. Table 39-48. NACK Details 39.6.8.3 Response Details Response value 0x41 Additional data N/A IDCODE The JTAG idcode for this device. Table 39-49. IDCODE Details 39.6.8.4 Response Details Response value 0xC0 Additional data JTAG idcode MEMDATA The data read from the address specified by the MEMORY_READ command. The last 3 bytes are status bytes from the read. The first status byte is the status of the command described in the table below. The last 2 bytes are the number of remaining data bytes to be sent in the data field of the packet when the error occurred. If the read was not successful all data bytes after the failure are undefined. A successful word read (4 bytes) will look like this: 1. 0x55 (sync) 2. 0xC1 (command) 3. 0x00 (length MSB) 4. 0x07 (length LSB) 5. 0xCA (Data MSB) 6. 0xFE 7. 0xBA 8. 0xBE (Data LSB) 9. 0x00 (Status byte) 10. 0x00 (Bytes remaining MSB) 11. 0x00 (Bytes remaining LSB) 12. 0xXX (CRC MSB) 13. 0xXX (CRC LSB) The status is 0x00 and all data read are valid. An unsuccessful four byte read can look like this: 1238 32117A-10/2010 AT32UC3C 1. 0x55 (sync) 2. 0xC1 (command) 3. 0x00 (length MSB) 4. 0x07 (length LSB) 5. 0xCA (Data MSB) 6. 0xFE 7. 0xXX (An error has occurred. Data read is undefined. 5 bytes remaining of the Data field) 8. 0xXX (More undefined data) 9. 0x02 (Status byte) 10. 0x00 (Bytes remaining MSB) 11. 0x05 (Bytes remaining LSB) 12. 0xXX (CRC MSB) 13. 0xXX (CRC LSB) The error occurred after reading 2 bytes on the SAB. The rest of the bytes read are undefined. The status byte indicates the error and the bytes remaining indicates how many bytes were remaining to be sent of the data field of the packet when the error occurred. Table 39-50. MEMDATA Status Byte status byte Description 0x00 Read successful 0x01 SAB busy 0x02 Bus error (wrong address) Other Reserved Table 39-51. MEMDATA Details 39.6.8.5 Response Details Response value 0xC1 Additional data Data read, status byte, and byte count (2 bytes) MEMORY_READWRITE_STATUS After a MEMORY_WRITE command this response is sent by AW. The response can also be sent after a MEMORY_READ command if AW encountered an error when receiving the address. The response contains 3 bytes, where the first is the status of the command and the 2 next contains the byte count when the first error occurred. The first byte is encoded this way: Table 39-52. MEMORY_READWRITE_STATUS Status Byte status byte Description 0x00 Write successful 0x01 SAB busy 0x02 Bus error (wrong address) Other Reserved 1239 32117A-10/2010 AT32UC3C Table 39-53. MEMORY_READWRITE_STATUS Details 39.6.8.6 Response Details Response value 0xC2 Additional data Status byte and byte count (2 bytes) BAUD_RATE The current baud rate in the AW. See Section 39.6.6.7 for more details. Table 39-54. BAUD_RATE Details 39.6.8.7 Response Details Response value 0xC3 Additional data Baud rate STATUS_INFO A status message from AW. Table 39-55. STATUS_INFO Contents Bit number Name Description 15-9 Reserved 8 Protected The protection bit in the internal flash is set. SAB access is restricted. This bit will read as one during reset. 7 SAB busy The SAB bus is busy with a previous transfer. This could indicate that the CPU is running on a very slow clock, the CPU clock has stopped for some reason or that the part is in constant reset. 6 Chip erase ongoing The Chip erase operation has not finished. 5 CPU halted This bit will be set if the CPU is halted. This bit will read as zero during reset. 4-1 0 Reserved Reset status This bit will be set if AW has reset the CPU using the RESET command. Table 39-56. STATUS_INFO Details 39.6.8.8 Response Details Response value 0xC4 Additional data 2 status bytes MEMORY_SPEED Counts the number of RC120M clock cycles it takes to sync one message to the SAB interface and back again. The SAB clock speed ( f sab ) can be calculated using the following formula: 3f aw f sab = ---------------CV - 3 1240 32117A-10/2010 AT32UC3C Table 39-57. MEMORY_SPEED Details 39.6.9 Response Details Response value 0xC5 Additional data Clock cycle count (MS) Security Restrictions When the security fuse in the Flash is programmed, the following aWire commands are limited: * MEMORY_WRITE * MEMORY_READ Unlimited access to these instructions is restored when the security fuse is erased by the CHIP_ERASE aWire command. Note that the security bit will read as programmed and block these instructions also if the Flash Controller is statically reset. 1241 32117A-10/2010 AT32UC3C 39.7 Module Configuration The bit mapping of the Peripheral Debug Register (PDBG) is described in the following table. Please refer to the On-Chip Debug chapter in the AVR32UC Technical Reference Manual for details. Table 39-58. Bit mapping of the Peripheral Debug Register (PDBG) bit Peripheral 0 AST 1 WDT 2 CANIF 3 QDEC0 4 QDEC1 5 ADCIFA 6 ACIFA0 7 ACIFA1 8 DACIFB0 9 DACIFB1 10 PEVC 11-31 Reserved 1242 32117A-10/2010 AT32UC3C 40. Electrical Characteristics 40.1 Absolute Maximum Ratings* Operating temperature..................................... -40C to +85C *NOTICE: Stresses beyond those listed under "Absolute Maximum Ratings" may cause permanent damage to the device. This is a stress rating only and functional operation of the device at these or other conditions beyond those indicated in the operational sections of this specification is not implied. Exposure to absolute maximum rating conditions for extended periods may affect device reliability. Storage temperature...................................... -60C to +150C Voltage on any pin except DM/DP/VBUS with respect to ground ................... -0.3V to VCC+VDDIO+0.3V Voltage on DM/DP with respect to ground.........-0.3V to +3.6V Voltage on VBUS with respect to ground...........-0.3V to +5.5V Maximum operating voltage (VDDIN_5) ........................... 5.5V Maximum operating voltage (VDDIO, VDDANA) .............. 5.5V Maximum operating voltage (VDDIN_33) ......................... 3.6V DC current per I/O pin................................................. TBD mA DC current VCC and GND pins ................................... TBD mA 40.2 Supply Characteristics The following characteristics are applicable to the operating temperature range: TA = -40C to 85C, unless otherwise specified and are valid for a junction temperature up to T J = 100C. Please refer to Section 6. "Supply and Startup Considerations" on page 48. Table 40-1. Supply Characteristics Voltage Symbol Parameter VVDDIN_5 DC supply internal regulators VVDDIN_33 DC supply USB I/O VVDDANA DC supply analog part VVDDIO DC supply peripheral I/O Condition Min Max Unit 5V range 4.5 5.5 V 3V range 3.0 3.6 V only in 3V range 3.0 3.6 V 5V range 4.5 5.5 V 3V range 3.0 3.6 V 5V range 4.5 5.5 V 3V range 3.0 3.6 V 1243 32117A-10/2010 AT32UC3C Table 40-2. Supply Rise Rates and Order Rise Rate Symbol Parameter Min Max VVDDIN_5 DC supply internal 3.3V regulator 0.01 V/ms 1.25 V/us VVDDIN_33 DC supply internal 1.8V regulator 0.01 V/ms 1.25 V/us VVDDIO DC supply peripheral I/O 0.01 V/ms 1.25 V/us Rise after or at the same time as VDDIN_5, VDDIN_33 VVDDANA DC supply analog part 0.01 V/ms 1.25 V/us Rise after or at the same time as VDDIN_5, VDDIN_33 40.3 Comment Maximum Clock Frequencies These parameters are given in the following conditions: * VVDDCORE = 1.85V * Temperature = -40C to 85C Table 40-3. Clock Frequencies Max(1) Units CPU clock frequency 66 MHz fPBA PBA clock frequency 66 MHz fPBB PBB clock frequency 66 MHz fPBC PBC clock frequency 66 MHz fGCLK0 GCLK0 clock frequency Generic clock for USBC 50 MHz fGCLK1 GCLK1 clock frequency Generic clock for CANIF 66 MHz fGCLK2 GCLK2 clock frequency Generic clock for AST 80 MHz fGCLK4 GCLK4 clock frequency Generic clock for PWM 133 MHz fGCLK11 GCLK11 clock frequency Generic clock for IISC 50 MHz Symbol Parameter fCPU Conditions Min Note: 1. These values are guaranteed by design and will be updated after characterization of current silicon. 40.4 Power Consumption The values in Table 40-4 are measured values of power consumption under the following conditions, except where noted: * Operating conditions core supply (Figure 40-1) - VDDIN_5 = VDDIN_33 = 3.3V - VVDDCORE = 1.85V, supplied by the internal regulator - VDDIO = 3.3V - VDDANA: 3.3V - Internal 3.3V regulator is off. * TA = 25C 1244 32117A-10/2010 AT32UC3C * I/Os are configured as inputs, with internal pull-up enabled. * Oscillators - OSC0/1 (crystal oscillator) stopped - OSC32K (32KHz crystal oscillator) stopped - PLL0 running - PLL1 stopped * Clocks - External clock on XIN0 as main clock source (10MHz) - CPU, HSB, and PBB clocks undivided - PBA, PBC clock divided by 4 - The following peripheral clocks running * PM, SCIF, AST, FLASHC, PBA bridge - All other peripheral clocks stopped Table 40-4. Mode Power Consumption for Different Operating Modes Conditions Measured on Consumption Typ -CPU running a recursive Fibonacci algorithm TBD -CPU running a division algorithm TBD Unit Active Idle TBD Frozen TBD Standby Amp A/MHz TBD Stop 73 DeepStop 43 A -OSC32K and AST running 31 -AST and OSC32K stopped 31 Static 1245 32117A-10/2010 AT32UC3C Figure 40-1. Measurement Schematic VDDANA VDDIO Amp VDDIN_5 VDDIN_33 VDDCORE GNDCORE GNDPLL 40.4.1 Peripheral Power Consumption The values in Table 40-5 are measured values of power consumption under the following conditions. * Operating conditions core supply (Figure 40-1) - VDDIN_5 = VDDIN_33 = 3.3V - VVDDCORE = 1.85V , supplied by the internal regulator - VDDIO = 3.3V - VDDANA: 3.3V - Internal 3.3V regulator is off. * TA = 25C * I/Os are configured as inputs, with internal pull-up enabled. * Oscillators - OSC0/1 (crystal oscillator) stopped - OSC32K (32KHz crystal oscillator) stopped - PLL0 running 1246 32117A-10/2010 AT32UC3C - PLL1 stopped * Clocks - External clock on XIN0 as main clock source. - CPU, HSB, and PB clocks undivided Consumption active is the added current consumption when the module clock is turned on and when the module is doing a typical set of operations. Table 40-5. Peripheral (1) ACIFA (1) Typical Current Consumption by Peripheral Typ Consumption Active Unit TBD ADCIFA TBD AST TBD CANIF TBD DACIFB(1) TBD EBI TBD EIC TBD FLASHC TBD FREQM TBD GPIO TBD HMATRIX TBD IISC TBD INTC TBD MACB TBD MDMA TBD PDCA TBD PEVC TBD PWM TBD QDEC TBD SAU TBD SDRAMC TBD SMC TBD SPI TBD TC TBD TWIM TBD TWIS TBD USART TBD USBC TBD WDT TBD A/MHz 1247 32117A-10/2010 AT32UC3C Notes: 40.5 1. Includes the current consumption on VDDANA. I/O Pin Characteristics Table 40-6. Normal I/O Pin Characteristics Symbol Parameter Condition Min Typ Max RPULLUP Pull-up resistance 15 kOhm RPULLDOWN Pull-down resistance 10 kOhm VIL Input low-level voltage VIH Input high-level voltage 0.8 2.0 Output low-level voltage IOL = -7mA for pad drive x2 V V IOL = -3.5mA for pad drive x1(1) VOL Units V (1) 0.4 (1) IOL = -14mA for pad drive x4 IOL = 3.5mA for pad drive x1(1) VOH Output high-level voltage (1) IOL = 7mA for pad drive x2 V VDDIO - 0.7 IOL = 14mA for pad drive x4(1) fMAX Output frequency Rise time tRISE tFALL Fall time ILEAK Input leakage current CIN Input capacitance Note: VVDDIO = 3.0V, load = 10pF TBD MHz VVDD = 3.0V, load = 30pF TBD MHz VVDDIO =4.5V, load = 10pF TBD MHz VVDD = 4.5V, load = 30pF TBD MHz VVDD = 3.0V, load = 10pF TBD ns VVDD = 3.0V, load = 30pF TBD ns VVDDIO =4.5V, load = 10pF TBD ns VVDD = 4.5V, load = 30pF TBD ns VVDD = 3.0V, load = 10pF TBD ns VVDD = 3.0V, load = 30pF TBD ns VVDDIO =4.5V, load = 10pF TBD ns VVDD = 4.5V, load = 30pF TBD ns Pull-up resistors disabled TBD A TBD pF 1. All PA, PB, PC, PD pins have drive x1/x2 capabilities except PB00, PB01, PB02, PB03, PB30, PB31, PC02, PC03, PC04, PC05, PC06, PC07 which have drive x1 capability and PB06, PB21, PB26, PD02, PD06, PD13 which have drive x2/x4 capabilities. The drive strength is programmable through ODCR0, ODCR0S, ODCR0C, ODCR0T registers of GPIO. 1248 32117A-10/2010 AT32UC3C 40.6 Oscillator Characteristics 40.6.1 Oscillator (OSC0 and OSC1) Characteristics 40.6.1.1 Digital Clock Characteristics The following table describes the characteristics for the oscillator when a digital clock is applied on XIN0 or XIN1. Table 40-7. Digital Clock Characteristics Symbol Parameter fCPXIN XIN clock frequency tCPXIN XIN clock duty cycle tSTARTUP Startup time CIN XIN input capacitance 40.6.1.2 Conditions Min Typ 40 Max Units 50 MHz 60 % 0 cycles TBD pF Crystal Oscillator Characteristics The following table describes the characteristics for the oscillator when a crystal is connected between XIN and XOUT as shown in Figure 40-2. The user must choose a crystal oscillator where the crystal load capacitance CL is within the range given in the table. The exact value of CL can be found in the crystal datasheet. The capacitance of the external capacitors (CLEXT) can then be computed as follows: C LEXT = 2 ( C L - C i ) - C PCB where CPCB is the capacitance of the PCB and Ci is the internal equivalent load capacitance. Figure 40-2. Oscillator Connection CLEXT XOUT Ci CL XIN CLEXT 1249 32117A-10/2010 AT32UC3C Table 40-8. Symbol Crystal Oscillator Characteristics Parameter Conditions Min Typ (1) Max Unit (1) MHz fOUT Crystal oscillator frequency CL Crystal load capacitance 12 pF Ci Internal equivalent load capacitance 2 pF tSTARTUP Startup time TBD cycles IOSC Current consumption TBD A Notes: 0.4 20 1. These values are guaranteed by design and will be updated after characterization of current silicon. 40.6.2 32KHz Crystal Oscillator (OSC32K) Characteristics 40.6.2.1 Digital Clock Characteristics The following table describes the characteristics for the oscillator when a digital clock is applied on XIN32. Table 40-9. Digital 32KHz Clock Characteristics Symbol Parameter fCPXIN XIN32 clock frequency tCPXIN XIN32 clock duty cycle tSTARTUP Startup time TBD cycles CIN XIN32 input capacitance TBD pF 40.6.2.2 Conditions Min Typ Max Units 32 768 TBD Hz TBD % Crystal Oscillator Characteristics Figure 40-2 and the equation above also applies to the 32KHz oscillator connection. The user must choose a crystal oscillator where the crystal load capacitance CL is within the range given in the table. The exact value of CL can then be found in the crystal datasheet.. Table 40-10. 32 KHz Crystal Oscillator Characteristics Symbol Parameter Conditions Min fOUT Crystal oscillator frequency tSTARTUP Startup time CL Crystal load capacitance Ci Internal equivalent load capacitance TBD pF IOSC32 Current consumption TBD A RS Equivalent series resistance RS = TBDkOhm, CL = TBDpF Typ TBD Unit 32 768 Hz TBD cycles TBD 32 768Hz Max TBD TBD pF kOhm 1250 32117A-10/2010 AT32UC3C 40.6.3 120MHz RC Oscillator (RC120M) Characteristics Table 40-11. Internal 120MHz RC Oscillator Characteristics Symbol Parameter fOUT Output frequency IRC120M Current consumption tSTARTUP Startup time Note: Conditions Min TBD VVDDCORE = 1.8V Typ (1) 120 Max Unit TBD MHz 1.85(1) mA 3(1) s 1. These values are guaranteed by design and will be updated after characterization of current silicon. 40.6.4 System RC Oscillator (RCSYS) Characteristics Table 40-12. System RC Oscillator Characteristics Symbol Parameter fOUT Output frequency Note: Conditions Min Typ Max Unit TBD 115(1) TBD kHz 1. These values are guaranteed by design and will be updated after characterization of current silicon. 40.6.5 8MHz/1MHz RC Oscillator (RC8M) Characteristics Table 40-13. 8MHz/1MHz RC Oscillator Characteristics Symbol Parameter Conditions Min Typ Max Unit (2) TBD (1) 8 TBD MHz SCIF.RCCR8.FREQMODE = 1(2) TBD 1(1) TBD MHz Max Unit SCIF.RCCR8.FREQMODE = 0 fOUT Note: Output frequency 1. These values are guaranteed by design and will be updated after characterization of current silicon. 2. Please refer to the SCIF chapter for details. 40.6.6 Phase Lock Loop (PLL0 and PLL1) Characteristics Table 40-14. PLL Characteristics Symbol Parameter Conditions Min Typ fVCO Output frequency 80 240 MHz fIN Input frequency 4 16 MHz IPLL Current consumption 500 A 1251 32117A-10/2010 AT32UC3C 40.7 Flash Characteristics Table 40-15 gives the device maximum operating frequency depending on the number of flash wait states. The FSW bit in the FLASHC FSR register controls the number of wait states used when accessing the flash memory. Table 40-15. Maximum Operating Frequency Flash Wait States Read Mode Maximum Operating Frequency 0 1 cycle 33MHz 1 2 cycles 66MHz Table 40-16. Flash Characteristics Symbol Parameter tFPP Page programming time tFPE Page erase time tFFP Fuse programming time tFEA Full chip erase time (EA) tFCE JTAG chip erase time (CHIP_ERASE) Conditions Min Typ Max Unit 4 4 fCLK_HSB = 66MHz TBD ms 8 fCLK_HSB = 115kHz TBD Table 40-17. Flash Endurance and Data Retention Symbol Parameter NFARRAY Array endurance (write/page) NFFUSE tRET Conditions Min Typ Max Unit 100k cycles General Purpose fuses endurance (write/bit) 10k cycles Data retention 15 years 1252 32117A-10/2010 AT32UC3C 40.8 Analog Characteristics 40.8.1 1.8V Voltage Regulator Characteristics Table 40-18. 1.8V Voltage Regulator Electrical Characteristics Symbol Parameter VVDDIN_5 Input voltage range VVDDCORE Output voltage, calibrated value IOUT DC output current IVREG Static current of regulator Condition Min Typ Max Units 5V range 5 V 3V range 3.3 V 1.85 V Normal mode TBD mA Low power mode TBD mA Normal mode TBD A Low power mode TBD A Table 40-19. Decoupling Requirements Symbol Parameter CIN1 Typ Techno. Units Input regulator capacitor 1 470 NPO nF CIN2 Input regulator capacitor 2 2.2 X7R nF COUT1 Output regulator capacitor 1 470 NPO F COUT2 Output regulator capacitor 2 2.2 X7R nF 40.8.2 Condition 3.3V Voltage Regulator Characteristics Table 40-20. 3.3V Voltage Regulator Electrical Characteristics Symbol Parameter VVDDIN_5 Input voltage range VVDDIN_33 Output voltage, calibrated value IOUT DC output current IVREG Static current of regulator Condition Min Typ Max Units 5 V 3.3 V Normal mode TBD mA Low power mode TBD mA Normal mode TBD A Low power mode TBD A 1253 32117A-10/2010 AT32UC3C 40.8.3 1.8V Brown Out Detector (BOD18) Characteristics The values in Table 40-21 describe the values of the BODLEVEL in the flash General Purpose Fuse register. Table 40-21. BODLEVEL Values BODLEVEL Value Min Typ(1) Max Units 0 1.40 V 20 1.50 V 1.57 V 28 1.60 V 32 1.65 V 36 1.70 V 40 1.75 V 44 1.80 V 52 1.90 V 58 1.95 V 64 2.00 V 26 Notes: 40.8.4 Parameter threshold at power-up sequence 1. These values are guaranteed by design and will be updated after characterization of current silicon. 3.3V Brown Out Detector (BOD33) Characteristics The values in Table 40-23 describe the values of the BOD33.LEVEL field in the SCIF module. Table 40-23. BOD33.LEVEL Values BOD33.LEVEL Value Parameter Min Typ(1) Max Units 3 2.10 V 6 2.20 V 11 2.30 V 17 2.40 V 22 2.50 V 27 2.60 V 2.63 V 33 2.70 V 39 2.80 V 44 2.90 V 49 3.00 V 53 3.10 V 60 3.20 V 31 threshold at power-up sequence 1254 32117A-10/2010 AT32UC3C Notes: 40.8.5 1. These values are guaranteed by design and will be updated after characterization of current silicon. 5V Brown Out Detector (BOD50) Characteristics The values in Table 40-25 describe the values of the BOD50.LEVEL field in the SCIF module. Table 40-25. BOD50.LEVEL Values BOD50.LEVEL Value Parameter Min Typ(1) Max Units 7 3.25 V 16 3.50 V 25 3.75 V 35 4.00 V 44 4.25 V 53 4.50 V 61 4.75 V Notes: 1. These values are guaranteed by design and will be updated after characterization of current silicon. 1255 32117A-10/2010 AT32UC3C 40.8.6 Analog to Digital Converter (ADC) Characteristics Table 40-27. Channel Conversion Time and ADC Clock Parameter Conditions Min Typ 12-bit resolution mode - VDDANA = 5V 1.5 Startup time Conversion time Throughput rate MHz 2 MHz 8-bit resolution mode - VDDANA = 5V TBD MHz 12-bit resolution mode - VDDANA = 3.3V 1.2(1) MHz 10-bit resolution mode - VDDANA = 3.3V 1.6 (1) MHz 8-bit resolution mode - VDDANA = 3.3V TBD MHz Return from idle mode TBD s 12-bit resolution mode ADC clock = 1.5 MHz - VDDANA = 5V 8 ADC clock 10-bit resolution mode ADC clock = 2MHz - VDDANA = 5V 7 ADC clock 8-bit resolution mode ADC clock = TBD - VDDANA = 5V 6 ADC clock 12-bit resolution mode ADC clock = 1.2 MHz - VDDANA = 3V 8 ADC clock 10-bit resolution mode ADC clock = 1.6MHz - VDDANA = 3V 7 ADC clock 8-bit resolution mode ADC clock = TBD - VDDANA = 3V 6 ADC clock 12-bit resolution ADC clock = 1.5 MHz - VDDANA = 5V 1.5 MSPS 2 MSPS 12-bit resolution ADC clock = 1.2 MHz - VDDANA = 3V 1.2 MSPS 10-bit resolution ADC clock = 1.6 MHz - VDDANA = 3V 1.6 MSPS 10-bit resolution ADC clock = 2 MHz - VDDANA = 5V Notes: Units (1) (1) 10-bit resolution mode - VDDANA = 5V ADC clock frequency Max 1. These values are guaranteed by design and will be updated after characterization of current silicon. Table 40-28. Reference Voltage Parameter Conditions Min ADCREF0/ADCREF1 input voltage range 5V Range 1(1) 3V Range (1) ADCREF0/ADCREF1 average current Internal 1V reference Internal 0.6*VDDANA reference Notes: 1 Typ Max Units 3.5(1) V (1) VVDDANA-0.7 TBD TBD V A 1.0(1) V 0.6*VVDDANA(1) V 1. These values are guaranteed by design and will be updated after characterization of current silicon. 1256 32117A-10/2010 AT32UC3C Table 40-29. Decoupling requirements Symbol Parameter CADCREFPN ADCREFP-ADCREFN capacitance Conditions Min Typ Max Units Units 100 nF Table 40-30. ADC Inputs Parameter Conditions Min Input leakage current External source impedance Note: Typ 0(1) ADC input voltage range Max Units VVDDANA(1) 1 A ADC used without S/H 1 k ADC used with S/H 3 k 1. These values are guaranteed by design and will be updated after characterization of current silicon. Table 40-31. Transfer Characteristics 12-bit Resolution Mode Parameter Conditions Min Typ Differential mode Resolution Single-ended mode Max Units 12 (1) Bit 11 (1) Bit Integral Non-Linearity (INL) TBD LSB Differential Non-Linearity (DNL) TBD LSB Offset error TBD LSB Gain error TBD LSB Max Units Note: 1. These values are guaranteed by design and will be updated after characterization of current silicon. 40.8.6.1 ADC S/H Characteristics Table 40-32. Channel Conversion Time and ADC Clock Parameter Conditions Min Typ 1 to 64(1) Gain Resolution Gain = 1 with calibration 11(1) Gain not equal to 1 clock frequency Note: bits (1) 9 1.5(1) bits MHz 1. These values are guaranteed by design and will be updated after characterization of current silicon. 1257 32117A-10/2010 AT32UC3C 40.8.7 Digital to Analog Converter (DAC) Characteristics Table 40-33. Channel Conversion Time and DAC Clock Parameter Conditions Min Typ Max Units TBD s 12-bit resolution One S/H 1(1) MSPS 12-bit resolution Two S/H 0.750(1) MSPS Startup time Throughput rate Note: 1. These values are guaranteed by design and will be updated after characterization of current silicon. Table 40-34. External Voltage Reference Input Parameter Conditions Min DACREF input voltage range DACREF input capacitance DACREF input resitance Max Units 1(1) Typ TBD V 1 (1) TBD pF 1 (1) TBD k DACREF average current TBD A Current consumption on VDDANA TBD mA Note: 1. These values are guaranteed by design and will be updated after characterization of current silicon. Table 40-35. DAC Outputs Parameter Min Output range 0 Typ (1) Max Units VDACREF(1)(2) Output settling time TBD Output capacitance TBD pF Output resitance TBD k Note: s 1. These values are guaranteed by design and will be updated after characterization of current silicon. 2. DACREF corresponds to the internal or external DAC reference voltage depending on the DACREF settings Table 40-36. Transfer Characteristics Parameter Resolution Conditions Min Typ Differential mode Max 12 (1) Units Bit Integral Non-Linearity (INL) TBD LSB Differential Non-linearity (DNL) TBD LSB Offset error TBD LSB Gain error TBD LSB Calibrated Gain/Offset error TBD LSB Note: 1. These values are guaranteed by design and will be updated after characterization of current silicon. 1258 32117A-10/2010 AT32UC3C 40.8.8 Analog Comparator Characteristics Table 40-37. Analog Comparator Characteristics Parameter Conditions Min Positive input voltage range 0 Negative input voltage range 0 Typ Max Units VVDDANA V VVDDANA V (1) TBD mV TBD mV 20(1) TBD mV (1) TBD mV High Speed mode TBD ns Low Speed mode TBD ns Offset +/-5 No Hysteresis Low High Propagation delay Current consumption on VDDANA 50 High Speed mode Low Speed mode Start-up time Note: (1) 170 A 23 (1) A 10 (1) s 1. These values are guaranteed by design and will be updated after characterization of current silicon. 1259 32117A-10/2010 AT32UC3C 40.9 Timing Characteristics 40.9.1 Startup, Reset, and Wake-up Timing The startup, reset, and wake-up timings are calculated using the following formula: t = t CONST + N CPU x t CPU Where t CONST and N CPU are found in Table 40-38. t CPU is the period of the CPU clock. If another clock source than RCSYS is selected as CPU clock the startup time of the oscillator, t OSCSTART , must added to the wake-up time in the stop, deepstop, and static sleep modes. Please refer to the source for the CPU clock in the "Oscillator Characteristics" on page 1249 for more details about oscillator startup times. Table 40-38. Maximum Reset and Wake-up Timing(1) Max t CONST (in s) Parameter Measuring Startup time from power-up, using regulator VDDIN_5 rising (TBD V/ms) Time from VDDIN_5=0 to the first instruction entering the decode stage of CPU. VDDCORE is supplied by the internal regulator. Startup time from reset release Time from releasing a reset source (except POR, BOD18, and BOD33) to the first instruction entering the decode stage of CPU. TBD 0 1240(1) 0 Idle 0 TBD Frozen 0 TBD 0 TBD TBD TBD Deepstop TBD TBD Static TBD TBD Standby Wake-up Stop Note: Max N CPU From wake-up event to the first instruction of an interrupt routine entering the decode stage of the CPU. 1. These values are guaranteed by design and will be updated after characterization of current silicon. 40.9.2 RESET_N characteristics Table 40-39. RESET_N Clock Waveform Parameters Symbol Parameter tRESET RESET_N minimum pulse length Condition Min. 2 * TRCSYS Typ. Max. Units clock cycles 1260 32117A-10/2010 AT32UC3C 41. Mechanical Characteristics 41.1 41.1.1 Thermal Considerations Thermal Data Table 41-1 summarizes the thermal resistance data depending on the package. Table 41-1. 41.1.2 Thermal Resistance Data Symbol Parameter Condition Package Typ JA Junction-to-ambient thermal resistance No air flow TQFP64 TBD JC Junction-to-case thermal resistance TQFP64 TBD JA Junction-to-ambient thermal resistance TQFP100 39.3 JC Junction-to-case thermal resistance TQFP100 8.5 JA Junction-to-ambient thermal resistance LQFP144 38.1 JC Junction-to-case thermal resistance LQFP144 8.4 No air flow No air flow Unit C/W C/W C/W Junction Temperature The average chip-junction temperature, TJ, in C can be obtained from the following: 1. T J = T A + ( P D x JA ) 2. T J = T A + ( P D x ( HEATSINK + JC ) ) where: * JA = package thermal resistance, Junction-to-ambient (C/W), provided in Table 41-1 on page 1261. * JC = package thermal resistance, Junction-to-case thermal resistance (C/W), provided in Table 41-1 on page 1261. * HEAT SINK = cooling device thermal resistance (C/W), provided in the device datasheet. * PD = device power consumption (W) estimated from data provided in the section "Power Consumption" on page 1244. * TA = ambient temperature (C). From the first equation, 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, the second equation should be used to compute the resulting average chip-junction temperature TJ in C. 1261 32117A-10/2010 AT32UC3C 41.2 Package Drawings Figure 41-1. QFN-64 package drawing Note: Table 41-2. The exposed pad is not connected to anything. Device and Package Maximum Weight TBD Table 41-3. mg Package Characteristics Moisture Sensitivity Level Table 41-4. Jdec J-STD0-20D - MSL 3 Package Reference JEDEC Drawing Reference MS-026 JESD97 Classification E3 1262 32117A-10/2010 AT32UC3C Figure 41-2. TQFP-64 package drawing Table 41-5. Device and Package Maximum Weight TBD Table 41-6. mg Package Characteristics Moisture Sensitivity Level Table 41-7. Jdec J-STD0-20D - MSL 3 Package Reference JEDEC Drawing Reference MS-026 JESD97 Classification E3 1263 32117A-10/2010 AT32UC3C Figure 41-3. TQFP-100 package drawing Table 41-8. Device and Package Maximum Weight 500 Table 41-9. mg Package Characteristics Moisture Sensitivity Level Jdec J-STD0-20D - MSL 3 Table 41-10. Package Reference JEDEC Drawing Reference MS-026 JESD97 Classification E3 1264 32117A-10/2010 AT32UC3C Figure 41-4. LQFP-144 package drawing Table 41-11. Device and Package Maximum Weight 1300 mg Table 41-12. Package Characteristics Moisture Sensitivity Level Jdec J-STD0-20D - MSL 3 Table 41-13. Package Reference JEDEC Drawing Reference MS-026 JESD97 Classification E3 1265 32117A-10/2010 AT32UC3C 41.3 Soldering Profile Table 41-14 gives the recommended soldering profile from J-STD-20. Table 41-14. Soldering Profile Profile Feature Green Package Average Ramp-up Rate (217C to Peak) 3C/sec Preheat Temperature 175C 25C Min. 150 C, Max. 200 C Temperature Maintained Above 217C 60-150 sec Time within 5C of Actual Peak Temperature 30 sec Peak Temperature Range 260 C Ramp-down Rate 6 C/sec Time 25C to Peak Temperature Max. 8 minutes Note: It is recommended to apply a soldering temperature higher than 250C. A maximum of three reflow passes is allowed per component. 1266 32117A-10/2010 AT32UC3C 42. Ordering Information Table 42-1. Device AT32UC3C0512C AT32UC3C0256C AT32UC3C0128C AT32UC3C064C AT32UC3C1512C AT32UC3C1256C AT32UC3C1128C AT32UC3C164C AT32UC3C2512C AT32UC3C2256C AT32UC3C2128C AT32UC3C264C Ordering Information Ordering Code Carrier Type AT32UC3C0512C-ALUES ES AT32UC3C0512C-ALUT Tray AT32UC3C0512C-ALUR Tape & Reel AT32UC3C0256C-ALUT Tray AT32UC3C0256C-ALUR Tape & Reel AT32UC3C0128C-ALUT Tray AT32UC3C0128C-ALUR Tape & Reel AT32UC3C064C-ALUT Tray AT32UC3C064C-ALUR Tape & Reel AT32UC3C1512C-AUES ES AT32UC3C1512C-AUT Tray AT32UC3C1512C-AUR Tape & Reel AT32UC3C1256C-AUT Tray AT32UC3C1256C-AUR Tape & Reel AT32UC3C1128C-AUT Tray AT32UC3C1128C-AUR Tape & Reel AT32UC3C164C-AUT Tray AT32UC3C164C-AUR Tape & Reel 32UC3C2512C-A2UES ES 32UC3C2512C-A2UT Tray 32UC3C2512C-A2UR Tape & Reel 32UC3C2512C-Z2UES ES 32UC3C2512C-Z2UT Tray 32UC3C2512C-Z2UR Tape & Reel 32UC3C2256C-A2UT Tray 32UC3C2256C-A2UR Tape & Reel 32UC3C2256C-Z2UT Tray 32UC3C2256C-Z2UR Tape & Reel 32UC3C2128C-A2UT Tray 32UC3C2128C-A2UR Tape & Reel 32UC3C2128C-Z2UT Tray 32UC3C2128C-Z2UR Tape & Reel 32UC3C2128C-A2UT Tray 32UC3C2128C-A2UR Tape & Reel 32UC3C2128C-Z2UT Tray 32UC3C2128C-Z2UR Tape & Reel Package Temperature Operating Range LQFP 144 TQFP 100 Industrial (-40C to 85C) TQFP 64 QFN 64 TQFP 64 QFN 64 TQFP 64 QFN 64 TQFP 64 QFN 64 1267 32117A-10/2010 AT32UC3C 43. Errata 43.1 43.1.1 rev D AST 1. AST wake signal is released one ast clock cycle after the busy register is cleared After writing to the Status Clear Register (SCR) the wake signal is released one AST clock cycle after the BUSY bit in the Status Register (SR.BUSY) is cleared. If entering sleep mode directly after the BUSY bit is cleared the part will wake up immediately. Fix/Workaround Read the Wake Enable Register (WER) and write this value back to the same register. Wait for BUSY to clear before entering sleep mode. 43.1.2 GPIO 1. Clearing Interrupt flags can mask other interrupts When clearing interrupt flags in a GPIO port, interrupts on other pins of that port, happening in the same clock cycle will not be registered. Fix / Workaround Read the PVR register of the port before and after clearing the interrupt to see if any pin change has happened while clearing the interrupt. If any change occurred in the PVR between the reads, they must be treated as an interrupt. 43.1.3 Power Manager 1. Clock Failure Detector (CFD) can be issued while turning off the CFD While turning off the CFD, the CFD bit in the Status Register (SR) can be set. This will change the main clock source to RCSYS. Fix/Workaround Solution 1: Enable CFD interrupt. If CFD interrupt is issues after turning off the CFD, switch back to original main clock source. Solution 2: Only turn off the CFD while running the main clock on RCSYS. 2. Requesting clocks in idle sleep modes will mask all other PB clocks than the requested In idle or frozen sleep mode, all the PB clocks will be frozen if the TWIS or the AST need to wake the cpu up. Fix/Workaround Disable the TWIS or the AST before entering idle or frozen sleep mode. 43.1.4 SPI 1. SPI disable does not work in SLAVE mode SPI disable does not work in SLAVE mode. Fix/Workaround Read the last received data, then perform a software reset by writing a one to the Software Reset bit in the Control Register (CR.SWRST). 2. SPI Bad Serial Clock Generation on 2nd chip select when SCBR==1, CPOL==1, and NCPHA==0 1268 32117A-10/2010 AT32UC3C When multiple chip selects are in use, if one of the baudrates is equal to 1 (CSRn.SCBR==1) and one of the others is not equal to 1, and CSRn.CPOL==1 and CSRn.NCPHA==0, an additional pulse will be generated on SCK. Fix/Workaround When multiple chip selects are in use, if one of the baudrates is equal to 1, the others must also be equal to 1 if CSRn.CPOL==1 and CSRn.NCPHA==0. 3. SPI data transfer hangs with CSR0.CSAAT==1 and MR.MODFDIS==0 When CSR0.CSAAT==1 and mode fault detection is enabled (MR.MODFDIS==0), the SPI module will not start a data transfer. Fix/Workaround Disable mode fault detection by writing a one to MR.MODFDIS. 4. Disabling SPI has no effect on the SR.TDRE bit Disabling SPI has no effect on SR.TDRE whereas the write data command is filtered when SPI is disabled. This means that as soon as the SPI is disabled it becomes impossible to reset the SR.TDRE bit by writing to TDR. So if the SPI is disabled during a PDCA transfer, the PDCA will continue to write data to TDR (as SR.TDRE stays high) until its buffer is empty, and all data written after the disable command is lost. Fix/Workaround Disable the PDCA, add 2 NOP (minimum), and disable the SPI. To continue the transfer, enable the SPI and the PDCA. 43.1.5 TWI 1. TWIM SMBAL polarity is wrong The SMBAL signal in the TWIM is active high instead of active low. Fix/Workaround Use an external inverter to invert the signal going into the TWIM. When using both TWIM and TWIS on the same pins, the SMBAL cannot be used. 43.1.6 USBC 1. UPINRQx.INRQ field is limited to 8-bits In Host mode, when using the UPINRQx.INRQ feature together with the multi-packet mode to launch a finite number of packet among multi-packet, the multi-packet size (located in the descriptor table) is limited to the UPINRQx.INRQ value multiply by the pipe size. Fix/Workaround UPINRQx.INRQ value shall be less than the number of configured multi-packet. 43.1.7 WDT 1. Clearing the Watchdog Timer (WDT) counter in second half of timeout period will issue a Watchdog reset If the WDT counter is cleared in the second half of the timeout period, the WDT will immediately issue a Watchdog reset. Fix/Workaround Use twice as long timeout period as needed and clear the WDT counter within the first half of the timeout period. If the WDT counter is cleared after the first half of the timeout period, you will get a Watchdog reset immediately. If the WDT counter is not cleared at all, the time before the reset will be twice as long as needed. 1269 32117A-10/2010 AT32UC3C 1270 32117A-10/2010 AT32UC3C 44. 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. 44.1 Rev. A - 10/10 1 Initial revision 1271 32117A-10/2010 AT32UC3C Table of Content 1 Description ............................................................................................... 3 2 Overview ................................................................................................... 5 3 4 5 6 7 2.1 Block diagram ....................................................................................................5 2.2 Configuration Summary .....................................................................................6 Package and Pinout ................................................................................. 8 3.1 Package .............................................................................................................8 3.2 Peripheral Multiplexing on I/O lines .................................................................10 3.3 Signals Description ..........................................................................................18 3.4 I/O Line Considerations ...................................................................................24 Processor and Architecture .................................................................. 25 4.1 Features ..........................................................................................................25 4.2 AVR32 Architecture .........................................................................................25 4.3 The AVR32UC CPU ........................................................................................26 4.4 Programming Model ........................................................................................30 4.5 Exceptions and Interrupts ................................................................................34 Memories ................................................................................................ 39 5.1 Embedded Memories ......................................................................................39 5.2 Physical Memory Map .....................................................................................40 5.3 Peripheral Address Map ..................................................................................41 5.4 CPU Local Bus Mapping .................................................................................43 Supply and Startup Considerations ..................................................... 46 6.1 Supply Considerations .....................................................................................46 6.2 Startup Considerations ....................................................................................49 Power Manager (PM) .............................................................................. 50 7.1 Features ..........................................................................................................50 7.2 Overview ..........................................................................................................50 7.3 Block Diagram .................................................................................................51 7.4 I/O Lines Description .......................................................................................51 7.5 Product Dependencies ....................................................................................51 7.6 Functional Description .....................................................................................52 7.7 User Interface ..................................................................................................58 7.8 Module Configuration ......................................................................................80 1272 32117A-10/2010 AT32UC3C 8 9 System Control Interface (SCIF) ........................................................... 81 8.1 Features ..........................................................................................................81 8.2 Description .......................................................................................................81 8.3 I/O Lines Description .......................................................................................81 8.4 Product Dependencies ....................................................................................81 8.5 Functional Description .....................................................................................82 8.6 User Interface ..................................................................................................90 8.7 Module Configuration ....................................................................................131 Asynchronous Timer (AST) ................................................................ 132 9.1 Features ........................................................................................................132 9.2 Overview ........................................................................................................132 9.3 Block Diagram ...............................................................................................133 9.4 Product Dependencies ..................................................................................133 9.5 Functional Description ...................................................................................134 9.6 User Interface ................................................................................................139 9.7 Module configuration .....................................................................................158 10 Watchdog Timer (WDT) ....................................................................... 159 10.1 Features ........................................................................................................159 10.2 Overview ........................................................................................................159 10.3 Block Diagram ...............................................................................................159 10.4 Product Dependencies ..................................................................................159 10.5 Functional Description ...................................................................................160 10.6 User Interface ................................................................................................165 10.7 Module Configuration ....................................................................................171 11 Interrupt Controller (INTC) .................................................................. 172 11.1 Features ........................................................................................................172 11.2 Overview ........................................................................................................172 11.3 Block Diagram ...............................................................................................172 11.4 Product Dependencies ..................................................................................173 11.5 Functional Description ...................................................................................173 11.6 User Interface ................................................................................................176 11.7 Interrupt Request Signal Map ........................................................................180 12 External Interrupt Controller (EIC) ..................................................... 185 12.1 Features ........................................................................................................185 12.2 Overview ........................................................................................................185 1273 32117A-10/2010 AT32UC3C 12.3 Block Diagram ...............................................................................................185 12.4 I/O Lines Description .....................................................................................186 12.5 Product Dependencies ..................................................................................186 12.6 Functional Description ...................................................................................186 12.7 User Interface ................................................................................................190 12.8 Module Configuration ....................................................................................206 13 Frequency Meter (FREQM) .................................................................. 207 13.1 Features ........................................................................................................207 13.2 Overview ........................................................................................................207 13.3 Block Diagram ...............................................................................................207 13.4 Product Dependencies ..................................................................................207 13.5 Functional Description ...................................................................................208 13.6 User Interface ................................................................................................210 13.7 Module Configuration ....................................................................................221 14 Peripheral Event Controller (PEVC) ................................................... 223 14.1 Features ........................................................................................................223 14.2 Overview ........................................................................................................223 14.3 Block Diagram ...............................................................................................224 14.4 I/O Lines Description .....................................................................................225 14.5 Product Dependencies ..................................................................................225 14.6 Functional Description ...................................................................................226 14.7 User Interface ................................................................................................228 14.8 Module Configuration ....................................................................................249 14.9 .......................................................................................................................250 15 Flash Controller (FLASHC) ................................................................. 251 15.1 Features ........................................................................................................251 15.2 Overview ........................................................................................................251 15.3 Product Dependencies ..................................................................................251 15.4 Functional description ....................................................................................252 15.5 Flash Commands ..........................................................................................257 15.6 General-purpose fuse bits .............................................................................259 15.7 Security bit .....................................................................................................262 15.8 User interface ................................................................................................263 15.9 Fuses Settings ...............................................................................................273 15.10 Calibration Settings .......................................................................................276 1274 32117A-10/2010 AT32UC3C 15.11 Serial Number ................................................................................................282 15.12 Module Configuration ....................................................................................282 16 HSB Bus Matrix (HMATRIXB) .............................................................. 283 16.1 Features ........................................................................................................283 16.2 Overview ........................................................................................................283 16.3 Product Dependencies ..................................................................................283 16.4 Functional Description ...................................................................................283 16.5 User Interface ................................................................................................287 16.6 Bus Matrix Connections .................................................................................295 17 External Bus Interface (EBI) ................................................................ 297 17.1 Features ........................................................................................................297 17.2 Overview ........................................................................................................297 17.3 Block Diagram ...............................................................................................298 17.4 I/O Lines Description .....................................................................................298 17.5 Product Dependencies ..................................................................................300 17.6 Functional Description ...................................................................................301 17.7 Application Example ......................................................................................302 18 Static Memory Controller (SMC) ......................................................... 305 18.1 Features ........................................................................................................305 18.2 Overview ........................................................................................................305 18.3 Block Diagram ...............................................................................................306 18.4 I/O Lines Description .....................................................................................306 18.5 Product Dependencies ..................................................................................306 18.6 Functional Description ...................................................................................307 18.7 User Interface ................................................................................................339 19 SDRAM Controller (SDRAMC) ............................................................ 346 19.1 Features ........................................................................................................346 19.2 Overview ........................................................................................................346 19.3 Block Diagram ...............................................................................................347 19.4 I/O Lines Description .....................................................................................347 19.5 Application Example ......................................................................................348 19.6 Product Dependencies ..................................................................................349 19.7 Functional Description ...................................................................................350 19.8 User Interface ................................................................................................359 1275 32117A-10/2010 AT32UC3C 20 Peripheral DMA Controller (PDCA) .................................................... 372 20.1 Features ........................................................................................................372 20.2 Overview ........................................................................................................372 20.3 Block Diagram ...............................................................................................373 20.4 Product Dependencies ..................................................................................373 20.5 Functional Description ...................................................................................374 20.6 Performance Monitors ...................................................................................376 20.7 User Interface ................................................................................................378 20.8 Module Configuration ....................................................................................406 21 Memory DMA Controller (MDMA) ....................................................... 408 21.1 Features ........................................................................................................408 21.2 Overview ........................................................................................................408 21.3 Product Dependencies ..................................................................................408 21.4 Functional Description ...................................................................................409 21.5 Single Transfer Mode ....................................................................................410 21.6 Descriptor Mode ............................................................................................411 21.7 User interface ................................................................................................413 21.8 Module Configuration ....................................................................................428 22 Secure Access Unit (SAU) .................................................................. 429 22.1 Features ........................................................................................................429 22.2 Overview ........................................................................................................429 22.3 Block Diagram ...............................................................................................430 22.4 Product Dependencies ..................................................................................431 22.5 Functional Description ...................................................................................431 22.6 User Interface ................................................................................................435 22.7 Module configuration .....................................................................................450 23 General-Purpose Input/Output Controller (GPIO) ............................. 451 23.1 Features ........................................................................................................451 23.2 Overview ........................................................................................................451 23.3 Block Diagram ...............................................................................................451 23.4 I/O Lines Description .....................................................................................452 23.5 Product Dependencies ..................................................................................452 23.6 Functional Description ...................................................................................453 23.7 User Interface ................................................................................................458 23.8 Module Configuration ....................................................................................483 1276 32117A-10/2010 AT32UC3C 24 Ethernet MAC (MACB) ......................................................................... 485 24.1 Features ........................................................................................................485 24.2 Overview ........................................................................................................485 24.3 Block Diagram ...............................................................................................486 24.4 Product Dependencies ..................................................................................486 24.5 Functional Description ...................................................................................487 24.6 Programming Interface ..................................................................................500 24.7 User Interface ................................................................................................503 24.8 Module Configuration ....................................................................................558 25 Universal Synchronous Asynchronous Receiver Transmitter (USART) 559 25.1 Features ........................................................................................................559 25.2 Overview ........................................................................................................559 25.3 Block Diagram ...............................................................................................561 25.4 I/O Lines Description ....................................................................................562 25.5 Product Dependencies ..................................................................................563 25.6 Functional Description ...................................................................................564 25.7 User Interface ................................................................................................622 25.8 Module Configuration ....................................................................................652 26 Serial Peripheral Interface (SPI) ......................................................... 654 26.1 Features ........................................................................................................654 26.2 Overview ........................................................................................................654 26.3 Block Diagram ...............................................................................................655 26.4 Application Block Diagram .............................................................................655 26.5 I/O Lines Description .....................................................................................656 26.6 Product Dependencies ..................................................................................656 26.7 Functional Description ...................................................................................656 26.8 User Interface ................................................................................................667 26.9 Module Configuration ....................................................................................694 27 Two-Wire Master Interface (TWIM) ..................................................... 695 27.1 Features ........................................................................................................695 27.2 Overview ........................................................................................................695 27.3 List of Abbreviations ......................................................................................696 27.4 Block Diagram ...............................................................................................696 27.5 Application Block Diagram .............................................................................697 1277 32117A-10/2010 AT32UC3C 27.6 I/O Lines Description .....................................................................................697 27.7 Product Dependencies ..................................................................................697 27.8 Functional Description ...................................................................................699 27.9 User Interface ................................................................................................711 27.10 Module Configuration ....................................................................................728 28 Two-Wire Slave Interface (TWIS) ........................................................ 729 28.1 Features ........................................................................................................729 28.2 Overview ........................................................................................................729 28.3 List of Abbreviations ......................................................................................730 28.4 Block Diagram ...............................................................................................730 28.5 Application Block Diagram .............................................................................731 28.6 I/O Lines Description .....................................................................................731 28.7 Product Dependencies ..................................................................................731 28.8 Functional Description ...................................................................................732 28.9 User Interface ................................................................................................742 28.10 Module Configuration ....................................................................................758 29 CAN Interface (CANIF) ......................................................................... 759 29.1 Features ........................................................................................................759 29.2 Overview ........................................................................................................759 29.3 Block Diagram ...............................................................................................760 29.4 I/O Lines Description .....................................................................................760 29.5 Product Dependencies ..................................................................................760 29.6 Functional Description ...................................................................................761 29.7 User Interface ................................................................................................771 29.8 Module Configuration ....................................................................................799 30 Inter-IC Sound Controller (IISC) .......................................................... 800 30.1 Features ........................................................................................................800 30.2 Overview ........................................................................................................800 30.3 Block Diagram ...............................................................................................801 30.4 I/O Lines Description .....................................................................................801 30.5 Product Dependencies ..................................................................................801 30.6 Functional Description ...................................................................................802 30.7 IISC Application Examples ............................................................................806 30.8 User Interface ................................................................................................808 30.9 Module configuration .....................................................................................822 1278 32117A-10/2010 AT32UC3C 31 Timer/Counter (TC) .............................................................................. 823 31.1 Features ........................................................................................................823 31.2 Overview ........................................................................................................823 31.3 Block Diagram ...............................................................................................824 31.4 I/O Lines Description .....................................................................................824 31.5 Product Dependencies ..................................................................................824 31.6 Functional Description ...................................................................................825 31.7 User Interface ................................................................................................840 31.8 Module Configuration ....................................................................................863 32 USB Interface (USBC) .......................................................................... 864 32.1 Features ........................................................................................................864 32.2 Overview ........................................................................................................864 32.3 Block Diagram ...............................................................................................864 32.4 Application Block Diagram .............................................................................866 32.5 I/O Lines Description .....................................................................................867 32.6 Product Dependencies ..................................................................................868 32.7 Functional Description ...................................................................................869 32.8 User Interface ................................................................................................898 32.9 Module Configuration ....................................................................................957 33 Pulse Width Modulation Controller (PWM) ........................................ 958 33.1 Features ........................................................................................................958 33.2 Overview ........................................................................................................958 33.3 Block Diagram ...............................................................................................960 33.4 I/O Lines Description .....................................................................................961 33.5 Product Dependencies ..................................................................................962 33.6 Functional Description ...................................................................................963 33.7 User Interface ................................................................................................989 33.8 Module Configuration ..................................................................................1042 34 Quadrature Decoder (QDEC) ............................................................ 1043 34.1 Features ......................................................................................................1043 34.2 Overview ......................................................................................................1043 34.3 Block Diagram .............................................................................................1044 34.4 I/O Lines Description ...................................................................................1044 34.5 Product Dependencies ................................................................................1044 34.6 Functional Description .................................................................................1045 1279 32117A-10/2010 AT32UC3C 34.7 User Interface ..............................................................................................1052 34.8 Module Configuration ..................................................................................1068 35 Analog Comparator Interface (ACIFA) ............................................. 1069 35.1 Features ......................................................................................................1069 35.2 Overview ......................................................................................................1069 35.3 Block Diagram .............................................................................................1070 35.4 Product Dependencies ................................................................................1071 35.5 Functional Description .................................................................................1071 35.6 User Interface ..............................................................................................1075 35.7 Module configuration ...................................................................................1094 36 ADC Interface (ADCIFA) .................................................................... 1097 36.1 Features ......................................................................................................1097 36.2 Overview ......................................................................................................1098 36.3 Block Diagram .............................................................................................1099 36.4 I/O Lines Description ...................................................................................1100 36.5 Product Dependencies ................................................................................1100 36.6 Functional Description .................................................................................1101 36.7 User Interface ..............................................................................................1114 36.8 Module configuration ...................................................................................1141 37 DACIFB Interface (DACIFB) .............................................................. 1143 37.1 Features ......................................................................................................1143 37.2 Overview ......................................................................................................1143 37.3 Block Diagram .............................................................................................1144 37.4 I/O Lines Description ...................................................................................1145 37.5 Product Dependencies ................................................................................1145 37.6 Functional Description .................................................................................1146 37.7 User Interface ..............................................................................................1152 37.8 Module Configuration ..................................................................................1172 38 aWire UART (AW) ............................................................................... 1173 38.1 Features ......................................................................................................1173 38.2 Overview ......................................................................................................1173 38.3 Block Diagram .............................................................................................1173 38.4 I/O Lines Description ...................................................................................1174 38.5 Product Dependencies ................................................................................1174 38.6 Functional Description .................................................................................1174 1280 32117A-10/2010 AT32UC3C 38.7 User Interface ..............................................................................................1177 38.8 Module Configuration ..................................................................................1190 39 Programming and Debugging .......................................................... 1191 39.1 Overview ......................................................................................................1191 39.2 Service Access Bus .....................................................................................1191 39.3 On-Chip Debug ............................................................................................1194 39.4 JTAG and Boundary-Scan (JTAG) ..............................................................1202 39.5 JTAG Instruction Summary .........................................................................1210 39.6 aWire Debug Interface (AW) .......................................................................1225 39.7 Module Configuration ..................................................................................1242 40 Electrical Characteristics .................................................................. 1243 40.1 Absolute Maximum Ratings* .......................................................................1243 40.2 Supply Characteristics .................................................................................1243 40.3 Maximum Clock Frequencies ......................................................................1244 40.4 Power Consumption ....................................................................................1244 40.5 I/O Pin Characteristics .................................................................................1248 40.6 Oscillator Characteristics .............................................................................1249 40.7 Flash Characteristics ...................................................................................1252 40.8 Analog Characteristics .................................................................................1253 40.9 Timing Characteristics .................................................................................1260 41 Mechanical Characteristics ............................................................... 1261 41.1 Thermal Considerations ..............................................................................1261 41.2 Package Drawings .......................................................................................1262 41.3 Soldering Profile ..........................................................................................1266 42 Ordering Information ......................................................................... 1267 43 Errata ................................................................................................... 1268 43.1 rev D ............................................................................................................1268 44 Datasheet Revision History .............................................................. 1271 44.1 Rev. A - 10/10 .............................................................................................1271 1281 32117A-10/2010 Headquarters International Atmel Corporation 2325 Orchard Parkway San Jose, CA 95131 USA Tel: 1(408) 441-0311 Fax: 1(408) 487-2600 Atmel Asia Unit 1-5 & 16, 19/F BEA Tower, Millennium City 5 418 Kwun Tong Road Kwun Tong, Kowloon Hong Kong Tel: (852) 2245-6100 Fax: (852) 2722-1369 Atmel Europe Le Krebs 8, Rue Jean-Pierre Timbaud BP 309 78054 Saint-Quentin-enYvelines Cedex France Tel: (33) 1-30-60-70-00 Fax: (33) 1-30-60-71-11 Atmel Japan 9F, Tonetsu Shinkawa Bldg. 1-24-8 Shinkawa Chuo-ku, Tokyo 104-0033 Japan Tel: (81) 3-3523-3551 Fax: (81) 3-3523-7581 Technical Support avr32@atmel.com Sales Contact www.atmel.com/contacts Product Contact Web Site www.atmel.com Literature Requests www.atmel.com/literature 92085 Disclaimer: The information in this document is provided in connection with Atmel products. No license, express or implied, by estoppel or otherwise, to any intellectual property right is granted by this document or in connection with the sale of Atmel products. EXCEPT AS SET FORTH IN ATMEL'S TERMS AND CONDITIONS OF SALE LOCATED ON ATMEL'S WEB SITE, ATMEL ASSUMES NO LIABILITY WHATSOEVER AND DISCLAIMS ANY EXPRESS, IMPLIED OR STATUTORY WARRANTY RELATING TO ITS PRODUCTS INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, CONSEQUENTIAL, PUNITIVE, SPECIAL OR INCIDENTAL DAMAGES (INCLUDING, WITHOUT LIMITATION, DAMAGES FOR LOSS OF PROFITS, BUSINESS INTERRUPTION, OR LOSS OF INFORMATION) ARISING OUT OF THE USE OR INABILITY TO USE THIS DOCUMENT, EVEN IF ATMEL HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. Atmel makes no representations or warranties with respect to the accuracy or completeness of the contents of this document and reserves the right to make changes to specifications and product descriptions at any time without notice. Atmel does not make any commitment to update the information contained herein. Unless specifically provided otherwise, Atmel products are not suitable for, and shall not be used in, automotive applications. Atmel's products are not intended, authorized, or warranted for use as components in applications intended to support or sustain life. (c) 2010 Atmel Corporation. All rights reserved. Atmel(R), Atmel logo and combinations thereof, AVR(R) and others are registered trademarks or trademarks of Atmel Corporation or its subsidiaries. Other terms and product names may be trademarks of others. 32117A-10/2010