Microchip Technology megaAVR 0 Series Manual
Hide thumbs Also See for megaAVR 0 Series:
Table of Contents

Advertisement

Introduction

The ATmega3208/3209/4808/4809 microcontrollers of the megaAVR
processor with hardware multiplier, running at up to 20 MHz, with a wide range of Flash sizes up to 48
KB, up to 6 KB of SRAM, and 256 bytes of EEPROM in 28-, 32-, or 48-pin package. The series uses the
latest technologies from Microchip with a flexible and low-power architecture including Event System and
SleepWalking, accurate analog features and advanced peripherals.
This Manual contains the general descriptions of the peripherals. While the available peripherals have
identical features and show the same behavior across the series, packages with fewer pins support a
subset of signals. Refer to the Data Sheet of the individual device for available pins and signals.

Features

®
AVR
CPU
Single-cycle I/O access
Two-level interrupt controller
Two-cycle hardware multiplier
Memories
Up to 48 KB In-system self-programmable Flash memory
256B EEPROM
Up to 6 KB SRAM
Write/Erase endurance:
Flash 10,000 cycles
EEPROM 100,000 cycles
Data retention: 20 Years at 85°C
System
Power-on Reset (POR) circuit
Brown-out Detection (BOD)
Clock options:
Lockable 20 MHz low power internal oscillator
32.768 kHz Ultra Low-Power (ULP) internal oscillator
32.768 kHz external crystal oscillator
External clock input
Single-pin Unified Program Debug Interface (UPDI)
Three sleep modes:
Idle with all peripherals running and mode for immediate wake-up time
©
2018 Microchip Technology Inc.
megaAVR
Manual
®
Datasheet Preliminary
®
0-Series
0-series are using the AVR
DS40002015A-page 1
®

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the megaAVR 0 Series and is the answer not in the manual?

Questions and answers

Subscribe to Our Youtube Channel

Summary of Contents for Microchip Technology megaAVR 0 Series

  • Page 1: Introduction

    32.768 kHz external crystal oscillator • External clock input – Single-pin Unified Program Debug Interface (UPDI) – Three sleep modes: • Idle with all peripherals running and mode for immediate wake-up time Datasheet Preliminary DS40002015A-page 1 © 2018 Microchip Technology Inc.
  • Page 2 Temperature Range: -40°C to 125°C • Speed Grades: – 0-5 MHz @ 1.8V – 5.5V – 0-10 MHz @ 2.7V – 5.5V – 0-20 MHz @ 4.5V – 5.5V, -40°C to 105°C Datasheet Preliminary DS40002015A-page 2 © 2018 Microchip Technology Inc.
  • Page 3: Table Of Contents

    Features............................. 50 7.2. Overview............................ 50 7.3. Architecture..........................50 7.4. Arithmetic Logic Unit (ALU)......................52 7.5. Functional Description........................52 7.6. Register Summary - CPU......................57 7.7. Register Description........................57 8. Nonvolatile Memory Controller (NVMCTRL)............62 Datasheet Preliminary DS40002015A-page 3 © 2018 Microchip Technology Inc.
  • Page 4 13.4. Register Summary - EVSYS....................123 13.5. Register Description......................... 123 14. Port Multiplexer (PORTMUX)................129 14.1. Overview..........................129 14.2. Register Summary - PORTMUX....................130 14.3. Register Description......................... 130 15. I/O Pin Configuration (PORT)................137 15.1. Features........................... 137 Datasheet Preliminary DS40002015A-page 4 © 2018 Microchip Technology Inc.
  • Page 5 20. 16-bit Timer/Counter Type B (TCB)............... 234 20.1. Features........................... 234 20.2. Overview..........................234 20.3. Functional Description......................235 20.4. Register Summary - TCB......................243 20.5. Register Description......................... 243 21. Real-Time Counter (RTC)..................255 21.1. Features........................... 255 21.2. Overview..........................255 Datasheet Preliminary DS40002015A-page 5 © 2018 Microchip Technology Inc.
  • Page 6 26. CCL – Configurable Custom Logic................ 378 26.1. Features........................... 378 26.2. Overview..........................378 26.3. Functional Description......................380 26.4. Register Summary - CCL......................388 26.5. Register Description......................... 388 27. Analog Comparator (AC)..................399 27.1. Features........................... 399 Datasheet Preliminary DS40002015A-page 6 © 2018 Microchip Technology Inc.
  • Page 7 Customer Change Notification Service................480 Customer Support....................... 480 Product Identification System..................481 Microchip Devices Code Protection Feature............... 481 Legal Notice.........................481 Trademarks......................... 482 Quality Management System Certified by DNV............482 Worldwide Sales and Service..................483 Datasheet Preliminary DS40002015A-page 7 © 2018 Microchip Technology Inc.
  • Page 8: Block Diagram

    LUTn-OUT BOD/ Bandgap RSTCTRL TCAn CLKCTRL SLPCTRL TCBn Clock generation CLKOUT USARTn OSC20M EXTCLK XDIR OSC32K MISO TOSC1 MOSI SPIn XOSC32K TOSC2 SDA (master) SCL (master) TWIn SDA (slave) SCL (slave) Datasheet Preliminary DS40002015A-page 8 © 2018 Microchip Technology Inc.
  • Page 9: Megaavr ® 0-Series Overview

    M=QFN 8=32 pins (SSOP: 28 pins) X=SSOP Memory Overview Table 2-1. Memory Overview Memory Type ATmega320x ATmega480x Flash 32 KB 48 KB SRAM 4 KB 6 KB EEPROM 256B 256B User row Datasheet Preliminary DS40002015A-page 9 © 2018 Microchip Technology Inc.
  • Page 10: Peripheral Overview

    1 (4) 1 (4) 1 (4) Window Watchdog Event System channels General purpose I/O External interrupts CRCSCAN TWI can operate as master and slave at the same time on different pins. Datasheet Preliminary DS40002015A-page 10 © 2018 Microchip Technology Inc.
  • Page 11: Conventions

    Table 3-3. Frequency and Time Symbol Description 1 kHz = 10 Hz = 1,000 Hz 1 KHz = 1,024 Hz, 32 KHz = 32,768 Hz 1 MHz = 10 Hz = 1,000,000 Hz Datasheet Preliminary DS40002015A-page 11 © 2018 Microchip Technology Inc.
  • Page 12: Registers And Bits

    Registers with SET/CLR suffix allows the user to clear and set bits in a register without doing a read-modify-write operation. These registers always come in pairs. Writing a ‘1’ to a bit in the CLR register will clear the corresponding bit in both registers, while Datasheet Preliminary DS40002015A-page 12 © 2018 Microchip Technology Inc.
  • Page 13 The peripheral name is written in the peripheral's register summary heading, e.g. "Register Summary - ACn", where "ACn" is the peripheral name. <peripheral_instance_name> is obtained by substituting any n or x in the peripheral name with the correct instance identifier. Datasheet Preliminary DS40002015A-page 13 © 2018 Microchip Technology Inc.
  • Page 14: Acronyms And Abbreviations

    DMA (Direct Memory Access) Controller Differential Nonlinearity (ADC characteristics) EEPROM Electrically Erasable Programmable Read-Only Memory EVSYS Event System Ground GPIO General Purpose Input/Output Inter-Integrated Circuit Interrupt flag Integral Nonlinearity (ADC characteristics) Datasheet Preliminary DS40002015A-page 14 © 2018 Microchip Technology Inc.
  • Page 15 Pulse-width Modulation Random Access Memory Reference Request RISC Reduced Instruction Set Computer RSTCTRL Reset Controller Real-time Counter Receiver/Receive SERCOM Serial Communication Interface SLPCTRL Sleep Controller SMBus System Management Bus Stack Pointer Datasheet Preliminary DS40002015A-page 15 © 2018 Microchip Technology Inc.
  • Page 16 Unified Program and Debug Interface USART Universal Synchronous and Asynchronous Serial Receiver and Transmitter Universal Serial Bus Voltage to be applied to V VREF Voltage Reference Voltage Common mode Watchdog Timer XOSC Crystal Oscillator Datasheet Preliminary DS40002015A-page 16 © 2018 Microchip Technology Inc.
  • Page 17: Memories

    The figure below shows the memory map for the biggest memory derivative in the series. Refer to the subsequent subsections for details on memory sizes and start addresses for devices with smaller memory sizes. Datasheet Preliminary DS40002015A-page 17 © 2018 Microchip Technology Inc.
  • Page 18: In-System Reprogrammable Flash Program Memory

    Boot Loader section, Application code section, and Application data section. Code placed in one section may be restricted from writing to addresses in other sections, see the NVMCTRL documentation for more details. Datasheet Preliminary DS40002015A-page 18 © 2018 Microchip Technology Inc.
  • Page 19: Sram Data Memory

    User Row (USERROW) In addition to the EEPROM, the ATmega3208/3209/4808/4809 has one extra page of EEPROM memory that can be used for firmware settings, the User Row (USERROW). This memory supports single byte Datasheet Preliminary DS40002015A-page 19 © 2018 Microchip Technology Inc.
  • Page 20: Signature Row (Sigrow)

    Signature Row. The signature bytes are given in the following table. Table 5-4. Device ID Device Name Signature Bytes Address 0x00 0x01 0x02 ATmega4809 0x1E 0x96 0x51 ATmega4808 0x1E 0x96 0x50 ATmega3209 0x1E 0x95 0x31 ATmega3208 0x1E 0x95 0x30 Datasheet Preliminary DS40002015A-page 20 © 2018 Microchip Technology Inc.
  • Page 21 0x0B SERNUM8 SERNUM[7:0] 0x0C SERNUM9 SERNUM[7:0] 0x0D Reserved 0x1F 0x20 TEMPSENSE0 TEMPSENSE[7:0] 0x21 TEMPSENSE1 TEMPSENSE[7:0] 0x22 OSC16ERR3V OSC16ERR3V[7:0] 0x23 OSC16ERR5V OSC16ERR5V[7:0] 0x24 OSC20ERR3V OSC20ERR3V[7:0] 0x25 OSC20ERR5V OSC20ERR5V[7:0] 5.7.2 Signature Row Description Datasheet Preliminary DS40002015A-page 21 © 2018 Microchip Technology Inc.
  • Page 22 This can be used to identify a device and hence, the available features by software. The Device ID consists of three bytes: SIGROW.DEVICEID[2:0]. DEVICEID[7:0] Access Reset Bits 7:0 – DEVICEID[7:0] Byte n of the Device ID Datasheet Preliminary DS40002015A-page 22 © 2018 Microchip Technology Inc.
  • Page 23 Each device has an individual serial number, representing a unique ID. This can be used to identify a specific device in the field. The serial number consists of ten bytes: SIGROW.SERNUM[9:0]. SERNUM[7:0] Access Reset Bits 7:0 – SERNUM[7:0] Serial Number Byte n Datasheet Preliminary DS40002015A-page 23 © 2018 Microchip Technology Inc.
  • Page 24 (signed). TEMPSENSE[7:0] Access Reset Bits 7:0 – TEMPSENSE[7:0] Temperature Sensor Calibration Byte n Refer to the ADC chapter for a description on how to use this register. Datasheet Preliminary DS40002015A-page 24 © 2018 Microchip Technology Inc.
  • Page 25 OSC16ERR3V[7:0] Access Reset Bits 7:0 – OSC16ERR3V[7:0] OSC16 Error at 3V These registers contain the signed oscillator frequency error value when running at internal 16 MHz at 3V, as measured during production. Datasheet Preliminary DS40002015A-page 25 © 2018 Microchip Technology Inc.
  • Page 26 OSC16ERR5V[7:0] Access Reset Bits 7:0 – OSC16ERR5V[7:0] OSC16 Error at 5V These registers contain the signed oscillator frequency error value when running at internal 16 MHz at 5V, as measured during production. Datasheet Preliminary DS40002015A-page 26 © 2018 Microchip Technology Inc.
  • Page 27 OSC20ERR3V[7:0] Access Reset Bits 7:0 – OSC20ERR3V[7:0] OSC20 Error at 3V These registers contain the signed oscillator frequency error value when running at internal 20 MHz at 3V, as measured during production. Datasheet Preliminary DS40002015A-page 27 © 2018 Microchip Technology Inc.
  • Page 28: Fuses (Fuse)

    The fuses are pre-programmed but can be altered by the user. Altered values in the configuration fuse will be effective only after a Reset. Note:  When writing the fuses write all reserved bits to ‘1’. Datasheet Preliminary DS40002015A-page 28 © 2018 Microchip Technology Inc.
  • Page 29 ACTIVE[1:0] SLEEP[1:0] 0x02 OSCCFG OSCLOCK FREQSEL[1:0] 0x03 Reserved 0x04 0x05 SYSCFG0 CRCSRC[1:0] RSTPINCFG EESAVE 0x06 SYSCFG1 SUT[2:0] 0x07 APPEND APPEND[7:0] 0x08 BOOTEND BOOTEND[7:0] 0x09 Reserved 0x0A LOCKBIT LOCKBIT[7:0] 5.8.2 Fuse Description Datasheet Preliminary DS40002015A-page 29 © 2018 Microchip Technology Inc.
  • Page 30 This value is loaded into the WINDOW bit field of the Watchdog Control A register (WDT.CTRLA) during Reset. Bits 3:0 – PERIOD[3:0] Watchdog Time-out Period This value is loaded into the PERIOD bit field of the Watchdog Control A register (WDT.CTRLA) during Reset. Datasheet Preliminary DS40002015A-page 30 © 2018 Microchip Technology Inc.
  • Page 31 Enabled with wake-up halted until BOD is ready Bits 1:0 – SLEEP[1:0] BOD Operation Mode in Sleep This value is loaded into the SLEEP bit field of the BOD Control A register (BOD.CTRLA) during Reset. Value Description Disabled Enabled Datasheet Preliminary DS40002015A-page 31 © 2018 Microchip Technology Inc.
  • Page 32 ® megaAVR 0-Series Memories Value Description Sampled Reserved Datasheet Preliminary DS40002015A-page 32 © 2018 Microchip Technology Inc.
  • Page 33 These bits select the operation frequency of the 20 MHz internal oscillator (OSC20M) and determine the respective factory calibration values to be written to CAL20M in CLKCTRL.OSC20MCALIBA and TEMPCAL20M in CLKCTRL.OSC20MCALIBB. Value Description Reserved Run at 16 MHz Run at 20 MHz Reserved Datasheet Preliminary DS40002015A-page 33 © 2018 Microchip Technology Inc.
  • Page 34 If the device is locked the EEPROM is always erased by a chip erase, regardless of this bit. Value Description EEPROM erased during chip erase EEPROM not erased under chip erase Datasheet Preliminary DS40002015A-page 34 © 2018 Microchip Technology Inc.
  • Page 35 Bits 2:0 – SUT[2:0] Start-Up Time Setting These bits select the start-up time between power-on and code execution. Value Description 0 ms 1 ms 2 ms 4 ms 8 ms 16 ms 32 ms 64 ms Datasheet Preliminary DS40002015A-page 35 © 2018 Microchip Technology Inc.
  • Page 36 A value of 0x00 defines the Flash from BOOTEND*256 to end of Flash as application code. When both FUSE.APPEND and FUSE.BOOTEND are 0x00, the entire Flash is BOOT section. Datasheet Preliminary DS40002015A-page 36 © 2018 Microchip Technology Inc.
  • Page 37 These bits set the end of the boot section in blocks of 256 bytes. A value of 0x00 defines the whole Flash as BOOT section. When both FUSE.APPEND and FUSE.BOOTEND are 0x00, the entire Flash is BOOT section. Datasheet Preliminary DS40002015A-page 37 © 2018 Microchip Technology Inc.
  • Page 38: Memory Section Access From Cpu And Updi On Locked Device

    The device is locked by writing any non-valid value to the LOCKBIT bit field in FUSE.LOCKBIT. Table 5-5. Memory Access in Unlocked Mode (FUSE.LOCKBIT Valid) Memory Section CPU Access UPDI Access Read Write Read Write SRAM Registers Flash EEPROM USERROW SIGROW Other Fuses Datasheet Preliminary DS40002015A-page 38 © 2018 Microchip Technology Inc.
  • Page 39: I/O Memory

    General Purpose I/O Registers The ATmega3208/3209/4808/4809 devices provide four General Purpose I/O Registers. These registers can be used for storing any information, and they are particularly useful for storing global variables and Datasheet Preliminary DS40002015A-page 39 © 2018 Microchip Technology Inc.
  • Page 40 ® megaAVR 0-Series Memories interrupt flags. General Purpose I/O Registers, which reside in the address range 0x1C - 0x1F, are directly bit-accessible using the SBI, CBI, SBIS, and SBIC instructions. Datasheet Preliminary DS40002015A-page 40 © 2018 Microchip Technology Inc.
  • Page 41 ® megaAVR 0-Series Memories 5.10.1 Register Summary - GPIOR Offset Name Bit Pos. 0x00 GPIOR0 GPIOR[7:0] 0x01 GPIOR1 GPIOR[7:0] 0x02 GPIOR2 GPIOR[7:0] 0x03 GPIOR3 GPIOR[7:0] 5.10.2 Register Description - GPIOR Datasheet Preliminary DS40002015A-page 41 © 2018 Microchip Technology Inc.
  • Page 42 These are general purpose registers that can be used to store data, such as global variables and flags, in the bit accessible I/O memory space. GPIOR[7:0] Access Reset Bits 7:0 – GPIOR[7:0] GPIO Register byte Datasheet Preliminary DS40002015A-page 42 © 2018 Microchip Technology Inc.
  • Page 43: Peripherals And Architecture

    Controller 0x0060 CLKCTRL Clock Controller X 0x0080 Brown-Out Detector 0x00A0 VREF Voltage Reference 0x0100 Watchdog Timer 0x0110 CPUINT Interrupt Controller 0x0120 CRCSCAN Cyclic Redundancy Check Memory Scan 0x0140 Real Time Counter Datasheet Preliminary DS40002015A-page 43 © 2018 Microchip Technology Inc.
  • Page 44 Comparator 0 0x0800 USART0 Universal Synchronous Asynchronous Receiver Transmitter 0 0x0820 USART1 Universal Synchronous Asynchronous Receiver Transmitter 1 0x0840 USART2 Universal Synchronous Asynchronous Receiver Transmitter 2 0x0860 USART3 Universal Synchronous Asynchronous Datasheet Preliminary DS40002015A-page 44 © 2018 Microchip Technology Inc.
  • Page 45: Interrupt Vector Mapping

    Description' of the respective peripheral for more details on the available interrupt sources. When the interrupt condition occurs, an Interrupt Flag is set in the Interrupt Flags register of the peripheral (peripheral.INTFLAGS). Datasheet Preliminary DS40002015A-page 45 © 2018 Microchip Technology Inc.
  • Page 46 USART0 - Data Register Empty 0x13 0x26 USART0 - Transmit Complete 0x14 0x28 PORTD - External interrupt 0x15 0x2A AC0 – Compare 0x16 0x2C ADC0 – Result Ready 0x17 0x2E ADC0 - Window Compare Datasheet Preliminary DS40002015A-page 46 © 2018 Microchip Technology Inc.
  • Page 47: System Configuration (Syscfg)

    System Configuration (SYSCFG) The system configuration contains the revision ID of the part. The revision ID is readable from the CPU, making it useful for implementing application changes between part revisions. Datasheet Preliminary DS40002015A-page 47 © 2018 Microchip Technology Inc.
  • Page 48 ® megaAVR 0-Series Peripherals and Architecture 6.3.1 Register Summary - SYSCFG Offset Name Bit Pos. 0x01 REVID REVID[7:0] 6.3.2 Register Description - SYSCFG Datasheet Preliminary DS40002015A-page 48 © 2018 Microchip Technology Inc.
  • Page 49 This register is read-only and displays the device revision ID. REVID[7:0] Access Reset Bits 7:0 – REVID[7:0] Revision ID These bits contain the device revision. 0x00 = A, 0x01 = B, and so on. Datasheet Preliminary DS40002015A-page 49 © 2018 Microchip Technology Inc.
  • Page 50: Avr Cpu

    Instructions in the program memory are executed with single-level pipelining. While one instruction is being executed, the next instruction is pre-fetched from the program memory. This enables instructions to be executed on every clock cycle. Datasheet Preliminary DS40002015A-page 50 © 2018 Microchip Technology Inc.
  • Page 51 This allows single-cycle arithmetic logic unit operation between registers or between a register and an immediate operand. Six of the 32 registers can be used Datasheet Preliminary DS40002015A-page 51 © 2018 Microchip Technology Inc.
  • Page 52: Arithmetic Logic Unit (Alu)

    Harvard architecture and the fast-access register file concept. This is the basic pipelining concept enabling up to 1 MIPS/MHz performance with high efficiency. Datasheet Preliminary DS40002015A-page 52 © 2018 Microchip Technology Inc.
  • Page 53 0x0006 is saved on the stack as 0x0003 (shifted one bit to the right), pointing to the fourth 16- bit instruction word in the program memory. The return address is popped off the stack with RETI (when Datasheet Preliminary DS40002015A-page 53 © 2018 Microchip Technology Inc.
  • Page 54 (ICALL and IJMP ) also use the Z-register. Refer to the instruction set or Instruction Set Summary for more information about how the X-, Y-, and Z- registers are used. Datasheet Preliminary DS40002015A-page 54 © 2018 Microchip Technology Inc.
  • Page 55 There are two modes of operation: one for protected I/O registers, and one for the protected self- programming. 7.5.7.1 Sequence for Write Operation to Configuration Change Protected I/O Registers In order to write to registers protected by CCP, these steps are required: Datasheet Preliminary DS40002015A-page 55 © 2018 Microchip Technology Inc.
  • Page 56 CCP period will set the corresponding interrupt flag as normal, and the request is kept pending. After the CCP period is completed, any pending interrupts are executed according to their level and priority. Datasheet Preliminary DS40002015A-page 56 © 2018 Microchip Technology Inc.
  • Page 57: Register Summary - Cpu

    ® megaAVR 0-Series AVR CPU Register Summary - CPU Offset Name Bit Pos. 0x04 CCP[7:0] 0x05 Reserved 0x0C SP[7:0] 0x0D 15:8 SP[15:8] 0x0F SREG Register Description Datasheet Preliminary DS40002015A-page 57 © 2018 Microchip Technology Inc.
  • Page 58 When the protected self-programming signature is written, CCP[1] will read as '1' as long as the CCP feature is enabled. CCP[7:2] will always read as zero. Value Name Description 0x9D Allow Self-Programming 0xD8 IOREG Un-protect protected I/O registers Datasheet Preliminary DS40002015A-page 58 © 2018 Microchip Technology Inc.
  • Page 59 Bits 15:8 – SP[15:8] Stack Pointer High Byte These bits hold the MSB of the 16-bit register. Bits 7:0 – SP[7:0] Stack Pointer Low Byte These bits hold the LSB of the 16-bit register. Datasheet Preliminary DS40002015A-page 59 © 2018 Microchip Technology Inc.
  • Page 60 The negative flag (N) indicates a negative result in an arithmetic or logic operation. Bit 1 – Z Zero Flag The zero flag (Z) indicates a zero result in an arithmetic or logic operation. Datasheet Preliminary DS40002015A-page 60 © 2018 Microchip Technology Inc.
  • Page 61 ® megaAVR 0-Series AVR CPU Bit 0 – C Carry Flag The carry flag (C) indicates a carry in an arithmetic or logic operation. Datasheet Preliminary DS40002015A-page 61 © 2018 Microchip Technology Inc.
  • Page 62: Nonvolatile Memory Controller (Nvmctrl)

    CPU is running the program from the Flash. 8.2.1 Block Diagram Figure 8-1. NVMCTRL Block Diagram NVM Block Program Memory Bus Flash NVMCTRL Data Memory Bus EEPROM Signature Row User Row Datasheet Preliminary DS40002015A-page 62 © 2018 Microchip Technology Inc.
  • Page 63: Functional Description

    Flash is regarded as BOOT section. APPEND should either be set to 0 or a value greater or equal than BOOTEND. Table 8-1. Setting Up Flash Sections BOOTEND APPEND BOOT Section APPCODE Section APPDATA Section 0 to FLASHEND > 0 0 to 256*BOOTEND 256*BOOTEND to FLASHEND Datasheet Preliminary DS40002015A-page 63 © 2018 Microchip Technology Inc.
  • Page 64 EEPROM, and User Row share the same page buffer so only one section can be programmed at a time. The Least Significant bits (LSb) of the address are used to select where in the page buffer the data is Datasheet Preliminary DS40002015A-page 64 © 2018 Microchip Technology Inc.
  • Page 65 If the write is to the Flash, the CPU will stop executing code as long as the Flash is busy with the write operation. If the write is to the EEPROM, the CPU can continue executing code while the operation is ongoing. Datasheet Preliminary DS40002015A-page 65 © 2018 Microchip Technology Inc.
  • Page 66 CPU and the Flash/EEPROM to operate properly. These issues are the same as for board level systems using Flash/EEPROM, and the same design solutions should be applied. Datasheet Preliminary DS40002015A-page 66 © 2018 Microchip Technology Inc.
  • Page 67 CPU.CCP register first, followed by a write access to the protected bits within four CPU instructions. It is possible to try writing to these registers at any time, but the values are not altered. The following registers are under CCP: Datasheet Preliminary DS40002015A-page 67 © 2018 Microchip Technology Inc.
  • Page 68 ® megaAVR 0-Series Nonvolatile Memory Controller (NVMCTRL) Table 8-3. NVMCTRL - Registers under Configuration Change Protection Register NVMCTRL.CTRLA Datasheet Preliminary DS40002015A-page 68 © 2018 Microchip Technology Inc.
  • Page 69: Register Summary - Nvmctrl

    CTRLA CMD[2:0] 0x01 CTRLB BOOTLOCK APCWP 0x02 STATUS WRERROR EEBUSY FBUSY 0x03 INTCTRL EEREADY 0x04 INTFLAGS EEREADY 0x05 Reserved DATA[7:0] 0x06 DATA 15:8 DATA[15:8] ADDR[7:0] 0x08 ADDR 15:8 ADDR[15:8] Register Description Datasheet Preliminary DS40002015A-page 69 © 2018 Microchip Technology Inc.
  • Page 70 ERWP Erase and write page (NVMCTRL.ADDR selects which memory) Page buffer clear CHER Chip erase: erase Flash and EEPROM (unless EESAVE in FUSE.SYSCFG is '1') EEER EEPROM Erase Write fuse (only accessible through UPDI) Datasheet Preliminary DS40002015A-page 70 © 2018 Microchip Technology Inc.
  • Page 71 Bit 0 – APCWP Application Code Section Write Protection Writing a ’1’ to this bit protects the application code section from further writes. This bit can only be written to ’1’. It is cleared to ’0’ only by Reset. Datasheet Preliminary DS40002015A-page 71 © 2018 Microchip Technology Inc.
  • Page 72 This bit will read '1' when the EEPROM is busy with a command. Bit 0 – FBUSY Flash Busy This bit will read '1' when the Flash is busy with a command. Datasheet Preliminary DS40002015A-page 72 © 2018 Microchip Technology Inc.
  • Page 73 Thus, the interrupt should not be enabled before triggering an NVM command, as the EEREADY flag will not be set before the NVM command issued. The interrupt should be disabled in the interrupt handler. Datasheet Preliminary DS40002015A-page 73 © 2018 Microchip Technology Inc.
  • Page 74 Access Reset Bit 0 – EEREADY EEREADY Interrupt Flag This flag is set continuously as long as the EEPROM is not busy. This flag is cleared by writing a '1' to it. Datasheet Preliminary DS40002015A-page 74 © 2018 Microchip Technology Inc.
  • Page 75 (suffix H) can be accessed at offset + 0x01. DATA[15:8] Access Reset DATA[7:0] Access Reset Bits 15:0 – DATA[15:0] Data Register This register is used by the UPDI for fuse write operations. Datasheet Preliminary DS40002015A-page 75 © 2018 Microchip Technology Inc.
  • Page 76 (suffix H) can be accessed at offset + 0x01. ADDR[15:8] Access Reset ADDR[7:0] Access Reset Bits 15:0 – ADDR[15:0] Address The Address register contains the address to the last memory location that has been updated. Datasheet Preliminary DS40002015A-page 76 © 2018 Microchip Technology Inc.
  • Page 77: Clock Controller (Clkctrl)

    The Main Clock (CLK_MAIN) is used by the CPU, RAM, and the I/O bus. The main clock source can be selected and prescaled. Some peripherals can share the same clock source as the main clock, or run asynchronously to the main clock domain. Datasheet Preliminary DS40002015A-page 77 © 2018 Microchip Technology Inc.
  • Page 78 CLK_RTC is used by the RTC/PIT. It will be requested when the RTC/PIT is enabled. The clock source for CLK_RTC should only be changed if the peripheral is disabled. – CLK_WDT is used by the WDT. It will be requested when the WDT is enabled. Datasheet Preliminary DS40002015A-page 78 © 2018 Microchip Technology Inc.
  • Page 79: Functional Description

    System Reset. CLK_MAIN is fed into a prescaler before it is used by the peripherals (CLK_PER) in the device. The prescaler divide CLK_MAIN by a factor from 1 to 64. Datasheet Preliminary DS40002015A-page 79 © 2018 Microchip Technology Inc.
  • Page 80 The calibration bits are protected by the Configuration Change Protection Mechanism, requiring a timed write procedure for changing the main clock and prescaler settings. Refer to the Electrical Characteristics section for the start-up time. Datasheet Preliminary DS40002015A-page 80 © 2018 Microchip Technology Inc.
  • Page 81 The TOSC1 and TOSC2 pins are dedicated to driving a 32.768 kHz Crystal Oscillator (XOSC32K). • Instead of a crystal oscillator, TOSC1 can be configured to accept an external clock source. Datasheet Preliminary DS40002015A-page 81 © 2018 Microchip Technology Inc.
  • Page 82 The following registers are under CCP: Table 9-1. CLKCTRL - Registers Under Configuration Change Protection Register CLKCTRL.MCLKCTRLB IOREG CLKCTRL.MCLKLOCK IOREG CLKCTRL.XOSC32KCTRLA IOREG CLKCTRL.MCLKCTRLA IOREG CLKCTRL.OSC20MCTRLA IOREG CLKCTRL.OSC20MCALIBA IOREG CLKCTRL.OSC20MCALIBB IOREG CLKCTRL.OSC32KCTRLA IOREG Datasheet Preliminary DS40002015A-page 82 © 2018 Microchip Technology Inc.
  • Page 83: Register Summary - Clkctrl

    OSC32KS OSC20MS SOSC 0x04 Reserved 0x0F 0x10 OSC20MCTRLA RUNSTDBY 0x11 Reserved 0x12 OSC20MCALIBB LOCK TEMPCAL20M[3:0] 0x13 Reserved 0x17 0x18 OSC32KCTRLA RUNSTDBY 0x19 Reserved 0x1B 0x1C XOSC32KCTRLA CSUT[1:0] RUNSTDBY ENABLE Register Description Datasheet Preliminary DS40002015A-page 83 © 2018 Microchip Technology Inc.
  • Page 84 This bit field selects the source for the Main Clock (CLK_MAIN). Value Name Description OSC20M 20 MHz internal oscillator OSCULP32K 32 KHz internal ultra low-power oscillator XOSC32K 32.768 kHz external crystal oscillator EXTCLK External clock Datasheet Preliminary DS40002015A-page 84 © 2018 Microchip Technology Inc.
  • Page 85 This bit must be written '1' to enable the prescaler. When enabled, the division ratio is selected by the PDIV bit field. When this bit is written to '0', the main clock will pass through undivided (CLK_PER=CLK_MAIN), regardless of the value of PDIV. Datasheet Preliminary DS40002015A-page 85 © 2018 Microchip Technology Inc.
  • Page 86 This provides protection for the CLKCTRL.MCLKCTRLA and CLKCTRL.MCLKCTRLB registers and calibration settings for the main clock source from unintentional modification by software. At Reset, the LOCKEN bit is loaded based on the OSCLOCK bit in FUSE.OSCCFG. Datasheet Preliminary DS40002015A-page 86 © 2018 Microchip Technology Inc.
  • Page 87 Description The clock source for CLK_MAIN is not undergoing a switch The clock source for CLK_MAIN is undergoing a switch and will change as soon as the new source is stable Datasheet Preliminary DS40002015A-page 87 © 2018 Microchip Technology Inc.
  • Page 88 When not requested by peripherals, no oscillator output is provided. It takes four oscillator cycles to open the clock gate after a request but the oscillator analog start-up time will be removed when this bit is set. Datasheet Preliminary DS40002015A-page 88 © 2018 Microchip Technology Inc.
  • Page 89 Bits 3:0 – TEMPCAL20M[3:0] Oscillator Temperature Coefficient Calibration These bits tune the slope of the temperature compensation. At Reset, the factory calibrated values are loaded based on the FREQSEL bits in FUSE.OSCCFG. Datasheet Preliminary DS40002015A-page 89 © 2018 Microchip Technology Inc.
  • Page 90 When not requested by peripherals, no oscillator output is provided. It takes four oscillator cycles to open the clock gate after a request but the oscillator analog start-up time will be removed when this bit is set. Datasheet Preliminary DS40002015A-page 90 © 2018 Microchip Technology Inc.
  • Page 91 According to RUNSTBY bit, the oscillator will be turned ON all the time if the device is in Active, Idle, or Standby Sleep mode, or only be enabled when requested. This bit is I/O protected to prevent unintentional enabling of the oscillator. Datasheet Preliminary DS40002015A-page 91 © 2018 Microchip Technology Inc.
  • Page 92 When this bit is written to '1', the configuration of the respective input pins is overridden to TOSC1 and TOSC2. Also, the Source Select bit (SEL) and Crystal Start-Up Time (CSUT) become read-only. This bit is I/O protected to prevent unintentional enabling of the oscillator. Datasheet Preliminary DS40002015A-page 92 © 2018 Microchip Technology Inc.
  • Page 93: Sleep Controller (Slpctrl)

    The content of the register file, SRAM and registers are kept during sleep. If a Reset occurs during sleep, the device will reset, start, and execute from the Reset vector. 10.2.1 Block Diagram Figure 10-1. Sleep Controller in System SLEEP Instruction Interrupt Request SLPCTRL Sleep State Interrupt Request Peripheral Datasheet Preliminary DS40002015A-page 93 © 2018 Microchip Technology Inc.
  • Page 94: Functional Description

    Table 10-1. Sleep Mode Activity Overview Group Peripheral Active in Sleep Mode Clock Idle Standby Power-Down Active Clock CLK_CPU Domain Peripherals CLK_PER CLK_RTC CLK_PER ADCn CLK_PER TCBn CLK_PER PIT (RTC) CLK_RTC BOD (VLM) CLK_BOD CLK_WDT Datasheet Preliminary DS40002015A-page 94 © 2018 Microchip Technology Inc.
  • Page 95 IDLE 6 CLK Standby 6 CLK + OSC start-up Power-Down 6 CLK + OSC start-up The start-up time for the different clock sources is described in the Clock Controller (CLKCTRL) section. Datasheet Preliminary DS40002015A-page 95 © 2018 Microchip Technology Inc.
  • Page 96 SLPCTRL will go to Active mode, even if there are no pending interrupt requests. If the peripheral is configured to require periodical service by the CPU through interrupts or similar, improper operation or data loss may result during halted debugging. Datasheet Preliminary DS40002015A-page 96 © 2018 Microchip Technology Inc.
  • Page 97: Register Summary - Slpctrl

    ® megaAVR 0-Series Sleep Controller (SLPCTRL) 10.4 Register Summary - SLPCTRL Offset Name Bit Pos. 0x00 CTRLA SMODE[1:0] 10.5 Register Description Datasheet Preliminary DS40002015A-page 97 © 2018 Microchip Technology Inc.
  • Page 98 Power-Down Sleep mode enabled other Reserved Bit 0 – SEN Sleep Enable This bit must be written to '1' before the SLEEP instruction is executed to make the MCU enter the selected sleep mode. Datasheet Preliminary DS40002015A-page 98 © 2018 Microchip Technology Inc.
  • Page 99: Reset Controller (Rstctrl)

    Figure 11-1. Reset System Overview RESET SOURCES RESET CONTROLLER Pull-up Resistor UPDI FILTER External Reset RESET All other Peripherals UPDI CPU (SW) 11.2.2 Signal Description Signal Description Type RESET External Reset (active-low) Digital input Datasheet Preliminary DS40002015A-page 99 © 2018 Microchip Technology Inc.
  • Page 100: Functional Description

    The Watchdog Timer (WDT) is a system function for monitoring correct program operation. If the WDT is not reset from software according to the programmed time-out period, a Watchdog Reset will be issued. See the WDT documentation for further details. Datasheet Preliminary DS40002015A-page 100 © 2018 Microchip Technology Inc.
  • Page 101 It is possible to try writing to these registers at any time, but the values are not altered. The following registers are under CCP: Table 11-2. RSTCTRL - Registers Under Configuration Change Protection Register RSTCTRL.SWRR IOREG Datasheet Preliminary DS40002015A-page 101 © 2018 Microchip Technology Inc.
  • Page 102: Register Summary - Rstctrl

    ® megaAVR 0-Series Reset Controller (RSTCTRL) 11.4 Register Summary - RSTCTRL Offset Name Bit Pos. 0x00 RSTFR UPDIRF SWRF WDRF EXTRF BORF PORF 0x01 SWRR SWRE 11.5 Register Description Datasheet Preliminary DS40002015A-page 102 © 2018 Microchip Technology Inc.
  • Page 103 After a POR, only the POR flag is set and all the other flags are cleared. No other flags can be set before a full system boot is run after the POR. Datasheet Preliminary DS40002015A-page 103 © 2018 Microchip Technology Inc.
  • Page 104 Property:  Configuration Change Protection SWRE Access Reset Bit 0 – SWRE Software Reset Enable When this bit is written to '1', a software reset will occur. This bit will always read as '0'. Datasheet Preliminary DS40002015A-page 104 © 2018 Microchip Technology Inc.
  • Page 105: Cpu Interrupt Controller (Cpuint)

    Interrupt generation must be globally enabled by writing a '1' to the Global Interrupt Enable bit (I) in the CPU Status register (CPU.SREG). This bit is not cleared when an interrupt is acknowledged. Datasheet Preliminary DS40002015A-page 105 © 2018 Microchip Technology Inc.
  • Page 106: Functional Description

    The Interrupt vector placement is dependent on the value of Interrupt Vector Select bit (IVSEL) in the Control A register (CPUINT.CTRLA). Refer to the IVSEL description in CPUINT.CTRLA for the possible locations. Datasheet Preliminary DS40002015A-page 106 © 2018 Microchip Technology Inc.
  • Page 107 A return from an interrupt handling routine takes four to five clock cycles, depending on the size of the Program Counter. During these clock cycles, the Program Counter is popped from the stack and the Stack Pointer is incremented. Datasheet Preliminary DS40002015A-page 107 © 2018 Microchip Technology Inc.
  • Page 108 When returning from the high priority interrupt handler, the execution of the normal priority interrupt handler will resume. Datasheet Preliminary DS40002015A-page 108 © 2018 Microchip Technology Inc.
  • Page 109 Y+1 has the highest priority. Note that in this case, the priorities will "wrap" so that IVEC0 has lower priority than IVECn. Refer to the Interrupt Vector Mapping of the device for available interrupt requests and their interrupt vector number. Datasheet Preliminary DS40002015A-page 109 © 2018 Microchip Technology Inc.
  • Page 110 IVEC Y+1 was the last interrupt to be acknowledged. Round robin scheduling for LVL0 interrupt requests is enabled by writing a ‘1’ to the Round Robin Priority Enable bit (LVL0RR) in the Control A register (CPUINT.CTRLA). Datasheet Preliminary DS40002015A-page 110 © 2018 Microchip Technology Inc.
  • Page 111 It is possible to try writing to these registers at any time, but the values are not altered. The following registers are under CCP: Table 12-2. INTCTRL - Registers under Configuration Change Protection Register IVSEL in CPUINT.CTRLA IOREG CVT in CPUINT.CTRLA IOREG Datasheet Preliminary DS40002015A-page 111 © 2018 Microchip Technology Inc.
  • Page 112: Register Summary - Cpuint

    CPU Interrupt Controller (CPUINT) 12.4 Register Summary - CPUINT Offset Name Bit Pos. 0x00 CTRLA IVSEL LVL0RR 0x01 STATUS NMIEX LVL1EX LVL0EX 0x02 LVL0PRI LVL0PRI[7:0] 0x03 LVL1VEC LVL1VEC[7:0] 12.5 Register Description Datasheet Preliminary DS40002015A-page 112 © 2018 Microchip Technology Inc.
  • Page 113 Description Priority is fixed for priority level 0 interrupt requests: The lowest interrupt vector address has the highest priority. Round Robin priority scheme is enabled for priority level 0 interrupt requests. Datasheet Preliminary DS40002015A-page 113 © 2018 Microchip Technology Inc.
  • Page 114 This flag is set when a priority level 0 interrupt is executing, or when the interrupt handler has been interrupted by a priority level 1 interrupt or an NMI. The flag is cleared when returning (RETI) from the interrupt handler. Datasheet Preliminary DS40002015A-page 114 © 2018 Microchip Technology Inc.
  • Page 115 LVL0PRI[7:0] Access Reset Bits 7:0 – LVL0PRI[7:0] Interrupt Priority Level 0 This register is used to modify the priority of the LVL0 interrupts. See Scheduling of Normal Priority Interrupts for more information. Datasheet Preliminary DS40002015A-page 115 © 2018 Microchip Technology Inc.
  • Page 116 This bit field contains the address of the single vector with increased priority level 1 (LVL1). If this bit field has the value 0x00, no vector has LVL1. Consequently, the LVL1 interrupt is disabled. Datasheet Preliminary DS40002015A-page 116 © 2018 Microchip Technology Inc.
  • Page 117: Event System (Evsys)

    The Event System can directly connect peripherals such as ADCs, analog comparators, I/O port pins, the real-time counter, timer/counters, and the configurable custom logic peripheral. Events can also be generated from software. Datasheet Preliminary DS40002015A-page 117 © 2018 Microchip Technology Inc.
  • Page 118 Figure 13-2. Example of Event Source, Generator, User, and Action Event Generator Event User Timer/Counter Compare Match Channel Sweep Event Routing Over-/Underflow Single Network Conversion Error Event Action Selection Event Source Event Action Datasheet Preliminary DS40002015A-page 118 © 2018 Microchip Technology Inc.
  • Page 119: Functional Description

    Generator Event Generating Length of event Constraints for Clock Domain synchronous user SYNC character CLK_PDI Waveform: SYNC char Synchronizing clock in on PDI RX input user must be fast enough Datasheet Preliminary DS40002015A-page 119 © 2018 Microchip Technology Inc.
  • Page 120 0 Compare match CLK_PER Pulse: 1 * CLK_PER ch 1 Compare match CLK_PER Pulse: 1 * CLK_PER ch 2 Compare match, CLK_PER Pulse: ≥1 * CLK_PER None timeout or when counting Datasheet Preliminary DS40002015A-page 120 © 2018 Microchip Technology Inc.
  • Page 121 Synchronization will delay the event by two system cycles. The event system automatically performs this synchronization if an asynchronous generator is selected for an event channel, no explicit configuration is needed. Datasheet Preliminary DS40002015A-page 121 © 2018 Microchip Technology Inc.
  • Page 122 Such generators will only work in Idle sleep mode or in Standby sleep mode if configured to run in Standby mode by setting the RUNSTBY bit in the appropriate register. 13.3.4 Debug Operation This peripheral is unaffected by entering Debug mode. Datasheet Preliminary DS40002015A-page 122 © 2018 Microchip Technology Inc.
  • Page 123: Register Summary - Evsys

    CHANNEL[7:0] 0x2F USER15 CHANNEL[7:0] 0x30 USER16 CHANNEL[7:0] 0x31 USER17 CHANNEL[7:0] 0x32 USER18 CHANNEL[7:0] 0x33 USER19 CHANNEL[7:0] 0x34 USER20 CHANNEL[7:0] 0x35 USER21 CHANNEL[7:0] 0x36 USER22 CHANNEL[7:0] 0x37 USER23 CHANNEL[7:0] 13.5 Register Description Datasheet Preliminary DS40002015A-page 123 © 2018 Microchip Technology Inc.
  • Page 124 Access Reset Bits 7:0 – STROBE[7:0] Channel Strobe If the strobe register location is written, each Event channel will be inverted for one system clock cycle, i.e. a single Event is generated. Datasheet Preliminary DS40002015A-page 124 © 2018 Microchip Technology Inc.
  • Page 125 Access Reset Bits 7:0 – STROBE[7:0] Channel Strobe If the strobe register location is written, each Event channel will be inverted for one system clock cycle, i.e. a single Event is generated. Datasheet Preliminary DS40002015A-page 125 © 2018 Microchip Technology Inc.
  • Page 126 0x68 SPI0 Sync 1000_0000 0x80 TCA0_OVF Sync 1000_0001 0x81 TCA0_ERR Sync 1000_0100 0x84 TCA0_CMP0 Sync CMP0 1000_0101 0x85 TCA0_CMP1 Sync CMP1 1000_0110 0x86 TCA0_CMP2 Sync CMP2 1010_nnn0 0xA0-0xAE TCBn Sync CMP0 Datasheet Preliminary DS40002015A-page 126 © 2018 Microchip Technology Inc.
  • Page 127 USART2 Event in USART3 Sync USART3 Event in Sync TCA Event in TCB0 Async TCB0 Event in TCB1 Async TCB1 Event in TCB2 Async TCB2 Event in TCB3 Async TCB3 Event in Datasheet Preliminary DS40002015A-page 127 © 2018 Microchip Technology Inc.
  • Page 128 Bits 7:0 – CHANNEL[7:0] User Channel Selection Describes which event system channel the user is connected to. Value Description OFF, no channel is connected to this event system user Event user is connected to CHANNEL(n-1) Datasheet Preliminary DS40002015A-page 128 © 2018 Microchip Technology Inc.
  • Page 129: Port Multiplexer (Portmux)

    Available options are described in detail in the PORTMUX register map and depend on the actual pin and its properties. For available pins and functionalities, refer to the “I/O Multiplexing and Considerations” chapter in the Device Data Sheet. Datasheet Preliminary DS40002015A-page 129 © 2018 Microchip Technology Inc.
  • Page 130: Register Summary - Portmux

    EVOUTC EVOUTB EVOUTA 0x01 CCLROUTEA LUT3 LUT2 LUT1 LUT0 0x02 USARTROUTEA USART3[1:0] USART2[1:0] USART1[1:0] USART0[1:0] 0x03 TWISPIROUTEA TWI0[1:0] SPI0[1:0] 0x04 TCAROUTEA TCA0[2:0] 0x05 TCBROUTEA TCB3 TCB2 TCB1 TCB0 14.3 Register Description Datasheet Preliminary DS40002015A-page 130 © 2018 Microchip Technology Inc.
  • Page 131 EVOUTC EVOUTB EVOUTA Access Reset Bits 0, 1, 2, 3, 4, 5 – EVOUT Event Output x Write this bit to '1' to select alternative pin location for Enable Event Output x. Datasheet Preliminary DS40002015A-page 131 © 2018 Microchip Technology Inc.
  • Page 132 Bit 0 – LUT0 CCL LUT 0 output Write this bit to '1' to select alternative pin location for CCL LUT 0. Value Name Description DEFAULT CCL LUT0 on PA[3] ALT1 CCL LUT0 on PA[6] Datasheet Preliminary DS40002015A-page 132 © 2018 Microchip Technology Inc.
  • Page 133 Bits 1:0 – USART0[1:0] USART 0 communication Write these bits to select alternative communication pins for USART 0. Value Name Description DEFAULT USART0 on PA[3:0] ALT1 USART0 on PA[7:4] Reserved NONE Not connected to any pins Datasheet Preliminary DS40002015A-page 133 © 2018 Microchip Technology Inc.
  • Page 134 Write these bits to select alternative communication pins for SPI 0. Value Name Description DEFAULT SPI on PA[7:4] ALT1 SPI on PC[3:0] ALT2 SPI on PE[3:0] NONE Not connected to any pins Datasheet Preliminary DS40002015A-page 134 © 2018 Microchip Technology Inc.
  • Page 135 TCA0 pins on PA[5:0] PORTB TCA0 pins on PB[5:0] PORTC TCA0 pins on PC[5:0] PORTD TCA0 pins on PD[5:0] PORTE TCA0 pins on PE[5:0] PORTF TCA0 pins on PF[5:0] Other Reserved Datasheet Preliminary DS40002015A-page 135 © 2018 Microchip Technology Inc.
  • Page 136 Bit 0 – TCB0 TCB0 output Write this bit to '1' to select alternative output pin for 16-bit timer/counter B 0. Value Name Description DEFAULT TCB0 on PA2 ALT1 TCB0 on PF4 Datasheet Preliminary DS40002015A-page 136 © 2018 Microchip Technology Inc.
  • Page 137: I/O Pin Configuration (Port)

    The direction of one port pin can be changed without unintentionally changing the direction of any other pin. The PORT pin configuration also controls input and output selection of other device functions. Datasheet Preliminary DS40002015A-page 137 © 2018 Microchip Technology Inc.
  • Page 138: Functional Description

    Functional Description 15.3.1 Initialization After Reset, all standard function device I/O pads are connected to the port with outputs tri-stated and input buffers enabled, even if there is no clock running. Datasheet Preliminary DS40002015A-page 138 © 2018 Microchip Technology Inc.
  • Page 139 If the interrupt setting is changed while synchronizing an interrupt, that interrupt may not be accepted. • Only a few pins support full asynchronous interrupt detection, see I/O Multiplexing and Considerations. These limitations apply for waking the system from sleep: Datasheet Preliminary DS40002015A-page 139 © 2018 Microchip Technology Inc.
  • Page 140 An interrupt request is generated when the corresponding interrupt source is enabled and the Interrupt Flag is set. The interrupt request remains active until the Interrupt Flag is cleared. See the peripheral's INTFLAGS register for details on how to clear Interrupt Flags. Datasheet Preliminary DS40002015A-page 140 © 2018 Microchip Technology Inc.
  • Page 141 Peripherals connected to the Ports can be affected by sleep modes, described in the respective peripherals' documentation. The PORT peripheral will always use the Main Clock. Input synchronization will halt when this clock stops. Datasheet Preliminary DS40002015A-page 141 © 2018 Microchip Technology Inc.
  • Page 142: Register Summary - Portx

    ISC[2:0] 0x13 PIN3CTRL INVEN PULLUPEN ISC[2:0] 0x14 PIN4CTRL INVEN PULLUPEN ISC[2:0] 0x15 PIN5CTRL INVEN PULLUPEN ISC[2:0] 0x16 PIN6CTRL INVEN PULLUPEN ISC[2:0] 0x17 PIN7CTRL INVEN PULLUPEN ISC[2:0] 15.5 Register Description - Ports Datasheet Preliminary DS40002015A-page 142 © 2018 Microchip Technology Inc.
  • Page 143 Writing a ‘0’ to PORTx.DIR[n] configures pin n as an input-only pin. Its properties can be configured by writing to the ISC bit in PORTx.PINnCTRL. PORTx.DIRn controls only the output enable. Setting PORTx.DIR[n] to ‘1’ does not disable the pin input. Datasheet Preliminary DS40002015A-page 143 © 2018 Microchip Technology Inc.
  • Page 144 This bit field can be used instead of a read-modify-write to set individual pins as output. Writing a '1' to DIRSET[n] will set the corresponding PORTx.DIR[n] bit. Reading this bit field will always return the value of PORTx.DIR. Datasheet Preliminary DS40002015A-page 144 © 2018 Microchip Technology Inc.
  • Page 145 This register can be used instead of a read-modify-write to configure individual pins as input-only. Writing a '1' to DIRCLR[n] will clear the corresponding bit in PORTx.DIR. Reading this bit field will always return the value of PORTx.DIR. Datasheet Preliminary DS40002015A-page 145 © 2018 Microchip Technology Inc.
  • Page 146 This bit field can be used instead of a read-modify-write to toggle the direction of individual pins. Writing a '1' to DIRTGL[n] will toggle the corresponding bit in PORTx.DIR. Reading this bit field will always return the value of PORTx.DIR. Datasheet Preliminary DS40002015A-page 146 © 2018 Microchip Technology Inc.
  • Page 147 If OUT[n] is written to '1', pin n is driven high. If OUT[n] is written to '0', pin n is driven low. In order to have any effect, the pin direction must be configured as output. Datasheet Preliminary DS40002015A-page 147 © 2018 Microchip Technology Inc.
  • Page 148 This bit field can be used instead of a read-modify-write to set the output value of individual pins to '1'. Writing a '1' to OUTSET[n] will set the corresponding bit in PORTx.OUT. Reading this bit field will always return the value of PORTx.OUT. Datasheet Preliminary DS40002015A-page 148 © 2018 Microchip Technology Inc.
  • Page 149 This register can be used instead of a read-modify-write to clear the output value of individual pins to '0'. Writing a '1' to OUTCLR[n] will clear the corresponding bit in PORTx.OUT. Reading this bit field will always return the value of PORTx.OUT. Datasheet Preliminary DS40002015A-page 149 © 2018 Microchip Technology Inc.
  • Page 150 This register can be used instead of a read-modify-write to toggle the output value of individual pins. Writing a '1' to OUTTGL[n] will toggle the corresponding bit in PORTx.OUT. Reading this bit field will always return the value of PORTx.OUT. Datasheet Preliminary DS40002015A-page 150 © 2018 Microchip Technology Inc.
  • Page 151 Port. If the digital input buffers are disabled, the input is not sampled and cannot be read. Writing to a bit of PORTx.IN will toggle the corresponding bit in PORTx.OUT. Datasheet Preliminary DS40002015A-page 151 © 2018 Microchip Technology Inc.
  • Page 152 The INT Flag is set when a pin change/state matches the pin's input sense configuration. Writing a '1' to a flag's bit location will clear the flag. For enabling and executing the interrupt, refer to ISC bit description in PORTx.PINnCTRL. Datasheet Preliminary DS40002015A-page 152 © 2018 Microchip Technology Inc.
  • Page 153 This register contains the slew rate limit enable bit for this port. Access Reset Bit 0 – SRL Slew Rate Limit Enable Writing a '1' to this bit enables slew rate limitation for all pins on this port. Datasheet Preliminary DS40002015A-page 153 © 2018 Microchip Technology Inc.
  • Page 154 Interrupt enabled with sense on rising edge FALLING Interrupt enabled with sense on falling edge INPUT_DISABLE Interrupt and digital input buffer disabled LEVEL Interrupt enabled with sense on low level other Reserved Datasheet Preliminary DS40002015A-page 154 © 2018 Microchip Technology Inc.
  • Page 155: Register Summary - Vportx

    ® megaAVR 0-Series I/O Pin Configuration (PORT) 15.6 Register Summary - VPORTx Offset Name Bit Pos. 0x00 DIR[7:0] 0x01 OUT[7:0] 0x02 IN[7:0] 0x03 INTFLAGS INT[7:0] 15.7 Register Description - Virtual Ports Datasheet Preliminary DS40002015A-page 155 © 2018 Microchip Technology Inc.
  • Page 156 I/O memory space where the regular PORT registers reside. DIR[7:0] Access Reset Bits 7:0 – DIR[7:0] Data Direction This bit field controls output enable for the individual pins of the Port. Datasheet Preliminary DS40002015A-page 156 © 2018 Microchip Technology Inc.
  • Page 157 I/O memory space where the regular PORT registers reside. OUT[7:0] Access Reset Bits 7:0 – OUT[7:0] Output Value This bit field selects the data output value for the individual pins in the Port. Datasheet Preliminary DS40002015A-page 157 © 2018 Microchip Technology Inc.
  • Page 158 Bits 7:0 – IN[7:0] Input Value This bit field holds the value present on the pins if the digital input buffer is enabled. Writing to a bit of VPORTx.IN will toggle the corresponding bit in VPORTx.OUT. Datasheet Preliminary DS40002015A-page 158 © 2018 Microchip Technology Inc.
  • Page 159 Writing a '1' to this flag's bit location will clear the flag. For enabling and executing the interrupt, refer to the ISC bits in PORTx.PINnCTRL. Datasheet Preliminary DS40002015A-page 159 © 2018 Microchip Technology Inc.
  • Page 160: Brown-Out Detector (Bod)

    When activated, the BOD can operate in Enabled mode, where the BOD is continuously active, and in Sampled mode, where the BOD is activated briefly at a given period to check the supply voltage level. Datasheet Preliminary DS40002015A-page 160 © 2018 Microchip Technology Inc.
  • Page 161: Functional Description

    VLM interrupt, the interrupt flag will always be set if VLMCFG equals 0x2 and may be set if VLMCFG is configured to 0x0 or 0x1. The VLM threshold is defined by writing the VLM Level bits (VLMLVL) in the Control A register (BOD.VLMCTRLA). Datasheet Preliminary DS40002015A-page 161 © 2018 Microchip Technology Inc.
  • Page 162 It is possible to try writing to these registers at any time, but the values are not altered. The following registers are under CCP: Table 16-2. Registers Under Configuration Change Protection Register SLEEP in BOD.CTRLA IOREG Datasheet Preliminary DS40002015A-page 162 © 2018 Microchip Technology Inc.
  • Page 163: Register Summary - Bod

    Offset Name Bit Pos. 0x00 CTRLA SAMPFREQ ACTIVE[1:0] SLEEP[1:0] 0x01 CTRLB LVL[2:0] 0x02 Reserved 0x07 0x08 VLMCTRLA VLMLVL[1:0] 0x09 INTCTRL VLMCFG[1:0] VLMIE 0x0A INTFLAGS VLMIF 0x0B STATUS VLMS 16.5 Register Description Datasheet Preliminary DS40002015A-page 163 © 2018 Microchip Technology Inc.
  • Page 164 These bits select the BOD operation mode when the device is in Standby or Power-Down Sleep mode. The Reset value is loaded from the SLEEP bits in FUSE.BODCFG. These bits are under Configuration Change Protection (CCP). Value Description Disabled Enabled Sampled Reserved Datasheet Preliminary DS40002015A-page 164 © 2018 Microchip Technology Inc.
  • Page 165 The Reset value is loaded from the BOD Level bits (LVL) in the BOD Configuration Fuse (FUSE.BODCFG). Value Name Description BODLEVEL0 1.8V BODLEVEL1 2.15V BODLEVEL2 2.60V BODLEVEL3 2.95V BODLEVEL4 3.30V BODLEVEL5 3.70V BODLEVEL6 4.00V BODLEVEL7 4.30V Datasheet Preliminary DS40002015A-page 165 © 2018 Microchip Technology Inc.
  • Page 166 These bits select the VLM threshold relative to the BOD threshold (LVL in BOD.CTRLB). Value Description VLM threshold 5% above BOD threshold VLM threshold 15% above BOD threshold VLM threshold 25% above BOD threshold other Reserved Datasheet Preliminary DS40002015A-page 166 © 2018 Microchip Technology Inc.
  • Page 167 Voltage crosses VLM threshold from below Either direction is triggering an interrupt request Other Reserved Bit 0 – VLMIE VLM Interrupt Enable Writing a '1' to this bit enables the VLM interrupt. Datasheet Preliminary DS40002015A-page 167 © 2018 Microchip Technology Inc.
  • Page 168 This flag is set when a trigger from the VLM is given, as configured by the VLMCFG bit in the BOD.INTCTRL register. The flag is only updated when the BOD is enabled. Datasheet Preliminary DS40002015A-page 168 © 2018 Microchip Technology Inc.
  • Page 169 Bit 0 – VLMS VLM Status This bit is only valid when the BOD is enabled. Value Description The voltage is above the VLM threshold level The voltage is below the VLM threshold level Datasheet Preliminary DS40002015A-page 169 © 2018 Microchip Technology Inc.
  • Page 170: Voltage Reference (Vref)

    VREF.CTRLA) before the respective modules are enabled. The reference buffer is then automatically enabled when requested by a peripheral. Changing the reference while these modules are enabled could lead to unpredictable behavior. Datasheet Preliminary DS40002015A-page 170 © 2018 Microchip Technology Inc.
  • Page 171 Force Enable bits (ADC0REFEN, AC0REFEN) in the Control B register (VREF.CTRLB). This can be used to remove the reference start-up time, at the cost of increased power consumption. Datasheet Preliminary DS40002015A-page 171 © 2018 Microchip Technology Inc.
  • Page 172: Register Summary - Vref

    ® megaAVR 0-Series Voltage Reference (VREF) 17.4 Register Summary - VREF Offset Name Bit Pos. 0x00 CTRLA ADC0REFSEL[2:0] AC0REFSEL[2:0] 0x01 CTRLB ADC0REFEN AC0REFEN 17.5 Register Description Datasheet Preliminary DS40002015A-page 172 © 2018 Microchip Technology Inc.
  • Page 173 2.5V 4.3V 1.5V Other Reserved Bits 2:0 – AC0REFSEL[2:0] AC0 Reference Select These bits select reference voltage for AC0. Value Name Description 0V55 0.55V 1.1V 2.5V 4.3V 1.5V Reserved Reserved AVDD AVDD Datasheet Preliminary DS40002015A-page 173 © 2018 Microchip Technology Inc.
  • Page 174 Writing a '1' to this bit forces the voltage reference for AC0 DACREF to be enabled, even if it is not requested. Writing a '0' to this bit allows to automatic enable/disable of the reference source when not requested. Datasheet Preliminary DS40002015A-page 174 © 2018 Microchip Technology Inc.
  • Page 175: Watchdog Timer (Wdt)

    Reset even if the main clock fails. The CCP mechanism ensures that the WDT settings cannot be changed by accident. For increased safety, a configuration for locking the WDT settings is available. Datasheet Preliminary DS40002015A-page 175 © 2018 Microchip Technology Inc.
  • Page 176: Functional Description

    WDR any time before the time-out occurs, the WDT will issue a system Reset. A new WDT time-out period will be started each time the WDT is reset by WDR. Datasheet Preliminary DS40002015A-page 176 © 2018 Microchip Technology Inc.
  • Page 177 = 8 ms WDTW WDTW The Window mode is enabled by writing a non-zero value to the WINDOW bit field in the Control A register (WDT.CTRLA), and disabled by writing WINDOW=0x0. Datasheet Preliminary DS40002015A-page 177 © 2018 Microchip Technology Inc.
  • Page 178 It is possible to try writing to these registers at any time, but the values are not altered. The following registers are under CCP: Table 18-1. WDT - Registers Under Configuration Change Protection Register WDT.CTRLA IOREG LOCK bit in WDT.STATUS IOREG List of bits/registers protected by CCP: Datasheet Preliminary DS40002015A-page 178 © 2018 Microchip Technology Inc.
  • Page 179 ® megaAVR 0-Series Watchdog Timer (WDT) • Period bits in Control A register (CTRLA.PERIOD) • Window Period bits in Control A register (CTRLA.WINDOW) • LOCK bit in STATUS register (STATUS.LOCK) Datasheet Preliminary DS40002015A-page 179 © 2018 Microchip Technology Inc.
  • Page 180: Register Summary - Wdt

    ® megaAVR 0-Series Watchdog Timer (WDT) 18.4 Register Summary - WDT Offset Name Bit Pos. 0x00 CTRLA WINDOW[3:0] PERIOD[3:0] 0x01 STATUS LOCK SYNCBUSY 18.5 Register Description Datasheet Preliminary DS40002015A-page 180 © 2018 Microchip Technology Inc.
  • Page 181 If LOCK in WDT.STATUS is '1', all bits are change-protected (Access = R) • If LOCK in WDT.STATUS is '0', all bits can be changed (Access = R/W) Value Name Description 8CLK 0.008s 16CLK 0.016s 32CLK 0.032s Datasheet Preliminary DS40002015A-page 181 © 2018 Microchip Technology Inc.
  • Page 182 ® megaAVR 0-Series Watchdog Timer (WDT) Value Name Description 64CLK 0.064s 128CLK 0.128s 256CLK 0.256s 512CLK 0.512s 1KCLK 1.0s 2KCLK 2.0s 4KCLK 4.1s 8KCLK 8.2s other Reserved Datasheet Preliminary DS40002015A-page 182 © 2018 Microchip Technology Inc.
  • Page 183 This bit is set after writing to the WDT.CTRLA register while the data is being synchronized from the system clock domain to the WDT clock domain. This bit is cleared by the system after the synchronization is finished. This bit is not under CCP. Datasheet Preliminary DS40002015A-page 183 © 2018 Microchip Technology Inc.
  • Page 184: Bit Timer/Counter Type A (Tca)

    By default, the TCA is a 16-bit timer/counter. The timer/counter has a Split mode feature that splits it into two 8-bit timer/counters with three compare channels each. A block diagram of the 16-bit timer/counter with closely related peripheral modules (in grey) is shown in the figure below. Datasheet Preliminary DS40002015A-page 184 © 2018 Microchip Technology Inc.
  • Page 185 Control Logic Event Counter System Compare Channel 0 Compare Channel 1 Compare Channel 2 Comparator Waveform Generation Buffer 19.2.1 Block Diagram The figure below shows a detailed block diagram of the timer/counter. Datasheet Preliminary DS40002015A-page 185 © 2018 Microchip Technology Inc.
  • Page 186 The Waveform Generator modes use these comparisons to set the waveform period or pulse width. A prescaled peripheral clock and events from the event system can be used to control the counter. Datasheet Preliminary DS40002015A-page 186 © 2018 Microchip Technology Inc.
  • Page 187: Functional Description

    To start using the timer/counter in a basic mode, follow these steps: • Write a TOP value to the Period register (TCAn.PER) • Enable the peripheral by writing a '1' to the ENABLE bit in the Control A register (TCAn.CTRLA). Datasheet Preliminary DS40002015A-page 187 © 2018 Microchip Technology Inc.
  • Page 188 BV flag is set when data is written to the buffer register and cleared on an UPDATE condition. This is shown for a Compare register (CMPn) below. Datasheet Preliminary DS40002015A-page 188 © 2018 Microchip Technology Inc.
  • Page 189 Figure 19-7. Unbuffered Dual-Slope Operation Counter wraparound "update" "write" BOTTOM New TOP written to New TOP written to PER that is higher PER that is lower than current CNT. than current CNT. Datasheet Preliminary DS40002015A-page 189 © 2018 Microchip Technology Inc.
  • Page 190 For frequency generation, the period time (T) is controlled by a TCAn.CMPn register instead of the Period register (TCAn.PER). The waveform generation output WG is toggled on each compare match between the TCAn.CNT and TCAn.CMPn registers. Datasheet Preliminary DS40002015A-page 190 © 2018 Microchip Technology Inc.
  • Page 191 ) depends on the period setting (TCA_PER), the system's PWM_SS peripheral clock frequency f , and the TCA prescaler (CLKSEL in TCAn.CTRLA). It is calculated by CLK_PER the following equation where N represents the prescaler divider used: Datasheet Preliminary DS40002015A-page 191 © 2018 Microchip Technology Inc.
  • Page 192 (OUT) on the corresponding port pin. Enabling inverted I/O on the port pin (INVEN=1 in PORT.PINn) inverts the corresponding WG output. Figure 19-12. Port Override for Timer/Counter Type A Waveform INVEN CMPnEN Datasheet Preliminary DS40002015A-page 192 © 2018 Microchip Technology Inc.
  • Page 193 Buffer registers and Buffer Valid Flags: Unused • Register Access: Byte Access to all registers • Temp register: Unused, 16-bit register of the Normal mode are Accessed as 8-bit 'TCA_H' and 'TCA_L', Respectively Datasheet Preliminary DS40002015A-page 193 © 2018 Microchip Technology Inc.
  • Page 194 The counter values can be read from the Counter bit field in the Counter registers (TCAn.CNT) Activating Split mode results in changes to the functionality of some registers and register bits. The modifications are described in a separate register map. Datasheet Preliminary DS40002015A-page 194 © 2018 Microchip Technology Inc.
  • Page 195 Low-byte Underflow interrupt Low-byte timer reaches BOTTOM. HUNF High-byte Underflow interrupt High-byte timer reaches BOTTOM. LCMP0 Compare channel 0 interrupt Match between the counter value and the low-byte of Compare 0 register. Datasheet Preliminary DS40002015A-page 195 © 2018 Microchip Technology Inc.
  • Page 196: Sleep Mode Operation

    The interrupt request remains active until the interrupt flag is cleared. See the peripheral's INTFLAGS register for details on how to clear interrupt flags. 19.4 Sleep Mode Operation The timer/counter will continue operation in Idle Sleep mode. Datasheet Preliminary DS40002015A-page 196 © 2018 Microchip Technology Inc.
  • Page 197: Register Summary - Tcan In Normal Mode (Splitm In Tcan.ctrld=0)

    CMP1 15:8 CMP[15:8] CMP[7:0] 0x2C CMP2 15:8 CMP[15:8] 0x2E Reserved 0x35 PERBUF[7:0] 0x36 PERBUF 15:8 PERBUF[15:8] CMPBUF[7:0] 0x38 CMP0nBUF 15:8 CMPBUF[15:8] CMPBUF[7:0] 0x3A CMP1nBUF 15:8 CMPBUF[15:8] CMPBUF[7:0] 0x3C CMP2nBUF 15:8 CMPBUF[15:8] Datasheet Preliminary DS40002015A-page 197 © 2018 Microchip Technology Inc.
  • Page 198: Register Description - Normal Mode

    ® megaAVR 0-Series 16-bit Timer/Counter Type A (TCA) 19.6 Register Description - Normal Mode Datasheet Preliminary DS40002015A-page 198 © 2018 Microchip Technology Inc.
  • Page 199 CLK_PER DIV2 CLK_PER DIV4 CLK_PER DIV8 CLK_PER DIV16 CLK_PER DIV64 CLK_PER DIV256 /256 CLK_PER DIV1024 /1024 CLK_PER Bit 0 – ENABLE Enable Value Description The peripheral is disabled The peripheral is enabled Datasheet Preliminary DS40002015A-page 199 © 2018 Microchip Technology Inc.
  • Page 200 The port pin direction must be set as output. Table 19-4. Timer Waveform Generation Mode WGMODE[2:0] Group Configuration Mode of Operation Top Update NORMAL Normal Frequency CMP0 TOP Reserved SINGLESLOPE Single-slope PWM BOTTOM BOTTOM Datasheet Preliminary DS40002015A-page 200 © 2018 Microchip Technology Inc.
  • Page 201 Dual-slope PWM BOTTOM BOTTOM Value Name Description NORMAL Normal operation mode Frequency mode SINGLESLOPE Single-slope PWM mode DSTOP Dual-slope PWM mode DSBOTH Dual-slope PWM mode DSBOTTOM Dual-slope PWM mode Other Reserved Datasheet Preliminary DS40002015A-page 201 © 2018 Microchip Technology Inc.
  • Page 202 The CMPnOV bits allow direct access to the waveform generator's output compare value when the timer/ counter is not enabled. This is used to set or clear the WG output value when the timer/counter is not running. Datasheet Preliminary DS40002015A-page 202 © 2018 Microchip Technology Inc.
  • Page 203 Bit 0 – SPLITM Enable Split Mode This bit sets the timer/counter in Split mode operation. It will then work as two 8-bit timer/counters. The register map will change compared to normal 16-bit mode. Datasheet Preliminary DS40002015A-page 203 © 2018 Microchip Technology Inc.
  • Page 204 Normally this bit is controlled in hardware by the Waveform Generation mode or by event actions, but this bit can also be changed from software. Value Description The counter is counting up (incrementing) The counter is counting down (decrementing) Datasheet Preliminary DS40002015A-page 204 © 2018 Microchip Technology Inc.
  • Page 205 Normally this bit is controlled in hardware by the Waveform Generation mode or by event actions, but this bit can also be changed from software. Value Description The counter is counting up (incrementing) The counter is counting down (decrementing) Datasheet Preliminary DS40002015A-page 205 © 2018 Microchip Technology Inc.
  • Page 206 These bits are automatically cleared on an UPDATE condition. Bit 0 – PERBV Period Buffer Valid This bit is set when a new value is written to the TCAn.PERBUF register. This bit is automatically cleared on an UPDATE condition. Datasheet Preliminary DS40002015A-page 206 © 2018 Microchip Technology Inc.
  • Page 207 These bits are automatically cleared on an UPDATE condition. Bit 0 – PERBV Period Buffer Valid This bit is set when a new value is written to the TCAn.PERBUF register. This bit is automatically cleared on an UPDATE condition. Datasheet Preliminary DS40002015A-page 207 © 2018 Microchip Technology Inc.
  • Page 208 0, down-counting when the event line is Bit 0 – CNTEI Enable Count on Event Input Value Description Counting on Event input is disabled Counting on Event input is enabled according to EVACT bit field Datasheet Preliminary DS40002015A-page 208 © 2018 Microchip Technology Inc.
  • Page 209 Bit 4 – CMP0 Compare Channel 0 Interrupt Enable Writing CMPn bit to '1' enables compare interrupt from channel n. Bit 0 – OVF Timer Overflow/Underflow Interrupt Enable Writing OVF bit to '1' enables overflow interrupt. Datasheet Preliminary DS40002015A-page 209 © 2018 Microchip Technology Inc.
  • Page 210 This flag is set either on a TOP (overflow) or BOTTOM (underflow) condition, depending on the WGMODE setting. The OVF flag is not cleared automatically, only by writing a ‘1’ to its bit location. Datasheet Preliminary DS40002015A-page 210 © 2018 Microchip Technology Inc.
  • Page 211 Bit 0 – DBGRUN Run in Debug Value Description The peripheral is halted in Break Debug mode and ignores events The peripheral will continue to run in Break Debug mode when the CPU is halted Datasheet Preliminary DS40002015A-page 211 © 2018 Microchip Technology Inc.
  • Page 212 It can be read and written by software. Refer to 16-bit access in the AVR CPU chapter. There is one common Temporary register for all the 16-bit registers of this peripheral. TEMP[7:0] Access Reset Bits 7:0 – TEMP[7:0] Temporary Bits for 16-bit Access Datasheet Preliminary DS40002015A-page 212 © 2018 Microchip Technology Inc.
  • Page 213 Bits 15:8 – CNT[15:8] Counter High Byte These bits hold the MSB of the 16-bit counter register. Bits 7:0 – CNT[7:0] Counter Low Byte These bits hold the LSB of the 16-bit counter register. Datasheet Preliminary DS40002015A-page 213 © 2018 Microchip Technology Inc.
  • Page 214 Bits 15:8 – PER[15:8] Periodic High Byte These bits hold the MSB of the 16-bit period register. Bits 7:0 – PER[7:0] Periodic Low Byte These bits hold the LSB of the 16-bit period register. Datasheet Preliminary DS40002015A-page 214 © 2018 Microchip Technology Inc.
  • Page 215 Bits 15:8 – CMP[15:8] Compare High Byte These bits hold the MSB of the 16-bit compare register. Bits 7:0 – CMP[7:0] Compare Low Byte These bits hold the LSB of the 16-bit compare register. Datasheet Preliminary DS40002015A-page 215 © 2018 Microchip Technology Inc.
  • Page 216 Bits 15:8 – PERBUF[15:8] Period Buffer High Byte These bits hold the MSB of the 16-bit period buffer register. Bits 7:0 – PERBUF[7:0] Period Buffer Low Byte These bits hold the LSB of the 16-bit period buffer register. Datasheet Preliminary DS40002015A-page 216 © 2018 Microchip Technology Inc.
  • Page 217 Bits 15:8 – CMPBUF[15:8] Compare High Byte These bits hold the MSB of the 16-bit compare buffer register. Bits 7:0 – CMPBUF[7:0] Compare Low Byte These bits hold the LSB of the 16-bit compare buffer register. Datasheet Preliminary DS40002015A-page 217 © 2018 Microchip Technology Inc.
  • Page 218: Register Summary - Tcan In Split Mode (Splitm In Tcan.ctrld=1)

    0x25 0x26 LPER LPER[7:0] 0x27 HPER HPER[7:0] 0x28 LCMP0 LCMP[7:0] 0x29 HCMP0 HCMP[7:0] 0x2A LCMP1 LCMP[7:0] 0x2B HCMP1 HCMP[7:0] 0x2C LCMP2 LCMP[7:0] 0x2D HCMP2 HCMP[7:0] 19.8 Register Description - Split Mode Datasheet Preliminary DS40002015A-page 218 © 2018 Microchip Technology Inc.
  • Page 219 CLK_PER DIV2 CLK_PER DIV4 CLK_PER DIV8 CLK_PER DIV16 CLK_PER DIV64 CLK_PER DIV256 /256 CLK_PER DIV1024 /1024 CLK_PER Bit 0 – ENABLE Enable Value Description The peripheral is disabled The peripheral is enabled Datasheet Preliminary DS40002015A-page 219 © 2018 Microchip Technology Inc.
  • Page 220 Bit 0 – LCMP0EN Low byte Compare 0 Enable Setting the LCMPnEN/HCMPnEN bits in the FRQ or PWM Waveform Generation mode of operation will override the port output register for the corresponding WOn pin. Datasheet Preliminary DS40002015A-page 220 © 2018 Microchip Technology Inc.
  • Page 221 The LCMPnOV/HCMPn bits allow direct access to the waveform generator's output compare value when the timer/counter is not enabled. This is used to set or clear the WOn output value when the timer/counter is not running. Datasheet Preliminary DS40002015A-page 221 © 2018 Microchip Technology Inc.
  • Page 222 Bit 0 – SPLITM Enable Split Mode This bit sets the timer/counter in Split mode operation. It will then work as two 8-bit timer/counters. The register map will change compared to normal 16-bit mode. Datasheet Preliminary DS40002015A-page 222 © 2018 Microchip Technology Inc.
  • Page 223 Bits 1:0 – CMDEN[1:0] Command enable These bits are used to indicate for which timer/counter the command (CMD) is valid. Value Name Description NONE None Reserved Reserved BOTH Command valid for both low-byte and high-byte T/C Datasheet Preliminary DS40002015A-page 223 © 2018 Microchip Technology Inc.
  • Page 224 Bits 1:0 – CMDEN[1:0] Command enable These bits are used to indicate for which timer/counter the command (CMD) is valid. Value Name Description NONE None Reserved Reserved BOTH Command valid for both low-byte and high-byte T/C Datasheet Preliminary DS40002015A-page 224 © 2018 Microchip Technology Inc.
  • Page 225 Bit 1 – HUNF High byte Underflow Interrupt Enable Writing HUNF bit to '1' enables high byte underflow interrupt. Bit 0 – LUNF Low byte Underflow Interrupt Enable Writing HUNF bit to '1' enables low byte underflow interrupt. Datasheet Preliminary DS40002015A-page 225 © 2018 Microchip Technology Inc.
  • Page 226 This flag is set on a low byte timer BOTTOM (underflow) condition. LUNF is not automatically cleared and needs to be cleared by software. This is done by writing a ‘1’ to its bit location. Datasheet Preliminary DS40002015A-page 226 © 2018 Microchip Technology Inc.
  • Page 227 Bit 0 – DBGRUN Run in Debug Value Description The peripheral is halted in Break Debug mode and ignores events The peripheral will continue to run in Break Debug mode when the CPU is halted Datasheet Preliminary DS40002015A-page 227 © 2018 Microchip Technology Inc.
  • Page 228 TCAn.LCNT contains the counter value in low byte timer. CPU and UPDI write access has priority over count, clear, or reload of the counter. LCNT[7:0] Access Reset Bits 7:0 – LCNT[7:0] Counter Value for Low Byte Timer These bits define the counter value of the low byte timer. Datasheet Preliminary DS40002015A-page 228 © 2018 Microchip Technology Inc.
  • Page 229 TCAn.HCNT contains the counter value in high byte timer. CPU and UPDI write access has priority over count, clear, or reload of the counter. HCNT[7:0] Access Reset Bits 7:0 – HCNT[7:0] Counter Value for High Byte Timer These bits define the counter value in high byte timer. Datasheet Preliminary DS40002015A-page 229 © 2018 Microchip Technology Inc.
  • Page 230 The TCAn.LPER register contains the TOP value of low byte timer. LPER[7:0] Access Reset Bits 7:0 – LPER[7:0] Period Value Low Byte Timer These bits hold the TOP value of low byte timer. Datasheet Preliminary DS40002015A-page 230 © 2018 Microchip Technology Inc.
  • Page 231 The TCAn.HPER register contains the TOP value of high byte timer. HPER[7:0] Access Reset Bits 7:0 – HPER[7:0] Period Value High Byte Timer These bits hold the TOP value of high byte timer. Datasheet Preliminary DS40002015A-page 231 © 2018 Microchip Technology Inc.
  • Page 232 LCMP[7:0] Access Reset Bits 7:0 – LCMP[7:0] Compare Value of Channel n These bits hold the compare value of channel n that is compared to TCAn.LCNT. Datasheet Preliminary DS40002015A-page 232 © 2018 Microchip Technology Inc.
  • Page 233 HCMP[7:0] Access Reset Bits 7:0 – HCMP[7:0] Compare Value of Channel n These bits hold the compare value of channel n that is compared to TCAn.HCNT. Datasheet Preliminary DS40002015A-page 233 © 2018 Microchip Technology Inc.
  • Page 234: Bit Timer/Counter Type B (Tcb)

    The base counter is clocked by the peripheral clock with optional prescaling. Datasheet Preliminary DS40002015A-page 234 © 2018 Microchip Technology Inc.
  • Page 235: Functional Description

    The counter reaches TOP when it becomes equal to the highest value in the count sequence. UPDATE The update condition is met when the timer/counter reaches BOTTOM or TOP, depending on the Waveform Generator mode. Counter register value. CCMP Capture/Compare register value. Datasheet Preliminary DS40002015A-page 235 © 2018 Microchip Technology Inc.
  • Page 236 In Freeze state, the counter will restart on a new edge. Reading count (TCBn.CNT) or compare/capture (TCBn.CCMP) register, or writing run bit (RUN in TCBn.STATUS) in Freeze state will have no effect. Datasheet Preliminary DS40002015A-page 236 © 2018 Microchip Technology Inc.
  • Page 237 Copy CNT to CCMP Copy CNT to CCMP Wraparound and interrupt and interrupt It is recommended to write zero to the TCBn.CNT register when entering this mode from any other mode. Datasheet Preliminary DS40002015A-page 237 © 2018 Microchip Technology Inc.
  • Page 238 The timer will automatically switch between rising and falling edge detection, but a minimum edge separation of two clock cycles is required for correct behavior. Datasheet Preliminary DS40002015A-page 238 © 2018 Microchip Technology Inc.
  • Page 239 Ignore till Trigger next Capture is read capture sequence Event Input Edge detector " Interrupt" BOTTOM Start Copy CNT to Stop counter and CPU reads the CCMP register counter CCMP interrupt Datasheet Preliminary DS40002015A-page 239 © 2018 Microchip Technology Inc.
  • Page 240 When this peripheral is enabled and in PWM mode, changing the value of the Compare/Capture register will change the output, but the transition may output invalid values. It is hence recommended to: Disable the peripheral. Datasheet Preliminary DS40002015A-page 240 © 2018 Microchip Technology Inc.
  • Page 241 TCB can be configured to use the clock (CLK_TCA) of the Timer/Counter type A (TCAn) by writing to the Clock Select bit field (CLKSEL) in the Control A register (TCBn.CTRLA). In this setting, the TCB will count on the exact same clock source as selected in TCA. Datasheet Preliminary DS40002015A-page 241 © 2018 Microchip Technology Inc.
  • Page 242 The module can stay fully operational in the Standby sleep mode if the Run In Standby (RUNSTDBY) bit in the TCBn.CTRLA register is written to '1'. All operations are halted in Power Down sleep mode. Datasheet Preliminary DS40002015A-page 242 © 2018 Microchip Technology Inc.
  • Page 243: Register Summary - Tcb

    0x04 EVCTRL FILTER EDGE CAPTEI 0x05 INTCTRL CAPT 0x06 INTFLAGS CAPT 0x07 STATUS 0x08 DBGCTRL DBGRUN 0x09 TEMP TEMP[7:0] CNT[7:0] 0x0A 15:8 CNT[15:8] CCMP[7:0] 0x0C CCMP 15:8 CCMP[15:8] 20.5 Register Description Datasheet Preliminary DS40002015A-page 243 © 2018 Microchip Technology Inc.
  • Page 244 Writing these bits selects the clock source for this peripheral. Value Description CLK_PER CLK_PER / 2 Use CLK_TCA from TCA0 Reserved Bit 0 – ENABLE Enable Writing this bit to '1' enables the Timer/Counter type B peripheral. Datasheet Preliminary DS40002015A-page 244 © 2018 Microchip Technology Inc.
  • Page 245 Periodic Interrupt mode Time-out Check mode Input Capture on Event mode Input Capture Frequency Measurement mode Input Capture Pulse-Width Measurement mode Input Capture Frequency and Pulse-Width Measurement mode Single-Shot mode 8-Bit PWM mode Datasheet Preliminary DS40002015A-page 245 © 2018 Microchip Technology Inc.
  • Page 246 Pulse Width Measurement mode On following Negative: Input Capture Positive: Stop counter, interrupt On 1 Negative: Clear and restart counter On following Positive: Input Capture Negative: Stop counter, interrupt Single-Shot mode Start counter Datasheet Preliminary DS40002015A-page 246 © 2018 Microchip Technology Inc.
  • Page 247 Count Mode EDGE Positive Edge Negative Edge Start counter Start counter 8-Bit PWM mode Bit 0 – CAPTEI Capture Event Input Enable Writing this bit to '1' enables the input capture event. Datasheet Preliminary DS40002015A-page 247 © 2018 Microchip Technology Inc.
  • Page 248 16-bit Timer/Counter Type B (TCB) 20.5.4 Interrupt Control Name:  INTCTRL Offset:  0x05 Reset:  0x00 Property:  - CAPT Access Reset Bit 0 – CAPT Capture Interrupt Enable Writing this bit to '1' enables the Capture interrupt. Datasheet Preliminary DS40002015A-page 248 © 2018 Microchip Technology Inc.
  • Page 249 Set on second (positive or negative) edge when the counter is Width Measurement mode stopped, cleared when Capture is read Single-Shot mode Set when counter reaches TOP 8-Bit PWM mode Set when the counter reaches CCMPL Datasheet Preliminary DS40002015A-page 249 © 2018 Microchip Technology Inc.
  • Page 250 When the counter is running, this bit is set to '1'. When the counter is stopped, this bit is cleared to '0'. The bit is read-only and cannot be set by UPDI. Datasheet Preliminary DS40002015A-page 250 © 2018 Microchip Technology Inc.
  • Page 251 Bit 0 – DBGRUN Debug Run Value Description The peripheral is halted in Break Debug mode and ignores events The peripheral will continue to run in Break Debug mode when the CPU is halted Datasheet Preliminary DS40002015A-page 251 © 2018 Microchip Technology Inc.
  • Page 252 It can be read and written by software. Refer to 16-bit access in the AVR CPU chapter. There is one common Temporary register for all the 16-bit registers of this peripheral. TEMP[7:0] Access Reset Bits 7:0 – TEMP[7:0] Temporary Value Datasheet Preliminary DS40002015A-page 252 © 2018 Microchip Technology Inc.
  • Page 253 Bits 15:8 – CNT[15:8] Count Value High These bits hold the MSB of the 16-bit Counter register. Bits 7:0 – CNT[7:0] Count Value Low These bits hold the LSB of the 16-bit Counter register. Datasheet Preliminary DS40002015A-page 253 © 2018 Microchip Technology Inc.
  • Page 254 These bits hold the MSB of the 16-bit compare, capture, and top value. Bits 7:0 – CCMP[7:0] Capture/Compare Value Low Byte These bits hold the LSB of the 16-bit compare, capture, and top value. Datasheet Preliminary DS40002015A-page 254 © 2018 Microchip Technology Inc.
  • Page 255: Real-Time Counter (Rtc)

    The RTC can be adjusted by software to an accuracy of ±1PPM. The RTC correction operation will either speed up (by skipping count) or slow down (by adding extra count) the prescaler to account for the crystal error. Datasheet Preliminary DS40002015A-page 255 © 2018 Microchip Technology Inc.
  • Page 256: Clocks

    An external clock can be used on the TOSC1 pin. 21.4 RTC Functional Description The RTC peripheral offers two timing functions: the Real-Time Counter (RTC) and a Periodic Interrupt Timer (PIT). This subsection describes the RTC. Datasheet Preliminary DS40002015A-page 256 © 2018 Microchip Technology Inc.
  • Page 257: Pit Functional Description

    The PIT is enabled by setting the Enable bit in the PIT Control A register (the PITEN bit in RTC.PITCTRLA to 1). The PIT is disabled by writing the PITEN bit in RTC.PITCTRLA to 0. Datasheet Preliminary DS40002015A-page 257 © 2018 Microchip Technology Inc.
  • Page 258 PIT and its first output is depending on the prescaler’s counting phase: the depicted first interrupt in the lower figure is produced by writing PITEN to ‘1’ at any time inside the leading time window. Datasheet Preliminary DS40002015A-page 258 © 2018 Microchip Technology Inc.
  • Page 259: Crystal Error Correction

    The final correction of the clock will be reflected in the RTC count value available through the RTC.CNTx registers or in the PIT intervals. Datasheet Preliminary DS40002015A-page 259 © 2018 Microchip Technology Inc.
  • Page 260: Events

    INTFLAGS register for details on how to clear interrupt flags. Note that: • The RTC has two INTFLAGS registers: RTC.INTFLAGS and RTC.PITINTFLAGS. • The RTC has two INTCTRL registers: RTC.INTCTRL and RTC.PITINTCTRL. Datasheet Preliminary DS40002015A-page 260 © 2018 Microchip Technology Inc.
  • Page 261: Sleep Mode Operation

    CTRLABUSY) in the STATUS register (RTC.STATUS). For the RTC.PITCTRLA register, a Synchronization Busy flag (SYNCBUSY) is available in the PIT STATUS register (RTC.PITSTATUS). Check for busy should be performed before writing to the mentioned registers. Datasheet Preliminary DS40002015A-page 261 © 2018 Microchip Technology Inc.
  • Page 262: Register Summary - Rtc

    CNT[15:8] PER[7:0] 0x0A 15:8 PER[15:8] CMP[7:0] 0x0C 15:8 CMP[15:8] 0x0E Reserved 0x0F 0x10 PITCTRLA PERIOD[3:0] PITEN 0x11 PITSTATUS CTRLBUSY 0x12 PITINTCTRL 0x13 PITINTFLAGS 0x14 Reserved 0x15 PITDBGCTRL DBGRUN 21.12 Register Description Datasheet Preliminary DS40002015A-page 262 © 2018 Microchip Technology Inc.
  • Page 263 RTC clock/2048 DIV4096 RTC clock/4096 DIV8192 RTC clock/8192 DIV16384 RTC clock/16384 DIV32768 RTC clock/32768 Bit 2 – CORREN Correction Enable Value Description Correction is disabled Correction is enabled Bit 0 – RTCEN RTC Enable Datasheet Preliminary DS40002015A-page 263 © 2018 Microchip Technology Inc.
  • Page 264 ® megaAVR 0-Series Real-Time Counter (RTC) Value Description RTC disabled RTC enabled Datasheet Preliminary DS40002015A-page 264 © 2018 Microchip Technology Inc.
  • Page 265 This bit is indicating whether the RTC is busy synchronizing the Count register (RTC.CNT) in RTC clock domain. Bit 0 – CTRLABUSY Control A Synchronization Busy This bit is indicating whether the RTC is busy synchronizing the Control A register (RTC.CTRLA) in RTC clock domain. Datasheet Preliminary DS40002015A-page 265 © 2018 Microchip Technology Inc.
  • Page 266 Enable interrupt-on-compare match (i.e., when the Counter value (CNT) matches the Compare value (CMP)). Bit 0 – OVF Overflow Interrupt Enable Enable interrupt-on-counter overflow (i.e., when the Counter value (CNT) matched the Period value (PER) and wraps around to zero). Datasheet Preliminary DS40002015A-page 266 © 2018 Microchip Technology Inc.
  • Page 267 Bit 0 – OVF Overflow Interrupt Flag This flag is set when the Counter value (CNT) has reached the Period value (PER) and wrapped to zero. Writing a '1' to this bit clears the flag. Datasheet Preliminary DS40002015A-page 267 © 2018 Microchip Technology Inc.
  • Page 268 It can be read and written by software. Refer to 16-bit access in the AVR CPU chapter. There is one common Temporary register for all the 16-bit registers of this peripheral. TEMP[7:0] Access Reset Bits 7:0 – TEMP[7:0] Temporary Temporary register for read/write operations in 16-bit registers. Datasheet Preliminary DS40002015A-page 268 © 2018 Microchip Technology Inc.
  • Page 269 Bit 0 – DBGRUN Debug Run Value Description The peripheral is halted in Break Debug mode and ignores events The peripheral will continue to run in Break Debug mode when the CPU is halted Datasheet Preliminary DS40002015A-page 269 © 2018 Microchip Technology Inc.
  • Page 270 Negative correction causing prescaler to count faster. Requires that prescaler configuration is set to minimum DIV2. Bits 6:0 – ERROR[6:0] Error Correction Value The number of correction clocks for each million RTC clock cycles interval (ppm). Datasheet Preliminary DS40002015A-page 270 © 2018 Microchip Technology Inc.
  • Page 271 A register of the Clock Controller (CLKCTRL.XOSC32KCTRLA) must be configured accordingly. Value Name Description INT32K 32.768 kHz from OSCULP32K INT1K 1.024 kHz from OSCULP32K TOSC32K 32.768 kHz from XOSC32K or external clock from TOSC1 EXTCLK External clock from EXTCLK pin Datasheet Preliminary DS40002015A-page 271 © 2018 Microchip Technology Inc.
  • Page 272 Bits 15:8 – CNT[15:8] Counter High Byte These bits hold the MSB of the 16-bit Counter register. Bits 7:0 – CNT[7:0] Counter Low Byte These bits hold the LSB of the 16-bit Counter register. Datasheet Preliminary DS40002015A-page 272 © 2018 Microchip Technology Inc.
  • Page 273 Bits 15:8 – PER[15:8] Period High Byte These bits hold the MSB of the 16-bit Period register. Bits 7:0 – PER[7:0] Period Low Byte These bits hold the LSB of the 16-bit Period register. Datasheet Preliminary DS40002015A-page 273 © 2018 Microchip Technology Inc.
  • Page 274 Bits 15:8 – CMP[15:8] Compare High Byte These bits hold the MSB of the 16-bit Compare register. Bits 7:0 – CMP[7:0] Compare Low Byte These bits hold the LSB of the 16-bit Compare register. Datasheet Preliminary DS40002015A-page 274 © 2018 Microchip Technology Inc.
  • Page 275 CYC4096 4096 cycles CYC8192 8192 cycles CYC16384 16384 cycles CYC32768 32768 cycles Reserved Bit 0 – PITEN Periodic Interrupt Timer Enable Writing a '1' to this bit enables the Periodic Interrupt Timer. Datasheet Preliminary DS40002015A-page 275 © 2018 Microchip Technology Inc.
  • Page 276 CTRLBUSY Access Reset Bit 0 – CTRLBUSY PITCTRLA Synchronization Busy This bit indicates whether the RTC is busy synchronizing the Periodic Interrupt Timer Control A register (RTC.PITCTRLA) in the RTC clock domain. Datasheet Preliminary DS40002015A-page 276 © 2018 Microchip Technology Inc.
  • Page 277 21.12.14 PIT Interrupt Control Name:  PITINTCTRL Offset:  0x12 Reset:  0x00 Property:  - Access Reset Bit 0 – PI Periodic interrupt Value Description The periodic interrupt is disabled The periodic interrupt is enabled Datasheet Preliminary DS40002015A-page 277 © 2018 Microchip Technology Inc.
  • Page 278 PITINTFLAGS Offset:  0x13 Reset:  0x00 Property:  - Access Reset Bit 0 – PI Periodic interrupt Flag This flag is set when a periodic interrupt is issued. Writing a '1' clears the flag. Datasheet Preliminary DS40002015A-page 278 © 2018 Microchip Technology Inc.
  • Page 279 Writing this bit to '1' will enable the PIT to run in Debug mode while the CPU is halted. Value Description The peripheral is halted in Break Debug mode and ignores events The peripheral will continue to run in Break Debug mode when the CPU is halted Datasheet Preliminary DS40002015A-page 279 © 2018 Microchip Technology Inc.
  • Page 280: Universal Synchronous And Asynchronous Receiver And Transmitter (Usart)

    The USART supports full-duplex communication, asynchronous and synchronous operation and one-wire configurations. The USART can be set in SPI master mode and used for SPI communication. Datasheet Preliminary DS40002015A-page 280 © 2018 Microchip Technology Inc.
  • Page 281 The USART can be linked to the Configurable Custom Logic unit (CCL). When used with the CCL, the RxD data can be decoded before the signal is fed into the USART receiver. TxD data can be encoded after the signal has been output from the USART transmitter. Datasheet Preliminary DS40002015A-page 281 © 2018 Microchip Technology Inc.
  • Page 282 Receive Shift Register Recovery Control Parity RXDATA Buffer Checker RXDATA 22.2.2 Signal Description Signal Type Description Input/output Receiving line Output Transmitting line Input/output Clock for synchronous operation XDIR Output Transmit Enable for RS485 Datasheet Preliminary DS40002015A-page 282 © 2018 Microchip Technology Inc.
  • Page 283: Functional Description

    Baud Rate Generator or externally from the transfer clock (XCK) pin. Five modes of clock generation are supported; Normal and Double-Speed Asynchronous mode, Master and Slave Synchronous mode, and Master SPI mode. Datasheet Preliminary DS40002015A-page 283 © 2018 Microchip Technology Inc.
  • Page 284 An External clock (XCK) is used in Synchronous Slave mode operation. The XCK clock input is sampled on the peripheral clock frequency and the maximum XCK clock frequency (f ) is limited by the � following: � < ���_��� ��� Datasheet Preliminary DS40002015A-page 284 © 2018 Microchip Technology Inc.
  • Page 285 Data bits are shifted out and latched in on opposite edges of the XCK signal, ensuring sufficient time for data signals to stabilize. The settings are summarized in the table below. Changing the setting of any of these bits during transmission will corrupt both the receiver and transmitter. Datasheet Preliminary DS40002015A-page 285 © 2018 Microchip Technology Inc.
  • Page 286 5, 6, 7, 8, or 9 Data bits • No, even, or odd Parity bit • 1 or 2 Stop bits Figure 22-5 illustrates the possible combinations of frame formats. Bits inside brackets are optional. Figure 22-5. Frame Formats Datasheet Preliminary DS40002015A-page 286 © 2018 Microchip Technology Inc.
  • Page 287 Transmit Complete Interrupt Flag (TXCIF in USARTn.STATUS) is set and the optional interrupt is generated. TXDATA can only be written when the Data Register Empty Flag (DREIF in USARTn.STATUS) is set, indicating that the register is empty and ready for new data. Datasheet Preliminary DS40002015A-page 287 © 2018 Microchip Technology Inc.
  • Page 288 A parity error is detected if one of the equations below is not �0 = ��0 XOR ��1 XOR ��2 XOR ��4 true which sets PERR in USARTn.RXDATAH. �1 = NOT ��1 XOR ��3 XOR ��4 XOR ��5 Datasheet Preliminary DS40002015A-page 288 © 2018 Microchip Technology Inc.
  • Page 289 • If two or three samples have a high level, the Start bit is rejected as a noise spike, and the receiver looks for the next high-to-low transition. Datasheet Preliminary DS40002015A-page 289 © 2018 Microchip Technology Inc.
  • Page 290 The following equations can be used to calculate the ratio of the incoming data rate and internal receiver baud rate. 16 � + 1 16 � + 2 � � 16 � + 1 + 6 16 � + 1 + 8 ���� ���� Datasheet Preliminary DS40002015A-page 290 © 2018 Microchip Technology Inc.
  • Page 291 As for the USART, a data transfer is initiated by writing to the USARTn.DATA register. This is the case for both sending and receiving data since the transmitter controls the transfer clock. The data written to Datasheet Preliminary DS40002015A-page 291 © 2018 Microchip Technology Inc.
  • Page 292 When the USART is not transmitting, its internal RxD signal will receive input data from the external USART through the TxD pin. Datasheet Preliminary DS40002015A-page 292 © 2018 Microchip Technology Inc.
  • Page 293 The start frame detection is supported in UART mode only. The UART start frame detector is limited to Standby Sleep mode only and can wake up the system when a Start bit is detected. Datasheet Preliminary DS40002015A-page 293 © 2018 Microchip Technology Inc.
  • Page 294 At the end of these 8-bit times, the counter is stopped. At this moment, the ten Most Significant bits of the counter (value divided by 64) gives Datasheet Preliminary DS40002015A-page 294 © 2018 Microchip Technology Inc.
  • Page 295 ® The IRCOM mode enables IrDA 1.4 compliant modulation and demodulation for baud rates up to 115.2 kbps. When IRCOM mode is enabled, Double-Speed mode cannot be used for the USART. Datasheet Preliminary DS40002015A-page 295 © 2018 Microchip Technology Inc.
  • Page 296 The USART generates the following event: • In SPI master mode: If USART is enabled and transmitting, the generated XCK clock is output on the USARTs event output. Otherwise, the event output is zero. Datasheet Preliminary DS40002015A-page 296 © 2018 Microchip Technology Inc.
  • Page 297 An interrupt request is generated when the corresponding interrupt source is enabled and the Interrupt Flag is set. The interrupt request remains active until the Interrupt Flag is cleared. See the USARTn.STATUS register for details on how to clear Interrupt Flags. Datasheet Preliminary DS40002015A-page 297 © 2018 Microchip Technology Inc.
  • Page 298: Register Summary - Usartn

    CMODE[1:0] PMODE[1:0] SBMODE CHSIZE[2:0] 0x07 CTRLC CMODE[1:0] UDORD UCPHA BAUD[7:0] 0x08 BAUD 15:8 BAUD[15:8] 0x0A Reserved 0x0B DBGCTRL DBGRUN 0x0C EVCTRL IREI 0x0D TXPLCTRL TXPL[7:0] 0x0E RXPLCTRL RXPL[6:0] 22.5 Register Description Datasheet Preliminary DS40002015A-page 298 © 2018 Microchip Technology Inc.
  • Page 299 9BIT Low byte first, read USARTn.RXDATAL before USARTn.RXDATAH. Otherwise, always read USARTn.RXDATAH before USARTn.RXDATAL in order to get the correct flags. DATA[7:0] Access Reset Bits 7:0 – DATA[7:0] Receiver Data Register Datasheet Preliminary DS40002015A-page 299 © 2018 Microchip Technology Inc.
  • Page 300 LINAUTO mode, this bit will be a Parity Check of the protected identifier field and will be valid when DATA[8] in USARTn.RXDATAH reads low. This flag is not used in Master SPI mode of operation. Datasheet Preliminary DS40002015A-page 300 © 2018 Microchip Technology Inc.
  • Page 301 Otherwise, the bit will be read as one. For Receiver mode other than LINAUTO mode, DATA[8] holds the ninth data bit in the received character when operating with serial frames with nine data bits. Datasheet Preliminary DS40002015A-page 301 © 2018 Microchip Technology Inc.
  • Page 302 Transmit Shift register when the Shift register is empty. The data is then transmitted on the TxD pin. DATA[7:0] Access Reset Bits 7:0 – DATA[7:0] Transmit Data Register Datasheet Preliminary DS40002015A-page 302 © 2018 Microchip Technology Inc.
  • Page 303 CHSIZE in USARTn.CTRLC is set to 9BIT Low byte first where USARTn.TXDATAL should be written first. This bit is unused in Master SPI mode of operation. DATA[8] Access Reset Bit 0 – DATA[8] Transmit Data Register This bit is used when CHSIZE=9BIT in USARTn.CTRLC. Datasheet Preliminary DS40002015A-page 303 © 2018 Microchip Technology Inc.
  • Page 304 It will also be set when USART is set to LINAUTO mode and the SYNC character differ from data value 0x55. Writing a ‘1’ to this bit will clear the flag and bring the USART back to Idle state. Datasheet Preliminary DS40002015A-page 304 © 2018 Microchip Technology Inc.
  • Page 305 BAUD rate through BREAK and SYNC as long as it falls within the valid range of the USARTn.BAUD register. This bit will always read ‘0’. Datasheet Preliminary DS40002015A-page 305 © 2018 Microchip Technology Inc.
  • Page 306 Name Description Disabled. Enables RS-485 mode with control of an external line driver through a dedicated Transmit Enable (TE) pin. Enables RS-485 mode with control of the internal USART transmitter. Reserved. Datasheet Preliminary DS40002015A-page 306 © 2018 Microchip Technology Inc.
  • Page 307 0x55. The GENAUTO and LINAUTO mode is only supported for USART operated in Asynchronous Slave mode. Value Name Description NORMAL Normal USART mode, Standard Transmission Speed CLK2X Normal USART mode, Double Transmission Speed Datasheet Preliminary DS40002015A-page 307 © 2018 Microchip Technology Inc.
  • Page 308 Writing a ‘1’ to this bit enables the Multi-Processor Communication mode: the USART receiver ignores all the incoming frames that do not contain address information. The transmitter is unaffected by the MPCM setting. For more detailed information see Multiprocessor Communication Mode. Datasheet Preliminary DS40002015A-page 308 © 2018 Microchip Technology Inc.
  • Page 309 Bit 3 – SBMODE Stop Bit Mode Writing this bit selects the number of Stop bits to be inserted by the transmitter. The receiver ignores this setting. Value Description 1 Stop bit 2 Stop bits Datasheet Preliminary DS40002015A-page 309 © 2018 Microchip Technology Inc.
  • Page 310 For 9BIT character size, the order of which byte to read or write first, low or high byte of RXDATA or TXDATA is selectable. Value Name Description 5BIT 5-bit 6BIT 6-bit 7BIT 7-bit 8BIT 8-bit Reserved Reserved 9BITL 9-bit (Low byte first) 9BITH 9-bit (High byte first) Datasheet Preliminary DS40002015A-page 310 © 2018 Microchip Technology Inc.
  • Page 311 Bit 1 – UCPHA Clock Phase The UCPHA bit setting determines if data is sampled on the leading (first) edge or tailing (last) edge of XCKn. Refer to the Master SPI Mode Clock Generation for details. Datasheet Preliminary DS40002015A-page 311 © 2018 Microchip Technology Inc.
  • Page 312 Bits 15:8 – BAUD[15:8] USART Baud Rate High Byte These bits hold the MSB of the 16-bit Baud register. Bits 7:0 – BAUD[7:0] USART Baud Rate Low Byte These bits hold the LSB of the 16-bit Baud register. Datasheet Preliminary DS40002015A-page 312 © 2018 Microchip Technology Inc.
  • Page 313 Bit 0 – DBGRUN Debug Run Value Description The peripheral is halted in Break Debug mode and ignores events The peripheral will continue to run in Break Debug mode when the CPU is halted Datasheet Preliminary DS40002015A-page 313 © 2018 Microchip Technology Inc.
  • Page 314 Bit 0 – IREI IrDA Event Input Enable This bit enables the event source for the IRCOM Receiver. If event input is selected for the IRCOM Receiver, the input from the USART’s RX pin is automatically disabled. Datasheet Preliminary DS40002015A-page 314 © 2018 Microchip Technology Inc.
  • Page 315 RX and TX signals pass through the IRCOM module unaltered. This enables other features through the IRCOM module, such as half-duplex USART, Loop-back testing, and USART RX input from an event channel. TXPL must be configured before the USART transmitter is enabled (TXEN). Datasheet Preliminary DS40002015A-page 315 © 2018 Microchip Technology Inc.
  • Page 316 By leaving this register value to zero, filtering is disabled. Setting this value between 0x01 and 0xFF will enable filtering, where x+1 equal samples are required for the pulse to be accepted. RXPL must be configured before USART receiver is enabled (RXEN). Datasheet Preliminary DS40002015A-page 316 © 2018 Microchip Technology Inc.
  • Page 317: Serial Peripheral Interface (Spi)

    SCK line to exchange data. Data is always shifted from master to slave on the master output, slave input (MOSI) line, and from slave to master on the master input, slave output (MISO) line. Datasheet Preliminary DS40002015A-page 317 © 2018 Microchip Technology Inc.
  • Page 318 In Master mode, the SPI has a clock generator to generate the SCK clock. In Slave mode, the received SCK clock is synchronized and sampled to trigger the shifting of data in the Shift register. Datasheet Preliminary DS40002015A-page 318 © 2018 Microchip Technology Inc.
  • Page 319: Functional Description

    When the SPI is configured in Master mode, a write to the SPIn.DATA register will start a new transfer. The SPI clock generator starts and the hardware shifts the eight bits into the selected slave. After the Datasheet Preliminary DS40002015A-page 319 © 2018 Microchip Technology Inc.
  • Page 320 The First Receive Buffer register has to be read before the next transmission is completed or data will be lost. This register is read by reading SPIn.DATA. The Transmit Buffer register and Second Receive Buffer register are not used in Normal mode. Datasheet Preliminary DS40002015A-page 320 © 2018 Microchip Technology Inc.
  • Page 321 Table 23-3. Overview of the SS Pin Functionality SS Configuration SS Pin-Level Description MISO Pin Mode Port Direction = Port Direction = Output Input Always Input High Slave deactivated Tri-stated Input (deselected) Slave activated Output Input (selected) Datasheet Preliminary DS40002015A-page 321 © 2018 Microchip Technology Inc.
  • Page 322 Figure 23-1. There are two different modes for the Buffer mode, selected with the Buffer mode Wait for Receive bit (BUFWR). The two different modes are described below with timing diagrams. Datasheet Preliminary DS40002015A-page 322 © 2018 Microchip Technology Inc.
  • Page 323 Data Register Empty Interrupt Flag goes high. The Transfer Complete Interrupt Flag is set one cycle after the Receive Complete Interrupt Flag is set when both the value in the shift register and the Transmit Buffer register have been sent. Datasheet Preliminary DS40002015A-page 323 © 2018 Microchip Technology Inc.
  • Page 324 SCK signal, ensuring sufficient time for data signals to stabilize. The leading edge is the first clock edge of a clock cycle. The trailing edge is the last clock edge of a clock cycle. Datasheet Preliminary DS40002015A-page 324 © 2018 Microchip Technology Inc.
  • Page 325 SPI is enabled, in master mode and transmitting. Otherwise, the SCK is not toggling. Refer to the SPI transfer modes as configured in SPIn.CTRLB for the idle state of SCK. SPI has no event inputs. Datasheet Preliminary DS40002015A-page 325 © 2018 Microchip Technology Inc.
  • Page 326 An interrupt request is generated when the corresponding interrupt source is enabled and the interrupt flag is set. The interrupt request remains active until the interrupt flag is cleared. See the peripheral's INTFLAGS register for details on how to clear interrupt flags. Datasheet Preliminary DS40002015A-page 326 © 2018 Microchip Technology Inc.
  • Page 327: Register Summary - Spin

    Bit Pos. 0x00 CTRLA DORD MASTER CLK2X PRESC[1:0] ENABLE 0x01 CTRLB BUFEN BUFWR MODE[1:0] 0x02 Reserved 0x03 INTFLAGS WRCOL 0x03 INTFLAGS RXCIF TXCIF DREIF SSIF BUFOVF 0x04 DATA DATA[7:0] 23.5 Register Description Datasheet Preliminary DS40002015A-page 327 © 2018 Microchip Technology Inc.
  • Page 328 The output of the SPI prescaler can be doubled by writing the CLK2X bit to ’1’. Value Name Description DIV4 CLK_PER/4 DIV16 CLK_PER/16 DIV64 CLK_PER/64 DIV128 CLK_PER/128 Bit 0 – ENABLE SPI Enable Datasheet Preliminary DS40002015A-page 328 © 2018 Microchip Technology Inc.
  • Page 329 ® megaAVR 0-Series Serial Peripheral Interface (SPI) Value Description SPI is disabled SPI is enabled Datasheet Preliminary DS40002015A-page 329 © 2018 Microchip Technology Inc.
  • Page 330 Leading edge: Rising, sample Trailing edge: Falling, setup Leading edge: Rising, setup Trailing edge: Falling, sample Leading edge: Falling, sample Trailing edge: Rising, setup Leading edge: Falling, setup Trailing edge: Rising, sample Datasheet Preliminary DS40002015A-page 330 © 2018 Microchip Technology Inc.
  • Page 331 The WRCOL flag is set if the SPIn.DATA register is written to before a complete byte has been shifted out. This flag is cleared by first reading the SPIn.INTFLAGS register when WRCOL is set, and then accessing the SPIn.DATA register. Datasheet Preliminary DS40002015A-page 331 © 2018 Microchip Technology Inc.
  • Page 332 This flag is valid until the receive buffer (SPIn.DATA) is read. Always write this bit location to ‘0’ when writing the SPIn.INTFLAGS register. Datasheet Preliminary DS40002015A-page 332 © 2018 Microchip Technology Inc.
  • Page 333 SPI output line. Reading this register in Buffer mode will read the second receive buffer and the contents of the first receive buffer will be moved to the second receive buffer. Datasheet Preliminary DS40002015A-page 333 © 2018 Microchip Technology Inc.
  • Page 334: Two-Wire Interface (Twi)

    (Sm) and fast (Fm, Fm+) bus frequencies from 100 kHz up to 1 MHz. A “smart mode” is added that can be enabled to auto-trigger operations and thus reduce software complexity. Datasheet Preliminary DS40002015A-page 334 © 2018 Microchip Technology Inc.
  • Page 335: Functional Description

    TIMEOUT bits are all located in the Master Control A register (TWIn.MCTRLA). If no TIMEOUT value is set, which is the case for I²C operation, the bus state must be manually set to IDLE by writing 0x1 to Datasheet Preliminary DS40002015A-page 335 © 2018 Microchip Technology Inc.
  • Page 336 (R/W) are then sent. After all data packets (DATA) are transferred, the master issues a Stop condition (P) on the bus to end the transaction. The receiver must acknowledge (A) or not-acknowledge (A) each byte received. Figure 24-3 shows a TWI transaction. Datasheet Preliminary DS40002015A-page 336 © 2018 Microchip Technology Inc.
  • Page 337 24-5, a bit transferred on the SDA line must be stable for the entire high period of the SCL line. Consequently, the SDA value can only be changed during the low period of the clock. This is ensured in hardware by the TWI module. Datasheet Preliminary DS40002015A-page 337 © 2018 Microchip Technology Inc.
  • Page 338 If the slave signals a NACK to the data, the master must assume that the slave cannot receive any more data and terminate the transaction. Datasheet Preliminary DS40002015A-page 338 © 2018 Microchip Technology Inc.
  • Page 339 Both the master and slave device can randomly stretch the clock on a byte level basis before and after the ACK/NACK bit. This provides time to process incoming or prepare outgoing data or perform other time-critical tasks. Datasheet Preliminary DS40002015A-page 339 © 2018 Microchip Technology Inc.
  • Page 340 Figure 24-11 shows an example where two masters are competing for control over the bus clock. The SCL line is the wired-AND result of the two masters clock outputs. Datasheet Preliminary DS40002015A-page 340 © 2018 Microchip Technology Inc.
  • Page 341 Figure 24-12. The values of the Bus State bits according to state, are shown in binary in the figure below. Datasheet Preliminary DS40002015A-page 341 © 2018 Microchip Technology Inc.
  • Page 342 The TWI master is byte-oriented, with an optional interrupt after each byte. There are separate interrupt flags for master write and master read. Interrupt flags can also be used for polled operation. There are Datasheet Preliminary DS40002015A-page 342 © 2018 Microchip Technology Inc.
  • Page 343 T will be considered as part of T . Likewise, T will be in a state between T FALL RISE until a high state has been detected. HIGH Datasheet Preliminary DS40002015A-page 343 © 2018 Microchip Technology Inc.
  • Page 344 A bus error will behave in the same way as an arbitration lost condition, but the Bus Error Flag (BUSERR in TWIn.MSTATUS) is set in addition to the write interrupt and arbitration lost flags. Datasheet Preliminary DS40002015A-page 344 © 2018 Microchip Technology Inc.
  • Page 345 R/W. When either RIF or WIF flag is set after issuing a Quick Command, the TWI will accept a stop command through writing the CMD bits in TWIn.MCTRLB. Datasheet Preliminary DS40002015A-page 345 © 2018 Microchip Technology Inc.
  • Page 346 A Start condition immediately followed by a Stop condition is an illegal operation and the bus error flag is set. The R/W direction flag reflects the direction bit received with the address. This can be read by software to determine the type of operation currently in progress. Datasheet Preliminary DS40002015A-page 346 © 2018 Microchip Technology Inc.
  • Page 347 Data register (TWIn.SDATA) is read or written. 24.3.5 Interrupts Table 24-1. Available Interrupt Vectors and Sources Name Vector Description Conditions Slave TWI Slave interrupt • DIF: Data Interrupt Flag in TWIn.SSTATUS set Datasheet Preliminary DS40002015A-page 347 © 2018 Microchip Technology Inc.
  • Page 348 If a slave device is in Sleep mode and a Start condition is detected, clock stretching is active during the wake-up period until the system clock is available. The master will stop operation in all Sleep modes. Datasheet Preliminary DS40002015A-page 348 © 2018 Microchip Technology Inc.
  • Page 349: Register Summary - Twin

    SCTRLA DIEN APIEN PIEN PMEN SMEN ENABLE 0x0A SCTRLB ACKACT SCMD[1:0] 0x0B SSTATUS APIF CLKHOLD RXACK COLL BUSERR 0x0C SADDR ADDR[7:0] 0x0D SDATA DATA[7:0] 0x0E SADDRMASK ADDRMASK[6:0] ADDREN 24.5 Register Description Datasheet Preliminary DS40002015A-page 349 © 2018 Microchip Technology Inc.
  • Page 350 Writing these bits selects the 1 MHz bus speed (Fast mode plus, Fm+) for the TWI in default configuration or for TWI Master in dual mode configuration. Value Description Fm+ disabled Fm+ enabled Datasheet Preliminary DS40002015A-page 350 © 2018 Microchip Technology Inc.
  • Page 351 This bit selects the 1 MHz bus speed for the TWI Slave. This bit is ignored if the TWI is not selected in bridge configuration. Bit 0 – ENABLE Enable This bit selects the bridge mode configuration. Datasheet Preliminary DS40002015A-page 351 © 2018 Microchip Technology Inc.
  • Page 352 Bit 0 – DBGRUN  Debug Run Value Description The peripheral is halted in Break Debug mode and ignores events. The peripheral will continue to run in Break Debug mode when the CPU is halted. Datasheet Preliminary DS40002015A-page 352 © 2018 Microchip Technology Inc.
  • Page 353 Writing this bit to '1' enables the Master Smart mode. When Smart mode is enabled, the acknowledge action is sent immediately after reading the Master Data (TWIn.MDATA) register. Bit 0 – ENABLE Enable TWI Master Writing this bit to '1' enables the TWI as master. Datasheet Preliminary DS40002015A-page 353 © 2018 Microchip Technology Inc.
  • Page 354 Writing to these bits triggers a master operation as defined by the table below. Table 24-4. Command Settings MCMD[1:0] DIR Description NOACT - No action REPSTART - Execute Acknowledge Action succeeded by repeated Start. RECVTRANS - Execute Acknowledge Action succeeded by a byte read operation. Datasheet Preliminary DS40002015A-page 354 © 2018 Microchip Technology Inc.
  • Page 355 For a master being a sender, it will normally wait for new data written to the Master Data register (TWIn.MDATA). The acknowledge action bits and command bits can be written at the same time. Datasheet Preliminary DS40002015A-page 355 © 2018 Microchip Technology Inc.
  • Page 356 CLKHOLD flag to be cleared by this method, since the flag is automatically cleared when accessing several other TWI registers. The CLKHOLD flag can be cleared by: Writing a '1' to it. Writing to the TWIn.MADDR register. Datasheet Preliminary DS40002015A-page 356 © 2018 Microchip Technology Inc.
  • Page 357 When the master is disabled, the bus state is 'unknown'. Value Name Description UNKNOWN Unknown bus state IDLE Bus is idle OWNER This TWI controls the bus BUSY The bus is busy Datasheet Preliminary DS40002015A-page 357 © 2018 Microchip Technology Inc.
  • Page 358 This bit field is used to derive the SCL high and low time and should be written while the master is disabled (ENABLE bit in TWIn.MCTRLA is '0'). For more information on how to calculate the frequency, see the section on Clock Generation. Datasheet Preliminary DS40002015A-page 358 © 2018 Microchip Technology Inc.
  • Page 359 The master control logic uses bit 0 of the TWIn.MADDR register as the bus protocol’s Read/Write flag (R/W). Datasheet Preliminary DS40002015A-page 359 © 2018 Microchip Technology Inc.
  • Page 360 Master Write Interrupt flag (WIF) is set instead. Observe that the two Master Interrupt Flags are mutually exclusive (i.e., both flags will not be set simultaneously). Datasheet Preliminary DS40002015A-page 360 © 2018 Microchip Technology Inc.
  • Page 361 Both TWI Master Interrupt Flags are cleared automatically if this register is read while ACKACT is set to either ACK or NACK. However, arbitration lost and bus error flags are left unchanged. Datasheet Preliminary DS40002015A-page 361 © 2018 Microchip Technology Inc.
  • Page 362 CMD or reading/writing DATA resets the interrupt and operation continues. If the Smart mode is disabled, the slave always waits for a CMD command before continuing. Bit 0 – ENABLE Enable TWI Slave Writing this bit to '1' enables the TWI slave. Datasheet Preliminary DS40002015A-page 362 © 2018 Microchip Technology Inc.
  • Page 363 Execute Acknowledge Action succeeded by slave data interrupt. Used in response to a data interrupt (DIF). Execute Acknowledge Action succeeded by reception of next byte. Execute a byte read operation followed by Acknowledge Action. Datasheet Preliminary DS40002015A-page 363 © 2018 Microchip Technology Inc.
  • Page 364 ® megaAVR 0-Series Two-Wire Interface (TWI) The acknowledge action bits and command bits can be written at the same time. Datasheet Preliminary DS40002015A-page 364 © 2018 Microchip Technology Inc.
  • Page 365 This bit is read-only and contains the most recently received Acknowledge bit from the master. When read as zero, the most recent acknowledge bit from the master was ACK. When read as one, the most recent acknowledge bit was NACK. Datasheet Preliminary DS40002015A-page 365 © 2018 Microchip Technology Inc.
  • Page 366 When the TWI slave address or Stop Interrupt Flag (APIF) is set, this bit determines whether the interrupt is due to address detection or a Stop condition. Value Name Description STOP A Stop condition generated the interrupt on APIF Address detection generated the interrupt on APIF Datasheet Preliminary DS40002015A-page 366 © 2018 Microchip Technology Inc.
  • Page 367 The TWI slave address match logic only supports recognition of the first byte of a 10-bit address (i.e., by setting ADDRA[7:1] = “0b11110aa” where “aa” represents bit 9 and 8, or the slave address). The second 10-bit address byte must be handled by software. Datasheet Preliminary DS40002015A-page 367 © 2018 Microchip Technology Inc.
  • Page 368 Accessing the slave DATA register, assumed that clock hold is active, auto-trigger bus operations dependent of the state of the Slave Acknowledge Action Command bits (ACKACT) and type of register access (read or write). Datasheet Preliminary DS40002015A-page 368 © 2018 Microchip Technology Inc.
  • Page 369 If this bit is written to '1', the slave address match logic responds to the two unique addresses in slave TWIn.SADDR and TWIn.SADDRMASK. If this bit is '0', the TWIn.SADDRMASK register acts as a mask to the TWIn.SADDR register. Datasheet Preliminary DS40002015A-page 369 © 2018 Microchip Technology Inc.
  • Page 370: Cyclic Redundancy Check Memory Scan (Crcscan)

    If the last bytes in the section contain the correct checksum, the CRC will pass. See Checksum for how to place the checksum. The initial value of the checksum register is 0xFFFF. Figure 25-1. CRC Implementation Description data Datasheet Preliminary DS40002015A-page 370 © 2018 Microchip Technology Inc.
  • Page 371: Functional Description

    CPU until completed. In Priority mode, the CRC fetches a new word (16-bit) on every third main clock cycle, or when the CRC peripheral is configured to do a scan from startup. Datasheet Preliminary DS40002015A-page 371 © 2018 Microchip Technology Inc.
  • Page 372 There are synchronized CRC Status bits in the debugger's internal register space, which can Datasheet Preliminary DS40002015A-page 372 © 2018 Microchip Technology Inc.
  • Page 373 Writing the OK bit to '1' will make the OK bit read as '1' when the BUSY bit in CRCSCAN.STATUS is '0'. Writes to CRCSCAN.CTRLA and CRCSCAN.CTRLB from the debugger are treated in the same way as writes from the CPU. Datasheet Preliminary DS40002015A-page 373 © 2018 Microchip Technology Inc.
  • Page 374: Register Summary - Crcscan

    0-Series Cyclic Redundancy Check Memory Scan (CRCSCAN... 25.4 Register Summary - CRCSCAN Offset Name Bit Pos. 0x00 CTRLA RESET NMIEN ENABLE 0x01 CTRLB SRC[1:0] 0x02 STATUS BUSY 25.5 Register Description Datasheet Preliminary DS40002015A-page 374 © 2018 Microchip Technology Inc.
  • Page 375 ENABLE bit will read as ’1’ when normal code execution starts. To see whether the CRCSCAN peripheral is busy with an ongoing check, poll the Busy bit (BUSY) in the Status register (CRCSCAN.STATUS). Datasheet Preliminary DS40002015A-page 375 © 2018 Microchip Technology Inc.
  • Page 376 The CRC is performed on the entire Flash (boot, application code, and application data sections). BOOTAPP The CRC is performed on the boot and application code sections of Flash. BOOT The CRC is performed on the boot section of Flash. Reserved. Datasheet Preliminary DS40002015A-page 376 © 2018 Microchip Technology Inc.
  • Page 377 Bit 0 – BUSY CRC Busy When this bit is read as ‘1’, the CRC module is busy. As long as the module is busy, the access to the control registers is limited. Datasheet Preliminary DS40002015A-page 377 © 2018 Microchip Technology Inc.
  • Page 378: Ccl - Configurable Custom Logic

    LUT outputs. An optional Sequential module can be enabled. The inputs to the Sequential module are individually controlled by two independent, adjacent LUT outputs, enabling complex waveform generation. Datasheet Preliminary DS40002015A-page 378 © 2018 Microchip Technology Inc.
  • Page 379 INSEL0 INSEL1 INSEL2 0x00 MASK None 0x01 FEEDBACK LUTn 0x02 LINK LUT(n+1) 0x03 EVENTA EVENTA 0x04 EVENTB EVENTB 0x05 0x06 AC0 OUT 0x07 0x08 USART USART0 TXD USART1 TXD USART2 TXD Datasheet Preliminary DS40002015A-page 379 © 2018 Microchip Technology Inc.
  • Page 380: Functional Description

    CCL.TRUTHn registers. Each combination of the input bits (IN[2:0]) corresponds to one bit in the TRUTHn register, as shown in the table below. Table 26-1. Truth Table of LUT IN[2] IN[1] IN[0] TRUTH[0] TRUTH[1] Datasheet Preliminary DS40002015A-page 380 © 2018 Microchip Technology Inc.
  • Page 381 LUT0 and LUT1. The sequential selection for each LUT follows the formula: IN 2N+1 � = SEQ � With N representing the sequencer number and i representing the index of the input LUT. Datasheet Preliminary DS40002015A-page 381 © 2018 Microchip Technology Inc.
  • Page 382 (EVENTA and EVENTB) are available, and can be selected as LUT input. Before selecting the EVENT input option by writing to the LUT CONTROL A or B register (CCL.LUTnCTRLB or LUTnCTRLC), the Event System must be configured. Datasheet Preliminary DS40002015A-page 382 © 2018 Microchip Technology Inc.
  • Page 383 The edge detector can be used to generate a pulse when detecting a rising edge on its input. To detect a falling edge, the TRUTH table should be programmed to provide inverted output. Datasheet Preliminary DS40002015A-page 383 © 2018 Microchip Technology Inc.
  • Page 384 Gated D Flip-Flop (DFF) The D-input is driven by the even LUT output (LUT2n), and the G-input is driven by the odd LUT output (LUT2n+1). Figure 26-7. D Flip-Flop even LUT CLK_MUX_OUT odd LUT Datasheet Preliminary DS40002015A-page 384 © 2018 Microchip Technology Inc.
  • Page 385 The D-input is driven by the even LUT output (LUT2n), and the G-input is driven by the odd LUT output (LUT2n+1). Figure 26-9. D-Latch even LUT odd LUT Table 26-4. D-Latch Characteristics Hold state (no change) Clear Datasheet Preliminary DS40002015A-page 385 © 2018 Microchip Technology Inc.
  • Page 386 The CCL peripheral must be disabled while changing the clock source to avoid undefined outputs from the peripheral. 26.3.3 Interrupts Table 26-6. Available Interrupt Vectors and Sources Name Vector Description Conditions CCL interrupt INTn in INTFLAG is raised as configured by INTMODEn bits in CCL.INTCTRLn Datasheet Preliminary DS40002015A-page 386 © 2018 Microchip Technology Inc.
  • Page 387 LUT input 2 (IN[2]) will always clock the Filter, Edge Detector, and Sequential block. The availability of the IN[2] clock in sleep modes will depend on the sleep settings of the peripheral employed. Datasheet Preliminary DS40002015A-page 387 © 2018 Microchip Technology Inc.
  • Page 388: Register Summary - Ccl

    ENABLE 0x09 LUT0CTRLB INSEL1[3:0] INSEL0[3:0] 0x0A LUT0CTRLC INSEL2[3:0] 0x0B TRUTH0 TRUTH[7:0] 0x0C LUT1CTRLA EDGEDET OUTEN FILTSEL[1:0] CLKSRC[2:0] ENABLE 0x0D LUT1CTRLB INSEL1[3:0] INSEL0[3:0] 0x0E LUT1CTRLC INSEL2[3:0] 0x0F TRUTH1 TRUTH[7:0] 26.5 Register Description Datasheet Preliminary DS40002015A-page 388 © 2018 Microchip Technology Inc.
  • Page 389 System clock is not required in Standby Sleep mode System clock is required in Standby Sleep mode Bit 0 – ENABLE Enable Value Description The peripheral is disabled The peripheral is enabled Datasheet Preliminary DS40002015A-page 389 © 2018 Microchip Technology Inc.
  • Page 390 The bits in SEQSELn select the sequential configuration for LUT[2n] and LUT[2n+1]. Value Name Description DISABLE Sequential logic is disabled D flip flop JK flip flop LATCH D latch RS latch Other Reserved Datasheet Preliminary DS40002015A-page 390 © 2018 Microchip Technology Inc.
  • Page 391 Bits 0:1, 2:3, 4:5, 6:7 – INTMODE The bits in INTMODEn select the interrupt sense configuration for LUTn-OUT. Value Name Description BOTH Sense both edges FALLING Sense falling edge RISING Sense rising edge INTDISABLE Interrupt disabled Datasheet Preliminary DS40002015A-page 391 © 2018 Microchip Technology Inc.
  • Page 392 Bits 0, 1, 2, 3 – INT Interrupt Flag The INTn flag is set when LUTn output change matches the interrupt sense mode as defined in CCL.INTCTRLn. Writing a '1' to this flag's bit location will clear the flag. Datasheet Preliminary DS40002015A-page 392 © 2018 Microchip Technology Inc.
  • Page 393 The CLK_MUX_OUT of the even LUT is used for clocking the Sequential block of a LUT pair. Value Name Description CLKPER None (masked) LUT input 2 Reserved Reserved OSC20M 20MHz internal oscillator Datasheet Preliminary DS40002015A-page 393 © 2018 Microchip Technology Inc.
  • Page 394 CCL – Configurable Custom Logic Value Name Description OSCULP32K 32.768kHz internal oscillator OSCULP1K 1.024kHz from internal oscillator Reserved Bit 0 – ENABLE LUT Enable Value Description The LUT is disabled. The LUT is enabled. Datasheet Preliminary DS40002015A-page 394 © 2018 Microchip Technology Inc.
  • Page 395 SPI0 MOSI TCA0 TCA0 WO1 Reserved TCB1 TCB1 WO Other Reserved Bits 3:0 – INSEL0[3:0] LUT n Input 0 Source Selection These bits select the source for input 0 of LUT n: Datasheet Preliminary DS40002015A-page 395 © 2018 Microchip Technology Inc.
  • Page 396 Feedback input LINK Output from LUTn+1 EVENTA Event CCL-LUTnA EVENTB Event CCL-LUTnB I/O-pin LUTn-IN0 AC0 out Reserved USART0 USART0 TXD SPI0 SPI0 MOSI TCA0 TCA0 WO1 Reserved TCB0 TCB0 WO Other Reserved Datasheet Preliminary DS40002015A-page 396 © 2018 Microchip Technology Inc.
  • Page 397 Feedback input LINK Output from LUTn+1 EVENTA Event CCL-LUTnA EVENTB Event CCL-LUTnB I/O-pin LUTn-IN0 AC0 out Reserved USART2 USART0 TXD SPI0 SPI0 SCK TCA0 TCA0 WO1 Reserved TCB2 TCB2 WO Other Reserved Datasheet Preliminary DS40002015A-page 397 © 2018 Microchip Technology Inc.
  • Page 398 Offset:  0x0B + n*0x04 [n=0..1] Reset:  0x00 Property:  Enable-Protected TRUTH[7:0] Access Reset Bits 7:0 – TRUTH[7:0] Truth Table These bits define the value of truth logic as a function of inputs IN[2:0]. Datasheet Preliminary DS40002015A-page 398 © 2018 Microchip Technology Inc.
  • Page 399: Analog Comparator (Ac)

    An AC has one positive input and one negative input. The digital output from the comparator is '1' when the difference between the positive and the negative input voltage is positive, and '0' otherwise. Datasheet Preliminary DS40002015A-page 399 © 2018 Microchip Technology Inc.
  • Page 400: Functional Description

    The input hysteresis can either be disabled or have one of three levels. The hysteresis is configured by writing to the Hysteresis Mode Select bit field (HYSMODE) in the Control A register (ACn.CTRLA). Datasheet Preliminary DS40002015A-page 400 © 2018 Microchip Technology Inc.
  • Page 401 Conditions COMP Analog comparator interrupt AC output is toggling as configured by INTMODE in ACn.CTRLA When an interrupt condition occurs, the corresponding Interrupt Flag is set in the Status register (ACn.STATUS). Datasheet Preliminary DS40002015A-page 401 © 2018 Microchip Technology Inc.
  • Page 402 Event, Interrupt, and AC output on pad even if the CLK_PER is not running in Standby sleep mode. In Power Down sleep mode, the AC and the output to the pad are disabled. Datasheet Preliminary DS40002015A-page 402 © 2018 Microchip Technology Inc.
  • Page 403: Register Summary - Ac

    Bit Pos. 0x00 CTRLA RUNSTDBY OUTEN INTMODE[1:0] LPMODE HYSMODE[1:0] ENABLE 0x01 Reserved 0x02 MUXCTRL INVERT MUXPOS[1:0] MUXNEG[1:0] 0x03 Reserved 0x04 DACREF DACREF[7:0] 0x05 Reserved 0x06 INTCTRL 0x07 STATUS STATE 27.5 Register Description Datasheet Preliminary DS40002015A-page 403 © 2018 Microchip Technology Inc.
  • Page 404 Bits 2:1 – HYSMODE[1:0] Hysteresis Mode Select Writing these bits select the hysteresis mode for the AC input. Value Name Description NONE No hysteresis SMALL Small hysteresis MEDIUM Medium hysteresis LARGE Large hysteresis Datasheet Preliminary DS40002015A-page 404 © 2018 Microchip Technology Inc.
  • Page 405 ® megaAVR 0-Series Analog Comparator (AC) Bit 0 – ENABLE Enable AC Writing this bit to '1' enables the AC. Datasheet Preliminary DS40002015A-page 405 © 2018 Microchip Technology Inc.
  • Page 406 Writing to this bit field selects the input signal to the negative input of the AC. Value Name Description AINN0 Negative pin 0 AINN1 Negative pin 1 AINN2 Negative pin 2 DACREF Internal DAC reference Datasheet Preliminary DS40002015A-page 406 © 2018 Microchip Technology Inc.
  • Page 407 These bits define the output voltage from the internal voltage divider. The DAC reference is divided from DACREF on the selections in the VREF module and the output voltage is defined by: � × � DACREF Datasheet Preliminary DS40002015A-page 407 © 2018 Microchip Technology Inc.
  • Page 408 Analog Comparator (AC) 27.5.4 Interrupt Control Name:  INTCTRL Offset:  0x06 Reset:  0x00 Property:  - Access Reset Bit 0 – CMP  Analog Comparator Interrupt Enable Writing this bit to '1' enables Analog Comparator Interrupt. Datasheet Preliminary DS40002015A-page 408 © 2018 Microchip Technology Inc.
  • Page 409 I/O register (three cycles). Bit 0 – CMP Analog Comparator Interrupt Flag This is the interrupt flag for AC. Writing a ‘1’ to this bit will clear the Interrupt flag. Datasheet Preliminary DS40002015A-page 409 © 2018 Microchip Technology Inc.
  • Page 410: Analog-To-Digital Converter (Adc)

    A window compare feature is available for monitoring the input signal and can be configured to only trigger an interrupt on user-defined thresholds for under, over, inside, or outside a window, with minimum software intervention required. Datasheet Preliminary DS40002015A-page 410 © 2018 Microchip Technology Inc.
  • Page 411 . Several parameters describe the deviation from the ideal behavior: Offset Error The deviation of the first transition (0x000 to 0x001) compared to the ideal transition (at 0.5 LSB). Ideal value: 0 LSB. Datasheet Preliminary DS40002015A-page 411 © 2018 Microchip Technology Inc.
  • Page 412 After adjusting for offset and gain error, the INL is the maximum deviation of an Linearity (INL) actual transition compared to an ideal transition for any code. Ideal value: 0 LSB. Datasheet Preliminary DS40002015A-page 412 © 2018 Microchip Technology Inc.
  • Page 413: Functional Description

    Configure the resolution by writing to the Resolution Selection bit (RESSEL) in the Control A register (ADCn.CTRLA). Optional: Enable the Free-Running mode by writing a ’1’ to the Free-Running bit (FREERUN) in ADCn.CTRLA. Datasheet Preliminary DS40002015A-page 413 © 2018 Microchip Technology Inc.
  • Page 414 Input bit (STARTEI) in the Event Control register (ADCn.EVCTRL). Any incoming event routed to the ADC through the Event System (EVSYS) will trigger an ADC conversion. This provides a method to start conversions at predictable intervals or at specific conditions. Datasheet Preliminary DS40002015A-page 414 © 2018 Microchip Technology Inc.
  • Page 415 CLK_ADC clock cycle. The prescaler is kept reset as long as there is no ongoing conversion. This PRESC assures a fixed delay from the trigger to the actual start of a conversion in CLK_PER cycles as: StartDelay = factor Datasheet Preliminary DS40002015A-page 415 © 2018 Microchip Technology Inc.
  • Page 416 CLK_ADC cycles) In Free-Running mode, a new conversion will be started immediately after the conversion completes, while the STCONV bit is one. The sampling rate R in free-running mode is calculated by: Datasheet Preliminary DS40002015A-page 416 © 2018 Microchip Technology Inc.
  • Page 417 , configure ADCnREFSEL[0:2] in the corresponding REFA VREF.CTRLn register to the value that is closest, but above the applied reference voltage. For external references higher than 4.3V, use ADCnREFSEL[0:2] = 0x3. Datasheet Preliminary DS40002015A-page 417 © 2018 Microchip Technology Inc.
  • Page 418 The individual compensation factors are determined during the production test and saved in the Signature Row: • SIGROW.TEMPSENSE0 is a gain/slope correction Datasheet Preliminary DS40002015A-page 418 © 2018 Microchip Technology Inc.
  • Page 419 An ADC conversion can be triggered automatically by an event input if the Start Event Input bit (STARTEI) in the Event Control register (ADCn.EVCTRL) is written to '1'. See also the description of the Asynchronous User Channel n Input Selection in the Event System (EVSYS.ASYNCUSERn). Datasheet Preliminary DS40002015A-page 419 © 2018 Microchip Technology Inc.
  • Page 420 At the end of conversion, the Result Ready Flag (RESRDY) will be set, but the content of the result registers (ADCn.RES) is invalid since the ADC was halted in the middle of a conversion. Datasheet Preliminary DS40002015A-page 420 © 2018 Microchip Technology Inc.
  • Page 421: Register Summary - Adcn

    WCOMP RESRDY 0x0C DBGCTRL DBGRUN 0x0D TEMP TEMP[7:0] 0x0E Reserved 0x0F RES[7:0] 0x10 15:8 RES[15:8] WINLT[7:0] 0x12 WINLT 15:8 WINLT[15:8] WINHT[7:0] 0x14 WINHT 15:8 WINHT[15:8] 0x16 CALIB DUTYCYC 28.5 Register Description Datasheet Preliminary DS40002015A-page 421 © 2018 Microchip Technology Inc.
  • Page 422 This is signaled by the RESRDY flag in ADCn.INTFLAGS. Bit 0 – ENABLE ADC Enable Value Description ADC is disabled ADC is enabled Datasheet Preliminary DS40002015A-page 422 © 2018 Microchip Technology Inc.
  • Page 423 Value Name Description NONE No accumulation. ACC2 2 results accumulated. ACC4 4 results accumulated. ACC8 8 results accumulated. ACC16 16 results accumulated. ACC32 32 results accumulated. ACC64 64 results accumulated. Reserved. Datasheet Preliminary DS40002015A-page 423 © 2018 Microchip Technology Inc.
  • Page 424 CLK_PER divided by 4 DIV8 CLK_PER divided by 8 DIV16 CLK_PER divided by 16 DIV32 CLK_PER divided by 32 DIV64 CLK_PER divided by 64 DIV128 CLK_PER divided by 128 DIV256 CLK_PER divided by 256 Datasheet Preliminary DS40002015A-page 424 © 2018 Microchip Technology Inc.
  • Page 425 ASDV bit. The delay is expressed as CLK_ADC cycles and is given directly by the bitfield setting. The sampling cap is kept open during the delay. Datasheet Preliminary DS40002015A-page 425 © 2018 Microchip Technology Inc.
  • Page 426 Value Name Description NONE No Window Comparison (default) BELOW RESULT < WINLT ABOVE RESULT > WINHT INSIDE WINLT < RESULT < WINHT OUTSIDE RESULT < WINLT or RESULT >WINHT) Other Reserved Datasheet Preliminary DS40002015A-page 426 © 2018 Microchip Technology Inc.
  • Page 427 These bits extend the ADC sampling length in a number of CLK_ADC cycles. By default, the sampling time is two CLK_ADC cycles. Increasing the sampling length allows sampling sources with higher impedance. The total conversion time increases with the selected sampling length. Datasheet Preliminary DS40002015A-page 427 © 2018 Microchip Technology Inc.
  • Page 428 MUXPOS Name Input 0x00-0x0F AIN0-AIN15 ADC input pin 0 - 15 0x10-0x1B Reserved 0x1C DACREF0 DAC reference in AC0 0x1D Reserved 0x1E TEMPSENSE Temperature Sensor 0x1F Other Reserved Datasheet Preliminary DS40002015A-page 428 © 2018 Microchip Technology Inc.
  • Page 429 Writing a '1' to this bit will start a single measurement. If in Free-Running mode this will start the first conversion. STCONV will read as '1' as long as a conversion is in progress. When the conversion is complete, this bit is automatically cleared. Datasheet Preliminary DS40002015A-page 429 © 2018 Microchip Technology Inc.
  • Page 430 Event Control Name:  EVCTRL Offset:  0x09 Reset:  0x00 Property:  - STARTEI Access Reset Bit 0 – STARTEI Start Event Input This bit enables using the event input as trigger for starting a conversion. Datasheet Preliminary DS40002015A-page 430 © 2018 Microchip Technology Inc.
  • Page 431 Bit 1 – WCOMP Window Comparator Interrupt Enable Writing a '1' to this bit enables window comparator interrupt. Bit 0 – RESRDY Result Ready Interrupt Enable Writing a '1' to this bit enables result ready interrupt. Datasheet Preliminary DS40002015A-page 431 © 2018 Microchip Technology Inc.
  • Page 432 The result ready interrupt flag is set when a measurement is complete and a new result is ready. The flag is cleared by either writing a '1' to the bit location or by reading the Result register (ADCn.RES). Writing a '0' to this bit has no effect. Datasheet Preliminary DS40002015A-page 432 © 2018 Microchip Technology Inc.
  • Page 433 Bit 0 – DBGRUN Debug Run Value Description The peripheral is halted in Break Debug mode and ignores events The peripheral will continue to run in Break Debug mode when the CPU is halted Datasheet Preliminary DS40002015A-page 433 © 2018 Microchip Technology Inc.
  • Page 434 It can be read and written by software. Refer to 16-bit access in the AVR CPU chapter. There is one common Temporary register for all the 16-bit registers of this peripheral. TEMP[7:0] Access Reset Bits 7:0 – TEMP[7:0] Temporary Temporary register for read/write operations in 16-bit registers. Datasheet Preliminary DS40002015A-page 434 © 2018 Microchip Technology Inc.
  • Page 435 These bits constitute the LSB of ADC/Accumulator Result, (ADCn.RES) register. The data format in ADC and Digital Accumulation is 1’s complement, where 0x0000 represents the zero and 0xFFFF represents the largest number (full scale). Datasheet Preliminary DS40002015A-page 435 © 2018 Microchip Technology Inc.
  • Page 436 Bits 15:8 – WINLT[15:8] Window Comparator Low Threshold High Byte These bits hold the MSB of the 16-bit register. Bits 7:0 – WINLT[7:0] Window Comparator Low Threshold Low Byte These bits hold the LSB of the 16-bit register. Datasheet Preliminary DS40002015A-page 436 © 2018 Microchip Technology Inc.
  • Page 437 Bits 15:8 – WINHT[15:8] Window Comparator High Threshold High Byte These bits hold the MSB of the 16-bit register. Bits 7:0 – WINHT[7:0] Window Comparator High Threshold Low Byte These bits hold the LSB of the 16-bit register. Datasheet Preliminary DS40002015A-page 437 © 2018 Microchip Technology Inc.
  • Page 438 > 1.5 MHz requires a minimum operating voltage of 2.7V Value Description 50% Duty Cycle must be used if ADC > 1.5 MHz 25% Duty Cycle (high 25% and low 75%) must be used for ADC ≤ 1.5 MHz Datasheet Preliminary DS40002015A-page 438 © 2018 Microchip Technology Inc.
  • Page 439: Unified Program And Debug Interface (Updi)

    The Asynchronous System Interface (ASI) provides direct interface access to On-Chip Debugging (OCD), NVM, and System Management features. This gives the debugger direct access to system information, without requesting bus access. Datasheet Preliminary DS40002015A-page 439 © 2018 Microchip Technology Inc.
  • Page 440 ASI, and the default UPDI clock start-up frequency is 4 MHz after enabling the UPDI. The UPDI clock frequency is changed by writing the UPDICLKSEL bits in the ASI_CTRLA register. Datasheet Preliminary DS40002015A-page 440 © 2018 Microchip Technology Inc.
  • Page 441: Functional Description

    In addition to the data frame, there are several control frames which are important to the communication. The supported frame formats are presented in Figure 29-3. Datasheet Preliminary DS40002015A-page 441 © 2018 Microchip Technology Inc.
  • Page 442 There is no writable baud rate register in the UPDI, so the baud rate sampled from the SYNCH character is used for data recovery by sampling the Start bit, and performing a majority vote on the middle samples. Datasheet Preliminary DS40002015A-page 442 © 2018 Microchip Technology Inc.
  • Page 443 SYNCH character. If the communication error was due to an incorrect sampling of the SYNCH character, the baud rate is unknown to the connected debugger. For this reason, Datasheet Preliminary DS40002015A-page 443 © 2018 Microchip Technology Inc.
  • Page 444 UPDI for communication. If the Start bit of the SYNCH character is not sent well within maximum T , the UPDI will disable itself, and the enable sequence must be repeated. This time DebZ Datasheet Preliminary DS40002015A-page 444 © 2018 Microchip Technology Inc.
  • Page 445 GTVAL in UPDI.CTRLA. The duration of each IDLE bit is given by the baud rate used by the current transmission. It is not recommended to use GTVAL setting 0x7, with no additional IDLE bits. Datasheet Preliminary DS40002015A-page 445 © 2018 Microchip Technology Inc.
  • Page 446 All instructions are byte instructions and must be preceded by a SYNCH character to determine the baud rate for the communication. See UPDI UART for information about setting the baud rate for the transmission. The following figure gives an overview of the UPDI instruction set. Datasheet Preliminary DS40002015A-page 446 © 2018 Microchip Technology Inc.
  • Page 447 S IB – S y s t e m I n f o r m a t i o n B l o c k s e l . R e c e iv e K E Y S e n d S I B Datasheet Preliminary DS40002015A-page 447 © 2018 Microchip Technology Inc.
  • Page 448 The size of the address and data operands are given by the size fields presented in the figure below. The maximum size for both address and data is 16 bits. STS supports repeated memory access when combined with the REPEAT instruction. Datasheet Preliminary DS40002015A-page 448 © 2018 Microchip Technology Inc.
  • Page 449 LD instruction is used with REPEAT. It is also possible to do an LD of the UPDI Pointer register. The maximum supported size for address and data load is 16 bits. Datasheet Preliminary DS40002015A-page 449 © 2018 Microchip Technology Inc.
  • Page 450 ST instruction is used with REPEAT. ST is also used to store the UPDI Address Pointer into the Pointer register. The maximum supported size for storing address and data is 16 bits. Datasheet Preliminary DS40002015A-page 450 © 2018 Microchip Technology Inc.
  • Page 451 SizeD field of the instruction after the write is executed • Set the SizeD field in the instruction to the desired data size • After sending the ST instruction, send SizeD bytes of address data Datasheet Preliminary DS40002015A-page 451 © 2018 Microchip Technology Inc.
  • Page 452 The total address space for STCS is 16 bytes, and can only access the internal UPDI register space. This instruction only supports byte access, and data size is not configurable. Datasheet Preliminary DS40002015A-page 452 © 2018 Microchip Technology Inc.
  • Page 453 The instruction that is loaded directly after the REPEAT instruction will be repeated RPT_0 times. The instruction will be issued a total of RPT_0 + 1 times. An ongoing repeat can only be aborted by sending a BREAK character. Datasheet Preliminary DS40002015A-page 453 © 2018 Microchip Technology Inc.
  • Page 454 For the KEY instruction, only 64-bit KEY size is supported. If the System Information Block (SIB) field of the KEY instruction is set, the KEY instruction returns the SIB instead of expecting incoming KEY bytes. Maximum supported size for SIB is 128 bits. Datasheet Preliminary DS40002015A-page 454 © 2018 Microchip Technology Inc.
  • Page 455 UPDI event. One particular thing is that if the capture is set up to trigger an interrupt, the first captured value should be ignored. The second captured value based Datasheet Preliminary DS40002015A-page 455 © 2018 Microchip Technology Inc.
  • Page 456 Debugger Processing Figure 29-17, GT denotes the Guard Time insertion, SB is for Stop Bit and IB is the inserted interbyte delay. The rest of the frames are data and instructions. Datasheet Preliminary DS40002015A-page 456 © 2018 Microchip Technology Inc.
  • Page 457 KEY signatures that must be shifted in to activate the interfaces. Table 29-5. KEY Activation Signatures KEY Name KEY Signature (LSB Written Size First) Chip Erase 0x4E564D4572617365 64 bits NVMPROG 0x4E564D50726F6720 64 bits USERROW-Write 0x4E564D5573267465 64 bits Datasheet Preliminary DS40002015A-page 457 © 2018 Microchip Technology Inc.
  • Page 458 The User Row Programming feature allows the user to program new values to the User Row (USERROW) on a locked device. To program with this functionality enabled, the following sequence should be followed. Datasheet Preliminary DS40002015A-page 458 © 2018 Microchip Technology Inc.
  • Page 459 It is possible to prevent the system clock from stopping when going into Sleep mode, by writing the CLKREQ bit in UPDI.ASI_SYS_CTRL to '1'. If this bit is set, the system Sleep mode state is emulated, Datasheet Preliminary DS40002015A-page 459 © 2018 Microchip Technology Inc.
  • Page 460 UPDI to access the system bus and read the peripheral registers even in the deepest Sleep modes. CLKREQ in UPDI.ASI_SYS_CTRL is by default '1', which means that the default operation is keeping the system clock on during Sleep modes. Datasheet Preliminary DS40002015A-page 460 © 2018 Microchip Technology Inc.
  • Page 461: Register Summary - Updi

    These registers are readable only through the UPDI with special instructions and are NOT readable through the CPU. Registers at offset addresses 0x0-0x3 are the UPDI Physical configuration registers. Registers at offset addresses 0x4-0xC are the ASI level registers. Datasheet Preliminary DS40002015A-page 461 © 2018 Microchip Technology Inc.
  • Page 462 Status A Name:  STATUSA Offset:  0x00 Reset:  0x10 Property:  - UPDIREV[3:0] Access Reset Bits 7:4 – UPDIREV[3:0] UPDI Revision These bits are read-only and contain the revision of the current UPDI implementation. Datasheet Preliminary DS40002015A-page 462 © 2018 Microchip Technology Inc.
  • Page 463 Examples of error cases are system domain in Sleep or system domain Reset. Clock Recovery error Wrong sampling of frame Start bit Reserved Reserved Reserved Contention error Signalize Driving Contention on the UPDI RXD/TXD line Datasheet Preliminary DS40002015A-page 463 © 2018 Microchip Technology Inc.
  • Page 464 UPDI Guard Time: 32 cycles UPDI Guard Time: 16 cycles UPDI Guard Time: 8 cycles UPDI Guard Time: 4 cycles UPDI Guard Time: 2 cycles GT off (no extra Idle bits inserted) Datasheet Preliminary DS40002015A-page 464 © 2018 Microchip Technology Inc.
  • Page 465 Writing a '1' to this bit disables the UPDI PHY interface. The clock request from the UPDI is lowered, and the UPDI is reset. All UPDI PHY configurations and KEYs will be reset when the UPDI is disabled. Datasheet Preliminary DS40002015A-page 465 © 2018 Microchip Technology Inc.
  • Page 466 This bit is set to '1' if the CHIPERASE KEY is active. This bit will automatically be reset when the Chip Erase sequence is completed. Otherwise, this bit reads as zero. Datasheet Preliminary DS40002015A-page 466 © 2018 Microchip Technology Inc.
  • Page 467 If this bit is '1', the UPDI has an active Reset request to the system. All other bits will read as '0'. The UPDI will not be reset when issuing a System Reset from this register. Datasheet Preliminary DS40002015A-page 467 © 2018 Microchip Technology Inc.
  • Page 468 MHz. Any other clock output selection is only recommended when the BOD is at the highest level. For all other BOD settings, the default 4 MHz selection is recommended. Value Description Reserved 16 MHz UPDI clock 8 MHz UPDI clock 4 MHz UPDI clock (Default Setting) Datasheet Preliminary DS40002015A-page 468 © 2018 Microchip Technology Inc.
  • Page 469 Writing a zero to this bit will lower the clock request. This bit will be reset when the UPDI is disabled. This bit is set by default when the UPDI is enabled. Datasheet Preliminary DS40002015A-page 469 © 2018 Microchip Technology Inc.
  • Page 470 Bit 0 – LOCKSTATUS NVM Lock Status If this bit is set, the device is locked. If a Chip Erase is done, and the Lockbits are cleared, this bit will read as zero. Datasheet Preliminary DS40002015A-page 470 © 2018 Microchip Technology Inc.
  • Page 471 These bits signalize the status of the CRC conversion. The bits are one-hot encoded. Value Description Not enabled CRC enabled, busy CRC enabled, done with OK signature CRC enabled, done with FAILED signature Other Reserved Datasheet Preliminary DS40002015A-page 471 © 2018 Microchip Technology Inc.
  • Page 472: Instruction Set Summary

    Displacement for direct addressing (6-bit) Unsigned × Unsigned operands Signed × Signed operands Signed × Unsigned operands Table 30-3. Stack Terminology Meaning STACK Stack for return address and pushed registers Stack Pointer to STACK Datasheet Preliminary DS40002015A-page 472 © 2018 Microchip Technology Inc.
  • Page 473 Rd ∧ K ANDI Rd, K Logical AND with Immediate ← Z,N,V,S Rd ∨ Rr Rd, Rr Logical OR ← Z,N,V,S Rd ∨ K Rd, K Logical OR with Immediate ← Z,N,V,S Datasheet Preliminary DS40002015A-page 473 © 2018 Microchip Technology Inc.
  • Page 474 (Z == 1) then PC ← PC + k + 1 None BRNE Branch if Not Equal if (Z == 0) then PC ← PC + k + 1 None Datasheet Preliminary DS40002015A-page 474 © 2018 Microchip Technology Inc.
  • Page 475 Load Indirect ← DS(Z) None 2 (1) Rd, Z+ Load Indirect and Post-Increment ← DS(Z) None ← 2 (1) Rd, -Z Load Indirect and Pre-Decrement ← Z - 1 None ← DS(Z) Datasheet Preliminary DS40002015A-page 475 © 2018 Microchip Technology Inc.
  • Page 476 Table 30-9. Bit and Bit-Test Instructions Operan #Clock Mnemonic Description Flags Logical Shift Left Rd(n+1) ← Rd(n) Z,C,N,V,H , n=0..6 Rd(0) ← ← Rd(7) Logical Shift Right Rd(n) ← Rd(n+1) Z,C,N,V , n=0..6 Rd(7) ← ← Datasheet Preliminary DS40002015A-page 476 © 2018 Microchip Technology Inc.
  • Page 477 Set Half Carry Flag in SREG ← Clear Half Carry Flag in SREG ← Table 30-10. MCU Control Instructions Mnemonic Operands Description Operation Flags #Clocks BREAK Break (See also in Debug None interface description) No Operation None Datasheet Preliminary DS40002015A-page 477 © 2018 Microchip Technology Inc.
  • Page 478 NVM. A minimum of one extra cycle must be added when reading Flash and EEPROM. One extra cycle must be added when accessing lower (64 bytes of) I/O space. Datasheet Preliminary DS40002015A-page 478 © 2018 Microchip Technology Inc.
  • Page 479: Data Sheet Revision History

    0-Series Data Sheet Revision History Data Sheet Revision History Note:  The data sheet revision is independent of the die revision and the device variant (last letter of the ordering number). Datasheet Preliminary DS40002015A-page 479 © 2018 Microchip Technology Inc.
  • Page 480: The Microchip Web Site

    Local sales offices are also available to help customers. A listing of sales offices and locations is included in the back of this document. Technical support is available through the web site at: http://www.microchip.com/support Datasheet Preliminary DS40002015A-page 480 © 2018 Microchip Technology Inc.
  • Page 481: Product Identification System

    Microchip from any and all damages, claims, suits, or expenses resulting Datasheet Preliminary DS40002015A-page 481 © 2018 Microchip Technology Inc.
  • Page 482: Trademarks

    SQTP is a service mark of Microchip Technology Incorporated in the U.S.A. Silicon Storage Technology is a registered trademark of Microchip Technology Inc. in other countries. GestIC is a registered trademark of Microchip Technology Germany II GmbH & Co. KG, a subsidiary of Microchip Technology Inc., in other countries.
  • Page 483: Worldwide Sales And Service

    New York, NY Sweden - Stockholm Tel: 631-435-6000 Tel: 46-8-5090-4654 San Jose, CA UK - Wokingham Tel: 408-735-9110 Tel: 44-118-921-5800 Tel: 408-436-4270 Fax: 44-118-921-5820 Canada - Toronto Tel: 905-695-1980 Fax: 905-695-2078 Datasheet Preliminary DS40002015A-page 483 © 2018 Microchip Technology Inc.

This manual is also suitable for:

Atmega4808Atmega4809Atmega3208Atmega3209

Table of Contents