图片仅供参考

详细数据请看参考数据手册

Datasheet下载
  • 型号: ATMEGA256RFR2-ZUR
  • 制造商: Atmel
  • 库位|库存: xxxx|xxxx
  • 要求:
数量阶梯 香港交货 国内含税
+xxxx $xxxx ¥xxxx

查看当月历史价格

查看今年历史价格

ATMEGA256RFR2-ZUR产品简介:

ICGOO电子元器件商城为您提供ATMEGA256RFR2-ZUR由Atmel设计生产,在icgoo商城现货销售,并且可以通过原厂、代理商等渠道进行代购。 ATMEGA256RFR2-ZUR价格参考。AtmelATMEGA256RFR2-ZUR封装/规格:RF 收发器 IC, IC 射频 TxRx + MCU 802.15.4 Zigbee® 2.4GHz 64-VFQFN 裸露焊盘。您可以下载ATMEGA256RFR2-ZUR参考资料、Datasheet数据手册功能说明书,资料中有ATMEGA256RFR2-ZUR 详细功能的应用电路图电压和使用方法及教程。

产品参数 图文手册 常见问题
参数 数值
产品目录

射频/IF 和 RFID

描述

IC MCU 8BIT 2.4GHZ 256K VQFN

产品分类

RF 收发器

品牌

Atmel

数据手册

点击此处下载产品Datasheet

产品图片

产品型号

ATMEGA256RFR2-ZUR

PCN其它

点击此处下载产品Datasheet

rohs

无铅 / 符合限制有害物质指令(RoHS)规范要求

产品系列

ATMEGA

其它名称

ATMEGA256RFR2-ZURTR
ATMEGA256RFR2ZUR

功率-输出

3.5dBm

包装

带卷 (TR)

天线连接器

PCB,表面贴装

存储容量

256Kb 闪存

封装/外壳

64-VFQFN 裸露焊盘

工作温度

-40°C ~ 85°C

应用

通用

应用说明

点击此处下载产品Datasheet点击此处下载产品Datasheet

数据接口

PCB,表面贴装

数据速率(最大值)

2Mbps

标准包装

4,000

灵敏度

-100dBm

电压-电源

1.8 V ~ 3.6 V

电流-传输

14.5mA

电流-接收

12.5mA

调制或协议

802.15.4 Zigbee,6LoWPAN,RF4CE,SP100,WirelessHART&trade,ISM

频率

2.4GHz

推荐商品

型号:SX1212IWLTRT

品牌:Semtech Corporation

产品名称:射频/IF 和 RFID

获取报价

型号:CC2640F128RGZT

品牌:Texas Instruments

产品名称:射频/IF 和 RFID

获取报价

型号:LMX9838SB/NOPB

品牌:Texas Instruments

产品名称:射频/IF 和 RFID

获取报价

型号:SI1061-A-GMR

品牌:Silicon Labs

产品名称:射频/IF 和 RFID

获取报价

型号:EZR32WG330F128R68G-B0

品牌:Silicon Labs

产品名称:射频/IF 和 RFID

获取报价

型号:SI1002-E-GM2

品牌:Silicon Labs

产品名称:射频/IF 和 RFID

获取报价

型号:NRF51822-QFAB-R7

品牌:Nordic Semiconductor ASA

产品名称:射频/IF 和 RFID

获取报价

型号:ATMEGA256RFR2-ZF

品牌:Microchip Technology

产品名称:射频/IF 和 RFID

获取报价

样品试用

万种样品免费试用

去申请
ATMEGA256RFR2-ZUR 相关产品

SI4432-V2-FM

品牌:Silicon Labs

价格:

BLUENRG-MSCSP

品牌:STMicroelectronics

价格:¥9.70-¥16.62

SI1062-A-GM

品牌:Silicon Labs

价格:

ATSAMR21G18A-MUT

品牌:Microchip Technology

价格:¥8.69-¥8.83

CC430F5137IRGZR

品牌:Texas Instruments

价格:

CC2540F256RHAR

品牌:Texas Instruments

价格:

AT86RF212B-ZUR

品牌:Microchip Technology

价格:

CC110LRGPR

品牌:Texas Instruments

价格:

PDF Datasheet 数据手册内容提取

ATmega256/128/64RFR2 Features • Network support by hardware assisted Multiple PAN Address Filtering • Advanced Hardware assisted R educed Power Consumption • High Performance, Low Power AVR® 8-Bit Microcontroller • Advanced RISC Architecture - 135 Powerful Instructions – Most Single Clock Cycle Execution - 32x8 General Purpose Working Registers / On-Chip 2-cycle Multiplier - Up to 16 MIPS Throughput a t 16 MHz and 1.8V – Fully Static Operation • Non-volatile Program and Data Memories - 256K/128K/64K Bytes of In-System Self-Programmable Flash 8-bit • Endurance: 10’000 Write/Erase Cycles @ 125°C (25’000 Cycles @ 85°C) - 8K/4K/2K Bytes EEPROM Microcontroller • Endurance: 20’000 Write/E rase Cycles @ 125°C (100’00 0 Cycles @ 25°C) - 32K/16K/8K Bytes Internal SRAM with Low Power • JTAG (IEEE std. 1149.1 compliant) Interface 2.4GHz - Boundary-scan Capabilities According to the JTAG Standard - Extensive On-chip Debug Support - Programming of Flash EEPR OM, Fuses and Lock Bits through the JTAG interface Transceiver for • Peripheral Features ZigBee and - Multiple Timer/Counter & PWM channels - Real Time Counter with Sepa rate Oscillator IEEE 802.15.4 - 10-bit, 330 ks/s A/D Converter; Analog Comparator; On-chip Temperature Sensor - Master/Slave SPI Serial Inter face - Two Programmable Serial USART - Byte Oriented 2-wire Serial Interface ATmega256RFR2 • Advanced Interrupt Handler an d Power Save Modes • Watchdog Timer with Separate On-Chip Oscillator ATmega128RFR2 • Power-on Reset and Low Current Brown-Out Detector • Fully integrated Low Power Transceiver for 2.4 GHz ISM Band ATmega64RFR2 - High Power Amplifier support by TX spectrum side lobe suppression - Supported Data Rates: 250 k b/s and 500 kb/s, 1 Mb/s, 2 Mb/s - -100 dBm RX Sensitivity; TX Output Power up to 3.5 dBm - Hardware Assisted MAC (Auto-Acknowledge, Auto-Retry) - 32 Bit IEEE 802.15.4 Symbol Counter - SFD-Detection, Spreading; De-Spreading; Framing ; CRC-16 Computation - Antenna Diversity and TX/RX control / TX/RX 128 Byte Frame Buffer - Phase measurement support • PLL synthesizer with 5 MHz and 500 kHz channel spacing for 2.4 GHz ISM Band • Hardware Security (AES, True R andom Generator) • Integrated Crystal Oscillators (32.768 kHz & 16 MHz, external crystal needed) • I/O and Package - 38 Programmable I/O Lines - 64-pad QFN (RoHS/Fully Green) • Temperature Range: -40°C to 1 25°C Industrial • Ultra Low Power consumption (1.8 to 3.6V) for AVR & Rx/Tx: 10.1mA/18.6 mA - CPU Active Mode (16MHz): 4.1 mA - 2.4GHz Transceiver: RX_ON 6.0 mA / TX 14.5 mA (maximum TX output power) - Deep Sleep Mode: <700nA @ 25°C • Speed Grade: 0 – 16 MHz @ 1.8 – 3.6V range with integrated voltage regulators Applications • ZigBee® / IEEE 802.15.4-2011/2006/2003™ – Full and Reduced Function Device 8393C-MCU Wireless-09/14 • General Purpose 2.4GHz ISM Band Transceiver with Microcontroller • RF4CE, SP100, WirelessHART™, ISM Applications and IPv6 / 6LoWPAN 1 8393C-MCU Wireless-09/14

1 Pin Configurations Figure 1-1. Pinout ATmega 256/128/64RFR2 O] K L 1:ADC1] 0:ADC0] EF] SS] DD] DD] SS:ASVSS] AL1] AL2] SS] VDD] 7:ICP3:INT7:C 6:T3:INT6] 5:OC3C:INT5] 4:OC3B:INT4] 3:OC3A:AIN1] F F R V V V V T T V E E E E E E P P A A A E A X X D D P P P P P [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ 64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 [PF2:ADC2:DIG2] 1 48 [PE2:XCK0:AIN0] [PF3:ADC3:DIG4] 2 47 [PE1:TXD0] [PF4:ADC4:TCK] 3 Index corner 46 [PE0:RXD0:PCINT8] [PF5:ADC5:TMS] 4 45 [DVSS] [PF6:ADC6:TDO] 5 44 [DEVDD] [PF7:ADC7:TDI] 6 ATmega256/128/64RFR2 43 [PB7:OC0A:OC1C:PCINT7] [AVSS_RFP] 7 42 [PB6:OC1B:PCINT6] [RFP] 8 41 [PB5:OC1A:PCINT5] [RFN] 9 40 [PB4:OC2A:PCINT4] [AVSS_RFN] 10 39 [PB3:MISO:PDO:PCINT3] [TST] 11 38 [PB2:MOSI:PDI:PCINT2] [RSTN] 12 37 [PB1:SCK:PCINT1] [RSTON] 13 36 [PB0:SSN:PCINT0] [PG0:DIG3] 14 35 [DVSS] Exposed paddle: [AVSS] [PG1:DIG1] 15 34 [DEVDD] [PG2:AMR] 16 33 [CLKI] 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 2] 1] B] S] D] D] D] S] 0] 1] 2]0 3] 1]0 1] 1] 0] C C 0 S D D D S T T T T P K T T S S C V V V V V N N N N C C 6: 7: [PG3:TO [PG4:TO [PG5:O [DVSS:DS [D [D [DE [D [PD0:SCL:I [PD1:SDA:I PD2:RXD1:I PD3:TXD1:I [PD4:I [PD5:X [PD [PD [ [ Note: The large center pad underneath the QFN/MLF package is made of metal and internally connected to AVSS. It should be soldered or glued to the board to ensure good mechanical stability. If the center pad is left unconnected, the package might loosen from the board. It is not recommended to use the exposed paddle as a replacement of the regular AVSS pins. 2 Disclaimer Typical values contained in this datasheet are based on simulation and characterization results of other AVR microcontrollers and radio transceivers manufactured in a similar process technology. Minimum and Maximum values will be available after the device is characterized. ATmega256/128/64RFR2 2 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 3 Overview The ATmega256/128/64RFR2 is a low-power CMOS 8-bit microcontroller based on the AVR enhanced RISC architecture combined with a high data rate transceiver for the 2.4 GHz ISM band. By executing powerful instructions in a single clock cycle, the device achieves throughputs approaching 1 MIPS per MHz allowing the system designer to optimize power consumption versus processing speed. The radio transceiver provides high data rates from 250 kb/s up to 2 Mb/s, frame handling, outstanding receiver sensitivity and high transmit output power enabling a very robust wireless communication. 3.1 Block Diagram Figure 3-1 Block Diagram The AVR core combines a rich instruction set with 32 general purpose working registers. All 32 registers are directly connected to the Arithmetic Logic Unit (ALU). Two independent registers can be accessed with one single instruction executed in one clock cycle. The resulting architecture is very code efficient while achieving throughputs up to ten times faster than conventional CISC microcontrollers. The system includes internal voltage regulation and an advanced power management. Distinguished by the small leakage current it allows an extended operation time from battery. The radio transceiver is a fully integrated ZigBee solution using a minimum number of external components. It combines excellent RF performance with low cost, small size and low current consumption. The radio transceiver includes a crystal stabilized fractional-N synthesizer, transmitter and receiver, and full Direct Sequence Spread 3 8393C-MCU Wireless-09/14

Spectrum Signal (DSSS) processing with spreading and despreading. The device is fully compatible with IEEE802.15.4-2011/2006/2003 and ZigBee standards. The ATmega256/128/64RFR2 provides the following features: 256K/128K/64K Bytes of In-System Programmable (I SP) Flash with read-while-write capabilities, 8K/4K/2K Bytes EEPROM, 32K/16K/8K Bytes SRAM, up to 35 general purpose I/O lines, 32 general purpose working registers, Real Time Counter (RTC), 6 flexible Timer/Counters with compare modes and PWM, a 32 bit Timer/Counter, 2 USART, a byte oriented 2-wire Serial Interface, a 8 channel, 10 bit analog to digital converter (ADC) with an optional differential input stage with programmable gain, programmable Watchdog Timer with Internal Oscillator, a SPI serial port, IEEE std. 1149.1 compliant JTAG test interface, also used for accessing the On-chip Debug system and programming and 6 software selectable power saving modes. The Idle mode stops the CPU while allowing the SRAM, Timer/Counters, SPI port, and interrupt system to continue functioning. The Power-down mode saves the register contents but freezes the Oscillator, disabling all other chip functions until the next interrupt or hardware reset. In Power-save mode, the asynchronous timer continues to run, allowing the user to maintain a timer base while the rest of the device is sleeping. The ADC Noise Reduction mode stops the CPU and all I/O modules except asynchronous timer and ADC, to minimize switching noise during ADC conversions. In Standby mode, the RC oscillator is running while the rest of the device is sleeping. This allows very fast start-up combined with low power consumption. In Extended Standby mode, both the main RC oscillator and the asynchronous timer continue to run. Typical supply current of the microcontroller with CPU clock set to 16MHz and the radio transceiver for the most important states is shown in the Figure 3-2 below. Figure 3-2 Radio transceiver and microcontroller (16MHz) supply current 20 18,6mA 1.8V 3.0V RPC disabled 16,6mA 3.6V A] 15 m ) [ D VD 10 RPC enabled □ 10.1mA E D, D V 4,7mA E 4,1mA D 5 ( I 275000nnAA 0 Deep Sleep SLEEP TRX_OFF RX_ON BUSY_TX Radio trans ceiver and microcontroller (16MHz) supply current The transmit output power is set to maximum. If the radio transceiver is in SLEEP mode the current is dissipated by the AVR microcontroller only. In Deep Sleep mode all major digital blocks with no data retention requirements are disconnected from main supply providing a very small leakage current. Watchdog timer, MAC symbol counter and 32.768kHz oscillator can be configured to continue to run. ATmega256/128/64RFR2 4 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 The device is manufactured using Atmel’s high-density nonvolatile memory technology. The On-chip ISP Flash allows the program memory to be reprogrammed in-system trough an SPI serial interface, by a conventional nonvolatile memory programmer, or by on on-chip boot program running on the AVR core. The boot program can use any interface to download the application program in the application Flash memory. Software in the boot Flash section will continue to run while the application Flash section is updated, providing true Read-While-Write operation. By combining an 8 bit RISC CPU with In-System Self-Programmable Flash on a monolithic chip, the Atmel ATmega256/128/64RFR2 is a powerful microcontroller that provides a highly flexible and cost effective solution to many embedded control applications. The ATmega256/128/64RFR2 AVR is supported with a full suite of program and system development tools including: C compiler, macro assemblers, program debugger/simulators, in-circuit emulators, and evaluation kits. 3.2 Pin Descriptions 3.2.1 EVDD External analog supply voltage. 3.2.2 DEVDD External digital supply voltage. 3.2.3 AVDD Regulated analog supply voltage (internally generated). 3.2.4 DVDD Regulated digital supply voltage (internally generated). 3.2.5 DVSS Digital ground. 3.2.6 AVSS Analog ground. 3.2.7 Port B (PB7...PB0) Port B is an 8-bit bi-directional I/O port with internal pull-up resistors (selected for each bit). The Port B output buffers have symmetrical drive characteristics with both high sink and source capability. As inputs, Port B pins that are externally pulled low will source current if the pull-up resistors are activated. The Port B pins are tri-stated when a reset condition becomes active, even if the clock is not running. Port B also provides functions of various special features of the ATmega256/128/64RFR2. 3.2.8 Port D (PD7...PD0) Port D is an 8-bit bi-directional I/O port with internal pull-up resistors (selected for each bit). The Port D output buffers have symmetrical drive characteristics with both high sink and source capability. As inputs, Port D pins that are externally pulled low will source current if the pull-up resistor s are activated. The Port D pins are tri-stated when a reset condition becomes active, even if the clock is not running. Port D also provides functions of various special features of the ATmega256/128/64RFR2. 3.2.9 Port E (PE7...PE0) Port E is an 8-bit bi-directional I/O port with internal pull-up resistors (selected for each bit). The Port E output buffers have symmetrical drive characteristics with both high sink and source capability. As inputs, Port E pins that are externally pulled low will source 5 8393C-MCU Wireless-09/14

current if the pull-up resistors are activated. The Port E pins are tri-stated when a reset condition becomes active, even if the clock is not running. Port E also provides functions of various special features of the ATmega256/128/64RFR2. 3.2.10 Port F (PF7...PF0) Port F is an 8-bit bi-directional I/O port with internal pull-up resistors (selected for each bit). The Port F output buffers have symmetrical drive characteristics with both high sink and source capability. As inputs, Port F pins that are externally pulled low will source current if the pull-up resistors are activated. The Port F pins are tri-stated when a reset condition becomes active, even if the clock is not running. Port F also provides functions of various special features of the ATmega256/128/64RFR2. 3.2.11 Port G (PG5…PG0) Port G is a 6-bit bi-directional I/O port with internal pull-up resistors (selected for each bit). The Port G output buffers have symmetrical drive characteristics with both high sink and source capability. However the driver strength of PG3 and PG4 is reduced compared to the other port pins. The output voltage drop (V , V ) is higher while the OH OL leakage current is smaller. As inputs, Port G pins that are externally pulled low will source current if the pull-up resistors are activated. The Port G pins are tri-stated when a reset condition becomes active, even if the clock is not running. Port G also provides functions of various special features of the ATmega256/128/64RFR2. 3.2.12 AVSS_RFP AVSS_RFP is a dedicated ground pin for the bi-directional, differential RF I/O port. 3.2.13 AVSS_RFN AVSS_RFN is a dedicated ground pin for the bi-directional, differential RF I/O port. 3.2.14 RFP RFP is the positive terminal for the bi-directional, differential RF I/O port. 3.2.15 RFN RFN is the negative terminal for the bi-directional, differential RF I/O port. 3.2.16 RSTN Reset input. A low level on this pin for longer than the minimum pulse length will generate a reset, even if the clock is not running. Shorter pulses are not guaranteed to generate a reset. 3.2.17 RSTON Reset output. A low level on this pin indicates a reset initiated by the internal reset sources or the pin RSTN. 3.2.18 XTAL1 Input to the inverting 16MHz crystal oscillator amplifier. In general a crystal between XTAL1 and XTAL2 provides the 16MHz reference clock of the radio transceiver. 3.2.19 XTAL2 Output of the inverting 16MHz crystal oscillator amplifier. 3.2.20 AREF Reference voltage output of the A/D Converter. In general this pin is left open. 3.2.21 TST Programming and test mode enable pin. If pin TST is not used pull it to low. ATmega256/128/64RFR2 6 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 3.2.22 CLKI Input to the clock system. If selected, it provides the operating clock of the microcontroller. 3.3 Unused Pins Floating pins can cause power dissipation in the digital input stage. They should be connected to an appropriate source. In normal operation modes the internal pull-up resistors can be enabled (in Reset all GPIO are configured as input and the pull-up resistors are still not enabled). Bi-directional I/O pins shall not be connected to ground or power supply directly. The digital input pins TST and CLKI must be connected. If unused pin TST can be connected to AVSS while CLKI should be connected to DVSS. Output pins are driven by the device and do not float. Power supply pins respective ground supply pins are connected together internally. XTAL1 and XTAL2 shall never be forced to supply voltage at the same time. 3.4 Compatibility to ATmega128RFA1 Backward compatibility of the ATmega256/128/64RFR2 to the ATmega128RFA1 is provided in most cases. However some incompatibilities may exist. The ATmega256/128/64RFR2 uses the same package as the ATmega128RFA1. 4 Resources A comprehensive set of development tools and application notes, and datasheets are available for download on http://www.atmel.com. 5 About Code Examples This documentation contains simple code examples that briefly show how to use various parts of the device. Be aware that not all C compiler vendors include bit definitions in the header files and interrupt handling in C is compiler dependent. Please confirm with the C compiler documentation for more details. These code examples assume that the part specific header file is included before compilation. For I/O registers located in extended I/O map, "IN", "OUT", "SBIS", "SBIC", "CBI", and "SBI" instructions must be replaced with instructions that allow access to extended I/O. Typically "LDS" and "STS" combined with "SBRS", "SBRC", "SBR", and "CBR". 6 Data Retention and Endurance 6.1 Data Retention The data retention of the non-volatile memories is • over 10 years at 125°C • over 100 years at 25°C 6.2 Endurance of the Code Memory (FLASH) The endurance of the code memory (FLASH) is 7 8393C-MCU Wireless-09/14

• 125°C – 10,000 Write/Erase cycles • 85°C – 25,000 Write/Erase cycles 6.3 Endurance of the Data Memory (EEPROM) The endurance of the entire data memory (EEPROM) is • 125°C – 20,000 Write/Erase cycles • 85°C – 50,000 Write/Erase cycles • 25°C – 100,000 Write/Erase cycles ATmega256/128/64RFR2 8 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 7 AVR CPU Core 7.1 Introduction This section discusses the AVR core architecture in general. The main function of the CPU core is to ensure correct program execution. The CPU must therefore be able to access memories, perform calculation, control peripherals, and handle interrupts. 7.2 Architectural Overview Figure 7-1.Block Diagram o f the AVR Architecture Data Bus 8-bit Program Status Flash Counter and Control Program Memory Interrupt 32 x 8 Unit Instruction General Register Purpose SPI Registers Unit Instruction Watchdog Decoder Timer g g n ssin essi ALU Analog Control Lines dre ddr C omparator ct Ad ect A Dire Indir I/O Module1 Data I/O Module 2 SRAM I/O Module n EEPROM I/O Lines In order to maximize performance and parallelism, the AVR uses a Harvard architecture – with separate memories and buses for program and data. Instructions in the program memory are executed with a single level pipelining. While one instruction is being executed, the next instruction is pre-fetched from the program memory. This concept enables instructions to be executed in every clock cycle. The program memory is In-System Reprogrammable Flash memory. 9 8393C-MCU Wireless-09/14

The fast-access Register File contains 32 x 8-bit general purpose working registers with a single clock cycle access time. This allows single-cycle Arithmetic Logic Unit (ALU) operation. In a typical ALU operation, two operands are output from the Register File, the operation is executed, and the result is stored back in the Register File – in one clock cycle. Six of the 32 registers can be used as three 16-bit indirect address register pointers for Data Space addressing – enabling efficient address calculations. One of these address pointers can also be used as an address pointer for look up tables in Flash program memory. These added function registers are the 16-bit X-, Y-, and Z-register, described later in this section. The ALU supports arithmetic and logic operations between registers or between a constant and a register. Si ngle register operations can also be executed in the ALU. After an arithmetic operation, the Status Register is updated to reflect information about the result of the operation. Program flow is provided by conditional and unconditional jump and call instructions, able to directly address the whole address space. Most AVR instructions have a single 16-bit word format. Every pr ogram memory address contains a 16- or 32-bit instruction. Program Flash memory space is divided in two sections, the Boot Program section and the Application Program section. Both sections have dedicated Lock bits for write and read/write protection. The SPM instruction that writes into the Application Flash memory section must reside in the Boot Program section. During interrupts and subroutine calls, the return address Program Counter (PC) is stored on the Stack. The Stack is effectively allocated in the general data SRAM, and consequently the Stack size is only limited by the total SRAM size and the usage of the SRAM. All user programs must initialize the SP in the Reset routine (before subroutines or interrupts are executed). The Stack Pointer (SP) is read/write accessible in the I/O space. The data SRAM can easily be accessed through the five different addressing modes supported in the AVR architecture. The memory spaces in the A VR architecture are all linear and regular memory maps. A flexible interrupt module has its control registers in the I/O space with an additional Global Interrupt Enable bit in the Status Register. All interrupts have a separate Interrupt Vector in the Interrupt Vector table. The interrupts have priority in accordance with their Interrupt Vector position. The lower the Interrupt Vector address, the higher the priority. The I/O memory space contains 64 addresses for CPU peripheral functions as Control Registers, SPI, and other I/O functions. The I/O Memory can be accessed directly, or as the Data Space locations following those of the Register File, 0x20 - 0x5F. In addition, the ATmega256/128/64RFR2 has Extended I/O space from 0x60 - 0x1FF in SRAM where only the ST/STS/STD and LD/LDS/LDD instructions can be used. 7.3 ALU – Arithmetic Logic Unit The high-performance AVR ALU operates in direct connection with all the 32 general purpose working registers. Within a single clock cycle, arithmetic operations between general purpose registers or between a register and an immediate are executed. The ALU operations are divided into three main categories – arithmetic, logical, and bit functions. Some implementations of the architecture also provide a powerful multiplier supporting both signed/unsigned multiplication and fractional format. See the “Instruction Set” section for a detailed description. ATmega256/128/64RFR2 10 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 7.4 Status Register The Status Register contains information about the result of the most recently executed arithmetic instruction. This information can be used for altering program flow in order to perform conditional operatio ns. Note that the Status Register is updated after all ALU operations, as specified in the Instruction Set Reference. This will in many cases remove the need for using the dedicated compare instructions, resulting in faster and more compact code. The Status Register is not automatically stored when entering an interrupt routine and restored when returning from an interrupt. This must be handled by software. 7.4.1 SREG – Status Register Bit 7 6 5 4 3 2 1 0 $3F ($5F) I T H S V N Z C SREG Read/Write RW RW RW RW RW RW RW RW Initial Value 0 0 0 0 0 0 0 0 • Bit 7 – I - Global Interrupt Enable The global interrupt enable bit must be set (one) for the interrupts to be enabled. The individual interrupt enable control is then performed in separate control registers. If the global interrupt enable bit is cleared (zero), none of the interrupts are enabled independent of the individual interrupt enable settings. The I-bit is cleared by hardware after an interrupt has occurred, and is set by the RETI instruction to enable subsequent interrupts. • Bit 6 – T - Bit Copy Storage The bit copy instructions BLD (Bit LoaD) and BST (Bit STore) use the T bit as source and destination for the operated bit. A bit from a register in the register file can be copied into T by the BST instruction, and a bit in T can be copied into a bit in a register in the register file by the BLD instruction. • Bit 5 – H - Half Carry Flag The half carry flag H indicates a half carry in some arithmetic operations. See the Instruction Set Description for detailed information. • Bit 4 – S - Sign Bit The S-bit is always an exclusive or between the negative flag N and the two's complement overflow flag V. See the Instruction Set Description for detailed information. • Bit 3 – V - Two's Complement Overflow Flag The two's complement overflow flag V supports two's complement arithmetics. See the Instruction Set Description for detailed information. • Bit 2 – N - Negative Flag The negative flag N indicates a negative result after the different arithmetic and logic operations. See the Instruction Set Description for detailed information. • Bit 1 – Z - Zero Flag The zero flag Z indicates a zero result after the different arithmetic and logic operations. See the Instruction Set Description for detailed information. • Bit 0 – C - Carry Flag The carry flag C indicates a carry in an arithmetic or logic operation. See the Instruction Set Description for detailed information. Note that the status register is not automatically 11 8393C-MCU Wireless-09/14

stored when entering an interrupt routine and restored when returning from an interrupt routine. This must be handled by software. 7.5 General Purpose Register File The Register File is optimized for the AVR Enhanced RISC instruction set. In order to achieve the required performance and flexibility, the following input/output schemes are supported by the Register File: • One 8-bit output operand and one 8-bit result input • Two 8-bit output operands and one 8-bit result input • Two 8-bit output operands and one 16-bit result input • One 16-bit output operand and one 16-bit result input Figure 7-1 below shows the structure of the 32 general purpose working registers in the CPU. Figure 7-1. AVR CPU General Purpose Working Registers Most of the instructions operating on the Register File have direct access to all registers, and most of them are single cycle instructions. As shown in Figure 7-1 above each register is also assigned a data memory address, mapping them directly into the first 32 locations of the user Data Space. Although not being physically implemented as SRAM locations, this memory organization provides great flexibility in access of the registers, as the X-, Y- and Z-pointer registers can be set to index any register in the file. 7.5.1 The X-register, Y-register, and Z-register The registers R26...R31 have some added functions to their general purpose usage. These registers are 16-bit address pointers for indirect addressing of the data space. The three indirect address registers X, Y, and Z are defined as described in Figure 7-2 on page 13. ATmega256/128/64RFR2 12 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 Figure 7-2. The X-, Y-, Z-registers In the different addressing modes these address registers have functions as fixed displacement, automatic increment, and automatic decrement (see the instruction set reference for details). 7.6 Stack Pointer The Stack is mainly used for storing temporary data, for storing local variables and for storing return addresses after interrupts and subroutine calls. The Stack Pointer Register always points to the top of the Stack. Note that the Stack is implemented as growing from higher memory locations to lower memory locations. This implies that a Stack PUSH command decreases the Stack Pointer. The Stack Pointer points to the data SRAM Stack area where the Subroutine and Interrupt Stacks are located . This Stack space in the data SRAM must be defined by the program before any subroutine calls are executed or interrupts are enabled. The Stack Pointer must be set to point above 0x0200. The initial value of the stack pointer is the last address of the internal SRAM. The Stack Pointer is decremented by one when data is pushed onto the Stack with the PUSH instruction, and it is d ecremented by two when the return address is pushed onto the Stack with subroutine call or interrupt. The Stack Pointer is incremented by one when data is popped from the Stack with the POP instruction, and it is incremented by two when data is popped from the Stack with return from subroutine RET or return from interrupt RETI. When the FLASH memory exceeds 128Kbyte one additional cycle is required. In this case the Stack Pointer is decremented by three when the return address is pushed onto the Stack with subroutine call or interrupt and is incremented by three when data is popped from the Stack with return from subroutine RET or return from interrupt RETI. Note: 1. If the Stack Pointer is zero and then decremented the new Stack Pointer value will be different within the device family: 0xffff (256K Byte FLASH memory), 0x7fff (128 K Byte FLASH memory) and 0x03fff (64 K Byte FLASH memory), respectively. Useful upper values of the Stack Pointer are defined by the SRAM size. 7.6.1 SPH – Stack Pointer High Bit 7 6 5 4 3 2 1 0 $3E ($5E) SP15 SP14 SP13 SP12 SP11 SP10 SP9 SP8 SPH Read/Write RW RW RW RW RW RW RW RW Initial Value 0 0 1 0 0 0 0 1 13 8393C-MCU Wireless-09/14

The AVR Stack Pointer is implemented as two 8-bit registers SPL and SPH in the I/O space. The number of bits actually used is implementation dependent. Note that the data space in some implem entations of the AVR architecture is so small that only SPL is needed. In this case, the SPH Register will not be present. • Bit 7:0 – SP15:8 - Stack Pointer High Byte 7.6.2 SPL – Stack Pointer Low Bit 7 6 5 4 3 2 1 0 $3D ($5D) SP7 SP6 SP5 SP4 SP3 SP2 SP1 SP0 SPL Read/Write RW RW RW RW RW RW RW RW Initial Value 1 1 1 1 1 1 1 1 The AVR Stack Pointer is implemented as two 8-bit registers SPL and SPH in the I/O space. The number of bits actually used is implementation dependent. Note that the data space in some implementations of the AVR architecture is so small that only SPL is needed. In this case, the SPH Register will not be present. • Bit 7:0 – SP7:0 - Stack Pointer Low Byte 7.6.3 RAMPZ – Extended Z-pointer Register for ELPM/SPM Bit 7 6 5 4 3 2 1 0 $3B ($5B) Res5 Res4 Res3 Res2 Res1 Res0 RAMPZ1 RAMPZ0 RAMPZ Read/Write R R R R R R RW RW Initial Value 0 0 0 0 0 0 0 0 For ELPM/SPM instructions, the Z-pointer is a concatenation of RAMPZ, ZH, and ZL. Note that LPM is not affected by the RAMPZ setting. • Bit 7:2 – Res5:0 - Reserved For compatibility with future devices, be sure to write these bits to zero. • Bit 1:0 – RAMPZ1:0 - Extended Z-Pointer Value Represent the MSB's of the Z-Pointer. Table 7-2 RAMPZ Register Bits Register Bits Value Description RAMPZ1:0 0 Default value of Z-pointer MSB's. For ELPM/SPM instructions, the Z-pointer is a concatenation of RAMPZ, ZH, and ZL, as shown in Figure 7-3 below. Note that LPM is not affected by the RAMPZ setting. Figure 7-3. The Z-pointer used by ELPM and SPM ATmega256/128/64RFR2 14 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 The actual number of bits is implementation dependent. Unused bits in an implementation will always read as zero. For compatibility with future devices, be sure to write these bits to zero. 7.6.4 EIND – Extended Indirect Register Bit 7 6 5 4 3 2 1 0 $3C ($5C) EIND0 EIND Read/Write RW Initial Value 0 • Bit 0 – EIND0 - Bit 0 For EICALL/EIJMP instructions. 7.7 Instruction Execution Timing Figure 7-4. The Parallel Instruction Fetches and Instruction Executions T1 T2 T3 T4 clk CPU 1st Instruction Fetch 1st Instruction Execute 2nd Instruction Fetch 2nd Instruction Execute 3rd Instruction Fetch 3rd Instruction Execute 4th Instruction Fetch Figure 7-5 below shows the internal timing concept for the Register File. In a single clock cycle an ALU operation using two register operands is executed, and the result is stored back to the destination register. Figure 7-5. Single Cycle ALU operation T1 T2 T3 T4 clk CPU Total Execution Time Register Operands Fetch ALU Operation Execute Result Write Back 7.8 Reset and Interrupt Handling The AVR provides several different interrupt sources. These interrupts and the separate Reset Vector each have a separate program vector in the program memory space. All 15 8393C-MCU Wireless-09/14

interrupts are assigned individual enable bits which must be written logic one together with the Global Interrupt Enable bit in the Status Register in order to enable the interrupt. Depending on the Program Counter value, interrupts may be automatically disabled when Boot Lock bits BLB02 or BLB12 are programmed. This feature improves software security. See the section "Memory Programming" on page 504 for details. The lowest addresses in the program memory space are by default defined as the Reset and Interrupt Vectors. The complete list of vectors is shown in "Interrupts" on page 243. The list also determines the priority levels of the different interrupts. The lower the address the higher is the priority level. RESET has the highest priority, and next is INT0 – the External Interrupt Request 0. The Interrupt Vectors can be moved to the start of the Boot Flash section by setting the IVSEL bit in the MCU Control Register (MCUCR). Refer to "Interrupts" on page 243 for more information. The Reset Vector can also be moved to the start of the Boot Flash section by programming the BOOTRST Fuse, see "Memory Programming" on page 504. When an interrupt occurs, the Global Interrupt Enable I-bit is cleared and all interrupts are disabled. The user software can write logic one to the I-bit to enable nested interrupts. All enabled interrupts can then interrupt the current interrupt routine. The I-bit is automatically set when a Return from Interrupt instruction – RETI – is executed. There are basically two types of interrupts. The first type is triggered by an event that sets the Interrupt Flag. For these interrupts, the Program Counter is vectored to the actual Interrupt Vector in order to execute the interrupt handling routine, and hardware clears the corresponding Interrupt Flag. Interrupt Flags can also be cleared by writing a logic one to the flag bit position(s) to be cleared. If an interrupt condition occurs while the corresponding interrupt enable bit is cleared, the Interrupt Flag will be set and remembered until the interr u pt is enabled, or the flag is cleared by software. Similarly, if one or more interrupt conditions occur while the Global Interrupt Enable bit is cleared, the corresponding Interrupt Flag(s) will be set and remembered until the Global Interrupt Enable bit is set, and will then be executed by order of priority. The second type of interrupts will trigger as long as the interrupt condition is present. These interrupts do not n ecessarily have Interrupt Flags. If the interrupt condition disappears before the interrupt is enabled, the interrupt will not be triggered. When the AVR exits from an interrupt, it will always return to the main program and execute one more instruction before any pending interrupt is served. Note that the Status Register is not automatically stored when entering an interrupt routine, nor restored when returning from an interrupt routine. This must be handled by software. When using the CLI instruc tion to disable interrupts, the interrupts will be immediately disabled. No interrupt will be executed after the CLI instruction, even if it occurs simultaneously with the CLI instruction. The following example shows how this can be used to avoid interrupts during the timed EEPROM write sequence. Assembly Code Example in r16, SREG ; store SREG value cli ; disable interrupts during timed sequence sbi EECR, EEMPE ; start EEPROM write sbi EECR, EEPE out SREG, r16 ; restore SREG value (I-bit) ATmega256/128/64RFR2 16 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 Assembly Code Example C Code Example char cSREG; cSREG = SREG; /* sto re SREG value */ /* disable interrupts during timed sequence */ __disable_interrupt(); EECR |= (1<<EEMPE); /* start EEPROM write */ EECR |= (1<<EEPE); SREG = cSREG; /* restore SREG value (I-bit) */ When using the SEI instruct ion to enable interrupts, the instruction following SEI will be executed before any pending interrupts, as shown in this example. Assembly Code Example sei ; set Global Int errupt Enable sleep; enter sleep, waiting for interrupt ; note: will enter sleep before any pending ; interrupt(s) C Code Example __enable_interrupt(); /* set Global Interrupt Enable */ __sleep(); /* enter sleep, waiting for interrupt */ /* note: will enter sleep before any pending interrupt(s) */ 7.8.1 Interrupt Response Time The interrupt execution response for all the enabled AVR interrupts is five clock cycles minimum. After five clock cycles the program vector address for the actual interrupt handling routine is executed. During these five clock cycle period, the Program Counter is pushed onto the Stack. The vector is normally a jump to the interrupt routine, and this jump takes three clock cycles. If an interrupt occurs during execution of a multi-cycle instruction, this instruction is completed before the interrupt is served. If an interrupt occurs when the MCU is in sleep mode, the interrupt execution response time is increased by five clock cycles. This increase comes in addition to the start-up time from the selected sleep mode. A return from an interrupt handling routine takes five clock cycles. During these five clock cycles, the Program Counter (three bytes) is popped back from the Stack, the Stack Pointer is incremented by three, and the I-bit in SREG is set. 17 8393C-MCU Wireless-09/14

8 AVR Memories This section describes the different memories in the ATmega256/128/64RFR2. The AVR architecture has two main memory spaces, the Data Memory and the Program Memory space. In addition, the ATmega256/128/64RFR2 features an EEPROM Memory for data storage. All three memory spaces are linear and regular. 8.1 In-System Reprogrammable Flash Program Memory The ATmega256/128/64RFR2 contains 256K/128K/64K Bytes On-chip In-System Reprogrammable Flash memory for program storage, see Figure 8-6 below. Since all AVR instructions are 16 or 32 bits wide, the Flash is 16 bit wide. For software security, the Flash Program memory space is divided into two sections, Boot Program section and Application Program section. The Flash memory has an endurance of at least 10'000 write/erase cycles. The ATmega256/128/64RFR2 Program Counter (PC) is 16 bits wide, thus addressing the required program memory locations. The operation of Boot Program section and associated Boot Lock bits for software protection are described in detail in "Boot Loader Support – Read-While-Write Self-Programming" on page 487. "Memory Programming" on page 504 contains a detailed description on Flash data serial downloading using the SPI pins or the JTAG interface. Constant tables can be allocated within the entire program memory address space (see the LPM – Load Program Memory instruction description and ELPM – Extended Load Program Memory instruction description). Timing diagrams for instruction fetch and execution are presented in "Instruction Execution Timing" on page 15. Figure 8-6. Program Flash Memory Map Program Memory $0000 Application Flash Section Boot Flash Section The application section of the Flash memory contains 3 user signature pages. These pages can be used to store data that should never be modified by an application program e.g. ID numbers, calibration data etc. For details see section "User Signature Data" on page 507. 8.2 SRAM Data Memory Figure 8-7 on page 19 shows how the ATmega256/128/64RFR2 SRAM Memory is organized. The ATmega256/128/64RFR2 is a complex microcontroller with more peripheral units than can be supported within the 64 location reserved in the Opcode for ATmega256/128/64RFR2 18 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 the IN and OUT instructions. For the Extended I/O space from $060 – $1FF in SRAM, only the ST/STS/STD and LD/LDS/LDD instructions can be used. The first Data Memory locations address both the Register File, the I/O Memory, Extended I/O Memory, and the internal data SRAM. The first 32 locations address the Register file, the next 64 location the standard I/O Memory, then 416 locations of Extended I/O memory and the following locations address the internal data SRAM. The five different addressing modes for the data memory cover: Direct, Indirect with Displacement, Indirect, Indirect with Pre-decrement, and Indirect with Post-increment. In the Register file, registers R26 to R31 feature the indirect addressing pointer registers. The direct addressing reaches the entire data space. The Indirect with Displacement mode reaches 63 address locations from the base address given by the Y- or Z-register. When using register indirect addressing modes with automatic pre-decrement and post- increment, the address registers X, Y, and Z are decremented or incremented. The 32 general purpose working registers, 64 I/O registers, and the internal data SRAM (32K/16K/8K Bytes) in the ATmega256/128/64RFR2 are all accessible through all these addressing modes. The Register File is described in "General Purpose Register File" on page 12. Figure 8-7. Data Memory Map Data Memory 32 Registers $0000 - $001F 64 I/O Registers $0020 - $005F 416 Ext I/O Reg. $0060 - $01FF $0200 Internal SRAM (32K/16K/8K x 8) $21FF $41FF $81FF $FFFF 8.2.1 Data Memory Access Times This section describes the general access timing concepts for internal memory access. Access to the internal data SRAM is performed in two clk cycles as described in CPU Figure 8-8 on page 20. 19 8393C-MCU Wireless-09/14

Figure 8-8. On-Chip Data SRAM Access Cycles T1 T2 T3 clk CPU Address Compute Address Address valid Data e Writ WR Data d a e RD R Memory Access Instruction Next Instruction (cid:13) 8.3 EEPROM Data Memory The ATmega256/128/64RFR2 contains 8K/4K/2K Bytes of data EEPROM memory. It is organized as a separate data space. Read access is byte-wise. The access between the EEPROM and the CPU is described in the following, specifying the EEPROM Address Registers, the EEPROM Data Register, and the EEPROM Control Register. For a detailed description of SPI, JTAG and Parallel data downloading to the EEPROM, see "Serial Downloading" on page 521, "Programming via the JTAG Interface" on page 525, and "Programming the EEPROM" on page 535 respectively. 8.3.1 EEPROM Read Write Access The EEPROM Access Registers are accessible in the I/O space, see "EEPROM Register Description" on page 26. The write access time for the EEPROM is given in Table 8-3 below. A self-timing function, however, lets the user software detect when the next byte can be written. If the user code contains instructions that write the EEPROM, some precautions must be taken. In heavily filtered power supplies, DVDD is likely to rise or fall slowly on power- up/down. This causes the device for some period of time to run at a voltage lower than specified as minimum for the clock frequency used. See "Preventing EEPROM Corruption" on page 26 for details on how to avoid problems in these situations. In order to prevent unintentional EEPROM writes, a specific write procedure must be followed. See the description of the EEPROM Control Register for details on this, "EEPROM Register Description" on page 26. When the EEPROM is read, the CPU is halted for four clock cycles before the next instruction is executed. When the EEPROM is written, the CPU is halted for two clock cycles before the next instruction is executed. The calibrated oscillator is used to time the EEPROM accesses. The following table lists the typical programming time for EEPROM access from the CPU. Table 8-3. EEPROM Programming Time Symbol Typical Programming time EEPROM write (from CPU) 4.5 ms EEPROM erase (from CPU) 8.5 ms ATmega256/128/64RFR2 20 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 The subsequent code examples show assembly and C functions for programming the EEPROM with separate and combined (atomic) erase/write operations respectively. The examples assume that interrupts are controlled (e.g. by disabling interrupts globally) so that no interrupts will occur during execution of these functions. The examples also assume that no Flash Boot Loader is present in the software. If such code is present, the EEPROM write function must also wait for any ongoing SPM command to finish. Assembly Code Example (Single Byte Programming) EEPROM_write: ; Wait for completion of previous erase/write sbic EECR,EEPE rjmp EEPROM_write ; Set up address (r18:r17) in address register out EEARH, r18 out EEARL, r17 ; Write data (r16) to Data Register out EEDR,r16 ; Write is controlled with r20 and r21 ldi r20, (1<<EEMPE) + (2<<EEPM0) ldi r21, (1<<EEMPE) + (1<<EEPE) + (2<<EEPM0) ; Start eeprom write out EECR, r20 out EECR, r21 ret EEPROM_erase: ; Wait for completion of previous erase/write sbic EECR,EEPE rjmp EEPROM_erase ; Set up address (r18:r17) in address register out EEARH, r18 out EEARL, r17 ; Set EEDR to 0xff ser r16 out EEDR,r16 ; Erase is control led with r20 and r21 ldi r20, (1<<EEMPE) + (1<<EEPM0) ldi r21, (1<<EEMPE) + (1<<EEPE) + (1<<EEPM0) ; Start eeprom erase out EECR, r20 out EECR, r21 ret ; main program … ldi r17, addr_low ldi r18, addr_high call EEPROM_erase ldi r16, ee_data 21 8393C-MCU Wireless-09/14

call EEPROM_write … C Code Example (Single Byte Programming) void EEPROM_write(un signed int uiAddress, unsigned char ucData) { /* Wait for completion of previous erase/write */ while(EECR & (1<<EEPE)) ; /* Set up address */ EEAR = uiAddress; EEDR = 255; /* Write logical one to EEMPE and enable erase only*/ EECR = (1<<EEMPE) + (1<<EEPM0); /* Start eeprom erase by setting EEPE */ EECR |= (1<<EEPE); /* Wait for completion of erase */ while(EECR & (1<<EEPE)) ; /* Set up Data Registers */ EEDR = ucData; /* Write logical one to EEMPE and enable write only */ EECR = (1<<EEMPE) + (2<<EEPM0); /* Start eeprom w rite by setting EEPE */ EECR |= (1<<EEPE); } Although the code for separate erase/write operations is more complex it is recommended over the atomic operation. The erase operation can be omitted if the target EEPROM byte already contains the value 255 (e.g. after a chip erase without the EESAVE fuse set). Assembly Code Example (Atomic Operation) EEPROM_atomic_write: ; Wait for completion of previous write sbic EECR,EEPE rjmp EEPROM_atomic_write ; Set up address (r18:r17) in address register out EEARH, r18 out EEARL, r17 ; Write data (r16 ) to Data Register out EEDR,r16 ; Write logical one to EEMPE sbi EECR,EEMPE ; Start eeprom write by setting EEPE sbi EECR,EEPE ret ATmega256/128/64RFR2 22 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 C Code Example (Atomic Operation) void EEPROM_atomic_write(unsigned int uiAddress, unsigned char ucData) { /* Wait for comple tion of previous write */ while(EECR & (1<<EEPE)) ; /* Set up address and Data Registers */ EEAR = uiAddress; EEDR = ucData; /* Write logical one to EEMPE */ EECR |= (1<<EEMPE); /* Start eeprom write by setting EEPE */ EECR |= (1<<EEPE); } The next code examples show assembly and C functions for reading the EEPROM. The examples assume that interrupts are controlled so that no interrupts will occur during execution of these functions. Assembly Code Example (EEPROM Read) EEPROM_read: ; Wait for completion of previous write sbic EECR,EEPE rjmp EEPROM_read ; Set up address (r18:r17) in address register out EEARH, r18 out EEARL, r17 ; Start eeprom read by writing EERE sbi EECR,EERE ; Read data from Data Register in r16,EEDR ret C Code Example (EEPROM Read) unsigned char EEPROM_read(unsigned int uiAddress) { /* Wait for completion of previous write */ while(EECR & (1<<EEPE)) ; /* Set up address register */ EEAR = uiAddress; /* Start eeprom read by writing EERE */ EECR |= (1<<EERE); /* Return data from Data Register */ return EEDR; } 23 8393C-MCU Wireless-09/14

The programming time can be reduced if an entire 8 byte EEPROM page is programmed instead of single bytes. In this case the data has to be loaded into the page buffer first. The page buffer will auto-erase after a write or erase operation. It is also erased after a system reset. Note that it is not possible to write more than one time to each address without erasing the page buffer. The EEPROM page programming is shown in following example code. Assembly Code Example (Page Mode Programming) EEPROM_pageerase: sbic EECR,EEPE ; wait for completion of previous rjmp EEPROM_pageerase ; EEPROM erase/write ; Page buffer loading is controlled with r20 and r21 ldi r20, (3<<EEPM0) + (1<<EEMPE) ldi r21, (3<<EEPM0) + (1<<EEMPE) + (1<<EEPE) ldi r16, 7 ; EEPROM page has 8 bytes, loop 7 bytes ser r16 out EEDR,r16 ; set EEDR to 0xff er_page_load: out EEARL, r17 ; set up address in page buffer out EECR, r20 out EECR, r21 er_load_wait: sbic EECR, EEWE ; wait for load complete rjmp er_load_wait dec r17 ; decrement address counter dec r16 ; decrement loop counter brne er_page_load ; complete loading of 7 bytes ; Erase is controlled with r20 and r21, load 8th byte ldi r20, (1<<EEMPE) + (1<<EEPM0) ldi r21, (1<<EEMPE) + (1<<EEPE) + (1<<EEPM0) out EEARL, r17 ; set up address, low byte (8th byte) out EEARH, r18 ; set up address, high byte out EECR, r20 ; start EEPROM page erase out EECR, r21 ret ; main program … ldi r17, addr_low ldi r18, addr_high call EEPROM_pageerase … C Code Example (Page Mode Programming)(1,2) void EEPROM_pagewrite(uint16_t uiAddress, uint8_t *ucData) { uint8_t byte_cnt = 0; ATmega256/128/64RFR2 24 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 while(EECR & (1<<EEPE)); // wait finish of previous erase/write EEAR = uiAddress; // set up address EEDR = 255; // data for erase do { EECR = (1<<EEMPE) + (3<<EEPM0); // enable buffer load only EECR |= (1<<EEPE); // start EEPROM loading while(EECR & (1<<EEPE)); // wait for loading complete EEARL++; // next address } while( ++byte_cnt<7 ); EECR = (1<<EEMPE) + (1<<EEPM0); // load last byte, erase only EECR |= (1<<EEPE); // start EEPROM erase while(EECR & (1<<EEPE)); // wait for erase complete EEAR = uiAddress; // set up address byte_cnt = 0; do { EEDR = ucData[byte_cnt]; // load data from SRAM EECR = (1<<EEMPE) + (3<<EEPM0); // enable buffer load only EECR |= (1<<EEPE); // start EEPROM loading while(EECR & (1<<EEPE)); // wait for loading complete EEARL++; // next address } while( ++byte_cnt<7 ); EEDR = ucData[byte_cnt]; // set up last data byte EECR = (1<<EEMPE) + (2<<EEPM0); // load last byte, write only EECR |= (1<<EEPE); // start EEPROM write } int main(void) { uint8_t buffer[8]; // load buffer … EEPROM_pagewrite(0x000, &buffer[0] ); // write EEPROM page 0 … } Notes: 1. The example code assumes that the part specific header file is included. 2. See section "About Code Examples" on page 7. The EEPROM page buffer can be loaded in arbitrary order. The data in the page buffer can also be overwritten. Loading the last byte and executing the EEPROM programming is one command. This programming command can be an erase, a write or a combined atomic erase/write operation just like for single byte programming mode. 25 8393C-MCU Wireless-09/14

8.3.2 Preventing EEPROM Corruption During periods of low DEVDD, the EEPROM data can be corrupted because the supply voltage is too low for the CPU and the EEPROM to operate properly. These issues are the same as for board leve l systems using EEPROM, and the same design solutions should be applied. An EEPROM data corruption can be caused by two situations when the voltage is too low. First, a regular write sequence to the EEPROM requires a minimum voltage to operate correctly. Secondly, the CPU itself can execute instructions incorrectly, if the supply voltage is too low. EEPROM data corruption can easily be avoided by following this design recommendation: Keep the AVR RESET active (low) during periods of insufficient power supply voltage. This can be done by enabling the internal Brown-out Detector (BOD). If the detection level of the internal BOD does not match the needed detection level, an external low DEVDD reset protection circuit can be used. If a reset occurs while a write operation is in progress, the write operation will be completed provided that the power supply voltage is sufficient. 8.4 EEPROM Register Description 8.4.1 EEARH – EEPROM Address Register High Byte Bit 7 6 5 4 3 2 1 0 $22 ($42) Res3 Res2 Res1 Res0 EEAR11 EEAR10 EEAR9 EEAR8 EEARH Read/Write R R R R RW RW RW RW Initial Value 0 0 0 0 X X X X The EEPROM Address Registers EEARH and EEARL specify the EEPROM address in the 4K bytes EEPROM s pace. The EEPROM data bytes are addressed linearly between 0 and 4096. The initial value of EEAR is undefined. A proper value must be written before the EEPROM may be accessed. • Bit 7:4 – Res3:0 - Reserved • Bit 3:0 – EEAR11:8 - EEPROM Address 8.4.2 EEARL – EEPROM Address Register Low Byte Bit 7 6 5 4 3 2 1 0 $21 ($41) EEAR7 EEAR6 EEAR5 EEAR4 EEAR3 EEAR2 EEAR1 EEAR0 EEARL Read/Write RW RW RW RW RW RW RW RW Initial Value X X X X X X X X The EEPROM Address Registers EEARH and EEARL specify the EEPROM address in the 4K bytes EEPROM space. The EEPROM data bytes are addressed linearly between 0 and 4096. The initial value of EEAR is undefined. A proper value must be written before the EEPROM may be accessed. • Bit 7:0 – EEAR7:0 - EEPROM Address ATmega256/128/64RFR2 26 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 8.4.3 EEDR – EEPROM Data Register Bit 7 6 5 4 3 2 1 0 $20 ($40) EEDR7:0 EEDR Read/Write RW RW RW RW RW RW RW RW Initial Value 0 0 0 0 0 0 0 0 For the EEPROM write operation, the EEDR Register contains the data to be written to the EEPROM in the address given by the EEAR Register. For the EEPROM read operation, the EEDR contains the data read out from the EEPROM at the address given by EEAR. • Bit 7:0 – EEDR7:0 - EEP ROM Data 8.4.4 EECR – EEPROM Control Register Bit 7 6 5 4 3 2 1 0 $1F ($3F) Res1 Res0 EEPM1 EEPM0 EERIE EEMPE EEPE EERE EECR Read/Write R R RW RW RW RW RW RW Initial Value 0 0 X X 0 0 X 0 • Bit 7:6 – Res1:0 - Reserved • Bit 5:4 – EEPM1:0 - EEPROM Programming Mode The EEPROM Programmin g mode bit setting defines if a page buffer load or a programming action will be triggered when writing EEPE. It is possible to program data in one atomic operation (erase the old value and program the new value) or to split the Erase and Write operations in two different operations. While EEPE is set, any write to EEPM1:0 will be ignored. During reset, the EEPM1:0 bits will be reset to 0 unless the EEPROM is busy programming. Table 8-4 EEPM Register Bits Register Bits Value Description EEPM1:0 0x00 Erase and Write in one operation (Atomic Operation) 0x01 Erase only 0x02 Write only 0x03 Page buffer load • Bit 3 – EERIE - EEPROM Ready Interrupt Enable Writing EERIE to one enables the EEPROM Ready Interrupt if the I bit in SREG is set. Writing EERIE to zero disables the interrupt. The EEPROM Ready interrupt generates a constant interrupt when EEPE is cleared. • Bit 2 – EEMPE - EEPROM Master Write Enable The EEMPE bit determines whether setting EEPE to one causes the EEPROM to be written or the page buffer to be loaded. When EEMPE is set, setting EEPE within four clock cycles will either start programming the EEPROM or load data to the EEPROM page buffer at the selected address If EEMPE is zero, setting EEPE will have no effect. When EEMPE has been written to one by software, hardware clears the bit to zero after four clock cycles. See the description of the EEPE bit for an EEPROM write procedure. • Bit 1 – EEPE - EEPROM Programming Enable 27 8393C-MCU Wireless-09/14

The EEPROM Programming Enable Signal EEPE is the write strobe to the EEPROM. It triggers either the programming or the page buffer loading. When address and data are correctly set up, the EEPE bit must be written to one to write the value into the EEPROM. The EEMPE bit must be written to one before a logical one is written to EEPE, otherwise no EEPROM write or load takes place. The following procedure should be adopted when writing or loading the EEPROM (the order of steps 3 and 4 is not essential): 1. Wait until EEPE becomes zero. 2. Wait until SPMEN in SPMCSR becomes zero. 3. Write new EEPROM address to EEAR (optional). 4. Write new EEPROM data to EEDR (optional). 5. Write a logical one to the EEMPE bit while writing a zero to EEPE in EECR. 6. Within four clock cycles after setting EEMPE, write a logical one to EEPE. The EEPROM can not be programmed and the page buffer not be loaded during a CPU write to the Flash memory . The software must check that the Flash programming is completed before initiating a new EEPROM write. Step 2 is only relevant if the software contains a Boot Loader allowing the CPU to program the Flash. If the Flash is never being updated by the CPU, step 2 can be omitted. Caution: an interrupt between step 5 and step 6 will make the write cycle fail, since the EEPROM Master Write Enable will time-out. If an interrupt routine accessing the EEPROM is interrupting another EEPROM access, the EEAR or EEDR Register will be modified, causing the interrupted EEPROM access to fail. It is recommended to have the Global Interrupt Flag cleared during all steps to avoid these problems. When the write access time has elapsed, the EEPE bit is cleared by hardware. The user software can poll this bit and wait for a zero before writing the next byte. When EEPE has been set, the CPU is halted for two cycles before the next instruction is executed. • Bit 0 – EERE - EEPROM Read Enable The EEPROM Read Enable Signal EERE is the read strobe to the EEPROM. When the correct address is set up in the EEAR Register, the EERE bit must be written to a logic one to trigger the EEPROM read. The EEPROM read access takes one instruction and the requested data is available immediately. When the EEPROM is read, the CPU is halted for four cycles before the next instruction is executed. The user should poll the EEPE bit before starting the read operation. If a write operation is in progress, it is neither possible to read the EEPROM nor to change the EEAR Register. 8.5 I/O Memory The Input/Output (I/O) space definition of the ATmega256/128/64RFR2 is shown in "Register Summary" on page 543. All ATmega256/128/64RFR2 I/Os and peripherals are placed in the I/O space. All I/O locations may be accessed by the LD/LDS/LDD and ST/STS/STD instructions, transferring data between the 32 general purpose working registers and the I/O space. I/O Registers within the address range 0x00 – 0x1F are directly bit-accessible using the SBI and CBI instructions. In these registers, the value of single bits can be checked by using the SBIS and SBIC instructions. Refer to the AVR instruction set for more details. When using the I/O specific commands IN and OUT, the I/O addresses 0x00 – 0x3F ATmega256/128/64RFR2 28 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 must be used. When addressing I/O Registers as data space using LD and ST instructions, 0x20 must be added to these addresses. The ATmega256/128/64RFR2 is a complex microcontroller with more peripheral units than can be supported within the 64 location reserved in Opcode for the IN and OUT instructions. For the Extended I/O space from 0x60 – 0x1F F in SRAM, only the ST/STS/STD and LD/LDS/LDD instructions can be used. For compatibility with future devices, reserved bits may not be modified. Reserved registers and I/O memory addresses should never be written. Some of the Status Flags are cleared by writing a logical one to them. Note that, unlike most other AVRs, the CBI and SBI instructions will only operate on the specified bit, and can therefore be used on registers containing such Status Flags. The CBI and SBI instructions work with registe rs 0x00 to 0x1F only. The control registers of I/O and peripherals are explained in later sections. 8.6 General Purpose I/O Registers The ATmega256/128/64RF R2 contains three General Purpose I/O Registers. These registers can be used for storing any information, and they are particularly useful for storing global variables and Status Flags. General Purpose I/O Registers within the address range 0x00 – 0x1F are directly bit-accessible using the SBI, CBI, SBIS, and SBIC instructions. 8.6.1 GPIOR0 – General Purpose IO Register 0 Bit 7 6 5 4 3 2 1 0 $1E ($3E) GPIOR07:00 GPIOR0 Read/Write RW RW RW RW RW RW RW RW Initial Value 0 0 0 0 0 0 0 0 The three General Purpose I/O Registers can be used for storing any information. • Bit 7:0 – GPIOR07:00 - General Purpose I/O Register 0 Value 8.6.2 GPIOR1 – General Purpose IO Register 1 Bit 7 6 5 4 3 2 1 0 $2A ($4A) GPIOR17:10 GPIOR1 Read/Write RW RW RW RW RW RW RW RW Initial Value 0 0 0 0 0 0 0 0 The three General Purpose I/O Registers can be used for storing any information. • Bit 7:0 – GPIOR17:10 - G eneral Purpose I/O Register 1 Value 8.6.3 GPIOR2 – General Purpose I/O Register 2 Bit 7 6 5 4 3 2 1 0 $2B ($4B) GPIOR27:20 GPIOR2 Read/Write RW RW RW RW RW RW RW RW Initial Value 0 0 0 0 0 0 0 0 29 8393C-MCU Wireless-09/14

The three General Purpose I/O Registers can be used for storing any information. • Bit 7:0 – GPIOR27:20 - General Purpose I/O Register 2 Value 8.7 Other Port Registers The inherited control registers of missing ports located in the I/O space are kept in the ATmega256/128/64RFR2. They can be used as general purpose I/O registers for storing any information. Registers placed in the address range 0x00 – 0x1F are directly bit-accessible using the SBI, CBI, SBIS and SBIC instructions. 8.7.1 PORTA – Port A Data Register Bit 7 6 5 4 3 2 1 0 $02 ($22) PORTA7:0 PORTA Read/Write RW RW RW RW RW RW RW RW Initial Value 0 0 0 0 0 0 0 0 The PORTA register can be used as a General Purpose I/O Register for storing any information. • Bit 7:0 – PORTA7:0 - Port A Data Register Value 8.7.2 DDRA – Port A Data Direction Register Bit 7 6 5 4 3 2 1 0 $01 ($21) DDA7 DDA6 DDA5 DDA4 DDA3 DDA2 DDA1 DDA0 DDRA Read/Write RW RW RW RW RW RW RW RW Initial Value 0 0 0 0 0 0 0 0 The DDRA register can be used as a General Purpose I/O Register for storing any information. • Bit 7:0 – DDA7:0 - Port A Data Direction Register Value 8.7.3 PINA – Port A Input Pins Address Bit 7 6 5 4 3 2 1 0 $00 ($20) PINA7:0 PINA Read/Write RW RW RW RW RW RW RW RW Initial Value 0 0 0 0 0 0 0 0 The PINA register is reserved for internal use and cannot be used as a General Purpose I/O Register. • Bit 7:0 – PINA7:0 - Port A Input Pins ATmega256/128/64RFR2 30 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 8.7.4 PORTC – Port C Data Register Bit 7 6 5 4 3 2 1 0 $08 ($28) PORTC7:0 PORTC Read/Write RW RW RW RW RW RW RW RW Initial Value 0 0 0 0 0 0 0 0 The PORTC register can be used as a General Purpose I/O Register for storing any information. • Bit 7:0 – PORTC7:0 - Port C Data Register Value 8.7.5 DDRC – Port C Data Direction Register Bit 7 6 5 4 3 2 1 0 $07 ($27) DDC7 DDC6 DDC5 DDC4 DDC3 DDC2 DDC1 DDC0 DDRC Read/Write RW RW RW RW RW RW RW RW Initial Value 0 0 0 0 0 0 0 0 The DDRC register can be used as a General Purpose I/O Register for storing any information. • Bit 7:0 – DDC7:0 - Port C Data Direction Register Value 8.7.6 PINC – Port C Input Pins Address Bit 7 6 5 4 3 2 1 0 $06 ($26) PINC7:0 PINC Read/Write R R R R R R R R Initial Value 0 0 0 0 0 0 0 0 The PINC register is reserved for internal use and cannot be used as a General Purpose I/O Register. • Bit 7:0 – PINC7:0 - Port C Input Pins 31 8393C-MCU Wireless-09/14

9 Low-Power 2.4 GHz Transceiver 9.1 Features • High performance RF-CMOS 2.4 GHz radio transceiver targeted for IEEE 802.15.4™, ZigBee™, IPv6 / 6LoWPAN, RF4CE, SP100, WirelessHART™ and ISM applications • Outstanding link budget (103.5 dB): o Receiver sensitivity -100 dBm o Programmable output power from -17 dBm up to +3.5 dBm • Ultra-low current consumption: o TRX_OFF = 0.4 mA o RX_ON = 12.5 mA o BUSY_TX = 14.5 mA (at max. transmit power of +3.5 dBm) • Optimized for low BoM cost and ease of production: o Few extern al components necessary (crystal, capacitors and antenna) o Excellent ESD robustness • Easy to use interface: o Registers and frame buffer access from software o Dedicated radio transceiver interrupts • Radio transceiver features: o 128 byte FIFO (SRAM) for data buffering o Integrated RX/TX switch o Fully integrated, fast settling PLL to support frequency hopping o Battery monitor o Fast wake- up time < 0.25 ms • Special IEEE 802.15.4 2006 hardware support: o FCS computation and clear channel assessment (CCA) o RSSI measurement, energy detection and link quality indication • MAC hardware accelerator: o Automated acknowledgement, CSMA-CA and frame retransmission o Automatic address filtering o Automated FCS check • Extended Feature Set Hardware Support: o AES 128 bit hardware accelerator o RX/TX indication (external RF front-end control) o RX antenna diversity o Supported PSDU data rates: 250 kb/s, 500 kb/s, 1 Mb/s and 2 Mb/s o True random number generation for security applications • Compliant to IEEE 802.15.4-2006, IEEE 802.15.4-2003 and RF4CE • Compliant to EN 300 328/440, FCC-CFR-47 Part 15, ARIB STD-66, RSS-210 ATmega256/128/64RFR2 32 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 The ATmega256/128/64RFR2 features a low-power 2.4 GHz radio transceiver designed for industrial and consumer ZigBee/IEEE 802.15.4, 6LoWPAN, RF4CE and high data rate 2.4 GHz ISM band applications. The radio transceiver is a true peripheral block of the AVR microcontroller. All RF-critical components except the antenna, crystal and de-coupling capa citors are integrated on-chip. Therefore, the ATmega256/128/64RFR2 is particularly suitable for applications like: • 2.4 GHz IEEE 802.15.4 and ZigBee systems • 6LoWPAN and RF4CE systems • Wireless sensor networks • Industrial control, sensing and automation (SP100, WirelessHART) • Residential and commercial automation • Health care • Consumer electronics • PC peripherals 9.2 General Circuit Description This radio transceiver is part of a system-on-chip solution with an AVR® microcontroller. It comprises a complex peripheral component containing the analog radio, digital modulation and demodulation including time and frequency synchronization and data buffering. The number of external components for the transceiver operation is minimized such that only the antenna, the crystal and decoupling capacitors are required. The bidirectional differential antenna pins (RFP, RFN) are used for transmission and reception, thus no external antenna switch is needed. The transceiver block diagram of the ATmega256/128/64RFR2 is shown in Figure 9-9 below. Figure 9-9. Transceiver Block Diagram L1 L2 A A AVREG T T DVREG X X ext. PA and Power XOSC Configuration Registers DIG3/4 Control PA PLL TX Data Data TX BBP µC Interrupts Interface Address RFP Frame Control FTN, BATMON Buffer RFN RX LNA PPF BPF Limiter ADC RX BBP AES RSSI AGC Control Logic AD Antenna Diversity DIG1/2 Analog Domain Digital Domain 33 8393C-MCU Wireless-09/14

The received RF signal at pins RFN and RFP is differentially fed through the low-noise amplifier (LNA) to the RF filter (PPF) to generate a complex signal, driving the integrated channel filter (BPF). The limiting amplifier provides sufficient gain to drive the succeeding analog-to-digital converter (RX ADC) and generates a digital RSSI signal. The RX ADC output signal is sampled by the digital base band receiver (RX BBP). The transmit modulation scheme is offset-QPSK (O-QPSK) with half-sine pulse shaping and 32-length block coding (spreading) according to [1] on page 110 and [2] on page 110. The modulation signal is generated in the digital transmitter (TX BBP) and applied to the fractional-N frequency synthesis (PLL), to ensure the coherent phase modulation required for demodulation of O-QPSK signals. The frequency-modulated signal is fed to the power amplifier (PA). A differential pin pair DIG3/D IG4 can be enabled to control an external RF front-end. The two on-chip low-dropout voltage regulators (A|DVREG) provide the analog and digital 1.8V supply. An internal 128-byte RAM for RX and TX (Frame Buffer) buffers the data to be transmitted or received. The configuration of the reading and writing of the Frame Buffer is controlled via the microcontroller interface. The transceiver further contains comprehensive hardware-MAC support (Extended Operating Mode) and a security engine (AES) to improve the overall system power efficiency and timing. The 128-bit AES engine can be accessed in parallel to all PHY operational transactions and states using the microcontroller interface, except during transceiver power down state. For applications not necessarily targeting IEEE 802.15.4 compliant networks, the radio transceiver also supports alternative data rates up to 2 Mb/s. For long-range applications or to improve the reliability of an RF connection the RF performance can further be improved by using an external RF front-end or Antenna Diversity. Both operation m odes are supported by the radio transceiver with dedicated control pins without the interaction of the microcontroller. Additional features of the Extended Feature Set, see section "Radio Transceiver Extended Feature Set" on page 92, are provided to simplify the interaction between radio transceiver and microcontroller. 9.3 Transceiver to Microcontroller Interface This section describes the internal Interface between the transceiver module and the microcontroller. Unlike all other AVR I/O modules, the transceiver module can operate asynchronously to the controller. The transceiver requires an accurate 16MHz crystal clock for operation, but the controller can run at any frequency within its operating limits. Note that the on-chip debug system (see section "Using the On-chip Debug System" on page 475) must be disabled for the best RF performance of the radio transceiver. 9.3.1 Transceiver Configuration and Data Access 9.3.1.1 Register Access All transceiver registers are mapped into I/O space of the controller. Due to the asynchronous interface a register access can take up to three transceiver clock cycles. Depending on the controller clock speed, program execution wait cycles are generated. ATmega256/128/64RFR2 34 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 That means if the controller runs with about 16MHz or faster, at least three wait cycles are generated, but if the controller runs with about 4MHz, no wait cycles are inserted. A register access is only possible, if the transceiver clock is available. Otherwise it returns 0x00 regardless of the current register content. Therefore the transceiver must be enabled (PRR1 Register) an d not in SLEEP state. 9.3.1.2 Frame Buffer Access The 128-byte Frame Buffer can hold the PHY service data unit (PSDU) data of one IEEE 802.15.4 compliant RX or one TX frame of maximum length at a time. A detailed description of the Frame Buffer can be found in section "Frame Buffer" on page 83. An introduction to the IEEE 802.15.4 frame format can be found in section "Introduction – IEEE 802.15.4-2006 Frame Format" on page 67. The Frame Buffer is located within the controller I/O address space above of the transceiver register set. The first byte of the Frame Buffer can be accessed with the symbolical address TRXFBST and the last byte can be accessed with the symbolical address TRXFBEND. Random access to single frame bytes is possible with “TRXFBST + byte index” or “TRXFBEND – byte index”. In contrast to the transceiver register access, the Frame Buffer allows single cycle read/write operations for all controller clock speeds. The content of the Frame Buffer is only overwritten by a new received frame or a Frame Buffer write access. The Frame Buffer usage is different between received and transmitted frames. Therefore it is not possible to retransmit a received frame without modifying the frame buffer. On received frames, the frame length byte is not stored in the Frame Buffer, but can be accessed over the TST_RX_LENGTH register. During frame receive, the Link Quality Indication (LQI) value (refer to "Link Quality Indication (LQI)" on page 78 ) is appended to the frame data in the Frame Buffer. For frame transmission, the first byte of the Frame Buffer must contain the frame length information followed by the frame data. The TST_RX_LENGTH register does not need to be written in this case. A detailed description of the Frame Buffer usage for receive and transmit frames can be found in Figure 9-32 on page 84. Notes: 1. The Frame Buffer is shared between RX and TX; therefore, the frame data are overwritten by new incoming frames. If the TX frame data are to be retransmitted, it must be ensured that no frame was received in the meanwhile. 2. To avoid overwriting during receive, Dynamic Frame Buffer Protection can be enabled. For details about this feature refer to section "Dynamic Frame Buffer Protection" on page 99. 3. It is not possible to retransmit received frames without inserting the frame length information at the beginning of the Frame Buffer. That requires a complete read out of the received frame and rewriting the modified fra me to the Frame Buffer. 4. For exceptions, e.g. receiving acknowledgement frames in Extended Operating Mode (TX_ARET) refer to section "TX_ARET_ON – Transmit with Automatic Retry and CSMA-CA Retry" on page 63. 9.3.1.3 Transceiver Pin Register TRXPR The Transceiver Pin Register TRXPR is located in the Controller clock domain and is accessible even if the transceiver is in sleep state. This register provides access to the 35 8393C-MCU Wireless-09/14

pin functionality, known from the Atmel standalone transceiver devices (two chip solution). The register (TRXRST) can be used to reset the transceiver without resetting the controller. After the reset bit was set, it is cleared immediately. A second configuration bit (SLPTR) is used to control frame transmission or sleep and wakeup of the transceiver. This bit is not cleared automatically. The function of the SLPTR bit relates to the current state of the transceiver module and is summarized in Table 9-1 below. The radio transceiver states are explained in detail in section "Operating Modes" on page 38. Table 9-1. SLPTR Multi-functional Configuration bit Transceiver Status Function SLPTR Bit Description PLL_ON TX start “0” (cid:1) “1” Starts frame transmission TX_ARET_ON TX start “0” (cid:1) “1” Starts TX_ARET transaction TRX_OFF Sleep “0” (cid:1) “1” Takes the radio transceiver into SLEEP state SLEEP Wakeup “1” (cid:1) “0” Takes th e radio transceiver back into TRX_OFF state; In states PLL_ON and TX_ARET_ON, bit SLPTR is used to initiate a TX transaction. Here bit SLPTR is sensitive on the transition from “0” to “1” only. The bit should be cleared before the frame transmission is finished. After initiating a state change by a “0” to “1” transition at bit SLPTR in radio transceiver states TRX_OFF, RX_ON or RX_AACK_ON, the radio transceiver remains in the new state as long as the bit is logical “1” and returns to the preceding state if the bit is set to “0”. SLEEP state The SLEEP state is used when radio transceiver functionality is not required, and thus the receiver module can be powered down to reduce the overall power consumption. When the radio transceiv er is in TRX_OFF state the microcontroller forces the transceiver to SLEEP by setting SLPTR = “1”. The transceiver awakes when the microcontroller releases bit SLPTR. 9.3.2 Interrupt Logic 9.3.2.1 Overview The transceiver module differentiates between eight interrupt events. Internally all pending interrupts are st ored in a separate bit of the interrupt status register (IRQ_STATUS). Each interrupt is enabled by setting the corresponding bit in the interrupt mask register (IRQ_MASK). If an IRQ is enabled an interrupt service routine must be defined to handle the IRQ. A pending IRQ is cleared automatically if an Interrupt service routine is called. It is also possible to handle IRQs manually by polling the IRQ_STATUS register. If an IRQ occurred, the appropriate IRQ_STATUS register bit is set. The IRQ can be cleared by writing ‘1’ to the register bit. It is recommended to clear the corresponding status bit before enabling an interrupt. More information about interrupt handling by the controller can be found in section "Interrupts" on page 243. The supported interrupts for the Basic Operating Mode are summarized in Table 9-2 on page 37. ATmega256/128/64RFR2 36 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 Table 9-2. Interrupt Description in Basic Operating Mode IRQ Vector IRQ Name Description Section Number/ Priority (1) 64 TRX24_AWAKE Indicates radio transceiver reached TRX_OFF "TRX_OFF – Clock State" on page 40 state RESET, or SLEEP states 63 TRX24_TX_END Indicates the completion of a frame "Frame Transmit Procedure" on page 91 transmission 62 TRX24_XAH_AMI Indicates address matching "Frame Filtering" on page 58 61 TRX24_CCA_ED_DONE Indicates the end of a CCA or ED "Energy Detection (ED)" on page 74 measurement 60 TRX24_RX_END Indicates the completion of a frame reception "Frame Transmit Procedure" on page 91 59 TRX24_RX_START Indicates the start of a PSDU reception. The "Frame Receive Procedure" on page 90 TRX_STATE changes to BUSY_RX, the PHR is ready to be read from Frame Buffer 58 TRX24_PLL_UNLOCK Indicates PLL unlock. If the radio transceiver "Interrupt Handling" on page 89 is in BUSY_TX / BUSY_TX_ARET state, the PA is turned off immediately, END interrupts will not happen (see Interrupt Handling on page 89) 57 TRX24_PLL_LOCK Indicates PLL lock "Interrupt Handling" on page 89 Note: 1. The lowest IRQ Number has the highest priority. During startup from SLEEP or RESET, the radio transceiver issues an TRX24_AWAKE interrupt when it enters state TRX_OFF. If the microcontroller initiates an energy-detect (ED) or clear-channel-assessment (CCA) measurement, the completion of the measurement is indicated by interrupt TRX24_CCA_ED_DONE, refer to sections "Energy Detection (ED)" on page 74 and "Clear Channel Assessment (CCA)" on page 76 for details. After RESET all interrupts are disabled. During radio transceiver initialization it is recommended to enable AWAKE to be notified once the TRX_OFF state is entered. Note that the TRX24_AWAKE interrupt can usually not be seen when the transceiver enters TRX_OFF state after RESET, because register IRQ_MASK is reset to mask all interrupts. In this case, state TRX_OFF is normally entered before the microcontroller could modify the register. The interrupt handling in Extended Operating Mode is described in section "Interrupt Handling" on page 65. 9.3.3 Radio Transceiver Identification The ATmega256/128/64RFR2 Transceiver module can be identified by four registers (PART_NUM, VERSION_NUM, MAN_ID_0, MAN_ID_1). One register contains a unique part number and one register the corresponding version number. Two additional registers contain the JTAG manufacture ID. The transceiver identification registers are provided for compatibility to the transceiver only device. A unique device identification is also possible with the three AVR signature bytes. For details about accessing this information refer to "Signature Bytes" on page 507. 37 8393C-MCU Wireless-09/14

9.3.4 TX Start Interrupt When the TRX24 starts a frame transmission a TRX24_TX_START interrupt is issued when the preamble starts. Table 9-3. Interrupt Description for TX_START interrupt IRQ Vector IRQ Name Description enable Number/ Priority 72 TRX24_TX_START Indicates the start of a preamble transmission. set bit TX_START in register IRQ_MASK1 When enabled, the TX_START interrupt is issued in both basic operating modes and extended operating modes . Thus it also indicates the frame start of a transmitted acknowledge frame in procedure RX_AACK. In procedure TX_ARET the TRX24_TX_START interrupt is issued separately for every frame transmission and frame retransmission. Figure 9-2. Interrupt timing in with TRX24_TX_START interrupt The figure above shows the timing of TRX24_TX_START interrupt in basic operation mode. For a description of other relevant interrupt timings see Interrupt Handling on page 42. The timing for extended operating modes are respective. 9.4 Operating Modes 9.4.1 Basic Operating Mode This section summarizes al l states to provide the basic functionality of the 2.4GHz radio transceiver, such as receiving and transmitting frames, the power up sequence and radio transceiver sleep. The Basic Operating Mode is designed for IEEE 802.15.4 and ISM applications; the corresponding radio transceiver states are shown in Figure 9-3 on page 39. ATmega256/128/64RFR2 38 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 Figure 9-3. Basic Operating Mode State Diagram (for timing refer to Table 9-4 on page 46) SLEEP (Sleep State) XOSC=OFF R = 0 3 2 SLPT SLPTR = 1 TRXRST =( f1rom all states) TRX_OFF FORCE_TRX_OFF 12 (Clock State) 13 TRXRST = 0 RESET (all states except SLEEP) XOSC=ON 6 RX_ON TRX_OFF 7 5 TRX_OFFPLL_ON 4 SHR Frame 8 11 Detected RX_ON End BUSY_RX RX_ON PLL_ON BUSY_TX (Receive State) (Rx Listen State) (PLL State) (Transmit State) Frame PLL_ON 9 10 End SLPTR = 1 or TX_START FORCE_PLL_ON 14 (all states except SLEEP, TRX_OFF) Legend: Blue: Register write to TRX_STATE Red: Control signals via Register TRXPR Green: Event Basic Operating Mode States X State transition number Note: 1. State transition numbers correspond to Table 9-4 on page 46. 9.4.1.1 State Control The radio transceiver states are controlled either by writing commands to bits TRX_CMD of register TRX_STATE, or directly by the two control bits SLPTR and TRXRST of the TRXPR register. A successful state change can be verified by reading the radio transceiver status from register TRX_STATUS. If TRX_STATUS = 0x1F (STATE_TRANSITION_IN_PROGRESS) the radio transceiver is on a state transition. Do not try to initiate a further state change while the radio transceiver is in STATE_TRANSITION_IN_PROGRESS. Bit SLPTR is a multifunctional bit (refer to section "Transceiver Pin Register TRXPR" on page 35 for more details). Dependent on the radio transceiver state, a “0” to “1” transition on SLPTR causes the following state transitions: • TRX_OFF (cid:2) SLEEP • PLL_ON (cid:2) BUSY_TX Whereas resetting bit SLPTR to “0” causes the following state transitions: • SLEEP (cid:2) TRX_OFF Bit TRXRST causes a reset of all radio transceiver registers and forces the radio transceiver into TRX_OFF state. For all states except SLEEP, the state change commands FORCE_TRX_OFF or TRX_OFF lead to a transition into TRX_OFF state. If the radio transceiver is in active receive or transmit states (BUSY_*), the command FORCE_TRX_OFF interrupts these 39 8393C-MCU Wireless-09/14

active processes, and forces an immediate transition to TRX_OFF. In contrast a TRX_OFF command is stored until an active state (receiving or transmitting) has been finished. After that the transition to TRX_OFF is performed. For a fast transition from receive or active transmit states to PLL_ON state the command FORCE_PLL_ON is provided. In contrast to FORCE_TRX_OFF this command does not disable the PLL and the analog voltage regulator AVREG. It is not available in states SLEEP, and RESET. The completion of each requested state-change shall always be confirmed by reading the bits TRX_STATUS of register TRX_STATUS. 9.4.1.2 Basic Operating Mode Description 9.4.1.2.1 SLEEP – Sleep State In radio transceiver SLEEP state, the entire radio transceiver is disabled. No circuitry is operating. The radio transceiver’s current consumption is reduced to leakage current only. This state can only be entered from state TRX_OFF, by setting the bit SLPTR = “1”. Setting SLPTR = “0” returns the radio transceiver to the TRX_OFF state. During radio transceiver SLEEP the register contents remains valid while the content of the Frame Buffer and the security engine (AES) are cleared. TRXRST = “1” in SLEEP state returns the radio transceiver to TRX_OFF state and thereby sets all registers to their reset values. 9.4.1.2.2 TRX_OFF – Clock State This state is reached immediately after Power On or Reset. In TRX_OFF the crystal oscillator is running. The digital voltage regulator is enabled, thus the radio transceiver registers, the Frame Buffer and security engine (AES) are accessible (see section "Frame Buffer" on page 83 and "Security Module (AES)" on page 99). SLPTR and TRXRST in register TRXPR can be used for state control (see "State Control" on page 39 for details). The analog front-end is disabled during TRX_OFF. Entering the TRX_OFF state from radio transceiver SLEEP, or RESET state is indicated by the TRX24_AWAKE interrupt. 9.4.1.2.3 PLL_ON – PLL State Entering the PLL_ON state from TRX_OFF state first enables the analog voltage regulator (AVREG). After the voltage regulator has been settled the PLL frequency synthesizer is enabled. When the PLL has been settled at the receive frequency to a channel defined by bits CHANNEL of register PHY_CC_CCA a successful PLL lock is indicated by issuing a TRX2 4_PLL_LOCK interrupt. If an RX_ON command is issued in PLL_ON state, the receiver is immediately enabled. If the PLL has not been settled before the state change nevertheless takes place. Even if the register bits TRX_STATUS of register TRX_STATUS indicates RX_ON, actual frame reception can only start once the PLL has locked. The PLL_ON state corresponds to the TX_ON state in IEEE 802.15.4. ATmega256/128/64RFR2 40 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 9.4.1.2.4 RX_ON and BUSY_RX – RX Listen and Receive State In RX_ON state the receiver blocks and the PLL frequency synthesizer are enabled. The receive mode is internally separated into the RX_ON and BUSY_RX states. There is no difference between these states with respect to the analog radio transceiver circuitry, which are always turned on. In both states the receiver and the PLL frequency synthesizer are enabled. During RX_ON state the receiver listens for incoming frames. After detecting a valid synchronization header (SHR), the receiver automatically enters the BUSY_RX state. The reception of a valid PHY header (PHR) generates an TRX24_RX_START interrupt and receives and demodulates the PSDU data. During PSDU reception the frame data are stored continuously in the Frame Buffer until the last byte was received. The completion of the frame reception is indicated by an TRX24_RX_END interrupt and the radio transceiver reenters the state RX_ON. At the same time the bits RX_CRC_VALID of register PHY_RSSI are updated with the result of the FCS check (see "Frame Check Sequence (FCS)" on page 72). Received frames are passed to the frame filtering unit, refer to section "Frame Filtering" on page 58. If the content of the MAC addressing fields of a frame (refer to IEEE 802.15.4 section 7.2.1) matches to the expected addresses, which is further dependent on the addressing mode, an address match interrupt (TRX24_XAH_AMI) is issued, refer to "Interrupt Logic" on page 36. The expected address values are to be stored in the registers Short-Address, PAN-ID and IEEE-address. Frame filtering is available in Basic and Extended Operating Mode, refer to section "Frame Filtering" on page 58. Leaving state RX_ON is only possible by writing a state change command to bits TRX_CMD of register TRX_STATE. 9.4.1.2.5 BUSY_TX – Transmit State A transmission can only be initiated in state PLL_ON. There are two ways to start a transmission: • Setting Bit SLPTR of register TRXPR to ‘1’. The bit should be cleared before the frame has been transmitted. This mode is for legacy operation and should be replaced by the TX_START command below. • TX_START command to bits TRX_CMD of register TRX_STATE. Either of these causes the radio transceiver into the BUSY_TX state. During the transition to BUSY_TX state, the PLL frequency shifts to the transmit frequency. The actual transmission of the first data chip of the SHR starts after 16 µs to allow PLL settling and PA ramp-up, see Figure 9-7 on page 44. After transmission of the SHR, the Frame Buffer content is transmitted. In case the PHR indicates a frame length of zero, the transmission is aborted. After the frame transmission has completed, the radio transceiver automatically turns off the power amplifier, generates a TRX24_TX_END interrupt and returns into PLL_ON state. 9.4.1.2.6 RESET State The RESET state is used to set back the state machine and to reset all registers of the radio transceiver to their default values. 41 8393C-MCU Wireless-09/14

A reset forces the radio transceiver into the TRX_OFF state. A reset is initiated by a ATmega256/128/64RFR2 main reset (see "Resetting the AVR" on page 209) or a radio transceiver reset (see "Transceiver Pin Register TRXPR" on page 35). During radio transceiver reset the TRXPR register is not cleared and therefore the application software has to set the SLPTR bit to “0”. 9.4.1.3 Interrupt Handling All interrupts provided by the radio transceiver are supported in Basic Operating Mode (see Table 9-2 on page 37). Required interrupts must b e enabled by writing to register IRQ_MASK and the global interrupt enable flag must be set. For a general explanation of the interrupt handling refer to "Reset and Interrupt Handling" on page 15 and "Interrupt Logic" on page 36. For example, interrupts are provided to observe the status of the RX and TX operations. On receive the TRX24_RX_START interrupt indicates the detection of a valid PHR, the TRX24_XAH_AMI interrupt an address match and the TRX24_RX_END interrupt the completion of the frame reception. On transmit the TRX24_TX_END interrupt indicates the completion of the frame transmission. Figure 9-14 on page 43 shows an example for a transmit/receive transaction between two devices and the related interrupt events in Basic Operating Mode. Device 1 transmits a frame containing a MAC header (in this example of length 7), payload and valid FCS. The frame is received by Device 2 which generates the interrupts during the processing of the incoming frame. The received frame is stored in the Frame Buffer. If the received frame passes the address filter (refer to section "Frame Filtering" on page 58) an address match TRX24_XAH_AMI interrupt is issued after the reception of the MAC header (MHR). In Basic Operating Mode the TRX24_RX_END interrupt is issued at the end of the received frame. In Extended Operating Mode (refer to "Extended Operating Mode" on page 47) the interrupt is only issued if the received frame passes the address filter and the FCS is valid. Further exceptions are explained in "Extended Operating Mode" on page 47. Processing delay t is a typical value (see chapter "Digital Interface Timing IRQ Characteristics" on page 563). ATmega256/128/64RFR2 42 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 Figure 9-14. Timing of TRX24_RX_START, TRX24_XAH_AMI, TRX24_TX_END and TRX24_RX_END Interrupts in Basic Operating Mode -16 0 128 160 192 192+(9+m)*32 Time [µs] TRX_STATE PLL_ON BUSY_TX PLL_ON SIRLQPTR TRX24_TX_END TX (Device1) Typ. Processing Delay 16 µs Number of Octets 4 1 1 7 m 2 me Air Frame Content Preamble SFD PHR MHR MSDU FCS Fra on TRX_STATE RX_ON BUSY_RX RX_ON IRQ TRX24_RX_START TRX24_XAH_AMI TRRXX_E24N_D RX Device 2) Interrupt latency tIRQ tIRQ tIRQ ( 9.4.1.4 Basic Operating Mode Timing The following paragraphs depict state transitions and their timing properties. Timing figures are explained in Table 9-4 on page 46 and section "Digital Interface Timing Characteristics" on page 563. 9.4.1.4.1 Wake-up Procedure The wake-up procedure fro m radio transceiver SLEEP state is shown in Figure 9-15 below. This figure implies, that the microcontroller is already running and hence, the digital voltage regulator is enabled. If the microcontroller clock source is set to Transceiver Clock, the crystal oscillator is also running, which reduces the radio transceiver wake-up time further. For information about the wake-up timing of the microcontroller, depending on the different clock source options, refer to "System Clock and Clock Options" on page 176. In order to calculate the total wake-up delay from microcontroller sleep mode (see "Power Management and Sleep Modes" on page 185), the microcontroller wake-up time, including the voltage regulator ramp-up and the radio transceiver wake-up time has to be added. Figure 9-15. Wake-up Procedure from Transceiver SLEEP State 0 100 200 400 Time [µs] Event SLPTR = 0 TRX24_AWAKE IRQ State SLEEP TRX_OFF Block XOSC startup FTN XOSC enabled Time tTR2 The radio transceiver SLEEP state is left by releasing bit SLPTR to “0”. This restarts the XOSC if it is not already running. After t = 215 µs + 25 µs = 240 µs (see Table 9-4 on TR2 page 46) the radio transceiver enters TRX_OFF state. If the XOSC is already running, the radio transceiver enters TRX_OFF state after 25 µs. 43 8393C-MCU Wireless-09/14

During this wake-up procedure the calibration of the filter-tuning network (FTN) is performed. Entering TRX_OFF state is signaled by the TRX24_AWAKE interrupt, if enabled. 9.4.1.4.2 PLL_ON and RX_ON States The transition from TRX_OFF to PLL_ON and RX_ON mode is shown in Figure 9-16 below. Figure 9-16. Transition from TRX_OFF to PLL_ON and RX_ON State 0 100 Time [µs] Event TRX24_PLL_LOCK IRQ State TRX_OFF PLL_ON RX_ON Block AVREG PLL RX Command PLL_ON RX_ON Time t t TR4 TR8 Note: 1. If TRX_CMD = RX_ON in TRX_OFF state RX_ON state is entered immediately, even if the PLL has not settled. 2. If the AVR ADC module is enabled, the AVREG is already started and thus the state transition time t is reduced. TR4 Entering the commands PLL_ON or RX_ON in TRX_OFF state initiates a ramp-up sequence of the internal 1.8V voltage regulator for the analog domain (AVREG), if AVREG is not already enabled by the AVR ADC module. RX_ON state can be entered any time from PLL_ON s tate regardless whether the PLL has already locked as indicated by the TRX24_PLL_LOCK interrupt. 9.4.1.4.3 BUSY_TX and RX_ON States The transition from PLL_ON to BUSY_TX state and subsequent to RX_ON state is shown in Figure 9-7 below. Figure 9-7. PLL_ON to BUSY_TX to RX_ON Timing 0 16 x x + 32 Time [µs] Event SLPTR State PLL_ON BUSY_TX RX_ON Block PLL PA PA, TX PLL RX Command or command TX_START RX_ON Time tTR10 tTR11 Starting from PLL_ON state it is assumed that the PLL is already locked. A transmission is initiated either by writing “1” to bit SLPTR or by command TX_START. The PLL settles to the transmit frequency and the PA is enabled. ATmega256/128/64RFR2 44 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 t = 16 µs after initiating the transmission, the radio transceiver changes into TR10 BUSY_TX state and the internally generated SHR is transmitted. After that the PSDU data are transmitted from the Frame Buffer. After completing the frame transmission, indicated by the TRX24_TX_END interrupt, the PLL settles back to the receive frequency within t = 32 µs in state PLL_ON. TR11 If during TX_BUSY the radio transmitter is programmed to change to a receive state it automatically proceeds the state change to RX_ON state after finishing the transmission. 9.4.1.4.4 Reset Procedure The radio transceiver reset p rocedure is shown in Figure 9-18 below. Figure 9-18. Reset Procedure 0 x x + 10 x + 40 Time [µs] Event [TRX24_AWAKE IRQ] State various TRX_OFF Block XOSC, DVREG enabled F T N XOSC, DVREG enabled TRXRST Time >t11 3xAVR clock tTR13 Note: 1. Timing parameter t = 37 µs refers to Table 9-4 on page 46; t refers to "Digital TR13 11 Interface Timing C haracteristics" on page 563. 2. If TRXRST is set during radio transceiver SLEEP state, the XOSC startup delay is extended by the XOSC startup time. TRXRST = “1” resets all radio transceiver registers to their default values. The radio transceiver reset is released automatically after 3 AVR clock cycles and the wake-up sequence without restarting XOSC and DVREG, nevertheless an FTN calibration cycle is performed, refer to "Automatic Filter Tuning (FTN)" on page 90. After that the TRX_OFF state is entered. Figure 9-18 above illustrates the radio transceiver reset procedure if the radio transceiver is in any state but not in SLEEP state. If the radio transceiver was in SLEEP state, the SLPTR bit in the TRXPR register must be cleared prior to clearing the TRXRST bit in order to enter the TRX_OFF state. Otherwise the radio transceiver enters the SLEEP state immediately. If the radio transceiver was in SLEEP state and the Transceiver Clock is not selected as the microcontroller clock source, the XOSC is enabled before entering TRX_OFF state. If register TRX_STATUS indicates STATE_TRANSITION_IN_PROGRESS during system initialization until the radio transceiver reaches TRX_OFF, do not try to initiate a further state change while the radio transceiver is in this state. Note that before accessing the radio transceiver module the TRX24_AWAKE event should be checked. 45 8393C-MCU Wireless-09/14

9.4.1.4.5 State Transition Timing Summary The transition numbers correspond to Table 9-4 below. See measurement setup in "Basic Application Schematic" on page 540. Table 9-4. Radio Transceiver State Transition Timing No Symbol Transition Time [µs], (typ) Comments Depends on crystal oscillator setup (CL = 10 pf) 1 t SLEEP (cid:1) TRX_OFF 240 TR2 TRX_OFF state indicated by TRX24_AWAKE interrupt 2 t TRX_OFF (cid:1) SLEEP 35 · 1 / f For f > 250 kHz TR3 CLKM CLKM 3 t TRX_OFF (cid:1) PLL_ON 110 Depends on external capacitor at AVDD (1 µF nom) TR4 4 t PLL_ON (cid:1) TRX_OFF 1 TR5 5 t TRX_OFF (cid:1) RX_ON 110 Depends on external capacitor at AVDD (1 µF nom) TR6 6 t RX_ON (cid:1) TRX_OFF 1 TR7 7 t PLL_ON (cid:1) RX_ON 1 TR8 8 t RX_ON (cid:1) PLL_ON 1 Transition time is also valid for TX_ARET_ON, RX_AACK_ON TR9 When setting bit SLPTR or TRX_CMD = TX_START, the first 9 t PLL_ON (cid:1) BUSY_TX 16 symbol transmission is delayed by 16 µs (PLL settling and TR10 PA ramp up). 10 t BUSY_TX (cid:1) PLL_ON 32 PLL settling time from TX_BUSY to PLL_ON state TR11 Using TRX_CMD = FORCE_TRX_OFF (see register 11 t All modes (cid:1) TRX_OFF 1 TRX_STATE), TR12 Not valid for SLEEP state 12 t RESET (cid:1) TRX_OFF 37 Not valid for SLEEP state TR13 Using TRX_CMD = FORCE_PLL_ON (see register Various 13 t (cid:1) PLL_ON 1 TRX_STATE), TR14 states Not valid for SLEEP, RESET and TRX_OFF The state transition timing is calculated based on the timing of the individual blocks shown in Table 9-9 on page 55. The worst case values include maximum operating temperature, minimum supply voltage, and device parameter variations. Table 9-9. Analog Block Initialization and Settling Time No Symbol Block Time [µs], (typ) Time [µs], (max) Comments Leaving SLEEP state, depends on crystal Q factor and load 15 t XOSC 215 1000 TR15 capacitor 16 t FTN 25 FTN tuning time, fixed TR16 Depends on external bypass capacitor at DVDD 17 t DVREG 60 1000 TR17 (CB3 = 1 µF nom., 10 µF worst case), depends on V DEVDD Depends on external bypass capacitor at AVDD 18 t AVREG 60 1000 TR18 (CB1 = 1 µF nom., 10 µF worst case) , depends on V EVDD PLL settling time TRX_OFF (cid:1) PLL_ON, including 60 µs 19 t PLL, initial 110 155 TR19 AVREG settling time 20 t PLL, settling 11 24 Settling time between channel switch TR20 PLL center frequency calibration, refer to "Calibration 21 tTR21 PLL, CF cal 35 Loops" on page 89 PLL DCU calibration, refer to "Calibration Loops" on 22 tTR22 PLL, DCU cal 6 page 89 23 t PLL, RX (cid:1) TX 16 Maximum PLL settling time RX (cid:1) TX TR23 ATmega256/128/64RFR2 46 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 No Symbol Block Time [µs], (typ) Time [µs], (max) Comments 24 t PLL, TX (cid:1) RX 32 Maximum PLL settling time TX (cid:1) RX TR24 RSSI update period in receive states, refer to "Reading 25 tTR25 RSSI, update 2 RSSI" on page 74 ED measurement period, refer to "Measurement 26 tTR26 ED 140 Description" on page 75 Typical SHR synchronization period, refer to 27 tTR27 SHR, sync 96 "Measurement Description" on page 75 CCA measurement period, refer to "Configuration and 28 tTR28 CCA 140 CCA Request" on page 77 Random value update period, refer to "Random 29 tTR29 Random value 1 Number Generator" on page 92 9.4.2 Extended Operating Mode The Extended Operating Mode is a hardware MAC accelerator and goes beyond the basic radio transceiver functionality provided by the Basic Operating Mode. It handles time critical MAC tasks requested by the IEEE 802.15.4 standard or by hardware such as automatic acknowledgement, automatic CSMA-CA and retransmission. This results in a more efficient IEEE 802.15.4 software MAC implementation including reduced code size and may allow operating at lower microcontroller clock rates. The Extended Operating Mode is designed to support IEEE 802.15.4-2006 compliant frames; the mode is backward compatible to IEEE 802.15.4-2003 and supports non IEEE 802.15.4 compliant frames. This mode comprises the following procedures: Automatic acknowledgement (RX_AACK) divides into the tasks: • Frame reception and automatic FCS check; • Configurable addressing f ields check; • Interrupt indicating address match; • Interrupt indicating frame reception, if it passes address filtering and FCS check; • Automatic ACK frame transmission (if the received frame passed the address filter and FCS check and if an ACK is required by the frame type and ACK request); • Support of slotted acknowledgment using SLPTR bit for frame start. Automatic CSMA-CA and Retransmission (TX_ARET) divides into the tasks: • CSMA-CA including automatic CCA retry and random back-off; • Frame transmission and automatic FCS field generation; • Reception of ACK frame (if an ACK was requested); • Automatic frame retry if ACK was expected but not received; • Interrupt signaling with transaction status. Automatic FCS check and generation (refer to "Frame Check Sequence (FCS)" on page 72) is used by the RX_AACK and TX_ARET modes. In RX_AACK mode an automatic FCS check is always performed for incoming frames. An ACK received in TX_ARET mode within the time required by IEEE 802.15.4 is accepted if the FCS is valid and if the sequence number of the ACK matches the sequence number of the previously transmitted frame. Dependent on the value of the 47 8393C-MCU Wireless-09/14

frame pending subfield in the received acknowledgement frame the transaction status is set according to Table 9-19 on page 64. The state diagram including the Extended Operating Mode states is shown in Figure 9- 19 below. Yellow marked states represent the Basic Operating Mode; blue marked states represent the Extended Operating Mode. Figure 9-19. Extended Operating Mode State Diagram SLEEP (Sleep State) XOSC=OFF LPTR = 0 R = 1 3 (from all states) S PT TRXRST = 1 2 SL TRX_O FF FORCE_TRX_OFF 12 13 TRXRST = 0 (Clock State) RESET (all modes except SLEEP) XOSC=ON 6 RX_ON TRX_OFF 7 5 TRX_OFFPLL_ON 4 SLPTR = 1 or SHR TX_START BUSY_RX Detected RX_ON 8 RX_ON PLL_ON 11 BUSY_TX (Receive State) Frame (Rx Listen State) PLL_ON (PLL State) 10 (Transmit State) 9 End Frame 14 End RX_AACK_TORNX_OFFTFRroXm_ O/ TFoF PLL_ONRX_ AACK_ON PLL_ON TX_ARET_ON TX_ARET_TORNX_SOFTFFLFRsrOoePXmRe_T OnC/R oTFEt oFe=_ s P1LL_ON SHR or Detected TX_START BUSY_RX_AACK RX_AACK_ON TX_ARET_ON BUSY_TX_ARET Trans- Frame action End Finished Legend: Blue: Register Write to TRX_STATE Red: Control signals via Register TRXPR Green: Event Basic Operating Mode States Extended Operating Mode States Note: 1. State transition numbers correspond to Table 9-4 on page 46. ATmega256/128/64RFR2 48 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 9.4.2.1 State Control The Extended Operating Mode states RX_AACK and TX_ARET are controlled via the bits TRX_CMD of register TRX_STATE, which receives the state transition commands. The states are entered from TRX_OFF or PLL_ON state as illustrated in Figure 9-19 on page 48. The completion of each state change command shall always be confirmed by reading the TRX_STATUS register. RX_AACK - Receive with Automatic ACK A state transition to RX_AACK_ON from PLL_ON or TRX_OFF is initiated by writing the command RX_AACK_ON to the register bits TRX_CMD. The state change can be confirmed by reading register TRX_STATUS, those changes to RX_AACK_ON or BUSY_RX_AACK on succe ss. BUSY_RX_AACK is returned if a frame is currently being received. The RX_AACK state is left by writing command TRX_OFF or PLL_ON to the register bits TRX_CMD. If the radio transceiver is within a frame receive or acknowledgment procedure (BUSY_RX_AACK) the state change is executed after finish. Alternatively, the commands FORCE_TR X_OFF or FORCE_PLL_ON can be used to cancel the RX_AACK transaction and change into radio transceiver state TRX_OFF or PLL_ON respectively. TX_ARET - Transmit with Automatic Retry and CSMA-CA Retry Similarly, a state transition to TX_ARET_ON from PLL_ON or TRX_OFF is initiated by writing command TX_ARET_ON to register bits TRX_CMD. The radio transceiver is in the TX_ARET_ON state after TRX_STATUS register changes to TX_ARET_ON. The TX_ARET transaction is sta rted with writing ‘1’ to the SLPTR bit of the TRXPR register or writing the command TX_START to register bits TRX_CMD. TX_ARET state is left by writing the command TRX_OFF or PLL_ON to the register bits TRX_CMD. If the radio transceiver is within a CSMA-CA, a frame-transmit or an acknowledgment procedure (BUSY_TX_ARET) the state change is executed after finish. Alternatively, the co mmand FORCE_TRX_OFF or FORCE_PLL_ON can be used to instantly terminate the TX_ARET transaction and change into radio transceiver states TRX_OFF or PLL_ON, respectively. Note that a state change request from TRX_OFF to RX_AACK_ON or TX_ARET_ON internally passes the state PLL_ON to initiate the radio transceiver. Thus the readiness to receive or transmit data is delayed accordingly. It is recommended to use interrupt TRX24_PLL_LOCK as an indicator. 9.4.2.2 Configuration The use of the Extended Operating Mode is based on Basic Operating Mode functionality. Only features beyond the basic radio transceiver functionality are described in the following sections. For details on the Basic Operating Mode refer to section "Basic Operating Mode" on page 38. When using the RX_AACK or TX_ARET modes, the following registers needs to be configured. RX_AACK configuration steps: • Short address, PAN-ID and IEEE address (register SHORT_AADR_0, SHORT_ADDR_1, PAN_ID_0, PAN_ID_1, IEEE_ADDR_0 … IEEE_ADDR_7) • Configure RX_AACK properties (register XAH_CTRL_0, CSMA_SEED_1) o Handling of Frame Version Subfield 49 8393C-MCU Wireless-09/14

o Handling of Pending Data Indicator o Characterize as PAN coordinator o Handling of Slotted Acknowledgement • Additional Frame Filtering Properties (register XAH_CTRL_1, CSMA_SEED_1) o Promiscuous Mode o Enable or disable automatic ACK generation o Handling of reserved frame types The addresses for the address match algorithm are to be stored in the appropriate address registers. Additional control of the RX_AACK mode is done with registers XAH_CTRL_1 and CSMA_SEED_1. As long as a short address has not been set, only broadcast frames and frames matching the IEEE address can be received. Configuration examples for different device operating modes and handling of various frame types can be found in section "Description of RX_AACK Configuration Bits" on page 53. TX_ARET configuration steps: • Leave register bit TX_AUTO_CRC_ON = 1 register TRX_CTRL_1 • Configure CSMA-CA o MAX_FRAME_RETRIES register XAH_CTRL_0 o MAX_CSMA_RETRIES register XAH_CTRL_0 o CSMA_SEED registers CSMA_SEED_0, CSMA_SEED_1 o MAX_BE, MIN_BE register CSMA_BE • Configure CCA (see section "Configuration and CCA Request" on page 77) MAX_FRAME_RETRIES (register XAH_CTRL_0) defines the maximum number of frame retransmissions. The register bits MAX_CSMA_RETRIES (register XAH_CTRL_0) configure the number of CSMA-CA retries after a busy channel is detected. The CSMA_SEED_0 and CSMA_SEED_1 registers define a random seed for the back- off-time random-number generator of the radio transceiver. The MAX_BE and MIN_BE register bits (register CSMA_BE) set the maximum and minimum CSMA back-off exponent (according to [1] on page 110). 9.4.2.3 RX_AACK_ON – Receive with Automatic ACK The general functionality of the RX_AACK procedure is shown in Figure 9-20 on page 52. The gray shaded area is the standard flow of a RX_AACK transaction for IEEE 802.15.4 compliant frames (refer to section "Configuration of IEEE Scenarios" on page 54). All other procedures are exceptions for specific operating modes or frame formats (refer to section "Configuration of non IEEE 802.15.4 Compliant Scenarios" on page 56). The frame filtering operation is described in detail in section "Frame Filtering" on page 58. In RX_AACK_ON state, the radio transceiver listens for incoming frames. After detecting SHR and a valid PHR, the radio transceiver parses the frame content of the MAC header (MHR) as described in section "PHY Header (PHR)" on page 67. ATmega256/128/64RFR2 50 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 Generally, at nodes, configured as a normal device or PAN coordinator, a frame is not indicated if the frame filter does not match and the FCS is invalid. Otherwise, the TRX_24_RX_END interrupt is issued after the completion of the frame reception. The microcontroller can then read the frame. An exception applies if promiscuous mode is enabled (see section "Conf iguration of IEEE Scenarios" on page 54). In that case a TRX_24_RX_END interrupt is issued even if the FCS fails. If the content of the MAC addressing fields of the received frame (refer to IEEE 802.15.4 section 7.2.1) matches one of the configured addresses, dependent on the addressing mode, an address match interrupt (TRX24_XAH_AMI) is issued (refer to section "Frame Filtering" on page 58). The expected address values are to be stored in registers Short-address, PAN-ID and IEEE-address. Frame filtering as described in section "Frame Filtering" on page 58 is also valid for Basic Operating Mode. During reception the radio transceiver parses bit[5] (ACK Request) of the frame control field of the received data or the MAC command frame to check if an ACK reply is expected. In that case and if the frame passes the third level of filtering (see IEEE 802.15.4-2006, section 7.5.6.2), the radio transceiver automatically generates and transmits an ACK frame. After the ACK transmission is finished, a TRX24_TX_END interrupt is generated. The content of the frame pending subfield of the ACK response is set by bit AACK_SET_PD of register CSMA_SEED_1 when the ACK frame is sent in response to a data request MAC command frame, otherwise this subfield is set to “0”. The sequence number is copied from the received frame. Optionally, the start of the transmission of the acknowledgement frame can be influenced by register bit AACK_ACK_TIME. Default value (according to standard IEEE 802.15.4, page 54) is 12 symbol times after the reception of the last symbol of a data or MAC command frame. If the bit AACK_DIS_ACK of register CSMA_SEED_1 is set, no acknowledgement frame is sent even if an acknowledgment frame was requested. This is useful for operating the MAC hardware accelerator in promiscuous mode (see section "Configuration of non IEEE 8 02.15.4 Compliant Scenarios" on page 56). The status of the RX_AACK operation is indicated by the bits TRAC_STATUS of register TRAC_STATUS. During the operations described above the radio transceiver remains in BUSY_RX_AACK state. 51 8393C-MCU Wireless-09/14

Figure 9-20. Flow Diagram of RX_AACK TRX_STATE = RX_AACK_ON N SHR detected Y TRX_STATE = BUSY_RX_AACK Generate TRX24_RX_START interrupt Scanning MHR Promiscuous Mode Reserved Frames Frame N Filtering Note 1: Frame Filtering, Promiscuous Mode and Y (se e Note 1) Frame reception Reserved Frames: -A radio transceiver in Promiscuous Mode, or configured to receive Reserved Generate TRX24_XAH_AMI Frames handles received frames passing interrupt the third level of filtering N -For details refer to the description of AACK_PROM_MODE Promiscuous Mode and Reserved == 1 Frame Types Frame reception Y N FCS valid N Note 2: FCS check is omitted for Promiscous Mode (see Note 2) FCF[2:0] > 3 Y Generate TRX24_RX_END Y interrupt N AACK_UPLD_RES_FT N ACK requested == 1 (see Note 3) Note 3: Additional conditions: -ACK requested & Y -ACK_DIS_ACK==0 & Y -frame_version<=AACK_FVN_MODE N N FCS valid Slotted Operation == 0 Y Y Generate Generate TRX24_RX_END TRX24_RX_END N N interrupt interrupt AACK_ACK_TIME AACK_ACK_TIME == 0 == 0 Y Y Wait 2 symbol Wait 6 symbol Wait 12 symbol Wait 2 symbol periods periods periods periods SLPTR bit = 1 N Y Transmit ACK GenerateTRX24_TX_END interrupt TRX_STATE = RX_AACK_ON ATmega256/128/64RFR2 52 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 9.4.2.3.1 Description of RX_AACK Configuration Bits Overview The following table summarizes all register bits which affect the behavior of a RX_AACK transaction. For address filtering it is further required to setup address registers to match to the expected address. Configuration and address bits are to be set in TRX_OFF or PLL_ON state prior to switching to RX_AACK mode. A graphical representation of various operating modes is illustrated in Figure 9-20 on page 52. Table 9-6. Overview of RX_AACK Configuration Bits Register Name Register Bits Description SHORT_ADDR_0/1 Set node addresses PAN_ADDR_0/1 IEEE_ADDR_0 … IEEE_ADDR_7 RX_SAFE_MODE 7 Protect buffer after frame receive AACK_PROM_MODE 1 Support promiscuous mode AACK_ACK_TIME 2 Change auto acknowledge start time AACK_UPLD_RES_FT 4 Enable reserved frame type reception, needed to receive non-standard compliant frames AACK_FLTR_RES_FT 5 Filter reserved frame types like data frame type, needed for filtering of non-standard compliant frames SLOTTED_OPERATION 0 If set, acknowledgment transmission has to be triggered by register bit SLPTR AACK_I_AM_COORD 3 If set, the device is a PAN coordinator AACK_DIS_ACK 4 Disable generation of acknowledgment AACK_SET_PD 5 Set frame pending subfield in Frame Control Field (FCF), refer to section "Overview" on page 72 AACK_FVN_MODE 7:6 Controls the ACK behavior, depending on FCF frame version number The usage of the RX_AACK configuration bits for various operating modes of a node is explained in the following se ctions. Configuration bits not mentioned in the following two sections should be set to their reset values. All registers mentioned in Table 9-6 above are described in section "Register Summary" on page 66. Note, that the general behavior of the Extended Feature Set settings: • OQPSK_DATA_RATE (PSDU data rate) • SFD_VALUE (alternative SFD value) • ANT_DIV (Antenna Diversity) • RX_PDT_LEVEL (blocking frame reception of lower power signals) are completely independent from RX_AACK mode (see "Radio Transceiver Extended Feature Set" on page 92). Each of these operating modes can be combined with the RX_AACK mode. 53 8393C-MCU Wireless-09/14

9.4.2.3.2 Configuration of IEEE Scenarios Normal Device The Table 9-7 below shows a typical RX_AACK configuration of an IEEE 802.15.4 device operated as a normal device rather than a PAN coordinator or router. Table 9-7. Configuration of IEEE 802.15.4 Devices Register Name Register Bits Description SHORT_ADDR_0/1 Set node addresses PAN_ADDR_0/1 IEEE_ADDR_0 … IEEE_ADDR_7 RX_SAFE_MODE 7 0: disable frame protection 1: enable frame protection SLOTTED_OPERATION 0 0: if transceiver works in unslotted mode 1: if transceiver works in slotted mode AACK_FVN_MODE 7:6 Controls the ACK behavior, depending on FCF frame version number 0x00 : acknowledges only frames with version number 0, i.e. according to IEEE 802.15.4-2003 frames 0x01 : acknowledges only frames with version number 0 or 1, i.e. frames according to IEEE 802.15.4-2006 0x10 : acknowledges only frames with version number 0 or 1 or 2 0x11 : acknowledges all frames, independent of the FCF frame version number Notes: 1. If no short address has been configured before the device has been assigned one by the PAN-coordinator, only frames directed to either the broadcast address or the IEEE address are received. 2. In IEEE 802.15.4-2003 standard the frame version subfield did not yet exist but was marked as reserved. According to this standard, reserved fields have to be set to zero. On the other hand, IEEE 802.15.4-2003 standard requires ignoring reserved bits upon reception. Thus, there is a contradiction in the standard which can be interpreted in two ways: a) If a network should only allow access to nodes which use the IEEE 802.15.4 -2003, then AACK_FVN_MODE should be set to 0. b) If a device should acknowledge all frames independent of its frame version, AACK_FVN_MODE should be set to 3. However, this can result in conflicts with co-existing IEEE 802.15.4-2006 standard compliant networks. The same holds for PAN coordinators as described below. PAN-Coordinator Table 9-8 on page 55 shows the RX_AACK configuration for a PAN coordinator. ATmega256/128/64RFR2 54 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 Table 9-8. Configuration of a PAN Coordinator Register Name Register Bits Description SHORT_ADDR_0/1 Set node addresses PAN_ADDR_0/1 IEEE_ADDR_0 … IEEE_ADDR_7 RX_SAFE_MODE 7 0: disable frame protection 1: enable frame protection SLOTTED_OPERATION 0 0: if transceiver works in unslotted mode 1: if transceiver works in slotted mode AACK_I_AM_COORD 3 1: device is PAN coordinator AACK_SET_PD 5 0: frame pending subfield is not set in FCF 1: frame pending subfield is set in FCF AACK_FVN_MODE 7:6 Controls the ACK behavior, depends on FCF frame version number 0x00 : acknowledges only frames with version number 0, i.e. according to IEEE 802.15.4-2003 frames 0x01 : acknowledges only frames with version number 0 or 1, i.e. frames according to IEEE 802.15.4-2006 0x10 : acknowledges only frames with version number 0 or 1 or 2 0x11 : acknowledges all frames, independent of the FCF frame version number Promiscuous Mode The promiscuous mode is described in IEEE 802.15.4-2006, section 7.5.6.5. This mode is further illustrated in Radio Transceiver Extended Feature Set on page 92. According to IEEE 802.15.4-2006 when in promiscuous mode, the MAC sub layer shall pass received frames with correct FCS to the next higher layer without further processing. That implies that frames should never be acknowledged. Only second level filter rules as defined by IEEE 802.15.4-2006, section 7.5.6.2, are applied to the received frame. Table 9-9 below shows the typical configuration of a device operating in promiscuous mode. Table 9-9. Configuration of Promiscuous Mode Register Name Register Bits Description SHORT_ADDR_0/1 Each address shall be set: 0x00 PAN_ADDR_0/1 IEEE_ADDR_0 … IEEE_ADDR_7 AACK_PROM_MODE 1 1: Enable promiscuous mode AACK_DIS_ACK 4 1: Disable generation of acknowledgment 55 8393C-MCU Wireless-09/14

Register Name Register Bits Description AACK_FVN_MODE 7:6 Controls the ACK behavior, depends on FCF frame version number 0x00 : acknowledges only frames with version number 0, i.e. according to IEEE 802.15.4-2003 frames 0x01 : acknowledges only frames with version number 0 or 1, i.e. frames according to IEEE 802.15.4-2006 0x10 : acknowledges only frames with version number 0 or 1 or 2 0x11 : acknowledges all frames, independent of the FCF frame version number Second level of filtering according to IEEE 802.15.4-2006, section 7.5.6.2, is applied to a received frame if the radio transceiver is in promiscuous mode. However, a TRX24_RX_END interrupt is issued even if the FCS is invalid. Thus it is necessary to read bit RX_CRC_VALID of register PHY_RSSI after the TRX24_RX_END interrupt in order to verify the reception of a frame with a valid FCS. If a device, operating in promiscuous mode, receives a frame with a valid FCS which in addition passed the third level filtering according to IEEE 802.15.4-2006, section 7.5.6.2, an acknowledgement frame would be transmitted. According to the definition of the promiscuous mode a received frame shall not be acknowledged even if it is requested. Thus bit AACK_DIS_ACK of register CSMA_SEED_1 has to be set to 1. In all receive modes a TRX24_AMI interrupt is issued, when the received frame matches the node’s address according to the filter rules described in section "Frame Filtering" on page 58. Alternatively, in RX_ON state of the Basic Operating Mode when a valid PHR is detected a TRX24_RX_START interrupt is generated and the frame is received. The end of the frame reception is signalized with a TRX24_RX_END interrupt. At the same time the bit RX_CRC_VALID of register PHY_RSSI is updated with the result of the FCS check (see "Overview" on page 72). The RX_CRC_VALID bit must be checked in order to dismiss corrupted frames according to the definition of the promiscuous mode. 9.4.2.3.3 Configuration of non IEEE 802.15.4 Compliant Scenarios Sniffer Table 9-10 below shows a RX_AACK configuration to setup a sniffer device. Other RX_AACK configuration bit s should be set to their reset values (see Table 9-6 on page 53). All frames received are indicated by a TRX24_RX_START and TRX24_RX_END interrupt. Bit RX_CRC_VALID of register PHY_RSSI is updated after frame reception with the result of the FCS check (see "Overview" on page 72). The RX_CRC_VALID bit needs to be checked in order to dismiss corrupted frames. Table 9-10. Configuration o f a Sniffer Device Register Name Register Bits Description AACK_PROM_MODE 1 1: Enable promiscuous mode AACK_DIS_ACK 4 1: Disable generation of acknowledgment This operating mode is similar to the promiscuous mode. ATmega256/128/64RFR2 56 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 Reception of Reserved Frames Frames with reserved frame types (see section Table 9-19 on page 69) can also be handled in RX_AACK mode. This might be required when implementing proprietary, non-standard compliant protocols. It is an extension of the address filtering in RX_AACK mode. Received frames are either handled similar to data frames or may be allowed to completely bypass the address filter. Table 9-11 below shows the required configuration for a node to receive reserved frames and Figure 9-20 on page 52 shows the corresponding flow chart. Table 9-11. RX_AACK Configuration to Receive Reserved Frame Types Register Name Register Bits Description SHORT_ADDR_0/1 Set node addresses PAN_ADDR_0/1 IEEE_ADDR_0 … IEEE_ADDR_7 RX_SAFE_MODE 7 0: disable frame protection 1: enable frame protection AACK_UPLD_RES_FT 4 1 : Enable reserved frame type reception AACK_FLTR_RES_FT 5 Filter reserved frame types like data frame type, see note below 0 : disable 1 : enable SLOTTED_OPERATION 0 0: if transceiver works in un-slotted mode 1: if transceiver works in slotted mode AACK_I_AM_COORD 3 0: device is not PAN coordinator 1: device is PAN coordinator AACK_DIS_ACK 4 0: Enable generation of acknowledgment 1: Disable generation of acknowledgment AACK_FVN_MODE 7:6 Controls the ACK behavior, depends on FCF frame version number 0x00 : acknowledges only frames with version number 0, i.e. according to IEEE 802.15.4-2003 frames 0x01 : acknowledges only frames with version number 0 or 1, i.e. frames according to IEEE 802.15.4-2006 0x10 : acknowledges only frames with version number 0 or 1 or 2 0x11 : acknowledges all frames, independent of the FCF frame version number There are two different optio ns for handling reserved frame types. 1. AACK_UPLD_RES_FT = 1, AACK_FLT_RES_FT = 0: Any non-corrupted frame with a reserved frame type is indicated by a TRX24_RX_END interrupt. No further address filtering is applied on those frames. A TRX24_AMI interrupt is never generated and the acknowledgment subfield is ignored. 2. AACK_UPLD_RES_FT = 1, AACK_FLT_RES_FT = 1: 57 8393C-MCU Wireless-09/14

If AACK_FLT_RES_FT = 1 any frame with a reserved frame type is filtered by the address filter similar to a data frame as described in the standard. Consequently, a TRX24_AMI interrupt is generated upon address match. A TRX24_RX_END interrupt is only generated if the address matched and the frame was not corrupted. An acknowledgment is only send, when the ACK request subfield was set in the received frame and a TRX24_RX_END interrupt occurred. Note that It is not allowed to set AACK_FLTR_RES_FT = 1 and have register bit AACK_FLTR_RES_FT set to 0. Short Acknowledgment Frame (ACK) Start Timing The bit AACK_ACK_TIME of register XAH_CTRL_1 defines the symbol time between frame reception and transm ission of an acknowledgment frame. Table 9-12. Overview of RX_AACK Configuration Bits Register Name Register Bit Description AACK_ACK_TIME 2 0: Standard compliant acknowledgement timing of 12 symbol periods. In slotted acknowledgement operation mode, the acknowledgment frame transmission can be triggered 6 symbol periods after reception of the frame earliest. 1: Reduced acknowledgment timing of 2 symbol periods (32 µs). Note that this feature can be used in all scenarios, independent of other configurations. However, shorter acknowledgment timing is especially useful when using High Data Rate Modes to increase bat tery lifetime and to improve the overall data throughput; see "High Data Rate Modes" on page 93 for details. 9.4.2.4 Frame Filtering Frame Filtering is an evaluation whether or not a received frame is dedicated for this node. To accept a receiv ed frame and to generate an address match interrupt (TRX24_AMI) a filtering procedure as described in IEEE 802.15.4-2006 chapter 7.5.6.2. (Third level of filtering) is applied to the frame. The radio transceiver’s RX_AACK mode accepts only frames that satisfy all of the following requirements (quote from IEEE 802.15.4-2006, 7.5.6.2): 1. The Frame Type subfield shall not contain a reserved frame type. 2. The Frame Version subfield shall not contain a reserved value. 3. If a destination PAN identifier is included in the frame, it shall match macPANId or shall be the broadcast PAN identifier (0xFFFF). 4. If a short destination address is included in the frame, it shall match either macShortAddress or the broadcast address (0xFFFF). Otherwise, if an extended destination address is included in the frame, it shall match aExtendedAddress. 5. If the frame type indicates that the frame is a beacon frame, the source PAN identifier shall match macPANId unless macPANId is equal to 0xFFFF, in which case the beacon frame shall be accepted regardless of the source PAN identifier. 6. If only source addressing fields are included in a data or MAC command frame, the frame shall be accepted only if the device is the PAN coordinator and the source PAN identifier matches macPANId. The radio transceiver requires two additional rules: 1. The frame type indicates that the frame is not an ACK frame (refer toTable 9-7 on page 54). ATmega256/128/64RFR2 58 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 2. At least one address field must be configured. Address match, indicated by the TRX24_AMI interrupt is further controlled by the content of subfields of the frame control field of a received frame according to the following rule: If (Destination Addressing Mode = 0 OR 1) AND (Source Addressing Mode = 0) no TRX24_AMI interrupt is generated, refer to Figure 9-27 on page 69. This effectively causes all acknowledgement frames not to be announced which otherwise always pass the filter regardless of whether they are intended for this device or not. For backward compatibility to IEEE 802.15.4-2003 third level filter rule 2 (Frame Version) can be disabled by the bits AACK_FVN_MODE of register CSMA_SEED_1. Frame filtering is available in Extended and Basic Operating Mode (see section "Basic Operating Mode" on page 38); a frame passing the frame filtering generates an TRX24_AMI interrupt, if enabled. Note: 1. Filter rule 1 is affected by register bits AACK_FLTR_RES_FT and AACK_UPLD_RES_FT (see register "XAH_CTRL_1 – Transceiver Acknowledgment Frame Control Register 1" on page 133). 2. Filter rule 2 is affected by register bits AACK_FVN_MODE (see register "CSMA_SEED_1 – Transceiver Acknowledgment Frame Control Register 2" on page 144). 9.4.2.4.1 RX_AACK Slotted Operation – Slotted Acknowledgement The radio transceiver supports slotted acknowledgement operation according to IEEE 802.15.4-2006, section 5.5.4.1. In RX_AACK mode with bit SLOTTED_OPERATION of register XAH_CTRL_0 set, the transmission of an acknowledgement frame has to be controlled by the microcontroller. If an ACK frame has to be transmitted the radio transceiver expects writing SLPTR=1 to actually start the transmission. This waiting state is signaled 6 symbol periods after the reception of the last symbol of a data or MAC command frame by bits TRAC_STATUS of register XAH_CTRL_0, which are set to SUCCESS_WAIT_FOR_ACK in that case. In networks using slotted operation the start of the acknowledgment frame and thus the exact timing must be provided by the microcontroller. A timing example of an RX_AACK transaction with bit SLOTTED_OPERATION of register XAH_CTRL_0 set is shown in the next figure. The acknowledgement frame is ready to transmit 6 symbol times after the reception of the last symbol of a data or MAC command frame. The transmission of the acknowledgement frame is initiated by the microcontroller by writing S LPTR=1 and starts 16µs (t ) later. The interrupt latency TR10 t is specified in section "Digital Interface Timing Characteristics" on page 563. IRQ 59 8393C-MCU Wireless-09/14

Figure 9-11. Example Timing of an RX_AACK Transaction for Slotted Operation 0 64 512 704 1026 time [µs] Frame Type S F D Data Frame (Length = 10, ACK=1) ACK Frame Frame on Air TRX_STATE RX_AACK_ON BUSY_RX_AACK RX_AACK_ON RX/TX RRXX TTXX RRXX IRQ TRX24_RX_END TRX24_TX_END TX X/ Typ. Processing Delay tIRQ tIRQ R 96 µs ACK transmission initiated by microcontroller (6 symbols) waiting period signaled by registe r bits TRAC_STATUS SLPTR SLPTR tTR10 If bit AACK_ACK_TIME of register XAH_CTRL_1 is set, an acknowledgment frame can be sent already 2 symbol times after the reception of the last symbol of a data or MAC command frame. 9.4.2.4.2 RX_AACK Mode Timing A timing example of an RX_AACK transaction is shown in the next figure. In this example a data frame of length 10 with an ACK request is received. The radio transceiver changes to state BUSY_RX_AACK after SFD detection. The completion of the frame reception is indicated by a TRX24_RX_END interrupt. Interrupts TRX24_RX_START and TRX24_AMI are disabled in this example. The ACK frame is automatically transmitted after a default wait period of 12 symbols (192 µs), bit AACK_ACK_TIME = 0 (reset value). The interrupt latency t is specified in section IRQ "Digital Interface Timing Characteristics" on page 563. Figure 9-12. Example Timing of an RX_AACK Transaction 0 64 512 704 1088 time [µs] Frame Type S F D Data Frame (Length = 10, ACK=1) ACK Frame Frame on Air TRX_STATE RX_AACK_ON BUSY_RX_AACK RX_AACK_ON RX/TX RX TX RX X T IRQ TRX24_RX_END TRX24_TX_END RX/ Typ. Processing Delay tIRQ tIRQ 192 µs (12 symbols) If bit AACK_ACK_TIME of register XAH_CTRL_1 is set, an acknowledgment frame is sent already 2 symbol times after the reception of the last symbol of a data or MAC command frame. 9.4.2.5 MAF – Multiple Address Filter Certain scenarios, like different PANs, may require to extend the address filter to multiple PANs. The address filter was extended to support four PANs. The address filter unit consists of four independent filter blocks. The incoming signal is analyzed in parallel by all filter blocks. Each block can be enabled separately and is ATmega256/128/64RFR2 60 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 configured by a short address and pan ID. The IEEE 64 bit address is the same for every filter block. There are some separate configuration bits for every filter block (see Table 9-13 below). Table 9-13. Additional regi ster set for Multiple Address Filter Register Name Description {MAFSA0H,MAFSA0L} short address for filter #0 both register are mirror register of {SHORT_ADDR_1,SHORT_ADDR_0} {MAFSA1H,MAFSA1L} short address for filter #1 {MAFSA2H,MAFSA2L} short address for filter #2 {MAFSA3H,MAFSA3L} short address for filter #3 {MAFPA0H,MAFPA0L} Pan ID for filter #0 both register are mirror register of {PAN_ID_1,PAN_ID_0} {MAFPA1H,MAFPA1L} Pa n ID for filter #1 {MAFPA2H,MAFPA2L} Pan ID for filter #2 {MAFPA3H,MAFPA3L} Pan ID for filter #3 MAFCR0 bits MAFxEN to enable filter #x MAFCR1 bits AACK_I_AM_COORDx to enable filter #x as coordinator bits AACK_SET_PDx to enable pending data bit of filter #x TRX24_AMIx each address filter #x generates the respective TRX24_AMIx int errupt Note: There are some register which are mirrored. • MAFSA0H <--> SHORT_ADDR_0 • MAFSA1H <--> SHORT_ADDR_1 • MAFPA0H <--> PAN_ID_0 • MAFPA1H <--> PAN_ID_1 • bit AACK_I_AM_COORD (register CSMA_SEED_1) <--> bit AACK_I_AM_COORD0 (register MAFCR1) • bit AACK_SET_PD (register CSMA_SEED_1) <--> bit AACK_SET_PD (register MAFCR1) That means access to the registers is equal, the internal function can be written or read by both registers. Bit MAF0EN is set by reset to provide backward compatibility. The four address filter blocks generate four address match interrupts. Table 9-14. Additional AMI Interrupts for Multiple Address Filter Interrupt Name Description TRX24_AMI0 address match interrupt from address filter #0, enabled bit AMI0 in register IRQ_MASK1 is set TRX24_AMI1 address match interrupt from address filter #1, enabled bit AMI1 in register IRQ_MASK1 is set TRX24_AMI2 address match interrupt from address filter #2, enabled bit AMI2 in register IRQ_MASK1 is set 61 8393C-MCU Wireless-09/14

Interrupt Name Description TRX24_AMI3 address match interrupt from address filter #3, enabled bit AMI3 in register IRQ_MASK1 is set Note: If bit AMI_EN is set in register IRQ_MASK, interrupt TRX24_XAH_AMI occures if any of the four filter detects an address match. It is not allowed to configure two enabled address filter to the same short address and PAN. ATmega256/128/64RFR2 62 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 9.4.2.6 TX_ARET_ON – Transmit with Automatic Retry and CSMA-CA Retry Figure 9-13. Flow Diagram of TX_ARET TRX_STATE = TX_ARET_ON frame_rctr = 0 N Start TX Y TRX_STATE = BUSY_TX_ARET TRAC_STATUS = INVALID (see Note 1) Note 1: If MAX_CSMA_RETRIES = 7 no retry is performed N MAX_CSMA_RETRIES <7 Y csma_rctr = 0 Random Back-Off csma_rctr = csma_rctr + 1 CCA N CCA Failure csma_ rctr > Y Result MAX_CSMA_RETRIES Success Transmit Frame frame_rctr = frame_rctr + 1 N ACK requested Y N Receive ACK until timeout Y Y ACK valid N N frame_rctr > N MAX_FRAME_RETRIES Data Pending Y Y TRAC_STATUS = TRAC_STATUS = TRAC_STATUS = TRAC_STATUS = NO_ACK SUCCESS_DATA_PENDING SUCCESS CHANNEL_ACCESS_FAILURE Issue TRX24_TX_END interrupt TRX_STATE = TX_ARET_ON 63 8393C-MCU Wireless-09/14

Overview The implemented TX_ARET algorithm is shown in Figure 9-13 on page 63. In TX_ARET mode, the radio transceiver first executes the CSMA-CA algorithm, as defined by IEEE 802.15.4–2006, section 7.5.1.4, initiated by a transmit start event. If the channel is IDLE a frame is transmitted from the Frame Buffer. If the acknowledgement frame is requested the radio transceiver additionally checks for an ACK reply. A TRX24_TX_END interrupt indicates the completion of the TX_ARET transmit transaction. Description Configuration and address bits are to be set in TRX_OFF or PLL_ON state prior to switching to TX_ARET mode. It is further recommended to transfer the PSDU data to the Frame Buffer in advance. The transaction is started by either writing SLPTR=1 as described in section "Transceiver Pin Register TRXPR" on page 35 or writing a TX_START command to register TRX_STATE. If the CSMA-CA detects a busy channel, it is retried as specified by bits MAX_CSMA_RETRIES of register XAH_CTRL_0. In case that CSMA-CA does not detect a clear channel after MAX_CSMA_RETRIES it aborts the TX_ARET transaction, issues a TRX24_TX_END interrupt and sets the value of the TRAC_STATUS register bits to CHANNEL_ACCESS_FAILURE. During transmission of a frame the radio transceiver parses bit 5 (ACK Request) of the MAC header (MHR) frame control field of the PSDU data (PSDU octet #1) to be transmitted to check if an AC K reply is expected. If an ACK is expected the radio transceiver automatically switches into receive mode to wait for a valid ACK reply. After receiving an ACK frame the Frame Pending subfield of that frame is parsed and the status register bits TRAC_STATUS are updated accordingly (see Table 9-19 below). This receive procedure does not overwrite the Frame Buffer content. Tran smit data in the Frame Buffer is not changed during the entire TX_ARET transaction. Received frames other than the expected ACK frame are discarded. If no valid ACK is received or after timeout of 54 symbol periods (864 µs), the radio transceiver retries the entire transaction (including CSMA-CA) until the maximum number of retransmissions as set by the bits MAX_FRAME_RETRIES in register XAH_CTRL_0 is exceeded. After that, the microcontroller may read the value of the bits TRAC_STATUS of register TRX_STATE to verify whether the transaction was successful or not. The register bits are set according to the following cases: Table 9-19. Interpretation of the TRAC_STATUS register bits Value Name Description 0 SUCCESS The transaction was responded by a valid ACK, or, if no ACK is requested, after a successful frame transmission 1 SUCCESS_DATA_PENDING Equivalent to SUCCESS; indicates pending frame data according to the MHR frame control field of the received ACK response 3 CHANNEL_ACCESS_FAILURE Channel is still busy after MAX_CSMA_RETRIES of CSMA-CA ATmega256/128/64RFR2 64 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 Value Name Description 5 NO_ACK No acknowledgement frames were received during all retry attempts 7 INVALID Entering TX_ARET mode sets TRAC_STATUS = 7 Note that if no ACK is expected (according to the content of the received frame in the Frame Buffer), the radio transceiver issues a TRX24_TX_END interrupt directly after the frame transmission has been completed. The value of the bits TRAC_STATUS of register TRX_STATE is set to SUCCESS. A value of MAX_CSMA_R ETRIES = 7 initiates an immediate TX_ARET transaction without performing CSMA-CA. This is required to support slotted acknowledgement operation. Further the value MAX_FRAME_RETRIES is ignored and the TX_ARET transaction is performed only once. A timing example of a TX_ARET transaction is shown in Figure 9-14 below . Figure 9-14. Example Timing of a TX_ARET Transaction 0 128 672 x x+352 time [µs] FrameType Data Frame (Length = 10, ACK=1) ACK Frame Frame on Air TRX_STATE TX_ARET_ON BUSY _TX_ARET TX_ARET_ON RX/TX CSMA-CA TTXX RRXX X T SLPTR X/ R IRQ RX_END Typ. Processing Delay tCSMA-CA 16 µs 32 µs tIRQ Note: 1. t defines the random CSMA-CA processing time. CSMA-CA Here an example data frame of length 10 with an ACK request is transmitted, see Table 9-16 on page 66. After the transmission the radio transceiver switches to receive mode and expects an acknowledgement response. During the whole transaction including frame transmit, wait for ACK and ACK receive the radio transceiver status register TRX_STATUS signals BUSY_TX_ARET. A successful reception of the acknowledgment frame is indicated by the TRX24_TX_END interrupt. The status register TRX_STATUS changes back to TX_ARET_ON. The TX_ARET status register TRAC_STATUS changes as well to TRAC_STATUS = SUCCESS or TRAC_STATUS = SUCCESS_DATA_PENDING if the frame pending subfield of the received ACK frame was set to 1. 9.4.2.7 Interrupt Handling The interrupt handling in the Extended Operating Mode is similar to the Basic Operating Mode (see section "Interrupt Handling" on page 42). The microcontroller enables interrupts by setting the appropriate bit in register IRQ_MASK. For RX_AACK and TX_ARET the following interrupts (Table 9-16 on page 66) inform about the status of a frame reception and transmission: 65 8393C-MCU Wireless-09/14

Table 9-16. Interrupt Handling in Extended Operating Mode Mode Interrupt Description RX_AACK TRX24_RX_START Indicates a PHR reception TRX24_AMI Issued at address match TRX24_RX_END Signals completion of RX_AACK transaction if successful - A received frame must pass the address filter; - The FCS is valid TX_ARET TRX24_TX_END Signals completion of TX_ARET transaction Both TRX24_PLL_LOCK Entering RX_AACK_ON or TX_ARET_ON state from TRX_OFF state, the TRX24_PLL_LOCK interrupt signals that the transaction can be started RX_AACK For RX_AACK it is recommended to enable the TRX24_RX_END interrupt. This interrupt is issued only if a frame passes the frame filtering (see section "Frame Filtering" on page 58) and has a valid FCS. This is different to Basic Operating Mode (see section "Basic Operating Mode" on page 38). The use of the other interrupts is optional. On reception of a valid PHR a TRX24_RX_START interrupt is issued. The TRX24_AMI interrupt indicates an address match (see filter rules in section "Frame Filtering" on page 58). The completion of a frame reception with a valid FCS is indicated by the TRX24_RX_END interrupt. Thus it can happen that a TRX24_RX_START and/or a TRX24_AMI interrupt are issued, but no TRX24_RX_END interrupt. The end of an acknowledgment transmission is confirmed by a TRX24_TX_END interrupt. TX_ARET In TX_ARET interrupt TRX24_TX_END is only issued after completing the entire TX_ARET transaction. Acknowledgement frames do not issue a TRX24_RX_START, TRX24_AMI or a TRX24_RX_END interrupt. All other interrupts as described in section Table 9-2 on page 37 are also available in Extended Operating Mode. 9.4.2.8 Register Summary The following registers (Table 9-17 below) are to be configured to control the Extended Operating Mode: Table 9-17. Register Summary Register Name Description TRX_STATUS Radio transceiver status, CCA result TRX_STATE Radio transceiver state control, TX_ARET status TRX_CTRL_1 TX_AUTO_CRC_ON PHY_CC_CCA CCA mode control, Table 9-24 on page 76 CCA_THRES CCA threshold settings, see "Overview" on page 76 XAH_CTRL_1 RX_AACK control ATmega256/128/64RFR2 66 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 Register Name Description IEEE_ADDR_7 …. IEEE_ADDR_0 Address filter configuration PAN_ID_1 Short address, PAN-ID and IEEE address PAN_ID_0 SHORT_ADDR_1 SHORT_ADDR_0 XAH_CTRL_0 TX_ARET control, retries value control CSMA_SEED_0 CSMA-CA seed value CSMA_SEED_1 CSMA-C A seed value, RX_AACK control CSMA_BE CSMA-CA back-off exponent control 9.5 Functional Description 9.5.1 Introduction – IEEE 802.15.4-2006 Frame Format Figure 9-15 below provides an overview of the physical layer (PHY) frame structure as defined by IEEE 802.15.4. Figure 9-16 on page 68 shows the frame structure of the medium access control (MAC) layer. Figure 9-15. IEEE 802.15.4 Frame Format - PHY-Layer Frame Structure (PPDU) 9.5.1.1 PHY Protocol Layer Data Unit (PPDU) 9.5.1.1.1 Synchronization Header (SHR) The SHR consists of a four-octet preamble field (all zero), followed by a single byte start-of-frame delimiter (SFD) which has the predefined value 0xA7. During transmit, the SHR is automatically generated by the radio transceiver, thus the Frame Buffer shall contain PHR and PSDU only. The transmission of the SHR requires 160 µs (10 symbols). As the frame buffer access is normally faster than the over-air data rate, this allows the application software to initiate a transmission without having transferred the full frame data already. Instead it is possible to subsequently write the frame content. During frame reception, the SHR is used for synchronization purposes. The matching SFD determines the beginning of the PHR and the following PSDU payload data. 9.5.1.1.2 PHY Header (PHR) The PHY header is a single octet following the SHR. The least significant 7 bits denote the frame length of the following PSDU, while the most significant bit of that octet is reserved, and shall be set to 0 for IEEE 802.15.4 compliant frames. 67 8393C-MCU Wireless-09/14

On receive the PHR is returned as the first octet during Frame Buffer read access, the most significant bit always set to 0. For IEEE 802.15.4 compliant operation bit 8 has to be masked by software. The reception of a valid PHR is signaled by a TRX24_RX_START interrupt. On transmit the PHR has to be written first to the Frame Buffer. 9.5.1.1.3 PHY Payload (PHY Service Data Unit, PSDU) The PSDU has a variable length between 0 and aMaxPHYPacketSize (127, maximum PSDU size in octets) whereas the last two octets are used for the Frame Check Sequence (FCS). The length of the PSDU is signaled by the frame length field (PHR) as described in Table 9-18 below. The PSDU contains the MAC Protocol Layer Data Unit (MPDU). Received frames with a frame length field set to 0x00 (invalid PHR) are not by an interrupt. Table 9-18 below summarizes the type of payload versus the frame length value. Table 9-18. Frame Length Field - PHR Frame Length Value Payload 0 - 4 Reserved 5 MPDU (Acknowledgement) 6 – 8 Reserved 9 - aMaxPHYPacketSize MPDU 9.5.1.2 MAC Protocol Layer Data Unit (MPDU) Figure 9-16 below shows the frame structure of the MAC layer. Figure 9-16. IEEE 802.15.4 Frame Format - MAC-Layer Fram e Structure (MPDU) 9.5.1.2.1 MAC Header (MHR) Fields The MAC header consists of the Frame Control Field (FCF), a sequence number, and the addressing fields (which are of variable length and can even be empty in certain situations). ATmega256/128/64RFR2 68 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 9.5.1.2.2 Frame Control Field (FCF) The FCF consists of 16 bits, and occupies the first two octets of either the MPDU or the PSDU, respectively. Figure 9-27. IEEE 802.15.4-2006 Frame Control Field (FCF) Bit [2:0]: describe the frame type. Table 9-19 below summarizes frame types defined by IEEE 802.15.4, section 7 .2.1.1.1. Table 9-19. Frame Control Field – Frame Type Subfield Frame Control Field Bit Assignments Description Frame Type Value Value b2 b1 b0 000 0 Beacon 001 1 Data 010 2 Acknowledge 011 3 MAC command 100 – 111 4 – 7 Reserved This subfield is used for address filtering by the third level filter rules. Only frame types 0 – 3 pass the third level filter rules (refer to section "Frame Filtering" on page 58). Automatic address filtering of the radio transceiver is enabled when using the RX_AACK mode (refer to "RX_AACK_ON – Receive with Automatic ACK" on page 50). A reserved frame (frame type value > 3) can be received if bit AACK_UPLD_RES_FT of register XAH_CTRL_1 is set. For details refer to chapter "Configuration of non IEEE 802.15.4 Compliant Scenarios" on page 56. Address filtering is also provided in Basic Operating Mode as explained in "Basic Operating Mode" on page 38. Bit 3: indicates whether security processing applies to this frame. Bit 4: is the “Frame Pending” subfield. This field can be set in an acknowledgment frame (ACK) in response to a data request MAC command frame. This bit indicates that the node, which transmitted the ACK, has more data to send to the node receiving the ACK. For acknowledgment frames automatically generated by the radio transceiver, this bit is set according to the content of bit AACK_SET_PD of register CSMA_SEED_1 if the received frame was a data request MAC command frame. Bit 5: forms the “Acknowledgment Request” subfield. If this bit is set within a data or MAC command frame tha t is not broadcast, the recipient shall acknowledge the reception of the frame within the time specified by IEEE 802.15.4 (i.e. within 192 µs for non beacon-enabled networks). The radio transceiver parses this bit during RX_AACK mode and transmits an acknowledgment frame if necessary. In TX_ARET mode this bit indicates if an acknowledgement frame is expected after transmitting a frame. If this is the case, the receiver waits for the acknowledgment frame, otherwise the TX_ARET transaction is finished. 69 8393C-MCU Wireless-09/14

Bit 6: the “Intra-PAN” subfield indicates that in a frame, where both, the destination and source addresses are present, the PAN-ID of the source address filed is omitted. In RX_AACK mode this bit is evaluated by the address filter logic of the radio transceiver. Bit [11:10]: the “Destinatio n Addressing Mode” subfield describes the format of the destination address of the frame. The values of the address modes are summarized in Table 9-20 below according to IEEE 802.15.4: Table 9-20. Frame Control Field – Destination and Source Addressing Mode Frame Control Field Bit Assignments Description Addressing Mode Value b b 11 10 b15 b14 00 0 PAN identifier and address fields are not present 01 1 Reserved 10 2 Address field contains a 16-bit short address 11 3 Address field contains a 64-bit extended address If the destination address mode is either 2 or 3 (i.e. if the destination address is present), it always consists of a 16-bit PAN-ID first followed by either the 16-bit or 64-bit address as defined by the mode. Bit [13:12]: the “Frame Version” subfield specifies the version number corresponding to the frame. These register bits are reserved in IEEE-802.15.4-2003. This subfield shall be set to 0 to indicate a frame compatible with IEEE 802.15.4-2003 and 1 to indicate an IEEE 802.15.4-2006 frame. All other subfield values shall be reserved for future use. The bit AACK_FVN_MODE of register CSMA_SEED_1 controls the RX_AACK behavior of frame acknowledgements. This register determines if, depending on the Frame Version Number, a frame is acknowledged or not. This is necessary for backward compatibility to IE EE 802.15.4-2003 and for future use. Even if frame version numbers 2 and 3 are reserved, it can be handled by the radio transceiver. For details refer to "CSMA_SEED_1 – Transceiver Acknowledgment Frame Control Register 2" on page 144. See IEEE 802.15.4-2006, section 7.2.3 for details on frame compatibility. Table 9-21. Frame Control Field – Frame Version Subfield Frame Control Field Bit Assignments Description Frame Version Value b b 13 12 00 0 Frames are compatible with IEEE 802.15.4-2003 01 1 Frames are compatible with IEEE 802.15.4-2006 10 2 Reserved 11 3 Reserved Bit [15:14]: the “Source Addressing Mode” subfield, with similar meaning as “Destination Addressing Mode” (refer to Table 9-20 above). The subfields of the FCF (Bits 0–2, 3, 6, 10–15) affect the address filter logic of the radio transceiver while executing a RX_AACK operation (see "RX_AACK_ON – Receive with Automatic ACK" on page 50). ATmega256/128/64RFR2 70 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 9.5.1.2.3 Frame Compatibility between IEEE 802.15.4-2003 and IEEE 802.15.4-2006 All unsecured frames according to IEEE 802.15.4-2006 are compatible with unsecured frames compliant with IEEE 802.15.4-2003 with two exceptions: a coordinator realignment command frame with the “Channel Page” field present (see IEEE 802.15.4- 2006 7.3.8) and any frame with a MAC Payload field larger than aMaxMACSafePayloadSize octets. Compatibility for secured frames is shown in the following table, which identifies the security operating modes for IEEE 802.15.4-2006. Table 9-22. Frame Control Field – Security and Frame Version Frame Control Field Bit Assignments Description Security Enabled Frame Version b3 b13 b12 0 00 No security. Frames are compatible between IEEE 802.15.4-2003 and IEEE 802.15.4-2006. 0 01 No security. Frames are not compatible between IEEE 802.15.4-2003 and IEEE 802.15.4-2006. 1 00 Secured frame formatted according to IEEE 802.15.4-2003. This frame type is not supported in IEEE 802.15.4-2006. 1 01 Secured frame formatted according to IEEE 802.15.4-2006 9.5.1.2.4 Sequence Number The one-octet sequence number following the FCF identifies a particular frame, so that duplicated frame transmissions can be detected. While operating in RX_AACK mode, the content of this field is copied from the frame to be acknowledged into the acknowledgment frame. 9.5.1.2.5 Addressing Fields The addressing fields of the MPDU are used by the radio transceiver for address matching indication. The destination address (if present) is always first, followed by the source address (if present). Each address field consists of the Intra PAN-ID and a device address. If both addresses are present and the “Intra PAN-ID compression” subfield in the FCF is set to one, the source Intra PAN-ID is omitted. Note that in addition to these general rules IEEE 802.15.4 further restricts the valid address combinations for the individual possible MAC frame types. For example the situation where both addresses are omitted (source addressing mode = 0 and destination addressing mode = 0) is only allowed for acknowledgment frames. The address filter in the radio transceiver has been designed to apply to IEEE 802.15.4 compliant frames. It can be configured to handle other frame formats and exceptions. 9.5.1.2.6 Auxiliary Security Header Field The Auxiliary Security Header specifies information required for security processing and has a variable length. This field determines how the frame is actually protected (security level) and which keying material from the MAC security PIB is used (see IEEE 802.15.4-2006, 7.6.1). This field shall be present only if the Security Enabled 71 8393C-MCU Wireless-09/14

subfield b3 is set to one (see section "Frame Compatibility between IEEE 802.15.4- 2003 and IEEE 802.15.4-2006" on page 71). For details of its structure see IEEE 802.15.4-2006, 7.6.2 Auxiliary security header. 9.5.1.2.7 MAC Service Data Unit (MSDU) This is the actual MAC payload. It is usually structured according to the individual frame type. A description can be found in IEEE 802.15.4-2006, chapter 5.5.3.2. 9.5.1.2.8 MAC Footer (MFR) Fields The MAC footer consists of a two-octet Frame Checksum (FCS). For details refer to the following section "Frame Check Sequence (FCS)" below. 9.5.2 Frame Check Sequence (FCS) The Frame Check Sequence (FCS) is characterized by: • Indicate bit errors based on a cyclic redundancy check (CRC) of 16 bit length; • Uses International Telecommunication Union (ITU) CRC polynomial; • Automatically evaluated during reception; • Can be automatically generated during transmission. 9.5.2.1 Overview The FCS is intended for use at the MAC layer to detect corrupted frames at a first level of filtering. It is computed b y applying an ITU CRC polynomial to all transferred bytes following the length field (MHR and MSDU fields). The frame check sequence has a length of 16 bit and is located in the last two bytes of a frame (MAC footer, see Figure 9-16 on page 68). The radio transceiver applies an FCS check on each received frame. The result of the FCS check is stored in bit RX_CRC_VALID of register PHY_RSSI. On transmit the radio transceiver generates and appends the FCS bytes during the frame transmission. This behavior can be disabled by setting the bit TX_AUTO_CRC_ON = 0 in register TRX_CTRL_1. 9.5.2.2 CRC calculation The CRC polynomial used in IEEE 802.15.4 networks is defined by G (x) = x16 + x12 + x5 +1 16 The FCS shall be calculated for transmission using the following algorithm: Let M(x) =b xk−1+bxk−2 +K+b x+b 0 1 k−2 k−1 be the polynomial representing the sequence of bits for which the checksum is to be computed. Multiply M(x) by x16 giving the polynomial N(x)= M(x)⋅x16 Divide N(x) modulo 2 by the generator polynomial G (x) to obtain the remainder 16 polynomial R(x) = r x15 +r x14 +...+r x+r 0 1 14 15 The FCS field is given by the coefficients of the remainder polynomial, R(x). ATmega256/128/64RFR2 72 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 Example: Consider a 5 octet ACK frame. The MHR field consists of 0100 0000 0000 0000 0101 0110. The leftmost bit (b ) is transmitted first in time. The FCS is in this case 0 0010 0111 1001 1110. The leftmost bit (r ) is transmitted first in time. 0 9.5.2.3 Automatic FCS generation The automatic FCS generation is performed with register bit TX_AUTO_CRC_ON = 1 (reset value). This allows th e radio transceiver to autonomously compute the FCS. For a frame with a frame length specified as N (3 ≤ N ≤ 127), the FCS is calculated on the first N-2 octets in the Frame Buffer and the resulting FCS field is transmitted in place of the last two octets from the Frame Buffer. If the automatic FCS generation of the radio transceivers is enabled, the Frame Buffer write access can be stoppe d right after MAC payload. There is no need to write FCS dummy bytes. In RX_AACK mode, when a received frame needs to be acknowledged, the FCS of the ACK frame is always automatically generated by the radio transceiver, independent of the TX_AUTO_CRC_ON setting. Example: A frame transmission of length five with TX_AUTO_CRC_ON set, is started with a Frame Buffer write access of five bytes (the last two bytes can be omitted). The first three bytes are used for FCS generation; the last two bytes are replaced by the internally calculated FCS. 9.5.2.4 Automatic FCS check An automatic FCS check is applied on each received frame with a frame length N ≥ 2. The bit RX_CRC_VALID of register PHY_RSSI is set if the FCS of a received frame is valid. The register bit is updated when issuing a TRX24_RX_END interrupt and remains valid until a new frame reception causes the next TRX24_RX_END interrupt. In RX_AACK mode, the radio transceiver rejects the frame and the TRX24_RX_END interrupt is not issued if the FCS of the received frame is not valid. In TX_ARET mode, the FCS and the sequence number of an ACK are automatically checked. The ACK is not ac cepted if one of those is not correct. 9.5.3 Received Signal Strength Indicator (RSSI) The Received Signal Strength Indicator is characterized by: • Minimum RSSI level is -90 dBm (RSSI_BASE_VAL); • Dynamic range is 81 dB; • Minimum RSSI value is 0; • Maximum RSSI value is 28. 9.5.3.1 Overview The RSSI is a 5-bit value indicating the receive power in the selected channel in steps of 3 dB. No attempt is made to distinguish IEEE 802.15.4 signals from others. Only the 73 8393C-MCU Wireless-09/14

received signal strength is evaluated. The RSSI provides the basis for an ED measurement. See section "Energy Detection (ED)" below for details. 9.5.3.2 Reading RSSI In Basic Operating Mode the RSSI value is valid in any receive state, and is updated every t = 2 µs to register PHY_RSSI. TR25 It is not recommended to read the RSSI value when using the Extended Operating Mode. The automatically generated ED value should then be used (see section "Energy Detection (ED)" below). 9.5.3.3 Data Interpretation The RSSI value is a 5-bit value indicating the receive power in steps of 3 dB and with a range of 0- 28. An RSSI value of 0 indicates a receiver RF input power of P < -90 dBm. For an RSSI RF value in the range of 1 to 28, the RF input power can be calculated as follows: P = RSSI_BASE_ VAL + 3 • (RSSI - 1) [dBm] RF Figure 9-18. Mapping between RSSI Value and Received Input Power 10 0 Measured m] -10 Ideal B [dF -20 R P -30 r e w -40 o P put -50 n -60 r I e v -70 ei c e -80 R -90 -100 0 2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 RSSI 9.5.4 Energy Detection (ED) The Energy Detection (ED) module is characterized by: • 85 unique energy levels d efined; • 1 dB resolution. 9.5.4.1 Overview The receiver ED measurement is used by the network layer as part of a channel selection algorithm. It is an estimation of the received signal power within the bandwidth of an IEEE 802.15.4 channel. No attempt is made to identify or decode signals on the channel. The ED value is calculated by averaging RSSI values over eight symbols (128 µs). ATmega256/128/64RFR2 74 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 For High Data Rate Modes the automated ED measurement duration is reduced to 32 µs as described in "High Data Rate Modes" on page 93. The measurement period in these modes is still 128 µs for manually initiated ED measurements as long as the receiver is in RX_ON state. 9.5.4.2 Measurement Description There are two ways to initiate an ED measurement: • Manually, by writing an arbitrary value to register PHY_ED_LEVEL, or • Automatically, after detection of a valid SHR of an incoming frame. For manually initiated ED measurements the radio transceiver needs to be in one of the states RX_ON or BUSY_RX. The end of the ED measurement is indicated by a TRX24_CCA_ED_DONE interrupt. The automatic ED measurement is started if a SHR is detected. The end of the automatic measurement is not signaled by an interrupt. The measurement result is stored after t = 140 µs (128 µs measurement duration TR26 and processing delay) in reg ister PHY_ED_LEVEL. Thus by using Basic Operating Mode a valid ED value from the currently received frame is accessible 108 µs after the TRX24_RX_START interrupt and remains valid until the next incoming frame generates a new TRX24_RX_START interrupt or until another ED measurement is initiated. When using the Extended Operating Mode it is recommended to mask the TRX24_RX_START interrupt. Hence the interrupt cannot be used as timing reference. A successful frame reception is signalized by the TRX24_RX_END interrupt. The minimum time span between a TRX24_RX_END interrupt and a following SFD detection is t = 96 µs due to the length of the SHR. The ED value needs to be read TR27 within 224 µs including the ED measurement time after the TRX24_RX_END interrupt. Otherwise it could be overwritten by the result of the next measurement cycle. This is important for time critical applications or if the TRX24_RX_START interrupt is not used to indicate the reception of a frame. The values of the register PHY_ED_LEVEL are: Table 9-23. Register Bit PHY_ED_LEVEL Interpretation PHY_ED_LEVEL Description 0xFF Reset value 0x00 … 0x53 ED measurement result of the last ED measurement Note: 1. It is not recomme nded to manually initiate an ED measurement when using the Extended Operating Mode. 9.5.4.3 Data Interpretation The PHY_ED_LEVEL is an 8-bit register. The ED value of the radio transceiver has a valid range from 0x00 to 0x53 with a resolution of 1 dB. All other values do not occur. A value of 0xFF indicates the reset value. A value of PHY_ED_LEVEL = 0 indicates that the measured energy is less than -90 dBm (see parameter RSSI_BASE_VAL in section "Receiver Characteristics" on page 565). Due to environmental conditions (temperature, voltage, semiconductor parameters etc.) the calculated ED value has a maximum tolerance of ±5 dB, this is to be considered as constant offset over the measurement range. An ED value of 0 indicates an RF input power of P ≤ -90 dBm. For an ED value in the RF range of 0 to 83, the RF input power can be calculated as follows: 75 8393C-MCU Wireless-09/14

P = -90 + ED [dBm] RF Figure 9-19. Mapping between values in PHY_ED_LEVEL and Received Input Power 10 0 Measured m] -10 Ideal B d -20 [F R P -30 r e w -40 o P ut -50 p n -60 r I e v -70 ei c Re -80 -90 -100 0 10 20 30 40 50 60 70 80 90 Register PHY_ED_LEVEL Value 9.5.4.4 Interrupt Handling The TRX24_CCA_ED_DONE interrupt is issued at the end of a manually initiated ED measurement. Note that an ED request should only be initiated in one of the receive states. Otherwise the radio transceiver generates a TRX24_CCA_ED_DONE interrupt but no ED measurement was performed. 9.5.5 Clear Channel Assessment (CCA) The main features of the Clear Channel Assessment (CCA) module are: • All 4 modes are available as defined by IEEE 802.15.4-2006 in section 6.9.9; • Adjustable threshold for energy detection algorithm. 9.5.5.1 Overview A CCA measurement is used to detect a clear channel. Four modes are specified by IEEE 802.15.4-2006: Table 9-24. CCA Mode Overview CCA Mode Description 1 Energy above threshold. CCA shall report a busy medium upon detecting any energy above the ED threshold. 2 Carrier sense only. CCA shall report a busy medium only upon the detection of a signal with the modulation and spreading characteristics of an IEEE 802.15.4 compliant signal. The signal strength may be above or below the ED threshold. ATmega256/128/64RFR2 76 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 CCA Mode Description 0, 3 Carrier sense with energy above threshold. CCA shall report a busy medium using a logical combination of - Detection of a signal with the modulation and spreading characteristics of this standard and - Energy above the ED threshold. Where the logical operator may be configured as either OR (mode 0) or AND (mode 3). 9.5.5.2 Configuration and CCA Request The CCA modes are configurable via register PHY_CC_CCA. Usimg the Basic Operating Mode, a CCA request can be initiated manually by setting CCA_REQUEST = 1 of register PHY_CC_CCA, if the radio transceiver is in any RX state. The current channel status (CCA_STATUS) and the CCA completion status (CCA_DONE) are accessible in register TRX_STATUS. The CCA evaluation is don e over eight symbol periods and the result is accessible t = 140 µs (128 µs measurement duration and processing delay) after the request. TR28 The end of a manually initiated CCA measurement is indicated by a TRX24_CCA_ED_DONE interrupt. The sub-register CCA_ED_THRES of register CCA_THRES defines the received power threshold of the “energy above threshold” algorithm. The threshold is calculated by RSSI_BASE_VAL + 2 • CCA_ED_THRES [dBm]. Any received power above this level is interpreted as a busy channel. Note that it is not recommended to manually initiate a CCA measurement when using the Extended Operating Mode. 9.5.5.3 Data Interpretation The current channel status (CCA_STATUS) and the CCA completion status (CCA_DONE) are accessible in register TRX_STATUS. Note, register bits CCA_DONE and CCA_STATUS are cleared in response to a CCA_REQUEST. The completion of a measurement cycle is indicated by CCA_DONE = 1. If the radio transceiver detected no signal (idle channel) during the measurement cycle, the CCA_STATUS bit is set to 1. When using the “energy above threshold” algorithm, any received power above CCA_ED_THRES level is interpreted as a busy channel. The “carrier sense” algorithm reports a busy channel when detecting an IEEE 802.15.4 signal above the RSSI_BASE_VAL (see parameter RSSI_BASE_VAL in "Transceiver Electrical Characteristics" on page 563). The radio transceiver is also able to detect signals below this value, but the detection probability decreases with the signal power. 9.5.5.4 Interrupt Handling The TRX24_CCA_ED_DONE interrupt is issued at the end of a manually initiated CCA measurement. Note: A CCA request should only be initiated in the receive states of Basic Operating Mode. Otherwise the radio transceiver generates a TRX24_CCA_ED_DONE interrupt and sets the register bit CCA_DONE = 1 even if no CCA measurement was performed. 77 8393C-MCU Wireless-09/14

9.5.5.5 Measurement Time The response time for a manually initiated CCA measurement depends on the receiver state. In RX_ON state the CCA measurement is done over eight symbol periods and the result is accessible 140 µs after the request (see section "Configuration and CCA Request" on page 77). In BUSY_RX state the CCA measurement duration depends on the CCA Mode and the CCA request relative to the reception of an SHR. The end of the CCA measurement is indicated by a TRX24_CCA_ED_DONE interrupt. The variation of a CCA measurement period in BUSY_RX state is described in Table 9-25 below. Table 9-25. CCA Measurem ent Period and Access in BUSY_RX state CCA Mode Request within ED measurement(1) Request after ED measurement 1 Energy above threshold. CCA result is available after finishing CCA result is immediately available automated ED measurement period. after request. 2 Carrier sense only. CCA result is immediately available after request. 3 Carrier sense with Energy above threshold (AND). CCA result is available after finishing CCA result is immediately available automated ED measurement period. after request. 0 Carrier sense with Energy above threshold (OR). CCA result is a vailable after finishing CCA result is immediately available automated ED measurement period. after request. Note: 1. After receiving the SHR an automated ED measurement is started with a length of 8 symbol periods (PSDU rate 250 kb/s), refer to section "Energy Detection (ED)" on page 74. This automated ED measurement must be finished to provide a result for the CCA measurement. Only one automated ED measurement per frame is performed. It is recommended to perform CCA measurements in RX_ON state only. To avoid accidental switching to BUSY_RX state the SHR detection can be disabled by setting bit RX_PDT_DIS of register RX_SYN. Refer to section "Receiver (RX)" on page 80 for details. The receiver remains in RX_ON state to perform a CCA measurement until the register bit RX_PDT_DIS is set back to continue the frame reception. In this case the CCA measurement duration is 8 symbol periods. 9.5.6 Link Quality Indication (LQI) According to IEEE 802.15.4 the LQI measurement is a characterization of the strength and/or quality of a received packet. The measurement may be implemented using receiver ED, a signal-to-noise ratio estimation or a combination of these methods. The use of the LQI result by the network or application layers is not specified in this standard. LQI values shall be an integer ranging from 0x00 to 0xFF. The minimum and maximum LQI values (0x00 and 0xFF) should be associated with the lowest and highest quality compliant signals, respectively, and LQI values in between should be uniformly distributed between these two limits. 9.5.6.1 Overview The LQI measurement of the radio transceiver is implemented as a measure of the link quality which can be described with the packet error rate (PER) of this link. A LQI value ATmega256/128/64RFR2 78 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 can be associated with an expected packet error rate. The PER is the ratio of erroneous received frames to the total number of received frames. A PER of zero indicates no frame error whereas at a PER of one no frame was received correctly. The radio transceiver uses correlation results of multiple symbols within a frame to determine the LQI value. This is done for each received frame. The minimum frame length for a valid LQI value is two octets PSDU. LQI values are integers ranging from 0 to 255. The following figure shows an example of a conditional packet error rate when receiving a certain LQI value. Figure 9-20. Conditional Packet Error Rate versus LQI 1 0.9 0.8 0.7 0.6 R E 0.5 P 0.4 0.3 0.2 0.1 0 0 50 100 150 200 250 LQI The values are taken from received frames of PSDU length of 20 octets on transmission channels with reasonable low multipath delay spreads. If the transmission channel characteristic has a higher multipath delay spread than assumed in the example, the PER is slightly higher for a certain LQI value. Since the packet error rate is a statistical value, the PER shown in Figure 9-20 above is based on a huge number of transactions. A reliable estimation of the packet error rate cannot be based on a single or a small number of L QI values. 9.5.6.2 Request a LQI Measurement The LQI byte can be obtained after a frame has been received by the radio transceiver. One additional byte is automatically attached to the received frame containing the LQI value. This information can also be read via Frame Buffer read access, see "User accessible Frame Content" on page 84. The LQI byte can be read after the TRX24_RX_END interrupt. 9.5.6.3 Data Interpretation According to IEEE 802.15.4 a low LQI value is associated with low signal strength and/or high signal distortions. Signal distortions are mainly caused by interference signals and/or multipath propagation. High LQI values indicate a sufficient high signal power and low signal distortions. 79 8393C-MCU Wireless-09/14

Note that the received signal power as indicated by the received signal strength indication (RSSI) value or energy detection (ED) value of the radio transceiver do not characterize the signal quality and the ability to decode a signal. As an example, a received signal with an input power of about 6 dB above the receiver sensitivity likely results in a LQI value close to 255 for radio channels with very low signal distortions. For higher signal power the LQI value becomes independent of the actual signal strength. This is because the packet error rate for these scenarios tends towards zero and further increased signal strength i.e. increasing the transmission power does not decrease the error rate any further. In this case RSSI or ED can be used to evaluate the signal strength and the link margin. ZigBee networks often require the identification of the “best” routing between two nodes. Both the LQI and the RSSI/ED can be used for this, dependent on the optimization criteria. If a low packet error rate (corresponding to high throughput) is the optimization criteria then the LQI value should be taken into consideration. If a low transmission power or the link margin is the optimization criteria then the RSSI/ED value is also helpful. Combinations of LQI, RSS I and ED are possible for routing decisions. As a rule of thumb RSSI and ED values are useful to differentiate between links with high LQI values. Transmission links with low LQI values should be discarded for routing decisions even if the RSSI/ED values are high. This is because RSSI and ED do not say anything about the possibility to decode a signal. It is only an information about the received signal strength whereas the source can be an interferer. 9.6 Module Description 9.6.1 Receiver (RX) 9.6.1.1 Overview The receiver is split into an analog radio front-end and a digital base band processor (RX BBP) according to the following figure. The digital base band processor and the control engine are connected to the Frame Buffer and control registers which are located in the microcontroller I/O memory space (see "I/O Memory" on page 28 and "Transceiver to Microcontroller Interface" on page 34 ). Figure 9-21. Receiver Block Diagram Analog Domain Digital Domain I/O LO Memory Space µC I/F RFP $01FF RX LNA PPF BPF Limiter RX BBP Frame ADC Buffer RFN $0180 $017F RSSI Registers AGC Control $0140 The differential RF signal is amplified by a low noise amplifier (LNA), filtered (PPF) and down converted to an intermediate frequency by a mixer. Channel selectivity is performed using an integrated band pass filter (BPF). A limiting amplifier (Limiter) provides sufficient gain to overcome the DC offset of the succeeding analog-to-digital ATmega256/128/64RFR2 80 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 converter (RX ADC) and generates a digital RSSI signal. The ADC output signal is sampled and processed further by the digital base band receiver (RX BBP). The RX BBP performs additional signal filtering and signal synchronization. The frequency offset of each frame is calculated by the synchronization unit and is used during the remaining receive process to correct the offset. The receiver is designed to handle frequency and symbol rate deviations up to ±120 ppm caused by combined receiver and transmitter deviations. For details refer to chapter "General RF Specifications" on page 564. Finally the signal is demodulated and the data are stored in the Frame Buffer. In Basic Operating Mode (see "Basic Operating Mode" on page 38), the reception of a frame is indicated by a TRX24_RX_START interrupt. Accordingly its end is signalized by a TRX24_RX_END inte rrupt. Based on the quality of the received signal a link quality indicator (LQI) is calculated and appended to the frame. For details refer to. Additional signal processing is applied to the frame data to provide further status information like ED value (register PHY_ED_LEVEL) and FCS correctness (register PHY_RSSI). Beyond these features the E xtended Operating Mode of the radio transceiver supports address filtering and pending data indication. For details refer to "Extended Operating Mode" on page 47. 9.6.1.2 Frame Receive Procedure The frame receive procedure including the radio s setup for reception and reading PSDU data from the Frame Buffer is described in "Frame Receive Procedure" on page 90. 9.6.1.3 Configuration In Basic Operating Mode the receiver is enabled by writing command RX_ON to the TRX_CMD bits of register TRX_STATE in the states TRX_OFF or PLL_ON. Similarly in Extended Operating Mode the receiver is enabled for RX_AACK operation from the states TRX_OFF or PLL_O N by writing the command RX_AACK_ON. There is no additional configuration required to receive IEEE 802.15.4 compliant frames when using the Basic Operating Mode. However, the frame reception in the Extended Operating Mode requires further register configurations. For details refer to "Extended Operating Mode" on page 47. The receiver has an outstanding sensitivity performance of -100 dBm. At certain environmental conditions or for High Data Rate Modes (see "High Data Rate Modes" on page 93) it may be useful to manually decrease this sensitivity. This is achieved by adjusting the detector threshold of the synchronization header using the RX_PDT_LEVEL bits of register RX_SYN. Received signals with a RSSI value below the threshold do not activate the demodulation process. Furthermore, it may be useful to protect a received frame against overwriting by subsequent received frames. A Dynamic Frame Buffer Protection is enabled with register bit RX_SAFE_MODE (TRX_CTRL_2) set (refer to "Dynamic Frame Buffer Protection" on page 99). After a frame has been received, the buffer is protected for new incoming frames and the receiver remains in RX_ON or RX_AACK_ON state until the RX_SAFE_MODE bit is cleared by the controller. The Frame Buffer content is only protected if the FCS is valid. A Static Frame Buffer Protection is enabled with bit RX_PDT_DIS of register RX_SYN set. The receiver remains in RX_ON or RX_AACK_ON state and no further SHR is detected until the register bit RX_PDT_DIS is set back. 81 8393C-MCU Wireless-09/14

9.6.2 Transmitter (TX) 9.6.2.1 Overview The transmitter consists of a digital base band processor (TX BBP) and an analog front end as shown in the following figure. Figure 9-22. Transmitter Block Diagram $0140 Ext. RF front-end and DIG3/4 Output Power Control Control Registers $017F $0180 RFP Frame PA Buf PLL – TX Modulation TX BBP Buffer TX Data $01FF RFN I/O Memory µC Analog Domain Digital Domain Space I/F The TX BBP reads the frame data from the Frame Buffer and performs the bit-to- symbol and symbol-to-chip mapping as specified by IEEE 802.15.4 in section 6.5.2. The O-QPSK modulation signal is generated and fed into the analog radio front end. The fractional-N frequency synthesizer (PLL) converts the baseband transmit signal to the RF signal which is amplified by the power amplifier (PA). The PA output is internally connected to bidirectional differential antenna pins (RFP, RFN) so that no external antenna switch is needed. 9.6.2.2 Frame Transmit Procedure The frame transmit procedure including writing PSDU data in the Frame Buffer and initiating a transmission is described in section "Frame Transmit Procedure" on page 91. The controller must ensure to provide valid frame data before starting the frame transmission. For save operation, it is recommended to write the complete frame into the Frame Buffer before starting the frame transmission. 9.6.2.3 Configuration The maximum output power of the transmitter is typically +3.5 dBm. The output power can be configured via the TX_PWR bits of register PHY_TX_PWR. The output power of the transmitter can be controlled over a 20 dB range. A transmission can be started from PLL_ON or TX_ARET_ON state by writing ‘1’ to bit SLPTR of the TRXPR register or by writing TX_START command to the TRX_CMD bits of register TRX_STATE. 9.6.2.4 TX Power Ramping To optimize the TX output power spectral density (PSD) the TX may be controlled by register PHY_TX_PWR and PARCR. The PA ramps up prior to TX data sent and ramps down after the TX data are completed. The signal sent during PA ramp up/down process is not modulated. The PLL frequency (+500kHz or -500kHz relative to carrier frequency) may be selected, separate for the PA ramp up and down process. A timing example using default settings illustrates the sequence in the next figure. In this example the transmission is initiated with the rising edge of the SLPTR bit. The modulation starts 16 µs after SLPTR. ATmega256/128/64RFR2 82 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 Figure 9-23. TX Power Ramping When using en external RF front-end (refer to "RX/TX Indicator" on page 97) it may be required to adjust the startup time of the external PA relative to the internal building blocks to optimize the overall PSD. This can be achieved by PARCR register in the bits PALTU/PALTD. 9.6.2.5 TX Spectrum side lobe suppression The output signal TX may be filtered to suppress spectral side lobes. This might be necessary if an external PA is used. By setting bit PLL_TX_FLT of register TRX_CTRL_1, the TX signal will be filtered. Filtering has influence to signal quality, thus EVM of the transmit signal slightly degrades (refer to Transmitter Characteristics on page 564). 9.6.3 Frame Buffer The radio transceiver contai ns a 128 byte dual port SRAM. One port of the frame buffer is directly connected to the controller I/O space. Therefore random access to single frame bytes is possible. The other port connects to the internal transmitter and receiver modules. Both ports are independent and simultaneously accessible for data communication. The Frame Buffer uses the controller I/O address space 0x180 to 0x1FF for RX and TX operation of the radio transceiver and can keep one IEEE 802.15.4 RX or one TX frame of maximum length at a time. Frame Buffer access is only possible if the radio transceiver is enabled (PRTRX24 bit in the Power Reduction Register PRR1 is not set) and not in SLEEP state. 9.6.3.1 Data Management Data in the Frame Buffer (received data or data to be transmitted) remain valid as long as: • No new frame or other data are written into the buffer; • No new frame is received (in any BUSY_RX state); • No state change into radio transceiver SLEEP state is made; • No radio transceiver RESET (see bit TRXRST in "TRXPR – Transceiver Pin Register" on page 199) or system reset took place; 83 8393C-MCU Wireless-09/14

• Bit PRTRX24 in register "PRR1 – Power Reduction Register 1" on page 198 is not set; By default there is no protection of the Frame Buffer against overwriting. If a frame is received during a Frame Buffer read access of a previously received frame, the stored data might be overwritten. Finally the application software should check the transferred frame data integrity by a FCS check. The state of the radio transceiver should be changed to PLL_ON state after reception to protect the Frame Buffer content against overwriting with new, incoming frames. This can be achieved by writing immediately the command PLL_ON to the TRX_CMD bits of register TRX_STATE after receiving the frame indicated by a TRX24_RX_END interrupt. Alternatively Dynamic Frame Buffer Protection can be used to protect received frames against overwriting. For details refer to "Dynamic Frame Buffer Protection" on page 99. Both procedures do not protect the Frame Buffer from overwriting by the application software. In Extended Operating Mode during TX_ARET operation (see "TX_ARET_ON – Transmit with Automatic Retry and CSMA-CA Retry" on page 63) the radio transceiver switches to receive if an acknowledgement of a previously transmitted frame was requested. During this period received frames are evaluated but not stored in the Frame Buffer. This allows the radio transceiver to wait for an acknowledgement frame and retry the frame transmission without writing the frame data to the Frame Buffer again. A radio transceiver state change except a transition to radio transceiver SLEEP state or a radio transceiver RESET does not affect the Frame Buffer content. The Frame Buffer is powered off and the stored data gets lost if the radio transceiver is forced into radio transceiver SLEEP state. Access conflicts may occur when reading and writing data simultaneously at the two independent ports of the Frame Buffer TX/RX BBP and Controller interface. 9.6.3.2 User accessible Frame Content The radio transceiver supports an IEEE 802.15.4 compliant frame format as shown in the following figure. Figure 9-32. Transceiver Frame Structure 0 Length [octets] 4 5 6 y + 3 y + 5 y + 6 Frame Preamble Sequence SFD PHR(1) Payload FCS LQI(2) Duration 4 octets / 128 µs 1 y octets / y • 32 µs (y <= 128) 1 SHR not accesible TX: Frame Buffer content Access PHY generated RX: Frame Buffer content Notes: 1. Stored into Frame Buffer for TX operation 2. Stored into Frame Buffer during frame reception. A frame comprises two sections. The radio transceiver internally generated SHR field and the user accessible part are stored in the Frame Buffer. The SHR contains the ATmega256/128/64RFR2 84 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 preamble and the SFD field. The variable frame section contains the PHR and the PSDU including the FCS (see "Overview" on page 72). The Frame Buffer content differs depending on the direction of the communication (receive or transmit). To access the data follow the procedures described in "Radio Transceiver Usage" on page 90. During frame reception, the payload and the link quality indicator (LQI) value of a successfully received frame are stored in the Frame Buffer. The radio transceiver appends the LQI value to the frame data after the last received octet. Information of the frame length is not stored in the Frame Buffer. The frame length information is located in register TST_RX_LENGTH. The SHR (except the SFD used to generate the last octet of the SHR) can generally not be read by the application software. The PHR and the PSDU need to be stored in the Frame Buffer for frame transmission. The PHR byte is the first byte in the Frame Buffer (address 0x180) and must be calculated based on the PHR and the PSDU. The maximum frame size supported by the radio transceiver is 128 bytes. If the TX_AUTO_CRC_ON bit is set in the register TRX_CTRL_1 – Transceiver Control Register 1, the FCS field of the PSDU is replaced by the automatically calculated FCS during frame transmission. There is no need to write the FCS field when using the automatic FCS generation. Manipulating individual bytes of the Frame Buffer is simply possible by accessing the appropriate buffer address. The minimum frame length supported by the radio transceiver for non IEEE 802.15.4 compliant frames is one byte (Frame Length Field + 1 byte of data). 9.6.4 Battery Monitor (BATMON) The main features of the battery monitor are: • Configurable voltage threshold range from 1.7V to 3.675V • Generates an interrupt wh en supply voltage drops below the threshold 9.6.4.1 Overview The battery monitor (BATMON) detects and indicates a low supply voltage of EVDD. This is done by comparing the voltage of EVDD with a configurable, internal threshold voltage. A simplified schematic of the BATMON with the most important input and output signals is shown in the following figure. Figure 9-25. Simplified Schematic of BATMON EVDD BATMON_HR BATMON_OK + 4 DAC - Threshold BATMON_VTH Voltage „1“ clear For input-to-output mapping see BATMON register D Q BATMON_IRQ 85 8393C-MCU Wireless-09/14

9.6.4.2 Configuration The Battery Monitor can be configured using the BATMON register. Register subfield BATMON_VTH sets the threshold voltage. It is configurable with a resolution of 75 mV in the upper voltage range (BATMON_HR = 1) and with a resolution of 50 mV in the lower voltage range (BATMON_HR = 0). 9.6.4.3 Data Interpretation The bit BATMON_OK of register BATMON monitors the current value of the battery voltage: • If BATMON_OK = 0 then the battery voltage is lower than the threshold voltage; • If BATMON_OK = 1 then the battery voltage is higher than the threshold voltage; The value BATMON_OK should be read out to verify the current supply voltage value after setting a new threshold. Note: The battery monitor is inactive during SLEEP states. Refer to status register TRX_STATUS for details. 9.6.4.4 Interrupt Handling A supply voltage drop below the configured threshold value is indicated by the BAT_LOW interrupt. The BAT_LOW status bit as well as the BATLOW_EN bit is located in the BATMON register. If BATLOW_EN =0, no IRQ is issued, but the status flag is set if the battery low event occurs. The interrupt is only issued if BATMON_OK changes from 1 to 0 and the event is stored until the IRQ handler is calle d or the BAT_LOW IRQ is cleared manually by writing ‘1’ to the BAT_LOW status flag. No interrupt is generated when: • The battery voltage is below the default 1.8V threshold at power up (BATMON_OK was never 1) or • A new threshold is set which is still above the current supply voltage (BATMON_OK remains 0). Noise or temporary voltage drops may generate unwanted interrupts when the battery voltage is close to the programmed threshold voltage. To avoid this: • Disable the BAT_LOW interrupt with the BATLOW_EN Bit in the BATMON register and treat the battery as empty or • Set a lower threshold value. 9.6.5 Crystal Oscillator (XOSC) The main features of the crystal oscillator are: • Amplitude controlled 16 MHz generation; • 215 µs typical settling tim e after leaving SLEEP state; • Configurable trimming with a capacitance array; 9.6.5.1 Overview The crystal oscillator generates the reference frequency for the radio transceiver. All other internally generated frequencies of the radio transceiver are derived from this unique frequency. The overall system performance is therefore critically determined by the accuracy of the crystal reference frequency. The external components of the crystal ATmega256/128/64RFR2 86 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 oscillator should be selected carefully and the related board layout should be done with caution as described in section "Application Circuits" on page 540. The register XOSC_CTRL provides access to the control signals of the oscillator. Two operating modes are supported. It is recommended to use the integrated oscillator setup as described in Figure 9-26 below. Nevertheless a reference frequency can be fed to the internal circuitry by using an external clock reference as shown in Figure 9-27 on page 88. 9.6.5.2 Integrated Oscillator Setup The output frequency of the internal oscillator depends on the load capacitance between the crystal pins XTAL1 and XTAL2. The total load capacitance C must be L equal to the specified load capacitance of the crystal itself. It consists of the external capacitors CX and parasitic capacitances connected to the XTAL nodes. The following figure shows all parasitic capacitances, such as PCB stray capacitances and the pin input capacitance summarized to C . PAR Figure 9-26. Simplified XOSC Schematic with External Components C CX CX C PAR PAR V EVDD 16MHz EVDD XTAL1 XTAL2 PCB IC internal C C TRIM TRIM XTAL_TRIM[3:0] XTAL_TRIM[3:0] EVDD Additional internal trimming capacitors C are available. Any value in the range from TRIM 0 pF to 4.5 pF with a 0.3 pF resolution is selectable using XTAL_TRIM of register XOSC_CTRL. To calculate the total load capacitance, the following formula can be used C = 0.5 • (CX + C + C ). L TRIM PAR The trimming capacitors provide the possibility to reduce frequency deviations caused by variations of the production process or by tolerances of external components. Note that the oscillation frequency can only be reduced by increasing the trimming capacitance. The frequency deviation caused by one step of C decreases with TRIM increasing values of the crystal load capacitor. An amplitude control circuit is included to ensure stable operation under different operating conditions and for different crystal types. Enabling the crystal oscillator after leaving SLEEP state causes a slightly higher current during the amplitude build-up phase to guarantee a short start-up time. The current is reduced to the amount 87 8393C-MCU Wireless-09/14

necessary for a robust oscillation during stable operation. This also keeps the drive level of the crystal low. Crystals with a higher load capacitance are generally less sensitive to parasitic pulling effects caused by variations of external components or board and circuit parasitics. On the other hand a larger crystal load capacitance results in a longer start-up time and a higher steady state current consumption. 9.6.5.3 External Reference Frequency Setup When using an external reference frequency, the signal must be connected to pin XTAL1 as indicated in Figure 9-27 below and the bits XTAL_MODE of register XOSC_CTRL need to be set to the external oscillator mode. The oscillation peak-to- peak amplitude shall betw een 100 mV and 500 mV, the optimum range is between 400 mV and 500 mV. Pin XTAL2 should not be wired Figure 9-27. Setup for Using an External Frequency Reference 16 MHz XTAL1 XTAL2 PCB IC internal 9.6.6 Frequency Synthesizer (PLL) The main features of the phase-locked loop are: • Generate RX/TX frequencies for all 2.4 GHz channels of IEEE 802.15.4; • Autonomous calibration loops for stable operation within the operating range; • Two PLL-interrupts for status indication; • Fast PLL settling to support frequency hopping; 9.6.6.1 Overview The PLL generates the RF frequencies for the radio transceiver. During receive operation the frequency synthesizer works as a local oscillator for the receive frequency of the radio transceiver. During transmit operation the voltage-controlled oscillator (VCO) is directly modulated to generate the RF transmit signal. The frequency synthesizer is implemented as a fractional-N PLL. Two calibration loops ensure correct PLL functionality within the specified operating limits. 9.6.6.2 Frequency Agility When the PLL is enabled during state transition from TRX_OFF to PLL_ON the settling time is typically t = 110 µs including the settling time of the analog voltage regulator TR4 (AVREG) and the PLL self calibration (refer to Table 9-9 on page 46Table 9-9). A lock of the PLL is indicated with a TRX24_PLL_LOCK interrupt. Switching between 2.4 GHz ISM band channels in PLL_ON or RX_ON states is typically done within t = 11 µs. This makes the radio transceiver highly suitable for TR20 frequency hopping applications. ATmega256/128/64RFR2 88 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 The PLL frequency is changed to the transmit frequency within t = 16 µs after TR23 starting the transmit procedure and before starting the transmission. After the transmission the PLL settles back to the receive frequency within t = 32 µs. This TR24 frequency step does not generate a TRX24_PLL_LOCK or TRX24_PLL_UNLOCK interrupt within these time sp ans. 9.6.6.3 Calibration Loops Due to temperature, supply voltage and part-to-part variations of the radio transceiver the VCO characteristics diverge. Two automated control loops are implemented to ensure a stable operation: center frequency (CF) tuning and delay cell (DCU) calibration. Both calibration loops are initiated automatically when the PLL is enabled during state transition from TRX_OFF to PLL_ON. The center frequency calibration is additionally initiated when the PLL changes to a center frequency of another channel. It is recommended to initiate the calibration loops manually if the PLL operates for a long time on the same channel e.g. more than 5 min or the operating temperature changes significantly. Both calibration loops can be initiated manually by setting PLL_CF_START = 1 of register PLL_CF and PLL_DCU_START = 1 of register PLL_DCU. The device must be in PLL_ON or RX_ON state to start the calibration. The completion of the center frequency tuning is indicated by a TRX24_PLL_LOCK interrupt. Both calibration loops may be run simultaneously. 9.6.6.4 Interrupt Handling Two different interrupts indicate the PLL status. The TRX24_PLL_LOCK interrupt indicates that the PLL has locked. The TRX24_PLL_UNLOCK interrupt indicates an unexpected unlock condition. A TRX24_PLL_LOCK interrupt is supposed to occur in the following situations: • State change from TRX_OFF to PLL_ON / RX_ON/ RX_AACK_ON/ TX_ARET_ON; • Channel change in states PLL_ON / RX_ON/ RX_AACK_ON/ TX_ARET_ON; Any other occurrences of PLL interrupts indicate erroneous behavior and require checking of the actual device status. The state transition from BUSY_TX to PLL_ON after successful transmission does not generate a TRX24_PLL_LOCK interrupt within the settling period. If a TRX24_PLL_UNLOCK interrupt occurs while the device is receiving/transmitting a frame the associated interru pts (TRX24_RX_END, TRX24_TX_END) will no happen. 9.6.6.5 RF Channel Selection The PLL is designed to support 16 channels in the 2.4 GHz ISM band with channel spacing of 5 MHz according to IEEE 802.15.4. The center frequency of these channels is defined as follows: F = 2405 + 5 (k – 11) in [MHz], for k = 11, 12 ... 26 c where k is the channel number. The channel k is selected by the CHANNEL bits of register PHY_CC_CCA (see "PHY_CC_CCA – Transceiver Clear Channel Assessment (CCA) Control Register" on page 120). 89 8393C-MCU Wireless-09/14

Additionally, the PLL supports all frequencies from 2322 MHz to 2527 MHz with 500 kHz frequency spacing. The frequency is selected by CC_BAND (see "CC_CTRL_1 – Channel Control Register 1" on page 136) and CC_NUMBER (see "CC_CTRL_0 – Channel Control Register 0" on page 136). Table 9-26 shows the settings of the register bits CC_BAND and CC_NUMBER. Table 9-26. Frequency Bands and Numbers CC_BAND(1) CC_NUMBER Description 0x0 Not used Channels according to IEEE 802.15.4; frequency selected by register bits CHANNEL (register 0x08, PHY_CC_CCA). 0x1, … , 0x7 0x00 – 0xFF reserved 0x8 0x00 – 0x1 F reserved 0x8 0x20 – 0xFF 2322 MHz – 2433.5 MHz F [MHz] = 2306 + 0.5 • CC_NUMBER c 0x9 0x00 – 0xBA 2434 MHz – 2527 MHz. F [MHz] = 2434 + 0.5 • CC_NUMBER c 0x9 0xBB – 0xFF reserved 0xA, … , 0xF 0x00 – 0xFF reserved Notes: 1. CC_CTRL_0 and CCTRL_1 form a combined16 bit register. Changed CC_BAND values in register CC_CTRL_1 are effective after writing to register CC_CTRL_0. 9.6.7 Automatic Filter Tuning (FTN) The FTN is incorporated to compensate device tolerances for temperature, supply voltage variations as well as part-to-part variations of the radio transceiver. The filter- tuning result is used to correct the transfer function of the analog baseband filter and the time constant of the PLL loop-filter (refer to "General Circuit Description" on page 33). An FTN calibration cycle is initiated automatically when entering the radio transceiver TRX_OFF state from the SLEEP or RESET state. Although receiver and transmitter are very robust against these variations, it is recommended to initiate the FTN manually if the radio transceiver does not use the SLEEP state. A calibration cycle is to be initiated in states TRX_OFF, PLL_ON or RX_ON if necessary. This applies in particular to the High Data Rate Modes with a much higher sensitivity to variations of the BPF transfer function. The recommended calibration interval is 5 min or less. 9.7 Radio Transceiver Usage This section describes the basic procedures to receive and transmit frames with the radio transceiver. 9.7.1 Frame Receive Procedure A frame reception comprises of two actions: The PHY listens for a frame, receives and demodulates the frame to the Frame Buffer and signalizes its reception to the application software. The application software reads the available frame data from the Frame Buffer after or during the progress of the frame reception. While in state RX_ON or RX_AACK_ON the radio transceiver searches for incoming frames on the selected channel. First a TRX24_RX_START interrupt indicates the detection of an IEEE 802.15.4 compliant frame assuming the appropriate interrupts are ATmega256/128/64RFR2 90 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 enabled. The frame reception is completed when issuing the TRX24_RX_END interrupt. Different Frame Buffer read access scenarios are recommended for: • Non-time critical applicatio ns: read access starts after the TRX24_RX_END interrupt; • Time-critical applications: read access starts after the TRX24_RX_START interrupt; The controller must ensure to read valid Frame Buffer contents. Reading frame data before frame reception is finished can lead to invalid data, if buffer regions are accessed which are not yet updated with the new frame. While receiving a frame the data needs to be primarily stored in the Frame Buffer before reading it. This is ensured by accessing the first Frame Buffer byte at least 32 µs after the TRX24_RX_START interrupt. It is recommended for operations considered to be not time-critical to wait for the TRX24_RX_END interrupt before starting a Frame Buffer read access. The following figure illustrates the frame receive procedure using the TRX24_RX_END interrupt. Figure 9-28. Transactions between radio transceiver and microcontroller during receive IRQ issued (TRX24_RX_START) Transceiver RI eRaQd iTsSs(RuTee_dgR i(XsTt_eRLrX Ea2Nc4cG_eRTsHsX) _reEgNisDt)er Microcontroller Read frame data (Frame Buffer access) Critical protocol timing could require starting the Frame Buffer read access after the TRX24_RX_START interrupt. The first byte of the frame data can be read 32 µs after the TRX24_RX_START interrupt. The application software must ensure to read slower than the frame is received. Otherwise a Frame Buffer under-run occurs and the frame data may be not valid. 9.7.2 Frame Transmit Procedure A frame transmission comp rises of the two actions Frame Buffer write access and transmission of the Frame Buffer content. Both actions can be run in parallel if required by critical protocol timing. Figure 9-29 on page 92 illustrates the frame transmit procedure by consecutively writing and transmitting the frame. The frame transmission is initiated writing SLPTR or writing command TX_START to re gister TRX_STATE after a Frame Buffer write access and while the radio transceiver is in state PLL_ON or TX_ARET_ON. The TRX24_TX_END interrupt indicates the completion of the transaction. 91 8393C-MCU Wireless-09/14

Figure 9-29. Transaction between radio transceiver and microcontroller during transmit Write frame data (Frame Buffer access) r e eiver Write TRX_CMD = TX_START, or write SLPTR ntroll Transc (Register access) Microco IRQ issued (TX_END) Alternatively a frame transmission can be started first, followed by the Frame Buffer write access (PSDU data) as shown in Figure 9-30 below. This is applicable for time critical applications. A transmission is initiated either by writing SLPTR or by writing the TX_START command to the TRX_CMD bits of register TRX_STATE. The radio transceiver then starts transmitting the SHR which is internally generated. This first phase requires 16 µs for PLL settling and 160 µs for SHR transmission. The PHR must be available in the Frame Buffer before this time elapses. Furthermore the Frame Buffer must be filled faster than the frame is transmitted to prevent a buffer under-run. Figure 9-30. Time Optimized Frame Transmit Procedure Write TRX_CMD = TX_START, or write SLPTR (Register access) r e ver oll ei ntr Transc Write frame data (Frame Buffer access) Microco IRQ issued (TX_END) 9.8 Radio Transceiver Extended Feature Set 9.8.1 Random Number Generator The radio transceiver incorporates a 2-bit, noise observing, true random number generator to be used to: • Generate random seeds for CSMA-CA algorithm (see"Extended Operating Mode" on page 47); • Generate random values for AES key generation (see "Security Module (AES)" on page 99); The values are stored in bits RND_VALUE of register PHY_RSSI. The random number is updated every t = 1 µs in Basic Operation Mode receive states with locked PLL. TR29 ATmega256/128/64RFR2 92 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 Note, if the PLL is not locked or unlocks in receive states or either antenna diversity or RPC mode is enabled, the RND_VALUE is zero. 9.8.2 High Data Rate Modes The main features of the High Data Rate Modes are: • High Data Rate Communication up to 2 Mb/s; • Support of Basic and Extended Operating Mode; • Support of other features of the Extended Feature Set; 9.8.2.1 Overview The radio transceiver also supports alternative data rates higher than 250 kb/s for applications beyond IEEE 802.15.4 compliant networks. The selection of a data rate does not affect the remaining functionality. Thus it is possible to run all features and operating modes of the radio transceiver in various combinations. The data rate can be selected by writing bits OQPSK_DATA_RATE of register TRX_CTRL_2. The High Data Rate Modes occupy the same RF channel bandwidth as the IEEE 802.15.4 – 2.4 GHz 250 kb/s standard mode. The sensitivity of the receiver is reduced due to the decreased spreading factor. The following table shows typical values of the sensitivity for different data rates. Table 9-27. High Data Rate Sensitivity High Data Rate Sensitivity Comment 250 kb/s -100 dBm PER ≤ 1%, PSDU length of 20 octets 500 kb/s -96 dBm PER ≤ 1%, PSDU length of 20 octets 1000 kb/s -94 dBm PER ≤ 1%, PSDU length of 20 octets 2000 kb/s -86 dBm PER ≤ 1%, PSDU length of 20 octets By default there is no header based signaling of the data rate within a transmitted frame. Thus nodes using a data rate other than the default IEEE 802.15.4 data rate of 250 kb/s are to be consistently configured in advance. The configurable start of frame delimiter (SFD) could be alternatively used as an indicator of the PHY data rate (see "Configurable Start-Of-Frame Delimiter (SFD)" on page 98). 9.8.2.2 High Data Rate Packet Structure Higher data rate modulation is restricted to only the payload octets in order to allow appropriate frame synchronization. The SHR and the PHR field are transmitted with the IEEE 802.15.4 compliant data rate of 250 kb/s (refer to "Introduction – IEEE 802.15.4- 2006 Frame Format" on page 67). A comparison of the genera l packet structure for different data rates with an example PSDU length of 80 octets is shown in Figure 9-31 on page 94. 93 8393C-MCU Wireless-09/14

Figure 9-31. High Data Rate Frame Structure 0 192 512 832 1472 2752 time [µs] 250 kb/s SFDPHR PSDU: 80 octets FCS 500 kb/s SFDPHR PSDU: 80 octets FCS 1000 kb/s SFDPHR PSDU: 80 octets 2000 kb/s SFDPHR PSDU: 80 octets The effective data rate is smaller than the selected data rate due to the overhead caused by the SHR, the PHR and the FCS. The overhead depends further on the length of the PSDU. A graphical representation of the effective data rate is shown in the following figure: Figure 9-32. Effective Data Rate “B” for High Data Rate Mode 1600 2000 1400 1000 500 1200 250 1000 ] s 2000 kbps p b 800 k [ 1000 kbps B 600 500 kbps 400 250 kbps 200 0 0 20 40 60 80 100 120 PSDU length in octets Therefore High Data Rate t ransmission and reception is useful for large PSDU lengths due to the higher effective data rate or to reduce the power consumption of the system. Furthermore the active on-air time using High Data Rate Modes is significantly reduced. 9.8.2.3 High Data Rate Frame Buffer Access The Frame Buffer access to read or write frames for High Data Rate communication is similar to the procedure described in "Frame Buffer" on page 83. However the last byte in the Frame Buffer after the PSDU data is the ED value rather than the LQI value. 9.8.2.4 High Data Rate Energy Detection According to IEEE 802.15.4 the ED measurement duration is 8 symbol periods. For frames operated at higher data rates the automated ED measurement duration is reduced to 32 µs to take the reduced frame length into account ("Energy Detection (ED)" on page 74). ATmega256/128/64RFR2 94 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 9.8.2.5 High Data Rate Mode Options Receiver Sensitivity Control The different data rates between PPDU header (SHR and PHR) and PHY payload (PSDU) cause a different se nsitivity between header and payload. This can be adjusted by defining sensitivity threshold levels of the receiver. The receiver does not receive frames with an RSSI level below the defined sensitivity threshold level (register bits RX_PDT_LEVEL > 0). Under these operating conditions the receiver current consumption is reduced by 500 µA (refer to chapter "Current Consumption Specifications" on page 566). A description of the settings to control the sensitivity threshold with register RX_SYN can be found in section "RX_SYN – Transceiver Receiver Sensitivity Control Register" on page 131. Reduced Acknowledgment Timing On higher data rates the IEEE 802.15.4 compliant acknowledgment frame response time of 192 µs significantly reduces the effective data rate of the network. To minimize this influence in Extended O perating Mode RX_AACK (see section "RX_AACK_ON – Receive with Automatic ACK" on page 50), the acknowledgment frame response time can be reduced to 32 µs. Figure 9-33 below illustrates an example for a reception and acknowledgement of a frame with a data rate of 2000 kb/s and a PSDU length of 80 symbols. The PSDU length of the acknowledgment frame is 5 octets according to IEEE 802.15.4. Figure 9-33. High Data Rate AACK Timing 0 192 512 544 704 916 time [µs] AACK_ACK_TIME = 0 SFD PHR PSDU: 80 octets 192 µs SFD PHR ACK AACK_ACK_TIME = 1 SFD PHR PSDU: 80 octets SFD PHR ACK 32 µs The acknowledgment time is reduced from 192 µs to 32 µs if bit AACK_ACK_TIME of register XAH_CTRL_1 is set. 9.8.3 Antenna Diversity The main features of the Antenna Diversity implementation are: • Improves signal path robustness between nodes; • Self-contained antenna diversity algorithm of the radio transceiver; • Direct register based antenna selection; 9.8.3.1 Overview The receive signal strength may vary and affect the link quality even for small changes of the antenna location due to multipath propagation effects between network nodes. These fading effects can result in an increased error floor or loss of the connection between devices. Antenna Diversity can be applied to reduce the effects of multipath propagation and fading hence improving the reliability of a RF connection between network nodes. 95 8393C-MCU Wireless-09/14

Antenna Diversity uses two antennas to switch to the most reliable RF signal path. This is done by the radio transceiver during RX_ON and RX_AACK_ON state without interaction of the application software. Both antennas should be carefully separated from each other to ensure highly independent receive signals. Antenna Diversity can be used in Basic and Extended Operating Modes and can also be combined with other features and operating modes like High Data Rate Mode and RX/TX Indication. 9.8.3.2 Antenna Diversity Application Example A block diagram for an application using an antenna switch is shown in the following figure. Figure 9-34. External Antenna Diversity – Block Diagram ANT0 1 DIG2 2 DIG4 ... SW1 B1 7 AVSS h n 8 RFP RF- Switc Balu 9 RFN 3 1 10 AVSS G G ... DI DI 14 15 ANT1 Generally, the Antenna D iversity algorithm is enabled with bit ANT_DIV_EN=1 in register ANT_DIV. For the External Antenna Diversity the control of the antenna switch (SW1) must be enabled by bit ANT_EXT_SW_EN of register ANT_DIV. Under this condition the control pins DIG1 and DIG2 are configured as outputs. DIG1 and DIG2 are used to feed the antenna switch signal and its inverse to the differential inputs of the RF Switch (SW1). See also "Alternate Functions of Port F" on page 232 and "Alternate Functions of Port G" on page 234. The selected antenna is indicated by bit ANT_SEL of register ANT_DIV. The antenna selection continues searching for new frames on both antennas after the frame reception is completed. However the register bit ANT_SEL maintains its previous value (from the last received frame) until a new SHR has been found and the selection algorithm locked into one antenna again. Then the register bit ANT_SEL is updated. The antenna defined by the ANT_CTRL bits of register ANT_DIV is selected for transmission. If for example the same antenna as selected for reception is to be used for transmission, the antenna must be set using the ANT_CTRL bits based on the value read from the ANT_SEL bit. It is recommended to read bit ANT_SEL after the TRX24_RX_START interrupt. The autonomous search and selection allows the use of Antenna Diversity during reception even if the application software currently does not control the radio transceiver for instance in Extended Operating Mode. ATmega256/128/64RFR2 96 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 An application software defined selection of a certain antenna can be done by disabling the automatic Antenna Diversity algorithm (ANT_DIV_EN = 0) and selecting one antenna using register bit ANT_CTRL. If the radio transceiver is not in a receive or transmit state, it is recommended to disable register bit ANT_EXT_SW_EN and to set the port pins DIG1 and DIG2 to output low via the I/O port control register (DDG1 = 1, PORTG1 = 0, DDF2 = 1, PORTF2 = 0). In this way the power consumption of the external RF switch is reduced and leakage currents are avoided especially during sleep modes. 9.8.3.3 Antenna Diversity with Extended Operation Modes A combination of Extended Operation Mode and antenna diversity is allowed. While the radio transceiver is in RX_AACK_ON state, it switches to an antenna with a reliable signal. The receive antenna selection is also used for transmission of an automatic acknowledge frame. While the radio transceiver is in TX_ARET state, the selected antenna is automatically changed for every frame transmission retry. 9.8.3.4 Antenna Diversity Sensitivity Control The detection threshold of the receiver has to be adjusted due to a different receive algorithm used by the Antenna Diversity algorithm. It is recommended to set bits PDT_THRES of register RX_CTRL to 3. 9.8.4 RX/TX Indicator The main features are: • RX/TX Indicator to control an external RF Front-End; • Application software independent RF Front-End Control; • Provide TX Timing Information; 9.8.4.1 Overview While IEEE 802.15.4 is a low-cost, low-power standard, solutions supporting higher transmit output power are occasionally desirable. A differential control pin pair can indicate that the radio transceiver is currently in transmit mode to simplify the control of an optional external RF front-end. The control of an external RF front-end is done via the digital control pins DIG3/DIG4. The function of this pin pair is enabled with bit PA_EXT_EN of register TRX_CTRL_1. Pin DIG3 is set to low level and DIG4 to high level while the transmitter is turned off. The two pins change the polarity when the radio transceiver starts transmitting. This differential pin pair can be used to control PA, LNA and RF switches. See also "Alternate Functions of Port F" on page 232 and "Alternate Functions of Port G" on page 234. If the radio transceiver is not in a receive or transmit state, it is recommended to disable register bit PA_EXT_EN and to set the port pins DIG3 and DIG4 to output low via the I/O port control register (DDG0 = 1, PORTG0 = 0, DDF3 = 1, PORTF3 = 0). In this way the power consumption of external RF switches and other building blocks is reduced and leakage currents are avoided especially during sleep modes. 97 8393C-MCU Wireless-09/14

9.8.4.2 External RF-Front End Control The setup time of the external power amplifier (PA) relative to the internal building blocks should be adjusted when using an external RF front-end including a power amplifier to optimize the ove rall power spectral density (PSD) mask. Figure 9-35. TX Power Ramping Control for RF Front-Ends 0 2 4 6 8 10 12 14 16 18 Length [µs] TRX_STATE PLL_ON BUSY_TX SLPTR PA buffer PA_BUF_LT PA PA_LT Modulation 1 1 0 1 1 0 0 1 1 DIG3 DIG4 The start-up sequence of the individual building blocks of the internal transmitter is shown in the previous figure. The transmission is actually initiated by writing ‘1’ to SLPTR. The radio transceiver state changes from PLL_ON to BUSY_TX and the PLL settles to the transmit frequency within 16 µs (parameter t at page 46). The TR23 modulation starts 16 µs (parameter t at page 46) after the SLPTR=1. The PA buffer TR10 and the internal PA are enabled during this time. The control of an external PA is done via the differential pin pair DIG3 and DIG4. DIG3 = H / DIG4 = L indicates that the transmission starts and can be used to enable an external PA. The timing of pins DIG3/DIG4 can be adjusted relative to the start of the frame and the activation of the internal PA buffer. This is controlled using the register bits PA_BUF_LT and PA_LT. For details refer to Figure 9-23 on page 83 and chapter "Transmitter (TX)" on page 82. 9.8.5 RX Frame Time Stamping To determine the exact timing of an incoming frame e.g. for beaconing networks, the Symbol Counter should be used. SFD Time Stamping is enabled by setting bit SCTSE of the Symbol Counter Control Register SCCR0. The actual 32 Bit Symbol Counter value is captured in the SFD Time Stamp register SCTSR at the time, the SFD has been received. For details see section "SFD and Beacon Timestamp Generation" on page 160. 9.8.6 Configurable Start-Of-Frame Delimiter (SFD) The SFD is a field indicating the end of the SHR and the start of the packet data. The length of the SFD is 1 octet (2 symbols). This octet is used for byte synchronization only and is not included in the Frame Buffer. The value of the SFD could be changed if it is needed to operate non IEEE 802.15.4 compliant networks. An IEEE 802.15.4 compliant network node does not synchronize to frames with a different SFD value. ATmega256/128/64RFR2 98 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 The register SFD_VALUE contains the one octet start-of-frame delimiter (SFD) to synchronize to a received frame. It is not recommended to set the low-order 4 bits to 0 due to the way the SHR is formed. 9.8.7 Dynamic Frame Buffer Protection The ATmega256/128/64RFR2 continues the reception of incoming frames as long as it is in any receive state. When a frame was successfully received and stored into the Frame Buffer, the following frame will overwrite the Frame Buffer content again. To relax the timing requirements for a Frame Buffer read access the Dynamic Frame Buffer Protection prevents that a new valid frame passes to the Frame Buffer until the buffer protection bit is cleared (RX_SAFE_MODE = 0). A received frame is automat ically protected against overwriting: • in Basic Operating Mode, if its FCS is valid • in Extended Operating Mode, if an TRX24_RX_END interrupt is generated The Dynamic Frame Buffer Protection is enabled, if register bit RX_SAFE_MODE (register TRX_CTRL_2, see "TRX_CTRL_2 – Transceiver Control Register 2" on page 124) is set and the radio transceiver state is RX_ON or RX_AACK_ON. Notes: 3. Dynamic Frame Buffer Protection only prevents write accesses from the air interface not from the application software. The application software may still modify the Frame Buffer content. 4. Dynamic Frame Buffer Protection influences SRT (see "SRT – Smart Receiving Technology" on page 104) when a frame has been received successfully. 9.8.8 Security Module (AES) The security module (AES) is characterized by: • Hardware accelerated encryption and decryption; • Compatible with AES-128 standard (128 bit key and data block size); • ECB (encryption/decryption) mode and CBC (encryption) mode support; • Stand-alone operation, independent of other blocks; • Uses 16MHz crystal clock of the transceiver; 9.8.8.1 Overview The security module is based on an AES-128 core according to the FIPS197 standard [6]. and provides two mode s, the Electronic Code Book (ECB) and the Cipher Block Chaining (CBC). The security module works independent of other building blocks of the radio transceiver. Encryption and decryption can be performed in parallel to a frame transmission or reception. During radio transceiver SLEEP the registers of the security engine (AES) are cleared (see section "SLEEP – Slee p State" on page 40). The ECB and CBC modules including the AES core are clocked with the 16 MHz Radio Transceiver Crystal Oscillator. Controlling the security block is possible over 5 Registers within AVR I/O space: Table 9-28. Security Module Address Space Overview Register Name Description AES_STATUS AES status register 99 8393C-MCU Wireless-09/14

Register Name Description AES_CTRL AES control register AES_KEY Access to 16 Byte key buffer AES_STATE Access to 16 Byte data buffer 9.8.8.2 Security Module Preparation The use of the security module requires a configuration of the security engine before starting a security operation. The following steps are required: Table 9-29. AES Engine Configuration Steps Step Description Description 1 Key Setup Write encryption or decryption key to KEY buffer (16 consecutive byte writes to AES_KEY) 2 AES configuration Select AES mode: ECB or CBC Select encryption or decryption Enable the AES Encryption Ready Interrupt AES_READY 3 Write Data Write plain text or cipher text to DATA buffer (16 consecutive byte writes to AES_STATE) 4 Start operation Start AES operation 5 Wait for AES finished: Wait until AES encryption/decryption is finished 1. AES_READY IRQ or successfully 2. polling AES_DONE bit (register AES_STATUS) or 3. wait for 24 µs 6 Read Data Read cipher text or plain text from DATA buffer (16 consecutive byte reads from AES_STATE) Before starting any security operation a 16 Byte key must be written to the security engine (refer to section "Security Key Setup" on page 101). This can be done by 16 consecutive write accesses to the I/O register AES_KEY. An internal address counter is incremented automatically with every read/ write operation. An AES encryption/ decryption run resets the internal byte counter. If the key and data buffer has not been read or written completely (all 16 Bytes), the following encryption/ decryption operation will finish with an error. The following step selects either Electronic Code Book (ECB) or Cipher Block Chaining (CBC) as the AES_MODE. These modes are explained in more detail in section "Security Operation Modes" on page 101. Encryption or decryption must be further selected with bit AES_DIR of register AES_CTRL. If the AES Error or AES Ready IRQ is used, the interrupt must be enabled with bit AES_IM. Next the 128-bit plain text or cipher text data has to be provided to the AES hardware engine. The 16 data bytes must be consecutively written to the AES_STATE register. The AES_STATE register can be accessed in the same way as the key register (refer to "Security Key Setup" on page 101). The encryption or decryption is initiated with bit AES_REQUEST = 1. ATmega256/128/64RFR2 100 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 The operation takes 24 µs and the completed encryption/ decryption is indicated by the AES_READY IRQ and the AES_DONE bit. The internal byte counter of the key and data buffer is cleared and the resulting data can be read out. For additional information about the key and data buffer please refer to section "AES_KEY – AES Encryption and Decryption Key Buffer Register" on page 112 and "AES_STATE – AES Plain and Cipher Text Buffer Register" on page 112. Notes: 1. Access to the security block is not possible while the radio transceiver is in state SLEEP. 2. All configurations of the security module, the SRAM content and keys are reset during SLEEP or RESET states. 9.8.8.3 Security Key Setup The key is stored in a 16 Byte sequential buffer. To read or write the contents of the buffer, 16 consecutive read or write operations to the AES_KEY register are required. A 16-folded read access to registers AES_KEY returns the last round key of the preceding security operatio n. This is the key required for the corresponding ECB decryption operation after an ECB encryption operation. However the initial AES key written to the security module in advance of an AES run (see step 1 in Table 9-29 on page 100) is not modified during an AES operation. This initial key is used for the next AES run although it cannot be read from AES_KEY. Before accessing the Key Buffer it must be ensured, that the internal address counter is initialized correctly. This is the cases after Radio Transceiver Reset (see TRXPR – Transceiver Pin Register on page 199) or a completed AES Encryption/ Decryption operation. After an interr upted buffer read or write access, Address pointer reinitialization is recommended by a simple read access to the AES_CTRL register. Note: 1. ECB decryption is not required for IEEE 802.15.4 or ZigBee security processing. The radio transceiver provides this functionality as an additional feature. 9.8.8.4 Security Operation Modes 9.8.8.4.1 Electronic Code Book (ECB) ECB is the basic operating mode of the security module and is configured by the AES_CTRL register. The bit AES_MODE = 0 defines the ECB mode and bit AES_DIR selects the direction to either encryption or decryption. The data to be processed has to be written to registers AES_STATE. A security operation can be started by writing the start command AES_REQUEST = 1 (AES_CTRL register). The ECB encryption operation is illustrated in Figure 9-36 on page 102. Figure 9-37 on page 102 shows the ECB decryption mode which is supported in a similar way. 101 8393C-MCU Wireless-09/14

Figure 9-36. ECB Mode - Encryption Plaintext Plaintext Encryption Block Cipher Encryption Block Cipher Key Encryption Key Encryption Ciphertext Ciphertext Figure 9-37. ECB Mode - Decryption Ciphertext Ciphertext Decryption Block Cipher Decryption Block Cipher Key Decryption Key Decryption Plaintext Plaintext Due to the nature of AES algorithm the initial key to be used when decrypting is not the same as the one used for encryption. Instead it is the last round key. This last round key is the content of the key address space stored after running one full encryption cycle and must be saved for decryption. If the decryption key has not been saved, it has to be recomputed by first running a dummy encryption (of an arbitrary plain text) using the original encryption key. Then the resulting round key must be fetched from the key memory and written back into the key memory as the decryption key. ECB decryption is not used by either IEEE 802.15.4 or ZigBee frame security. Both of these standards do not directly encrypt the payload. Instead they protect the payload by applying a XOR operation between the original payload and the resulting (AES-) cipher text with a nonce (number used once). As the nonce is the same for encryption and decryption only ECB encryption is required. Decryption is performed by a XOR operation between the received cipher text and its own encryption result concluding in the original plain text payload upon success. 9.8.8.4.2 Cipher Block Chaining (CBC) In CBC mode the result of a previous AES operation is XOR-combined with the new incoming vector forming the new plain text to encrypt as shown in the next figure. This mode is used for the computation of a cryptographic checksum (message integrity code, MIC). ATmega256/128/64RFR2 102 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 Figure 9-38. CBC Mode - Encryption Plaintext Initialization Vector (IV) Plaintext Encryption Block Cipher Encryption Block Cipher Key Encryption Key Encryption Ciphertext Ciphertext ECB CBC mode mode After preparing the AES key and defining the AES operation direction register bit AES_DIR, the data has to be provided to the AES engine and the CBC operation can be started. The first CBC run has to be configured as ECB to process the initial data (plain text XOR with an initialization ve ctor provided by the application software). All succeeding AES runs are to be configured as CBC by setting bit AES_MODE = 1 (AES_CTRL register). Bit AES_DIR (AES_CTRL register) must be set to AES_DIR = 0 to enable AES encryption. The data to be processed has to be transferred to the AES_STATE register. Setting bit AES_REQUEST = 1 (AES_CTRL register) as described in section "Security Operation Modes" on page 101 starts the first encryption. This causes the next 128 bits of plain text data to be XORed with the previous cipher text data, see Figure 9-38 above. According to IEEE 802.15. 4 the input for the very first CBC operation has to be prepared by a XOR operation of the plain text with the initialization vector (IV). The value of the initialization vector is 0. However any other initialization vector can be applied for non-compliant usage. This operation has to be prepared by the application software. Note that the MIC algorithm of the IEEE 802.15.4-2006 standard requires CBC mode encryption only because it implements a one-way hash function. The status of the security processing is indicated by register AES_STATUS. After a AES processing time of 24 µs the register bit AES_DONE changes to 1 (register AES_STATUS) indicating that the security operation has finished (see "Digital Interface Timing Characteristics" on page 563). The end of the AES processing can also be indicated by the AES_READY Interrupt. The bit AES_ER of register AES_STATUS is set if the operation has finished with an error. Otherwise this bit is zero but AES_DONE is ‘1’. 9.8.8.5 AES Interrupt Handling The AES Interrupt handling is slightly different from all other IRQ’s. If the AES_IM Bit (AES_CTRL Register) and the global interrupt enable flag is set, the AES core can generate an AES Ready Interrupt (AES_READY). If the IRQ is issued, the AES_STATUS register must be read to check the finish status of the last operation. If AES_DONE is set, the last AES operation finished successfully. If AES_ER is set, an error occurred during the last operation. The AES_ER flag is cleared automatically during the read access to the AES_STATUS register. The AES_DONE flag is cleared during the next read or write access to the AES_STATE (AES data) register. The two status flags must be cleared before a new Interrupt can be issued. 103 8393C-MCU Wireless-09/14

If AES_IM is not set, the processing status can be polled by software (AES_STATUS register), but no Interrupt occurs. 9.8.9 Receiver Override The RX Override feature improves the network throughput under busy conditions. When an incoming received frame is overlayed by a later starting stronger signal, the overlayed signal would surely destroy the received frame. With an enabled RX Override feature, the receiver breakes the reception and restarts synchronisation to the stronger signal. The IRQs are set like after reception of a wrong FCS. The feature RX Override is enabled if the bit RX_OVERRIDE in register RX_SYN is set. 9.8.10 Reduced Power Consumption Mode (RPC) 9.8.10.1 Overview The Reduced Power Consumption mode is characterized by: • Significant power reductio n for several transceiver operating modes • Self-contained, self-calibrating and adaptive power reduction schemes The RPC mode of the ATmega256/128/64RFR2 offers a variety of independent techniques and methods to significantly reduce the power consumption of the radio transceiver. RPC is applicable to selected operating modes and is transparent to most other extended features. In this context an RPC state change (disable or enable) needs to be understood as a major state change within all transceiver sections (TX, RX, PLL, state machines) and has to respect the associated settling time as specified in "State Transition Timing Summary" on page 46. In case of RX_ON / RX_AACK_ON / PLL_ON the PLL needs time to settle (tTR20=11µs). To achieve the lowest possible power consumption set register TRX_RPC to 0xFF. For disabling the Reduced Pow er Consumption modes set register TRX_RPC to 0xC1 or 0x01. See "TRX_RPC – Transceiver Reduced Power Consumption Control" on page 136 for detailed description of the TRX_RPC register bits. 9.8.10.2 RPC Methods and Elements 9.8.10.2.1 PES – PLL Energy Saving The PES mode is activated with bit PLL_RPC_EN of register TRX_RPC set to one. Applicable to states: PLL_ON and TX_ARET_ON A state change towards PLL_ON or TX_ARET_ON causes an initial PLL calibration run, immediately followed by en tering the PES mode. A state change towards RX or TX states, a channel switch or PLL calibration causes a PLL wake-up. After finishing such an operation, the PLL automatically enters the PES mode. 9.8.10.2.2 SRT – Smart Receiving Technology The SRT mode is activated with bit RX_RPC_EN of register TRX_RPC set to one. ATmega256/128/64RFR2 104 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 Applicable to states: RX_ON, RX_AACK_ON and TX_ARET_ON SRT reduces the average power consumption during RX listening periods. In typical environment situations SRT reduces the average current consumption of the transceiver in the RX_ON state by up to 50%. The configuration of SRT is done with the RX_RPC_CTRL bits of register TRX_RPC. Notes: 1. It’s recommended to disable SRT during RSSI measurements or RND generation. 2. During CCA or/and ED scan the SRT is disabled automatically. 3. If autonomous antenna diversity is enabled, SRT cannot achieve the maximum effect. 4. The effective reduction of the current consumption may vary depending on operating conditions (wireless traffic, temperature, channel noise, frequency settings). 5. SRT shall be disabled when using the Random Number Generator. The total access time to the random value in PHY_RSSI – Receiver Signal Strength Indicator Register after SRT-disable is 2·tTR29+tTR20. 6. When a frame is received successfully while SRT and Dynamic Frame Buffer Protection are enabled the SRT is blocked until RX_SAFE_MODE bit in the register TRX_CTRL_2 is set to 0 to release the protection. 9.8.10.2.3 ERD – Extended Receiver Desensitizing ATmega256/128/64RFR2 ERD is activated with bit PDT_RPC_EN of register TRX_RPC set to one. Applicable to states: RX_ON, RX_AACK_ON and TX_ARET_ON In combination with RX_PDT_LEVEL settings, the average RX current is further significantly reduced, for details refer to "Current Consumption Specifications" on page 566. Setting RX_PDT_LEVEL = 0x08 requires special attention. In contrast to definitions in section "RX_SYN – Transceiver Receiver Sensitivity Control Register" on page 131, the sensitivity is reduced to -80 dBm only. However the average RX_ON current is much lower than for comparable register settings. Notes: 1. With RX_PDT_LEVEL ≥ 0x08, RSSI/ED can not resolve receiver input levels from -80 dBm to -67 dBm. 2. During CCA or/and ED scan the ERD is disabled automatically. 9.8.10.2.4 PAM – PAN Address Match Recognition ATmega256/128/64RFR2 PAM is activated with bit IPAN_RPC_EN of register TRX_RPC set to one. PAM is automatically deactivated if RX override is enabled (see "Receiver Override" on page 104 and "RX_SYN – Transceiver Receiver Sensitivity Control Register" on page 131 for details). Applicable to states: RX_AACK_ON The indication of an address match fail of the IEEE 802.15.4 frame filtering (see "Frame Filtering" on page 58) stops the receive procedure in two ways: 1. If the PAN address does not match, a new listen period starts immediately, 105 8393C-MCU Wireless-09/14

2. If the PAN address matches (but not the short destination address), the radio transceiver enters power saving mode for the remaining frame. If acknowledgement is also requested, power saving continues through the acknowledgement period. . Notes: 1. PAM is applicab le to short acknowledgement times and reserved frame types as set by the bits AACK_ACK_TIME and AACK_FLTR_RES_FT of register XAH_CTRL_1, respectively (see "XAH_CTRL_1 – Transceiver Acknowledgment Frame Control Register 1" on page 133). 2. PAM is disabled automatically if promiscuous mode is enabled with bit AACK_PROM_MODE in register XAH_CTRL_1) set to one.. 9.8.10.2.5 Miscellaneous Power Reduction Functions Applicable to states: RX_ON and RX_AACK_ON In addition to Dynamic Frame Buffer Protection, refer to section "Dynamic Frame Buffer Protection" on page 99. During Dynamic Frame Buffer Protection, the radio transceiver automatically enters the power save mode. Applicable to states: TX_ARET_ON In addition to CSMA-CA retry, refer to section "TX_ARET_ON – Transmit with Automatic Retry and CSMA-CA Retry" on page 63. After starting the TX_ARET transaction, a random back-off period is performed. Within this back-off period the radio transceiver automatically enters power saving mode. Applicable to states: TX_ARET_ON and RX_AACK_ON In addition to the TX/RX turnaround time, refer to section "Extended Operating Mode" on page 47. The radio transceiver automatically enters power saving mode in: • TX_ARET: during the time waiting for an ACK frame, or • RX_AACK: during the time waiting for ACK transmission. Note: 1. To handle nodes configured with a RX/TX turnaround time less than 12 symbols, set RX_RPC_CTRL = 0 within TX_ARET state or set bit AACK_ACK_TIME of register XAH_CTRL_1 to one. 9.8.11 Phase Difference Measurement 9.8.11.1 Overview The Phase Difference Measurement Unit (PMU) is characterized by: • Relative phase measurement of received signal. 9.8.11.2 Description The ATmega256/128/64RF R2 performs a phase measurement of a received signal relative to an internal reference. The derived value represents the phase delay of the received signal referenced to an internal reference signal in the receiver low-IF domain (see "General Circuit Description" on page 33). Once a phase measurement is started successive readings, updated every 1µs, are stored in the transceiver frame buffer (see chapter "Frame Buffer Access " on page 35) starting with the address of the register TRXFBST – Start of frame buffer. ATmega256/128/64RFR2 106 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 9.9 Continuous Transmission Test Mode 9.9.1 Overview The 2.4GHz transceiver off ers a Continuous Transmission Test Mode to support final application / production tests as well as certification tests. In this test mode the radio transceiver transmits continuously a previously transferred frame (PRBS mode) or a continuous wave signal (CW mode). In CW mode two different signal frequencies per channel can be transmitted: • f = f + 0.5 MHz 1 CH • f = f - 0.5 MHz 2 CH Here f is the channel cente r frequency programmed by register PHY_CC_CCA. CH Note that in CW mode it is not possible to transmit a RF signal directly on the channel center frequency. PSDU data in the Frame Buffer must contain at least a valid PHR (see section "Introduction – IEEE 802.15.4-2006 Frame Format" on page 67). It is recommended to use a frame of maximum length (127 bytes) and arbitrary PSDU data for the PRBS mode. The SH R and the PHR are not transmitted. The transmission starts with the PSDU data and is repeated continuously. 9.9.2 Configuration All register configurations shall be setup as follows before enabling Continuous Transmission Test Mode: • TX channel setting (optional); • TX output power setting ( o ptional); • Mode selection (PRBS / CW); An access to the registers TST_CTRL_DIGI and PART_NUM enables the Continuous Transmission Test Mode. The transmission is started by enabling the PLL (TRX_CMD = PLL_ON) and writing the TX_START command to register TRX_STATE. Even for CW signal transmission it is required to write valid PSDU data (see chapter "Frame Buffer Access " on page 35) to the Frame Buffer. The first byte defines the frame length information. The frame length has to match to the length of the pattern stored in the frame buffer. For PRBS mode it is recommended to use a frame of maximum length. The detailed programming sequence is shown in Table 9-30 below. The column R/W informs about writing (W) or reading (R) a register or the Frame Buffer. Table 9-30. Continuous Transmission Programming Sequence Step Action Register R/ Value Description W 1 RESET Reset the transceiver 2 Register Access IRQ_MASK W 0x01 Set IRQ mask register, enable PLL_LOCK interrupt and set global AVR IRQ enable 3 Register Access TRX_CTRL_1 W 0x00 Disable TX_AUTO_CRC_ON 4 Register Access TRX_STATE W 0x03 Set radio transceiver state TRX_OFF 5 Register Access PHY_CC_CCA W 0x33 Set IEEE 802.15.4 CHANNEL, e.g. 19 107 8393C-MCU Wireless-09/14

Step Action Register R/ Value Description W 6 Register Access PHY_TX_PWR W 0x00 Set TX output power, e.g. to P max 7 Register Access TRX_STATUS R 0x08 Verify TRX_OFF state 8 Register Access TST_CTRL_DIGI W 0x0F Enable Continuous Transmission Test Mode – step # 1 9(1) Register Access TRX_CTRL_2 W 0x03 Enable High Data Rate Mode, 2 Mb/s 10(1) Register Access RX_CTRL W 0xA7 Configure High Data Rate Mode 11(2) Frame Buffer W Write PSDU data (even for CW Write Access mode), refer to Table 9-31 below 12 Register Access PART_NUM W 0x54 Enable Continuous Transmission Test Mode – step # 2 13 Register Access PART_NUM W 0x46 Enable Continuous Transmission Test Mode – step # 3 14 Register Access TRX_STATE W 0x09 Enable PLL_ON state 15 Interrupt event R 0x01 Wait for PLL_LOCK interrupt 16 Register Access TRX_STATE W 0x02 Initiate Transmission, enter BUSY_TX state 17 Measurement Perform measurement 18 Register Access PART_NUM W 0x00 Disable Continuous Transmission Test Mode 19 RESET Reset the transceiver Notes: 1. Only required for CW mode, do not configure for PRBS mode. 2. Frame Buffer content varies for different modulation schemes. The content of the Frame Buffer has to be defined for Continuous Transmission PRBS mode or CW mode. To m easure the power spectral density (PSD) mask of the transmitter it is recommended to use a random sequence of maximum length for the PSDU data. To measure CW signals it is necessary to write either 0x00 or 0xFF to each byte of the Frame Buffer according to the given frame length. For details refer to Table 9-31 below. Table 9-31. Frame Buffer Content (after frame length information) for various Continuous Transmission Modulation Schemes Step Action Fra me Content Comment 11 Frame Buffer Random Sequence modulated RF signal Write Access 0x00 (each byte) f – 0.5 MHz, CW signal CH 0xFF (each byte) f + 0.5 MHz, CW signal CH 9.10 Abbreviations AACK - Automatic acknowledgement ACK - Acknowledgement ADC - Analog-to-digital converter AD - Antenna diversity ATmega256/128/64RFR2 108 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 AGC - Automated gain control AES - Advanced encryption standard ARET - Automatic retransmission AVREG - Voltage regulator for analog building blocks AWGN - Additive White Gaussian Noise BATMON - Battery monitor BBP - Base band processor BPF - Band pass filter CBC - Ciph er block chaining CRC - Cyclic redundancy check CCA - Clear channel assessment CSMA-CA - Carrier sense multiple access/Collision avoidance CW - Continuous wave DVREG - Voltage regulator for digital building blocks ECB - Electronic code book ED - Energy detection ESD - Electro static discharge EVM - Error vector magnitude FCF - Frame control field FCS - Frame check sequence FIFO - First in first out FTN - Filte r tuning network GPIO - General purpose input output ISM - Industrial, scientific, and medical LDO - Low-drop output LNA - Low-noise amplifier LO - Local oscillator LQI - Link quality indicator LSB - Least significant bit MAC - Medium access control MFR - MAC footer MHR - MAC header MSB - Most significant bit MSDU - MAC service data unit MPDU - MAC protocol data unit MSK - Minimum shift keying 109 8393C-MCU Wireless-09/14

O-QPSK - Offset - quadrature phase shift keying PA - Power amplifier PAN - Personal area network PCB - Printed circuit board PER - Packet error rate PHR - PHY header PHY - Physical layer PLL - Phase locked loop POR - Pow er-on reset PPF - Poly-phase filter PRBS - Pseudo random bit sequence PSDU - PHY service data unit PSD - Power spectral mask QFN - Quad flat no-lead package RF - Radio frequency RSSI - Received signal strength indicator RX - Receiver SFD - Sta rt-of-frame delimiter SHR - Synchronization header SPI - Serial peripheral interface SRAM - Static random access memory SSBF - Single side band filter TX - Transmitter VCO - Voltage controlled oscillator VREG - Voltage regulator XOSC - Crystal oscillator 9.11 Reference Documents [1] IEEE Std 802.15.4™-2006: Wireless Medium Access Control (MAC) and Physical Layer (PHY) Specifications for Low-Rate Wireless Personal Area Networks (LR-WPANs) [2] IEEE Std 802.15.4™-2003: Wireless Medium Access Control (MAC) and Physical Layer (PHY) Specifications for Low-Rate Wireless Personal Area Networks (LR-WPANs) [3] IEEE Std 802.15.4™-2011: Low-Rate Wireless Personal Area Networks (WPANs) ATmega256/128/64RFR2 110 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 [4] ANSI / ESD-STM5.1-2001: ESD Association Standard Test Method for electrostatic discharge sensitivity testing – Human Body Model (HBM). [5] ESD-STM5.3.1-1999: ESD Association Standard Test Method for electrostatic discharge sensitivity testing – Charged Device Model (CDM). [6] NIST FIPS PUB 197: Advanced Encryption Standard (AES), Federal Information Processing Standards Publication 197, US Department of Commerce/NIST, November 26, 2001 9.12 Register Description 9.12.1 AES_CTRL – AES Control Register Bit 7 6 5 4 3 2 1 0 NA ($13C) AES_REQUEST Res AES_MODE Res AES_DIR AES_IM Res1 Res0 AES_CTRL Read/Write RW R RW R RW RW R R Initial Value 0 0 0 0 0 0 0 0 This register controls the operation of the security module. Do not access this register during AES operation to read the AES core status. A read or write access to the register stops the ongoing processing. To read the AES status use bit AES_DONE of register AES_STATUS. Note that the AES_CTRL register is cleared when entering the radio transceiver SLEEP state. • Bit 7 – AES_REQUEST - Request AES Operation. A write access with AES_REQUEST = 1 initiates the AES operation. • Bit 6 – Res - Reserved Bit This bit is reserved for future use. The result of a read access is undefined. The register bit must always be written w ith the reset value. • Bit 5 – AES_MODE - Set AES Operation Mode This register bit sets the AES operation mode (ECB/CBC Mode). Table 9-32 AES_MODE Register Bits Register Bits Value Description AES_MODE 0 AES Mode is ECB (Electronic Code Book). 1 AES Mode is CBC (Cipher Block Chaining). • Bit 4 – Res - Reserved Bit This bit is reserved for future use. The result of a read access is undefined. The register bit must always be written with the reset value. • Bit 3 – AES_DIR - Set AES Operation Direction This register bit sets the AES operation direction to either encryption or decryption. Table 9-33 AES_DIR Register Bits Register Bits Value Description AES_DIR 0 AES operation is encryption. 1 AES operation is decryption. • Bit 2 – AES_IM - AES Interrupt Enable This register bit is used to enable the AES interrupt. 111 8393C-MCU Wireless-09/14

• Bit 1:0 – Res1:0 - Reserved Bit These bits are reserved for future use. The result of a read access is undefined. The register bits must always be written with the reset value. 9.12.2 AES_STATUS – AES Status Register Bit 7 6 5 4 3 2 1 0 NA ($13D) AES_ER Res5 Res4 Res3 Res2 Res1 Res0 AES_DONE AES_STATUS Read/Write R R R R R R R R Initial Value 0 0 0 0 0 0 0 0 This read-only register signals the status of the security module and operation. Note that the AES_STATUS register is cleared when entering the radio transceiver SLEEP state. • Bit 7 – AES_ER - AES Operation Finished with Error This register bit indicates an error during AES module run. An error occurs if accessing AES_CTRL while an AES operation is running or if AES_KEY or AES_STATE Memory is not loaded completely or less than 16 Byte read from AES_STATE. • Bit 6:1 – Res5:0 - Reserved These bits are reserved for future use. • Bit 0 – AES_DONE - AES Operation Finished with Success This register bit indicates a successfully finished operation of the AES module. 9.12.3 AES_STATE – AES Plain and Cipher Text Buffer Register Bit 7 6 5 4 3 2 1 0 NA ($13E) AES_STATE7:0 AES_STATE Read/Write RW RW RW RW RW RW RW RW Initial Value 0 0 0 0 0 0 0 0 The AES_STATE register accesses a 16 byte internal data buffer. The buffer is accessed by reading or writing 16 times to the same address location (AES_STATE). If the buffer is not completely read or written an error occurs when an AES operation is started. Note that the AES_STATE register is cleared when entering the radio transceiver SLEEP state. • Bit 7:0 – AES_STATE7:0 - AES Plain and Cipher Text Buffer These bits represent the data buffer for the AES operation. 9.12.4 AES_KEY – AES Encryption and Decryption Key Buffer Register Bit 7 6 5 4 3 2 1 0 NA ($13F) AES_KEY7:0 AES_KEY Read/Write RW RW RW RW RW RW RW RW Initial Value 0 0 0 0 0 0 0 0 ATmega256/128/64RFR2 112 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 The AES key register accesses a 128 Bit internal buffer that holds the Encryption or Decryption Key. The AES_KEY buffer is a 16 Byte buffer. The buffer is accessed by reading or writing 16 fold to the same address location (AES_KEY). A read access to registers AES_KEY returns the last round key of the preceding security operation. This is the key that is required fo r the corresponding ECB decryption operation after an ECB encryption operation. However, the initial AES key written to the security module in advance of an AES run is not modified during an AES operation. This initial key is used for the next AES run even if it cannot be read from AES_KEY register. Note that the AES_KEY register is cleared when entering the radio transceiver SLEEP state. • Bit 7:0 – AES_KEY7:0 - AES Encryption/Decryption Key Buffer These bits represent the data buffer for the AES Encryption/Decryption key. 9.12.5 TRX_STATUS – Transceiver Status Register Bit 7 6 5 4 NA ($141) CCA_DONE CCA_STATUS TST_STATUS TRX_STATUS4 TRX_STATUS Read/Write R R R R Initial Value 0 0 0 0 Bit 3 2 1 0 NA ($141) TRX_STATUS3 TRX_STATUS2 TRX_STATUS1 TRX_STATUS0 TRX_STATUS Read/Write R R R R Initial Value 0 0 0 0 This read-only register signals the present state of the radio transceiver as well as the status of the CCA operation. A state change is initiated by writing a state transition command to the TRX_CMD bits of register TRX_STATE. The register is not accessible in SLEEP state. • Bit 7 – CCA_DONE - CC A Algorithm Status This bit indicates if a CCA request is completed. This is also indicated by a TRX24_CCA_ED_DONE interrupt. Note that register bit CCA_DONE is cleared in response to a CCA_REQUEST. Table 9-34 CCA_DONE Register Bits Register Bits Value Description CCA_DONE 0 CCA calculation not finished 1 CCA calculation finished • Bit 6 – CCA_STATUS - CCA Status Result The result of the CCA measurement is available in register bit CCA_STATUS after a CCA request is completed. Note that register bit CCA_STATUS is cleared in response to a CCA_REQUEST. Table 9-35 CCA_STATUS Register Bits Register Bits Value Description CCA_STATUS 0 Channel indicated as busy. 1 Channel indicated as idle. • Bit 5 – TST_STATUS - Test mode status This bit is reserved for internal use. It indicates the status of the test mode. 113 8393C-MCU Wireless-09/14

Table 9-36 TST_STATUS Register Bits Register Bits Value Description TST_STATUS 0 Test mode is disabled. 1 Test mode is active. • Bit 4:0 – TRX_STATUS4:0 - Transceiver Main Status The register bits TRX_STATUS signal the current radio transceiver status. Do not try to initiate a further state change while the radio transceiver is in STATE_TRANSITION_IN_PROGRESS state. Values not listed in the following table are reserved. Table 9-37 TRX_STATUS Register Bits Register Bits Value Description TRX_STATUS4:0 0x01 BUSY_RX 0x02 BUSY_TX 0x06 RX_ON 0x08 TRX_OFF 0x09 PLL_ON 0x0F SLEEP 0x11 BUSY_RX_AACK 0x12 BUSY_TX_ARET 0x16 RX_AACK_ON 0x19 TX_ARET_ON 0x1F STATE_TRANSITION_IN_PROGRESS 9.12.6 TRX_STATE – Transceiver State Control Register Bit 7 6 5 4 NA ($142) TRAC_STATUS2 TRAC_STATUS1 TRAC_STATUS0 TRX_CMD4 TRX_STATE Read/Write R R R RW Initial Value 0 0 0 0 Bit 3 2 1 0 NA ($142) TRX_CMD3 TRX_CMD2 TRX_CMD1 TRX_CMD0 TRX_STATE Read/Write RW RW RW RW Initial Value 0 0 0 0 The states of the radio transceiver are controlled via register TRX_STATE using register bits TRX_CMD. The read-only register bits TRAC_STATUS indicate the status or result of an Extended Operating Mode transaction. A successful state transition shall be confirmed by reading register bits TRX_STATUS. This register is used for both Basic and Extended Operating Mode. • Bit 7:5 – TRAC_STATUS2:0 - Transaction Status The status of the RX_AACK and TX_ARET procedure is indicated by register bits TRAC_STATUS. TRAC_STATUS is only valid in Extended Operating Modes (note, ATmega256/128/64RFR2 114 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 TRAC_STATUS is valid 2us after the respective procedure is finished by TX_END or RX_END IRQ). Details of the algorithm and a description of the status information are given in the RX_AACK_ON and TX_ARET_ON sections of the data-sheet. Even though the reset value for register bits TRAC_STATUS is 0, the RX_AACK and TX_ARET procedures set the register b its to TRAC_STATUS = 7 (INVALID) when it is started. Not all status values are used in both RX_AACK and TX_ARET transactions. In TX_ARET the status SUCCESS_DATA_PENDING indicates a successful reception of an ACK frame with frame pending bit set to 1. In RX_AACK the status SUCCESS_WAIT_FOR_ACK indicates an ACK frame is about to sent in RX_AACK slotted acknowledgment. Slotted acknowledgment operation must be enabled with the SLOTTED_OPERATION bit of register XAH_CTRL_0. The application software must set the SLPTR bit of register TRXPWR at the next back-off slot boundary in order to initiate a transmission of t h e ACK frame. For details refer to IEEE 802.15.4-2006, chapter 5.5.4.1. Values not listed in the following table are reserved. Table 9-38 TRAC_STATUS Register Bits Register Bits Value Description TRAC_STATUS2:0 0 SUCCESS (RX_AACK, TX_ARET) 1 SUCCESS_DATA_PENDING (TX_ARET) 2 SUCCESS_WAIT_FOR_ACK (RX_AACK) 3 CHANNEL_ACCESS_FAILURE (TX_ARET) 5 NO_ACK (TX_ARET) 7 INVALID (RX_AACK, TX_ARET) • Bit 4:0 – TRX_CMD4:0 - State Control Command A write access to register bits TRX_CMD initiates a state transition of the radio transceiver towards the new state as defined by the write access. Do not try to initiate a further state change while the radio transceiver is in STATE_TRANSITION_IN_PROGRESS state (see TRX_STATUS register). FORCE_PLL_ON is not valid for the SLEEP state as well as during STATE_TRANSITION_IN_P ROGRESS towards the SLEEP state. Values not listed in the following table are reserved and mapped to NOP. Table 9-39 TRX_CMD Register Bits Register Bits Value Description TRX_CMD4:0 0x00 NOP 0x02 TX_START 0x03 FORCE_TRX_OFF 0x04 FORCE_PLL_ON 0x06 RX_ON 0x08 TRX_OFF 0x09 PLL_ON (TX_ON) 0x16 RX_AACK_ON 0x19 TX_ARET_ON 115 8393C-MCU Wireless-09/14

9.12.7 TRX_CTRL_0 – Tranceiver Control Register 0 Bit 7 6 5 4 NA ($143) Res7 PMU_EN PMU_START PMU_IF_INV TRX_CTRL_0 Read/Write R RW RW RW Initial Value 0 0 0 0 Bit 3 2 1 0 NA ($143) Res3 Res2 Res1 Res0 TRX_CTRL_0 Read/Write R R R R Initial Value 0 0 0 0 The TRX_CTRL_0 register is a multi purpose register to control various operating modes and settings of the radio transceiver. • Bit 7 – Res7 - Reserved These bits are reserved for future use. • Bit 6 – PMU_EN - Enable Phase Measurement Unit This bit enables the Phase Measurement Unit. • Bit 5 – PMU_START - Start of Phase Measurement Unit This bit starts the Phase Measurement Unit. It is automatically cleared after the frame buffer has been written completely (128 values). • Bit 4 – PMU_IF_INV - PMU IF Inverse This bit controls the PMU In termediate Frequency path (normal IF position = 0 / inverse IF position = 1). • Bit 3:0 – Res3:0 - Reserved These bits are reserved for future use. 9.12.8 TRX_CTRL_1 – Transceiver Control Register 1 Bit 7 6 5 4 NA ($144) PA_EXT_EN IRQ_2_EXT_EN TX_AUTO_CRC_ON PLL_TX_FLT TRX_CTRL_1 Read/Write RW RW RW RW Initial Value 0 0 1 0 Bit 3 2 1 0 NA ($144) Res3 Res2 Res1 Res0 TRX_CTRL_1 Read/Write R R R R Initial Value 0 0 0 0 The TRX_CTRL_1 register is a multi purpose register to control various operating modes and settings of the radio transceiver. • Bit 7 – PA_EXT_EN - External PA support enable This register bit enables pin DIG3 and pin DIG4 to indicate the transmit state of the radio transceiver. The control of the external RF front-end is disabled when this bit is 0. Both pins DIG3 and DIG4 are then defined by the register of I/O ports F and G (PORTF, DDRF, PORTG, DDRG). The control of the external front-end is enabled when this bit is 1. DIG3 and DIG4 then indicate the state of the radio transceiver. Pin DIG3 is high and pin DIG4 is low in the state TX_BUSY. In all other states pin DIG3 is low and pin DIG4 ATmega256/128/64RFR2 116 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 is high. It is recommended to set PA_EXT_EN=1 only in receive or transmit states to reduce the power consumption or avoid leakage current of external RF switches or other building blocks especially during SLEEP state. • Bit 6 – IRQ_2_EXT_EN - Connect Frame Start IRQ to TC1 When this bit is set to one the capture input of Timer/Counter 1 is connected to the RX frame start signal and pin DIG2 becomes an output, driving the RX frame start signal. Antenna Diversity RF switch control (ANT_EXT_SW_EN=1) shall not be used at the same time, because it shares the same device pin. The function IRQ_2_EXT_EN is available for alternate frame time stamping using Timer/Counter 1. In general the preferred method for frame time stamping is using the symbol counter. • Bit 5 – TX_AUTO_CRC_ON - Enable Automatic CRC Calculation This register bit controls the automatic FCS generation for TX operations. The automatic FCS algorithm is performed autonomously by the radio transceiver if register bit TX_AUTO_CRC_ON=1. • Bit 4 – PLL_TX_FLT - Enable PLL TX Filter PLL TX filtering controls the output spectrum of the transmitted signal to decrease sidelobes. This is required for systems with an external power amplifier. TX filtering influences the signal quality. The EVM of the transmitted signal slightly degrades. • Bit 3:0 – Res3:0 - Reserved 9.12.9 PHY_TX_PWR – Transceiver Transmit Power Control Register Bit 7 6 5 4 3 2 1 0 NA ($145) Res3 Res2 Res1 Res0 TX_PWR3 TX_PWR2 TX_PWR1 TX_PWR0 PHY_TX_PWR Read/Write R R R R RW RW RW RW Initial Value 0 0 0 0 0 0 0 0 This register controls the output power of the transmitter. • Bit 7:4 – Res3:0 - Reserved • Bit 3:0 – TX_PWR3:0 - Transmit Power Setting These register bits determine the TX output power of the radio transceiver. Table 9-40 TX_PWR Register Bits Register Bits Value Description TX_PWR3:0 0 3.5 dBm 1 3.3 dBm 2 2.8 dBm 3 2.3 dBm 4 1.8 dBm 5 1.2 dBm 6 0.5 dBm 7 -0.5 dBm 8 -1.5 dBm 9 -2.5 dBm 10 -3.5 dBm 11 -4.5 dBm 117 8393C-MCU Wireless-09/14

Register Bits Value Description 12 -6.5 dBm 13 -8.5 dBm 14 -11.5 dBm 15 -16.5 dBm 9.12.10 PARCR – Power Amplifier Ramp up/down Control Register Bit 7 6 5 4 3 2 1 0 NA ($138) PALTD2 PALTD1 PALTD0 PALTU2 PALTU1 PALTU0 PARDFI PARUFI PARCR Read/Write RW RW RW RW RW RW RW RW Initial Value 0 1 1 0 1 1 0 0 This Register controls the power up and power down behavior of the Power Amplifier. • Bit 7:5 – PALTD2:0 - ext. PA Ramp Down Lead Time These bits control the ramp down lead time for the external power amplifier. Table 9-41 PALTD Register Bits Register Bits Value Description PALTD2:0 0 -3µs 1 -2µs 2 -1µs 3 0µs 4 1µs 5 2µs 6 3µs 7 4µs • Bit 4:2 – PALTU2:0 - ext. PA Ramp Up Lead Time These bits control the ramp up lead time for the external power amplifier. Table 9-42 PALTU Register Bits Register Bits Value Description PALTU2:0 0 -3µs 1 -2µs 2 -1µs 3 0µs 4 1µs 5 2µs 6 3µs 7 4µs • Bit 1 – PARDFI - Power Amplifier Ramp Down Frequency Inversion If this bit is clear, the PLL frequency is +500kHz (relative to carrier) while PA is ramping down and -500kHz otherwise. • Bit 0 – PARUFI - Power Amplifier Ramp Up Frequency Inversion ATmega256/128/64RFR2 118 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 If this bit is clear, the PLL frequency is -500kHz (relative to carrier) while PA is ramping up and +500kHz otherwise. 9.12.11 PHY_RSSI – Receiver Signal Strength Indicator Register Bit 7 6 5 4 NA ($146) RX_CRC_VALID RND_VALUE1 RND_VALUE0 RSSI4 PHY_RSSI Read/Write R R R R Initial Value 0 0 0 0 Bit 3 2 1 0 NA ($146) RSSI3 RSSI2 RSSI1 RSSI0 PHY_RSSI Read/Write R R R R Initial Value 0 0 0 0 The PHY_RSSI register is a multi purpose register that indicates FCS validity, provides random numbers and shows the current RSSI value. • Bit 7 – RX_CRC_VALID - Received Frame CRC Status Reading this register bit indicates whether the last received frame has a valid FCS or not. The register bit is updated when issuing a TRX24_RX_END interrupt and remains valid until the next TRX24_RX_END interrupt is issued, caused by a new frame reception. Table 9-43 RX_CRC_VALID Register Bits Register Bits Value Description RX_CRC_VALID 0 CRC (FCS) not valid 1 CRC (FCS) valid • Bit 6:5 – RND_VALUE1:0 - Random Value A 2-bit random value can be retrieved by reading register bits RND_VALUE. The value can be used for random numbers for security applications. Note that the radio transceiver shall be in Basic Operating Mode receive state. The values are updated every 1 µs. Ensure that register bit RX_PDT_DIS (register RX_SYN) is set to 0 at least 1 µs before reading a random value. • Bit 4:0 – RSSI4:0 - Receiver Signal Strength Indicator The result of the automated RSSI measurement is stored in these register bits. The value is updated every 2µs in receive states. The read value is a number between 0 and 28 indicating the received signal strength as a linear curve on a logarithmic input power scale (dBm) with a resolution of 3 dB. A RSSI value of 0 indicates a RF input power lower than RSSI_BASE_VAL (-90 dBm). A value of 28 marks a power higher or equal to -10 dBm. Table 9-44 RSSI Register B its Register Bits Value Description RSSI4:0 0 Minimum RSSI value: P(RF) < -90 dBm 1 P(RF) = RSSI_BASE_VAL+3 · (RSSI-1) [dBm] 2 ... 28 Maximum RSSI value: P(RF) ≥ -10 dBm 119 8393C-MCU Wireless-09/14

9.12.12 PHY_ED_LEVEL – Transceiver Energy Detection Level Register Bit 7 6 5 4 NA ($147) ED_LEVEL7 ED_LEVEL6 ED_LEVEL5 ED_LEVEL4 PHY_ED_LEVEL Read/Write R R R R Initial Value 1 1 1 1 Bit 3 2 1 0 NA ($147) ED_LEVEL3 ED_LEVEL2 ED_LEVEL1 ED_LEVEL0 PHY_ED_LEVEL Read/Write R R R R Initial Value 1 1 1 1 This register contains the result of an Energy Detection measurement. • Bit 7:0 – ED_LEVEL7:0 - Energy Detection Level The minimum ED value (ED_LEVEL = 0) indicates a receiver power less than or equal to RSSI_BASE_VAL. The range is 83 dB with a resolution of 1 dB and an absolute accuracy of ±5 dB. A manua l ED measurement can be initiated by a write access to this register. A value of 0xFF signals that no measurement has yet been started (reset value). The measurement duration is 8 symbol periods (128 µs) for a data rate of 250 kb/s. For High Data Rate Modes the automated measurement duration is reduced to 32 µs. For manually initiated ED measurements in these modes the measurement period is still 128 µs as long as the receiver is in RX_ON state. A value other than 0xFF indicates the result of the last ED measurement. Table 9-45 ED_LEVEL Register Bits Register Bits Value Description ED_LEVEL7:0 0x00 Minimum result of last ED measurement 0x01 P(RF) = RSSI_BASE_VAL+ED [dBm] 0x02 ... 0x53 Maximum result of last ED measurement 0xFF Reset value 9.12.13 PHY_CC_CCA – Transceiver Clear Channel Assessment (CCA) Control Register Bit 7 6 5 4 NA ($148) CCA_REQUEST CCA_MODE1 CCA_MODE0 CHANNEL4 PHY_CC_CCA Read/Write RW RW RW RW Initial Value 0 0 1 0 Bit 3 2 1 0 NA ($148) CHANNEL3 CHANNEL2 CHANNEL1 CHANNEL0 PHY_CC_CCA Read/Write RW RW RW RW Initial Value 1 0 1 1 This register is provided to initiate and control a CCA measurement. • Bit 7 – CCA_REQUEST - Manual CCA Measurement Request A manual CCA measurement is initiated with setting CCA_REQUEST=1. The end of the CCA measurement is indicated by the TRX24_CCA_ED_DONE interrupt. Register bits CCA_DONE and CCA_STATUS of register TRX_STATUS are updated after a ATmega256/128/64RFR2 120 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 CCA_REQUEST. The register bit is automatically cleared after requesting a CCA measurement with CCA_REQUEST=1. • Bit 6:5 – CCA_MODE1:0 - Select CCA Measurement Mode The CCA mode can be se lected using these register bits. Note that IEEE 802.15.4- 2006 CCA Mode 3 defines the logical combination of CCA Mode 1 and 2 with the logical operators AND or OR. This can be selected with CCA_MODE=0 for logical operation OR and CCA_MODE=3 for logical operation AND. Table 9-46 CCA_MODE Register Bits Register Bits Value Description CCA_MODE1:0 0 Mode 3a, Carrier sense OR energy above threshold 1 Mode 1, Energy above threshold 2 Mode 2, Carrier sense only 3 Mode 3b, Carrier sense AND energy above threshold • Bit 4:0 – CHANNEL4:0 - RX/TX Channel Selection These register bits define the RX/TX channel. The channel assignment is according to IEEE 802.15.4. Table 9-47 CHANNEL Register Bits Register Bits Value Description CHANNEL4:0 11 2405 MHz 12 2410 MHz 13 2415 MHz 14 2420 MHz 15 2425 MHz 16 2430 MHz 17 2435 MHz 18 2440 MHz 19 2445 MHz 20 2450 MHz 21 2455 MHz 22 2460 MHz 23 2465 MHz 24 2470 MHz 25 2475 MHz 26 2480 MHz 9.12.14 CCA_THRES – Transceiver CCA Threshold Setting Register Bit 7 6 NA ($149) CCA_CS_THRES3 CCA_CS_THRES2 CCA_THRES Read/Write RW RW Initial Value 1 1 121 8393C-MCU Wireless-09/14

Bit 5 4 NA ($149) CCA_CS_THRES1 CCA_CS_THRES0 CCA_THRES Read/Write RW RW Initial Value 0 0 Bit 3 2 NA ($149) CCA_ED_THRES3 CCA_ED_THRES2 CCA_THRES Read/Write RW RW Initial Value 0 1 Bit 1 0 NA ($149) CCA_ED_THRES1 CCA_ED_THRES0 CCA_THRES Read/Write RW RW Initial Value 1 1 This register sets the threshold level for the Energy Detection (ED) of the Clear Channel Assessment (CCA). • Bit 7:4 – CCA_CS_THRES3:0 - CS Threshold Level for CCA Measurement These bits are reserved for internal use. • Bit 3:0 – CCA_ED_THRES3:0 - ED Threshold Level for CCA Measurement These bits define the received power threshold of the Energy above threshold algorithm. The threshold is calculated by RSSI_BASE_VAL + 2CCA_ED_THRES [dBm]. Any received power above this level is interpreted as a busy channel. 9.12.15 RX_CTRL – Transceiver Receive Control Register Bit 7 6 5 4 NA ($14A) SDM_MODE1 SDM_MODE0 ACR_MODE SOFT_MODE RX_CTRL Read/Write RW RW RW RW Initial Value 1 0 1 1 Bit 3 2 1 0 NA ($14A) PDT_THRES3 PDT_THRES2 PDT_THRES1 PDT_THRES0 RX_CTRL Read/Write RW RW RW RW Initial Value 0 1 1 1 The register controls the sensitivity of the Antenna Diversity Mode. Note that in High Data Rate modes the ACR module will always be disabled. • Bit 7:6 – SDM_MODE1:0 - Sigma-Delta Modulator Order and Delay Compensation These bits are reserved f o r internal use. They select the order of the sigma-delta modulator (SDM), turn on or off the delay compensation unit (DCU) and other internal functions. Table 9-48 SDM_MODE Register Bits Register Bits Value Description SDM_MODE1:0 0 SDM mode 1 selected (Mash 1), DCU turned on 1 SDM mode 1 with random carry threshold ATmega256/128/64RFR2 122 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 Register Bits Value Description 2 SDM mode 2 selected (Mash 1-1), DCU turned on 3 SDM mode 2 with random ACCU2 • Bit 5 – ACR_MODE - Adjacent Channel Rejection Mode This bit is reserved for internal use. It turns on or off the ACR module. For high rate modes the ACR module will be always disabled. • Bit 4 – SOFT_MODE - Correlator Soft Mode This bit is reserved for internal use. It controls the correlation function of the digital baseband processor. Furthermore the bit enables or disables the data scrambling in the high data rate modes. • Bit 3:0 – PDT_THRES3:0 - Receiver Sensitivity Control These register bits control the sensitivity of the receiver correlation unit. If the Antenna Diversity algorithm is enabled the value shall be set to PDT_THRES = 3. Otherwise it shall be set back to the reset value. Values not listed in the following table are reserved. Table 9-49 PDT_THRES Register Bits Register Bits Value Description PDT_THRES3:0 0x7 Reset value, to be used if Antenna Diversity algorithm is disabled 0x3 Recommended correlator threshold for Antenna Diversity operation 9.12.16 SFD_VALUE – Start of Frame Delimiter Value Register Bit 7 6 5 4 3 2 1 0 NA ($14B) SFD_VALUE7:0 SFD_VALUE Read/Write RW RW R W RW RW RW RW RW Initial Value 1 0 1 0 0 1 1 1 This register contains the one octet start-of-frame delimiter (SFD) to synchronize to a received frame. The lower 4 bits must not be all zero to avoid decoding conflicts. • Bit 7:0 – SFD_VALUE7:0 - Start of Frame Delimiter Value For compliant IEEE 802.15.4 networks set SFD_VALUE = 0xA7. This is the default value of the register. To esta blish non IEEE 802.15.4 compliant networks the SFD value can be changed to any other value. If enabled a RX_START interrupt is issued only if the received SFD matches the register content of SFD_VALUE and a valid PHR is received. Table 9-50 SFD_VALUE Register Bits Register Bits Value Description SFD_VALUE7:0 0xA7 IEEE 802.15.4 compliant value of the SFD 123 8393C-MCU Wireless-09/14

9.12.17 TRX_CTRL_2 – Transceiver Control Register 2 Bit 7 6 5 4 NA ($14C) RX_SAFE_MODE Res4 Res3 Res2 TRX_CTRL_2 Read/Write RW R R R Initial Value 0 0 0 0 Bit 3 2 1 0 NA ($14C) Res1 Res0 OQPSK_DATA_RATE1 OQPSK_DATA_RATE0 TRX_CTRL_2 Read/Write R R RW RW Initial Value 0 0 0 0 This register controls the data rate setting of the radio transceiver. • Bit 7 – RX_SAFE_MODE - RX Safe Mode If this bit is set, the next received frame will be protected and not overwritten by following frames. Set this bit to 0 to release the buffer (and set it again for further protection). • Bit 6:2 – Res4:0 - Reserved • Bit 1:0 – OQPSK_DATA_RATE1:0 - Data Rate Selection A write access to these register bits sets the OQPSK PSDU data rate used by the radio transceiver. The reset value OQPSK_DATA_RATE = 0 is the PSDU data rate according to IEEE 802.15.4. All other values are used in High Data Rate Modes. Table 9-51 OQPSK_DATA_RATE Register Bits Register Bits Value Description OQPSK_DATA_RATE1:0 0 250 kb/s (IEEE 802.15.4 compliant) 1 500 kb/s 2 1000 kb/s 3 2000 kb/s 9.12.18 ANT_DIV – Antenna Diversity Control Register Bit 7 6 5 4 NA ($14D) ANT_SEL Res2 Res1 Res0 ANT_DIV Read/Write R R R R Initial Value 0 0 0 0 Bit 3 2 1 0 NA ($14D) ANT_DIV_EN ANT_EXT_SW_EN ANT_CTRL1 ANT_CTRL0 ANT_DIV Read/Write RW RW RW RW Initial Value 0 0 1 1 This register controls the Antenna Diversity. • Bit 7 – ANT_SEL - Antenna Diversity Antenna Status This register bit signals the currently selected antenna path. The selection may be based either on the last antenna diversity cycle (ANT_DIV_EN = 1) or on the content of register bits ANT_CTRL. ATmega256/128/64RFR2 124 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 Table 9-52 ANT_SEL Register Bits Register Bits Value Description ANT_SEL 0 Antenna 0 1 Antenna 1 • Bit 6:4 – Res2:0 - Reserved • Bit 3 – ANT_DIV_EN - Enable Antenna Diversity If this register bit is set the Antenna Diversity algorithm is enabled. On reception of a frame the algorithm selects an antenna autonomously during SHR search. This selection is kept until 1. A new SHR search starts or 2. Receive states are left or 3. A manually programming of bits ANT_CTRL occurred. If ANT_DIV_EN = 1 the bit ANT_EXT_SW_EN shall also be set to 1. Table 9-53 ANT_DIV_EN Register Bits Register Bits Value Description ANT_DIV_EN 0 Antenna Diversity algorithm disabled 1 Antenna Diversity algorithm enabled • Bit 2 – ANT_EXT_SW_EN - Enable External Antenna Switch Control If enabled, pin DIG1 and pin DIG2 become output pins and provide a differential control signal for an external Antenna Diversity switch. The selection of a specific antenna is done either by the automatic Antenna Diversity algorithm (ANT_DIV_EN = 1) or according to bits ANT_CTRL if the Antenna Diversity algorithm is disabled. Do not enable Antenna Diversity RF switch control (ANT_EXT_SW_EN = 1) and RX Frame Time Stamping (IRQ_2_EXT_EN = 1, see register TRX_CTRL_1) at the same time. If this bit is set the control pins DIG1/DIG2 are activated in all radio transceiver states as long as bit ANT_EXT_SW_EN is also set. If the radio transceiver is not in a receive or transmit state, it is recomme nded to disable bit ANT_EXT_SW_EN to reduce the power consumption or avoid leakage current of an external RF switch especially during SLEEP state. If bit ANT_EXT_SW_EN = 0, the output pins DIG1 and DIG2 are controlled by the register of I/O ports F and G (PORTF, DDRF, PORTG, DDRG). Table 9-54 ANT_EXT_SW_EN Register Bits Register Bits Value Description ANT_EXT_SW_EN 0 Antenna Diversity RF switch control disabled 1 Antenna Diversity RF switch control enabled • Bit 1:0 – ANT_CTRL1:0 - Static Antenna Diversity Switch Control These bits provide a static control of an Antenna Diversity switch. This register setting defines the selected antenna if ANT_DIV_EN is set to 0 (Antenna Diversity disabled). Register values 1 and 2 are valid for ANT_EXT_SW_EN = 1. Table 9-55 ANT_CTRL Register Bits Register Bits Value Description ANT_CTRL1:0 0 Reserved 1 Antenna 1: DIG1=L, DIG2=H 2 Antenna 0: DIG1=H, DIG2=L 3 Default value for ANT_EXT_SW_EN=0; Mandatory setting for applications not using 125 8393C-MCU Wireless-09/14

Register Bits Value Description Antenna Diversity 9.12.19 IRQ_MASK – Transceiver Interrupt Enable Register Bit 7 6 5 4 NA ($14E) AWAKE_EN TX_END_EN AMI_EN CCA_ED_DONE_EN IRQ_MASK Read/Write RW RW RW RW Initial Value 0 0 0 0 Bit 3 2 1 0 NA ($14E) RX_END_EN RX_START_EN PLL_UNLOCK_EN PLL_LOCK_EN IRQ_MASK Read/Write RW RW RW RW Initial Value 0 0 0 0 This register is used to enable or disable individual interrupts of the radio transceiver. An interrupt is enabled if the corresponding bit is set to 1. All interrupts are disabled after the power up sequence or reset. If an interrupt is enabled it is recommended to read the interrupt status register IRQ_STATUS first to clear the history. • Bit 7 – AWAKE_EN - Awake Interrupt Enable • Bit 6 – TX_END_EN - TX_END Interrupt Enable • Bit 5 – AMI_EN - Address Match Interrupt Enable • Bit 4 – CCA_ED_DONE_EN - End of ED Measurement Interrupt Enable • Bit 3 – RX_END_EN - RX_END Interrupt Enable • Bit 2 – RX_START_EN - RX_START Interrupt Enable • Bit 1 – PLL_UNLOCK_EN - PLL Unlock Interrupt Enable • Bit 0 – PLL_LOCK_EN - PLL Lock Interrupt Enable 9.12.20 IRQ_MASK1 – Transceiver Interrupt Enable Register 1 Bit 7 6 NA ($BE) Res2 Res1 IRQ_MASK1 Read/Write R R Initial Value 0 0 Bit 5 4 NA ($BE) Res0 MAF_3_AMI_EN IRQ_MASK1 Read/Write R RW Initial Value 0 0 Bit 3 2 NA ($BE) MAF_2_AMI_EN MAF_1_AMI_EN IRQ_MASK1 Read/Write RW RW Initial Value 0 0 Bit 1 0 NA ($BE) MAF_0_AMI_EN TX_START_EN IRQ_MASK1 Read/Write RW RW Initial Value 0 0 ATmega256/128/64RFR2 126 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 This register is used to enable or disable additional interrupts of the radio transceiver. An interrupt is enabled if the corresponding bit is set to 1. All interrupts are disabled after the power up sequence or reset. If an interrupt is enabled it is recommended to read the interrupt status register IRQ_STATUS first to clear the history. • Bit 7:5 – Res2:0 - Reserved Bit • Bit 4 – MAF_3_AMI_EN - Address Match Interrupt enable Address filter 3 • Bit 3 – MAF_2_AMI_EN - Address Match Interrupt enable Address filter 2 • Bit 2 – MAF_1_AMI_EN - Address Match Interrupt enable Address filter 1 • Bit 1 – MAF_0_AMI_EN - Address Match Interrupt enable Address filter 0 • Bit 0 – TX_START_EN - Transmit Start Interrupt enable 9.12.21 IRQ_STATUS – Transceiver Interrupt Status Register Bit 7 6 5 4 NA ($14F) AWAKE TX_END AMI CCA_ED_DONE IRQ_STATUS Read/Write RW RW RW RW Initial Value 0 0 0 0 Bit 3 2 1 0 NA ($14F) RX_END RX_START PLL_UNLOCK PLL_LOCK IRQ_STATUS Read/Write RW RW RW RW Initial Value 0 0 0 0 This register contains the status of the pending interrupt requests. An interrupt is pending if the associated bit has a value of one. Such a pending interrupts can be manually cleared by writing a 1 to that register bit. Interrupts are automatically cleared when the corresponding interrupt service routine is being executed. • Bit 7 – AWAKE - Awake Interrupt Status • Bit 6 – TX_END - TX_END Interrupt Status • Bit 5 – AMI - Address Match Interrupt Status • Bit 4 – CCA_ED_DONE - End of ED Measurement Interrupt Status • Bit 3 – RX_END - RX_END Interrupt Status • Bit 2 – RX_START - RX_START Interrupt Status • Bit 1 – PLL_UNLOCK - PLL Unlock Interrupt Status • Bit 0 – PLL_LOCK - PLL Lock Interrupt Status 9.12.22 IRQ_STATUS1 – Transceiver Interrupt Status Register 1 Bit 7 6 5 4 NA ($BF) Res2 Res1 Res0 MAF_3_AMI IRQ_STATUS1 Read/Write R R R RW Initial Value 0 0 0 0 Bit 3 2 1 0 NA ($BF) MAF_2_AMI MAF_1_AMI MAF_0_AMI TX_START IRQ_STATUS1 Read/Write RW RW RW RW Initial Value 0 0 0 0 127 8393C-MCU Wireless-09/14

This register contains the status of additional pending interrupt requests. An interrupt is pending if the associated bit has a value of one. Such a pending interrupts can be manually cleared by writing a 1 to that register bit. Interrupts are automatically cleared when the corresponding interrupt service routine is being executed. • Bit 7:5 – Res2:0 - Reserved Bit • Bit 4 – MAF_3_AMI - Address Match Interrupt Status Address filter 3 • Bit 3 – MAF_2_AMI - Address Match Interrupt Status Address filter 2 • Bit 2 – MAF_1_AMI - Address Match Interrupt Status Address filter 1 • Bit 1 – MAF_0_AMI - Address Match Interrupt Status Address filter 0 • Bit 0 – TX_START - Transmit Start Interrupt Status 9.12.23 VREG_CTRL – Voltage Regulator Control and Status Register Bit 7 6 5 4 NA ($150) AVREG_EXT AVDD_OK AVREG_TRIM1 AVREG_TRIM0 VREG_CTRL Read/Write RW R RW RW Initial Value 0 0 0 0 Bit 3 2 1 0 NA ($150) DVREG_EXT DVDD_OK DVREG_TRIM1 DVREG_TRIM0 VREG_CTRL Read/Write RW R RW RW Initial Value 0 0 0 0 This register controls the use of the voltage regulators and indicates their status. • Bit 7 – AVREG_EXT - Use External AVDD Regulator This bit is reserved for IC test and should not be modified by the application firmware. If set, this register bit disables the internal analog voltage regulator to apply an external regulated 1.8V supply for th e analog building blocks. Table 9-56 AVREG_EXT Register Bits Register Bits Value Description AVREG_EXT 0 Internal AVDD voltage regulator for the analog section is enabled. 1 Internal AVDD voltage regulator is disabled. • Bit 6 – AVDD_OK - AVDD Supply Voltage Valid This register bit indicates if the internal 1.8V regulated voltage supply AVDD has settled. The bit is set to logic high if AVREG_EXT = 1. Table 9-57 AVDD_OK Register Bits Register Bits Value Description AVDD_OK 0 Analog voltage regulator disabled or supply voltage not stable 1 Analog supply voltage has settled • Bit 5:4 – AVREG_TRIM1:0 - Adjust AVDD Supply Voltage These bits are reserved for internal use. They allow adjusting the value of the analog supply voltage (AVDD). ATmega256/128/64RFR2 128 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 Table 9-58 AVREG_TRIM Register Bits Register Bits Value Description AVREG_TRIM1:0 0 1.80V 1 1.75V 2 1.84V 3 1.88V • Bit 3 – DVREG_EXT - Use External DVDD Regulator This bit may be set in the Register, but is deactivated in the design. The DVREG_EXT functionality to deactivate the digital voltage regulator is no implemented anymore Table 9-59 DVREG_EXT Register Bits Register Bits Value Description DVREG_EXT 0 Internal DVDD voltage regulator for the digital section is enabled. 1 Internal DVDD voltage regulator is disabled; use external regulated 1.8V supply voltage for the digital section. • Bit 2 – DVDD_OK - DVDD Supply Voltage Valid This register bit indicates if the internal 1.8V regulated voltage supply DVDD has settled. The bit is set to logic high if DVREG_EXT = 1. Table 9-60 DVDD_OK Register Bits Register Bits Value Description DVDD_OK 0 Digital voltage regulator disabled or supply voltage not stable 1 Digital supply voltage has settled • Bit 1:0 – DVREG_TRIM1:0 - Adjust DVDD Supply Voltage These bits are reserved for internal use. They allow adjusting the value of the digital supply voltage (DVDD). Table 9-61 DVREG_TRIM Register Bits Register Bits Value Description DVREG_TRIM1:0 0 1.80V 1 1.75V 2 1.84V 3 1.88V 9.12.24 BATMON – Battery Monitor Control and Status Register Bit 7 6 5 4 NA ($151) BAT_LOW BAT_LOW_EN BATMON_OK BATMON_HR BATMON Read/Write RW RW R RW Initial Value 0 0 0 0 Bit 3 2 1 0 NA ($151) BATMON_VTH3 BATMON_VTH2 BATMON_VTH1 BATMON_VTH0 BATMON Read/Write RW RW RW RW Initial Value 0 0 1 0 129 8393C-MCU Wireless-09/14

This register configures the battery monitor to observe the supply voltage at EVDD. The status of the EVDD supply voltage is accessible by reading bit BATMON_OK with respect to the actual BATMON settings. Furthermore the Battery Monitor Interrupt can be controlled with the bits BAT_LOW and BAT_LOW_EN similar to the function of the IRQ_STATUS and IRQ_MASK register for other radio transceiver interrupts. • Bit 7 – BAT_LOW - Battery Monitor Interrupt Status A BATMON Interrupt is pending if this bit is set. Writing one to this bit if it has been at one will clear the interrupt. • Bit 6 – BAT_LOW_EN - Battery Monitor Interrupt Enable The Battery Monitor Interrupt is enabled if this bit is set to one. The Battery Monitor will not generate an interrupt if this bit is zero. • Bit 5 – BATMON_OK - Battery Monitor Status The register bit BATMON_OK indicates the level of the external supply voltage with respect to the programmed threshold BATMON_VTH. Table 9-62 BATMON_OK Register Bits Register Bits Value Description BATMON_OK 0 The battery voltage is below the threshold. 1 The battery voltage is above the threshold. • Bit 4 – BATMON_HR - Battery Monitor Voltage Range This bit sets the range and resolution of the battery monitor. Table 9-63 BATMON_HR Register Bits Register Bits Value Description BATMON_HR 0 Enables the low range, see BATMON_VTH 1 Enables the high range, see BATMON_VTH • Bit 3:0 – BATMON_VTH3:0 - Battery Monitor Threshold Voltage The threshold values for th e battery monitor are set by these register bits according to the following table. Table 9-64 BATMON_VTH Register Bits Register Bits Value Description BATMON_VTH3:0 0x0 2.550V / 1.70V (BATMON_HR=1/0) 0x1 2.625V / 1.75V (BATMON_HR=1/0) 0x2 2.700V / 1.80V (BATMON_HR=1/0) 0x3 2.775V / 1.85V (BATMON_HR=1/0) 0x4 2.850V / 1.90V (BATMON_HR=1/0) 0x5 2.925V / 1.95V (BATMON_HR=1/0) 0x6 3.000V / 2.00V (BATMON_HR=1/0) 0x7 3.075V / 2.05V (BATMON_HR=1/0) 0x8 3.150V / 2.10V (BATMON_HR=1/0) 0x9 3.225V / 2.15V (BATMON_HR=1/0) 0xA 3.300V / 2.20V (BATMON_HR=1/0) 0xB 3.375V / 2.25V (BATMON_HR=1/0) 0xC 3.450V / 2.30V (BATMON_HR=1/0) 0xD 3.525V / 2.35V (BATMON_HR=1/0) ATmega256/128/64RFR2 130 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 Register Bits Value Description 0xE 3.600V / 2.40V (BATMON_HR=1/0) 0xF 3.675V / 2.45V (BATMON_HR=1/0) 9.12.25 XOSC_CTRL – Crystal Oscillator Control Register Bit 7 6 5 4 NA ($152) XTAL_MODE3 XTAL_MODE2 XTAL_MODE1 XTAL_MODE0 XOSC_CTRL Read/Write RW RW RW RW Initial Value 1 1 1 1 Bit 3 2 1 0 NA ($152) XTAL_TRIM3 XTAL_TRIM2 XTAL_TRIM1 XTAL_TRIM0 XOSC_CTRL Read/Write RW RW RW RW Initial Value 0 0 0 0 This register controls the operation of the 16MHz crystal oscillator. • Bit 7:4 – XTAL_MODE3:0 - Crystal Oscillator Operating Mode These register bits set the operating mode of the 16 MHz crystal oscillator. For normal operation the default value is set to XTAL_MODE = 0xF after reset. For use with an external clock source it is recommended to set XTAL_MODE = 0x4. Table 9-65 XTAL_MODE Register Bits Register Bits Value Description XTAL_MODE3:0 0x4 Internal crystal oscillator disabled; use external reference frequency. 0xF Internal crystal oscillator enabled; amplitude regulation of oscillation enabled. • Bit 3:0 – XTAL_TRIM3:0 - Crystal Oscillator Load Capacitance Trimming These register bits control two internal capacitance arrays connected to pins XTAL1 and XTAL2. A capacitance value in the range from 0 pF to 4.5 pF is selectable with a resolution of 0.3 pF. Table 9-66 XTAL_TRIM Register Bits Register Bits Value Description XTAL_TRIM3:0 0x0 0.0 pF, trimming capacitors disconnected 0x1 0.3 pF, trimming capacitor switched on 0x2 ... 0xF 4.5 pF, trimming capacitor switched on 9.12.26 RX_SYN – Transceiver Receiver Sensitivity Control Register Bit 7 6 NA ($155) RX_PDT_DIS RX_OVERRIDE RX_SYN Read/Write RW RW Initial Value 0 1 131 8393C-MCU Wireless-09/14

Bit 5 4 NA ($155) RXO_CFG1 RXO_CFG0 RX_SYN Read/Write RW RW Initial Value 0 0 Bit 3 2 NA ($155) RX_PDT_LEVEL3 RX_PDT_LEVEL2 RX_SYN Read/Write RW RW Initial Value 0 0 Bit 1 0 NA ($155) RX_PDT_LEVEL1 RX_PDT_LEVEL0 RX_SYN Read/Write RW RW Initial Value 0 0 This register controls the sensitivity threshold of the receiver. • Bit 7 – RX_PDT_DIS - P revent Frame Reception RX_PDT_DIS = 1 prevents the reception of a frame even if the radio transceiver is in receive modes. An ongoing frame reception is not affected. This operation mode is independent of the setting of register bits RX_PDT_LEVEL. • Bit 6 – RX_OVERRIDE - Receiver Override Function If this bit is set, the receiver restarts the reception if a co-channel interferer is detected. This function is not directly visible, but should lead to a better co-channel interference suppression. • Bit 5 – RXO_CFG1 - RX_OVERRIDE Configuration Configures the different RX_OVERRIDE options. • Bit 4 – RXO_CFG0 - RX_OVERRIDE configuration Configures the different RX_OVERRIDE options. • Bit 3:0 – RX_PDT_LEVEL3:0 - Reduce Receiver Sensitivity These register bits reduce the receiver sensitivity such that frames with a RSSI level below the RX_PDT_LEVEL threshold level are not received (RX_PDT_LEVEL>0). The threshold level can be calculated according to the following formula: RX_THRES > RSSI_BASE_VAL+3·(RX_PDT_LEVEL-1), for RX_PDT_LEVEL>0. If register bits RX_PDT_LEVEL>0 the current consumption of the receiver in states RX_ON and RX_AACK_ON is reduced by 500 µA. If register bits RX_PDT_LEVEL=0 (reset value) all frames with a valid SH R and PHR are received, independently of their signal strength. Examples for certain register settings are given in the following table. Table 9-67 RX_PDT_LEVEL Register Bits Register Bits Value Description RX_PDT_LEVEL3:0 0x0 RX_THRES ≤ RSSI_BASE_VAL (Reset value); RSSI value not considered 0x1 RX_THRES > RSSI_BASE_VAL + 0 · 3; RSSI > -90 dBm 0x2 ... 0xE RX_THRES > RSSI_BASE_VAL + 13 · 3; RSSI > -51 dBm 0xF RX_THRES > RSSI_BASE_VAL + 14 · 3; RSSI > -48 dBm ATmega256/128/64RFR2 132 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 9.12.27 XAH_CTRL_1 – Transceiver Acknowledgment Frame Control Register 1 Bit 7 6 5 4 NA ($157) Res1 Res0 AACK_FLTR_RES_FT AACK_UPLD_RES_FT XAH_CTRL_1 Read/Write R R RW RW Initial Value 0 0 0 0 Bit 3 2 1 0 NA ($157) Res AACK_ACK_TIME AACK_PROM_MODE Res XAH_CTRL_1 Read/Write R RW RW R Initial Value 0 0 0 0 This register is a multi-purpose control register for various RX_AACK settings. • Bit 7:6 – Res1:0 - Reserved Bit This bit is reserved for future use. The result of a read access is undefined. The register bit must always be written with the reset value. • Bit 5 – AACK_FLTR_RES_FT - Filter Reserved Frames This register bit shall only be set if AACK_UPLD_RES_FT = 1. If AACK_FLTR_RES_FT = 1 reserved frame types are filtered similar to data frames as specified in IEEE 802.15.4-2006. Reserved frame types are explained in IEEE 802.15.4 section 7.2.1.1.1. If AACK_FLTR_RES_FT = 0 a received, reserved frame is only checked for a valid FCS. • Bit 4 – AACK_UPLD_RES_FT - Process Reserved Frames If AACK_UPLD_RES_FT = 1 received frames indicated as reserved are further processed. A RX_END interrupt is generated if the FCS of those frames is valid. In conjunction with the configuration bit AACK_FLTR_RES_FT set, these frames are handled like IEEE 802.15.4 compliant data frames during RX_AACK transaction. An AMI interrupt is issued if the address in the received frame matches the node address. That means if a reserved frame passes the third level filter rules, an acknowledgment frame is generated and transmitted if it was requested by the received frame. If this is not wanted bit AACK_DIS_ACK in register CSMA_SEED_1 has to be set. • Bit 3 – Res - Reserved Bit This bit is reserved for future use. The result of a read access is undefined. The register bit must always be written with the reset value. • Bit 2 – AACK_ACK_TIME - Reduce Acknowledgment Time According to IEEE 802.15.4, section 7.5.6.4.2 the transmission of an acknowledgment frame shall commence 12 symbols (aTurnaroundTime) after the reception of the last symbol of a data or MAC command frame. This is achieved with the reset value of the register bit AACK_ACK_TIME. If AACK_ACK_TIME = 1 an acknowledgment frame is alternatively sent already 2 s ymbol periods (32 µs) after the reception of the last symbol of a data or MAC command frame. This may be applied to proprietary networks or networks using the High Data Rate Modes to increase battery lifetime and to improve the overall data throughput. This setting affects also to acknowledgment frame response time for slotted acknowledgment operation. Table 9-68 AACK_ACK_TIME Register Bits Register Bits Value Description AACK_ACK_TIME 0 12 symbols acknowledgment time 133 8393C-MCU Wireless-09/14

Register Bits Value Description 1 2 symbols acknowledgment time • Bit 1 – AACK_PROM_MODE - Enable Promiscuous Mode This register bit enables the promiscuous mode within the RX_AACK mode; refer to IEEE 802.15.4-2006 chapter 7.5.6.5. If this bit is set, every incoming frame with a valid PHR finishes with a RX_END interrupt even if the third level filter rules do not match or the FCS is not valid. The bit RX_CRC_VALID of register PHY_RSSI is set accordingly. If this bit is set and a frame passes the third level filter rules, an acknowledgment frame is generated and transmitted unless disabled by bit AACK_DIS_ACK of register CSMA_SEED_1. • Bit 0 – Res - Reserved Bit This bit is reserved for future use. The result of a read access is undefined. The register bit must always be written with the reset value. 9.12.28 FTN_CTRL – Transceiver Filter Tuning Control Re gister Bit 7 6 5 4 NA ($158) FTN_START FTN_ROUND FTNV5 FTNV4 FTN_CTRL Read/Write RW RW RW RW Initial Value 0 1 0 1 Bit 3 2 1 0 NA ($158) FTNV3 FTNV2 FTNV1 FTNV0 FTN_CTRL Read/Write RW RW RW RW Initial Value 1 0 0 0 This register controls the operation of the calibration loop of the filter tuning network. • Bit 7 – FTN_START - Start Calibration Loop of Filter Tuning Network FTN_START = 1 initiates the calibration of the filter tuning network. When the calibration cycle has finished after at most 25 µs the register bit is automatically reset to 0. • Bit 6 – FTN_ROUND - Round Filter Tuning Calibration Result This bit is reserved for internal use. • Bit 5:0 – FTNV5:0 - Filter Tuning Calibration Result These bits are reserved for internal use. 9.12.29 PLL_CF – Transceiver Center Frequency Calibration Control Register Bit 7 6 NA ($15A) PLL_CF_START EN_PLL_CF PLL_CF Read/Write RW RW Initial Value 0 1 Bit 5 4 NA ($15A) PLL_VMOD_TUNE1 PLL_VMOD_TUNE0 PLL_CF Read/Write RW RW Initial Value 0 1 ATmega256/128/64RFR2 134 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 Bit 3 2 NA ($15A) PLL_CF3 PLL_CF2 PLL_CF Read/Write RW RW Initial Value 0 1 Bit 1 0 NA ($15A) PLL_CF1 PLL_CF0 PLL_CF Read/Write RW RW Initial Value 1 1 This register controls the operation of the center frequency calibration loop. Consecutive read/write com mands to this register must include a wait time of at least 500ns between each access. • Bit 7 – PLL_CF_START - Start Center Frequency Calibration PLL_CF_START = 1 initiates the center frequency calibration. The calibration cycle has finished after 35 µs (typical). The register bit is cleared immediately after finishing the calibration. • Bit 6 – EN_PLL_CF - Enable Center Frequency Tuning This bit is reserved for internal use. • Bit 5:4 – PLL_VMOD_TUNE1:0 - VCO Modulation Tuning These bits are reserved for internal use. • Bit 3:0 – PLL_CF3:0 - Center Frequency Control Word These bits are reserved for i nternal use. 9.12.30 PLL_DCU – Transceiver Delay Cell Calibration Control Register Bit 7 6 5 4 NA ($15B) PLL_DCU_START Res PLL_DCUW5 PLL_DCUW4 PLL_DCU Read/Write RW R RW RW Initial Value 0 0 1 0 Bit 3 2 1 0 NA ($15B) PLL_DCUW3 PLL_DCUW2 PLL_DCUW1 PLL_DCUW0 PLL_DCU Read/Write RW RW RW RW Initial Value 0 0 0 0 This register controls the operation of the calibration loop of the delay cell. • Bit 7 – PLL_DCU_START - Start Delay Cell Calibration PLL_DCU_START = 1 initiates the delay cell calibration. The calibration cycle has finished after at most 6 µs. The register bit is cleared immediately after finishing the calibration. • Bit 6 – Res - Reserved Bit This bit is reserved for future use. The result of a read access is undefined. The register bit must always be written with the reset value. • Bit 5:0 – PLL_DCUW5:0 - Delay Range Setting These bits are reserved for internal use. 135 8393C-MCU Wireless-09/14

9.12.31 CC_CTRL_0 – Channel Control Register 0 Bit 7 6 5 4 NA ($153) CC_NUMBER7 CC_NUMBER6 CC_NUMBER5 CC_NUMBER4 CC_CTRL_0 Read/Write RW RW RW RW Initial Value 0 0 0 0 Bit 3 2 1 0 NA ($153) CC_NUMBER3 CC_NUMBER2 CC_NUMBER1 CC_NUMBER0 CC_CTRL_0 Read/Write RW RW RW RW Initial Value 0 0 0 0 This register controls the frequency of the transceiver PLL. CC_CTRL_0 and CC_CTRL_1 form a 16 bit register. Changed CC_CTRL_1 bits are updated only when writing to CC_CTRL_0. • Bit 7:0 – CC_NUMBER7:0 - Channel Number These register bits set the channel number 9.12.32 CC_CTRL_1 – Channel Control Register 1 Bit 7 6 5 4 3 2 1 0 NA ($154) CC_BAND3 CC_BAND2 CC_BAND1 CC_BAND0 CC_CTRL_1 Read/Write RW RW RW RW Initial Value 0 0 0 0 This register controls the band of the transceiver PLL. CC_CTRL_0 and CC_CTRL_1 form a 16 bit register. Changed CC_BAND bits are updated only when writing to register CC_CTRL_0. • Bit 3:0 – CC_BAND3:0 - Channel Band These register bits set the channel band 9.12.33 TRX_RPC – Transceiver Reduced Power Consumption Control Bit 7 6 5 4 NA ($156) RX_RPC_CTRL1 RX_RPC_CTRL0 RX_RPC_EN PDT_RPC_EN TRX_RPC Read/Write RW RW RW RW Initial Value 1 1 0 0 Bit 3 2 1 0 NA ($156) PLL_RPC_EN Res0 IPAN_RPC_EN XAH_RPC_EN TRX_RPC Read/Write RW R RW RW Initial Value 0 0 0 1 The TRX_RPC register controls the Reduced Power Consumption / Smart Receiving Modes. • Bit 7:6 – RX_RPC_CTRL1:0 - Smart Receiving Mode Timing ATmega256/128/64RFR2 136 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 The register bits RX_RPC_CTRL[1:0] are used for timing calculation within smart receiving mode. Table 9-69 RX_RPC_CTRL Register Bits Register Bits Value Description RX_RPC_CTRL1:0 0 Activates minimum power saving behaviour for smart receiving mode 1 Reserved 2 Reserved 3 Activates maximum power saving behaviour for smart receiving mode • Bit 5 – RX_RPC_EN - R e ceiver Smart Receiving Mode Enable If the bit RX_RPC_EN is set, the receiver is periodically in power-save during all RX states to reduce the current consumption while listening for incoming signals. Note: this feature causes a sensitivity loss of approximately 2 dB. • Bit 4 – PDT_RPC_EN - Smart Receiving Mode Reduced Sensitivity Enable If the bit PDT_RPC_EN is set, the RX sensitivity is reduced and the current consumption is decreased. Note that together with this setting the value of the register RX_PDT_LEVEL should be adapted. • Bit 3 – PLL_RPC_EN - PLL Smart Receiving Mode Enable If bit PLL_RPC_EN is set, the PLL is in power-save during the transceiver states PLL_ON or TX_ARET_ON while no frame transmission has been initiated. • Bit 2 – Res0 - Reserved • Bit 1 – IPAN_RPC_EN - Smart Receiving Mode IPAN Handling Enable If the bit IPAN_RPC_EN is set, RPC for IPAN is enabled. This causes a transceiver power-save while receiving a frame with matching PAN but not matching address. Note that an enabled RX override feature will automatically disable the IPAN_RPC_EN function. • Bit 0 – XAH_RPC_EN - Smart Receiving in Extended Operating Modes Enable If the bit XAH_RPC_EN is set, RPC functionality for the Extended Operating Mode is enabled. This reduces the PLL power consumption during the CSMA/CA back-off time, a transmit/receive turnaround in TX_ARET state or an active frame protection (RX_SAFE_MODE). 9.12.34 PART_NUM – Device Identification Register (Part Number) Bit 7 6 5 4 3 2 1 0 NA ($15C) PART_NUM7:0 PART_NUM Read/Write R R R R R R R R Initial Value 1 0 0 1 0 1 0 0 This register contains the part number of the device. • Bit 7:0 – PART_NUM7:0 - Part Number These bits decode the part number of the device according to the following table. 137 8393C-MCU Wireless-09/14

Table 9-70 PART_NUM Register Bits Register Bits Value Description PART_NUM7:0 0x94 RFR2 family 9.12.35 VERSION_NUM – Device Identification Register (Version Number) Bit 7 6 5 4 3 2 1 0 NA ($15D) VERSION_NUM7:0 VERSION_NUM Read/Write R R R R R R R R Initial Value 0 0 0 0 0 0 1 1 This register contains the version number of the device. The device identification overwrites the Reset value. • Bit 7:0 – VERSION_NUM7:0 - Version Number These bits decode the versi on number of the device according to the following table. Table 9-71 VERSION_NUM Register Bits Register Bits Value Description VERSION_NUM7:0 12 Revision A 1 Revision B 3 Revision C 4 Revision D 9.12.36 MAN_ID_0 – Device Identification Register (Manufacture ID Low Byte) Bit 7 6 5 4 3 2 1 0 NA ($15E) MAN_ID_07:00 MAN_ID_0 Read/Write R R R R R R R R Initial Value 0 0 0 1 1 1 1 1 Bits [7:0] of the 32-bit JEDEC manufacturer ID are stored in this register. Bits [15:8] are stored in register MAN_ID_1. The highest 16 bits of the JEDEC ID are not stored in registers. • Bit 7:0 – MAN_ID_07:00 - Manufacturer ID (Low Byte) These bits contain bits [7:0] of the 32-bit JEDEC manufacturer ID. 9.12.37 MAN_ID_1 – Device Identification Register (Manufacture ID High Byte) Bit 7 6 5 4 3 2 1 0 NA ($15F) MAN_ID_17:10 MAN_ID_1 Read/Write R R R R R R R R Initial Value 0 0 0 0 0 0 0 0 Bits [15:8] of the 32-bit JEDEC manufacturer ID are stored in this register. Bits [7:0] are stored in register MAN_ID_0. The highest 16 bits of the JEDEC ID are not stored in registers. ATmega256/128/64RFR2 138 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 • Bit 7:0 – MAN_ID_17:10 - Manufacturer ID (High Byte) These bits contain bits [15:8] of the 32-bit JEDEC manufacturer ID. Table 9-72 MAN_ID_ Register Bits Register Bits Value Description MAN_ID_17:10 0x00 Atmel JEDEC manufacturer ID, bits [15:8] of 32 bit manufacturer ID: 00 00 00 1F 9.12.38 SHORT_ADDR_0 – Transceiver MAC Short Address Register (Low Byte) Bit 7 6 5 4 3 2 1 0 NA ($160) SHORT_ADDR_07:00 SHORT_ADDR_0 Read/Write RW RW RW RW RW RW RW RW Initial Value 1 1 1 1 1 1 1 1 This register contains the lower 8 bits of the MAC short address for Frame Filter address recognition. • Bit 7:0 – SHORT_ADDR_07:00 - MAC Short Address These bits contain the bits [7:0] of the MAC short address. 9.12.39 SHORT_ADDR_1 – Transceiver MAC Short Address Register (High Byte) Bit 7 6 5 4 3 2 1 0 NA ($161) SHORT_ADDR_17:10 SHORT_ADDR_1 Read/Write RW RW RW RW RW RW RW RW Initial Value 1 1 1 1 1 1 1 1 This register contains the upper 8 bits of the MAC short address for Frame Filter address recognition. • Bit 7:0 – SHORT_ADDR_17:10 - MAC Short Address These bits contain the bits [15:8] of the MAC short address. 9.12.40 PAN_ID_0 – Transceiver Personal Area Network ID Register (Low Byte) Bit 7 6 5 4 3 2 1 0 NA ($162) PAN_ID_07:00 PAN_ID_0 Read/Write RW RW RW RW RW RW RW RW Initial Value 1 1 1 1 1 1 1 1 This register contains the lower 8 bits of the MAC PAN ID for Frame Filter address recognition. • Bit 7:0 – PAN_ID_07:00 - MAC Personal Area Network ID These bits contain the bits [7:0] of the MAC PAN ID. 139 8393C-MCU Wireless-09/14

9.12.41 PAN_ID_1 – Transceiver Personal Area Network ID Register (High Byte) Bit 7 6 5 4 3 2 1 0 NA ($163) PAN_ID_17:10 PAN_ID_1 Read/Write RW RW RW RW RW RW RW RW Initial Value 1 1 1 1 1 1 1 1 This register contains the upper 8 bits of the MAC PAN ID for Frame Filter address recognition. • Bit 7:0 – PAN_ID_17:10 - MAC Personal Area Network ID These bits contain the bits [15:8] of the MAC PAN ID. 9.12.42 IEEE_ADDR_0 – Transceiver MAC IEEE Address Register 0 Bit 7 6 5 4 3 2 1 0 NA ($164) IEEE_ADDR_07:00 IEEE_ADDR_0 Read/Write RW RW RW RW RW RW RW RW Initial Value 0 0 0 0 0 0 0 0 This register contains the bits [7:0] of the MAC IEEE address for Frame Filter address recognition. • Bit 7:0 – IEEE_ADDR_07:00 - MAC IEEE Address These bits map to the bits [7:0] of the 64 bit MAC IEEE address. 9.12.43 IEEE_ADDR_1 – Transceiver MAC IEEE Address Register 1 Bit 7 6 5 4 3 2 1 0 NA ($165) IEEE_ADDR_17:10 IEEE_ADDR_1 Read/Write RW RW RW RW RW RW RW RW Initial Value 0 0 0 0 0 0 0 0 This register contains the bits [15:8] of the MAC IEEE address for Frame Filter address recognition. • Bit 7:0 – IEEE_ADDR_17:10 - MAC IEEE Address These bits map to the bits [15:8] of the 64 bit MAC IEEE address. 9.12.44 IEEE_ADDR_2 – Transceiver MAC IEEE Address R egister 2 Bit 7 6 5 4 3 2 1 0 NA ($166) IEEE_ADDR_27:20 IEEE_ADDR_2 Read/Write RW RW RW RW RW RW RW RW Initial Value 0 0 0 0 0 0 0 0 This register contains the bits [23:16] of the MAC IEEE address for Frame Filter address recognition. ATmega256/128/64RFR2 140 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 • Bit 7:0 – IEEE_ADDR_27:20 - MAC IEEE Address These bits map to the bits [23:16] of the 64 bit MAC IEEE address. 9.12.45 IEEE_ADDR_3 – Transceiver MAC IEEE Address Register 3 Bit 7 6 5 4 3 2 1 0 NA ($167) IEEE_ADDR_37:30 IEEE_ADDR_3 Read/Write RW RW RW RW RW RW RW RW Initial Value 0 0 0 0 0 0 0 0 This register contains the bits [31:24] of the MAC IEEE address for Frame Filter address recognition. • Bit 7:0 – IEEE_ADDR_37:30 - MAC IEEE Address These bits map to the bits [31:24] of the 64 bit MAC IEEE address. 9.12.46 IEEE_ADDR_4 – Transceiver MAC IEEE Address Register 4 Bit 7 6 5 4 3 2 1 0 NA ($168) IEEE_ADDR_47:40 IEEE_ADDR_4 Read/Write RW RW RW RW RW RW RW RW Initial Value 0 0 0 0 0 0 0 0 This register contains the bits [39:32] of the MAC IEEE address for Frame Filter address recognition. • Bit 7:0 – IEEE_ADDR_47:40 - MAC IEEE Address These bits map to the bits [3 9:32] of the 64 bit MAC IEEE address. 9.12.47 IEEE_ADDR_5 – Transceiver MAC IEEE Address Register 5 Bit 7 6 5 4 3 2 1 0 NA ($169) IEEE_ADDR_57:50 IEEE_ADDR_5 Read/Write RW RW RW RW RW RW RW RW Initial Value 0 0 0 0 0 0 0 0 This register contains the bits [47:40] of the MAC IEEE address for Frame Filter address recognition. • Bit 7:0 – IEEE_ADDR_5 7:50 - MAC IEEE Address These bits map to the bits [47:40] of the 64 bit MAC IEEE address. 141 8393C-MCU Wireless-09/14

9.12.48 IEEE_ADDR_6 – Transceiver MAC IEEE Address Register 6 Bit 7 6 5 4 3 2 1 0 NA ($16A) IEEE_ADDR_67:60 IEEE_ADDR_6 Read/Write RW RW RW RW RW RW RW RW Initial Value 0 0 0 0 0 0 0 0 This register contains the bits [55:48] of the MAC IEEE address for Frame Filter address recognition. • Bit 7:0 – IEEE_ADDR_67:60 - MAC IEEE Address These bits map to the bits [55:48] of the 64 bit MAC IEEE address. 9.12.49 IEEE_ADDR_7 – Transceiver MAC IEEE Address Register 7 Bit 7 6 5 4 3 2 1 0 NA ($16B) IEEE_ADDR_77:70 IEEE_ADDR_7 Read/Write RW RW RW RW RW RW RW RW Initial Value 0 0 0 0 0 0 0 0 This register contains the bits [63:56] of the MAC IEEE address for Frame Filter address recognition. • Bit 7:0 – IEEE_ADDR_77:70 - MAC IEEE Address These bits map to the bits [63:56] of the 64 bit MAC IEEE address. 9.12.50 XAH_CTRL_0 – Transceiver Extended Operating Mode Control Register Bit 7 6 NA ($16C) MAX_FRAME_RETRIES3 MAX_FRAME_RETRIES2 XAH_CTRL_0 Read/Write RW RW Initial Value 0 0 Bit 5 4 NA ($16C) MAX_FRAME_RETRIES1 MAX_FRAME_RETRIES0 XAH_CTRL_0 Read/Write RW RW Initial Value 1 1 Bit 3 2 NA ($16C) MAX_CSMA_RETRIES2 MAX_CSMA_RETRIES1 XAH_CTRL_0 Read/Write RW RW Initial Value 1 0 Bit 1 0 NA ($16C) MAX_CSMA_RETRIES0 SLOTTED_OPERATION XAH_CTRL_0 Read/Write RW RW Initial Value 0 0 This register is used to control various settings of the Extended Operating Mode. ATmega256/128/64RFR2 142 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 • Bit 7:4 – MAX_FRAME_RETRIES3:0 - Maximum Number of Frame Re- transmission Attempts The setting of MAX_FRAME_RETRIES in TX_ARET mode specifies the number of attempts to retransmit a frame when it was not acknowledged by the recipient. The transaction gets canceled if the number of attempts exceeds MAX_FRAME_RETRIES. Table 9-73 MAX_FRAME_RETRIES Register Bits Register Bits Value Description MAX_FRAME_RETRIES3:0 0x0 Retransmission of frame is not attempted. 0x1 Retransmission of frame is attempted once. 0x2 ... 0xF Retransmission of frame is attempted 15 times. • Bit 3:1 – MAX_CSMA_RETRIES2:0 - Maximum Number of CSMA-CA Procedure Repetition Attempts MAX_CSMA_RETRIES specifies the number of retries in TX_ARET mode to repeat the CSMA-CA procedure before the transaction gets canceled. According to IEEE 802.15.4 the valid range of MAX_CSMA_RETRIES is 0 to 5. A value of MAX_CSMA_RETRIES = 7 initiates an immediate frame transmission without performing CSMA-CA. This may especially be required for slotted acknowledgment operation. MAX_CSMA_RETRIES = 6 is reserved. Table 9-74 MAX_CSMA_RETRIES Register Bits Register Bits Value Description MAX_CSMA_RETRIES2:0 0x0 No repetition of CSMA-CA procedure 0x1 One repetition of CSMA-CA procedure 0x2 ... 0x5 Five repetitions (highest IEEE 802.15.4 compliant value) 0x6 Reserved 0x7 Immediate frame re-transmission without performing CSMA-CA • Bit 0 – SLOTTED_OPERATION - Set Slotted Acknowledgment When using RX_AACK mode in networks operating in beacon or slotted mode according to IEEE 802.15.4-2006, chapter 5.5.1 the register bit SLOTTED_OPERATION indicates that acknowledgment frames are to be sent on back- off slot boundaries (slott ed acknowledgment). If this register bit is set the acknowledgment frame transmission has to be initiated by the application software using bit SLPTR of register TRXPR. This waiting state is signaled in sub register TRAC_STATUS of register TRX_STATE with value SUCCESS_WAIT_FOR_ACK. Table 9-75 SLOTTED_OPERATION Register Bits Register Bits Value Description SLOTTED_OPERATION 0 The radio transceiver operates in unslotted mode. An acknowledgment frame is automatically sent if requested. 1 The transmission of an acknowledgment frame has to be controlled by the microcontroller. 143 8393C-MCU Wireless-09/14

9.12.51 CSMA_SEED_0 – Transceiver CSMA-CA Random Number Generator Seed Register Bit 7 6 5 4 3 2 1 0 NA ($16D) CSMA_SEED_07:00 CSMA_SEED_0 Read/Write RW RW RW RW RW RW RW RW Initial Value 1 1 1 0 1 0 1 0 This register contains the lower 8 bits of the CSMA_SEED. The upper 3 bits are part of register CSMA_SEED_1. CSMA_SEED is the seed for the random number generation that determines the length of the back-off period in the CSMA-CA algorithm. It is recommended to initialize registers CSMA_SEED by random values. This can be done using the bits RND_VALUE of register PHY_RSSI. • Bit 7:0 – CSMA_SEED_07:00 - Seed Value for CSMA Random Number Generator These bits contain the bits [7:0] of the CSMA_SEED. 9.12.52 CSMA_SEED_1 – Transceiver Acknowledgment Frame Control Register 2 Bit 7 6 NA ($16E) AACK_FVN_MODE1 AACK_FVN_MODE0 CSMA_SEED_1 Read/Write RW RW Initial Value 0 1 Bit 5 4 NA ($16E) AACK_SET_PD AACK_DIS_ACK CSMA_SEED_1 Read/Write RW RW Initial Value 0 0 Bit 3 2 NA ($16E) AACK_I_AM_COORD CSMA_SEED_12 CSMA_SEED_1 Read/Write RW RW Initial Value 0 0 Bit 1 0 NA ($16E) CSMA_SEED_11 CSMA_SEED_10 CSMA_SEED_1 Read/Write RW RW Initial Value 1 0 This register is a control register for RX_AACK and contains a part of the CSMA_SEED for the CSMA-CA algorithm. • Bit 7:6 – AACK_FVN_MODE1:0 - Acknowledgment Frame Filter Mode The frame control field of t he MAC header (MHR) contains a frame version subfield. The setting of AACK_FVN_MODE specifies the frame filtering behavior of the radio transceiver. According to the content of these register bits the radio transceiver passes frames with a specific frame version number, number group or independent of the frame version number. Thus the register bits AACK_FVN_MODE define the maximum acceptable frame version. Received frames with a higher frame version number than configured do not pass the address filter and are not acknowledged. ATmega256/128/64RFR2 144 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 Table 9-76 AACK_FVN_MODE Register Bits Register Bits Value Description AACK_FVN_MODE1:0 0 Acknowledge frames with version number 0 1 Acknowledge frames with version number 0 or 1 2 Acknowledge frames with version number 0 or 1 or 2 3 Acknowledge frames independent of frame version number • Bit 5 – AACK_SET_PD - Set Frame Pending Sub-field The content of AACK_SET_PD bit is copied into the frame pending subfield of the acknowledgment frame if the acknowledgment is the answer to a data request MAC command frame. If in addition the bits AACK_FVN_MODE of this register are configured to accept frames with a frame version other than 0 or 1, the content of register bit AACK_SET_PD is also copied into the frame pending subfield of the acknowledgment frame for any MAC command frame with a frame version of 2 or 3 that have the security enabled s u bfield set to 1. This is done in the assumption that a future version of the IEEE 802.15.4 standard might change the length or structure of the auxiliary security header, so that it is not possible to safely detect whether the MAC command frame is actually a data request command or not. • Bit 4 – AACK_DIS_ACK - Disable Acknowledgment Frame Transmission If this bit is set no acknowledgment frames are transmitted in RX_AACK Extended Operating Mode even if requested. • Bit 3 – AACK_I_AM_CO ORD - Set Personal Area Network Coordinator This register bit has to be set if the node is a PAN coordinator. It is used for address filtering in RX_AACK. • Bit 2:0 – CSMA_SEED_12:10 - Seed Value for CSMA Random Number Generator These bits contain the bits [10:8] of the CSMA_SEED. The lower part is defined in register CSMA_SEED_0. See register CSMA_SEED_0 for details. 9.12.53 CSMA_BE – Transceiver CSMA-CA Back-off Exponent Control Register Bit 7 6 5 4 NA ($16F) MAX_BE3 MAX_BE2 MAX_BE1 MAX_BE0 CSMA_BE Read/Write RW RW RW RW Initial Value 0 1 0 1 Bit 3 2 1 0 NA ($16F) MIN_BE3 MIN_BE2 MIN_BE1 MIN_BE0 CSMA_BE Read/Write RW RW RW RW Initial Value 0 0 1 1 This register controls the back-off exponent for the CSMA-CA procedure. • Bit 7:4 – MAX_BE3:0 - Maximum Back-off Exponent These register bits define the maximum back-off exponent used in the CSMA-CA algorithm to generate a pseudo random number for back off the CCA. For details refer to IEEE 802.15.4-2006, section 7.5.1.4. Valid values are 3 to 8. 145 8393C-MCU Wireless-09/14

Table 9-77 MAX_BE Register Bits Register Bits Value Description MAX_BE3:0 1 This value is not valid for the maximum back-off exponent. 2 This value is not valid for the maximum back-off exponent. 3 Minimum, IEEE compliant value for the maximum back-off exponent. 4 ... 8 Maximum, IEEE compliant value for the maximum back-off exponent. • Bit 3:0 – MIN_BE3:0 - Minimum Back-off Exponent These register bits define the minimum back-off exponent used in the CSMA-CA algorithm to generate a pseudo random number for back off the CCA. For details refer to IEEE 802.15.4-2006, section 7.5.1.4. Valid values are MAX_BE, MAX_BE-1), ..., 0. If MIN_BE = 0 and MAX_BE = 0 the CCA back off period is always set to 0. Table 9-78 MIN_BE Register Bits Register Bits Value Description MIN_BE3:0 0 Minimum value of minimum back-off exponent. 1 ... 8 Maximum value of minimum back-off exponent. MIN_BE must be smaller or equal to MAX_BE. 9.12.54 MAFCR0 – Multiple Address Filter Configuration Register 0 Bit 7 6 5 4 3 2 1 0 NA ($10C) Res3 Res2 Res1 Res0 MAF3EN MAF2EN MAF1EN MAF0EN MAFCR0 Read/Write R R R R RW RW RW RW Initial Value 0 0 0 0 0 0 0 1 With this register, the four independent Address Filter can be enabled or disabled. • Bit 7:4 – Res3:0 - Reserved Bit These bits are reserved for future use. The result of a read access is undefined. The register bits must always be written with the reset value. • Bit 3 – MAF3EN - Multiple Address Filter 3 Enable This bit enables the Multiple Address Filter 3. If the bit is set and the corresponding Short Address and PAN ID Register is configured, an address match is indicated in the IRQ_STATUS1 register and an interrupt occurs if the interrupt enable flag is set in the IRQ_MASK register. • Bit 2 – MAF2EN - Multiple Address Filter 2 Enable This bit enables the Multiple Address Filter 2. If the bit is set and the corresponding Short Address and PAN ID Register is configured, an address match is indicated in the IRQ_STATUS1 register and an interrupt occurs if the interrupt enable flag is set in the IRQ_MASK register. ATmega256/128/64RFR2 146 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 • Bit 1 – MAF1EN - Multiple Address Filter 1 Enable This bit enables the Multiple Address Filter 1. If the bit is set and the corresponding Short Address and PAN ID Register is configured, an address match is indicated in the IRQ_STATUS1 register and an interrupt occurs if the interrupt enable flag is set in the IRQ_MASK register. • Bit 0 – MAF0EN - Multiple Address Filter 0 Enable This bit enables the Multiple Address Filter 0. If the bit is set and the corresponding Short Address and PAN ID Register is configured, an address match is indicated in the IRQ_STATUS1 register and an interrupt occurs if the interrupt enable flag is set in the IRQ_MASK register. 9.12.55 MAFCR1 – Multiple Address Filter Configuration Register 1 Bit 7 6 NA ($10D) AACK_3_SET_PD AACK_3_I_AM_COORD MAFCR1 Read/Write RW RW Initial Value 0 0 Bit 5 4 NA ($10D) AACK_2_SET_PD AACK_2_I_AM_COORD MAFCR1 Read/Write RW RW Initial Value 0 0 Bit 3 2 NA ($10D) AACK_1_SE T_PD AACK_1_I_AM_COORD MAFCR1 Read/Write RW RW Initial Value 0 0 Bit 1 0 NA ($10D) AACK_0_SET_PD AACK_0_I_AM_COORD MAFCR1 Read/Write RW RW Initial Value 0 0 With this register, the behavior of the four independent Address Filters can be configured. • Bit 7 – AACK_3_SET_PD - Set Data Pending bit for address filter 3. Set the data pending subfield in Frame Control Field (FCF) for automatic frame acknowledge. The content of AACK_SET_PD3 bit is copied into the frame pending subfield of the acknowledgment frame if the ACK is the answer to a data request MAC command frame. • Bit 6 – AACK_3_I_AM_COORD - Enable PAN Coordinator mode for address filter 3. This register bit has to be set if the node is a PAN coordinator for address filter 3. It is used for frame filtering in RX_AACK. If set, the device acts as a PAN coordinator within the filtered network, i.e. it responds to a null address. If the devices handles multiple networks, it can operate as coordinator for one network and as a end node for the other network simultaneously. • Bit 5 – AACK_2_SET_PD - Set Data Pending bit for address filter 2. Set the data pending subfield in Frame Control Field (FCF) for automatic frame acknowledge. The content of AACK_SET_PD2 bit is copied into the frame pending 147 8393C-MCU Wireless-09/14

subfield of the acknowledgment frame if the ACK is the answer to a data request MAC command frame. • Bit 4 – AACK_2_I_AM_COORD - Enable PAN Coordinator mode for address filter 2. This register bit has to be set if the node is a PAN coordinator for address filter 2. It is used for frame filtering in RX_AACK. If set, the device acts as a PAN coordinator within the filtered network, i.e. it responds to a null address. If the devices handles multiple networks, it can operate as coordinator for one network and as a end node for the other network simultaneously. • Bit 3 – AACK_1_SET_PD - Set Data Pending bit for address filter 1. Set the data pending subfield in Frame Control Field (FCF) for automatic frame acknowledge. The content of AACK_SET_PD1 bit is copied into the frame pending subfield of the acknowledgment frame if the ACK is the answer to a data request MAC command frame. • Bit 2 – AACK_1_I_AM_COORD - Enable PAN Coordinator mode for address filter 1. This register bit has to be set if the node is a PAN coordinator for address filter 1. It is used for frame filtering in RX_AACK. If set, the device acts as a PAN coordinator within the filtered network, i.e. it responds to a null address. If the devices handles multiple networks, it can operate as coordinator for one network and as a end node for the other network simultaneously. • Bit 1 – AACK_0_SET_PD - Set Data Pending bit for address filter 0. Set the data pending subfield in Frame Control Field (FCF) for automatic frame acknowledge. The content of AACK_SET_PD0 bit is copied into the frame pending subfield of the acknowledgment frame if the ACK is the answer to a data request MAC command frame. • Bit 0 – AACK_0_I_AM_COORD - Enable PAN Coordinator mode for address filter 0. This register bit has to be set if the node is a PAN coordinator for address filter 0. It is used for frame filtering in RX_AACK. If set, the device acts as a PAN coordinator within the filtered network, i.e. it responds to a null address. If the devices handles multiple networks, it can operate as coordinator for one network and as a end node for the other network simultaneously. 9.12.56 MAFPA0H – Transceiver Personal Area Network ID Register for Frame Filter 0 (High Byte) Bit 7 6 5 4 3 2 1 0 NA ($111) MAFPA0H7:0 MAFPA0H Read/Write RW RW RW RW RW RW RW RW Initial Value 1 1 1 1 1 1 1 1 This register contains the upper 8 bits of the MAC PAN ID for Frame Filter 0 address recognition. • Bit 7:0 – MAFPA0H7:0 - MAC Personal Area Network ID high Byte for Frame Filter 0 These bits contain the bits [15:8] of the MAC PAN ID for Frame Filter 0. ATmega256/128/64RFR2 148 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 9.12.57 MAFPA0L – Transceiver Personal Area Network ID Register for Frame Filter 0 (Low Byte) Bit 7 6 5 4 3 2 1 0 NA ($110) MAFPA0L7:0 MAFPA0L Read/Write RW RW RW RW RW RW RW RW Initial Value 1 1 1 1 1 1 1 1 This register contains the lower 8 bits of the MAC PAN ID for Frame Filter 0 address recognition. • Bit 7:0 – MAFPA0L7:0 - MAC Personal Area Network ID low Byte for Frame Filter 0 These bits contain the bits [7:0] of the MAC PAN ID for Frame Filter 0. 9.12.58 MAFPA1H – Transceiver Personal Area Network ID Register for Frame Filter 1 (High Byte) Bit 7 6 5 4 3 2 1 0 NA ($115) MAFPA1H7:0 MAFPA1H Read/Write RW RW RW RW RW RW RW RW Initial Value 1 1 1 1 1 1 1 1 This register contains the upper 8 bits of the MAC PAN ID for Frame Filter 1 address recognition. • Bit 7:0 – MAFPA1H7:0 - MAC Personal Area Network ID high Byte for Frame Filter 1 These bits contain the bits [15:8] of the MAC PAN ID for Frame Filter 1. 9.12.59 MAFPA1L – Transceiver Personal Area Network ID Register for Frame Filter 1 (Low Byte) Bit 7 6 5 4 3 2 1 0 NA ($114) MAFPA1L7:0 MAFPA1L Read/Write RW RW RW RW RW RW RW RW Initial Value 1 1 1 1 1 1 1 1 This register contains the lo wer 8 bits of the MAC PAN ID for Frame Filter 1 address recognition. • Bit 7:0 – MAFPA1L7:0 - MAC Personal Area Network ID low Byte for Frame Filter 1 These bits contain the bits [7:0] of the MAC PAN ID for Frame Filter 1. 9.12.60 MAFPA2H – Transceiver Personal Area Network ID Register for Frame Filter 2 (High Byte) Bit 7 6 5 4 3 2 1 0 NA ($119) MAFPA2H7:0 MAFPA2H Read/Write RW RW RW RW RW RW RW RW Initial Value 1 1 1 1 1 1 1 1 149 8393C-MCU Wireless-09/14

This register contains the upper 8 bits of the MAC PAN ID for Frame Filter 2 address recognition. • Bit 7:0 – MAFPA2H7:0 - MAC Personal Area Network ID high Byte for Frame Filter 2 These bits contain the bits [15:8] of the MAC PAN ID for Frame Filter 2. 9.12.61 MAFPA2L – Transceiver Personal Area Network ID Register for Frame Filter 2 (Low Byte) Bit 7 6 5 4 3 2 1 0 NA ($118) MAFPA2L7:0 MAFPA2L Read/Write RW RW RW RW RW RW RW RW Initial Value 1 1 1 1 1 1 1 1 This register contains the l ower 8 bits of the MAC PAN ID for Frame Filter 2 address recognition. • Bit 7:0 – MAFPA2L7:0 - MAC Personal Area Network ID low Byte for Frame Filter 2 These bits contain the bits [7:0] of the MAC PAN ID for Frame Filter 2. 9.12.62 MAFPA3H – Transceiver Personal Area Network ID Register for Frame Filter 3 (High Byte) Bit 7 6 5 4 3 2 1 0 NA ($11D) MAFPA3H7:0 MAFPA3H Read/Write RW RW RW RW RW RW RW RW Initial Value 1 1 1 1 1 1 1 1 This register contains the upper 8 bits of the MAC PAN ID for Frame Filter 3 address recognition. • Bit 7:0 – MAFPA3H7:0 - MAC Personal Area Network ID high Byte for Frame Filter 3 These bits contain the bits [15:8] of the MAC PAN ID for Frame Filter 3. 9.12.63 MAFPA3L – Transceiver Personal Area Network ID Register for Frame Filter 3 (Low Byte) Bit 7 6 5 4 3 2 1 0 NA ($11C) MAFPA3L7:0 MAFPA3L Read/Write RW RW RW RW RW RW RW RW Initial Value 1 1 1 1 1 1 1 1 This register contains the lower 8 bits of the MAC PAN ID for Frame Filter 3 address recognition. • Bit 7:0 – MAFPA3L7:0 - MAC Personal Area Network ID low Byte for Frame Filter 3 ATmega256/128/64RFR2 150 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 These bits contain the bits [7:0] of the MAC PAN ID for Frame Filter 3. 9.12.64 MAFSA0H – Transceiver MAC Short Address Register for Frame Filter 0 (High Byte) Bit 7 6 5 4 3 2 1 0 NA ($10F) MAFSA0H7:0 MAFSA0H Read/Write RW RW RW RW RW RW RW RW Initial Value 1 1 1 1 1 1 1 1 This register contains the upper 8 bits of the MAC short address for Frame Filter 0 address recognition. • Bit 7:0 – MAFSA0H7:0 - MAC Short Address high Byte for Frame Filter 0 These bits contain the bits [15:8] of the MAC short address for Frame Filter 0. 9.12.65 MAFSA0L – Transceiver MAC Short Address Register for Frame Filter 0 (Low Byte) Bit 7 6 5 4 3 2 1 0 NA ($10E) MAFSA0L7:0 MAFSA0L Read/Write RW RW RW RW RW RW RW RW Initial Value 1 1 1 1 1 1 1 1 This register contains the lower 8 bits of the MAC short address for Frame Filter 0 address recognition. • Bit 7:0 – MAFSA0L7:0 - MAC Short Address low Byte for Frame Filter 0 These bits contain the bits [7:0] of the MAC short address for Frame Filter 0. 9.12.66 MAFSA1H – Transceiver MAC Short Address Register for Frame Filter 1 (High Byte) Bit 7 6 5 4 3 2 1 0 NA ($113) MAFSA1H7:0 MAFSA1H Read/Write RW RW RW RW RW RW RW RW Initial Value 1 1 1 1 1 1 1 1 This register contains the upper 8 bits of the MAC short address for Frame Filter 1 address recognition. • Bit 7:0 – MAFSA1H7:0 - MAC Short Address high Byte for Frame Filter 1 These bits contain the bits [1 5:8] of the MAC short address for Frame Filter 1. 9.12.67 MAFSA1L – Transceiver MAC Short Address Register for Frame Filter 1 (Low Byte) Bit 7 6 5 4 3 2 1 0 NA ($112) MAFSA1L7:0 MAFSA1L Read/Write RW RW RW RW RW RW RW RW Initial Value 1 1 1 1 1 1 1 1 151 8393C-MCU Wireless-09/14

This register contains the lower 8 bits of the MAC short address for Frame Filter 1 address recognition. • Bit 7:0 – MAFSA1L7:0 - MAC Short Address low Byte for Frame Filter 1 These bits contain the bits [7:0] of the MAC short address for Frame Filter 1. 9.12.68 MAFSA2H – Transceiver MAC Short Address Register for Frame Filter 2 (High Byte) Bit 7 6 5 4 3 2 1 0 NA ($117) MAFSA2H7:0 MAFSA2H Read/Write RW RW RW RW RW RW RW RW Initial Value 1 1 1 1 1 1 1 1 This register contains the upper 8 bits of the MAC short address for Frame Filter 2 address recognition. • Bit 7:0 – MAFSA2H7:0 - MAC Short Address high Byte for Frame Filter 2 These bits contain the bits [15:8] of the MAC short address for Frame Filter 2. 9.12.69 MAFSA2L – Transceiver MAC Short Address Register for Frame Filter 2 (Low Byte) Bit 7 6 5 4 3 2 1 0 NA ($116) MAFSA2L7:0 MAFSA2L Read/Write RW RW RW RW RW RW RW RW Initial Value 1 1 1 1 1 1 1 1 This register contains the lower 8 bits of the MAC short address for Frame Filter 2 address recognition. • Bit 7:0 – MAFSA2L7:0 - MAC Short Address low Byte for Frame Filter 2 These bits contain the bits [7:0] of the MAC short address for Frame Filter 2. 9.12.70 MAFSA3H – Transceiver MAC Short Address Register for Frame Filter 3 (High Byte) Bit 7 6 5 4 3 2 1 0 NA ($11B) MAFSA3H7:0 MAFSA3H Read/Write RW RW RW RW RW RW RW RW Initial Value 1 1 1 1 1 1 1 1 This register contains the upper 8 bits of the MAC short address for Frame Filter 3 address recognition. • Bit 7:0 – MAFSA3H7:0 - MAC Short Address high Byte for Frame Filter 3 These bits contain the bits [15:8] of the MAC short address for Frame Filter 3. ATmega256/128/64RFR2 152 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 9.12.71 MAFSA3L – Transceiver MAC Short Address Register for Frame Filter 3 (Low Byte) Bit 7 6 5 4 3 2 1 0 NA ($11A) MAFSA3L7:0 MAFSA3L Read/Write RW RW RW RW RW RW RW RW Initial Value 1 1 1 1 1 1 1 1 This register contains the lower 8 bits of the MAC short address for Frame Filter 3 address recognition. • Bit 7:0 – MAFSA3L7:0 - MAC Short Address low Byte for Frame Filter 3 These bits contain the bits [7:0] of the MAC short address for Frame Filter 3. 9.12.72 TST_CTRL_DIGI – Transceiver Digital Test Control Register Bit 7 6 NA ($176) TST_CTRL_DIG_7 TST_CTRL_DIG_6 TST_CTRL_DIGI Read/Write RW RW Initial Value 0 0 Bit 5 4 NA ($176) TST_CTRL_DIG_5 TST_CTRL_DIG_4 TST_CTRL_DIGI Read/Write RW RW Initial Value 0 0 Bit 3 2 NA ($176) TST_CTRL_DIG3 TST_CTRL_DIG2 TST_CTRL_DIGI Read/Write RW RW Initial Value 0 0 Bit 1 0 NA ($176) TST_CTRL_DIG1 TST_CTRL_DIG0 TST_CTRL_DIGI Read/Write RW RW Initial Value 0 0 This register takes part in the activation sequence of the continuous transmission test mode. Other functionality of this register is reserved for internal use. • Bit 7 – TST_CTRL_DIG_ 7 - Disable Receiver Baseband Frequency Synthesis This bit is reserved for internal use. It is used to switch the frequency synthesis of the receiver baseband path. A value of 0 switches the synthesis on. A value of 1 switches the synthesis off. • Bit 6 – TST_CTRL_DIG_6 - Disable Receiver Baseband Drift Compensation This bit is reserved for internal use. It is used to switch the drift compensation of the receiver baseband path. A value of 0 switches the compensation on. A value of 1 switches the compensation off. • Bit 5 – TST_CTRL_DIG_5 - Enable Switch of Transceiver FIFO This bit is reserved for internal use. It is used enable a bypass for TX/RX FIFO buffers. A frame transmit will be write the TX FIFO data directly into the RX FIFO data field with the same address. This test can be used for the RX/TX FIFO test. A value of 0 disables the bypass. A value of 1 enables the bypass. 153 8393C-MCU Wireless-09/14

• Bit 4 – TST_CTRL_DIG_4 - Switch Receiver Input Data This bit is reserved for internal use. It is used to switch the input source from the receiver. A value of 0 selects the default RX ADC path. A value of 1 selects the DIG1 pin as a receive data source. • Bit 3:0 – TST_CTRL_DIG3:0 - Digital Test Controller Register This sub-register selects a test controller function. All values not listed int the following table are reserved for internal use. Table 9-79 TST_CTRL_DIG Register Bits Register Bits Value Description TST_CTRL_DIG3:0 0 NORMAL (no test is active) 15 TST_CONT_TX (continuous transmit) 9.12.73 TST_RX_LENGTH – Transceiver Received Frame Length Register Bit 7 6 5 4 NA ($17B) RX_LENGTH7 RX_LENGTH6 RX_LENGTH5 RX_LENGTH4 TST_RX_LENGTH Read/Write R R R R Initial Value 0 0 0 0 Bit 3 2 1 0 NA ($17B) RX_LENGTH3 RX_LENGTH2 RX_LENGTH1 RX_LENGTH0 TST_RX_LENGTH Read/Write R R R R Initial Value 0 0 0 0 This register contains the frame length information of a received frame. This information is not stored in the frame buffer. The frame length information is written to this register after the last received octet. • Bit 7:0 – RX_LENGTH7:0 - Received Frame Length These bits contain the length of the last received frame. 9.12.74 TST_AGC – Transceiver Automatic Gain Control and Test Register Bit 7 6 5 4 NA ($17C) Res1 Res0 AGC_HOLD_SEL AGC_RST TST_AGC Read/Write R R RW RW Initial Value 0 0 0 0 Bit 3 2 1 0 NA ($17C) AGC_OFF AGC_HOLD GC1 GC0 TST_AGC Read/Write RW RW RW RW Initial Value 0 0 0 0 It allows to modify the operation of the automatic gain control (AGC) circuit. A write access to this register (which will effect operation) reguires enable PMU_EN in the register TRX_CTRL_0. Otherwise reset values will be applied. • Bit 7:6 – Res1:0 - Reserved Bit ATmega256/128/64RFR2 154 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 This bit is reserved for future use. The result of a read access is undefined. The register bit must always be written with the reset value. • Bit 5 – AGC_HOLD_SEL - Enable AGC Hold Function A value of 1 will disable th e AGC hold function of the base-band processor. Normal operation of the AGC is achieved with a value of 0 (reset value) of this bit. • Bit 4 – AGC_RST - Reset AGC Gain A value of 1 will reset the AGC gain to the maximum value (GC=0). Normal operation (no reset) of the AGC is achieved with a value of 0 (reset value) of this bit. • Bit 3 – AGC_OFF - Disable AGC Regulation A value of 0 (reset value) enables the gain regulation of the AGC circuit. A value of 1 will disable the AGC regulat ion. The gain can then be set manually using the GC bits of this register. • Bit 2 – AGC_HOLD - Select AGC Hold Function A value of 0 (reset value) defines the free-running AGC mode. A value of 1 set the AGC hold mode. • Bit 1:0 – GC1:0 - Receiver Gain Control Word These bits contain the selected gain of the AGC circuit. The gain can be set manually with these bits if the bit AGC_OFF of this register is set to 1. Table 9-80 GC Register Bits Register Bits Value Description GC1:0 0 Maximum AGC gain 1 Medium gain 2 Minimum gain 3 Minimum gain 9.12.75 TST_SDM – Transceiver Sigma-Delta Modulator Control and Test Register Bit 7 6 5 4 3 2 1 0 NA ($17D) MOD_SEL MOD TX_RX TX_RX_SEL Resx3 Resx2 Resx1 Resx0 TST_SDM Read/Write RW RW RW RW RW RW RW RW Initial Value 0 0 0 0 0 0 0 0 It allows to modify the ope ration of the sigma-delta modulator (SDM) circuit. A write access to this register (which will affect operation) reguires enable PMU_EN in the register TRX_CTRL_0. Otherwise reset values will be applied. • Bit 7 – MOD_SEL - Select Modulation Data Source A value of 0 selects the TX RAM as the modulation data source. A value of 1 selects an input data stream according to the value of the MOD bit of this register. • Bit 6 – MOD - Select Modulation Signal Type This bit defines the modulation source of the sigma-delta modulator if bit MOD_SEL = 1 in this register. A value of MOD = 0 supplies continuous 0 chips. A value of MOD = 1 supplies continuous 1 chips. • Bit 5 – TX_RX - Switch between Transmit and Receive This bit allows to switch between transmit and receive operation of the sigma-delta modulator. A value of 0 selects the receive path. A value of 1 selects the transmit path. 155 8393C-MCU Wireless-09/14

• Bit 4 – TX_RX_SEL - Select Transmit/Receive Control Signal A value of 0 (reset value) selects the state-machine to control the sigma-delta modulator. A value of 1 selects this register as the control input. • Bit 3:0 – Resx3:0 - Res erved 9.12.76 TRXFBST – Start of frame buffer Bit 7 6 5 4 3 2 1 0 NA ($180) TRXFBST7:0 TRXFBST Read/Write RW RW RW RW RW RW RW RW Initial Value 0 0 0 0 0 0 0 0 This register is the first byte of the 128 byte long frame buffer of the radio transceiver. • Bit 7:0 – TRXFBST7:0 - Frame Buffer Start Byte 9.12.77 TRXFBEND – End of frame buffer Bit 7 6 5 4 3 2 1 0 NA ($1FF) TRXFBEND7:0 TRXFBEND Read/Write RW RW RW RW RW RW RW RW Initial Value 0 0 0 0 0 0 0 0 This register is the last byte of the 128 byte long frame buffer of the radio transceiver. • Bit 7:0 – TRXFBEND7:0 - Frame Buffer End Byte ATmega256/128/64RFR2 156 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 10 MAC Symbol Counter Figure 10-1. Symbol Counter Overview 32kHz RTC 16MHz xtal clock prescaler configuration register 320µs clock backoff slot select counter 32Bit Symbol Counter us B O R I/ compare V A unit 1 interrupt generation SFD Beacon compare timestamp timestamp unit 2 compare unit 3 10.1 Main Features The MAC symbol counter provides symbol timing information for IEEE 802.15.4 wireless networks. The counter time base can be derived from the 16 MHz crystal or the RTC (32.768 kHz crys tal on TOSC) during operation. In deep-sleep mode the counter operates from the RTC clock. The module provides the following features: • Backoff slot counter with interrupt generation • Counter clock source selection between XTAL1 (16 MHz) and TOSC1 (RTC) • Automatic RTC clock selection for sleep mode operation and automatic fallback • 3 independent compare units with relative and absolute compare mode and interrupt generation (su pport for slotted operation and superframe handling) • Low-power, deep-sleep mode operation and system wake up with all symbol counter interrupt events • Automatic SFD and incoming beacon timestamping • Manual beacon timestamping • Manual timer synchronization within a 16 µs symbol period by resetting clock prescaler and backoff slot counter • Atomic read/write access for 32 bit registers 10.2 Clock source selection and Sleep/Active mode operation The symbol counter can be sourced by the transceiver clock or by the asynchronous Real Time Clock (RTC) oscillator. If the transceiver goes from active mode into sleep mode, the symbol counter clock source is switched to the RTC clock automatically. A 157 8393C-MCU Wireless-09/14

clock source change is indicated in the bit SCCKSEL of Register "SCCR0 – Symbol Counter Control Register 0" on page 171 . The bit SCCKSEL can not be written if the radio transceiver is in SLEEP mode. After wake up, the counter switches back to the clock source which was selected before going to sleep mode. Switching the clock source from RTC to 16 MHz resets the 16 MHz clock prescaler. This makes sure, that after switching back the clock source, the symbol counter starts counting with a full 16 µs symbol period. The clock source can be selected with bit SCCKSEL in the SCCR0 Register Note: The AVR system clock has to be at least 4 times the symbol counter clock frequency. The symbol counter clock frequency is usually 62.5kHz, which would require a minimum of 250kHz AVR system clock frequency. 10.3 32 bit Register Access (Atomic Read/Write) All 32 bit registers support atomic read or write operation. That means reading or writing the least significant xxxLL byte (the register name ends in LL) updates or captures the complete 32 bit value. Read Access: 1. Reading the LL-Byte captures the 32 bit value in a temporary register 2. Read the upper 3 bytes Write Access: 1. Write the upper 3 byte 2. Writing the LL-Byte stores the 32 bit value in the counter registers The same temporary register is used for all 32 bit register of the MAC symbol counter. 10.4 Symbol Counter (32 bit, SCCNT) The symbol counter is a 32 bit counter which can be sourced by a 62.5 kHz clock, derived from the 16 MHz system clock or from the RTC (32.768 kHz). If sourced by the RTC, a special control circuitry ensures that the counter error does not exceed one symbol period. The symbol counter can be set or read from the controller. Reading must start with the least significant byte. If the least significant byte is accessed, all 32 bit of the counter are captured. A read access to SCCNTLL requires a maximum of three AVR clocks. Reading the upper three bytes of the counter requires two CPU clock cycles for each byte. Writing to the counter should start with the most significant byte. Writing the least significant byte initiates the counter update and the new 32 bit counter value is loaded into the counter with the next available counter clock edge. This can take up to 16 µs beginning from the low byte write operation, if the counter is sourced by the RTC. If the counter clock is derived from the 16 MHz clock system, the new counter value is stored immediately. During the counter update cycle, the counter busy flag SCBSY in the SCSR register is set to “1”. As long as this bit is “1”, no further read/write access to the counter should be initiated. The same applies if the AVR is forced to any sleep mode with disabled AVR clock, right after writing to the SCCNT register. If the counter busy flag is not checked before going to sleep, it is possible that the counter register is not updated correctly. The symbol counter overflow is indicated by a overflow interrupt. The interrupt is generated when the counter turns from 0xFFFFFFFF to 0x00000000. 10.5 Symbol Counter SFD Timestamp Register (32 bit, SCTSR, Read Only) The SFD timestamp register stores the symbol counter value at the time, the SFD has been detected. The Register value becomes valid if a valid frame length byte (frame ATmega256/128/64RFR2 158 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 length > 0) has been detected, but it is not checked if the received frame is valid (CRC check). Timestamping must be enabled in the control register (Bit SCTSE of Register SCCR0). A read access to SCTSRLL requires a maximum of three AVR clocks. Reading the upper three bytes of the timestamp requires two CPU clock cycles for each byte. Note that there is no separate interrupt provided for timestamping. Instead the TRX24_RX_START interrupt can be used (see "Interrupt Vectors in ATmega256/128/64RFR2" on page 243). 10.6 Symbol Counter Beacon Timestamp Register (32 bit, SCBTSR) If timestamping is enabled in the SCCR register, the beacon timestamp register is updated with the SFD times tamp at the end of the received frame, if the received frame was a beacon frame with valid FCS and: • Source PAN identifier == {PAN_ID_1, PAN_ID_0} or • {PAN_ID_1, PAN_ID_0} == 0xFFFF PAN_ID_0 and PAN_ID_1 are register of the radio transceiver, see "PAN_ID_0 – Transceiver Personal Area Network ID Register (Low Byte)" on page 139. Beacon timestamps can also be generated manually. Writing “1” to SCMBTS of Register SCCR0 captures the current symbol counter value and stores it in the beacon timestamp register. The bit is cleared automatically afterwards. It is also possible to manually set the register in order to provide a distinct starting value for the relative compare modes (see next section). 10.7 Compare Unit (3x 32 bit, SCOCR1, SCOCR2, SCOCR3) The compare unit contains 3 independent 32 bit compare modules and is used to compare the current counter value with the value stored in the compare register, and optionally the beacon timestamp register. There are two possible modes available which can be selected separ ately for all three compare modules: 1. Absolute Compare: In this mode the value stored in the compare register is compared directly with the symbol counter value (SCCNT == SCOCRx). If the values are equal an interrupt is generated. 2. Relative Compare: This mode allows the compare between the current symbol counter value and the compare value plus the beacon timestamp value (SCCNT == SCBTSR + SCOCRx). This mode can be used to generate an interrupt at a time offset relative to the value stored in the beacon timestamp register. Note that a beacon timestamp is valid after a valid FCS. The relative compare must exceed the beacon length, otherwise no relative compare interrupt will occur. 10.8 Interrupt Control Registers The interrupt status and ma sk registers control the interrupt generation. Each interrupt can be enabled in SCIRQM (Symbol Counter IRQ Mask Register). If an interrupt occurs, the appropriate interrupt flag within the interrupt status register is set regardless of the interrupt mask register setting. If the appropriate interrupt is enabled, an interrupt is generated. The interrupt flags can be cleared either by: 1. Entering the respective interrupt handler, or 2. Writing “one” to the according interrupt flag in the interrupt status register. 159 8393C-MCU Wireless-09/14

All Interrupts can be used to wakeup the controller from any sleep state. 10.9 Backoff Slot Counter The backoff slot counter c an be used to provide accurate MAC protocol timing. The counter is sourced by the transceiver clock and works only if the transceiver clock is running. If the transceiver is disabled or in sleep mode the counter is also disabled. The counter generates periodic Interrupts every 20 symbols, i.e. every 320 µs. 10.10 Symbol Counter Usage 10.10.1 SFD and Beacon Timestamp Generation The SFD timestamp register is updated with the symbol counter value at the time the SFD value has been received completely. For an incoming frame, the register is valid after the RX_START IRQ was issued until the next RX_START IRQ. SFD timestamps are generated for all incoming frames with valid SFD and length field even if the PSDU is corrupted (invalid FCS). Figure 10-2. SFD and Beacon Timestamp Generation Note that Figure 10-2 contains no exact timing information; it is for visualization only. The beacon timestamp register is updated with the SFD timestamp value at the end of the frame (RX_END IRQ), if the received frame was a beacon frame with valid FCS and expected source PAN identifier or { PAN_ID_1, PAN_ID_0} = 0xFFFF. The register value is valid until a new beacon frame has been received or the beacon timestamp is updated manually. A manual beacon timestamp can be generated by writing “1” to SCMBTS of the SCCR0 register. 10.10.2 Relative Compare Mode for Superframe Access Timing The IEEE 802.15.4 describes a superframe structure which contains different time slots where a device can access the channel. ATmega256/128/64RFR2 160 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 The Symbol Counter together with the three compare units provide support for waking up the device at the right time to receive the beacon for superframe synchronization and at certain times within the superframe. A typical superframe timing scenario using the symbol counter relative compare mode is shown in Figure 10-3 below. The Symbol Counter values in the figure do not reflect realistic time intervals but demonstrate the principle of operation. Figure 10-3. Relative Compare Mode Activation Beacon Activation Beacon 323324325326327328329 402403404405406407 480481482483484485 635636637638640641 The compare match registers are programmed with symbol intervals relative to the beacon frame SFD timestamp. For instance the SCCMP1 is programmed to 80, because the first Granted Time Slot (GTS1) is expected 80 symbols after the beacon frame. Register SCCMP2 is programmed to 156 to meet GTS3 156 symbols after the beacon frame. SCCMP3 is programmed to 312. This is the time interval where the beacon of the next superframe is expected. Because it requires some time to activate the transceiver and there is also some timing drift possible, the compare interrupt must be programmed to wake up some symbols in advance to make sure the next beacon is not missed. If the controller receives a compare match wake up event it is activating the transceiver. After the frame operations are finished, the system can go back to sleep until the next compare match event occurs. 10.11 Register Description 10.11.1 SCCSR – Symbol Counter Compare Source Register Bit 7 6 5 4 3 2 1 0 NA ($DB) Res1 Res0 SCCS31 SCCS30 SCCS21 SCCS20 SCCS11 SCCS10 SCCSR Read/Write R R RW RW RW RW RW RW Initial Value 0 0 0 0 0 0 0 0 161 8393C-MCU Wireless-09/14

The Register describes the source timestamp register used for the relative compare mode. The time stamp source can be selected separately for each compare unit. Possible sources for the relative compare are the Transmit Timestamp, the Receive Timestamp or the Beacon Timestamp (default). • Bit 7:6 – Res1:0 - Reserved Bit This bit is reserved for future use. The result of a read access is undefined. The register bit must always be written with the reset value. • Bit 5:4 – SCCS31:30 - Symbol Counter Compare Source select register for Compare Unit 3 This configuration bits allow the selection of the source timestamp used for the relative compare mode. The default selection is the Beacon Timestamp Register, but the Transmit Frame Timestamp or the Receive Frame Timestamp register can also be selected. Table 10-81 SCCS3 Register Bits Register Bits Value Description SCCS31:30 0 Compare Unit 3 Relative Compare Source = Beacon Timestamp Register 1 Compare Unit 3 Relative Compare Source = Transmit Frame Timestamp Register 2 Compare Unit 3 Relative Compare Source = Received Frame Timestamp Register • Bit 3:2 – SCCS21:20 - Symbol Counter Compare Source select register for Compare Unit 2 This configuration bits allow the selection of the source timestamp used for the relative compare mode. The default selection is the Beacon Timestamp Register, but the Transmit Frame Timestamp or the Receive Frame Timestamp register can also be selected. Table 10-82 SCCS2 Regist er Bits Register Bits Value Description SCCS21:20 0 Compare Unit 2 Relative Compare Source = Beacon Timestamp Register 1 Compare Unit 2 Relative Compare Source = Transmit Frame Timestamp Register 2 Compare Unit 2 Relative Compare Source = Received Frame Timestamp Register • Bit 1:0 – SCCS11:10 - Symbol Counter Compare Source select register for Compare Unit 1 This configuration bits allow the selection of the source timestamp used for the relative compare mode. The default selection is the Beacon Timestamp Register, but the Transmit Frame Timestamp or the Receive Frame Timestamp register can also be selected. Table 10-83 SCCS1 Register Bits Register Bits Value Description SCCS11:10 0 Compare Unit 1 Relative Compare Source = Beacon Timestamp Register 1 Compare Unit 1 Relative Compare Source = Transmit Frame Timestamp Register ATmega256/128/64RFR2 162 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 Register Bits Value Description 2 Compare Unit 1 Relative Compare Source = Received Frame Timestamp Register 10.11.2 SCCNTHH – Symbol Counter Register HH-Byte Bit 7 6 5 4 3 2 1 0 NA ($E4) SCCNTHH7:0 SCCNTHH Read/Write RW RW RW RW RW RW RW RW Initial Value 0 0 0 0 0 0 0 0 This register contains the most significant byte of the 32 bit Symbol Counter. • Bit 7:0 – SCCNTHH7:0 - Symbol Counter Register HH-Byte 10.11.3 SCCNTHL – Symbol Counter Register HL-Byte Bit 7 6 5 4 3 2 1 0 NA ($E3) SCCNTHL7:0 SCCNTHL Read/Write RW RW RW RW RW RW RW RW Initial Value 0 0 0 0 0 0 0 0 This register contains the se cond most significant byte of the 32 bit Symbol Counter. • Bit 7:0 – SCCNTHL7:0 - Symbol Counter Register HL-Byte 10.11.4 SCCNTLH – Symbol Counter Register LH-Byte Bit 7 6 5 4 3 2 1 0 NA ($E2) SCCNTLH7:0 SCCNTLH Read/Write RW RW RW RW RW RW RW RW Initial Value 0 0 0 0 0 0 0 0 This register contains the second least significant byte of the 32 bit Symbol Counter. • Bit 7:0 – SCCNTLH7:0 - Symbol Counter Register LH-Byte 10.11.5 SCCNTLL – Symbol Counter Register LL-Byte Bit 7 6 5 4 3 2 1 0 NA ($E1) SCCNTLL7:0 SCCNTLL Read/Write RW RW RW RW RW RW RW RW Initial Value 0 0 0 0 0 0 0 0 This register contains the least significant byte of the 32 bit Symbol Counter. • Bit 7:0 – SCCNTLL7:0 - Symbol Counter Register LL-Byte 163 8393C-MCU Wireless-09/14

10.11.6 SCTSRHH – Symbol Counter Frame Timestamp Register HH-Byte Bit 7 6 5 4 3 2 1 0 NA ($EC) SCTSRHH7:0 SCTSRHH Read/Write R R R R R R R R Initial Value 0 0 0 0 0 0 0 0 This register contains the most significant byte of the 32 bit frame (SFD) timestamp register • Bit 7:0 – SCTSRHH7:0 - Symbol Counter Frame Timestamp Register HH-Byte 10.11.7 SCTSRHL – Symbol Counter Frame Timestamp Register HL-Byte Bit 7 6 5 4 3 2 1 0 NA ($EB) SCTSRHL7:0 SCTSRHL Read/Write R R R R R R R R Initial Value 0 0 0 0 0 0 0 0 This register contains the second most significant byte of the 32 bit Frame (SFD) Timestamp Register • Bit 7:0 – SCTSRHL7:0 - Symbol Counter Frame Timestamp Register HL-Byte 10.11.8 SCTSRLH – Symbol Counter Frame Timestamp Register LH-Byte Bit 7 6 5 4 3 2 1 0 NA ($EA) SCTSRLH7:0 SCTSRLH Read/Write R R R R R R R R Initial Value 0 0 0 0 0 0 0 0 This register contains the second least significant byte of the 32 bit Frame (SFD) Timestamp Register • Bit 7:0 – SCTSRLH7:0 - Symbol Counter Frame Timestamp Register LH-Byte 10.11.9 SCTSRLL – Symbol Counter Frame Timestamp Register LL-Byte Bit 7 6 5 4 3 2 1 0 NA ($E9) SCTSRLL7:0 SCTSRLL Read/Write R R R R R R R R Initial Value 0 0 0 0 0 0 0 0 This register contains the least significant byte of the 32 bit Frame (SFD) Timestamp Register • Bit 7:0 – SCTSRLL7:0 - Symbol Counter Frame Timestamp Register LL-Byte ATmega256/128/64RFR2 164 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 10.11.10 SCTSTRHH – Symbol Counter Transmit Frame Timestamp Register HH-Byte Bit 7 6 5 4 3 2 1 0 NA ($FC) SCTSTRHH7:0 SCTSTRHH Read/Write R R R R R R R R Initial Value 0 0 0 0 0 0 0 0 This register contains the most significant byte of the 32 bit Transmit Frame Timestamp Register. The Transmit Frame Timestamp Register is updated one symbol before the beginning of the frame transmission (preamble transmission). To allign the Transmit Frame Timestamp with a Received Frame Timestamp (SFD Timestamp),a fixed offset of 11 symbols (1 Symbol Startup + 8 Symbols Preamble + 2 Symbols SFD) need to be added to the Transmit Timestamp . • Bit 7:0 – SCTSTRHH7:0 - Symbol Counter Transmit Frame Timestamp Register HH-Byte 10.11.11 SCTSTRHL – Symbol Counter Transmit Frame Timestamp Register HL-Byte Bit 7 6 5 4 3 2 1 0 NA ($FB) SCTSTRHL7:0 SCTSTRHL Read/Write R R R R R R R R Initial Value 0 0 0 0 0 0 0 0 This register contains the second most significant byte of the 32 bit Transmit Frame Timestamp Register. • Bit 7:0 – SCTSTRHL7:0 - Symbol Counter Transmit Frame Timestamp Register HL-Byte 10.11.12 SCTSTRLH – Symbol Counter Transmit Frame Timestamp Register LH-Byte Bit 7 6 5 4 3 2 1 0 NA ($FA) SCTSTRLH7:0 SCTSTRLH Read/Write R R R R R R R R Initial Value 0 0 0 0 0 0 0 0 This register contains the second least significant byte of the 32 bit Transmit Frame Timestamp Register. • Bit 7:0 – SCTSTRLH7:0 - Symbol Counter Transmit Frame Timestamp Register LH-Byte 10.11.13 SCTSTRLL – Symbol Counter Transmit Frame Timestamp Register LL-Byte Bit 7 6 5 4 3 2 1 0 NA ($F9) SCTSTRLL7:0 SCTSTRLL Read/Write R R R R R R R R Initial Value 0 0 0 0 0 0 0 0 165 8393C-MCU Wireless-09/14

This register contains the least significant byte of the 32 bit Transmit Frame Timestamp Register. • Bit 7:0 – SCTSTRLL7:0 - Symbol Counter Transmit Frame Timestamp Register LL-Byte 10.11.14 SCRSTRHH – Symbol Counter Received Frame Timestamp Register HH-Byte Bit 7 6 5 4 3 2 1 0 NA ($DA) SCRSTRHH7:0 SCRSTRHH Read/Write R R R R R R R R Initial Value 0 0 0 0 0 0 0 0 This register contains the most significant byte of the 32 bit Received Frame Timestamp Register. The Received Frame Timestamp Register is updated at the end of the frame reception with the contents of the Frame Timestamp Register (SFD timestamp) if the received frame was valid (FCS ok). If the transceiver auto modes are enabled and address filtering is active, the Received Frame Timestamp is only updated, if there was an address match also. • Bit 7:0 – SCRSTRHH7:0 - Symbol Counter Received Frame Timestamp Register HH-Byte 10.11.15 SCRSTRHL – Symbol Counter Received Frame Timestamp Register HL-Byte Bit 7 6 5 4 3 2 1 0 NA ($D9) SCRSTRHL7:0 SCRSTRHL Read/Write R R R R R R R R Initial Value 0 0 0 0 0 0 0 0 This register contains the second most significant byte of the 32 bit Received Frame Timestamp Register. • Bit 7:0 – SCRSTRHL7:0 - Symbol Counter Received Frame Timestamp Register HL-Byte 10.11.16 SCRSTRLH – Symbol Counter Received Frame Timestamp Register LH-Byte Bit 7 6 5 4 3 2 1 0 NA ($D8) SCRSTRLH7:0 SCRSTRLH Read/Write R R R R R R R R Initial Value 0 0 0 0 0 0 0 0 This register contains the second least significant byte of the 32 bit Received Frame Timestamp Register. • Bit 7:0 – SCRSTRLH7:0 - Symbol Counter Received Frame Timestamp Register LH-Byte ATmega256/128/64RFR2 166 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 10.11.17 SCRSTRLL – Symbol Counter Received Frame Timestamp Register LL-Byte Bit 7 6 5 4 3 2 1 0 NA ($D7) SCRSTRLL7:0 SCRSTRLL Read/Write R R R R R R R R Initial Value 0 0 0 0 0 0 0 0 This register contains the least significant byte of the 32 bit Received Frame Timestamp Register. • Bit 7:0 – SCRSTRLL7:0 - Symbol Counter Received Frame Timestamp Register LL-Byte 10.11.18 SCBTSRHH – Symbol Counter Beacon Timestamp Register HH-Byte Bit 7 6 5 4 3 2 1 0 NA ($E8) SCBTSRHH7:0 SCBTSRHH Read/Write RW RW RW RW RW RW RW RW Initial Value 0 0 0 0 0 0 0 0 This register contains the most significant byte of the 32 bit Beacon Timestamp Register. The Beacon Timestamp Register is updated with the contents of the Frame Timestamp Register if the received frame was a valid beacon frame with matching source PAN identifier or register {PAN_ID_1, PAN_ID_0} = 0xFFFF. • Bit 7:0 – SCBTSRHH7:0 - Symbol Counter Beacon Timestamp Register HH- Byte 10.11.19 SCBTSRHL – Symbol Counter Beacon Timestamp Register HL-Byte Bit 7 6 5 4 3 2 1 0 NA ($E7) SCBTSRHL7:0 SCBTSRHL Read/Write RW RW RW RW RW RW RW RW Initial Value 0 0 0 0 0 0 0 0 This register contains the second most significant byte of the 32 bit Beacon Timestamp Register. • Bit 7:0 – SCBTSRHL7:0 - Symbol Counter Beacon Timestamp Register HL- Byte 10.11.20 SCBTSRLH – Symbol Counter Beacon Timestamp Register LH-Byte Bit 7 6 5 4 3 2 1 0 NA ($E6) SCBTSRLH7:0 SCBTSRLH Read/Write RW RW RW RW RW RW RW RW Initial Value 0 0 0 0 0 0 0 0 167 8393C-MCU Wireless-09/14

This register contains the second least significant byte of the 32 bit Beacon Timestamp Register. • Bit 7:0 – SCBTSRLH7:0 - Symbol Counter Beacon Timestamp Register LH- Byte 10.11.21 SCBTSRLL – Symbol Counter Beacon Timestamp Register LL-Byte Bit 7 6 5 4 3 2 1 0 NA ($E5) SCBTSRLL7:0 SCBTSRLL Read/Write RW RW RW RW RW RW RW RW Initial Value 0 0 0 0 0 0 0 0 This register contains the least significant byte of the 32 bit Beacon Timestamp Register. • Bit 7:0 – SCBTSRLL7:0 - Symbol Counter Beacon Timestamp Register LL-Byte 10.11.22 SCOCR1HH – Symbol Counter Output Compare Register 1 HH-Byte Bit 7 6 5 4 3 2 1 0 NA ($F8) SCOCR1HH7:0 SCOCR1HH Read/Write RW RW RW RW RW RW RW RW Initial Value 0 0 0 0 0 0 0 0 This register contains the most significant byte of the 32 bit compare value for the first compare unit • Bit 7:0 – SCOCR1HH7:0 - Symbol Counter Output Compare Register 1 HH-Byte 10.11.23 SCOCR1HL – Symbol Counter Output Compare Register 1 HL-Byte Bit 7 6 5 4 3 2 1 0 NA ($F7) SCOCR1HL7:0 SCOCR1HL Read/Write RW RW RW RW RW RW RW RW Initial Value 0 0 0 0 0 0 0 0 This register contains the second most significant byte of the 32 bit compare value for the first compare unit • Bit 7:0 – SCOCR1HL7:0 - Symbol Counter Output Compare Register 1 HL-Byte 10.11.24 SCOCR1LH – Symbol Counter Output Compare Register 1 LH-Byte Bit 7 6 5 4 3 2 1 0 NA ($F6) SCOCR1LH7:0 SCOCR1LH Read/Write RW RW RW RW RW RW RW RW Initial Value 0 0 0 0 0 0 0 0 ATmega256/128/64RFR2 168 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 This register contains the second least significant byte of the 32 bit compare value for the first compare unit • Bit 7:0 – SCOCR1LH7:0 - Symbol Counter Output Compare Register 1 LH-Byte 10.11.25 SCOCR1LL – Symbol Counter Output Compare Register 1 LL-Byte Bit 7 6 5 4 3 2 1 0 NA ($F5) SCOCR1LL7:0 SCOCR1LL Read/Write RW RW RW RW RW RW RW RW Initial Value 0 0 0 0 0 0 0 0 This register contains the least significant byte of the 32 bit compare value for the first compare unit • Bit 7:0 – SCOCR1LL7:0 - Symbol Counter Output Compare Register 1 LL-Byte 10.11.26 SCOCR2HH – Symbol Counter Output Compare Register 2 HH-Byte Bit 7 6 5 4 3 2 1 0 NA ($F4) SCOCR2HH7:0 SCOCR2HH Read/Write RW RW RW RW RW RW RW RW Initial Value 0 0 0 0 0 0 0 0 This register contains the most significant byte of the 32 bit compare value for the second compare unit • Bit 7:0 – SCOCR2HH7:0 - Symbol Counter Output Compare Register 2 HH-Byte 10.11.27 SCOCR2HL – Symbol Counter Output Compare Register 2 HL-Byte Bit 7 6 5 4 3 2 1 0 NA ($F3) SCOCR2HL7:0 SCOCR2HL Read/Write RW RW RW RW RW RW RW RW Initial Value 0 0 0 0 0 0 0 0 This register contains the second most significant byte of the 32 bit compare value for the second compare unit • Bit 7:0 – SCOCR2HL7:0 - Symbol Counter Output Compare Register 2 HL-Byte 10.11.28 SCOCR2LH – Symbol Counter Output Compare Register 2 LH-Byte Bit 7 6 5 4 3 2 1 0 NA ($F2) SCOCR2LH7:0 SCOCR2LH Read/Write RW RW RW RW RW RW RW RW Initial Value 0 0 0 0 0 0 0 0 169 8393C-MCU Wireless-09/14

This register contains the second least significant byte of the 32 bit compare value for the second compare unit • Bit 7:0 – SCOCR2LH7:0 - Symbol Counter Output Compare Register 2 LH-Byte 10.11.29 SCOCR2LL – Symbol Counter Output Compare Register 2 LL-Byte Bit 7 6 5 4 3 2 1 0 NA ($F1) SCOCR2LL7:0 SCOCR2LL Read/Write RW RW RW RW RW RW RW RW Initial Value 0 0 0 0 0 0 0 0 This register contains the least significant byte of the 32 bit compare value for the second compare unit • Bit 7:0 – SCOCR2LL7:0 - Symbol Counter Output Compare Register 2 LL-Byte 10.11.30 SCOCR3HH – Symbol Counter Output Compare Register 3 HH-Byte Bit 7 6 5 4 3 2 1 0 NA ($F0) SCOCR3HH7:0 SCOCR3HH Read/Write RW RW RW RW RW RW RW RW Initial Value 0 0 0 0 0 0 0 0 This register contains the most significant byte of the 32 bit compare value for the third compare unit • Bit 7:0 – SCOCR3HH7:0 - Symbol Counter Output Compare Register 3 HH-Byte 10.11.31 SCOCR3HL – Symbol Counter Output Compare Register 3 HL-Byte Bit 7 6 5 4 3 2 1 0 NA ($EF) SCOCR3HL7:0 SCOCR3HL Read/Write RW RW RW RW RW RW RW RW Initial Value 0 0 0 0 0 0 0 0 This register contains the second most significant byte of the 32 bit compare value for the third compare unit • Bit 7:0 – SCOCR3HL7:0 - Symbol Counter Output Compare Register 3 HL-Byte 10.11.32 SCOCR3LH – Symbol Counter Output Compare Register 3 LH-Byte Bit 7 6 5 4 3 2 1 0 NA ($EE) SCOCR3LH7:0 SCOCR3LH Read/Write RW RW RW RW RW RW RW RW Initial Value 0 0 0 0 0 0 0 0 ATmega256/128/64RFR2 170 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 This register contains the second least significant byte of the 32 bit compare value for the third compare unit • Bit 7:0 – SCOCR3LH7:0 - Symbol Counter Output Compare Register 3 LH-Byte 10.11.33 SCOCR3LL – Symbol Counter Output Compare Register 3 LL-Byte Bit 7 6 5 4 3 2 1 0 NA ($ED) SCOCR3LL7:0 SCOCR3LL Read/Write RW RW RW RW RW RW RW RW Initial Value 0 0 0 0 0 0 0 0 This register contains the least significant byte of the 32 bit compare value for the third compare unit • Bit 7:0 – SCOCR3LL7:0 - Symbol Counter Output Compare Register 3 LL-Byte 10.11.34 SCCR0 – Symbol Counter Control Register 0 Bit 7 6 5 4 3 2 1 0 NA ($DC) SCRES SCMBTS SCEN SCCKSEL SCTSE SCCMP3 SCCMP2 SCCMP1 SCCR0 Read/Write RW RW RW RW RW RW RW RW Initial Value 0 0 0 0 0 0 0 0 The Control Register 0 is used to setup the operating mode of the symbol counter and the compare units • Bit 7 – SCRES - Symbol Counter Synchronization If this bit is set to 1, the 16 MHz clock prescaler as well as the backoff slot counter is cleared. This function can be used to align the symbol timing within one 16 µs symbol period and to restart the backoff slot counter with a complete 320 µs period. This feature works only if the symbol counter module operates with the 16 MHz clock from XTAL1. After switching to RTC clock source, the symbol period synchronization is lost. This bit is cleared automatically. • Bit 6 – SCMBTS - Manual Beacon Timestamp With this bit a manual beacon timestamp can be generated. If set to 1, the current symbol counter value is sto red into the beacon timestamp register. The bit is cleared afterwards. The manual beacon timestamping can be used in conjunction with the relative compare mode of the three compare units to generate compare match interrupts without having a beacon frame received. • Bit 5 – SCEN - Symbol Counter enable This bit activates the symbo l counter module. If the bit is not set, the counter, backoff slot counter and the compare unit are disabled and disconnected from the clock. In this way the power consumption can be reduced. All registers can be accessed, but write access to the counter register SCCNT is not possible. • Bit 4 – SCCKSEL - Symbol Counter Clock Source select With this bit the clock source for the symbol counter can be selected. If the bit is one, the RTC clock from TOSC1 is selected, otherwise the symbol counter operates with the clock from XTAL1. During transceiver sleep modes the clock falls back to the RTC clock 171 8393C-MCU Wireless-09/14

source, regardless of the selected clock. After wakeup, it switches back to the previosly selected clock source. • Bit 3 – SCTSE - Symbol Counter Automatic Timestamping enable This bit enables automatic SFD and Beacon Timestamping. If the bit is zero, no automatic timestamp capturing is possible. Only manual beacon timestamping can be used. • Bit 2 – SCCMP3 - Symbol Counter Compare Unit 3 Mode select This bit enables the relative compare mode for compare unit 3. If enabled, the counter value is compared against the content of the timestamp register selected in Compare Source Register SCCSR select bits SCCS3 plus the content of the compare register 3 (SCCNT == timestamp+SCOCR3). Otherwise, the counter is compared against the compare register 3 (SCCNT == SCOCR3). • Bit 1 – SCCMP2 - Symbol Counter Compare Unit 2 Mode select This bit enables the relative compare mode for compare unit 2. If enabled, the counter value is compared against the content of the timestamp register selected in Compare Source Register SCCSR se lect bits SCCS2 plus the content of the compare register 2 (SCCNT == timestamp+SCOCR2). Otherwise, the counter is compared against the compare register 2 (SCCNT == SCOCR2). • Bit 0 – SCCMP1 - Symbol Counter Compare Unit 1 Mode select This bit enables the relative compare mode for compare unit 1. If enabled, the counter value is compared against the content of the timestamp register selected in Compare Source Register SCCSR select bits SCCS1 plus the content of the compare register 1 (SCCNT == timestamp+SCOCR1). Otherwise, the counter is compared against the compare register 1 (SCCNT == SCOCR1). 10.11.35 SCCR1 – Symbol Counter Control Register 1 Bit 7 6 5 4 NA ($DD) Res6 Res5 SCBTSM SCCKDIV2 SCCR1 Read/Write R R RW RW Initial Value 0 0 0 0 Bit 3 2 1 0 NA ($DD) SCCKDIV1 SCCKDIV0 SCEECLK SCENBO SCCR1 Read/Write RW RW RW RW Initial Value 0 0 0 0 This register is used to enable the backoff slot counter. • Bit 7:6 – Res6:5 - Reserved Bit This bit is reserved for futur e use. The result of a read access is undefined. The register bit must always be written with the reset value. • Bit 5 – SCBTSM - Symbol Counter Beacon Timestamp Mask Register This bit must be set to disable automatic beacon timestamping. All other timestamps as well as manual beacon timestamping is not effected by this setting. • Bit 4:2 – SCCKDIV2:0 - Clock divider for synchronous clock source (16MHz Transceiver Clock) ATmega256/128/64RFR2 172 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 The 3 Bit value controls the symbol counter clock prescaler. The input clock to the prescaler is the 16MHz transceiver clock. The different prescaler values are defined in the table below. The default prescaler setting is 62.5kHz. If the transceiver clock is selected, the counter continues on the RTC time base during sleep mode, regardless of the SCCKDIV setting. Table 10-84 SCCKDIV Register Bits Register Bits Value Description SCCKDIV2:0 0 Transceiver Clock divided by 256, (62.5kHz) 1 Transceiver Clock divided by 128, (125kHz) 2 Transceiver Clock divided by 64, (250kHz) 3 Transceiver Clock divided by 32, (500kHz) 4 Transceiver Clock divided by 16, (1MHz) 5 Transceiver Clock divided by 8, (2MHz) 6 Transceiver Clock divided by 4, (4MHz) • Bit 1 – SCEECLK - Enable External Clock Source on PG2 If this bit is set, a asynchronous clock provided on PG2 can be used to run the symbol counter. SCEECLK overrieds SCCKSEL and forces the selection of the external clock source. The clock source on PG2 can have a maximum frequency of 1/4 of the controller clock speed. If selected, the clock on PG2 is used during sleep mode also. • Bit 0 – SCENBO - Backoff Slot Counter enable If this bit is set, the backoff slot counter starts working. To enable the corresponding IRQ the SCIRQM register must be updated. 10.11.36 SCSR – Symbol Counter Status Register Bit 7 6 5 4 3 2 1 0 NA ($DE) Res6 Res5 Res4 Res3 Res2 Res1 Res0 SCBSY SCSR Read/Write R R R R R R R R Initial Value 0 0 0 0 0 0 0 0 • Bit 7:1 – Res6:0 - Reserved Bit This bit is reserved for future use. The result of a read access is undefined. The register bit must always be written with the reset value. • Bit 0 – SCBSY - Symbol Counter busy This bit is set if a write operation to the symbol counter register is pending. This bit is set after writing the counter low byte (SCCNTLL) until the symbol counter is updated with the new value. This update process can take up to 16 µs and during this time no read or write access to the 32 bit counter register should occur. 10.11.37 SCIRQS – Symbol Counter Interrupt Status Register Bit 7 6 5 4 3 2 1 0 NA ($E0) Res2 Res1 Res0 IRQSBO IRQSOF IRQSCP3 IRQSCP2 IRQSCP1 SCIRQS Read/Write R R R RW RW RW RW RW Initial Value 0 0 0 0 0 0 0 0 173 8393C-MCU Wireless-09/14

The Interrupt Status Register indicates pending interrupt requests. If the corresponding interrupt mask bit is set, an interrupt service routine is called and the status bit is cleared automatically. It is also possible to clear the status bit by writing "1" to the selected bit. • Bit 7:5 – Res2:0 - Reserved Bit This bit is reserved for future use. The result of a read access is undefined. The register bit must always be written with the reset value. • Bit 4 – IRQSBO - Backoff Slot Counter IRQ This interrupt is generated every 320 µs, that means every 20 symbols. • Bit 3 – IRQSOF - Symbol Counter Overflow IRQ This interrupt is generated when the 32 bit counter turns from 0xFFFFFFF to 0x00000000. • Bit 2 – IRQSCP3 - Compare Unit 3 Compare Match IRQ This interrupt indicates a co mpare match on compare unit 3. • Bit 1 – IRQSCP2 - Compare Unit 2 Compare Match IRQ This interrupt indicates a compare match on compare unit 2. • Bit 0 – IRQSCP1 - Compare Unit 1 Compare Match IRQ This interrupt indicates a compare match on compare unit 1. 10.11.38 SCIRQM – Symbol Counter Interrupt Mask Register Bit 7 6 5 4 3 2 1 0 NA ($DF) Res2 Res1 Res0 IRQMBO IRQMOF IRQMCP3 IRQMCP2 IRQMCP1 SCIRQM Read/Write R R R RW RW RW RW RW Initial Value 0 0 0 0 0 0 0 0 The Interrupt Mask Register is used to enable corresponding interrupts. After reset all interrupts are disabled. Disabled interrupts are still captured in the interrupt status register SCIRQS, but no interrupt is requested. Before enabling an interrupt, the corresponding interrupt status bit should be cleared by writing a 1. If the status bit is set and the IRQ gets enabled, the IRQ handler is called immediately. • Bit 7:5 – Res2:0 - Reserved Bit This bit is reserved for future use. The result of a read access is undefined. The register bit must always be written with the reset value. • Bit 4 – IRQMBO - Backoff Slot Counter IRQ enable This bit enables the SCNT_ BACKOFF interrupt. • Bit 3 – IRQMOF - Symbol Counter Overflow IRQ enable This bit enables the SCNT_OVFL interrupt. • Bit 2 – IRQMCP3 - Symbol Counter Compare Match 3 IRQ enable This bit enables the SCNT_CMP3 interrupt. • Bit 1 – IRQMCP2 - Symbol Counter Compare Match 2 IRQ enable This bit enables the SCNT_CMP2 interrupt. ATmega256/128/64RFR2 174 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 • Bit 0 – IRQMCP1 - Symbol Counter Compare Match 1 IRQ enable This bit enables the SCNT_CMP1 interrupt. 175 8393C-MCU Wireless-09/14

11 System Clock and Clock Options This section describes the clock options for the AVR microcontroller. 11.1 Overview Figure 11-1 below presents the principal clock systems in the AVR and their distribution. All of the clocks need not be active at a given time. In order to reduce power consumption, the clocks to modules not being used can be halted by using different sleep modes, as described in chapter "Power Management and Sleep Modes" on page 185. The clock systems are detailed below. Figure 11-1. Clock Distribution Symbol Asynchronous General I/O Flash and Radio ADC CPU Core RAM Counter Timer Modules EEPROM Transceiver clkASY clkRAMREGF MuCltliopclekxer clkADC MuCltliopclekxer clkI/O AVR Clock clkCPU clkCALIB Control Unit clkFLASH Source clock Reset Logic Watchdog Timer 1/8 Clock Prescaler System Clock Prescaler Clock Multiplexer clkTRX clkRCOSC clkWDT 1:2 Prescaler Timer/Counter Transceiver Crystal Calibrated RC Watchdog Oscillator Oscillator External Clock Oscillator Oscillator (16MHz) (128kHz) (32.768kHz) (16MHz) TOSC1 TOSC2 AMR CLKI XTAL1 XTAL2 11.2 Clock Systems and their Distribution The AVR Clock Control U nit distributes the pre-scaled system clock to the various functional blocks of the device. The radio transceiver always runs with the 16 MHz crystal oscillator clock. 11.2.1 CPU Clock – clk CPU The CPU clock is routed to parts of the system concerned with operation of the AVR core. Examples of such modules are the General Purpose Register File, the Status Register and the data memory holding the Stack Pointer. Halting the CPU clock inhibits the core from performing general operations and calculations. ATmega256/128/64RFR2 176 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 11.2.2 I/O Clock – clk I/O The I/O clock is used by the majority of the I/O modules, like Timer/Counters, SPI, and USART. The I/O clock is also used by the External Interrupt module, but note that some external interrupts are detected by asynchronous logic, allowing such interrupts to be detected even if the I/O clock is halted. Also note that start condition detection in the 2- wire serial interface (TWI) module is carried out asynchronously when clk is halted. I/O Similar the TWI address recognition in all sleep modes also occurs asynchronously. 11.2.3 Flash Clock – clk FLASH The Flash clock controls operation of the Flash interface. The Flash clock is usually active simultaneously with the CPU clock. 11.2.4 Asynchronous Timer Clock – clk ASY The Asynchronous Timer clock allows the Asynchronous Timer/Counter to be clocked directly from an external clock or an external 32 kHz clock crystal. The dedicated clock domain allows using this Timer/Counter as a real-time counter even if the device is in sleep mode. 11.2.5 ADC Clock – clk ADC The ADC is provided with a dedicated clock domain. This allows halting the CPU and I/O clocks in order to reduce noise generated by digital circuitry. This gives more accurate ADC conversion results. 11.3 Clock Sources The device has the following clock source options, selectable by Flash Fuse bits as shown below. The clock from the selected source is input to the AVR clock generator, and routed to the appropriate modules. Table 11-1. Device Clocking Options Select(1) Device Clocking Option CKSEL3:0 Transceiver clock 1111 – 0110 Reserved 0101 - 0100 Internal 128 kHz RC Oscillator 0011 Calibrated Internal RC Oscillator 0010 External Clock 0000 Reserved 0001 Notes: 1. For all fuses “1” means unprogrammed while “0” means programmed. 11.3.1 Default Clock Source The device is shipped with internal RC oscillator at 16.0 MHz, the 1:2 prescaler enabled and with the fuse CKDIV8 programmed, resulting in 1.0 MHz system clock. The startup time is set to maximum time. (CKSEL = "0010", SUT = "10", CKDIV8 = "0"). The default setting ensures that all users can make their desired clock source setting using any available programming interface. 11.3.2 Clock Start-up Sequence Any clock source needs a minimum number of oscillating cycles before it can be considered stable. 177 8393C-MCU Wireless-09/14

To ensure sufficient startup time, the device issues an internal reset with a time-out delay (t ) after the device reset is released by all other reset sources. Section TOUT "Power-on Reset" on page 210 describes the start conditions for the internal reset. The delay (t ) is timed from the Watchdog Oscillator and the number of cycles in the TOUT delay is set by the SUTx and CKSELx fuse bits. The selectable delays are shown in Table 11-2 below. The frequency of the Watchdog Oscillator is voltage dependent as shown in section "Typical Characteristics" on page 567. Table 11-2. Number of Watchdog Oscillator Cycles Typ Time-out Number of Cycles 0 ms 0 4.0 ms 512 64 ms 8K (8,192) Main purpose of the delay is to keep the AVR in reset until it is supplied with a stable V . The delay will not monitor the actual voltage and it will be required to select a DEVDD delay longer than the DEVDD rise time. If this is not possible, an internal or external Brown-Out Detection (BOD) circuit should be used. A BOD circuit will ensure sufficient V before it releases the reset, and the time-out delay can be disabled. Disabling DEVDD the time-out delay without utilizing a Brown-Out Detection circuit is not recommended. The oscillator is required to oscillate for a minimum number of cycles before the clock is considered stable. An internal ripple counter monitors the oscillator output clock, and keeps the internal reset active for a given number of clock cycles. The reset is then released and the device will start to execute. The recommended oscillator start-up time is dependent on the clock t ype, and varies from 6 cycles for an externally applied clock to 32K cycles for a low frequency crystal. The start-up sequence for the clock includes both the time-out delay and the start-up time when the device starts up from reset. When starting up from Power-save or Power- down mode, DEVDD is assumed to be at a sufficient level and only the start-up time is included. 11.4 Calibrated Internal RC Oscillator By default, the Internal RC Oscillator provides an approximate 16 MHz clock. The RC oscillator is voltage and temperature dependent, but can be very accurately calibrated by the user. See chapter "Clock Characteristics" on page 555 and "Internal Oscillator Speed" on page 590 for more details. The device is shipped with the CKDIV8 Fuse and the 1:2 system clock prescaler programmed. See section "System Clock Prescaler" on page 181 for more details. This clock may be selected as the system clock by programming the CKSEL Fuses as shown in Table 11-3 on page 179. If selected, it will operate with no external components. During reset, hardware loads the pre-programmed calibration value into the OSCCAL Register and thereby automatically calibrates the RC Oscillator. The accuracy of this calibration is shown as Factory calibration in section "Clock Characteristics" on page 555. By changing the OSCCAL register (see "OSCCAL – Oscillator Calibration Value" on page 182) from Software, it is possible to get a higher calibration accuracy than by using the factory calibration. The accuracy of this calibration is shown as User calibration in section "Clock Characteristics" on page 555. ATmega256/128/64RFR2 178 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 When this Oscillator is used as the chip clock, the Watchdog Oscillator will still be used for the Watchdog Timer and for the Reset Time-out. For more information on the pre- programmed calibration value, see the section "Calibration Byte" on page 507. Table 11-3. Internal Calibrated RC Oscillator Operating Modes(1)(2) Frequency Range (MHz) CKSEL3:0 9.6 ... 22.4 0010 Notes: 2. The device is shipped with this option selected. When this Oscillator is selected, start-up times are determined by the SUT Fuses as shown in the following table. Table 11-4. Start-up times for the internal calibrated RC Oscillator clock selection Power Conditions Start-up Time from Power- Additional Delay from SUT1:0 down and Power-save Reset BOD enabled 6 CK 14CK 00 Fast rising power 6 CK 14CK + 4.0 ms 01 Slowly rising power 6 CK 14CK + 64 ms(1) 10 Reserved 11 Notes: 1. The device is shipped with this option selected 11.5 128 kHz Internal Oscillator The 128 kHz Internal Oscillator is an ultra-low power RC oscillator providing a clock of approximate 128 kHz nominal frequency. This clock may be selected as the system clock by programming the CKSEL Fuses to “0011” as shown in the following table. Table 11-5. 128 kHz Internal Oscillator Operating Modes(1) Nominal Frequency CKSEL3:0 128 kHz 0011 Notes: 1. Note that the 128 kHz oscillator is a very low power clock source, and is not designed for high accuracy When this clock source is selected, start-up times are determined by the SUT Fuses as shown in the following table. Table 11-6. Start-up Times for the 128 kHz Internal Oscillator Power Conditions Start-up Time from Power-down Additional Delay from SUT1:0 and Power-save Reset BOD enabled 6 CK 14CK 00 Fast rising power 6 CK 14CK + 4.1 ms 01 Slowly rising power 6 CK 14CK + 64 ms 10 Reserved 11 11.6 External Clock To drive the device from an external clock source, CLKI should be used as shown in Figure 11-2 on page 180. To run the device on an external clock, the CKSEL Fuses must be programmed to “0000”. 179 8393C-MCU Wireless-09/14

Figure 11-2. External Clock Drive Configuration external clock CLKI VSS When this clock source is selected, start-up times are determined by the SUT Fuses as shown in Table 11-8 below. Table 11-7. External Clock Frequency Nominal Frequency CKSEL3:0 0 – 16 MHz 0000 Table 11-8. Start-up Times for the External Clock Selection Power Conditions Start-up Time from Power-down Additional Delay from SUT1:0 and Power-save Reset BOD enabled 6 CK 14 CK 00 Fast rising power 6 CK 14 CK + 4.0 ms 01 Slowly rising power 6 CK 14 CK + 64 ms 10 Reserved 11 When applying an external clock, it is required to avoid sudden changes in the applied clock frequency to ensure stable operation of the microcontroller unit (MCU). A variation in frequency of more than 2% from one clock cycle to the next can lead to unpredictable behavior. If changes of more than 2% are required, ensure that the MCU is kept in Reset during the changes. Note that the System Clock Prescaler can be used to implement run-time changes of the internal clock frequency while still ensuring stable operation. Refer to section "System Clock Prescaler" on page 181 for details. 11.7 Transceiver Crystal Oscillator The integrated crystal oscillator for the radio transceiver generates a low-jitter 16MHz clock frequency. See sectio n "Crystal Oscillator (XOSC)" on page 86 for details about the operation of this oscillator. The AVR core and the radio transceiver operate synchronously on the same clock if this oscillator is selected. If the transceiver crystal oscillator is selected as AVR core clock, it remains enabled even if the radio transceiver is in SLEEP mode or its power reduction bit PRTRX24 is set. Table 11-9. Transceiver Crystal Clock Operating Mode Frequency Range (MHz) CKSEL3:0(1) 16 1111 - 0110 Notes: 1. All CKSEL fuse values have the same significance. ATmega256/128/64RFR2 180 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 Table 11-10. Start-up Times for the Transceiver Oscillator Clock Selection Power Conditions Start-up Time from Additional Delay CKSEL0 SUT1:0 Power-down and from Reset Power-save fast rising power 258 CK 14CK + 4.1 ms 0 00 slowly rising power 258 CK 14CK + 65 ms 0 01 BOD enabled 1K CK 14CK + 0 ms 0 10 fast rising power 1K CK 14CK + 4.1 ms 0 11 slowly rising power 1K CK 14CK + 65 ms 1 00 BOD enabled 16K CK 14CK + 0 ms 1 01 fast rising power 16K CK 14CK + 4.1 ms 1 10 slowly rising power 16K CK 14CK + 65 ms 1 11 11.8 Clock Output Buffer The device can output the system clock on the CLKO pin. To enable the output, the CKOUT Fuse has to be programmed. This mode is suitable when the chip clock is used to drive other circuits on the system. The clock also will be output during reset, and the normal operation of I/O pin will be overridden when the fuse is programmed. Any clock source, including the internal RC Oscillator, can be selected when the clock is output on CLKO. If the System Clock Prescaler is used, it is the divided system clock that is output. Special attention is required to prevent unwanted radiation from the connected PCB clock trace. Proper filtering c an help to suppress higher harmonics. 11.9 Timer/Counter Oscillator The device can operate the Timer/Counter2 as well as the MAC Symbol Counter from the 32.768 kHz crystal oscillator or an external clock source. See section "Application Circuits" on page 540 for the watch crystal connection and the asynchronous control register "ASSR – Asynchronous Status Register" on page 360 to get the 32.768 kHz crystal oscillator enabled by the control bit AS2. 11.10 System Clock Prescaler The ATmega256/128/64RFR2 has a system clock prescaler, and the system clock can be divided by setting the “CLKPR – Clock Prescale Register”. This feature can be used to decrease the system c lock frequency and the power consumption when the requirement for processing power is low. This can be used with all clock source options, and it will affect the clock frequency of the CPU and all synchronous peripherals. The clocks clk , clk , clk , and clk are divided by a factor as shown in CLKPR – I/O ADC CPU FLASH Clock Prescale Register on page 183. The prescaler clock division factor of the internal RC-Oscillator is different from all other clock sources, see register description CLKPR – Clock Prescale Register on page 183 Flash, EEPROM, Fuse- and Lock-bit programming is not allowed while using RC- Oscillator with CLKPS=0xF (clk = 16MHz). CPU When switching between prescaler settings, the System Clock Prescaler ensures that no glitches occur in the clock system. It also ensures that no intermediate frequency is higher than neither the clock frequency corresponding to the previous setting nor the clock frequency corresponding to the new setting. 181 8393C-MCU Wireless-09/14

The prescaler is implemented as a ripple counter running at the frequency of the undivided clock, which may be faster than the CPU's clock frequency. Hence, it is not possible to determine the state of the prescaler - even if it were readable. The exact time it takes to switch from one clock division to another cannot be exactly predicted. From the time the CLKPS values are written, it takes between t + t and t + 2t before 1 2 1 2 the new clock frequency is active. In this interval 2 active clock edges are produced. Here t is the previous clock period and t is the clock period corresponding to the new 1 2 prescaler setting. To avoid unintentional changes of clock frequency, a special write procedure must be followed to change the CLKPS bits: 1. Write the Clock Prescaler Change Enable (CLKPCE) bit to one and all other bits in CLKPR to zero. 2. Within four cycles, write the desired value to CLKPS while writing a zero to CLKPCE. Interrupts must be disabled when changing prescaler settings to make sure the write procedure is not interrupted. It is not required to change the prescaler setting of an existing software package written for an 8MHz internal RC oscillator. The change of the prescaler (additional 1:2 divider) is compensated by doubling the RC oscillator frequency of the ATmega256/128/64RFR2. 11.11 Register Description 11.11.1 OSCCAL – Oscillator Calibration Value Bit 7 6 5 4 3 2 1 0 NA ($66) CAL7 CAL6 CAL5 CAL4 CAL3 CAL2 CAL1 CAL0 OSCCAL Read/Write R/W R/W R/W R/W R/W R/W R/W R/W Initial Value 0 0 0 0 0 0 0 0 The Oscillator Calibration Register is used to trim the Calibrated Internal RC Oscillator to remove process variations from the oscillator frequency. A preprogrammed calibration value is automatically written to this register during chip reset, giving the Factory calibrated frequency. The application software can write this register to change the oscillator frequency. The oscillator can be calibrated to frequencies as specified in the section "Electrical Characteristics". Calibration outside that range is not guaranteed. Note that this oscillator is used to time EEPROM and Flash write accesses and these write times will be affected accordingly. The calibration to very high frequencies can cause EEPROM or Flash erase/write failures. The CAL7 bit determines the range of operation for the oscillator. Setting this bit to 0 gives the lowest frequency range, setting this bit to 1 gives the highest frequency range. The two frequency ranges are overlapping, in other words a setting of OSCCAL = 0x7F gives a higher frequency than OSCCAL = 0x80. The CAL 6..0 bits are used to tune the frequency within the selected range. A setting of 0x00 gives the lowest frequency in that range, and a setting of 0x7F gives the highest frequency in the range. • Bit 7:0 – CAL7:0 - Oscillator Calibration Tuning Value Table 11-11 CAL Register Bits Register Bits Value Description CAL7:0 0x00 Calibration value for lowest oscillator frequency ATmega256/128/64RFR2 182 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 Register Bits Value Description 0x7f End value of low frequency range calibration 0x80 Start value of high frequency range calibration 0xff Calibration value for highest oscillator frequency 11.11.2 CLKPR – Clock Prescale Register Bit 7 6 5 4 3 2 1 0 NA ($61) CLKPCE Res2 Res1 Res0 CLKPS3 CLKPS2 CLKPS1 CLKPS0 CLKPR Read/Write RW R R R RW RW RW RW Initial Value 0 0 0 0 0 0 0 0 • Bit 7 – CLKPCE - Clock Prescaler Change Enable The CLKPCE bit must be written to logic one to enable change of the CLKPS bits. The CLKPCE bit is only updated when the other bits in CLKPR are simultaneously written to zero. CLKPCE is cleared by hardware four cycles after it is written or when CLKPS bits are written. Rewriting the CLKPCE bit within this time-out period does neither extend the time-out period, nor clear the CLKPCE bit. • Bit 6:4 – Res2:0 - Reserved • Bit 3:0 – CLKPS3:0 - Clock Prescaler Select Bits These bits define the divisio n factor between the selected clock source and the internal system clock. These bits can be written run-time to vary the clock frequency to suit the application requirements. As the divider divides the master clock input to the MCU, the speed of all synchronous peripherals is reduced when a division factor is used. The division factors are given in the following table. Note that the factor is different when using the internal 16MHz RC oscillator as the clock source. The CKDIV8 Fuse determines the initial value of the CLKPS bits. If CKDIV8 is not programmed, the CLKPS bits will be reset to 0000. If CKDIV8 is programmed, CLKPS bits are reset to 0011 giving a division factor of 8 at start up. This feature should be used if the selected clock source has a higher frequency than the maximum frequency of the device at the present operating conditions. Note that any value can be written to the CLKPS bits regardless of the CKDIV8 Fuse setting. The Application software must ensure that a sufficient division factor is chosen if the selected clock source has a higher frequency than the maximum frequency of the device at the present operating conditions. The device is shipped with the CKDIV8 Fuse programmed. Table 11-12 CLKPS Register Bits Register Bits Value Description CLKPS3:0 0x0 Division factor 1 / RC-Oscillator 2 0x1 Division factor 2 / RC-Oscillator 4 0x2 Division factor 4 / RC-Oscillator 8 0x3 Division factor 8 / RC-Oscillator 16 0x4 Division factor 16 / RC-Oscillator 32 0x5 Division factor 32 / RC-Oscillator 64 0x6 Division factor 64 / RC-Oscillator 128 0x7 Division factor 128 / RC-Oscillator 256 183 8393C-MCU Wireless-09/14

Register Bits Value Description 0x8 Division factor 256 / RC-Oscillator 512 0x9 Reserved 0xA Reserved 0xB Reserved 0xC Reserved 0xD Reserved 0xE Reserved 0xF Division factor 1 only permitted for RC- Oscillator. Flash and EEPROM programming is not allowed. ATmega256/128/64RFR2 184 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 12 Power Management and Sleep Modes Sleep modes enable the application to shut down unused modules in the MCU, thereby saving power. The AVR microcontroller and the RF transceiver provide various sleep modes allowing the user to tailor the power consumption to the application’s requirements. 12.1 Deep-Sleep Mode When the microcontroller goes into Power-down or Power-save modes while the transceiver is in SLEEP state the device enters the Deep-Sleep mode. Sending the microcontroller to Power-down or Power-save is not allowed during the wake-up phase of the trans ceiver. The TRX24_AWAKE interrupt shall be used to wait for the transceiver is operational. The DVDD voltage regulator and the associated power chain will be switched off. Remaining running logic will then be supplied from the Low Leakage Voltage Regulator. Even the AVDD regulator will switched off. See chapter "Radio Transceiver" on page 190 how to disable the radio transceiver. Before entering Deep-Sleep mode the automatic calibration of the Low Leakage Voltage Regulator must be completed. This automatic calibration can be temporarily disabled for very short wake-up times. For details see "Low Leakage Voltage Regulator (LLVREG)" on page 194. The SRAM blocks use the data retention mode to preserve its content while saving leakage power. The Low Leakage Voltage Regulator has only limited driving capabilities, see section "Su pply Voltage and Leakage Control" on page 191 for details. Therefore the remaining running logic must be clocked with low frequencies only. The Deep-Sleep mode can be finished by a wake-up source shown by the Table 12-1 on page 186. Then DVDD voltage regulator and the associated power chain will be switched on. If the power-chain is completely enabled the standard AVR wake-up procedure continues (for det ails see chapter "Power-chain" on page 191). Note that the wake-up time from Deep-sleep mode is significantly longer than the wake- up time from the Power-down or Power-save mode because the entire power-chain will be restarted. Additionally note that if the ADC is enabled and/or running a conversion, while entering Deep-sleep mode, the ADC supply voltage is switched off. Therefore the ADC must be disabled before entering Deep-sleep mode to avoid an undefined ADC operation. If Timer/Counter 2 is not op erated asynchronously (i.e., AS2 in ASSR is 0), the timer is kept running in all sleep modes (see chapter Power-save Mode on page 188). This implies the main oscillator (as selected by the fuse configuration) is kept running. The power chain remains enabled and the device does not enter the Deep-Sleep mode. Assembly Code Example … ldi r16, (1<<SLPTR) sts TRXPR, r16 ; disable transceiver ldi r16, (2<<SM0) + (1<<SE) ; select power down mode out SMCR, r16 ; enable sleep mode sleep ; go to deep sleep … 185 8393C-MCU Wireless-09/14

C Code Example(1) #include <avr/sleep.h> int main(void) { … TRXPR = 1 << SLPTR; // sent transceiver to sleep set_sleep_mode(SLEEP_MODE_PWR_DOWN); // select power down mode sleep_enable(); sleep_cpu(); // go to deep sleep sleep_disable(); // executed after wake-up … } Notes: 1. See also section "About Code Examples" on page 7. The C-source code example uses high level functions from the library. Deep-Sleep mode will not be entered during on-chip debug sessions. Refer to section "Transceiver Pin Register TRXPR" on page 35 for a description of the functionality of the SLPTR bit. 12.2 AVR Microcontroller Sleep Modes In chapter "System Clock and Clock Options" on page 176 the different clock systems in the ATmega256/128/64RFR2, and their distribution were presented. Figure 11-1 on page 176 is helpful in selecting an appropriate sleep mode. The following table shows the different sleep modes an d their wake-up sources. Table 12-1. Active Clock Domains and Wake-up Sources in the Different Sleep Modes Active Clock Domains Oscillators Wake-up Sources SMloedepe clkCPU clkFLASH clkIO clkADC clkASY Main Clock-source Enabled Timer Oscillator Enabled INT7:0 and Pin Change TWI Address Match Timer/Counter2 SPM/EEPROM Ready ADC WDT Interrupt Other I/O Symbol Counter Transceiver Idle X X X X X(2) X X X X X X X X(4) X(4) ADCNRM X X X X(2) X(3) X X(2) X X X X(4) X(4) Power- X(3) X X X(4) X(4) down Power- X X(2) X(3) X X X X(4) X(4) save Standby (1) X X(3 ) X X X(4) X(4) Extended X(2) X X(2) X(3) X X X X(4) X(4) Standby Notes: 1. Only recommended with external crystal or resonator selected as clock source. 2. If Timer/Counter2 is running in asynchronous mode. 3. For INT7:4, only level interrupt. 4. The Symbol Counter and/or the Transceiver can wakeup the AVR if the Transceiver Oscillator is enabled (Transceiver not in SLEEP). ATmega256/128/64RFR2 186 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 To enter any of the sleep modes, the SE bit in in the SMCR register (see "SMCR – Sleep Mode Control Register" on page 196) must be written to logic one and a SLEEP instruction must be executed. The SM2, SM1, and SM0 bits in the SMCR Register select which sleep mode will be activated by the SLEEP instruction. See chapter "Register Description" on pa ge 196 for a summary. If an enabled interrupt occurs while the MCU is in a sleep mode, the MCU wakes up. The MCU is then halted for four cycles in addition to the start-up time, executes the interrupt routine, and resumes execution from the instruction following SLEEP. The contents of the Register File and SRAM are unaltered when the device wakes up from sleep. Note that SRAM data retention must be enabled in some sleep modes to preserve the memory contents (see section "SRAM with Data Retention" on page 193). If a reset occurs during sleep mode, the MCU wakes up and executes from the Reset Vector. 12.2.1 Idle Mode When the SM2:0 bits are written to 000 in the SMCR register, the SLEEP instruction makes the MCU enter Idle mode, stopping the CPU but allowing the SPI, USART, Analog Comparator, ADC, 2-wire Serial Interface, Timer/Counters, Watchdog, and the interrupt system to continue operating. This sleep mode basically halts clk and CPU clk , while allowing the other clocks to run. FLASH Idle mode enables the MCU to wake up from external triggered interrupts as well as internal ones like the Timer Overflow and USART Transmit Complete interrupts. If wake-up from the Analog Comparator interrupt is not required, the Analog Comparator can be powered down by setting the ACD bit in the Analog Comparator Control and Status Register – ACSR. This will reduce power consumption in Idle mode. If the ADC is enabled, a conversion starts automatically when this mode is entered. 12.2.2 ADC Noise Reduction Mode When the SM2:0 bits are written to 001, the SLEEP instruction makes the MCU enter ADC Noise Reduction mode (ADCNRM), stopping the CPU but allowing the ADC, the external interrupts, 2-wire Serial Interface address match, Timer/Counter2 and the Watchdog to continue operating (if enabled). This sleep mode basically halts clk , I/O clk , and clk , while allowing the other clocks to run. CPU FLASH This improves the noise environment for the ADC, enabling higher resolution measurements. If the ADC is enabled, a conversion starts automatically when this mode is entered. Apart form the ADC Conversion Complete interrupt, only an External Reset, a Watchdog System Reset, a Watchdog interrupt, a Brown-out Reset, a 2-wire serial interface interrupt, a T imer/Counter2 interrupt, an SPM/EEPROM ready interrupt, an external level interrupt on INT7:4 or a pin change interrupt can wakeup the MCU from ADC Noise Reduction mode. 12.2.3 Power-down Mode When the SM2:0 bits are w ritten to 010, the SLEEP instruction makes the MCU enter Power-down mode. In this mode, the 16 MHz crystal oscillator is stopped (if selected by CKSEL fuses), while the external interrupts, the 2-wire Serial Interface, and the Watchdog continue operating (if enabled). Only an External Reset, a Watchdog Reset, a Brown-out Reset, 2-wire Serial Interface address match, an external level interrupt on INT7:4, an external interrupt on INT3:0, a pin change interrupt, or a symbol counter interrupt can wake up the MCU. This sleep mode basically halts all generated clocks, allowing operation of asynchronous modules only. 187 8393C-MCU Wireless-09/14

Note that if a level triggered interrupt is used for wake-up from Power-down mode, the changed level must be held for some time to wake up the MCU. Refer to section "External Interrupts" on page 250 for details. When waking up from Pow er-down mode, there is a delay from the wake-up condition occurs until the wake-up becomes effective. This allows the clock to restart and become stable after have been stopped. The wake-up period is defined by the same CKSEL Fuses that define the Reset Time-out period, as described in chapter "System Clock and Clock Options" on page 176. 12.2.4 Power-save Mode When the SM2:0 bits are written to 011, the SLEEP instruction makes the MCU enter Power-save mode. This mo de is identical to Power-down, with one exception: If Timer/Counter2 is enabled, it will keep running during sleep. The device can wake up from either Timer Overflow or Output Compare event from Timer/Counter2 if the corresponding Timer/Counter2 interrupt enable bits are set in TIMSK2, and the Global Interrupt Enable bit in SREG is set. If Timer/Counter2 is not running, Power-down mode is recommended instead of Power-save mode. The Timer/Counter2 can be clocked both synchronously and asynchronously in Power- save mode. If the Timer/Counter2 is not using the asynchronous clock, the Timer/Counter Oscillator is stopped during sleep. If the Timer/Counter2 is not using the synchronous clock, the clock source is stopped during sleep. Note that even if the synchronous clock is running in Power-save, this clock is only available for the Timer/Counter2. Timer/Counter2 operation is described in detail in section "8-bit Timer/Counter2 with PWM and Asynchronous Operation" on page 341. 12.2.5 Standby Mode When the SM2:0 bits are 110 and the crystal oscillator of the radio transceiver is selected, the SLEEP instruction makes the MCU enter Standby mode. This mode is identical to Power-down with the exception that the Oscillator is kept running. From Standby mode, the device wakes up in six clock cycles. 12.2.6 Extended Standby Mode When the SM2:0 bits are 111 and the crystal oscillator of the radio transceiver is selected, the SLEEP instruction makes the MCU enter Extended Standby mode. This mode is identical to Power-save mode with the exception that the oscillator is kept running. From Extended Standby mode, the device wakes up in six clock cycles. 12.3 Power Reduction Register The Power Reduction Register (PRR), see "PRR0 – Power Reduction Register0" on page 197, "PRR1 – Power Reduction Register 1" on page 198 and "PRR2 – Power Reduction Register 2" on page 199, provide a method to stop the clock to individual peripherals to reduce power consumption. Note that when the clock for a peripheral is stopped, then: • The current state of the peripheral is frozen. • The associated registers can not be read or written. • Resources used by the peripheral (e.g. IO pins) will remain occupied. The peripheral unit should in most cases be disabled before stopping the clock. Waking up a module, which is done by clearing the bit in PRR, puts the module in the same state as before the shutdown. Exceptions are the SRAM blocks and the radio ATmega256/128/64RFR2 188 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 transceiver. The SRAM is shut down by a DRT switch and the radio transceiver is in reset state if its respective power reduction bit is set. Module shutdown can be used in Idle mode and Active mode to significantly reduce the overall power consumption. See chapter "Typical Characteristics" on page 567 for examples. In all other sleep modes, the clock is already stopped. 12.4 Minimizing Power Consumption There are several issues to consider when trying minimizing the power consumption in an AVR controlled system. In general, sleep modes should be used as much as possible, and the sleep mode should be selected so that as few as possible of the device’s functions are operating. All functions not needed should be disabled. In particular, the following mod ules may need special consideration when trying to achieve the lowest possible power consumption. 12.4.1 Analog to Digital Converter If enabled, the ADC will be enabled in all sleep modes. To save power, the ADC should be disabled before entering any sleep mode. Refer to chapter "ADC – Analog to Digital Converter" on page 444 for details on ADC operation. 12.4.2 Analog Comparator When entering Idle mode, the Analog Comparator should be disabled if not used. When entering ADC Noise Reduction mode the Analog Comparator should also be disabled. In other sleep modes, the Analog Comparator is automatically disabled. However, if the Analog Comparator is set up to use the Internal Voltage Reference as input, the Analog Comparator should be disabled in all sleep modes. Otherwise, the Internal Voltage Reference will be enabled, independent of sleep mode. Refer to "AC – Analog Comparator" on page 440 for details on how to configure the Analog Comparator. 12.4.3 Brown-out Detector If the Brown-out Detector is enabled by the BODLEVEL Fuses, it will be disabled in Deep-sleep mode. Refer to "Brown-out Detection" on page 211 for details on how to configure the Brown-out Detector. It is recommended to enable the Brown-out Detector. 12.4.4 Internal Voltage Reference The Internal Voltage Reference will be enabled when needed by the Brown-out Detection, the Analog Comparator or the ADC. If these modules are disabled as described in the sections ab ove, the internal voltage reference will be disabled and not consume power. When turned on again, the user must allow the reference to start up before the output is used. If the reference is kept on in sleep mode, the output can be used immediately. Refer to "Internal Voltage Reference" on page 212 for details on the start-up time. 12.4.5 Watchdog Timer If the Watchdog Timer is not needed in the application, the module should be turned off. If the Watchdog Timer is enabled, it will be enabled in all sleep modes, and hence, always consume power. In the deeper sleep modes, this will contribute significantly to the total current consumption. Refer to "Watchdog Timer" on page 213 for details on how to configure the Watchdog Timer. 189 8393C-MCU Wireless-09/14

12.4.6 Port Pins When entering a sleep mode, all port pins should be configured to use minimum power. The most important is then to ensure that no pins drive resistive loads. In sleep modes where both the I/O clock (clkI/O) and the ADC clock (clkADC) are stopped, the input buffers of the device will be disabled. This ensures that no power is consumed by the input logic when not needed. In some cases, the input logic is needed for detecting wake-up conditions, and it will then be enabled. Refer to the section "I/O-Ports" on page 219 for details on which pins are enabled. If the input buffer is enabled and the input signal is left floating or have an analog signal level close to DEVDD/2, the input buffer will use excessive power. For analog input pins, the digital input buffer should be disabled at all times. An analog signal level close to DEVD D/2 on an input pin can cause significant current even in active mode. Digital input buffers can be disabled by writing to the Digital Input Disable Registers DIDR1 and DIDR0. Refer to "DIDR1 – Digital Input Disable Register 1" on page 442 and "DIDR0 – Digital Input Disable Register 0" on page 469 for details. 12.4.7 On-chip Debug System If the On-chip debug system is enabled by the OCDEN Fuse and the chip enters sleep mode, the main clock source is enabled, and hence, always consumes power. In the deeper sleep modes, this will contribute significantly to the total current consumption. There are three alternative ways to disable the OCD system: • Disable the OCDEN Fuse. • Disable the JTAGEN Fuse. • Write one to the JTD bit in MCUCR. 12.4.8 Symbol Counter The Symbol Counter acts as a separate counter, which uses either the 16MHz clock from XTAL1/XTAL2 crystal pins or the clock from PG3/PG4 low frequency crystal pins. If the Symbol Counter mod ule is not used, it should be disabled, see section "MAC Symbol Counter" on page 157. 12.4.9 Radio Transceiver The radio transceiver module is automatically starting its state machine after power on. While the CPU is in any sleep mode, the radio transceiver remains active. This enables the radio transceiver to wakeup the MCU if a pending action is over (frame received or transmission completed). The radio transceiver will be inactive during sleep, if either the its power reduction bit PRT R X24 in register PRR1 is set or it is send into SLEEP mode, see "PRR1 – Power Reduction Register 1" on page 198 for details. After reactivation the 16MHz crystal oscillator is started first and afterwards the radio transceiver with TRX_OFF state. The radio transceiver is derived from a stand alone solution that was partly controlled by external pins. Now the ra dio transceiver is fully controlled by individual register bits. The radio transceiver has a separate reset signal. A radio transceiver reset is initiated by setting bit TRXRST in register TRXPR. This bit is self-resetting. The radio transceiver signal SLPTR can be controlled by the bit SLPTR in register TRXPR and is used to set the radio transceiver into SLEEP mode (assuming TRX_STATE is TRX_OFF). This bit has a multiple function, see section "Low-Power 2.4 GHz Transceiver" on page 32 for a detailed description of the radio transceiver. ATmega256/128/64RFR2 190 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 12.5 Supply Voltage and Leakage Control For battery applications using DEEP_SLEEP periods, the leakage current defines the system life time. Due to the typical strong temperature dependency of the leakage current, major contributors to the leakage budget are turned off: • Analog and digital voltage regulator, • Non-volatile memory (NVM), • SRAM, • Digital signal processor of the radio transceiver including AES engine. If the CPU uses one of the sleep modes “power-down” or “power-save”, the above mentioned blocks will be switched off by power switches. When the CPU wakes up, the blocks are switched on aga in. There are some additional exceptions (internal voltage regulator, SRAM, radio transceiver), see section "Power-chain" below . The supply voltage control is mainly hidden to the application, it is not necessary to configure the supply voltage control. Nevertheless some configurations can be done in order to get the maximum effect and the lowest sleep current, for details see section "SRAM with Data Retention" on page 193. 12.5.1 Power-chain The following figure shows the major dependencies of the power-chain and how the power switches are situated inside the chain. Figure 12-1. Power-chain connections powerchain_ ok power_control bandgap DVREG drt_switch drt_switch power_switch power_switch Radio LLVREG First SRAM Last SRAM NVM llvreg_ok Transceiver trx24_sleeps Startup and Wakeup from DEEP_SLEEP After power-on reset (POR) or wakeup from DEEP_SLEEP the power switches of the blocks will be enabled one after another (power-chained) to decrease current peaks. The blocks will be enabled in the following order: 1. Bandgap reference and voltage regulator, 2. Digital voltage regulator (DVREG) and low leakage voltage regulator (LLVREG), 3. first SRAM block (lower 4k bytes), 4. last SRAM block (upper 4k bytes), 5. Radio transceiver including AES engine, 6. Non-volatile memory. If the power-chain is completely enabled the standard AVR wake-up procedure continues. 191 8393C-MCU Wireless-09/14

Figure 12-2 shows the chained startup procedure after power up. The Figure 12-3 shows the startup from DEEP_SLEEP. A module is only switched on if it is not deselected by power reduction register (PRR1 or PRR2). This is possible for SRAM blocks and radio transceiver power switch. At the end of the startup, the pin RSTON is enabled. Depending of the currently enabled memory blocks (N ), the startup SRAM procedure takes different time. t = t + t + N ·t + 3·t + t STARTUP_TOTAL BG DVREG SRAM DRT_ON PWRSW_ON OSC_STARTUP The SRAM is organized in 4kByte blocks, the NVM in 128kByte blocks. Deselected SRAM blocks (by PRR2 register) reduce the wakeup time from DEEP_SLEEP. For further timing information see "Power Management Electrical Characteristics" on page 557. Figure 12-2. Timing visualization of power up RSTON startup startup DRT switch DRT switch DRT switch DRT switch power switch power switch oscillator POR bandgap DVREG SRAM #0 SRAM #1 SRAM #2 SRAM #3 radio trans. NVM startup tPOR tBG tDVREG tDRT_ON tDRT_ON tDRT_ON tDRT_ON tPWRSW_ON tPWRSW_ON tOSC_STARTUP tSTARTUP Figure 12-3. Timing visualization of wakeup from DEEP_SLEEP startup startup DRT switch DRT switch DRT switch DRT switch power switch power switch oscillator SLEEP bandgap DVREG SRAM #0 SRAM #1 SRAM #2 SRAM #3 radio trans. NVM startup tBG tDVREG tDRT_ON tDRT_ON tD RT_ON tDRT_ON tPWRSW_ON tPWRSW_ON tOSC_STARTUP tSTARTUP Sleep Six sleep modes are defined for the CPU. Disabling the power-chain and thus switching off of the above mentioned blocks makes only sense for the modes “power-down” and “power-save”. Also an enab led radio transceiver prevents the power-chain from being disabled. In order to disable the power-chain, one of the following conditions must fit: • The radio transceiver has to be disabled (power reduction register PRR1 bit PRTRX24). • The radio transceiver is sent into SLEEP mode (register TRXPR bit SLPTR). The SRAM blocks may be configured separately to decrease their leakage current (see section "SRAM with Data Retention" on page 193). The following table shows the different implemented sleep modes and the behavior of the power-chain depending on the current state of the radio transceiver. Table 12-2. Power states of microcontroller and radio transceiver AVR State Radi o Transceiver State Powerchain ON ON ON ON off (SLEEP or power reduction) ON off (1…6) ON ON off (1,4…6) off (SLEEP or power reduction) ON ATmega256/128/64RFR2 192 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 AVR State Radio Transceiver State Powerchain off (2,3) off (SLEEP or power reduction) off (7) DEEP SLEEP Notes: 1. Idle 2. Power Down 3. Power Save 4. ADC Noise Reduction Mode 5. Standby 6. Extended Standby 7. If the OCDEN fuse is programmed, the Power-chain is always on 12.5.2 SRAM with Data Retention It is necessary to prevent any data loss of the SRAM when setting the CPU in one of the DEEP_SLEEP modes. For that purpose the SRAM blocks will not be completely switched off if the power-chain is disabled. The supply voltage for any individual SRAM block is decreased to reduce its leakage current but guaranteeing its data retention. The SRAM memory is divided into 4kByte blocks. Each block can be fully switched off by setting the correspondent bit (PRRAM0 ... PRRAM3) in register PRR2 (see "PRR2 – Power Reduction Register 2" on page 199). This enables the application software to switch off unused SRAM memory to save power and to reduce leakage currents. Every SRAM block can be enabled again by resetting the respective bit (PRRAM0 ... PRRAM3) of register PRR2. For each SRAM block n the bit DRTSWOK of the corresponding register DRT RAMn shows the state of the DRT switch (logic high means SRAM block can be accessed). If the power-chain is switched off during deep-sleep modes, the content of the SRAM blocks must be sustained. To provide data retention and lowest leakage current, a data retention block controls the SRAM behavior during deep-sleep. Since the leakage current is dramatically depe n ding from the voltage of the SRAM, the supply voltage can be decreased by enabling the data retention mode DRT. Every SRAM block n is controlled by its assigned register DRTRAMn. The bit ENDRT enables the data retention mode during deep-sleep. If this bit is zero, the respective SRAM block is completely switched off. Table 12-3. SRAM behavior while in deep-sleep mode ENDRT Power-chain SRAM supply voltage 1 ON 1.8V (DVDD) 0 ON 1.8V (DVDD) 1 off Reduced 0 off Disconnected The lower 4-bit of the registe r DRTRAMn are reserved and should not be changed. The reset value of the DRT voltage settings are preprogrammed during the manufacturing process and need not to be changed. 12.5.3 Voltage Regulators (AVREG, DVREG) The main features of the Voltage Regulator blocks are: • Bandgap stabilized 1.8V supply for analog and digital domain; • Low dropout (LDO) voltage regulator; 193 8393C-MCU Wireless-09/14

• Configurable to use an external voltage regulator; The internal voltage regulators supply a stabilized voltage to the ATmega256/128/64RFR2. The AVREG provides the regulated 1.8V supply voltage for the analog section and the DVREG supplies the 1.8V supply voltage for the digital section. The DVREG is enabled during startup and is switched off if the power-chain is disabled. The AVREG is enabled only on request by either the A/D converter or the radio transceiver. A simplified schematic of the internal voltage regulator is shown in Figure 12-4 below. Figure 12-4. Simplified Schematic of AVREG/DVREG (D)EVDD Bandgap voltage 1.25V reference AVDD, DVDD The voltage regulators require bypass capacitors for stable operation. The value of the bypass capacitors determines their settling time. The bypass capacitors shall be placed as close as possible to the pins and shall be connected to ground with the shortest possible traces. The voltage regulators can be configured with the register VREG_CTRL. It is recommended to use the internal regulators but it is also possible to supply the low voltage domains by an external voltage supply. For this configuration the internal analog voltage regulator needs to be switched off by setting the register bit AVREG_EXT = 1 (see "VREG_CTRL – Voltage Regulator Control and Status Register" on page 128). The internal digital voltage regulator may not be switched off, an external voltage has to overdrive the internal voltage. A regulated external supply voltage of 1.8V must then be connected to the pins 13, 14 (DVDD) and pin 29 (AVDD). When turning on the external supply ensure a sufficiently long stabilization time before interacting with the ATmega256/128/64RFR2. The status bits AVDD_OK = 1 and DVDD_OK = 1 of register VREG_CTRL indicate an enabled and stable internal supply voltage. Reading value 0 indicates that the internal supply voltage is disabled or not yet settled to the final value. In case the ATmega256/128/64RFR2 is not supplied with a sufficient (D)EVDD and the digital voltage regulator output voltage is too low, a power on reset (POR) is initiated. 12.5.4 Low Leakage Voltage Regulator (LLVREG) The main digital voltage regulator (DVREG) will be switched off during the DEEP_SLEEP modes “power-down” and “power-save”. The Low Leakage Voltage Regulator will then keep the digital supply voltage to provide data retention. No application software control is required. During the active power states, when the main voltage regulator supplies the chip, the Low Leakage Voltage Regulator is digitally calibrated. Its output voltage is adjusted to match the output voltage of the main regulator. This fixed calibration result is stored and used when the chip enters a power-down state where the main regulator is switched off. ATmega256/128/64RFR2 194 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 Because the calibration setting is fixed, temperature and load current variations during the following DEEP_SLEEP period are not regulated out. Thus the output voltage may drift away from the target value. However the design guarantees that for allowed operating conditions the output voltage will stay within valid limits. After every wake-up a new calibration cycle is ini tiated. The output driving capability of the Low Leakage Voltage Regulator is limited. Its main purpose is to provide the leakage current of the connected analog and digital blocks. At least one full calibration cycle of the Low Leakage Voltage Regulator has to be completed before the power-chain can be disabled. Therefore if the CPU uses one of the DEEP_SLEEP modes “power down” or “power save”, the power-chain is not disabled before the Low Leakage Voltage Regulator completed this first calibration cycle. By default the LLVREG automatically starts the calibration after finishing the power-on reset and the wake-up/start-up procedures (see section "Low Leakage Voltage Regulator Control" below for a detailed description of the Low Leakage Voltage Regulator). Notes: 1. The LLVREG calibration will be inaccurate at a DEVDD supply voltage of 1.8V or lower. Therefore when operating the device at 1.8V the LLVREG calibration should be disabled and the register values of LLDRL and LLDRH should be set to 0x06 and 0x0f, respectively. 2. When waking up from Deep Sleep mode the LLVREG calibration starts after 4 clock cycles of the 128 kHz oscillator. If the device goes to sleep again earlier then the old calibration values will be used. 12.5.5 Low Leakage Voltage Regulator Control The three register LLCR, LLDRL and LLDRH allow the software to monitor the calibration process and to modify or correct the calibration results. The automatic calibration is the normal operation mode. It is an internal process that does not require any software interaction. Nevertheless the calibration is transparent for the user through LLCR, LLDRL and LLDRH (control and data register respectively). The register access requires a minimum system clock of at least the output frequency of the 128 kHz RC oscillator. The register access will not work if the system clock is slower. See chapter "System Clock and Clock Options" on page 176 for details on how to set the system clock frequency. Before the device can enter the sleep mode “power down” or “power save” the first calibration cycle of the Low Leakage Voltage Regulator must be completed to get valid data in LLDRL and LLDRH. The cycle time t (see Table 35-28 on page 558) is not CAL fixed. It depends on the temperature, manufacturing process and the frequency of the 128 kHz RC oscillator (independent of the Watchdog setting). Systems that require very short power-up times may temporarily disable the calibration process by setting bit LLENCAL to 0. After disabling the calibration the register values read from LLCR, LLDRL a nd LLDRH will be stable after at most five 64 kHz clock cycles (clock output of the 128 kHz RC oscillator divided by 2). The output voltage of the Low Leakage Voltage Regulator in sleep mode will be the most accurate if constantly calibrated to compensate for any environmental changes (e.g. temperature). However these changes may be slow enough to skip the calibration during some power-up cycles (e.g. calibrate only every 10th power-up time and use the old calibration results during all other times). 195 8393C-MCU Wireless-09/14

After the completion of the power-up process the calibration will start automatically if bit LLENCAL in the control register LLCR is 1 (default). The completion of a calibration cycle is indicated by the bit LLDONE in that same register. After the first cycle the calibration will continue to run until either the device goes into a sleep mode (“power down” or “power save”) or by setting the LLENCAL bit to 0. The output voltage of the Low Leakage Voltage Regulator is then defined by the values in the data register LLDRL and LLDRH and by the bits LLTCO and LLSHORT of the control register. Write access to the three register is granted when the bit LLENCAL is set to 0. The application software can then modify the calibration results. Higher values in the data register generate lower output voltages in the sleep modes. In general it is not recommended nor required to alter the automatically generated calibration result. The write access to the thr ee register must follow a certain scheme to be successful. The registers are implemented in the I/O clock domain while the logic of the Low Leakage Voltage Regulator runs with 64 kHz (clock output of the 128 kHz RC oscillator divided by 2). It takes at least two 64 kHz clock cycles before the data written to the register take effect in the regulator circuit. The write access from the software must be aware of this process. Furthermore the value of LLDRH must be written first followed by LLDRL. Otherwise the LLDRH write access will be ignored. The following Assembler code fragment shows a working example. Note the polling of bit 3 LLCAL of the LLCR register to verify the completion of the synchronization process. Assembly Code Example … clr r20 sts LLDRH,r18 ; write LLDRH first sts LLDRL,r19 ; write LLDRL second sts LLCR,r20 ; bit 0 cleared = disable automatic calibration ; poll LLCAL bit of LLCR to check if automatic calibration is ; turned of wait_calib: lds r20,LLCR sbrc r20,3 rjmp wait_calib ; not executed if bit 3 of LLCR is cleared … 12.6 Register Description 12.6.1 SMCR – Sleep Mode Control Register Bit 7 6 5 4 3 2 1 0 $33 ($53) Res3 Res2 Res1 Res0 SM2 SM1 SM0 SE SMCR Read/Write R R R R RW RW RW RW Initial Value 0 0 0 0 0 0 0 0 The Sleep Mode Control Register contains control bits for power management. • Bit 7:4 – Res3:0 - Reserved • Bit 3:1 – SM2:0 - Sleep Mode Select bit 2 These bits select between the five available sleep modes. Standby modes are only recommended for use with external crystals or resonators. ATmega256/128/64RFR2 196 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 Table 12-104 SM Register Bits Register Bits Value Description SM2:0 0x00 Idle 0x01 ADC Noise Reduction (If Available) 0x02 Power Down 0x03 Power Save 0x04 Reserved 0x05 Reserved 0x06 Standby 0x07 Extended Standby • Bit 0 – SE - Sleep Enable The SE bit must be written to logic one to make the MCU enter the sleep mode when the SLEEP instruction is executed. To avoid the MCU entering the sleep mode unless it is the programmers purpose, it is recommended to write the Sleep Enable (SE) bit to one just before the execution of the SLEEP instruction and to clear it immediately after waking up. 12.6.2 PRR0 – Power Reduction Register0 Bit 7 6 5 4 3 2 1 0 NA ($64) PRTWI PRTIM2 PRTIM0 PRPGA PRTIM1 PRSPI PRUSART0 PRADC PRR0 Read/Write R/W R/W R/W R/W R/W R/W R/W R/W Initial Value 0 0 0 0 0 0 0 0 • Bit 7 – PRTWI - Power Reduction TWI Writing a logic one to this bit shuts down the TWI by stopping the clock to the module. When waking up the TWI again, the TWI should be re initialized to ensure proper operation. • Bit 6 – PRTIM2 - Power Reduction Timer/Counter2 Writing a logic one to this bit shuts down the Timer/Counter2 module. When the Timer/Counter2 is enabled, operation will continue like before the shutdown. • Bit 5 – PRTIM0 - Power Reduction Timer/Counter0 Writing a logic one to this bit shuts down the Timer/Counter0 module. When the Timer/Counter0 is enabled, operation will continue like before the shutdown. • Bit 4 – PRPGA - Power Reduction PGA Writing a logic one to this bit reduced the power consumption of the programmable gain amplifier. The block is not turned off. Only the current levels in the amplifiers are reduced. Reducing the PGA current levels is only recommended for slow ADC clock frequencies. A new ADC conversion using the PGA should be delayed by a default start-up time after changing (setting or resetting) this bit. • Bit 3 – PRTIM1 - Power Reduction Timer/Counter1 Writing a logic one to this bit shuts down the Timer/Counter1 module. When the Timer/Counter1 is enabled, operation will continue like before the shutdown. • Bit 2 – PRSPI - Power Reduction Serial Peripheral Interface 197 8393C-MCU Wireless-09/14

Writing a logic one to this bit shuts down the Serial Peripheral Interface by stopping the clock to the module. When waking up the SPI again, the SPI should be re initialized to ensure proper operation. • Bit 1 – PRUSART0 - Po wer Reduction USART Writing a logic one to this bit shuts down the USART0 by stopping the clock to the module. When waking up the USART0 again, the USART0 should be reinitialized to ensure proper operation. • Bit 0 – PRADC - Power Reduction ADC Writing a logic one to this bit shuts down the ADC. The ADC must be disabled (reset ADEN bit in register ADCSRA) before shut down. The analog comparator cannot use the ADC input MUX when the ADC is shut down. 12.6.3 PRR1 – Power Reduction Register 1 Bit 7 6 5 4 3 2 1 0 NA ($65) Res PRTRX24 PRTIM5 PRTIM4 PRTIM3 PRUSART1 PRR1 Read/Write R RW RW RW RW RW Initial Value 0 0 0 0 0 0 • Bit 7 – Res - Reserved Bit This bit is reserved for future use. A read access always will return zero. A write access does not modify the content. • Bit 6 – PRTRX24 - Power Reduction Transceiver Writing a logic one to this bit shuts down the transceiver (disconnect from the power supply). In power-down and power-save modes the power-chain will be disabled when this bit is one. Writing a logic zero to this bit will re-enable the transceiver. • Bit 5 – PRTIM5 - Power Reduction Timer/Counter5 Writing a logic one to this bit shuts down the Timer/Counter5 module. When the Timer/Counter5 is enabled, operation will continue like before the shutdown. • Bit 4 – PRTIM4 - Power Reduction Timer/Counter4 Writing a logic one to this bit shuts down the Timer/Counter4 module. When the Timer/Counter4 is enabled, operation will continue like before the shutdown. • Bit 3 – PRTIM3 - Power Reduction Timer/Counter3 Writing a logic one to this bit shuts down the Timer/Counter3 module. When the Timer/Counter3 is enabled, operation will continue like before the shutdown. • Bit 0 – PRUSART1 - Power Reduction USART1 Writing a logic one to this bit shuts down the USART1 by stopping the clock to the module. When waking up the USART1 again, the USART1 should be reinitialized to ensure proper operation. ATmega256/128/64RFR2 198 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 12.6.4 PRR2 – Power Reduction Register 2 Bit 7 6 5 4 3 2 1 0 NA ($63) Res3 Res2 Res1 Res0 PRRAM3 PRRAM2 PRRAM1 PRRAM0 PRR2 Read/Write R R R R RW RW RW RW Initial Value 0 0 0 0 0 0 0 0 The Power Reduction Register PRR2 allows to individually disable all four SRAM blocks. Setting any PRRAM3:0 bit to one will completely switch off (disconnect from the power supply) the corresponding SRAM block. This enables the application to disable unused SRAM memory to save power. Every SRAM block can be re-enabled by reseting the appropriate PRRAM3:0 bit. • Bit 7:4 – Res3:0 - Reserved Bit This bit is reserved for future use. A read access always will return zero. A write access does not modify the content. • Bit 3 – PRRAM3 - Power Reduction SRAM 3 Setting this bit to one will disable the SRAM block 3. Setting this bit to zero will enable the SRAM block 3. • Bit 2 – PRRAM2 - Power Reduction SRAM 2 Setting this bit to one will disable the SRAM block 2. Setting this bit to zero will enable the SRAM block 2. • Bit 1 – PRRAM1 - Power Reduction SRAM 1 Setting this bit to one will di sable the SRAM block 1. Setting this bit to zero will enable the SRAM block 1. • Bit 0 – PRRAM0 - Power Reduction SRAM 0 Setting this bit to one will disable the SRAM block 0. Setting this bit to zero will enable the SRAM block 0. 12.6.5 TRXPR – Transceiver Pin Register Bit 7 6 5 4 3 2 1 0 NA ($139) Res3 Res2 Res1 Res0 ATBE TRXTST SLPTR TRXRST TRXPR Read/Write R R R R RW RW RW RW Initial Value 0 0 0 0 0 0 0 0 The register TRXPR allows to control basic actions of the radio transceiver like reset or state transitions. The register bit functionality is inherited from the external pins of the stand-alone radio transceiver. • Bit 7:4 – Res3:0 - Reser ved • Bit 3 – ATBE - Analog Test-bus Enable The analog test-bus can be enabled by setting this bit to one. The test-bus can only be activated in the test-mode. Internal analog signals are then available at the TSTOP, TSTON, TSIP and TSTIN pins. • Bit 2 – TRXTST - Transceiver Test-mode Enable The TRXTST bit enables the test-functionality of the transceiver. In addition the general device test-mode must be enabled by applying the appropriate test-signature. 199 8393C-MCU Wireless-09/14

• Bit 1 – SLPTR - Multi-purpose Transceiver Control Bit The bit SLPTR is a multi-functional bit to control transceiver state transitions. Dependent on the radio transceiver state, a rising edge of bit SLPTR causes the following state transitions: TRX_OFF => SLEEP (level sensitive), PLL_ON => BUSY_TX. Whereas the falling edge of bit SLPTR causes the following state transition: SLEEP => TRX_OFF (level sensitive). When the radio transceiver is in TRX_OFF state the microcontroller forces the transceiver to SLEEP by setting SLPTR = H. The Transceiver awakes when the microcontroller releases the bit SLPTR. In states PLL_ON and TX_ARET_ON, bit SLPTR is used as trigger input to initiate a TX transaction. Here SLPTR is sensitive on rising edge only. After initiating a state change by a rising edge at Bit SLPTR in radio transceiver states TRX_OFF, RX_ON or RX_AACK_ON, the radio transceiver remains in the new state as long as the pin is logical high and returns to the preceding state with the falling edge. • Bit 0 – TRXRST - Force Transceiver Reset The RESET state is used to set back the state machine and to reset all registers of the transceiver (except IRQ_MASK) to their default values. A reset forces the radio transceiver into the TRX_OFF state and resets all transceiver register to their default values. A reset is initiated with bit TRXRST = H. The bit is cleared automatically. During transceiver reset the microcontroller has to set the radio transceiver control bit SLPTR to the default value. 12.6.6 DRTRAM0 – Data Retention Configuration Register #0 Bit 7 6 5 4 3 2 1 0 NA ($135) Res1 Res0 DRTSWOK ENDRT DRTMP1 DRTMP0 DRTMN1 DRTMN0 DRTRAM0 Read/Write R R R RW RW RW RW RW Initial Value 0 0 0 0 0 0 0 0 The DRTRAM0 register con trols the behavior of SRAM block #0 (ATmega256RF block #0 and #1 in parallel) in the power-states "power-save" and "power-down". To prevent any data loss the SRAM will not completely disconnected from the power supply. Reserved bits will be overwritten during chip reset by the factory calibration and should not be modified. • Bit 7:6 – Res1:0 - Reserved • Bit 5 – DRTSWOK - DRT Switch OK This bit indicates the status of the SRAM power-switch. A logical one indicates that the SRAM supply voltage is fully available and the memory may be accessed normally. • Bit 4 – ENDRT - Enable SRAM Data Retention During "Deep-Sleep" each SRAM block will either be switched off or provides data retention of its memory content. This bit must set to one if data retention mode should be used. Otherwise the SR AM is switched off (disconnected from the power supply) and all its data are lost. • Bit 3:2 – DRTMP1:0 - Positive Data Retention Voltage Setting The bits DRTMP1:0 define the reduction of the positive supply voltage during data retention (DRT) mode. A preprogrammed calibration value is automatically written to this register during chip reset, giving the factory value. The DRT mode must be enabled by setting ENDRT high. Otherwise the SRAM is switched off (disconnected from the power supply) and all its data are lost. The typical voltage reduction levels are shown in the following table. ATmega256/128/64RFR2 200 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 Table 12-105 DRTMP Register Bits Register Bits Value Description DRTMP1:0 0 500 mV 1 425 mV 2 360 mV 3 < 5 mV • Bit 1:0 – DRTMN1:0 - Negative Data Retention Voltage Setting The bits DRTMN1:0 define the reduction of the negative supply voltage during data retention (DRT) mode. A preprogrammed calibration value is automatically written to this register during chip reset, giving the factory value. The DRT mode must be enabled by setting ENDRT high. Ot herwise the SRAM is switched off (disconnected from the power supply) and all its data are lost. The typical voltage reduction levels are shown in the following table. Table 12-106 DRTMN Register Bits Register Bits Value Description DRTMN1:0 0 525 mV 1 415 mV 2 325 mV 3 < 5 mV 12.6.7 DRTRAM1 – Data Retention Configuration Register #1 Bit 7 6 5 4 3 2 1 0 NA ($134) Res1 Res0 DRTSWOK ENDRT DRTMP1 DRTMP0 DRTMN1 DRTMN0 DRTRAM1 Read/Write R R R RW RW RW RW RW Initial Value 0 0 0 0 0 0 0 0 The DRTRAM1 register controls the behavior of SRAM block #1 (ATmega256RF block #2 and #3 in parallel) in the power-states "power-save" and "power-down". To prevent any data loss the SRAM will not completely disconnected from the power supply. Reserved bits will be overwritten during chip reset by the factory calibration and should not be modified. • Bit 7:6 – Res1:0 - Reserved • Bit 5 – DRTSWOK - DRT Switch OK This bit indicates the status of the SRAM power-switch. A logical one indicates that the SRAM supply voltage is fully available and the memory may be accessed normally. • Bit 4 – ENDRT - Enable SRAM Data Retention During "Deep-Sleep" each SRAM block will either be switched off or provides data retention of its memory content. This bit must set to one if data retention mode should be used. Otherwise the SRAM is switched off (disconnected from the power supply) and all its data are lost. • Bit 3:2 – DRTMP1:0 - Positive Data Retention Voltage Setting The bits DRTMP1:0 define the reduction of the positive supply voltage during data retention (DRT) mode. A preprogrammed calibration value is automatically written to this register during chip reset, giving the factory value. The DRT mode must be enabled by setting ENDRT high. Otherwise the SRAM is switched off (disconnected from the 201 8393C-MCU Wireless-09/14

power supply) and all its data are lost. The typical voltage reduction levels are shown in the following table. Table 12-107 DRTMP Register Bits Register Bits Value Description DRTMP1:0 0 500 mV 1 425 mV 2 360 mV 3 < 5 mV • Bit 1:0 – DRTMN1:0 - Negative Data Retention Voltage Setting The bits DRTMN1:0 define the reduction of the negative supply voltage during data retention (DRT) mode. A preprogrammed calibration value is automatically written to this register during chip reset, giving the factory value. The DRT mode must be enabled by setting ENDRT high. Otherwise the SRAM is switched off (disconnected from the power supply) and all its data are lost. The typical voltage reduction levels are shown in the following table. Table 12-108 DRTMN Register Bits Register Bits Value Description DRTMN1:0 0 525 mV 1 415 mV 2 325 mV 3 < 5 mV 12.6.8 DRTRAM2 – Data Retention Configuration Register #2 Bit 7 6 5 4 3 2 1 0 NA ($133) DISPC Res DRTSWOK ENDRT DRTMP1 DRTMP0 DRTMN1 DRTMN0 DRTRAM2 Read/Write RW R R RW RW RW RW RW Initial Value 0 0 0 0 0 0 0 0 The DRTRAM2 register controls the behavior of SRAM block #2 (ATmega256RF block #4 and #5 in parallel) in the power-states "power-save" and "power-down". To prevent any data loss the SRAM will not completely disconnected from the power supply. Reserved bits will be overwritten during chip reset by the factory calibration and should not be modified. • Bit 7 – DISPC - Disable Power-chain of SRAM 2 This bit allows to temporarily disable the power-chain of the SRAM block #2 (ATmega256RF block #4 and #5 in parallel) . In this way the block can be put into data retention (DRT) mode to measure the DRT voltage levels. See section "SRAM DRT Voltage Measurement" for d etails. • Bit 6 – Res - Reserved Bit This bit is reserved for future use. A read access always will return zero. A write access does not modify the content. • Bit 5 – DRTSWOK - DRT Switch OK This bit indicates the status of the SRAM power-switch. A logical one indicates that the SRAM supply voltage is fully available and the memory may be accessed normally. ATmega256/128/64RFR2 202 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 • Bit 4 – ENDRT - Enable SRAM Data Retention During "Deep-Sleep" each SRAM block will either be switched off or provides data retention of its memory content. This bit must set to one if data retention mode should be used. Otherwise the SRAM is switched off (disconnected from the power supply) and all its data are lost. • Bit 3:2 – DRTMP1:0 - Positive Data Retention Voltage Setting The bits DRTMP1:0 define the reduction of the positive supply voltage during data retention (DRT) mode. A preprogrammed calibration value is automatically written to this register during chip reset, giving the factory value. The DRT mode must be enabled by setting ENDRT high. Otherwise the SRAM is switched off (disconnected from the power supply) and all its data are lost. The typical voltage reduction levels are shown in the following table. Table 12-109 DRTMP Register Bits Register Bits Value Description DRTMP1:0 0 500 mV 1 425 mV 2 360 mV 3 < 5 mV • Bit 1:0 – DRTMN1:0 - Negative Data Retention Voltage Setting The bits DRTMN1:0 define the reduction of the negative supply voltage during data retention (DRT) mode. A preprogrammed calibration value is automatically written to this register during chip reset, giving the factory value. The DRT mode must be enabled by setting ENDRT high. Otherwise the SRAM is switched off (disconnected from the power supply) and all its data are lost. The typical voltage reduction levels are shown in the following table. Table 12-110 DRTMN Register Bits Register Bits Value Description DRTMN1:0 0 525 mV 1 415 mV 2 325 mV 3 < 5 mV 12.6.9 DRTRAM3 – Data Retention Configuration Register #3 Bit 7 6 5 4 3 2 1 0 NA ($132) Res1 Res0 DRTSWOK ENDRT DRTMP1 DRTMP0 DRTMN1 DRTMN0 DRTRAM3 Read/Write R R R RW RW RW RW RW Initial Value 0 0 0 0 0 0 0 0 The DRTRAM3 register controls the behavior of SRAM block #3 (ATmega256RF block #6 and #7 in parallel) in the power-states "power-save" and "power-down". To prevent any data loss the SRAM will not completely disconnected from the power supply. Reserved bits will be overwritten during chip reset by the factory calibration and should not be modified. • Bit 7:6 – Res1:0 - Reserved • Bit 5 – DRTSWOK - DRT Switch OK 203 8393C-MCU Wireless-09/14

This bit indicates the status of the SRAM power-switch. A logical one indicates that the SRAM supply voltage is fully available and the memory may be accessed normally. • Bit 4 – ENDRT - Enable SRAM Data Retention During "Deep-Sleep" each SRAM block will either be switched off or provides data retention of its memory content. This bit must set to one if data retention mode should be used. Otherwise the SRAM is switched off (disconnected from the power supply) and all its data are lost. • Bit 3:2 – DRTMP1:0 - Positive Data Retention Voltage Setting The bits DRTMP1:0 define the reduction of the positive supply voltage during data retention (DRT) mode. A preprogrammed calibration value is automatically written to this register during chip reset, giving the factory value. The DRT mode must be enabled by setting ENDRT high. Otherwise the SRAM is switched off (disconnected from the power supply) and all its data are lost. The typical voltage reduction levels are shown in the following table. Table 12-111 DRTMP Register Bits Register Bits Value Description DRTMP1:0 0 500 mV 1 425 mV 2 360 mV 3 < 5 mV • Bit 1:0 – DRTMN1:0 - Negative Data Retention Voltage Setting The bits DRTMN1:0 define the reduction of the negative supply voltage during data retention (DRT) mode. A preprogrammed calibration value is automatically written to this register during chip reset, giving the factory value. The DRT mode must be enabled by setting ENDRT high. Otherwise the SRAM is switched off (disconnected from the power supply) and all its data are lost. The typical voltage reduction levels are shown in the following table. Table 12-112 DRTMN Register Bits Register Bits Value Description DRTMN1:0 0 525 mV 1 415 mV 2 325 mV 3 < 5 mV 12.6.10 LLCR – Low Leakage Voltage Regulator Control Register Bit 7 6 5 4 3 2 1 0 NA ($12F) Res1 Res0 LLDONE LLCOMP LLCAL LLTCO LLSHORT LLENCAL LLCR Read/Write R R R R R RW RW RW Initial Value 0 0 0 0 0 0 0 1 This register allows to monitor and to control the calibration process of the low-leakage voltage regulator. The automatic calibration is the normal operation mode. However, certain circumstances may require to disable this automatic process for instance to save power-up time. The results of the automatic calibration can also be modified when required by the application for instance to get a higher or lower output voltage. ATmega256/128/64RFR2 204 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 • Bit 7:6 – Res1:0 - Reserved Bit This bit is reserved for future use. A read access always will return zero. A write access does not modify the content. • Bit 5 – LLDONE - Calibr ation Done This bit indicates the last state of the calibration algorithm. The data register contents is updated with new calibration data after the bit changed to 1. The bit will only be high for one 64kHz clock period, because a new calibration loop is started automatically. • Bit 4 – LLCOMP - Comparator Output This bit indicates the output state of the comparator of the low-leakage voltage regulator. In this way the calibration progress can be directly monitored for debug purposes. The state of the bit changes at most every 64kHz clock period. • Bit 3 – LLCAL - Calibration Active This bit indicates that the automatic calibration is in progress. The analog part of the calibration circuit is powered up if the bit is 1. • Bit 2 – LLTCO - Temperature Coefficient of Current Source This bit shows the status of the selection of the temperature coefficient. The state of the bit is updated in the course of the automatic calibration. A valid value is present after the LLDONE bit is 1 for the first time. Write access is only enabled when the automatic calibration is turned off (LLENCAL is 0). This bit should not be changed without further information. • Bit 1 – LLSHORT - Short Lower Calibration Circuit This bit shows the status of the short switch for the lower calibration circuit. The state of the bit is updated in the co urse of the automatic calibration. A valid value is present after the LLDONE bit is 1 for the first time. If this bit is set to 1 register LLDRL has no function. Write access is only possible when the automatic calibration is turned off (LLENCAL is 0). This bit should not be changed without further information. • Bit 0 – LLENCAL - Enable Automatic Calibration This bit enables the automatic calibration. The automatic calibration runs if the state of the bit is 1. Write access to the two data register and the bits LLSHORT and LLTCO is then denied. If the state of LLENCAL is 0 then the calibration algorithm is stopped and the output voltage of the low-leakage voltage regulator is defined by the values in the two data register LLDRL and LLDRH and by the bits LLSHORT and LLTCO. 12.6.11 LLDRH – Low Leakage Voltage Regulator Data Register (High-Byte) Bit 7 6 5 4 3 2 1 0 NA ($131) Res2 Res1 Res0 LLDRH4 LLDRH3 LLDRH2 LLDRH1 LLDRH0 LLDRH Read/Write R R R RW RW RW RW RW Initial Value 0 0 0 0 0 0 0 0 The high-byte of the calibration data can be accessed through this register. Write access is only enabled when the bit LLENCAL of the LLCR register is 0. Then the data bits LLDRH4:0 directly control the output voltage of the low-leakage voltage regulator. Higher numbers generate lower voltages. If the bit LLENCAL is 1 then the results of the automatic calibration are stored. • Bit 7:5 – Res2:0 - Reserved These bits are reserved for future use. 205 8393C-MCU Wireless-09/14

• Bit 4:0 – LLDRH4:0 - High-Byte Data Register Bits Value of the high-byte calibration result Table 12-113 LLDRH Register Bits Register Bits Value Description LLDRH4:0 0x00 Calibration limit for fast process corner/high output voltage 0x10 Calibration limit for slow process corner/low output voltage 12.6.12 LLDRL – Low Leakage Voltage Regulator Data Register (Low-Byte) Bit 7 6 5 4 3 2 1 0 NA ($130) Res3 Res2 Res1 Res0 LLDRL3 LLDRL2 LLDRL1 LLDRL0 LLDRL Read/Write R R R R RW RW RW RW Initial Value 0 0 0 0 0 0 0 0 The low-byte of the calibration data can be accessed through this register. Write access is only enabled when the bit LLENCAL of the LLCR register is 0. Then the data bits LLDRL3:0 directly control the output voltage of the low-leakage voltage regulator. Higher numbers generate lower voltages. The contents of this register is meaningless when the bit LLSHORT of the LLCR register is 1. If the bit LLENCAL is 1 then the results of the automatic calibration are stored. • Bit 7:4 – Res3:0 - Rese rved These bits are reserved for future use. • Bit 3:0 – LLDRL3:0 - Low-Byte Data Register Bits Value of the low-byte calibration result Table 12-114 LLDRL Regis ter Bits Register Bits Value Description LLDRL3:0 0x00 Calibration limit for fast process corner/high output voltage 0x08 Calibration limit for slow process corner/low output voltage 12.6.13 DPDS0 – Port Driver Strength Register 0 Bit 7 6 5 4 3 2 1 0 NA ($136) PFDRV1 PFDRV0 PEDRV1 PEDRV0 PDDRV1 PDDRV0 PBDRV1 PBDRV0 DPDS0 Read/Write RW RW RW RW RW RW RW RW Initial Value 0 0 0 0 0 0 0 0 The output driver strength can be set individually for each digital I/O port. The following tables show output current levels for a typical supply voltage of DEVDD = 3.3V. Refer to section "Electrical Characteristics" for details. • Bit 7:6 – PFDRV1:0 - Driver Strength Port F ATmega256/128/64RFR2 206 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 Table 12-115 PFDRV Register Bits Register Bits Value Description PFDRV1:0 0 2 mA 1 4 mA 2 6 mA 3 8 mA • Bit 5:4 – PEDRV1:0 - Driver Strength Port E Table 12-116 PEDRV Register Bits Register Bits Value Description PEDRV1:0 0 2 mA 1 4 mA 2 6 mA 3 8 mA • Bit 3:2 – PDDRV1:0 - Driver Strength Port D Table 12-117 PDDRV Register Bits Register Bits Value Description PDDRV1:0 0 2 mA 1 4 mA 2 6 mA 3 8 mA • Bit 1:0 – PBDRV1:0 - Dr iver Strength Port B Table 12-118 PBDRV Register Bits Register Bits Value Description PBDRV1:0 0 2 mA 1 4 mA 2 6 mA 3 8 mA 12.6.14 DPDS1 – Port Driver Strength Register 1 Bit 7 6 5 4 3 2 1 0 NA ($137) Res5 Res4 Res3 Res2 Res1 Res0 PGDRV1 PGDRV0 DPDS1 Read/Write R R R R R R RW RW Initial Value 0 0 0 0 0 0 0 0 The output driver strength can be set individually for each digital I/O port. The following table shows output current levels for a typical supply voltage of DEVDD = 3.3V. Refer to section "Electrical Characteristics" for details. • Bit 7:2 – Res5:0 - Reserved • Bit 1:0 – PGDRV1:0 - Driver Strength Port G Driver strength can be set for port G except the port pins PG3 and PG4. The leakage current of the ports PG3 and PG4 is reduced. 207 8393C-MCU Wireless-09/14

Table 12-119 PGDRV Register Bits Register Bits Value Description PGDRV1:0 0 2 mA 1 4 mA 2 6 mA 3 8 mA ATmega256/128/64RFR2 208 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 13 System Control and Reset 13.1 Resetting the AVR During reset, all I/O Registers are set to their initial values, and the program starts execution from the Reset Vector. The instruction placed at the Reset Vector must be a JMP – Absolute Jump – instruction to the reset handling routine. If the program never enables an interrupt source, the Interrupt Vectors are not used, and regular program code can be placed at these locations. This is also the case if the Reset Vector is in the Application section while the Interrupt Vectors are in the Boot section or vice versa. The circuit diagram in Figure 13-1 on page 210 shows the reset logic."System and Reset Characteristics" on page 556 defines the electrical parameters of the reset circuitry. The I/O ports of the AVR are immediately reset to their initial state when a reset source goes active. This does not require any clock source to be running. After all reset sources have gone inactive, a delay counter is invoked, stretching the internal reset. This allows the power to reach a stable level before normal operation starts. The time-out period of the delay counter is defined by the user through the SUT and CKSEL Fuses. The different selections for the delay period are presented in "Clock Sources" on page 177. 13.2 Reset Sources The ATmega256/128/64RFR2 has five sources of reset: • Power-on Reset. The MCU is reset when the supply voltage is below the Power-on Reset threshold (V ). POT • External Reset. The MCU is reset when a low level is present on the RSTN pin for longer than the minimum pulse length. • Watchdog Reset. The MCU is reset when the Watchdog Timer period expires and the Watchdog is enabled. • Brown-out Reset. The MCU is reset when the supply voltage EVDD is below the Brown-out Reset threshold (V ) and the Brown-out Detector is enabled. BOT • JTAG AVR Reset. The MCU is reset as long as there is a logic one in the Reset Register, one of the scan chains of the JTAG system. Refer to the section "IEEE 1149.1 (JTAG) Boundary-scan" on page 478 for details. 209 8393C-MCU Wireless-09/14

Figure 13-1. Reset Logic DATABUS MCU Status Register (MCUSR) FFFFF RRRRR EVDD Brown-out BOPOEXTWDJT BODLEVEL[2..0] Reset Circuit DEVDD Power-on Reset Circuit Pull-upResistor ET S E RSTN FSILPTIKEER Reset Circuit S Q AL R T N SE R ER E T JTRAeGg iRsteesret WaTticmhedrog ER R IN T N U O C Watchdog Oscillator Clock CK Delay Counters Generator TIMEOUT CKSEL[3:0] SUT[1:0] 13.2.1 Power-on Reset A Power-on Reset (POR) pulse is generated by a dynamic, on-chip detection circuit. The POR is active when DEVDD is rising. The electrical characteristics are defined in "System and Reset Characteristics" on page 556. The POR circuit can be used to trigger the start-up reset. To detect a failure in the supply voltage (e.g. a voltage drop) the brown-own detector sho uld be used. A Power-on Reset (POR) circuit ensures that the device is reset from Power-on. Reaching the Power-on Reset threshold voltage invokes the delay counter, which determines how long the device is kept in RESET after the DEVDD rise. The RESET signal is activated again without any delay, when DEVDD decreases below the detection level. Figure 13-2. MCU Start-up, RSTN Tied to DEVDD DEVDD VPOT RSTN VRST tTOUT TIME-OUT INTERNAL RESET ATmega256/128/64RFR2 210 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 Figure 13-3. MCU Start-up, RSTN Extended Externally V VCC POT RSTN VRST tTOUT TIME-OUT INTERNAL RESET 13.2.2 External Reset An External Reset is generated by a low level on the RSTN pin. Reset pulses longer than the minimum pulse width (see "System and Reset Characteristics" on page 556) will generate a reset, even if the clock is not running. Shorter pulses are not guaranteed to generate a reset. When the applied signal reaches the Reset Threshold Voltage – VRST – on its positive edge, t he delay counter starts the MCU after the Time-out period – t – has expired. TOUT Figure 13-4. Reset During Operation DEVDD RSTN VRST tTOUT TIME-OUT INTERNAL RESET 13.2.3 Brown-out Detection ATmega256/128/64RFR2 has an On-chip Brown-out Detection (BOD) circuit for monitoring the EVDD level during operation by comparing it to a fixed trigger level. The trigger level for the BOD can be selected by the BODLEVEL Fuses. The trigger level has a hysteresis to ensure spike free Brown-out Detection. The hysteresis on the detection level should be interpreted as V = V + V /2 and V = V - BOT+ BOT HYST BOT- BOT V /2. HYST When the BOD is enabled, and EVDD decreases to a value below the trigger level (V in Figure 13-5 on page 212), the Brown-out Reset is immediately activated. When BOT- EVDD increases above the trigger level (V in Figure 13-5 on page 212), the delay BOT+ counter starts the MCU after the Time-out period t has expired. TOUT The BOD circuit will only de tect a drop in EVDD if the voltage stays below the trigger level for longer than t given in "System and Reset Characteristics" on page 556. BOD 211 8393C-MCU Wireless-09/14

Figure 13-5. Brown-out Reset During Operation EVDD VBOT- VBOT+ RSTN tTOUT TIME-OUT INTERNAL RESET 13.2.4 Watchdog Reset When the Watchdog times out, it will generate a short reset pulse of one CK cycle duration. On the falling edge of this pulse, the delay timer starts counting the Time-out period t . See "Watchdog Timer" on page 213. for details on operation of the TOUT Watchdog Timer. Figure 13-6. Watchdog Reset During Operation DEVDD RSTN 1 CK Cycle WDT TIME-OUT RESET tTOUT TIME-OUT INTERNAL RESET 13.3 Internal Voltage Reference ATmega256/128/64RFR2 features an internal bandgap reference. This reference is used for Brown-out Detection, and it can be used as an input to the Analog Comparator or the ADC. Voltage Reference Enable Signals and Start-up Time The voltage reference has a start-up time that may influence the way it should be used. The start-up time is given in "System and Reset Characteristics" on page 556. To save power, the reference is not always turned on. The reference is on during the following situations: 1. When the BOD is enable d (by programming the BODLEVEL [2:0] Fuse). 2. When the bandgap reference is connected to the Analog Comparator (by setting the ACBG bit in ACSR). 3. When the ADC is enabled. Thus, when the BOD is not enabled, after setting the ACBG bit or enabling the ADC, the user must always allow the reference to start up before the output from the Analog Comparator or ADC is used. To reduce power consumption in Power-down mode, the user can avoid the three conditions above to ensure that the reference is turned off before entering Power-down mode. ATmega256/128/64RFR2 212 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 13.4 Watchdog Timer 13.4.1 Features • Clocked from separate On-chip Oscillator • 3 Operating modes - Interrupt - System Reset - Interrupt and System Reset • Selectable Time-out period from 16ms to 8s • Possible Hardware fuse Watchdog always on (WDTON) for fail-safe mode Figure 13-7. Watchdog Timer 128kHz OSCILLATOR KKKKKKKKKK 2486248624 OSC/OSC/ OSC/OSC/1OSC/3OSC/6SC/12SC/25SC/51C/102 OOOS O WDP0 WDP1 WATCHDOG WDP2 RESET WDP3 WDE MCU RESET WDIF INTERRUPT WDIE 13.4.2 Overview ATmega256/128/64RFR2 has an Enhanced Watchdog Timer (WDT). The WDT is a timer counting cycles of a separate on-chip 128 kHz oscillator. The WDT gives an interrupt or a system reset when the counter reaches a given time-out value. In normal operation mode, it is required that the system uses the WDR -Watchdog Timer Reset - instruction to restart the counter before the time-out value is reached. If the system doesn't restart the counter, a n interrupt or system reset will be issued. In Interrupt mode, the WDT gives an interrupt when the timer expires. This interrupt can be used to wake the device from sleep-modes, and also as a general system timer. One example is to limit the maximum time allowed for certain operations, giving an interrupt when the operation has run longer than expected. In System Reset mode, the WDT gives a reset when t h e timer expires. This is typically used to prevent system hang-up in case of runaway code. The third mode, Interrupt and System Reset mode, combines the other two modes by first giving an interrupt and then switch to System Reset mode. This mode will for instance allow a safe shutdown by saving critical parameters before a system reset. The Watchdog always on (WDTON) fuse, if programmed, will force the Watchdog Timer to System Reset mode. With the fuse programmed the System Reset mode bit (WDE) and Interrupt mode bit (WDIE) are locked to 1 and 0 respectively. To further ensure 213 8393C-MCU Wireless-09/14

program security, alterations to the Watchdog set-up must follow timed sequences. The sequence for clearing WDE and changing time-out configuration is as follows: 1. In the same operation, write a logic one to the Watchdog change enable bit (WDCE) and WDE. A logic one m ust be written to WDE regardless of the previous value of the WDE bit. 2. Within the next four clock cycles, write the WDE and Watchdog prescaler bits (WDP) as desired, but with the WDCE bit cleared. This must be done in one operation. The following code example shows one assembly and one C function for turning off the Watchdog Timer. The example assumes that interrupts are controlled (e.g. by disabling interrupts globally) so that no interrupts will occur during the execution of these functions. Assembly Code Example, Disable Watchdog Timer(1) WDT_off: ; Turn off global interrupt cli ; Reset Watchdog T imer wdr ; Clear WDRF in MCUSR in r16, MCUSR andi r16, (0xff & (0<<WDRF)) out MCUSR, r16 ; Write logical one to WDCE and WDE ; Keep old prescal er setting to prevent unintentional time-out lds r16, WDTCSR ori r16, (1<<WDCE) | (1<<WDE) sts WDTCSR, r16 ; Turn off WDT ldi r16, (0<<WDE) sts WDTCSR, r16 ; Turn on global interrupt sei ret C Code Example, Disable Watchdog Timer (1) void WDT_off(void) { disable_interrupt(); watchdog_reset(); /* Clear WDRF in MCUSR*/ MCUSR &= ~(1<<WDRF); /* Write logical one to WDCE and WDE */ /* Keep old prescaler setting to prevent unintentional time-out */ WDTCSR |= (1<<WDCE) | (1<<WDE); /* Turn off WDT */ WDTCSR = 0x00; __enable_interrupt(); } ATmega256/128/64RFR2 214 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 Note: 1. The example code assumes that the part specific header file is included. If the Watchdog is accidentally enabled, for example by a runaway pointer or brown-out condition, the device will be reset and the Watchdog Timer will stay enabled. If the code is not set up to handle the Watchdog, this might lead to an eternal loop of time-out resets. To avoid this situation, the application software should always clear the Watchdog System Reset Flag (WDRF) and the WDE control bit in the initialization routine, even if the Watchdog is not in use. The following code example shows one assembly and one C function for changing the time-out value of the Watchdog Timer. Assembly Code Example, Prescaler Change(1,2) WDT_Prescaler_Change : ; Turn off global interrupt cli ; Reset Watchdog Timer wdr ; Start timed sequence lds r16, WDTCSR ori r16, (1<<WDCE) | (1<<WDE) sts WDTCSR, r16 ; --Got four cycles to set the new values from here – ; Set new prescaler(time-out) value = 64K cycles (~0.5 s) ldi r16, (1<<WDE) | (1<<WDP2) | (1<<WDP0) sts WDTCSR, r16 ; --Finished setting new values, used 2 cycles – ; Turn on global interrupt sei ret C Code Example, Prescaler Change(1,2) void WDT_Prescaler_Change(void) { __disable_interrupt(); __watchdog_reset(); /* Start timed sequence */ WDTCSR |= (1<<WDCE) | (1<<WDE); /* Set new prescaler(time-out) value = 64K cycles (~0.5 s) */ WDTCSR = (1<<WDE) | (1<<WDP2) | (1<<WDP0); __enable_interrupt(); } Note: 1. The example code assumes that the part specific header file is included. 2. The Watchdog Timer should be reset before any change of the WDP bits, since a change in the WDP bits can result in a time-out when switching to a shorter time-out period. When using the Watchdog Timer in Interrupt Mode the WDIE bit must be used as shown in the following code example. 215 8393C-MCU Wireless-09/14

Assembly Code Example, Interrupt Mode(1,2) WDT_Interrupt_Mode: ; Turn off global interrupt cli ; Reset Watchdog Timer wdr ; Start timed sequence, use WDCE and WDE bits ldi r16, (1<<WDCE) | (1<<WDE) sts WDTCSR, r16 ; --Got four cycles to set the new values from here – ; Use WDIE bit to set new time-out value (64K cycles ~0.5 s) ldi r16, (1<<WDIF) | (1<<WDIE) | (1<<WDP2) | (1<<WDP0) sts WDTCSR, r16 ; --Finished setting new values, used 2 cycles – ; Turn on global interrupt sei ret C Code Example, Interrupt Mode(1,2) void WDT_Interrupt_Mode(void) { __disable_interrupt(); __watchdog_reset(); /* Start timed sequence, use WDCE and WDE bits*/ WDTCSR = (1<<WDCE) | (1<<WDE); /* Use WDIE bit to set time-out value (64k cycles ~0.5 s) */ WDTCSR = (1<<WDIF) | (1<<WDIE) | (1<<WDP2) | (1<<WDP0); __enable_interrupt(); } Note: 1. The example code assumes that the part specific header file is included. 2. The Watchdog Timer should be reset before any change of the WDP bits, since a change in the WDP bits can result in a time-out when switching to a shorter time-out period. To clear any pending old Watchdog interrupt the WDIF bit is written to one together with the WDIE bit. 13.5 Register Description 13.5.1 MCUSR – MCU Status Register Bit 7 6 5 4 3 2 1 0 $34 ($54) Res2 Res1 Res0 JTRF WDRF BORF EXTRF PORF MCUSR Read/Write R R R RW R/W R/W R/W R/W Initial Value 0 0 0 0 0 0 0 0 The MCU Status Register provides information on which reset source caused an MCU reset. To make use of the Reset Flags to identify a reset condition, the user should read and then Reset the MCUSR as early as possible in the program. If the register is ATmega256/128/64RFR2 216 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 cleared before another reset occurs, the source of the reset can be found by examining the Reset Flags. Note, after power on the bit EXTRF has to be ignored. • Bit 7:5 – Res2:0 - Reserved • Bit 4 – JTRF - JTAG Re s et Flag This bit is set if a reset is being caused by a logic one in the JTAG Reset Register selected by the JTAG instruction AVR_RESET. This bit is reset by a Power-on Reset, or by writing a logic zero to the flag. • Bit 3 – WDRF - Watchdog Reset Flag This bit is set if a Watchdog Reset occurs. The bit is reset by a Power-on Reset, or by writing a logic zero to the flag. • Bit 2 – BORF - Brown-o ut Reset Flag This bit is set if a Brown-out Reset occurs. The bit is reset by a Power-on Reset, or by writing a logic zero to the flag. • Bit 1 – EXTRF - External Reset Flag This bit is set if an External Reset occurs. The bit is reset by a Power-on Reset, or by writing a logic zero to the flag. • Bit 0 – PORF - Power-on Reset Flag This bit is set if a Power-on Reset occurs. The bit is reset only by writing a logic zero to the flag. 13.5.2 WDTCSR – Watchdog Timer Control Register Bit 7 6 5 4 3 2 1 0 NA ($60) WDIF WDIE WDP3 WDCE WDE WDP2 WDP1 WDP0 WDTCSR Read/Write RW RW RW RW RW RW RW RW Initial Value 0 0 0 0 0 0 0 0 • Bit 7 – WDIF - Watchdog Timeout Interrupt Flag This bit is set when a time-out occurs in the Watchdog Timer and the Watchdog Timer is configured for interrupt. WDIF is cleared by hardware when executing the corresponding interrupt handling vector. Alternatively, WDIF is cleared by writing a logic one to the flag. When the I-bit in SREG and WDIE are set, the Watchdog Time-out Interrupt is executed. • Bit 6 – WDIE - Watchdog Timeout Interrupt Enable When this bit is written to one and the I-bit in the Status Register is set, the Watchdog Interrupt is enabled. If WDE is cleared in combination with this setting, the Watchdog Timer is in Interrupt Mode, and the corresponding interrupt is executed if time-out in the Watchdog Timer occurs. If WDE is set, the Watchdog Timer is in Interrupt and System Reset Mode. The first time -out in the Watchdog Timer will set WDIF. Executing the corresponding interrupt vector will clear WDIE and WDIF automatically by hardware (the Watchdog goes to System Reset Mode). This is useful for keeping the Watchdog Timer security while using the interrupt. To stay in Interrupt and System Reset Mode, WDIE must be set after each interrupt. This should however not be done within the interrupt service routine itself, as this might compromise the safety-function of the Watchdog System Reset mode. If the interrupt is not executed before the next time-out, a System Reset will be applied. 217 8393C-MCU Wireless-09/14

Table 13-1. Watchdog Timer Configuration WDTON(1) WDE WDIE Mode Action on Time-out 1 0 0 Stopped None 1 0 1 Interrupt Mode Interrupt 1 1 0 System Reset Mode Reset Interrupt and System Interrupt, then go to 1 1 1 Reset Mode System Reset Mode 0 x x System Reset Mode Reset Note: 1. WDTON Fuse set to “0“ means programmed and “1” means un-programmed. • Bit 4 – WDCE - Watchdog Change Enable This bit is used in timed sequences for changing WDE and prescaler bits. To clear the WDE bit, and/or change the prescaler bits, WDCE must be set. Once written to one, hardware will clear WDCE after four clock cycles. • Bit 3 – WDE - Watch Dog Enable When the WDE is set (one) the Watchdog Timer is enabled. WDE is overridden by WDRF in MCUSR. This means that WDE is always set when WDRF is set. To clear WDE, WDRF must be cleared first. This feature ensures multiple resets during conditions causing failure, and a safe start-up after the failure. • Bit 5, 2:0 – WDP3:0 – Watchdog Timer Prescaler 3, 2, 1 and 0 The WDP3:0 bits determine the Watchdog Timer prescaling when the Watchdog Timer is running. The following tab le also shows approximate time-out values. Table 13-2. WDP Register Bits Register Bits Value Description WDP3:0 0x00 Oscillator Cycles 2k, (16ms) 0x01 Oscillator Cycles 4k, (32ms) 0x02 Oscillator Cycles 8k, (64ms) 0x03 Oscillator Cycles 16k, (0.125s) 0x04 Oscillator Cycles 32k, (0.25s) 0x05 Oscillator Cycles 64k, (0.5s) 0x06 Oscillator Cycles 128k, (1.0s) 0x07 Oscillator Cycles 256k, (2.0s) 0x08 Oscillator Cycles 512k, (4.0s) 0x09 Oscillator Cycles 1024k, (8.0s) ATmega256/128/64RFR2 218 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 14 I/O-Ports 14.1 Introduction All ATmega256/128/64RFR2 ports have true Read-Modify-Write functionality when used as general digital I/O ports. This means that the direction of one port pin can be changed without unintentionally changing the direction of any other pin with the SBI and CBI instructions. The same applies when changing drive value (if configured as output) or enabling/disabling of pull-up resistors (if configured as input). Each output buffer has symmetrical drive characteristics with both configurable sink and source capability. Every port is individually configurable in four different drive strengths. The pin driver is strong enough to drive LED displays directly. All port pins have individually selectable pull-up resistors with a supp ly-voltage invariant resistance. All I/O pins have protection diodes to both DEVDD and DVSS as indicated in Figure 14-1 below. Refer to "Electrical Characteristics" on page 553 for a complete list of parameters. Figure 14-1. I/O Pin Equivalent Schematic All registers and bit references in this section are written in general form. A lower case “x” represents the numbering letter for the port, and a lower case “n” represents the bit number. However, when using the register or bit defines in a program, the precise form must be used. For example, PORTB3 for bit no. 3 in Port B, here documented generally as PORTxn. Three I/O memory address locations are allocated for each port, one each for the Data Register – PORTx, Data Direction Register – DDRx, and the Port Input Pins – PINx. The Port Input Pins I/O location is read only, while the Data Register and the Data Direction Register are read/write. However, writing a logic one to a bit in the PINx Register, will result in a toggle in the corresponding bit in the Data Register. In addition, the Pull-up Disable – PUD bit in MCUCR disables the pull-up function for all pins in all ports when set. Using the I/O port as General Digital I/O is described in "Ports as General Digital I/O" on page 220. Most port pins are multiplexed with alternate functions for the peripheral features on the device. Ho w each alternate function interferes with the port pin is described in "Alternate Port Functions" on page 224. Refer to the individual module sections for a full description of the alternate functions. Note that enabling the alternate function of some of the port pins does not affect the use of the other pins in the port as general digital I/O. 219 8393C-MCU Wireless-09/14

14.2 Ports as General Digital I/O The ports are bi-directional I/O ports with optional internal pull-ups. Figure 14-2 below shows a functional description of one I/O-port pin, here generically called Pxn. Figure 14-2. General Digital I/O(1) DPDS0/DPDS1 DPDS0/DPDS1: drive strength register Note: 1. WRx, WPx, WDx, RRx, RPx, and RDx are common to all pins within the same port. clk , SLEEP, and PUD are common to all ports. I/O 14.2.1 Configuring the Port Drive strength of output buffers is configurable port-wise. Source/sink capably of 2mA, 4mA, 6mA or 8mA is selectable through registers DPDS1 and DPDS0. Note that pins PG3 and PG4 of PORTG have fixed drive strength of 2mA to enable the operation of the low power crystal oscillator. 14.2.2 Configuring the Pin Each port pin consists of three register bits: DDxn, PORTxn, and PINxn. The DDxn bits are accessed at the DDRx I/O address, the PORTxn bits at the PORTx I/O address, and the PINxn bits at the PINx I/O address. The DDxn bit in the DDRx Register selects the direction of this pin. If DDxn is written logic one, Pxn is configure d as an output pin. If DDxn is written logic zero, Pxn is configured as an input pin. If PORTxn is written logic one when the pin is configured as an input pin, the pull-up resistor is activated. To switch the pull-up resistor off, PORTxn has to be written logic zero or the pin has to be configured as an output pin. The port pins are tri-stated when reset condition becomes active, even if no clocks are running. If PORTxn is written logic one when the pin is configured as an output pin, the port pin is driven high (one). If PORTxn is written logic zero when the pin is configured as an output pin, the port pin is driven low (zero). ATmega256/128/64RFR2 220 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 14.2.3 Toggling the Pin Writing a logic one to PINxn toggles the value of PORTxn, independent on the value of DDRxn. Note that the SBI instruction can be used to toggle one single bit in a port. 14.2.4 Switching Between Input and Output When switching between tri-state ({DDxn, PORTxn} = 0b00) and output high ({DDxn, PORTxn} = 0b11), an intermediate state with either pull-up enabled {DDxn, PORTxn} = 0b01) or output low ({DDxn, PORTxn} = 0b10) must occur. Normally, the pull-up enabled state is fully acceptable, as a high-impedance environment will not notice the difference between a strong high driver and a pull-up. If this is not the case, the PUD bit in the MCUCR Register can be set to disable all pull-ups in all ports. Switching between input with pull-up and output low generates the same problem. The user must use either the tri-state ({DDxn, PORTxn} = 0b00) or the output high state ({DDxn, PORTxn} = 0b11) as an intermediate step. The following table summarizes the control signals for the pin value. Table 14-1. Port Pin Configu rations R) n UC xn RTx D MC D O U n D P P (i I/O Pull-up Comment 0 0 X Input No Tri-state (Hi-Z) 0 1 0 Inp u t Yes Pxn will source current if ext. pulled low. 0 1 1 Input No Tri-state (Hi-Z) 1 0 X Output No Output Low (Sink) 1 1 X Output No Output High (Source) 14.2.5 Reading the Pin Value Independent of the setting of Data Direction bit DDxn, the port pin can be read through the PINxn Register bit. As shown in Figure 14-2 on page 220, the PINxn Register bit and the preceding latch constitute a synchronizer. This is needed to avoid meta-stability if the physical pin changes value near the edge of the internal clock, but it also introduces a delay. Figure 14-3 on page 222 shows a timing diagram of the synchronization when reading an externally applied pin value. The maximum and minimum propagation delays are denoted t and t respectively. PD,MAX PD,MIN 221 8393C-MCU Wireless-09/14

Figure 14-3. Synchronization when reading an external applied pin value Consider the clock period starting shortly after the first falling edge of the system clock. The latch is closed when th e clock is low, and goes transparent when the clock is high, as indicated by the shaded region of the “SYNC LATCH” signal. The signal value is latched when the system clock goes low. It is clocked into the PINxn Register at the succeeding positive clock edge. As indicated by the two arrows t and t , a PD,MAX PD,MIN single signal transition on the pin will be delayed between ½ and 1½ system clock period depending upon the time of assertion. When reading back a software assigned pin value, a NOP instruction must be inserted as indicated in Figure 14-4 below. The out instruction sets the “SYNC LATCH” signal at the positive edge of the clo ck. In this case, the delay t through the synchronizer is 1 PD system clock period. Figure 14-4. Synchronization when reading software assigned pin value The following code example shows how to set port B pins 0 and 1 high, 2 and 3 low, and define the port pins from 4 to 7 as input with pull-ups assigned to port pins 6 and 7. The resulting pin values are read back again, but as previously discussed, a NOP instruction is included to be able to read back the value recently assigned to some of the pins. ATmega256/128/64RFR2 222 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 Assembly Code Example(1) … ; Define pull-ups and set outputs high ; Define directions f or port pins ldi r16,(1<<PB7)|(1<<PB6)|(1<<PB1)|(1<<PB0) ldi r17,(1<<DDB3)|(1<<DDB2)|(1<<DDB1)|(1<<DDB0) out PORTB,r16 out DDRB,r17 ; Insert nop for synchronization nop ; Read port pins in r16,PINB … C Code Example unsigned char i; … /* Define pull-ups and set outputs high */ /* Define directions for port pins */ PORTB = (1<<PB7)|(1<<PB6)|(1<<PB1)|(1<<PB0); DDRB = (1<<DDB3)|(1<<DDB2)|(1<<DDB1)|(1<<DDB0); /* Insert nop for synchronization*/ __no_operation(); /* Read port pins */ i = PINB; … Note: 1. For the assembly program, two temporary registers are used to minimize the time from pull-ups are set on pins 0, 1, 6, and 7, until the direction bits are correctly set, defining bit 2 and 3 as low and redefining bits 0 and 1 as strong high drivers. 14.2.6 Digital Input Enable and Sleep Modes As shown in Figure 14-2 on page 220, the digital input signal can be clamped to ground at the input of the Schmitt-Trigger. The signal denoted SLEEP in the figure, is set by the MCU Sleep Controller in Power-down mode, Power-save mode, and Standby mode to avoid high power consumption if some input signals are left floating, or have an analog signal level close to VDEVDD/2 . SLEEP is overridden for port pins enabled as external interrupt pins. If the external interrupt request is not enabled, SLEEP is active also for these pins. SLEEP is also overridden by various other alternate functions as described in "Alternate Port Functions" on page 224. If a logic high level (“one”) is present on an asynchronous external interrupt pin configured as “Interrupt on Rising Edge, Falling Edge, or Any Logic Change on Pin” while the external interrupt is not enabled, the corresponding External Interrupt Flag will be set when resuming from the above mentioned Sleep mode, as the clamping in these sleep mode produces the requested logic change. 14.2.7 Unconnected Pins If some pins are unused, it is recommended to ensure that these pins have a defined level. Even though most of the digital inputs are disabled in the deep sleep modes as 223 8393C-MCU Wireless-09/14

described above, floating inputs should be avoided to reduce current consumption in all other modes where the digital inputs are enabled (Reset-, Active- and Idle-mode). The simplest method to ensure a defined level of an unused pin is to enable the internal pull-up. In this case, the pu ll-up will be disabled during reset. If low power consumption during reset is important, it is recommended to use an external pull-up or pull-down. Connecting unused pins directly to DEVDD or DVSS is not recommended, since this may cause excessive currents if the pin is accidentally configured as an output. 14.3 Alternate Port Functions Most port pins have alternate functions in addition to being general digital I/O ports. Figure 14-5 below shows how the port pin control signals from the simplified Figure 14-2 on page 220 can be overridden by alternate functions. The overriding signals may not be present in all port pins, but the figure serves as a generic description applicable to all port pins in the AVR microcontroller family. Figure 14-5. Alternate Port Functions (1) ATmega256/128/64RFR2 224 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 Note: 1. WRx, WPx, WDx, RRx, RPx, and RDx are common to all pins within the same port. clk , SLEEP, and PUD are common to all ports. All other signals are unique for I/O each pin. The following table summar izes the function of the overriding signals. The pin and port indexes from Figure 14-5 on page 224 are not shown in the succeeding tables. The overriding signals are generated internally in the modules having the alternate function. Table 14-2. Generic Description of Overriding Signals for Alternate Functions Signal Name Full Name Description PUOE Pull-up Override If this signal is set, the pull-up enable is controlled by Enable the PUOV signal. If this signal is cleared, the pull-up is enabled when {DDxn, PORTxn, PUD} = 0b010. PUOV Pull-up Override If PUOE is set, the pull-up is enabled/disabled when Value PUOV is set/cleared, regardless of the setting of the DDxn, PORTxn, and PUD Register bits. DDOE Data Direction If this signal is set, the Output Driver Enable is Override Enable controlled by the DDOV signal. If this signal is cleared, the Output driver is enabled by the DDxn Register bit. DDOV Data Direction If DDOE is set, the Output Driver is enabled/disabled Override Value when DDOV is set/cleared, regardless of the setting of the DDxn Register bit. PVOE Port Value Override If this signal is set and the Output Driver is enabled, the Enable port value is controlled by the PVOV signal. If PVOE is cleared, and the Output Driver is enabled, the port Value is controlled by the PORTxn Register bit. PVOV Port Value Override If PVOE is set, the port value is set to PVOV, Value regardless of the setting of the PORTxn Register bit. PTOE Port Toggle Override If PTOE is set, the PORTxn Register bit is inverted. Enable DIEOE Digital Input Enable If this bit is set, the Digital Input Enable is controlled by Override Enable the DIEOV signal. If this signal is cleared, the Digital Input Enable is determined by MCU state (Normal mode, sleep mode). DIEOV Digital Input Enable If DIEOE is set, the Digital Input is enabled/disabled Override Value when DIEOV is set/cleared, regardless of the MCU state (Normal mode, sleep mode). DI Digital Input This is the Digital Input to alternate functions. In the figure, the signal is connected to the output of the Schmitt-Trigger but before the synchronizer. Unless the Digital Input is used as a clock source, the module with the alternate function will use its own synchronizer. AIO Analog Input/Output This is the Analog Input/output to/from alternate functions. The signal is connected directly to the pad, and can be used bi-directionally. The following subsections shortly describe the alternate functions for each port, and relate the overriding signals to the alternate function. Refer to the alternate function description for further details. 14.3.1 Alternate Functions of Port B The Port B pins with alternate functions are shown in the following table. 225 8393C-MCU Wireless-09/14

Table 14-3. Port B Pins Alternate Functions Port Pin Alternate Functions PB7 OC0A/OC1C/PCINT7 (Output Compare and PWM Output A for Timer/Coun ter0, Output Compare and PWM Output C for Timer/Counter1 or Pin Change Interrupt 7) PB6 OC1B/PCINT6 (Output Compare and PWM Output B for Timer/Counter1 or Pin Change Interrupt 6) PB5 OC1A/PCINT5 (Output Compare and PWM Output A for Timer/Counter1 or Pin Change Interrupt 5) PB4 OC2A/PCINT4 (Output Compare and PWM Output A for Timer/Counter2 or Pin Change Interrupt 4) PB3 MISO/PDO/PCINT3 (SPI Bus Master Input/Slave Output, Programming Data Output or Pin Change Interrupt 3) PB2 MOSI/PDI/PCINT2 (SPI Bus Master Output/Slave Input , Programming Data Input or Pin Change Interrupt 2) PB1 SCK/PCINT1 (SPI Bus Serial Clock or Pin Change Interrupt 1) PB0 S¯¯S/PCINT0 (SPI Slave Select input or Pin Change Interrupt 0) The alternate pin configuration is as follows: • OC0A/OC1C/PCINT7, Bit 7 OC0A, Output Compare Match A output: The PB7 pin can serve as an external output for the Timer/Counter0 Output Compare. The pin has to be configured as an output (DDB7 set “one”) to serve this function. The OC0A pin is also the output pin for the PWM mode timer function. OC1C, Output Compare Match C output: The PB7 pin can serve as an external output for the Timer/Counter1 Output Compare C. The pin has to be configured as an output (DDB7 set (one)) to serve this function. The OC1C pin is also the output pin for the PWM mode timer function. PCINT7, Pin Change Interru pt source 7: The PB7 pin can serve as an external interrupt source. • OC1B/PCINT6, Bit 6 OC1B, Output Compare Match B output: The PB6 pin can serve as an external output for the Timer/Counter1 Output Compare B. The pin has to be configured as an output (DDB6 set (one)) to serve this function. The OC1B pin is also the output pin for the PWM mode timer function. PCINT6, Pin Change Interru pt source 6: The PB6 pin can serve as an external interrupt sourceOC1A, Output Compare Match A output: The PB5 pin can serve as an external output for the Timer/Counter1 Output Compare A. The pin has to be configured as an output (DDB5 set (one)) to serve this function. The OC1A pin is also the output pin for the PWM mode timer function. PCINT5, Pin Change Interru pt source 5: The PB5 pin can serve as an external interrupt source. • OC2A/PCINT4, Bit 4 OC2A, Output Compare Match output: The PB4 pin can serve as an external output for the Timer/Counter2 Output Compare. The pin has to be configured as an output (DDB4 set (one)) to serve this function. The OC2A pin is also the output pin for the PWM mode timer function. ATmega256/128/64RFR2 226 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 PCINT4, Pin Change Interrupt source 4: The PB4 pin can serve as an external interrupt source. • MISO/PDO/PCINT3 – Port B, Bit 3 MISO: Master Data input, Slave Data output pin for SPI channel. When the SPI is enabled as a master, this pin is configured as an input regardless of the setting of DDB3. When the SPI is enabled as a slave, the data direction of this pin is controlled by DDB3. When the pin is forced to be an input, the pull-up can still be controlled by the PORTB3 bit. PDO, SPI Serial Programming Data Output. During Serial Program Downloading, this pin is used as data output line (see section "Serial Downloading" on page 521 for details). PCINT3, Pin Change Interrupt source 3: The PB3 pin can serve as an external interrupt source. • MOSI/PDI/PCINT2 – Port B, Bit 2 MOSI: SPI Master Data output, Slave Data input for SPI channel. When the SPI is enabled as a slave, this pin is configured as an input regardless of the setting of DDB2. When the SPI is enabled as a master, the data direction of this pin is controlled by DDB2. When the pin is forced to be an input, the pull-up can still be controlled by the PORTB2 bit. PDI, SPI Serial Programming Data Input. During Serial Program Downloading, this pin is used as data input line (see section "Serial Downloading" on page 521 for details). PCINT2, Pin Change Interrupt source 2: The PB2 pin can serve as an external interrupt source. • SCK/PCINT1 – Port B, Bit 1 SCK: Master Clock output, Slave Clock input pin for SPI channel. When the SPI is enabled as a slave, this pin is configured as an input regardless of the setting of DDB1. When the SPI0 is enabled as a master, the data direction of this pin is controlled by DDB1. When the pin is forc ed to be an input, the pull-up can still be controlled by the PORTB1 bit. PCINT1, Pin Change Interrupt source 1: The PB1 pin can serve as an external interrupt source. • S¯S¯ /PCINT0 – Port B, Bit 0 S¯S¯ : Slave Port Select input. When the SPI is enabled as a slave, this pin is configured as an input regardless of the setting of DDB0. As a slave, the SPI is activated when this pin is driven low. When the SPI is enabled as a master, the data direction of this pin is controlled by DDB0. When the pin is forced to be an input, the pull-up can still be controlled by the PORTB0 bit. Table 14-4 below and Table 14-5 on page 228 relate the alternate functions of Port B to the overriding signals shown in Figure 14-5 on page 224. SPI MSTR INPUT and SPI SLAVE OUTPUT constitute the MISO signal, while MOSI is divided into SPI MSTR OUTPUT and SPI SLAVE INPUT. PCINT0, Pin Change Interrupt source 0: The PB0 pin can serve as an external interrupt source. Table 14-4. Overriding Signals for Alternate Functions in PB7:PB4 Signal PB7/OC0A/OC1C PB6/OC1B PB5/OC1A PB4/OC2A Name PUOE 0 0 0 0 227 8393C-MCU Wireless-09/14

Signal PB7/OC0A/OC1C PB6/OC1B PB5/OC1A PB4/OC2A Name PUOV 0 0 0 0 DDOE 0 0 0 0 DDOV 0 0 0 0 PVOE OC0/OC1C OC1B ENABLE OC1A ENABLE OC2A ENABLE ENABLE PVOV OC0/OC1C OC1B OC1A OC2A DIEOE PCINT7•PCIE0 PCINT6•PCIE0 PCINT5•PCIE0 PCINT4•PCIE0 DIEOV 1 1 1 1 DI PCINT7 INPUT PCINT6 INPUT PCINT5 INPUT PCINT4 INPUT AIO – – – – Table 14-5. Overriding Signals for Alternate Functions in PB3:PB0 Signal PB3/MISO/PDO PB2/MOSI/PDI PB1/SCK PB0/S¯¯S Name PUOE SPE•MSTR SPE•(~MSTR) SPE•(~MSTR) SPE•(~MSTR) PUOV PORTB3•(~PUD) PORTB2•(~PUD) PORTB1•(~PUD) PORTB0•(~PUD) DDOE SPE•MSTR SPE•(~MSTR) SPE•(~MSTR) SPE•(~MSTR) DDOV 0 0 0 0 PVOE SPE•(~MSTR) SPE•MSTR SPE•MSTR 0 PVOV SPI SLAVE SPI MSTR SCK OUTPUT 0 OUTPUT OUTPUT DIEOE PCINT3•PCIE0 PCINT2•PCIE0 PCINT1•PCIE0 PCINT0•PCIE0 DIEOV 1 1 1 1 DI SPI MSTR INPUT SPI SLAVE INPUT SCK INPUT SPI S¯¯S PCINT0 PCINT3 INPUT PCINT2 INPUT PCINT1 INPUT INPUT AIO – – – – 14.3.2 Alternate Functions of Port D The Port D pins with alternate functions are shown in the following table. Table 14-6. Port D Pins Alternate Functions Port Pin Alternate Function PD7 T0 (Timer/Counter0 Clock Input) PD6 T1 (Timer/Counter1 Clock Input) PD5 XCK1 (USART1 External Clock Input/Output) PD4 ICP1 (Timer/Counter1Input Capture Trigger) PD3 INT3/TXD1 (External Interrupt3 Input or USART1 Transmit Pin) PD2 INT2/RXD 1(External Interrupt2 Input or USART1 Receive Pin) PD1 INT1/SDA (External Interrupt1 Input or TWI Serial Data) PD0 INT0/SCL (External Interrupt0 Input or TWI Serial Clock) The alternate pin configuration is as follows: • T0 – Port D, Bit 7 T0, this is Timer/Counter0 counter source. ATmega256/128/64RFR2 228 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 • T1 – Port D, Bit 6 T1, this is Timer/Counter1 counter source. • XCK1 – Port D, Bit 5 XCK1, USART1 External cl ock: The Data Direction Register (DDD5) controls whether the clock is output (DDD5 set) or input (DDD5 cleared). The XCK1 pin is active only when the USART1 operates in Synchronous mode. • ICP1 – Port D, Bit 4 ICP1 – Input Capture Pin 1: The PD4 pin can act as an input capture pin for Timer/Counter1. • INT3/TXD1 – Port D, Bit 3 INT3, External Interrupt source 3: The PD3 pin can serve as an external interrupt source to the MCU. TXD1, Transmit Data (Data output pin for the USART1). When the USART1 Transmitter is enabled, this pin is configured as an output regardless of the value of DDD3. • INT2/RXD1 – Port D, Bit 2 INT2, External Interrupt source 2: The PD2 pin can serve as an External Interrupt source to the MCU. RXD1, Receive Data (Data input pin for the USART1). When the USART1 receiver is enabled this pin is configured as an input regardless of the value of DDD2. When the USART forces this pin to be an input, the pull-up can still be controlled by the PORTD2 bit. • INT1/SDA – Port D, Bit 1 INT1, External Interrupt source 1: The PD1 pin can serve as an external interrupt source to the MCU. SDA, 2-wire Serial Interface Data: When the TWEN bit in TWCR is set (one) to enable the 2-wire Serial Interface, pin PD1 is disconnected from the port and becomes the Serial Data I/O pin for the 2 -wire Serial Interface. In this mode, there is a spike filter on the pin to suppress spikes shorter than 50 ns on the input signal, and the pin is driven by an open drain driver with slew rate limitation. • INT0/SCL – Port D, Bit 0 INT0, External Interrupt source 0: The PD0 pin can serve as an external interrupt source to the MCU. SCL, 2-wire Serial Interface Clock: When the TWEN bit in TWCR is set (one) to enable the 2-wire Serial Interface, pin PD0 is disconnected from the port and becomes the Serial Clock I/O pin for the 2-wire Serial Interface. In this mode, there is a spike filter on the pin to suppress spikes shorter than 50 ns on the input signal, and the pin is driven by an open drain driver with slew-rate limitation. Table 14-7 below and Table 14-8 on page 230 relates the alternate functions of Port D to the overriding signals sho wn in Figure 14-5 on page 224. Table 14-7. Overriding Signals for Alternate Functions PD7:PD4 Signal PD7/T0 PD6/T1 PD5/XCK1 PD4/ICP1 Name PUOE 0 0 0 0 PUOV 0 0 0 0 DDOE 0 0 XCK1 OUTPUT 0 ENABLE 229 8393C-MCU Wireless-09/14

Signal PD7/T0 PD6/T1 PD5/XCK1 PD4/ICP1 Name DDOV 0 0 1 0 PVOE 0 0 XCK1 OUTPUT 0 ENABLE PVOV 0 0 XCK1 OUTPUT 0 DIEOE 0 0 0 0 DIEOV 0 0 0 0 DI T0 INPUT T1 INPUT XCK1 INPUT ICP1 INPUT AIO – – – – Table 14-8. Overriding Signals for Alternate Functions PD3:PD0 Signal PD3/INT3/TXD1 PD2/INT2/RXD1 PD1/INT1/SDA PD0/INT0/SCL Name PUOE TXEN1 RXEN1 TWEN TWEN PUOV 0 PORTD2&(~PUD) PORTD1&(~PUD) PORTD0&(~PUD) DDOE TXEN1 RXEN1 TWEN TWEN DDOV 1 0 SDA_OUT SCL_OUT PVOE TXEN1 0 TWEN TWEN PVOV TXD1 0 0 0 DIEOE INT3 ENABLE INT2 ENABLE INT1 ENABLE INT0 ENABLE DIEOV 1 1 1 1 DI INT3 INPUT INT2 INPUT/RXD1 INT1 INPUT INT0 INPUT AIO - - SDA INPUT SCL INPUT Note: 1. When enabled, the 2-wire Serial Interface enables Slew-Rate controls on the output pins PD0 and PD1. This is not shown in this table. In addition, spike filters are connected between the AIO outputs shown in the port figure and the digital logic of the TWI module. 14.3.3 Alternate Functions of Port E The Port E pins with alternate functions are shown in the following table. Table 14-9. Port E Pins Alternate Functions Port Alternate Function Pin PE7 INT7/ICP3/CLK0 (External Interrupt7 Input, Timer/Counter3 Input Capture Trigger or Divided System Clock) PE6 INT6/T3 (External Interrupt6 Input or Timer/Counter3 Clock Input) PE5 INT5/OC3C (External Interrupt5 Input or Output Compare and PWM Output C for Timer/Counter3) PE4 INT4/OC3B (External Interrupt4 Input or Output Compare and PWM Output B for Timer/Counter3) PE3 AIN1/OC3A (Analog Comparator Negative Input or Output Compare and PWM Output A for Timer/Counter3) PE2 AIN0/XCK0 (Analog Comparator or Positive Input or USART0 external clock input/output) PE1 TXD0 (USART0 Transmit Pin) ATmega256/128/64RFR2 230 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 Port Alternate Function Pin PE0 RXD0/PCINT8 (USART0 Receive Pin or Pin Change Interrupt8) • INT7/ICP3/CLKO – Port E, Bit 7 INT7, External Interrupt source 7: The PE7 pin can serve as an external interrupt source. ICP3, Input Capture Pin 3: The PE7 pin can act as an input capture pin for Timer/Counter3. CLKO - Divided System Clock: The divided system clock can be output on the PE7 pin. The divided system clock will be output if the CKOUT Fuse is programmed, regardless of the PORTE7 and DDE7 s ettings. It will also be output during reset. • INT6/T3 – Port E, Bit 6 INT6, External Interrupt source 6: The PE6 pin can serve as an external interrupt source. T3, this is the Timer/Counter 3 counter source. • INT5/OC3C – Port E, Bit 5 INT5, External Interrupt source 5: The PE5 pin can serve as an External Interrupt source. OC3C, Output Compare Match C output: The PE5 pin can serve as an External output for the Timer/Counter3 Output Compare C. The pin has to be configured as an output (DDE5 set “one”) to serve this function. The OC3C pin is also the output pin for the PWM mode timer function. • INT4/OC3B – Port E, Bit 4 INT4, External Interrupt source 4: The PE4 pin can serve as an External Interrupt source. OC3B, Output Compare Match B output: The PE4 pin can serve as an External output for the Timer/Counter3 Output Compare B. The pin has to be configured as an output (DDE4 set (one)) to serve this function. The OC3B pin is also the output pin for the PWM mode timer function. • AIN1/OC3A – Port E, Bit 3 AIN1 – Analog Comparator Negative input. This pin is directly connected to the negative input of the Analog Comparator. OC3A, Output Compare Match A output: The PE3 pin can serve as an External output for the Timer/Counter3 Output Compare A. The pin has to be configured as an output (DDE3 set “one”) to serve this function. The OC3A pin is also the output pin for the PWM mode timer function. • AIN0/XCK0 – Port E, Bit 2 AIN0 – Analog Comparator Positive input. This pin is directly connected to the positive input of the Analog Comparator. XCK0, this is the USART0 External clock. The Data Direction Register (DDE2) controls whether the clock is output (DDE2 set) or input (DDE2 cleared). The XCK0 pin is active only when the USART0 operates in Synchronous mode. • TXD0 – Port E, Bit 1 TXD0, this is the USART0 Transmit pin. • RXD0/PCINT8 – Port E, Bit 0 231 8393C-MCU Wireless-09/14

RXD0, USART0 Receive Pin. Receive Data (Data input pin for the USART0). When the USART0 receiver is enabled this pin is configured as an input regardless of the value of DDRE0. When the USART0 forces this pin to be an input, a logical one in PORTE0 will turn on the internal pull-up. PCINT8, Pin Change Interrupt source 8: The PE0 pin can serve as an external interrupt source. Table 14-10 below and Table 14-11 below relates the alternate functions of Port E to the overriding signals shown in Figure 14-5 on page 224. Table 14-10. Overriding Signals for Alternate Functions PE7:PE4 Signal PE7/INT7/ICP3 PE6/INT6/T3 PE5/INT5/OC3C PE4/INT4/OC3B Name PUOE 0 0 0 0 PUOV 0 0 0 0 DDOE 0 0 0 0 DDOV 0 0 0 0 PVOE 0 0 OC3C ENABLE OC3B ENABLE PVOV 0 0 OC3C OC3B DIEOE INT7 ENABLE INT6 ENABLE INT5 ENABLE INT4 ENABLE DIEOV 1 1 1 1 DI INT7 INPUT / ICP3 INT7 INPUT / T3 INT5 INPUT INT4 INPUT INPUT INPUT AIO – – – – Table 14-11. Overriding Signals for Alternate Functions PE3:PE0 Signal PE3/AIN1/OC3A PE2/AIN0/XCK0 PE1/TXD0 PE0 / Name RXD0/PCINT8 PUOE 0 0 TXEN0 RXEN0 PUOV 0 0 0 PORTE0 & (~PUD) DDOE 0 XCK0 OUTPUT TXEN0 RXEN0 ENABLE DDOV 0 1 1 0 PVOE OC3BENABLE XCK0 OUTPUT TXEN0 0 ENABLE PVOV OC3B XCK0 OUTPUT TXD0 0 DIEOE 0 0 0 PCINT8 & PCIE1 DIEOV 0 0 0 1 DI 0 XCK0 INPUT – RXD0 PE0 0 0 0 PCINT8 INPUT AIO AIN1 INPUT AIN0 INPUT - - 14.3.4 Alternate Functions of Port F The Port F has an alternate function as analog input for the ADC as shown in Table 14-12 on page 233. If some Port F pins are configured as outputs, it is essential that these do not switch when a conversion is in progress. This might corrupt the result of the conversion. If the JTAG interface is enabled, the pull-up resistors on pins PF7(TDI), PF5(TMS), and PF4(TCK) will be activated even if a Reset occurs. ATmega256/128/64RFR2 232 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 Table 14-12. Port F Pins Alternate Functions Port Pin Alternate Function PF7 ADC7/TDI (ADC input channel 7 or JTAG Test Data Input) PF6 ADC6/TDO (ADC input channel 6 or JTAG Test Data Output) PF5 ADC5/TMS (ADC input channel 5 or JTAG Test Mode Select) PF4 ADC4/TCK (ADC input channel 4 or JTAG Test Clock) PF3 ADC3/DIG4 (ADC input channel 3 or Radio Transceiver RX/TX Indicator Output) PF2 ADC2/DIG2 (ADC input channel 2 or Radio Transceiver Antenna Diversity Control Output) PF1 ADC1 (ADC input channel 1) PF0 ADC0 (ADC input channel 0) • TDI, ADC7 – Port F, Bit 7 ADC7, Analog to Digital Converter, Channel 7. TDI, JTAG Test Data In: Se rial input data to be shifted in to the Instruction Register or Data Register (scan chains). When the JTAG interface is enabled, this pin can not be used as an I/O pin. • TDO, ADC6 – Port F, Bit 6 ADC6, Analog to Digital Converter, Channel 6. TDO, JTAG Test Data Out: Serial output data from Instruction Register or Data Register. When the JTAG interface is enabled, this pin can not be used as an I/O pin. The TDO pin is tri-stated unl ess TAP states that shift out data are entered. • TMS, ADC5 – Port F, Bit 5 ADC5, Analog to Digital Converter, Channel 5. TMS, JTAG Test Mode Select: This pin is used for navigating through the TAP- controller state machine. When the JTAG interface is enabled, this pin can not be used as an I/O pin. • TCK, ADC4 – Port F, Bit 4 ADC4, Analog to Digital Converter, Channel 4. TCK, JTAG Test Clock: JTAG operation is synchronous to TCK. When the JTAG interface is enabled, this pin can not be used as an I/O pin. • DIG4, ADC3 – Port F, Bit 3 ADC3, Analog to Digital Converter, Channel 3. DIG4, Radio Transceiver RX/TX Indicator Output: If the bit PA_EXT_EN in TRX_CTRL_1 is set to one then the PF3 pin serves as the Radio Transceiver receive/transmit indicator output to control an external RF front-end. • DIG2, ADC2 – Port F, B i t 2 ADC2, Analog to Digital Converter, Channel 2. DIG2, Radio Transceiver Antenna Diversity Control Output: If the bit ANT_EXT_SW_EN in ANT_DIV is set to one then the PF2 pin serves as a Radio Transceiver output to control External Antenna Diversity. • ADC1 – ADC0 – Port F, Bit 1:0 Analog to Digital Converter, Channel 1:0. 233 8393C-MCU Wireless-09/14

Table 14-13. Overriding Signals for Alternate Functions PF7:PF4 Signal PF7/ADC7/TDI PF6/ADC6/TDO PF5/ADC5/TMS PF4/ADC4/TCK Name PUOE JTAGEN JTAGEN JTAGEN JTAGEN PUOV 1 0 1 1 DDOE JTAGEN JTAGEN JTAGEN JTAGEN DDOV 0 SHIFT_IR+SHIFT_DR 0 0 PVOE 0 JTAGEN 0 0 PVOV 0 TDO 0 0 DIEOE JTAGEN JTAGEN JTAGEN JTAGEN DIEOV 0 0 0 0 DI – – – – AIO TDI/ADC7 INPUT ADC6 INPUT TMS/ADC5 TCK/ADC4 INPUT INPUT Table 14-14. Overriding Sig nals for Alternate Functions PF3:PF0 Signal PF3/ADC3/DIG4 PF2/ADC2/DIG2 PF1/ADC1 PF0/ADC0 Name PUOE 0 0 0 0 PUOV 0 0 0 0 DDOE PA_EXT_EN ANT_EXT_SW_EN 0 0 DDOV PA_EXT_EN ANT_EXT_SW_EN 0 0 PVOE PA_EXT_EN ANT_EXT_SW_EN 0 0 PVOV DIG4 DIG2 0 0 DIEOE 0 0 0 0 DIEOV 0 0 0 0 DI – – – – AIO ADC3 INPUT ADC2 INPUT ADC1 INPUT ADC0 INPUT 14.3.5 Alternate Functions of Port G The Port G alternate pin configuration is as follows: Table 14-15. Port G Pins Alternate Functions Port Pin Alternate Function PG5 OC0B (Output Compare and PWM Output B for Timer/Counter0) PG4 TOSC1 (RTC Oscillator Timer/Counter2) PG3 TOSC2 (RTC Oscillator Timer/Counter2) PG2 AMR (Automated Meter Reading - Counter Input for Timer/Counter2) PG1 DIG1 (Radio Transceiver Antenna Diversity Control Output) PG0 DIG3 (Radio Transceiver RX/TX Indicator Output) • OC0B – Port G, Bit 5 OC0B, Output Compare match B output: The PG5 pin can serve as an external output for the TImer/Counter0 Output Compare. The pin has to be configured as an output (DDG5 set) to serve this function. The OC0B pin is also the output pin for the PWM mode timer function. • TOSC1 – Port G, Bit 4 ATmega256/128/64RFR2 234 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 TOSC2, Timer Oscillator pin 1: Setting the AS2 bit to one and the EXCLKAMR bit to zero in ASSR, enables asynchronous clocking of Timer/Counter2 by a Crystal Oscillator. The pin PG4 is disconnected from the port, and becomes the input of the inverting Oscillator amplifier. In this mode, a Crystal Oscillator is connected to this pin, and the pin can not be used as an I/O pin. TOSC2 – Port G, Bit 3 TOSC2, Timer Oscillator pin 2: Setting the AS2 bit to one and the EXCLKAMR bit to zero in ASSR, enables asynchronous clocking of Timer/Counter2 by a Crystal Oscillator. The pin PG3 is disconnected from the port, and becomes the inverting output of the Oscillator amplifier. In this mode, a Crystal Oscillator is connected to this pin, and the pin can not be used as an I/O pin. • AMR – Port G, Bit 2 AMR, Automated Meter Reading Input: Setting the AS2 and the EXCLKAMR bits in ASSR to one, enables asynchronous clocking of Timer/Counter2 by the AMR pin • DIG1 – Port G, Bit 1 DIG1, Radio Transceive r Antenna Diversity Control Output: If the bit ANT_EXT_SW_EN in ANT_DIV is set to one then the PG1 pin serves as a Radio Transceiver output to control External Antenna Diversity. • DIG3 – Port G, Bit 0 DIG3, Radio Transceiver RX/TX Indicator Output: If the bit PA_EXT_EN in TRX_CTRL_1 is set to one then the PG0 pin serves as the Radio Transceiver receive/transmit indicator output to control an external RF front-end. Table 14-16 below relates the alternate functions of Port G to the overriding signals shown in Figure 14-5 on page 224. Table 14-16. Overriding Signals for Alternate Functions PG5:PG2 Signal PG5/OC0B PG4/TOSC1 PG3/TOSC2 PG2/AMR Name PUOE – AS2 & AS2 & AS2 & EXCLKAMR (~EXCLKAMR) (~EXCLKAMR) & (~EXCLK) PUOV – 0 0 0 DDOE – AS2 & AS2 & AS2 & EXCLKAMR (~EXCLKAMR) (~EXCLKAMR) & (~EXCLK) DDOV – 0 0 0 PVOE OC0B Enable 0 0 0 PVOV OC0B 0 0 0 DIEOE – AS2 & AS2 & AS2 & EXCLKAMR (~EXCLKAMR) (~EXCLKAMR) & (~EXCLK) DIEOV – EXCLK 0 1 DI – – – AMR AIO – T/C2 T/C2 – OSC INPUT OSC OUTPUT 235 8393C-MCU Wireless-09/14

Table 14-17. Overriding Signals for Alternate Functions PG1:PG0 Signal PG1/DIG1 PG0/DIG3 Name PUOE 0 0 PUOV 0 0 DDOE ANT_EXT_SW_EN PA_EXT_EN DDOV ANT_EXT_SW_EN PA_EXT_EN PVOE ANT_EXT_SW_EN PA_EXT_EN PVOV DIG1 DIG3 DIEOE 0 0 DIEOV 0 0 DI – – AIO – – 14.4 Register Description For a detailed description of register MCUCR see chapter "MCUCR – MCU Control Register" on page 249. 14.4.1 MCUCR – MCU Control Register Bit 7 6 5 4 3 2 1 0 $35 ($55) PUD MCUCR Read/Write RW Initial Value 0 The MCU Control Register contains control bits of the general Microcontroller Unit functions. • Bit 4 – PUD - Pull-up Disable When this bit is written to one, the I/O ports pull-up resistors are disabled even if the DDxn and PORTxn Registers are configured to enable the pull-up resistor ({DDxn, PORTxn} = 2'b01). See section "Ports as General Digital I/O" for more details about this feature. 14.4.2 DPDS0 – Port Driver Strength Register 0 Bit 7 6 5 4 3 2 1 0 NA ($136) PFDRV1 PFDRV0 PEDRV1 PEDRV0 PDDRV1 PDDRV0 PBDRV1 PBDRV0 DPDS0 Read/Write RW RW RW RW RW RW RW RW Initial Value 0 0 0 0 0 0 0 0 The output driver strength can be set individually for each digital I/O port. The following tables show output current levels for a typical supply voltage of DEVDD = 3.3V. Refer to section "Electrical Characteristics" for details. • Bit 7:6 – PFDRV1:0 - Driver Strength Port F ATmega256/128/64RFR2 236 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 Table 14-18 PFDRV Register Bits Register Bits Value Description PFDRV1:0 0 2 mA 1 4 mA 2 6 mA 3 8 mA • Bit 5:4 – PEDRV1:0 - Driver Strength Port E Table 14-19 PEDRV Register Bits Register Bits Value Description PEDRV1:0 0 2 mA 1 4 mA 2 6 mA 3 8 mA • Bit 3:2 – PDDRV1:0 - Driver Strength Port D Table 14-20 PDDRV Register Bits Register Bits Value Description PDDRV1:0 0 2 mA 1 4 mA 2 6 mA 3 8 mA • Bit 1:0 – PBDRV1:0 - Dr iver Strength Port B Table 14-21 PBDRV Register Bits Register Bits Value Description PBDRV1:0 0 2 mA 1 4 mA 2 6 mA 3 8 mA 14.4.3 DPDS1 – Port Driver Strength Register 1 Bit 7 6 5 4 3 2 1 0 NA ($137) Res5 Res4 Res3 Res2 Res1 Res0 PGDRV1 PGDRV0 DPDS1 Read/Write R R R R R R RW RW Initial Value 0 0 0 0 0 0 0 0 The output driver strength can be set individually for each digital I/O port. The following table shows output current levels for a typical supply voltage of DEVDD = 3.3V. Refer to section "Electrical Characteristics" for details. • Bit 7:2 – Res5:0 - Reserved • Bit 1:0 – PGDRV1:0 - Driver Strength Port G Driver strength can be set for port G except the port pins PG3 and PG4. The leakage current of the ports PG3 and PG4 is reduced. 237 8393C-MCU Wireless-09/14

Table 14-22 PGDRV Register Bits Register Bits Value Description PGDRV1:0 0 2 mA 1 4 mA 2 6 mA 3 8 mA 14.4.4 PORTB – Port B Data Register Bit 7 6 5 4 3 2 1 0 $05 ($25) PORTB7:0 PORTB Read/Write RW RW RW RW RW RW RW RW Initial Value 0 0 0 0 0 0 0 0 If PORTBn is written logic o ne when the PORTB pin n is configured as an input pin, the pull-up resistor is activated. To switch the pull-up resistor off, PORTBn has to be written logic zero or the pin has to be configured as an output pin. If PORTBn is written logic one when the pin is configured as an output pin, the port pin is driven high (one). If PORTBn is written logic zero when the pin is configured as an output pin, the port pin is driven low (zero). • Bit 7:0 – PORTB7:0 - Port B Data Register Value 14.4.5 DDRB – Port B Data Direction Register Bit 7 6 5 4 3 2 1 0 $04 ($24) DDB7 DDB6 DDB5 DDB4 DDB3 DDB2 DDB1 DDB0 DDRB Read/Write RW RW RW RW RW RW RW RW Initial Value 0 0 0 0 0 0 0 0 The DDBn bit in the DDRB Register selects the direction of the PORTB pin n. If DDBn is written logic one, PBn is configured as an output pin. If DDBn is written logic zero, PBn is configured as an input pin. • Bit 7:0 – DDB7:0 - Port B Data Direction Register Value 14.4.6 PINB – Port B Input Pins Address Bit 7 6 5 4 3 2 1 0 $03 ($23) PINB7:0 PINB Read/Write R R R R R R R R Initial Value 0 0 0 0 0 0 0 0 This register allows access to the PORTB pins independent of the setting of the Data Direction bit DDBn. The port pin can be read through the PINBn Register bit, and writing a logic one to PINBn toggles the value of PORTBn. • Bit 7:0 – PINB7:0 - Port B Input Pins Value ATmega256/128/64RFR2 238 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 14.4.7 PORTD – Port D Data Register Bit 7 6 5 4 3 2 1 0 $0B ($2B) PORTD7:0 PORTD Read/Write RW RW RW RW RW RW RW RW Initial Value 0 0 0 0 0 0 0 0 If PORTDn is written logic one when the PORTD pin n is configured as an input pin, the pull-up resistor is activated. To switch the pull-up resistor off, PORTDn has to be written logic zero or the pin has to be configured as an output pin. If PORTDn is written logic one when the pin is configured as an output pin, the port pin is driven high (one). If PORTDn is written logic zero when the pin is configured as an output pin, the port pin is driven low (zero). • Bit 7:0 – PORTD7:0 - Port D Data Register Value 14.4.8 DDRD – Port D Data Direction Register Bit 7 6 5 4 3 2 1 0 $0A ($2A) DDD7 DDD6 DDD5 DDD4 DDD3 DDD2 DDD1 DDD0 DDRD Read/Write RW RW RW RW RW RW RW RW Initial Value 0 0 0 0 0 0 0 0 The DDDn bit in the DDRD Register selects the direction of the PORTD pin n. If DDDn is written logic one, PDn is configured as an output pin. If DDDn is written logic zero, PDn is configured as an input pin. • Bit 7:0 – DDD7:0 - Port D Data Direction Register Value 14.4.9 PIND – Port D Input Pins Address Bit 7 6 5 4 3 2 1 0 $09 ($29) PIND7:0 PIND Read/Write R R R R R R R R Initial Value 0 0 0 0 0 0 0 0 This register allows access to the PORTD pins independent of the setting of the Data Direction bit DDDn. The port pin can be read through the PINDn Register bit, and writing a logic one to PINDn toggles the value of PORTDn. • Bit 7:0 – PIND7:0 - Port D Input Pins Value 14.4.10 PORTE – Port E Data Register Bit 7 6 5 4 3 2 1 0 $0E ($2E) PORTE7:0 PORTE Read/Write RW RW RW RW RW RW RW RW Initial Value 0 0 0 0 0 0 0 0 239 8393C-MCU Wireless-09/14

If PORTEn is written logic one when the PORTE pin n is configured as an input pin, the pull-up resistor is activated. To switch the pull-up resistor off, PORTEn has to be written logic zero or the pin has to be configured as an output pin. If PORTEn is written logic one when the pin is configured as an output pin, the port pin is driven high (one). If PORTEn is written logic zero when the pin is configured as an output pin, the port pin is driven low (zero). • Bit 7:0 – PORTE7:0 - Port E Data Register Value 14.4.11 DDRE – Port E Data Direction Register Bit 7 6 5 4 3 2 1 0 $0D ($2D) DDE7 DDE6 DDE5 DDE4 DDE3 DDE2 DDE1 DDE0 DDRE Read/Write RW RW RW RW RW RW RW RW Initial Value 0 0 0 0 0 0 0 0 The DDEn bit in the DDRE Register selects the direction of the PORTE pin n. If DDEn is written logic one, PEn is configured as an output pin. If DDEn is written logic zero, PEn is configured as an input pin. • Bit 7:0 – DDE7:0 - Port E Data Direction Register Value 14.4.12 PINE – Port E Input Pins Address Bit 7 6 5 4 3 2 1 0 $0C ($2C) PINE7:0 PINE Read/Write R R R R R R R R Initial Value 0 0 0 0 0 0 0 0 This register allows access to the PORTE pins independent of the setting of the Data Direction bit DDEn. The port pin can be read through the PINEn Register bit, and writing a logic one to PINEn toggles the value of PORTEn. • Bit 7:0 – PINE7:0 - Port E Input Pins Value 14.4.13 PORTF – Port F Data Register Bit 7 6 5 4 3 2 1 0 $11 ($31) PORTF7:0 PORTF Read/Write RW RW RW RW RW RW RW RW Initial Value 0 0 0 0 0 0 0 0 If PORTFn is written logic one when the PORTF pin n is configured as an input pin, the pull-up resistor is activated. To switch the pull-up resistor off, PORTFn has to be written logic zero or the pin has to be configured as an output pin. If PORTFn is written logic one when the pin is configured as an output pin, the port pin is driven high (one). If PORTFn is written logic zero when the pin is configured as an output pin, the port pin is driven low (zero). • Bit 7:0 – PORTF7:0 - Port F Data Register Value ATmega256/128/64RFR2 240 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 14.4.14 DDRF – Port F Data Direction Register Bit 7 6 5 4 3 2 1 0 $10 ($30) DDF7 DDF6 DDF5 DDF4 DDF3 DDF2 DDF1 DDF0 DDRF Read/Write RW RW RW RW RW RW RW RW Initial Value 0 0 0 0 0 0 0 0 The DDFn bit in the DDRF Register selects the direction of the PORTF pin n. If DDFn is written logic one, PFn is configured as an output pin. If DDFn is written logic zero, PFn is configured as an input pin. • Bit 7:0 – DDF7:0 - Port F Data Direction Register Value 14.4.15 PINF – Port F Input Pins Address Bit 7 6 5 4 3 2 1 0 $0F ($2F) PINF7:0 PINF Read/Write R R R R R R R R Initial Value 0 0 0 0 0 0 0 0 This register allows access to the PORTF pins independent of the setting of the Data Direction bit DDFn. The port pin can be read through the PINFn Register bit, and writing a logic one to PINFn toggles the value of PORTFn. • Bit 7:0 – PINF7:0 - Port F Input Pins Value 14.4.16 PORTG – Port G Data Register Bit 7 6 5 4 3 2 1 0 $14 ($34) Res1 Res0 PORTG5 PORTG4 PORTG3 PORTG2 PORTG1 PORTG0 PORTG Read/Write R R RW RW RW RW RW RW Initial Value 0 0 0 0 0 0 0 0 If PORTGn is written logic one when the PORTG pin n is configured as an input pin, the pull-up resistor is activated. To switch the pull-up resistor off, PORTGn has to be written logic zero or the pin has to be configured as an output pin. If PORTGn is written logic one when the pin is configured as an output pin, the port pin is driven high (one). If PORTGn is written logic zero when the pin is configured as an output pin, the port pin is driven low (zero). • Bit 7:6 – Res1:0 - Reser ved Bit This bit is reserved for future use. A read access always will return zero. A write access does not modify the content. • Bit 5:0 – PORTG5:0 - Port G Data Register Value 241 8393C-MCU Wireless-09/14

14.4.17 DDRG – Port G Data Direction Register Bit 7 6 5 4 3 2 1 0 $13 ($33) Res1 Res0 DDG5 DDG4 DDG3 DDG2 DDG1 DDG0 DDRG Read/Write R R RW RW RW RW RW RW Initial Value 0 0 0 0 0 0 0 0 The DDGn bit in the DDRG Register selects the direction of the PORTG pin n. If DDGn is written logic one, PGn is configured as an output pin. If DDGn is written logic zero, PGn is configured as an input pin. • Bit 7:6 – Res1:0 - Reserved Bit This bit is reserved for future use. A read access always will return zero. A write access does not modify the content. • Bit 5:0 – DDG5:0 - Port G Data Direction Register Value 14.4.18 PING – Port G Input Pins Address Bit 7 6 5 4 3 2 1 0 $12 ($32) Res1 Res0 PING5 PING4 PING3 PING2 PING1 PING0 PING Read/Write R R R R R R R R Initial Value 0 0 0 0 0 0 0 0 This register allows access to the PORTG pins independent of the setting of the Data Direction bit DDGn. The port pin can be read through the PINGn Register bit, and writing a logic one to PINGn toggles the value of PORTGn. • Bit 7:6 – Res1:0 - Reserved Bit This bit is reserved for future use. A read access always will return zero. A write access does not modify the content. • Bit 5:0 – PING5:0 - Port G Input Pins Value ATmega256/128/64RFR2 242 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 15 Interrupts This section describes the specifics of the interrupt handling as performed in ATmega256/128/64RFR2. For a general explanation of the AVR interrupt handling, refer to "Reset and Interrupt Handling" on page 15. 15.1 Interrupt Vectors in ATmega256/128/64RFR2 Table 15-1. Reset and Interrupt Vectors Vector Program No. Address(2) Source Interrupt Definition External Pin, Power-on Reset, Brown-out 0 $0000(1) RESET Reset, Watchdog Reset, and JTAG AVR Reset 1 $0002 INT0 External Interrupt Request 0 2 $0004 INT1 External Interrupt Request 1 3 $0006 INT2 External Interrupt Request 2 4 $0008 INT3 External Interrupt Request 3 5 $000A INT4 External Interrupt Request 4 6 $000C INT5 External Interrupt Request 5 7 $000E INT6 External Interrupt Request 6 8 $0010 INT7 External Interrupt Request 7 9 $0012 PCINT0 Pin Change Interrupt Request 0 10 $0014 PCINT1 Pin Change Interrupt Request 1 11 $0016(3) PCINT2 Pin Change Interrupt Request 2 12 $0018 WDT Watchdog Time-out Interrupt 13 $001A TIMER2_COMPA Timer/Counter2 Compare Match A 14 $001C TIMER2_COMPB Timer/Counter2 Compare Match B 15 $001E TIMER2_OVF Timer/Counter2 Overflow 16 $0020 TIMER1_CAPT Timer/Counter1 Capture Event 17 $0022 TIMER1_COMPA Timer/Counter1 Compare Match A 18 $0024 TIMER1_COMPB Timer/Counter1 Compare Match B 19 $0026 TIMER1_COMPC Timer/Counter1 Compare Match C 20 $0028 TIMER1_OVF Timer/Counter1 Overflow 21 $002A TIMER0_COMPA Timer/Counter0 Compare Match A 22 $002C TIM ER0_COMPB Timer/Counter0 Compare match B 23 $002E TIMER0_OVF Timer/Counter0 Overflow 24 $0030 SPI_STC SPI Serial Transfer Complete 25 $0032 USART0_RX USART0 Rx Complete 26 $0034 USART0_UDRE USART0 Data Register Empty 27 $0036 USART0_TX USART0 Tx Complete 28 $0038 ANALOG_COMP Analog Comparator 243 8393C-MCU Wireless-09/14

Vector Program No. Address(2) Source Interrupt Definition 29 $003A ADC ADC Conversion Complete 30 $003C EE_READY EEPROM Ready 31 $003E TIMER3_CAPT Timer/Counter3 Capture Event 32 $0040 TIMER3_COMPA Timer/Counter3 Compare Match A 33 $0042 TIMER3_COMPB Timer/Counter3 Compare Match B 34 $0044 TIMER3_COMPC Timer/Counter3 Compare Match C 35 $0046 TIMER3_OVF Timer/Counter3 Overflow 36 $0048 USART1_RX USART1 Rx Complete 37 $004A USART1_UDRE USART1 Data Register Empty 38 $004C USART1_TX USART1 Tx Complete 39 $004E TWI 2-wire Serial Interface 40 $0050 SPM_READY Store Program Memory Ready 41 $0052(3) TIMER4_CAPT Timer/Counter4 Capture Event 42 $0054 TIMER4_COMPA Timer/Counter4 Compare Match A 43 $0056 TIMER4_COMPB Timer/Counter4 Compare Match B 44 $0058 TIMER4_COMPC Timer/Counter4 Compare Match C 45 $005A T IMER4_OVF Timer/Counter4 Overflow 46 $005C(3) TIMER5_CAPT Timer/Counter5 Capture Event 47 $005E TIMER5_COMPA Timer/Counter5 Compare Match A 48 $0060 TIMER5_COMPB Timer/Counter5 Compare Match B 49 $0062 TIMER5_COMPC Timer/Counter5 Compare Match C 50 $0064 TIMER5_OVF Timer/Counter5 Overflow 51 $0066(3) Reserved 52 $0068(3) Reserved 53 $006A(3) Reserved 54 $006C(3) Reserved 55 $006E(3) Reserved 56 $0070(3) Reserved 57 $0072 TRX24_PLL_LOCK Transceiver PLL Lock 58 $0074 TRX24_PLL_UNLOCK Transceiver PLL Unlock 59 $0076 TRX24_RX_START Transceiver Receive Start 60 $0078 TRX24_RX_END Transceiver Receive End 61 $007A TRX24_CCA_ED_DONE Transceiver CCAED Meassurement finished 62 $007C TRX24_XAH_AMI Transceiver Frame Address Match 63 $007E TRX24_TX_END Transceiver Transmit End 64 $0080 TRX24_AWAKE Transceiver Wakeup finished ATmega256/128/64RFR2 244 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 Vector Program No. Address(2) Source Interrupt Definition 65 $0082 SCNT_CMP1 Symbol Counter Compare Match 1 66 $0084 SCNT_CMP 2 Symbol Counter Compare Match 2 67 $0086 SCNT_CMP 3 Symbol Counter Compare Match 3 68 $0088 SCNT_OVFL Symbol Counter Overflow 69 $008A SCNT_BACKOFF Symbol Counter Backoff Slot Counter 70 $008C AES_READY AES Encryption Ready 71 $008E BAT_LOW Battery Monitor Alert 72 $0090 TRX24_TX_START Transceiver Transmit Start 73 $0092 TRX24_AMI0 Transceiver Address Match Filter 0 74 $0094 TRX24_AMI1 Transceiver Address Match Filter 1 75 $0096 T RX24_AMI2 Transceiver Address Match Filter 2 76 $0098 TRX24_AMI3 Transceiver Address Match Filter 3 Note: 1. When the BOOTRST Fuse is programmed, the device will jump to the Boot Loader address at reset, see "Memory Programming" on page 504. 2. When the IVSEL bit in MCUCR is set, Interrupt Vectors will be moved to the start of the Boot Flash Section. The address of each Interrupt Vector will then be the address in this table added to the start address of the Boot Flash Section. 3. Not useful in ATmega256/128/64RFR2 due to limited pin count. 15.2 Reset and Interrupt Vector Placement Table 15-2 below shows Reset and Interrupt Vectors placement for the various combinations of BOOTRST and IVSEL settings. If the program never enables an interrupt source, the Interru pt Vectors are not used, and regular program code can be placed at these locations. This is also the case if the Reset Vector is in the Application section while the Interrupt Vectors are in the Boot section or vice versa. Table 15-2. Reset and Interrupt Vectors Placement (1) BOOTRST IVSEL Reset Address Interrupt Vectors Start Address 1 0 0x0000 0x0002 1 1 0x0000 Boot Reset Address + 0x0002 0 0 Boot Reset Address 0x0002 0 1 Boot Reset Address Boot Reset Address + 0x0002 Note: 1. The Boot Reset Address is shown in Table 30-10 on page 500 through Table 30-6 on page 498. For the BOOTRST Fuse “1” means unprogrammed while “0” means programmed. The most typical and general program setup for the Reset and Interrupt Vector Addresses in ATmega256/128/64RFR2 is: Address Labels Code Comments 0x0000 jmp RESET ;Reset Handler 0x0002 jmp INT0 ;IRQ0 Handler 0x0004 jmp INT1 ;IRQ1 Handler 0x0006 jmp INT2 ;IRQ2 Handler 245 8393C-MCU Wireless-09/14

0x0008 jmp INT3 ;IRQ3 Handler 0x000A jmp INT4 ;IRQ4 Handler 0x000C jmp INT5 ;IRQ5 Handler 0x000E jmp INT6 ;IRQ6 Handler 0x0010 jmp INT7 ;IRQ7 Handler 0x0012 jmp PCINT0 ;PCINT0 Handler 0x0014 jmp PCINT1 ;PCINT1 Handler 0x0016 jmp PCINT2 ;PCINT2 Handler 0X0018 jmp WDT ;Watchdog Timeout Handler 0x001A jmp TIM2_COMPA ;Timer2 CompareA Handler 0x001C jmp TIM2_COMPB ;Timer2 CompareB Handler 0x001E jmp TIM2_OVF ;Timer2 Overflow Handler 0x0020 jmp TIM1_CAPT ;Timer1 Capture Handler 0x0022 jmp TIM1_COMPA ;Timer1 CompareA Handler 0x0024 jmp TIM1_COMPB ;Timer1 CompareB Handler 0x0026 jmp TIM1_COMPC ;Timer1 CompareC Handler 0x0028 jmp TIM1_OVF ;Timer1 Overflow Handler 0x002A jmp TIM0_COMPA ;Timer0 CompareA Handler 0x002C jmp TIM0_COMPB ;Timer0 CompareB Handler 0x002E jmp TIM0_OVF ;Timer0 Overflow Handler 0x0030 jmp SPI_STC ;SPI Transfer Complete Handler 0x0032 jmp USART0_RX ;USART0 RX Complete Handler 0x0034 jmp USART0_UDRE ;USART0,UDR Empty Handler 0x0036 jmp USART0_TX ;USART0 TX Complete Handler 0x0038 jmp ANA_COMP ;Analog Comparator Handler 0x003A jmp ADC ;ADC Conversion Complete Handler 0x003C jmp EE_RDY ;EEPROM Ready Handler 0x003E jmp TIM3_CAPT ;Timer3 Capture Handler 0x0040 jmp TIM3_COMPA ;Timer3 CompareA Handler 0x0042 jmp TIM3_COMPB ;Timer3 CompareB Handler 0x0044 jmp TIM3_COMPC ;Timer3 CompareC Handler 0x0046 jmp TIM3_OVF ;Timer3 Overflow Handler 0x0048 jmp USART1_RX ;USART1 RX Complete Handler 0x004A jmp USART1_UDRE ;USART1,UDR Empty Handler 0x004C jmp USART1_TX ;USART1 TX Complete Handler 0x004E jmp TWI ;2-wire Serial Handler 0x0050 jmp SPM_RDY ;SPM Ready Handler 0x0052 jmp TIM4_CAPT ;Timer4 Capture Handler 0x0054 jmp TIM4_COMPA ;Timer4 CompareA Handler 0x0056 jmp TIM4_COMPB ;Timer4 CompareB Handler 0x0058 jmp TIM4_COMPC ;Timer4 CompareC Handler 0x005A jmp TIM4_OVF ;Timer4 Overflow Handler 0x005C jmp TIM5_CAPT ;Timer5 Capture Handler 0x005E jmp TIM5_COMPA ;Timer5 CompareA Handler 0x0060 jmp TIM5_COMPB ;Timer5 CompareB Handler 0x0062 jmp TIM5_COMPC ;Timer5 CompareC Handler 0x0064 jmp TIM5_OVF ;Timer5 Overflow Handler 0x0066 jmp 0x15e ;0x15e <__bad_interrupt> 0x0068 jmp 0x15e ;0x15e <__bad_interrupt> 0x006A jmp 0x15e ;0x15e <__bad_interrupt> 0x006C jmp 0x15e ;0x15e <__bad_interrupt> 0x006E jmp 0x15e ;0x15e <__bad_interrupt> 0x0070 jmp 0x15e ;0x15e <__bad_interrupt> 0x0072 jmp TRX24_PLL_LOCK ;Transceiver PLL Lock Handler 0x0074 jmp TRX24_PLL_UNLOCK ;Transceiver PLL Unlock Handler 0x0076 jmp TRX24_RX_START ;Transceiver RX Start Handler 0x0078 jmp TRX24_RX_END ;Transceiver RX End Handler 0x007A jmp TRX24_CCA_ED_DONE ;Transceiver CCAED DONE Handler ATmega256/128/64RFR2 246 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 0x007C jmp TRX24_XAH_AMI ;Transceiver Addr. Match Handler 0x007E jmp TRX24_TX_END ;Transceiver Transmit End Handler 0x0080 jmp TRX24_AWAKE ;Transceiver Wake Up Handler 0x0082 jmp SCNT_CMP1 ;Symbol Counter Compare Match 1 0x0084 jmp SCNT_CMP2 ;Symbol Counter Compare Match 2 0x0086 jmp SCNT_CMP3 ;Symbol Counter Compare Match 3 0x0088 jmp SCNT_OVFL ;Symbol Counter Overflow Handler 0x008A jmp SCNT_BACKOFF ;Symbol Backoff Slot Counter H. 0x008C jmp AES_READY ;Encryption/Decryption Ready H. 0x008E jmp BAT_LOW ;Batterie Monitor Alert Handler 0x0090 jmp TRX24_TX_START ;Transceiver Transmit Start Hand. 0x0092 jmp TRX24_AMI0 ;Transceiver Address Match 0 H. 0x0094 jmp TRX24_AMI1 ;Transceiver Address Match 1 H. 0x0096 jmp TRX24_AMI2 ;Transceiver Address Match 2 H. 0x0098 jmp TRX24_AMI3 ;Transceiver Address Match 3 H. ; 0x009A RESET: ldi r16, high(RAMEND) ;Main program start 0x009B out SPH,r16 ;Set Stack Pointer to top of RAM 0x009C ldi r16, low(RAMEND) 0x009D out SPL,r16 0x009E sei ;Enable interrupts 0x009F <instr> xxx ... ... ... ... When the BOOTRST Fuse is unprogrammed, the Boot section size set to 8KBytes and the IVSEL bit in the MCUCR Register is set before any interrupts are enabled, the most typical and general program setup for the Reset and Interrupt Vector Addresses is: Address Labels Code Comments________________________ 0x0000 RESET: ldi r16,high(RAMEND) ;Main program start 0x0001 out SPH,r16 ;Set Stack Pointer to top of RAM 0x0002 ldi r16,low(RAMEND) 0x0003 out SPL,r16 0x0004 sei ;Enable interrupts 0x0005 <instr> xxx .org 0xF002 0xF002 jmp EXT_INT0 ;IRQ0 Handler 0xF004 jmp EXT_INT1 ;IRQ1 Handler ... ... ... ; 0xF098 jmp TRX24_AMI3 ;Transceiver Address Match 3 H. When the BOOTRST Fuse is programmed and the Boot section size set to 8KBytes, the most typical and gen eral program setup for the Reset and Interrupt Vector Addresses is: Address Labels Code Comments________________________ .org 0x0002 0x0002 jmp EXT_INT0 ;IRQ0 Handler 0x0004 jmp EXT_INT1 ;IRQ1 Handler ... ... ... ; .org 0xF000 0xF000 RESET: ldi r16,high(RAMEND) ;Main program start 0xF001 out SPH,r16 ;Set Stack Pointer to top of RAM 0xF002 ldi r16,low(RAMEND) 0xF003 out SPL,r16 0xF004 sei ;Enable interrupts 0xF005 <instr> xxx 247 8393C-MCU Wireless-09/14

When the BOOTRST Fuse is programmed, the Boot section size set to 8KBytes and the IVSEL bit in the MCUCR Register is set before any interrupts are enabled, the most typical and general program setup for the Reset and Interrupt Vector Addresses is: Address Labels Cod e Comments________________________ .org 0xF000 0xF000 jmp RESET ;Reset handler 0xF002 jmp EXT_INT0 ;IRQ0 Handler 0xF004 jmp EXT_INT1 ;IRQ1 Handler ... ... ... ; 0xF09A RESET: ldi r16,high(RAMEND) ; Main program start 0xF09B out SPH,r16 ;Set Stack Pointer to top of RAM 0xF09C ldi r16,low(RAMEND) 0xF09D out SPL,r16 0xF09E sei ;Enable interrupts 0xF09F <instr> xxx 15.3 Moving Interrupts Between Application and Boot Section The MCU Control Register controls the placement of the Interrupt Vector table, see Code Example below. For more details, see "Reset and Interrupt Handling" on page 15. Assembly Code Example Move_interrupts: ; Get MCUCR in r16, MCUCR mov r17, r16 ; Enable change of Interrupt Vectors ori r16, (1<<IVCE) out MCUCR, r16 ; Move interrupts to Boot Flash section ori r16, (1<<IVSEL) out MCUCR, r17 ret C Code Example void Move_interrupts(void) { uchar temp; /* Get MCUCR */ temp = MCUCR; /* Enable change of Interrupt Vectors */ MCUCR = temp|(1<<IVCE); /* Move interrupts to Boot Flash section */ MCUCR = temp|(1<<IVSEL); } ATmega256/128/64RFR2 248 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 15.4 Register Description 15.4.1 MCUCR – MCU Control Register Bit 7 6 5 4 3 2 1 0 $35 ($55) JTD Res1 Res0 PUD Res1 Res0 IVSEL IVCE MCUCR Read/Write RW R R RW R R RW RW Initial Value 0 0 0 0 0 0 0 0 The MCU Control Register contains control bits for general Microcontroller Unit functions. • Bit 7 – JTD - JTAG Interface Disable When this bit is zero, the JTAG interface is enabled if the JTAGEN Fuse is programmed. If this bit is one, the JTAG interface is disabled. In order to avoid unintentional disabling or enabling of the JTAG interface, a timed sequence must be followed when changing this bit: The application software must write this bit to the desired value twice within fo ur cycles to change its value. Note that this bit must not be altered when using the On-chip Debug system. • Bit 6:5 – Res1:0 - Reserved • Bit 4 – PUD - Pull-up Disable When this bit is written to one, the I/O ports pull-up resistors are disabled even if the DDxn and PORTxn Registers are configured to enable the pull-up resistor ({DDxn, PORTxn} = 2'b01). See section "Ports as General Digital I/O" for more details about this feature. • Bit 3:2 – Res1:0 - Reserved • Bit 1 – IVSEL - Interrupt Vector Select When the IVSEL bit is cleared (zero), the Interrupt Vectors are placed at the start of the Flash memory. When this bit is set (one), the Interrupt Vectors are moved to the beginning of the Boot Loader section of the Flash. The actual address of the start of the Boot Flash Section is determined by the BOOTSZ Fuses. Refer to the section "Memory Programming" for details. To avoid unintentional changes of Interrupt Vector tables, a special write procedure must be followed to change the IVSEL bit (see section "Moving Interrupts Between Application and Boot Section" for details): 1. Write the Interrupt Vector Change Enable (IVCE) bit to one; 2. Within four cycles, write the desired value to IVSEL while writing a zero to IVCE. Interrupts will be automatically disabled while this sequence is executed. Interrupts are disabled in the same cycle IVCE is set, and they remain disabled until after t he instruction following the write to IVSEL. If IVSEL is not written, interrupts remain disabled for four cycles. The I-bit in the Status Register is unaffected by the automatic disabling. Note that if Interrupt Vectors are placed in the Boot Loader section and Boot Lock bit BLB02 is programmed, interrupts are disabled while executing from the Application section. If Interrupt Vectors are placed in the Application section and Boot Lock bit BLB12 is programed, interrupts are disabled while executing from the Boot Loader section. • Bit 0 – IVCE - Interrupt Vector Change Enable The IVCE bit must be written to logic one to enable change of the IVSEL bit. IVCE is cleared by hardware four cycles after it is written or when IVSEL is written. Setting the IVCE bit will disable interrupts as explained in the IVSEL description. 249 8393C-MCU Wireless-09/14

16 External Interrupts The External Interrupts are triggered by the INT7:0 pin or any of the PCINT8:0 pins. Observe that if enabled, the interrupts will trigger even if the INT7:0 or PCINT8:0 pins are configured as outputs. This feature provides a way of generating a software interrupt. The Pin Change Interrupt PCI0 will trigger if any enabled PCINT7:0 pin toggles, Pin change interrupt PCI1 if the enabled PCINT8 toggles. PCINT23:9 have no function inside the ATmega256/128/64RFR2. Their corresponding I/O port are not implemented. PCMSK1 and PCMSK0 Registers control which pins contribute to the pin change interrupts. PCI2 and PCMSK2 associated to PCINT23:16 have no task in this design. Pin change interrupts on PCINT8:0 are detected asynchronously. This implies that these interrupts can be used for waking the part also from sleep modes other than Idle mode. The External Interrupts can be triggered by a falling or rising edge or a low level. This is set up as indicated in the specification for the External Interrupt Control Registers – EICRA (INT3:0) and EICRB (INT7:4). When the external interrupt is enabled and is configured as level triggered, the interrupt will trigger as long as the pin is held low. Note that recognition of falling or rising edge interrupts on INT7:4 requires the presence of an I/O clock, described in "Overview" on page 3. Low level interrupts and the edge interrupt on INT3:0 are detected asynchronously. This implies that these interrupts can be used for waking the part also from sleep modes other than Idle mode. The I/O clock is halted in all sleep modes except Idle mode. Note that if a level triggered interrupt is used for wake-up from Power-down, the required level must be held long enough for the MCU to complete the wake-up to trigger the level interrupt. If the level disappears before the end of the Start-up Time, the MCU will still wake up, but no interrupt will be generated. The start-up time is defined by the SUT and CKSEL Fuses as described in "Clock Sources" on page 177. 16.1 Pin Change Interrupt Timing An example of timing of a pin change interrupt is shown in Figure 16-1 below. Figure 16-1. Normal Pin Change Interrupt pin_lat pcint_in_(0) PCINT(0) D Q 0 pcint_syn pcint_setflag PCIF LE pin_sync clk x PCINT(0) in PCMSK(x) clk clk PCINT(n) pin_lat pin_sync pcint_in_(n) pcint_syn pcint_setflag PCIF ATmega256/128/64RFR2 250 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 16.2 Register Description 16.2.1 EICRA – External Interrupt Control Register A Bit 7 6 5 4 3 2 1 0 NA ($69) ISC31 ISC30 ISC21 ISC20 ISC11 ISC10 ISC01 ISC00 EICRA Read/Write RW RW RW RW RW RW RW RW Initial Value 0 0 0 0 0 0 0 0 The External Interrupts 3 - 0 are activated by the external pins INT3:0 if the SREG I-flag and the corresponding interrupt mask in the EIMSK is set. The level and edges on the external pins that activate the interrupts are defined in the following tables. Edges on INT3:0 are registered asynchronously. Pulses on INT3:0 pins wider than the minimum pulse width of typical 50 ns will generate an interrupt. Shorter pulses are not guaranteed to generate an interrupt. If low level interrupt is selected, the low level must be held until the completio n of the currently executing instruction to generate an interrupt. If enabled, a level triggered interrupt will generate an interrupt request as long as the pin is held low. When changing the ISCn bit, an interrupt can occur. Therefore, it is recommended to first disable INTn by clearing its Interrupt Enable bit in the EIMSK Register. Then, the ISCn bit can be changed. Finally, the INTn interrupt flag should be cleared by writing a logical one to its Interrupt Flag bit (INTFn) in the EIFR Register before the interrupt is re-enabled. When changing the ISCn1/ISCn0 bits, the interrupt must be disabled by clearing its Interrupt Enable bit in the EIMSK Register. Otherwise an interrupt can occur when the bits are changed. • Bit 7:6 – ISC31:30 - External Interrupt 3 Sense Control Bit Table 16-146 ISC3 Register Bits Register Bits Value Description ISC31:30 0x00 The low level of INTn generates an interrupt request. 0x01 Any edge of INTn generates asynchronously an interrupt request. 0x02 The falling edge of INTn generates asynchronously an interrupt request. 0x03 The rising edge of INTn generates asynchronously an interrupt request. • Bit 5:4 – ISC21:20 - Exte rnal Interrupt 2 Sense Control Bit Table 16-147 ISC2 Register Bits Register Bits Value Description ISC21:20 0x00 The low level of INTn generates an interrupt request. 0x01 Any edge of INTn generates asynchronously an interrupt request. 0x02 The falling edge of INTn generates asynchronously an interrupt request. 0x03 The rising edge of INTn generates asynchronously an interrupt request. • Bit 3:2 – ISC11:10 - External Interrupt 1 Sense Control Bit 251 8393C-MCU Wireless-09/14

Table 16-148 ISC1 Register Bits Register Bits Value Description ISC11:10 0x00 The low level of INTn generates an interrupt request. 0x01 Any edge of INTn generates asynchronously an interrupt request. 0x02 The falling edge of INTn generates asynchronously an interrupt request. 0x03 The rising edge of INTn generates asynchronously an interrupt request. • Bit 1:0 – ISC01:00 - External Interrupt 0 Sense Control Bit Table 16-149 ISC0 Register Bits Register Bits Value Description ISC01:00 0x00 The low level of INTn generates an interrupt request. 0x01 Any edge of INTn generates asynchronously an interrupt request. 0x02 The falling edge of INTn generates asynchronously an interrupt request. 0x03 The rising edge of INTn generates asynchronously an interrupt request. 16.2.2 EICRB – External Interrupt Control Register B Bit 7 6 5 4 3 2 1 0 NA ($6A) ISC71 ISC70 ISC61 ISC60 ISC51 ISC50 ISC41 ISC40 EICRB Read/Write RW RW RW RW RW RW RW RW Initial Value 0 0 0 0 0 0 0 0 The External Interrupts 7 - 4 are activated by the external pins INT7:4 if the SREG I-flag and the corresponding interrupt mask in the EIMSK is set. The level and edges on the external pins that activate the interrupts are defined in the following tables. Edges on INT7:4 are registered asynchronously. Pulses on INT7:4 pins wider than the minimum pulse width of typical 50 ns will generate an interrupt. Shorter pulses are not guaranteed to generate an interrupt. If low level interrupt is selected, the low level must be held until the complet i on of the currently executing instruction to generate an interrupt. If enabled, a level triggered interrupt will generate an interrupt request as long as the pin is held low. When changing the ISCn bit, an interrupt can occur. Therefore, it is recommended to first disable INTn by clearing its Interrupt Enable bit in the EIMSK Register. Then, the ISCn bit can be changed. Finally, the INTn interrupt flag should be cleared by writing a logica l one to its Interrupt Flag bit (INTFn) in the EIFR Register before the interrupt is re-enabled. When changing the ISCn1/ISCn0 bits, the interrupt must be disabled by clearing its Interrupt Enable bit in the EIMSK Register. Otherwise an interrupt can occur when the bits are changed. • Bit 7:6 – ISC71:70 - External Interrupt 7 Sense Control Bit Table 16-150 ISC7 Register Bits Register Bits Value Description ISC71:70 0x00 The low level of INTn generates an interrupt ATmega256/128/64RFR2 252 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 Register Bits Value Description request. 0x01 Any edge of INTn generates asynchronously an interrupt request. 0x02 The falling edge of INTn generates asynchronously an interrupt request. 0x03 The rising edge of INTn generates asynchronously an interrupt request. • Bit 5:4 – ISC61:60 - External Interrupt 6 Sense Control Bit Table 16-151 ISC6 Register Bits Register Bits Value Description ISC61:60 0x00 The low level of INTn generates an interrupt request. 0x01 Any edge of INTn generates asynchronously an interrupt request. 0x02 The falling edge of INTn generates asynchronously an interrupt request. 0x03 The rising edge of INTn generates asynchronously an interrupt request. • Bit 3:2 – ISC51:50 - External Interrupt 5 Sense Control Bit Table 16-152 ISC5 Register Bits Register Bits Value Description ISC51:50 0x00 The low level of INTn generates an interrupt request. 0x01 Any edge of INTn generates asynchronously an interrupt request. 0x02 The falling edge of INTn generates asynchronously an interrupt request. 0x03 The rising edge of INTn generates asynchronously an interrupt request. • Bit 1:0 – ISC41:40 - External Interrupt 4 Sense Control Bit Table 16-153 ISC4 Register Bits Register Bits Value Description ISC41:40 0x00 The low level of INTn generates an interrupt request. 0x01 Any edge of INTn generates asynchronously an interrupt request. 0x02 The falling edge of INTn generates asynchronously an interrupt request. 0x03 The rising edge of INTn generates asynchronously an interrupt request. 253 8393C-MCU Wireless-09/14

16.2.3 EIMSK – External Interrupt Mask Register Bit 7 6 5 4 3 2 1 0 $1D ($3D) INT7 INT6 INT5 INT4 INT3 INT2 INT1 INT0 EIMSK Read/Write RW RW RW RW RW RW RW RW Initial Value 0 0 0 0 0 0 0 0 When an INT7:0 bit is written to one and the I-bit in the Status Register (SREG) is set (one), the corresponding external pin interrupt is enabled. The Interrupt Sense Control bits in the External Interrupt Control Registers EICRA and EICRB define whether the External Interrupt is activated on rising or falling edge or level sensed. Activity on any of these pins will trigger an in terrupt request even if the pin is enabled as an output. This provides a way of generating a software interrupt. • Bit 7:0 – INT7:0 - External Interrupt Request Enable Table 16-154 INT Register Bits Register Bits Value Description INT7:0 0x00 All external pin interrupts are disabled. 0xff All external pin interrupts are enabled. 16.2.4 EIFR – External Interrupt Flag Register Bit 7 6 5 4 3 2 1 0 $1C ($3C) INTF7 INTF6 INTF5 INTF4 INTF3 INTF2 INTF1 INTF0 EIFR Read/Write RW RW RW RW RW RW RW RW Initial Value 0 0 0 0 0 0 0 0 When an edge or logic change on the INT7:0 pin triggers an interrupt request, INTF7:0 becomes set (one). If the I-bit in SREG and the corresponding interrupt enable bit INT7:0 in EIMSK are set (one), the MCU will jump to the interrupt vector. The flag is cleared when the interrupt routine is executed. Alternatively, the flag can be cleared by writing a logical one to it. These flags are always cleared when INT7:0 are configured as level interrupt. Note that when entering sleep mode with the INT3:0 interrupts disabled, the input buffers on these pins will be disabled. This may cause a logic change in internal signals which will set the INTF3:0 flags. See "Digital Input Enable and Sleep Modes" for more information. • Bit 7:0 – INTF7:0 - External Interrupt Flag Table 16-155 INTF Register Bits Register Bits Value Description INTF7:0 0x00 No edge or logic change on INT7:0 occurred. 0x01 A edge or logic change on INT0 occurred and triggered an interrupt request. 0x02 ... 0x80 A edge or logic change on INT7 occurred and triggered an interrupt request. ATmega256/128/64RFR2 254 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 16.2.5 PCICR – Pin Change Interrupt Control Register Bit 7 6 5 4 3 2 1 0 NA ($68) Res4 Res3 Res2 Res1 Res0 PCIE2 PCIE1 PCIE0 PCICR Read/Write R R R R R RW RW RW Initial Value 0 0 0 0 0 0 0 0 • Bit 7:3 – Res4:0 - Reserved Bit This bit is reserved for future use. A read access always will return zero. A write access does not modify the content. • Bit 2 – PCIE2 - Pin Change Interrupt Enable 2 When the PCIE2 bit is set (one) and the I-bit in the Status Register (SREG) is set (one), pin change interrupt 2 is enabled. Any change on any enabled PCINT23:16 pin will cause an interrupt. The corresponding interrupt of Pin Change Interrupt Request is executed from the PCI2 Interrupt Vector. PCINT23:16 pins are enabled individually by the PCMSK2 Register. Note that the I/O ports corresponding to PCINT23:16 are not implemented. Therefore PCI E2 has no function in this device. • Bit 1 – PCIE1 - Pin Change Interrupt Enable 1 When the PCIE1 bit is set (one) and the I-bit in the Status Register (SREG) is set (one), pin change interrupt 1 is enabled. Any change on any enabled PCINT15:8 pin will cause an interrupt. The corresponding interrupt of Pin Change Interrupt Request is executed from the PCI1 Interrupt Vector. PCINT15:8 pins are enabled individually by the PCMSK1 Register. Note that the I/O ports corresponding to PCINT15:9 are not implemented. • Bit 0 – PCIE0 - Pin Change Interrupt Enable 0 When the PCIE0 bit is set (one) and the I-bit in the Status Register (SREG) is set (one), pin change interrupt 0 is enabled. Any change on any enabled PCINT7:0 pin will cause an interrupt. The corresponding interrupt of Pin Change Interrupt Request is executed from the PCI0 Interrupt Vec t or. PCINT7:0 pins are enabled individually by the PCMSK0 Register. 16.2.6 PCIFR – Pin Change Interrupt Flag Register Bit 7 6 5 4 3 2 1 0 $1B ($3B) Res4 Res3 Res2 Res1 Res0 PCIF2 PCIF1 PCIF0 PCIFR Read/Write R R R R R RW RW RW Initial Value 0 0 0 0 0 0 0 0 • Bit 7:3 – Res4:0 - Reserved Bit This bit is reserved for future use. A read access always will return zero. A write access does not modify the content. • Bit 2 – PCIF2 - Pin Change Interrupt Flag 2 When a logic change on any PCINT23:16 pin triggers an interrupt request, PCIF2 becomes set (one). If the I-bit in SREG and the PCIE2 bit in PCICR are set (one), the MCU will jump to the corresponding Interrupt Vector. The flag is cleared when the interrupt routine is executed. Alternatively, the flag can be cleared by writing a logical one to it. Note that the I/O ports corresponding to PCINT23:16 are not implemented. Therefore PCIF2 has no function in this device. 255 8393C-MCU Wireless-09/14

• Bit 1 – PCIF1 - Pin Change Interrupt Flag 1 When a logic change on any PCINT15:8 pin triggers an interrupt request, PCIF1 becomes set (one). If the I-bit in SREG and the PCIE1 bit in PCICR are set (one), the MCU will jump to the corresponding Interrupt Vector. The flag is cleared when the interrupt routine is executed. Alternatively, the flag can be cleared by writing a logical one to it. Note that the I/O ports corresponding to PCINT15:9 are not implemented. • Bit 0 – PCIF0 - Pin Change Interrupt Flag 0 When a logic change on any PCINT7:0 pin triggers an interrupt request, PCIF0 becomes set (one). If the I-bit in SREG and the PCIE0 bit in PCICR are set (one), the MCU will jump to the corresponding Interrupt Vector. The flag is cleared when the interrupt routine is executed. Alternatively, the flag can be cleared by writing a logical one to it. 16.2.7 PCMSK2 – Pin Change Mask Register 2 Bit 7 6 5 4 NA ($6D) PCINT23 PCINT22 PCINT21 PCINT20 PCMSK2 Read/Write RW RW RW RW Initial Value 0 0 0 0 Bit 3 2 1 0 NA ($6D) PCINT19 PCINT18 PCINT17 PCINT16 PCMSK2 Read/Write RW RW RW RW Initial Value 0 0 0 0 Note that the PCMSK2 register has no function in this device. The I/O ports associated to PCINT23:16 are not implemented. Normally each bit PCINT23:16 selects whether the pin change interrupt is enabled on the corresponding I/O pin. If PCINT23:16 is set and the PCIE2 bit in PC ICR is set, the pin change interrupt is enabled on the corresponding I/O pin. If PCINT23:16 is cleared, the pin change interrupt on the corresponding I/O pin is disabled. • Bit 7:0 – PCINT23:16 - Pin Change Enable Mask 16.2.8 PCMSK1 – Pin Change Mask Register 1 Bit 7 6 5 4 NA ($6C) PCINT15 PCINT14 PCINT13 PCINT12 PCMSK1 Read/Write RW RW RW RW Initial Value 0 0 0 0 Bit 3 2 1 0 NA ($6C) PCINT11 PCINT10 PCINT9 PCINT8 PCMSK1 Read/Write RW RW RW RW Initial Value 0 0 0 0 Bit PCINT8 selects whether the pin change interrupt is enabled on the corresponding I/O pin. If PCINT8 is set and the PCIE1 bit in PCICR is set, the pin change interrupt is enabled on the corresponding I/O pin. If PCINT8 is cleared, the pin change interrupt on the corresponding I/O pin is disabled. ATmega256/128/64RFR2 256 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 • Bit 7:1 – PCINT15:9 - Pin Change Enable Mask Bits 15:9 of the PCMSK1 register have no function in this device. The I/O ports associated to PCINT15:9 are not implemented. • Bit 0 – PCINT8 - Pin Ch a nge Enable Mask 8 If this bit is set to one the pin change interrupt on the corresponding I/O pin is enabled. If this bit is set to zero the pin change interrupt is disabled. 16.2.9 PCMSK0 – Pin Change Mask Register 0 Bit 7 6 5 4 3 2 1 0 NA ($6B) PCINT7 PCINT6 PCINT5 PCINT4 PCINT3 PCINT2 PCINT1 PCINT0 PCMSK0 Read/Write RW RW RW RW RW RW RW RW Initial Value 0 0 0 0 0 0 0 0 Each bit PCINT7:0 selects whether the pin change interrupt is enabled on the corresponding I/O pin. If PCINT7:0 is set and the PCIE0 bit in PCICR is set, the pin change interrupt is enabled on the corresponding I/O pin. If PCINT7:0 is cleared, the pin change interrupt on the corresponding I/O pin is disabled. • Bit 7:0 – PCINT7:0 - Pin Change Enable Mask 257 8393C-MCU Wireless-09/14

17 8-bit Timer/Counter0 with PWM 17.1 Features • Two Independent Output Compare Units • Double Buffered Output Compare Registers • Clear Timer on Compare Match (Auto Reload) • Glitch Free, Phase Correct Pulse Width Modulator (PWM) • Variable PWM Period • Frequency Generator • Three Independent Inte rrupt Sources (TOV0, OCF0A, and OCF0B) 17.2 Overview Timer/Counter0 is a general purpose 8-bit Timer/Counter module with two independent Output Compare Units and with PWM support. It allows accurate program execution timing (event management) and wave generation. A simplified block diagram of the 8-bit Timer/Counter is shown in Figure 17-1. For the actual placement of I/O pins refer to section "Pin Configurations" on page 2. CPU accessible I/O Registers, including I/O bits and I/O pins, are shown in bold. The device- specific I/O Register and bit locations are listed in the "Register Description" on page 270. Figure 17-1. 8-bit Timer/Counter Block Diagram Count TOVn Clear (Int.Req.) Control Logic Direction clk Clock Select Tn Edge Tn Detector TOP BOTTOM ( From Prescaler ) Timer/Counter TCNTn = = 0 OCnA (Int.Req.) = Waveform OCnA Generation OCRnA Fixed OCnB TOP (Int.Req.) S Value U B = Waveform OCnB A Generation T A D OCRnB TCCRnA TCCRnB ATmega256/128/64RFR2 258 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 17.2.1 Registers The Timer/Counter (TCNT0) and Output Compare Registers (OCR0A and OCR0B) are 8-bit registers. Interrupt request signals (abbreviated to Int.Req. in the figure) are all visible in the Timer Interrupt Flag Register (TIFR0). All interrupts are individually masked with the Timer Interrupt Mask Register (TIMSK0). TIFR0 and TIMSK0 are not shown in the figure. The Timer/Counter can be clocked internally, via the prescaler or by an external clock source on the T0 pin. The Clock Select logic block controls which clock source and edge the Timer/Counter uses to increment (or decrement) its value. The Timer/Counter is inactive when no clock source is selected. The output from the Clock Select logic is referred to as the timer clock (clk ). T0 The double buffered Output Compare Registers (OCR0A and OCR0B) are compared with the Timer/Counter value at all times. The result of the compare can be used by the Waveform Generator to generate a PWM or variable frequency output on the Output Compare pins (OC0A and OC0B); see "Output Compare Unit" on page 260 for details. The Compare Match event will also set the Compare Flag (OCF0A or OCF0B) which can be used to generate an Output Compare interrupt request. 17.2.2 Definitions Many register and bit references in this section are written in general form. A lower case “n” replaces the Timer/Counter number (in this case 0). A lower case “x” replaces the Output Compare Unit (in this case Compare Unit A or Compare Unit B). However when using the register or bit defines in a program, the precise form must be used i.e., TCNT0 for accessing Timer/Counter0 counter value and so on. The definitions in Table 17-1 are also used extensively throughout the document. Table 17-1. Definitions BOTTOM The counter reaches the BOTTOM when it becomes 0x00. MAX The counter reaches its MAXimum when it becomes 0xFF (decimal 255). TOP The counter reaches the TOP when it becomes equal to the highest value in the count sequence. The TOP value can be assigned to be the fixed value 0xFF (MAX) or the value stored in the OCR0A Register. The assignment is dependent on the mode of operation. 17.3 Timer/Counter Clock Sources The Timer/Counter can be clocked by an internal or an external clock source. The clock source is selected by the C lock Select logic which is controlled by the Clock Select (CS02:0) bits located in the Timer/Counter Control Register (TCCR0B). For details on clock sources and prescaler see Timer/Counter 0, 1, 3, 4, and 5 Prescaler on page 336 17.4 Counter Unit The main part of the 8-bit Timer/Counter is the programmable bi-directional counter unit. Figure 17-2 shows a block diagram of the counter and its surroundings. 259 8393C-MCU Wireless-09/14

Figure 17-2. Counter Unit Block Diagram TOVn DATA BUS (Int.Req.) Clock Select count Edge Tn TCNTn clear Control Logic clkTn Detector direction ( From Prescaler ) bottom top Signal description (internal signals): count Increme nt or decrement TCNT0 by 1; direction Select between increment and decrement; clear Clear TCNT0 (set all bits to zero); clk Timer/Counter clock referred to as clk in the following text; Tn T0 top Signalize that TCNT0 has reached maximum value; bottom Signalize that TCNT0 has reached minimum value (zero); Depending of the mode of operation used, the counter is cleared, incremented or decremented at each timer clock (clk ). clk can be generated from an external or T0 T0 internal clock source selected by the Clock Select bits (CS02:0). When no clock source is selected (CS02:0 = 0) the timer is stopped. However, the TCNT0 value can be accessed by the CPU regardless of whether clk is present or not. A CPU write access T0 overrides (has priority over) all counter clear or count operations. The counting sequence is determined by the setting of the WGM01 and WGM00 bits located in the Timer/Counter Control Register (TCCR0A) and the WGM02 bit located in the Timer/Counter Control Register B (TCCR0B). There are close connections between how the counter behaves (counts) and how waveforms are generated on the Output Compare outputs OC0A and OC0B. For more details about advanced counting sequences and waveform g eneration, see "Modes of Operation" on page 264. The Timer/Counter Overflow Flag (TOV0) is set according to the mode of operation selected by the WGM02:0 bits. TOV0 can be used for generating a CPU interrupt. 17.5 Output Compare Unit The 8-bit comparator continuously compares TCNT0 with the Output Compare Registers (OCR0A and OCR0B). The comparator signals a match whenever TCNT0 equals OCR0A or OCR0B. A match will set the Output Compare Flag (OCF0A or OCF0B) at the next clock cycle of the timer. If the corresponding interrupt is enabled, the Output Compare Flag generates an Output Compare interrupt. The Output Compare Flag is automatically cleared when the interrupt is executed. The flag can alternatively be software-cleared by writing a logical one to its I/O bit location. The Waveform Generator uses the match signal to generate an output according to the operating mode set by the WGM02:0 bits and Compare Output mode (COM0x1:0) bits. The MAX and BOTTOM signals are used by the Waveform Generator for handling the special cases of the extreme values in some modes of operation (refer to "Modes of Operation" on page 264). ATmega256/128/64RFR2 260 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 Figure 17-3. Output Compare Unit, Block Diagram DATA BUS OCRnx TCNTn = (8-bit Comparator ) OCFnx (Int.Req.) top bottom Waveform Generator OCnx FOCn WGMn1:0 COMnX1:0 The OCR0x Registers are double buffered when using any of the Pulse Width Modulation (PWM) modes. For the normal and Clear Timer on Compare (CTC) modes of operation, the double buffering is disabled. The double buffering synchronizes the update of the OCR0x Compare Registers to either TOP or BOTTOM of the counting sequence. The synchronization prevents the occurrence of odd-length, non-symmetrical PWM pulses and thereby making the output glitch-free. The OCR0x Register access may seem complex, but this is not the case. When the double buffering is enabled, the CPU has access to the OCR0x Buffer Register. If double buffering is disabled the CPU will access the OCR0x directly. 17.5.1 Force Output Compare In non-PWM waveform generation modes, the match output of the comparator can be forced by writing a one to the Force Output Compare (FOC0x) bit. Forcing Compare Match will not set the OCF0x Flag or reload/clear the timer, but the OC0x pin will be updated as if a real Compare Match had occurred (the COM0x1:0 bits settings define whether the OC0x pin is set, cleared or toggled). 17.5.2 Compare Match Blocking by TCNT0 Write All CPU write operations to the TCNT0 Register will block any Compare Match that occur in the next timer clock cycle, even when the timer is stopped. This feature allows OCR0x to be initialized to the same value as TCNT0 without triggering an interrupt when the Timer/Counter clock is enabled. 17.5.3 Using the Output Compare Unit Since writing TCNT0 in any mode of operation will block all Compare Matches for one timer clock cycle, there are risks involved when changing TCNT0 while using the Output Compare Unit, independently of whether the Timer/Counter is running or not. If the value written to TCNT0 equals the OCR0x value, the Compare Match will be missed resulting in an incorrect waveform generation. Similarly, do not write the TCNT0 value equal to BOTTOM when the counter is down-counting. The setup of the OC0x should be performed before setting the Data Direction Register for the port pin to output. The easiest way of setting the OC0x value is to use the Force Output Compare (FOC0x) strobe bits in Normal mode. The OC0x Registers keep their values even when changing between Waveform Generation modes. 261 8393C-MCU Wireless-09/14

Be aware that the COM0x1:0 bits are not double buffered together with the compare value. A Change of the COM0x1:0 bits will take effect immediately. 17.6 Compare Match Output Unit The Compare Output mode (COM0x1:0) bits have two functions. The Waveform Generator uses the COM0x1:0 bits for defining the Output Compare (OC0x) state at the next Compare Match. The COM0x1:0 bits control also the OC0x pin output source. Figure 17-4 shows a simplified schematic of the logic affected by the COM0x1:0 bit setting. The I/O Registers, I/O bits and I/O pins in the figure are shown in bold. Only the parts of the general I/O Port Control Registers (DDR and PORT) affected by the COM0x1:0 bits are shown. When referring to the OC0x state, the reference is to the internal OC0x Register and not to the OC0x pin. The OC0x Register is reset to “0” if a system reset occurs. Figure 17-4. Compare Match Output Unit Schematic COMnx1 COMnx0 Waveform D Q FOCn Generator 1 OCnx OCnx Pin 0 D Q S U B PORT A T A D D Q DDR clkI/O The general I/O port function is overridden by the Output Compare (OC0x) from the Waveform Generator if either of the COM0x1:0 bits are set. However the OC0x pin direction (input or output) is still controlled by the Data Direction Register (DDR) of the port pin. The Data Direction Register bit of the OC0x pin (DDR_OC0x) must be set as output before the OC0x value is visible at the pin. The port override function is independent of the Waveform Generation mode. The design of the Output Compare pin logic allows initializing the OC0x state before the output is enabled. Note that some COM0x1:0 bit settings are reserved for certain modes of operation (see "Register Description" on page 270). 17.6.1 Compare Output Mode and Waveform Generation The Waveform Generator uses the COM0x1:0 bits differently in Normal, CTC and PWM modes. A setting of COM0x1:0 = 0 tells the Waveform Generator in all modes that no action on the OC0x Register is to be performed on the next Compare Match. For compare output actions in the non-PWM modes refer to Table 17-2. For fast PWM mode refer to Table 17-3 and for phase correct PWM refer to Table 17-4. ATmega256/128/64RFR2 262 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 A state change of the COM0x1:0 bits will have effect at the first Compare Match after the bits are written. For non-PWM modes the action can be forced to have immediate effect by using the FOC0x strobe bits. The following table shows the COM0x1:0 bit functionality when the WGM02:0 bits are set to a normal or CTC mode (non-PWM). Table 17-2. Compare Output Mode, non-PWM Mode COM0A1 COM0A0 COM0B1 COM0B0 Description 0 0 Normal port operation, OC0x disconnected; 0 1 Toggle OC0x on Compare Match; 1 0 Cle ar OC0x on Compare Match; 1 1 Set OC0x on Compare Match; Table 17-3 shows the COM0x1:0 bit functionality when the WGM01:0 bits are set to fast PWM mode. Table 17-3. Compare Outpu t Mode, Fast PWM Mode COM0A1 COM0A0 COM0B1 COM0B0 Description 0 0 Normal port operation, OC0x disconnected. WGM02 = 0: Normal Port Operation, OC0A Disconnected. 0 1 WGM02 = 1: Toggle OC0A on Compare Match. OC0B: not applicable, reserved function; Cle ar OC0x on Compare Match, set OC0x at BOTTOM, (non- 1 0 inverting mode). Set OC0x on Compare Match, clear OC0x at BOTTOM, (inverting 1 1 mode). Note: A special case occurs when OCR0x equals TOP and COM0x1 is set. In this case, the Compare Match is ig nored, but the set or clear is done at BOTTOM. See "Fast PWM Mode" on page 265. Table 17-4 shows the COM0x1:0 bit functionality when the WGM02:0 bits are set to phase correct PWM mode. Table 17-4. Compare Output Mode, Phase Correct PWM Mode COM0A1 COM0A0 COM0B1 COM0B0 Description 0 0 No rmal port operation, OC0x disconnected. WGM02 = 0: Normal Port Operation, OC0A Disconnected. 0 1 WGM02 = 1: Toggle OC0A on Compare Match. OC0B: not applicable, reserved function; Clear OC0x on Compare Match when up-counting. Set OC0x on 1 0 Compare Match when down-counting. Set OC0x on Compare Match when up-counting. Clear OC0x on 1 1 Compare Match when down-counting. Note: A special case occurs when OCR0x equals TOP and COM0x1 is set. In this case, the Compare Match is ignored, but the set or clear is done at TOP. See "Fast PWM Mode" on page 265 for more details. 263 8393C-MCU Wireless-09/14

17.7 Modes of Operation The mode of operation i.e., the behavior of the Timer/Counter and the Output Compare pins, is defined by the combination of the Waveform Generation mode (WGM02:0) and Compare Output mode (CO M0x1:0) bits. The Compare Output mode bits do not affect the counting sequence while the Waveform Generation mode bits do. The COM0x1:0 bits control whether the PWM output generated should be inverted or not (inverted or non-inverted PWM). For non-PWM modes the COM0x1:0 bits control whether the output should be set, cleared, or toggled at a Compare Match (see "Output Compare Unit" on page 260). For detailed timing information see "Timer/Counter Timing Diagrams" on page 268. Table 17-5 shows the funct ion of the WGM2:0 bits of registers TCCR0A and TCCR0B. These bits control the counting sequence of the counter, the source for maximum (TOP) counter value, and what type of waveform generation to be used. Table 17-5. Waveform Generation Mode Bit Description Timer/Counter Mode of Update of TOV Flag Mode WGM2 WGM1 WGM0 Operation TOP OCRX at Set on(0,0) 0 0 0 0 Normal 0xFF Immediate MAX PWM, Phase 1 0 0 1 0xFF TOP BOTTOM Correct 2 0 1 0 CTC OCRA Immediate MAX 3 0 1 1 Fast PWM 0xFF TOP MAX 4 1 0 0 Reserved – – – PWM, Phase 5 1 0 1 OCRA TOP BOTTOM Correct 6 1 1 0 Reserved – – – 7 1 1 1 Fast PWM OCRA BOTTOM TOP Notes: 1. MAX = 0xFF 2. BOTTOM = 0x00 17.7.1 Normal Mode The simplest mode of operation is the Normal mode (WGM02:0 = 0). In this mode the counting direction is always up (incrementing) and no counter clear is performed. The counter simply overruns when it passes its maximum 8-bit value (TOP = 0xFF) and then restarts from the BOTTOM (0x00). In normal operation the Timer/Counter Overflow Flag (TOV0) will be set at the same timer clock cycle when the TCNT0 becomes zero. The TOV0 Flag in this case behaves like a 9th bit, except that it is only set and not cleared. However, the timer resolution can be increased by software utilizing the timer overflow interrupt that automatically clears the TOV0 Flag. There are no special cases to consider in the Normal mode. A new counter value can be written at anytime. The Output Compare Unit can be used to generate interrupts at some given time. It is not recommended to use the Output Compare for waveform generation in Normal mode, since this will occupy too much CPU time. 17.7.2 Clear Timer on Compare Match (CTC) Mode In Clear Timer on Compare (CTC) mode (WGM02:0 = 2), the OCR0A Register is used to manipulate the counter resolution. In CTC mode the counter is cleared to zero when the counter value (TCNT0) matches OCR0A. The OCR0A value defines the TOP value ATmega256/128/64RFR2 264 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 for the counter, hence also its resolution. This mode allows greater control of the Compare Match output frequency. It also simplifies the operation of counting external events. The timing diagram for the CTC mode is shown in Figure 17-5. The counter value (TCNT0) increases until a Compare Match occurs between TCNT0 and OCR0A. The counter (TCNT0) is then cleared. Figure 17-5. CTC Mode Timing Diagram OCnx Interrupt Flag Set TCNTn OCn (COMnx1:0 = 1) (Toggle) Period 1 2 3 4 An interrupt can be generated each time the counter value reaches the TOP value by using the OCF0A Flag. If the interrupt is enabled, the interrupt handler routine can update the TOP value. However, changing TOP to a value close to BOTTOM when the counter is running with no or a low prescaler value must be done with care since the CTC mode does not have the double buffering feature. If the new value written to OCR0A is lower than the current value of TCNT0, the counter will miss the Compare Match. The counter will then have to count to its maximum value (0xFF) and wrap around starting at 0x00 before the Compare Match can occur. For generating a waveform output in CTC mode, the OC0A output can be set to toggle its logical level on each Compare Match by setting the Compare Output mode bits to toggle mode (COM0A1:0 = 1). The OC0A value will not be visible on the port pin unless the data direction of the pin is set to output. The generated waveform will have a maximum frequency of f = f /2 when OCR0A is set to zero (0x00). The waveform OC0 clkI/O frequency is defined by the following equation: f f = clkI/O OC0x 2⋅N ⋅(1+OCR0x) The N variable represents the prescaler factor (1, 8, 64, 256 or 1024). As for the Normal mode of operation, the TOV0 Flag is set in the same timer clock cycle that the counter changes from MAX to 0x00. 17.7.3 Fast PWM Mode The fast Pulse Width Modulation (PWM) mode (WGM02:0 = 3 or 7) provides a high frequency PWM waveform generation option. The fast PWM mode differs from the other PWM modes by its single-slope operation. The counter counts from BOTTOM to TOP and then restarts from BOTTOM. TOP is defined as 0xFF when WGM2:0 = 3, and OCR0A when WGM2:0 = 7. In non-inverting Compare Output mode the Output Compare (OC0x) is cleared on the Compare Match between TCNT0 and OCR0x and set at BOTTOM. In inverting Compare Output mode the output is set on Compare Match and cleared at BOTTOM. Due to the single-slope operation, the operating frequency of the fast PWM mode can be twice as high as in the phase correct PWM mode that uses dual-slope operation. This high frequency operation makes the fast 265 8393C-MCU Wireless-09/14

PWM mode well suited for power regulation, rectification and DAC applications. The high frequency allows physically small sized external components (coils, capacitors), and therefore reduces total system cost. In fast PWM mode, the cou nter is incremented until the counter value matches the TOP value. The counter is then cleared at the following timer clock cycle. The timing diagram for the fast PWM mode is shown in Figure 17-6. The TCNT0 value is shown in the timing diagram as a histogram illustrating the single-slope operation. The diagram includes non-inverted and inverted PWM outputs. The small horizontal line marks on the TCNT0 slopes represent Compare Matches between OCR0x and TCNT0. Figure 17-6. Fast PWM Mode Timing Diagram OCRnx Interrupt Flag Set OCRnx Update and(cid:3) TOVn Interrupt Flag Set TCNTn OCnx (COMnx1:0 = 2) OCnx (COMnx1:0 = 3) Period 1 2 3 4 5 6 7 The Timer/Counter Overflow Flag (TOV0) is set each time the counter reaches TOP. The interrupt handler routine can be used for updating the compare value if the interrupt is enabled. In fast PWM mode the compare unit allows generating PWM waveforms on the OC0x pins. Setting the COM0x1:0 bits to 2 will produce a non-inverted PWM. An inverted PWM output can be generated by setting the COM0x1:0 to 3. Setting the COM0A1:0 bits to 1 allows the OC0A pin to toggle on Compare Matches if the WGM02 bit is set. This option is not available for the OC0B pin (see Table 17-3 on page 263). The actual OC0x value will only be visible at the port pin if the data direction of the port pin is set to output. The PWM waveform is generated by setting (or clearing) the OC0x Register at the Compare Match between OCR0x and TCNT0, and by clearing (or setting) the OC0x Register at the timer clock cycle when the counter is cleared (changes from TOP to BOTTOM). The PWM frequency for the output f can be calculated with the following OC0xPWM equation: f f = clkI/O OC0xPWM N ⋅256 The N variable represents the prescale factor (1, 8, 64, 256 or 1024). The extreme values for the OCR0A Register represent special cases when generating a PWM waveform output in the fast PWM mode. If the OCR0A is set equal to BOTTOM, the output will be a narrow spike for each MAX+1 timer clock cycle. Setting the OCR0A ATmega256/128/64RFR2 266 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 equal to MAX will result in a constantly high or low output (depending on the polarity of the output set by the COM0A1:0 bits.) A frequency with 50% duty cycle waveform output in fast PWM mode can be achieved by setting OC0x to toggle its logical level on each Compare Match (COM0x1:0 = 1). The generated waveform will have a maximum frequency of f = f /2 when OCR0A OC0xPWM clkI/O is set to zero. This feature is similar to the OC0A toggle in CTC mode, except that in the fast PWM mode the double buffer feature of the Output Compare unit is enabled. 17.7.4 Phase Correct PWM Mode The phase correct pulse-width modulation (PWM) mode (WGM02:0 = 1 or 5) provides a phase-correct, high-resolution PWM waveform generation option. The phase correct PWM mode is based on a dual-slope operation. The counter counts repeatedly from BOTTOM to TOP and then from TOP to BOTTOM. TOP is defined as 0xFF when WGM2:0 = 1 and TOP = OCR0A when WGM2:0 = 5. In non-inverting Compare Output mode, the Output Compare (OC0x) is cleared on the Compare Match between TCNT0 and OCR0x while up-counting, and OC0x is set on the Compare Match while down- counting. The operation is inverted in inverting Output Compare mode. The dual-slope operation has a lower maximum operation frequency than single-slope operation. However, due to the symmetric feature of the dual-slope PWM modes, these modes are preferred for motor control applications. In phase correct PWM mode the counter is incremented until the counter value matches TOP. The counter changes the direction when reaching TOP. The TCNT0 value will be equal to TOP for one timer clock cycle. The timing diagram for the phase correct PWM mode is shown in Figure 17-7 below. The TCNT0 value is shown in the timing diagram as a histogram illustrating the dual-slope operation. The diagram includes non-inverted and inverted PWM outputs. The small horizontal line marks on the TCNT0 slopes represent Compare Matches between OCR0x and TCNT0. Figure 17-7. Phase Correct PWM Mode Timing Diagram OCnx Interrupt Flag Set OCRnx Update TOVn Interrupt Flag Set TCNTn OCnx (COMnx1:0 = 2) OCnx (COMnx1:0 = 3) Period 1 2 3 The Timer/Counter Overflow Flag (TOV0) is set each time the counter reaches BOTTOM. The Interrupt Flag can be used to generate an interrupt each time the counter reaches the BOTTOM value. 267 8393C-MCU Wireless-09/14

In phase correct PWM mode, the compare unit allows generating PWM waveforms on the OC0x pins. Setting the COM0x1:0 bits to 2 will produce a non-inverted PWM. An inverted PWM output can be generated by setting the COM0x1:0 to 3. Setting the COM0A0 bits to 1 allows the OC0A pin to toggle on Compare Matches if the WGM02 bit is set. This option is not available for the OC0B pin (see Table 17-4 on page 263). The actual OC0x value will only be visible at the port pin if the data direction for the port pin is set to output. The PWM waveform is generated by clearing (or setting) the OC0x Register at the Compare Match between OCR0x and TCNT0 when the counter increments, and by setting (or clearing) the OC0x Register at Compare Match between OCR0x and TCNT0 when the counter decrements. The PWM frequency for the output f when using phase-correct PWM can be calculated with the following OC0xPCPWM equation: f f = clkI/O OC0xPCPWM N ⋅510 The N variable represents the prescale factor (1, 8, 64, 256 or 1024). The extreme values for the OCR0A Register represent special cases when generating a PWM waveform output in the phase-correct PWM mode. If the OCR0A is set equal to BOTTOM, the output will be continuously low and if set equal to MAX the output will be continuously high for non-inverted PWM mode. For inverted PWM the output will have the opposite logic values. At the very start of period 2 in Figure 17-7 OCnx has a transition from high to low even though there is no Compare Match. The reason of this transition is to guarantee symmetry around BOTTOM. There are two cases that give a transition without Compare Match: • OCR0x changes its value from MAX like in Figure 17-7 on page 267. When the OCR0x value is MAX the OC0x pin value is the same as the result of a down- counting Compare Match. To ensure symmetry around BOTTOM the OC0x value at MAX must correspond to the result of an up-counting Compare Match. • The timer starts countin g from a value higher than the one in OCR0x. For that reason it misses the Compare Match and hence the OC0x change that would have happened on the way up. 17.8 Timer/Counter Timing Diagrams The Timer/Counter is a synchronous design and the timer clock (clk ) is therefore T0 shown as a clock enable signal in the following figures. The figures include information on when Interrupt Flags are set. Figure 17-8 contains timing data for basic Timer/Counter operation. The figure shows the count sequence close to the MAX value in all modes other than phase correct PWM mode. Figure 17-8. Timer/Counter Timing Diagram, no Prescaling clk I/O clk Tn (clk /1) I/O TCNTn MAX - 1 MAX BOTTOM BOTTOM + 1 TOVn ATmega256/128/64RFR2 268 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 Figure 17-9 shows the same timing data, but with the prescaler enabled. Figure 17-9. Timer/Counter Timing Diagram with Prescaler (f /8) clkI/O clk I/O clk Tn (clk /8) I/O TCNTn MAX - 1 MAX BOTTOM BOTTOM + 1 TOVn Figure 17-10 shows the setting of OCF0B and OCF0A in all modes except CTC and PWM mode, where OCR0A is TOP. Figure 17-10. Timer/Counter Timing Diagram, setting of OCF0x with Prescaler (f /8) clkI/O clk I/O clk Tn (clk /8) I/O TCNTn OCRnx - 1 OCRnx OCRnx + 1 OCRnx + 2 OCRnx OCRnx Value OCFnx Figure 17-11 shows the setting of OCF0A and the clearing of TCNT0 in CTC mode and fast PWM mode where OCR0A is TOP. Figure 17-11. Timer/Counter Timing Diagram, Clear Timer on Compare Match mode with Prescaler (f /8) clkI/O clk I/O clk Tn (clk /8) I/O TCNTn TOP - 1 TOP BOTTOM BOTTOM + 1 (CTC) OCRnx TOP OCFnx 269 8393C-MCU Wireless-09/14

17.9 Register Description 17.9.1 GTCCR – General Timer/Counter Control Register Bit 7 6 5 4 3 2 1 0 $23 ($43) TSM Res4 Res3 Res2 Res1 Res0 PSRASY PSRSYNC GTCCR Read/Write RW R R R R R R RW Initial Value 0 0 0 0 0 0 0 0 • Bit 7 – TSM - Timer/Counter Synchronization Mode Writing the TSM bit to one activates the Timer/Counter Synchronization mode. In this mode the value that is wr itten to the PSRASY and PSRSYNC bits is kept, hence keeping the corresponding prescaler reset signals asserted. This ensures that the corresponding Timer/Counters are halted and can be configured to the same value without the risk of one of them advancing during the configuration. When the TSM bit is written to zero, the PSRASY and PSRSYNC bits are cleared by hardware and the Timer/Counters simultaneou sly start counting. • Bit 6:2 – Res4:0 - Reserved This bit is reserved for future use. A read access always will return zero. A write access does not modify the content. • Bit 1 – PSRASY - Prescaler Reset Timer/Counter2 When this bit is one, the Timer/Counter2 prescaler will be reset. This bit is normally cleared immediately by hardware. If the bit is written when Timer/Counter2 is operating in asynchronous mode, the bit will remain one until the prescaler has been reset. The bit will not be cleared by hardware if the TSM bit is set. • Bit 0 – PSRSYNC - Prescaler Reset for Synchronous Timer/Counters When this bit is one, the Timer/Counter0, Timer/Counter1, Timer/Counter3, Timer/Counter4 and Timer/Counter5 prescaler will be reset. This bit is normally cleared immediately by hardware, except if the TSM bit is set. Note that Timer/Counter0, Timer/Counter1, Timer/Counter3, Timer/Counter4 and Timer/Counter5 share the same prescaler and a reset of this prescaler will affect all timers. 17.9.2 TCCR0A – Timer/Counter0 Control Register A Bit 7 6 5 4 3 2 1 0 $24 ($44) COM0A1 COM0A0 COM0B1 COM0B0 Res1 Res0 WGM01 WGM00 TCCR0A Read/Write RW RW RW RW R R RW RW Initial Value 0 0 0 0 0 0 0 0 • Bit 7:6 – COM0A1:0 - Compare Match Output A Mode These bits control the Output Compare pin (OC0A) behavior. If one or both of the COM0A1:0 bits are set, the OC0A output overrides the normal port functionality of the I/O pin it is connected to. However, note that the Data Direction Register (DDR) bit corresponding to the OC0A pin must be set in order to enable the output driver. When OC0A is connected to the pin, the function of the COM0A1:0 bits depends on the WGM02:0 bit setting. The following shows the COM0A1:0 bit functionality when the WGM02:0 bits are set to a normal or CTC mode (non-PWM). For the functionality in other modes refer to section "Operating Modes". ATmega256/128/64RFR2 270 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 Table 17-6 COM0A Register Bits Register Bits Value Description COM0A1:0 0 Normal port operation, OC0A disconnected 1 Toggle OC0A on Compare Match 2 Clear OC0A on Compare Match 3 Set OC0A on Compare Match • Bit 5:4 – COM0B1:0 - Compare Match Output B Mode These bits control the Output Compare pin (OC0B) behavior. If one or both of the COM0B1:0 bits are set, the OC0B output overrides the normal port functionality of the I/O pin it is connected to. However, note that the Data Direction Register (DDR) bit corresponding to the OC0B pin must be set in order to enable the output driver. When OC0B is connected to the pin, the function of the COM0B1:0 bits depends on the WGM02:0 bit setting. The following shows the COM0B1:0 bit functionality when the WGM02:0 bits are set to a normal or CTC mode (non-PWM). For the functionality in other modes refer to section "Operating Modes". Table 17-7 COM0B Registe r Bits Register Bits Value Description COM0B1:0 0 Normal port operation, OC0B disconnected 1 Toggle OC0B on Compare Match 2 Clear OC0B on Compare Match 3 Set OC0B on Compare Match • Bit 3:2 – Res1:0 - Reserved Bit This bit is reserved for future use. A read access always will return zero. A write access does not modify the content. • Bit 1:0 – WGM01:00 - Waveform Generation Mode Combined with the WGM02 bit found in the TCCR0B Register, these bits control the counting sequence of the c ounter, the source for maximum (TOP) counter value, and what type of waveform generation to be used according to the following table. Modes of operation supported by the Timer/Counter0 unit are: Normal mode (counter), Clear Timer on Compare Match (CTC) mode, and two types of Pulse Width Modulation (PWM) modes (see section "Modes of Operation" for details). Table 17-8 WGM0 Register Bits Register Bits Value Description WGM02:00 0x0 Normal mode of operation 0x1 PWM, phase correct, TOP=0xFF 0x2 CTC, TOP = OCRA 0x3 Fast PWM, TOP=0xFF 0x4 Reserved 0x5 PWM, Phase correct, TOP = OCRA 0x6 Reserved 0x7 Fast PWM, TOP=OCRA 271 8393C-MCU Wireless-09/14

17.9.3 TCCR0B – Timer/Counter0 Control Register B Bit 7 6 5 4 3 2 1 0 $25 ($45) FOC0A FOC0B Res1 Res0 WGM02 CS02 CS01 CS00 TCCR0B Read/Write W W R R RW RW RW RW Initial Value 0 0 0 0 0 0 0 0 • Bit 7 – FOC0A - Force Output Compare A The FOC0A bit is only active when the WGM02:0 bits specify a non-PWM mode. However, for ensuring compatibility with future devices, this bit must be set to zero when TCCR0B is written in a PWM operation mode. When writing a logical one to the FOC0A bit, an immediate C ompare Match is forced on the Waveform Generation unit. The OC0A output is changed according to its COM0A1:0 bits setting. Note that the FOC0A bit is implemented as a strobe. Therefore it is the value present in the COM0A1:0 bits that determines the effect of the forced compare. A FOC0A strobe will not generate any interrupt nor will it clear the timer in CTC mode using OCR0A as TOP. The FOC0A bit is always read as zero. • Bit 6 – FOC0B - Force Output Compare B The FOC0B bit is only active when the WGM02:0 bits specify a non-PWM mode. However, for ensuring compatibility with future devices, this bit must be set to zero when TCCR0B is written in a PWM operation mode. When writing a logical one to the FOC0B bit, an immediate Compare Match is forced on the Waveform Generation unit. The OC0B output is changed according to its COM0B1:0 bits setting. Note that the FOC0B bit is implemented as a strobe. Therefore it is the value present in the COM0B1:0 bits that determ ines the effect of the forced compare. A FOC0B strobe will not generate any interrupt nor will it clear the timer in CTC mode using OCR0B as TOP. The FOC0B bit is always read as zero. • Bit 5:4 – Res1:0 - Reserved Bit This bit is reserved for future use. A read access always will return zero. A write access does not modify the content. • Bit 3 – WGM02 - Waveform Generation Mode Combined with the WGM01:00 bits found in the TCCR0A Register, these bits control the counting sequence of the counter, the source for maximum (TOP) counter value, and what type of waveform generation to be used. Modes of operation supported by the Timer/Counter unit are: Normal mode (counter), Clear Timer on Compare Match (CTC) mode, and two types of Pulse Width Modulation (PWM) modes (see section "Modes of Operation"). • Bit 2:0 – CS02:00 - Clock Select The three Clock Select bits select the clock source to be used by the Timer/Counter0 according to the following table.If external pin modes are used for Timer/Counter0, transitions on the T0 pin will clock the counter even if the pin is configured as an output. This feature allows software control of the counting. Table 17-9 CS0 Register Bits Register Bits Value Description CS02:00 0x00 No clock source (Timer/Counter0 stopped) 0x01 clkIO/1 (no prescaling) 0x02 clkIO/8 (from prescaler) 0x03 clkIO/64 (from prescaler) ATmega256/128/64RFR2 272 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 Register Bits Value Description 0x04 clkIO/256 (from prescaler) 0x05 clkIO/1024 (from prescaler) 0x06 External clock source on T0 pin, clock on falling edge 0x07 External clock source on T0 pin, clock on rising edge 17.9.4 TCNT0 – Timer/Counter0 Register Bit 7 6 5 4 $26 ($46) TCNT0_7 TCNT0_6 TCNT0_5 TCNT0_4 TCNT0 Read/Write RW RW RW RW Initial Value 0 0 0 0 Bit 3 2 1 0 $26 ($46) TCNT0_3 TCNT0_2 TCNT0_1 TCNT0_0 TCNT0 Read/Write RW RW RW RW Initial Value 0 0 0 0 The Timer/Counter Register gives direct access, both for read and write operations, to the Timer/Counter0 unit 8-bit counter. Writing to the TCNT0 Register blocks (removes) the Compare Match on the following timer clock. Modifying the counter (TCNT0) while the counter is running, intro duces a risk of missing a Compare Match between TCNT0 and the OCR0x Registers. • Bit 7:0 – TCNT0_7:0 - Timer/Counter0 Byte 17.9.5 OCR0A – Timer/Counter0 Output Compare Register Bit 7 6 5 4 $27 ($47) OCR0A_7 OCR0A_6 OCR0A_5 OCR0A_4 OCR0A Read/Write RW RW RW RW Initial Value 0 0 0 0 Bit 3 2 1 0 $27 ($47) OCR0A_3 OCR0A_2 OCR0A_1 OCR0A_0 OCR0A Read/Write RW RW RW RW Initial Value 0 0 0 0 The Output Compare Register A contains an 8-bit value that is continuously compared with the counter value (TCN T0). A match can be used to generate an Output Compare interrupt, or to generate a waveform output on the OC0A pin. • Bit 7:0 – OCR0A_7:0 - Output Compare Register 273 8393C-MCU Wireless-09/14

17.9.6 OCR0B – Timer/Counter0 Output Compare Register B Bit 7 6 5 4 $28 ($48) OCR0B_7 OCR0B_6 OCR0B_5 OCR0B_4 OCR0B Read/Write RW RW RW RW Initial Value 0 0 0 0 Bit 3 2 1 0 $28 ($48) OCR0B_3 OCR0B_2 OCR0B_1 OCR0B_0 OCR0B Read/Write RW RW RW RW Initial Value 0 0 0 0 The Output Compare Register B contains an 8-bit value that is continuously compared with the counter value (TCNT0). A match can be used to generate an Output Compare interrupt, or to generate a waveform output on the OC0B pin. • Bit 7:0 – OCR0B_7:0 - Output Compare Register 17.9.7 TIMSK0 – Timer/Counter0 Interrupt Mask Register Bit 7 6 5 4 3 2 1 0 NA ($6E) Res4 Res3 Res2 Res1 Res0 OCIE0B OCIE0A TOIE0 TIMSK0 Read/Write R R R R R RW RW RW Initial Value 0 0 0 0 0 0 0 0 • Bit 7:3 – Res4:0 - Reserved This bit is reserved for future use. A read access always will return zero. A write access does not modify the content. • Bit 2 – OCIE0B - Timer/Counter0 Output Compare Match B Interrupt Enable When the OCIE0B bit is written to one, and the I-bit in the Status Register is set, the Timer/Counter0 Compare Match B interrupt is enabled. The corresponding interrupt is executed if a Compare Match in Timer/Counter0 occurs, i.e., when the OCF0B bit is set in the Timer/Counter0 Interrupt Flag Register TIFR0. • Bit 1 – OCIE0A - Timer/Counter0 Output Compare Match A Interrupt Enable When the OCIE0A bit is written to one, and the I-bit in the Status Register is set, the Timer/Counter0 Compare Match A interrupt is enabled. The corresponding interrupt is executed if a Compare Mat c h in Timer/Counter0 occurs, i.e., when the OCF0A bit is set in the Timer/Counter0 Interrupt Flag Register TIFR0. • Bit 0 – TOIE0 - Timer/Counter0 Overflow Interrupt Enable When the TOIE0 bit is written to one, and the I-bit in the Status Register is set, the Timer/Counter0 Overflow interrupt is enabled. The corresponding interrupt is executed if an overflow in Timer/Counter0 occurs i.e., when the TOV0 bit is set in the Timer/Counter0 Interrupt Flag Register TIFR0. ATmega256/128/64RFR2 274 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 17.9.8 TIFR0 – Timer/Counter0 Interrupt Flag Register Bit 7 6 5 4 3 2 1 0 $15 ($35) Res4 Res3 Res2 Res1 Res0 OCF0B OCF0A TOV0 TIFR0 Read/Write R R R R R RW RW RW Initial Value 0 0 0 0 0 0 0 0 • Bit 7:3 – Res4:0 - Reserved This bit is reserved for future use. A read access always will return zero. A write access does not modify the content. • Bit 2 – OCF0B - Timer/Counter0 Output Compare B Match Flag The OCF0B bit is set when a Compare Match occurs between the Timer/Counter0 and the data in OCR0B Output Compare Register. OCF0B is cleared by hardware when executing the corresponding interrupt handling vector. Alternatively, OCF0B is cleared by writing a logic one to the flag. When the I-bit in SREG, OCIE0B (Timer/Counter Compare B Match Interrupt Enable) and OCF0B are set, the Timer/Counter Compare Match Interrupt is executed. • Bit 1 – OCF0A - Timer/Counter0 Output Compare A Match Flag The OCF0A bit is set when a Compare Match occurs between the Timer/Counter0 and the data in OCR0A Output Compare Register. OCF0A is cleared by hardware when executing the corresponding interrupt handling vector. Alternatively, OCF0A is cleared by writing a logic one to the flag. When the I-bit in SREG, OCIE0A (Timer/Counter Compare A Match Interrupt Enable) and OCF0A are set, the Timer/Counter Compare Match Interrupt is executed. • Bit 0 – TOV0 - Timer/Counter0 Overflow Flag The bit TOV0 is set when an overflow occurs in Timer/Counter0. TOV0 is cleared by hardware when executing the corresponding interrupt handling vector. Alternatively, TOV0 is cleared by writing a logic one to the flag. When the SREG I-bit, TOIE0 (Timer/Counter0 Overflow I nterrupt Enable) and TOV0 are set, the Timer/Counter0 Overflow interrupt is executed. The setting of this flag is dependent of the WGM02:0 bit setting. 275 8393C-MCU Wireless-09/14

18 16-bit Timer/Counter (Timer/Counter 1, 3, 4, and 5) 18.1 Features • True 16-bit Design (i.e., allows 16-bit PWM) • Three independent Output Compare Units • Double Buffered Output Compare Registers • One Input Capture Unit • Input Capture Noise Canceller • Clear Timer on Compare Match (Auto Reload) • Glitch-free, Phase Corr ect Pulse Width Modulator (PWM) • Variable PWM Period • Frequency Generator • External Event Counter • Numerous independent interrupt sources o TOV1, OCF1A, OCF1B, OCF1C, ICF1 o TOV3, OCF3A, OCF3B, OCF3C, ICF3 o TOV4, OCF4A, OCF4B, OCF4C o TOV5, OCF5A, OCF5B, OCF5C 18.2 Overview The 16-bit Timer/Counter unit allows accurate program execution timing (event management), wave generation and signal timing measurement. Most register and bit references in this section are written in general form. A lower case “n” replaces the Timer/Counter number, and a lower case “x” replaces the Output Compare unit channel. However when using the register or bit defines in a program, the precise form must be used i.e., TCNT1 for accessing Timer/Counter1 counter value and so on. A simplified block diagram of the 16-bit Timer/Counter is shown in Figure 18-1. For the actual placement of I/O pins, see section "Pin Configurations" on page 2. CPU accessible I/O Registers, including I/O bits and I/O pins are shown in bold. The device- specific I/O Register and bit locations are listed in the section "Register Description" on page 298. The Power Reduction Timer/Counter1 bit, PRTIM1, in "PRR0 – Power Reduction Register0" on page 197 must be written to zero to enable Timer/Counter1 module. The Power Reduction bits of Timer/Counter3 (PRTIM3), Timer/Counter4 bit (PRTIM4) and Timer/Counter5 (PRTIM5) in "PRR1 – Power Reduction Register 1" on page 198 must be written to zero to enable the respective Timer/Counter module. Note, note the complete Timer/Counter I/O functionality is provided for each Timer/Counter module depending on the available I/O pins. ATmega256/128/64RFR2 276 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 Figure 18-1. 16-bit Timer/Counter Block Diagram(1) Count TOVn Clear (Int.Req.) Control Logic Direction clk Clock Select Tn Edge Tn Detector TOP BOTTOM ( From Prescaler ) Timer/Counter TCNTn = = 0 OCnA (Int.Req.) = Waveform OCnA Generation OCRnA Fixed OCnB S TOP (Int.Req.) U Values B = Waveform OCnB A Generation T A D OCRnB ( From Analog Comparator Ouput ) ICFn (Int.Req.) Edge Noise ICRn Detector Canceler ICPn TCCRnA TCCRnB Notes: 1. Refer to Figure 1-1 on page 2, Table 14-3 on page 226 and Table 14-9 en page 230 for Timer/Counter1, 2 and 3 pin placements and description. 18.2.1 Registers The Timer/Counter (TCNTn) Output Compare Registers (OCRnA/B/C) and Input Capture Register (ICRn) are all 16-bit registers. Special procedures must be followed when accessing the 16-bit registers. These procedures are described in the section "Accessing 16-bit Register s" on page 278. The Timer/Counter Control Registers (TCCRnA/B/C) are 8-bit registers and have no CPU access restrictions. Interrupt requests (shorten as Int.Req.) signals are all visible in the Timer Interrupt Flag Register (TIFRn). All interrupts are individually masked with the Timer Interrupt Mask Register (TIMSKn). TIFRn and TIMSKn are not shown in the figure since these registers are shared by other timer units. The Timer/Counter can be clocked internally, via the prescaler or by an external clock source on the Tn pin. The Clock Select logic block controls which clock source and which clock edge the Timer/Counter uses to increment (or decrement) its value. The Timer/Counter is inactive when no clock source is selected. The output from the clock select logic is referred to as the timer clock (clk ). Tn The double buffered Output Compare Registers (OCRnA/B/C) are compared with the 277 8393C-MCU Wireless-09/14

Timer/Counter value at all time. The result of the compare can be used by the Waveform Generator to generate a PWM or variable frequency output on the Output Compare pin (OCnA/B/C). See section "Output Compare Units" on page 284 for details. The compare match event will also set the Compare Match Flag (OCFnA/B/C) which can be used to generate an Output Compare interrupt request. The Input Capture Register can capture the Timer/Counter value at a given external (edge triggered) event on either the Input Capture pin (ICPn) or on the Analog Comparator pins (see "AC – Analog Comparator" on page 440). The Input Capture unit includes a digital filtering unit (Noise Canceller) for reducing the chance of capturing noise spikes. The TOP value, or maximum Timer/Counter value, can in some modes of operation be defined by either the OCRn A Register, the ICRn Register or by a set of fixed values. When using OCRnA as TOP value in a PWM mode, the OCRnA Register can not be used for generating a PWM output. However the TOP value will in this case be double buffered allowing the TOP value to be changed at run time. If a fixed TOP value is required, the ICRn Register can be used as an alternative, freeing the OCRnA to be used as PWM output. 18.2.2 Definitions The following definitions are used extensively throughout the document: Table 18-1. Definitions BOTTOM The counter reaches the BOTTOM when it becomes 0x0000. MAX The counter reaches its MAXimum when it becomes 0xFFFF (decimal 65535). TOP The counter re aches the TOP when it becomes equal to the highest value in the count sequence. The TOP value can be assigned to be one of the fixed values: 0x00FF, 0x01FF, 0x03FF or to the value stored in the OCRnA or ICRn Register. The assignment is dependent of the mode of operation. 18.3 Accessing 16-bit Registers The TCNTn, OCRnA/B/C and ICRn are 16-bit registers that can be accessed by the AVR CPU via the 8-bit data bus. The 16-bit register must be byte accessed using two read or write operations. Each 16-bit timer has a single 8-bit register for temporary storing of the high byte of the 16-bit access. The same Temporary Register is shared between all 16-bit registers within each 16-bit timer. Accessing the low byte triggers the 16-bit read or write operation. When the low byte of a 16-bit register is written by the CPU, the written low byte and the high byte stored in the Temporary Register are both copied into the 16-bit regis ter in the same clock cycle. When the low byte of a 16-bit register is read by the CPU, the high byte of the 16-bit register is copied into the Temporary Register in the same clock cycle as the low byte is read. Not all 16-bit accesses use the Temporary Register for the high byte. Reading the OCRnA/B/C 16-bit registers does not involve using the Temporary Register. To do a 16-bit write, the high byte must be written before the low byte. For a 16-bit read, the low byte must be read before the high byte. The following code examples show how to access the 16-bit timer registers assuming that no interrupt updates the temporary register. The same principle can be used directly for accessing the OCRnA/B/C and ICRn Registers. Note that when using the C- programming language, the compiler handles the 16-bit access. ATmega256/128/64RFR2 278 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 Assembly Code Examples(1) ... ; Set TCNTn to 0x01FF ldi r17,0x01 ldi r16,0xFF out TCNTnH,r17 out TCNTnL,r16 ; Read TCNTn into r17:r16 in r16,TCNTnL in r17,TCNTnH ... C Code Examples(1) unsigned int i; ... /* Set TCNTn to 0x01FF */ TCNTn = 0x1FF; /* Read TCNTn into i */ i = TCNTn; ... Notes: 1. See "About Code Examples" on page 7. The assembly code example returns the TCNTn value in the r17:r16 register pair. It is important to notice tha t accessing 16-bit registers are atomic operations. If an interrupt occurs between the two instructions accessing the 16-bit register and the interrupt code updates the temporary register by accessing the same or any other of the 16-bit Timer Registers, then the result of the access outside the interrupt will be corrupted. Therefore the main code must disable the interrupts during the 16-bit access when both the main code and the interrupt code update the temporary register. The following code examples show how to do an atomic read of the TCNTn Register contents. Reading any of the OCRnA/B/C or ICRn Registers can be done by using the same principle. The assembly code example returns the TCNTn value in the r17:r16 register pair. Assembly Code Examples(1) TIM16_ReadTCNTn: ; Save global interrupt flag in r18,SREG ; Disable interrupts cli ; Read TCNTn into r17:r16 in r16,TCNTnL in r17,TCNTnH ; Restore global interrupt flag out SREG,r18 ret 279 8393C-MCU Wireless-09/14

C Code Examples(1) unsigned int TIM16_ReadTCNTn( void ) { unsigned char sre g; unsigned int i; /* Save global interrupt flag */ sreg = SREG; /* Disable interrupts */ __disable_interrupt(); /* Read TCNTn into i */ i = TCNTn; /* Restore global interrupt flag */ SREG = sreg; return i; } Notes: 1. See "About Code Examples" on page 7 . The following code examples show how to do an atomic write of the TCNTn Register contents. Writing any of the OCRnA/B/C or ICRn Registers can be done by using the same principle. The assembly code example requires that the r17:r16 register pair contains the value to be written to TCNTn. Assembly Code Examples(1 ) TIM16_WriteTCNTn: ; Save global interrupt flag in r18,SREG ; Disable interrupts cli ; Set TCNTn to r17:r16 out TCNTnH,r17 out TCNTnL,r16 ; Restore global interrupt flag out SREG,r18 ret ATmega256/128/64RFR2 280 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 C Code Examples(1) void TIM16_WriteTCNTn( unsigned int i ) { unsigned char sreg ; unsigned int i; /* Save global interrupt flag */ sreg = SREG; /* Disable interrupts */ __disable_interrupt(); /* Set TCNTn to i */ TCNTn = i; /* Restore global interrupt flag */ SREG = sreg; } Notes: 1. See "About Code Examples" on page 7 . 18.3.1 Reusing the Temporary High Byte Register If writing to more than one 16-bit register where the high byte is the same for all registers written, then the high byte only needs to be written once. However note that the same rule of atomic operation described previously also applies in this case. 18.4 Timer/Counter Clock Sources The Timer/Counter can be clocked by an internal or an external clock source. The clock source is selected by the Clock Select logic which is controlled by the Clock Select (CSn2:0) bits located in the Timer/Counter control Register B (TCCRnB). For details on clock sources and prescaler, see "Timer/Counter 0, 1, 3, 4, and 5 Prescaler" on page 336. 18.5 Counter Unit The main part of the 16-bit Timer/Counter is the programmable 16-bit bi-directional counter unit. The following figure shows a block diagram of the counter and its surroundings. Figure 18-2. Counter Unit Block Diagram DATA BUS (8-bit) TOVn (Int.Req.) TEMP (8-bit) Clock Select Count Edge TCNTnH (8-bit) TCNTnL (8- bit) Clear clk Detector Tn Control Logic Tn Direction TCNTn (16-bit Counter) ( From Prescaler ) TOP BOTTOM Signal description (internal signals): Count Increment or decrement TCNTn by 1; Direction Select between increment and decrement; 281 8393C-MCU Wireless-09/14

Clear Clear TCNTn (set all bits to zero); clk Timer/Counter clock; Tn TOP Signalize that TCNTn has reached maximum value; BOTTOM Signalize that TCNTn has reached minimum value (zero); The 16-bit counter is mapped into two 8-bit I/O memory locations: Counter High (TCNTnH) contains the upper eight bits of the counter and Counter Low (TCNTnL) contains the lower eight bits. The TCNTnH Register can only be indirectly accessed by the CPU. When the CPU does an access to the TCNTnH I/O location, the CPU accesses the high byte temporary register (TEMP). The temporary register is updated with the TCNTnH value when the TCNTnL is read and TCNTnH is updated with the temporary register value when TCNTnL is written. This allows the CPU to read or write the entire 16-bit counter value within one clock cycle via the 8-bit data bus. It is important to notice that there are special cases of writing to the TCNTn Register giving unpredictable results when the counter is running. These special cases are described in the sections of their importance. Depending on the mode of operation, the counter is cleared, incremented or decremented at each timer clock (clk ). The clk can be generated from an external or Tn Tn internal clock source selected by the Clock Select bits (CSn2:0). The timer is stopped when no clock source is selected (CSn2:0 = 0). However, the TCNTn value can be accessed by the CPU independent of whether clk is present or not. A CPU write Tn overrides (has priority over) all counter clear or count operations. The counting sequence is determined by the settings of the Waveform Generation mode bits (WGMn3:0) located in the Timer/Counter Control Registers A and B (TCCRnA and TCCRnB). There are close connections between how the counter behaves (counts) and how waveforms are generated on the Output Compare outputs OCnx. For more details about advanced counting sequences and waveform generation, see "Modes of Operation" on page 288. The Timer/Counter Overflow Flag (TOVn) is set according to the mode of operation selected by the WGMn3:0 b its. TOVn can be used for generating a CPU interrupt. 18.6 Input Capture Unit The Timer/Counter incorporates an input capture unit that can capture external events and give them a time-stamp indicating time of occurrence. The external signal indicating an event, or multiple events, can be applied via the ICPn pin or alternatively, for the Timer/Counter1 only, via the Analog Comparator unit. The time-stamps can then be used to calculate frequency, duty-cycle and other features of the signal applied. Alternatively the time-stamps can be used for creating a log of the events. The Input Capture unit is illustrated by the block diagram shown in Figure 18-3. The elements of the block diagram not direct parts of the input capture unit are gray shaded. The small “n” in register and bit names indicates the Timer/Counter number. A capture will be triggered when a change of the logic level (an event) occurs on the Input Capture Pin (ICPn), or alternatively on the analog Comparator output (ACO), and this change matches the setting of the edge detector. When a capture is triggered, the 16-bit value of the counter (TCNTn) is written to the Input Capture Register (ICRn). The Input Capture Flag (ICFn) is set at the same system clock as the TCNTn value is copied into ICRn Register. If enabled (TICIEn = 1), the input capture flag generates an input capture interrupt. The ICFn flag is automatically cleared when the interrupt is executed. Alternatively the ICFn flag can be software-cleared by writing a logical one to its I/O bit location. ATmega256/128/64RFR2 282 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 Figure 18-3. Input Capture Unit Block Diagram DATA BUS (8-bit) TEMP (8-bit) ICRnH (8-bit) ICRnL (8-bit) TCNTnH (8-bit) TCNTnL (8-bit) WRITE ICRn (16-bit Register) TCNTn (16-bit Counter) ACO* ACIC* ICNC ICES Analog Comparator Noise Edge ICFn (Int.Req.) Canceler Detector ICPn Note: 1. The Analog Comparator Output (ACO) can only trigger the Timer/Counter1 ICP – not Timer/Counter3, 4 or 5. Reading the 16-bit value in the Input Capture Register (ICRn) is done by first reading the low byte (ICRnL) and then the high byte (ICRnH). When the low byte is read the high byte is copied into the high byte Temporary Register (TEMP). The CPU will access the TEMP Register when reading the ICRnH I/O location. The ICRn Register can only be written when using a Waveform Generation mode that utilizes the ICRn Register for defining the counter’s TOP value. In these cases the Waveform Generation mode (WGMn3:0) bits must be set before the TOP value can be written to the ICRn Register. When writing the ICRn Register the high byte must be written to the ICRnH I/O location before the low byte is written to ICRnL. For more information on how to access the 16-bit registers refer to "Accessing 16-bit Registers" on page 278. 18.6.1 Input Capture Trigger Source The main trigger source for the input capture unit is the Input Capture Pin (ICPn). Timer/Counter1 can alternatively use the analog comparator output as trigger source for the input capture unit. The Analog Comparator is selected as trigger source by setting the analog Comparator Input Capture (ACIC) bit in the Analog Comparator Control and Status Register (ACSR). Be aware that changing trigger source can trigger a capture. The input capture flag must therefore be cleared after the change. Both the Input Capture Pin (ICPn) and the Analog Comparator output (ACO) inputs are sampled using the same technique as for the Tn pin (Figure 19-1 on page 336). The edge detector is also identical. However, when the noise canceller is enabled, additional logic is inserted before the edge detector increasing the delay by four system 283 8393C-MCU Wireless-09/14

clock cycles. Note that the input of the noise canceller and edge detector is always enabled unless the Timer/Counter is set in a Waveform Generation mode that uses ICRn to define TOP. An input capture can be sof tware-triggered by controlling the port of the ICPn pin. 18.6.2 Noise Canceller The noise canceller improves noise immunity by using a simple digital filtering scheme. The noise canceller input is monitored over four samples and all four must be equal for changing the output that in turn is used by the edge detector. The noise canceller is enabled by setting the Input Capture Noise Canceller (ICNCn) bit in Timer/Counter Control Register B (TCCRnB). When enabled the noise canceller introduces additional four system clock cycles of delay from a change applied to the input to the update of the ICRn Register. The noise canceller uses the system clock and is therefore not affected by the prescaler. 18.6.3 Using the Input Capture Unit The main challenge when using the Input Capture unit is to assign enough processor capacity for handling the incoming events. The time between two events is critical. The ICRn will be overwritten with a new value if the processor has not read the captured value in the ICRn Register before the next event occurs. In this case the result of the capture will be incorrect. When using the Input Capture interrupt, the ICRn Register should be read as early in the interrupt handler routine as possible. Even though the Input Capture interrupt has relatively high priority, the maximum interrupt response time is dependent on the maximum number of clock cycles it takes to handle any of the other interrupt requests. It is not recommended to use the Input Capture unit in any mode of operation where the TOP value (resolution) is actively changed while counting. Measurement of the duty cycle of an external signal requires that the trigger edge is changed after each capture. Changing the edge sensing must be done as early as possible after the ICRn Register has been read. After a change of the edge, the Input Capture Flag (ICFn) must be cleared by software (writing a logical one to the I/O bit location). For measuring frequency only, the clearing of the ICFn Flag is not required (if an interrupt handler is used). 18.7 Output Compare Units The 16-bit comparator co ntinuously compares TCNTn with the Output Compare Register (OCRnx). If TCNTn equals OCRnx the comparator signals a match. A match will set the Output Compare Flag (OCFnx) at the next clock cycle of the timer. If enabled (OCIEnx = 1), the Output Compare Flag generates an Output Compare interrupt. The OCFnx Flag is automatically cleared when the interrupt is executed. Alternatively the OCFnx Flag can be software-cleared by writing a logical one to its I/O bit location. The Waveform Generator uses the match signal to generate an output according to the Waveform Generation mode bits (WGMn3:0) and Compare Output mode bits (COMnx1:0). The TOP and BOTTOM signals are used by the Waveform Generator for handling the special cases of the extreme values in some modes of operation (see "Modes of Operation" on page 288). A special feature of Output Compare unit A allows it to define the Timer/Counter TOP value i.e., the counter resolution. In addition to the counter resolution, the TOP value defines the period time for waveforms generated by the Waveform Generator. ATmega256/128/64RFR2 284 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 Figure 18-4 shows a block diagram of the Output Compare unit. The small “n” in the register and bit names indicates the device number (n = Timer/Counter n), and the “x” indicates Output Compare unit A, B or C. The elements of the block diagram not direct parts of the Output Compare unit are gray shaded. Figure 18-4. Output Compare Unit Block Diagram DATA BUS (8-bit) TEMP (8-bit) OCRnxH Buf. (8-bit) OCRnxL Buf. (8-bit) TCNTnH (8-bit) TCNTnL (8-bit) OCRnx Buffer (16-bit Register) TCNTn (16-bit Counter) OCRnxH (8-bit) OCRnxL (8-bit) OCRnx (16-bit Register) = (16-bit Comparator ) OCFnx (Int.Req.) TOP Waveform Generator OCnx BOTT OM WGMn3:0 COMnx1:0 The OCRnx Register is double buffered when using any of the twelve Pulse Width Modulation (PWM) modes. For the Normal and Clear Timer on Compare (CTC) modes of operation, the double buffering is disabled. The double buffering synchronizes the update of the OCRnx Compare Register to either TOP or BOTTOM of the counting sequence. The synchronization prevents the occurrence of odd-length, non-symmetrical PWM pulses, thereby making the output glitch-free. The OCRnx Register access may seem complex, but this is not the case. When the double buffering is enabled, the CPU has access to the OCRnx Buffer Register. If double buffering is disabled the CPU will access the OCRnx directly. The content of the OCR1x (Buffer or Compare) Register is only changed by a write operation (the Timer/Counter does not up date this register automatically as the TCNT1 and ICR1 Register). Therefore OCR1x is not read via the high byte temporary register (TEMP). However, it is a good practice to read the low byte first similar to accessing other 16-bit registers. Writing the OCRnx Registers must be done via the TEMP Register since the compare of all 16 bits is done continuously. The high byte (OCRnxH) has to be written first. The TEMP Register will be updated with the value written by the CPU to the high byte I/O location. Then when the low byte (OCRnxL) is written to the lower eight bits, the high byte will be copied into the upper 8-bits of either the OCRnx buffer or OCRnx Compare Register in the same system clock cycle. For more information of how to access the 16-bit registers refer to "Accessing 16-bit Registers" on page 278. 285 8393C-MCU Wireless-09/14

18.7.1 Force Output Compare In non-PWM Waveform Generation modes, the match output of the comparator can be forced by writing a one to the Force Output Compare (FOCnx) bit. Forcing compare match will not set the OCF nx Flag or reload/clear the timer, but the OCnx pin will be updated as if a real compare match had occurred (the COMn1:0 bits settings define whether the OCnx pin is set, cleared or toggled). 18.7.2 Compare Match Blocking by TCNTn Write All CPU writes to the TCNTn Register will block any compare match that occurs in the next clock cycle of the timer even when the timer is stopped. This feature allows OCRnx to be initialized to the same value as TCNTn without triggering an interrupt when the Timer/Counter clock is enab led. 18.7.3 Using the Output Compare Unit Since writing TCNTn in any mode of operation will block all compare matches for one timer clock cycle, there are risks involved when changing TCNTn using any of the Output Compare channels, independent of whether the Timer/Counter is running or not. If the value written to TCNTn equals the OCRnx value, the compare match will be missed resulting in incorrect waveform generation. Do not write the TCNTn equal to TOP in PWM modes with variable TOP values. The compare match for the TOP will be ignored and the counter will continue to 0xFFFF. Similarly, do not write the TCNTn value equal to BOTTOM when the counter is down-counting. The setup of the OCnx should be performed before setting the Data Direction Register for the port pin to output. The easiest way of setting the OCnx value is to use the Force Output Compare (FOCnx) strobe bits in Normal mode. The OCnx Register keeps its value even when changing between Waveform Generation modes. Be aware that the COMnx1:0 bits are not double buffered together with the compare value. A change of the COMnx1:0 bits will immediately take effect. 18.8 Compare Match Output Unit The Compare Output mode (COMnx1:0) bits have two functions. The Waveform Generator uses the COMnx1:0 bits for defining the Output Compare (OCnx) state at the next compare match. Secondly the COMnx1:0 bits control the OCnx pin output source. Figure 18-5 shows a simplified schematic of the logic affected by the COMnx1:0 bit setting. The I/O Registers, I/O bits and I/O pins in the figure are shown in bold. Only the parts of the general I/O Port Control Registers (DDR and PORT) that are affected by the COMnx1:0 bits are show n. When referring to the OCnx state, the reference is to the internal OCnx Register and not to the OCnx pin. After a system reset the OCnx Register will have a value of “0”. The general I/O port function is overridden by the Output Compare (OCnx) from the Waveform Generator if either of the COMnx1:0 bits are set. However, the OCnx pin direction (input or output) is still controlled by the Data Direction Register (DDR) for the port pin. The Data Direction Register bit for the OCnx pin (DDR_OCnx) must be set as output before the OCnx value is visible on the pin. The port override function is generally independent of the Waveform Generation mode, but there are some exceptions. Refer to Table 18-2, Table 18-3 and Table 18-4 on page 288 for details. The design of the Output Compare pin logic allows initialization of the OCnx state before the output is enabled. Note that some COMnx1:0 bit settings are reserved for certain modes of operation (see section "Register Description" on page 298). The COMnx1:0 bits have no effect on the Input Capture unit. ATmega256/128/64RFR2 286 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 Figure 18-5. Compare Match Output Unit, Schematic COMnx1 Wavefor m COMnx0 D Q FOCnx Generator 1 OCnx OCnx Pin 0 D Q S U B PORT A T A D D Q DDR clkI/O 18.8.1 Compare Output Mode and Waveform Generation The Waveform Generator uses the COMnx1:0 bits differently in normal, CTC and PWM modes. A setting of COMnx1:0 = 0 tells the Waveform Generator in all modes that no action on the OCnx Regis ter is to be performed on the next compare match. For compare output actions in the non-PWM modes refer to Table 18-2. For fast PWM mode refer to Table 18-3 and for phase-correct and phase-and-frequency-correct PWM refer to Table 18-4. A change of the COMnx1:0 bits state will have effect at the first compare match after the bits are written. For non -PWM modes, the action can be forced to have immediate effect by using the FOCnx strobe bits. Table 18-2 shows the COMnx1:0 bit functionality when the WGMn3:0 bits are set to a normal or a CTC mode (non-PWM). Table 18-2. Compare Output Mode, non-PWM COMnA1 COMnA0 COMnB1 COMnB0 COMnC1 COMnC0 Description 0 0 Normal port operation, OCnA/OCnB/OCnC disconnected. 0 1 Toggle OCnA/OCnB/OCnC on compare match. Clear OCnA/OCnB/OCnC on compare match (set output to low 1 0 level). Set OCnA/OCnB/OCnC on compare match (set output to high 1 1 level). Table 18-3 shows the COMnx1:0 bit functionality when the WGMn3:0 bits are set to the fast PWM mode. 287 8393C-MCU Wireless-09/14

Table 18-3. Compare Output Mode, Fast PWM COMnA1 COMnA0 COMnB1 COMnB0 COMnC1 COMnC0 Description 0 0 Normal port operation, OCnA/OCnB/OCnC disconnected. WGM13:0 = 14 or 15: Toggle OC1A on Compare Match, OC1B and 0 1 OC1C disconnected (normal port operation). For all other WGM1 settings, normal port operation, OC1A/OC1B/OC1C disconnected. Clear OCnA/OCnB/OCnC on compare match; set 1 0 OCnA/OCnB/OCnC at BOTTOM (non-inverting mode). Set OCnA/OCnB/OCnC on compare match, clear 1 1 OC nA/OCnB/OCnC at BOTTOM (inverting mode). Note: 1. A special case occurs when OCRnA/OCRnB/OCRnC equals TOP and COMnA1/COMnB1/COMnC1 is set. In this case the compare match is ignored, but the set or clear is done at BOTTOM. See "Fast PWM Mode" on page 290 for more details. Table 18-4 shows the COMnx1:0 bit functionality when the WGMn3:0 bits are set to the phase correct and phase and frequency correct PWM mode. Table 18-4. Compare Output Mode, Phase Correct and Phase/Frequency Correct PWM COMnA1 COMnA0 COMnB1 COMnB0 COMnC1 COMnC0 Description 0 0 Normal port operation, OCnA/OCnB/OCnC disconnected. WGM13:0 =9 or 11: Toggle OC1A on Compare Match, OC1B and 0 1 OC1C disconnected (normal port operation). For all other WGM1 settings, normal port operation, OC1A/OC1B/OC1C disconnected. Cl ear OCnA/OCnB/OCnC on compare match when up-counting. 1 0 Set OCnA/OCnB/OCnC on compare match when down-counting. Set OCnA/OCnB/OCnC on compare match when up-counting. 1 1 Clear OCnA/OCnB/OCnC on compare match when down-counting. Note: 1. A special case occurs when OCRnA/OCRnB/OCRnC equals TOP and COMnA1/COMnB1/COMnC1 is set. See "Phase and Frequency Correct PWM Mode" on page 294 for more details. 18.9 Modes of Operation The mode of operation i.e., the behavior of the Timer/Counter and the Output Compare pins, is defined by the combination of the Waveform Generation mode (WGMn3:0) and the Compare Output mode (COMnx1:0) bits. The Compare Output mode bits do not affect the counting sequence, but the Waveform Generation mode bits do. The COMnx1:0 bits control whether the PWM output generated should be inverted or not (inverted or non-inverted PWM). For non-PWM modes the COMnx1:0 bits control if the output should be set, cleared or toggle at a compare match (See "Compare Match Output Unit" on page 286) ATmega256/128/64RFR2 288 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 Table 18-5. Waveform Generation Mode Bit Description (1) WGMn2 WGMn1 WGMn0) Timer/Counter Update of TOVn Flag Mode WGMn3 (CTCn) (PWMn1) (PWMn0) Mode of Operation TOP OCRnx at Set on 0 0 0 0 0 Normal 0xFFFF Immediate MAX 1 0 0 0 1 PWM, Phase Correct, 8-bit 0x00FF TOP BOTTOM 2 0 0 1 0 PWM, Phase Correct, 9-bit 0x01FF TOP BOTTOM 3 0 0 1 1 PWM, Phase Correct, 10-bit 0x3FF TOP BOTTOM 4 0 1 0 0 CTC OCRnA Immediate MAX 5 0 1 0 1 Fast PWM, 8-bit 0x00FF BOTTOM TOP 6 0 1 1 0 Fast PWM, 9-bit 0x01FF BOTTOM TOP 7 0 1 1 1 Fast PWM, 10-bit 0x03FF BOTTOM TOP PWM, Phase and Frequency 8 1 0 0 0 ICRn BOTTOM BOTTOM Correct PWM, Phase and Frequency 9 1 0 0 1 OCRnA BOTTOM BOTTOM Correct 10 1 0 1 0 PWM, Phase Correct ICRn TOP BOTTOM 11 1 0 1 1 PWM, Phase Correct OCRnA TOP BOTTOM 12 1 1 0 0 CTC ICRn Immediate MAX 13 1 1 0 1 (Reserved) – – – 14 1 1 1 0 Fast PWM ICRn BOTTOM TOP 15 1 1 1 1 Fast PWM OCRnA BOTTOM TOP Notes: 1. The CTCn and PWMn1:0 bit definition names are ob solete. Use the WGMn2:0 definitions. However, the functionality and location of these bits are compatible with previous versions of the timer. For detailed timing information refer to "Timer/Counter Timing Diagrams" on page 296. 18.9.1 Normal Mode The simplest mode of operation is the Normal mode (WGMn3:0 = 0). In this mode the counting direction is always up (incrementing) and no counter clear is performed. The counter simply overruns when it passes its maximum 16-bit value (MAX = 0xFFFF) and then restarts from the BOTTOM (0x0000). In normal operation the Timer/Counter Overflow Flag (TOVn) will be set in the same timer clock cycle as the TCNTn becomes zero. In this case the TOVn Flag behaves like a 17th bit, except that it is only set and not cleared. However the timer resolution can be increased by software when combined with the timer overflow interrupt that automatically clears the TOVn Flag. There are no special cases to consider in the Normal mode. A new counter value can be written anytime. The Input Capture unit is easy to use in Normal mode. However it is important to note that the maximum interval between the external events must not exceed the resolution of the counter. The timer overflow interrupt or the prescaler must be used to extend the resolution for the capture unit if the intervals between events are too long. The Output Compare units can be used to generate interrupts at some given time. Using the Output Compare to generate waveforms in Normal mode is not recommended because this will occupy too much CPU time. 18.9.2 Clear Timer on Compare Match (CTC) Mode In Clear Timer on Compare (CTC) mode (WGMn3:0 = 4 or 12), the OCRnA or ICRn Register are used to manipulate the counter resolution. In CTC mode the counter is 289 8393C-MCU Wireless-09/14

cleared to zero when the counter value (TCNTn) matches either the OCRnA (WGMn3:0 = 4) or the ICRn (WGMn3:0 = 12). The OCRnA or ICRn define the top value for the counter, hence also its resolution. This mode allows greater control of the compare match output frequency. It also simplifies the operation of counting external events. The timing diagram for the CTC mode is shown in the following figure. The counter value (TCNTn) increases until a compare match occurs with either OCRnA or ICRn, and then counter (TCNTn) is cleared. Figure 18-6. CTC Mode Timing Diagram OCnA Interrupt Flag Set or ICFn Interrupt Flag Set (Interrupt on TOP) TCNTn OCnA (COMnA1:0 = 1) (Toggle) Period 1 2 3 4 Each time the counter reaches the TOP value an interrupt can be generated by either the OCFnA or ICFn Flag according to the register used to define the TOP value. If the interrupt is enabled, the interrupt handler routine can be used for updating the TOP value. However, changing TOP to a value close to BOTTOM when the counter is running with no or a low prescaler value must be done with care since the CTC mode does not have the double buffering feature. The counter will miss the compare match if the new value written to OCRnA or ICRn is lower than the current value of TCNTn. The counter will then have to count to its maximum value (0xFFFF) and wrap around starting at 0x0000 before the compare match can occur. In many cases this feature is not desirable. The fast PWM mode is available as an alternative using OCRnA for defining TOP (WGMn3:0 = 15). The OCRnA then will be double buffered. For generating a waveform output in CTC mode, the OCnA output can be set to toggle its logical level on each compare match by setting the Compare Output mode bits to toggle mode (COMnA1:0 = 1). The OCnA value will not be visible on the port pin unless the data direction for the pin is set to output (DDR_OCnA = 1). The waveform generated will have a maximum frequency of f = f /2 when OCRnA is set to zero OCnA clkI/O (0x0000). The waveform fre quency is given by the following equation: f f = clkI/O OCnA 2⋅N ⋅(1+OCRnA) The N variable represents the prescaler factor (1, 8, 64, 256, or 1024). As for the Normal mode of operation, the TOVn Flag is set in the same clock cycle of the timer when the counter changes from MAX to 0x0000. 18.9.3 Fast PWM Mode The fast Pulse Width Modulation (PWM) mode (WGMn3:0 = 5, 6, 7, 14 or 15) provides a high frequency PWM waveform generation option. The fast PWM differs from the other PWM options by its single-slope operation. The counter counts from BOTTOM to TOP then restarts from BOTTOM. In non-inverting Compare Output mode, the Output Compare (OCnx) is cleared on the compare match between TCNTn and OCRnx, and ATmega256/128/64RFR2 290 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 OCnx is set at BOTTOM. In inverting Compare Output mode output is set on compare match and cleared at BOTTOM. Due to the single-slope operation, the operating frequency of the fast PWM mode can be twice as high as the phase-correct and phase and frequency correct PWM modes that use dual-slope operation. This high frequency makes the fast PWM mod e well suited for power regulation, rectification and DAC applications. High frequency allows physically small sized external components (coils, capacitors), hence reducing total system cost. The PWM resolution for fast PWM can be fixed to 8-, 9-, or 10-bit, or defined by either ICRn or OCRnA. The minimum resolution allowed is 2-bit (ICRn or OCRnA set to 0x0003), and the maximum resolution is 16-bit (ICRn or OCRnA set to MAX). The PWM resolution R in bits can be calculated with the following equation: FPWM log(TOP+1) R = FPWM log(2) In fast PWM mode the counter is incremented until the counter value matches either one of the fixed values 0x00FF, 0x01FF or 0x03FF (WGMn3:0 = 5, 6 or 7), the value in ICRn (WGMn3:0 = 14) or the value in OCRnA (WGMn3:0 = 15). The counter is then cleared at the following timer clock cycle. The timing diagram for the fast PWM mode is shown in Figure 18-7. The figure shows fast PWM mode when OCRnA or ICRn is used to define TOP. The TCNTn value is in the timing diagram shown as a histogram for illustrating the single-slope operation. The diagram includes non-inverted and inverted PWM outputs. The small horizontal line marks on the TCNTn slopes represent compare matches between OCRnx and TCNTn. The OCnx Interrupt Flag will be set when a compare match occurs. Figure 18-7. Fast PWM Mode Timing Diagram OCRnx / TOP Update and TOVn Interrupt Flag Set and OCnA Interrupt Flag Set or ICFn Interrupt Flag Set (Interrupt on TOP) TCNTn OCnx (COMnx1:0 = 2) OCnx (COMnx1:0 = 3) Period 1 2 3 4 5 6 7 8 The Timer/Counter Overflow Flag (TOVn) is set each time the counter reaches TOP. In addition the OCnA or ICFn Flag is set at the same timer clock cycle as TOVn is set when either OCRnA or ICRn is used to define the TOP value. If one of the interrupts are enabled, the interrupt handler routine can be utilized for updating the TOP and compare values. When changing the TOP value the program must ensure that the new TOP value is higher or equal to the value of all of the Compare Registers. A compare match will never occur between the TCNTn and the OCRnx if the TOP value is lower than any of the Compare Registers. Note that when working with fixed TOP values the unused bits are masked to zero when any of the OCRnx Registers are written. 291 8393C-MCU Wireless-09/14

The procedure for updating ICRn differs from updating OCRnA when used for defining the TOP value. The ICRn Register is not double buffered. This means that if ICRn is changed to a low value while the counter is running with no or a low prescaler value, there is a risk that the newly written ICRn value is lower than the current value of TCNTn. In consequence the counter will miss the compare match at the TOP value. The counter must then count to the MAX value (0xFFFF) and wrap around starting at 0x0000 before the compare match can occur. The OCRnA Register is double buffered though. This feature allows writing the OCRnA I/O location at anytime. When the OCRnA I/O location is written the new value will be put first into the OCRnA Buffer Register. The OCRnA Compare Register will then be updated with the value in the Buffer Register at the next clock cycle of the timer when TCNTn matches TOP. The update is done at the same timer clock cycle as the TCNTn is cleared and the TOVn Flag is set. The definition of TOP with the ICRn Register works well for fixed TOP values. Combined with ICRn, the OCRnA Register is free to be used for generating a PWM output on OCnA. However, if the base PWM frequency is actively changed (by modifying the TOP value), working with the OCRnA as TOP is clearly a better choice due to its double buffer feat ure. In fast PWM mode the compare units allow the generation of PWM waveforms on the OCnx pins. Setting the COMnx1:0 bits to 2 will produce a non-inverted PWM and an inverted PWM output can be generated by setting the COMnx1:0 to 3 (see Table 18-3 on page 288). The actual OCnx value will only be visible on the port pin if the data direction of the port pin is set to output (DDR_OCnx). The PWM waveform is generated by setting (or clearing) the OCnx Register at the compare match between OCRnx and TCNTn, and by clearing (or setting) the OCnx Register at the timer clock cycle the counter is cleared (changes from TOP to BOTTOM). The PWM frequency of the output f can be calculated with the following OCnxPWM equation: f f = clkI/O OCnxPWM N⋅(1+TOP) The N variable represents the prescaler divider (1, 8, 64, 256 or 1024). The extreme values for the OCRnx Register represent special cases when generating a PWM waveform output in the fast PWM mode. If the OCRnx is set equal to BOTTOM (0x0000), the output will be a narrow spike for each TOP+1 timer clock cycle. Setting the OCRnx equal to TOP will result in a constant high or low output (depending on the polarity of the output set by the COMnx1:0 bits.) A frequency (with 50% duty cycle) waveform output in fast PWM mode can be achieved by setting OCnA to toggle its logical level on each compare match (COMnA1:0 = 1). This applies only if OCR1A is used to define the TOP value (WGM13:0 = 15). The waveform generated will have a maximum frequency of f = f /2 when OCRnA is OCnA clkI/O set to zero (0x0000). This feature is similar to the OCnA toggle in CTC mode, except the double buffer feature of the Output Compare unit is enabled in the fast PWM mode. 18.9.4 Phase Correct PWM Mode The phase correct Pulse Width Modulation (PWM) mode (WGMn3:0 = 1, 2, 3, 10 or 11) provides a high resolution phase correct PWM waveform generation option. The phase correct PWM mode is, like the phase and frequency correct PWM mode, based on a dual-slope operation. The counter counts repeatedly from BOTTOM (0x0000) to TOP and then from TOP to BOTTOM. In non-inverting Compare Output mode, the Output Compare (OCnx) is cleared on the compare match between TCNTn and OCRnx while ATmega256/128/64RFR2 292 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 up-counting, and set on the compare match while down-counting. In inverting Output Compare mode, the operation is inverted. The dual-slope operation has a lower maximum operation frequency than single slope operation. However these modes are preferred for motor control applications due to the symmetric feature of the dual-slope PWM modes. The PWM resolution for the phase correct PWM mode can be fixed to 8, 9 or 10 bit, or be defined by either ICRn or OCRnA. The minimum resolution allowed is 2 bit (ICRn or OCRnA set to 0x0003), and the maximum resolution is 16-bit (ICRn or OCRnA set to MAX). The PWM resolution R in bits can be calculated with the following equation: PCPWM log(TOP+1) R = PCPWM log(2) In phase correct PWM mode the counter is incremented until the counter value matches either one of the fixed values 0x00FF, 0x01FF or 0x03FF (WGMn3:0 = 1, 2, or 3), the value in ICRn (WGMn3:0 = 10) or the value in OCRnA (WGMn3:0 = 11). The counter has then reached the TOP and changes the count direction. The TCNTn value will be equal to TOP for one timer clock cycle. The timing diagram for the phase correct PWM mode is shown on Figure 18-8 below. The figure shows phase correct PWM mode when OCRnA or ICRn is used to define TOP. The TCNTn value is shown in the timing diagram as a histogram illustrating the dual-slope operation. The diagram includes non- inverted and inverted PWM outputs. The small horizontal line marks on the TCNTn slopes represent compare matches between OCRnx and TCNTn. The OCnx Interrupt Flag will be set when a compare match occurs. Figure 18-8. Phase Correct PWM Mode Timing Diagram OCRnx/TOP Update and(cid:13) OCnA Interrupt Flag Set(cid:13) or ICFn Interrupt Flag Set(cid:13) (Interrupt on TOP) TOVn Interrupt Flag Set (Interrupt on Bottom) TCNTn OCnx (COMnx1:0 = 2) OCnx (COMnx1:0 = 3) Period 1 2 3 4 The Timer/Counter Overflow Flag (TOVn) is set each time the counter reaches BOTTOM. When either OCRnA or ICRn is used for defining the TOP value, the OCnA or ICFn Flag is set accordingly at the same timer clock cycle as the OCRnx Registers are updated with the double buffer value (at TOP). The Interrupt Flags can be used to generate an interrupt each time the counter reaches the TOP or BOTTOM value. When changing the TOP value the program must ensure that the new TOP value is higher or equal to the value of all of the Compare Registers. If the TOP value is lower than any of the Compare Registers, a compare match will never occur between the 293 8393C-MCU Wireless-09/14

TCNTn and the OCRnx. Note that when working with fixed TOP values, the unused bits are masked to zero when any of the OCRnx Registers are written. As the third period shown in Figure 18-8 illustrates, changing the TOP actively while the Timer/Counter is running in the phase correct mode can result in an asymmetrical output. The reason for this can be found in the update time of the OCRnx Register. Since the OCRnx update occurs at TOP, the PWM period starts and ends at TOP. This implies that the length of the falling slope is determined by the previous TOP value, while the length of the rising slope is determined by the new TOP value. When these two values are not equal the two slopes of the period will differ in length. The difference in length gives the asymmetrical result of the output. It is recommended to use the phase and frequency correct mode instead of the phase correct mode when changing the TOP value while the Timer/Counter is running. When using a static TOP value there are practically no differences between the two modes of operation. In phase correct PWM mode, the compare units allow generating PWM waveforms on the OCnx pins. Setting the COMnx1:0 bits to 2 will produce a non-inverted PWM. An inverted PWM output can be generated by setting the COMnx1:0 to 3 (see Table 18-4 on page 288). The actual OCnx value will only be visible on the port pin if the data direction of the port pin is set to output (DDR_OCnx). The PWM waveform is generated by setting (or clearing) the OCnx Register at the compare match between OCRnx and TCNTn when the counter increments, and by clearing (or setting) the OCnx Register at compare match between OCRnx and TCNTn when the counter decrements. The PWM frequency of the output f when using phase-correct PWM can be calculated OCnxPCPWM with the following equation: f f = clkI/O OCnxPCPWM 2⋅N ⋅TOP) The N variable represents the prescaler divider (1, 8, 64, 256, or 1024). The extreme values for the OCRnx Register represent special cases when generating a PWM waveform output in t he phase correct PWM mode. If the OCRnx is set equal to BOTTOM the output will be continuously low and if set equal to TOP the output will be continuously high for non-inverted PWM mode. For inverted PWM the output will have the opposite logic values. If OCR1A is used to define the TOP value (WGM13:0 = 11) and COM1A1:0 = 1, the OC1A output will toggle with a 50% duty cycle. 18.9.5 Phase and Frequency Correct PWM Mode The phase and frequency correct Pulse Width Modulation (PWM) mode (WGMn3:0 = 8 or 9) provides a high resolution phase and frequency correct PWM waveform generation option. The phase and frequency correct PWM mode is, like the phase correct PWM mode, based on a dual-slope operation. The counter counts repeatedly from BOTTOM (0x0000) to TOP and then from TOP to BOTTOM. In non-inverting Compare Output mode, the Output Compare (OCnx) is cleared on the compare match between TCNTn and OCR n x while up-counting, and set on the compare match while down-counting. In inverting Compare Output mode, the operation is inverted. The dual- slope operation gives a lower maximum operation frequency compared to the single- slope operation. However these modes are preferred for motor control applications due to the symmetric feature of the dual-slope PWM modes. The main difference between the phase correct and the phase and frequency correct PWM mode is the time the OCRnx Register is updated by the OCRnx Buffer Register, (see Figure 18-8 on page 293 and Figure 18-9 on page 295). ATmega256/128/64RFR2 294 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 The PWM resolution for the phase and frequency correct PWM mode can be defined by either ICRn or OCRnA. The minimum resolution allowed is 2 bit (ICRn or OCRnA set to 0x0003), and the maximum resolution is 16 bit (ICRn or OCRnA set to MAX). The PWM resolution R in bits can be calculated with the following equation: PFCPWM log(TOP+1) R = PFCPWM log(2) In phase and frequency correct PWM mode the counter is incremented until the counter value matches either the value in ICRn (WGMn3:0 = 8), or the value in OCRnA (WGMn3:0 = 9). The counter has then reached TOP and changes the count direction. The TCNTn value will be equal to TOP for one timer clock cycle. The timing diagram for the phase correct and frequency correct PWM mode is shown in Figure 18-9 below. The figure shows phase and frequency correct PWM mode when OCRnA or ICRn is used to define TOP. The TCNTn value is shown in the timing diagram as a histogram for illustrating the dual-slope operation. The diagram includes non-inverted and inverted PWM outputs. The small horizontal line marks on the TCNTn slopes represent compare matches between OCRnx and TCNTn. The OCnx Interrupt Flag will be set when a compare match occurs. Figure 18-9. Phase and Frequency Correct PWM Mode Timing Diagram OCnA Interrupt Flag Set or ICFn Interrupt Flag Set (Interrupt on TOP) OCRnx/TOP Update and TOVn Interrupt Flag Set (Interrupt on Bottom) TCNTn OCnx (COMnx1:0 = 2) OCnx (COMnx1:0 = 3) Period 1 2 3 4 The Timer/Counter Overflo w Flag (TOVn) is set at the timer clock cycle when the OCRnx Registers are updated with the double-buffered value (at BOTTOM). The OCnA or ICFn Flag is set after TCNTn has reached TOP when either OCRnA or ICRn is used for defining the TOP value. The Interrupt Flags can then be used to generate an interrupt each time the counter reaches the TOP or BOTTOM value. When changing the TOP v alue the program must ensure that the new TOP value is higher or equal to the value of all of the Compare Registers. If the TOP value is lower than any of the Compare Registers, a compare match will never occur between the TCNTn and the OCRnx. As Figure 18-9 shows the output generated is, in contrast to the phase correct mode, symmetrical in all periods. Since the OCRnx Registers are updated at BOTTOM, the length of the rising and the falling slopes will always be equal. This gives symmetrical output pulses and is therefore frequency correct. 295 8393C-MCU Wireless-09/14

The definition of TOP with the ICRn Register works well when using fixed TOP values. Combined with ICRn the OCRnA Register is available for generating a PWM output on OCnA. However, if the base PWM frequency is actively changed by modifying the TOP value, using the OCRnA as TOP is clearly a better choice due to its double buffer feature. In phase and frequency correct PWM mode, the compare units allow generating PWM waveforms on the OCnx pins. Setting the COMnx1:0 bits to 2 will produce a non- inverted PWM. An inverted PWM output can be generated by setting the COMnx1:0 to 3 (see Table 18-4 on page 288). The actual OCnx value will only be visible at the port pin if the data direction of the port pin is set to output (DDR_OCnx). The PWM waveform is generated by setting (or clearing) the OCnx Register at the compare match between OCRnx and TCNTn when the counter increments, and by clearing (or setting) the OCnx Register at compare match between OCRnx and TCNTn when the counter decrements. The PWM frequency of the output f when using phase and OCnxPFCPWM frequency correct PWM can be calculated with the following equation: f f = clkI/O OCnxPFCPWM 2⋅N⋅TOP) The N variable represents the prescaler divider (1, 8, 64, 256, or 1024). The extreme values for the OCRnx Register represent special cases when generating a PWM waveform output in the phase correct PWM mode. If the OCRnx is set equal to BOTTOM the output will be continuously low and if set equal to TOP the output will be set to high for non-inverted PWM mode. For inverted PWM the output will have the opposite logic values. If OCR1A is used to define the TOP value (WGM13:0 = 9) and COM1A1:0 = 1, the OC1A o utput will toggle with a 50% duty cycle. 18.10 Timer/Counter Timing Diagrams The Timer/Counter is a synchronous design and the timer clock (clk ) is therefore Tn shown as a clock enable signal in the following figures. The figures include information on when Interrupt Flags are set and when the OCRnx Register is updated with the OCRnx buffer value (only for modes utilizing double buffering). Figure 18-10 shows a timing diagram for the setting of OCFnx. Figure 18-10. Timer/Counter Timing Diagram, Setting of OCFnx, no Prescaling clk I/O clk Tn (clk /1) I/O TCNTn OCRnx - 1 OCRnx OCRnx + 1 OCRnx + 2 OCRnx OCRnx Value OCFnx ATmega256/128/64RFR2 296 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 Figure 18-11 shows the same timing data, but with the prescaler enabled. Figure 18-11. Timer/Counter Timing Diagram, Setting of OCFnx with Prescaler (f /8) clkI/O clk I/O clk Tn (clk /8) I/O TCNTn OCRnx - 1 OCRnx OCRnx + 1 OCRnx + 2 OCRnx OCRnx Value OCFnx Figure 18-12 shows the count sequence close to TOP in various modes. When using phase and frequency correct PWM mode the OCRnx Register is updated at BOTTOM. The timing diagrams will be the same, but TOP should be replaced by BOTTOM, TOP- 1 by BOTTOM+1 and so on. The same renaming applies for modes that set the TOVn Flag at BOTTOM. Figure 18-12. Timer/Counter Timing Diagram, no Prescaling clk I/O clk Tn (clk /1) I/O TCNTn TOP - 1 TOP BOTTOM BOTTOM + 1 (CTC and FPWM) TCNTn TOP - 1 TOP TOP - 1 TOP - 2 (PC and PFC PWM) TOVn (FPWM) and ICFn (if used as TOP) OCRnx Old OCRnx Value New OCRnx Value (Update at TOP) 297 8393C-MCU Wireless-09/14

Figure 18-13 shows the same timing data, but with the prescaler enabled. Figure 18-13. Timer/Counter Timing Diagram with Prescaler (f /8) clkI/O clk I/O clk Tn (clk/8) I/O TCNTn TOP - 1 TOP BOTTOM BOTTOM + 1 (CTC and FPWM) TCNTn TOP - 1 TOP TOP - 1 TOP - 2 (PC and PFC PWM) TOVn (FPWM) and ICFn (if used as TOP) OCRnx Old OCRnx Value New OCRnx Value (Update at TOP) 18.11 Register Description 18.11.1 TCCR1A – Timer/Counter1 Control Register A Bit 7 6 5 4 3 2 1 0 NA ($80) COM1A1 COM1A0 COM1B1 COM1B0 COM1C1 COM1C0 WGM11 WGM10 TCCR1A Read/Write RW RW RW RW RW RW RW RW Initial Value 0 0 0 0 0 0 0 0 • Bit 7:6 – COM1A1:0 - C ompare Output Mode for Channel A The COM1A1:0 bits control the output compare behavior of pin OC1A. If one or both of the COM1A1:0 bits are written to one, the OC1A output overrides the normal port functionality of the I/O pin it is connected to. However note that the Data Direction Register (DDR) bit corresponding to the OC1A pin must be set in order to enable the output driver. When the OC1A is connected to the pin, the function of the COM1A1:0 bits is dependent of the WGM13:0 bits setting. The following table shows the COM1A1:0 bit functionality when the WGM13:0 bits are set to a normal or a CTC mode (non-PWM). For the other functionality refer to section "Modes of Operation". Table 18-6 COM1A Register Bits Register Bits Value Description COM1A1:0 0 Normal port operation, OCnA/OCnB/OCnC disconnected. 1 Toggle OCnA/OCnB/OCnC on Compare Match. 2 Clear OCnA/OCnB/OCnC on Compare Match (set output to low level). 3 Set OCnA/OCnB/OCnC on Compare Match (set output to high level). • Bit 5:4 – COM1B1:0 - Compare Output Mode for Channel B ATmega256/128/64RFR2 298 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 The COM1B1:0 bits control the output compare behavior of pin OC1B. If one or both of the COM1B1:0 bits are written to one, the OC1B output overrides the normal port functionality of the I/O pin it is connected to. However note that the Data Direction Register (DDR) bit corresponding to the OC1B pin must be set in order to enable the output driver. When the OC 1A is connected to the pin, the function of the COM1B1:0 bits is dependent of the WGM13:0 bits setting. The following table shows the COM1B1:0 bit functionality when the WGM13:0 bits are set to a normal or a CTC mode (non-PWM). For the other functionality refer to section "Modes of Operation". Table 18-7 COM1B Register Bits Register Bits Value Description COM1B1:0 0 Normal port operation, OCnA/OCnB/OCnC disconnected. 1 Toggle OCnA/OCnB/OCnC on Compare Match. 2 Clear OCnA/OCnB/OCnC on Compare Match (set output to low level). 3 Set OCnA/OCnB/OCnC on Compare Match (set output to high level). • Bit 3:2 – COM1C1:0 - Compare Output Mode for Channel C The COM1C1:0 bits control the output compare behavior of pin OC1C. If one or both of the COM1C1:0 bits are written to one, the OC1C output overrides the normal port functionality of the I/O pin it is connected to. However note that the Data Direction Register (DDR) bit corresponding to the OC1C pin must be set in order to enable the output driver. When the OC1A is connected to the pin, the function of the COM1C1:0 bits is dependent of the WGM13:0 bits setting. The following table shows the COM1C1:0 bit functionality when the WGM13:0 bits are set to a normal or a CTC mode (non-PWM). For the other functionality refer to section "Modes of Operation". Table 18-8 COM1C Register Bits Register Bits Value Description COM1C1:0 0 Normal port operation, OCnA/OCnB/OCnC disconnected. 1 Toggle OCnA/OCnB/OCnC on Compare Match. 2 Clear OCnA/OCnB/OCnC on Compare Match (set output to low level). 3 Set OCnA/OCnB/OCnC on Compare Match (set output to high level). • Bit 1:0 – WGM11:10 - Waveform Generation Mode Combined with the WGM13:12 bits, found in the TCCR1B Register, these bits control the counting sequence of the counter, the source for maximum (TOP) counter value and what type of waveform generation to be used. Modes of operation supported by the Timer/Counter unit are: Normal mode (counter), Clear Timer on Compare match (CTC) mode, and three types of Pulse Width Modulation (PWM) modes. For more information on the different modes see section "Modes of Operation". Table 18-9 WGM1 Register Bits Register Bits Value Description WGM13:10 0x0 Normal mode of operation 0x1 PWM, phase correct, 8-bit 299 8393C-MCU Wireless-09/14

Register Bits Value Description 0x2 PWM, phase correct, 9-bit 0x3 PWM, phase correct, 10-bit 0x4 CTC, TOP = OCRnA 0x5 Fast PWM, 8-bit 0x6 Fast PWM, 9-bit 0x7 Fast PWM, 10-bit 0x8 PWM, Phase and frequency correct, TOP = ICRn 0x9 PWM, Phase and frequency correct, TOP = OCRnA 0xA PWM, Phase correct, TOP = ICRn 0xB PWM, Phase correct, TOP = OCRnA 0xC CTC, TOP = OCRnA 0xD Reserved 0xE Fast PWM, TOP = ICRn 0xF Fast PWM, TOP = OCRnA 18.11.2 TCCR1B – Timer/Counter1 Control Register B Bit 7 6 5 4 3 2 1 0 NA ($81) ICNC1 ICES1 Res WGM13 WGM12 CS12 CS11 CS10 TCCR1B Read/Write RW RW R RW RW RW RW RW Initial Value 0 0 0 0 0 0 0 0 • Bit 7 – ICNC1 - Input Capture 1 Noise Canceller Setting this bit (to one) activates the Input Capture Noise Canceler. When the Noise Canceler is activated, the input from the Input Capture Pin (ICP1) is filtered. The filter function requires four successive equal valued samples of the ICP1 pin for changing its output. The input capture is therefore delayed by four Oscillator cycles when the noise canceler is enabled. • Bit 6 – ICES1 - Input Capture 1 Edge Select This bit selects which edge on the Input Capture Pin (ICP1) that is used to trigger a capture event. When the ICES1 bit is written to zero, a falling (negative) edge is used as trigger. When the ICES1 bit is written to one, a rising (positive) edge will trigger the capture. When a capture is triggered according to the ICES1 setting, the counter value is copied into the Input Capture Register (ICR1). The event will also set the Input Capture Flag (ICF1). This can be used to cause an Input Capture Interrupt, if this interrupt is enabled. When the ICR1 is used as TOP value (see description of the WGM13:0 bits located in the TCCR1A and the TCCR1B Register), the ICP1 is disconnected and consequently the input capture function is disabled. • Bit 5 – Res - Reserved Bit This bit is reserved for future use. A read access always will return zero. A write access does not modify the content. • Bit 4:3 – WGM13:12 - Waveform Generation Mode ATmega256/128/64RFR2 300 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 Combined with the WGM11:10 bits, found in the TCCR1A Register, these bits control the counting sequence of the counter, the source for maximum (TOP) counter value and what type of waveform generation to be used. Modes of operation supported by the Timer/Counter unit are: Normal mode (counter), Clear Timer on Compare match (CTC) mode, and three types of Pu lse Width Modulation (PWM) modes. For more information on the different modes see section "Modes of Operation". Table 18-10 WGM1 Register Bits Register Bits Value Description WGM13:10 0x0 Normal mode of operation 0x1 PWM, phase correct, 8-bit 0x2 PWM, phase correct, 9-bit 0x3 PWM, phase correct, 10-bit 0x4 CTC, TOP = OCRnA 0x5 Fast PWM, 8-bit 0x6 Fast PWM, 9-bit 0x7 Fast PWM, 10-bit 0x8 PWM, Phase and frequency correct, TOP = ICRn 0x9 PWM, Phase and frequency correct, TOP = OCRnA 0xA PWM, Phase correct, TOP = ICRn 0xB PWM, Phase correct, TOP = OCRnA 0xC CTC, TOP = OCRnA 0xD Reserved 0xE Fast PWM, TOP = ICRn 0xF Fast PWM, TOP = OCRnA • Bit 2:0 – CS12:10 - Cloc k Select The three clock select bits select the clock source to be used by the Timer/Counter1 according to the following table. If external pin modes are used for the Timer/Counter1, transitions on the T1 pin will clock the counter even if the pin is configured as an output. This feature allows software control of the counting. Table 18-11 CS1 Register Bits Register Bits Value Description CS12:10 0x00 No clock source (Timer/Counter stopped) 0x01 clkIO/1 (no prescaling) 0x02 clkIO/8 (from prescaler) 0x03 clkIO/64 (from prescaler) 0x04 clkIO/256 (from prescaler) 0x05 clkIO/1024 (from prescaler) 0x06 External clock source on Tn pin, clock on falling edge 0x07 External clock source on Tn pin, clock on rising edge 301 8393C-MCU Wireless-09/14

18.11.3 TCCR1C – Timer/Counter1 Control Register C Bit 7 6 5 4 3 2 1 0 NA ($82) FOC1A FOC1B FOC1C Res4 Res3 Res2 Res1 Res0 TCCR1C Read/Write RW RW RW R R R R R Initial Value 0 0 0 0 0 0 0 0 • Bit 7 – FOC1A - Force Output Compare for Channel A The FOC1A bit is only active when the WGM13:0 bits specify a non-PWM mode. When writing a logical one to the FOC1A bit, an immediate compare match is forced on the waveform generation unit. The OC1A output is changed according to its COM1A1:0 bits setting. Note that the FOC1 A bits are implemented as strobes. Therefore it is the value present in the COM1A1:0 bits that determine the effect of the forced compare. A FOC1A strobe will not generate any interrupt nor will it clear the timer in Clear Timer on Compare Match (CTC) mode using OCR1A as TOP. The FOC1A bits are always read as zero. • Bit 6 – FOC1B - Force O utput Compare for Channel B The FOC1B bit is only active when the WGM13:0 bits specify a non-PWM mode. When writing a logical one to the FOC1B bit, an immediate compare match is forced on the waveform generation unit. The OC1B output is changed according to its COM1B1:0 bits setting. Note that the FOC1B bits are implemented as strobes. Therefore it is the value present in the COM1B1:0 bits that determine the effect of the forced compare. A FOC1B strobe will not generate any interrupt nor will it clear the timer in Clear Timer on Compare Match (CTC) mode using OCR1B as TOP. The FOC1B bits are always read as zero. • Bit 5 – FOC1C - Force Output Compare for Channel C The FOC1C bit is only active when the WGM13:0 bits specify a non-PWM mode. When writing a logical one to the FOC1C bit, an immediate compare match is forced on the waveform generation unit. The OC1C output is changed according to its COM1C1:0 bits setting. Note that the FOC1C bits are implemented as strobes. Therefore it is the value present in the COM1C1:0 bits that determine the effect of the forced compare. A FOC1C strobe will not generate any interrupt nor will it clear the timer in Clear Timer on Compare Match (CTC) mode using OCR1C as TOP. The FOC1C bits are always read as zero. • Bit 4:0 – Res4:0 - Reserved These bits are reserved for future use. 18.11.4 TCNT1H – Timer/Counter1 High Byte Bit 7 6 5 4 3 2 1 0 NA ($85) TCNT1H7:0 TCNT1H Read/Write RW RW RW RW RW RW RW RW Initial Value 0 0 0 0 0 0 0 0 The two Timer/Counter I/O locations (TCNT1H and TCNT1L, combined TCNT1) give direct access, both for read and for write operations, to the Timer/Counter unit 16-bit counter. To ensure that both the high and low bytes are read and written simultaneously when the CPU accesses these registers, the access is performed using an 8-bit temporary High Byte Register (TEMP). This temporary register is shared by all the other ATmega256/128/64RFR2 302 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 16-bit registers. See section "Accessing 16-bit Registers" for details. Modifying the counter (TCNT1) while the counter is running introduces a risk of missing a compare match between TCNT1 and one of the OCR1x Registers. Writing to the TCNT1 Register blocks (removes) the compare match on the following timer clock for all compare units. • Bit 7:0 – TCNT1H7:0 - Timer/Counter1 High Byte 18.11.5 TCNT1L – Timer/Counter1 Low Byte Bit 7 6 5 4 3 2 1 0 NA ($84) TCNT1L7:0 TCNT1L Read/Write RW RW RW RW RW RW RW RW Initial Value 0 0 0 0 0 0 0 0 The two Timer/Counter I/O locations (TCNT1H and TCNT1L, combined TCNT1) give direct access, both for read and for write operations, to the Timer/Counter unit 16-bit counter. To ensure that both the high and low bytes are read and written simultaneously when the CPU accesses these registers, the access is performed using an 8-bit temporary High Byte Register (TEMP). This temporary register is shared by all the other 16-bit registers. See section "Accessing 16-bit Registers" for details. Modifying the counter (TCNT1) while the counter is running introduces a risk of missing a compare match between TCNT1 and one of the OCR1x Registers. Writing to the TCNT1 Register blocks (removes) the compare match on the following timer clock for all compare units. • Bit 7:0 – TCNT1L7:0 - Timer/Counter1 Low Byte 18.11.6 OCR1AH – Timer/Counter1 Output Compare Register A High Byte Bit 7 6 5 4 3 2 1 0 NA ($89) OCR1AH7:0 OCR1AH Read/Write RW RW RW RW RW RW RW RW Initial Value 0 0 0 0 0 0 0 0 The Output Compare Registers contain a 16-bit value that is continuously compared with the counter value (TCNT1). A match can be used to generate an Output Compare interrupt, or to generate a waveform output on the OC1A pin. The Output Compare Registers are 16-bit in size. To ensure that both the high and low bytes are written simultaneously when the CPU writes to these registers, the access is performed using an 8-bit temporary High Byte Register (TEMP). This temporary register is shared by all the other 16-bit registers. See section "Accessing 16-bit Registers" for details. • Bit 7:0 – OCR1AH7:0 - Timer/Counter1 Output Compare Register High Byte 18.11.7 OCR1AL – Timer/Counter1 Output Compare Register A Low Byte Bit 7 6 5 4 3 2 1 0 NA ($88) OCR1AL7:0 OCR1AL Read/Write RW RW RW RW RW RW RW RW Initial Value 0 0 0 0 0 0 0 0 303 8393C-MCU Wireless-09/14

The Output Compare Registers contain a 16-bit value that is continuously compared with the counter value (TCNT1). A match can be used to generate an Output Compare interrupt, or to generate a waveform output on the OC1A pin. The Output Compare Registers are 16-bit in size. To ensure that both the high and low bytes are written simultaneously when the CPU writes to these registers, the access is performed using an 8-bit temporary High Byte Register (TEMP). This temporary register is shared by all the other 16-bit registers. See section "Accessing 16-bit Registers" for details. • Bit 7:0 – OCR1AL7:0 - Timer/Counter1 Output Compare Register Low Byte 18.11.8 OCR1BH – Timer/Counter1 Output Compare Register B High Byte Bit 7 6 5 4 3 2 1 0 NA ($8B) OCR1BH7:0 OCR1BH Read/Write RW RW RW RW RW RW RW RW Initial Value 0 0 0 0 0 0 0 0 The Output Compare Registers contain a 16-bit value that is continuously compared with the counter value (TCNT1). A match can be used to generate an Output Compare interrupt, or to generate a waveform output on the OC1B pin. The Output Compare Registers are 16-bit in size. To ensure that both the high and low bytes are written simultaneously when the CPU writes to these registers, the access is performed using an 8-bit temporary High Byte Register (TEMP). This temporary register is shared by all the other 16-bit registers. See section "Accessing 16-bit Registers" for details. • Bit 7:0 – OCR1BH7:0 - Timer/Counter1 Output Compare Register High Byte 18.11.9 OCR1BL – Timer/Counter1 Output Compare Register B Low Byte Bit 7 6 5 4 3 2 1 0 NA ($8A) OCR1BL7:0 OCR1BL Read/Write R RW RW RW RW RW RW RW Initial Value 0 0 0 0 0 0 0 0 The Output Compare Registers contain a 16-bit value that is continuously compared with the counter value (TCN T1). A match can be used to generate an Output Compare interrupt, or to generate a waveform output on the OC1B pin. The Output Compare Registers are 16-bit in size. To ensure that both the high and low bytes are written simultaneously when the CPU writes to these registers, the access is performed using an 8-bit temporary High Byte Register (TEMP). This temporary register is shared by all the other 16-bit registers. See section "Accessing 16-bit Registers" for details. • Bit 7:0 – OCR1BL7:0 - Timer/Counter1 Output Compare Register Low Byte ATmega256/128/64RFR2 304 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 18.11.10 OCR1CH – Timer/Counter1 Output Compare Register C High Byte Bit 7 6 5 4 3 2 1 0 NA ($8D) OCR1CH7:0 OCR1CH Read/Write RW RW RW RW RW RW RW RW Initial Value 0 0 0 0 0 0 0 0 The Output Compare Registers contain a 16-bit value that is continuously compared with the counter value (TCNT1). A match can be used to generate an Output Compare interrupt, or to generate a waveform output on the OC1C pin. The Output Compare Registers are 16-bit in size. To ensure that both the high and low bytes are written simultaneously when the CPU writes to these registers, the access is performed using an 8-bit temporary High Byte Register (TEMP). This temporary register is shared by all the other 16-bit registers. See section "Accessing 16-bit Registers" for details. • Bit 7:0 – OCR1CH7:0 - Timer/Counter1 Output Compare Register High Byte 18.11.11 OCR1CL – Timer/Counter1 Output Compare Register C Low Byte Bit 7 6 5 4 3 2 1 0 NA ($8C) OCR1CL7:0 OCR1CL Read/Write R RW RW RW RW RW RW RW Initial Value 0 0 0 0 0 0 0 0 The Output Compare Registers contain a 16-bit value that is continuously compared with the counter value (TCNT1). A match can be used to generate an Output Compare interrupt, or to generate a waveform output on the OC1C pin. The Output Compare Registers are 16-bit in size. To ensure that both the high and low bytes are written simultaneously when the CPU writes to these registers, the access is performed using an 8-bit temporary High Byt e Register (TEMP). This temporary register is shared by all the other 16-bit registers. See section "Accessing 16-bit Registers" for details. • Bit 7:0 – OCR1CL7:0 - Timer/Counter1 Output Compare Register Low Byte 18.11.12 ICR1H – Timer/Counter1 Input Capture Register High Byte Bit 7 6 5 4 3 2 1 0 NA ($87) ICR1H7:0 ICR1H Read/Write R R R R R R R R Initial Value 0 0 0 0 0 0 0 0 The Input Capture Register is updated with the counter (TCNT1) value each time an event occurs on the ICP1 pin or on the Analog Comparator output. The Input Capture Register can be used for defining the counter TOP value. The Input Capture Register is 16-bit in size. To ensure that both the high and low bytes are read simultaneously when the CPU accesses these registers, the access is performed using an 8-bit temporary High Byte Register (TEMP). This temporary register is shared by all the other 16-bit registers. See section "Accessing 16-bit Registers" for details. • Bit 7:0 – ICR1H7:0 - Timer/Counter1 Input Capture Register High Byte 305 8393C-MCU Wireless-09/14

18.11.13 ICR1L – Timer/Counter1 Input Capture Register Low Byte Bit 7 6 5 4 3 2 1 0 NA ($86) ICR1L7:0 ICR1L Read/Write R R R R R R R R Initial Value 0 0 0 0 0 0 0 0 The Input Capture Register is updated with the counter (TCNT1) value each time an event occurs on the ICP1 pin or on the Analog Comparator output. The Input Capture Register can be used for defining the counter TOP value. The Input Capture Register is 16-bit in size. To ensure that both the high and low bytes are read simultaneously when the CPU accesses these r egisters, the access is performed using an 8-bit temporary High Byte Register (TEMP). This temporary register is shared by all the other 16-bit registers. See section "Accessing 16-bit Registers" for details. • Bit 7:0 – ICR1L7:0 - Timer/Counter1 Input Capture Register Low Byte 18.11.14 TIMSK1 – Timer/Counter1 Interrupt Mask Register Bit 7 6 5 4 3 2 1 0 NA ($6F) Res1 Res0 ICIE1 Res OCIE1C OCIE1B OCIE1A TOIE1 TIMSK1 Read/Write R R RW R R R RW RW Initial Value 0 0 0 0 0 0 0 0 • Bit 7:6 – Res1:0 - Reserved Bit This bit is reserved for future use. A read access always will return zero. A write access does not modify the content. • Bit 5 – ICIE1 - Timer/Counter1 Input Capture Interrupt Enable When this bit is written to one, and the I-flag in the Status Register is set (interrupts globally enabled), the Timer/Counter1 Input Capture interrupt is enabled. The corresponding Interrupt Vector is executed when the ICF1 Flag, located in TIFR1, is set. • Bit 4 – Res - Reserved Bit This bit is reserved for future use. A read access always will return zero. A write access does not modify the content. • Bit 3 – OCIE1C - Timer/ Counter1 Output Compare C Match Interrupt Enable When this bit is written to one, and the I-flag in the Status Register is set (interrupts globally enabled), the Timer/Counter1 Output Compare C Match interrupt is enabled. The corresponding Interrupt Vector is executed when the OCF1C Flag, located in TIFR1, is set. • Bit 2 – OCIE1B - Timer/Counter1 Output Compare B Match Interrupt Enable When this bit is written to one, and the I-flag in the Status Register is set (interrupts globally enabled), the Timer/Counter1 Output Compare B Match interrupt is enabled. The corresponding Interrupt Vector is executed when the OCF1B Flag, located in TIFR1, is set. • Bit 1 – OCIE1A - Timer/Counter1 Output Compare A Match Interrupt Enable When this bit is written to one, and the I-flag in the Status Register is set (interrupts globally enabled), the Timer/Counter1 Output Compare A Match interrupt is enabled. ATmega256/128/64RFR2 306 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 The corresponding Interrupt Vector is executed when the OCF1A Flag, located in TIFR1, is set. • Bit 0 – TOIE1 - Timer/Counter1 Overflow Interrupt Enable When this bit is written to o ne, and the I-flag in the Status Register is set (interrupts globally enabled), the Timer/Counter1 Overflow interrupt is enabled. The corresponding Interrupt Vector is executed when the TOV1 Flag, located in TIFR1, is set. 18.11.15 TIFR1 – Timer/Counter1 Interrupt Flag Register Bit 7 6 5 4 3 2 1 0 $16 ($36) Res1 Res0 ICF1 Res OCF1C OCF1B OCF1A TOV1 TIFR1 Read/Write R R RW R RW RW RW RW Initial Value 0 0 0 0 0 0 0 0 • Bit 7:6 – Res1:0 - Reserved Bit This bit is reserved for future use. A read access always will return zero. A write access does not modify the content. • Bit 5 – ICF1 - Timer/Counter1 Input Capture Flag This flag is set when a capture event occurs on the ICP1 pin. When the Input Capture Register (ICR1) is set by the WGM13:0 to be used as the TOP value, the ICF1 Flag is set when the counter reaches the TOP value. ICF1 is automatically cleared when the Input Capture Interrupt Vector is executed. Alternatively, ICF1 can be cleared by writing a logic one to its bit location. • Bit 4 – Res - Reserved Bit This bit is reserved for future use. A read access always will return zero. A write access does not modify the content. • Bit 3 – OCF1C - Timer/C ounter1 Output Compare C Match Flag This flag is set in the timer clock cycle after the counter (TCNT1) value matches the Output Compare Register C (OCR1C). Note that a Forced Output Compare (FOC1C) strobe will not set the OCF1C Flag. OCF1C is automatically cleared when the Output Compare Match C Interrupt Vector is executed. Alternatively, OCF1C can be cleared by writing a logic one to its bit location. • Bit 2 – OCF1B - Timer/Counter1 Output Compare B Match Flag This flag is set in the timer clock cycle after the counter (TCNT1) value matches the Output Compare Register B (OCR1B). Note that a Forced Output Compare (FOC1B) strobe will not set the OCF1B Flag. OCF1B is automatically cleared when the Output Compare Match B Interrupt Vector is executed. Alternatively, OCF1B can be cleared by writing a logic one to its bit location. • Bit 1 – OCF1A - Timer/Counter1 Output Compare A Match Flag This flag is set in the timer clock cycle after the counter (TCNT1) value matches the Output Compare Register A (OCR1A). Note that a Forced Output Compare (FOC1A) strobe will not set the OCF1A Flag. OCF1A is automatically cleared when the Output Compare Match A Interrupt Vector is executed. Alternatively, OCF1A can be cleared by writing a logic one to its bit location. • Bit 0 – TOV1 - Timer/Counter1 Overflow Flag The setting of this flag is dependent of the WGM13:0 bits setting of the Timer/Counter1 Control Register. In Normal and CTC modes, the TOV1 Flag is set when the timer 307 8393C-MCU Wireless-09/14

overflows. TOV1 is automatically cleared when the Timer/Counter1 Overflow Interrupt Vector is executed. Alternatively, TOV1 can be cleared by writing a logic one to its bit location. 18.11.16 TCCR3A – Timer/Counter3 Control Register A Bit 7 6 5 4 3 2 1 0 NA ($90) COM3A1 COM3A0 COM3B1 COM3B0 COM3C1 COM3C0 WGM31 WGM30 TCCR3A Read/Write RW RW RW RW RW RW RW RW Initial Value 0 0 0 0 0 0 0 0 • Bit 7:6 – COM3A1:0 - Compare Output Mode for Channel A The COM3A1:0 bits control the output compare behavior of pin OC3A. If one or both of the COM3A1:0 bits are written to one, the OC3A output overrides the normal port functionality of the I/O pin it is connected to. However note that the Data Direction Register (DDR) bit corresp o nding to the OC3A pin must be set in order to enable the output driver. When the OC3A is connected to the pin, the function of the COM3A1:0 bits is dependent of the WGM33:0 bits setting. The following table shows the COM3A1:0 bit functionality when the WGM33:0 bits are set to a normal or a CTC mode (non-PWM). For the other functionality refer to section "Modes of Operation". Table 18-12 COM3A Register Bits Register Bits Value Description COM3A1:0 0 Normal port operation, OCnA/OCnB/OCnC disconnected. 1 Toggle OCnA/OCnB/OCnC on Compare Match. 2 Clear OCnA/OCnB/OCnC on Compare Match (set output to low level). 3 Set OCnA/OCnB/OCnC on Compare Match (set output to high level). • Bit 5:4 – COM3B1:0 - Compare Output Mode for Channel B The COM3B1:0 bits control the output compare behavior of pin OC3B. If one or both of the COM3B1:0 bits are written to one, the OC3B output overrides the normal port functionality of the I/O pin it is connected to. However note that the Data Direction Register (DDR) bit corresponding to the OC3B pin must be set in order to enable the output driver. When the OC 3B is connected to the pin, the function of the COM3B1:0 bits is dependent of the WGM33:0 bits setting. The following table shows the COM3B1:0 bit functionality when the WGM33:0 bits are set to a normal or a CTC mode (non-PWM). For the other functionality refer to section "Modes of Operation". Table 18-13 COM3B Register Bits Register Bits Value Description COM3B1:0 0 Normal port operation, OCnA/OCnB/OCnC disconnected. 1 Toggle OCnA/OCnB/OCnC on Compare Match. 2 Clear OCnA/OCnB/OCnC on Compare Match (set output to low level). 3 Set OCnA/OCnB/OCnC on Compare Match ATmega256/128/64RFR2 308 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 Register Bits Value Description (set output to high level). • Bit 3:2 – COM3C1:0 - Compare Output Mode for Channel C The COM3C1:0 bits control the output compare behavior of pin OC3C. If one or both of the COM3C1:0 bits are written to one, the OC3C output overrides the normal port functionality of the I/O pin it is connected to. However note that the Data Direction Register (DDR) bit corresponding to the OC3C pin must be set in order to enable the output driver. When the OC3C is connected to the pin, the function of the COM3C1:0 bits is dependent of the WGM33:0 bits setting. The following table shows the COM3C1:0 bit functionality when the WGM33:0 bits are set to a normal or a CTC mode (non-PWM). For the other functionality refer to section "Modes of Operation". Table 18-14 COM3C Register Bits Register Bits Value Description COM3C1:0 0 Normal port operation, OCnA/OCnB/OCnC disconnected. 1 Toggle OCnA/OCnB/OCnC on Compare Match. 2 Clear OCnA/OCnB/OCnC on Compare Match (set output to low level). 3 Set OCnA/OCnB/OCnC on Compare Match (set output to high level). • Bit 1:0 – WGM31:30 - Waveform Generation Mode Combined with the WGM33:32 bits, found in the TCCR3B Register, these bits control the counting sequence of the counter, the source for maximum (TOP) counter value and what type of waveform generation to be used. Modes of operation supported by the Timer/Counter unit are: Normal mode (counter), Clear Timer on Compare match (CTC) mode, and three types of Pulse Width Modulation (PWM) modes. For more information on the different modes see section "Modes of Operation". Table 18-15 WGM3 Register Bits Register Bits Value Description WGM33:30 0x0 Normal mode of operation 0x1 PWM, phase correct, 8-bit 0x2 PWM, phase correct, 9-bit 0x3 PWM, phase correct, 10-bit 0x4 CTC, TOP = OCRnA 0x5 Fast PWM, 8-bit 0x6 Fast PWM, 9-bit 0x7 Fast PWM, 10-bit 0x8 PWM, Phase and frequency correct, TOP = ICRn 0x9 PWM, Phase and frequency correct, TOP = OCRnA 0xA PWM, Phase correct, TOP = ICRn 0xB PWM, Phase correct, TOP = OCRnA 0xC CTC, TOP = OCRnA 0xD Reserved 309 8393C-MCU Wireless-09/14

Register Bits Value Description 0xE Fast PWM, TOP = ICRn 0xF Fast PWM, TOP = OCRnA 18.11.17 TCCR3B – Timer/Counter3 Control Register B Bit 7 6 5 4 3 2 1 0 NA ($91) ICNC3 ICES3 Res WGM33 WGM32 CS32 CS31 CS30 TCCR3B Read/Write RW RW R RW RW RW RW RW Initial Value 0 0 0 0 0 0 0 0 • Bit 7 – ICNC3 - Input Capture 3 Noise Canceller Setting this bit (to one) activates the Input Capture Noise Canceler. When the Noise Canceler is activated, the input from the Input Capture Pin (ICP3) is filtered. The filter function requires four successive equal valued samples of the ICP3 pin for changing its output. The input capture is therefore delayed by four Oscillator cycles when the noise canceler is enabled. • Bit 6 – ICES3 - Input Capture 3 Edge Select This bit selects which edge on the Input Capture Pin (ICP3) that is used to trigger a capture event. When the ICES3 bit is written to zero, a falling (negative) edge is used as trigger. When the ICES3 bit is written to one, a rising (positive) edge will trigger the capture. When a capture is triggered according to the ICES3 setting, the counter value is copied into the Input C apture Register (ICR3). The event will also set the Input Capture Flag (ICF3). This can be used to cause an Input Capture Interrupt, if this interrupt is enabled. When the ICR3 is used as TOP value (see description of the WGM33:0 bits located in the TCCR3A and the TCCR3B Register), the ICP3 is disconnected and consequently the input capture function is disabled. • Bit 5 – Res - Reserved Bit This bit is reserved for future use. A read access always will return zero. A write access does not modify the content. • Bit 4:3 – WGM33:32 - Waveform Generation Mode Combined with the WGM31:30 bits, found in the TCCR3A Register, these bits control the counting sequence of the counter, the source for maximum (TOP) counter value and what type of waveform generation to be used. Modes of operation supported by the Timer/Counter unit are: Nor mal mode (counter), Clear Timer on Compare match (CTC) mode, and three types of Pulse Width Modulation (PWM) modes. For more information on the different modes see section "Modes of Operation". Table 18-16 WGM3 Register Bits Register Bits Value Description WGM33:30 0x0 Normal mode of operation 0x1 PWM, phase correct, 8-bit 0x2 PWM, phase correct, 9-bit 0x3 PWM, phase correct, 10-bit 0x4 CTC, TOP = OCRnA 0x5 Fast PWM, 8-bit 0x6 Fast PWM, 9-bit ATmega256/128/64RFR2 310 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 Register Bits Value Description 0x7 Fast PWM, 10-bit 0x8 PWM, Phase and frequency correct, TOP = ICRn 0x9 PWM, Phase and frequency correct, TOP = OCRnA 0xA PWM, Phase correct, TOP = ICRn 0xB PWM, Phase correct, TOP = OCRnA 0xC CTC, TOP = OCRnA 0xD Reserved 0xE Fast PWM, TOP = ICRn 0xF Fast PWM, TOP = OCRnA • Bit 2:0 – CS32:30 - Clock Select The three clock select bits select the clock source to be used by the Timer/Counter3 according to the following table. If external pin modes are used for the Timer/Counter3, transitions on the T3 pin will clock the counter even if the pin is configured as an output. This feature allows software control of the counting. Table 18-17 CS3 Register Bits Register Bits Value Description CS32:30 0x00 No clock source (Timer/Counter stopped) 0x01 clkIO/1 (no prescaling) 0x02 clkIO/8 (from prescaler) 0x03 clkIO/64 (from prescaler) 0x04 clkIO/256 (from prescaler) 0x05 clkIO/1024 (from prescaler) 0x06 External clock source on Tn pin, clock on falling edge 0x07 External clock source on Tn pin, clock on rising edge 18.11.18 TCCR3C – Timer/Counter3 Control Register C Bit 7 6 5 4 3 2 1 0 NA ($92) FOC3A FOC3B FOC3C Res4 Res3 Res2 Res1 Res0 TCCR3C Read/Write RW RW RW R R R R R Initial Value 0 0 0 0 0 0 0 0 • Bit 7 – FOC3A - Force O utput Compare for Channel A The FOC3A bit is only active when the WGM33:0 bits specify a non-PWM mode. When writing a logical one to the FOC3A bit, an immediate compare match is forced on the waveform generation unit. The OC3A output is changed according to its COM3A1:0 bits setting. Note that the FOC3A bits are implemented as strobes. Therefore it is the value present in the COM3A1:0 bits that determine the effect of the forced compare. A FOC3A strobe will not generate any interrupt nor will it clear the timer in Clear Timer on Compare Match (CTC) mode using OCR3A as TOP. The FOC3A bits are always read as zero. 311 8393C-MCU Wireless-09/14

• Bit 6 – FOC3B - Force Output Compare for Channel B The FOC3B bit is only active when the WGM33:0 bits specify a non-PWM mode. When writing a logical one to the FOC3B bit, an immediate compare match is forced on the waveform generation unit. The OC3B output is changed according to its COM3B1:0 bits setting. Note that the FOC3B bits are implemented as strobes. Therefore it is the value present in the COM3B1:0 bits that determine the effect of the forced compare. A FOC3B strobe will not generate any interrupt nor will it clear the timer in Clear Timer on Compare Match (CTC) mode using OCR1B as TOP. The FOC3B bits are always read as zero. • Bit 5 – FOC3C - Force Output Compare for Channel C The FOC3C bit is only active when the WGM33:0 bits specify a non-PWM mode. When writing a logical one to the FOC3C bit, an immediate compare match is forced on the waveform generation unit. The OC3C output is changed according to its COM3C1:0 bits setting. Note that the FOC3C bits are implemented as strobes. Therefore it is the value present in the COM3C1:0 bits that determine the effect of the forced compare. A FOC3C strobe will not generate any interrupt nor will it clear the timer in Clear Timer on Compare Match (CTC) mode using OCR3C as TOP. The FOC3C bits are always read as zero. • Bit 4:0 – Res4:0 - Reserved These bits are reserved for future use. 18.11.19 TCNT3H – Timer/Counter3 High Byte Bit 7 6 5 4 3 2 1 0 NA ($95) TCNT3H7:0 TCNT3H Read/Write RW RW RW RW RW RW RW RW Initial Value 0 0 0 0 0 0 0 0 The two Timer/Counter I/O locations (TCNT3H and TCNT3L, combined TCNT3) give direct access, both for read and for write operations, to the Timer/Counter unit 16-bit counter. To ensure that both the high and low bytes are read and written simultaneously when the CPU accesses these registers, the access is performed using an 8-bit temporary High Byte Register (TEMP). This temporary register is shared by all the other 16-bit registers. See section "Accessing 16-bit Registers" for details. Modifying the counter (TCNT3) while the counter is running introduces a risk of missing a compare match between TCNT3 and one of the OCR3x Registers. Writing to the TCNT3 Register blocks (removes) the compare match on the following timer clock for all compare units. • Bit 7:0 – TCNT3H7:0 - Timer/Counter3 High Byte 18.11.20 TCNT3L – Timer/Counter3 Low Byte Bit 7 6 5 4 3 2 1 0 NA ($94) TCNT3L7:0 TCNT3L Read/Write RW RW RW RW RW RW RW RW Initial Value 0 0 0 0 0 0 0 0 ATmega256/128/64RFR2 312 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 The two Timer/Counter I/O locations (TCNT3H and TCNT3L, combined TCNT3) give direct access, both for read and for write operations, to the Timer/Counter unit 16-bit counter. To ensure that both the high and low bytes are read and written simultaneously when the CPU accesses these registers, the access is performed using an 8-bit temporary High Byte Registe r (TEMP). This temporary register is shared by all the other 16-bit registers. See section "Accessing 16-bit Registers" for details. Modifying the counter (TCNT3) while the counter is running introduces a risk of missing a compare match between TCNT3 and one of the OCR3x Registers. Writing to the TCNT3 Register blocks (removes) the compare match on the following timer clock for all compare units. • Bit 7:0 – TCNT3L7:0 - Timer/Counter3 Low Byte 18.11.21 OCR3AH – Timer/Counter3 Output Compare Register A High Byte Bit 7 6 5 4 3 2 1 0 NA ($99) OCR3AH7:0 OCR3AH Read/Write RW RW RW RW RW RW RW RW Initial Value 0 0 0 0 0 0 0 0 The Output Compare Registers contain a 16-bit value that is continuously compared with the counter value (TCNT3). A match can be used to generate an Output Compare interrupt, or to generate a waveform output on the OC3A pin. The Output Compare Registers are 16-bit in size. To ensure that both the high and low bytes are written simultaneously when the CPU writes to these registers, the access is performed using an 8-bit temporary High Byte Register (TEMP). This temporary register is shared by all the other 16-bit registers. See section "Accessing 16-bit Registers" for details. • Bit 7:0 – OCR3AH7:0 - Timer/Counter3 Output Compare Register High Byte 18.11.22 OCR3AL – Timer/Counter3 Output Compare Register A Low Byte Bit 7 6 5 4 3 2 1 0 NA ($98) OCR3AL7:0 OCR3AL Read/Write RW RW RW RW RW RW RW RW Initial Value 0 0 0 0 0 0 0 0 The Output Compare Registers contain a 16-bit value that is continuously compared with the counter value (TCNT3). A match can be used to generate an Output Compare interrupt, or to generate a waveform output on the OC3A pin. The Output Compare Registers are 16-bit in size. To ensure that both the high and low bytes are written simultaneously when the CPU writes to these registers, the access is performed using an 8-bit temporary High Byt e Register (TEMP). This temporary register is shared by all the other 16-bit registers. See section "Accessing 16-bit Registers" for details. • Bit 7:0 – OCR3AL7:0 - Timer/Counter3 Output Compare Register Low Byte 313 8393C-MCU Wireless-09/14

18.11.23 OCR3BH – Timer/Counter3 Output Compare Register B High Byte Bit 7 6 5 4 3 2 1 0 NA ($9B) OCR3BH7:0 OCR3BH Read/Write RW RW RW RW RW RW RW RW Initial Value 0 0 0 0 0 0 0 0 The Output Compare Registers contain a 16-bit value that is continuously compared with the counter value (TCNT3). A match can be used to generate an Output Compare interrupt, or to generate a waveform output on the OC3B pin. The Output Compare Registers are 16-bit in size. To ensure that both the high and low bytes are written simultaneously when the C PU writes to these registers, the access is performed using an 8-bit temporary High Byte Register (TEMP). This temporary register is shared by all the other 16-bit registers. See section "Accessing 16-bit Registers" for details. • Bit 7:0 – OCR3BH7:0 - Timer/Counter3 Output Compare Register High Byte 18.11.24 OCR3BL – Timer/Counter3 Output Compare Register B Low Byte Bit 7 6 5 4 3 2 1 0 NA ($9A) OCR3BL7:0 OCR3BL Read/Write R RW RW RW RW RW RW RW Initial Value 0 0 0 0 0 0 0 0 The Output Compare Registers contain a 16-bit value that is continuously compared with the counter value (TCNT3). A match can be used to generate an Output Compare interrupt, or to generate a waveform output on the OC3B pin. The Output Compare Registers are 16-bit in size. To ensure that both the high and low bytes are written simultaneously when the CPU writes to these registers, the access is performed using an 8-bit temporary High By te Register (TEMP). This temporary register is shared by all the other 16-bit registers. See section "Accessing 16-bit Registers" for details. • Bit 7:0 – OCR3BL7:0 - Timer/Counter3 Output Compare Register Low Byte 18.11.25 OCR3CH – Timer/Counter3 Output Compare Register C High Byte Bit 7 6 5 4 3 2 1 0 NA ($9D) OCR3CH7:0 OCR3CH Read/Write RW RW RW RW RW RW RW RW Initial Value 0 0 0 0 0 0 0 0 The Output Compare Regi sters contain a 16-bit value that is continuously compared with the counter value (TCNT3). A match can be used to generate an Output Compare interrupt, or to generate a waveform output on the OC3C pin. The Output Compare Registers are 16-bit in size. To ensure that both the high and low bytes are written simultaneously when the CPU writes to these registers, the access is performed using an 8-bit temporary High Byte Register (TEMP). This temporary register is shared by all the other 16-bit registers. See section "Accessing 16-bit Registers" for details. • Bit 7:0 – OCR3CH7:0 - Timer/Counter3 Output Compare Register High Byte ATmega256/128/64RFR2 314 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 18.11.26 OCR3CL – Timer/Counter3 Output Compare Register C Low Byte Bit 7 6 5 4 3 2 1 0 NA ($9C) OCR3CL7:0 OCR3CL Read/Write R RW RW RW RW RW RW RW Initial Value 0 0 0 0 0 0 0 0 The Output Compare Registers contain a 16-bit value that is continuously compared with the counter value (TCNT3). A match can be used to generate an Output Compare interrupt, or to generate a waveform output on the OC3C pin. The Output Compare Registers are 16-bit in size. To ensure that both the high and low bytes are written simultaneously when the CPU writes to these registers, the access is performed using an 8-bit temporary High Byte Register (TEMP). This temporary register is shared by all the other 16-bit registers. See section "Accessing 16-bit Registers" for details. • Bit 7:0 – OCR3CL7:0 - Timer/Counter3 Output Compare Register Low Byte 18.11.27 ICR3H – Timer/Counter3 Input Capture Register High Byte Bit 7 6 5 4 3 2 1 0 NA ($97) ICR3H7:0 ICR3H Read/Write R R R R R R R R Initial Value 0 0 0 0 0 0 0 0 The Input Capture Register is updated with the counter (TCNT3) value each time an event occurs on the ICP3 pin. The Input Capture Register can be used for defining the counter TOP value. The Input Capture Register is 16-bit in size. To ensure that both the high and low bytes are read simultaneously when the CPU accesses these registers, the access is performed using an 8-bit temporary High Byte Register (TEMP). This temporary register is shared by all the other 16-bit registers. See section "Accessing 16- bit Registers" for details. • Bit 7:0 – ICR3H7:0 - Timer/Counter3 Input Capture Register High Byte 18.11.28 ICR3L – Timer/Counter3 Input Capture Register Low Byte Bit 7 6 5 4 3 2 1 0 NA ($96) ICR3L7:0 ICR3L Read/Write R R R R R R R R Initial Value 0 0 0 0 0 0 0 0 The Input Capture Register is updated with the counter (TCNT3) value each time an event occurs on the ICP3 pin. The Input Capture Register can be used for defining the counter TOP value. The Input Capture Register is 16-bit in size. To ensure that both the high and low bytes are read simultaneously when the CPU accesses these registers, the access is performed using an 8-bit temporary High Byte Register (TEMP). This temporary register is shared by all the other 16-bit registers. See section "Accessing 16- bit Registers" for details. • Bit 7:0 – ICR3L7:0 - Timer/Counter3 Input Capture Register Low Byte 315 8393C-MCU Wireless-09/14

18.11.29 TIMSK3 – Timer/Counter3 Interrupt Mask Register Bit 7 6 5 4 3 2 1 0 NA ($71) Res1 Res0 ICIE3 Res OCIE3C OCIE3B OCIE3A TOIE3 TIMSK3 Read/Write R R RW R R R RW RW Initial Value 0 0 0 0 0 0 0 0 • Bit 7:6 – Res1:0 - Reserved Bit This bit is reserved for future use. A read access always will return zero. A write access does not modify the content. • Bit 5 – ICIE3 - Timer/Counter3 Input Capture Interrupt Enable When this bit is written to one, and the I-flag in the Status Register is set (interrupts globally enabled), the Timer/Counter3 Input Capture interrupt is enabled. The corresponding Interrupt Vector is executed when the ICF3 Flag, located in TIFR3, is set. • Bit 4 – Res - Reserved Bit This bit is reserved for future use. A read access always will return zero. A write access does not modify the content. • Bit 3 – OCIE3C - Timer/Counter3 Output Compare C Match Interrupt Enable When this bit is written to one, and the I-flag in the Status Register is set (interrupts globally enabled), the Timer/Counter3 Output Compare C Match interrupt is enabled. The corresponding Interrupt Vector is executed when the OCF3C Flag, located in TIFR3, is set. • Bit 2 – OCIE3B - Timer/Counter3 Output Compare B Match Interrupt Enable When this bit is written to one, and the I-flag in the Status Register is set (interrupts globally enabled), the Timer/Counter3 Output Compare B Match interrupt is enabled. The corresponding Interrupt Vector is executed when the OCF3B Flag, located in TIFR3, is set. • Bit 1 – OCIE3A - Timer/Counter3 Output Compare A Match Interrupt Enable When this bit is written to one, and the I-flag in the Status Register is set (interrupts globally enabled), the Timer/Counter3 Output Compare A Match interrupt is enabled. The corresponding Interrupt Vector is executed when the OCF3A Flag, located in TIFR3, is set. • Bit 0 – TOIE3 - Timer/Counter3 Overflow Interrupt Enable When this bit is written to one, and the I-flag in the Status Register is set (interrupts globally enabled), the Timer/Counter3 Overflow interrupt is enabled. The corresponding Interrupt Vector is executed when the TOV3 Flag, located in TIFR3, is set. 18.11.30 TIFR3 – Timer/Counter3 Interrupt Flag Register Bit 7 6 5 4 3 2 1 0 $18 ($38) Res1 Res0 ICF3 Res OCF3C OCF3B OCF3A TOV3 TIFR3 Read/Write R R RW R RW RW RW RW Initial Value 0 0 0 0 0 0 0 0 • Bit 7:6 – Res1:0 - Reserved Bit ATmega256/128/64RFR2 316 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 This bit is reserved for future use. A read access always will return zero. A write access does not modify the content. • Bit 5 – ICF3 - Timer/Counter3 Input Capture Flag This flag is set when a capt ure event occurs on the ICP3 pin. When the Input Capture Register (ICR3) is set by the WGM33:0 to be used as the TOP value, the ICF3 Flag is set when the counter reaches the TOP value. ICF3 is automatically cleared when the Input Capture Interrupt Vector is executed. Alternatively, ICF3 can be cleared by writing a logic one to its bit location. • Bit 4 – Res - Reserved Bit This bit is reserved for future use. A read access always will return zero. A write access does not modify the content. • Bit 3 – OCF3C - Timer/Counter3 Output Compare C Match Flag This flag is set in the timer clock cycle after the counter (TCNT3) value matches the Output Compare Register C (OCR3C). Note that a Forced Output Compare (FOC3C) strobe will not set the OCF3C Flag. OCF3C is automatically cleared when the Output Compare Match C Interrupt Vector is executed. Alternatively, OCF3C can be cleared by writing a logic one to its bit location. • Bit 2 – OCF3B - Timer/Counter3 Output Compare B Match Flag This flag is set in the timer clock cycle after the counter (TCNT3) value matches the Output Compare Register B (OCR3B). Note that a Forced Output Compare (FOC3B) strobe will not set the OCF3B Flag. OCF3B is automatically cleared when the Output Compare Match B Interrupt Vector is executed. Alternatively, OCF3B can be cleared by writing a logic one to its bit location. • Bit 1 – OCF3A - Timer/Counter3 Output Compare A Match Flag This flag is set in the timer clock cycle after the counter (TCNT3) value matches the Output Compare Register A (OCR3A). Note that a Forced Output Compare (FOC3A) strobe will not set the OCF3A Flag. OCF3A is automatically cleared when the Output Compare Match A Interrupt Vector is executed. Alternatively, OCF3A can be cleared by writing a logic one to its bit location. • Bit 0 – TOV3 - Timer/Counter3 Overflow Flag The setting of this flag is dependent of the WGM33:0 bits setting of the Timer/Counter3 Control Register. In Normal and CTC modes, the TOV3 Flag is set when the timer overflows. TOV3 is automatically cleared when the Timer/Counter3 Overflow Interrupt Vector is executed. Alternatively, TOV3 can be cleared by writing a logic one to its bit location. 18.11.31 TCCR4A – Timer/Counter4 Control Register A Bit 7 6 5 4 3 2 1 0 NA ($A0) COM4A1 COM4A0 COM4B1 COM4B0 COM4C1 COM4C0 WGM41 WGM40 TCCR4A Read/Write RW RW RW RW RW RW RW RW Initial Value 0 0 0 0 0 0 0 0 • Bit 7:6 – COM4A1:0 - Compare Output Mode for Channel A The Timer/Counter4 has only limited functionality. Therefore the COM4A1:0 bits do not control the output compare behavior of any pin. The following table shows the 317 8393C-MCU Wireless-09/14

COM4A1:0 bit functionality when the WGM43:0 bits are set to a normal or a CTC mode (non-PWM). For the other functionality refer to section "Modes of Operation". Table 18-18 COM4A Register Bits Register Bits Value Description COM4A1:0 0 Normal operation 1 Reserved 2 Reserved 3 Reserved • Bit 5:4 – COM4B1:0 - Compare Output Mode for Channel B The Timer/Counter4 has only limited functionality. Therefore the COM4B1:0 bits do not control the output compare behavior of any pin. The following table shows the COM4B1:0 bit functionality when the WGM43:0 bits are set to a normal or a CTC mode (non-PWM). For the other functionality refer to section "Modes of Operation". Table 18-19 COM4B Register Bits Register Bits Value Description COM4B1:0 0 Normal operation 1 Reserved 2 Reserved 3 Reserved • Bit 3:2 – COM4C1:0 - Compare Output Mode for Channel C The Timer/Counter4 has only limited functionality. Therefore the COM4C1:0 bits do not control the output compare behavior of any pin. The following table shows the COM4C1:0 bit functionality when the WGM43:0 bits are set to a normal or a CTC mode (non-PWM). For the other functionality refer to section "Modes of Operation". Table 18-20 COM4C Register Bits Register Bits Value Description COM4C1:0 0 Normal operation 1 Reserved 2 Reserved 3 Reserved • Bit 1:0 – WGM41:40 - Waveform Generation Mode Combined with the WGM43:42 bits, found in the TCCR4B Register, these bits control the counting sequence of t he counter, the source for maximum (TOP) counter value and what type of waveform generation to be used. Modes of operation supported by the Timer/Counter unit are: Normal mode (counter), Clear Timer on Compare match (CTC) mode, and three types of Pulse Width Modulation (PWM) modes. For more information on the different modes see section "Modes of Operation". Note that Timer/Counter4 has only limited functionality. It c annot be connected to any I/O pin. Table 18-21 WGM4 Register Bits Register Bits Value Description WGM43:40 0x0 Normal mode of operation 0x1 PWM, phase correct, 8-bit 0x2 PWM, phase correct, 9-bit 0x3 PWM, phase correct, 10-bit 0x4 CTC, TOP = OCRnA ATmega256/128/64RFR2 318 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 Register Bits Value Description 0x5 Fast PWM, 8-bit 0x6 Fast PWM, 9-bit 0x7 Fast PWM, 10-bit 0x8 PWM, Phase and frequency correct, TOP = ICRn 0x9 PWM, Phase and frequency correct, TOP = OCRnA 0xA PWM, Phase correct, TOP = ICRn 0xB PWM, Phase correct, TOP = OCRnA 0xC CTC, TOP = OCRnA 0xD Reserved 0xE Fast PWM, TOP = ICRn 0xF Fast PWM, TOP = OCRnA 18.11.32 TCCR4B – Timer/Counter4 Control Register B Bit 7 6 5 4 3 2 1 0 NA ($A1) ICNC4 ICES4 Res WGM43 WGM42 CS42 CS41 CS40 TCCR4B Read/Write RW RW R RW RW RW RW RW Initial Value 0 0 0 0 0 0 0 0 • Bit 7 – ICNC4 - Input Capture 4 Noise Canceller Timer/Counter4 has only limited functionality. It is not connected to any Input Capture Pin. Therefore this bit has no meaningful function. • Bit 6 – ICES4 - Input Capture 4 Edge Select Timer/Counter4 has only limited functionality. It is not connected to any Input Capture Pin. Therefore this bit has no meaningful function. • Bit 5 – Res - Reserved Bit This bit is reserved for future use. A read access always will return zero. A write access does not modify the content. • Bit 4:3 – WGM43:42 - Waveform Generation Mode Combined with the WGM41 :40 bits, found in the TCCR4A Register, these bits control the counting sequence of the counter, the source for maximum (TOP) counter value and what type of waveform generation to be used. Modes of operation supported by the Timer/Counter unit are: Normal mode (counter), Clear Timer on Compare match (CTC) mode, and three types of Pulse Width Modulation (PWM) modes. For more information on the different modes see section "Modes of Operation". Note that Timer/Counter4 has only limited functionality. It cannot be connected to any I/O pin. Table 18-22 WGM4 Register Bits Register Bits Value Description WGM43:40 0x0 Normal mode of operation 0x1 PWM, phase correct, 8-bit 0x2 PWM, phase correct, 9-bit 0x3 PWM, phase correct, 10-bit 319 8393C-MCU Wireless-09/14

Register Bits Value Description 0x4 CTC, TOP = OCRnA 0x5 Fast PWM, 8-bit 0x6 Fast PWM, 9-bit 0x7 Fast PWM, 10-bit 0x8 PWM, Phase and frequency correct, TOP = ICRn 0x9 PWM, Phase and frequency correct, TOP = OCRnA 0xA PWM, Phase correct, TOP = ICRn 0xB PWM, Phase correct, TOP = OCRnA 0xC CTC, TOP = OCRnA 0xD Reserved 0xE Fast PWM, TOP = ICRn 0xF Fast PWM, TOP = OCRnA • Bit 2:0 – CS42:40 - Clock Select The three clock select bits select the clock source to be used by the Timer/Counter4 according to the following table. External pin modes cannot be used for the Timer/Counter4. Table 18-23 CS4 Register Bits Register Bits Value Description CS42:40 0x00 No clock source (Timer/Counter stopped) 0x01 clkIO/1 (no prescaling) 0x02 clkIO/8 (from prescaler) 0x03 clkIO/64 (from prescaler) 0x04 clkIO/256 (from prescaler) 0x05 clkIO/1024 (from prescaler) 0x06 Reserved 0x07 Reserved 18.11.33 TCCR4C – Timer/Counter4 Control Register C Bit 7 6 5 4 3 2 1 0 NA ($A2) FOC4A FOC4B FOC4C Res4 Res3 Res2 Res1 Res0 TCCR4C Read/Write RW RW RW R R R R R Initial Value 0 0 0 0 0 0 0 0 • Bit 7 – FOC4A - Force Output Compare for Channel A The FOC4A bit is only active when the WGM43:0 bits specify a non-PWM mode. When writing a logical one to the FOC4A bit, an immediate compare match is forced. Due to the limited functionality of the Timer/Counter4 the match has no direct impact on any output pin. Note that the FOC4A bits are implemented as strobes. Therefore it is the value present in the COM4A1:0 bits that determine the effect of the forced compare. A FOC4A strobe will not generate any interrupt nor will it clear the timer in Clear Timer on ATmega256/128/64RFR2 320 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 Compare Match (CTC) mode using OCR4A as TOP. The FOC4A bits are always read as zero. • Bit 6 – FOC4B - Force Output Compare for Channel B The FOC4B bit is only active when the WGM43:0 bits specify a non-PWM mode. When writing a logical one to the FOC4B bit, an immediate compare match is forced. Due to the limited functionality of the Timer/Counter4 the match has no direct impact on any output pin. Note that the FOC4B bits are implemented as strobes. Therefore it is the value present in the COM4B1:0 bits that determine the effect of the forced compare. A FOC4B strobe will not generate any interrupt nor will it clear the timer in Clear Timer on Compare Match (CTC) mode using OCR4B as TOP. The FOC4B bits are always read as zero. • Bit 5 – FOC4C - Force O utput Compare for Channel C The FOC4C bit is only active when the WGM43:0 bits specify a non-PWM mode. When writing a logical one to the FOC4C bit, an immediate compare match is forced. Due to the limited functionality of the Timer/Counter4 the match has no direct impact on any output pin. Note that the FOC4C bits are implemented as strobes. Therefore it is the value present in the COM4C 1:0 bits that determine the effect of the forced compare. A FOC4C strobe will not generate any interrupt nor will it clear the timer in Clear Timer on Compare Match (CTC) mode using OCR4C as TOP. The FOC4C bits are always read as zero. • Bit 4:0 – Res4:0 - Reserved These bits are reserved for future use. 18.11.34 TCNT4H – Timer/Counter4 High Byte Bit 7 6 5 4 3 2 1 0 NA ($A5) TCNT4H7:0 TCNT4H Read/Write RW RW RW RW RW RW RW RW Initial Value 0 0 0 0 0 0 0 0 The two Timer/Counter I/O locations (TCNT4H and TCNT4L, combined TCNT4) give direct access, both for read and for write operations, to the Timer/Counter unit 16-bit counter. To ensure that both the high and low bytes are read and written simultaneously when the CPU accesses these registers, the access is performed using an 8-bit temporary High Byte Register (TEMP). This temporary register is shared by all the other 16-bit registers. See sectio n "Accessing 16-bit Registers" for details. Modifying the counter (TCNT4) while the counter is running introduces a risk of missing a compare match between TCNT4 and one of the OCR4x Registers. Writing to the TCNT4 Register blocks (removes) the compare match on the following timer clock for all compare units. • Bit 7:0 – TCNT4H7:0 - T imer/Counter4 High Byte 18.11.35 TCNT4L – Timer/Counter4 Low Byte Bit 7 6 5 4 3 2 1 0 NA ($A4) TCNT4L7:0 TCNT4L Read/Write RW RW RW RW RW RW RW RW Initial Value 0 0 0 0 0 0 0 0 321 8393C-MCU Wireless-09/14

The two Timer/Counter I/O locations (TCNT4H and TCNT4L, combined TCNT4) give direct access, both for read and for write operations, to the Timer/Counter unit 16-bit counter. To ensure that both the high and low bytes are read and written simultaneously when the CPU accesses these registers, the access is performed using an 8-bit temporary High Byte Register (TEMP). This temporary register is shared by all the other 16-bit registers. See section "Accessing 16-bit Registers" for details. Modifying the counter (TCNT4) while the counter is running introduces a risk of missing a compare match between TCNT4 and one of the OCR4x Registers. Writing to the TCNT4 Register blocks (removes) the compare match on the following timer clock for all compare units. • Bit 7:0 – TCNT4L7:0 - T imer/Counter4 Low Byte 18.11.36 OCR4AH – Timer/Counter4 Output Compare Register A High Byte Bit 7 6 5 4 3 2 1 0 NA ($A9) OCR4AH7:0 OCR4AH Read/Write RW RW RW RW RW RW RW RW Initial Value 0 0 0 0 0 0 0 0 The Output Compare Registers contain a 16-bit value that is continuously compared with the counter value (TCNT4). A match can be used to generate an Output Compare interrupt. The Output Compare Registers are 16-bit in size. To ensure that both the high and low bytes are written simultaneously when the CPU writes to these registers, the access is performed using an 8-bit temporary High Byte Register (TEMP). This temporary register is shared by all the other 16-bit registers. See section "Accessing 16- bit Registers" for details. • Bit 7:0 – OCR4AH7:0 - Timer/Counter4 Output Compare Register High Byte 18.11.37 OCR4AL – Timer/Counter4 Output Compare Register A Low Byte Bit 7 6 5 4 3 2 1 0 NA ($A8) OCR4AL7:0 OCR4AL Read/Write RW RW RW RW RW RW RW RW Initial Value 0 0 0 0 0 0 0 0 The Output Compare Registers contain a 16-bit value that is continuously compared with the counter value (TCNT4). A match can be used to generate an Output Compare interrupt. The Output Compare Registers are 16-bit in size. To ensure that both the high and low bytes are written simultaneously when the CPU writes to these registers, the access is performed using an 8-bit temporary High Byte Register (TEMP). This temporary register is shared by all the other 16-bit registers. See section "Accessing 16- bit Registers" for details. • Bit 7:0 – OCR4AL7:0 - Timer/Counter4 Output Compare Register Low Byte ATmega256/128/64RFR2 322 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 18.11.38 OCR4BH – Timer/Counter4 Output Compare Register B High Byte Bit 7 6 5 4 3 2 1 0 NA ($AB) OCR4BH7:0 OCR4BH Read/Write RW RW RW RW RW RW RW RW Initial Value 0 0 0 0 0 0 0 0 The Output Compare Registers contain a 16-bit value that is continuously compared with the counter value (TCNT4). A match can be used to generate an Output Compare interrupt. The Output Compare Registers are 16-bit in size. To ensure that both the high and low bytes are written simultaneously when the CPU writes to these registers, the access is performed using an 8-bit temporary High Byte Register (TEMP). This temporary register is shared by all the other 16-bit registers. See section "Accessing 16- bit Registers" for details. • Bit 7:0 – OCR4BH7:0 - Timer/Counter4 Output Compare Register High Byte 18.11.39 OCR4BL – Timer/Counter4 Output Compare Register B Low Byte Bit 7 6 5 4 3 2 1 0 NA ($AA) OCR4BL7:0 OCR4BL Read/Write R RW RW RW RW RW RW RW Initial Value 0 0 0 0 0 0 0 0 The Output Compare Registers contain a 16-bit value that is continuously compared with the counter value (TCNT4). A match can be used to generate an Output Compare interrupt. The Output Compare Registers are 16-bit in size. To ensure that both the high and low bytes are written simultaneously when the CPU writes to these registers, the access is performed using an 8-bit temporary High Byte Register (TEMP). This temporary register is shared by all the other 16-bit registers. See section "Accessing 16- bit Registers" for details. • Bit 7:0 – OCR4BL7:0 - Timer/Counter4 Output Compare Register Low Byte 18.11.40 OCR4CH – Timer/Counter4 Output Compare Register C High Byte Bit 7 6 5 4 3 2 1 0 NA ($AD) OCR4CH7:0 OCR4CH Read/Write RW RW RW RW RW RW RW RW Initial Value 0 0 0 0 0 0 0 0 The Output Compare Registers contain a 16-bit value that is continuously compared with the counter value (TCNT4). A match can be used to generate an Output Compare interrupt. The Output Compare Registers are 16-bit in size. To ensure that both the high and low bytes are written simultaneously when the CPU writes to these registers, the access is performed using an 8-bit temporary High Byte Register (TEMP). This temporary register is shared by all the other 16-bit registers. See section "Accessing 16- bit Registers" for details. • Bit 7:0 – OCR4CH7:0 - Timer/Counter4 Output Compare Register High Byte 323 8393C-MCU Wireless-09/14

18.11.41 OCR4CL – Timer/Counter4 Output Compare Register C Low Byte Bit 7 6 5 4 3 2 1 0 NA ($AC) OCR4CL7:0 OCR4CL Read/Write R RW RW RW RW RW RW RW Initial Value 0 0 0 0 0 0 0 0 The Output Compare Registers contain a 16-bit value that is continuously compared with the counter value (TCNT4). A match can be used to generate an Output Compare interrupt. The Output Compare Registers are 16-bit in size. To ensure that both the high and low bytes are written simultaneously when the CPU writes to these registers, the access is performed usin g an 8-bit temporary High Byte Register (TEMP). This temporary register is shared by all the other 16-bit registers. See section "Accessing 16- bit Registers" for details. • Bit 7:0 – OCR4CL7:0 - Timer/Counter4 Output Compare Register Low Byte 18.11.42 ICR4H – Timer/Counter4 Input Capture Register High Byte Bit 7 6 5 4 3 2 1 0 NA ($A7) ICR4H7:0 ICR4H Read/Write R R R R R R R R Initial Value 0 0 0 0 0 0 0 0 The Timer/Counter4 has only limited functionality. It is not connected to any I/O pin. Therefore the contents of this register is never updated with the counter (TCNT4) value. The Input Capture Register is 16-bit in size. To ensure that both the high and low bytes are read simultaneously when the CPU accesses these registers, the access is performed using an 8-bit temporary High Byte Register (TEMP). This temporary register is shared by all the other 1 6-bit registers. See section "Accessing 16-bit Registers" for details. • Bit 7:0 – ICR4H7:0 - Timer/Counter4 Input Capture Register High Byte 18.11.43 ICR4L – Timer/Counter4 Input Capture Register Low Byte Bit 7 6 5 4 3 2 1 0 NA ($A6) ICR4L7:0 ICR4L Read/Write R R R R R R R R Initial Value 0 0 0 0 0 0 0 0 The Timer/Counter4 has o nly limited functionality. It is not connected to any I/O pin. Therefore the contents of this register is never updated with the counter (TCNT4) value. The Input Capture Register is 16-bit in size. To ensure that both the high and low bytes are read simultaneously when the CPU accesses these registers, the access is performed using an 8-bit temporary High Byte Register (TEMP). This temporary register is shared by all the other 16-bit registers. See section "Accessing 16-bit Registers" for details. • Bit 7:0 – ICR4L7:0 - Timer/Counter4 Input Capture Register Low Byte ATmega256/128/64RFR2 324 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 18.11.44 TIMSK4 – Timer/Counter4 Interrupt Mask Register Bit 7 6 5 4 3 2 1 0 NA ($72) Res1 Res0 ICIE4 Res OCIE4C OCIE4B OCIE4A TOIE4 TIMSK4 Read/Write R R RW R R R RW RW Initial Value 0 0 0 0 0 0 0 0 • Bit 7:6 – Res1:0 - Reserved Bit This bit is reserved for future use. A read access always will return zero. A write access does not modify the content. • Bit 5 – ICIE4 - Timer/Counter4 Input Capture Interrupt Enable The Timer/Counter4 has only limited functionality. It does not have an Input Capture pin. Therefore this bit has no useful meaning. • Bit 4 – Res - Reserved Bit This bit is reserved for future use. A read access always will return zero. A write access does not modify the content. • Bit 3 – OCIE4C - Timer/Counter4 Output Compare C Match Interrupt Enable When this bit is written to one, and the I-flag in the Status Register is set (interrupts globally enabled), the Timer/Counter4 Output Compare C Match interrupt is enabled. The corresponding Interrupt Vector is executed when the OCF4C Flag, located in TIFR4, is set. • Bit 2 – OCIE4B - Timer/Counter4 Output Compare B Match Interrupt Enable When this bit is written to o ne, and the I-flag in the Status Register is set (interrupts globally enabled), the Timer/Counter4 Output Compare B Match interrupt is enabled. The corresponding Interrupt Vector is executed when the OCF4B Flag, located in TIFR4, is set. • Bit 1 – OCIE4A - Timer/Counter4 Output Compare A Match Interrupt Enable When this bit is written to one, and the I-flag in the Status Register is set (interrupts globally enabled), the Timer/Counter4 Output Compare A Match interrupt is enabled. The corresponding Interrupt Vector is executed when the OCF4A Flag, located in TIFR4, is set. • Bit 0 – TOIE4 - Timer/Counter4 Overflow Interrupt Enable When this bit is written to one, and the I-flag in the Status Register is set (interrupts globally enabled), the Timer/Counter4 Overflow interrupt is enabled. The corresponding Interrupt Vector is executed when the TOV4 Flag, located in TIFR4, is set. 18.11.45 TIFR4 – Timer/Counter4 Interrupt Flag Register Bit 7 6 5 4 3 2 1 0 $19 ($39) Res1 Res0 ICF4 Res OCF4C OCF4B OCF4A TOV4 TIFR4 Read/Write R R RW R RW RW RW RW Initial Value 0 0 0 0 0 0 0 0 • Bit 7:6 – Res1:0 - Reserved Bit This bit is reserved for future use. A read access always will return zero. A write access does not modify the content. 325 8393C-MCU Wireless-09/14

• Bit 5 – ICF4 - Timer/Counter4 Input Capture Flag The Timer/Counter4 has only limited functionality. It does not have an Input Capture pin. Therefore this bit has no useful meaning. • Bit 4 – Res - Reserved Bit This bit is reserved for future use. A read access always will return zero. A write access does not modify the content. • Bit 3 – OCF4C - Timer/Counter4 Output Compare C Match Flag This flag is set in the timer clock cycle after the counter (TCNT4) value matches the Output Compare Register C (OCR4C). Note that a Forced Output Compare (FOC4C) strobe will not set the OCF4C Flag. OCF4C is automatically cleared when the Output Compare Match C Interrupt Vector is executed. Alternatively, OCF4C can be cleared by writing a logic one to its bit location. • Bit 2 – OCF4B - Timer/Counter4 Output Compare B Match Flag This flag is set in the timer clock cycle after the counter (TCNT4) value matches the Output Compare Register B (OCR4B). Note that a Forced Output Compare (FOC4B) strobe will not set the OCF 4B Flag. OCF4B is automatically cleared when the Output Compare Match B Interrupt Vector is executed. Alternatively, OCF4B can be cleared by writing a logic one to its bit location. • Bit 1 – OCF4A - Timer/Counter4 Output Compare A Match Flag This flag is set in the timer clock cycle after the counter (TCNT4) value matches the Output Compare Register A (OCR4A). Note that a Forced Output Compare (FOC4A) strobe will not set the OCF4A Flag. OCF4A is automatically cleared when the Output Compare Match A Interrupt Vector is executed. Alternatively, OCF4A can be cleared by writing a logic one to its bit location. • Bit 0 – TOV4 - Timer/Counter4 Overflow Flag The setting of this flag is dependent of the WGM43:0 bits setting of the Timer/Counter4 Control Register. In Normal and CTC modes, the TOV4 Flag is set when the timer overflows. TOV4 is automa tically cleared when the Timer/Counter4 Overflow Interrupt Vector is executed. Alternatively, TOV4 can be cleared by writing a logic one to its bit location. 18.11.46 TCCR5A – Timer/Counter5 Control Register A Bit 7 6 5 4 3 2 1 0 NA ($120) COM5A1 COM5A0 COM5B1 COM5B0 COM5C1 COM5C0 WGM51 WGM50 TCCR5A Read/Write RW RW RW RW RW RW RW RW Initial Value 0 0 0 0 0 0 0 0 • Bit 7:6 – COM5A1:0 - Compare Output Mode for Channel A The Timer/Counter5 has only limited functionality. Therefore the COM5A1:0 bits do not control the output compare behavior of any pin. The following table shows the COM5A1:0 bit functionality when the WGM53:0 bits are set to a normal or a CTC mode (non-PWM). For the other functionality refer to section "Modes of Operation". Table 18-24 COM5A Register Bits Register Bits Value Description COM5A1:0 0 Normal operation ATmega256/128/64RFR2 326 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 Register Bits Value Description 1 Reserved 2 Reserved 3 Reserved • Bit 5:4 – COM5B1:0 - Compare Output Mode for Channel B The Timer/Counter5 has only limited functionality. Therefore the COM5B1:0 bits do not control the output compare behavior of any pin. The following table shows the COM5B1:0 bit functionality when the WGM53:0 bits are set to a normal or a CTC mode (non-PWM). For the other functionality refer to section "Modes of Operation". Table 18-25 COM5B Register Bits Register Bits Value Description COM5B1:0 0 Normal operation 1 Reserved 2 Reserved 3 Reserved • Bit 3:2 – COM5C1:0 - Compare Output Mode for Channel C The Timer/Counter5 has only limited functionality. Therefore the COM5C1:0 bits do not control the output compare behavior of any pin. The following table shows the COM5C1:0 bit functionality when the WGM53:0 bits are set to a normal or a CTC mode (non-PWM). For the other functionality refer to section "Modes of Operation". Table 18-26 COM5C Register Bits Register Bits Value Description COM5C1:0 0 Normal operation 1 Reserved 2 Reserved 3 Reserved • Bit 1:0 – WGM51:50 - Waveform Generation Mode Combined with the WGM53:52 bits, found in the TCCR5B Register, these bits control the counting sequence of the counter, the source for maximum (TOP) counter value and what type of waveform generation to be used. Modes of operation supported by the Timer/Counter unit are: Normal mode (counter), Clear Timer on Compare match (CTC) mode, and three types of Pulse Width Modulation (PWM) modes. For more information on the different modes see section "Modes of Operation". Note that Timer/Counter5 has only limited functionality. It cannot be connected to any I/O pin. Table 18-27 WGM5 Register Bits Register Bits Value Description WGM53:50 0x0 Normal mode of operation 0x1 PWM, phase correct, 8-bit 0x2 PWM, phase correct, 9-bit 0x3 PWM, phase correct, 10-bit 0x4 CTC, TOP = OCRnA 0x5 Fast PWM, 8-bit 0x6 Fast PWM, 9-bit 0x7 Fast PWM, 10-bit 327 8393C-MCU Wireless-09/14

Register Bits Value Description 0x8 PWM, Phase and frequency correct, TOP = ICRn 0x9 PWM, Phase and frequency correct, TOP = OCRnA 0xA PWM, Phase correct, TOP = ICRn 0xB PWM, Phase correct, TOP = OCRnA 0xC CTC, TOP = OCRnA 0xD Reserved 0xE Fast PWM, TOP = ICRn 0xF Fast PWM, TOP = OCRnA 18.11.47 TCCR5B – Timer/Counter5 Control Register B Bit 7 6 5 4 3 2 1 0 NA ($121) ICNC5 ICES5 Res WGM53 WGM52 CS52 CS51 CS50 TCCR5B Read/Write RW RW R RW RW RW RW RW Initial Value 0 0 0 0 0 0 0 0 • Bit 7 – ICNC5 - Input Capture 5 Noise Canceller Timer/Counter5 has only limited functionality. It is not connected to any Input Capture Pin. Therefore this bit has n o meaningful function. • Bit 6 – ICES5 - Input Capture 5 Edge Select Timer/Counter5 has only limited functionality. It is not connected to any Input Capture Pin. Therefore this bit has no meaningful function. • Bit 5 – Res - Reserved Bit This bit is reserved for future use. A read access always will return zero. A write access does not modify the content. • Bit 4:3 – WGM53:52 - Waveform Generation Mode Combined with the WGM51:50 bits, found in the TCCR5A Register, these bits control the counting sequence of the counter, the source for maximum (TOP) counter value and what type of waveform generation to be used. Modes of operation supported by the Timer/Counter unit are: Normal mode (counter), Clear Timer on Compare match (CTC) mode, and three types of P ulse Width Modulation (PWM) modes. For more information on the different modes see section "Modes of Operation". Note that Timer/Counter5 has only limited functionality. It cannot be connected to any I/O pin. Table 18-28 WGM5 Register Bits Register Bits Value Description WGM53:50 0x0 Normal mode of operation 0x1 PWM, phase correct, 8-bit 0x2 PWM, phase correct, 9-bit 0x3 PWM, phase correct, 10-bit 0x4 CTC, TOP = OCRnA 0x5 Fast PWM, 8-bit 0x6 Fast PWM, 9-bit ATmega256/128/64RFR2 328 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 Register Bits Value Description 0x7 Fast PWM, 10-bit 0x8 PWM, Phase and frequency correct, TOP = ICRn 0x9 PWM, Phase and frequency correct, TOP = OCRnA 0xA PWM, Phase correct, TOP = ICRn 0xB PWM, Phase correct, TOP = OCRnA 0xC CTC, TOP = OCRnA 0xD Reserved 0xE Fast PWM, TOP = ICRn 0xF Fast PWM, TOP = OCRnA • Bit 2:0 – CS52:50 - Clock Select The three clock select bits select the clock source to be used by the Timer/Counter5 according to the following table. External pin modes cannot be used for the Timer/Counter5. Table 18-29 CS5 Register Bits Register Bits Value Description CS52:50 0x00 No clock source (Timer/Counter stopped) 0x01 clkIO/1 (no prescaling) 0x02 clkIO/8 (from prescaler) 0x03 clkIO/64 (from prescaler) 0x04 clkIO/256 (from prescaler) 0x05 clkIO/1024 (from prescaler) 0x06 Reserved 0x07 Reserved 18.11.48 TCCR5C – Timer/Counter5 Control Register C Bit 7 6 5 4 3 2 1 0 NA ($122) FOC5A FOC5B FOC5C Res4 Res3 Res2 Res1 Res0 TCCR5C Read/Write RW RW RW R R R R R Initial Value 0 0 0 0 0 0 0 0 • Bit 7 – FOC5A - Force Output Compare for Channel A The FOC5A bit is only active when the WGM53:0 bits specify a non-PWM mode. When writing a logical one to the FOC5A bit, an immediate compare match is forced. Due to the limited functionality of the Timer/Counter5 the match has no direct impact on any output pin. Note that the FOC5A bits are implemented as strobes. Therefore it is the value present in the COM5A1:0 bits that determine the effect of the forced compare. A FOC5A strobe will not generate any interrupt nor will it clear the timer in Clear Timer on Compare Match (CTC) mode using OCR5A as TOP. The FOC5A bits are always read as zero. • Bit 6 – FOC5B - Force Output Compare for Channel B 329 8393C-MCU Wireless-09/14

The FOC5B bit is only active when the WGM53:0 bits specify a non-PWM mode. When writing a logical one to the FOC5B bit, an immediate compare match is forced. Due to the limited functionality of the Timer/Counter5 the match has no direct impact on any output pin. Note that the FOC5B bits are implemented as strobes. Therefore it is the value present in the COM5B1:0 bits that determine the effect of the forced compare. A FOC5B strobe will not generate any interrupt nor will it clear the timer in Clear Timer on Compare Match (CTC) mode using OCR5B as TOP. The FOC5B bits are always read as zero. • Bit 5 – FOC5C - Force Output Compare for Channel C The FOC5C bit is only active when the WGM53:0 bits specify a non-PWM mode. When writing a logical one to the FOC5C bit, an immediate compare match is forced. Due to the limited functionality of t he Timer/Counter5 the match has no direct impact on any output pin. Note that the FOC5C bits are implemented as strobes. Therefore it is the value present in the COM5C1:0 bits that determine the effect of the forced compare. A FOC5C strobe will not generate any interrupt nor will it clear the timer in Clear Timer on Compare Match (CTC) mode using OCR5C as TOP. The FOC5C bits are always read as zero. • Bit 4:0 – Res4:0 - Reserved These bits are reserved for future use. 18.11.49 TCNT5H – Timer/Counter5 High Byte Bit 7 6 5 4 3 2 1 0 NA ($125) TCNT5H7:0 TCNT5H Read/Write RW RW RW RW RW RW RW RW Initial Value 0 0 0 0 0 0 0 0 The two Timer/Counter I/O locations (TCNT5H and TCNT5L, combined TCNT5) give direct access, both for read and for write operations, to the Timer/Counter unit 16-bit counter. To ensure that both the high and low bytes are read and written simultaneously when the CPU accesses these registers, the access is performed using an 8-bit temporary High Byte Register (TEMP). This temporary register is shared by all the other 16-bit registers. See section "Accessing 16-bit Registers" for details. Modifying the counter (TCNT5) while the counter is running introduces a risk of missing a compare match between TCNT5 and one of the OCR5x Registers. Writing to the TCNT5 Register blocks (removes) the compare match on the following timer clock for all compare units. • Bit 7:0 – TCNT5H7:0 - Timer/Counter5 High Byte 18.11.50 TCNT5L – Timer/Counter5 Low Byte Bit 7 6 5 4 3 2 1 0 NA ($124) TCNT5L7:0 TCNT5L Read/Write RW RW RW RW RW RW RW RW Initial Value 0 0 0 0 0 0 0 0 The two Timer/Counter I/O locations (TCNT5H and TCNT5L, combined TCNT5) give direct access, both for read and for write operations, to the Timer/Counter unit 16-bit ATmega256/128/64RFR2 330 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 counter. To ensure that both the high and low bytes are read and written simultaneously when the CPU accesses these registers, the access is performed using an 8-bit temporary High Byte Register (TEMP). This temporary register is shared by all the other 16-bit registers. See section "Accessing 16-bit Registers" for details. Modifying the counter (TCNT5) while the counter is running introduces a risk of missing a compare match between TCNT5 and one of the OCR5x Registers. Writing to the TCNT5 Register blocks (removes) the compare match on the following timer clock for all compare units. • Bit 7:0 – TCNT5L7:0 - Timer/Counter5 Low Byte 18.11.51 OCR5AH – Timer/Counter5 Output Compare Register A High Byte Bit 7 6 5 4 3 2 1 0 NA ($129) OCR5AH7:0 OCR5AH Read/Write RW RW RW RW RW RW RW RW Initial Value 0 0 0 0 0 0 0 0 The Output Compare Registers contain a 16-bit value that is continuously compared with the counter value (TCNT5). A match can be used to generate an Output Compare interrupt. The Output Compare Registers are 16-bit in size. To ensure that both the high and low bytes are written simultaneously when the CPU writes to these registers, the access is performed using an 8-bit temporary High Byte Register (TEMP). This temporary register is shared by all the other 16-bit registers. See section "Accessing 16- bit Registers" for details. • Bit 7:0 – OCR5AH7:0 - Timer/Counter5 Output Compare Register High Byte 18.11.52 OCR5AL – Timer/Counter5 Output Compare Register A Low Byte Bit 7 6 5 4 3 2 1 0 NA ($128) OCR5AL7:0 OCR5AL Read/Write RW RW RW RW RW RW RW RW Initial Value 0 0 0 0 0 0 0 0 The Output Compare Registers contain a 16-bit value that is continuously compared with the counter value (TCNT5). A match can be used to generate an Output Compare interrupt. The Output Compare Registers are 16-bit in size. To ensure that both the high and low bytes are written simultaneously when the CPU writes to these registers, the access is performed using an 8-bit temporary High Byte Register (TEMP). This temporary register is shared by all the other 16-bit registers. See section "Accessing 16- bit Registers" for details. • Bit 7:0 – OCR5AL7:0 - Timer/Counter5 Output Compare Register Low Byte 18.11.53 OCR5BH – Timer/Counter5 Output Compare Register B High Byte Bit 7 6 5 4 3 2 1 0 NA ($12B) OCR5BH7:0 OCR5BH Read/Write RW RW RW RW RW RW RW RW Initial Value 0 0 0 0 0 0 0 0 331 8393C-MCU Wireless-09/14

The Output Compare Registers contain a 16-bit value that is continuously compared with the counter value (TCNT5). A match can be used to generate an Output Compare interrupt. The Output Comp are Registers are 16-bit in size. To ensure that both the high and low bytes are written simultaneously when the CPU writes to these registers, the access is performed using an 8-bit temporary High Byte Register (TEMP). This temporary register is shared by all the other 16-bit registers. See section "Accessing 16- bit Registers" for details. • Bit 7:0 – OCR5BH7:0 - Timer/Counter5 Output Compare Register High Byte 18.11.54 OCR5BL – Timer/Counter5 Output Compare Register B Low Byte Bit 7 6 5 4 3 2 1 0 NA ($12A) OCR5BL7:0 OCR5BL Read/Write R RW RW RW RW RW RW RW Initial Value 0 0 0 0 0 0 0 0 The Output Compare Registers contain a 16-bit value that is continuously compared with the counter value (TCNT5). A match can be used to generate an Output Compare interrupt. The Output Compare Registers are 16-bit in size. To ensure that both the high and low bytes are written simultaneously when the CPU writes to these registers, the access is performed using an 8-bit temporary High Byte Register (TEMP). This temporary register is shared by all the other 16-bit registers. See section "Accessing 16- bit Registers" for details. • Bit 7:0 – OCR5BL7:0 - Timer/Counter5 Output Compare Register Low Byte 18.11.55 OCR5CH – Timer/Counter5 Output Compare Register C High Byte Bit 7 6 5 4 3 2 1 0 NA ($12D) OCR5CH7:0 OCR5CH Read/Write RW RW RW RW RW RW RW RW Initial Value 0 0 0 0 0 0 0 0 The Output Compare Registers contain a 16-bit value that is continuously compared with the counter value (TCN T5). A match can be used to generate an Output Compare interrupt. The Output Compare Registers are 16-bit in size. To ensure that both the high and low bytes are written simultaneously when the CPU writes to these registers, the access is performed using an 8-bit temporary High Byte Register (TEMP). This temporary register is shared by all the other 16-bit registers. See section "Accessing 16- bit Registers" for details. • Bit 7:0 – OCR5CH7:0 - Timer/Counter5 Output Compare Register High Byte ATmega256/128/64RFR2 332 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 18.11.56 OCR5CL – Timer/Counter5 Output Compare Register C Low Byte Bit 7 6 5 4 3 2 1 0 NA ($12C) OCR5CL7:0 OCR5CL Read/Write R RW RW RW RW RW RW RW Initial Value 0 0 0 0 0 0 0 0 The Output Compare Registers contain a 16-bit value that is continuously compared with the counter value (TCNT5). A match can be used to generate an Output Compare interrupt. The Output Compare Registers are 16-bit in size. To ensure that both the high and low bytes are written simultaneously when the CPU writes to these registers, the access is performed using an 8-bit temporary High Byte Register (TEMP). This temporary register is shared by all the other 16-bit registers. See section "Accessing 16- bit Registers" for details. • Bit 7:0 – OCR5CL7:0 - Timer/Counter5 Output Compare Register Low Byte 18.11.57 ICR5H – Timer/Counter5 Input Capture Register High Byte Bit 7 6 5 4 3 2 1 0 NA ($127) ICR5H7:0 ICR5H Read/Write R R R R R R R R Initial Value 0 0 0 0 0 0 0 0 The Timer/Counter5 has only limited functionality. It is not connected to any I/O pin. Therefore the contents of this register is never updated with the counter (TCNT5) value. The Input Capture Register is 16-bit in size. To ensure that both the high and low bytes are read simultaneously when the CPU accesses these registers, the access is performed using an 8-bit temporary High Byte Register (TEMP). This temporary register is shared by all the other 16 -bit registers. See section "Accessing 16-bit Registers" for details. • Bit 7:0 – ICR5H7:0 - Timer/Counter5 Input Capture Register High Byte 18.11.58 ICR5L – Timer/Counter5 Input Capture Register Low Byte Bit 7 6 5 4 3 2 1 0 NA ($126) ICR5L7:0 ICR5L Read/Write R R R R R R R R Initial Value 0 0 0 0 0 0 0 0 The Timer/Counter5 has only limited functionality. It is not connected to any I/O pin. Therefore the contents of this register is never updated with the counter (TCNT5) value. The Input Capture Register is 16-bit in size. To ensure that both the high and low bytes are read simultaneously when the CPU accesses these registers, the access is performed using an 8-bit temporary High Byte Register (TEMP). This temporary register is shared by all the other 16-bit registers. See section "Accessing 16-bit Registers" for details. • Bit 7:0 – ICR5L7:0 - Timer/Counter5 Input Capture Register Low Byte 333 8393C-MCU Wireless-09/14

18.11.59 TIMSK5 – Timer/Counter5 Interrupt Mask Register Bit 7 6 5 4 3 2 1 0 NA ($73) Res1 Res0 ICIE5 Res OCIE5C OCIE5B OCIE5A TOIE5 TIMSK5 Read/Write R R RW R R R RW RW Initial Value 0 0 0 0 0 0 0 0 • Bit 7:6 – Res1:0 - Reserved Bit This bit is reserved for future use. A read access always will return zero. A write access does not modify the content. • Bit 5 – ICIE5 - Timer/Counter5 Input Capture Interrupt Enable The Timer/Counter5 has only limited functionality. It does not have an Input Capture pin. Therefore this bit has no useful meaning. • Bit 4 – Res - Reserved Bit This bit is reserved for future use. A read access always will return zero. A write access does not modify the content . • Bit 3 – OCIE5C - Timer/Counter5 Output Compare C Match Interrupt Enable When this bit is written to one, and the I-flag in the Status Register is set (interrupts globally enabled), the Timer/Counter5 Output Compare C Match interrupt is enabled. The corresponding Interrupt Vector is executed when the OCF5C Flag, located in TIFR5, is set. • Bit 2 – OCIE5B - Timer/Counter5 Output Compare B Match Interrupt Enable When this bit is written to one, and the I-flag in the Status Register is set (interrupts globally enabled), the Timer/Counter5 Output Compare B Match interrupt is enabled. The corresponding Interrupt Vector is executed when the OCF5B Flag, located in TIFR5, is set. • Bit 1 – OCIE5A - Timer/Counter5 Output Compare A Match Interrupt Enable When this bit is written to one, and the I-flag in the Status Register is set (interrupts globally enabled), the Timer/Counter5 Output Compare A Match interrupt is enabled. The corresponding Interrupt Vector is executed when the OCF5A Flag, located in TIFR5, is set. • Bit 0 – TOIE5 - Timer/Counter5 Overflow Interrupt Enable When this bit is written to one, and the I-flag in the Status Register is set (interrupts globally enabled), the Timer/Counter5 Overflow interrupt is enabled. The corresponding Interrupt Vector is executed when the TOV5 Flag, located in TIFR5, is set. 18.11.60 TIFR5 – Timer/Counter5 Interrupt Flag Register Bit 7 6 5 4 3 2 1 0 $1A ($3A) Res1 Res0 ICF5 Res OCF5C OCF5B OCF5A TOV5 TIFR5 Read/Write R R RW R RW RW RW RW Initial Value 0 0 0 0 0 0 0 0 • Bit 7:6 – Res1:0 - Reserved Bit This bit is reserved for future use. A read access always will return zero. A write access does not modify the content. ATmega256/128/64RFR2 334 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 • Bit 5 – ICF5 - Timer/Counter5 Input Capture Flag The Timer/Counter5 has only limited functionality. It does not have an Input Capture pin. Therefore this bit has no useful meaning. • Bit 4 – Res - Reserved B it This bit is reserved for future use. A read access always will return zero. A write access does not modify the content. • Bit 3 – OCF5C - Timer/Counter5 Output Compare C Match Flag This flag is set in the timer clock cycle after the counter (TCNT5) value matches the Output Compare Register C (OCR5C). Note that a Forced Output Compare (FOC5C) strobe will not set the OCF5C Flag. OCF5C is automatically cleared when the Output Compare Match C Interrupt Vector is executed. Alternatively, OCF5C can be cleared by writing a logic one to its bit location. • Bit 2 – OCF5B - Timer/Counter5 Output Compare B Match Flag This flag is set in the timer clock cycle after the counter (TCNT5) value matches the Output Compare Register B (OCR5B). Note that a Forced Output Compare (FOC5B) strobe will not set the OCF 5B Flag. OCF5B is automatically cleared when the Output Compare Match B Interrupt Vector is executed. Alternatively, OCF5B can be cleared by writing a logic one to its bit location. • Bit 1 – OCF5A - Timer/Counter5 Output Compare A Match Flag This flag is set in the timer clock cycle after the counter (TCNT5) value matches the Output Compare Register A (OCR5A). Note that a Forced Output Compare (FOC5A) strobe will not set the OCF5A Flag. OCF5A is automatically cleared when the Output Compare Match A Interrupt Vector is executed. Alternatively, OCF5A can be cleared by writing a logic one to its bit location. • Bit 0 – TOV5 - Timer/Counter5 Overflow Flag The setting of this flag is dependent of the WGM53:0 bits setting of the Timer/Counter5 Control Register. In Normal and CTC modes, the TOV5 Flag is set when the timer overflows. TOV5 is automatically cleared when the Timer/Counter5 Overflow Interrupt Vector is executed. Alternatively, TOV5 can be cleared by writing a logic one to its bit location. 335 8393C-MCU Wireless-09/14

19 Timer/Counter 0, 1, 3, 4, and 5 Prescaler Timer/Counter 0, 1, 3, 4, and 5 share the same prescaler module, but the Timer/Counters can have different prescaler settings. The description below applies to all Timer/Counters. Tn is used as a general name, n = 0, 1, 3, 4, or 5. 19.1 Internal Clock Source The Timer/Counter can be clocked directly by the system clock (by setting the CSn2:0 = 1). This provides the fastest operation with a maximum Timer/Counter clock frequency equal to system clock frequency (f ). Alternatively one of four taps from the prescaler clkI/O can be used as a clock source. The prescaled clock has a frequency of either f /8, clkI/O fclkI/O/64, fclkI/O/256 or fclkI/O/10 24. 19.2 Prescaler Reset The prescaler is free running, i.e., operates independently of the Clock Select logic of the Timer/Counter, and it is shared by the Timer/Counter Tn. Since the prescaler is not affected by the Timer/Cou nter’s clock select, the state of the prescaler will have implications for situations where a prescaled clock is used. One example of prescaling artifacts occurs when the timer is enabled and clocked by the prescaler (6 > CSn2:0 > 1). The number of system clock cycles from the moment the timer is enabled until the first count occurs can be from 1 to N+1 system clock cycles, where N equals the prescaler divisor (8, 64, 256, or 1024). It is possible to use the prescaler reset for synchronizing the Timer/Counter to program execution. However care must be taken if the other Timer/Counter that shares the same prescaler also uses prescaling. A prescaler reset will affect the prescaler period for all connected Timer/Counters. 19.3 External Clock Source An external clock source a pplied to the Tn pin can be used as Timer/Counter clock (clk ). The Tn pin is sampled once every system clock cycle by the pin synchronization Tn logic. The synchronized (sampled) signal is then passed through the edge detector. Figure 19-1 shows a functional equivalent block diagram of the Tn synchronization and edge detector logic. The registers are clocked at the positive edge of the internal system clock (clk ). The latch is transparent in the high period of the internal system I/O clock. The edge detector generates one clk pulse for each positive (CSn2:0 = 7) or negative Tn (CSn2:0 = 6) edge it detects . Figure 19-1. Tn/T0 Pin Sampling Tn D Q D Q D Q Tn_sync (To Clock Select Logic) LE clk I/O Synchronization Edge Detector The synchronization and edge detector logic introduces a delay of 2.5 to 3.5 system clock cycles from an edge applied to the Tn pin to the counter being updated. ATmega256/128/64RFR2 336 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 Enabling and disabling of the clock input must be done when Tn has been stable for at least one system clock cycle. Otherwise there is a risk of generating a false Timer/Counter clock pulse. Each half period of the applied, external clock must be longer than one system clock cycle to ensure correct sampling. The external clock must be guaranteed to have less than half the system clock frequency (f < f /2) given a 50/50% duty cycle. Since ExtClk clkI/O the edge detector uses sampling, the maximum frequency of a detectable external clock is half the sampling frequency (Nyquist sampling theorem). However due to variation of the system clock frequency and duty cycle caused by Oscillator source (crystal, resonator and capacitors) tolerances, it is recommended to limit the maximum frequency of an external clock source to less than f /2.5. An external clock source clkI/O can not be prescaled. Figure 19-2. Prescaler for synchronous Timer/Counters clk I/O Clear PSR10 Tn Synchronization Tn Synchronization CSn0(cid:13) CSn0(cid:13) CSn1(cid:13) CSn1(cid:13) CSn2 CSn2 TIME R/COUNTERn CLOCK SOURCE(cid:13) TIMER/COUNTERn CLOCK SOURCE(cid:13) clk clk Tn Tn 19.4 Register Description 19.4.1 GTCCR – General Timer/Counter Control Register Bit 7 6 5 4 3 2 1 0 $23 ($43) TSM Res4 Res3 Res2 Res1 Res0 PSRASY PSRSYNC GTCCR Read/Write RW R R R R R R RW Initial Value 0 0 0 0 0 0 0 0 • Bit 7 – TSM - Timer/Counter Synchronization Mode Writing the TSM bit to one activates the Timer/Counter Synchronization mode. In this mode the value that is written to the PSRASY and PSRSYNC bits is kept, hence keeping the corresponding prescaler reset signals asserted. This ensures that the corresponding Timer/Counters are halted and can be configured to the same value without the risk of one of them advancing during the configuration. When the TSM bit is written to zero, the PSRASY and PSRSYNC bits are cleared by hardware and the Timer/Counters simultaneously start counting. • Bit 6:2 – Res4:0 - Reserved 337 8393C-MCU Wireless-09/14

This bit is reserved for future use. A read access always will return zero. A write access does not modify the content. • Bit 1 – PSRASY - Prescaler Reset Timer/Counter2 When this bit is one, the T imer/Counter2 prescaler will be reset. This bit is normally cleared immediately by hardware. If the bit is written when Timer/Counter2 is operating in asynchronous mode, the bit will remain one until the prescaler has been reset. The bit will not be cleared by hardware if the TSM bit is set. • Bit 0 – PSRSYNC - Prescaler Reset for Synchronous Timer/Counters When this bit is one, the Timer/Counter0, Timer/Counter1, Timer/Counter3, Timer/Counter4 and Timer/Counter5 prescaler will be reset. This bit is normally cleared immediately by hardware, except if the TSM bit is set. Note that Timer/Counter0, Timer/Counter1, Timer/Counter3, Timer/Counter4 and Timer/Counter5 share the same prescaler and a reset of this prescaler will affect all timers. ATmega256/128/64RFR2 338 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 20 Output Compare Modulator (OCM1C0A) 20.1 Overview The Output Compare Modulator (OCM) allows generation of waveforms modulated with a carrier frequency. The modulator uses the outputs from the Output Compare Unit C of the 16-bit Timer/Counter1 and the Output Compare Unit of the 8-bit Timer/Counter0. For more details about these Timer/Counters see "Timer/Counter 0, 1, 3, 4, and 5 Prescaler" on page 336 and "8-bit Timer/Counter2 with PWM and Asynchronous Operation" on page 341. Figure 20-1. Output Compare Modulator, Block Diagram Timer/Counter 1 OC1C Pin OC1C / Timer/Counter 0 OC0A OC0A / PB7 When the modulator is enabled, the two output compare channels are modulated together as shown in the block diagram (Figure 20-1 above). 20.2 Description The Output Compare unit 1C and Output Compare unit 2 share the PB7 port pin for output. The outputs of the Output Compare units (OC1C and OC0A) override the normal PORTB7 Register when one of them is enabled (i.e., when COMnx1:0 is not equal to zero). When both OC1C and OC0A are enabled at the same time, the modulator is automatically enabled. The functional equivalent schematic of the modulator is shown on in the following figure. The schematic includes part of the Timer/Counter units and the port B bit 7 output driver circuit. Figure 20-2. Output Compare Modulator, Schematic COMA01 Vcc COMA00 COM1C1 Modulator COM1C0 0 1 ( From Waveform Generator ) D Q 1 OC1C Pin 0 OC1C / ( From Waveform Generator ) D Q OC0A/ PB7 OC0A D Q D Q PORTB7 DDRB7 DATABUS 339 8393C-MCU Wireless-09/14

When the modulator is enabled the type of modulation (logical AND or OR) can be selected by the PORTB7 Register. Note that the DDRB7 controls the direction of the port independent of the COMnx1:0 bit setting. 20.3 Timing Example Figure 20-3 below illustrates the modulator in action. In this example the Timer/Counter1 is set to operate in fast PWM mode (non-inverted) and Timer/Counter0 uses CTC waveform mode with toggle Compare Output mode (COMnx1:0 = 1). Figure 20-3. Output Compare Modulator, Timing Diagram clk I/O OC1C (FPWM Mode) OC0A (CTC Mode) PB7 (PORTB7 = 0) PB7 (PORTB7 = 1) 1 2 3 (Period) In this example Timer/Counter2 provides the carrier while the modulating signal is generated by the Output Compare unit C of the Timer/Counter1. The resolution of the PWM signal (OC1C) is reduced by the modulation. The reduction factor is equal to the number of system clock cycles of one period of the carrier (OC0A). In this example the resolution is reduced by a factor of two. The reason for the reduction is illustrated in Figure 20-3 above at the second and third period of the PB7 output when PORTB7 equals zero. The period 2 high time is one cycle longer than the period 3 high time, but the result on the PB7 output is equal in both periods. ATmega256/128/64RFR2 340 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 21 8-bit Timer/Counter2 with PWM and Asynchronous Operation 21.1 Features Timer/Counter2 is a general purpose, single channel, 8-bit Timer/Counter module. The main features are: • Single channel counter • Clear timer on compare match (auto reload) • Glitch-free, phase-correct pulse-width modulator (PWM) • Frequency generator • 10 bit clock prescaler • Overflow and compare match interrupt sources (TOV2, OCF2A and OCF2B) • Able to run with external 32 kHz watch crystal independent of the I/O clock 21.2 Overview A simplified block diagram of the 8-bit Timer/Counter is shown on Figure 21-1 on page 342. For the current placement of I/O pins, see chapter "Pin Configurations" on page 2. CPU accessible I/O Registers, including I/O bits and I/O pins, are shown in bold. The device-specific I/O Register and bit locations are listed in the "Register Description" on page 356. The Power Reduction Timer/Counter2 bit PRTIM2 in register PRR0 (see "PRR0 – Power Reduction Register0" on page 197) must be written to zero to enable Timer/Counter2 module. Note: OC2B is implemented but not routed to a pin and for this reason it can’t be used. 21.2.1 Registers The Timer/Counter (TCNT2) and Output Compare Register (OCR2A and OCR2B) are 8 bit registers. Interrupt request (abbreviated to Int.Req.) signals are all visible in the Timer Interrupt Flag Register (TIFR2). All interrupts are individually masked with the Timer Interrupt Mask Register (TIMSK2). TIFR2 and TIMSK2 are not shown in the figure. The Timer/Counter can be clocked internally, via the prescaler, asynchronously clocked from the TOSC1/2 pins or alternatively from the Automated Meter Reading (AMR) pin as detailed later in this section. The asynchronous operation is controlled by the Asynchronous Status Register (ASSR). The Clock Select logic block controls which clock source the Timer/Counter uses to increment (or decrement) its value. The Timer/Counter is inactive when no clock source is selected. The output from the Clock Select logic is referred to as the timer clock (clk ). T2 The double buffered Output Compare Register (OCR2A and OCR2B) are compared with the Timer/Counter value at all times. The result of the compare can be used by the Waveform Generator to generate a PWM or variable frequency output on the Output Compare pins (OC2A and OC2B). See chapter "Output Compare Unit" on page 348 for details. The compare match event will also set the Compare Flag (OCF2A or OCF2B) which can be used to generate an Output Compare interrupt request. 21.2.2 Definitions Many register and bit references in this document are written in general form. A lower case “n” replaces the Timer/Counter number, in this case 2. However, when using the 341 8393C-MCU Wireless-09/14

register or bit defines in a program, the precise form must be used, i.e., TCNT2 for accessing Timer/Counter2 counter value and so on. Figure 21-1. 8-bit Timer/Co unter Block Diagram The definitions in Table Table 21-1 below are also used extensively throughout the section. Table 21-1. Definitions BOTTOM The counter reaches the BOTTOM when it becomes zero (0x00). MAX The counter reaches its MAXimum when it becomes 0xFF (decimal 255). TOP The counter reaches the TOP when it becomes equal to the highest value in the count sequence. The TOP value can be assigned to be the fixed value 0xFF (MAX) or the value stored in the OCR2A Register. The assignment is dependent on the mode of operation. 21.3 Timer/Counter Clock Sources The Timer/Counter can be clocked by an internal synchronous or an external asynchronous clock source. The clock source clk is by default equal to the MCU T2 clock, clk . When the AS2 bit in the ASSR Register is written to logic one, the clock I/O source is either taken from the Timer/Counter Oscillator connected to TOSC1 and TOSC2 or from the AMR pin. For details on asynchronous operation, see section ATmega256/128/64RFR2 342 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 "Asynchronous Operation of Timer/Counter2" on page 352. For details on clock sources and prescaler, see section "Timer/Counter Prescaler" on page 355. 21.4 Counter Unit The main part of the 8-bit Timer/Counter is the programmable bi-directional counter unit. Figure 21-2 below shows a block diagram of the counter and its surrounding environment. Figure 21-2. Counter Unit Block Diagram Signal description (internal signals): count Increment or decrement TCNT2 by 1. direction Selects between increment and decrement. clear Clear TCNT2 (set all bits to zero). clk Timer/Counter clock, referred to as clk in the following. Tn T2 top Signalizes that TCNT2 has reached maximum value. bottom Signalizes that TCNT2 has reached minimum value (zero). Depending on the mode of operation used, the counter is cleared, incremented, or decremented at each timer clock (clk ). clk can be generated from an external or T2 T2 internal clock source, selected by the Clock Select bits (CS22:0). When no clock source is selected (CS22:0 = 0) the timer is stopped. However, the TCNT2 value can be accessed by the CPU, regardless of whether clk is present or not. A CPU write T2 overrides (has priority over) all counter clear or count operations. The counting sequence is determined by the setting of the WGM21 and WGM20 bits located in the Timer/Counter Control Register (TCCR2A) and the WGM22 located in the Timer/Counter Control Register B (TCCR2B). There are close connections between how the counter behaves (counts) and how waveforms are generated on the Output Compare outputs OC2A and OC2B. For more details about advanced counting sequences and waveform generation, see chapter "Modes of Operation" below. The Timer/Counter Overflow Flag (TOV2) is set according to the mode of operation selected by the WGM22:0 bits. TOV2 can be used for generating a CPU interrupt. 21.5 Modes of Operation The mode of operation, i.e., the behaviour of the Timer/Counter and the Output Compare pins, is defined by the combination of the Waveform Generation mode (WGM22:0) and Compare Output mode (COM2x1:0) bits. The Compare Output mode bits do not affect the counting sequence, while the Waveform Generation mode bits do. The COM2x1:0 bits control whether the PWM output generated should be inverted or 343 8393C-MCU Wireless-09/14

not (inverted or non-inverted PWM). For non-PWM modes the COM2x1:0 bits control whether the output should be set, cleared, or toggled at a compare match (see chapter "Compare Match Output Unit" on page 349). For detailed timing informa tion refer to chapter "Timer/Counter Timing Diagrams" on page 351. The following table shows the function of the WGM22:0 bits of registers TCCR2A and TCCR2B. These bits control the counting sequence of the counter, the source for maximum (TOP) counter value, and what type of waveform generation to be used. Table 21-2. Waveform Generation Mode Bit Description Timer/Counter Mode of Update of TOV Flag Mode WGM2 WGM1 WGM0 Operation TOP OCRX at Set on(1,2) 0 0 0 0 Normal 0xFF Immediate MAX PWM, Phase 1 0 0 1 0xFF TOP BOTTOM Correct 2 0 1 0 CTC OCRA Immediate MAX 3 0 1 1 Fast PWM 0xFF TOP MAX 4 1 0 0 Reserved – – – PWM, Phase 5 1 0 1 OCRA TOP BOTTOM Correct 6 1 1 0 Reserved – – – 7 1 1 1 Fast PWM OCRA BOTTOM TOP Notes: 1. MAX = 0xFF 2. BOTTOM = 0x00 21.5.1 Normal Mode The simplest mode of operation is the Normal mode (WGM22:0 = 0). In this mode the counting direction is always up (incrementing), and no counter clear is performed. The counter simply overruns when it passes its maximum 8 bit value (TOP = 0xFF) and then restarts from the bottom (0x00). In normal operation the Timer/Counter Overflow Flag (TOV2) will be set in the same timer clock cycle as the TCNT2 becomes zero. The TOV2 Flag in this case behaves like a ninth bit, except that it is only set, not cleared. However combined with the timer overflow interrupt that automatically clears the TOV2 Flag, the timer resolution can be increased by software. There are no special cases to consider in the Normal mode, a new counter value can be written anytime. The Output Compare unit can be used to generate interrupts at some given time. Using the Output Compare to generate waveforms in Normal mode is not recommended, since this will occupy too much of the CPU time. 21.5.2 Clear Timer on Compare Match (CTC) Mode In Clear Timer on Compare or CTC mode (WGM22:0 = 2), the OCR2A Register is used to manipulate the counter resolution. In CTC mode the counter is cleared to zero when the counter value (TCNT2) matches the OCR2A. The OCR2A defines the top value for the counter, hence also its resolution. This mode allows greater control of the compare match output frequency. It also simplifies the operation of counting external events. The timing diagram for the CTC mode is shown in Table 20-3. The counter value (TCNT2) increases until a compare match occurs between TCNT2 and OCR2A, and then counter (TCNT2) is cleared. ATmega256/128/64RFR2 344 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 Figure 21-3. CTC Mode, Timing Diagram OCnx Interrupt Flag Set TCNTn OCn (COMnx1:0 = 1) (Toggle) Period 1 2 3 4 An interrupt can be generated each time the counter value reaches the TOP value by using the OCF2A Flag. If the interrupt is enabled, the interrupt handler routine can be used for updating the TOP value. However, changing TOP to a value close to BOTTOM when the counter is running with none or a low prescaler value must be done with care since the CTC mode does not have the double buffering feature. If the new value written to OCR2A is lower than the current value of TCNT2, the counter will miss the compare match. The counter will then have to count to its maximum value (0xFF) and wrap around starting at 0x00 before the compare match can occur. For generating a waveform output in CTC mode, the OC2A output can be set to toggle its logical level on each compare match by setting the Compare Output mode bits to toggle mode (COM2A1:0 = 1). The OC2A value will not be visible on the port pin unless the data direction for the pin is set to output. The waveform generated will have a maximum frequency of f = f /2 when OCR2A is set to zero (0x00). The waveform OC2A clkI/O frequency is defined by the following equation f f = clkI/O OCnx 2⋅N⋅(1+OCRnx) The N variable represents th e pre-scale factor (1, 8, 32, 64, 128, 256, or 1024). As for the Normal mode of operation, the TOV2 Flag is set in the same timer clock cycle that the counter counts from MAX to 0x00. 21.5.3 Fast PWM Mode The Timer/Counter Overflow Flag (TOV2) is set each time the counter reaches TOP. If the interrupt is enabled, the interrupt handler routine can be used for updating the compare value. In fast PWM mode, the compare unit allows generation of PWM waveforms on the OC2x pin. Setting the COM2x1:0 bits to two will produce a non-inverted PWM and an inverted PWM output can be generated by setting the COM2x1:0 to three. TOP is defined as 0xFF when WGM22:0 = 3, and OCR2A when WGM22:0 = 7 (see section "Register Description" on pa ge 356 for register TCCR2A). The actual OC2x value will only be visible on the port pin if the data direction for the port pin is set as output. The PWM waveform is generated by setting (or clearing) the OC2x Register at the compare match between OCR2x and TCNT2, and clearing (or setting) the OC2x Register at the timer clock cycle the counter is cleared (changes from TOP to BOTTOM). 345 8393C-MCU Wireless-09/14

Figure 21-4. Fast PWM Mode, Timing Diagram OCRnx Interrupt Flag Set OCRnx Update and(cid:3) TOVn Interrupt Flag Set TCNTn OCnx (COMnx1:0 = 2) OCnx (COMnx1:0 = 3) Period 1 2 3 4 5 6 7 The PWM frequency for the output can be calculated by the following equation: f f = clkI/O OCnxPWM N⋅256 The N variable represents the pre-scale factor (1, 8, 32, 64, 128, 256, or 1024). The extreme values for the OCR2A Register represent special cases when generating a PWM waveform output in the fast PWM mode. If the OCR2A is set equal to BOTTOM, the output will be a narrow spike for each MAX+1 timer clock cycle. Setting the OCR2A equal to MAX will result in a constantly high or low output (depending on the polarity of the output set by the COM2A1:0 bits.) A frequency (with 50% duty cycle) waveform output in fast PWM mode can be achieved by setting OC2x to toggle it s logical level on each compare match (COM2x1:0 = 1). The waveform generated will have a maximum frequency of f = f /2 when OCR2A is OC2A clkI/O set to zero. This feature is similar to the OC2A toggle in CTC mode, except the double buffer feature of the Output Compare unit is enabled in the fast PWM mode. 21.5.4 Phase Correct PWM Mode The phase correct PWM mode (WGM22:0 = 1 or 5) provides a high resolution phase correct PWM waveform generation option. The phase correct PWM mode is based on a dual-slope operation. The c ounter counts repeatedly from BOTTOM to TOP and then from TOP to BOTTOM. TOP is defined as 0xFF when WGM22:0 = 1, and OCR2A when WGM22:0 = 5. In non-inverting Compare Output mode, the Output Compare (OC2x) is cleared on the compare match between TCNT2 and OCR2x while up-counting, and set on the compare match while down-counting. In inverting Output Compare mode, the operation is inverted. The dual-slope operation has lower maximum operation frequency than single slope operation. However, due to the symmetric feature of the dual-slope PWM modes, these modes are preferred for motor control applications. In phase correct PWM mode the counter is incremented until the counter value matches TOP. When the counter reaches TOP, it changes the count direction. The TCNT2 value will be equal to TOP for one timer clock cycle. The timing diagram for the phase correct PWM mode is shown on Figure 21-5 on page 347. The TCNT2 value is in the timing diagram shown as a histogram for illustrating the dual-slope operation. The diagram ATmega256/128/64RFR2 346 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 includes non-inverted and inverted PWM outputs. The small horizontal line marks on the TCNT2 slopes represent compare matches between OCR2x and TCNT2. Figure 21-5. Phase Correct PWM Mode, Timing Diagram OCnx Interrupt Flag Set OCRnx Update TOVn Interrupt Flag Set TCNTn OCnx (COMnx1:0 = 2) OCnx (COMnx1:0 = 3) Period 1 2 3 The Timer/Counter Overflow Flag (TOV2) is set each time the counter reaches BOTTOM. The Interrupt Flag can be used to generate an interrupt each time the counter reaches the BOTTOM value. In phase correct PWM mode, the compare unit allows generation of PWM waveforms on the OC2x pin. Setting the COM2x1:0 bits to two will produce a non-inverted PWM. An inverted PWM output can be generated by setting the COM2x1:0 to three. TOP is defined as 0xFF when WGM22:0 = 3, and OCR2A when WGM22:0 = 7 (see section "Register Description" on page 356 for register TCCR2A). The actual OC2x value will only be visible on the port pin if the data direction for the port pin is set as output. The PWM waveform is generated by clearing (or setting) the OC2x Register at the compare match between OCR2x and TCNT2 when the counter increments, and setting (or clearing) the OC2x Register at compare match between OCR2x and TCNT2 when the counter decrements. The PWM frequency for the output when using phase correct PWM can be calculated by the following equation: f f = clk_I/O OCnxPCPWM N⋅510 The N variable represents the pre-scale factor (1, 8, 32, 64, 128, 256, or 1024). The extreme values for the OCR2A Register represent special cases when generating a PWM waveform output in the phase correct PWM mode. If the OCR2A is set equal to BOTTOM, the output will be continuously low and if set equal to MAX the output will be continuously high for non-inverted PWM mode. For inverted PWM the output will have the opposite logic values. At the very start of period 2 in Figure 21-5 above OCnx has a transition from high to low even though there is no Compare Match. The point of this transition is to guarantee symmetry around BOTTOM. There are two cases that give a transition without Compare Match. 347 8393C-MCU Wireless-09/14

• OCR2A changes its value from MAX, like in Figure 21-5 on page 347. When the OCR2A value is MAX the OCn pin value is the same as the result of a down- counting compare match. To ensure symmetry around BOTTOM the OCn value at MAX must correspond to the result of an up-counting Compare Match. • The timer starts counting from a value higher than the one in OCR2A, and for that reason misses the Compare Match and hence the OCn change that would have happened on the way up. 21.6 Output Compare Unit The 8 bit comparator continuously compares TCNT2 with the Output Compare Register (OCR2A and OCR2B). Whenever TCNT2 equals OCR2A or OCR2B, the comparator signals a match. A match w ill set the Output Compare Flag (OCF2A or OCF2B) at the next timer clock cycle. If the corresponding interrupt is enabled, the Output Compare Flag generates an Output Compare interrupt. The Output Compare Flag is automatically cleared when the interrupt is executed. Alternatively, the Output Compare Flag can be cleared by software by writing a logical one to its I/O bit location. The Waveform Generator uses the match signal to generate an output according to operating mode set by the WGM22:0 bits and Compare Output mode (COM2x1:0) bits. The max and bottom signals are used by the Waveform Generator for handling the special cases of the extreme values in some modes of operation (chapter "Modes of Operation" on page 343). Figure 21-6 below shows a block diagram of the Output Compare unit. Figure 21-6. Output Compare Unit, Block Diagram DATA BUS OCRn TCNTn = (8-bit Comparator ) OCFn (Int.Req.) top bottom Waveform Generator OCxy FOCn WGMn1:0 COMn1:0 The OCR2x Register is double buffered when using any of the Pulse Width Modulation (PWM) modes. For the Normal and Clear Timer on Compare (CTC) modes of operation, the double buffering is disabled. The double buffering synchronizes the update of the OCR2x Compare Register to either top or bottom of the counting sequence. The synchronization prevents the occurrence of odd-length, non-symmetrical PWM pulses, thereby making the output glitch-free. ATmega256/128/64RFR2 348 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 The OCR2x Register access may seem complex, but this is not the case. When the double buffering is enabled, the CPU has access to the OCR2x Buffer Register, and if double buffering is disabled the CPU will access the OCR2x directly. 21.6.1 Force Output Compare In non-PWM waveform generation modes, the match output of the comparator can be forced by writing a one to the Force Output Compare (FOC2x) bit. Forcing compare match will not set the OCF2x Flag or reload/clear the timer, but the OC2x pin will be updated as if a real compare match had occurred (the COM2x1:0 bits settings define whether the OC2x pin is set, cleared or toggled). 21.6.2 Compare Match Blocking by TCNT2 Write All CPU write operations to the TCNT2 Register will block any compare match that occurs in the next timer clock cycle, even when the timer is stopped. This feature allows OCR2x to be initialized to the same value as TCNT2 without triggering an interrupt when the Timer/Counter clock is enabled. 21.6.3 Using the Output Compare Unit Since writing TCNT2 in any mode of operation will block all compare matches for one timer clock cycle, there are risks involved when changing TCNT2 when using the Output Compare channel, independently of whether the Timer/Counter is running or not. If the value written to TCNT2 equals the OCR2x value, the compare match will be missed, resulting in incorrect waveform generation. Similarly, do not write the TCNT2 value equal to BOTTOM when the counter is down-counting. The setup of the OC2x shou ld be performed before setting the Data Direction Register for the port pin to output. The easiest way of setting the OC2x value is to use the Force Output Compare (FOC2x) strobe bit in Normal mode. The OC2x Register keeps its value even when changing between Waveform Generation modes. Be aware that the COM2x1:0 bits are not double buffered together with the compare value. A change of the COM 2x1:0 bits will take effect immediately. 21.7 Compare Match Output Unit The Compare Output mode (COM2x1:0) bits have two functions. The Waveform Generator uses the COM2x1:0 bits for defining the Output Compare (OC2x) state at the next compare match. Also, the COM2x1:0 bits control the OC2x pin output source. Figure 20-7 shows a simplified schematic of the logic affected by the COM2x1:0 bit setting. The I/O Registers, I /O bits, and I/O pins in the figure are shown in bold. Only the parts of the general I/O Port Control Registers (DDR and PORT) that are affected by the COM2x1:0 bits are shown. When referring to the OC2x state, the reference is for the internal OC2x Register, not the OC2x pin. The general I/O port function is overridden by the Output Compare (OC2x) from the Waveform Generator if eith er of the COM2x1:0 bits are set. However, the OC2x pin direction (input or output) is still controlled by the Data Direction Register (DDR) for the port pin. The Data Direction Register bit for the OC2x pin (DDR_OC2x) must be set as output before the OC2x value is visible on the pin. The port override function is independent of the Waveform Generation mode. The design of the Output Compare pin logic allows initialization of the OC2x state before the output is enabled. Note that some COM2x1:0 bit settings are reserved for certain modes of operation. See section "Register Description" on page 356 for details. 349 8393C-MCU Wireless-09/14

Figure 21-7. Compare Match Output Unit, Schematic COMnx1 Waveform COMnx0 D Q Generator FOCn 1 OCnx OCnx Pin 0 D Q S U B PORT A T A D D Q DDR clk I/O 21.7.1 Compare Output Mode and Waveform Generation The Waveform Generator uses the COM2x1:0 bits differently in normal, CTC, and PWM modes. Setting the COM2x1:0 = 0 for all modes tells the Waveform Generator that no action on the OC2x Register is to be performed on the next compare match. For compare output actions in the non-PWM modes for fast PWM mode and for phase correct PWM refer to section "Register Description" on page 356 for register TCCR2A. A change of the COM2x1:0 bits state will have effect at the first compare match after the bits are written. For non -PWM modes, the action can be forced to have immediate effect by using the FOC2x strobe bits. The following table shows the COM2x1:0 bit functionality when the WGM02:0 bits are set to a normal or CTC mode (non-PWM). Table 21-3. Compare Output Mode, non-PWM Mode COM2x1 COM2x0 Description 0 0 Normal port operation, OC2x disconnected; 0 1 Toggle OC2x on Compare Match; 1 0 Clear OC2x on Compare Match; 1 1 Set OC2x on Compare Match; Table 17-3 shows the COM2x1:0 bit functionality when the WGM21:0 bits are set to fast PWM mode. Table 21-4. Compare Output Mode, Fast PWM Mode COM2x1 COM2x0 Description 0 0 Normal port operation, OC2x disconnected. WGM22 = 0: Normal Port Operation, OC2A Disconnected. 0 1 WGM22 = 1: Toggle OC2A on Compare Match. OC2B: not applicable, reserved function; ATmega256/128/64RFR2 350 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 COM2x1 COM2x0 Description Clear OC2x on Compare Match, set OC2x at BOTTOM, (non- 1 0 inverting mode). Se t OC2x on Compare Match, clear OC2x at BOTTOM, (inverting 1 1 mode). Note: 1. A special case occurs when OCR2x equals TOP and COM2x1 is set. In this case, the Compare Match is ignored, but the set or clear is done at BOTTOM. See "Fast PWM Mode" on page 345. Table 17-4 shows the COM2x1:0 bit functionality when the WGM22:0 bits are set to phase correct PWM mode. Table 21-5. Compare Outpu t Mode, Phase Correct PWM Mode COM2x1 COM2x0 Description 0 0 Normal port operation, OC2x disconnected. WGM22 = 0: Normal Port Operation, OC2A Disconnected. 0 1 WGM22 = 1: Toggle OC2A on Compare Match. OC2B: not applicable, reserved function; Clear OC2x on Compare Match when up-counting. Set OC2x on 1 0 Compare Match when down-counting. Set OC2x on Compare Match when up-counting. Clear OC2x on 1 1 Compare Match when down-counting. Note: 1. A special case occurs when OCR2x equals TOP and COM2x1 is set. In this case, the Compare Match is ignored, but the set or clear is done at TOP. See "Phase Correct PWM Mo de" on page 346 for more details. 21.8 Timer/Counter Timing Diagrams The following figures show the Timer/Counter in synchronous mode, and the timer clock (clk ) is therefore shown as a clock enable signal. In asynchronous mode, clk should T2 I/O be replaced by the Timer/Counter Oscillator clock. The figures include information on when Interrupt Flags are set. Figure 21-8 below contains timing data for basic Timer/Counter operation. The figure shows the count sequence close to the MAX value in all modes other than phase correct PWM mode. Figure 21-8. Timer/Counter Timing Diagram, no Prescaling clk I/O clk Tn (clk /1) I/O TCNTn MAX - 1 MAX BOTTOM BOTTOM + 1 TOVn 351 8393C-MCU Wireless-09/14

Figure 21-9 below shows the same timing data, but with the prescaler enabled. Figure 21-9. Timer/Counter Timing Diagram, with Prescaler (f /8) clkI/O clk I/O clk Tn (clk /8) I/O TCNTn MAX - 1 MAX BOTTOM BOTTOM + 1 TOVn Figure 21-10 below shows the setting of OCF2A in all modes except CTC mode. Figure 21-10. Timer/Counter Timing Diagram, Setting of OCF2A, with Prescaler (f /8) clkI/O clk I/O clk Tn (clk /8) I/O TCNTn OCRnx - 1 OCRnx OCRnx + 1 OCRnx + 2 OCRnx OCRnx Value OCFnx Figure 21-11 below shows the setting of OCF2A and the clearing of TCNT2 in CTC mode. Figure 21-11. Timer/Counter Timing Diagram, Clear Timer on Compare Match mode, with Prescaler (f /8) clkI/O clk I/O clk Tn (clk /8) I/O TCNTn TOP - 1 TOP BOTTOM BOTTOM + 1 (CTC) OCRnx TOP OCFnx 21.9 Asynchronous Operation of Timer/Counter2 When Timer/Counter2 operates asynchronously, some considerations must be taken. ATmega256/128/64RFR2 352 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 • Warning: When switching between asynchronous and synchronous clocking of Timer/Counter2, the Timer Registers TCNT2, OCR2x, and TCCR2x might be corrupted. A safe procedure for switching clock source is: 1. Disable the Timer/Counter2 interrupts by clearing OCIE2x and TOIE2. 2. Select clock source by setting AS2 as appropriate. 3. Write new values to TCNT2, OCR2x, and TCCR2x. 4. To switch to asynchronous operation: Wait for TCN2UB, OCR2xUB, and TCR2xUB. 5. Clear the Timer/Counter2 Interrupt Flags. 6. Enable interrupts, if needed. • The CPU main clock frequency must be more than four times the Oscillator frequency. • When writing to one of the registers TCNT2, OCR2x, or TCCR2x, the value is transferred to a temporary register, and latched after two positive edges on TOSC1. The user should not write a new value before the contents of the temporary register have been transferred to its destination. Each of the five mentioned registers have their individual temporary register, which means that e.g. writing to TCNT2 does not disturb an OCR2x write in progress. To detect that a transfer to the destination register has taken place, the Asynchronous Status Register – ASSR has been implemented. • When entering Power-save or ADC Noise Reduction mode after having written to TCNT2, OCR2x, or TCCR2x, the user must wait until the written register has been updated if Timer/Counter2 is used to wake up the device. Otherwise, the MCU will enter sleep mode before the changes are effective. This is particularly important if any of the Output Compare2 interrupt is used to wake up the device, since the Output Compare function is disabled during writing to OCR2x or TCNT2. If the write cycle is not finished, and the MCU enters sleep mode before the corresponding OCR2xUB bit returns to zero, the device will never receive a compare match interrupt, and the MCU will not wake up. • If Timer/Counter2 is used to wake the device up from Power-save or ADC Noise Reduction mode, precau tions must be taken if the user wants to re-enter one of these modes: The interrupt logic needs one TOSC1 cycle to be reset. If the time between wake-up and re-entering sleep mode is less than one TOSC1 cycle, the interrupt will not occur, and the device will fail to wake up. If the user is in doubt whether the time before re-entering Power-save or ADC Noise Reduction mode is sufficient, the following algorithm can be used to ensure that one TOSC1 cycle has elapsed: 1. Write a value to TCCR2x, TCNT2, or OCR2x. 2. Wait until the corresponding Update Busy Flag in ASSR returns to zero. . 3. Enter Power-save or ADC Noise Reduction mode. C Code Example (Fragment)(1) ISR( TIMER2_OVF_vect ) {…} // TC2 overflow IRQ service routine int main(void){ … ASSR = 1<<AS2; // turn on 32kHz crystal oscillator TIMSK2 = 1<<TOIE2; // enable TC2 overflow interrupt TCCR2B = 0x05; // divide clock by 128 (1s interrupts) do {} while(ASSR & (1<<TCR2BUB)); // check if busy 353 8393C-MCU Wireless-09/14

C Code Example (Fragment)(1) … do { // main loop … TRXPR = 1 << SLPTR; // disable transceiver set_sleep_mode(SLEEP_MODE_PWR_SAVE); TCNT2 = 0; // reset counter do // check if busy before sleeping {} while(ASSR & (1<<TCN2UB)); sleep_enable(); sleep_c pu(); // go to deep-sleep (power- save) sleep_disable(); // executed after wakeup … } … } Notes: 1. See section "About Code Examples" on page 7. • When the asynchronous operation is selected, the 32.768 kHz Oscillator for Timer/Counter2 is always running, except in Power-down and Standby modes. After a Power-up Reset or wake-up from Power-down or Standby mode, the user should be aware of the fact that this Oscillator might take as long as one second to stabilize. The user is advised to wait for at least one second before using Timer/Counter2 after power-up or wake-up from Power-down or Standby mode. The contents of all Timer/Counter2 Registers must be considered lost after a wake-up from Power- down or Standby mode due to unstable clock signal upon start-up, no matter whether the Oscillator is in use or a clock signal is applied to the TOSC1 pin. • Description of wake up from Power-save or ADC Noise Reduction mode when the timer is clocked asynchronously: When the interrupt condition is met, the wake up process is started on the following cycle of the timer clock, that is, the timer is always advanced by at least one before the processor can read the counter value. After wake-up, the MCU is halted for four cycles, it executes the interrupt routine, and resumes execution from the instruction following SLEEP. • Reading of the TCNT2 Register shortly after wake-up from Power-save may give an incorrect result. Since TCNT2 is clocked on the asynchronous TOSC clock, reading TCNT2 must be done through a register synchronized to the internal I/O clock domain. Synchronization takes place for every rising TOSC1 edge. When waking up from Power-save mode, and the I/O clock (clk ) again becomes active, TCNT2 will I/O read as the previous value (before entering sleep) until the next rising TOSC1 edge. The phase of the TOSC clock after waking up from Power-save mode is essentially unpredictable, as it depends on the wake-up time. The recommended procedure for reading TCNT2 is thus a s follows: 1. Write any value to either of the registers OCR2x or TCCR2x. 2. Wait for the corresponding Update Busy Flag to be cleared. 3. Read TCNT2. • During asynchronous operation, the synchronization of the Interrupt Flags for the asynchronous timer takes 3 processor cycles plus one timer cycle. The timer is therefore advanced by at least one before the processor can read the timer value ATmega256/128/64RFR2 354 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 causing the setting of the Interrupt Flag. The Output Compare pin is changed on the timer clock and is not synchronized to the processor clock. • If the CPU wakes up from asynchronous timer and goes back to sleep again, it may wakeup multiple times or the IRQ is called multiple times. This may be avoided if the CPU waits with the next sleep instruction until the next asynchronous clock arrives. 21.10 Timer/Counter Prescaler Figure 21-12. Prescaler for Timer/Counter2 The register ASSR defines the clock source for the asynchronous Timer/Counter2. The clock source for Timer/Counter2 is named clk . clk is by default connected to the T2S T2S main system I/O clock clk . By setting the AS2 bit in ASSR, Timer/Counter2 is I/O asynchronously clocked either from the TOSC1 or from the AMR pin. This enables the use of Timer/Counter2 as a Real Time Counter (RTC). The TOSC1 pin is selected by setting the EXCLKAMR bit in the ASSR register to logic zero. Under this condition TOSC1 and TOSC2 are disconnected from Port G and a crystal can then be connected between the TOSC1 and TOSC2 pins to serve as an independent clock source for Timer/Counter2. The Oscillator is optimized for use with a 32.768 kHz crystal. By setting the EXCLK bit in the ASSR, a 32 kHz external clock can be applied on TOSC1. Setting the EXCLKAMR bit to logic one selects the AMR pin as the Timer/Counter2 clock source. Thus the 32 kHz oscillator can be used by the MAC symbol counter while the Timer/Counter2 uses pin AMR as clock source, see "MAC Symbol Counter" on page 157. A complete overview of the implemented asynchronous clock sources can be found in Table 21-6 on page 356. The last column mentions which pins are available for GPIO functionality. For details about the ASSR register refer to section "Register Description" on page 356. For Timer/Counter2, the possible pre-scaled selections are: clk /8, clk /32, clk T2S T2S T2S /64, clk /128, clk /256, and clk /1024. Additionally, clk as well as 0 (stop) may T2S T2S T2S T2S be selected. Setting the PSRASY bit in GTCCR resets the prescaler. This allows the user to operate with a predictable prescaler. 355 8393C-MCU Wireless-09/14

Table 21-6. Asynchronous clock selection for Timer/Counter2 and Symbol-Counter Timer/Counter2 32 kHz crystal Osc. PG2, PG3, PG4 AS2 EXCLK EXCLKAMR clock source (TOSC1/TOSC2) as GPIOs 0 0 0 clkI/O off PG2, PG3, PG4 0 1 0 not defined not defined not defined 1 0 0 32 kHz crystal Osc on PG2 1 1 0 TOSC1 (PG4) off PG2, PG3 0 0 1 clkI/O off PG2, PG3, PG4 0 1 1 not defined not defined not defined 1 0 1 AMR (PG2) on 1 1 1 AMR (PG2) off PG3, PG4 21.11 Register Description 21.11.1 TIMSK2 – Timer/Counter Interrupt Mask register Bit 7 6 5 4 3 2 1 0 NA ($70) Res4 Res3 Res2 Res1 Res0 OCIE2B OCIE2A TOIE2 TIMSK2 Read/Write R R R R R RW RW RW Initial Value 0 0 0 0 0 0 0 0 • Bit 7:3 – Res4:0 - Reserved Bit This bit is reserved for future use. A read access always will return zero. A write access does not modify the content. • Bit 2 – OCIE2B - Timer/Counter2 Output Compare Match B Interrupt Enable When the OCIE2B bit is written to one and the I-bit in the Status Register is set (one), the Timer/Counter2 Compa re Match B interrupt is enabled. The corresponding interrupt is executed if a compare match in Timer/Counter2 occurs, i.e., when the OCF2B bit is set in the Timer/Counter2 Interrupt Flag Register TIFR2. • Bit 1 – OCIE2A - Timer/Counter2 Output Compare Match A Interrupt Enable When the OCIE2A bit is written to one and the I-bit in the Status Register is set (one), the Timer/Counter2 Compare Match A interrupt is enabled. The corresponding interrupt is executed if a compare match in Timer/Counter2 occurs, i.e., when the OCF2A bit is set in the Timer/Counter2 Interrupt Flag Register TIFR2. • Bit 0 – TOIE2 - Timer/Counter2 Overflow Interrupt Enable When the TOIE2 bit is written to one and the I-bit in the Status Register is set (one), the Timer/Counter2 Overflow interrupt is enabled. The corresponding interrupt is executed if an overflow in Timer/Counter2 occurs i.e., when the TOV2 bit is set in the Timer/Counter2 Interrupt Flag Register TIFR2. 21.11.2 TIFR2 – Timer/Counter Interrupt Flag Register Bit 7 6 5 4 3 2 1 0 $17 ($37) Res4 Res3 Res2 Res1 Res0 OCF2B OCF2A TOV2 TIFR2 Read/Write R R R R R RW RW RW Initial Value 0 0 0 0 0 0 0 0 ATmega256/128/64RFR2 356 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 • Bit 7:3 – Res4:0 - Reserved Bit This bit is reserved for future use. A read access always will return zero. A write access does not modify the content. • Bit 2 – OCF2B - Output Compare Flag 2 B The OCF2B bit is set (one) when a compare match occurs between the Timer/Counter2 and the data in OCR2B Output Compare Register2. OCF2B is cleared by hardware when executing the corresponding interrupt handling vector. Alternatively, OCF2B is cleared by writing a logic one to the flag. When the I-bit in SREG, OCIE2B (Timer/Counter2 Compare Match Interrupt Enable), and OCF2B are set (one), the Timer/Counter2 Compare Match Interrupt is executed. • Bit 1 – OCF2A - Output Compare Flag 2 A The OCF2A bit is set (one) when a compare match occurs between the Timer/Counter2 and the data in OCR2A Output Compare Register2. OCF2A is cleared by hardware when executing the corresponding interrupt handling vector. Alternatively, OCF2A is cleared by writing a logic one to the flag. When the I-bit in SREG, OCIE2A (Timer/Counter2 Compare Match Interrupt Enable), and OCF2A are set (one), the Timer/Counter2 Compare Match Interrupt is executed. • Bit 0 – TOV2 - Timer/Counter2 Overflow Flag The TOV2 bit is set (one) when an overflow occurs in Timer/Counter2. TOV2 is cleared by hardware when executing the corresponding interrupt handling vector. Alternatively, TOV2 is cleared by writing a logic one to the flag. When the SREG I-bit, TOIE2A (Timer/Counter2 Overflow Interrupt Enable), and TOV2 are set (one), the Timer/Counter2 Overflow in terrupt is executed. In PWM mode, this bit is set when Timer/Counter2 changes counting direction at 0x00. 21.11.3 TCCR2A – Timer/Counter2 Control Register A Bit 7 6 5 4 3 2 1 0 NA ($B0) COM2A1 COM2A0 COM2B1 COM2B0 Res1 Res0 WGM21 WGM20 TCCR2A Read/Write RW RW RW RW R R RW RW Initial Value 0 0 0 0 0 0 0 0 • Bit 7:6 – COM2A1:0 - Compare Match Output A Mode These bits control the Out p ut Compare pin (OC2A) behavior. If one or both of the COM2A1:0 bits are set, the OC2A output overrides the normal port functionality of the I/O pin it is connected to. However, note that the Data Direction Register (DDR) bit corresponding to the OC2A pin must be set in order to enable the output driver. When OC2A is connected to the pin, the function of the COM2A1:0 bits depends on the WGM22:20 bit settings. The following table shows the COM2A1:0 bit functionality when the WGM22:20 bits are set to a normal or CTC mode (non-PWM). Refer to section "Compare Match Output Unit" for a description of the functionality in the other modes. Table 21-7 COM2A Register Bits Register Bits Value Description COM2A1:0 0 Normal port operation, OC2A disconnected 1 Toggle OC2A on Compare Match 2 Clear OC2A on Compare Match 357 8393C-MCU Wireless-09/14

Register Bits Value Description 3 Set OC2A on Compare Match • Bit 5:4 – COM2B1:0 - Compare Match Output B Mode These bits control the Output Compare pin (OC2B) behavior. If one or both of the COM2B1:0 bits are set, the OC2B output overrides the normal port functionality of the I/O pin it is connected to. However, note that the Data Direction Register (DDR) bit corresponding to the OC2B pin must be set in order to enable the output driver. When OC2B is connected to the pin, the function of the COM2B1:0 bits depends on the WGM22:20 bit settings. The following table shows the COM2B1:0 bit functionality when the WGM22:20 bits are set to a normal or CTC mode (non-PWM). Refer to section "Compare Match Output Unit" for a description of the functionality in the other modes. Table 21-8 COM2B Register Bits Register Bits Value Description COM2B1:0 0 Normal port operation, OC2B disconnected 1 Toggle OC2B on Compare Match 2 Clear OC2B on Compare Match 3 Set OC2B on Compare Match • Bit 3:2 – Res1:0 - Reserved • Bit 1:0 – WGM21:20 - Waveform Generation Mode Combined with the WGM22 bit found in the TCCR2B Register, these bits control the counting sequence of the counter, the source for maximum (TOP) counter value, and what type of waveform generation to be used. Modes of operation supported by the Timer/Counter2 unit are: Normal mode (counter), Clear Timer on Compare Match (CTC) mode, and two types of Pulse Width Modulation (PWM) modes (see section "Modes of Operation" for details). Table 21-9 WGM2 Register Bits Register Bits Value Description WGM22:20 0x0 Normal mode of operation 0x1 PWM, phase correct, TOP=0xFF 0x2 CTC, TOP = OCRA 0x3 Fast PWM, TOP=0xFF 0x4 Reserved 0x5 PWM, Phase correct, TOP = OCRA 0x6 Reserved 0x7 Fast PWM, TOP=OCRA 21.11.4 TCCR2B – Timer/Counter2 Control Register B Bit 7 6 5 4 3 2 1 0 NA ($B1) FOC2A FOC2B Res1 Res0 WGM22 CS22 CS21 CS20 TCCR2B Read/Write RW RW RW RW RW RW RW RW Initial Value 0 0 0 0 0 0 0 0 • Bit 7 – FOC2A - Force Output Compare A ATmega256/128/64RFR2 358 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 The FOC2A bit is only active when the WGM bits specify a non-PWM mode. However, for ensuring compatibility with future devices, this bit must be set to zero when TCCR2B is written in PWM mode operation. When writing a logical one to the FOC2A bit, an immediate Compare Match is forced on the Waveform Generation unit. The OC2A output is changed according to its COM2A1:0 bits setting. Note that the FOC2A bit is implemented as a strobe. Therefore it is the value present in the COM2A1:0 bits that determines the effect of the forced compare. A FOC2A strobe will not generate any interrupt, nor will it clear the timer in CTC mode using OCR2A as TOP. The FOC2A bit is always read as zero. • Bit 6 – FOC2B - Force Output Compare B The FOC2B bit is only active when the WGM bits specify a non-PWM mode. However, for ensuring compatibility with future devices, this bit must be set to zero when TCCR2B is written in PWM mode operation. When writing a logical one to the FOC2B bit, an immediate Compare Match is forced on the Waveform Generation unit. The OC2B output is changed according to its COM2B1:0 bits setting. Note that the FOC2B bit is implemented as a strobe. Therefore it is the value present in the COM2B1:0 bits that determines the effect of the forced compare. A FOC2B strobe will not generate any interrupt, nor will it clear the timer in CTC mode using OCR2B as TOP. The FOC2B bit is always read as zero. • Bit 5:4 – Res1:0 - Reserved • Bit 3 – WGM22 - Waveform Generation Mode Combined with the WGM21:20 bits found in the TCCR2A Register, this bit controls the counting sequence of the counter, the source for maximum (TOP) counter value, and what type of waveform generation to be used. See description of "TCCR2A - Timer/Counter2 Control Reg ister A" for details. • Bit 2:0 – CS22:20 - Clock Select The three Clock Select bits select the clock source to be used by the Timer/Counter2. If external pin modes are used for the Timer/Counter2, transitions on the T2 pin will clock the counter even if the pin is configured as an output. This feature allows software control of the counting. Table 21-10 CS2 Register Bits Register Bits Value Description CS22:20 0x00 No clock source (Timer/Counter2 stopped) 0x01 clkT2S/1 (no prescaling) 0x02 clkT2S/8 (from prescaler) 0x03 clkT2S/32 (from prescaler) 0x04 clkT2S/64 (from prescaler) 0x05 clkT2S/128 (from prescaler) 0x06 clkT2S/256 (from prescaler) 0x07 clkT2S/1024 (from prescaler) 21.11.5 TCNT2 – Timer/Counter2 Bit 7 6 5 4 3 2 1 0 NA ($B2) TCNT27:20 TCNT2 Read/Write RW RW RW RW RW RW RW RW Initial Value 0 0 0 0 0 0 0 0 359 8393C-MCU Wireless-09/14

The Timer/Counter Register gives direct access, both for read and write operations, to the 8-bit counter unit of the Timer/Counter2. Writing to the TCNT2 Register blocks (removes) the Compare Match on the following timer clock. Modifying the counter (TCNT2) while the counter is running, introduces a risk of missing a Compare Match between TCNT2 and the OCR2x Registers. • Bit 7:0 – TCNT27:20 - Timer/Counter2 Byte 21.11.6 OCR2A – Timer/Counter2 Output Compare Register A Bit 7 6 5 4 3 2 1 0 NA ($B3) OCR2A7:0 OCR2A Read/Write RW RW RW RW RW RW RW RW Initial Value 0 0 0 0 0 0 0 0 The Output Compare Register A contains an 8-bit value that is continuously compared with the counter value (TCN T2). A match can be used to generate an Output Compare interrupt, or to generate a waveform output on the OC2A pin. • Bit 7:0 – OCR2A7:0 - Output Compare Register 21.11.7 OCR2B – Timer/Counter2 Output Compare Register B Bit 7 6 5 4 3 2 1 0 NA ($B4) OCR2B7:0 OCR2B Read/Write RW RW RW RW RW RW RW RW Initial Value 0 0 0 0 0 0 0 0 The Output Compare Regis ter B contains an 8-bit value that is continuously compared with the counter value (TCNT2). A match can be used to generate an Output Compare interrupt, or to generate a waveform output on the OC2B pin. • Bit 7:0 – OCR2B7:0 - Output Compare Register 21.11.8 ASSR – Asynchronous Status Register Bit 7 6 5 4 3 2 1 0 NA ($B6) EXCLKAMR EXCLK AS2 TCN2UB OCR2AUB OCR2BUB TCR2AUB TCR2BUB ASSR Read/Write RW RW RW R R R R R Initial 0 0 0 0 0 0 0 0 The register ASSR controls the asynchronous clocks for Timer/Counter2 and enables the asynchronous 32kHz clock for the symbol counter. Three bits (AS2,EXCLK,EXCLKAMR) are used to control the clocks. Note, to prevent clock spikes on asynchronous clock wires, every access to ASSR should change only one of the three bits. • Bit 7 – EXCLKAMR - Enable External Clock Input for AMR ATmega256/128/64RFR2 360 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 The bit EXCLKAMR extends the available clock sources for Timer/Counter2. If this bit is written to one, and asynchronous clock is selected (bit AS2 set), AMR functionality is enabled and Timer/Counter2 is clocked by pin AMR. • Bit 6 – EXCLK - Enable External Clock Input When EXCLK is written to one, and asynchronous clock is selected, the external clock input buffer is enabled and an external clock can be input on Timer Oscillator 1 (TOSC1) pin instead of a 32 kHz crystal. Writing to EXCLK should be done before asynchronous operation is selected. Note that the crystal Oscillator will only run when this bit is zero. • Bit 5 – AS2 - Timer/Counter2 Asynchronous Mode When AS2 is written to zero, Timer/Counter2 is clocked from the I/O clock, clkI/O. When AS2 is written to one, Timer/Counter2 is clocked from a crystal Oscillator connected to the Timer Oscillator 1 (TOSC1) pin. When the value of AS2 is changed, the contents of TCNT2, OCR2A, OCR2B, TCCR2A and TCCR2B might be corrupted. • Bit 4 – TCN2UB - Timer/Counter2 Update Busy When Timer/Counter2 operates asynchronously and TCNT2 is written, this bit becomes set. When TCNT2 has been updated from the temporary storage register, this bit is cleared by hardware. A logical zero in this bit indicates that TCNT2 is ready to be updated with a new value. • Bit 3 – OCR2AUB - Timer/Counter2 Output Compare Register A Update Busy When Timer/Counter2 operates asynchronously and OCR2A is written, this bit becomes set. When OCR2A has been updated from the temporary storage register, this bit is cleared by hardware. A logical zero in this bit indicates that OCR2A is ready to be updated with a new value . • Bit 2 – OCR2BUB - Timer/Counter2 Output Compare Register B Update Busy When Timer/Counter2 operates asynchronously and OCR2B is written, this bit becomes set. When OCR2B has been updated from the temporary storage register, this bit is cleared by hardware. A logical zero in this bit indicates that OCR2B is ready to be updated with a new value. • Bit 1 – TCR2AUB - Timer/Counter2 Control Register A Update Busy When Timer/Counter2 operates asynchronously and TCCR2A is written, this bit becomes set. When TCCR2A has been updated from the temporary storage register, this bit is cleared by hardware. A logical zero in this bit indicates that TCCR2A is ready to be updated with a new value. • Bit 0 – TCR2BUB - Timer/Counter2 Control Register B Update Busy When Timer/Counter2 operates asynchronously and TCCR2B is written, this bit becomes set. When TCCR2B has been updated from the temporary storage register, this bit is cleared by hardware. A logical zero in this bit indicates that TCCR2B is ready to be updated with a new value. 21.11.9 GTCCR – General Timer Counter Control register Bit 7 6 5 4 3 2 1 0 $23 ($43) TSM PSRASY GTCCR Read/Write RW RW Initial Value 0 0 361 8393C-MCU Wireless-09/14

• Bit 7 – TSM - Timer/Counter Synchronization Mode Writing the TSM bit to one activates the Timer/Counter Synchronization mode. In this mode the value that is written to the PSRASY and PSRSYNC bits is kept, hence keeping the corresponding prescaler reset signals asserted. This ensures that the corresponding Timer/Counters are halted and can be configured to the same value without the risk of one of them advancing during the configuration. When the TSM bit is written to zero, the PSRASY and PSRSYNC bits are cleared by hardware and the Timer/Counters simultaneously start counting. • Bit 1 – PSRASY - Prescaler Reset Timer/Counter2 When this bit is one, the Timer/Counter2 prescaler will be reset. This bit is normally cleared immediately by hardware. If the bit is written when Timer/Counter2 is operating in asynchronous mode, the bit will remain one until the prescaler has been reset. The bit will not be cleared by hardware if the TSM bit is set. ATmega256/128/64RFR2 362 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 22 SPI- Serial Peripheral Interface 22.1 Features The Serial Peripheral Interface (SPI) allows high-speed synchronous data transfer between the ATmega256/128/64RFR2 and peripheral devices or between several AVR devices. The ATmega256/128/64RFR2 SPI includes the following features: • Full-duplex, Three-wire Synchronous Data Transfer • Master or Slave Operation • LSB First or MSB First Data Transfer • Seven Programmable Bit Rates • End of Transmission Interrupt Flag • Write Collision Flag Protection • Wake-up from Idle Mode • Double Speed (CK/2) Master SPI Mode 22.2 Functional Description USART can also be used in Master SPI mode, see "USART in SPI Mode" on page 401. The Power Reduction SPI bit, PRSPI, in "PRR0 – Power Reduction Register0" on page 197 must be written to zero to enable SPI module. The block diagram of the SPI interface is shown in Figure 22-1 on page 364. The interconnection between Master and Slave CPUs with SPI is shown in Figure 22-2 on page 364. The system consists of two shift Registers, and a Master clock generat_o_r. The SPI Master initiates the communication cycle when pulling low the Slave Select SS pin of the desired Slave. Master and Slave prepare the data to be sent in their respective shift Registers, and the Master generates the required clock pulses on the SCK line to interchange data . Data is always shifted from Master to Slave on the Master Out – Slave In, MOSI, line, and from Slave to Master on the Master In – Slave Out, MISO, line. After each_ _data packet, the Master will synchronize the Slave by pulling high the Slave Select, SS, line. __ When configured as a Master, the SPI interface has no automatic control of the SS line. This must be handled by user software before communication can start. When this is done, writing a byte to the SPI Data Register starts the SPI clock generator, and the hardware shifts the eight bits into the Slave. After shifting one byte, the SPI clock generator stops, setting the end of Transmission Flag (SPIF). If the SPI Interrupt Enable bit (SPIE) in the SPCR Register is set, an interrupt is requested. The Master may continue to shift the next byte_ b_y writing it into SPDR, or signal the end of packet by pulling high the Slave Select, SS line. The last incoming byte will be kept in the Buffer Register for later use. When configure_d_ as a Slave, the SPI interface will remain sleeping with MISO tri-stated as long as the SS pin is driven high. In this state, software may update the contents of the SPI Data Register, SPDR, but the data will not be shifted out by incoming clock pulses on the SCK pin until the SS pin is driven low. As one byte has been completely shifted, the end of Transmission Flag, SPIF is set. If the SPI Interrupt Enable bit, SPIE, in the SPCR Register is set, an interrupt is requested. The Slave may continue to place new data to be sent into SPDR before reading the incoming data. The last incoming byte will be kept in the Buffer Register for later use. 363 8393C-MCU Wireless-09/14

Figure 22-1. SPI Block Diagram(1) DIVIDER(cid:13) /2/4/8/16/32/64/128 X 2 PI S X 2 PI S Note: 1. Refer to Figure 1- 1 on page 2 and Table 14-3 on page 226 for SPI pin placement. Figure 22-2. SPI Master-slave Interconnection SHIFT(cid:13) ENABLE The system is single buffered in the transmit direction and double buffered in the receive direction. This means that bytes to be transmitted cannot be written to the SPI Data Register before the entire shift cycle is completed. When receiving data, however, a received character must be read from the SPI Data Register before the next character has been completely shifted in. Otherwise, the first byte is lost. In SPI Slave mode, the ATmega256/128/64RFR2 364 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 control logic will sample the incoming signal of the SCK pin. To ensure correct sampling of the clock signal, the minimum low and high periods should be: Low period: longer than 2 CPU clock cycles High period: longer than 2 CPU clock cycles __ When the SPI is enabled, the data direction of the MOSI, MISO, SCK, and SS pins is overridden according to Table 21-1. For more details on automatic port overrides, refer to "Alternate Port Functions" on page 224. (1) Table 22-1. Pin Overrides Pin Direction, Master SPI Direction, Slave SPI MOSI User Defined Input MISO Input User Defined SCK User Defined Input SS User Defined Input Note: 1. See "Alternate F unctions of Port B" on page 225 for a detailed description of how to define the direction of the user defined SPI pins. The following code examples show how to initialize the SPI as a Master and how to perform a simple transmission. DDR_SPI in the examples must be replaced by the actual Data Direction Register controlling the SPI pins. DD_MOSI, DD_MISO and DD_SCK must be replaced by the actual data direction bits for these pins. E.g. if MOSI is placed on pin PB5, replace DD_MOSI with DDB5 and DDR_SPI with DDRB. Assembly Code Example(1) SPI_MasterInit: ; Set MOSI and SCK output, all others input ldi r17,(1<<DD_MOSI)|(1<<DD_SCK) out DDR_SPI,r17 ; Enable SPI, Master, set clock rate fck/16 ldi r17,(1<<SPE)|(1<<MSTR)|(1<<SPR0) out SPCR,r17 ret SPI_MasterTransmit: ; Start transmission of data (r16) out SPDR,r16 Wait_Transmit: ; Wait for transmission complete sbis SPSR,SPIF rjmp Wait_Transmit ret 365 8393C-MCU Wireless-09/14

C Code Example(1) void SPI_MasterInit(void) { /* Set MOSI and SCK output, all others input */ DDR_SPI = (1<<DD_MOSI)|(1<<DD_SCK); /* Enable SPI, Master, set clock rate fck/16 */ SPCR = (1<<SPE)|(1<<MSTR)|(1<<SPR0); } void SPI_MasterTransmit(char cData) { /* Start transmiss ion */ SPDR = cData; /* Wait for transmission complete */ while(!(SPSR & (1<<SPIF))) ; } Note: 1. See "About Code Examples" on page 7 Assembly Code Example(1) SPI_SlaveInit: ; Set MISO output, all others input ldi r17,(1<<DD_MISO) out DDR_SPI,r17 ; Enable SPI ldi r17,(1<<SPE) out SPCR,r17 ret SPI_SlaveReceive: ; Wait for reception complete sbis SPSR,SPIF rjmp SPI_SlaveReceive ; Read received data and return in r16,SPDR ret ATmega256/128/64RFR2 366 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 C Code Example(1) void SPI_SlaveInit(void) { /* Set MISO output, all others input */ DDR_SPI = (1<<DD_MISO); /* Enable SPI */ SPCR = (1<<SPE); } char SPI_SlaveReceive(void) { /* Wait for recepti on complete */ while(!(SPSR & (1<<SPIF))) ; /* Return Data Register */ return SPDR; } Note: 1. See "About Code Examples" on page 7; __ 22.3 Pin Functionality Slave Select Pin SS 22.3.1 Slave Mode __ W__hen the SPI is configured as a Slave, the Slave Select (SS) pin is always input. When SS is held low, the SPI is activated, and M__ISO becomes an output if configured so by the user. All other pins are inputs. When SS is driven high, all pins are inputs, and the SPI is passive, which mean_s_ that it will not receive inc_o_ming data. Note that the SPI logic will be reset once the SS pin is driven high. The SS pin is useful for packet/byte synchronization to ke_e_p the slave bit counter synchronous with the master clock generator. When the SS pin is driven high, the SPI slave will immediately reset the send and receive logic, and drop any partially received data in the Shift Register. 22.3.2 Master Mode When the SPI is configured a_s_ a Maste_r_ (MSTR in SPCR is set), the user can determine the direction of the SS pin. If SS is configured as an output, the pin is a general out_p_ut pin which does not a_ff_ect the SPI system. Typically, the pin will be driving the SS pin of the SPI Slave. If S_S_ is configured as an input, it must be held high to ensure Master SPI operation. If the SS p_in_ is driven low by peripheral circuitry when the SPI is configured as a Master with the SS pin defined as an input, the SPI system interprets this as another master selecting the SPI as a slave and starting to send data to it. To avoid bus contention, the SPI system takes the following actions: 1. The MSTR bit in SPCR is cleared and the SPI system becomes a Slave. As a result of the SPI becoming a Slave, the MOSI and SCK pins become inputs. 2. The SPIF Flag in SPSR is set, and if the SPI interrupt is enabled, and the I-bit in SREG is set, the interrupt routine will be executed. Thus, when interr_u_pt-driven SPI transmission is used in Master mode, and there exists a possibility that SS is driven low, the interrupt should always check that the MSTR bit is still set. If the MSTR bit has been cleared by a slave select, it must be set by the user to re-enable SPI Master Mode. 367 8393C-MCU Wireless-09/14

22.3.3 Data Mode There are four combinations of SCK phase and polarity with respect to serial data, which are determined by control bits CPHA and CPOL. The SPI data transfer formats are shown in Figure 22-3 b elow and Figure 22-4 below. Data bits are shifted out and latched in on opposite edges of the SCK signal, ensuring sufficient time for data signals to stabilize. This is clearly seen in the summary of Table 22-2 below: Table 22-2. CPOL Functionality Leading Edge Trailing Edge SPI Mode CPOL=0, CPHA=0 Sample (Rising) Setup (Falling) 0 CPOL=0, CPHA=1 Setup (Rising) Sample (Falling) 1 CPOL=1, CPHA=0 Sample (Falling) Setup (Rising) 2 CPOL=1, CPHA=1 Setup (Falling) Sample (Rising) 3 Figure 22-3. SPI Transfer Format with CPHA = 0 SCK (CPOL = 0) mode 0 SCK (CPOL = 1) mode 2 SAMPLE I MOSI/MISO CHANGE 0 MOSI PIN CHANGE 0 MISO PIN SS MSB first (DORD = 0) MSB Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 LSB LSB first (DORD = 1) LSB Bit 1 Bit 2 Bit 3 Bit 4 Bit 5 Bit 6 MSB Figure 22-4. SPI Transfer Format with CPHA = 1 SCK (CPOL = 0) mode 1 SCK (CPOL = 1) mode 3 SAMPLE I MOSI/MISO CHANGE 0 MOSI PIN CHANGE 0 MISO PIN SS MSB first (DORD = 0) MSB Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 LSB LSB first (DORD = 1) LSB Bit 1 Bit 2 Bit 3 Bit 4 Bit 5 Bit 6 MSB ATmega256/128/64RFR2 368 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 22.4 Register Description 22.4.1 SPCR – SPI Control Register Bit 7 6 5 4 3 2 1 0 $2C ($4C) SPIE SPE DORD MSTR CPOL CPHA SPR1 SPR0 SPCR Read/Write RW RW RW RW RW RW RW RW Initial Value 0 0 0 0 0 0 0 0 • Bit 7 – SPIE - SPI Interrupt Enable This bit causes the SPI interrupt to be executed if SPIF bit in the SPSR Register is set and the if the Global Interrupt Enable bit in SREG is set.s • Bit 6 – SPE - SPI Enable When the SPE bit is set (one), the SPI is enabled. This bit must be set to enable any SPI operations. • Bit 5 – DORD - Data Order When the DORD bit is written to one, the LSB of the data word is transmitted first. When the DORD bit is written to zero, the MSB of the data word is transmitted first. • Bit 4 – MSTR - Master/Slave Select This bit selects Master SPI mode when written to one, and Slave SPI mode when written logic zero. If the Slave Select pin is configured as an input and is driven low while MSTR is set, MSTR w ill be cleared and SPIF in SPSR are set. The user will then have to set MSTR to re-enable SPI Master mode. • Bit 3 – CPOL - Clock polarity When this bit is written to one, SCK is high when idle. When CPOL is written to zero, SCK is low when idle. Refer to the "Data Modes" section for an example. The CPOL functionality is summarized below. Table 22-3 CPOL Register Bits Register Bits Value Description CPOL 0 Rising (Leading Edge), Falling (Trailing Edge) 1 Falling (Leading Egde), Rising (Trailing Edge) • Bit 2 – CPHA - Clock Phase The settings of the Clock Phase bit (CPHA) determine if data is sampled on the leading (first) or trailing (last) edge of SCK. Refer to the "Data Modes" section for an example. The CPOL functionality is summarized below. Table 22-4 CPHA Register B its Register Bits Value Description CPHA 0 Sample (Leading Edge), Setup (Trailing Edge) 1 Setup (Leading Edge), Sample (Trailing Edge) • Bit 1:0 – SPR1:0 - SPI Clock Rate Select 1 and 0 369 8393C-MCU Wireless-09/14

These two bits control the SCK rate of the device configured as a Master. SPR1 and SPR0 have no effect on the Slave. The relationship between SCK and the Oscillator Clock frequency fosc is shown in the following table. Table 22-5 SPR Register B its Register Bits Value Description SPR1:0 0x00 fosc/4 / fosc/2 (SPI2X=0/1) 0x01 fosc/16 / fosc/8 (SPI2X=0/1) 0x02 fosc/64 / fosc/32 (SPI2X=0/1) 0x03 fosc/128 / fosc/64 (SPI2X=0/1) 22.4.2 SPSR – SPI Status Register Bit 7 6 5 4 3 2 1 0 $2D ($4D) SPIF WCOL Res4 Res3 Res2 Res1 Res0 SPI2X SPSR Read/Write R R R R R R R RW Initial Value 0 0 0 0 0 0 0 0 • Bit 7 – SPIF - SPI Interrupt Flag When a serial transfer is complete, the SPIF Flag is set. An interrupt is generated if SPIE in SPCR is set and global interrupts are enabled. The SPIF Flag is also set if the Slave Select pin is an input and is driven low when the SPI is in Master mode. SPIF is cleared by hardware when executing the corresponding interrupt handling vector. Alternatively, the SPIF bit is cleared by first reading the SPI Status Register with SPIF set and then accessing the SPI Data Register (SPDR). • Bit 6 – WCOL - Write Collision Flag The WCOL bit is set if the SPI Data Register (SPDR) is written during a data transfer. The WCOL bit (and the SPIF bit) are cleared by first reading the SPI Status Register with WCOL set and then accessing the SPI Data Register. • Bit 5:1 – Res4:0 - Reserved • Bit 0 – SPI2X - Double SPI Speed Bit When this bit is written logic one the SPI speed (SCK Frequency) will be doubled when the SPI is in Master mode. This means that the minimum SCK period will be two CPU clock periods. When the SPI is configured as Slave, the SPI is only guaranteed to work at fosc/4 or lower. The SPI interface is also used for program memory and EEPROM downloading or uploading. See section "Serial Downloading" for serial programming and verification. 22.4.3 SPDR – SPI Data Register Bit 7 6 5 4 3 2 1 0 $2E ($4E) SPDR7:0 SPDR Read/Write RW RW RW RW RW RW R R Initial Value X X X X X X 0 0 ATmega256/128/64RFR2 370 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 The SPI Data Register is a read/write register used for data transfer between the Register File and the SPI Shift Register. Writing to the register initiates data transmission. Reading the register causes the Shift Register Receive buffer to be read. • Bit 7:0 – SPDR7:0 - SPI Data Register 371 8393C-MCU Wireless-09/14

23 USART 23.1 Features • Full duplex operation (independent serial receive and transmit registers) • Asynchronous or synchronous operation • Master or slave clocked synchronous operation • High resolution baud rate generator • Supports serial frames with 5, 6, 7, 8, or 9 data bits and 1 or 2 stop bits • Odd or even parity generation and parity check supported by hardware • Data overrun detection • Framing error detection • Noise filtering includes false start bit detection and digital low pass filter • 3 separate interrupts on TX complete, TX data register empty and RX complete • Multi-processor communication mode • Double speed, asynchronous communication mode 23.2 Overview The Universal Synchronous and Asynchronous Serial Receiver and Transmitter (USART) is a highly flexible serial communication device. The ATmega256/128/64RFR2 has two USART’s, USART0 and USART1. The functionality for all two USART’s is described below. USART0 and USART1 have different I/O registers as shown in "Register Summary" on page 543. A simplified block diagram of the USART transmitter is shown in Figure 23-1 on page 373 on page 373. CPU accessible I/O registers and I/O pins are shown in bold. The Power Reduction USART0 bit, PRUSART0, in "PRR0 – Power Reduction Register0" on page 197 m ust be disabled by writing a logical zero to it. The Power Reduction USART1 bit, PRUSART1, in "PRR1 – Power Reduction Register 1" on page 198 must be disabled by writing a logical zero to it. The dashed boxes in the block diagram Figure 23-1 on page 373 separate the three main parts of the USART (listed from the top): clock generator, transmitter and receiver. Control registers are shared by all units. The clock generation logic consists of synchronization logic for external clock input used by synchronous slave operation, and the baud rate generator. The XCKn (transfer clock) pin is only used by synchronous transfer mode. The transmitter consists of a single write buffer, a serial shift register, Parity generator and control logic for handling different serial frame formats. The write buffer allows a continuous transfer of data without any delay between frames. The receiver is the most complex part of the USART module due to its clock and data recovery units. The recovery units are used for asynchronous data reception. In addition to the recovery un its, the receiver includes a parity checker, control logic, a shift register and a two level receive buffer (UDRn). The receiver supports the same frame formats as the transmitter, and can detect frame, data overrun and parity errors. ATmega256/128/64RFR2 372 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 Figure 23-1. USART Block Diagram(1) Clock Generator UBRR[H:L] OSC BAUD RATE GENERATOR SYNC LOGIC PIN XCK CONTROL Transmitter TX UDR (Transmit) CONTROL S PARITY U GENERATOR B PIN A TRANSM IT SHIFT REGISTER CONTROL TxD T A D Receiver CLOCK RX RECOVERY CONTROL DATA PIN RECEIVE SHIFT REGISTER RxD RECOVERY CONTROL PARITY UDR (Receive) CHECKER UCSRA UCSRB UCSRC Note: 1. See Figure 1-1 on page 2, Table 14-6 on page 228 and Table 14-9 on page 230Table 14-9 on page 230for USART pin placement. 23.3 Clock Generation The clock generation logic generates the base clock for the transmitter and receiver. The USART supports four modes of clock operation: Normal asynchronous, double speed asynchronous, master synchronous and slave synchronous mode. The UMSELn bit in USART Control and Status Register C (UCSRnC) selects between asynchronous and synchronous operation. Double speed (asynchronous mode only) is controlled by the U2Xn found in the UCS RnA register. When using synchronous mode (UMSELn = 1), the data direction register for the XCKn pin (DDR_XCKn) controls whether the clock source is internal (master mode) or external (slave mode). The XCKn pin is only active when using synchronous mode. 373 8393C-MCU Wireless-09/14

Figure 22-2 on page 364 shows a block diagram of the clock generation logic. Figure 23-2. Clock Generation Logic, Block Diagram UBRR U2X fosc Prescaling UBRR+1 /2 /4 /2 Down-Counter 0 1 0 OSC txclk 1 DDR_XCK Sync Edge xcki Register Detector 0 XCK xcko 1 UMSEL Pin DDR_XCK UCPOL 1 rxclk 0 Signal description: txclk Transmitter clock (internal signal). rxclk Receiver base clock (internal signal). xcki Input from XCK pin (internal signal). Used for synchronous slave operation. xcko Clock output to XCK pin (internal signal). Used for synchronous master operation. f System clock frequency. OSC 23.3.1 Internal Clock Generation – The Baud Rate Generat or Internal clock generation is used for the asynchronous and the synchronous master modes of operation. The description in this section refers to Figure 22-2 on page 364. The USART Baud Rate Register (UBRRn) and the down-counter connected to it function as a programmable prescaler or baud rate generator. The down-counter, running at system clock (f ), is loaded with the UBRRn value each time the counter OSC has counted down to zero or when the UBRRLn register is written. A clock is generated each time the counter reaches zero. This clock is the baud rate generator clock output (= f /(UBRRn+1)). The transmitter divides the baud rate generator clock output by 2, OSC 8 or 16 depending on mode. The baud rate generator output is used directly by the receiver’s clock and data recovery units. However, the recovery units use a state machine that uses 2, 8 or 16 states depending on mode set by the state of the UMSELn, U2Xn and DDR_XCKn bits. Table 23-1 below contains equations for calculating the baud rate (in bits per second) and for calculating the UBRRn value for each mode of operation using an internally generated clock source. Table 23-1. Equations for Calculating Baud Rate Register Setting Operating Mode Equation for Calculating Equation for Calculating Baud Rate(1) UBRR Value Asynchronous Normal Mode f f (U2Xn = 0) BAUD= OSC U B R Rn = OSC −1 16(UBRRn+1) 16BAUD Asynchronous Double Speed f f Mode (U2Xn = 1) BAUD= OSC UBRRn= OSC −1 8(UBRRn+1) 8BAUD ATmega256/128/64RFR2 374 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 Operating Mode Equation for Calculating Equation for Calculating Baud Rate(1) UBRR Value Synchronous Master Mode f f BAUD= OSC UBRRn= OSC −1 2(UBRRn+1) 2BAUD Note: 1. The baud rate is defined to be the transfer rate in bit per second (bps). BAUD Baud rate (in bits per second, bps) f System oscillator clock frequency OSC UBRRn Contents of the UBRRHn and UBRRLn registers, (0-4095) Some examples of UBRRn values for some system clock frequencies are found in Table 23-14 on page 398. 23.3.2 Double Speed Operation (U2Xn) The transfer rate can be doubled by setting the U2Xn bit in UCSRnA. Setting this bit only has effect for the asynchronous operation. Set this bit to zero when using synchronous operation. Setting this bit will reduce the divisor of the baud rate divider from 16 to 8, effectively doubling the transfer rate for asynchronous communication. Note however that the receiver will in this case only use half the number of samples (reduced from 16 to 8) for data sampling and clock recovery, and therefore a more accurate baud rate setting and system clock are required when this mode is used. For the transmitter, there are no downsides. 23.3.3 External Clock External clocking is used by the synchronous slave modes of operation. The description in this section refers to Figure 22-2 on page 364 for details. External clock input from the XCKn pin is sampled by a synchronization register to minimize the chance of m e ta-stability. The output from the synchronization register must then pass through an edge detector before it can be used by the transmitter and receiver. This process introduces a two CPU clock period delay and therefore the maximum external XCKn clock frequency is limited by the following equation: f f < OSC XCK 4 Note that f depends on the stability of the system clock source. It is therefore OSC recommended to add some margin to avoid possible loss of data due to frequency variations. 23.3.4 Synchronous Clock Operation When synchronous mode is used (UMSELn = 1), the XCKn pin will be used as either clock input (slave) or clock output (master). The dependency between the clock edges and data sampling or data change is the same. The basic principle is that data input (on RxDn) is sampled at the opposite XCKn clock edge of the edge the data output (TxDn) is changed. 375 8393C-MCU Wireless-09/14

Figure 23-3. Synchronous Mode XCKn Timing UCPOL = 1 XCK RxD / TxD Sample UCPOL = 0 XCK RxD / TxD Sample The UCPOLn bit UCRSC selects which XCKn clock edge is used for data sampling and which is used for data change. As Figure 22-3 on page 368 shows, when UCPOLn is zero the data will be changed at rising XCKn edge and sampled at falling XCKn edge. If UCPOLn is set, the data will be changed at falling XCKn edge and sampled at rising XCKn edge. 23.4 Frame Formats A serial frame is defined to be one character of data bits with synchronization bits (start and stop bits), and optionally a parity bit for error checking. The USART accepts all 30 combinations of the following as valid frame formats: • 1 start bit • 5, 6, 7, 8, or 9 data bits • no, even or odd parity bit • 1 or 2 stop bits A frame starts with the start bit followed by the least significant data bit. Then the next data bits, up to a total of nine, are succeeding, ending with the most significant bit. If enabled, the parity bit is inserted after the data bits, before the stop bits. When a complete frame is transmitted, it can be directly followed by a new frame, or the communication line can be set to an idle (high) state. Figure 23-4 below illustrates the possible combinations of the frame formats. Bits inside brackets are optional. Figure 23-4. Frame Formats FRAME (IDLE) St 0 1 2 3 4 [5] [6] [7] [8] [P] Sp1 [Sp2] (St / IDLE) St Start bit, always low (n) Data bits (0 to 8) P Parity bit - can be odd or even Sp Stop bit, always high IDLE No transfers on the communication line (RxDn or TxDn). An IDLE line must be high The frame format used by the USART is set by the UCSZn2:0, UPMn1:0 and USBSn bits in UCSRnB and UCSRnC. The receiver and transmitter use the same setting. Note that changing the setting of any of these bits will corrupt all ongoing communication for both the receiver and transmitter. ATmega256/128/64RFR2 376 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 The USART Character Size (UCSZn2:0) bits select the number of data bits in the frame. The USART Parity Mode (UPMn1:0) bits enable and set the type of parity bit. The selection between one or two stop bits is done by the USART Stop Bit Select (USBSn) bit. The receiver ignores the second stop bit. A frame error will therefore only be detected in cases where the first stop bit is zero. 23.4.1 Parity Bit Calculation The parity bit is calculated by doing an exclusive-or of all the data bits. If odd parity is used, the result of the exclusive or is inverted. The parity bit is located between the last data bit and first stop bit of a serial frame. The relation between the parity bit and data bits is as follows: P = d ⊕K⊕d ⊕d ⊕d ⊕d ⊕0 even n−1 3 2 1 0 P = d ⊕K⊕d ⊕d ⊕d ⊕d ⊕1 odd n−1 3 2 1 0 P Parity bit using even parity even P Parity bit using odd parity odd d Data bit n of the character n 23.5 USART Initialization The USART has to be initialized before any communication can take place. The initialization process normally consists of setting the baud rate, setting frame format and enabling the transmitter or the receiver depending on the usage. For interrupt driven USART operation, the global interrupt flag should be cleared (and interrupts globally disabled) when doing the initialization. Before doing a re-initialization with changed baud rate or frame format, be sure that there are no ongoing transmissions during the period the registers are changed. The TXCn flag can be used to check that the transmitter has completed all transfers, and the RXC flag can be used to check that there are no unread data in the receive buffer. Note that the TXCn flag must be cleared before each transmission (before UDRn is written) if it is used for this p urpose. The following simple USART initialization code examples show one assembly and one C function that are equal in functionality. The examples assume asynchronous operation using polling (no interrupts enabled) and a fixed frame format. The baud rate is given as a function parameter. For the assembly code, the baud rate parameter is assumed to be stored in the r17:r16 Registers. Assembly Code Example(1) USART_Init: ; Set baud rate out UBRRnH, r17 out UBRRnL, r16 ; Enable receiver and transmitter ldi r16, (1<<RXENn)|(1<<TXENn) out UCSRnB,r16 ; Set frame format: 8data, 2stop bit ldi r16, (1<<USBSn)|(3<<UCSZn0) out UCSRnC,r16 ret 377 8393C-MCU Wireless-09/14

C Code Example(1) #define FOSC 8000000// Clock Speed #define BAUD 9600 #define (MYUBRR FOS C/16/BAUD-1) void main( void ) {... USART_Init ( MYUBRR ); ...} // main void USART_Init( unsigned int ubrr){ /* Set baud rate */ UBRRnH = (unsigned char)(ubrr>>8); UBRRnL = (unsigned char) ubrr; /* Enable receiver and transmitter */ UCSRnB = (1<<RXEN)|(1<<TXEN); /* Set frame format: 8data, 2stop bit */ UCSRnC = (1<<USBS)| (3<<UCSZ0); } // USART_Init Note: 1. See "About Code Examples" on page 7 More advanced initialization routines can be made that include frame format as parameters, disable interrupts and so on. However, many applications use a fixed setting of the baud and control registers, and for these types of applications the initialization code can be placed directly in the main routine, or be combined with initialization code for other I/O modules. 23.6 Data Transmission – The USART Transmitter The USART transmitter is enabled by setting the Transmit Enable (TXEN) bit in the UCSRnB register. When the transmitter is enabled, the normal port operation of the TxDn pin is overridden by the USART and gives the function as the transmitter’s serial output. The baud rate, mode of operation and frame format must be set up once before doing any transmissions. If synchronous operation is used, the clock on the XCKn pin will be overridden and used as transmission clock. 23.6.1 Sending Frames with 5 to 8 Data Bit A data transmission is initiated by loading the transmit buffer with the data to be transmitted. The CPU can load the transmit buffer by writing to the UDRn I/O location. The buffered data in the transmit buffer will be moved to the shift register when the shift register is ready to send a new frame. The shift register is loaded with new data if it is in idle state (no ongoing transmission) or immediately after the last stop bit of the previous frame is transmitted. When the shift register is loaded with new data, it will transfer one complete frame at the rat e given by the baud rate register, U2Xn bit or by XCKn depending on mode of operation. The following code examples show a simple USART transmit function based on polling of the Data Register Empty Flag (UDREn). When using frames with less than eight bits, the most significant bits written to the UDRn are ignored. The USART has to be initialized before the function can be used. For the assembly code, the data to be sent is assumed to be stored in register r16. ATmega256/128/64RFR2 378 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 Assembly Code Example(1) USART_Transmit: ; Wait for empty transmit buffer sbis UCSRnA,UDREn r jmp USART_Transmit ; Put data (r16) into buffer, sends the data out UDRn,r16 ret C Code Example(1) void USART_Transmit( unsigned char data ) { /* Wait for empty transmit buffer */ while ( !( UCSRnA & (1<<UDREn)) ); /* Put data into buffer, sends the data */ UDRn = data; } Note: 1. See "About Code Examples" on page 7 The function simply waits for the transmit buffer to be empty by checking the UDREn flag, before loading it with new data to be transmitted. If the data register empty interrupt is utilized, the interrupt routine writes the data into the buffer. 23.6.2 Sending Frames with 9 Data Bit If 9 bit characters are used ( UCSZn2:0 = 7), the ninth bit must be written to the TXB8 bit in UCSRnB before the low byte of the character is written to UDRn. The following code examples show a transmit function that handles 9 bit characters. For the assembly code, the data to be sent is assumed to be stored in registers r17:r16. Assembly Code Example(1)(2 ) USART_Transmit: ; Wait for empty transmit buffer sbis UCSRnA,UDREn rjmp USART_Transmit ; Copy 9th bit from r17 to TXB8 cbi UCSRnB,TXB8 sbrc r17,0 sbi UCSRnB,TXB8 ; Put LSB data (r16) into buffer, sends the data out UDRn,r16 ret 379 8393C-MCU Wireless-09/14

C Code Example(1)(2) void USART_Transmit( unsigned int data ) { /* Wait for empty transmit buffer */ while ( !( UCSRnA & (1<<UDREn))) ); /* Copy 9th bit to TXB8 */ UCSRnB &= ~(1<<TXB8); if ( data & 0x0100 ) UCSRnB |= (1<<TXB8); /* Put data into buffer, sends the data */ UDRn = data; } Note: 1. These transmit functions are written to be general functions. They can be optimized if the content of the UCSRnB is static. For example, only the TXB8 bit of the UCSRnB register is used after initialization. 2. See "About Cod e Examples" on page 7 The 9th bit can be used for indicating an address frame when using multi processor communication mode or for other protocol handling as for example synchronization. 23.6.3 Transmitter Flags and Interrupts The USART transmitter has two flags that indicate its state: USART Data Register Empty (UDREn) and Transmit Complete (TXCn). Both flags can be used for generating interrupts. The Data Register Empty Flag (UDREn) indicates whether the transmit buffer is ready to receive new data. This bit is set when the transmit buffer is empty, and cleared when the transmit buffer contains data to be transmitted that has not yet been moved into the shift register. For compatibility with future devices, always write this bit to zero when writing the UCSRnA registe r. When the USART Data Register Empty Interrupt Enable (UDRIEn) bit in UCSRnB is written to one, the USART data register empty interrupt will be executed as long as UDREn is set (provided that global interrupts are enabled). UDREn is cleared by writing UDRn. When interrupt-driven data transmission is used, the data register empty interrupt routine must either write new data to UDRn in order to clear UDREn or disable the data register empty interrupt, otherwise a new interrupt will occur once the interrupt routine terminates. The Transmit Complete Flag (TXCn) bit is set one when the entire frame in the transmit shift register has been shifted out and there are no new data currently present in the transmit buffer. The TXCn flag bit is automatically cleared when a transmission complete interrupt is executed, or it can be cleared by writing a one to its bit location. The TXCn flag is useful in half-duplex communication interfaces (like the RS-485 standard), where a transm itting application must enter receive mode and free the communication bus immediately after completing the transmission. When the Transmission Complete Interrupt Enable (TXCIEn) bit in UCSRnB is set, the USART transmission complete interrupt will be executed when the TXCn flag becomes set (provided that global interrupts are enabled). When the transmission complete interrupt is used, the interrupt handling routine does not have to clear the TXCn flag. This is done automatically when the interrupt is executed. ATmega256/128/64RFR2 380 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 23.6.4 Parity Generator The parity generator calculates the parity bit for the serial frame data. When parity bit is enabled (UPMn1 = 1), the transmitter control logic inserts the parity bit between the last data bit and the first stop bit of the frame that is sent. 23.6.5 Disabling the Transmitter The disabling of the transmitter (setting the TXEN to zero) will not become effective until ongoing and pending transmissions are completed, i.e., when the transmit shift register and transmit buffer register do not contain data to be transmitted. The transmitter will no longer override the TxDn pin when disabled. 23.7 Data Reception – The USART Receiver The USART receiver is enabled by writing the Receive Enable (RXENn) bit in the UCSRnB register to one. When the receiver is enabled, the normal pin operation of the RxDn pin is overridden by the USART and given the function as the receiver’s serial input. The baud rate, mode of operation and frame format must be set up once before any serial reception can be done. If synchronous operation is used, the clock on the XCKn pin will be used as transfer clock. 23.7.1 Receiving Frames with 5 to 8 Data Bits The receiver starts data reception when it detects a valid start bit. Each bit that follows the start bit will be sampled at the baud rate or XCKn clock, and shifted into the receive shift register until the first stop bit of a frame is received. A second stop bit will be ignored by the receiver. When the first stop bit is received, i.e., a complete serial frame is present in the receive shift register, the contents of the shift register will be moved into the receive buffer. The receive buffer can then be read by reading the UDRn I/O location. The following code example shows a simple USART receive function based on polling of the Receive Complete Flag (RXCn). When using frames with less than eight bits the most significant bits of the data read from the UDRn will be masked to zero. The USART has to be initialized before the function can be used. The function simply waits for data to be present in the receive buffer by checking the RXCn flag before reading the buffer and returning the value. Assembly Code Example(1) USART_Receive: ; Wait for data to be received sbis UCSRnA, RXCn rjmp USART_Receive ; Get and return received data from buffer in r16, UDRn ret 381 8393C-MCU Wireless-09/14

C Code Example(1) unsigned char USART_Receive( void ) { /* Wait for data t o be received */ while ( !(UCSRnA & (1<<RXCn)) ); /* Get and return received data from buffer */ return UDRn; } Note: 1. See "About Code Examples" on page 7 23.7.2 Receiving Frames with 9 Data Bits If 9 bit characters are used (UCSZn2:0=7) the 9th bit must be read from the RXB8n bit in UCSRnB before reading the low bits from the UDRn register. This rule applies to the FEn, DORn and UPEn status flags as well. Read status from UCSRnA, then data from UDRn. Reading the UDRn I/O location will change the state of the receive buffer FIFO and consequently the TXB8n, FEn, DORn and UPEn bits, which all are stored in the FIFO, will change. The following code example shows a simple USART receive function that handles both nine bit characters and the status bits. Assembly Code Example(1) USART_Receive: ; Wait for data to be received sbis UCSRnA, RXCn rjmp USART_Receive ; Get status and 9th bit, then data from buffer in r18, UCSRnA in r17, UCSRnB in r16, UDRn ; If error, return -1 andi r18,(1<<FEn)|(1<<DORn)|(1<<UPEn) breq USART_ReceiveNoError ldi r17, HIGH(-1) ldi r16, LOW(-1) USART_ReceiveNoError: ; Filter the 9th bit, then return lsr r17 andi r17, 0x01 ret ATmega256/128/64RFR2 382 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 C Code Example(1) unsigned int USART_Receive( void ) { unsigned char statu s, resh, resl; /* Wait for data to be received */ while ( !(UCSRnA & (1<<RXCn)) ); /* Get status and 9th bit, then data */ /* from buffer */ status = UCSRnA; resh = UCSRnB; resl = UDRn; /* If error, return -1 */ if ( status & (1<<FEn)|(1<<DORn)|(1<<UPEn) ) return -1; /* Filter the 9th bit, then return */ resh = (resh >> 1) & 0x01; return ((resh << 8) | resl); } Note: 1. See "About Code Examples" on page 7 The receive function example reads all the I/O registers into the register file before any computation is done. This gives an optimal receive buffer utilization since the buffer location read will be free to accept new data as early as possible. 23.7.3 Receive Complete Flag and Interrupt The USART receiver has one flag that indicates the receiver state. The Receive Complete Flag (RXCn) indicates if there are unread data present in the receive buffer. This flag is o ne when unread data exist in the receive buffer, and zero when the receive buffer is empty (i.e., does not contain any unread data). If the receiver is disabled (RXENn = 0), the receive buffer will be flushed and consequently the RXCn bit will become zero. When the Receive Complete Interrupt Enable (RXCIEn) in UCSRnB is set, the USART receive complete interrupt will be executed as long as the RXCn flag is set (provided that global interrupts are enabled). When interrupt-driven data reception is used, the receive complete routine must read the received data from UDRn in order to clear the RXCn flag, otherwise a new interrupt will occur once the interrupt routine terminates. 23.7.4 Receiver Error Flags The USART receiver has three error flags: Frame Error (FEn), Data OverRun (DORn) and Parity Error (UPEn). All can be accessed by reading UCSRnA. Common for the error flags is that they are lo cated in the receive buffer together with the frame for which they indicate the error status. Due to the buffering of the error flags, the UCSRnA must be read before the receive buffer (UDRn), since reading the UDRn I/O location changes the buffer read location. The error flags cannot be altered by the application software doing a write to the flag location. However, all flags must be set to zero when the UCSRnA is written for upward compatibility of future USART implementations. None of the error flags can generate interrupts. The Frame Error Flag (FEn) indicates the state of the first stop bit of the next readable frame stored in the receive buffer. The FEn flag is zero when the stop bit was correctly 383 8393C-MCU Wireless-09/14

read (as one), and the FEn flag will be one when the stop bit was incorrect (zero). This flag can be used for detecting out-of-sync conditions, detecting break conditions and protocol handling. The FEn flag is not affected by the setting of the USBSn bit in UCSRnC since the receiver ignores all, except for the first, stop bits. For compatibility with future devices, always set this bit to zero when writing to UCSRnA. The Data OverRun Flag (DORn) indicates data loss due to a receiver buffer full condition. A data overrun occurs when the receive buffer is full (two characters), it is a new character waiting in the receive shift register, and a new start bit is detected. If the DORn flag is set there was one or more serial frame lost between the frame last read from UDRn, and the next frame read from UDRn. For compatibility with future devices, always write this bit to zero when writing to UCSRnA. The DORn flag is cleared when the frame received was successfully moved from the shift register to the receive buffer. The Parity Error Flag (UPEn) indicates that the next frame in the receive buffer had a parity error when received. If parity check is not enabled the UPEn bit will always be read zero. For compatibility with future devices, always set this bit to zero when writing to UCSRnA. For more details see "Parity Bit Calculation" on page 377 and "Parity Checker" below. 23.7.5 Parity Checker The parity checker is active when the high USART parity mode (UPMn1) bit is set. Type of parity check to be performed (odd or even) is selected by the UPMn0 bit. When enabled, the parity checker calculates the parity of the data bits in incoming frames and compares the result with the parity bit from the serial frame. The result of the check is stored in the receive buffer together with the received data and stop bits. The Parity Error Flag (UPEn) can then be read by software to check if the frame had a parity error. The UPEn bit is set if the next character that can be read from the receive buffer had a parity error when received .The parity checking was enabled at that point (UPMn1 = 1). This bit is valid until the receive buffer (UDRn) is read. 23.7.6 Disabling the Receiver In contrast to the transmitter, disabling of the receiver will be immediate. Data from ongoing receptions will therefore be lost. When disabled (i.e., the RXENn is set to zero) the receiver will no longer override the normal function of the RxDn port pin. The receiver buffer FIFO will be flushed when the receiver is disabled. Remaining data in the buffer will be lost 23.7.7 Flushing the Receive Buffer The receiver buffer FIFO will be flushed when the receiver is disabled, i.e., the buffer will be emptied of its contents. Unread data will be lost. If the buffer has to be flushed during normal operation, due to for instance an error condition, read the UDRn I/O location until the RXCn flag is cleared. The following code example shows how to flush the receive buffer. Assembly Code Example(1) USART_Flush: sbis UCSRnA, RXCn ret in r16, UDRn rjmp USART_Flush ATmega256/128/64RFR2 384 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 C Code Example(1) void USART_Flush( void ) { unsigned char dummy ; while ( UCSRnA & (1<<RXCn) ) dummy = UDRn; } Note: 1. See "About Code Examples" on page 7 23.8 Asynchronous Data Reception The USART includes a clock recovery and a data recovery unit for handling asynchronous data reception. The clock recovery logic is used for synchronizing the internally generated baud rate clock to the incoming asynchronous serial frames at the RxDn pin. The data recovery logic samples and low pass filters each incoming bit, thereby improving the noise immunity of the receiver. The asynchronous reception operational range depends on the accuracy of the internal baud rate clock, the rate of the incoming frames, and th e frame size in number of bits. 23.8.1 Asynchronous Clock Recovery The clock recovery logic synchronizes internal clock to the incoming serial frames. Figure 23-5 below illustrates the sampling process of the start bit of an incoming frame. The sample rate is 16 times the baud rate for Normal mode, and eight times the baud rate for double speed mode. The horizontal arrows illustrate the synchronization variation due to the sampling process. Note the larger time variation when using the double speed mode (U2Xn = 1) of operation. Samples denoted zero are samples done when the RxDn line is idle (i.e., no communication activity). Figure 23-5. Start Bit Sampling RxD IDLE START BIT 0 Sample (U2X = 0) 0 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 1 2 3 Sample (U2X = 1) 0 1 2 3 4 5 6 7 8 1 2 When the clock recovery logic detects a high (idle) to low (start) transition on the RxDn line, the start bit detection sequence is initiated. Let sample 1 denote the first zero- sample as shown in the figure. The clock recovery logic then uses samples 8, 9 and 10 for Normal mode, and samples 4, 5 and 6 for double speed mode (indicated with sample numbers inside boxes on the figure), to decide if a valid start bit is received. If two or more of these three samples have logical high levels (the majority wins), the start bit is rejected as a noise spike and the receiver starts looking for the next high to low- transition. If however, a valid start bit is detected, the clock recovery logic is synchronized and the data recovery can begin. The synchronization process is repeated for each start bit. 23.8.2 Asynchronous Data Recovery When the receiver clock is synchronized to the start bit, the data recovery can begin. The data recovery unit uses a state machine that has 16 states for each bit in Normal mode and eight states for each bit in double speed mode. Figure 23-6 on page 386 385 8393C-MCU Wireless-09/14

shows the sampling of the data bits and the parity bit. Each of the samples is given a number that is equal to the state of the recovery unit. Figure 23-6. Sampling of D ata and Parity Bit RxD BIT n Sample (U2X = 0) 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 1 Sample (U2X = 1) 1 2 3 4 5 6 7 8 1 The decision of the logic level of the received bit is taken by doing a majority voting of the logic value to the three samples in the centre of the received bit. The centre samples are emphasized on the figure by having the sample number inside boxes. The majority voting process is done as follows: If two or all three samples h ave high levels, the received bit is registered to be logic 1. If two or all three samples have low levels, the received bit is registered to be logic 0. This majority voting process acts as a low pass filter for the incoming signal on the RxDn pin. The recovery process is then repeated until a complete frame is received including the first stop bit. Note that the receiver only uses the first stop bit of a frame. Figure 23-7 below shows the sampling of the stop bit and the earliest possible beginning of the start bit of the next frame. Figure 23-7. Stop Bit Sampling and Next Start Bit Sampling RxD STOP 1 (A) (B) (C) Sample (U2X = 0) 1 2 3 4 5 6 7 8 9 10 0/1 0/1 0/1 Sample (U2X = 1) 1 2 3 4 5 6 0/1 The same majority voting is done to the stop bit as done for the other bits in the frame. If the stop bit is registered to have a logic 0 value, the Frame Error Flag (FEn) will be set. A new high to low transition indicating the start bit of a new frame can come right after the last of the bits used for majority voting. For normal speed mode, the first low level sample can be at point marked (A) in Figure 23-7 above. For double speed mode the first low level must be delayed to (B). (C) marks a stop bit of full length. The early start bit detection influences the operational range of the receiver. 23.8.3 Asynchronous Operational Range The operational range of the receiver is dependent on the mismatch between the received bit rate and the internally generated baud rate. If the transmitter is sending frames at too fast or too slow bit rates, or the internally generated baud rate of the receiver does not have a similar (see Table 23-2 on page 387) base frequency, the receiver will not be able to synchronize the frames to the start bit. ATmega256/128/64RFR2 386 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 The following equations can be used to calculate the ratio of the incoming data rate and internal receiver baud rate. (D+1)S (D+2)S R = R = slow S −1+D ⋅S +S fast (D+1)S +S F MF D Sum of character size and parity size (D = 5 to 10 bit) S Samples per bit. S = 16 for normal speed mode and S = 8 for double speed mode. S First sample number used for majority voting. S = 8 for normal speed and F F S = 4 for double speed mode. F S Middle sample number used for majority voting. S = 9 for normal speed and M M S = 5 for double sp eed mode. M R is the ratio of the slowest incoming data rate that can be accepted in relation to slow the receiver baud rate. R is the ratio of the fastest incoming data rate that can be accepted in relation to fast the receiver baud rate. Table 23-2 below and Table 23-3 below list the maximum receiver baud rate error that can be tolerated. Note that normal speed mode has higher tolerance of baud rate variations. Table 23-2. Recommended Maximum Receiver Baud Rate Error for Normal Speed Mode (U2Xn = 0) D Recommended Max # (Data+Parity Bit) R (%) R (%) Max Total Error (%) Receiver Error (%) slow fast 5 93.20 106.67 +6.67/-6.8 ± 3.0 6 94.12 105.79 +5.79/-5.88 ± 2.5 7 94.81 105.11 +5.11/-5.19 ± 2.0 8 95.36 104.58 +4.58/-4.54 ± 2.0 9 95.81 104.14 +4.14/-4.19 ± 1.5 10 96.17 103.78 +3.78/-3.83 ± 1.5 Table 23-3. Recommended Maximum Receiver Baud Rate Error for Double Speed Mode (U2Xn = 1) D Recommended Max # (Data+Parity Bit) R (%) R (%) Max Total Error (%) Receiver Error (%) slow fast 5 94.12 105.66 +5.66/-5.88 ± 2.5 6 94.92 104.92 +4.92/-5.08 ± 2.0 7 95.52 104,35 +4.35/-4.48 ± 1.5 8 96.00 103.90 +3.90/-4.00 ± 1.5 9 96.39 103.53 +3.53/-3.61 ± 1.5 10 96.70 103.23 +3.23/-3.30 ± 1.0 The recommendations of the maximum receiver baud rate error were made under the assumption that the receiver and transmitter equally divides the maximum total error. There are two possible sources for the receiver baud rate error. The receiver’s system clock will always have some minor instability over the supply voltage range and the temperature range. When using the radio transceiver crystal oscillator (XOSC) to generate the system clock, this is rarely a problem, but for the internal RC oscillator the system clock may differ more than 2% over the temperature range. The second source for the error is more controllable. The baud rate generator can not always do an exact 387 8393C-MCU Wireless-09/14

division of the system frequency to get the baud rate wanted. In this case an UBRR value that gives an acceptable low error can be used if possible. 23.9 Multi-processor Communication Mode Setting the Multi-processor Communication Mode (MPCMn) bit in UCSRnA enables a filtering function of incoming frames received by the USART receiver. Frames that do not contain address information will be ignored and not put into the receive buffer. This effectively reduces the number of incoming frames that has to be handled by the MCU, in a system with multiple MCUs that communicate via the same serial bus. The transmitter is unaffected by the MPCMn setting, but has to be used differently when it is a part of a system utilizing the multi-processor communication mode. If the receiver is set up to receive frames that contain 5 to 8 data bits, then the first stop bit indicates if the frame contains data or address information. If the receiver is set up for frames with nine data bits, then the ninth bit (RXB8n) is used for identifying address and data frames. When the frame type bit (the first stop or the ninth bit) is one, the frame contains an address. When the frame type bit is zero the frame is a data frame. The multi-processor communication mode enables several slave MCUs to receive data from a master MCU. This is done by first decoding an address frame to find out which MCU has been addressed. If a particular slave MCU has been addressed, it will receive the following data frames as normal, while the other slave MCUs will ignore the received frames until another address frame is received. 23.9.1 Using MPCMn For an MCU to act as a master MCU, it can use a 9 bit character frame format (UCSZn2:0 = 7). The 9th bit (TXB8n) must be set when an address frame (TXB8n = 1) or cleared when a data frame (TXB = 0) is being transmitted. The slave MCUs must in this case be set to use a 9 bit character frame format. The following procedure should be used to exchange data in multi-processor communication mode: 1. All slave MCUs are in multi-processor communication mode (MPCMn in UCSRnA is set). 2. The master MCU sends an address frame, and all slaves receive and read this frame. In the slave MCUs, the RXCn flag in UCSRnA will be set as normal. 3. Each slave MCU reads the UDRn register and determines if it has been selected. If so, it clears the MPCMn bit in UCSRnA, otherwise it waits for the next address byte and keeps the MPCMn setting. 4. The addressed MCU will receive all data frames until a new address frame is received. The other slave MCUs, which still have the MPCMn bit set, will ignore the data frames. 5. When the last data frame is received by the addressed MCU, the addressed MCU sets the MPCMn bit and waits for a new address frame from master. The process then repeats from 2. Using any of the 5 to 8 bit character frame formats is possible, but impractical since the receiver must change between using n and n+1 character frame formats. This makes full-duplex operation difficult since the transmitter and receiver uses the same character size setting. If 5 to 8 bit character frames are used, the transmitter must be set to use two stop bit (USBSn = 1) since the first stop bit is used for indicating the frame type. ATmega256/128/64RFR2 388 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 Do not use read-modify-write instructions (SBI and CBI) to set or clear the MPCMn bit. The MPCMn bit shares the same I/O location as the TXCn flag and this might accidentally be cleared when using SBI or CBI instructions. 23.10 Register Description 23.10.1 UDR0 – USART0 I/O Data Register Bit 7 6 5 4 3 2 1 0 NA ($C6) UDR07:00 UDR0 Read/Write RW RW RW RW RW RW RW RW Initial Value 0 0 0 0 0 0 0 0 The USART Transmit Data Buffer Register and USART Receive Data Buffer Registers share the same I/O address referred to as USART Data Register or UDR0. The Transmit Data Buffer Register (TXB) will be the destination for data written to the UDR0 Register location. Reading the UDR0 Register location will return the contents of the Receive Data Buffer Register (RXB). For 5-, 6-, or 7-bit characters the upper unused bits will be ignored by the Transmitter and set to zero by the Receiver. The transmit buffer can only be written when the UDRE0 Flag in the UCSR0A Register is set. Data written to UDR0 when the UDRE0 Flag is not set, will be ignored by the USART Transmitter. When data is written to the transmit buffer and the Transmitter is enabled, the Transmitter will load the data into the Transmit Shift Register when the Shift Register is empty. Then the data will be serially transmitted on the TxD0 pin. The receive buffer consists of a two level FIFO. The FIFO will change its state whenever the receive buffer is accessed. D ue to this behavior of the receive buffer, do not use Read- Modify-Write instructions (SBI and CBI) on this location. Be careful when using bit test instructions (SBIC and SBIS), since these also will change the state of the FIFO. • Bit 7:0 – UDR07:00 - USART I/O Data Register 23.10.2 UCSR0A – USART0 Control and Status Register A Bit 7 6 5 4 3 2 1 0 NA ($C0) RXC0 TXC0 UDRE0 FE0 DOR0 UPE0 U2X0 MPCM0 UCSR0A Read/Write R RW R R R R RW RW Initial Value 0 0 1 0 0 0 0 0 • Bit 7 – RXC0 - USART Receive Complete This flag bit is set when there are unread data in the receive buffer and cleared when the receive buffer is empty (i.e., does not contain any unread data). If the Receiver is disabled, the receive buffer will be flushed and consequently the RXC0 bit will become zero. The RXC0 Flag can be used to generate a Receive Complete interrupt (see description of the RXCIE0 bit). • Bit 6 – TXC0 - USART Transmit Complete This flag bit is set when the entire frame in the Transmit Shift Register has been shifted out and there are no new data currently present in the transmit buffer (UDR0). The TXC0 Flag bit is automatically cleared when a transmit complete interrupt is executed, or it can be cleared by writing a one to its bit location. The TXC0 Flag can generate a Transmit Complete interrupt (see description of the TXCIE0 bit). 389 8393C-MCU Wireless-09/14

• Bit 5 – UDRE0 - USART Data Register Empty The UDRE0 Flag indicates if the transmit buffer (UDR0) is ready to receive new data. If UDRE0 is one, the buffer is empty, and therefore ready to be written. The UDRE0 Flag can generate a Data Register Empty interrupt (see description of the UDRIE0 bit). UDRE0 is set after a reset to indicate that the Transmitter is ready. • Bit 4 – FE0 - Frame Error This bit is set if the next character in the receive buffer had a Frame Error when received. I.e., when the first stop bit of the next character in the receive buffer is zero. This bit is valid until the receive buffer (UDR0) is read. The FE0 bit is zero when the stop bit of received data is one. Always set this bit to zero when writing to UCSR0A. • Bit 3 – DOR0 - Data OverRun This bit is set if a Data OverRun condition is detected. A Data OverRun occurs when the receive buffer is full (two characters), it is a new character waiting in the Receive Shift Register and a new start bit is detected. This bit is valid until the receive buffer (UDR0) is read. Always set this bit to zero when writing to UCSR0A. • Bit 2 – UPE0 - USART P arity Error This bit is set if the next character in the receive buffer had a Parity Error when received and the Parity Checking was enabled at that point (UPM01 = 1). This bit is valid until the receive buffer (UDR0) is read. Always set this bit to zero when writing to UCSR0A. • Bit 1 – U2X0 - Double the USART Transmission Speed This bit only has effect for the asynchronous operation. Write this bit to zero when using synchronous operation. Writing this bit to one will reduce the divisor of the baud rate divider from 16 to 8 effectively doubling the transfer rate for asynchronous communication. • Bit 0 – MPCM0 - Multi-processor Communication Mode This bit enables the Multi-processor Communication mode. When the MPCM0 bit is written to one, all the incoming frames received by the USART Receiver that do not contain address informatio n will be ignored. The Transmitter is unaffected by the MPCM0 setting. For more detailed information see section "Multi-processor Communication Mode". 23.10.3 UCSR0B – USART0 Control and Status Register B Bit 7 6 5 4 3 2 1 0 NA ($C1) RXCIE0 TXCIE0 UDRIE0 RXEN0 TXEN0 UCSZ02 RXB80 TXB80 UCSR0B Read/Write RW RW RW RW RW RW R W Initial Value 0 0 1 0 0 0 0 0 • Bit 7 – RXCIE0 - RX Complete Interrupt Enable Writing this bit to one enables interrupt on the RXC0 Flag. A USART Receive Complete interrupt will be generated only if the RXCIE0 bit is written to one, the Global Interrupt Flag in SREG is written to one and the RXC0 bit in UCSR0A is set. • Bit 6 – TXCIE0 - TX Complete Interrupt Enable Writing this bit to one enables interrupt on the TXC0 Flag. A USART Transmit Complete interrupt will be generated only if the TXCIE0 bit is written to one, the Global Interrupt Flag in SREG is written to one and the TXC0 bit in UCSR0A is set. • Bit 5 – UDRIE0 - USART Data Register Empty Interrupt Enable ATmega256/128/64RFR2 390 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 Writing this bit to one enables interrupt on the UDRE0 Flag. A Data Register Empty interrupt will be generated only if the UDRIE0 bit is written to one, the Global Interrupt Flag in SREG is written to one and the UDRE0 bit in UCSR0A is set. • Bit 4 – RXEN0 - Receiver Enable Writing this bit to one enables the USART Receiver. The Receiver will override normal port operation for the RxD0 pin when enabled. Disabling the Receiver will flush the receive buffer invalidating the FE0, DOR0 and UPE0 Flags. • Bit 3 – TXEN0 - Transmitter Enable Writing this bit to one enables the USART Transmitter. The Transmitter will override normal port operation for the TxD0 pin when enabled. The disabling of the Transmitter (writing TXEN0 to zero) will not become effective until ongoing and pending transmissions are completed, i.e., when the Transmit Shift Register and Transmit Buffer Register do not contain data to be transmitted. When disabled, the Transmitter will no longer override the TxD0 port. • Bit 2 – UCSZ02 - Character Size The UCSZ02 bits combined with the UCSZ01:0 bit in UCSR0C sets the number of data bits (Character Size) in the frame that the Receiver and Transmitter use. • Bit 1 – RXB80 - Receive Data Bit 8 RXB80 is the 9th data bit of the received character when operating with serial frames with nine data bits. The bit must be read before reading the lower 8 bits from UDR0. • Bit 0 – TXB80 - Transmit Data Bit 8 TXB80 is the 9th data bit in the character to be transmitted when operating with serial frames with nine data bits. The bit must be written before writing the lower 8 bits to UDR0. 23.10.4 UCSR0C – USART0 Control and Status Register C Bit 7 6 5 4 3 2 1 0 NA ($C2) UMSEL01 UMSEL00 UPM01 UPM00 USBS0 UCSZ01 UCSZ00 UCPOL0 UCSR0C Read/Write RW RW RW RW RW RW RW RW Initial Value 0 0 0 0 0 0 1 0 • Bit 7:6 – UMSEL1:0 - USART Mode Select These bits select the mode of operation of the USART0 as shown in the following table. See section "USART in SPI Mode" for a full description of the Master SPI Mode (MSPIM) operation. Table 23-4 UMSEL0 Register Bits Register Bits Value Description UMSEL1:0 0x00 Asynchronous USART 0x01 Synchronous USART 0x02 Reserved 0x03 Master SPI (MSPIM) • Bit 5:4 – UPM1:0 - Parity Mode These bits enable and set type of parity generation and check. If enabled, the Transmitter will automatically generate and send the parity of the transmitted data bits within each frame. The Receiver will generate a parity value for the incoming data and 391 8393C-MCU Wireless-09/14

compare it to the UPM0 setting. If a mismatch is detected, the UPE0 Flag in UCSR0A will be set. Table 23-5 UPM0 Register Bits Register Bits Value Description UPM1:0 0x00 Disabled 0x01 Reserved 0x02 Enabled, Even Parity 0x03 Enabled, Odd Parity • Bit 3 – USBS0 - Stop Bit Select This bit selects the number of stop bits to be inserted by the Transmitter. The Receiver ignores this setting. Table 23-6 USBS0 Register Bits Register Bits Value Description USBS0 0x00 1-bit 0x01 2-bit • Bit 2:1 – UCSZ1:0 - Character Size The UCSZ01:0 bits combined with the UCSZ02 bit in UCSR0B sets the number of data bits (Character Size) in the frame that the Receiver and Transmitter use. Table 23-7 UCSZ0 Register Bits Register Bits Value Description UCSZ1:0 0 5-bit 1 6-bit 2 7-bit 3 8-bit 4 Reserved 5 Reserved 6 Reserved 7 9-bit • Bit 0 – UCPOL0 - Clock Polarity This bit is used for synchronous mode only. Write this bit to zero when asynchronous mode is used. The UCPOL0 bit sets the relationship between data output change and data input sample, and the s ynchronous clock (XCK0). Table 23-8 UCPOL0 Register Bits Register Bits Value Description UCPOL0 0 Rising XCKn Edge (Transmitted Data Changed), Falling XCKn Edge (Received Data Sampled) 1 Falling XCKn Edge (Transmitted Data Changed), Rising XCKn Edge (Received Data Sampled) ATmega256/128/64RFR2 392 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 23.10.5 UBRR0H – USART0 Baud Rate Register High Byte Bit 7 6 5 4 3 2 1 0 NA ($C5) Res3 Res2 Res1 Res0 UBRR11 UBRR10 UBRR9 UBRR8 UBRR0H Read/Write R R R R RW RW RW RW Initial Value 0 0 0 0 0 0 0 0 UBRR0 is a 12-bit register which contains the USART baud rate. The UBRR0H contains the four most significant bits, and the UBRR0L contains the eight least significant bits of the USART baud rate. Ongoing transmissions by the Transmitter and Receiver will be corrupted if the baud rate is changed. Writing UBRR0L will trigger an immediate update of the baud rate prescaler. • Bit 7:4 – Res3:0 - Reserved Bit This bit is reserved for future use. A read access always will return zero. A write access does not modify the content. • Bit 3:0 – UBRR11:8 - USART Baud Rate Register These bits represent bits [11:8] of the Baud Rate Register. Sample values for commonly used clock frequencies can be found in section "Examples of Baud Rate Setting". 23.10.6 UBRR0L – USART0 Baud Rate Register Low Byte Bit 7 6 5 4 3 2 1 0 NA ($C4) UBRR7 UBRR6 UBRR5 UBRR4 UBRR3 UBRR2 UBRR1 UBRR0 UBRR0L Read/Write RW RW RW RW RW RW RW RW Initial Value 0 0 0 0 0 0 0 0 UBRR0 is a 12-bit registe r which contains the USART baud rate. The UBRR0H contains the four most significant bits, and the UBRR0L contains the eight least significant bits of the USART baud rate. Ongoing transmissions by the Transmitter and Receiver will be corrupted if the baud rate is changed. Writing UBRR0L will trigger an immediate update of the baud rate prescaler. • Bit 7:0 – UBRR7:0 - USART Baud Rate Register These bits represent bits [7:0] of the Baud Rate Register. Sample values for commonly used clock frequencies can be found in section "Examples of Baud Rate Setting". 23.10.7 UDR1 – USART1 I/O Data Register Bit 7 6 5 4 3 2 1 0 NA ($CE) UDR17:10 UDR1 Read/Write RW RW RW RW RW RW RW RW Initial Value 0 0 0 0 0 0 0 0 The USART Transmit Data Buffer Register and USART Receive Data Buffer Registers share the same I/O address referred to as USART Data Register or UDR1. The Transmit Data Buffer Register (TXB) will be the destination for data written to the UDR1 Register location. Reading the UDR1 Register location will return the contents of the 393 8393C-MCU Wireless-09/14

Receive Data Buffer Register (RXB). For 5-, 6-, or 7-bit characters the upper unused bits will be ignored by the Transmitter and set to zero by the Receiver. The transmit buffer can only be written when the UDRE1 Flag in the UCSR1A Register is set. Data written to UDR1 when the UDRE1 Flag is not set, will be ignored by the USART Transmitter. When data is written to the transmit buffer and the Transmitter is enabled, the Transmitter will load the data into the Transmit Shift Register when the Shift Register is empty. Then the data will be serially transmitted on the TxD1 pin. The receive buffer consists of a two level FIFO. The FIFO will change its state whenever the receive buffer is accessed. Due to this behavior of the receive buffer, do not use Read- Modify-Write instructions (SBI and CBI) on this location. Be careful when using bit test instructions (SBIC and SBIS), since these also will change the state of the FIFO. • Bit 7:0 – UDR17:10 - USART I/O Data Register 23.10.8 UCSR1A – USART1 Control and Status Register A Bit 7 6 5 4 3 2 1 0 NA ($C8) RXC1 TXC1 UDRE1 FE1 DOR1 UPE1 U2X1 MPCM1 UCSR1A Read/Write R RW R R R R RW RW Initial Value 0 0 1 0 0 0 0 0 • Bit 7 – RXC1 - USART Receive Complete This flag bit is set when there are unread data in the receive buffer and cleared when the receive buffer is empty (i.e., does not contain any unread data). If the Receiver is disabled, the receive buffer will be flushed and consequently the RXC1 bit will become zero. The RXC1 Flag can be used to generate a Receive Complete interrupt (see description of the RXCIE1 bit). • Bit 6 – TXC1 - USART Transmit Complete This flag bit is set when the entire frame in the Transmit Shift Register has been shifted out and there are no new data currently present in the transmit buffer (UDR1). The TXC1 Flag bit is automatically cleared when a transmit complete interrupt is executed, or it can be cleared by writing a one to its bit location. The TXC1 Flag can generate a Transmit Complete interrupt (see description of the TXCIE1 bit). • Bit 5 – UDRE1 - USART Data Register Empty The UDRE1 Flag indicates if the transmit buffer (UDR1) is ready to receive new data. If UDRE1 is one, the buffer is empty, and therefore ready to be written. The UDRE1 Flag can generate a Data Reg ister Empty interrupt (see description of the UDRIE1 bit). UDRE1 is set after a reset to indicate that the Transmitter is ready. • Bit 4 – FE1 - Frame Error This bit is set if the next character in the receive buffer had a Frame Error when received. I.e., when the first stop bit of the next character in the receive buffer is zero. This bit is valid until the re ceive buffer (UDR1) is read. The FE1 bit is zero when the stop bit of received data is one. Always set this bit to zero when writing to UCSR1A. • Bit 3 – DOR1 - Data OverRun This bit is set if a Data OverRun condition is detected. A Data OverRun occurs when the receive buffer is full (two characters), it is a new character waiting in the Receive Shift Register and a new start bit is detected. This bit is valid until the receive buffer (UDR1) is read. Always set this bit to zero when writing to UCSR1A. • Bit 2 – UPE1 - USART Parity Error ATmega256/128/64RFR2 394 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 This bit is set if the next character in the receive buffer had a Parity Error when received and the Parity Checking was enabled at that point (UPM11 = 1). This bit is valid until the receive buffer (UDR1) is read. Always set this bit to zero when writing to UCSR1A. • Bit 1 – U2X1 - Double the USART Transmission Speed This bit only has effect for the asynchronous operation. Write this bit to zero when using synchronous operation. Writing this bit to one will reduce the divisor of the baud rate divider from 16 to 8 effectively doubling the transfer rate for asynchronous communication. • Bit 0 – MPCM1 - Multi-processor Communication Mode This bit enables the Multi-processor Communication mode. When the MPCM1 bit is written to one, all the incoming frames received by the USART Receiver that do not contain address information will be ignored. The Transmitter is unaffected by the MPCM1 setting. For more detailed information see section "Multi-processor Communication Mode". 23.10.9 UCSR1B – USART1 Control and Status Register B Bit 7 6 5 4 3 2 1 0 NA ($C9) RXCIE1 TXCIE1 UDRIE1 RXEN1 TXEN1 UCSZ12 RXB81 TXB81 UCSR1B Read/Write RW RW RW RW RW RW R W Initial Value 0 0 1 0 0 0 0 0 • Bit 7 – RXCIE1 - RX Com plete Interrupt Enable Writing this bit to one enables interrupt on the RXC1 Flag. A USART Receive Complete interrupt will be generated only if the RXCIE1 bit is written to one, the Global Interrupt Flag in SREG is written to one and the RXC1 bit in UCSR1A is set. • Bit 6 – TXCIE1 - TX Complete Interrupt Enable Writing this bit to one enables interrupt on the TXC1 Flag. A USART Transmit Complete interrupt will be generated only if the TXCIE1 bit is written to one, the Global Interrupt Flag in SREG is written to one and the TXC1 bit in UCSR1A is set. • Bit 5 – UDRIE1 - USART Data Register Empty Interrupt Enable Writing this bit to one enables interrupt on the UDRE1 Flag. A Data Register Empty interrupt will be generated only if the UDRIE1 bit is written to one, the Global Interrupt Flag in SREG is written to one and the UDRE1 bit in UCSR1A is set. • Bit 4 – RXEN1 - Receiver Enable Writing this bit to one enables the USART Receiver. The Receiver will override normal port operation for the RxD1 pin when enabled. Disabling the Receiver will flush the receive buffer invalidating the FE1, DOR1 and UPE1 Flags. • Bit 3 – TXEN1 - Transmitter Enable Writing this bit to one enables the USART Transmitter. The Transmitter will override normal port operation for the TxD1 pin when enabled. The disabling of the Transmitter (writing TXEN1 to zero) will not become effective until ongoing and pending transmissions are completed, i.e., when the Transmit Shift Register and Transmit Buffer Register do not contain data to be transmitted. When disabled, the Transmitter will no longer override the TxD1 port. • Bit 2 – UCSZ12 - Character Size 395 8393C-MCU Wireless-09/14

The UCSZ12 bits combined with the UCSZ11:0 bit in UCSR1C sets the number of data bits (Character Size) in the frame that the Receiver and Transmitter use. • Bit 1 – RXB81 - Receive Data Bit 8 RXB81 is the 9th data bit o f the received character when operating with serial frames with nine data bits. The bit must be read before reading the lower 8 bits from UDR1. • Bit 0 – TXB81 - Transmit Data Bit 8 TXB81 is the 9th data bit in the character to be transmitted when operating with serial frames with nine data bits. The bit must be written before writing the lower 8 bits to UDR1. 23.10.10 UCSR1C – USART1 Control and Status Register C Bit 7 6 5 4 3 2 1 0 NA ($CA) UMSEL11 UMSEL10 UPM11 UPM10 USBS1 UCSZ11 UCSZ10 UCPOL1 UCSR1C Read/Write RW RW RW RW RW RW RW RW Initial Value 0 0 0 0 0 1 1 0 • Bit 7:6 – UMSEL11:10 - USART Mode Select These bits select the mode of operation of the USART1 as shown in the following table. See section "USART in SPI Mode" for a full description of the Master SPI Mode (MSPIM) operation. Table 23-9 UMSEL1 Regist er Bits Register Bits Value Description UMSEL11:10 0x00 Asynchronous USART 0x01 Synchronous USART 0x02 Reserved 0x03 Master SPI (MSPIM) • Bit 5:4 – UPM11:10 - Parity Mode These bits enable and set type of parity generation and check. If enabled, the Transmitter will automatically generate and send the parity of the transmitted data bits within each frame. The Receiver will generate a parity value for the incoming data and compare it to the UPM1 setting. If a mismatch is detected, the UPE1 Flag in UCSR1A will be set. Table 23-10 UPM1 Register Bits Register Bits Value Description UPM11:10 0x00 Disabled 0x01 Reserved 0x02 Enabled, Even Parity 0x03 Enabled, Odd Parity • Bit 3 – USBS1 - Stop Bit Select This bit selects the number of stop bits to be inserted by the Transmitter. The Receiver ignores this setting. ATmega256/128/64RFR2 396 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 Table 23-11 USBS1 Register Bits Register Bits Value Description USBS1 0x00 1-bit 0x01 2-bit • Bit 2:1 – UCSZ11:10 - Character Size The UCSZ11:0 bits combined with the UCSZ12 bit in UCSR1B sets the number of data bits (Character Size) in the frame that the Receiver and Transmitter use. Table 23-12 UCSZ1 Register Bits Register Bits Value Description UCSZ11:10 0 5-bit 1 6-bit 2 7-bit 3 8-bit 4 Reserved 5 Reserved 6 Reserved 7 9-bit • Bit 0 – UCPOL1 - Clock Polarity This bit is used for synchronous mode only. Write this bit to zero when asynchronous mode is used. The UCPOL1 bit sets the relationship between data output change and data input sample, and the synchronous clock (XCK1). Table 23-13 UCPOL1 Register Bits Register Bits Value Description UCPOL1 0 Rising XCKn Edge (Transmitted Data Changed), Falling XCKn Edge (Received Data Sampled) 1 Falling XCKn Edge (Transmitted Data Changed), Rising XCKn Edge (Received Data Sampled) 23.10.11 UBRR1H – USART1 Baud Rate Register High Byte Bit 7 6 5 4 3 2 1 0 NA ($CD) Res3 Res2 Res1 Res0 UBRR11 UBRR10 UBRR9 UBRR8 UBRR1H Read/Write R R R R RW RW RW RW Initial Value 0 0 0 0 0 0 0 0 UBRR1 is a 12-bit registe r which contains the USART baud rate. The UBRR1H contains the four most significant bits, and the UBRR1L contains the eight least significant bits of the USART baud rate. Ongoing transmissions by the Transmitter and Receiver will be corrupted if the baud rate is changed. Writing UBRR1L will trigger an immediate update of the baud rate prescaler. • Bit 7:4 – Res3:0 - Reserved Bit This bit is reserved for future use. A read access always will return zero. A write access does not modify the content. 397 8393C-MCU Wireless-09/14

• Bit 3:0 – UBRR11:8 - USART Baud Rate Register These bits represent bits [11:8] of the Baud Rate Register. Sample values for commonly used clock frequencies can be found in section "Examples of Baud Rate Setting". 23.10.12 UBRR1L – USART1 Baud Rate Register Low Byte Bit 7 6 5 4 3 2 1 0 NA ($CC) UBRR7 UBRR6 UBRR5 UBRR4 UBRR3 UBRR2 UBRR1 UBRR0 UBRR1L Read/Write RW RW RW RW RW RW RW RW Initial Value 0 0 0 0 0 0 0 0 UBRR1 is a 12-bit register which contains the USART baud rate. The UBRR1H contains the four most significant bits, and the UBRR1L contains the eight least significant bits of the USART baud rate. Ongoing transmissions by the Transmitter and Receiver will be corrupted if the baud rate is changed. Writing UBRR1L will trigger an immediate update of the baud rate prescaler. • Bit 7:0 – UBRR7:0 - USART Baud Rate Register These bits represent bits [7:0] of the Baud Rate Register. Sample values for commonly used clock frequencies can be found in section "Examples of Baud Rate Setting". 23.11 Examples of Baud Rate Setting For standard crystal and resonator frequencies, the most commonly used baud rates for asynchronous operation can be generated by using the UBRR settings in Table 23-14 below to Table 23-16 on page 400. UBRR values which yield an actual baud rate differing less than 0.5% from the target baud rate, are bold in the table. Higher error ratings are acceptable, but the Receiver will have less noise resistance when the error ratings are high, especially for large serial frames (see "Asynchronous Operational Range" on page 386). The error values are calculated using the following equation: BaudRate  Error[%]= ClosestMatch −1⋅100%  BaudRate  Table 23-14. Examples of UBRRn Settings for Commonly Used Oscillator Frequencies fOSC = 1.8432 MHz fOSC = 2.0000 MHz fOSC = 3.6864 MHz Baud U2Xn = 0 U2Xn = 1 U2Xn = 0 U2Xn = 1 U2Xn = 0 U2Xn = 1 Rate (bps) UBRR Error UBRR Error UBRR Error UBRR Error UBRR Error UBRR Error 2400 47 0.0% 95 0.0% 51 0.2% 103 0.2% 95 0.0% 191 0.0% 4800 23 0.0% 47 0.0% 25 0.2% 51 0.2% 47 0.0% 95 0.0% 9600 11 0.0% 23 0.0% 12 0.2% 25 0.2% 23 0.0% 47 0.0% 14.4k 7 0.0% 15 0.0% 8 -3.5% 16 2.1% 15 0.0% 31 0.0% 19.2k 5 0.0% 11 0.0% 6 -7.0% 12 0.2% 11 0.0% 23 0.0% 28.8k 3 0.0% 7 0.0% 3 8.5% 8 -3.5% 7 0.0% 15 0.0% 38.4k 2 0.0% 5 0.0% 2 8.5% 6 -7.0% 5 0.0% 11 0.0% ATmega256/128/64RFR2 398 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 fOSC = 1.8432 MHz fOSC = 2.0000 MHz fOSC = 3.6864 MHz Baud U2Xn = 0 U2Xn = 1 U2Xn = 0 U2Xn = 1 U2Xn = 0 U2Xn = 1 Rate (bps) UBRR Error UBRR Error UBRR Erro r UBRR Error UBRR Error UBRR Error 57.6k 1 0.0% 3 0.0% 1 8.5% 3 8.5% 3 0.0% 7 0.0% 76.8k 1 -25.0% 2 0.0% 1 -18.6% 2 8.5% 2 0.0% 5 0.0% 115.2k 0 0.0% 1 0.0% 0 8.5% 1 8.5% 1 0.0% 3 0.0% 230.4k - - 0 0.0% - - - - 0 0.0% 1 0.0% 250k - - - - - - 0 0.0%% 0 -7.8% 1 -7.8% Max. (1) 115.2 kbps 230.4 kbps 125 kbps 250 kbps 230.4 kbps 460.8 kbps Notes: 1. UBRR = 0, Error = 0.0% Table 23-15. Examples of UBRRn Settings for Commonly Used Oscillator Frequencies (Continued) fOSC = 4.0000 MHz fOSC = 7.3728 MHz fOSC = 8.0000 MHz Baud U2Xn = 0 U2Xn = 1 U2Xn = 0 U2Xn = 1 U2Xn = 0 U2Xn = 1 Rate (bps) UBRR Error UBRR Error UBRR Error UBRR Error UBRR Error UBRR Error 2400 103 0.2% 207 0.2% 191 0.0% 383 0.0% 207 0.2% 416 -0.1% 4800 51 0.2% 103 0.2% 95 0.0% 191 0.0% 103 0.2% 207 0.2% 9600 25 0.2% 51 0.2% 47 0.0% 95 0.0% 51 0.2% 103 0.2% 14.4k 16 2.1% 34 -0.8% 31 0.0% 63 0.0% 34 -0.8% 68 0.6% 19.2k 12 0.2% 25 0.2% 23 0.0% 47 0.0% 25 0.2% 51 0.2% 28.8k 8 -3.5% 16 2.1% 15 0.0% 31 0.0% 16 2.1% 34 -0.8% 38.4k 6 -7.0% 12 0.2% 11 0.0% 23 0.0% 12 0.2% 25 0.2% 57.6k 3 8.5% 8 -3.5% 7 0.0% 15 0.0% 8 -3.5% 16 2.1% 76.8k 2 8.5% 6 -7.0% 5 0.0% 11 0.0% 6 -7.0% 12 0.2% 115.2k 1 8.5% 3 8.5% 3 0.0% 7 0.0% 3 8.5% 8 -3.5% 230.4k 0 8.5% 1 8.5% 1 0.0% 3 0.0% 1 8.5% 3 8.5% 250k 0 0.0% 1 0.0% 1 -7.8% 3 -7.8% 1 0.0% 3 0.0% 0.5M - - 0 0.0% 0 -7.8% 1 -7.8% 0 0.0% 1 0.0% 1M - - - - - - 0 -7.8% - - 0 0.0% Max. (1) 250 kbps 0.5 Mbps 460.8 kbps 921.6 kbps 0.5 Mbps 1 Mbps Notes: 1. UBRR = 0, Error = 0.0% 399 8393C-MCU Wireless-09/14

Table 23-16. Examples of UBRRn Settings for Commonly Used Oscillator Frequencies (Continued) fOSC = 11.0592 MHz fOSC = 14.7456 MHz fOSC = 16.0000 MHz Baud U2Xn = 0 U2Xn = 1 U2Xn = 0 U2Xn = 1 U2Xn = 0 U2Xn = 1 Rate (bps) UBRR Error UBRR Error UBRR Error UBRR Error UBRR Error UBRR Error 2400 287 0.0% 575 0.0% 383 0.0% 767 0.0% 416 -0.1% 832 0.0% 4800 143 0.0% 287 0.0% 191 0.0% 383 0.0% 207 0.2% 416 -0.1% 9600 71 0.0% 143 0.0% 95 0.0% 191 0.0% 103 0.2% 207 0.2% 14.4k 47 0.0% 95 0.0% 63 0.0% 127 0.0% 68 0.6% 138 -0.1% 19.2k 35 0.0% 71 0.0% 47 0.0% 95 0.0% 51 0.2% 103 0.2% 28.8k 23 0.0% 47 0.0% 31 0.0% 63 0.0% 34 -0.8% 68 0.6% 38.4k 17 0.0% 35 0.0% 23 0.0% 47 0.0% 25 0.2% 51 0.2% 57.6k 11 0.0% 23 0.0% 15 0.0% 31 0.0% 16 2.1% 34 -0.8% 76.8k 8 0.0% 17 0.0% 11 0.0% 23 0.0% 12 0.2% 25 0.2% 115.2k 5 0.0% 11 0.0% 7 0.0% 15 0.0% 8 -3.5% 16 2.1% 230.4k 2 0.0% 5 0.0% 3 0.0% 7 0.0% 3 8.5% 8 -3.5% 250k 2 -7.8% 5 -7.8% 3 -7.8% 6 5.3% 3 0.0% 7 0.0% 0.5M - - 2 -7.8% 1 -7.8% 3 -7.8% 1 0.0% 3 0.0% 1M - - - - 0 -7.8% 1 -7.8% 0 0.0% 1 0.0% Max. (1) 691.2 kbps 1.3824 Mbps 921.6 kbps 1.8432 Mbps 1 Mbps 2 Mbps Notes: 1. UBRR = 0, Error = 0.0% ATmega256/128/64RFR2 400 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 24 USART in SPI Mode The Universal Synchronous and Asynchronous Serial Receiver and Transmitter (USART) can be set to a master SPI compliant mode of operation. The Master SPI Mode (MSPIM) has the follo wing features: • Full duplex, three-wire synchronous data transfer • Master operation • Supports all four SPI modes of operation (mode 0, 1, 2, and 3) • LSB first or MSB first data transfer (configurable data order) • Queued operation (double buffered) • High resolution baud rate generator • High speed operation (f = f /2) XCK,MAX CK • Flexible interrupt generation 24.1 Overview Setting both UMSELn1:0 bit s to one enables the USART in MSPIM logic. In this mode of operation the SPI master control logic takes direct control over the USART resources. These resources include the transmitter and receiver shift register and buffers, and the baud rate generator. The parity generator and checker, the data and clock recovery logic, and the RX and TX control logic is disabled. The USART RX and TX control logic is replaced by a common SPI transfer control logic. However, the pin control logic and interrupt generation logic is identical in both modes of operation. The I/O register locations are the same in both modes. However, some of the functionality of the control re gisters changes when using MSPIM. 24.2 USART MSPIM vs. SPI The ATmega256/128/64RFR2 USART in MSPIM mode is fully compatible with the ATmega256/128/64RFR2 SPI regarding: • Master mode timing diagram. • The UCPOLn bit functionality is identical to the SPI CPOL bit. • The UCPHAn bit functionality is identical to the SPI CPHA bit. • The UDORDn bit functionality is identical to the SPI DORD bit. However, since the USART in MSPIM mode reuses the USART resources, the use of the USART in MSPIM mode is somewhat different compared to the SPI. In addition to differences of the control register bits, and that only master operation is supported by the USART in MSPIM mode, the following features differ between the two modules: • The USART in MSPIM mode includes (double) buffering of the transmitter. The SPI has no buffer. • The USART in MSPIM mode receiver includes an additional buffer level. • The SPI WCOL (Write Co llision) bit is not included in USART in MSPIM mode. • The SPI double speed mode (SPI2X) bit is not included. However, the same effect is achieved by setting UBRRn accordingly. • Interrupt timing is not compatible. • Pin control differs due to the master only operation of the USART in MSPIM mode. A comparison of the USART in MSPIM mode and the SPI pins is shown in Table 24–3 on page 406. 401 8393C-MCU Wireless-09/14

24.2.1 Clock Generation The Clock Generation logic generates the base clock for the Transmitter and Receiver. For USART MSPIM mode of operation only internal clock generation (i.e. master operation) is supported. Th e Data Direction Register for the XCKn pin (DDR_XCKn) must therefore be set to one (i.e. as output) for the USART in MSPIM to operate correctly. Preferably the DDR_XCKn should be set up before the USART in MSPIM is enabled (i.e. TXENn and RXENn bit set to one). The internal clock generation used in MSPIM mode is identical to the USART synchronous master mode. The baud rate or UBRRn setting can therefore be calculated using the same equations, see Table 24-1 below: Table 24-1. Equations for Calculating Baud Rate Register Setting Operating Mode Equation for Calculating Equation for Calculating Baud Rate(1) UBRR Value Synchronous Master mode f f BAUD= OSC UBRRn= OSC −1 2(UBRRn+1) 2BAUD Note: The Baud rate is defined to be the transfer rate in bit per second (bps) BAUD Baud rate (in bits per second, bps) f System Oscillator clock frequency OSC UBRRn Contents of the UBRRHn and UBRRLn Registers, (0-4095) 24.3 SPI Data Modes and Timing There are four combinations of XCKn (SCK) phase and polarity with respect to serial data, which are determined by control bits UCPHAn and UCPOLn. The data transfer timing diagrams are shown in Figure 24-1 below. Data bits are shifted out and latched in on opposite edges of the XCKn signal, ensuring sufficient time for data signals to stabilize. The UCPOLn and UCPHAn functionality is summarized in Table 24-2 below. Note that changing the setting of any of these bits will corrupt all ongoing communication for both the receiver and transmitter. Figure 24-1. UCPHAn and UCPOLn data transfer timing diagrams UCPOL=0 UCPOL=1 1 = A XCK XCK H P Data setup (TXD) Data setup (TXD) C U Data sample (RXD) Data sample (RXD) 0 = XCK XCK A H P Data setup (TXD) Data setup (TXD) C U Data sample (RXD) Data sample (RXD) Table 24-2. UCPOLn and UCPHAn Functionality UCPOLn UCPHAn SPI Mode Leading Edge Trailing Edge 0 0 0 Sample (Rising) Setup (Falling) 0 1 1 Setup (Rising) Sample (Falling) 1 0 2 Sample (Falling) Setup (Rising) ATmega256/128/64RFR2 402 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 UCPOLn UCPHAn SPI Mode Leading Edge Trailing Edge 1 1 3 Setup (Falling) Sample (Rising) 24.4 Frame Formats A serial frame for the MSPIM is defined to be one character of 8 data bits. The USART in MSPIM mode has two valid frame formats: • 8-bit data with MSB first • 8-bit data with LSB first A frame starts with the least or most significant data bit. Then the next data bits, up to a total of eight, are succeeding, ending with the most or least significant bit accordingly. When a complete frame is transmitted, a new frame can directly follow it, or the communication line can be set to an idle (high) state. The UDORDn bit in UCSRnC sets the frame format used by the USART in MSPIM mode. The Receiver and Transmitter use the same setting. Note that changing the setting of any of these bits will corrupt all ongoing communication for both the Receiver and Transmitter. 16-bit data transfer can be achieved by writing two data bytes to UDRn. A UART transmit complete interrupt will then signal that the 16-bit value has been shifted out. 24.4.1 USART MSPIM Initialization The USART in MSPIM mode has to be initialized before any communication can take place. The initialization process normally consists of setting the baud rate, setting master mode of operation (by setting DDR_XCKn to one), setting frame format and enabling the Transmitter and the Receiver. Only the transmitter can operate independently. For interrupt driven USART operation, the Global Interrupt Flag should be cleared (and thus interrupts globally disabled) when doing the initialization. Note: To ensure immediate initialization of the XCKn output the baud-rate register (UBRRn) must be z ero at the time the transmitter is enabled. Contrary to the normal mode USART operation the UBRRn must then be written to the desired value after the transmitter is enabled, but before the first transmission is started. Setting UBRRn to zero before enabling the transmitter is not necessary if the initialization is done immediately after a reset since UBRRn is reset to zero. Before doing a re-initialization with changed baud rate, data mode, or frame format, be sure that there is no ongoing transmissions during the period the registers are changed. The TXCn Flag can be used to check that the Transmitter has completed all transfers, and the RXCn Flag can be used to check that there are no unread data in the receive buffer. Note that the TXCn Flag must be cleared before each transmission (before UDRn is written) if it is used for this purpose. The following simple USART initialization code examples show one assembly and one C function that are equal in functionality. The examples assume polling (no interrupts enabled). The baud rate is given as a function parameter. For the assembly code, the baud rate parameter is assumed to be stored in the r17:r16 registers. 403 8393C-MCU Wireless-09/14

Assembly Code Example(1) USART_Init: clr r18 out UBRRnH,r18 out UBRRnL,r18 ; Setting the XCKn port pin as output, enables master mode. sbi XCKn_DDR, XCKn ; Set MSPI mode of operation and SPI data mode 0. ldi r18, (1<<UMSELn1)|(1<<UMSELn0)|(0<<UCPHAn)|(0<<UCPOLn) out UCSRnC,r18 ; Enable receiver and transmitter. ldi r18, (1<<RXENn)|(1<<TXENn) out UCSRnB,r18 ; Set baud rate. ; IMPORTANT: ; The Baud Rate must be set after the transmitter is enabled! out UBRRnH, r17 out UBRRnL, r18 ret C Code Example(1) void USART_Init( unsigned int baud ) { UBRRn = 0; /* Setting the XCKn port pin as output, enables master mode. */ XCKn_DDR |= (1<<XCKn); /* Set MSPI mode of operation and SPI data mode 0. */ UCSRnC = (1<<UMSELn1)|(1<<UMSELn0)|(0<<UCPHAn)|(0<<UCPOLn); /* Enable receiver and transmitter. */ UCSRnB = (1<<RXENn)|(1<<TXENn); /* Set baud rate. */ /* IMPORTANT: */ /* The Baud Rate must be set after the transmitter is enabled */ UBRRn = baud; } Note: 1. See "About Code Examples" on page 7 24.5 Data Transfer Using the USART in MSPI mode requires the Transmitter to be enabled, i.e. the TXENn bit in the UCSRnB register is set to one. When the Transmitter is enabled, the normal port operation of the TxDn pin is overridden and given the function as the Transmitter's serial output. Enabling the receiver is optional and is done by setting the RXENn bit in the UCSRnB register to one. When the receiver is enabled, the normal pin operation of the RxDn pin is overridden and given the function as the Receiver's serial input. The XCKn will in both cases be used as the transfer clock. After initialization the USART is ready for doing data transfers. A data transfer is initiated by writing to the UDRn I/O location. This is the case for both sending and receiving data since the transmitter controls the transfer clock. The data written to ATmega256/128/64RFR2 404 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 UDRn is moved from the transmit buffer to the shift register when the shift register is ready to send a new frame. Note: To keep the input buffer in sync with the number of data bytes transmitted, the UDRn register must be read once for each byte transmitted. The input buffer operation is identical to normal USART mode, i.e. if an overflow occurs the character last received will be lost, not the first data in the buffer. This means that if four bytes are transferred, byte 1 first, then byte 2, 3, and 4, and the UDRn is not read before all transfers are completed, then byte 3 to be received will be lost, and not byte 1. The following code examples show a simple USART in MSPIM mode transfer function based on polling of the Data Register Empty (UDREn) Flag and the Receive Complete (RXCn) Flag. The USART h as to be initialized before the function can be used. For the assembly code, the data to be sent is assumed to be stored in Register r16 and the data received will be available in the same register (r16) after the function returns. The function simply waits for the transmit buffer to be empty by checking the UDREn Flag, before loading it with new data to be transmitted. The function then waits for data to be present in the receive buffer by checking the RXCn Flag, before reading the buffer and returning the value. Assembly Code Example(1) USART_MSPIM_Transfer: ; Wait for empty transmit buffer sbis UCSRnA, UDREn rjmp USART_MSPIM_Transfer ; Put data (r16) in to buffer, sends the data out UDRn,r16 ; Wait for data to be received USART_MSPIM_Wait_RXCn: sbis UCSRnA, RXCn rjmp USART_MSPIM_Wait_RXCn ; Get and return received data from buffer in r16, UDRn ret C Code Example(1) unsigned char USART_Receive( void ) { /* Wait for empty transmit buffer */ while ( !( UCSRnA & (1<<UDREn)) ); /* Put data into buffer, sends the data */ UDRn = data; /* Wait for data t o be received */ while ( !(UCSRnA & (1<<RXCn)) ); /* Get and return received data from buffer */ return UDRn; } Notes: 1. See "About Code Examples" on page 7 405 8393C-MCU Wireless-09/14

24.5.1 Transmitter and Receiver Flags and Interrupts The RXCn, TXCn, and UDREn flags and corresponding interrupts in USART in MSPIM mode are identical in function to the normal USART operation. However, the receiver error status flags (FE, DOR , and PE) are not in use and are always read as zero. 24.5.2 Disabling the Transmitter or Receiver The disabling of the transmitter or receiver in USART in MSPIM mode is identical in function to the normal USART operation. 24.6 USART MSPIM Register Description The following section descri bes the registers used for SPI operation using the USART. 24.6.1 UDRn – USART MSPIM I/O Data Register The function and bit description of the USART data register (UDRn) in MSPI mode is identical to normal USART operation. See "UDR0 – USART0 I/O Data Register" on page 389. 24.6.2 UBRRnL and UBRRnH – USART MSPIM Baud Rate Registers The function and bit description of the baud rate registers in MSPI mode is identical to normal USART operation. See "UBRR0L – USART0 Baud Rate Register Low Byte" on page 393 and "UBRR0H – USART0 Baud Rate Register High Byte" on page 393. Table 24–3. Comparison of USART in MSPIM mode and SPI pins USART_MSPIM SPI Comment TxDn MOSI Master Out only RxDn MISO Master In only XCKn SCK (Functional identical) (N/A) S¯¯S Not supported by USART in MSPIM 24.6.3 UCSR0A – USART0 MSPIM Control and Status Register A Bit 7 6 5 4 3 2 1 0 NA ($C0) RXC0 TXC0 UDRE0 UCSR0A Read/Write R RW R Initial Value 0 0 0 • Bit 7 – RXC0 - USART Receive Complete This flag bit is set when there are unread data in the receive buffer and cleared when the receive buffer is empty (i.e., does not contain any unread data). If the Receiver is disabled, the receive buffer will be flushed and consequently the RXC0 bit will become zero. The RXC0 Flag can be used to generate a Receive Complete interrupt (see description of the RXCIE0 bit). • Bit 6 – TXC0 - USART Transmit Complete This flag bit is set when the entire frame in the Transmit Shift Register has been shifted out and there are no new data currently present in the transmit buffer (UDR0). The TXC0 Flag bit is automatically cleared when a transmit complete interrupt is executed, or it can be cleared by writing a one to its bit location. The TXC0 Flag can generate a Transmit Complete interrupt (see description of the TXCIE0 bit). ATmega256/128/64RFR2 406 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 • Bit 5 – UDRE0 - USART Data Register Empty The UDRE0 Flag indicates if the transmit buffer (UDR0) is ready to receive new data. If UDRE0 is one, the buffer is empty, and therefore ready to be written. The UDRE0 Flag can generate a Data Register Empty interrupt (see description of the UDRIE0 bit). UDRE0 is set after a reset to indicate that the Transmitter is ready. 24.6.4 UCSR0B – USART0 MSPIM Control and Status Register B Bit 7 6 5 4 3 2 1 0 NA ($C1) RXCIE0 TXCIE0 UDRIE0 RXEN0 TXEN0 UCSR0B Read/Write RW RW RW RW RW Initial Value 0 0 1 0 0 • Bit 7 – RXCIE0 - RX Complete Interrupt Enable Writing this bit to one enables interrupt on the RXC0 Flag. A USART Receive Complete interrupt will be generated o nly if the RXCIE0 bit is written to one, the Global Interrupt Flag in SREG is written to one and the RXC0 bit in UCSR0A is set. • Bit 6 – TXCIE0 - TX Complete Interrupt Enable Writing this bit to one enables interrupt on the TXC0 Flag. A USART Transmit Complete interrupt will be generated only if the TXCIE0 bit is written to one, the Global Interrupt Flag in SREG is written to one and the TXC0 bit in UCSR0A is set. • Bit 5 – UDRIE0 - USART Data Register Empty Interrupt Enable Writing this bit to one enables interrupt on the UDRE0 Flag. A Data Register Empty interrupt will be generated only if the UDRIE0 bit is written to one, the Global Interrupt Flag in SREG is written to one and the UDRE0 bit in UCSR0A is set. • Bit 4 – RXEN0 - Receiver Enable Writing this bit to one enables the USART Receiver in MSPIM mode. The Receiver will override normal port operation for the RxD0 pin when enabled. Disabling the Receiver will flush the receive buffer. Only enabling the receiver in MSPI mode (i.e. setting RXEN0=1 and TXEN0=0) has no meaning since it is the transmitter that controls the transfer clock and since only master mode is supported. • Bit 3 – TXEN0 - Transmitter Enable Writing this bit to one enables the USART Transmitter. The Transmitter will override normal port operation for the TxD0 pin when enabled. The disabling of the Transmitter (writing TXEN0 to zero) will not become effective until ongoing and pending transmissions are completed, i.e., when the Transmit Shift Register and Transmit Buffer Register do not contain data to be transmitted. When disabled, the Transmitter will no longer override the TxD0 port. 24.6.5 UCSR0C – USART0 MSPIM Control and Status Register C Bit 7 6 5 4 3 2 1 0 NA ($C2) UDORD0 UCPHA0 UCPOL0 UCSR0C Read/Write RW RW RW Initial Value 1 1 0 • Bit 2 – UDORD0 - Data Order 407 8393C-MCU Wireless-09/14

When set to one the LSB of the data word is transmitted first. When set to zero the MSB of the data word is transmitted first. Refer to section "Frame Formats" for details. • Bit 1 – UCPHA0 - Clock Phase The UCPHA0 bit setting de termines if data is sampled on the leading (first) or tailing (last) edge of XCK0. Refer to the section "SPI Data Modes and Timing" for details. • Bit 0 – UCPOL0 - Clock Polarity The UCPOL0 bit sets the polarity of the XCK0 clock. The combination of the UCPOL0 and UCPHA0 bit settings determine the timing of the data transfer. Refer to the section "SPI Data Modes and Timing" for details. 24.6.6 UCSR1A – USART1 MSPIM Control and Status Register A Bit 7 6 5 4 3 2 1 0 NA ($C8) RXC1 TXC1 UDRE1 UCSR1A Read/Write R RW R Initial Value 0 0 0 • Bit 7 – RXC1 - USART Receive Complete This flag bit is set when there are unread data in the receive buffer and cleared when the receive buffer is empty (i.e., does not contain any unread data). If the Receiver is disabled, the receive buffer will be flushed and consequently the RXC1 bit will become zero. The RXC1 Flag can be used to generate a Receive Complete interrupt (see description of the RXCIE1 bit). • Bit 6 – TXC1 - USART Transmit Complete This flag bit is set when the entire frame in the Transmit Shift Register has been shifted out and there are no new data currently present in the transmit buffer (UDR1). The TXC1 Flag bit is automatically cleared when a transmit complete interrupt is executed, or it can be cleared by writing a one to its bit location. The TXC1 Flag can generate a Transmit Complete interrupt (see description of the TXCIE1 bit). • Bit 5 – UDRE1 - USART Data Register Empty The UDRE1 Flag indicates if the transmit buffer (UDR1) is ready to receive new data. If UDRE1 is one, the buffer is empty, and therefore ready to be written. The UDRE1 Flag can generate a Data Register Empty interrupt (see description of the UDRIE1 bit). UDRE1 is set after a reset to indicate that the Transmitter is ready. 24.6.7 UCSR1B – USART1 MSPIM Control and Status Register B Bit 7 6 5 4 3 2 1 0 NA ($C9) RXCIE1 TXCIE1 UDRIE1 RXEN1 TXEN1 UCSR1B Read/Write RW RW RW RW RW Initial Value 0 0 1 0 0 • Bit 7 – RXCIE1 - RX Complete Interrupt Enable Writing this bit to one enables interrupt on the RXC1 Flag. A USART Receive Complete interrupt will be generated only if the RXCIE1 bit is written to one, the Global Interrupt Flag in SREG is written to one and the RXC1 bit in UCSR1A is set. ATmega256/128/64RFR2 408 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 • Bit 6 – TXCIE1 - TX Complete Interrupt Enable Writing this bit to one enables interrupt on the TXC1 Flag. A USART Transmit Complete interrupt will be generated only if the TXCIE1 bit is written to one, the Global Interrupt Flag in SREG is written to one and the TXC1 bit in UCSR1A is set. • Bit 5 – UDRIE1 - USART Data Register Empty Interrupt Enable Writing this bit to one enables interrupt on the UDRE1 Flag. A Data Register Empty interrupt will be generated only if the UDRIE1 bit is written to one, the Global Interrupt Flag in SREG is written to one and the UDRE1 bit in UCSR1A is set. • Bit 4 – RXEN1 - Receiver Enable Writing this bit to one enables the USART Receiver in MSPIM mode. The Receiver will override normal port operation for the RxD1 pin when enabled. Disabling the Receiver will flush the receive buffer. Only enabling the receiver in MSPI mode (i.e. setting RXEN1=1 and TXEN1=0) has no meaning since it is the transmitter that controls the transfer clock and since only master mode is supported. • Bit 3 – TXEN1 - Transmitter Enable Writing this bit to one enab les the USART Transmitter. The Transmitter will override normal port operation for the TxD1 pin when enabled. The disabling of the Transmitter (writing TXEN1 to zero) will not become effective until ongoing and pending transmissions are completed, i.e., when the Transmit Shift Register and Transmit Buffer Register do not contain data to be transmitted. When disabled, the Transmitter will no longer override the TxD1 port. 24.6.8 UCSR1C – USART1 MSPIM Control and Status Regi ster C Bit 7 6 5 4 3 2 1 0 NA ($CA) UDORD1 UCPHA1 UCPOL1 UCSR1C Read/Write RW RW RW Initial Value 1 1 0 • Bit 2 – UDORD1 - Data Order When set to one the LSB of the data word is transmitted first. When set to zero the MSB of the data word is transmitted first. Refer to section "Frame Formats" for details. • Bit 1 – UCPHA1 - Clock Phase The UCPHA1 bit setting determines if data is sampled on the leading (first) or tailing (last) edge of XCK1. Refer to the section "SPI Data Modes and Timing" for details. • Bit 0 – UCPOL1 - Clock Polarity The UCPOL1 bit sets the polarity of the XCK1 clock. The combination of the UCPOL1 and UCPHA1 bit settings determine the timing of the data transfer. Refer to the section "SPI Data Modes and Timing" for details. 409 8393C-MCU Wireless-09/14

25 2-wire Serial Interface 25.1 Features • Simple yet powerful and flexible communication interface, only two bus lines needed • Both master and slave operation supported • Device can operate as transmitter or receiver • 7-bit address space allows up to 128 different slave addresses • Multi-master arbitration support • Up to 400 kHz data transfer speed • Slew-rate limited output drivers • Noise suppression circuitry rejects spikes on bus lines • Fully programmable slave address with general call support • Address recognition causes wake-up when microcontroller is in sleep mode 25.2 2-wire Serial Interface Bus Definition The 2-wire Serial Interface (TWI) is ideally suited for typical microcontroller applications. The TWI protocol allows the systems designer to interconnect up to 128 different devices using only two bi-directional bus lines, one for clock (SCL) and one for data (SDA). The only external hardware needed to implement the bus is a single pull-up resistor for each of the TWI bus lines. All devices connected to the bus have individual addresses, and mechanisms for resolving bus contention are inherent in the TWI protocol. Figure 25-1. TWI Bus Interconnection DEVDD Device 1 Device 2 Device 3 ........ Device n R1 R2 SDA SCL 25.2.1 TWI Terminology The following definitions are frequently encountered in this section. Table 25-1. TWI Terminology Term Description Master The device that initiates and terminates a transmission. The Master also generates the SCL clock. Slave The device addressed by a Master. Transmitter The device placing data on the bus. Receiver The device reading data from the bus. ATmega256/128/64RFR2 410 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 The Power Reduction TWI bit, PRTWI bit in "PRR0 – Power Reduction Register0" on page 197 must be written to zero to enable the 2-wire Serial Interface. 25.2.2 Electrical Interconnection As depicted in Figure 25-1 on page 410, both bus lines are connected to the positive supply voltage through pull-up resistors. The bus drivers of all TWI-compliant devices are open-drain or open-collector. This implements a wired-AND function which is essential to the operation of the interface. A low level on a TWI bus line is generated when one or more TWI devices output a zero. A high level is output when all TWI devices trim-state their outputs, allowing the pull-up resistors to pull the line high. Note that all AVR devices connected to the TWI bus must be powered in order to allow any bus operation. The number of devices that can be connected to the bus is only limited by the bus capacitance limit of 400 pF and the 7-bit slave address space. A detailed specification of the electrical characteristics of the TWI is given in "2-wire Serial Interface Characteristics" on page 559. Two different sets of specifications are presented there, one relevant for bus speeds below 100 kHz, and one valid for bus speeds up to 400 kHz. 25.3 Data Transfer and Frame Format 25.3.1 Transferring Bits Each data bit transferred on the TWI bus is accompanied by a pulse on the clock line. The level of the data line must be stable when the clock line is high. The only exception to this rule is for generating start and stop conditions. Figure 25-2. Data Validity SDA SCL Data Stable Data Stable Data Change 25.3.2 START and STOP Conditions The Master initiates and terminates a data transmission. The transmission is initiated when the Master issues a START condition on the bus, and it is terminated when the Master issues a STOP condition. Between a START and a STOP condition, the bus is considered busy, and no ot her master should try to seize control of the bus. A special case occurs when a new START condition is issued between a START and STOP condition. This is referred to as a REPEATED START condition, and is used when the Master wishes to initiate a new transfer without relinquishing control of the bus. After a REPEATED START, the bus is considered busy until the next STOP. This is identical to the START behavior, and therefore START is used to describe both START and REPEATED START for the remainder of this datasheet, unless otherwise noted. As depicted below, START and STOP conditions are signaled by changing the level of the SDA line when the SCL line is high. 411 8393C-MCU Wireless-09/14

Figure 25-3. START, REPEATED START and STOP conditions SDA SCL START STOP START REPEATED START STOP 25.3.3 Address Packet Format All address packets transmitted on the TWI bus are 9 bits long, consisting of 7 address bits, one READ/WRITE control bit and an acknowledge bit. If the READ/WRITE bit is set, a read operation is to be performed, otherwise a write operation should be performed. When a Slave recognizes that it is being addressed, it should acknowledge by pulling SDA low in the ninth SCL (ACK) cycle. If the addressed Slave is busy, or for some other reason can not service the Master’s request, the SDA line should be left high in the ACK clock cycle. The Master can then transmit a STOP condition, or a REPEATED START condition to initiate a new transmission. An address packet consisting of a slave address and a READ or a WRITE bit is called SLA+R or SLA+W, respectively. The MSB of the address byte is transmitted first. Slave addresses can freely be allocated by the designer, b ut the address 0000 000 is reserved for a general call. When a general call is issued, all slaves should respond by pulling the SDA line low in the ACK cycle. A general call is used when a Master wishes to transmit the same message to several slaves in the system. When the general call address followed by a Write bit is transmitted on the bus, all slaves set up to acknowledge the general call will pull the SDA line low in the ack cycle. The following data packets will then be received by all the slaves that acknowledged the general call. Note that transmitting the general call address followed by a Read bit is meaningless, as this would cause contention if several slaves started transmitting different data. All addresses of the format 1111 xxx should be reserved for future purposes. Figure 25-4. Address Packet Format Addr MSB Addr LSB R/W ACK SDA SCL 1 2 7 8 9 START 25.3.4 Data Packet Format All data packets transmitted on the TWI bus are nine bits long, consisting of one data byte and an acknowledge bit. During a data transfer, the Master generates the clock and the START and STOP conditions, while the Receiver is responsible for acknowledging the reception. An Acknowledge (ACK) is signaled by the Receiver ATmega256/128/64RFR2 412 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 pulling the SDA line low during the ninth SCL cycle. If the Receiver leaves the SDA line high, a NACK is signaled. When the Receiver has received the last byte, or for some reason cannot receive any more bytes, it should inform the Transmitter by sending a NACK after the final byte. The MSB of the data byte is transmitted first. Figure 25-5. Data Packet Format Data MSB Data LSB ACK Aggregate SDA SDA from Transmitter SDA from Receiver SCL from Master 1 2 7 8 9 STOP, REPEATED SLA+R/W Data Byte START or Next Data Byte 25.3.5 Combining Address and Data Packets into a Transmission A transmission basically consists of a START condition, a SLA+R/W, one or more data packets and a STOP condition. An empty message, consisting of a START followed by a STOP condition, is illegal. Note that the Wired-ANDing of the SCL line can be used to implement handshaking between the Master and the Slave. The Slave can extend the SCL low period by pulling the SCL line low. This is useful if the clock speed set up by the Master is too fast for the Slave, or the Slave needs extra time for processing between the data transmissions. The Slave extending the SCL low period will not affect the SCL high period, which is determined by the Master. As a consequence, the Slave can reduce the TWI data transfer speed by prolonging the SCL duty cycle. Figure 25-6 below shows a typical data transmission. Note that several data bytes can be transmitted between the SLA+R/W and the STOP condition, depending on the software protocol implemented by the application software. Figure 25-6. Typical Data Transmission Addr MSB Addr LSB R/W ACK Data MSB Data LSB ACK SDA SCL 1 2 7 8 9 1 2 7 8 9 START SLA+R/W Data Byte STOP 25.4 Multi-master Bus Systems, Arbitration and Synchronization The TWI protocol allows bus systems with several masters. Special concerns have been taken in order to ensure that transmissions will proceed as normal, even if two or more masters initiate a transmission at the same time. Two problems arise in multi- master systems: 413 8393C-MCU Wireless-09/14

• An algorithm must be implemented allowing only one of the masters to complete the transmission. All other masters should cease transmission when they discover that they have lost the selection process. This selection process is called arbitration. When a contending master discovers that it has lost the arbitration process, it should immediately switch to Slave mode to check whether it is being addressed by the winning master. The fact that multiple masters have started transmission at the same time should not be detectable to the slaves, i.e. the data being transferred on the bus must not be corrupted. • Different masters may use different SCL frequencies. A scheme must be devised to synchronize the serial clocks from all masters, in order to let the transmission proceed in a lockstep fashion. This will facilitate the arbitration process. The wired-ANDing of the bus lines is used to solve both these problems. The serial clocks from all masters will be wired-ANDed, yielding a combined clock with a high period equal to the one from the Master with the shortest high period. The low period of the combined clock is equal to the low period of the Master with the longest low period. Note that all masters listen to the SCL line, effectively starting to count their SCL high and low time-out periods when the combined SCL line goes high or low, respectively. Figure 25-7. SCL Synchronization Between Multiple Masters TA TA low high SCL from Master A SCL from Master B SCL Bus Line T Blow TBhigh Masters Start Masters Start Counting Low Period Counting High Period Arbitration is carried out by all masters continuously monitoring the SDA line after outputting data. If the value read from the SDA line does not match the value the Master had output, it has lost the arbitration. Note that a Master can only lose arbitration when it outputs a high SDA value while another Master outputs a low value. The losing Master should immediately go to Slave mode, checking if it is being addressed by the winning Master. The SDA line should be left high, but losing masters are allowed to generate a clock signal until the end of the current data or address packet. Arbitration will continue until only one Master remains, and this may take many bits. If several masters are trying to address the same Slave, arbitration will continue into the data packet. Note that arbitration is not allowed between: • A REPEATED START condition and a data bit. • A STOP condition and a data bit. • A REPEATED START and a STOP condition. It is the user software’s responsibility to ensure that these illegal arbitration conditions never occur. This implies that in multi-master systems, all data transfers must use the same composition of SLA+R/W and data packets. In other words: All transmissions ATmega256/128/64RFR2 414 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 must contain the same number of data packets, otherwise the result of the arbitration is undefined. Figure 25-8. Arbitration Between Two Masters START Master A Loses Arbitration, SDA SDA SDA from A Master A SDA from Master B SDA Line Synchronized SCL Line 25.5 Overview of the TWI Module The TWI module is comprised of several sub-modules, as shown in Figure 25-9 below. All registers drawn in a thick line are accessible through the AVR data bus. Figure 25-9. Overview of the TWI Module SCL SDA Slew-rate Spike Slew-rate Spike Control Filter Control Filter Bus Interface Unit Bit Rate Generator START / STOP Spike Suppression Prescaler Control Address/Data Shift Bit Rate Register Arbitration detection Ack Register (TWDR) (TWBR) Address Match Unit Control Unit t Address Register Status Register Control Register ni (TWAR) (TWSR) (TWCR) U I W State Machine and T Address Comparator Status control 415 8393C-MCU Wireless-09/14

25.5.1 SCL and SDA Pins These pins interface the AVR TWI with the rest of the MCU system. The output drivers contain a slew-rate limiter in order to conform to the TWI specification. The input stages contain a spike suppressio n unit removing spikes shorter than 50 ns. Note that the internal pull-ups in the AVR pads can be enabled by setting the PORT bits corresponding to the SCL and SDA pins, as explained in the I/O Port section. The internal pull-ups can in some systems eliminate the need for external ones. 25.5.2 Bit Rate Generator Unit This unit controls the period of SCL when operating in a Master mode. The SCL period is controlled by settings in the TWI Bit Rate Register (TWBR) and the Prescaler bits in the TWI Status Register ( T WSR). Slave operation does not depend on Bit Rate or Prescaler settings, but the CPU clock frequency in the Slave must be at least 16 times higher than the SCL frequency. Note that slaves may prolong the SCL low period, thereby reducing the average TWI bus clock period. The SCL frequency is generated according to the following equation: CPU Clock frequency SCL frequency = 16+2(TWBR)⋅4TWPS • TWBR = Value of the TWI Bit Rate Register. • TWPS = Value of the prescaler bits in the TWI Status Register. Note that pull-up resistor values should be selected according to the SCL frequency and the capacitive bus line load. See in "2-wire Serial Interface Characteristics" on page 559 for value of pull-up resistor. 25.5.3 Bus Interface Unit This unit contains the Data and Address Shift Register (TWDR), a START/STOP Controller and Arbitration detection hardware. The TWDR contains the address or data bytes to be transmitted, or the address or data bytes received. In addition to the 8-bit TWDR, the Bus Interface Unit also contains a register containing the (N)ACK bit to be transmitted or received. This (N)ACK Register is not directly accessible by the application software. However, when receiving, it can be set or cleared by manipulating the TWI Control Register (TWCR). When in Transmitter mode, the value of the received (N)ACK bit can be determined by the value in the TWSR. The START/STOP Controller is responsible for generation and detection of START, REPEATED START, and STOP conditions. The START/STOP controller is able to detect START and STOP c onditions even when the AVR MCU is in one of the sleep modes, enabling the MCU to wake up if addressed by a Master. If the TWI has initiated a transmission as Master, the Arbitration Detection hardware continuously monitors the transmission trying to determine if arbitration is in process. If the TWI has lost an arbitration, the Control Unit is informed. Correct action can then be taken and appropriate statu s codes generated. 25.5.4 Address Match Unit The Address Match unit checks if received address bytes match the seven-bit address in the TWI Address Register (TWAR). If the TWI General Call Recognition Enable (TWGCE) bit in the TWAR is written to one, all incoming address bits will also be compared against the General Call address. Upon an address match, the Control Unit is informed, allowing correct action to be taken. The TWI may or may not acknowledge its address, depending on settings in the TWCR. The Address Match unit is able to ATmega256/128/64RFR2 416 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 compare addresses even if the AVR MCU is in sleep mode, enabling the MCU to wake up if addressed by a Master. If another interrupt (e.g., INT0) occurs during TWI Power- down address match and wakes up the CPU, the TWI aborts operation and return to it’s idle state. If this cause any problems, ensure that TWI Address Match is the only enabled interrupt when ente ring Power-down. 25.5.5 Control Unit The Control unit monitors the TWI bus and generates responses corresponding to settings in the TWI Control Register (TWCR). When an event requiring the attention of the application occurs on the TWI bus, the TWI Interrupt Flag (TWINT) is asserted. In the next clock cycle, the TWI Status Register (TWSR) is updated with a status code identifying the event. The TWSR only contains relevant status information when the TWI Interrupt Flag is asserted. At all other times, the TWSR contains a special status code indicating that no relevant status information is available. As long as the TWINT Flag is set, the SCL line is held low. This allows the application software to complete its tasks before allowing the TWI transmission to continue. The TWINT Flag is set in the following situations: • After the TWI has transmitted a START/REPEATED START condition. • After the TWI has transmitted SLA+R/W. • After the TWI has transmitted an address byte. • After the TWI has lost arbitration. • After the TWI has been addressed by own slave address or general call. • After the TWI has received a data byte. • After a STOP or REPEA TED START has been received while still addressed as a Slave. • When a bus error has occurred due to an illegal START or STOP condition. 25.6 Using the TWI The ATmega256/128/64RFR2 TWI is byte-oriented and interrupt based. Interrupts are issued after all bus events, like reception of a byte or transmission of a START condition. Because the TWI is interrupt-based, the application software is free to carry on other operations during a TWI byte transfer. Note that the TWI Interrupt Enable (TWIE) bit in TWCR together with the Global Interrupt Enable bit in SREG allow the application to decide whether or not assertion of the TWINT Flag should generate an interrupt request. If the TWIE bit is cleared, the application must poll the TWINT Flag in order to detect actions on the TWI bus. When the TWINT Flag is asserted, the TWI has finished an operation and awaits application response. In this case, the TWI Status Register (TWSR) contains a value indicating the current state of the TWI bus. The application software can then decide how the TWI should behave in the next TWI bus cycle by manipulating the TWCR and TWDR Registers. Figure 25-10 on page 418 is a simple example of how the application can interface to the TWI hardware. In this example, a Master wishes to transmit a single data byte to a Slave. This description is quite abstract, a more detailed explanation follows later in this section. A simple code example implementing the desired behavior is also presented. 417 8393C-MCU Wireless-09/14

Figure 25-10. Interfacing the Application to the TWI in a Typical Transmission 3. Check TWSR to see if START was 5. Check TWSR to see if SLA+W was 1. Application 7. Check TWSR to see if data was sent sent. Application loads SLA+W into sent and ACK received. n writes to TWCR to and ACK received. plicatioAction transinmitiisasteion of TsWigDnRalT,s Wa innItdNo TlTo aWisd Cws Rrait,pt empnrao tkpoirn ioa sntueer ,ce o tnhtarot l AlpoTpaWldi csCa aRtipo, pnmr olaopkaridniasgt eds auctroaen ittnrhotaol t s TTigWWnDIaNlRsT ,i naistnod Aspipglnicaalsti oton sloeandds S aTpOpPro pinrtioa tTeW coCnRtr,ol p START making sure that TWINT is written to one A and TWSTA is written to zero. written to one TWI bus START SLA+W A Data A STOP Indicates e 4. TWINT set. TWIardwarAction SSTtaAt2Ru.sT T cWcoodInNedT iitn isodenict .saetenst SStaLtuAs+ cWo dsee nint,d AicCaKtes daSttaa ts6ue.s nT ctW,o AdINCeT Kin srdeeictc.aetievesd TWINT set H received 1. The first step in a TWI transmission is to transmit a START condition. This is done by writing a specific value into TWCR, instructing the TWI hardware to transmit a START condition. Which value to write is described later on. However, it is important that the TWINT bit is set in the value written. Writing a one to TWINT clears the flag. The TWI will not start any operation as long as the TWINT bit in TWCR is set. Immediately after the application has cleared TWINT, the TWI will initiate transmission of the START condition. 2. When the START condition has been transmitted, the TWINT Flag in TWCR is set, and TWSR is updated with a status code indicating that the START condition has successfully been sent. 3. The application software should now examine the value of TWSR, to make sure that the START condition was successfully transmitted. If TWSR indicates otherwise, the application software might take some special action, like calling an error routine. Assuming that the status code is as expected, the application must load SLA+W into TWDR. Remember that TWDR is used both for address and data. After TWDR has been loaded with the desired SLA+W, a specific value must be written to TWCR, instructing the TWI hardware to transmit the SLA+W present in TWDR. Which value to write is described later on. However, it is important that the TWINT bit is set in the value written. Writing a one to TWINT clears the flag. The TWI will not start any operation as long as the TWINT bit in TWCR is set. Immediately after the application has cleared TWINT, the TWI will initiate transmission of the address packet. 4. When the address packet has been transmitted, the TWINT Flag in TWCR is set, and TWSR is updated with a status code indicating that the address packet has successfully been sent. The status code will also reflect whether a Slave acknowledged the packe t or not. 5. The application software should now examine the value of TWSR, to make sure that the address packet was successfully transmitted, and that the value of the ACK bit was as expected. If TWSR indicates otherwise, the application software might take some special action, like calling an error routine. Assuming that the status code is as expected, the application must load a data packet into TWDR. Subsequently, a specific value must be written to TWCR, instructing the TWI hardware to transmit the data packet present in TWDR. Which value to write is described later on. However, it is important that the TWINT bit is set in the value written. Writing a one to TWINT ATmega256/128/64RFR2 418 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 clears the flag. The TWI will not start any operation as long as the TWINT bit in TWCR is set. Immediately after the application has cleared TWINT, the TWI will initiate transmission of the data packet. 6. When the data packet has been transmitted, the TWINT Flag in TWCR is set, and TWSR is updated with a status code indicating that the data packet has successfully been sent. The status code will also reflect whether a Slave acknowledged the packet or not. 7. The application software should now examine the value of TWSR, to make sure that the data packet was successfully transmitted, and that the value of the ACK bit was as expected. If TWSR indicates otherwise, the application software might take some special action, like calling an error routine. Assuming that the status code is as expected, the application must write a specific value to TWCR, instructing the TWI hardware to transmit a STOP condition. Which value to write is described later on. However, it is important that the TWINT bit is set in the value written. Writing a one to TWINT clears the flag. The TWI will not start any operation as long as the TWINT bit in TWCR is set. Immediately after the application has cleared TWINT, the TWI will initiate transmission of the STOP condition. Note that TWINT is NOT set after a STOP condition has been sent. Even though this example is simple, it shows the principles involved in all TWI transmissions. These can be summarized as follows: • When the TWI has finished an operation and expects application response, the TWINT Flag is set. The SCL line is pulled low until TWINT is cleared. • When the TWINT Flag is set, the user must update all TWI Registers with the value relevant for the next TWI bus cycle. As an example, TWDR must be loaded with the value to be transmitted in the next bus cycle. • After all TWI Register updates and other pending application software tasks have been completed, TWCR is written. When writing TWCR, the TWINT bit should be set. Writing a one to TWINT clears the flag. The TWI will then commence executing whatever operation was specified by the TWCR setting. In the following an assembly and C implementation of the example is given. Note that the code below assumes that several definitions have been made, for example by using include-files. Table 25-2. Code example Assembly Code Example C Example Comments 1 ldi TWCR = (1<<TWINT)|(1<<TWSTA)| Send START condition r16,(1<<TWINT)|(1<<TWSTA)| (1<<TWEN) (1<<TWEN) out TWCR, r16 2 wait1: while (!(TWCR & (1<<TWINT))); Wait for TWINT Flag set. This in r16,TWCR indicates that the START condition has been transmitted sbrs r16,TWINT rjmp wait1 3 in r16,TWSR if ((TWSR & 0xF8) != START) Check value of TWI Status Register. andi r16, 0xF8 ERROR(); Mask prescaler bits. If status different from START go to ERROR cpi r16, START brne ERROR ldi r16, SLA_W TWDR = SLA_W; Load SLA_W into TWDR Register. out TWDR, r16 TWCR = (1<<TWINT)|(1<<TWEN); Clear TWINT bit in TWCR to start transmission of address ldi r16, (1<<TWINT)|(1<<TWEN) out TWCR, r16 419 8393C-MCU Wireless-09/14

Assembly Code Example C Example Comments 4 wait2: while (!(TWCR & (1<<TWINT))); Wait for TWINT Flag set. This in r16,TWCR indicates that the SLA+W has been sbrs r16,TWINT transmitted, and ACK/NACK has been received. rjmp wait2 5 in r16,TWSR if ((TWSR & 0xF8) != MT_SLA_ACK) Check value of TWI Status Register. andi r16, 0xF8 ERROR(); Mask prescaler bits. If status different from MT_SLA_ACK go to ERROR cpi r16, MT_SLA_ACK brne ERROR ldi r16, DATA TWDR = DATA; Load DATA into TWDR Register. out TWDR, r16 TWCR = (1<<TWI NT) | (1<<TWEN); Clear TWINT bit in TWCR to start transmission of data ldi r16, (1<<TWINT)|(1<<TWEN) out TWCR, r16 6 wait3: while (!(TWCR & (1<<TWINT))); Wait for TWINT Flag set. This in r16,TWCR indicates that the DATA has been transmitted, and ACK/NACK has sbrs r16,TWINT been received. rjmp wait3 7 in r16,TWSR if ((TWSR & 0xF8) != MT_DATA_ACK) Check value of TWI Status Register. andi r16, 0xF8 ERROR(); Mask prescaler bits. If status different from MT_DATA_ACK go to ERROR cpi r16, MT_DATA_ACK brne ERROR ldi r16,(1<<TWINT)|(1<<TWEN)| TWCR = (1<<TWINT)|(1<<TWEN)| Transmit STOP condition (1<<TWSTO) (1<<TWSTO); out TWCR, r16 25.7 Transmission Modes The TWI can operate in one of four major modes. These are named Master Transmitter (MT), Master Receiver (MR), Slave Transmitter (ST) and Slave Receiver (SR). Several of these modes can be used in the same application. As an example, the TWI can use MT mode to write data into a TWI EEPROM, MR mode to read the data back from the EEPROM. If other masters are present in the system, some of these might transmit data to the TWI, and then SR mode would be used. It is the application software that decides which modes are legal. The following sections describe each of these modes. Possible status codes are described along with figures detailing data transmission in each of the modes. These figures contain the following abbreviations: S: START condition Rs: REPEATED START condition R: Read bit (high level at SDA) W: Write bit (low level at SDA) Data: 8-bit data byte P: STOP condition S_LA: Slave Address A: Acknowledge bit (low level at SDA) A: Not acknowledge bit (high level at SDA) In Figure 25-12 on page 422 to Figure 25-18 on page 432 circles are used to indicate that the TWINT Flag is set. The numbers in the circles show the status code held in TWSR, with the prescaler bits masked to zero. At these points, actions must be taken by the application to continue or complete the TWI transfer. The TWI transfer is suspended until the TWINT Flag is cleared by software. When the TWINT Flag is set, the status code in TWSR is used to determine the appropriate software action. For each status code, the required software action and ATmega256/128/64RFR2 420 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 details of the following serial transfer are given in Table 25-3 on page 423 to Table 25-6 on page 431. Note that the prescaler bits are masked to zero in these tables. 25.7.1 Master Transmitter Mode In the Master Transmitter mode, a number of data bytes are transmitted to a Slave Receiver (see Figure 25-11 below). In order to enter a Master mode, a START condition must be transmitted. The format of the following address packet determines whether Master Transmitter or Master Receiver mode is to be entered. If SLA+W is transmitted, MT mode is entered, if SLA+R is transmitted, MR mode is entered. All status codes mentioned in this section assume that the prescaler bits are zero or are masked to zero. Figure 25-11. Data Transfer in Master Transmitter Mode DEVDD Device 1 Device 2 MASTER SLAVE Device 3 ........ Device n R1 R2 TRANSMITTER RECEIVER SDA SCL A START condition is sent by writing the following value to TWCR: TWCR TWINT TWEA TWSTA TWSTO TWWC TWEN – TWIE Value 1 X 1 0 X 1 0 X TWEN must be set to enable the 2-wire Serial Interface, TWSTA must be written to one to transmit a START condit ion and TWINT must be written to one to clear the TWINT Flag. The TWI will then test the 2-wire Serial Bus and generate a START condition as soon as the bus becomes free. After a START condition has been transmitted, the TWINT Flag is set by hardware, and the status code in TWSR will be 0x08 (see Table 25-3 on page 423). In order to enter MT mode, SLA+W must be transmitted. This is done by writing SLA+W to TWDR. Thereafter the TWINT bit should be cleared (by writing it to one) to continue the transfer. This is accomplished by writing the following value to TWCR: TWCR TWINT TWEA TWSTA TWSTO TWWC TWEN – TWIE Value 1 X 0 0 X 1 0 X When SLA+W have been transmitted and an acknowledgement bit has been received, TWINT is set again and a number of status codes in TWSR are possible. Possible status codes in Master mo d e are 0x18, 0x20, or 0x38. The appropriate action to be taken for each of these status codes is detailed in Table 25-3 on page 423. When SLA+W has been successfully transmitted, a data packet should be transmitted. This is done by writing the data byte to TWDR. TWDR must only be written when TWINT is high. If not, the access will be discarded, and the Write Collision bit (TWWC) will be set in the TWCR Register. After updating TWDR, the TWINT bit should be cleared (by writing it to one) to continue the transfer. This is accomplished by writing the following value to TWCR: 421 8393C-MCU Wireless-09/14

TWCR TWINT TWEA TWSTA TWSTO TWWC TWEN – TWIE Value 1 X 0 0 X 1 0 X This scheme is repeated un til the last byte has been sent and the transfer is ended by generating a STOP condition or a repeated START condition. A STOP condition is generated by writing the following value to TWCR: TWCR TWINT TWEA TWSTA TWSTO TWWC TWEN – TWIE Value 1 X 0 1 X 1 0 X A REPEATED START condition is generated by writing the following value to TWCR: TWCR TWINT TWEA TWSTA TWSTO TWWC TWEN – TWIE Value X 1 0 X 1 0 X After a REPEATED START condition (state 0x10) the 2-wire Serial Interface can access the same Slave again, or a new Slave without transmitting a STOP condition. Repeated START enables the Master to switch between Slaves, Master Transmitter mode and Master Receiver mode without losing control of the bus. Figure 25-12. Formats and States in the Master Transmitter Mode MT Successful transmission S SLA W A DATA A P to a slave receiver $08 $18 $28 Next transfer started with a RS SLA W repeated start condition $10 Not acknowledge R received after the A P slave address $20 MR Not acknowledge received after a data A P byte $30 Aadrbdirterastsio onr ldoastt ain b syltaeve A or A Otchoenrt imnuaesster A or A Otchoenrt imnuaesster $38 $38 Aadrbdirterastsioend laoss ts alanvde A Otchoenrt imnuaesster $68 $78 $B0 Tsota cteosr riens sploanved inmgode Any number of data bytes From master to slave DATA A and their associated acknowledge bits From slave to master This number (contained in TWSR) corresponds n to a defined state of the Two-Wire Serial Bus. The prescaler bits are zero or masked to zero ATmega256/128/64RFR2 422 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 Table 25-3. Status codes for Master Transmitter Mode Status Code Status of the 2-wire Application Software Response (TWSR) Serial Bus and 2-wire To TWCR Prescaler Serial Interface Next Action Taken by TWI Bits are 0 Hardware To/from TWDR ST A STO TWINT TWEA Hardware 0x08 A START condition has Load SLA+W 0 0 1 X SLA+W will be transmitted; ACK or been transmitted NOT ACK will be received 0x10 A repeated START Load SLA+W or 0 0 1 X SLA+W will be transmitted; ACK or condition has been NOT ACK will be received transmitted Load SLA+R 0 0 1 X SLA+R will be transmitted; Logic will switch to Master Receiver mode 0x18 SLA+W has been Load data byte o 0 0 1 X Data byte will be transmitted and transmitted; ACK has ACK or NOT ACK will be received been received No TWDR action or 1 0 1 X Repeated START will be transmitted No TWDR action or 0 1 1 X STOP condition will be transmitted and TWSTO Flag will be reset No TWDR action 1 1 1 X STOP condition followed by a START condition will be transmitted and TWSTO Flag will be reset 0x20 SLA+W has been Load data byte or 0 0 1 X Data byte will be transmitted and transmitted; NOT ACK ACK or NOT ACK will be received has been received No TWDR action or 1 0 1 X Repeated START will be transmitted No TWDR action or 0 1 1 X STOP condition will be transmitted and TWSTO Flag will be rese No TWDR action 1 1 1 X STOP condition followed by a START condition will be transmitted and TWSTO Flag will be reset 0x28 Data byte has been Load data byte or 0 0 1 X Data byte will be transmitted and transmitted; ACK has ACK or NOT ACK will be received been received No TWDR action or 1 0 1 X Repeated START will be transmitted No TWDR action or 0 1 1 X STOP condition will be transmitted and TWSTO Flag will be reset No TWDR action 1 1 1 X STOP condition followed by a START condition will be transmitted and TWSTO Flag will be reset 0x30 Data byte has been Load data byte or 0 0 1 X Data byte will be transmitted and transmitted; NOT ACK ACK or NOT ACK will be received has been received No TWDR action or 1 0 1 X Repeated START will be transmitted No TWDR action or 0 1 1 X STOP condition will be transmitted and TWSTO Flag will be reset No TWDR action 1 1 1 X STOP condition followed by a START condition will be transmitted and TWSTO Flag will be reset 0x38 Arbitration lost in SLA+W No TWDR action or 0 0 1 X 2-wire Serial Bus will be released and or data bytes not addressed Slave mode entered No TWDR action 1 0 1 X A START condition will be transmitted when the bus be-comes free 25.7.2 Master Receiver Mode In the Master Receiver mode, a number of data bytes are received from a Slave Transmitter (for Slave see Figure 25-13 on page 424). In order to enter a Master mode, a START condition must be transmitted. The format of the following address packet determines whether Master Transmitter or Master Receiver mode is to be entered. If SLA+W is transmitted, MT mode is entered, if SLA+R is transmitted, MR mode is entered. All the status codes mentioned in this section assume that the prescaler bits are zero or are masked to zero. 423 8393C-MCU Wireless-09/14

Figure 25-13. Data Transfer in Master Receiver Mode DEVDD Device 1 Device 2 MASTER SLAVE Device 3 ........ Device n R1 R2 RECEIVER TRANSMITTER SDA SCL A START condition is sent by writing the following value to TWCR: TWCR TWINT TWEA TWSTA TWSTO TWWC TWEN – TWIE Value 1 X 1 0 X 1 0 X TWEN must be written to one to enable the 2-wire Serial Interface, TWSTA must be written to one to transmit a START condition and TWINT must be set to clear the TWINT Flag. The TWI will then test the 2-wire Serial Bus and generate a START condition as soon as the bus becomes free. After a START condition has been transmitted, the TWINT Flag is set by hardware, and the status code in TWSR will be 0x08 (see Table 25-4 on page 425). In order to enter MR mode, SLA+R must be transmitted. This is done by writing SLA+R to TWDR. Thereafter the TWINT bit should be cleared (by writing it to one) to continue the transfer. This is accomplished by writing the following value to TWCR: TWCR TWINT TWEA TWSTA TWSTO TWWC TWEN – TWIE Value 1 X 0 0 X 1 0 X When SLA+R have been transmitted and an acknowledgement bit has been received, TWINT is set again and a number of status codes in TWSR are possible. Possible status codes in Master mode are 0x38, 0x40, or 0x48. The appropriate action to be taken for each of these status codes is detailed in Table 25-4 on page 425. Received data can be read from the TWDR Register when the TWINT Flag is set high by hardware. This scheme is repeated until the last byte has been received. After the last byte has been received, the MR should inform the ST by sending a NACK after the last received data byte. The tran sfer is ended by generating a STOP condition or a repeated START condition. A STOP condition is generated by writing the following value to TWCR: TWCR TWINT TWEA TWSTA TWSTO TWWC TWEN – TWIE value 1 X 0 1 X 1 0 X A REPEATED START condition is generated by writing the following value to TWCR: TWCR TWINT TWEA TWSTA TWSTO TWWC TWEN – TWIE Value 1 X 1 0 X 1 0 X After a repeated START condition (state 0x10) the 2-wire Serial Interface can access the same Slave again, or a new Slave without transmitting a STOP condition. Repeated ATmega256/128/64RFR2 424 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 START enables the Master to switch between Slaves, Master Transmitter mode and Master Receiver mode without losing control over the bus. Table 25-4. Status codes for Master Receiver Mode Status Code Status of the 2-wire Application S oftware Response (TWSR) Serial Bus and 2-wire To TWCR Prescaler Serial Interface Hard- Next Action Taken by TWI Bits are 0 ware To/from TWDR STA STD TWINT TWEA Hardware 0x08 A START condition has Load SLA+R 0 0 1 X SLA+R will be transmitted ACK or been transmitted NOT ACK will be received 0x10 A repeated START Load SLA+R or 0 0 1 X SLA+R will be transmitted ACK or condition has been NOTACK will be received transmitted Load SLA+W 0 0 1 X SLA+W will be transmitted Logic will switch to Master Transmitter mode 0x38 Arbitration lost in SLA+R No TWDR action or 0 0 1 X 2-wire Serial Bus will be released or NOT ACK bit and not addressed Slave mode will No TWDR action 1 0 1 X be entered A START condition will be transmitted when the bus becomes free 0x40 SLA+R has been No TWDR action or 0 0 1 0 Data byte will be received and NOT transmitted; ACK has ACK will be returned been received No TWDR action 0 0 1 1 Data byte will be received and ACK will be returned 0x48 SLA+R has been No TWDR action or 1 0 1 X Repeated START will be transmitted transmitted; NOT ACK has been received No TWDR action or 0 1 1 X STOP condition will be transmitted and TWSTO Flag will be reset No TWDR action 1 1 1 X STOP condition followed by a START condition will be transmitted and TWSTO Flag will be reset 0x50 Data byte has been Read data byte or 0 0 1 0 Data byte will be received and NOT received; ACK has been ACK will be returned returned Read data byte 0 0 1 1 Data byte will be received and ACK will be returned 0x58 Data byte has been Read data byte or 1 0 1 X Repeated START will be transmitted received; NOT ACK has been returned Read data byte or 0 1 1 X STOP condition will be transmitted and TWSTO Flag will be reset Read data byte 1 1 1 X STOP condition followed by a START condition will be transmitted and TWSTO Flag will be reset 425 8393C-MCU Wireless-09/14

Figure 25-14. Formats and States in the Master Receiver Mode MR Successful reception S SLA R A DATA A DATA A P from a slave receiver $08 $40 $50 $58 Next transfer started with a RS SLA R repeated start condition $10 Not acknowledge W received after the A P slave address $48 MT Aadrbdirterastsio onr ldoastt ain b syltaeve A or A Otchoenrt imnuaesster A Otchoenrt imnuaesster $38 $38 Aadrbdirterastsioend laoss ts alanvde A Otchoenrt imnuaesster $68 $78 $B0 Tsota cteosr riens sploanved inmgode Any number of data bytes From master to slave DATA A and their associated acknowledge bits From slave to master This number (contained in TWSR) corresponds n to a defined state of the Two-Wire Serial Bu s. The prescaler bits are zero or masked to zero 25.7.3 Slave Receiver Mode In the Slave Receiver mode, a number of data bytes are received from a Master Transmitter (see Figure 25-15 below). All the status codes mentioned in this section assume that the prescaler bits are zero or are masked to zero. Figure 25-15. Data transfer in Slave Receiver mode DEVDD Device 1 Device 2 SLAVE MASTER Device 3 ........ Device n R1 R2 RECEIVER TRANSMITTER SDA SCL To initiate the Slave Receiver mode, TWAR and TWCR must be initialized as follows: TWAR TWA6 TWA5 TWA4 TWA3 TWA2 TWA1 TWA0 TWGCE Value Device’s Own Slave Address ATmega256/128/64RFR2 426 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 The upper 7 bits are the address to which the 2-wire Serial Interface will respond when addressed by a Master. If the LSB is set, the TWI will respond to the general call address (0x00), otherwise it will ignore the general call address. TWCR TWINT TWEA TWSTA TWSTO TWWC TWEN – TWIE Value 0 1 0 0 0 1 0 X TWEN must be written to one to enable the TWI. The TWEA bit must be written to one to enable the acknowledgement of the device’s own slave address or the general call address. TWSTA and TWSTO must be written to zero. When TWAR and TWCR have been initialized, the TWI waits until it is addressed by its own slave address (or the general call address if enabled) followed by the data direction bit. If the direction bit is “0” (write), the TWI will operate in SR mode, otherwise ST mode is entered. After its own slave address and the write bit have been received, the TWINT Flag is set and a valid status code can be read from TWSR. The status code is used to determine the appropriate software action. The appropriate action to be taken for each status code is detailed in Table 25-5 below. The Slave Receiver mode may also be entered if arbitration is lost while the TWI is in the Master mode (see states 0x68 and 0x78). If the TWEA bit is reset during a transfer, the TWI will return a “Not Acknowledge” (“1”) to SDA after the next received data byte. This can be used to indicate that the Slave is not able to receive any more bytes. While TWEA is zero, the TWI does not acknowledge its own slave address. However, the 2-wire Serial Bus is still monitored and address recognition may resume at any time by setting TWEA. This implies that the TWEA bit may be used to temporarily isolate the TWI from the 2-wire Serial Bus. In all sleep modes other than Idle mode, the clock system to the TWI is turned off. If the TWEA bit is set, the interface can still acknowledge its own slave address or the general call address by using the 2-wire Serial Bus clock as a clock source. The part will then wake up from sleep and the TWI will hold the SCL clock low during the wake up and until the TWINT Flag is cleared (by writing it to one). Further data reception will be carried out as normal, with the AVR clocks running as normal. Observe that if the AVR is set up with a long start-up time, the SCL line may be held low for a long time, blocking other data transmissions. Note that the 2-wire Serial Interface Data Register – TWDR does not reflect the last byte present on the bus when waking up from these Sleep modes. Table 25-5. Status Codes for Slave Receiver Mode Status Code Status of the 2-wire Application Software Response (TWSR) Serial Bus and 2-wire To TWCR Prescaler Serial Interface Next Action Taken by TWI Bits are 0 Hardware To/from TWDR STA STO TWINT TWEA Hardware 0x60 Own SLA+W has been No TWDR action or X 0 1 0 Data byte will be received and NOT received; ACK has been ACK will be returned returned No TWDR action X 0 1 1 Data byte will be received and ACK will be returned 0x68 Arbitration lost in No TWDR action or X 0 1 0 Data byte will be received and NOT SLA+R/W as Master; ACK will be returned own SLA+W has been No TWDR action X 0 1 1 Data byte will be received and ACK received; ACK has been will be returned returned 0x70 General call address has No TWDR action or X 0 1 0 Data byte will be received and NOT been received; ACK has ACK will be returned been returned No TWDR action X 0 1 1 Data byte will be received and ACK will be returned 427 8393C-MCU Wireless-09/14

0x78 Arbitration lost in No TWDR action or X 0 1 0 Data byte will be received and NOT SLA+R/W as Master; ACK will be returned General call address has No TWDR action X 0 1 1 Data byte will be received and ACK been received; ACK has will be returned been returned 0x80 Previously addressed Read data byte or X 0 1 0 Data byte will be received and NOT with own SLA+W; data ACK will be returned has been received; ACK Read data byte X 0 1 1 Data byte will be received and ACK has been returned will be returned 0x88 Previously addressed Read data byte or 0 0 1 0 Switched to the not addressed Slave with own SLA+W; data mode; no recognition of own SLA or has been received; NOT Read data byte or 0 0 1 1 GCA ACK has been returned Switched to the not addressed Slave mode; own SLA will be recognized; Read data byte or 1 0 1 0 GCA will be recognized if TWGCE = “1” Switched to the not addressed Slave mode; no recognition of own SLA or Read data byte 1 0 1 1 GCA; a START condition will be transmitted when the bus becomes free Switched to the not addressed Slave mode; own SLA will be recognized; GCA will be recognized if TWGCE = “1”; a START condition will be transmitted when the bus becomes free 0x90 Previously addressed Read data byte or X 0 1 0 Data byte will be received and NOT with general call; data ACK will be returned has been received; ACK Read data byte X 0 1 1 Data byte will be received and ACK has been returned will be returned 0x98 Previously addressed Read data byte or 0 0 1 0 Switched to the not addressed Slave with general call; data mode; no recognition of own SLA or has been received; NOT Read data byte or 0 0 1 1 GCA ACK has been returned Switched to the not addressed Slave Read data byte or mode; own SLA will be recognized; 1 0 1 0 GCA will be recognized if TWGCE = Read data byte “1” Switched to the not addressed Slave mode; no recognition of own SLA or 1 0 1 1 GCA; a START condition will be transmitted when the bus becomes free Switched to the not addressed Slave mode; own SLA will be recognized; GCA will be recognized if TWGCE = “1”; a START condition will be transmitted when the bus becomes free ATmega256/128/64RFR2 428 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 0xA0 A STOP condition or No action 0 0 1 0 Switched to the not addressed Slave repeated START mode; no recognition of own SLA or condition has been 0 0 1 1 GCA received while still Switched to the not addressed Slave addressed as Slave mode; own SLA will be recognized; 1 0 1 0 GCA will be recognized if TWGCE = “1” Switched to the not addressed Slave mode; no recognition of own SLA or 1 0 1 1 GCA; a START condition will be transmitted when the bus becomes free Switched to the not addressed Slave mode; own SLA will be recognized; GCA will be recognized if TWGCE = “1”; a START condition will be transmitted when the bus becomes free Figure 25-16. Formats and States in the Slave Receiver Mode Reception of the own slave address and one or S SLA W A DATA A DATA A P or S more data bytes. All are acknowledged $60 $80 $80 $A0 Last data byte received is not acknowledged A P or S $88 Arbitration lost as master and addressed as slave A $68 Reception of the general call address and one or more data General Call A DATA A DATA A P or S bytes $70 $90 $90 $A0 Last data byte received is not acknowledged A P or S $98 Arbitration lost as master and addressed as slave by general call A $78 Any number of data bytes From master to slave DATA A and their associated acknowledge bits From slave to master This number (contained in TWSR) corresponds n to a defined state of the Two-Wire Serial Bus. The prescaler bits are zero or masked to zero 25.7.4 Slave Transmitter Mode In the Slave Transmitter mode, a number of data bytes are transmitted to a Master Receiver (see Figure 25-17 on page 430). All the status codes mentioned in this section assume that the prescaler bits are zero or are masked to zero. 429 8393C-MCU Wireless-09/14

Figure 25-17. Data Transfer in Slave Transmitter Mode DEVDD Device 1 Device 2 SLAVE MASTER Device 3 ........ Device n R1 R2 TRANSMITTER RECEIVER SDA SCL To initiate the Slave Transmitter mode, TWAR and TWCR must be initialized as follows: TWAR TWA6 TWA5 TWA4 TWA3 TWA2 TWA1 TWA0 TWGCE Value Device’s Own Slav e Address The upper seven bits are the address to which the 2-wire Serial Interface will respond when addressed by a Master. If the LSB is set, the TWI will respond to the general call address (0x00), otherwise it will ignore the general call address. TWCR TWINT TWEA TWSTA TWSTO TWWC TWEN – TWIE Value 0 1 0 0 0 1 0 X TWEN must be written to one to enable the TWI. The TWEA bit must be written to one to enable the acknowledgement of the device’s own slave address or the general call address. TWSTA and TWSTO must be written to zero. When TWAR and TWCR have been initialized, the TWI waits until it is addressed by its own slave address (or the g eneral call address if enabled) followed by the data direction bit. If the direction bit is “1” (read), the TWI will operate in ST mode, otherwise SR mode is entered. After its own slave address and the write bit have been received, the TWINT Flag is set and a valid status code can be read from TWSR. The status code is used to determine the appropriate software action. The appropriate action to be taken for each status code is detailed in Table 25-6 on page 431. The Slave Transmitter mode may also be entered if arbitration is lost while the TWI is in the Master mode (see state 0xB0). If the TWEA bit is written to zero during a transfer, the TWI will transmit the last byte of the transfer. State 0xC0 or state 0xC8 will be entered, depending on whether the Master Receiver transmits a NACK or ACK after the final byte. The TWI is switched to the not addressed Slave mode, and will ignore the Master if it continues the transfer. Thus the Master Receiver receives all “1” as serial data. State 0xC8 is entered if the Master demands additional data bytes (by transmitting ACK), even though the Slave has transmitted the last byte (TWEA zero and expecting NACK from the Master). While TWEA is zero, the TWI does not respond to its own slave address. However, the 2-wire Serial Bus is still monitored and address recognition may resume at any time by setting TWEA. This implies that the TWEA bit may be used to temporarily isolate the TWI from the 2-wire Serial Bus. In all sleep modes other than Idle mode, the clock system to the TWI is turned off. If the TWEA bit is set, the interface can still acknowledge its own slave address or the general call address by using the 2-wire Serial Bus clock as a clock source. The part ATmega256/128/64RFR2 430 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 will then wake up from sleep and the TWI will hold the SCL clock will low during the wake up and until the TWINT Flag is cleared (by writing it to one). Further data transmission will be carried out as normal, with the AVR clocks running as normal. Observe that if the AVR is set up with a long start-up time, the SCL line may be held low for a long time, blocking other data transmissions. Note that the 2-wire Serial Interface Data Register – TWDR does not reflect the last byte present on the bus when waking up from these sleep modes. Table 25-6. Status Code for Slave Transmitter Mode Status Code Status of the 2-wire Application Software Response (TWSR) Serial Bus and 2-wire To TWCR Prescaler Serial Interface Next Action Taken by TWI Bits are 0 Hardware To/from TWDR ST A STD TWINT TWEA Hardware 0xA8 Own SLA+R has been Load data byte or X 0 1 0 Last data byte will be transmitted and received; ACK has been NOT ACK should be received Data returned Load data byte X 0 1 1 byte will be transmitted and ACK should be received 0xB0 Arbitration lost in SLA+R/W Load data byte or X 0 1 0 Last data byte will be transmitted and as Master; own SLA+R has NOT ACK should be received Data been received; ACK has Load data byte X 0 1 1 byte will be transmitted and ACK been returned should be received 0xB8 Data byte in TWDR has Load data byte or X 0 1 0 Last data byte will be transmitted and been transmitted; ACK has NOT ACK should be received been received Load data byte X 0 1 1 Data byte will be transmitted and ACK should be received 0xC0 Data byte in TWDR has No TWDR action or 0 0 1 0 Switched to the not addressed Slave been transmitted; NOT mode; no recognition of own SLA or ACK has been received No TWDR action or 0 0 1 1 GCA Switched to the not addressed Slave mode; own SLA will be recognized; No TWDR action or 1 0 1 0 GCA will be recognized if TWGCE = “1” Switched to the not addressed Slave mode; no recognition of own SLA or No TWDR action 1 0 1 1 GCA; a START condition will be transmitted when the bus becomes free Switched to the not addressed Slave mode; own SLA will be recognized; GCA will be recognized if TWGCE = “1”; a START condition will be transmitted when the bus becomes free 0xC8 Last data byte in TWDR No TWDR action or 0 0 1 0 Switched to the not addressed Slave has been transmitted mode; no recognition of own SLA or (TWEA = “0”); ACK has No TWDR action or 0 0 1 1 GCA been received Switched to the not addressed Slave mode; own SLA will be recognized; No TWDR action or 1 0 1 0 GCA will be recognized if TWGCE = “1” Switched to the not addressed Slave mode; no recognition of own SLA or No TWDR action 1 0 1 1 GCA; a START condition will be transmitted when the bus becomes free Switched to the not addressed Slave mode; own SLA will be recognized; GCA will be recognized if TWGCE = “1”; a START condition will be transmitted when the bus becomes free 431 8393C-MCU Wireless-09/14

Figure 25-18. Formats and States in the Slave Transmitter Mode Reception of the own slave address and one or S SLA R A DATA A DATA A P or S more data bytes $A8 $B8 $C0 Arbitration lost as master and addressed as slave A $B0 Last data byte transmitted. Switched to not addressed A All 1’s P or S slave (TWEA = ’0’) $C8 Any number of data bytes From master to slave DATA A and their associated acknowledge bits From slave to master n Ttoh ais dneufminbeedr s (tcaoten toafi ntheed Tinw ToW-WSirRe) Sceorriraels Bpuosn.d Tshe prescaler bits are zero or masked to zero 25.7.5 Miscellaneous States There are two status codes that do not correspond to a defined TWI state, see Table 25-7 below. Status 0xF8 indicates that no relevant information is available because the TWINT Flag is not set. This occurs between other states, and when the TWI is not involved in a serial transfer. Status 0x00 indicates that a bus error has occurred during a 2-wire Serial Bus transfer. A bus error occurs when a START or STOP condition occurs at an illegal position in the format frame. Examples of such illegal positions are during the serial transfer of an address byte, a data byte, or an acknowledge bit. When a bus error occurs, TWINT is set. To recover from a bus error, the TWSTO Flag must set and TWINT must be cleared by writing a logic one to it. This causes the TWI to enter the not addressed Slave mode and to clear the TWSTO Flag (no other bits in TWCR are affected). The SDA and SCL lines are released, and no STOP condition is transmitted. Table 25-7. Miscellaneous States Status Code Status of the 2-wire Application Software Response (TWSR) Serial Bus and 2-wire To TWCR Prescaler Serial Interface Hard- Next Action Taken by TWI Bits are 0 ware To/from TWDR STA STO TWINT TWEA Hardware 0xF8 No relevant state TWDR action No TWCR action Wait or proceed current transfer information available 0x00 Bus error due to an illegal No TWDR action 0 1 1 X Only the internal hardware is START or STOP condition affected, no STOP condition is sent on the bus. In all cases, the bus is released and TWSTO is cleared. 25.7.6 Combining Several TWI Modes In some cases, several TWI modes must be combined in order to complete the desired action. Consider for example reading data from a serial EEPROM. Typically, such a transfer involves the following steps: 1. The transfer must be initiated. 2. The EEPROM must be instructed what location should be read. ATmega256/128/64RFR2 432 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 3. The reading must be performed. 4. The transfer must be finished. Note that data is transmitted both from Master to Slave and vice versa. The Master must instruct the Slave what location it wants to read, requiring the use of the MT mode. Subsequently, data must be read from the Slave, implying the use of the MR mode. Thus, the transfer direction must be changed. The Master must keep control of the bus during all these steps, and the steps should be carried out as an atomic operation. If this principle is violated in a multi-master system, another Master can alter the data pointer in the EEPROM between steps 2 and 3, and the Master will read the wrong data location. Such a change in transfer direction is accomplished by transmitting a REPEATED START between the transmission of the address byte and reception of the data. After a REPEATED START, the Master keeps ownership of the bus. The following figure shows the flow in this transfer. Figure 25-19. Combining Several TWI Modes to Access a Serial EEPROM Master Transmitter Master Receiver S SLA+W A ADDRESS A Rs SLA+R A DATA A P S = START Rs = REPEATED START P = STOP Transmitted from master to slave Transmitted from slave to master 25.8 Multi-master Systems and Arbitration If multiple masters are connected to the same bus, transmissions may be initiated simultaneously by one or more of them. The TWI standard ensures that such situations are handled in such a way that one of the masters will be allowed to proceed with the transfer, and that no data will be lost in the process. An example of an arbitration situation is depicted below, where two masters are trying to transmit data to a Slave Receiver. Figure 25-20. An Arbitration Example DEVDD Device 1 Device 2 Device 3 MASTER MASTER SLAVE ........ Device n R1 R2 TRANSMITTER TRANSMITTER RECEIVER SDA SCL Several different scenarios may arise during arbitration, as described below: • Two or more masters are performing identical communication with the same Slave. In this case, neither the Slave nor any of the masters will know about the bus contention. • Two or more masters are accessing the same Slave with different data or direction bit. In this case, arbitration will occur, either in the READ/WRITE bit or in the data bits. The masters trying to output a one on SDA while another Master outputs a zero 433 8393C-MCU Wireless-09/14

will lose the arbitration. Losing masters will switch to not addressed Slave mode or wait until the bus is free and transmit a new START condition, depending on application software action. • Two or more masters are accessing different slaves. In this case, arbitration will occur in the SLA bits. Masters trying to output a one on SDA while another Master outputs a zero will lose the arbitration. Masters losing arbitration in SLA will switch to Slave mode to check if they are being addressed by the winning Master. If addressed, they will switch to SR or ST mode, depending on the value of the READ/WRITE bit. If they are not being addressed, they will switch to not addressed Slave mode or wait until the bus is free and transmit a new START condition, depending on application software action. This is summarized in Figure 25-21 below. Possible status values are given in circles. Figure 25-21. Possible Status Codes Caused by Arbitration START SLA Data STOP Arbitratio n lost in SLA Arbitration lost in Data Own No 38 TWI bus will be released and not addressed slave mode will be entered Address / General Call A START condition will be transmitted when the bus becomes free received Yes Wr ite 68/78 Data byte will be received and NOT ACK will be returned Direction Data byte will be received and ACK will be returned Read Last data byte will be transmitted and NOT ACK should be received B0 Data byte will be transmitted and ACK should be received 25.9 Register Description 25.9.1 TWBR – TWI Bit Rate Register Bit 7 6 5 4 3 2 1 0 NA ($B8) TWBR7:0 TWBR Read/Write RW RW RW RW RW RW RW RW Initial Value 0 0 0 0 0 0 0 0 The SCL period is controlled by settings in the TWI Bit Rate Register (TWBR) and the Prescaler bits in the TWI Status Register (TWSR). Slave operation does not depend on Bit Rate or Prescaler settings, but the CPU clock frequency in the Slave must be at least 16 times higher than the SCL frequency. • Bit 7:0 – TWBR7:0 - TWI Bit Rate Register Value The TWBR register selects the division factor for the bit rate generator. The bit rate generator is a frequency divider which generates the SCL clock frequency in the Master modes. See section "Bit Rate Generator Unit" for calculating bit rates. ATmega256/128/64RFR2 434 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 25.9.2 TWCR – TWI Control Register Bit 7 6 5 4 3 2 1 0 NA ($BC) TWINT TWEA TWSTA TWSTO TWWC TWEN Res TWIE TWCR Read/Write RW RW RW RW RW RW R RW Initial Value 0 0 0 0 0 0 0 0 The TWCR is used to control the operation of the TWI. It is used to enable the TWI, to initiate a Master access by applying a START condition to the bus, to generate a Receiver acknowledge, to generate a stop condition, and to control halting of the bus while the data to be written to the bus are put into the TWDR. It also indicates a write collision if data writing to TWDR is attempted while the register is inaccessible. • Bit 7 – TWINT - TWI Interrupt Flag This bit is set by hardware when the TWI has finished its current job and expects application software response. If the I-bit in SREG and TWIE in TWCR are set, the MCU will jump to the TWI Interrupt Vector. While the TWINT Flag is set, the SCL low period is stretched. The TW INT Flag must be cleared by software by writing a logic one to it. Note that this flag is not automatically cleared by hardware when executing the interrupt routine. Also note that clearing this flag starts the operation of the TWI. So all accesses to the TWI Address Register (TWAR), TWI Status Register (TWSR) and TWI Data Register (TWDR) must be complete before clearing this flag. • Bit 6 – TWEA - TWI Enable Acknowledge Bit The TWEA bit controls the generation of the acknowledge pulse. If the TWEA bit is written to one, the ACK pulse is generated on the TWI bus if the following conditions are met: 1. The devices own slave address has been received; 2. A general call has been received, while the TWGCE bit in the TWAR is set. 3. A data byte has been received in Master Receiver or Slave Receiver mode. By writing the TWEA bit to zero, the device can be virtually disconnected from the 2-wire Serial Bus temporarily. Address recognition can then be resumed by writing the TWEA bit to one again. • Bit 5 – TWSTA - TWI START Condition Bit The application writes the TWSTA bit to one when it desires to become a Master on the 2-wire Serial Bus. The TWI hardware checks if the bus is available and generates a START condition on the bus if it is free. However, if the bus is not free, the TWI waits until a STOP condition is detected and then generates a new START condition to claim the bus Master status. TWSTA must be cleared by software when the START condition has been transmitted. • Bit 4 – TWSTO - TWI ST OP Condition Bit Writing the TWSTO bit to one in Master mode will generate a STOP condition on the 2- wire Serial Bus. When the STOP condition is executed on the bus, the TWSTO bit is cleared automatically. In Slave mode, setting the TWSTO bit can be used to recover from an error condition. This will not generate a STOP condition, but the TWI returns to a well-defined not-addressed Slave mode and releases the SCL and SDA lines to a high impedance state. • Bit 3 – TWWC - TWI Write Collision Flag The TWWC bit is set when attempting to write to the TWI Data Register TWDR when TWINT is low. This flag is cleared by writing the TWDR Register when TWINT is high. • Bit 2 – TWEN - TWI Enable Bit The TWEN bit enables TWI operation and activates the TWI interface. When TWEN is written to one, the TWI takes control over the I/O ports connected to the SCL and SDA 435 8393C-MCU Wireless-09/14

pins enabling the slew-rate limiters and spike filters. If this bit is written to zero, the TWI is switched off and all TWI transmissions are terminated regardless of any ongoing operation. • Bit 1 – Res - Reserved Bit This bit is reserved for future use. A read access always will return zero. A write access does not modify the content. • Bit 0 – TWIE - TWI Interrupt Enable When this bit is written to one and the I-bit in SREG is set, the TWI interrupt request will be activated for as long as the TWINT Flag is high. 25.9.3 TWSR – TWI Status Register Bit 7 6 5 4 3 2 1 0 NA ($B9) TWS7 TWS6 TWS5 TWS4 TWS3 Res TWPS1 TWPS0 TWSR Read/Write RW RW RW RW RW R RW RW Initial Value 0 0 0 0 0 0 0 0 • Bit 7:3 – TWS4:0 - TWI Status These 5 bits reflect the status of the TWI logic and the 2-wire Serial Bus. The different status codes for both transmitter and receiver mode are described in the following table. Note that the value read from TWSR contains both the 5-bit status value and the 2-bit prescaler value. The application designer should mask the prescaler bits to zero when checking the Status bits. This makes status checking independent of prescaler setting. This approach is used in this datasheet, unless otherwise noted. Table 25-8 TWS Register Bits Register Bits Value Description TWS4:0 0x00 Bus error due to illegal START or STOP condition. 0x08 A START condition has been transmitted. 0x10 A repeated START condition has been transmitted. 0x18 SLA+W has been transmitted; ACK has been received. 0x20 SLA+W has been transmitted; NOT ACK has been received. 0x28 Data byte has been transmitted; ACK has been received. 0x30 Data byte has been transmitted; NOT ACK has been received. 0x38 Arbitration lost in SLA+W or data bytes (Transmitter); Arbitration lost in SLA+R or NOT ACK bit (Receiver). 0x40 SLA+R has been transmitted; ACK has been received. 0x48 SLA+R has been transmitted; NOT ACK has been received. 0x50 Data byte has been received; ACK has been ATmega256/128/64RFR2 436 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 Register Bits Value Description returned. 0x58 Data byte has been received; NOT ACK has been returned. 0x60 Own SLA+W has been received; ACK has been returned. 0x68 Arbitration lost in SLA+R/W as Master; own SLA+W has been received; ACK has been returned. 0x70 General call address has been received; ACK has been returned. 0x78 Arbitration lost in SLA+R/W as Master; general call address has been received; ACK has been returned. 0x80 Previously addressed with own SLA+W; data has been received; ACK has been returned. 0x88 Previously addressed with own SLA+W; data has been received; NOT ACK has been returned. 0x90 Previously addressed with general call; data has been received; ACK has been returned. 0x98 Previously addressed with general call; data has been received; NOT ACK has been returned. 0xA0 A STOP condition or repeated START condition has been received while still addressed as Slave. 0xA8 Own SLA+R has been received; ACK has been returned. 0xB0 Arbitration lost in SLA+R/W as Master; own SLA+R has been received; ACK has been returned. 0xB8 Data byte in TWDR has been transmitted; ACK has been received. 0xC0 Data byte in TWDR has been transmitted; NO ACK has been received. 0xC8 Last data byte in TWDR has been transmitted (TWEA = 0); ACK has been received. 0xF8 No relevant state information available; TWINT = 0. • Bit 2 – Res - Reserved Bit This bit is reserved for future use. A read access always will return zero. A write access does not modify the content. • Bit 1:0 – TWPS1:0 - TWI Prescaler Bits These bits can be read and written and control the bit rate of the prescaler. Table 25-9 TWPS Register Bits Register Bits Value Description TWPS1:0 0x00 1 437 8393C-MCU Wireless-09/14

Register Bits Value Description 0x01 4 0x02 16 0x03 64 25.9.4 TWDR – TWI Data Register Bit 7 6 5 4 3 2 1 0 NA ($BB) TWD7 TWD6 TWD5 TWD4 TWD3 TWD2 TWD1 TWD0 TWDR Read/Write RW RW RW RW RW RW RW RW Initial Value 1 1 1 1 1 1 1 1 In Transmit mode, TWDR contains the next byte to be transmitted. In Receive mode, the TWDR contains the last byte received. It is writable while the TWI is not in the process of shifting a byte. This occurs when the TWI Interrupt Flag (TWINT) is set by hardware. Note that the Data Register cannot be initialized by the user before the first interrupt occurs. The data in TWDR remains stable as long as TWINT is set. While data is shifted out, data on the bus is simultaneously shifted in. TWDR always contains the last byte present on the bus, except after a wake up from a sleep mode by the TWI interrupt. In this case, the contents of TWDR is undefined. In the case of a lost bus arbitration, no data is lost in the transition from Master to Slave. Handling of the ACK bit is automatically controlled by the TWI logic. The CPU cannot access the ACK bit directly. • Bit 7:0 – TWD7:0 - TWI Data Register Byte 25.9.5 TWAR – TWI (Slave) Address Register Bit 7 6 5 4 3 2 1 0 NA ($BA) TWA6 TWA5 TWA4 TWA3 TWA2 TWA1 TWA0 TWGCE TWAR Read/Write RW RW RW RW RW RW RW RW Initial Value 0 0 0 0 0 0 0 0 The TWAR should be loaded with the 7-bit Slave address (in the seven most significant bits of TWAR) to which the TWI will respond when programmed as a Slave Transmitter or Receiver. This register is not needed in the Master modes. In multi-master systems TWAR must be set in Masters which can be addressed as Slaves by other Masters. The LSB of TWAR is used to enable the recognition of the general call address (0x00). There is an associated address comparator that looks for the slave address (or general call address if enabled) in the received serial address. If a match is found, an interrupt request is generated. • Bit 7:1 – TWA6:0 - TWI (Slave) Address These bits contain the TWI address operated as a Slave device. • Bit 0 – TWGCE - TWI General Call Recognition Enable Bit If set, this bit enables the recognition of a General Call given over the 2-wire Serial Bus. ATmega256/128/64RFR2 438 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 25.9.6 TWAMR – TWI (Slave) Address Mask Register Bit 7 6 5 4 3 2 1 0 NA ($BD) TWAM6 TWAM5 TWAM4 TWAM3 TWAM2 TWAM1 TWAM0 Res TWAMR Read/Write RW RW RW RW RW RW RW R Initial Value 0 0 0 0 0 0 0 0 • Bit 7:1 – TWAM6:0 - TWI Address Mask The TWAMR can be loaded with a 7-bit Slave Address mask. Each of the bits in TWAMR can mask (disable) the corresponding address bit in the TWI Address Register (TWAR). If the mask bit is set to one then the address match logic ignores the compare between the incoming addre ss bit and the corresponding bit in TWAR. • Bit 0 – Res - Reserved Bit This bit is reserved for future use. A read access always will return zero. A write access does not modify the content. 439 8393C-MCU Wireless-09/14

26 AC – Analog Comparator The Analog Comparator compares the input values on the positive pin AIN0 and negative pin AIN1. When the voltage on the positive pin AIN0 is higher than the voltage on the negative pin AIN1, the Analog Comparator output, ACO, is set. The comparator’s output can be set to trigger the Timer/Counter1 Input Capture function. In addition, the comparator can trigger a separate interrupt, exclusive to the Analog Comparator. The user can select Interrupt triggering on comparator output rise, fall or toggle. A block diagram of the comparator and its surrounding logic is shown in Figure 26-1 below. The Power Reduction ADC bit PRADC in PRR0 (see "PRR0 – Power Reduction Register0" on page 197) must be disabled by writing a logical zero to be able to use the ADC input multiplexer. Figure 26-1. Analog Comparator Block Diagram Note: 1. See Table 26-1 below. 2. Refer to Figure 1-1 on page 2 and Table 14-9 en page 230 for Analog Comparator pin placement. 26.1 Analog Comparator Multiplexed Input It is possible to select any of the ADC7:0 pins as the negative input of the Analog Comparator. The ADC multiplexer is used to select this input and consequently the ADC must be switched off to utilize this feature. If the Analog Comparator Multiplexer Enable bit (ACME in ADCSRB) is set and the ADC is switched off (ADEN in ADCSRA is zero), MUX5 and MUX2:0 in ADMUX select the input pin to replace the negative input to the Analog Comparator, as shown in Table 26-1 below. If ACME is cleared or ADEN is set, AIN1 is applied to the negative input to the Analog Comparator. Table 26-1. Analog Comparator Multiplexed Input ACME ADEN MUX5 MUX2:0 Analog Comparator Negative Input 0 x x xxx AIN1 1 1 x xxx AIN1 1 0 0 000 ADC0 1 0 0 001 ADC1 1 0 0 010 ADC2 1 0 0 011 ADC3 1 0 0 100 ADC4 ATmega256/128/64RFR2 440 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 ACME ADEN MUX5 MUX2:0 Analog Comparator Negative Input 1 0 0 101 ADC5 1 0 0 110 ADC6 1 0 0 111 ADC7 26.2 Register Description 26.2.1 ACSR – Analog Comparator Control And Status Register Bit 7 6 5 4 3 2 1 0 $30 ($50) ACD ACBG ACO ACI ACIE ACIC ACIS1 ACIS0 ACSR Read/Write RW RW R RW RW RW RW RW Initial Value 0 0 NA 0 0 0 0 0 • Bit 7 – ACD - Analog Comparator Disable When this bit is written logic one, the power to the Analog Comparator is switched off. This bit can be set at any time to turn off the Analog Comparator. This will reduce power consumption in Active and Idle mode. When changing the ACD bit, the Analog Comparator Interrupt must be disabled by clearing the ACIE bit in ACSR. Otherwise an interrupt can occur when the bit is changed. • Bit 6 – ACBG - Analog Comparator Bandgap Select When this bit is set, a fixed bandgap reference voltage connects to the positive input of the Analog Comparator. When this bit is cleared, AIN0 is applied to the positive input of the Analog Comparator. When the bandgap reference is used as the input of the Analog Comparator, it will take a certain time for the voltage to stabilize. If not stabilized, the first comparison may give a wrong value. See section "Internal Voltage Reference" for details. • Bit 5 – ACO - Analog Compare Output The output of the analog comparator is synchronized and then directly connected to ACO. The synchronization introduces a delay of 1-2 clock cycles. • Bit 4 – ACI - Analog Comparator Interrupt Flag This bit is set by hardware when a comparator output event triggers the interrupt mode defined by ACIS1 and ACIS0. The Analog Comparator Interrupt routine is executed if the ACIE bit is set and the I-bit in SREG is set. ACI is cleared by hard-ware when executing the corresponding interrupt handling vector. Alternatively, ACI is cleared by writing a logic one to the flag . • Bit 3 – ACIE - Analog Comparator Interrupt Enable When the ACIE bit is written logic one and the I-bit in the Status Register is set, the analog comparator interrupt is activated. When written logic zero, the interrupt is disabled. • Bit 2 – ACIC - Analog Comparator Input Capture Enable When written logic one, this bit enables the input capture function in Timer/Counter1 to be triggered by the Analog Comparator. The comparator output is in this case directly connected to the input capture front-end logic, making the comparator utilize the noise canceler and edge select features of the Timer/Counter1 Input Capture interrupt. When written logic zero, no connection between the Analog Comparator and the input capture function exists. To make the comparator trigger the Timer/Counter1 Input Capture interrupt, the ICIE1 bit in the Timer Interrupt Mask Register (TIMSK1) must be set. 441 8393C-MCU Wireless-09/14

• Bit 1:0 – ACIS1:0 - Analog Comparator Interrupt Mode Select These bits determine which comparator events that trigger the Analog Comparator interrupt. The different settings are shown in the following table. When changing the ACIS1/ACIS0 bits, the Analog Comparator Interrupt must be disabled by clearing its Interrupt Enable bit in the ACSR Register. Otherwise an interrupt can occur when the bits are changed. Table 26-2 ACIS Register Bits Register Bits Value Description ACIS1:0 0x00 Interrupt on Toggle 0x01 Reserved 0x02 Interrupt on Falling Edge 0x03 Interrupt on Rising Edge 26.2.2 ADCSRB – ADC Control and Status Register B Bit 7 6 5 4 3 2 1 0 NA ($7B) ACME ADCSRB Read/Write RW Initial Value 0 • Bit 6 – ACME - Analog Comparator Multiplexer Enable When this bit is written logic one and the ADC is switched off (ADEN in ADCSRA is zero), the ADC multiplexer defines the negative input of the Analog Comparator. When this bit is written logic zero, AIN1 is applied to the negative input of the Analog Comparator. For a detailed description of this bit, see section "Analog Comparator Multiplexed Input". 26.2.3 DIDR1 – Digital Input Disable Register 1 Bit 7 6 5 4 3 2 1 0 NA ($7F) AIN1D AIN0D DIDR1 Read/Write RW RW Initial Value 0 0 • Bit 1 – AIN1D - AIN1 Digital Input Disable When this bit is written logic one, the digital input buffer on the AIN1 pin is disabled. The corresponding PIN Register bit will always read as zero when this bit is set. When an analog signal is applied to the AIN1 pin and the digital input from this pin is not needed, this bit should be written l ogic one to reduce power consumption in the digital input buffer. • Bit 0 – AIN0D - AIN0 Digital Input Disable When this bit is written logic one, the digital input buffer on the AIN0 pin is disabled. The corresponding PIN Register bit will always read as zero when this bit is set. When an analog signal is applied to the AIN0 pin and the digital input from this pin is not needed, this bit should be written logic one to reduce power consumption in the digital input buffer. ATmega256/128/64RFR2 442 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 443 8393C-MCU Wireless-09/14

27 ADC – Analog to Digital Converter 27.1 Features • 10-bit Resolution • Differential Non-Linearity is less than ± 0.5 LSB • 2 LSB Integral Non-Linearity • 3 - 240 µs Conversion Time • Up to 330 kSPS (Up to 570 kSPS with 8-bit Resolution) • 8 Multiplexed Single Ended Input Channels • 11 Differential Input Ch annels • 2 Differential Input Channels with an Optional Gain of 10x and 200x • Internal Linear Temperature Sensor • Supply Voltage (V ) Measurement EVDD • Optional Left Adjustment for ADC Result Readout • 0 - V ADC Input Voltage Range AVDD • 0 - V Differential ADC Input Voltage Range EVDD • Selectable 1.5V, 1.6V or V ADC Reference Voltage AVDD • Free Running or Single Conversion Mode • Interrupt on ADC Conversion Complete • Sleep Mode Noise Canceller The ATmega256/128/64RFR2 features a 10-bit successive approximation ADC. The ADC is connected to an 8-channel Analog Multiplexer which allows eight single-ended voltage inputs constructed from the pins of Port F. The single-ended voltage inputs refer to 0V (AVSS). The device also supports multiple differential voltage input combinations. Two of the differential inputs (ADC1 & ADC0 and ADC3 & ADC2) are equipped with a programmable gain stage, providing amplification steps of 0 dB (1x), 20 dB (10x) or 46 dB (200x) on the differential input voltage before the A/D conversion. The differential input channels are constructed of pairs out of the 8 single-ended inputs. They share a common negative terminal (ADC0, ADC1 or ADC2), while most of the other ADC inputs can be selected as the positive input terminal. If 1x or 10x gain is used, 8 bit resolution can be expected. If 200x gain is used, 6 bit resolution can be expected. The ADC contains a Sampl e and Hold circuit which ensures that the input voltage to the ADC is held at a constant level during conversion. A block diagram of the ADC is shown in Figure 27-1 on page 445. The analog components of the ADC are supplied from the analog supply voltage AVDD. AVDD is generated from EVDD by an internal voltage generator. The logic part of the ADC is supplied from the digital supply voltage DVDD. DVDD is generated from DEVDD also by an internal voltage generator. Internal reference voltages of nominally 1.5V, 1.6V or AVDD (1.8V) are provided on- chip. The 1.6V reference is calibrated to ± 1 LSB during manufacturing. The reference voltage can be monitored at the AREF pin. Additional de-coupling capacitance at AREF is not required. A high capacitive loading of AREF will de-stabilize the internal reference voltage generation. An external reference voltage in the range of 0 < V ≤ V AREF,EXT AVDD may be used but must be supplied with a very low impedance. ATmega256/128/64RFR2 444 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 The Power Reduction ADC bit, PRADC (see "PRR0 – Power Reduction Register0" on page 197) must be disabled by writing a logical zero to enable the ADC. Figure 27-1. Analog to Digital Converter Block Schematic F E DI DI A A REFS[1:0] MUX[4:0] ADLAR MUX[5] ACCH ADTHT[1:0] ADSUT[4:0] ADEN ADIF ADPS[2:0] ADSC ADFR DC[9:0] A N ECTIO ELECT EL SEL GAIN S NN F / A F CH DI 27.2 Operation The ADC converts an analog input voltage to a 10-bit digital value through successive approximation. The minimu m value represents 0V (conversion result 0x000) and the maximum value in single ended mode represents the reference voltage minus 1 LSB (conversion result 0x3FF). The reference voltage can be measured at the AREF pin. The internal, generated reference voltage can have the values 1.5V, 1.6V or AVDD where the 1.6V has the highest absolute accuracy. The reference voltage is selected by writing to the REFSn bits in the ADMUX Register. An external reference voltage can also be selected. Such an external voltage must be supplied with a very low impedance R (see "ADC Characteristics" on page 561). The load current I (see "ADC AREF,EXT L,AREF Characteristics" on page 561) seen by the external source is code dependent and 445 8393C-MCU Wireless-09/14

changes in the course of the successive approximation process (load current steps). The internal voltage reference (except AVDD) must not be decoupled by an external capacitor. Adding unnecessary external capacitance at the AREF pin will cause instable operation of the internal reference voltage buffer and will not improve noise immunity. The analog input channel is selected by writing to the MUX bits in ADMUX and ADCSRB. Any of the ADC input pins, as well as AVSS and a fixed bandgap voltage reference can be selected as single ended inputs to the ADC. A choice of ADC input pins can be selected as positive and negative inputs to the differential amplifier. Furthermore the temperature sensor and the DRT voltages of SRAM2 can also be processed with the ADC. If differential channels are selected, the amplified voltage difference between the selected input channel pai r then becomes the input of the ADC. The respective pin voltages for a differential measurement can be in the range from 0V to EVDD. In this way it is possible to handle differential input voltages with a common mode value higher than AVDD e.g. process a 50mV differential signal with a 2.5V common mode voltage. If single ended channels are used, the gain amplifier is bypassed altogether. Any ADC input voltage (single-ended or amplified-differential) exceeding AVDD will be internally clamped to AVDD to avoid damaging the ADC circuitry. Note that the pin input current will not increase if the clamp circuit is active. The ADC is enabled by setting ADEN bit in ADCSRA. Voltage reference and input channel selections will not go into effect until ADEN is set. The ADC does not consume power when ADEN is cleared. It is required to disable the ADC before entering power saving sleep modes. The ADC generates a 10-bit result which is presented in the ADC Data Registers, ADCH and ADCL. By default, the result is presented right adjusted, but can optionally be presented left adjusted by setting the ADLAR bit in ADMUX. If the result is left adjusted and no more than 8-bit precision is required, it is sufficient to read ADCH. Otherwise, ADCL must be read first, then ADCH, to ensure that the content of the Data Registers belongs to the same conversion. Once ADCL is read, ADC access to Data Registers is blocked. This means that if ADCL has been read, and a conversion completes before ADCH is read, neither register is updated and the result from the conversion is lost. When ADCH is read, ADC access to the ADCH and ADCL Registers is re-enabled. The ADC has its own interrupt which can be triggered when a conversion completes. When ADC access to the Data Registers is prohibited between reading of ADCH and ADCL, the interrupt will trigger even if the result is lost. 27.3 ADC Start-Up After the ADC is enabled by setting ADEN, it will go through a start-up phase. The analog supply voltage AVDD is turned on. It takes time t (see "Power Management AVREG Electrical Characteristics" on page 557) µs for AVDD to stabilize. A stable AVDD voltage is indicated by the AVDDOK bit in ADCSRB. After this the ADC and, for differential input channels also the gain amplifier, is powered up. The duration of this phase depends on the ADC clock period and the configuration of the Start-Up and Track-And–Hold Time bits, ADSUT and ADTHT in ADCSRC. For details about the start- up timing refer to section "Pre-scaling and Conversion Timing" on page 448. During the ADC start-up phase a conversion start can already be requested by writing a logical one to the ADC Start Conversion bit, ADSC in ADCSRA. In this case a conversion is started directly after the start-up phase. During the start-up phase it is still ATmega256/128/64RFR2 446 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 possible to change the analog input channel until the AVDDOK bit changes to logic one or, if the AVDDOK bit is one, until the ADSC bit is set. 27.4 Starting a Conversion A single conversion is started by writing a logical one to the ADC Start Conversion bit, ADSC. This bit stays high as long as the conversion is in progress and will be cleared by hardware when the conversion is completed. If a different data channel is selected while a conversion is in progress, the ADC will finish the current conversion before performing the channel change. Alternatively, a conversion can be triggered automatically by various sources. Auto Triggering is enabled by setting the ADC Auto Trigger Enable bit, ADATE in ADCSRA. The trigger source is selecte d by setting the ADC Trigger Select bits, ADTS in ADCSRB (See description of the ADTS bits for a list of the trigger sources). When a positive edge occurs on the selected trigger signal, the ADC prescaler is reset and a conversion is started. This provides a method of starting conversions at fixed intervals. If the trigger signal still is set when the conversion completes, a new conversion will not be started. If another positive edge occur s on the trigger signal during conversion, the edge will be ignored. Note that an Interrupt Flag will be set even if the specific interrupt is disabled or the Global Interrupt Enable bit in SREG is cleared. A conversion can thus be triggered without causing an interrupt. However, the Interrupt Flag must be cleared in order to trigger a new conversion at the next interrupt event. Figure 27-2. ADC Auto Trigger Logic ADTS[2:0] PRESCALER START CLK ADC ADIF ADATE SOURCE 1 . CONVERSION . LOGIC . . EDGE DETECTOR SOURCE n ADSC Using the ADC Interrupt Flag as a trigger source makes the ADC start a new conversion as soon as the ongoing conversion has finished. The ADC then operates in Free Running mode, constantly sampling and updating the ADC Data Register. The first conversion must be started by writing a logical one to the ADSC bit in ADCSRA. In this mode the ADC will perform successive conversions independently of whether the ADC Interrupt Flag, ADIF is cleared or not. If Auto Triggering is enabled, single conversions can be started by writing ADSC in ADCSRA to one. ADSC can also be used to determine if a conversion is in progress. The ADSC bit will be read as one during a conversion, independently of how the conversion was started. 447 8393C-MCU Wireless-09/14

27.5 Pre-scaling and Conversion Timing 27.5.1 Prescaler By default, the successive approximation circuitry requires an input clock frequency between 50 kHz and 4 MHz. If a lower resolution than 10 bits is needed, the input clock frequency to the ADC can be as high as 8 MHz to get a higher sample rate. For differential input channels the ADC clock speed is restricted to a maximum of 2 MHz. Figure 27-3. ADC Prescaler ADEN Reset START 7-BIT ADC PRESCALER CK 8 6 2 4 2 2 4 8 1 3 6 1 K/ K/ K/ K/ K/ K/ K/ C C C C C C C ADPS0 ADPS1 ADPS2 ADC CLOCK SOURCE The ADC module contains a prescaler, which generates an acceptable ADC clock frequency from any CPU frequency above 100 kHz. The pre-scaling is set by the ADPS bits in ADCSRA. The prescaler starts counting from the moment when the ADC is enabled. The prescaler keeps running for as long as the ADEN bit is set, and is continuously reset when ADEN is low. Note: 1. If the ADC prescaler value is changed while ADCEN is high then the resulting start-up and track-and-hold times may be incorrect. These timings are set defined by the ADSUT and ADTHT bits in register ADCSRC. Change ADC prescaler only when ADC is disabled (ADEN=0). 27.5.2 Start-Up Timing The ADC is enabled by s e tting the ADEN bit in ADCSRA. First the analog voltage regulator is powered up which takes t (see "Power Management Electrical AVREG Characteristics" on page 557). A stable AVDD is indicated by the AVDDOK bit in ADCSRB. After AVDD has stabilized, the ADC is started. The ADC start-up time has a length of t and can be adjuste d by the Start-Up time bits ADSUT5:0 in ADCSRC. If ADSU differential input channels are used, then an additional initialization period t is AINIT required by the gain amplifier. This period is configured by the Track-And-Hold Time bits, ADTHT1:0 in ADCSRC. ADSUT5:0 and ADTHT1:0 are fixed numbers of ADC clock cycles and can be setup for different ADC clock speeds. The minimum required ADC start-up time is 20 µs. For a summary of start-up times and sequences see Table 27-1 on page 449, Table 27-2 on page 449, Figure 27-4 on page 449 and Figure 27-5 on page 449. ATmega256/128/64RFR2 448 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 Table 27-1. Start-Up Time, Single Ended Channels Parameter Duration in ADC Clock Cycles ADC Start-Up Time t 4(ADSUT+1), minimum 20 µs ADSU Table 27-2. Start-Up Time, Differential Channels Parameter Duration in ADC Clock Cycles ADC Start-Up Time t 4(ADSUT+1), minimum 20 µs ADSU Gain Amplifier Initialization Time t (1) 2(ADTHT+3) AINIT Note: 1. Time t is 2(ADTHT+2) for ATmega128RFA1. AINIT Figure 27-4. ADC Timing Di agram, Start-Up for Single Ended Channels PoAwVeDr-DUp StAaDrt-CUp Conversion ADC Clock ADEN AVDDOK ADSC ADIF ADCH Sign and MSB of Result ADCL LSB of Result tAVPU tADSU 11 TADC_CLK MUX and REFS Update S &a mHopllde CoCnovmerpsleiotne Figure 27-5. ADC Timing Di agram, Start-Up for Differential Channels PoAwVeDr-DUp StAaDrt-CUp AmIpnliitfier Conversion ADC Clock ADEN AVDDOK ADSC ADIF ADCH Sign and MSB ADCL LSB of Result tAVPU tADSU tAINIT 11 TADC_CLK MUX and REFS Update S &a mHopllde CoCnovmerpsleiotne All bits of register ADCSRC are single buffered (2) through a temporary register to which the CPU has random access. This ensures that start-up time and track-and-hold time changes only take place at a safe point during the conversion. This mechanism is identical to changing an ADC channel of reference voltage, see section "Changing Channel or Reference Selection" on page 451 for details. Note: 2. ADCSRC is not buffered in ATmega128RFA1. Therefore with these devices the start-up time and the track-and-hold time must not change while a conversion is in progress. 27.5.3 Conversion Timing The delay from requesting a conversion start by setting the ADSC bit in ADCSRA to the moment where the sample-and-hold takes place is fixed. The same fixed delay also applies for auto triggered conversions. In this case three additional CPU clock cycles are used for the trigger event synchronization logic. The delay is different for single- 449 8393C-MCU Wireless-09/14

ended and differential channels. A summary is given in Table 27-3 below. All conversions take 11 ADC clock cycles. When a conversion is complete, the result is written to the ADC Data Registers, and ADIF is set. In Single Conv e rsion mode, ADSC is cleared simultaneously. The software may then set ADSC again, and a new conversion will be initiated at the earliest after the following tracking phase. The tracking phase is required after each conversion. Its duration can be adjusted according to the ADC clock speed by the ADTHT bits in ADCSRC and is different for single-ended and differential channels. For details see Table 27-4 below. In Free Running mode, a new conversion will be started immediately after the tracking phase of the previous conversion while ADSC remains high. The calculation of the resulting sample rate is give n in Table 27-5 below. For timing diagrams of single and auto triggered and free running conversions see Figure 27-6 below to Figure 27-8 on page 451. Table 27-3. Conversion Start Delay Channel Dela y from Conversion Start Request to Sample & Hold tSCSMP Single-Ended (1) 2 CPU clock cycles Differential 2 ADC clock cycles Note: 1. The time t is between 0…4 CPU clock cycles depending on the ADPS CSMP configuration of register ADCSRA for the ATmega128RFA1 Table 27-4. Tracking Time Channel Tracking Phase Duration t in ADC Clock Cycles TRCK Single-Ended ADTHT+1, minimum 500 ns Differential 2ADTHT+3 Table 27-5. Sample Rate in Free Running Mode Channel Sample Rate in ADC Clock Cycles Single-Ended ADTHT+12 Differential 2ADTHT+14 Figure 27-6. ADC Timing Diagram, Single Conversion Conversion Tracking Conversion ADC Clock ADEN ADSC ADIF ADCH Sign and MSB of Result ADCL LSB of Result tSCSMP 11 TADC_CLK tTRCK tSCSMP Prescaler MUX and REFS Update PaSnraedmscpalele &r RHeosldet CoCnovmerpsleiotne MUX and REFS Update RaSnaedmseptle & Hold ATmega256/128/64RFR2 450 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 Figure 27-7. ADC Timing Diagram, Auto Triggered Conversion Conversion Tracking Conversion ADC Clock ADEN Trigger Source ADATE ADIF ADCH Sign and MSB of Result ADCL LSB of Result tSCSMP 11 TADC_CLK tTRCK tSCSMP Prescaler MUX and REFS Update PaSnraedmscpalele &r RHeosldet CoCnovmerpsleiotne MUX and REFS Update RaSnaedmseptle & Hold Figure 27-8. ADC Timing Diagram, Free Running Conversion Conversion Tracking Conversion ADC Clock ADTS[2:0] 0 ADSC ADIF ADCH Sign and MSB of Result ADCL LSB of Result 11 TADC_CLK tTRCK 11 TADC_CLK CoCnovmerpsleiotne MUX and REFS Update Sample & Hold 27.6 Changing Channel or Reference Selection The MUXn and REFSn bits in the ADMUX and ADCSRB Register are single buffered through a temporary register to which the CPU has random access. This ensures that the channels and reference selection only takes place at a safe point during the conversion. The channel and reference selection is continuously updated either during the AVDD power-up phase or until a conversion is started by setting ADSC. After this the channel and reference selection is locked to ensure a sufficient initialization and sampling time for the ADC. Continuous updating of the channel selection resumes after the conversion has completed (ADIF in ADCSRA is set). If Auto Triggering is used, t he exact time of the triggering event can be undetermined. Special care must be taken when updating the ADMUX Register, in order to control which conversion will be affected by the new settings. If both ADATE and ADEN in the ADSCRA Register are written to one, an interrupt event can occur at any time. If the ADMUX Register is changed in this period, the user cannot tell if the next conve rsion is based on the old or the new settings. ADMUX can be safely updated in the following ways: 1. When ADATE or ADEN is cleared. 2. During a conversion 3. After a conversion, before the Interrupt Flag used as trigger source is cleared. When updating ADMUX in one of these conditions, the new settings will affect the next A/D conversion. 451 8393C-MCU Wireless-09/14

After the channel or reference voltage selection is updated a settling time is required for the ADC and the gain amplifier or the reference voltage to stabilize. When changing the channel selection while the ADC is enabled the required settling phase is automatically inserted by the ADC interface, see section "ADC Input Channels" below. For consideration on changing the reference voltage selection please refer to section "ADC Voltage Reference" on page 453. 27.6.1 Accessing the ADMUX Register The channel selection bits MUX4:0 and MUX5 are located in two different register, the ADMUX and the ADCSRB register. To ensure that changes go only into effect after both register have been changed they are internally buffered (see Figure 27-9 below and Figure 27-10 on page 453). The MUX5 bit has to written first followed by a write access to the MUX4:0 bits which triggers the update of the internal buffer. If only the MUX4:0 bits need to be modified then a write access to the MUX4:0 bits is sufficient. 27.6.2 ADC Input Channels The ADC input channels can be changed while the ADC is running under the condition that the previous channel was a single-ended one. Changing between differential channels however requires that the ADC is disabled and enabled again to make the ADC go through the initial start-up phase. If changing from single-ended to single-ended or from single-ended to differential input channels a settling phase is automatically inserted by the ADC interface logic after the input channel is modified. The settling phase is required by the ADC and the gain amplifier to stabilize. If a conversions start is requested during this settling phase, by setting ADSC or by a trig g er event in Auto Triggered mode then the conversion is started only after the settling phase has completed. Figure 27-9. ADC Timing Diagram, Changing MUXn after a Conversion Conversion ADC Settling ADC Clock MUX5:0 Old Channel New Channel MUX5:0internal Old Channel New Channel ADIF ADCH Sign and MSB of Result ADCL LSB of Result tASET Conversion tCHDLY ADC Input New Conversion Complete Channel is can be started changed from here In case the MUXn bits are altered during an ongoing conversion, the ADC input channel is changed after the conversion has completed. MUXn changes occurring during the tracking phase, which follows a conversion, will stop the tracking phase and the ADC settling phase will be entered. ATmega256/128/64RFR2 452 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 Figure 27-10. ADC Timing Diagram, Changing MUXn during a Conversion Conversion ADC Settling ADC Clock MUX5:0 Old Channel New Channel MUX5:0internal Old Channel New Channel ADIF ADCH Sign and MSB of Result ADCL LSB of Result 11 TADC_CLK tASET CoCnovmerpsleiotne tCHDLY ACDhaCn Innepl uist Ncaenw b Ce osntavretresdio n changed from here In Free Running mode MUXn can also be modified. In this case the ADC input channel is changed after the conversion end or from the subsequent tracking phase. As a consequence the time from one conversion to the next is extended by the duration of the ADC settling phase. The ADC settling time t depends on the previous and the new channel and on the ASET configuration of the ADSUT and ADTHT bits as shown in Table 27-6 below. Additionally a synchronization delay t from 0.5 to 2 ADC Clock cycles is required between CHDLY changing the ADC input channel selection and the beginning of the settling phase. For details see the timing diagrams Figure 27-9 on page 452 and Figure 27-10 above. If the analog input signal encounters large variations it can be useful to manually reset the ADC and the gain ampl ifier before starting a new conversion. To achieve this, the settling phase can be forced without modifying MUXn by writing a logic one to the Analog Channel Change bit ACCH in ADCSRB (2). Table 27-6. Settling Time after Channel Changes Channel Transition Settling Time tASET in ADC Clock Cycles To Single-Ended ADTHT+2 To Differential (1) 4(ADSUT+1) + 2(ADTHT+2) Note: 1. Not allowed for ATmegaRF128RFA1 - changing to/between differential channels requires the ADC to be disabled and enabled again. 2. The function of the ACCH bit is not available for ATmegaRF128RFA1. 27.6.3 ADC Voltage Reference The reference voltage for the ADC (V ) indicates the conversion range for the ADC. REF Single ended channels that exceed V will result 0x3FF. V can be selected by the REF REF REFSn bits in the ADMUX register as either AVDD (1.8V), internal 1.5V or 1.6V reference or an external volt age at the AREF pin. AVDD is connected to the ADC through a passive switch. The internal 1.5V and 1.6V references are generated from a bandgap reference (VBG) through an amplifier. In either case, the external AREF pin is directly connected to the ADC and the reference voltage can be measured at the AREF pin with a high impedance voltmeter. When using the internal 1.5V or 1.6V references no external de-coupling capacitor must be connected to AREF. High capacitive loading will de-stabilize the internal voltage amplifier. The 1.6V reference voltage is calibrated to an absolute accuracy of 1 LSB during the manufacturing process. 453 8393C-MCU Wireless-09/14

If the user has a fixed voltage source connected to the AREF pin, the user may not use the other reference voltage options in the application, as they will be shorted to the external voltage. An external reference voltage must be supplied with a very low impedance R (see "ADC Characteristics" on page 561). The load current I AREF,EXT L,AREF (see "ADC Characteristics" on page 561) seen by the external source is code dependent and changes (current steps) in the course of the successive approximation process. If no external voltage is applied to the AREF pin, the user may switch between AVDD, 1.5V and 1.6V as reference selection. For internal references a stable voltage is indicated by the REFOK bit in ADCSRB. Changes of the reference selection bits REFSn will take effect until a conversion start is requested by setting ADSC in ADCSRA. After the reference voltage selection is updated a settling time is required for the reference voltage to stabilize. This settling phase is automatically inserted by the ADC interface when changing the reference selection while the ADC is enabled. Notes: 1. The ADC has to be disabled and enabled again for new reference selections in ATmegaRF128RFA1. 2. Changing the re ference voltage in Free Running mode will abort Free Running mode. The newly selected reference voltage is available after the automatically inserted settling phase, yet no new conversion will be started. 27.7 ADC Noise Canceller The ADC features a noise canceller that enables conversion during sleep mode to reduce noise induced from the CPU core and other I/O peripherals. The noise canceller can be used with ADC Noise Reduction and Idle mode. To make use of this feature, the following procedure should be used: 1. Make sure that the ADC is enabled and is not busy converting. Single Conversion mode must be selected and the ADC Conversion Complete interrupt must be enabled. 2. Enter ADC Noise Reduction mode (or Idle mode). The ADC will start a conversion once the CPU has been halted. 3. If no other interrupts occur before the A/D conversion completes, the ADC interrupt will wake up the CPU and execute the ADC Conversion Complete interrupt routine. If another interrupt wakes up the CPU before the A/D conversion is complete, that interrupt will be executed, and an ADC Conversion Complete interrupt request will be generated when the A/D conversion completes. The CPU will remain in active mode until a new sleep c ommand is executed. Note that the ADC will not be automatically turned off when entering other sleep modes than Idle mode and ADC Noise Reduction mode. The user is advised to write zero to ADEN before entering such sleep modes to avoid excessive power consumption. 27.7.1 Analog Input Circuitry The analog input circuitry for single ended channels is illustrated in Figure 27-11 on page 455. An analog source applied to ADCn is subjected to the pin capacitance and input leakage of that pin, regardless of whether that channel is selected as input for the ADC. When the channel is selected, the source must drive the S/H capacitor through the series resistance (combined resistance in the input path). The ADC is optimized for analog signals having output impedance Z of OUT approximately 3 kΩ or less. If such a source is used, the sampling time will be negligible. If a source with higher impedance is used, the correct sampling time will ATmega256/128/64RFR2 454 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 depend on how much time is needed to charge the S/H capacitor, which can vary widely. The user is recommended to only use low impedance sources with slowly varying signals, since this minimizes the required charge transfer to the S/H capacitor. The required tracking time (input sampling switch closed) t to settle to within 1 LSB DTRCK can be estimated to t =(Z /kΩ+2000)⋅0.097ns DTRCK OUT for Z > 3kΩ (worst case: maximum input step). A minimum tracking time of 500ns is OUT guaranteed by the conversion logic. Based on the ADC clock frequency the bits ADTHT[1:0] of register ADCSRC allow the adjustment of the tracking time to the user’s requirements. Tracking time requirements should also be considered for the differential mode. The input signal is sampled by the gain amplifier. The value of the input capacitance C S/H depends on the selected gain (~7pF for 200x gain, <1pF otherwise). The tracking is equal to 50% of the clock period of CK . Hence in differential mode a slower clock ADC2 frequency is required for input sources with high impedance. Figure 27-11. Analog Input Circuitry IIH 2k ADCn IIL CS/H = 14pF VAVDD/2 Signal components higher than the Nyquist frequency (f /2) should not be present for ADC either kind of channels, to avoid distortion from unpredictable signal convolution. The user is advised to remove high frequency components with a low-pass filter before applying the signals as input s to the ADC. 27.7.2 Analog Noise Canceling Techniques Digital circuitry inside and outside the device generates EMI which might affect the accuracy of analog measurements. If conversion accuracy is critical, the noise level can be reduced by applying the following techniques: 1. Keep analog signal paths as short as possible. Make sure analog tracks run over the ground plane, and keep t hem well away from high-speed switching digital tracks. 2. Use the ADC noise canceller function to reduce induced noise from the CPU. 3. If any ADC port pins are used as digital outputs, it is essential that these do not switch while a conversion is in progress. 27.7.3 Offset Compensation Schemes The differential amplifier has a built-in offset cancellation circuitry that nulls the offset of differential measurements as much as possible. The remaining offset in the analog path can be measured directly by selecting the same channel for both differential inputs. This offset residue can then be subtracted in software from the measurement results. The offset on any channel can be reduced below one LSB using this kind of software based offset correction. 455 8393C-MCU Wireless-09/14

27.7.4 Differential Amplifier Limitations The programmable gain, differential amplifier (PGA) converts a differential input voltage to a single-ended output voltage that is further processed with the 10 bit ADC. The performance of the PGA i s determined by the physical properties of its operational amplifier: • The noise of PGA adds to the random error of the ADC conversation result. However the PGA noise enables the application of oversampling techniques to recover or even increase the ADC resolution. • The gain of the PGA falls if the output voltage of the operational amplifier approaches the supply rails (AVSS) resulting in an increased non-linearity. Hence for reasonable INL and DNL performance the input voltage range must be limited. 27.7.5 ADC Accuracy Definitions An n-bit single-ended ADC converts a voltage linearly between 0V and V in 2n steps REF (LSB’s). The lowest code is read as 0, and the highest code is read as 2n-1. Several parameters describ e the deviation from the ideal behavior: • Offset: The deviation of the first transition (0x000 to 0x001) compared to the ideal transition (at 0.5 LSB). Ideal value: 0 LSB. Figure 27-12. Offset Error Output Code Ideal ADC Actual ADC Offset Error VREF Input Voltage • Gain Error: After adjusting for offset, the Gain Error is found as the deviation of the last transition (0x3FE to 0x3FF) compared to the ideal transition (at 1.5 LSB below maximum). Ideal value: 0 LSB. ATmega256/128/64RFR2 456 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 Figure 27-13. Gain Error Output Code Gain Error Ideal ADC Actual ADC VREF Input Voltage • Integral Non-linearity (INL): After adjusting for offset and gain error, the INL is the maximum deviation of an actual transition compared to an ideal transition for any code. Ideal value: 0 LSB. Figure 27-14. Integral Non-linearity (INL) Output Code IN L Ideal ADC Actual ADC VREF Input Voltage • Differential Non-linearity (DNL): The maximum deviation of the actual code width (the interval between two adjacent transitions) from the ideal code width (1 LSB). Ideal value: 0 LSB. 457 8393C-MCU Wireless-09/14

Figure 27-15. Differential Non-linearity (DNL) Output Code 0x3FF 1 LSB DNL 0x000 0 V Input Voltage REF • Quantization Error: Due to the quantization of the input voltage into a finite number of codes, a range of input voltages (1 LSB wide) will code to the same value. It is always ±0.5 LSB. • Absolute Accuracy: The maximum deviation of an actual (unadjusted) transition compared to an ideal transition for any code. This is the compound effect of offset, gain error, differential error, non-linearity, and quantization error. Ideal value: ±0.5 LSB. 27.8 ADC Conversion Result After the conversion is complete (ADIF is high), the conversion result can be found in the ADC Result Registers (ADCL, ADCH). For single ended conversion , the result is V ⋅1024 ADC = IN V REF where V is the voltage on the selected input pin and V the selected voltage IN REF reference (see "Table 27-11" on page 464 and "Table 27-12" on page 465). 0x000 represents analog ground, and 0x3FF represents the selected reference voltage minus one LSB. If differential channels are used, the result is (V −V )⋅GAIN⋅512 ADC = POS NEG V REF where V is the voltage on the positive input pin, V the voltage on the negative POS NEG input pin, and V the selected voltage reference. The result is presented in two’s REF complement form, from 0x200 (-512d) through 0x1FF (+511d). Note that if the user wants to perform a quick polarity check of the result, it is sufficient to read the MSB of the result (ADC9 in ADCH). If the bit is one, the result is negative, and if this bit is zero, the result is positive. Figure 27-16 on page 459 shows the decoding of the differential input range. Table 27-7 below shows the resulting output codes if the differential input channel pair (ADCn - ADCm) is selected with a gain of GAIN and a reference voltage of V . REF ATmega256/128/64RFR2 458 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 Figure 27-16. Differential Measurement Range Output code 0x1FF 0x000 - VREF/GAIN 0x3FF 0 VREF/GAIN Dvoiflfteargeen t(iVaol lItnsp)ut 0x200 Table 27-7. Correlation Between Input Voltage and Output Codes V Read Code Corresponding Decimal Value ADCn V + V / GAIN 0x1FF 511 ADCm REF V + 0.999 V / GAIN 0x1FF 511 ADCm REF V + 0.998 V / GAIN 0x1FE 510 ADCm REF … … … V + 0.001 V / GAIN 0x001 1 ADCm REF V 0x000 0 ADCm V - 0.001 V / GAIN 0x3FF -1 ADCm REF … … … VADCm - 0.999 VREF / GAIN 0x201 -511 V - V / GAIN 0x200 -512 ADCm REF Example: ADMUX = 0xED (ADC3 - ADC2, 10x gain, 1.6V reference, left adjusted result) The voltage on ADC3 is 300 mV; the voltage on ADC2 is 425 mV. ADCR = 512 * 10 * (300 - 425) / 1600 = -400 = 0x270. ADCL will thus read 0x00, and ADCH will read 0x9C. Writing zero to ADLAR right adjusts the result: ADCL = 0x70, ADCH = 0x02. 459 8393C-MCU Wireless-09/14

27.9 Internal Temperature Measurement The on-chip temperature can be measured using a special setup of the A/D converter inputs. The integrated temperature sensor provides a linear, medium-accurate voltage proportional to the absolute temperature (in Kelvin). This voltage is first amplified with the programmable gain amplifier and then processed with the A/D converter. A low frequency of the conversion clock must be selected due to the nature of the input signal. The absolute accuracy of the temperature measurement is limited by manufacturing tolerances, noise from supply and ground voltages and the exactness of the reference voltage. One time calibration at room temperature can easily compensate this distribution. The resolution of the temperature reading can be improved (<1K) by averaging (using float numbers) or decimation (based on integer numbers) of multiple A/D conversion results. In this way the impact of noise is reduced (see measurement results "Temperature Sensor" on page 588 and "Differential Amplifier Limitations" on page 456). The following table summarizes the preferred setup of the temperature measurement: Table 27-8. Recommended ADC Setup for Temperature Measurement Parameter Register Recommended Setup ADC Channel ADMUX, Select the Temperature Sensor, MUX4:0 = 01001; ADCSRB MUX5 = 1; ADC Clock ADCSRA Select a clock frequency of 500 kHz or lower; V ADMUX Select the internal 1.6V reference voltage; REF Start-up time ADCSRC Standard requirement of 20 µs is sufficient; Tracking time ADCSRC Setting ADTHT = 0 is sufficient; Assembly Code Example(1) … ldi r17,(1<<ADEN)+(4<<ADPS0) ; enable the ADC, prescaler = 16 sts ADCSRA, temp wait_avdd_ok: ; wait for AVDD to come up lds r17, ADCSRB sbrs r17, AVDDOK rjmp wait_avdd_o k ; set start-up time to 80us (500kHz ADC clock) ldi r17, 10<<ADSUT0 sts ADCSRC, temp ldi r17, 1<<MUX5 sts ADCSRB, tem p ; set MUX5 before MUX4:1 ; 1.6V reference voltage + temperature sensor channel ldi r17, (3<<REFS0)+(9<<MUX0) sts ADMUX, temp wait_vref_ok: lds r17, ADCSRB ; wait for reference voltage sbrs r17, REFOK rjmp wait_vref_ok ATmega256/128/64RFR2 460 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 ldi run_cmd, (1<<ADEN)+(1<<ADSC)+(4<<ADPS0) run_conversion: sts ADCSRA, run_cmd wait_adsc: lds r17, ADCSRA sbrc r17, ADSC ; flag cleared at conversion complete rjmp wait_adsc lds r18, ADCL ; measured temperature in ADCL and ADCH lds r19, ADCH … The above Assembly code example enables the temperature measurement step by step. Waiting for AVDDOK and REFOK is optional. The conversion will not start before the two bits are set. The wait time can be extended if necessary or choose a longer start-up time. An 8 MHz CPU clock is assumed. C Code Example(1) uint16_t adc_meastemp (void) { ADCSRC = 10<<ADSUT0; // set start-up time ADCSRB = 1<<MUX5; // set MUX5 first ADMUX = (3<<REFS0) + (9<<MUX0); // store new ADMUX, 1.6V AREF // switch ADC on, set prescaler, start conversion ADCSRA = (1<<ADEN) + (1<<ADSC) + (4<<ADPS0); do {} while( (ADCSRA & (1<<ADSC))); // wait for conversion end ADCSRA = 0; // disable the ADC return (ADC); } Notes: 1. See section "About Code Examples" on page 7. The C Code Example fully relies on the integrated start-up mechanism of the A/D converter. The accuracy can be increased by averaging and/or oversampling. In addition a dummy conversion can be inserted before the first temperature measurement is assessed. The A/D conversion result ADC will always be a positive number. The ideal result TEMP can be calculated when using the internal 1.6V reference voltage according to the following equation: ADC =241.4+0.885⋅θ/°C TEMP Similar the Celsius-temperature θ can be extracted from the A/D conversion result with this formula: θ/°C =1.13⋅ADC −272.8 TEMP Note that the above equations are only valid in the allowed operating temperature range. The translation of the A/D measurement result to a Celsius-temperature value can be easily achieved with a look-up table in software. The temperature sensor is 461 8393C-MCU Wireless-09/14

connected to a differential input channel with a gain of 10. The voltage offset error of the differential signal processing can be corrected to the first order by using an appropriate similar channel (e.g. MUX4:0=01000, MUX5=0, see Table 27-12 on page 465). The ADC result of this channel is then subtracted from the ADC result of the temperature sensor. Offset errors are typically only +1 bit (ADC = 0x001) or -1 bit (ADC = 0x3ff). Note: 1. For the ATmega128RFA1 changing between the temperature sensor channel and the channel for the offset error correction requires to disable the ADC, select the new channel and then enable the ADC again, or to discard the first conversion result from the new input channel. 27.10 SRAM DRT Voltage Measurement The decrease of the supply voltage of SRAM block 2 for the leakage current reduction can also be measured using a special setup of the A/D converter inputs. The details of the SRAM leakage current reduction are described in section "SRAM with Data Retention" on page 193. Th e supply voltage of a disabled SRAM block can be reduced to save leakage power while maintaining data retention. This feature applies to all four SRAM blocks however only the voltage of SRAM block 2 can be verified using the A/D converter. The default factory setting for the data retention (DRT) voltage normally guarantees the best leakage performances. Other values are nevertheless possible and can be selected by the application software. The true value of the supply voltage reduction is depending on the manufacturing process and environmental conditions like temperature. The A/D converter allows determining the value of the DRT voltage of SRAM block 2. The same voltage setting results for all practical purposes in the same supply voltage for all other SRAM blocks. Care must be taken when verifying the DRT voltage of SRAM block 2 with the A/D converter because it will be put into sleep mode and hence it is not available for the application program. Addressing the disabled SRAM will return invalid data (all data read zero). The voltage measurement is split into two parts. One setting allows measuring the voltage drop from DVDD. The other setting allows verifying the voltage shift from DVSS. Both measurements are differential and use the programmable gain amplifier. A low frequency of the conversion clock must be selected due to the high- impedance nature of the input signal. Accurate and stable voltage readings may just be available after a long waiting time of up to 100 ms. This limitation is the consequence of the small leakage currents that discharge the internal de-coupling capacitances before the supply voltage settles to the DRT value. The following table summarizes the preferred setup of the DRT voltage measurement: Table 27-9. Recommended ADC Setup for DRT Voltage Measurements Parameter Register Recommended Setup SRAM DRT on DRTRAM2 Set bits DISPC and ENDRT to 1; ADC Channel ADMUX, Select MUX4:0 = 10100 to measure V ; DRTBBP Select MUX4:0 = 11101 to measure V ; DRTBBN ADCSRB MUX5 = 1; ADC Clock ADCSRA Select a clock frequency of 500kHz or lower; V ADMUX Select the internal 1.6V reference voltage; REF Start-up time ADCSRC Standard requirement of 20µs is sufficient; Tracking time ADCSRC Setting ADTHT = 0 is sufficient; ATmega256/128/64RFR2 462 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 The A/D conversion result will always be a positive number for both V and DRTBBP V . The SRAM supply voltage is easily calculated according to the following DRTBBN equation (see chapter "SRAM with Data Retention" on page 193): V =V −(V +V ) DD,SRAM,DRT DD DRTBBP DRTBBN The conversion result is coded as described in "ADC Conversion Result" on page 458 with a GAIN of 0.5. It is not possible to read both V and V at the same time. DRTBBP DRTBBN However the time required for the A/D conversion is short compared to the time constant of a DRT voltage change. 27.11 EVDD Voltage Measurement A dedicated, internal, single-ended input channel is available (1) to measure the EVDD supply voltage directly with the A/D converter. This feature is a supplement to observing EVDD with the battery monitor (see "Battery Monitor (BATMON)" on page 85). The EVDD supply voltage is internally divided by three with a resistor. The typical, total resistor value is 120 kΩ. Hence when activating the EVDD measurement channel, EVDD is loaded with an additional current. Deselect the EVDD measurement channel after completion of the A/D conversion. It is important to allow a sufficient high tracking time for full settling of the ADC input voltage due to the attached RC time constant of this input channel. The following table summarizes the preferred setup of the EVDD voltage measurement: Table 27-10. Recommended ADC Setup for EVDD Voltage Measurements Parameter Register Recommended Setup ADC Channel ADMUX, Select MUX4:0 = 00110 to measure V ; DRTBBP ADCSRB MUX5 = 1; ADC Clock ADCSRA Select a clock frequency of 1 MHz or lower; V ADMUX Select the internal 1.6V reference voltage; REF Start-up time ADCSRC Standard requirement of 20 µs is sufficient; Tracking time ADCSRC Value depends on ADC Clock, a minimum of 4 µs is required; The A/D conversion result ADC will always be a positive number (single-ended EVDD conversion). The input voltage V of the converter is easily derived by: IN V = 1/3 V IN EVDD Refer to section "ADC Conversion Result" on page 458 for details about deriving A/D conversion result. ADC and Analog Comparator share the same Analog Multiplexer. It allows routing the divided voltage to the negative input of the Analog Comparator if the Analog Comparator Multiplexer Enable bit (ACME in ADCSRB) is set. 463 8393C-MCU Wireless-09/14

27.12 Register Description 27.12.1 ADMUX – ADC Multiplexer Selection Register Bit 7 6 5 4 3 2 1 0 NA ($7C) REFS1 REFS0 ADLAR MUX4 MUX3 MUX2 MUX1 MUX0 ADMUX Read/Write RW RW RW RW RW RW RW RW Initial Value 0 0 0 0 0 0 0 0 • Bit 7:6 – REFS1:0: Reference Selection Bits These bits select the voltage reference for the ADC, as shown in the following table. Changes of these bits will take effect until a conversion start is requested by setting ADSC. The internal voltage reference options may not be used if an external reference voltage is being applied to the AREF pin. Table 27-11. Reference Voltage Selections for ADC REFS1 REFS0 Reference Voltage Selection 0 0 AREF, Internal V turned off REF 0 1 AVDD (1.8V) 1 0 Internal 1.5V Voltage Reference (no external capacitor at AREF pin) 1 1 Internal 1.6V Voltage Reference (no external capacitor at AREF pin) Note: 1. ATmega128RFA1: Changes of the REFS bits will only take effect until the first conversion start is requested. After this the ADC has to be disabled and enabled again for new reference selections. • Bit 5 – ADLAR: ADC Left Adjust Result The ADLAR bit affects the presentation of the A/D conversion result in the ADC Data Register. Write one to ADLAR to left adjust the result. Otherwise, the result is right adjusted. Changing the ADLAR bit will affect the ADC Data Register immediately, regardless of any ongoing c onversions. For a complete description of this bit, see "ADCL and ADCH – The ADC Data Register" on page 469. • Bits 4:0 – MUX4:0: Analog Channel and Gain Selection Bits The value of these bits selects which combination of analog inputs is connected to the ADC. See Table 27-12 on page 465 for details. If these bits are changed during a conversion, the change will not go in effect until this conversion is complete (ADIF in ADCSRA is set). Note that the MUX5 bit is located in the ADCSRB register. A write access to the MUX4:0 bits triggers the update of the internally buffered MUX5 bit, see "Accessing the ADMUX Reg ister" on page 452 . 27.12.2 ADCSRB – ADC Control and Status Register B Bit 7 6 5 4 3 2 1 0 NA ($7B) AVDDOK ACME REFOK ACCH MUX5 ADTS2 ADTS1 ADTS0 ADCSRB Read/Write R R/W R R/W R/W R/W R/W R/W Initial Value 0 0 0 0 0 0 0 0 • Bit 7 – AVDDOK: AVDD Supply Voltage OK The analog functions of the ADC are powered from the AVDD domain. AVDD is supplied from an internal voltage regulator. Setting the ADEN bit in register ADCSRA will power-up the AVDD domain if not already requested by another functional group of the device. The bit allows the user to monitor (poll) the status of the AVDD domain. A status of 1 indicates that AVDD has been powered-up. ATmega256/128/64RFR2 464 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 • Bit 6 – ACME: Analog Comparator Multiplexer Enable This bit is used for the Analog Comparator only. See "ADCSRB – ADC Control and Status Register B" on page 442 for details. • Bit 5 – REFOK: Referen ce Voltage OK The status of the internal generated reference voltage can be monitored through this bit. Setting the ADEN bit in register ADCSRA will enable the reference voltage for the ADC according to the REFSn bits in the ADMUX register. The reference voltage will be available after a start-up delay. A REFOK value of 1 indicates that the internal generated reference voltage is approaching final levels. • Bit 4 – ACCH: Analog Channel Change The user can force a reset of the analog blocks by setting this bit to 1 without requesting a different channel. The analog blocks of the ADC will be reset to handle possible new voltage ranges. Such a reset phase is especially important for the gain amplifier. It could be temporarily disabled by a large step of its input common voltage leading to erroneous A/D conversion results. ACCH will read as one until the reset phase of the analog blocks can be entered. • Bit 3 – MUX5: Analog Channel and Gain Selection Bit This bit is used together with MUX4:0 in ADMUX to select the analog input signals connected to the ADC. See the following table for details. If this bit is changed during a conversion, the change will not go in effect until this conversion is complete. Note that the MUX5 bit is internally buffered and a write access to the MUX4:0 bits is required to trigger the update of the MUX5 bit, see "Accessing the ADMUX Register" on page 452 . Table 27-12. Input Channel Selections Single Ended Positive Differential Negative Differential MUX5:0 Input Input Input Gain 000000 ADC0 000001 ADC1 000010 ADC2 000011 ADC3 N/A 000100 ADC4 000101 ADC5 000110 ADC6 000111 ADC7 001000 ADC0 ADC0 10x 001001 ADC1 ADC0 10x 001010 ADC0 ADC0 200x 001011 ADC1 ADC0 200x N/A 001100 ADC2 ADC2 10x 001101 ADC3 ADC2 10x 001110 ADC2 ADC2 200x 001111 ADC3 ADC2 200x 010000 ADC0 ADC1 1x 010001 ADC1 ADC1 1x N/A 010010 ADC2 ADC1 1x 010011 ADC3 ADC1 1x 465 8393C-MCU Wireless-09/14

Single Ended Positive Differential Negative Differential MUX5:0 Input Input Input Gain 010100 ADC4 ADC1 1x 010101 ADC5 ADC1 1x 010110 ADC6 ADC1 1x 010111 ADC7 ADC1 1x 011000 ADC0 ADC2 1x 011001 ADC1 ADC2 1x 011010 ADC2 ADC2 1x N/A 011011 ADC3 ADC2 1x 011100 ADC4 ADC2 1x 011101 ADC5 ADC2 1x 011110 1.2V (V ) BG N/A 011111 0V (AVSS) 100000 Reserved 100001 Reserved 100010 Reserved 100011 Reserved N/A 100100 Reserved 100101 Reserved 100110 EVDD(1) 100111 Reserved 101000 Reserved 101001 Temperature Sensor 101010 Reserved 101011 Reserved N/A 101100 Reserved 101101 Reserved 101110 Reserved 101111 Reserved 110000 Reserved 110001 Reserved 110010 Reserved 110011 Reserved N/A 110100 SRAM Back-bias Voltage V DRTBBP 110101 Reserved 110110 Reserved 110111 Reserved 111000 Reserved 111001 Reserved 111010 N/A Reserved 111011 Reserved 111100 Reserved ATmega256/128/64RFR2 466 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 Single Ended Positive Differential Negative Differential MUX5:0 Input Input Input Gain 111101 SRAM Back-bias Voltage V DRTBBN 111110 Reserved N/A 111111 Reserved Note: 1. EVDD measurement is not available in ATmega128RFA1. • Bits 2:0 – ADTS2:0: ADC Auto Trigger Source If ADATE in ADCSRA is written to one, the value of these bits selects which source will trigger an A/D conversion. If ADATE is cleared, the ADTS2:0 settings will have no effect. A conversion will be triggered by the rising edge of the selected Interrupt Flag. Note that switching from a trigger source that is cleared, to a trigger source that is set, will generate a positive edge on the trigger signal. If ADEN in ADCSRA is set, this will start a conversion. Switching to Free Running mode (ADTS2:0=0) will not cause a trigger event, even if the ADC Interrupt Flag is set. Table 27-13. ADC Auto Trig ger Source Selections ADTS2 ADTS1 ADTS0 Trigger Source 0 0 0 Free Running mode 0 0 1 Analog Comparator 0 1 0 External Interrupt Request 0 0 1 1 Timer/Counter0 Compare Match A 1 0 0 Timer/Counter0 Overflow 1 0 1 Timer/Counter1 Compare Match B 1 1 0 Timer/Counter1 Overflow 1 1 1 Timer/Counter1 Capture Event 27.12.3 ADCSRA – ADC Control and Status Register A Bit 7 6 5 4 3 2 1 0 NA ($7A) ADEN ADSC ADATE ADIF ADIE ADPS2 ADPS1 ADPS0 ADCSRA Read/Write R/W R/W R/W R/W R/W R/W R/W R/W Initial Value 0 0 0 0 0 0 0 0 • Bit 7 – ADEN: ADC Enable Writing this bit to one enable s the ADC. The AVDD supply voltage will also be enabled if not already available. By writing it to zero, the ADC is turned off. Turning the ADC off while a conversion is in progress will terminate this conversion. • Bit 6 – ADSC: ADC Start Conversion In Single Conversion mode, write this bit to one to start each conversion. In Free Running mode, write this b it to one to start the first conversion. The first conversion after ADSC has been written after the ADC has been enabled, or if ADSC is written at the same time as the ADC is enabled, will include a start-up time to initialize the analog blocks of the ADC. The start-up time is defined by the ADSUT bits of register ADCSRC. ADSC will read as one as long as a conversion is in progress. When the conversion is complete, it returns to zero. Writing zero to this bit has no effect. 467 8393C-MCU Wireless-09/14

• Bit 5 – ADATE: ADC Auto Trigger Enable When this bit is written to one, Auto Triggering of the ADC is enabled. The ADC will start a conversion on a positive edge of the selected trigger signal. The trigger source is selected by setting the ADC Trigger Select bits, ADTS in ADCSRB. • Bit 4 – ADIF: ADC Interrupt Flag This bit is set when an A/D conversion is completed and the Data Register are updated. The ADC Conversion Complete Interrupt is executed if the ADIE bit and the I-bit in SREG are set. ADIF is cleared by hardware when executing the corresponding interrupt handling vector. Alternatively, ADIF is cleared by writing a logical one to the flag. Beware that if doing a Read-Modify-Write on ADCSRA, a pending interrupt can be disabled. This also applies if the SBI and CBI instructions are used. • Bit 3 – ADIE: ADC Interrupt Enable When this bit is written to one and the I-bit in SREG is set, the ADC Conversion Complete Interrupt is activated. • Bits 2:0 – ADPS2:0: ADC Prescaler Select Bits These bits determine the di vision factor between the CPU frequency and the input clock to the ADC. Table 27-14. ADC Prescaler Selections ADPS2 ADPS1 ADPS0 Division Factor 0 0 0 2 0 0 1 2 0 1 0 4 0 1 1 8 1 0 0 16 1 0 1 32 1 1 0 64 1 1 1 128 27.12.4 ADCSRC – ADC Control and Status Register C Bit 7 6 5 4 3 2 1 0 NA ($77) ADTHT1 ADTHT0 ADSUT5(1) ADSUT4 ADSUT3 ADSUT2 ADSUT1 ADSUT0 ADCSRC Read/Write RW RW RW RW RW RW RW RW Initial Value 0 1 0 1 0 1 0 0 This register defines the track-and-hold time for sampling the analog input voltage of the ADC and it defines the start-up time for the analog blocks based on a number of ADC clock cycles. The ADC clock is generated from the system clock with the ADC prescaler. The bits ADPS2:0 of register ADCSRA set the prescaler ratio. Correct start- up and track-and-hold times are important for precise conversion results. • Bits 7:6 – ADTHT1:0: ADC Track-and-Hold Time These bits define the number of ADC clock cycles for the sampling time of the analog input voltage. For a complete description of this bit, see "Pre-scaling and Conversion Timing" on page 448. ATmega256/128/64RFR2 468 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 • Bits 5:0 – ADSUT5:0: ADC Start-up Time These bits define the number of ADC clock cycles for the start-up time of the analog blocks. For a complete description of this bit, see "Pre-scaling and Conversion Timing" on page 448. Note: 1. ADSUT5 is not available in ATmega128RFA1. 27.12.5 ADCL and ADCH – The ADC Data Register 27.12.5.1 ADLAR = 0 Bit 15 14 13 12 11 10 9 8 NA ($79) – – – – – – ADC9 ADC8 ADCH NA ($78) ADC7 ADC6 ADC5 ADC4 ADC3 ADC2 ADC1 ADC0 ADCL 7 6 5 4 3 2 1 0 Read/Write R R R R R R R R R R R R R R R R Initial Value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 27.12.5.2 ADLAR = 1 Bit 15 14 13 12 11 10 9 8 NA ($79) ADC9 ADC8 ADC7 ADC6 ADC5 ADC4 ADC3 ADC2 ADCH NA ($78) ADC1 ADC0 – – – – – – ADCL 7 6 5 4 3 2 1 0 Read/Write R R R R R R R R R R R R R R R R Initial Value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 When an A/D conversion is complete, the result is found in these two registers. If differential channels are used, the result is presented in two’s complement form. When ADCL is read, the ADC Data Register is not updated until ADCH is read. Consequently, if the result is left adjusted and no more than 8-bit precision (7 bit + sign bit for differential input channels) is required, it is sufficient to read ADCH. Otherwise, ADCL must be read first, then ADCH. The ADLAR bit in ADMUX, and the MUXn bits in ADMUX affect the way the result is read from the registers. If ADLAR is set, the result is left adjusted. If ADLAR is cleared (default), the result is right adjusted. • ADC9:0: A/D Conversion Result These bits represent the result from the conversion as detailed in "ADC Conversion Result" on page 458. 27.12.6 DIDR0 – Digital Input Disable Register 0 Bit 7 6 5 4 3 2 1 0 NA ($7E) ADC7D ADC6D ADC5D ADC4D ADC3D ADC2D ADC1D ADC0D DIDR0 Read/Write RW RW RW RW RW RW RW RW Initial Value 0 0 0 0 0 0 0 0 469 8393C-MCU Wireless-09/14

• Bits 7:0 – ADC7D:ADC0D: Digital Input Disable When this bit is written logic one, the digital input buffer on the corresponding ADC pin is disabled. The corresponding PIN Register bit will always read as zero when this bit is set. When an analog signal is applied to the ADC7:0 pin and the digital input from this pin is not needed, this bit should be written logic one to reduce power consumption in the digital input buffer. 27.12.7 DIDR2 – Digital Input Disable Register 2 Bit 7 6 5 4 3 2 1 0 NA ($7D) ADC15D ADC14D ADC13D ADC12D ADC11D ADC10D ADC9D ADC8D DIDR2 Read/Write RW RW RW RW RW RW RW RW Initial Value 0 0 0 0 0 0 0 0 Reserved for future use. • Bit 7:0 – ADC15D:ADC8D - Reserved Bits This bit is reserved for future use. For ensuring compatibility with future devices, this bit must be written to zero. 27.12.8 BGCR – Reference Voltage Calibration Register Bit 7 6 5 4 NA ($67) Res BGCAL_FINE3 BGCAL_FINE2 BGCAL_FINE1 BGCR Read/Write R RW RW RW Initial Value 0 0 0 0 Bit 3 2 1 0 NA ($67) BGCAL_FINE0 BGCAL2 BGCAL1 BGCAL0 BGCR Read/Write RW RW RW RW Initial Value 0 0 0 0 This register contains the calibration values of the reference voltage of the ADC. The values are loaded from the fuse memory after power-up. They can be corrected by the application software e.g. to compensate for temperature changes. The internal 1.6V reference voltage is calibra t ed and has therefore the highest accuracy compared to the 1.5V or AVDD reference. • Bit 7 – Res - Reserved Bit This bit is reserved for future use. A read access always will return zero. A write access does not modify the content. • Bit 6:3 – BGCAL_FINE3:0 - Fine Calibration Bits These bits allow the calibration of the AREF voltage with a resolution of 2mV. Table 27-15 BGCAL_FINE Register Bits Register Bits Value Description BGCAL_FINE3:0 0 Center value 1 Voltage step up 8 Voltage step down ATmega256/128/64RFR2 470 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 Register Bits Value Description 7 Setting for highest voltage 15 Setting for lowest voltage • Bit 2:0 – BGCAL2:0 - Coarse Calibration Bits These bits allow the calibration of the AREF voltage with a resolution of 10mV. Table 27-16 BGCAL Register Bits Register Bits Value Description BGCAL2:0 4 Center value 3 Voltage step up 5 Voltage step down 0 Setting for highest voltage 7 Setting for lowest voltage 471 8393C-MCU Wireless-09/14

28 JTAG Interface and On-chip Debug System 28.1 Features • JTAG (IEEE std. 1149.1 Compliant) Interface • Boundary-scan Capabilities According to the IEEE std. 1149.1 (JTAG) Standard • Debugger Access to: o All Internal Peripheral Units o Internal and External RAM o The Internal Register File–Program Counter o EEPROM and Flash Memories • Extensive on-chip debug Support for Break Conditions, Including o AVR Break Instruction o Break on Change of Program Memory Flow o Single Step Break o Program Memory Breakpoints on Single Address or Address Range o Data Memory Breakpoints on Single Address or Address Range • Programming of Flash, EEPROM, Fuses, and Lock Bits through the JTAG Interface • On-chip debugging Supported by AVR Studio® 28.2 Overview The AVR IEEE std. 1149.1 compliant JTAG interface can be used for • Testing PCBs by using the JTAG Boundary-scan capability • Programming the non-volatile memories, Fuses and Lock bits • On-chip debugging A brief description is given in the following sections. Detailed descriptions for Programming via the JTAG interface, and using the Boundary-scan Chain can be found in the sections "Programming via the JTAG Interface" on page 525 and "Programming via the JTAG Interface" on page 525, respectively. The on-chip debug support is considered being private JTAG instructions, and distributed within ATMEL and to selected third party vendors only. Figure 28-1 on page 473 sh ows a block diagram of the JTAG interface and the on-chip debug system. The TAP Controller is a state machine controlled by the TCK and TMS signals. The TAP Controller selects either the JTAG Instruction Register or one of several Data Registers as the scan chain (Shift Register) between the TDI – input and TDO – output. The Instruction Register holds JTAG instructions controlling the behavior of a Data Register. The ID-Register, Bypass Register, and the Boundary-scan Chain are the Data Registers used for board-level testing. The JTAG Programming Interface (actually consisting of several physical and virtual Data Registers) is used for serial programming via the JTAG interface. The internal scan-chain and breakpoint scan-chain are used for on-chip debugging only. ATmega256/128/64RFR2 472 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 Figure 28-1. Block Diagram I/O PORT 0 DEVICE BOUNDARY BOUNDARY SCAN CHAIN TDI TDO TAP JTAGI NPTREORGFRAACMEMING TCK CONTROLLER TMS AVR CPU INTERNAL INRSETGRUISCTTEIRON MFELMAOSRHY AddDreastas CSHCAAINN PInCstruction ID REGISTER BREAKPOINT UNIT M FLOW CONTROL U BYPASS UNIT X REGISTER PEDRUIIGPNIHITTEASRLAL PEARUNIPNAHILTEOSRGAL Analog inputs BREAKPOINT SCAN CHAIN JTAG / AVR CORE COMMUNICATION DAEDCDORDESESR OCD STATUS INTERFACE AND CONTROL Control & Clock lines I/O PORT n 28.3 TAP - Test Access Port The JTAG interface is acce ssed through four of the AVR’s pins. In JTAG terminology, these pins constitute the Test Access Port – TAP. These pins are: • TMS: Test mode select. This pin is used for navigating through the TAP-controller state machine. • TCK: Test Clock. JTAG operation is synchronous to TCK. • TDI: Test Data In. Serial input data to be shifted in to the Instruction Register or Data Register (Scan Chains). • TDO: Test Data Out. Ser ial output data from Instruction Register or Data Register. The IEEE std. 1149.1 also specifies an optional TAP signal; TRST – Test ReSeT – which is not provided. When the JTAGEN Fuse is un-programmed, these four TAP pins are normal port pins, and the TAP controller is in reset. When programmed the input TAP signals are internally pulled high and the JTAG is enabled for Boundary-scan and programming. The device is shipped with this fuse programmed. For the on-chip debug system, in addition to the JTAG interface pins, the RESET pin is monitored by the debugger to be able to detect external reset sources. The debugger can also pull the RESET pin low to reset the whole system, assuming only open collectors on the reset line are used in the application. 473 8393C-MCU Wireless-09/14

Figure 28-2. TAP Controller State Diagram 1 Test-Logic-Reset 0 0 Run-Test/Idle 1 Select-DR Scan 1 Select-IR Scan 1 0 0 1 1 Capture-DR Capture-IR 0 0 Shift-DR 0 Shift-IR 0 1 1 Exit1-DR 1 Exit1-IR 1 0 0 Pause-DR 0 Pause-IR 0 1 1 0 0 Exit2-DR Exit2-IR 1 1 Update-DR Update-IR 1 0 1 0 28.4 TAP Controller The TAP controller is a 16-state finite state machine that controls the operation of the Boundary-scan circuitry, JTAG programming circuitry, or on-chip debug system. The state transitions depicted in Figure 28-2 above depend on the signal present on TMS (shown adjacent to each state transition) at the time of the rising edge at TCK. The initial state after a Power-on Reset is Test-Logic-Reset. As a definition in this document, the LSB is shifted in and out first for all Shift Registers. Assuming Run-Test/Idle is the present state, a typical scenario for using the JTAG interface is: • At the TMS input, apply the sequence 1, 1, 0, 0 at the rising edges of TCK to enter the Shift Instruction Register – Shift-IR state. While in this state, shift the four bits of the JTAG instructions into the JTAG Instruction Register from the TDI input at the rising edge of TCK. The TMS input must be held low during input of the 3 LSBs in order to remain in the Shift-IR state. The MSB of the instruction is shifted in when this state is left by setting TMS high. While the instruction is shifted in from the TDI pin, the captured IR-state 0x01 is shifted out on the TDO pin. The JTAG Instruction ATmega256/128/64RFR2 474 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 selects a particular Data Register as path between TDI and TDO and controls the circuitry surrounding the selected Data Register. • Apply the TMS sequence 1, 1, 0 to re-enter the Run-Test/Idle state. The instruction is latched onto the parallel output from the Shift Register path in the Update-IR state. The Exit-IR, Pause-IR, and Exit2-IR states are only used for navigating the state machine. • At the TMS input, apply the sequence 1, 0, 0 at the rising edges of TCK to enter the Shift Data Register – Shift-DR state. While in this state, upload the selected Data Register (selected by the present JTAG instruction in the JTAG Instruction Register) from the TDI input at the rising edge of TCK. In order to remain in the Shift-DR state, the TMS input must be held low during input of all bits except the MSB. The MSB of the data is shifted in when this state is left by setting TMS high. While the Data Register is shifted in from the TDI pin, the parallel inputs to the Data Register captured in the Capture-DR state is shifted out on the TDO pin. • Apply the TMS sequence 1, 1, 0 to re-enter the Run-Test/Idle state. If the selected Data Register has a latched parallel-output, the latching takes place in the Update- DR state. The Exit-DR, Pause-DR, and Exit2-DR states are only used for navigating the state machine. As shown in the state diagram, the Run-Test/Idle state need not be entered between selecting JTAG instruction and using Data Registers, and some JTAG instructions may select certain functions to be performed in the Run-Test/Idle, making it unsuitable as an Idle state. Note that independent of the initial state of the TAP Controller, the Test-Logic-Reset state can always be entered by holding TMS high for five TCK clock periods. For detailed information on the JTAG specification, refer to the literature listed in "Bibliography" on page 477. 28.5 Using the Boundary-scan Chain A complete description of the Boundary-scan capabilities are given in the section "IEEE 1149.1 (JTAG) Boundary-sc an" on page 478. 28.6 Using the On-chip Debug System The on-chip debug system must be disabled for the best RF performance of the radio transceiver. As shown in Figure 28-1, the hardware support for on-chip debugging consists mainly of • A scan chain on the interface between the internal AVR CPU and the internal peripheral units. • Breakpoint unit. • Communication interface between the CPU and JTAG system. All read or modify/write operations needed for implementing the debugger are done by applying AVR instructions via the internal AVR CPU Scan Chain. The CPU sends the result to an I/O memory mapped location which is part of the communication interface between the CPU and the JTAG system. The Breakpoint Unit implements Break on Change of Program Flow, Single Step Break, two program memory breakpoints and two combined breakpoints. Together, the four breakpoints can be configured as either: • 4 single program memory breakpoints; • 3 single program memory breakpoint + 1 single data memory breakpoint; • 2 single program memory breakpoints + 2 single data memory breakpoints; 475 8393C-MCU Wireless-09/14

• 2 single program memory breakpoints + 1 program memory breakpoint with mask (“range breakpoint”). • 2 single program memory breakpoints + 1 data memory breakpoint with mask (“range breakpoint”). A debugger, like the AVR Studio, may however use one or more of these resources for its internal purpose, leaving less flexibility to the end-user. A list of the on-chip debug specific JTAG instructions is given in "On-chip Debug Specific JTAG Instructions" below. The JTAGEN Fuse must be programmed to enable the JTAG Test Access Port. In addition, the OCDEN Fuse must be programmed and no Lock bits must be set for the on-chip debug system to work. As a security feature, the on-chip debug system is disabled when either of the LB1 or LB2 Lock-bits are set. Otherwise, the on-chip debug system would have provided a back-door into a secured device. The AVR Studio enables the user to fully control execution of programs on an AVR device with on-chip debug capability, AVR In-Circuit Emulator, or the built-in AVR Instruction Set Simulator. AVR Studio supports source level execution of Assembly programs assembled with Atmel Corporation’s AVR Assembler and C programs compiled with third party vendors’ compilers. For a full description of the AVR Studio, please refer to the AVR Studio User Guide. Only highlights are presented in this document. All necessary execution commands are available in AVR Studio, both on source level and on disassembly level. The user can execute the program, single step through the code either by tracing into or stepping over functions, step out of functions, place the cursor on a statement and execute until the statement is reached, stop the execution, and reset the execution target. In addition, the user can have an unlimited number of code breakpoints (using the BREAK instruction) and up to two data memory Breakpoints, alternatively combined as a mask (range) breakpoint. 28.7 On-chip Debug Specific JTAG Instructions The on-chip debug support is considered being private JTAG instructions, and distributed within ATMEL and to selected third party vendors only. Instruction operation codes are listed for reference. 28.7.1 PRIVATE0; 0x8 Private JTAG instruction for accessing on-chip debug system; 28.7.2 PRIVATE1; 0x9 Private JTAG instruction for accessing on-chip debug system; 28.7.3 PRIVATE2; 0xA Private JTAG instruction for accessing on-chip debug system; 28.7.4 PRIVATE3; 0xB Private JTAG instruction for accessing on-chip debug system; 28.8 Using the JTAG Programming Capabilities Programming of the ATmega256/128/64RFR2 via JTAG is performed via the 4-pin JTAG port, TCK, TMS, TDI, and TDO. These are the only pins that need to be controlled and observed to perform JTAG programming (in addition to power pins). The JTAGEN Fuse must be programmed and the JTD bit in the MCUCR Register must be cleared to enable the JTAG Test Access Port. ATmega256/128/64RFR2 476 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 The JTAG programming capability supports: • Flash programming and verifying. • EEPROM programming and verifying. • Fuse programming and v erifying. • Lock bit programming and verifying. The Lock bit security is exactly as in parallel programming mode. If the Lock bits LB1 or LB2 are programmed, the OCDEN Fuse cannot be programmed unless first doing a chip erase. This is a security feature that ensures no back-door exists for reading out the content of a secured device. The details on programming through the JTAG interface and programming specific JTAG instructions are given in the section "Programming via the JTAG Interface" on page 525. 28.9 Bibliography For more information about general Boundary-scan, the following literature can be consulted: • IEEE: IEEE Std. 1149.1-1990. IEEE Standard Test Access Port and Boundary-scan Architecture, IEEE, 1993. • Colin Maunder: The Board Designers Guide to Testable Logic Circuits, Addison- Wesley, 1992. 28.10 On-chip Debug Related Register in I/O Memory 28.10.1 OCDR – On-Chip Debug Register Bit 7 6 5 4 3 2 1 0 $31 ($51) OCDR7:0 OCDR Read/Write RW RW RW RW RW RW RW RW Initial Value 0 0 0 0 0 0 0 0 The OCDR Register provides a communication channel from the running program in the microcontroller to the debugger. The CPU can transfer a byte to the debugger by writing to this location. At the same time, an internal flag; I/O Debug Register Dirty IDRD is set to indicate to the debugger that the register has been written. When the CPU reads the OCDR Register the 7 LSB will be from the OCDR Register, while the MSB is the IDRD bit. The debugger clears the IDRD bit when it has read the information. In some AVR devices, this register is shared with a standard I/O location. In this case, the OCDR Register can only be accessed if the OCDEN Fuse is programmed, and the debugger enables access to the OCDR Register. In all other cases, the standard I/O location is accessed. • Bit 7:0 – OCDR7:0 - On-Chip Debug Register Data Table 28-17 OCDR Register Bits Register Bits Value Description OCDR7:0 0 Refer to the debugger documentation for further information on how to use this register. 477 8393C-MCU Wireless-09/14

29 IEEE 1149.1 (JTAG) Boundary-scan 29.1 Features • JTAG (IEEE std. 1149.1 compliant) Interface • Boundary-scan Capabilities According to the JTAG Standard • Full Scan of all Port Functions as well as Analog Circuitry having Off-chip Connections • Supports the Optional IDCODE Instruction • Additional Public AVR_RESET Instruction to Reset the ATmega256/128/64RFR2 29.2 System Overview The Boundary-scan chain has the capability of driving and observing the logic levels on the digital I/O pins, as well as the boundary between digital and analog logic for analog circuitry having off-chip connections. At system level, all ICs having JTAG capabilities are connected serially by the TDI/TDO signals to form a long Shift Register. An external controller sets up the devices to drive values at their output pins, and observe the input values received from other devices. The controller compares the received data with the expected result. In this way, Boundary-scan provides a mechanism for testing interconnections and integrity of components on Printed Circuits Boards by using the four TAP signals only. The four IEEE 1149.1 defined mandatory JTAG instructions IDCODE, BYPASS, SAMPLE/PRELOAD, and E XTEST, as well as the AVR specific public JTAG instruction AVR_RESET can be used for testing the Printed Circuit Board. Initial scanning of the Data Register path will show the ID-Code of the device, since IDCODE is the default JTAG instruction. It may be desirable to have the AVR device in reset during test mode. If not reset, inputs to the device may be determined by the scan operations, and the internal software may be in an undetermined state when exiting the test mode. Entering reset, the outputs of any port pin will instantly enter the high impedance state, making the HIGHZ instruction redundant. If needed, the BYPASS instruction can be issued to make the shortest possible scan chain through the device. The device can be set in the reset state either by pulling the external RESET pin low, or issuing the AVR_RESET instruction with appropriate setting of the Reset Data Register. The EXTEST instruction is used for sampling external pins and loading output pins with data. The data from the output latch will be driven out on the pins as soon as the EXTEST instruction is loaded into the JTAG IR-Register. Therefore, the SAMPLE/PRELOAD should also be used for setting initial values to the scan ring, to avoid damaging the board when issuing the EXTEST instruction for the first time. SAMPLE/PRELOAD can also be used for taking a snapshot of the external pins during normal operation of the part. The JTAGEN Fuse must be programmed and the JTD bit in the I/O Register MCUCR must be cleared to enable the JTAG Test Access Port. When using the JTAG interface for Boundary-scan, using a JTAG TCK clock frequency higher than the internal chip frequency is possible. The chip clock is not required to run. 29.3 Data Registers The Data Registers relevant for Boundary-scan operations are: • Bypass Register ATmega256/128/64RFR2 478 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 • Device Identification Register • Reset Register • Boundary-scan Chain 29.3.1 Bypass Register The Bypass Register consists of a single Shift Register stage. When the Bypass Register is selected as path between TDI and TDO, the register is reset to 0 when leaving the Capture-DR controller state. The Bypass Register can be used to shorten the scan chain on a system when the other devices are to be tested. 29.3.2 Device Identification Register Figure 29-1. The Format of the Device Identification Register MSB LSB Bit 31 28 27 12 11 1 0 Device ID Version Part Number Manufacturer ID 1 4 bits 16 bits 11 bits 1 bit 29.3.2.1 Version Version is a 4-bit number identifying the revision of the component. The JTAG version number follows the revision of the device. Revision A is 0x0, revision B is 0x1 and so on. 29.3.2.2 Part Number The part number is a 16-bit code identifying the component. The JTAG Part Number for ATmega256/128/64RFR2 is listed in Table 31-6 on page 507. 29.3.2.3 Manufacturer ID The Manufacturer ID is a 11-bit code identifying the manufacturer. The JTAG manufacturer ID for ATMEL is listed in Table 31-6 on page 507. 29.3.3 Reset Register The Reset Register is a test Data Register used to reset the part. Since the AVR tri- states Port Pins when reset, the Reset Register can also replace the function of the unimplemented optional JTAG instruction HIGHZ. A high value in the Reset Register corresponds to pulling the external Reset low. The part is reset as long as there is a high value present in the Reset Register. Depending on the fuse settings for the clock options, the part will remain reset for a reset time-out period (see "Clock Sources" on page 177) after releasing the Reset Register. The output from this Data Register is not latched, so the reset will take place immediately, as shown in Figure 29-2 on page 480. 479 8393C-MCU Wireless-09/14

Figure 29-2. Reset Register To (cid:13) TDO From Other Internal and(cid:13) External Reset Sources From(cid:13) Internal reset D Q TDI ClockDR · AVR_RESET 29.3.4 Boundary-scan Chain The Boundary-scan Chain has the capability of driving and observing the logic levels on the digital I/O pins, as well as the boundary between digital and analog logic for analog circuitry having off-chip connections. See "Boundary-scan Chain" on page 481 for a complete description. 29.4 Boundary-scan Specific JTAG Instructions The Instruction Register is 4-bit wide, supporting up to 16 instructions. Listed below are the JTAG instructions useful for Boundary-scan operation. Note that the optional HIGHZ instruction is not implement ed, but all outputs with tri-state capability can be set in high- impedance state by using the AVR_RESET instruction, since the initial state for all port pins is tri-state. As a definition in this datasheet, the LSB is shifted in and out first for all Shift Registers. The OPCODE for each instruction is shown behind the instruction name in hex format. The text describes which Data Register is selected as path between TDI and TDO for each instruction. 29.4.1 EXTEST; 0x0 Mandatory JTAG instruction for selecting the Boundary-scan Chain as Data Register for testing circuitry external to the AVR package. For port-pins, Pull-up Disable, Output Control, Output Data, and Input Data are all accessible in the scan chain. For Analog circuits having off-chip connections, the interface between the analog and the digital logic is in the scan chain. The contents of the latched outputs of the Boundary-scan chain is driven out as soon as the JTAG IR-Register is loaded with the EXTEST instruction. The active states are: • Capture-DR: Data on the external pins are sampled into the Boundary-scan Chain. • Shift-DR: The Internal Scan Chain is shifted by the TCK input. • Update-DR: Data from the scan chain is applied to output pins. 29.4.2 IDCODE; 0x1 Optional JTAG instruction selecting the 32 bit ID-Register as Data Register. The ID- Register consists of a version number, a device number and the manufacturer code chosen by JEDEC. This is the default instruction after power-up. ATmega256/128/64RFR2 480 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 The active states are: • Capture-DR: Data in the IDCODE Register is sampled into the Boundary-scan Chain. • Shift-DR: The IDCODE s can chain is shifted by the TCK input. 29.4.3 SAMPLE_PRELOAD; 0x2 Mandatory JTAG instruction for pre-loading the output latches and taking a snap-shot of the input/output pins without affecting the system operation. However, the output latches are not connected to the pins. The Boundary-scan Chain is selected as Data Register. The active states are: • Capture-DR: Data on the external pins are sampled into the Boundary-scan Chain. • Shift-DR: The Boundary-scan Chain is shifted by the TCK input. • Update-DR: Data from the Boundary-scan chain is applied to the output latches. However, the output latches are not connected to the pins. 29.4.4 AVR_RESET; 0xC The AVR specific public JTAG instruction for forcing the AVR device into the Reset mode or releasing the JTAG reset source. The TAP controller is not reset by this instruction. The one bit Reset Register is selected as Data Register. Note that the reset will be active as long as there is a logic “one” in the Reset Chain. The output from this chain is not latched. The active states are: • Shift-DR: The Reset Register is shifted by the TCK input. 29.4.5 BYPASS; 0xF Mandatory JTAG instruction selecting the Bypass Register for Data Register. The active states are: • Capture-DR: Loads a logic “0” into the Bypass Register. • Shift-DR: The Bypass Register cell between TDI and TDO is shifted. 29.5 Boundary-scan Chain The Boundary-scan chain has the capability of driving and observing the logic levels on the digital I/O pins, as well a s the boundary between digital and analog logic for analog circuitry having off-chip connection. 29.5.1 Scanning the Digital Port Pins Figure 29-3 on page 482 shows the Boundary-scan Cell for a bi-directional port pin. The pull-up function is disabled during Boundary-scan when the JTAG IC contains EXTEST or SAMPLE_PRELOAD. The cell consists of a bi-directional pin cell that combines the three signals Output Control - OCxn, Output Data - ODxn, and Input Data - IDxn, into only a two-stage Shift Register. The port and pin indexes are not used in the following description. The Boundary-scan logic is not included in the figures in the datasheet. Figure 29-4 on page 483 shows a simple digital port pin as described in the section "I/O-Ports" on page 219. The Boundary-scan details from Figure 29-3 on page 482 replaces the dashed box in Figure 29-4 on page 483. 481 8393C-MCU Wireless-09/14

When no alternate port function is present, the Input Data - ID - corresponds to the PINxn Register value (but ID has no synchronizer), Output Data corresponds to the PORT Register, Output Control corresponds to the Data Direction - DD Register, and the Pull-up Enable - PUExn – corresponds to logic expression: PUD⋅DDxn⋅PORTxn Digital alternate port functions are connected outside the dotted box Figure 29-4 on page 483 to make the scan chain read the actual pin value. For analog function, there is a direct connection from the external pin to the analog circuit. There is no scan chain on the interface between the digital and the analog circuitry, but some digital control signal to analog circuitry are turned off to avoid driving contention on the pads. When JTAG IR contains EX TEST or SAMPLE_PRELOAD the clock is not sent out on the port pins even if the CKOUT fuse is programmed. Even though the clock is output when the JTAG IR contains SAMPLE_PRELOAD, the clock is not sampled by the boundary scan. Figure 29-3. Boundary-scan Cell for Bi-directional Port Pin with Pull-up Function ATmega256/128/64RFR2 482 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 Figure 29-4. General Port Pin Schematic Diagram See Boundary-scan Description for Details! PUExn PUD Q D DDxn QCLR WDx RESET OCxn RDx S U B Pxn ODxn QPORTxDn TA IDxn QCLR WRx DA RESET SLEEP RRx SYNCHRONIZER RPx D Q D Q PINxn L Q Q CLKI/O PUD: PULLUP DISABLE WDx: WRITE DDRx PUExn: PULLUP ENABLE for pin Pxn RDx: READ DDRx OCxn: OUTPUT CONTROL for pin Pxn WRx: WRITE PORTx ODxn: OUTPUT DATA to pin Pxn RRx: READ PORTx REGISTER IDxn: INPUT DATA from pin Pxn RPx: READ PORTx PIN SLEEP: SLEEP CONTROL CLK I / O : I/O CLOCK 29.5.2 Scanning the RSTN, CLKI and TST Pin An observe-only cell as shown in Figure 29-5 below is inserted for the active low reset signal RSTN, for the active high programming and test mode enable signal TST and for the clock input CLKI. Figure 29-5. Observe-only Cell To(cid:13) Next(cid:13) ShiftDR Cell From System Pin To System Logic FF1 0 D Q 1 From(cid:13) ClockDR Previous(cid:13) Cell 483 8393C-MCU Wireless-09/14

29.5.3 Scanning the RSTON Pin For the low-active reset output pin RSTON a boundary-scan cell as shown in Figure 29-6 below is inserted. Figure 29-6. Boundary-scan Cell for Output Pins without Pull-up Function 29.6 Boundary-scan Related Register in I/O Memory For detailed register description see chapter "MCUCR – MCU Control Register" on page 249 and "MCUSR – MCU Status Register" on page 216. 29.6.1 MCUCR – MCU Control Register Bit 7 6 5 4 3 2 1 0 $35 ($55) JTD MCUCR Read/Write RW Initial Value 0 The MCU Control Register contains control bits for general Microcontroller Unit functions. • Bit 7 – JTD - JTAG Interface Disable When this bit is zero, the JTAG interface is enabled if the JTAGEN Fuse is programmed. If this bit is one, the JTAG interface is disabled. In order to avoid unintentional disabling or enabling of the JTAG interface, a timed sequence must be followed when changing this bit: The application software must write this bit to the desired value twice within four cycles to change its value. Note that this bit must not be altered when using the On-chip Debug system. 29.6.2 MCUSR – MCU Status Register Bit 7 6 5 4 3 2 1 0 $34 ($54) JTRF MCUSR Read/Write RW Initial Value 0 ATmega256/128/64RFR2 484 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 The MCU Status Register provides information on which reset source caused an MCU reset. • Bit 4 – JTRF - JTAG Reset Flag This bit is set if a reset is being caused by a logic one in the JTAG Reset Register selected by the JTAG instruction AVR_RESET. This bit is reset by a Power-on Reset, or by writing a logic zero to the flag. 29.7 Boundary-scan Description Language Files Boundary-scan Description Language (BSDL) files describe Boundary-scan capable devices in a standard form at used by automated test-generation software. The order and function of bits in the Boundary-scan Data Register are included in this description. BSDL files are available for ATmega256/128/64RFR2. 29.8 ATmega256/128/64RFR2 Boundary-scan Order Table 29-1 on page 486 shows the Scan order between TDI and TDO when the Boundary-scan chain is selected as data path. Bit 0 is the LSB; the first bit scanned in, and the first bit scanned out. The scan order follows the pin-out order. In Figure 29-3 on page 482, PXn. Data corresponds to FF0, PXn. Control corresponds to FF1, PXn. Bit 4, 5, 6 and 7 of Port F is not in the scan chain, since these pins constitute the TAP pins when the JTAG is enabled. 485 8393C-MCU Wireless-09/14

Table 29-1. ATmega256/128/64RFR2 Boundary-Scan Order Bit Bit Number Signal Name Module Number Signal Name Module 0 PF1.Control 36 CLKI.Data Clock Input (Input Only) 1 PF1.Data 37 PD7.Control Port F 2 PF0.Control 38 PD7.Data 3 PF0.Data 39 PD6.Control 4 PE7.Control 40 PD6.Data 5 PE7.Data 41 PD5.Control 6 PE6.Control 42 PD5.Data 7 PE6.Data 43 PD4.Control 8 PE5.Control 44 PD4.Data Port D 9 PE5.Data 45 PD3.Control 10 PE4.Control 46 PD3.Data 11 PE4.Data 47 PD2.Control Port E 12 PE3.Control 48 PD2.Data 13 PE3.Data 49 PD1.Control 14 PE2.Control 50 PD1.Data 15 PE2.Data 51 PD0.Control 16 PE1.Control 52 PD0.Data 17 PE1.Data 53 PG5.Control 18 PE0.Control 54 PG5.Data 19 PE0.Data 55 PG4.Control 20 PB7.Control 56 PG4.Data 21 PB7.Data 57 PG3.Control 22 PB6.Control 58 PG3.Data Port G 23 PB6.Data 59 PG2.Control 24 PB5.Control 60 PG2.Data 25 PB5.Data 61 PG1.Control 26 PB4.Control 62 PG1.Data 27 PB4.Data 63 PG0.Control 28 PB3.Control 64 PG0.Data Port B Reset Logic Output (Output Only 29 PB3.Data 65 RSTON.Data without Pull-up) 30 PB2.Control 66 RSTT.Data Reset Logic (Observe Only) Test and Programming Mode 31 PB2.Data 67 TST.Data Enable (Observe Only) 32 PB1.Control 68 PF3.Control 33 PB1.Data 69 PF3.Data Port F 34 PB0.Control 70 PF2.Control 35 PB0.Data 71 PF2.Data ATmega256/128/64RFR2 486 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 30 Boot Loader Support – Read-While-Write Self-Programming The Boot Loader Support provides a real Read-While-Write Self-Programming mechanism for downloading and uploading program code by the MCU itself. This feature allows flexible appl ication software updates controlled by the MCU using a Flash-resident Boot Loader program. The Boot Loader program can use any available data interface and associated protocol to read code and write that (program) code into the Flash memory, or read the code from the program memory. The program code within the Boot Loader section has the capability to write into the entire Flash, including the Boot Loader memory. The Boot Loader can thus even modify itself (including erasing) from the code if the feature is not needed anymore. The size of the Boot Loader memory is configurable with fuses and the Boot Loader has two separate sets of Boot Lock bits which can be set independently. This gives the user a unique flexibility to select different levels of protection. 30.1 Features • Read-While-Write Self-Programming • Flexible Boot Memory S ize • High Security (Separate Boot Lock Bits for a Flexible Protection) • Separate Fuse to Select Reset Vector • Optimized Page(1) Size • Code Efficient Algorithm • Efficient Read-Modify-Write Support Note: 1. A page is a section in the Flash consisting of several bytes (see "Table 31-7" on page 507) used dur ing programming. The page organization does not affect normal operation. 30.2 Application and Boot Loader Flash Sections The Flash memory is organized in two main sections: the Application section and the Boot Loader section (see Figure 30-2 on page 489). The size of the different sections is configured by the BOOTSZ Fuses as shown in Table 30-7 on page 499 and Figure 30-2 on page 489. These two sections can have different level of protection since they have different sets of Lock bits. 30.2.1 Application Section The Application section is the region of the Flash that is used for storing the application code. The protection level fo r the Application section can be selected by the application Boot Lock bits (Boot Lock bits 0, BLB0), see Table 31-2 on page 504. The Application section can never store any Boot Loader code since the SPM instruction is disabled when executed from the Application section. 30.2.2 BLS – Boot Loader Section While the Application section is used for storing the application code, the Boot Loader software must be located in the BLS. The SPM instruction can only initiate programming when executed from the BLS. The SPM instruction can access the entire Flash, including the BLS itself. The protection level for the Boot Loader section can be selected by the Boot Loader Lock bits (Boot Lock bits 1, BLB1), see Table 31-2 on page 504. 487 8393C-MCU Wireless-09/14

30.3 Read-While-Write and No Read-While-Write Flash Sections Whether the CPU supports Read-While-Write or if the CPU is halted during a Boot Loader software update is dependent on the address that is being programmed. In addition to the two sections that are configurable by the BOOTSZ Fuses as described above, the Flash is also divided into two fixed sections, the Read-While-Write (RWW) section and the No Read-While-Write (NRWW) section. The limit between the RWW- and NRWW sections is given in Table 30-1 on page 489 and Figure 30-1 below. The main differences between the two sections are: • When erasing or writing a page located inside the RWW section, the NRWW section can be read during the operation. • When erasing or writing a page located inside the NRWW section, the CPU is halted during the entire operation. Note that the user software can never read any code that is located inside the RWW section during a Boot Loader software operation. The syntax “Read-While-Write section” refers to the section that is being programmed (erased or written) and not to the section that actually is being read during a Boot Loader software update. Figure 30-1. Read-While-Write vs. No Read-While-Write Read-While-Write(cid:13) (RWW) Section(cid:13) (cid:13) (cid:13) Z-pointer(cid:13) Addresses NRWW(cid:13) Section Z-pointer(cid:13) Addresses RWW(cid:13) No Read-While-Write (cid:13) Section (NR(cid:13)WW) Section(cid:13) (cid:13) (cid:13) CPU is Halted(cid:13) During the Operation Code Located in (cid:13) NRWW Section(cid:13) Can be Read During(cid:13) the Operation 30.3.1 RWW – Read-While-Write Section If a Boot Loader software update is programming a page inside the RWW section, it is possible to read code from the Flash, but only code that is located in the NRWW section. During an ongoing programming, the software must ensure that the RWW section never is being read. If the user software is trying to read code that is located inside the RWW section (i.e., by load program memory, call, or jump instructions or an interrupt) during programming, the software might end up in an unknown state. To avoid this, the interrupts should either be disabled or moved to the Boot Loader section. The Boot Loader section is always located in the NRWW section. The RWW Section Busy bit (RWWSB) in the Store Program Memory Control and Status Register (SPMCSR) will be read as logical one as long as the RWW section is blocked for reading. After a ATmega256/128/64RFR2 488 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 programming is completed, the RWWSB must be cleared by software before reading code located in the RWW section. See "SPMCSR – Store Program Memory Control Register" on page 501 for details on how to clear RWWSB. 30.3.2 NRWW – No Read-While-Write Section The code located in the NRWW section can be read when the Boot Loader software is updating a page in the RWW section. When the Boot Loader code updates the NRWW section, the CPU is halted during the entire Page Erase or Page Write operation. Table 30-1. Read-While-Write Features Which Section does the Z-pointer Which Section can be Read Read-While-Write Address during the Programming? during Programming? CPU Halted? Supported? RWW Section NRWW Section No Yes NRWW Section None Yes No Figure 30-2. Memory Sections Program Memory(cid:13) Program Memory(cid:13) BOOTSZ = '11' BOOTSZ = '10' 0x0000 0x0000 Section Section Write Application Flash Section Write Application Flash Section While- While- Read- Read- Section (cid:13)ESntadr tR NWRWWW Section ESntadr tR NWRWWW Write Application Flash Section Write Application Flash Section Read-While- Boot Lo(cid:13)ad(cid:13)er Flash Section FESlntaadsr thA Bepnopdolitc Laotioander Read-While- Boot Lo(cid:13)a(cid:13)der Flash Section ESFlntaadsr thA Bepnopdolitc Laotioander No No Program Memory(cid:13) Program Memory(cid:13) BOOTSZ = '01' BOOTSZ = '00' 0x0000 0x0000 n n o o ecti ecti S S Write Application Flash Section Write Application Flash Section e- e- hil hil W W d- d- a a e e R R n End RWW n End RWW, End Application ectio Start NRWW ectio Start NRWW, Start Boot Loader(cid:13) e S Application Flash Section e S While-Writ Boot Loa(cid:13)der Flash Section ESntadr tA Bpopolitc Laotioander While-Writ Boot Lo(cid:13)a(cid:13)der Flash Section d- (cid:13) d- a a Re Flashend Re Flashend o o N N Note: 1. The parameters in the figure above are given in Table 30-7 on page 499. 489 8393C-MCU Wireless-09/14

30.4 Boot Loader Lock Bits If no Boot Loader capability is needed, the entire Flash is available for application code. The Boot Loader has two separate sets of Boot Lock bits which can be set independently. This gives the user a unique flexibility to select different levels of protection. The user can select: • To protect the entire Flash from a software update by the MCU. • To protect only the Boot Loader Flash section from a software update by the MCU. • To protect only the Application Flash section from a software update by the MCU. • Allow software update in the entire Flash. See Table 31-2 on page 504 for further details. The Boot Lock bits can be set in software and in Serial or Parallel Programming mode, but they can be cleared by a Chip Erase command only. The general Write Lock (Lock Bit mode 2) does not control the programming of the Flash memory by SPM instruction. Similarly, the general Read/Write Lock (Lock Bit mode 1) does not control reading nor writing by (E)LPM/SPM, if it is attempted. 30.4.1 Entering the Boot Loader Program Entering the Boot Loader takes place by a jump or call from the application program. This may be initiated by a trigger such as a command received via USART, or SPI interface. Alternatively, the Boot Reset Fuse can be programmed so that the Reset Vector is pointing to the Boot Flash start address after a reset. In this case, the Boot Loader is started after a reset. After the application code is loaded, the program can start executing the application code. Note that the fuses cannot be changed by the MCU itself. This means that once the Boot Reset Fuse is programmed, the Reset Vector will always point to the Boot Loader Reset and the fuse can only be changed through the serial or parallel programming interface. Table 30-2. Boot Reset Fuse(1) BOOTRST Reset Address 1 Reset Vector = Application Reset (address 0x0000) 0 Reset Vector = Boot Loader Reset (see Table 30-7 on page 499) Note: 1. “1” means unprogrammed, “0” means programmed 30.5 Addressing the Flash During Self-Programming The Z-pointer is used to address the SPM commands. The Z pointer consists of the Z- registers ZL and ZH in the register file, and RAMPZ in the I/O space. The number of bits actually used is implementation dependent. Note that the RAMPZ register is only implemented when the program space is larger than 64K bytes. Bit 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 RAMPZ RAMPZ1 RAMPZ0 ZH (R31) Z15 Z14 Z13 Z12 Z11 Z10 Z9 Z8 ZL (R30) Z7 Z6 Z5 Z4 Z3 Z2 Z1 Z0 7 6 5 4 3 2 1 0 ATmega256/128/64RFR2 490 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 Since the Flash is organized in pages (see "Table 31-7" on page 507), the Program Counter can be treated as having two different sections. One section, consisting of the least significant bits, is addressing the words within a page, while the most significant bits are addressing the pages. This is shown in Figure 30-3 below. Note that the Page Erase and Page Write opera tions are addressed independently. Therefore it is of major importance that the Boot Loader software addresses the same page in both the Page Erase and Page Write operation. Once a programming operation is initiated, the address is latched and the Z-pointer can be used for other operations. The (E)LPM instruction uses the Z-pointer to store the address. Since this instruction addresses the Flash byte-by-byte, also bit Z0 of the Z-pointer is used. Figure 30-3. Addressing the Flash during SPM BIT 15 ZPCMSB ZPAGEMSB 1 0 Z - REGISTER 0 PCMSB PAGEMSB PROGRAM(cid:13) PCPAGE PCWORD COUNTER PAGE ADDRESS(cid:13) WORD ADDRESS(cid:13) WITHIN THE FLASH WITHIN A PAGE PROGRAM MEMORY PAGE PCWORD[PAGEMSB:0]: PAGE INSTRUCTION WORD 00 01 02 PAGEEND Note: 1. The different variables used in Figure 30-3 above are listed in Table 30-6 on page 498. 30.6 Self-Programming the Flash The program memory is updated in a page by page fashion. Before programming a page with the data stored in the temporary page buffer, the page must be erased. The temporary page buffer is filled one word at a time using SPM. The buffer must be filled before the Page Write command. Required sequence for self-p rogramming the Flash: • Perform a Page Erase, • Fill temporary page buffer, • Perform a Page Write; If only a part of the page needs to be changed, the rest of the page must be stored before the erase, and then be rewritten. The temporary page buffer can be accessed in a random sequence. It is essential that the page address used in both the Page Erase 491 8393C-MCU Wireless-09/14

and Page Write operation is addressing the same page. For an assembly code example see "Simple Assembly Code Example for a Boot Loader" on page 496. 30.6.1 Performing Page Erase by SPM To execute Page Erase, set up the address in the Z-pointer, write “X0000011” to SPMCSR and execute SPM within four clock cycles after writing SPMCSR. The data in R1 and R0 is ignored. The page address must be written to PCPAGE in the Z-register. Other bits in the Z-pointer will be ignored during this operation. • Page Erase to the RWW section: The NRWW section can be read during the Page Erase. • Page Erase to the NRWW section: The CPU is halted during the operation. 30.6.2 Filling the Temporary Buffer (Page Loading) To write an instruction word, set up the address in the Z-pointer and data in R1:R0, write “00000001” to SPMCSR and execute SPM within four clock cycles after writing SPMCSR. The content of PCWORD in the Z-register is used to address the data in the temporary buffer. The temporary buffer will be auto-erased after a Page Write operation or by writing the RWWSRE bit in SPMCSR. It is also erased after a system reset. Note that it is not possible to write more than one time to each address without erasing the temporary buffer. If the EEPROM is written in the middle of an SPM Page Load operation, all data loaded is still buffered. 30.6.3 Performing a Page Write To execute Page Write, set up the address in the Z-pointer, write “X0000101” to SPMCSR and execute SPM within four clock cycles after writing SPMCSR. The data in R1 and R0 is ignored. The page address must be written to PCPAGE. Other bits in the Z-pointer must be written to zero during this operation. • Page Write to the RWW section: The NRWW section can be read during the Page Write. • Page Write to the NRWW section: The CPU is halted during the operation. 30.6.4 Using the SPM Interrupt If the SPM interrupt is enabled, the SPM interrupt will generate a constant interrupt when the SPMEN bit in SPMCSR is cleared. This means that the interrupt can be used instead of polling the SPMCSR Register in software. When using the SPM interrupt, the Interrupt Vectors should be moved to the BLS section to avoid that an interrupt is accessing the RWW section when it is blocked for reading. How to move the interrupts is described in "Interrupts" on page 243. 30.6.5 Consideration While Updating BLS Special care must be taken if the user allows the Boot Loader section to be updated by leaving Boot Lock bit11 un-programmed. An accidental write to the Boot Loader itself can corrupt the entire Boot Loader, and further software updates might be impossible. If it is not necessary to change the Boot Loader software itself, it is recommended to program the Boot Lock bit11 to protect the Boot Loader software from any internal software changes. ATmega256/128/64RFR2 492 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 30.6.6 Prevent Reading the RWW Section During Self-Programming During Self-Programming (either Page Erase or Page Write), the RWW section is always blocked for reading. The user software itself must prevent that this section is addressed during the self programming operation. The RWWSB in the SPMCSR will be set as long as the RWW section is busy. During Self-Programming the Interrupt Vector table should be moved to the BLS as described in "Interrupts" on page 243, or the interrupts must be disabled. Before addressing the RWW section after the programming is completed, the user software must clear the RWWSB by writing the RWWSRE. See "Simple Assembly Code Example for a Boot Loader" on page 496 for an example. 30.6.7 Setting the Boot Loader Lock Bits by SPM To set the Boot Loader Loc k bits and general Lock bits, write the desired data to R0, write “X0001001” to SPMCSR and execute SPM within four clock cycles after writing SPMCSR. Bit 7 6 5 4 3 2 1 0 R0 1 1 BLB12 BLB11 BLB02 BLB01 LB2 LB1 See Table 31-2 on page 504 for how the different settings of the Boot Loader bits affect the Flash access. If bits 5:0 in R0 are cleared (zero), the corresponding Lock bit will be programmed if an SPM instruction is executed within four cycles after BLBSET and SPMEN are set in SPMCSR. The Z-pointer is don’t care during this operation, but for future compatibility it is recommended to load the Z-pointer with 0x0001 (same as used for reading the Lock bits). For future compatibility it is also recommended to set bits 7 and 6 in R0 to “1” when writing the Lock bits. When programming the Lock bits the entire Flash can be read during the operation. 30.6.8 EEPROM Write Prevents Writing to SPMCSR Note that an EEPROM write operation will block all software programming to Flash. Reading the Signature Row , Fuses and Lock bits from software will also be prevented during the EEPROM write operation. It is recommended that the user checks the status bit (EEPE) in the EECR Register and verifies that the bit is cleared before writing to the SPMCSR Register. 30.6.9 Reading the Fuse and Lock Bits from Software It is possible to read both the Fuse and Lock bits from software. To read the Lock bits, load the Z-pointer with 0x0001 and set the BLBSET and SPMEN bits in SPMCSR. When an (E)LPM instruction is executed within three CPU cycles after the BLBSET and SPMEN bits are set in SPMCSR, the value of the Lock bits will be loaded in the destination register. The BLBSET and SPMEN bits will auto-clear upon completion of reading the Lock bits or if no (E)LPM instruction is executed within three CPU cycles or no SPM instruction is executed within four CPU cycles. When BLBSET and SPMEN are cleared, (E)LPM will work as described in the Instruction Set Manual. Bit 7 6 5 4 3 2 1 0 Rd - - BLB12 BLB11 BLB02 BLB01 LB2 LB1 The algorithm for reading the Fuse Low byte is similar to the one described above for reading the Lock bits. To read the Fuse Low byte, load the Z-pointer with 0x0000 and set the BLBSET and SPMEN bits in SPMCSR. When an (E)LPM instruction is executed within three cycles after the BLBSET and SPMEN bits are set in the SPMCSR, the value of the Fuse Low byte (FLB) will be loaded in the destination register as shown on 493 8393C-MCU Wireless-09/14

the next page. Refer to (see "Table 31-5" on page 506) for a detailed description and mapping of the Fuse Low byte. Bit 7 6 5 4 3 2 1 0 Rd FLB7 FLB6 FLB5 FLB4 FLB3 FLB2 FLB1 FLB0 Similarly, load 0x0003 in the Z-pointer for reading the Fuse High byte. When an (E)LPM instruction is executed within three cycles after the BLBSET and SPMEN bits are set in the SPMCSR, the value of the Fuse High byte (FHB) will be loaded in the destination register as shown below. Refer to "Table 31-4" on page 505 for detailed description and mapping of the Fuse High byte. Bit 7 6 5 4 3 2 1 0 Rd FHB7 FHB6 FHB5 FHB4 FHB3 FHB2 FHB1 FHB0 Load 0x0002 in the Z-pointer for reading the Extended Fuse byte. When an (E)LPM instruction is executed within three cycles after the BLBSET and SPMEN bits are set in the SPMCSR, the value of the Extended Fuse byte (EFB) will be loaded in the destination register as shown below. Refer to Table 31-3 on page 505 for detailed description and mapping of the Extended Fuse byte. Bit 7 6 5 4 3 2 1 0 Rd - - - - - EFB2 EFB1 EFB0 Fuse and Lock bits that are programmed will be read as zero. Fuse and Lock bits that are un-programmed will be read as one. 30.6.10 Reading the Signature Row from Software To read the Signature Row from software, load the Z-pointer with the signature byte address given in Table 30-3 on page 495 and set the SIGRD and SPMEN bits in SPMCSR. When a LPM instruction is executed within three CPU cycles after the SIGRD and SPMEN bits are set in SPMCSR, the signature byte value will be loaded in the destination register. The SIGRD and SPMEN bits will auto-clear upon completion of reading the Signature Row or if no LPM instruction is executed within three CPU cycles. Write access to the register SPMCSR is blocked during the three CPU cycles. When SIGRD and SPMEN are cleared, LPM will work as described in the Instruction Set Manual. The Signature Row cannot be read during an EEPROM write/erase operation. Assembly Code Example ; - The routine rea ds the three device signature bytes. ; - At the end the device signature bytes are stored in the CPU ; register r3, r4 and r5. ; - the nop statements can be replaced by any other statements as ; long as the blocking condition (respective time) of SPMCSR is ; respected. ldi r16, (1<<SIGRD)|(1<<SPMEN) out SPMCSR, r16 lpm r3, Z+ ; read Signature nop nop nop ATmega256/128/64RFR2 494 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 Assembly Code Example out SPMCSR, r16 ; write SPMCSR lpm r4, Z+ nop nop nop out SPMCSR, r16 ; write SPMCSR lpm r5, Z+ Table 30-3. Signature Row Addressing Signature Byte Z-Pointer Address(1) Device Signature Byte 1 0x0000 Device Signature Byte 2 0x0002 Device Signature Byte 3 0x0004 RC Oscillator Calibration Byte 0x0001 User Signature Data – Page 1 0x0100 – 0x01FF User Signature Data – Page 2 0x0200 – 0x02FF User Signature Data – Page 3 0x0300 – 0x03FF Note: 1. All other addresses are reserved for future use. 30.6.11 Preventing Flash Corruption During periods of V <1.8V, the Flash program can be corrupted because the supply DEVDD voltage is too low for the CPU and the Flash to operate properly. These issues are the same as for board level systems using Flash, and the same design solutions should be applied. A Flash program corruption can be caused by two situations when the voltage is too low. First, a regular write sequence to the Flash requires a minimum voltage to operate correctly. Secondly, the CPU itself can execute instructions incorrectly, if the supply voltage for executing instructions is too low. Flash corruption can easily be avoided by following these design recommendations (one is sufficient): 1. If there is no need for a Boot Loader update in the system, program the Boot Loader Lock bits to prevent any Boot Loader software updates. 2. Keep the AVR RESET active (low) during periods of insufficient power supply voltage. This can be done by enabling the internal Brown-out Detector (BOD) if the operating voltage matches the detection level. If not, an external low V reset DEVDD protection circuit can be used. If a reset occurs while a write operation is in progress, the write operation will be completed under the condition that the power supply voltage is sufficient. 3. Keep the AVR core in Power-down sleep mode during periods of low V . This DEVDD will prevent the CPU from attempting to decode and execute instructions, effectively protecting the SPMCSR Register and thus the Flash from unintentional writes. 495 8393C-MCU Wireless-09/14

30.6.12 Programming Time for Flash when Using SPM The calibrated RC Oscillator is used to time Flash accesses. Table 30-4 below shows the typical programming time for Flash accesses from the CPU. Table 30-4. SPM Programming Time Symbol Min Programming Time Max Programming Time Flash write (Page Write, and write 3.7 ms 4.5 ms Lock bits by SPM) Flash write (Page Erase) 7.3 ms 8.9 ms 30.6.13 Simple Assembly Code Example for a Boot Loader Assembly Code Example(1) ;-the routine writes one page of data from RAM to Flash ; the first data location in RAM is pointed to by the Y pointer ; the first data location in Flash is pointed to by the Z-pointer ;-error handling is not included ;-the routine must be placed inside the Boot space ; (at least the Do_spm sub routine). Only code inside NRWW section ; can be read during Self-Programming (Page Erase and Page Write). ;-registers used: r0, r1, temp1 (r16), temp2 (r17), looplo (r24), ; loophi (r25), spmcrval (r20) ; storing and restoring of registers is not included in the routine ; register usage ca n be optimized at the expense of code size ;-It is assumed that either the interrupt table is moved to the ; Boot loader section or that the interrupts are disabled. .equ PAGESIZEB=PAGESIZE*2 ;PAGESIZEB is page in BYTES, not words .org SMALLBOOTSTART Write_page: ; Page Erase ldi spmcrval, (1<<PGERS) | (1<<SPMEN) call Do_spm ; re-enable the RWW section ldi spmcrval, (1<<RWWSRE) | (1<<SPMEN) call Do_spm ; transfer data f rom RAM to Flash page buffer ldi looplo, low(PAGESIZEB) ;init loop variable ldi loophi, high(PAGESIZEB) ;not required for PAGESIZEB<=256 Wrloop: ld r0, Y+ ld r1, Y+ ldi spmcrval, (1<<SPMEN) call Do_spm adiw ZH:ZL, 2 sbiw loophi:looplo, 2 ;use subi for PAGESIZEB<=256 brne Wrloop ; execute Page Write ATmega256/128/64RFR2 496 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 Assembly Code Example(1) subi ZL, low(PAGESIZEB) ;restore pointer sbci ZH, high(PAGESIZEB) ;not required for PAGESIZEB<=256 ldi spmcrval, (1<< PGWRT) | (1<<SPMEN) call Do_spm ; re-enable the RWW section ldi spmcrval, (1<<RWWSRE) | (1<<SPMEN) call Do_spm ; read back and check, optional ldi looplo, low(PAGESIZEB) ;init loop variable ldi loophi, high(P AGESIZEB) ;not required for PAGESIZEB<=256 subi YL, low(PAGESIZEB) ;restore pointer sbci YH, high(PAGESIZEB) Rdloop: elpm r0, Z+ ld r1, Y+ cpse r0, r1 jmp Error sbiw loophi:looplo, 1 ;use subi for PAGESIZEB<=256 brne Rdloop ; return to RWW section ; verify that RWW section is safe to read Return: in temp1, SPMCSR ; If RWWSB is set, the RWW section is not ready yet sbrs temp1, RWWSB ret ; re-enable the RWW section ldi spmcrval, (1<<RWWSRE) | (1<<SPMEN) call Do_spm rjmp Return Do_spm: ; check for previous SPM complete Wait_spm: in temp1, SPMCSR sbrc temp1, SPMEN rjmp Wait_spm ; input: spmcrval determines SPM action ; disable interrupts if enabled, store status in temp2, SREG cli ; check that no EEPROM write access is present Wait_ee: sbic EECR, EEPE rjmp Wait_ee 497 8393C-MCU Wireless-09/14

Assembly Code Example(1) ; SPM timed sequence out SPMCSR, spmcrval spm ; restore SREG (to enable interrupts if originally enabled) out SREG, temp2 ret Notes: 1. See "About Code Examples" on page 7. 30.6.14 Boot Loader Parameters for 64 kByte of Flash Mem ory In Table 30-5 below through Table 30-7 on page 499, the parameters used in the description of the Self-Programming are given. Table 30-5. Read-While-Write Limit with 64 kByte of Flash Memory Section(1) Pages Address Read-While-Write section (RWW) 224 0x0000 – 0x6FFF No Read-While-Write section (NRWW) 32 0x7000 – 0x7FFF Note: 1. For details about these two sections see "NRWW – No Read-While-Write Section" on page 489. Table 30-6. Explanation of different variables used in Figure 30-3 on page 491 and the mapping to the Z-pointer for 64 kByte of Flash Memory Corresponding Variable Value Z-value(2) Description(1) Most significant bit in the Program Counter. PCMSB 14 (The Program Counter is 16 bits PC[15:0]) Most significant bit which is used to address PAGEMSB 6 the words within one page (128 words in a page requires seven bits PC [6:0]). Bit in Z-pointer that is mapped to PCMSB. ZPCMSB Z15 Because Z0 is not used, the ZPCMSB equals PCMSB + 1. Bit in Z-pointer that is mapped to PCMSB. ZPAGEMSB Z7 Because Z0 is not used; the ZPAGEMSB equals PAGEMSB + 1. Program Counter page address: Page PCPAGE PC[14:7] Z15:Z8 select, for Page Erase and Page Write. Program Counter word address: Word PCWORD PC[6:0] Z7:Z1 select, for filling temporary buffer (must be zero during Page Write operation) Notes: 1. Z0: should be ze ro for all SPM commands, byte select for the (E)LPM instruction. 2. See "Addressing the Flash During Self-Programming" on page 490 for details about the use of Z-pointer during Self-Programming. ATmega256/128/64RFR2 498 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 Table 30-7. Boot Size Configuration with 64 kByte of Flash Memory(1) s BOOTSZ1 BOOTSZ0 Boot Size Pages Application Flash Section Boot Loader Flash Section End Application Section Boot Reset AddresStart Boot Loader Section) ( 512 0x0000 – 0x7E00 – 1 1 4 0x7DFF 0x7E00 words 0x7DFF 0x7FFF 1024 0x0000 – 0x7C00 – 1 0 8 0x7BFF 0x7C00 words 0x7BFF 0x7FFF 2048 0x0000 – 0x7800 – 0 1 16 0x77FF 0x7800 words 0x77FF 0x7FFF 4096 0x0000 – 0x7000 – 0 0 32 0x6FFF 0x7000 words 0x6FFF 0x7FFF Note: 1. The different BOOTSZ Fuse configurations are shown in Figure 30-2 on page 489. 30.6.15 Boot Loader Parameters for 128 kByte of Flash Memory In Table 30-8 below through Table 30-10 on page 500, the parameters used in the description of the Self-Programming are given. Table 30-8. Read-While-Wri te Limit with 128 kByte of Flash Memory Section(1) Pages Address Read-While-Write section (RWW) 480 0x0000 – 0xEFFF No Read-While-Write section (NRWW) 32 0xF000 – 0xFFFF Note: 1. For details about these two sections see "NRWW – No Read-While-Write Section" on page 489 . Table 30-9. Explanation of different variables used in Figure 30-3 on page 491 and the mapping to the Z-pointer for 128 kByte of Flash Memory Corresponding Variable Value Z-value(2) Description(1) Most significant bit in the Program Counter. PCMSB 15 (The Program Counter is 16 bits PC[15:0]) Most significant bit which is used to address PAGEMSB 6 the words within one page (128 words in a page requires seven bits PC [6:0]). Bit in Z-pointer that is mapped to PCMSB. ZPCMSB Z16(3) Because Z0 is not used, the ZPCMSB equals PCMSB + 1. Bit in Z-pointer that is mapped to PCMSB. ZPAGEMSB Z7 Because Z0 is not used; the ZPAGEMSB equals PAGEMSB + 1. Program Counter page address: Page PCPAGE PC[15:7] Z16(3):Z8 select, for Page Erase and Page Write. 499 8393C-MCU Wireless-09/14

Corresponding Variable Value Z-value(2) Description(1) Program Counter word address: Word PCWORD PC[6:0] Z7:Z1 select, for filling temporary buffer (must be zero during Page Write operation) Notes: 1. Z0: should be zero for all SPM commands, byte select for the (E)LPM instruction. 2. See "Addressing the Flash During Self-Programming" on page 490 for details about the use of Z-pointer during Self-Programming. 3. The Z-register is only 16 bits wide. Bit 16 is located in the RAMPZ register in the I/O map. Table 30-10. Boot Size Configuration with 128 kByte of Flash Memory(1) s BOOTSZ1 BOOTSZ0 Boot Size Pages Application Flash Section Boot Loader Flash Section End Application Section Boot Reset AddresStart Boot Loader Section) ( 512 0x0000 – 0xFE00 – 1 1 4 0xFDFF 0xFE00 words 0xFDFF 0xFFFF 1024 0x0000 – 0xFC00 – 1 0 8 0xFBFF 0xFC00 words 0xFBFF 0xFFFF 20 48 0x0000 – 0xF800 – 0 1 16 0xF7FF 0xF800 words 0xF7FF 0xFFFF 4096 0x0000 – 0xF000 – 0 0 32 0xEFFF 0xF000 words 0xEFFF 0xFFFF Note: 1. The different BOOTSZ Fuse configurations are shown in Figure 30-2 on page 489. 30.6.16 Boot Loader Parameters for 256 kByte of Flash Memory In Table 30-11 below through Table 30-13 on page 501, the parameters used in the description of the Self-Programming are given. Table 30-11. Read-While-Write Limit with 256 kByte of Flash Memory Section(1) Pages Address Read-While-Write section (RWW) 992 0x00000 – 0x1EFFF No Read-While-Write section (NRWW) 32 0x1F000 – 0x1FFFF Note: 1. For details about these two sections see "NRWW – No Read-While-Write Section" on page 489. Table 30-12. Explanation of different variables used in Figure 30-3 on page 491 and the mapping to the Z-pointer for 256 kByte of Flash Memory Corresponding Variable Value Z-value(2) Description(1) Most significant bit in the Program Counter. PCMSB 16 (The Program Counter is 16 bits PC[15:0]) Most significant bit which is used to address PAGEMSB 6 the words within one page (128 words in a page requires seven bits PC [6:0]). ATmega256/128/64RFR2 500 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 Corresponding Variable Value Z-value(2) Description(1) Bit in Z-pointer that is mapped to PCMSB. ZPCMSB Z17:Z16(3) Because Z0 is not used, the ZPCMSB equals PCMSB + 1. Bit in Z-pointer that is mapped to PCMSB. ZPAGEMSB Z7 Because Z0 is not used; the ZPAGEMSB equals PAGEMSB + 1. Program Counter page address: Page PCPAGE PC[16:7] Z17(3):Z8 select, for Page Erase and Page Write. Program Counter word address: Word PCWORD PC[6:0] Z7:Z1 select, for filling temporary buffer (must be zero during Page Write operation) Notes: 1. Z0: should be zero for all SPM commands, byte select for the (E)LPM instruction. 2. See "Addressing the Flash During Self-Programming" on page 490 for details about the use of Z-pointer during Self-Programming. 3. The Z-register is only 16 bits wide. Bit [17:16] are located in the RAMPZ register in the I/O map. Table 30-13. Boot Size Configuration with 256 kByte of Flash Memory(1) s BOOTSZ1 BOOTSZ0 Boot Size Pages Application Flash Section Boot Loader Flash Section End Application Section Boot Reset AddresStart Boot Loader Section) ( 512 0x00000 – 0x1FE00 – 1 1 4 0x1FDFF 0x1FE00 words 0x1FDFF 0x1FFFF 1024 0x00000 – 0x1FC00 – 1 0 8 0x1FBFF 0x1FC00 words 0x1FBFF 0x1FFFF 2048 0x00000 – 0x1F800 – 0 1 16 0x1F7FF 0x1F800 words 0x1F7FF 0x1FFFF 4096 0x00000 – 0x1F000 – 0 0 32 0x1EFFF 0x1F000 words 0x1EFFF 0x1FFFF Note: 1. The different BOOTSZ Fuse configurations are shown in Figure 30-2 on page 489. 30.7 Register Description 30.7.1 SPMCSR – Store Program Memory Control Register Bit 7 6 5 4 3 2 1 0 $37 ($57) SPMIE RWWSB SIGRD RWWSRE BLBSET PGWRT PGERS SPMEN SPMCSR Read/Write RW R RW RW RW RW RW RW Initial Value 0 0 0 0 0 0 0 0 The Store Program Memory Control Register contains the control bits needed to control the Boot Loader operations. Note: Only one SPM instruction should be active at any time. 501 8393C-MCU Wireless-09/14

• Bit 7 – SPMIE - SPM Interrupt Enable When the SPMIE bit is written to one, and the I-bit in the Status Register is set (one), the SPM ready interrupt will be enabled. The SPM ready Interrupt will be executed as long as the SPMEN bit in the SPMCR register is cleared. • Bit 6 – RWWSB - Read While Write Section Busy When a self-programming (page erase or page write) operation to the RWW section is initiated, the RWWSB will be set (one) by hardware. When the RWWSB bit is set, the RWW section cannot be accessed. The RWWSB bit will be cleared if the RWWSRE bit is written to one after a self-programming operation is completed. Alternatively the RWWSB bit will automatically be cleared if a page load operation is initiated. • Bit 5 – SIGRD - Signature Row Read If this bit is written to one at the same time as SPMEN, the next LPM instruction within three clock cycles will read a byte from the signature row into the destination register. A SPM instruction within four cycles after SIGRD and SPMEN are set, will have no effect. This operation is reserved for future use and should not be used. • Bit 4 – RWWSRE - Rea d While Write Section Read Enable When programming (page erase or page write) to the RWW section, the RWW section is blocked for reading (the RWWSB will be set by hardware). To re-enable the RWW section, the user software must wait until the programming is completed (SPMEN will be cleared). Then, if the RWWSRE bit is written to one at the same time as SPMEN, the next SPM instruction within four clock cycles re-enables the RWW section. The RWW section cannot be re-enabled while the Flash is busy with a page erase or a page write (SPMEN is set). If the RWWSRE bit is written while the Flash is being loaded, the Flash load operation will ab ort and the data loaded will be lost. • Bit 3 – BLBSET - Boot Lock Bit Set If this bit is written to one at the same time as SPMEN, the next SPM instruction within four clock cycles sets Boot Lock bits, according to the data in R0. The data in R1 and the address in the Z pointer are ignored. The BLBSET bit will automatically be cleared upon completion of the lock bit set, or if no SPM instruction is executed within four clock cycles. A LPM instruction within three cycles after BLBSET and SPMEN are set in the SPMCR register, will read either the Lock-bits or the Fuse bits (depending on Z0 in the Z pointer) into the destination register. • Bit 2 – PGWRT - Page Write If this bit is written to one at the same time as SPMEN, the next SPM instruction within four clock cycles executes page write, with the data stored in the temporary buffer. The page address is taken from the high part of the Z pointer. The data in R1 and R0 are ignored. The PGWRT bit will auto-clear upon completion of a page write, or if no SPM instruction is executed within four clock cycles. The CPU is halted during the entire page write operation if the NRWW section is addressed. • Bit 1 – PGERS - Page Erase If this bit is written to one a t the same time as SPMEN, the next SPM instruction within four clock cycles executes page erase. The page address is taken from the high part of the Z pointer. The data in R1 and R0 are ignored. The PGERS bit will auto-clear upon completion of a page erase, or if no SPM instruction is executed within four clock cycles. The CPU is halted during the entire page write operation if the NRWW section is addressed. • Bit 0 – SPMEN - Store Program Memory Enable This bit enables the SPM instruction for the next four clock cycles. If written to one together with either RWWSRE, BLB-SET, PGWRT or PGERS, the following SPM ATmega256/128/64RFR2 502 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 instruction will have a special meaning, see description above. If only SPMEN is written, the following SPM instruction will store the value in R1:R0 in the temporary page buffer addressed by the Z pointer. The LSB of the Z pointer is ignored. The SPMEN bit will auto-clear upon completion of an SPM instruction, or if no SPM instruction is executed within four clock cycles. Dur ing page erase and page write, the SPMEN bit remain high until the operation is completed. Writing any other combination than "10001", "01001", "00101", "00011" or "00001" in the lower five bits will have no effect. 30.7.2 NEMCR – Flash Extended-Mode Control-Register Bit 7 6 5 4 3 2 1 0 NA ($75) Resx7 ENEAM AEAM1 AEAM0 Resx3 Resx2 Resx1 Resx0 NEMCR Read/Write RW RW RW RW RW RW RW RW Initial Value 0 0 0 0 1 0 1 0 The Flash Extended-Mode Control-Register handles the extended address-mode of the extra rows. • Bit 7 – Resx7 - Reserved • Bit 6 – ENEAM - Enable Extended Address Mode for Extra Rows When active high, the extended address mode of the extra rows is enabled. The address is decoded from bits AEAM1:0 of this register. • Bit 5:4 – AEAM1:0 - Address for Extended Address Mode of Extra Rows These bits are only used w hen bit ENEAM of this register is set high. Then AEAM1:0 are used to decode the addresses of the extra rows. A value of 0 decodes the default Signature Row that is also accessible when the extended address mode is deactivated. Table 30-14 AEAM Register Bits Register Bits Value Description AEAM1:0 0 Signature Row 1 User Row 1 2 User Row 2 3 User Row 3 • Bit 3:0 – Resx3:0 - Reserved 503 8393C-MCU Wireless-09/14

31 Memory Programming 31.1 Program And Data Memory Lock Bits The ATmega256/128/64RFR2 provides six Lock bits which can be left un-programmed (“1”) or can be programmed (“0”) to obtain the additional features listed in Table 31-2 below. The Lock bits can only be erased to “1” with the Chip Erase command. Table 31-1. Lock Bit Byte (1) Lock Bit Byte Bit No Description Default Value − 7 − 1 (un-programmed) − 6 − 1 (un-programmed) BLB12 5 Boot Lock bit 1 (un-programmed) BLB11 4 Boot Lock bit 1 (un-programmed) BLB02 3 Boot Lock bit 1 (un-programmed) BLB01 2 Boot Lock bit 1 (un-programmed) LB2 1 Lock bit 1 (un-programmed) LB1 0 Lock bit 1 (un-programmed) Note: 1. “1” means un-programmed, “0” means programmed. Table 31-2. Lock Bit Protection Modes (1)(2) Memory Lock Bits Protection Type LB Mode LB2 LB1 1 1 1 No memory lock features enabled. Further programming of the Flash and EEPROM is disabled in Parallel, JTAG and Serial Programming 2 1 0 mode. The Fuse bits are locked in Parallel, JTAG and Serial Programming mode.(1) Further programming and verification of the Flash and EEPROM is disabled in Parallel, JTAG and Serial 3 0 0 Programming mode. The Boot Lock bits and Fuse bits are locked in Parallel, JTAG and Serial Programming mode.(1) BLB0 Mode BL02 BL01 No restrictions for SPM or (E)LPM accessing the 1 1 1 Application section. 2 1 0 SPM is not allowed to write to the Application section. SPM is not allowed to write to the Application section, and (E)LPM executing from the Boot Loader section is not allowed to read from the Application section. If 3 0 0 Interrupt Vectors are placed in the Boot Loader section, interrupts are disabled while executing from the Application section. (E)LPM executing from the Boot Loader section is not allowed to read from the Application section. If 4 0 1 Interrupt Vectors are placed in the Boot Loader section, interrupts are disabled while executing from the Application section. ATmega256/128/64RFR2 504 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 Memory Lock Bits Protection Type BLB1 Mode BL12 BL11 No restrictions for SPM or (E)LPM accessing the Boot 1 1 1 Loader section. SPM is not allowed to write to the Boot Loader 2 1 0 section. SPM is not allowed to write to the Boot Loader section, and (E)LPM executing from the Application section is not allowed to read from the Boot Loader 3 0 0 section. If Interrupt Vectors are placed in the Application section, interrupts are disabled while executing from the Boot Loader section. (E)LPM executing from the Application section is not allowed to read from the Boot Loader section. If 4 0 1 Interrupt Vectors are placed in the Application section, interrupts are disabled while executing from the Boot Loader section. Notes: 1. Program the Fuse bits and Boot Lock bits before programming the LB1 and LB2. 2. “1” means un-programmed, “0” means programmed. 31.2 Fuse Bits The ATmega256/128/64RFR2 has three Fuse bytes. Table 31-3 below – Table 31-5 on page 506 describe briefly the functionality of all the fuses and how they are mapped into the Fuse bytes. Note that the fuses are read as logical zero, “0”, if they are programmed. Table 31-3. Extended Fuse Byte Ext. Fuse Byte Bit No Description Default Value − 7 − 1 − 6 − 1 − 5 − 1 − 4 − 1 Reserved 3 Do not modify 1 (un-programmed) BODLEVEL2(1) 2 Brown-out Detector trigger level 1 (un-programmed) BODLEVEL1(1) 1 Brown-out Detector trigger level 1 (un-programmed) BODLEVEL0(1) 0 Brown-out Detector trigger level 0 (programmed) Notes: 1. See Table 35-23 on page 556 for BODLEVEL Fuse decoding. Table 31-4. Fuse High Byte Fuse High Byte Bit No Description Default Value OCDEN(4) 7 Enable On-chip debugging 1 (un-programmed, OCD (OCD) disabled) JTAGEN 6 Enable JTAG interface 0 (programmed, JTAG enabled) SPIEN(1) 5 Enable Serial Program and Data 0 (programmed, SPI Downloading (SPI) programming enabled) WDTON(3) 4 Watchdog Timer always on 1 (un-programmed) 505 8393C-MCU Wireless-09/14

Fuse High Byte Bit No Description Default Value EESAVE 3 EEPROM memory is preserved 1 (un-programmed, through the Chip Erase EEPROM not preserved) BOOTSZ1 2 Select Boot Size (see Table 30- 0 (programmed)(2) 10 on page 500 for details) BOOTSZ0 1 Select Boot Size (see Table 30- 0 (programmed) (2) 10 on page 500for details) BOOTRST 0 Select Reset Vector 1 (un-programmed) Notes: 1. The SPIEN Fuse is not accessible in serial programming mode. 2. The default value of BOOTSZ1:0 results in maximum Boot Size. See Table 30-10 on page 500 for details. 3. See "WDTCSR – Watchdog Timer Control Register" on page 217 for details. 4. Never ship a product with the OCDEN Fuse programmed regardless of the setting of Lock bits and JTAGEN Fuse. A programmed OCDEN Fuse enables some parts of the clock system to be running in all sleep modes. This may increase the power consumption. Table 31-5. Fuse Low Byte Fuse Low Byte Bit No Description Default Value CKDIV8(4) 7 Divide clock by 8 0 (programmed) CKOUT(3) 6 Clock output 1 (un-programmed) SUT1 5 Select start-up time 1 (un-programmed)(1) SUT0 4 Select start-up time 0 (programmed) (1) CKSEL3 3 Select Clock source 0 (programmed)(2) CKSEL2 2 Select Clock source 0 (programmed) (2) CKSEL1 1 Select Clock source 1 (un-programmed) (2) CKSEL0 0 Select Clock source 0 (programmed) (2) Notes: 1. The default value of SUT1:0 results in maximum start-up time for the default clock source. See "System Control and Reset" on page 209 for details. 2. The default setting of CKSEL3:0 results in internal RC Oscillator @ 8 MHz. See "Table 11-1" on page 177 for details. 3. The CKOUT Fuse allows the system clock to be output on PORTE7. See "Clock Output Buffer" on page 181 for details. 4. See "System Clock Prescaler" on page 181 for details. The status of the Fuse bits is not affected by Chip Erase. Note that the Fuse bits are locked if Lock bit1 (LB1) is programmed. Program the Fuse bits before programming the Lock bits. 31.2.1 Latching of Fuses The fuse values are latched when the device enters programming mode and changes of the fuse values will have no effect until the part leaves Programming mode. This does not apply to the EESAVE Fuse which will take effect once it is programmed. The fuses are also latched on Power-up in Normal mode. ATmega256/128/64RFR2 506 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 31.3 Signature Bytes All Atmel microcontrollers have a three-byte signature code which identifies the device. This code can be read in both serial and parallel mode, also when the device is locked. The three bytes reside in a separate address space. For the ATmega256/128/64RFR2 the signature bytes are given in Table 31-6 below. Accessing the signature bytes from software is described in section "Reading the Signature Row from Software" on page 494. Table 31-6. Device and JTAG ID (64-pin package) Signature Byte Number JTAG Part 0 1 2 Part Number Manufacturer ID ATmega256RFR2 0x1E 0xA8 0x02 0xA802 0x1F ATmega128RFR2 0x1E 0xA7 0x02 0xA702 0x1F ATmega64RFR2 0x1E 0xA6 0x02 0xA602 0x1F 31.4 User Signature Data Three Flash pages are dedicated for user signature data. These signature pages are isolated from the main Flash and will not be cleared by a Chip Erase command. Special commands are available to erase and write data to user signature pages via the Parallel and JTAG interface (see "Parallel Programming" on page 510 and "Programming via the JTAG Interface" on page 525 for details). User signature rows can be read from software in the same way as the device and JTAG identifiers (see section "Reading the Signature Row from Softwar e" on page 494). 31.5 Calibration Byte The ATmega256/128/64RFR2 has a byte calibration value for the internal RC Oscillator. This byte resides in the high byte of address 0x000 in the signature address space. During reset, this b yte is automatically written into the OSCCAL Register to ensure correct frequency of the calibrated RC Oscillator. 31.6 Page Size Table 31-7. Number of Words in a Page and Number of Pages in the Flash Flash Size Page Size PCWORD No. of PCPAGE PCMSB Pages 128k words (256k bytes) 1 28 words PC[6:0] 1024 PC[16:7] 16 64k words (128k bytes) 128 words PC[6:0] 512 PC[15:7] 15 32k words (64k bytes) 128 words PC[6:0] 256 PC[14:7] 14 Notes: 1. The page size for user signature data in all devices is also 128 words. Table 31-8. Number of Bytes in a Page and Number of Pages in the EEPROM EEPROM Size Page Size PCWORD No. of PCPAGE EEAMSB Pages 8k bytes 8 bytes EEA[2:0] 1024 EEA[12:3] 12 4k bytes 8 bytes EEA[2:0] 512 EEA[11:3] 11 2k bytes 8 bytes EEA[2:0] 256 EEA[10:3] 10 507 8393C-MCU Wireless-09/14

31.7 Parallel Programming Parameters, Pin Mapping, and Commands This section describes how to parallel program and verify Flash Program memory, EEPROM Data memory, Memory Lock bits, and Fuse bits in the ATmega256/128/64RFR2. 31.7.1 Signal Names In this section, some pins of the ATmega256/128/64RFR2 are referenced by signal names describing their functionality during parallel programming; see Figure 31-1 below and Table 31-9 below. Pins not described in this table are referenced by their default pin names. The XA1/XA0 pins determin e the action executed when the CLKI pin is given a positive pulse. The bit coding is shown in Table 31-12 on page 509. ___ __ When pulsing WR or OE or, the command loaded determines the action executed. The different commands are shown in Table 31-13 on page 509. Figure 31-1. Parallel Progra mming (1) Note: 1. Unused Pins should be left floating. Table 31-9. Pin Name Mapping Signal Name in Programming Mode Pin Name I/O Function ___ 0: Device is busy programming, 1: Device is RDY/BSY PD1 O ready for new command. __ OE PD2 I Output Enable (Active low). ___ WR PD3 I Write Pulse (Active low). BS1 PD4 I Byte Select 1. XA0 PD5 I XTAL Action Bit 0. XA1 PD6 I XTAL Action Bit 1. Program Memory and EEPROM data Page PAGEL PD7 I Load. ATmega256/128/64RFR2 508 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 Signal Name in Programming Mode Pin Name I/O Function BS2 PE2 I Byte Select 2. Bi-directional Data bus (Output when ¯O¯E¯ is DATA PB7-0 I/O low). Table 31-10. BS2 and BS1 Encoding Flash / EEPROM Flash Data Fuse Reading Fuse BS2 BS1 Address Loading / Reading Programming and Lock Bits 0 0 Low Byte Low Byte Low Byte Fuse Low Byte 0 1 High Byte High Byte High Byte Lock Bits Extended High Extended Fuse 1 0 Reserved Extended Byte Byte Byte 1 1 Reserved Reserved Reserved Fuse High Byte Table 31-11. Pin Values Used to Enter Programming Mode Pin Symbol Value PAGEL Prog_enable[3] 0 XA1 Prog_enable[2] 0 XA0 Prog_enable[1] 0 BS1 Prog_enable[0] 0 Table 31-12. XA1 and XA0 Encoding XA1 XA0 Action when CLKI is Pulsed Load Flash or EEPROM Address (High or low address byte 0 0 determined by BS2 and BS1). Load Data (High or Low data byte for Flash determined by 0 1 BS1). 1 0 Load Command. 1 1 No Action, Idle. Table 31-13. Command Byte Bit Encoding Command Byte Command Executed 1000 0000 Chip Erase 0100 0000 Write Fuse bits 0010 0000 Write Lock bits 0001 0000 Write Flash 0001 0001 Write EEPROM 0000 1000 Read Signature bytes and Calibration byte 0000 0100 Read Fuse and Lock bits 0000 0010 Read Flash 0000 0011 Read EEPROM 509 8393C-MCU Wireless-09/14

Table 31-14. Command Byte Bit Encoding (EEPROM Erase, User Signature Data) Command Byte Command Executed 1000 0010 Chip Erase EEPROM only 1000 0011 Erase EEPROM Page 0001 0010 Write User Signature Page(1) 1000 0100 Erase User Signature Page(1) 0000 1000 Read User Signature Page(1) Note: 1. See section "User Signature Data" on page 507. 31.8 Parallel Programming Pulses of CLKI and in the following command sequences are assumed to be at least 250 ns wide unless otherwise noted. 31.8.1 Enter Programming Mode The following algorithm puts the device in parallel programming mode: 1. Apply 3.3V between DEVDD and DVSS. 2. Set RSTN to 0 and TST to 0. 3. Set the Prog_enable pins listed in Table 31-11 on page 509 to “0000” and wait at least 100ns. 4. Set TST to 1. TST can be set high any time before but not after the rising edge of RSTN (t ). TSTRNH 5. Set RSTN to 1. Any activity on Prog_enable pins within 100 ns after RSTN is set to 1 will cause the device to fail entering programming mode. 6. Wait at least 50 µs before sending a command. 31.8.2 Considerations for Efficient Programming The loaded command and address are retained in the device during programming. For efficient programming, the following should be considered. • The command needs only be loaded once when writing or reading multiple memory locations. • Skip writing the data value 0xFF, that is the contents of the entire EEPROM (unless the EESAVE Fuse is programmed) and Flash after a Chip Erase. • Address high byte needs only be loaded before programming or reading a new 256 word window in Flash or 256 byte EEPROM. This consideration also applies to Signature bytes reading. 31.8.3 Chip Erase The Chip Erase will erase the Flash and EEPROM (1) memories plus Lock bits. The Lock bits are not reset until the program memory has been completely erased. The Fuse bits are not changed. A Chip Erase must be performed before the Flash and/or EEPROM are reprogrammed. Note: 1. The EEPROM memory is preserved during Chip Erase if the EESAVE Fuse is programmed. Load Command “Chip Erase” ATmega256/128/64RFR2 510 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 1. Set XA1, XA0 to “10”. This enables command loading. 2. Set BS1 to “0”. 3. Set DATA to “1000 0000”. This is the command for Chip Erase. 4. Give CLKI a positive puls e. This loads the command. ___ ___ 5. Give WR a negative pulse. This starts the Chip Erase. RDY/ BSY goes low. ___ 6. Wait until RDY/BSY goes high before loading a new command. 31.8.4 Programming the Flash The Flash is organized in pages; see Table 31-7 on page 507. When programming the Flash, the program data is latched into a page buffer. This allows one page of program data to be programmed simultaneously. The following procedure describes how to program the entire Flash memory: A. Load Command “Write Flash” 1. Set XA1, XA0 to “10”. This enables command loading. 2. Set BS1 to “0”. 3. Set DATA to “0001 0000”. This is the command for Write Flash. 4. Give CLKI a positive pulse. This loads the command. B. Load Address Low byte (Address bits 7:0) 1. Set XA1, XA0 to “00”. This enables address loading. 2. Set BS2, BS1 to “00”. This selects the address low byte. 3. Set DATA = Address low byte (0x00 - 0xFF). 4. Give CLKI a positive pulse. This loads the address low byte. C. Load Data Low Byte 1. Set XA1, XA0 to “01”. Th is enables data loading. 2. Set DATA = Data low byte (0x00 - 0xFF). 3. Give CLKI a positive pulse. This loads the data byte. D. Load Data High Byte 1. Set BS1 to “1”. This selects high data byte. 2. Set XA1, XA0 to “01”. This enables data loading. 3. Set DATA = Data high byte (0x00 - 0xFF). 4. Give CLKI a positive pulse. This loads the data byte. E. Latch Data 1. Set BS1 to “1”. This selects high data byte. 2. Give PAGEL a positive pulse. This latches the data bytes. (see Figure 31-3 on page 513 for signal waveforms). F. Repeat B through E until the entire buffer is filled or until all data within the page is loaded. While the lower bits in the address are mapped to words within the page, the higher bits address the pages within the Flash. This is illustrated in Figure 31-5 on page 513. Note 511 8393C-MCU Wireless-09/14

that if less than eight bits are required to address words in the page (page size < 256), the most significant bit(s) in the address low byte are used to address the page when performing a Page Write. G. Load Address High byte (Address bits15:8) 1. Set XA1, XA0 to “00”. This enables address loading. 2. Set BS2, BS1 to “01”. This selects the address high byte. 3. Set DATA = Address high byte (0x00 - 0xFF). 4. Give CLKI a positive pulse. This loads the address high byte. H. Load Address Extended High byte (Address bits 23:16) 1. Set XA1, XA0 to “00”. This enables address loading. 2. Set BS2, BS1 to “10”. This selects the address high byte. 3. Set DATA = Address extended high byte (0x00 - 0xFF). 4. Give CLKI a positive pulse. This loads the address extended high byte. I. Program Page 1. Set BS2, BS1 to “00” ___ 2. Give W__R_ a negative pulse. This starts programming of the entire page of data. RDY/BSY goes low. ___ 3. Wait until RDY/BSY goes high (See Figure 31-3 on page 513 for signal waveforms). J. Repeat B through I until the entire Flash is programmed or until all data has been programmed. K. End Page Programming 1. Set XA1, XA0 to “10”. Th is enables command loading. 2. Set DATA to “0000 0000”. This is the command for No Operation. 3. Give CLKI a positive pulse. This loads the command, and the internal write signals are reset. ATmega256/128/64RFR2 512 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 Figure 31-5. Addressing the Flash which is Organized in Pages (1) PCMSB PAGEMSB PROGRAM(cid:13) PCPAGE PCWORD COUNTER PAGE ADDRESS(cid:13) WORD ADDRESS(cid:13) WITHIN THE FLASH WITHIN A PAGE PROGRAM MEMORY PAGE PCWORD[PAGEMSB:0]: PAGE INSTRUCTION WORD 00 01 02 PAGEEND Note: 1. PCPAGE and PCWORD are listed in Table 31-7 on page 507. Figure 31-3. Programming the Flash Waveforms (1) Note: 1. “XX” is don’t care. The letters refer to the programming description above. 31.8.5 Programming the EEPROM The EEPROM is organized in pages; see Table 31-8 on page 507. When programming the EEPROM, the program data is latched into a page buffer. This allows one page of data to be programmed simultaneously. The programming algorithm for the EEPROM data memory is as follows (refer to "Programming the Flash" on page 511 for details on Command, Address and Data loading): 1. A: Load Command “0001 0001”. 2. G: Load Address High Byte (0x00 - 0xFF). 3. B: Load Address Low Byte (0x00 - 0xFF). 4. C: Load Data (0x00 - 0xFF). 5. E: Latch data (give PAGEL a positive pulse). 513 8393C-MCU Wireless-09/14

K: Repeat 3 through 5 until the entire buffer is filled. L: Program EEPROM page 1. Set BS2, BS1 to “00”. ___ ___ 2. Give WR a negative pulse. This starts programming of the EEPROM page. RDY/BSY goes low. ___ 3. Wait until to RDY/BSY goes high before programming the next page (See Figure 31- 7 below for signal waveforms). Figure 31-7. Programming the EEPROM Waveforms K A G B C E B C E L DATA 0x11 ADDR. HIGH ADDR. LOW DATA XX ADDR. LOW DATA XX XA1 XA0 BS1 BS2 CLKI WR RDY/BSY RSTN OE PAGEL 31.8.6 Reading the Flash The algorithm for reading the Flash memory is as follows (refer to "Programming the Flash" on page 511 for details on Command and Address loading): 1. A: Load Command “0000 0010”. 2. H: Load Address Extended High Byte (0x00 - 0xFF). 3. G: Load Address High Byte (0x00 - 0xFF). 3. B: Load Address Low Byte (0x00 - 0xFF). __ 4. Set OE to “0”, and BS1 to “0”. The Flash word low byte can now be read at DATA. 5. Set BS1 to “1”. The Flash word high byte can now be read at DATA. __ 6. Set OE to “1”. 31.8.7 Reading the EEPROM The algorithm for reading the EEPROM memory is as follows (refer to "Programming the Flash" on page 511 for details on Command and Address loading): 1. A: Load Command “0000 0011”. 2. G: Load Address High B yte (0x00 - 0xFF). 3. B: Load Address Low Byte (0x00 - 0xFF). __ 4. Set OE to “0”, and BS1 to “0”. The EEPROM Data byte can now be read at DATA. __ 5. Set OE to “1”. 31.8.8 Programming the Fuse Low Bits The algorithm for programming the Fuse Low bits is as follows (refer to "Programming the Flash" on page 511 for details on Command and Data loading): ATmega256/128/64RFR2 514 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 1. A: Load Command “0100 0000”. 2. C: Load Data Low Byte. Bit n = “0” programs and bit n = “1” erases the Fuse bit. ___ ___ 3. Give WR a negative pulse and wait for RDY/BSY to go high. 31.8.9 Programming the Fuse High Bits The algorithm for programming the Fuse High bits is as follows (refer to "Programming the Flash" on page 511 for details on Command and Data loading): 1. A: Load Command “0100 0000”. 2. C: Load Data Low Byte. Bit n = “0” programs and bit n = “1” erases the Fuse bit. 3. Set BS2, BS1 to “01”. This selects high data byte. ___ ___ 4. Give WR a negative puls e and wait for RDY/BSY to go high. 5. Set BS2, BS1 to “00”. This selects low data byte. 31.8.10 Programming the Extended Fuse Bits The algorithm for programming the Extended Fuse bits is as follows (refer to "Programming the Flash" on page 511 for details on Command and Data loading): 1. A: Load Command “0100 0000”. 2. C: Load Data Low Byte. Bit n = “0” programs and bit n = “1” erases the Fuse bit. 3. Set BS2, BS1 to “10”. This selects extended data byte. ___ ___ 4. Give WR a negative pulse and wait for RDY/BSY to go high. 5. Set BS2, BS1 to “00”. This selects low data byte. Figure 31-8. Programming the Fuses Waveforms 31.8.11 Programming the Lock Bits The algorithm for programming the Lock bits is as follows (refer to "Programming the Flash" on page 511 for details on Command and Data loading): 1. A: Load Command “0010 0000”. 2. C: Load Data Low Byte. Bit n = “0” programs the Lock bit. If LB mode 3 is active (LB1 and LB2 are programmed), it is not possible to program the Boot Lock bits by any External Programming mode. ___ ___ 3. Give WR a negative pulse and wait for RDY/BSY to go high. The Lock bits can only be cleared by executing Chip Erase. 515 8393C-MCU Wireless-09/14

31.8.12 Reading the Fuse and Lock Bits The algorithm for reading the Fuse and Lock bits is as follows (refer to "Programming the Flash" on page 511 for details on Command and Data loading): 1. A: Load Command “0000 0100”. __ 2. Set OE to “0”, and BS2, BS1 to “00”. The status of the Fuse Low bits can now be read at DATA (“0” means programmed). __ 3. Set OE to “0”, and BS2, BS1 to “11”. The status of the Fuse High bits can now be read at DATA (“0” means programmed). __ 4. Set OE to “0”, and BS2, BS1 to “10”. The status of the Extended Fuse bits can now be read at DATA (“0” means programmed). __ 5. Set OE to “0”, and BS2, BS1 to “01”. The status of the Lock bits can now be read at DATA (“0” means programmed). __ 6. Set OE to “1”. Figure 31-9. Mapping between BS1, BS2 and the Fuse and Lock Bits during Read Fuse Low Byte 0 0 Extended Fuse Byte 1 DATA BS2 Lock Bits 0 1 BS1 Fuse High Byte 1 BS2 31.8.13 Reading the Signature Bytes The algorithm for reading the Signature bytes is as follows (refer to "Programming the Flash" on page 511 for details on Command and Data loading): 1. A: Load Command “0000 1000”. 2. B: Load Address Low Byte (0x00 - 0x02). __ 3. Set O__E to “0” and BS to “0”. The selected Signature byte can now be read at DATA. 4. Set OE to “1”. 31.8.14 Reading the Calibration Byte The algorithm for reading the Calibration byte is as follows (refer to "Programming the Flash" on page 511 for deta ils on Command and Data loading): 1. A: Load Command “0000 1000”. 2. B: Load Address Low Byte, 0x00. __ 3. Set OE to “0” and BS1 to “1”. The Calibration byte can now be read at DATA. __ 4. Set OE to “1”. ATmega256/128/64RFR2 516 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 31.8.15 Chip Erase of EEPROM only This special Chip Erase command will erase only the EEPROM (1) memory. The Flash, Lock and Fuse bits are not changed. The EEPROM must be erased before it can be reprogrammed. Note: 1. The EEPROM memory is also preserved during this special Chip Erase if the EESAVE Fuse is programmed. Load Command “Chip Erase EEPROM only” 1. Set XA1, XA0 to “10”. This enables command loading. 2. Set BS1 to “0”. 3. Set DATA to “1000 0010 ” . This is the command for Chip Erase EEPROM only. 4. Give CLKI a positive pulse. This loads the command. ___ ___ 5. Give WR a negative pulse. This starts the Chip Erase of the EEPROM. RDY/ BSY goes low. ___ 6. Wait until RDY/BSY goes high before loading a new command. 31.8.16 Erase EEPROM Page The EEPROM is organized in pages; see Table 31-8 on page 507. When programming the EEPROM, the program data is latched into a page buffer. In contrast when erasing the EEPROM, only the byte address is required and latched into the page buffer. The program data are ignored. This allows erasing only selected bytes of an EEPROM page. The algorithm for erasing EEPROM data is as follows (refer to "Programming the Flash" on page 511 for details on Command, Address and Data loading): 1. A: Load Command “1000 0011”. 2. G: Load Address High Byte (0x00 - 0xFF). 3. B: Load Address Low Byte (0x00 - 0xFF). 4. E: Latch address (give PAGEL a positive pulse). K: Repeat 3 through 5 until all addresses of bytes to be erased have been latched. If all byte locations in the EEPROM page have been latched, then the entire page is erased. L: Erase EEPROM page 1. Set BS2, BS1 to “00”. ___ ___ 2. Give WR a negative pulse. This starts erasing of the EEPROM page. RDY/BSY goes low. ___ 3. Wait until to RDY/BSY go es high before a new program or erase operation. Note: 1. The EEPROM memory is not preserved during the EEPROM page erase if the EESAVE Fuse is programmed. 31.8.17 Writing User Signature Data Three Flash pages are dedicated for user signature data (see "User Signature Data" on page 507 for details). Writing the user signature pages is similar to programming any other page of the Flash. For programming signature pages, the user data is latched into a page buffer. This allows one page of user signature data to be programmed at a time. The following procedure describes how to write all user signature pages (refer to "Programming the Flash" on page 511 for details on Command, Address and Data loading): 1. A. Load Command “0001 0010” (Write User Signature Page). 517 8393C-MCU Wireless-09/14

2. B. Load Address Low byte (Address bits 7:0). 3. C. Load Data Low Byte (0x00 - 0xFF). 4. D. Load Data High Byte (0x00 - 0xFF). 5. E. Latch Data (give PAGEL a positive pulse). F. Repeat B through E until the entire buffer is filled or until all data within the page is loaded. While the lower bits in the address are mapped to words within the page, the higher bits address one of the three signature pages. G. Load Address High byte (Address bits15:8): 0x01, 0x02 or 0x03I. Program Page 1. Set BS2, BS1 to “00” ___ 2. Give WR a _n_e_gative pulse. This starts programming of the entire signature page of data. RDY/BSY goes low. ___ 3. Wait until RDY/BSY goes high (See Figure 31-3 on page 513 for signal waveforms). J. Repeat B through I until a ll user signature pages or all data has been programmed. K. End Page Programming. Note: 1. User Signature Pages must be erased before being written. See "Erasing User Signature Data" below. 31.8.18 Erasing User Signature Data Three Flash pages are dedicated for user signature data (see "User Signature Data" on page 507 for details). A us er signature page must be erased before being written. A Chip Erase does not modify the signature pages. Erasing user signature data follows a similar procedure as shown in section "Writing User Signature Data" on page 517. The data of one signature page at a time can be erased. The following procedure describes how to write all user signature pages (refer to "Programming the Flash" on page 511 for details on Command, Address and Data loading): 1. A. Load Command “1000 0100” (Erase User Signature Page). While the lower bits in the address are mapped to words within the page, the higher bits address one of the three signature pages. 2. B. Load Address Low byte (Address bits 7:0): 0x00 3. G. Load Address High byte (Address bits15:8): 0x01, 0x02 or 0x03 I. Program Page (Erase) 4. Set BS2, BS1 to “00” ___ 5. Give WR a _n_e_gative pulse. This starts erasing the data of the entire user signature page. RDY/BSY goes low. ___ 6. Wait until RDY/BSY goes high (See Figure 31-3 on page 513 for signal waveforms). J. Repeat B through I until all user signature pages are erased. K. End Page Programming. 31.8.19 Reading User Signature Data The algorithm for reading User Signature Data is similar to reading from Flash (refer to "Programming the Flash" on page 511 for details on Command and Data loading). The algorithm for reading User Signature Data is similar to read from Flash. ATmega256/128/64RFR2 518 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 1. A: Load Command “0000 1000”. 2. G: Load Address High Byte. 2. B: Load Address Low Byte. __ 3. Set OE to “0” and BS to “0 ”. The Signature word low byte can now be read at DATA. __ 4. Set OE to “1”. 5. Set BS1 to “1”. The Signature word high byte can now be read at DATA. __ 6. Set OE to “1”. Repeat steps 2 to 6 until all data have been read. 31.8.20 Parallel Programming Characteristics Figure 31-10. Parallel progr amming timing including some general timing requirements tXLWL CLKI tXHXL tDVXH tXLDX Data & Control (DATA, XA0/1, BS1, BS2) PAGEL tBVPH tPHPL tPLBX tBVWL tWLBX tWLWH WR tPLWL WLRL RDY/BSY tWLRH Figure 31-11. Parallel programming loading sequence with timing requirements (2) LOAD ADDRESS(cid:13) LOAD DATA (cid:13) LOAD DATA(cid:13) LOAD DATA(cid:13) LOAD ADDRESS(cid:13) (LOW BYTE) (LOW BYTE) (HIGH BYTE) (cid:13) (LOW BYTE) tXLXH tXLPH tPLXH CLKI BS1 PAGEL DATA ADDR0 (Low Byte) DATA (Low Byte) DATA (High Byte) ADDR1 (Low Byte) XA0 XA1 Note: 2. The timing requirements shown in Figure 31-10 above (i.e., t , t , and t ) DVXH XHXL XLDX also apply to loading operation. 519 8393C-MCU Wireless-09/14

Figure 31-12. Parallel programming reading sequence (within the same page) with timing requirements (1) LOAD ADDRESS(cid:13) READ DATA (cid:13) READ DATA(cid:13) LOAD ADDRESS(cid:13) (LOW BYTE) (LOW BYTE) (HIGH BYTE) (LOW BYTE) tXLOL CLKI tBVDV BS1 tOLDV OE tOHDZ DATA ADDR0 (Low Byte) DATA (Low Byte) DATA (High Byte) ADDR1 (Low Byte) XA0 XA1 Note: 1. The timing requirements shown in Figure 31-10 on page 519 (i.e., t , t , and DVXH XHXL t ) also apply to reading operation. XLDX Table 31-15. Parallel Programming Characteristics, V = 3.3V ± 10% DEVDD Symbol Parameter Min Typ Max Units t Delay TST High before RSTN High 0 ns TSTRNH t Data and Control Valid before CLKI High 67 ns DVXH t CLKI Low to CLKI High 200 ns XLXH t CLKI Pulse Width High 150 ns XHXL t Data and Control Hold after CLKI Low 67 ns XLDX ___ t CLKI Low to WR Low 0 ns XLWL t CLKI Low to PAGEL high 0 ns XLPH t PAGEL low to CLKI high 150 ns PLXH t BS1 Valid before PAGEL High 67 ns BVPH t PAGEL Pulse Width High 150 ns PHPL t BS1 Hold after PAGEL Low 67 ns PLBX ___ t BS2/1 Hold after WR Low 67 ns WLBX ___ tPLWL PAGEL Low to _W __R Low 67 ns t BS2/1 Valid to WR Low 67 ns BVWL ___ t WR Pulse Width Low 150 ns WLWH ___ ___ t WR Low to RDY/BSY Low 0 1 µs WLRL ___ ___ t WR Low to RDY/BSY High(1) 3.7 4.5 ms WLRH ___ ___ t WR Low to RDY/BSY High for Chip Erase(2) 16 18.5 ms WLRH_CE __ t CLKI Low to OE Low 0 ns XLOL t BS1 Valid to DATA valid 0 250 ns BVDV __ t OE Low to DATA Valid 250 ns OLDV __ t OE High to DATA Tri-stated 250 ns OHDZ ATmega256/128/64RFR2 520 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 Notes: 1. t is valid for the Write Flash, Write EEPROM, Write Fuse bits and Write Lock WLRH bits commands. 2. t is valid for the Chip Erase command. WLRH_CE 31.9 Serial Downloading Both the Flash and EEPROM memory arrays can be programmed using a serial programming bus while RSTN is pulled to DVSS. The serial programming interface consists of pins SCK, PDI (input) and PDO (output). After RSTN is set low, the Programming Enable instruction needs to be executed first before program/erase operations can be executed. NOTE, in Table 31-16 below, the pin mapping for serial programming is listed. 31.9.1 Serial Programming Pin Mapping Table 31-16. Pin Mapping Serial Programming Symbol Pins I/O Description PDI PB2 I Serial Data In PDO PB3 O Serial Data Out SCK PB1 I Serial Clock Figure 31-13. Serial Programming and Verify (1)(2) Notes: 1. If the device is clocked by the internal Oscillator, it is not required to connect a clock source to the CLKI pin. 2. VDEVDD-0.3V < VE VDD < VDEVDD+0.3V, both VEVDD and VDEVDD must stay in valid supply voltage limits. When programming the EEPROM, an auto-erase cycle is built into the self-timed programming operation (in the Serial mode ONLY) and there is no need to first execute the Chip Erase instruction. The Chip Erase operation turns the content of every memory location in both the Program and EEPROM arrays into 0xFF. Depending on CKSEL Fuses, a valid clock must be present. The minimum low and high periods for the serial clock (SCK) input are defined as follows: 521 8393C-MCU Wireless-09/14

Low: > 2 CPU clock cycles for f < 12 MHz, 3 CPU clock cycles for f >= 12 MHz; ck ck High: > 2 CPU clock cycles for f < 12 MHz, 3 CPU clock cycles for f >= 12 MHz; ck ck 31.9.2 Serial Programming Algorithm When writing serial data to the ATmega256/128/64RFR2, data is clocked on the rising edge of SCK. When reading data from the ATmega256/128/64RFR2, data is clocked on the falling edge of SCK. See Figure 31-15 on page 524 for timing details. To program and verify the ATmega256/128/64RFR2 in the serial programming mode, the following sequence is recommended (See four byte instruction formats in Table 31- 18 on page 523): 1. Power-up sequence: Apply power between DEVDD and DVSS while RSTN and SCK are set to “0”. In some systems, the programmer can not guarantee that SCK is held low during power-up. In this case, RSTN must be given a positive pulse of at least two CPU clock cycles duration after SCK has been set to “0”. 2. Wait for at least 20 ms and enable serial programming by sending the Programming Enable serial instruction to pin PDI. 3. The serial programming instructions will not work if the communication is out of synchronization. When in sync. the second byte (0x53), will echo back when issuing the third byte of the Programming Enable instruction. Whether the echo is correct or not, all four bytes of the instruction must be transmitted. If the 0x53 did not echo back, give RSTN a positive pulse and issue a new Programming Enable command. 4. The Flash is programmed one page at a time. The memory page is loaded one byte at a time by supplying the 7 LSB of the address and data together with the Load Program Memory Page instruction. To ensure correct loading of the page, the data low byte must be loaded before data high byte is applied for a given address. The Program Memory Page is stored by loading the Write Program Memory Page instruction with the addre ss lines 15:8. Before issuing this command, make sure the instruction Load Address Extended High Byte has been used to define the MSB of the address. The address extended high byte with the address lines 23:16 is stored until the command is re-issued, i.e., the command needs only be issued for the first page, and when crossing the 64k word boundary. If polling (RDY/B¯S¯¯Y) is not used, the user must wait at least t before issuing the next page (see Table 31-17 WD_FLASH on page 523). Accessing the serial programming interface before the Flash write operation completes can result in incorrect programming. 5. The EEPROM array is pr ogrammed one byte at a time by supplying the address and data together with the appropriate Write instruction. An EEPROM memory location is first automatically erased before new data is written. If polling is not used, the user must wait at least t before issuing the next byte (see Table 31-17 on page WD_EEPROM 523). In a chip erased device, no 0xFFs in the data file(s) need to be programmed. 6. Any memory location can be verified by using the Read instruction which returns the content at the selected address at serial output PDO. When reading the Flash memory, use the instruction Load Address Extended High Byte to define the upper address byte, which is not included in the Read Program Memory instruction. The address extended high byte with the address lines 23:16 is stored until the command is re-issued, i.e., the command needs only be issued for the first page, and when crossing the 64k word boundary. 7. At the end of the programming session, RSTN can be set high to commence normal operation. ATmega256/128/64RFR2 522 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 8. Power-off sequence (if needed): Set RESET to “1”. Turn DEVDD power off. Table 31-17. Minimum Wait Delay before writing the next Fuse/Flash/EEPROM location Symbol Minimum Wait Delay t 4.5 ms WD_FUSE t 4.5 ms WD_FLASH t 13 ms WD_EEPROM t 18.5 ms WD_CHIPERASE 31.9.3 Serial Programming Instruction Set Table 31-18 below and Figu re 31-14 on page 524 describe the Instruction set. Table 31-18. Serial Programming Instruction Set (5)(6) Instruction Format (2) Instruction/Operation Byte1 Byte2 Byte3 Byte4 Programming Enable $AC $53 $00 $00 Chip Erase (Program Memory/EEPROM) $AC $80 $00 $00 Poll RDY/B¯S¯¯Y $F0 $00 $00 data byte out Load Instruction Load Address Extended High Byte(1) $4D $00 Extended addr. $00 Load Program Memory Page, High Byte $48 $00 addr. LSB high data byte in Load Program Memory Page, Low Byte $40 $00 addr. LSB low data byte in Load EEPROM Memory Page (page access) $C1 $00 0000 000aa data byte in Read Instruction Read Program Memory, High byte $28 addr. MSB addr. LSB high data byte out Read Program Memory, Low byte $20 addr. MSB addr. LSB low data byte out Read EEPROM Memory $A0 0000 aaaa aaaa aaaa data byte out Read Lock Bits $58 $00 $00 data byte out Read Signature Byte $30 $00 0000 000aa data byte out Read Fuse Bits $50 $00 $00 data byte out Read Fuse High Bits $58 $08 $00 data byte out Read Extended Fuse Bits $50 $08 $00 data byte out Read Calibration Byte $38 $00 $00 data byte out Write Instructions (3)(4) Write Program Memory Page $4C addr. MSB addr. LSB $00 Write EEPROM Memory $C0 0000 aaaa aaaa aaaa data byte in Write EEPROM Memory Page (page access) $C2 0000 aaaa aaaa 00 $00 Write Lock Bits $AC $E0 $00 data byte in Write Fuse Bits $AC $A0 $00 data byte in Write Fuse High Bits $AC $A8 $00 data byte in Write Extended Fuse Bits $AC $A4 $00 data byte in Notes: 1. Not all instructions are applicable for all parts. 2. a = address. 3. Bits are programmed ‘0’, un-programmed ‘1’. 523 8393C-MCU Wireless-09/14

4. To ensure future compatibility, unused Fuses and Lock bits should be un-programmed (‘1’). 5. Refer to the corresponding section for Fuse and Lock bits, Calibration and Signature bytes and Page size. 6. See http://www.atmel.com/avr for Application Notes regarding programming and programmers. If the LSB in RDY/B¯S¯¯Y data byte out is ‘1’, a programming operation is still pending. Wait until this bit returns ‘0’ before the next instruction is carried out. Within the same page, the low data byte must be loaded prior to the high data byte. After data is loaded to the page buffer, program the EEPROM page; see Figure 31-14 below. Figure 31-14. Serial Programming Instruction Example Serial Programming Instruction Load Program Memory Page (High/Low Byte)/ Write Program Memory Page/ Load EEPROM Memory Page (page access) Write EEPROM Memory Page Byte 1 Byte 2 Byte 3 Byte 4 Byte 1 Byte 2 Byte 3 Byte 4 AAAAAdddddrrrrr MMMMMSSSSSBBBBB Adr LSB Adr MSB AAAAAdddddrrrrr LLLLLSSSSSBBBBB Bit 15 B 0 Bit 15 B 0 Page Buffer Page Offset Page 0 Page 1 Pag e 2 Page Number Page N-1 Program Memory/ EEPROM Memory 31.9.4 Serial Programming Characteristics For characteristics of the Serial Programming module see "SPI Timing Characteristics" on page 560. Figure 31-15. Serial Programming Waveforms SERIAL DATA INPUT MSB LSB (MOSI) SERIAL DATA OUTPUT MS B LSB (MISO) SERIAL CLOCK INPUT (SCK) SAMPLE ATmega256/128/64RFR2 524 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 31.10 Programming via the JTAG Interface Programming through the JTAG interface requires control of the four JTAG specific pins: TCK, TMS, TDI, and TDO. Control of the reset and clock pins is not required. To be able to use the JTAG interface, the JTAGEN Fuse must be programmed. The device is default shipped with the fuse programmed. In addition, the JTD bit in MCUCR must be cleared. Alternatively, if the JTD bit is set, the external reset can be forced low. Then, the JTD bit will be cleared after two chip clocks, and the JTAG pins are available for programming. This provides a means of using the JTAG pins as normal port pins in running mode while still allowing In-System Programming via the JTAG interface. Note that this technique can not be used when using the JTAG pins for Boundary-scan or On-chip Debug. In these cases the JTAG pins must be dedicated for this purpose. During programming the clock frequency of the TCK Input must be less than the maximum frequency of the chip. The System Clock Prescaler can not be used to divide the TCK Clock Input into a sufficiently low frequency. As a definition in this datasheet, the LSB is shifted in and out first of all Shift Registers. 31.10.1 Programming Specific JTAG Instructions The Instruction Register is 4-bit wide, supporting up to 16 instructions. The JTAG instructions useful for programming are listed below. The OPCODE for each instruction is shown behind the instruction name in hex format. The text describes which Data Register is selected as path between TDI and TDO for each instruction. The Run-Test/Idle state of t h e TAP-controller is used to generate internal clocks. It can also be used as an idle state between JTAG sequences. The state machine sequence for changing the instruction word is shown in Figure 31-16 on page 526. 525 8393C-MCU Wireless-09/14

Figure 31-16. State Machine Sequence for Changing the Instruction Word 1 Test-Logic-Reset 0 0 Run-Test/Idle 1 Select-DR Scan 1 Select-IR Scan 1 0 0 1 1 Capture-DR Capture-IR 0 0 Shift-DR 0 Shift-IR 0 1 1 1 1 Exit1-DR Exit1-IR 0 0 Pause-DR 0 Pause-IR 0 1 1 0 Exit2-DR 0 Exit2-IR 1 1 Update-DR Update-IR 1 0 1 0 31.10.2 AVR_RESET (0xC) The AVR specific public JTAG instruction is used for setting the AVR device in the Reset mode or taking the device out from the Reset mode. The TAP-controller is not reset by this instruction. The one bit Reset Register is selected as Data Register. Note that the reset will be active as long as there is a logic “one” in the Reset Chain. The output from this chain is not latched. The active states are: • Shift-DR: The Reset Reg ister is shifted by the TCK input. 31.10.3 PROG_ENABLE (0x4) The AVR specific public JTAG instruction enables programming via the JTAG port. The 16-bit Programming Enable Register is selected as Data Register. The active states are the following: • Shift-DR: The programming enable signature is shifted into the Data Register. ATmega256/128/64RFR2 526 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 • Update-DR: The programming enable signature is compared to the correct value, and Programming mode is entered if the signature is valid. 31.10.4 PROG_COMMANDS (0x5) The AVR specific public JTAG instruction is used for entering programming commands via the JTAG port. The 15-bit Programming Command Register is selected as Data Register. The active states are the following: • Capture-DR: The result of the previous command is loaded into the Data Register. • Shift-DR: The Data Register is shifted by the TCK input, shifting out the result of the previous command and shifting in the new command. • Update-DR: The programming command is applied to the Flash inputs. • Run-Test/Idle: One clock cycle is generated, executing the applied command. 31.10.5 PROG_PAGELOAD (0x6) The AVR specific public JTAG instruction directly loads the Flash data page via the JTAG port. An 8-bit Flash Data Byte Register is selected as the Data Register. This is physically the 8 LSB’s of the Programming Command Register. The active states are the following: • Shift-DR: The Flash Data Byte Register is shifted by the TCK input. • Update-DR: The content of the Flash Data Byte Register is copied into a temporary register. A write sequence is initiated that within 11 TCK cycles loads the content of the temporary register into the Flash page buffer. The AVR automatically alternates between writing the low and the high byte for each new Update-DR state, starting with the low byte for the first Update-DR encountered after entering the PROG_PAGELOAD command. The Program Counter is pre-incremented before writing the low byte, except for the first written byte. This ensures that the first data is written to the address set up by PROG_COMMANDS, and loading the last location in the page buffer does not make the program counter increment into the next page. 31.10.6 PROG_PAGEREAD (0x7) The AVR specific public JTAG instruction directly captures the Flash content via the JTAG port. An 8-bit Flash Data Byte Register is selected as the Data Register. This is physically the 8 LSB’s of the Programming Command Register. The active states are the following: • Capture-DR: The content of the selected Flash byte is captured into the Flash Data Byte Register. The AVR automatically alternates between reading the low and the high byte for each new Capture-DR state, starting with the low byte for the first Capture-DR encountered after entering the PROG_PAGEREAD command. The Program Counter is post-incremented after reading each high byte, including the first read byte. This ensures that the first data is captured from the first address set up by PROG_COMMANDS, and reading the last location in the page makes the program counter increment into th e next page. • Shift-DR: The Flash Data Byte Register is shifted by the TCK input. 31.10.7 Data Registers The Data Registers are selected by the JTAG instruction registers described in section "Programming Specific JTAG Instructions" on page 525. The Data Registers relevant for programming operations are: • Reset Register 527 8393C-MCU Wireless-09/14

• Programming Enable Register • Programming Command Register • Flash Data Byte Register 31.10.8 Reset Register The Reset Register is a Test Data Register used to reset the part during programming. It is required to reset the part before entering Programming mode. A high value in the Reset Register corresponds to pulling the external reset low. The part is reset as long as there is a high value present in the Reset Register. Depending on the Fuse settings for the clock options, the part will remain reset for a Reset Time- out period (refer to "Clock Sources" on page 177) after releasing the Reset Register. The output from this Data Register is not latched, so the reset will take place immediately, as shown in "Figure 29-2" on page 480. 31.10.9 Programming Enable Register The Programming Enable Register is a 16-bit register. The content of this register is compared to the programming enable signature, binary code 1010_0011_0111_0000. When the content of the register is equal to the programming enable signature, programming via the JTAG port is enabled. The register is reset to 0 on Power-on Reset, and should always be reset when leaving Programming mode. Figure 31-17. Programming Enable Register TDI D(cid:13) 0xA370 = A(cid:13) D Q Programming Enable T(cid:13) A ClockDR & PROG_ENABLE TDO 31.10.10 Programming Command Register The Programming Command Register is a 15-bit register. This register is used to serially shift in programming commands, and to serially shift out the result of the previous command, if any. The JTAG Programming Instruction Set is shown in Table 31-19 on page 529. The state sequence when shifting in the programming commands is illustrated in Figure 31-19 on page 532. ATmega256/128/64RFR2 528 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 Figure 31-18. Programming Command Register TDI S(cid:13) T(cid:13) R(cid:13) O(cid:13) B(cid:13) E(cid:13) S Flash(cid:13) EEPROM(cid:13) A(cid:13) Fuses(cid:13) D(cid:13) Lock Bits D(cid:13) R(cid:13) E(cid:13) S(cid:13) S(cid:13) /(cid:13) D(cid:13) A(cid:13) T(cid:13) A TDO Table 31-19. JTAG Programming Instruction (set a = address high bits, b = address low bits, c = address extended bits, H = 0 - Low byte, 1 - High Byte, o = data out, i = data in, x = don’t care) Instruction TDI Sequence TDO Sequence Notes 0100011_10000000 xxxxxxx_xxxxxxxx 0110001_10000000 xxxxxxx_xxxxxxxx 1a. Chip Erase 0110011_10000000 xxxxxxx_xxxxxxxx 0110011_10000000 xxxxxxx_xxxxxxxx 1b. Poll for Chip Erase Complete 0110011_10000000 xxxxxox_xxxxxxxx (2) 0100011_10000010 xxxxxxx_xxxxxxxx 0110001_10000010 xxxxxxx_xxxxxxxx 1c. Chip Erase EEPROM only 0110011_10000010 xxxxxxx_xxxxxxxx 0110011_10000010 xxxxxxx_xxxxxxxx 2a. Enter Flash Write 0100011_00010000 xxxxxxx_xxxxxxxx 2b. Load Address Extended High Byte 0001011_cccccccc xxxxxxx_xxxxxxxx (10) 2c. Load Address High Byte 0000111_aaaaaaaa xxxxxxx_xxxxxxxx 2d. Load Address Low Byte 0000011_bbbbbb bb xxxxxxx_xxxxxxxx 2e. Load Data Low Byte 0010011_iiiiiiii xxxxxxx_xxxxxxxx 2f. Load Data High Byte 0010111_iiiiiiii xxxxxxx_xxxxxxxx 0110111_00000000 xxxxxxx_xxxxxxxx 2g. Latch Data 1110111_00000000 xxxxxxx_xxxxxxxx (1) 0110111_00000000 xxxxxxx_xxxxxxxx 0110111_00000000 xxxxxxx_xxxxxxxx 0110101_00000000 xxxxxxx_xxxxxxxx 2h. Write Flash Page (1) 0110111_00000000 xxxxxxx_xxxxxxxx 0110111_00000000 xxxxxxx_xxxxxxxx 2i. Poll for Page Write Complete 0110111_00000000 xxxxxox_xxxxxxxx (2) 3a. Enter Flash Read 0100011_00000010 xxxxxxx_xxxxxxxx 3b. Load Address Extended High Byte 0001011_cccccccc xxxxxxx_xxxxxxxx (10) 529 8393C-MCU Wireless-09/14

Instruction TDI Sequence TDO Sequence Notes 3c. Load Address High Byte 0000111_aaaaaaaa xxxxxxx_xxxxxxxx 3d. Load Address Low Byte 0000011_bbbbbbbb xxxxxxx_xxxxxxxx 0110010_00000000 xxxxxxx_xxxxxxxx 3e. Read Data Low and High Byte 0110110_00000000 xxxxxxx_oooooooo Low byte 0110111_00000000 xxxxxxx_oooooooo High byte 4a. Enter EEPROM Write 0100011_00010001 xxxxxxx_xxxxxxxx 4b. Load Address High Byte 0000111_aaaaaaaa xxxxxxx_xxxxxxxx (10) 4c. Load Address Low Byte 0000011_bbbbbbbb xxxxxxx_xxxxxxxx 4d. Load Data Byte 0010011_iiiiiiii xxxxxxx_xxxxxxxx 0110111_00000000 xxxxxxx_xxxxxxxx 4e. Latch Data 1110111_00000000 xxxxxxx_xxxxxxxx (1) 0110111_00000000 xxxxxxx_xxxxxxxx 0110011_00000000 xxxxxxx_xxxxxxxx 0110001_000000 00 xxxxxxx_xxxxxxxx 4f. Write EEPROM Page (1) 0110011_00000000 xxxxxxx_xxxxxxxx 0110011_00000000 xxxxxxx_xxxxxxxx 4g. Poll for Page Write Complete 0110011_00000000 xxxxxox_xxxxxxxx (2) 4h. Enter EEPROM Erase 0100011_10000011 xxxxxxx_xxxxxxxx 5a. Enter EEPROM Read 0100011_00000011 xxxxxxx_xxxxxxxx 5b. Load Address High Byte 0000111_aaaaaaaa xxxxxxx_xxxxxxxx (10) 5c. Load Address Low Byte 0000011_bbbbb bbb xxxxxxx_xxxxxxxx 0110011_bbbbbbbb xxxxxxx_xxxxxxxx 5d. Read Data Byte 0110010_00000000 xxxxxxx_xxxxxxxx 0110011_00000000 xxxxxxx_oooooooo 6a. Enter Fuse Write 0100011_01000000 xxxxxxx_xxxxxxxx 6b. Load Data Low Byte 0010011_iiiiiiii xxxxxxx_xxxxxxxx (3)(6) 0111011_00000000 xxxxxxx_xxxxxxxx 0111001_00000000 xxxxxxx_xxxxxxxx 6c. Write Fuse Extended Byte (1) 0111011_00000000 xxxxxxx_xxxxxxxx 0111011_00000000 xxxxxxx_xxxxxxxx 6d. Poll for Fuse Write Complete 0110111_00000000 xxxxxox_xxxxxxxx (2) 6e. Load Data Low Byte 0010011_iiiiiiii xxxxxxx_xxxxxxxx (3)(7) 0110111_00000000 xxxxxxx_xxxxxxxx 0110101_00000000 xxxxxxx_xxxxxxxx 6f. Write Fuse High Byte (1) 0110111_00000000 xxxxxxx_xxxxxxxx 0110111_00000000 xxxxxxx_xxxxxxxx 6g. Poll for Fuse Write Complete 0110111_000000 00 xxxxxox_xxxxxxxx (2) 6h. Load Data Low Byte 0010011_iiiiiiii xxxxxxx_xxxxxxxx (3)(8) 0110011_00000000 xxxxxxx_xxxxxxxx 0110001_00000000 xxxxxxx_xxxxxxxx 6i. Write Fuse Low Byte (1) 0110011_00000000 xxxxxxx_xxxxxxxx 0110011_00000000 xxxxxxx_xxxxxxxx 6j. Poll for Fuse Write Complete 0110011_00000000 xxxxxox_xxxxxxxx (2) 7a. Enter Lock Bit Write 0100011_00100000 xxxxxxx_xxxxxxxx ATmega256/128/64RFR2 530 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 Instruction TDI Sequence TDO Sequence Notes 7b. Load Data Byte 0010011_11iiiiii xxxxxxx_xxxxxxxx (4)(9) 0110011_00000000 xxxxxxx_xxxxxxxx 0110001_000000 00 xxxxxxx_xxxxxxxx 7c. Write Lock Bits (1) 0110011_00000000 xxxxxxx_xxxxxxxx 0110011_00000000 xxxxxxx_xxxxxxxx 7d. Poll for Lock Bit Write complete 0110011_00000000 xxxxxox_xxxxxxxx (2) 8a. Enter Fuse/Lock Bit Read 0100011_00000100 xxxxxxx_xxxxxxxx 0111010_00000000 xxxxxxx_xxxxxxxx 8b. Read Extended Fuse Byte (6)(5) 0111011_00000000 xxxxxxx_oooooooo 0111110_00000000 xxxxxxx_xxxxxxxx 8c. Read Fuse High Byte (7)(5) 0111111_00000000 xxxxxxx_oooooooo 0110010_00000000 xxxxxxx_xxxxxxxx 8d. Read Fuse Low Byte (8)(5) 0110011_00000000 xxxxxxx_oooooooo 0110110_00000000 xxxxxxx_xxxxxxxx 8e. Read Lock Bits (9)(5) 0110111_00000000 xxxxxxx_xxoooooo 0111010_00000000 xxxxxxx_xxxxxxxx (5) 0111110_00000000 xxxxxxx_oooooooo Fuse Ext. byte 8f. Read Fuses and Lock Bits 0110010_00000000 xxxxxxx_oooooooo Fuse High byte 0110110_00000000 xxxxxxx_oooooooo Fuse Low byte 0110111_00000000 xxxxxxx_oooooooo Lock bits 9a. Enter Signature Byte Read 0100011_00001000 xxxxxxx_xxxxxxxx 9b. Load Address Byte 0000011_bbbbbbbb xxxxxxx_xxxxxxxx 0110010_00000000 xxxxxxx_xxxxxxxx 9c. Read Signature Byte 0110011_00000000 xxxxxxx_oooooooo 9d. Enter User Signature Page Write 0100011_00010010 xxxxxxx_xxxxxxxx (12) 9e. Enter User Signature Page Erase 0100011_100001 00 xxxxxxx_xxxxxxxx (12) 10a. Enter Calibration Byte Read 0100011_00001000 xxxxxxx_xxxxxxxx 10b. Load Address Byte 0000011_bbbbbbbb xxxxxxx_xxxxxxxx 0110110_00000000 xxxxxxx_xxxxxxxx 10c. Read Calibration Byte 0110111_00000000 xxxxxxx_oooooooo 0100011_00000000 xxxxxxx_xxxxxxxx 11a. Load No Operation Command 0110011_00000000 xxxxxxx_xxxxxxxx 531 8393C-MCU Wireless-09/14

Notes: 1. This command sequence is not required if the seven MSB’s are correctly set by the previous command sequence (which is normally the case). 2. Repeat until o = “1”. 3. Set bits to “0” to program the corresponding Fuse, “1” to un-program the Fuse. 4. Set bits to “0” to program the corresponding Lock bit, “1” to leave the Lock bit unchanged. 5. “0” = programmed, “1” = un-programmed. 6. The bit mapping for Fuses Extended byte is listed in Table 31-3 on page 505. 7. The bit mapping for Fuses High byte is listed in Table 31-4 on page 505. 8. The bit mapping for Fuses Low byte is listed in Table 31-5 on page 506. 9. The bit mapping for Lock bits byte is listed in Table 31-1 on page 504. 10. Address bits exceeding PCMSB and EEAMSB (Table 31-7 on page 507 and Table 31-8 on page 507) are don’t care. 11. All TDI and TDO sequences are represented by binary digits. 12. See "User Signature Data" on page 507. Figure 31-19. State Machin e Sequence for Changing/Reading the Data Word 1 Test-Logic-Reset 0 0 Run-Test/Idle 1 Select-DR Scan 1 Select-IR Scan 1 0 0 1 1 Capture-DR Capture-IR 0 0 Shift-DR 0 Shift-IR 0 1 1 1 1 Exit1-DR Exit1-IR 0 0 Pause-DR 0 Pause-IR 0 1 1 0 0 Exit2-DR Exit2-IR 1 1 Update-DR Update-IR 1 0 1 0 ATmega256/128/64RFR2 532 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 31.10.11 Flash Data Byte Register The Flash Data Byte Register provides an efficient way to load the entire Flash page buffer before executing Page Write, or to read out/verify the content of the Flash. A state machine sets up the control signals to the Flash and senses the strobe signals from the Flash, thus only the data words need to be shifted in/out. The Flash Data Byte Register actually consists of the 8-bit scan chain and an 8-bit temporary register. During page load, the Update-DR state copies the content of the scan chain over to the temporary register and initiates a write sequence that within 11 TCK cycles loads the content of the temporary register into the Flash page buffer. The AVR automatically alternates between writing the low and the high byte for each new Update-DR state, starting with the low byte for the first Update-DR encountered after entering the PROG_PAGEL OAD command. The Program Counter is pre-incremented before writing the low byte, except for the first written byte. This ensures that the first data is written to the address set up by PROG_COMMANDS, and loading the last location in the page buffer does not make the Program Counter increment into the next page. During Page Read, the con tent of the selected Flash byte is captured into the Flash Data Byte Register during the Capture-DR state. The AVR automatically alternates between reading the low and the high byte for each new Capture-DR state, starting with the low byte for the first Capture-DR encountered after entering the PROG_PAGEREAD command. The Program Counter is post-incremented after reading each high byte, including the first read byte. This ensures that the first data is captured from the first address set up by PROG_COMMANDS, and reading the last location in the page makes the program counter increment into the next page. Figure 31-20. Flash Data Byte Register STROBES State(cid:13) Machine TDI ADDRESS Flash(cid:13) EEPROM(cid:13) Fuses(cid:13) Lock Bits D(cid:13) A(cid:13) T(cid:13) A TDO The state machine controlling the Flash Data Byte Register is clocked by TCK. During normal operation in which e ight bits are shifted for each Flash byte, the clock cycles needed to navigate through the TAP-controller automatically feeds the state machine for the Flash Data Byte Register with sufficient number of clock pulses to complete its operation transparently for the user. However, if too few bits are shifted between each Update-DR state during page load, the TAP-controller should stay in the Run-Test/Idle state for some TCK cycles to ensure that there are at least 11 TCK cycles between each Update-DR state. 533 8393C-MCU Wireless-09/14

31.10.12 Programming Algorithm All references below of type “1a”, “1b”, and so on, refer to Table 31-19 on page 529. 31.10.13 Entering Programming Mode 7. Enter JTAG instruction AVR_RESET and shift 1 in the Reset Register. 8. Enter instruction PROG_ENABLE and shift 0b1010_0011_0111_0000 in the Programming Enable Register. 31.10.14 Leaving Programming Mode 1. Enter JTAG instruction PROG_COMMANDS. 2. Disable all programming instructions by using no operation instruction 11a. 3. Enter instruction PROG_ENABLE and shift 0b0000_0000_0000_0000 in the programming Enable Register. 4. Enter JTAG instruction AVR_RESET and shift 0 in the Reset Register. 31.10.15 Performing Chip Erase 1. Enter JTAG instruction PROG_COMMANDS. 2. Start Chip Erase using programming instruction 1a. 3. Poll for Chip Erase complete using programming instruction 1b, or wait for t WLRH_CE (refer to Table 31-15 on page 520). 31.10.16 Programming the Flash Before programming the Flash a Chip Erase must be performed, see section "Performing Chip Erase" above. 1. Enter JTAG instruction PROG_COMMANDS. 2. Enable Flash write using programming instruction 2a. 3. Load Extended High byt e of address using programming instruction 2b. 4. Load High byte of address using programming instruction 2c. 5. Load Low byte of address using programming instruction 2d. 6. Load data using programming instructions 2e, 2f and 2g. 7. Repeat steps 5 and 6 for all instruction words in the page. 8. Write the page using programming instruction 2h. 9. Poll for Flash write complete using programming instruction 2i, or wait for t (refer WLRH to Table 31-15 on page 5 20). 10. Repeat steps 4 to 9 until all data have been programmed. A more efficient data transfer can be achieved using the PROG_PAGELOAD instruction: 1. Enter JTAG instruction PROG_COMMANDS. 2. Enable Flash write using programming instruction 2a. 3. Load the page address using programming instructions 2b, 2c and 2d. PCWORD (refer to Table 31-7 on page 507) is used to address within one page and must be written as 0. 4. Enter JTAG instruction PROG_PAGELOAD. 5. Load the entire page by shifting in all instruction words in the page byte-by-byte, starting with the LSB of the first instruction in the page and ending with the MSB of the last instruction in the page. Use Update-DR to copy the contents of the Flash ATmega256/128/64RFR2 534 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 Data Byte Register into the Flash page location and to auto-increment the Program Counter before each new word. 6. Enter JTAG instruction PROG_COMMANDS. 7. Write the page using programming instruction 2h. 8. Poll for Flash write complete using programming instruction 2i, or wait for t (refer WLRH to Table 31-15 on page 520). 9. Repeat steps 3 to 8 until all data have been programmed. 31.10.17 Reading the Flash 1. Enter JTAG instruction PROG_COMMANDS. 2. Enable Flash read using programming instruction 3a. 3. Load address using programming instructions 3b, 3c and 3d. 4. Read data using programming instruction 3e. 5. Repeat steps 3 and 4 until all data have been read. A more efficient data transfer can be achieved using the PROG_PAGEREAD instruction: 1. Enter JTAG instruction PROG_COMMANDS. 2. Enable Flash read using programming instruction 3a. 3. Load the page address using programming instructions 3b, 3c and 3d. PCWORD (refer to Table 31-7 on page 507) is used to address within one page and must be written as 0. 4. Enter JTAG instruction PROG_PAGEREAD. 5. Read the entire page (or Flash) by shifting out all instruction words in the page (or Flash), starting with the LSB of the first instruction in the page (Flash) and ending with the MSB of the last instruction in the page (Flash). The Capture-DR state both captures the data from the Flash, and also auto-increments the program counter after each word is read. Note that Capture-DR comes before the shift-DR state. Hence, the first byte whic h is shifted out contains valid data. 6. Enter JTAG instruction PROG_COMMANDS. 7. Repeat steps 3 to 6 until all data have been read. 31.10.18 Programming the EEPROM The EEPROM must be erased before being programmed. A Chip Erase always erases both Flash and EEPROM memories, see "Performing Chip Erase" on page 534. 1. Enter JTAG instruction P ROG_COMMANDS. 2. Enable EEPROM write using programming instruction 4a. 3. Load High byte of address using programming instruction 4b. 4. Load Low byte of address using programming instruction 4c. 5. Load data using programming instructions 4d and 4e. 6. Repeat steps 4 and 5 for all data bytes in the page. 7. Write the data using programming instruction 4f. 8. Poll for EEPROM write complete using programming instruction 4g, or wait for t WLRH (refer to Table 31-15 on page 520). 9. Repeat steps 3 to 8 until all data have been programmed. Note that the PROG_PAGELOAD instruction can not be used when programming the EEPROM. 535 8393C-MCU Wireless-09/14

31.10.19 Reading the EEPROM 1. Enter JTAG instruction PROG_COMMANDS. 2. Enable EEPROM read using programming instruction 5a. 3. Load address using programming instructions 5b and 5c. 4. Read data using programming instruction 5d. 5. Repeat steps 3 and 4 until all data have been read. Note that the PROG_PAGEREAD instruction can not be used when reading the EEPROM. 31.10.20 Programming the Fuses 1. Enter JTAG instruction PROG_COMMANDS. 2. Enable Fuse write using programming instruction 6a. 3. Load data high byte using programming instructions 6b. A bit value of “0” will program the corresponding fuse; a “1” will un-program the fuse. 4. Write Fuse High byte using programming instruction 6c. 5. Poll for Fuse write complete using programming instruction 6d, or wait for t WLRH (refer to Table 31-15 on page 520). 6. Load data low byte using programming instructions 6e. A “0” will program the fuse, a “1” will un-program the fuse. 7. Write Fuse low byte using programming instruction 6f. 8. Poll for Fuse write complete using programming instruction 6g, or wait for t WLRH (refer to Table 31-15 on page 520). 31.10.21 Programming the Lock Bits 1. Enter JTAG instruction PROG_COMMANDS. 2. Enable Lock bit write using programming instruction 7a. 3. Load data using progra mming instructions 7b. A bit value of “0” will program the corresponding lock bit, a “1” will leave the lock bit unchanged. 4. Write Lock bits using programming instruction 7c. 5. Poll for Lock bit write complete using programming instruction 7d, or wait for t WLRH (refer to Table 31-15 on page 520). 31.10.22 Reading the Fuses and Lock Bits 1. Enter JTAG instruction PROG_COMMANDS. 2. Enable Fuse/Lock bit read using programming instruction 8a. 3. To read all Fuses and Lock bits, use programming instruction 8e. To only read Fuse High byte, use programming instruction 8b. To only read Fuse Low byte, use programming instruction 8c. To only read Lock bits, use programming instruction 8d. 31.10.23 Reading the Signature Bytes 1. Enter JTAG instruction PROG_COMMANDS. 2. Enable Signature byte read using programming instruction 9a. 3. Load address 0x00 using programming instruction 9b. 4. Read first signature byte using programming instruction 9c. ATmega256/128/64RFR2 536 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 5. Repeat steps 3 and 4 with address 0x01 and address 0x02 to read the second and third signature bytes, respectively. 31.10.24 Reading the Calibration Byte 1. Enter JTAG instruction PROG_COMMANDS. 2. Enable Calibration byte read using programming instruction 10a. 3. Load address 0x00 using programming instruction 10b. 4. Read the calibration byte using programming instruction 10c. 31.10.25 Performing Chip Erase of only the EEPROM The EEPROM must be erased before being programmed. A Chip Erase always erases both Flash and EEPROM memories, see "Performing Chip Erase" on page 534. This command allows erasing only the EEPROM contents. The Flash, Lock and Fuse bits are not changed. 1. Enter JTAG instruction P ROG_COMMANDS. 2. Start EEPROM Chip Erase using programming instruction 1c. 3. Poll for Chip Erase complete using programming instruction 1b, or wait for t WLRH (refer to Table 31-15 on page 520). Note: 13. The EEPROM memory is also preserved during this special Chip Erase if the EESAVE Fuse is programmed. 31.10.26 Erasing an EEPROM Page The EEPROM must be erased before being programmed. A Chip Erase always erases the entire EEPROM memory. This command allows erasing selected bytes up to an entire page of EEPROM memory. 1. Enter JTAG instruction PROG_COMMANDS. 2. Enable EEPROM erase using programming instruction 4h. 3. Load High byte of address using programming instruction 4b. 4. Load Low byte of address using programming instruction 4c. 5. Latch the address using programming instructions 4e. 6. Repeat steps 4 and 5 for all data bytes in the page. 7. Erase the data using pro g ramming instruction 4f. 8. Poll for EEPROM write complete using programming instruction 4g, or wait for t WLRH (refer to Table 31-15 on page 520). 9. Repeat steps 3 to 8 until all data have been erased. Note that the PROG_PAGELOAD instruction can not be used when programming the EEPROM. Note: 1. The EEPROM memory is not preserved during the EEPROM page erase if the EESAVE Fuse is programmed. 537 8393C-MCU Wireless-09/14

31.10.27 Programming User Signature Data Three Flash pages are dedicated for user signature data (see "User Signature Data" on page 507 for details). Before programming the user signature pages a Page Erase must be performed, see section " Erasing User Signature Data" below. 1. Enter JTAG instruction PROG_COMMANDS. 2. Enable user signature page write using programming instruction 9d. 3. Load High byte of address using programming instruction 2c (0x01, 0x02 or 0x03). 4. Load Low byte of address using programming instruction 2d. 5. Load data using programming instructions 2e, 2f and 2g. 6. Repeat steps 4 and 5 for all instruction words in the page. 7. Write the user signature page using programming instruction 2h. 8. Poll for Flash write complete using programming instruction 2i, or wait for t (refer WLRH to Table 31-15 on page 520). 9. Repeat steps 4 to 9 until all user signature data have been programmed. A more efficient data tra nsfer can be achieved using the PROG_PAGELOAD instruction: 1. Enter JTAG instruction PROG_COMMANDS. 2. Enable user signature page write using programming instruction 9d. 3. Load the page address using programming instructions 2c and 2d. PCWORD (refer to Table 31-7 on page 507) is used to address within one page and must be written as 0. 4. Enter JTAG instruction P ROG_PAGELOAD. 5. Load the entire page by shifting in all instruction words in the page byte-by-byte, starting with the LSB of the first instruction in the page and ending with the MSB of the last instruction in the page. Use Update-DR to copy the contents of the Flash Data Byte Register into the Flash page location and to auto-increment the Program Counter before each new word. 6. Enter JTAG instruction PROG_COMMANDS. 7. Write the user signature page using programming instruction 2h. 8. Poll for Flash write complete using programming instruction 2i, or wait for t (refer WLRH to Table 31-15 on page 520). 9. Repeat steps 3 to 8 until all user signature data have been programmed. 31.10.28 Erasing User Signature Data Three Flash pages are dedicated for user signature data (see "User Signature Data" on page 507 for details). User signature pages must be erased before being written. A Flash Chip Erase (see section "Performing Chip Erase" on page 534) does not clear the contents of signature pages. Erasing user signature data is performed with the following command sequence. 1. Enter JTAG instruction PROG_COMMANDS. 2. Enable user signature page erase using programming instruction 9e. 3. Load High byte of address using programming instruction 2c (0x01, 0x02 or 0x03). 4. Load Low byte of address using programming instruction 2d. 5. Latch the page address using programming instructions 2g. 6. Erase the user signature page using programming instruction 2h. ATmega256/128/64RFR2 538 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 7. Poll for Flash write complete using programming instruction 2i, or wait for t (refer WLRH to Table 31-15 on page 520). 8. Repeat steps 4 to 7 until all user signature data have been erased. 31.10.29 Reading User Signature Data The algorithm for reading User Signature Data is similar to read from Flash. 1. Enter JTAG instruction PROG_COMMANDS. 2. Enable Signature read using programming instruction 9a. 3. Load address using programming instructions 3c and 3d. 4. Read data using programming instruction 3e. 5. Repeat steps 3 and 4 un t il all data have been read. A more efficient data transfer can be achieved using the PROG_PAGEREAD instruction: 1. Enter JTAG instruction PROG_COMMANDS. 2. Enable Signature read using programming instruction 9a. 3. Load the page address using programming instructions 3c and 3d. PCWORD (refer to Table 31-7 on page 507) is used to address within one page and must be written as 0. 4. Enter JTAG instruction PROG_PAGEREAD. 5. Read the entire User Signature page (or all three pages) by shifting out all instruction words in the page, starting with the LSB of the first instruction in the page and ending with the MSB of the last instruction in the page (or last User Signature page). The Capture-DR s tate both captures the data from the Flash, and also auto- increments the program counter after each word is read. Note that Capture-DR comes before the shift-DR state. Hence, the first byte which is shifted out contains valid data. 6. Enter JTAG instruction PROG_COMMANDS. 7. Repeat steps 3 to 6 until all data have been read. 539 8393C-MCU Wireless-09/14

32 Application Circuits 32.1 Basic Application Schematic A basic application schematic of the ATmega256/128/64RFR2 with a single-ended RF connector is shown in Figure 32-1 below and the associated Bill of Material in Table 32- 1 on page 541. The 50Ω single-ended RF input is transformed to the 100Ω differential RF port impedance using Balun B1. The capacitors C1 and C2 provide AC coupling of the RF input to the RF port, capacitor C4 improves matching. Figure 32-1. Basic Application schematic (64-pin package) CX1 CX2 XTAL CB2 VDD CB1 64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 21 PF0 AREF AVSS AVDD EVDD AVSS XTAL1 XTAL2 DVSS DEVDD PE7 4478 3 PE0 46 4 DVSS 45 5 DEVDD 44 6 PF7 PB7 43 C1 7 AVSS 42 RF 8 RFP 41 B1 C4 9 RFN 40 C2 10 AVSS 39 11 TST 38 12 RSTN 37 Pins TST & CLKI 13 RSTON PB0 36 must be connected 14 PG0 DVSS 35 15 DEVDD 34 D S D D D S 16 5 S D D V S 0 7 33 CLKI G V V V E V D D P D D D D D P P 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 CB3 CB4 VDD XTAL CX3 32kHz CX4 The power supply bypass capacitors (CB2, CB4) are connected to the external analog supply pin (EVDD, pin 59) and external digital supply pin (DEVDD, pin 23). Pins 34, 44 and 54 supply the digital port pins. Floating pins can cause e xcessive power dissipation (e.g. during power on). They should be connected to an appropriate source. GPIO shall not be connected to ground or power supply directly. The digital input pins TST and CLKI must be connected. If pin TST will never be used it can be connected to AVSS while an unused pin CLKI could be connected to DVSS (see chapter "Unused Pins" on page 7). Capacitors CB1 and CB3 are bypass capacitors for the integrated analog and digital voltage regulators to ensure stable operation and to improve noise immunity. ATmega256/128/64RFR2 540 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 Capacitors should be placed as close as possible to the pins and should have a low- resistance and low-inductance connection to ground to achieve the best performance. The crystal (XTAL), the two load capacitors (CX1, CX2), and the internal circuitry connected to pins XTAL1 and XTAL2 form the 16MHz crystal oscillator for the 2.4GHz transceiver. To achieve the best accuracy and stability of the reference frequency, large parasitic capacitances must be avoided. Crystal lines should be routed as short as possible and not in proximity of digital I/O signals. This is especially required for the High Data Rate Modes. The 32.768 kHz crystal connected to the internal low power (sub 1µA) crystal oscillator provides a stable time reference for all low power modes including 32 Bit IEEE 802.15.4 Symbol Counter ("MAC Symbol Counter" on page 157) and real time clock application using the asynchronous timer T/C2 ("8-bit Timer/Counter2 with PWM and Asynchronous Operation" on page 341). Total shunt capacitance including CX3, CX4 should not exceed 15pF across both pins. The very low supply current of the oscillator requires careful layout of the PCB and any leakage path must be avoided. Crosstalk and radiation from switching digital signals to the crystal pins or the RF pins can degrade the system p erformance. The programming of minimum drive strength settings for the digital output signal is recommended (see "DPDS0 – Port Driver Strength Register 0" on page 206). Table 32-1. Bill of Materials (BoM) Designator Description Value Manufacturer Part Number Comment B1 SMD balun 2.4 GHz Wuerth 748421245 SMD balun / filter Johanson 2450FB15L0001 Filter included Tech nology CB1 LDO VREG 1 µF AVX 0603YD105KAT2A X5R 10% 16V CB3 bypass capacitor (100nF minimum) Murata GRM188R61C105KA12D (0603) CB2 Power supply bypass 1 µF CB4 capacitor (100nF minimum) CX1, CX2 16MHz crystal load 12 pF AVX 06035A120JA COG 5% 50V capacitor Murata GRP1886C1H120JA01 (0603) CX3, CX4 32.768kHz crystal load 12 … 25 pF capacitor C1, C2 RF coupling capacitor 22 pF Epcos B37930 C0G 5% 50V Epcos B37920 (0402 or 0603) AVX 06035A220JAT2A C4 (optional) RF matching 0.47 pF Johnstech XTAL Crystal CX-4025 16 MHz ACAL Taitjen XWBBPL-F-1 SX-4025 16 MHz Siward A207-011 XTAL 32kHz Crystal Rs=100 kOhm 32.2 Extended Feature Set Application Schematic The ATmega256/128/64RFR2 supports additional features like: • Security Module (AES) • High Data Rate Mode up to 2MBits/s • Antenna Diversity using alternate pin function DIG1/2 at Port G and F 541 8393C-MCU Wireless-09/14

• RX/TX Indicator using alternate pin function DIG3/4 at Port G and F An extended feature set application schematic illustrating the use of the ATmega256/128/64RFR2 Extended Feature Set, is shown in Figure 32-2 below. Figure 32-2. Extended Feature Application schematic CX1 CX2 XTAL CB2 VDD CB1 64 63 6 2 61 60 59 58 57 56 55 54 53 52 51 50 49 0 F S D D S 1 2 S D 7 1 PF ARE AVS AVD EVD AVS XTAL XTAL DVS DEVD PE 48 2 47 3 PE0 46 4 DVSS 45 ANT0 5 DEVDD 44 6 PF7 PB7 43 N2 7 AVSS 42 LNA SW2 RF-Switch PA RF-Switch Balun 89 RRFFPN 4401 N1 10 AVSS 39 SW1 B1 11 TST 38 12 RSTN 37 ANT1 13 RSTON PB0 36 14 PG0 DVSS 35 15 DEVDD 34 D S D D D S 16 5 S D D V S 0 7 33 CLKI G V V V E V D D P D D D D D P P Pins TST & CLKI 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 must be connected CB3 CB4 VDD XTAL CX3 32kHz CX4 Although this example show s all additional hardware features combined, it is possible to use all features separately or in various combinations. ATmega256/128/64RFR2 542 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 33 Register Summary Address Name Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0 Page (0x1FF) TRXFBEND TRXFBEND7 TRXFBEND6 TRXFBEND5 TRX FBEND4 TRXFBEND3 TRXFBEND2 TRXFBEND1 TRXFBEND0 156 ... (0x180) TRXFBST TRXFBST7 TRXFBST6 TRXFBST5 TRXFBST4 TRXFBST3 TRXFBST2 TRXFBST1 TRXFBST0 156 (0x17F) Reserved Res7 Res6 Res5 Res4 Res3 Res2 Res1 Res0 (0x17E) Reserved Res7 Res6 Res5 Res4 Res3 Res2 Res1 Res0 (0x17D) TST_SDM MOD_SEL MOD TX_RX TX_RX_SEL Res3 Res2 Res1 Res0 155 (0x17C) TST_AGC Res1 Res0 AGC_HOLD_SEL AGC_RST AGC_OFF AGC_HOLD GC1 GC0 154 (0x17B) TST_RX_LENGTH RX_LENGTH7 RX_LENGTH6 RX_LENGTH5 RX_LENGTH4 RX_LENGTH3 RX_LENGTH2 RX_LENGTH1 RX_LENGTH0 154 (0x17A) Reserved Res7 Res6 Res5 Res4 Res3 Res2 Res1 Res0 (0x179) Reserved Res7 Res6 Res5 Res4 Res3 Res2 Res1 Res0 (0x178) Reserved Res7 Res6 Res5 R es4 Res3 Res2 Res1 Res0 (0x177) Reserved Res7 Res6 Res5 Res4 Res3 Res2 Res1 Res0 (0x176) TST_CTRL_DIGI Res7 Res6 Res5 Res4 TST_CTRL_DIG3 TST_CTRL_DIG2 TST_CTRL_DIG1 TST_CTRL_DIG0 153 (0x175) Reserved Res7 Res6 Res5 Res4 Res3 Res2 Res1 Res0 ... (0x173) Reserved Res7 Res6 Res5 Res4 Res3 Res2 Res1 Res0 (0x172) Reserved Res7 Res6 Res5 Res4 Res3 Res2 Res1 Res0 (0x171) Reserved Res7 Res6 Res5 Res4 Res3 Res2 Res1 Res0 (0x170) Reserved Res7 Res6 Res5 Res4 Res3 Res2 Res1 Res0 (0x16F) CSMA_BE MAX_BE3 MAX_BE2 MAX_BE1 MAX_BE0 MIN_BE3 MIN_BE2 MIN_BE1 MIN_BE0 145 (0x16E) CSMA_SEED_1 AACK_FVN_MODE1 AACK_FVN_MODE0 AACK_SET_PD AACK_DIS_ACK AACK_I_AM_COORD CSMA_SEED_12 CSMA_SEED_11 CSMA_SEED_10 144 (0x16D) CSMA_SEED_0 CSMA_SEED_07 CSMA_SEED_06 CSMA_SEED_05 CSMA_SEED_04 CSMA_SEED_03 CSMA_SEED_02 CSMA_SEED_01 CSMA_SEED_00 144 (0x16C) XAH_CTRL_0 MAX_FRAME_RETRIES3 MAX_FRAME_RETRIES2 MAX_FRAME_RETRIES1 MAX_FRAME_RETRIES0 MAX_CSMA_RETRIES2 MAX_CSMA_RETRIES1 MAX_CSMA_RETRIES0 SLOTTED_OPERATION 142 (0x16B) IEEE_ADDR_7 IEEE_ADDR_77 IEEE_ADDR_76 IEEE_ADDR_75 IEEE_ADDR_74 IEEE_ADDR_73 IEEE_ADDR_72 IEEE_ADDR_71 IEEE_ADDR_70 142 (0x16A) IEEE_ADDR_6 IEEE_ADDR_67 IEEE_ADDR_66 IEEE_ADDR_65 IEEE_ADDR_64 IEEE_ADDR_63 IEEE_ADDR_62 IEEE_ADDR_61 IEEE_ADDR_60 142 (0x169) IEEE_ADDR_5 IEEE_ADDR_57 IEEE_ADDR_56 IEEE_ADDR_55 IEEE_ADDR_54 IEEE_ADDR_53 IEEE_ADDR_52 IEEE_ADDR_51 IEEE_ADDR_50 141 (0x168) IEEE_ADDR_4 IEEE_ADDR_47 IEEE_ADDR_46 IEEE_ADDR_45 IEEE_ADDR_44 IEEE_ADDR_43 IEEE_ADDR_42 IEEE_ADDR_41 IEEE_ADDR_40 141 (0x167) IEEE_ADDR_3 IEEE_ADDR_37 IEEE_ADDR_36 IEEE_ADDR_35 IEEE_ADDR_34 IEEE_ADDR_33 IEEE_ADDR_32 IEEE_ADDR_31 IEEE_ADDR_30 141 (0x166) IEEE_ADDR_2 IEEE_ADDR_27 IEEE_ADDR_26 IEEE_ADDR_25 IEEE_ADDR_24 IEEE_ADDR_23 IEEE_ADDR_22 IEEE_ADDR_21 IEEE_ADDR_20 140 (0x165) IEEE_ADDR_1 IEEE_ADDR_17 IEEE_ADDR_16 IEEE_ADDR_15 IEEE_ADDR_14 IEEE_ADDR_13 IEEE_ADDR_12 IEEE_ADDR_11 IEEE_ADDR_10 140 (0x164) IEEE_ADDR_0 IEEE_ADDR_07 IEEE_ADDR_06 IEEE_ADDR_05 IEEE_ADDR_04 IEEE_ADDR_03 IEEE_ADDR_02 IEEE_ADDR_01 IEEE_ADDR_00 140 (0x163) PAN_ID_1 PAN_ID_17 PAN_ID_16 PAN_ID_15 PAN_ID_14 PAN_ID_13 PAN_ID_12 PAN_ID_11 PAN_ID_10 140 (0x162) PAN_ID_0 PAN_ID_07 PAN_ID_06 PAN_ID_05 PAN_ID_04 PAN_ID_03 PAN_ID_02 PAN_ID_01 PAN_ID_00 139 (0x161) SHORT_ADDR_1 SHORT_ADDR_17 SHORT_ADDR_16 SHORT_ADDR_15 SHORT _ADDR_14 SHORT_ADDR_13 SHORT_ADDR_12 SHORT_ADDR_11 SHORT_ADDR_10 139 (0x160) SHORT_ADDR_0 SHORT_ADDR_07 SHORT_ADDR_06 SHORT_ADDR_05 SHORT_ADDR_04 SHORT_ADDR_03 SHORT_ADDR_02 SHORT_ADDR_01 SHORT_ADDR_00 139 (0x15F) MAN_ID_1 MAN_ID_17 MAN_ID_16 MAN_ID_15 MAN_ID_14 MAN_ID_13 MAN_ID_12 MAN_ID_11 MAN_ID_10 138 (0x15E) MAN_ID_0 MAN_ID_07 MAN_ID_06 MAN_ID_05 MAN_ID_04 MAN_ID_03 MAN_ID_02 MAN_ID_01 MAN_ID_00 138 (0x15D) VERSION_NUM VERSION_NUM7 VERSION_NUM6 VERSION_NUM5 VERSION_NUM4 VERSION_NUM3 VERSION_NUM2 VERSION_NUM1 VERSION_NUM0 138 (0x15C) PART_NUM PART_NUM7 PART_NUM6 PART_NUM5 PART_NUM4 PART_NUM3 PART_NUM2 PART_NUM1 PART_NUM0 137 (0x15B) PLL_DCU PLL_DCU_START Res6 Res5 Res4 Res3 Res2 Res1 Res0 135 (0x15A) PLL_CF PLL_CF_START Res6 Res5 Res4 Res3 Res2 Res1 Res0 134 (0x159) Reserved Res7 Res6 Res5 Res4 Res3 Res2 Res1 Res0 (0x158) FTN_CTRL FTN_START Res6 Res5 Res4 Res3 Res2 Res1 Res0 134 (0x157) XAH_CTRL_1 Res1 Res0 AACK_FLTR_RES_FT AACK_U PLD_RES_FT Res AACK_ACK_TIME AACK_PROM_MODE Res 133 (0x156) TRX_RPC RX_RPC_CTRL1 RX_RPC_CTRL0 RX_RPC_EN PDT_RPC_EN PLL_RPC_EN Res0 IPAN_RPC_EN Res0 136 (0x155) RX_SYN RX_PDT_DIS RX_OVERRIDE RXO_CFG1 RXO_CFG0 RX_PDT_LEVEL3 RX_PDT_LEVEL2 RX_PDT_LEVEL1 RX_PDT_LEVEL0 131 (0x154) CC_CTRL_1 CC_BAND3 CC_BAND2 CC_BAND1 CC_BAND0 136 (0x153) CC_CTRL_0 CC_NUMBER7 CC_NUMBER6 CC_NUMBER5 CC_NUMBER4 CC_NUMBER3 CC_NUMBER2 CC_NUMBER1 CC_NUMBER0 136 (0x152) XOSC_CTRL XTAL_MODE3 XTAL_MODE2 XTAL_MODE1 XTAL_MODE0 XTAL_TRIM3 XTAL_TRIM2 XTAL_TRIM1 XTAL_TRIM0 131 (0x151) BATMON BAT_LOW BAT_LOW_EN BATMON_OK BATMON_HR BATMON_VTH3 BATMON_VTH2 BATMON_VTH1 BATMON_VTH0 129 (0x150) VREG_CTRL AVREG_EXT AVDD_OK Res5 Res4 DVREG_EXT DVDD_OK Res1 Res0 128 (0x14F) IRQ_STATUS AWAKE TX_END AMI CCA_ED_DONE RX_END RX_START PLL_UNLOCK PLL_LOCK 127 (0x14E) IRQ_MASK AWAKE_EN TX_END_EN AMI_EN CCA_ED_DONE_EN RX_END_EN RX_START_EN PLL_UNLOCK_EN PLL_LOCK_EN 126 (0x14D) ANT_DIV ANT_SEL Res2 Res1 Res0 ANT_DIV_EN ANT_EXT_SW_EN ANT_CTRL1 ANT_CTRL0 124 (0x14C) TRX_CTRL_2 RX_SAFE_MODE Res4 Res3 Res2 Res1 Res0 OQPSK_DATA_RATE1 OQPSK_DATA_RATE0 124 (0x14B) SFD_VALUE SFD_VALUE7 SFD_VALUE6 SFD_VALUE5 SFD_VALUE4 SFD_VALUE3 SFD_VALUE2 SFD_VALUE1 SFD_VALUE0 123 (0x14A) RX_CTRL Res7 Res6 Res5 Res4 PDT_THRES3 PDT_THRES2 PDT_THRES1 PDT_THRES0 122 (0x149) CCA_THRES CCA_CS_THRES3 CCA_CS_THRES2 CCA_CS_THRES1 CCA_CS_THRES0 CCA_ED_THRES3 CCA_ED_THRES2 CCA_ED_THRES1 CCA_ED_THRES0 121 (0x148) PHY_CC_CCA CCA_REQUEST CCA_MODE1 CCA_MODE0 CHANNEL4 CHANNEL3 CHANNEL2 CHANNEL1 CHANNEL0 120 (0x147) PHY_ED_LEVEL ED_LEVEL7 ED_LEVEL6 ED_LEVEL5 ED_LEVEL4 ED_LEVEL3 ED_LEVEL2 ED_LEVEL1 ED_LEVEL0 120 (0x146) PHY_RSSI RX_CRC_VALID RND_VALUE1 RND_VALUE0 RSSI4 RSSI3 RSSI2 RSSI1 RSSI0 119 543 8393C-MCU Wireless-09/14

Address Name Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0 Page (0x145) PHY_TX_PWR Res3 Res2 Res1 Res0 TX_PWR3 TX_PWR2 TX_PWR1 TX_PWR0 117 (0x144) TRX_CTRL_1 PA_EXT_EN IRQ_2_EXT_EN TX_AUTO_CRC_ON PLL_TX_FLT Res3 Res2 Res1 Res0 116 (0x143) TRX_CTRL_0 Res7 PMU_EN PMU_START PMU_IF_INV Res3 Res2 Res1 Res0 116 (0x142) TRX_STATE TRAC_STATUS2 TRAC_STATUS1 TRAC_STATUS0 TR X_CMD4 TRX_CMD3 TRX_CMD2 TRX_CMD1 TRX_CMD0 114 (0x141) TRX_STATUS CCA_DONE CCA_STATUS TST_STATUS TRX_STATUS4 TRX_STATUS3 TRX_STATUS2 TRX_STATUS1 TRX_STATUS0 113 ... Reserved (0x13F) AES_KEY AES_KEY7 AES_KEY6 AES_KEY5 AES_KEY4 AES_KEY3 AES_KEY2 AES_KEY1 AES_KEY0 112 (0x13E) AES_STATE AES_STATE7 AES_STATE6 AES_STATE5 AES_STATE4 AES_STATE3 AES_STATE2 AES_STATE1 AES_STATE0 112 (0x13D) AES_STATUS AES_ER Res5 Res4 Res3 Res2 Res1 Res0 AES_DONE 112 (0x13C) AES_CTRL AES_REQUEST Res AES_MODE Res AES_DIR AES_IM Res1 Res0 111 (0x13B) Reserved Res7 Res6 Res5 Res4 Res3 Res2 Res1 Res0 ... Reserved (0x139) TRXPR Res3 Res2 Res1 Res0 Res3 Res2 SLPTR TRXRST 199 (0x138) PARCR PALTD2 PALTD1 PALTD0 P ALTU2 PALTU1 PALTU0 PARDFI PARUFI 118 (0x137) DPDS1 Res5 Res4 Res3 Res2 Res1 Res0 PGDRV1 PGDRV0 207 (0x136) DPDS0 PFDRV1 PFDRV0 PEDRV1 PEDRV0 PDDRV1 PDDRV0 PBDRV1 PBDRV0 206 (0x135) DRTRAM0 Res1 Res0 DRTSWOK ENDRT Res3 Res2 Res1 Res0 200 (0x134) DRTRAM1 Res1 Res0 DRTSWOK ENDRT Res3 Res2 Res1 Res0 201 (0x133) DRTRAM2 Res7 Res DRTSWOK ENDRT Res3 Res2 Res1 Res0 202 (0x132) DRTRAM3 Res1 Res0 DRTSWOK ENDRT Res3 Res2 Res1 Res0 203 (0x131) LLDRH Res2 Res1 Res0 LLDRH4 LLDRH3 LLDRH2 LLDRH1 LLDRH0 205 (0x130) LLDRL Res3 Res2 Res1 Res0 LLDRL3 LLDRL2 LLDRL1 LLDRL0 206 (0x12F) LLCR Res1 Res0 LLDONE LLCOMP LLCAL LLTCO LLSHORT LLENCAL 204 ... Reserved (0x12D) OCR5CH OCR5CH7 OCR5CH6 OCR5CH5 OCR5CH4 OCR5CH3 OCR5CH2 OCR5CH1 OCR5CH0 332 (0x12C) OCR5CL OCR5CL7 OCR5CL6 OCR5CL5 OCR5CL4 OCR5CL3 OCR5CL2 OCR5CL1 OCR5CL0 333 (0x12B) OCR5BH OCR5BH7 OCR5BH6 OCR5BH5 OCR5BH4 OCR5BH3 OCR5BH2 OCR5BH1 OCR5BH0 331 (0x12A) OCR5BL OCR5BL7 OCR5BL6 OCR5BL5 OCR5BL4 OCR5BL3 OCR5BL2 OCR5BL1 OCR5BL0 332 (0x129) OCR5AH OCR5AH7 OCR5AH6 OCR5AH5 OCR5AH4 OCR5AH3 OCR5AH2 OCR5AH1 OCR5AH0 331 (0x128) OCR5AL OCR5AL7 OCR5AL6 OCR5AL5 OCR5AL4 OCR5AL3 OCR5AL2 OCR5AL1 OCR5AL0 331 (0x127) ICR5H ICR5H7 ICR5H6 ICR5H5 ICR5H4 ICR5H3 ICR5H2 ICR5H1 ICR5H0 333 (0x126) ICR5L ICR5L7 ICR5L6 ICR5L5 ICR5L4 ICR5L3 ICR5L2 ICR5L1 ICR5L0 333 (0x125) TCNT5H TCNT5H7 TCNT5H6 TCNT5H5 TCNT5H4 TCNT5H3 TCNT5H2 TCNT5H1 TCNT5H0 330 (0x124) TCNT5L TCNT5L7 TCNT5L6 TCNT5L5 TCNT5L4 TCNT5L3 TCNT5L2 TCNT5L1 TCNT5L0 330 ... Reserved (0x122) TCCR5C FOC5A FOC5B FOC5C Res4 Res3 Res2 Res1 Res0 329 (0x121) TCCR5B ICNC5 ICES5 Res W GM53 WGM52 CS52 CS51 CS50 328 (0x120) TCCR5A COM5A1 COM5A0 COM5B1 COM5B0 COM5C1 COM5C0 WGM51 WGM50 326 ... Reserved (0x11D) MAFPA3H MAFPA3H7 MAFPA3H6 MAFPA3H5 MAFPA3H4 MAFPA3H3 MAFPA3H2 MAFPA3H1 MAFPA3H0 150 (0x11C) MAFPA3L MAFPA3L7 MAFPA3L6 MAFPA3L5 MAFPA3L4 MAFPA3L3 MAFPA3L2 MAFPA3L1 MAFPA3L0 150 (0x11B) MAFSA3H MAFSA3H7 MAFSA3H6 MAFSA3H5 MAFSA3H4 MAFSA3H3 MAFSA3H2 MAFSA3H1 MAFSA3H0 152 (0x11A) MAFSA3L MAFSA3L7 MAFSA3L6 MAFSA3L5 MAFSA3L4 MAFSA3L3 MAFSA3L2 MAFSA3L1 MAFSA3L0 153 (0x119) MAFPA2H MAFPA2H7 MAFPA2H6 MAFPA2H5 MAFPA2H4 MAFPA2H3 MAFPA2H2 MAFPA2H1 MAFPA2H0 149 (0x118) MAFPA2L MAFPA2L7 MAFPA2L6 MAFPA2L5 MAFPA2L4 MAFPA2L3 MAFPA2L2 MAFPA2L1 MAFPA2L0 150 (0x117) MAFSA2H MAFSA2H7 MAFSA2H6 MAFSA2H5 MAFSA2H4 MAFSA2H3 MAFSA2H2 MAFSA2H1 MAFSA2H0 152 (0x116) MAFSA2L MAFSA2L7 MAFSA2L6 MAFSA2L5 MA FSA2L4 MAFSA2L3 MAFSA2L2 MAFSA2L1 MAFSA2L0 152 (0x115) MAFPA1H MAFPA1H7 MAFPA1H6 MAFPA1H5 MAFPA1H4 MAFPA1H3 MAFPA1H2 MAFPA1H1 MAFPA1H0 149 (0x114) MAFPA1L MAFPA1L7 MAFPA1L6 MAFPA1L5 MAFPA1L4 MAFPA1L3 MAFPA1L2 MAFPA1L1 MAFPA1L0 149 (0x113) MAFSA1H MAFSA1H7 MAFSA1H6 MAFSA1H5 MAFSA1H4 MAFSA1H3 MAFSA1H2 MAFSA1H1 MAFSA1H0 151 (0x112) MAFSA1L MAFSA1L7 MAFSA1L6 MAFSA1L5 MAFSA1L4 MAFSA1L3 MAFSA1L2 MAFSA1L1 MAFSA1L0 151 (0x111) MAFPA0H MAFPA0H7 MAFPA0H6 MAFPA0H5 MAFPA0H4 MAFPA0H3 MAFPA0H2 MAFPA0H1 MAFPA0H0 148 (0x110) MAFPA0L MAFPA0L7 MAFPA0L6 MAFPA0L5 MAFPA0L4 MAFPA0L3 MAFPA0L2 MAFPA0L1 MAFPA0L0 149 (0x10F) MAFSA0H MAFSA0H7 MAFSA0H6 MAFSA0H5 MA FSA0H4 MAFSA0H3 MAFSA0H2 MAFSA0H1 MAFSA0H0 151 (0x10E) MAFSA0L MAFSA0L7 MAFSA0L6 MAFSA0L5 MAFSA0L4 MAFSA0L3 MAFSA0L2 MAFSA0L1 MAFSA0L0 151 (0x10D) MAFCR1 AACK_3_SET_PD AACK_3_I_AM_COORD AACK_2_SET_PD AACK_2_I_AM_COORD AACK_1_SET_PD AACK_1_I_AM_COORD AACK_0_SET_PD AACK_0_I_AM_COORD 147 (0x10C) MAFCR0 Res3 Res2 Res1 Res0 MAF3EN MAF2EN MAF1EN MAF0EN 146 ... Reserved (0xFC) SCTSTRHH SCTSTRHH7 SCTSTRHH6 SCTSTRHH5 SCTSTRHH4 SCTSTRHH3 SCTSTRHH2 SCTSTRHH1 SCTSTRHH0 165 (0xFB) SCTSTRHL SCTSTRHL7 SCTSTRHL6 SCTSTRHL5 SCTSTRHL4 SCTSTRHL3 SCTSTRHL2 SCTSTRHL1 SCTSTRHL0 165 (0xFA) SCTSTRLH SCTSTRLH7 SCTSTRLH6 SCTSTRLH5 SCTSTRLH4 SCTSTRLH3 SCTSTRLH2 SCTSTRLH1 SCTSTRLH0 165 (0xF9) SCTSTRLL SCTSTRLL7 SCTSTRLL6 SCTSTRLL5 SCTSTRLL4 SCTSTRLL3 SCTSTRLL2 SCTSTRLL1 SCTSTRLL0 165 (0xF8) SCOCR1HH SCOCR1HH7 SCOCR1HH6 SCOCR1HH5 SCOCR1HH4 SCOCR1HH3 SCOCR1HH2 SCOCR1HH1 SCOCR1HH0 168 (0xF7) SCOCR1HL SCOCR1HL7 SCOCR1HL6 SCOCR1HL5 SCOCR1HL4 SCOCR1HL3 SCOCR1HL2 SCOCR1HL1 SCOCR1HL0 168 ATmega256/128/64RFR2 544 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 Address Name Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0 Page (0xF6) SCOCR1LH SCOCR1LH7 SCOCR1LH6 SCOCR1LH5 SCOCR1LH4 SCOCR1LH3 SCOCR1LH2 SCOCR1LH1 SCOCR1LH0 168 (0xF5) SCOCR1LL SCOCR1LL7 SCOCR1LL6 SCOCR1LL5 SCOCR1LL4 SCOCR1LL3 SCOCR1LL2 SCOCR1LL1 SCOCR1LL0 169 (0xF4) SCOCR2HH SCOCR2HH7 SCOCR2HH6 SCOCR2HH5 SCOCR2HH4 SCOCR2HH3 SCOCR2HH2 SCOCR2HH1 SCOCR2HH0 169 (0xF3) SCOCR2HL SCOCR2HL7 SCOCR2HL6 SCOCR2HL5 SCO CR2HL4 SCOCR2HL3 SCOCR2HL2 SCOCR2HL1 SCOCR2HL0 169 (0xF2) SCOCR2LH SCOCR2LH7 SCOCR2LH6 SCOCR2LH5 SCOCR2LH4 SCOCR2LH3 SCOCR2LH2 SCOCR2LH1 SCOCR2LH0 169 (0xF1) SCOCR2LL SCOCR2LL7 SCOCR2LL6 SCOCR2LL5 SCOCR2LL4 SCOCR2LL3 SCOCR2LL2 SCOCR2LL1 SCOCR2LL0 170 (0xF0) SCOCR3HH SCOCR3HH7 SCOCR3HH6 SCOCR3HH5 SCOCR3HH4 SCOCR3HH3 SCOCR3HH2 SCOCR3HH1 SCOCR3HH0 170 (0xEF) SCOCR3HL SCOCR3HL7 SCOCR3HL6 SCOCR3HL5 SCOCR3HL4 SCOCR3HL3 SCOCR3HL2 SCOCR3HL1 SCOCR3HL0 170 (0xEE) SCOCR3LH SCOCR3LH7 SCOCR3LH6 SCOCR3LH5 SCOCR3LH4 SCOCR3LH3 SCOCR3LH2 SCOCR3LH1 SCOCR3LH0 170 (0xED) SCOCR3LL SCOCR3LL7 SCOCR3LL6 SCOCR3LL5 SCOCR3LL4 SCOCR3LL3 SCOCR3LL2 SCOCR3LL1 SCOCR3LL0 171 (0xEC) SCTSRHH SCTSRHH7 SCTSRHH6 SCTSRHH5 SCTSRHH4 SCTSRHH3 SCTSRHH2 SCTSRHH1 SCTSRHH0 164 (0xEB) SCTSRHL SCTSRHL7 SCTSRHL6 SCTSRHL5 SCTSRHL4 SCTSRHL3 SCTSRHL2 SCTSRHL1 SCTSRHL0 164 (0xEA) SCTSRLH SCTSRLH7 SCTSRLH6 SCTSRLH5 SCTSRLH4 SCTSRLH3 SCTSRLH2 SCTSRLH1 SCTSRLH0 164 (0xE9) SCTSRLL SCTSRLL7 SCTSRLL6 SCTSRLL5 SCT SRLL4 SCTSRLL3 SCTSRLL2 SCTSRLL1 SCTSRLL0 164 (0xE8) SCBTSRHH SCBTSRHH7 SCBTSRHH6 SCBTSRHH5 SCBTSRHH4 SCBTSRHH3 SCBTSRHH2 SCBTSRHH1 SCBTSRHH0 167 (0xE7) SCBTSRHL SCBTSRHL7 SCBTSRHL6 SCBTSRHL5 SCBTSRHL4 SCBTSRHL3 SCBTSRHL2 SCBTSRHL1 SCBTSRHL0 167 (0xE6) SCBTSRLH SCBTSRLH7 SCBTSRLH6 SCBTSRLH5 SCBTSRLH4 SCBTSRLH3 SCBTSRLH2 SCBTSRLH1 SCBTSRLH0 167 (0xE5) SCBTSRLL SCBTSRLL7 SCBTSRLL6 SCBTSRLL5 SCBTSRLL4 SCBTSRLL3 SCBTSRLL2 SCBTSRLL1 SCBTSRLL0 168 (0xE4) SCCNTHH SCCNTHH7 SCCNTHH6 SCCNTHH5 SCCNTHH4 SCCNTHH3 SCCNTHH2 SCCNTHH1 SCCNTHH0 163 (0xE3) SCCNTHL SCCNTHL7 SCCNTHL6 SCCNTHL5 SCCNTHL4 SCCNTHL3 SCCNTHL2 SCCNTHL1 SCCNTHL0 163 (0xE2) SCCNTLH SCCNTLH7 SCCNTLH6 SCCNTLH5 SCC NTLH4 SCCNTLH3 SCCNTLH2 SCCNTLH1 SCCNTLH0 163 (0xE1) SCCNTLL SCCNTLL7 SCCNTLL6 SCCNTLL5 SCCNTLL4 SCCNTLL3 SCCNTLL2 SCCNTLL1 SCCNTLL0 163 (0xE0) SCIRQS Res2 Res1 Res0 IRQSBO IRQSOF IRQSCP3 IRQSCP2 IRQSCP1 173 (0xDF) SCIRQM Res2 Res1 Res0 IRQMBO IRQMOF IRQMCP3 IRQMCP2 IRQMCP1 174 (0xDE) SCSR Res6 Res5 Res4 Res3 Res2 Res1 Res0 SCBSY 173 (0xDD) SCCR1 Res6 Res5 SCBTSM SCCKDIV2 SCCKDIV1 SCCKDIV0 SCEECLK SCENBO 172 (0xDC) SCCR0 SCRES SCMBTS SCEN SCCKSEL SCTSE SCCMP3 SCCMP2 SCCMP1 171 (0xDB) SCCSR Res1 Res0 SCCS31 SCCS30 SCCS21 SCCS20 SCCS11 SCCS10 161 (0xDA) SCRSTRHH SCRSTRHH7 SCRSTRHH6 SCRSTRHH5 SCRSTRHH4 SCRSTRHH3 SCRSTRHH2 SCRSTRHH1 SCRSTRHH0 166 (0xD9) SCRSTRHL SCRSTRHL7 SCRSTRHL6 SCRSTRHL5 SCRSTRHL4 SCRSTRHL3 SCRSTRHL2 SCRSTRHL1 SCRSTRHL0 166 (0xD8) SCRSTRLH SCRSTRLH7 SCRSTRLH6 SCRSTRLH5 SCR STRLH4 SCRSTRLH3 SCRSTRLH2 SCRSTRLH1 SCRSTRLH0 166 (0xD7) SCRSTRLL SCRSTRLL7 SCRSTRLL6 SCRSTRLL5 SCRSTRLL4 SCRSTRLL3 SCRSTRLL2 SCRSTRLL1 SCRSTRLL0 167 ... Reserved (0xD1) Reserved Res7 Res6 Res5 Res4 Res3 Res2 Res1 Res0 (0xD0) Reserved Res7 Res6 Res5 Res4 Res3 Res2 Res1 Res0 ... Reserved (0xCE) UDR1 UDR17 UDR16 UDR15 UDR14 UDR13 UDR12 UDR11 UDR10 393 (0xCD) UBRR1H Res3 Res2 Res1 Res0 UBRR11 UBRR10 UBRR9 UBRR8 397 (0xCC) UBRR1L UBRR7 UBRR6 UBRR5 UBRR4 UBRR3 UBRR2 UBRR1 UBRR0 398 ... Reserved (0xCA) UCSR1C UMSEL11 UMSEL10 UPM11 UPM10 USBS1 UDORD1 UCPHA1 UCPOL1 409 (0xC9) UCSR1B RXCIE1 TXCIE1 UDRIE1 RXEN1 TXEN1 UCSZ12 RXB81 TXB81 408 (0xC8) UCSR1A RXC1 TXC1 UDRE1 FE1 DOR1 UPE1 U2X1 MPCM1 408 ... Reserved (0xC6) UDR0 UDR07 UDR06 UDR05 UDR04 UDR03 UDR02 UDR01 UDR00 389 (0xC5) UBRR0H Res3 Res2 Res1 Res0 UBRR11 UBRR10 UBRR9 UBRR8 393 (0xC4) UBRR0L UBRR7 UBRR6 UBRR5 UBRR4 UBRR3 UBRR2 UBRR1 UBRR0 393 ... Reserved (0xC2) UCSR0C UMSEL01 UMSEL00 UPM01 UPM00 USBS0 UDORD0 UCPHA0 UCPOL0 407 (0xC1) UCSR0B RXCIE0 TXCIE0 UDRIE0 RXEN0 TXEN0 UCSZ02 RXB80 TXB80 407 (0xC0) UCSR0A RXC0 TXC0 UDRE0 FE0 DOR0 UPE0 U2X0 MPCM0 406 (0xBF) IRQ_STATUS1 Res2 Res1 Res0 MAF_3_AMI MAF_2_AMI MAF_1_AMI MAF_0_AMI TX_START 127 (0xBE) IRQ_MASK1 Res2 Res1 Res0 MAF_3_AMI_EN MAF_2_AMI_EN MAF_1_AMI_EN MAF_0_AMI_EN TX_START_EN 126 (0xBD) TWAMR TWAM6 TWAM5 TWAM4 TW AM3 TWAM2 TWAM1 TWAM0 Res 439 (0xBC) TWCR TWINT TWEA TWSTA TWSTO TWWC TWEN Res TWIE 435 (0xBB) TWDR TWD7 TWD6 TWD5 TWD4 TWD3 TWD2 TWD1 TWD0 438 (0xBA) TWAR TWA6 TWA5 TWA4 TWA3 TWA2 TWA1 TWA0 TWGCE 438 (0xB9) TWSR TWS7 TWS6 TWS5 TWS4 TWS3 Res TWPS1 TWPS0 436 (0xB8) TWBR TWBR7 TWBR6 TWBR5 TWBR4 TWBR3 TWBR2 TWBR1 TWBR0 434 ... Reserved (0xB6) ASSR EXCLKAMR EXCLK AS2 TCN2UB OCR2AUB OCR2BUB TCR2AUB TCR2BUB 360 ... Reserved (0xB4) OCR2B OCR2B7 OCR2B6 OCR2B5 OCR2B4 OCR2B3 OCR2B2 OCR2B1 OCR2B0 360 (0xB3) OCR2A OCR2A7 OCR2A6 OCR2A5 OCR2A4 OCR2A3 OCR2A2 OCR2A1 OCR2A0 360 545 8393C-MCU Wireless-09/14

Address Name Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0 Page (0xB2) TCNT2 TCNT27 TCNT26 TCNT25 TCNT24 TCNT23 TCNT22 TCNT21 TCNT20 359 (0xB1) TCCR2B FOC2A FOC2B Res1 Res0 WGM22 CS22 CS21 CS20 358 (0xB0) TCCR2A COM2A1 COM2A0 COM2B1 COM2B0 Res1 Res0 WGM21 WGM20 357 ... Reserved (0xAD) OCR4CH OCR4CH7 OCR4CH6 OCR4CH5 OCR4CH4 OCR4CH3 OCR4CH2 OCR4CH1 OCR4CH0 323 (0xAC) OCR4CL OCR4CL7 OCR4CL6 OCR4CL5 OCR4CL4 OCR4CL3 OCR4CL2 OCR4CL1 OCR4CL0 324 (0xAB) OCR4BH OCR4BH7 OCR4BH6 OCR4BH5 OCR4BH4 OCR4BH3 OCR4BH2 OCR4BH1 OCR4BH0 323 (0xAA) OCR4BL OCR4BL7 OCR4BL6 OCR4BL5 OCR4BL4 OCR4BL3 OCR4BL2 OCR4BL1 OCR4BL0 323 (0xA9) OCR4AH OCR4AH7 OCR4AH6 OCR4AH5 OCR4AH4 OCR4AH3 OCR4AH2 OCR4AH1 OCR4AH0 322 (0xA8) OCR4AL OCR4AL7 OCR4AL6 OCR4AL5 OCR4AL4 OCR4AL3 OCR4AL2 OCR4AL1 OCR4AL0 322 (0xA7) ICR4H ICR4H7 ICR4H6 ICR4H5 ICR4H4 ICR4H3 ICR4H2 ICR4H1 ICR4H0 324 (0xA6) ICR4L ICR4L7 ICR4L6 ICR4L5 ICR4L4 ICR4L3 ICR4L2 ICR4L1 ICR4L0 324 (0xA5) TCNT4H TCNT4H7 TCNT4H6 TCNT4H5 TCNT4H4 TCNT4H3 TCNT4H2 TCNT4H1 TCNT4H0 321 (0xA4) TCNT4L TCNT4L7 TCNT4L6 TCNT4L5 TC NT4L4 TCNT4L3 TCNT4L2 TCNT4L1 TCNT4L0 321 ... Reserved (0xA2) TCCR4C FOC4A FOC4B FOC4C Res4 Res3 Res2 Res1 Res0 320 (0xA1) TCCR4B ICNC4 ICES4 Res WGM43 WGM42 CS42 CS41 CS40 319 (0xA0) TCCR4A COM4A1 COM4A0 COM4B1 COM4B0 COM4C1 COM4C0 WGM41 WGM40 317 ... Reserved (0x9D) OCR3CH OCR3CH7 OCR3CH6 OCR3CH5 OCR3CH4 OCR3CH3 OCR3CH2 OCR3CH1 OCR3CH0 314 (0x9C) OCR3CL OCR3CL7 OCR3CL6 OCR3CL5 OCR3CL4 OCR3CL3 OCR3CL2 OCR3CL1 OCR3CL0 315 (0x9B) OCR3BH OCR3BH7 OCR3BH6 OCR3BH5 OCR3BH4 OCR3BH3 OCR3BH2 OCR3BH1 OCR3BH0 314 (0x9A) OCR3BL OCR3BL7 OCR3BL6 OCR3BL5 OCR3BL4 OCR3BL3 OCR3BL2 OCR3BL1 OCR3BL0 314 (0x99) OCR3AH OCR3AH7 OCR3AH6 OCR3AH5 OCR3AH4 OCR3AH3 OCR3AH2 OCR3AH1 OCR3AH0 313 (0x98) OCR3AL OCR3AL7 OCR3AL6 OCR3AL5 OCR3AL4 OCR3AL3 OCR3AL2 OCR3AL1 OCR3AL0 313 (0x97) ICR3H ICR3H7 ICR3H6 ICR3H5 ICR3H4 ICR3H3 ICR3H2 ICR3H1 ICR3H0 315 (0x96) ICR3L ICR3L7 ICR3L6 ICR3L5 ICR3L4 ICR3L3 ICR3L2 ICR3L1 ICR3L0 315 (0x95) TCNT3H TCNT3H7 TCNT3H6 TCNT3H5 TCNT3H4 TCNT3H3 TCNT3H2 TCNT3H1 TCNT3H0 312 (0x94) TCNT3L TCNT3L7 TCNT3L6 TCNT3L5 TCNT3L4 TCNT3L3 TCNT3L2 TCNT3L1 TCNT3L0 312 ... Reserved (0x92) TCCR3C FOC3A FOC3B FOC3C Res4 Res3 Res2 Res1 Res0 311 (0x91) TCCR3B ICNC3 ICES3 Res WGM33 WGM32 CS32 CS31 CS30 310 (0x90) TCCR3A COM3A1 COM3A0 COM3B1 COM3B0 COM3C1 COM3C0 WGM31 WGM30 308 ... Reserved (0x8D) OCR1CH OCR1CH7 OCR1CH6 OCR1CH5 OCR1CH4 OCR1CH3 OCR1CH2 OCR1CH1 OCR1CH0 305 (0x8C) OCR1CL OCR1CL7 OCR1CL6 OCR1CL5 OCR1CL4 OCR1CL3 OCR1CL2 OCR1CL1 OCR1CL0 305 (0x8B) OCR1BH OCR1BH7 OCR1BH6 OCR1BH5 OC R1BH4 OCR1BH3 OCR1BH2 OCR1BH1 OCR1BH0 304 (0x8A) OCR1BL OCR1BL7 OCR1BL6 OCR1BL5 OCR1BL4 OCR1BL3 OCR1BL2 OCR1BL1 OCR1BL0 304 (0x89) OCR1AH OCR1AH7 OCR1AH6 OCR1AH5 OCR1AH4 OCR1AH3 OCR1AH2 OCR1AH1 OCR1AH0 303 (0x88) OCR1AL OCR1AL7 OCR1AL6 OCR1AL5 OCR1AL4 OCR1AL3 OCR1AL2 OCR1AL1 OCR1AL0 303 (0x87) ICR1H ICR1H7 ICR1H6 ICR1H5 ICR1H4 ICR1H3 ICR1H2 ICR1H1 ICR1H0 305 (0x86) ICR1L ICR1L7 ICR1L6 ICR1L5 ICR1L4 ICR1L3 ICR1L2 ICR1L1 ICR1L0 306 (0x85) TCNT1H TCNT1H7 TCNT1H6 TCNT1H5 TCNT1H4 TCNT1H3 TCNT1H2 TCNT1H1 TCNT1H0 302 (0x84) TCNT1L TCNT1L7 TCNT1L6 TCNT1L5 TCNT1L4 TCNT1L3 TCNT1L2 TCNT1L1 TCNT1L0 303 ... Reserved (0x82) TCCR1C FOC1A FOC1B FOC1C Res4 Res3 Res2 Res1 Res0 302 (0x81) TCCR1B ICNC1 ICES1 Res W GM13 WGM12 CS12 CS11 CS10 300 (0x80) TCCR1A COM1A1 COM1A0 COM1B1 COM1B0 COM1C1 COM1C0 WGM11 WGM10 298 (0x7F) DIDR1 AIN1D AIN0D 442 (0x7E) DIDR0 ADC7D ADC6D ADC5D ADC4D ADC3D ADC2D ADC1D ADC0D 469 (0x7D) DIDR2 ADC15D ADC14D ADC13D ADC12D ADC11D ADC10D ADC9D ADC8D 470 (0x7C) ADMUX REFS1 REFS0 ADLAR MUX4 MUX3 MUX2 MUX1 MUX0 464 (0x7B) ADCSRB AVDDOK ACME REFOK ACCH MUX5 ADTS2 ADTS1 ADTS0 464 (0x7A) ADCSRA ADEN ADSC ADATE ADIF ADIE ADPS2 ADPS1 ADPS0 467 (0x79) ADCH ADCH7 ADCH6 ADCH5 ADCH4 ADCH3 ADCH2 ADCH1 ADCH0 469 (0x78) ADCL ADCL7 ADCL6 ADCL5 ADCL4 ADCL3 ADCL2 ADCL1 ADCL0 469 (0x77) ADCSRC ADTHT1 ADTHT0 Res0 ADSUT4 ADSUT3 ADSUT2 ADSUT1 ADSUT0 468 ... Reserved (0x75) NEMCR Res7 ENEAM AEAM1 AEAM0 Res3 Res2 Res1 Res0 503 (0x74) Reserved Res7 Res6 Res5 Res4 Res3 Res2 Res1 Res0 (0x73) TIMSK5 Res1 Res0 ICIE5 Res OCIE5C OCIE5B OCIE5A TOIE5 334 (0x72) TIMSK4 Res1 Res0 ICIE4 Res OCIE4C OCIE4B OCIE4A TOIE4 325 (0x71) TIMSK3 Res1 Res0 ICIE3 Res OCIE3C OCIE3B OCIE3A TOIE3 316 (0x70) TIMSK2 Res4 Res3 Res2 Res1 Res0 OCIE2B OCIE2A TOIE2 356 ATmega256/128/64RFR2 546 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 Address Name Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0 Page (0x6F) TIMSK1 Res1 Res0 ICIE1 Res OCIE1C OCIE1B OCIE1A TOIE1 306 (0x6E) TIMSK0 Res4 Res3 Res2 Res1 Res0 OCIE0B OCIE0A TOIE0 274 (0x6D) PCMSK2 PCINT23 PCINT22 PCINT21 PCINT20 PCINT19 PCINT18 PCINT17 PCINT16 256 (0x6C) PCMSK1 PCINT15 PCINT14 PCINT13 PC INT12 PCINT11 PCINT10 PCINT9 PCINT8 256 (0x6B) PCMSK0 PCINT7 PCINT6 PCINT5 PCINT4 PCINT3 PCINT2 PCINT1 PCINT0 257 (0x6A) EICRB ISC71 ISC70 ISC61 ISC60 ISC51 ISC50 ISC41 ISC40 252 (0x69) EICRA ISC31 ISC30 ISC21 ISC20 ISC11 ISC10 ISC01 ISC00 251 (0x68) PCICR Res4 Res3 Res2 Res1 Res0 PCIE2 PCIE1 PCIE0 255 (0x67) BGCR Res BGCAL_FINE3 BGCAL_FINE2 BGCAL_FINE1 BGCAL_FINE0 BGCAL2 BGCAL1 BGCAL0 470 (0x66) OSCCAL CAL7 CAL6 CAL5 CAL4 CAL3 CAL2 CAL1 CAL0 182 (0x65) PRR1 Res PRTRX24 PRTIM5 PRTIM4 PRTIM3 PRUSART1 198 (0x64) PRR0 PRTWI PRTIM2 PRTIM0 PRPGA PRTIM1 PRSPI PRUSART0 PRADC 197 (0x63) PRR2 Res3 Res2 Res1 Res0 PRRAM3 PRRAM2 PRRAM1 PRRAM0 199 ... Reserved (0x61) CLKPR CLKPCE Res2 Res1 Res0 CLKPS3 CLKPS2 CLKPS1 CLKPS0 183 (0x60) WDTCSR WDIF WDIE WDP3 WDCE WDE WDP2 WDP1 WDP0 217 0x3F (0x5F) SREG I T H S V N Z C 11 0x3E (0x5E) SPH SP15 SP14 SP13 SP12 SP11 SP10 SP9 SP8 13 0x3D (0x5D) SPL SP7 SP6 SP5 SP4 SP3 SP2 SP1 SP0 14 0x3C (0x5C) EIND EIND0 15 0x3B (0x5B) RAMPZ Res5 Res4 Res3 R es2 Res1 Res0 RAMPZ1 RAMPZ0 14 ... Reserved 0x37 (0x57) SPMCSR SPMIE RWWSB SIGRD RWWSRE BLBSET PGWRT PGERS SPMEN 501 ... Reserved 0x35 (0x55) MCUCR JTD Res1 Res0 PUD Res1 Res0 IVSEL IVCE 236 0x34 (0x54) MCUSR Res2 Res1 Res0 JTRF WDRF BORF EXTRF PORF 216 0x33 (0x53) SMCR Res3 Res2 Res1 Res0 SM2 SM1 SM0 SE 196 ... Reserved 0x31 (0x51) OCDR OCDR7 OCDR6 OCDR5 OCDR4 OCDR3 OCDR2 OCDR1 OCDR0 477 0x30 (0x50) ACSR ACD ACBG ACO ACI ACIE ACIC ACIS1 ACIS0 441 ... Reserved 0x2E (0x4E) SPDR SPDR7 SPDR6 SPDR5 SPDR4 SPDR3 SPDR2 SPDR1 SPDR0 370 0x2D (0x4D) SPSR SPIF WCOL Res4 Res3 Res2 Res1 Res0 SPI2X 370 0x2C (0x4C) SPCR SPIE SPE DORD MSTR CPOL CPHA SPR1 SPR0 369 0x2B (0x4B) GPIOR2 GPIOR27 GPIOR26 GPIOR25 GPIOR24 GPIOR23 GPIOR22 GPIOR21 GPIOR20 29 0x2A (0x4A) GPIOR1 GPIOR17 GPIOR16 GPIOR15 GPIOR14 GPIOR13 GPIOR12 GPIOR11 GPIOR10 29 ... Reserved 0x28 (0x48) OCR0B OCR0B_7 OCR0B_6 OCR0B_5 OCR0B_4 OCR0B_3 OCR0B_2 OCR0B_1 OCR0B_0 274 0x27 (0x47) OCR0A OCR0A_7 OCR0A_6 OCR0A_5 OCR0A_4 OCR0A_3 OCR0A_2 OCR0A_1 OCR0A_0 273 0x26 (0x46) TCNT0 TCNT0_7 TCNT0_6 TCNT0_5 TCNT0_4 TCNT0_3 TCNT0_2 TCNT0_1 TCNT0_0 273 0x25 (0x45) TCCR0B FOC0A FOC0B Res1 Res0 WGM02 CS02 CS01 CS00 272 0x24 (0x44) TCCR0A COM0A1 COM0A0 COM0B1 COM0B0 Res1 Res0 WGM01 WGM00 270 0x23 (0x43) GTCCR TSM Res4 Res3 Res2 Res1 Res0 PSRASY PSRSYNC 361 0x22 (0x42) EEARH Res3 Res2 Res1 Res0 EEAR11 EEAR10 EEAR9 EEAR8 26 0x21 (0x41) EEARL EEAR7 EEAR6 EEAR5 EEAR4 EEAR3 EEAR2 EEAR1 EEAR0 26 0x20 (0x40) EEDR EEDR7 EEDR6 EEDR5 EEDR4 EEDR3 EEDR2 EEDR1 EEDR0 27 0x1F (0x3F) EECR Res1 Res0 EEPM1 EEPM0 EERIE EEMPE EEPE EERE 27 0x1E (0x3E) GPIOR0 GPIOR07 GPIOR06 GPIOR05 GPIOR04 GPIOR03 GPIOR02 GPIOR01 GPIOR00 29 0x1D (0x3D) EIMSK INT7 INT6 INT5 INT4 INT3 INT2 INT1 INT0 254 0x1C (0x3C) EIFR INTF7 INTF6 INTF5 INTF4 INTF3 INTF2 INTF1 INTF0 254 0x1B (0x3B) PCIFR Res4 Res3 Res2 Res1 Res0 PCIF2 PCIF1 PCIF0 255 0x1A (0x3A) TIFR5 Res1 Res0 ICF5 Res OCF5C OCF5B OCF5A TOV5 334 0x19 (0x39) TIFR4 Res1 Res0 ICF4 Res OCF4C OCF4B OCF4A TOV4 325 0x18 (0x38) TIFR3 Res1 Res0 ICF3 Res OCF3C OCF3B OCF3A TOV3 316 0x17 (0x37) TIFR2 Res4 Res3 Res2 Res1 Res0 OCF2B OCF2A TOV2 356 0x16 (0x36) TIFR1 Res1 Res0 ICF1 Res OCF1C OCF1B OCF1A TOV1 307 0x15 (0x35) TIFR0 Res4 Res3 Res2 Res1 Res0 OCF0B OCF0A TOV0 275 0x14 (0x34) PORTG Res1 Res0 PORTG5 PORTG4 PORTG3 PORTG2 PORTG1 PORTG0 241 0x13 (0x33) DDRG Res1 Res0 DDG5 DDG4 DDG3 DDG2 DDG1 DDG0 242 0x12 (0x32) PING Res1 Res0 PING5 PING4 PING3 PING2 PING1 PING0 242 0x11 (0x31) PORTF PORTF7 PORTF6 PORTF5 PORTF4 PORTF3 PORTF2 PORTF1 PORTF0 240 0x10 (0x30) DDRF DDF7 DDF6 DDF5 DDF4 DDF3 DDF2 DDF1 DDF0 241 0x0F (0x2F) PINF PINF7 PINF6 PINF5 PINF4 PINF3 PINF2 PINF1 PINF0 241 0x0E (0x2E) PORTE PORTE7 PORTE6 PORTE5 PORTE4 PORTE3 PORTE2 PORTE1 PORTE0 239 547 8393C-MCU Wireless-09/14

Address Name Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0 Page 0x0D (0x2D) DDRE DDE7 DDE6 DDE5 DDE4 DDE3 DDE2 DDE1 DDE0 240 0x0C (0x2C) PINE PINE7 PINE6 PINE5 PINE4 PINE3 PINE2 PINE1 PINE0 240 0x0B (0x2B) PORTD PORTD7 PORTD6 PORTD5 PORTD4 PORTD3 PORTD2 PORTD1 PORTD0 239 0x0A (0x2A) DDRD DDD7 DDD6 DDD5 DDD4 DDD3 DDD2 DDD1 DDD0 239 0x09 (0x29) PIND PIND7 PIND6 PIND5 PIND4 PIND3 PIND2 PIND1 PIND0 239 0x08 (0x28) PORTC PORTC7 PORTC6 PORTC5 PORTC4 PORTC3 PORTC2 PORTC1 PORTC0 31 0x07 (0x27) DDRC DDC7 DDC6 DDC5 DDC4 DDC3 DDC2 DDC1 DDC0 31 0x06 (0x26) PINC PINC7 PINC6 PINC5 PINC4 PINC3 PINC2 PINC1 PINC0 31 0x05 (0x25) PORTB PORTB7 PORTB6 PORTB5 PORTB4 PORTB3 PORTB2 PORTB1 PORTB0 238 0x04 (0x24) DDRB DDB7 DDB6 DDB5 DDB4 DDB3 DDB2 DDB1 DDB0 238 0x03 (0x23) PINB PINB7 PINB6 PINB5 PINB4 PINB3 PINB2 PINB1 PINB0 238 0x02 (0x22) PORTA PORTA7 PORTA6 PORTA5 PORTA4 PORTA3 PORTA2 PORTA1 PORTA0 30 0x01 (0x21) DDRA DDA7 DDA6 DDA5 DDA4 DDA3 DDA2 DDA1 DDA0 30 0x00 (0x20) PINA PINA7 PINA6 PINA5 P INA4 PINA3 PINA2 PINA1 PINA0 30 Notes: 1. Reserved registers, bits and I/O memory addresses (marked as Res*) may not be modified. 2. I/O registers within the address range 0x00 - 0x1F are directly bit-accessible using the SBI and CBI instructions. In these registers, the value of single bits can be checked by using the SBIS and SBIC instructions. 3. Some of the status flags are cleared by writing a logical one to them. Note that the CBI and SBI instructions will operate on all bits in the I/O register, writing a one back into any flag read as set, thus clearing the flag. The CBI and SBI instructions work with registers 0x00 to 0x1F only. 4. When using the I/O specific commands IN and OUT, the I/O addresses 0x00 – 0x3F must be used. When addressing I/O registers as data space using LD and ST instructions, 0x20 must be added to these addresses. The device is a complex microcontroller with more peripheral units than can be supported within the 64 location reserved in Op-code for the IN and OUT instructions. For the Extended I/O space from 0x60 – 0x1FF in SRAM, only the ST/STS/STD and LD/LDS/LDD instructions can be used. 34 Instruction Set Summary Depending on the size of the Flash memory the instructions • EICALL and EIJMP do not exist in devices with 128K/64KByte Flash memory, • ELPM does not exist in the device with 64Kbyte Flash memory. 34.1 Arithmetic and Logic Instructions Mnemonics Operands Description Operation Flags #Clocks ADD Rd, Rr Add two Registers Rd ← Rd + Rr Z,C,N,V,H 1 ADC Rd, Rr Add with Carry two Registers Rd ← Rd + Rr + C Z,C,N,V,H 1 ADIW Rdl,K Add Immediate to Word Rdh:Rdl ← Rdh:Rdl + K Z,C,N,V,S 2 SUB Rd, Rr Subtract two Registers Rd ← Rd - Rr Z,C,N,V,H 1 SUBI Rd, K Subtract Constant from Register Rd ← Rd - K Z,C,N,V,H 1 SBC Rd, Rr Subtract with Carry two Registers Rd ← Rd - Rr - C Z,C,N,V,H 1 SBCI Rd, K Subtract with Carry Constant from Reg. Rd ← Rd - K - C Z,C,N,V,H 1 SBIW Rdl, K Subtract Immediate from Word Rdh:Rdl ← Rdh:Rdl - K Z,C,N,V,S 2 AND Rd, Rr Logical AND Registers Rd ← Rd • Rr Z,N,V 1 ANDI Rd, K Logical AND Register and Constant Rd ← Rd • K Z,N,V 1 OR Rd, Rr Logical OR Registers Rd ← Rd v Rr Z,N,V 1 ORI Rd, K Logical OR Register and Constant Rd ← Rd v K Z,N,V 1 EOR Rd, Rr Exclusive OR Registers Rd ← Rd ⊕ Rr Z,N,V 1 COM Rd One’s Complement Rd ← 0xFF − Rd Z,C,N,V 1 NEG Rd Two’s Complement Rd ← 0x00 − Rd Z,C,N,V,H 1 ATmega256/128/64RFR2 548 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 Mnemonics Operands Description Operation Flags #Clocks SBR Rd,K Set Bit(s) in Register Rd ← Rd v K Z,N,V 1 CBR Rd,K Clear Bit(s) in Register Rd ← Rd • (0xFF - K) Z,N,V 1 INC Rd Increment Rd ← Rd + 1 Z,N,V 1 DEC Rd Decrement Rd ← Rd − 1 Z,N,V 1 TST Rd Test for Zero or Minus Rd ← Rd • Rd Z,N,V 1 CLR Rd Clear Register Rd ← Rd ⊕ Rd Z,N,V 1 SER Rd Set Register Rd ← 0xFF None 1 MUL Rd, Rr Multiply Unsigned R1:R0 ← Rd x Rr Z,C 2 MULS Rd, Rr Multiply Signed R1:R0 ← Rd x Rr Z,C 2 MULSU Rd, Rr Multiply Signed with Unsigned R1:R0 ← Rd x Rr Z,C 2 FMUL Rd, Rr Fractional Multiply Unsigned R1:R0 ← (Rd x Rr) << 1 Z,C 2 FMULS Rd, Rr Fractional Multiply Signed R1:R0 ← (Rd x Rr) << 1 Z,C 2 FMULSU Rd, Rr Fractional Multiply Signed with Unsigned R1:R0 ← (Rd x Rr) << 1 Z,C 2 34.2 Branch Instructions Mnemonics Operands Description Operation Flags #Clocks RJMP k Relative Jump PC ← PC + k + 1 None 2 IJMP Indirect Jump to (Z) PC ← Z None 2 EIJMP Extended Indirect Jump to (Z) PC ←(EIND:Z) None 2 JMP k Direct Jump PC ← k None 3 RCALL k Relative Subroutine Call PC ← PC + k + 1 None 4 ICALL Indirect Call to (Z) PC ← Z None 4 EICALL Extended Indirect Call to (Z) PC ←(EIND:Z) None 4 CALL k Direct Subroutine Call PC ← k None 5 RET Subroutine Return PC ← STACK None 5 RETI Interrupt Return PC ← STACK I 5 CPSE Rd,Rr Compare, Skip if Equal if (Rd = Rr) PC ← PC + 2 or 3 None 1 / 2 / 3 CP Rd,Rr Compare Rd − Rr Z,N,V,C,H 1 CPC Rd,Rr Compare with Carry Rd − Rr − C Z,N,V,C,H 1 CPI Rd,K Compare Register with Immediate Rd − K Z,N,V,C,H 1 SBRC Rr, b Skip if Bit in Register Cleared if (Rr(b)=0) PC ← PC + 2 or 3 None 1 / 2 / 3 SBRS Rr, b Skip if Bit in Register is Set if (Rr(b)=1) PC ← PC + 2 or 3 None 1 / 2 / 3 SBIC P, b Skip if Bit in I/O Register Cleared if (P(b)=0) PC ← PC + 2 or 3 None 1 / 2 / 3 SBIS P, b Skip if Bit in I/O Register is Set if (P(b)=1) PC ← PC + 2 or 3 None 1 / 2 / 3 BRBS s, k Branch if Status Flag Set if (SREG(s) = 1) then None 1 / 2 PC ← PC + k + 1 BRBC s, k Branch if Status Flag Cleared if (SREG(s) = 0) then None 1 / 2 PC ← PC + k + 1 BREQ k Branch if Equal if (Z = 1) then PC ← PC + k + 1 None 1 / 2 BRNE k Branch if Not Equal if (Z = 0) then PC ← PC + k + 1 None 1 / 2 BRCS k Branch if Carry Set if (C = 1) then PC ← PC + k + 1 None 1 / 2 BRCC k Branch if Carry Cleared if (C = 0) then PC ← PC + k + 1 None 1 / 2 549 8393C-MCU Wireless-09/14

Mnemonics Operands Description Operation Flags #Clocks BRSH k Branch if Same or Higher if (C = 0) then PC ← PC + k + 1 None 1 / 2 BRLO k Branch if Lower if (C = 1) then PC ← PC + k + 1 None 1 / 2 BRMI k Branch if Minus if (N = 1) then PC ← PC + k + 1 None 1 / 2 BRPL k Branch if Plus if (N = 0) then PC ← PC + k + 1 None 1 / 2 BRGE k Branch if Greater or Equal, Signed if (N ⊕ V= 0) then None 1 / 2 PC ← PC + k + 1 BRLT k Branch if Less Than Zero, Signed if (N ⊕ V= 1) then None 1 / 2 PC ← PC + k + 1 BRHS k Branch if Half Carry Flag Set if (H = 1) then PC ← PC + k + 1 None 1 / 2 BRHC k Branch if Half Carry Flag Cleared if (H = 0) then PC ← PC + k + 1 None 1 / 2 BRTS k Branch if T Flag Set if (T = 1) then PC ← PC + k + 1 None 1 / 2 BRTC k Branch if T Flag Cleared if (T = 0) then PC ← PC + k + 1 None 1 / 2 BRVS k Branch if Overflow Flag is Set if (V = 1) then PC ← PC + k + 1 None 1 / 2 BRVC k Branch if Overflow Flag is Cleared if (V = 0) then PC ← PC + k + 1 None 1 / 2 BRIE k Branch if Interrupt Enabled if ( I = 1) then PC ← PC + k + 1 None 1 / 2 BRID k Branch if Interrupt Disabled if ( I = 0) then PC ← PC + k + 1 None 1 / 2 34.3 Bit and Bit Test Instructions Mnemonics Operands Description Operation Flags #Clocks SBI P,b Set Bit in I/O Register I/O(P,b) ← 1 None 2 CBI P,b Clear Bit in I/O Register I/O(P,b) ← 0 None 2 LSL Rd Logical Shift Left Rd(n+1) ← Rd(n), Rd(0) ← 0 Z,C,N,V 1 LSR Rd Logical Shift Right Rd(n) ← Rd(n+1), Rd(7) ← 0 Z,C,N,V 1 ROL Rd Rotate Left Through Carry Rd(0) ← C, Rd(n+1) ← Rd(n), Z,C,N,V 1 C ← Rd(7) ROR Rd Rotate Right Through Carry Rd(7) ← C, Rd(n) ← Rd(n+1), Z,C,N,V 1 C ← Rd(0) ASR Rd Arithmetic Shift Right Rd(n) ← Rd(n+1), n=0..6 Z,C,N,V 1 SWAP Rd Swap Nibbles Rd(3..0) ← Rd(7..4), None 1 Rd(7..4) ← Rd(3..0) BSET s Flag Set SREG(s) ← 1 SREG(s) 1 BCLR s Flag Clear SREG(s) ← 0 SREG(s) 1 BST Rr, b Bit Store from Register to T T ← Rr(b) T 1 BLD Rd, b Bit load from T to Register Rd(b) ← T None 1 SEC Set Carry C ← 1 C 1 CLC Clear Carry C ← 0 C 1 SEN Set Negative Flag N ← 1 N 1 CLN Clear Negative Flag N ← 0 N 1 SEZ Set Zero Flag Z ← 1 Z 1 CLZ Clear Zero Flag Z ← 0 Z 1 SEI Global Interrupt Enable I ← 1 I 1 CLI Global Interrupt Disable I ← 0 I 1 ATmega256/128/64RFR2 550 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 Mnemonics Operands Description Operation Flags #Clocks SES Set Signed Test Flag S ← 1 S 1 CLS Clear Signed Test Flag S ← 0 S 1 SEV Set Twos Complement Overflow V ← 1 V 1 CLV Clear Twos Complement Overflow V ← 0 V 1 SET Set T in SREG T ← 1 T 1 CLT Clear T in SREG T ← 0 T 1 SEH Set Half Carry Flag in SREG H ← 1 H 1 CLH Clear Half Carry Flag in SREG H ← 0 H 1 34.4 Data Transfer Instructions Mnemonics Operands Description Operation Flags #Clocks MOV Rd, Rr Move Between Registers Rd ← Rr None 1 MOVW Rd, Rr Copy Register Word Rd+1:Rd ← Rr+1:Rr None 1 LDI Rd, K Load Immediate Rd ← K None 1 LD Rd, X Load Indirect Rd ← (X) None 2 LD Rd, X+ Load Indirect and Post-Inc. Rd ← (X), X ← X + 1 None 2 LD Rd, - X Load Indirect and Pre-Dec. X ← X - 1, Rd ← (X) None 2 LD Rd, Y Load Indirect Rd ← (Y) None 2 LD Rd, Y+ Load Indirect and Post-Inc. Rd ← (Y), Y ← Y + 1 None 2 LD Rd, - Y Load Indirect and Pre-Dec. Y ← Y - 1, Rd ← (Y) None 2 LDD Rd,Y+q Load Indirect with Displacement Rd ← (Y + q) None 2 LD Rd, Z Load Indirect Rd ← (Z) None 2 LD Rd, Z+ Load Indirect and Post-Inc. Rd ← (Z), Z ← Z+1 None 2 LD Rd, -Z Load Indirect and Pre-Dec. Z ← Z - 1, Rd ← (Z) None 2 LDD Rd, Z+q Load Indirect with Displacement Rd ← (Z + q) None 2 LDS Rd, k Load Direct from SRAM Rd ← (k) None 2 ST X, Rr Store Indirect (X) ← Rr None 2 ST X+, Rr Store Indirect and Post-Inc. (X) ← Rr, X ← X + 1 None 2 ST - X, Rr Store Indirect and Pre-Dec. X ← X - 1, (X) ← Rr None 2 ST Y, Rr Store Indirect (Y) ← Rr None 2 ST Y+, Rr Store Indirect and Post-Inc. (Y) ← Rr, Y ← Y + 1 None 2 ST - Y, Rr Store Indirect and Pre-Dec. Y ← Y - 1, (Y) ← Rr None 2 STD Y+q,Rr Store Indirect with Displacement (Y + q) ← Rr None 2 ST Z, Rr Store Indirect (Z) ← Rr None 2 ST Z+, Rr Store Indirect and Post-Inc. (Z) ← Rr, Z ← Z + 1 None 2 ST -Z, Rr Store Indirect and Pre-Dec. Z ← Z - 1, (Z) ← Rr None 2 STD Z+q,Rr Store Indirect with Displacement (Z + q) ← Rr None 2 STS k, Rr Store Direct to SRAM (k) ← Rr None 2 LPM Load Program Memory R0 ← (Z) None 3 LPM Rd, Z Load Program Memory Rd ← (Z) None 3 LPM Rd, Z+ Load Program Memory and Post-Inc Rd ← (Z), Z ← Z+1 None 3 551 8393C-MCU Wireless-09/14

Mnemonics Operands Description Operation Flags #Clocks ELPM Extended Load Program Memory R0 ← (RAMPZ:Z) None 3 ELPM Rd, Z Extended Load Program Memory Rd ← (RAMPZ:Z) None 3 ELPM Rd, Z+ Extended Load Program Memory Rd ← (RAMPZ:Z), None 3 RAMPZ:Z ← RAMPZ:Z+1 SPM Store Program Memory (Z) ← R1:R0 None - IN Rd, P In Port Rd ← P None 1 OUT P, Rr Out Port P ← Rr None 1 PUSH Rr Push Register on Stack STACK ← Rr None 2 POP Rd Pop Register from Stack Rd ← STACK None 2 34.5 MCU Control Instructions Mnemonics Operands Description Operation Flags #Clocks NOP No Operation None 1 SLEEP Sleep (see specific description for None 1 Sleep function) WDR Watchdog Reset (see specific description for None 1 WDR/timer) BREAK Break For On-chip Debug Only None N/A ATmega256/128/64RFR2 552 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 35 Electrical Characteristics 35.1 Absolute Maximum Ratings Note that stresses beyond those listed under “Absolute Maximum Ratings” may cause permanent damage to the device. This is a stress rating only and functional operation of the device at these or any other conditions beyond those indicated in the operational sections of this specification are not implied. Exposure to absolute maximum rating conditions for extended periods may affect device reliability. Symbol Parameter Condition Min. Typ. Max. Units T Storage temperature -50 150 °C STOR T Lead temperature T = 10s (soldering profile compliant with 260 °C LEAD IPC/JEDEC J-STD-020B) V ESD robustness Compliant to [4] 4 kV ESD P Input RF level +14 dBm RF VDDMAX Maximum voltage Maximum voltage fr om any pin to ground -0.3 3.6 V V Maximum voltage difference -0.3 0.3 V DMAXEV between DEVDD and EVDD V Voltage on all pins except pins 8,9,21,22,60,62 -0.3 V V DIG DDMAX V Voltage on pins 8,9,21,22,60,62 -0.3 2.0 V ANA V Comparator input voltage Pins with Comparator input connected by -0.3 V V COMP_IN DDMAX the analog multiplexer VPGA_IN PGA input voltage Pins with PGA inpu t connected by the -0.3 VDDMAX V analog multiplexer V ADC input voltage Pins with ADC input connected by the -0.3 2.0 V ADC_IN analog multiplexer (PGA bypassed) 35.2 Recommended Operating Range Symbol Parameter Condition Min. Typ. Max. Units T Operating temperature range -40 +85 °C OP_ZU T Operating temperature range -40 +125 °C OP_ZF V Supply voltage Voltage on pins 23,34,44,54,59(2) 1.8 3.0 3.6 V DD VDEV Voltage difference between EVDD and DEVDD should be tight 0.0 V DEVDD and EVDD together on the PCB V Supply voltage External voltage supply(1) 1.7 1.8 1.9 V DD1.8 (on pins 21,22,60) V Pin Overdrive voltage Pin Voltage exceeding supply voltage +0.3 V OVRDRV except pins 8,9,21,2 2,60,62 Notes: 1. Register VREG_CTRL needs to be programmed to disable internal voltage regulators and supply blocks by an external 1.8V supply, refer to section "Voltage Regulators (AVREG, DVREG)" on page 193. 2. Even if an implementation uses the external 1.8V voltage supply V it is required to connect V . DD1.8 DD 553 8393C-MCU Wireless-09/14

35.3 Digital Pin Characteristics Test Conditions: T = -40°C to 125°C, V =1.8V to 3.6V (unless otherwise stated) OP DD Symbol Parameter Condition Min Typ Max Units V High level input voltage(1) Except pin RSTN 0.7 V V IH DD V Low level input voltage(1) Except pin RSTN 0.3 V V IL DD V High level input voltage(1) Pin RSTN 0.9 V V IHRSTN DD V Low level input voltage(1) Pin RSTN 0.1 V V ILRSTN DD V High level output voltage(1) I = -12mA, V = 3.6V V – V OH OH DD DD I = -6mA, V = 1.8V 0.4 OH DD Maximum. drive str ength by DPDS0/1 Except Pins 17,18 V Low level output voltage(1) I = 16mA, V = 3.6V 0.4 V OL OL DD I = 10mA, V = 1.8V OL DD Maximum drive strength by DPDS0/1 Except Pins 17,18 V High level output voltage(1) I = -3mA, V = 3.6V V – V OHMIN OH DD DD I = -1.5mA, V = 1.8V 0.4 OH DD Minimum drive strength by DPDS0/1 Except Pins 17,18 V Low level output voltage(1) I = 4mA, V = 3.6V 0.4 V OLMIN OL DD I = 2.5mA, V = 1.8V OL DD Minimum. drive stre ngth by DPDS0/1 Except Pins 17,18 R Reset pull-up resistor 120 360 kΩ RSTN R GPIO pull-up resistor If pull-up resistor is enabled 120 360 kΩ GPIO I Input Leakage current V = 3.6V, pin low 1 µA IL DD T = 25 °C <10 nA I Input Leakage current V = 3.6V, pin high 1 µA IH DD T = 25 °C <10 nA Note: 1. The capacitive load should not be larger than 50 pF for all I/Os when using the default driver strength settings, refer to section "DPDS0 – Port Driver Strength Register 0" on page 206 and "DPDS1 – Port Driver Strength Register 1" on page 207. Generally, large load capacitances increase the overall current consumption. 35.4 Transceiver Pin Characteristics Test Conditions: T = 25°C, V =1.8V to 3.6V (unless otherwise stated) OP DD Symbol Parameter Condition Min Typ Max Units V DC level RF pins RFN and RFP Transceiver in BUS Y_TX 0.9 V RFNPDC1 V Transceiver in receive states 0.02 V RFNPDC2 V Transceiver, other states 0 V RFNPDC3 V DC level pins XTAL1 and XTAL2 C and C connected 0.9 V XTALDC X1 X2 Note: 1. Pins RFN and RFP require an AC coupling if the external parts (e.g. balun, antenna) have a DC path to ground. Serial capacitances and capacitance of each pin to ground must be < 30 pF. 2. For C and C see "Table 32-1" on page 541 X1 X2 ATmega256/128/64RFR2 554 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 35.5 Power Supply Currents (RF transceiver in SLEEP mode) Test Conditions: T = 25°C, V =3.0V (unless otherwise stated) OP DD Symbol Parameter Condition / AVR mode Min Typ Max Units I Power Supply Current Standby mode 0.31 mA SUPPLY (PRR0=0xFF, PRR1=0x3F, Idle 1MHz 0.45 mA 16MHz RC Oscillator selected) Idle 8MHz 0.8 mA Idle 16MHz 1.1 mA Active 1MHz 0.8 mA Active 8MHz 2.5 mA Active 16MHz 3.7 mA Power Supply Current Active, 16MHz RC Oscillator 4.0 mA (PRR0=0x00, PRR1=0x00) Active, 16MHz Crystal Oscillator 4.5 mA Active, external 16MHz clock on CLKI 4.5 mA Test Conditions: T = 25°C, V =3.0V (unless otherwise stated) OP DD Symbol Parameter Condition Min Typ Max Units I Power Supply current in AVR in Power Down mode WDT disabled 0.75 µA DS0 DEEP_SLEEP I Power Down mode, WDT enabled 1.4 µA DS_PDW (Transceiver in SLEEP mode, AVR I Power Save mode, 32.768kHz crystal 1.5 µA DS_PSX in Power Save/Down mode) oscillator enabled I Power Save mode, WDT and 32.768kHz 2.15 µA DS_PSWX crystal oscillator enabled Test Conditions: V =3.0V (unless otherwise stated) DD Symbol Parameter Condition Min Typ Max Units I DEEP_SLEEP current (Transceiver T = 25 °C 0.75 µA DS0T in SLEEP mode, AVR in Power T = 85 °C 3.0 µA Save/Down mode, WDT disabled) T = 125 °C 19.6 µA 35.6 Clock Characteristics 35.6.1 Calibrated Internal RC Oscillator Accuracy Table 35-2. Calibration Accuracy of Internal RC Oscillator Frequency V Temperature Calibration Accuracy DEVDD Factory Calibration 16 MHz 3.0V 25°C ± 10 % User Calibration 15.1 – 17.5MHz 1.8V – 3.6V -40°C - 125°C ± 1 % 35.6.2 32.768kHz Crystal Oscillator Symbol Parameter Condition Min. Typ. Max. Units f Crystal frequency 32.768 kHz 0 C External load capacitor to ground C = 2·(C – C – C ) 20.0 pF EXT32 EXT32 LOAD32 PAR32 PAR_PCB see Application schematic CX3, CX4 555 8393C-MCU Wireless-09/14

C Load capacitance as specified by the 6 12.5 pF LOAD32 crystal manufacturer C Shunt capacitance 0.6 2.0 pF SHUNT32 C Internal parasitic capacitance 2.1 2.4 2.7 pF PAR32 ESR Equivalent series resistance Crystal @ 32.768 kHz 50 100 kΩ 35.6.3 External Clock Drive (pin CLKI) Figure 35-1 External Clock Drive Waveforms V IH1 V IL1 Table 35-3. External Clock Drive Symbol Parameter Min. Max. Units 1/t Oscillator Frequency 16 MHz CLCL t Clock Period 62.5 ns CLCL tCHCX High Time 25 ns t Low Time 25 ns CLCX t Rise Time 0.1 µs CLCH t Fall Time 0.1 µs CHCL ∆t Change in period from one clock cycle to the next 1 % CLCL 35.7 System and Reset Characteristics Table 35-23. BODLEVEL Fuse Coding(1) BODLEVEL2:0 Fuses Min V Typ V Max V Units BOD BOD BOD 111 BOD Disabled 110 1.8 V 101 1.9 V 100 2.0 V 011 2.1 V 010 2.2 V 001 2.3 V 000 2.4 V Note: 1. V may be below nominal minimum operating voltage. The device is operated down to V = V during the BOT DEVDD BOT production test. This guarantees that a Brown-Out Reset will occur before V drops to a voltage where correct DEVDD operation of the microcontroller is no longer guaranteed. The test is performed using BODLEVEL = 110 for 16 MHz operation of the ATmega256/128/64RFR2. ATmega256/128/64RFR2 556 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 Table 35-5. Reset, Brown-out and Internal Voltage Characteristics Symbol Parameter Condition Min Typ Max Units V RSTN Pin Threshold Voltage 0.1V 0.9V V RST DD DD t Minimum pulse width on RSTN Pin 200 300 ns RST V Brown-out Detector Hysteresis 7.5 50 mV HYS t Min Pulse Width on Brown-out Reset 100 ns BOD V Bandgap reference voltage V = 3.0V, T = 25°C 1.2 V BG DD A Table 35-6. Power-On Reset Voltage Characteristics Symbol Parameter Condition Min(1) Typ(1) Max(1) Units Power-on Reset Threshold Voltage Power supply discharged 1.55 1.6 1.65 V (rising) (2) V POT Power-on Reset Threshold Voltage 1.45(4) 1.5(4) 1.55(4) (falling)(3) 0.9(5) 1.2(5) 1.4(5) V t Power-on Reset recovery time Time of EVDD/DEVDD<V 1.0 ms POT POT V Power-on slope rate 0.01 3300 V/ms PSR Note: 1. Values are guidelines only. 2. Threshold where device is released from reset when voltage is rising. 3. The Power-on Reset will not work unless the supply voltage has been below V (falling). POT 4. Threshold voltage if the device is not in DEEP_SLEEP state 5. DEEP_SLEEP state the threshold voltage is reduced to a second level. 35.8 Power Management Electrical Characteristics 35.8.1 Power Switches Table 35-7. Timing Characteristics of the Power Switches Symbol Parameter Condition Min. Typ. Max. Units t Power-on reset time Applies if the device is powered up. Additional 170 µs POR delay may occur if slow rising power supply. t Bandgap startup time 7 µs BG t DRT switch switch-on time 2 µs DRT_ON t Power switch switch-on time 2 µs PWRSW_ON 35.8.2 Voltage Regulators Table 35-8. Timing Characteristics of the Voltage regulators Symbol Parameter Condition Min. Typ. Max. Units t Power up time AVREG C = 1 µF 60 µs AVREG AVDD t Power up time DVREG Startup after Power-On DVREG C = 100 nF 40 µs DVDD C = 1 µF 60 µs DVDD t Power up time DVREG Startup after DEEP_SLEEP DVREG C = 100 nF… 1 µF 10 µs DVDD 557 8393C-MCU Wireless-09/14

Symbol Parameter Condition Min. Typ. Max. Units I Max. load current during ramp-up Current limitation is applied to ramp-up only. 15 mA RAMPMAX 35.8.3 Low-Leakage Voltage Regulator Table 35-28. Timing Characteristics of the Low-Leakage Voltage Regulator(1,2) Symbol Parameter Condition Min. Typ. Max. Units t Calibration time After power-on or wake-up from DEEP_SLEEP 200 µs CAL Notes: 1. Values are guidelines only. 2. The autonomous calibration process must be completed before the device can enter DEEP_SLEEP mode. Entering DEEP_SLEEP is only delayed if the CPU code execution until the sleep() command is shorter than t . See sections CAL "Low Leakage Voltage Regulator (LLVREG)" on page 194 and "Low Leakage Voltage Regulator Control" on page 195 for further details. 35.8.4 Deep-Sleep Mode Table 35-10. Timing Characteristics entering Deep-Sleep Mode (256K Byte FLASH memory configuration) Symbol Parameter Condition Min. Typ. Max. Units t Time to enter DEEP_SLEEP(1) CPU sleep() instruction to oscillator is turned off DS 3 CLK while transceiver is already in SLEEP state t Time from wake-up event to CPU running with 16 MHz RC oscillator clock, DSWRC 34 µs CPU code execution (ISR(3)) wake-up with pin change interrupt t Time from wake-up event to CPU running with 128 kHz RC oscillator clock, DSWRC128K 420 µs CPU code execution (ISR) wake-up with pin change interrupt t Time from wake-up event to CPU running with 16 MHz crystal clock DSWXT CPU code execution (ISR) (CKSEL = 0110), wake-up with pin change 600 µs interrupt (SUT = 00 (cid:3) 258 clocks)(2) t Time from wake-up event to CPU running with 16 MHz RC oscillator clock, DSWRC,TRXOFF 650 µs TRX_OFF transceiver state wake-up with pin change interrupt t Time from wake-up event to CPU running with 16 MHz crystal clock DSWXT,TRXOFF TRX_OFF transceiver state (CKSEL = 0110), wake-up with pin change 650 µs interrupt (SUT = 00 (cid:3) 258 clocks) (2) t Reduction of wake-up time for DSWOFF,128K 128K Byte FLASH memory 9 µs configuration(4) t Reduction of wake-up time for DSWOFF,64K 64K Byte FLASH memory 13 µs configuration(4) Note: 1. The automatic LLVREG calibration must have been completed or disabled. See "Low Leakage Voltage Regulator (LLVREG)" on page 194 and Table 35-28 above for details. 2. Crystal oscillator start-up times depend on CKSEL and SUT setting. See Table 11-10 on page 181 for details. 3. ISR = Interrupt Service Routine. 4. Subtract t from wake-up times given for 256K Byte FLASH memory configuration. DSWOFF ATmega256/128/64RFR2 558 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 35.9 2-wire Serial Interface Characteristics Table 35-11 below describes the requirements for devices connected to the 2-wire Serial Bus. The ATmega256/128/64RFR2 2-wire Serial Interface meets or exceeds these requirements under th e noted conditions. Timing symbols refer to Figure 35-2 on page 560. Table 35-11. 2-wire Serial Bus Requirements Symbol Parameter Condition Min Max Units V Input Low-voltage -0.5 0.3V V IL DD V Input High-voltage 0.7V V +0.5 V IH DD DD Vhys(1) Hysteresis of Schmitt Trigger Inputs 0.05VDD(2) V V (1) Output Low-voltage 3 mA sink current 0 0.4 V OL t(1) Rise Time for both SDA and SCL 20+0.1C (2,3) 300 ns r b t (1) Output Fall Time from V to V 10 pF < C < 400 pF(3) 20+0.1C (2,3) 250 ns of IHmin ILmax b b t (1) Spikes suppressed by the input filter 0 50(2) ns SP I Input current each I/O Pin 0.1V < V < 0.9V -10 10 µA i DD i DD C(1) Capacitance for each I/O Pin 10 pF i f SCL Clock frequency f (4)>max(16f ,250 kHz) (5) 0 400 kHz SCL CK SCL Rp Value of Pull-up resistor V -0.4V 1000 ns DD f ≤ 100 kHz Ω SCL 3mA C b V -0.4V 300 ns DD f > 100 kHz Ω SCL 3mA C b t Hold time (repeated) START condition f ≤ 100 kHz 4.0 µs HD;STA SCL f > 100 kHz 0.6 µs SCL t Low period of the SCL clock f ≤ 100 kHz(6) 4.7 µs LOW SCL fSCL > 10 0 kHz(7) 1.3 µs t High period of the SCL clock f ≤ 100 kHz 4.0 µs HIGH SCL f > 100 kHz 0.6 µs SCL t Set-up time for a repeated START condition f ≤ 100 kHz 4.7 µs SU;STA SCL f > 100 kHz 0.6 µs SCL t Data hold time f ≤ 100 kHz 0 µs HD;DAT SCL f > 100 kHz 0 µs SCL t Date setup time f ≤ 100 kHz 250 ns SU;DAT SCL f > 100 kHz 100 ns SCL t Setup time for STOP condition f ≤ 100 kHz 4.0 µs SU;STO SCL f > 100 kHz 0.6 µs SCL t Bus free time between a STOP and START f ≤ 100 kHz 4.7 µs BUF SCL condition f > 100 kHz 1.3 µs SCL Notes: 1. This parameter is characterized and not 100% tested 2. Required only for f > 100 kHz SCL 3. C =capacitance of one bus line in pF b 4. f =CPU clock frequency CK 559 8393C-MCU Wireless-09/14

5. This requirement applies to all the ATmega256/128/64RFR2 2-wire Serial Interface operation. Other devices connected to the 2-wire Serial Bus need only obey the general f requirement. SCL 6. The actual low period generated by the ATmega256/128/64RFR2 2-wire Serial interface is (1/f – 2/f ), thus f SCL CK CK must be greater than 6MHz for the low time requirem ent to be strictly met at fSCL = 100 kHz. 7. The actual low period generated by the ATmega256/128/64RFR2 2-wire Serial interface is (1/f – 2/f ), thus the SCL CK low time requirement will not be strictly met for f > 308 kHz when f = 8 MHz. Still, ATmega256/128/64RFR2 SCL CK devices connected to the bus may communicated at full speed (400 kHz) with other ATmega256/128/64RFR2 devices, as well as any other device with proper t acceptance margin. LOW Figure 35-2. 2-wire Serial Bus Timing tof tHIGH tr tLOW tLOW SCL tSU;STA tHD;STA tHD;DAT tSU;DAT tSU;STO SDA tBUF 35.10 SPI Timing Characteristics See Figure 35-3 on page 561 and Figure 35-4 on page 561 for details. Table 35-12. SPI Timing Parameters Description Mode Min Typ Max Units SCK period Master See "SPCR – SPI Control Register" on page 369. SCK high/low Master 50% duty cycle Rise/fall time Master 3.6 ns Setup Master 10 ns Hold Master 10 ns Out to SCK Master 0.5 t SCK SCK to out Master 10 ns SCK to out high Master 10 ns __ SS low to out Slave 10 ns SCK period Slave 4 t CK SCK high/low(1) Slave 2 t CK Rise/fall time Slave 1600 ns Setup Slave 10 ns Hold Slave t CK SCK to out Slave 15 ns __ SCK to SS high Slave 20 ns __ SS high to tri-state Slave 10 ns __ SS low to SCK Slave 20 ns Note: 1. In SPI Programming mode the minimum SCK high/low period is 2 t for f < 12 CLCL CK MHz and 3 t for f > 12 MHz. CLCL CK ATmega256/128/64RFR2 560 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 Figure 35-3. SPI timing Requirements (Master Mode) SS 6 1 SCK (CPOL = 0) 2 2 SCK (CPOL = 1) 4 5 3 MISO MSB ... LSB (Data Input) 7 8 MOSI MSB ... LSB (Data Output) Figure 35-4. SPI timing Requirements (Slave Mode) SS 10 16 9 SCK (CPOL = 0) 11 11 SCK (CPOL = 1) 13 14 12 MOSI MSB ... LSB (Data Input) 15 17 MISO MSB ... LSB X (Data Output) 35.11 ADC Characteristics Table 35-13. ADC Electrical Characteristics Symbol Parameter Condition Min Typ Max Units V Internal Voltage Reference 1.5 V REFINT1 V Internal Voltage Reference 1.6 V REFINT2 V Internal Voltage Reference AVDD V REFINT3 R External Voltage AREF,EXT 6 Ω Impedance IL,AREF Load Current Loading AREF is not r ecommended. 0.1 mA I Supply Current ADC Current (Single ended conversion, SUPPLY,ADCSE 0.85 1.0 mA f = 2MHz) CLKADC I Supply Current ADC Current with PGA (Differential SUPPLY,ADCD 1.75 2.0 mA conversion, f = 1MHz) CLKADC 561 8393C-MCU Wireless-09/14

Table 35-14. ADC Characteristics, Single Ended Channels (1)(2) Symbol Parameter Condition Min Typ Max Units d Single Ended Conversion f ≤ 4 MHz 10 Bits RES4M CLKADC Resolution d Single Ended Conversio n f = 8 MHz 8 Bits RES8M CLKADC Single Ended Conversion e 2 LSB ABS500k V = 1.6V f = 500kHz REF CLKADC Absolute accuracy (Including Single Ended Conversion e INL, DNL, quantization error, 2 LSB ABS2M V = 1.6V f = 2MHz gain and offset error) (3) REF CLKADC Single Ended Conversion e 2 LSB ABS4M V = 1.6V f = 4MHz REF CLKADC Single Ended Conversion e Integral Non-Linearity (INL) 0.8 LSB INL V = 1.6V f = 4MHz REF CLKADC Differential Non-Linearity Single Ended Conversion e -0.5 LSB DNL (DNL) V = 1.6V f = 4MHz REF CLKADC Single Ended Conversion e Gain Error 1 LSB GAIN V = 1.6V f = 4MHz REF CLKADC Single Ended Conversion e Offset Error 1.5 LSB OFFSET V = 1.6V f = 4MHz REF CLKADC t Conversion Time Free Running Conversion 3 240 µs CONV,SE f Clock Frequency Single Ended Conversion 8 MHz CLKADC V Reference Voltage 1.5 AVDD V REF VIN,SE Input Voltage 0 AVDD V f Input Bandwidth 20 kHz IBW C Input Sampling Capacitance 14 pF AIN R Analog Series Resistance(4) Between pin and sampling capacitor 2 kΩ AIN,SER R Analog Input Resistance Static load resistor of input signal 100 MΩ AIN Notes: 1. Values are guidelines only. 2. All values are valid for EVDD = 3.0V. 3. Absolute accuracies do not include dependencies on the absolute value of the reference voltage. 4. Series resistor depends on supply voltage (MOS switch resistance ~ 1/V ). SUPPLY Table 35-15. PGA and ADC Characteristics, Differential Channels (1)(2)(4) Symbol Parameter Condition Min Typ Max Units d Resolution All gain settings 10 Bits RES,D Absolute accuracy (Including Gain = 1x e INL, DNL, quantization error, 3 LSB ABS,D1 V = 1.6V f = 2MHz gain and offset error) (3) REF CLKADC Gain = 1x e Integral Non-Linearity (INL) 3 LSB INL,D1 V = 1.6V f = 2MHz REF CLKADC Differential Non-Linearity Gain = 1x e -0.75 LSB DNL,D1 (DNL) V = 1.6V f = 2MHz REF CLKADC e Gain = 1x 1 GAIN,D1 e Gain Error Gain = 10x 1.5 LSB GAIN,D10 e Gain = 200x 10 GAIN,D200 ATmega256/128/64RFR2 562 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 Symbol Parameter Condition Min Typ Max Units Gain = 1x e Offset Error 0.7 LSB OFFSET,D1 V = 1.6V f = 2MHz REF CLKADC t Conversion Time Free Running Conve rsion 100 µs CONV,D f Clock Frequency Single Ended Conversion 2 MHz CLKADC V Reference Voltage 1.5 AVDD V REF V Input Common Mode Voltage 0 EVDD V CM V Input Differential Voltage Input pin voltage ≥ 0V -AVDD AVDD V IN,DIFF d ADC Conversion Output -512 511 LSB OUT,D f Input Bandwidth 20 kHz IBW,D C Input Sampling Capacitance Gain = 200x 7.5 pF AIN,PGA R Analog Series Resistance(5) Between pin and sampling capacitor 0.5 kΩ AIN,SER R Analog Input Resistance Static load resistor of input signal 100 MΩ AIN Notes: 1. Values are guidelines only 2. All values are valid for EVDD = 3.0V 3. Absolute accuracies do not include dependencies on the absolute value of the reference voltage. 4. Performance of differential channels deteriorates if PGA output voltage is close to ground. 5. Series resistor depends on supply voltage (MOS switch resistance ~ 1/V ). SUPPLY 35.12 Temperature Sensor Characteristics Table 35-16. Temperature Sensor Characteristics Symbol Parameter Condition Min Typ Max Units T Temperature distribution Typical, No calibration performed, T = 25 ºC DISTNOCAL 3.5 K Internal1.6V Bandgap reference selected 35.13 Analog Comparator Characteristics Table 35-17. Analog Comparator Electrical Characteristics Symbol Parameter Condition Min Typ Max Units V Input Offset Voltage(1) V = 3.0V, V = V /2, T = 25°C <10 mV ACIO DD IN DD I Input Leakage Current(4) V = 3.0V, V = V /2, T = 25°C <10 nA ACLK DD IN DD t Propagation Delay(2) V = 3.0V, V = V /2, T = 25°C 175 nA ACID DD IN DD I Supply Current(3) V = 3.0V, V = V /2, T = 25°C 50 µA SUPPLY,AC DD IN DD Notes: 1. This parameter is characterized and not 100% tested. 2. Analog delay only. Output of comparator is clocked into ACO bit of ACSR register. 3. Bit ACD in register ACSR is low. 4. See also parameters I and I in section "Digital Pin Characteristics" on page 554. IL IH 35.14 Transceiver Electrical Characteristics 35.14.1 Digital Interface Timing Characteristics Test Conditions: T = 25°C, V = 3.0V, C = 50 pF (unless otherwise stated) OP DD L 563 8393C-MCU Wireless-09/14

Symbol Parameter Condition Min. Typ. Max. Units t AES core cycle time 24 µs 12 t Interrupt event latency Relative to the event on the RF pins to be 9 µs IRQ indicated (e.g. TRX 24_RX_END interrupt) t Battery monitor latency 2 µs BATMON 35.14.2 General RF Specifications Test Conditions (unless otherwise stated): V = 3.0V, f = 2.45 GHz, T = 25°C, Measurement setup see Figure 32-1 on page DD RF OP 540. Symbol Parameter Condition Min. Typ. Max. Units f Frequency range As specified in [1],[2] 2405 2480 MHz RF f Channel spacing As specified in [1],[2] 5 MHz CH f Header bit rate (SHR, PHR) As specified in [1],[2] 250 kb/s HDR f PSDU bit rate As specified in [1],[2] 250 kb/s PSDU OQPSK_DATA_RATE = 1 500 kb/s OQPSK_DATA_RATE = 2 1000 kb/s OQPSK_DATA_RATE = 3 2000 kb/s f Chip rate As specified in [1],[2] 2000 kchip/s CHIP f Crystal oscillator frequency Reference frequency oscillator 16 MHz CLK f Required reference frequency PSDU bit rate 250 kb/s -60(1) +60(1) ppm CLK_ACC accuracy 500 kb/s -40 +40 ppm 1000 kb/s -40 +40 ppm 2000 kb/s -30 +30 ppm t Reference oscillator settling time Leaving SLEEP state to crystal clock 215 1000 µs XTAL available B 20 dB bandwidth 2.8 MHz 20dB Note: 1. A reference frequency accuracy of ±40 ppm is required by [1], [2]. 35.14.3 Transmitter Characteristics Test Conditions (unless otherwise stated): V = 3.0V, f = 2.45 GHz, T = 25°C, Measurement setup see Figure 32-1 on page DD RF OP 540. Symbol Parameter Condition Min. Typ. Max. Units P TX Output power Maximum configurable TX output power 0 +3.5 +6 dBm TX value Register bit TX_PW R = 0 P Output power range 16 steps, configurable in 20 dB RANGE register PHY_TX_PWR P Output power tolerance ±3 dB ACC TX Return loss 100+j0 Ω differential impedance, 10 dB P = +3.5 dBm TX EVM 8 %rms ATmega256/128/64RFR2 564 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 Symbol Parameter Condition Min. Typ. Max. Units P Harmonics HARM 2nd harmonic -38 dBm 3rd harmonic -45 dBm P Spurious Emissions Complies with SPUR 30 – ≤ 1000 MHz EN 300 328/440, -36 dBm >1 – 12.75 GHz FCC-CFR-47 part 15, -30 dBm 1.8 – 1.9 GHz ARIB STD-66, RSS-210 -47 dBm 5.15 – 5.3 GHz -47 dBm 35.14.4 Receiver Characteristics Test Conditions (unless otherwise stated): V = 3.0V, f = 2.45 GHz, T = 25°C, PSDU bit rate = 250 kb/s, Measurement setup DD RF OP see Figure 32-1 on page 540. Symbol Parameter Condition Min. Typ. Max. Units P Receiver sensitivity AWGN channel, PER ≤ 1%, SENS 250 kb/s PSDU length 20 octets -100 dBm 500 kb/s High Data Rate Modes: -96 dBm 1000 kb/s PSDU length 20 octets -94 dBm 2000 kb/s -86 dBm Antenna Diversity 250 kb/s, PSDU 20 octets -99 dBm RL Return loss 100+j0 Ω differentia l impedance 10 dB NF Noise figure 6 dB P Maximum RX input level PER ≤ 1%, PSDU length of 20 octets 10 dBm RXMAX P Adjacent channel rejection: PER ≤ 1%, PSDU length of 20 octets, 34 dB ACRN -5 MHz PRF = -82 dBm P Adjacent channel rejection: PER ≤ 1%, PSDU length of 20 octets, 38 dB ACRP +5 MHz PRF = -82 dBm P Alternate channel rejection: PER ≤ 1%, PSDU length of 20 octets, 54 dB AACRN -10 MHz PRF = -82 dBm P Alternate channel rejection: PER ≤ 1%, PSDU length of 20 octets, 54 dB AACRP +10 MHz PRF = -82 dBm P Spurious emissions: SPUR LO leakage -71 dBm 30 – ≤ 1000 MHz -57 dBm >1 – 12.75 GHz -47 dBm f TX/RX carrier frequency offset Sensitivity loss < 2 dB -300(1) +300 kHz RXTXOFFS IIP3 3rd – order intercept point At maximum gain -14 dBm Offset freq. interf. 1 = 5 MHz Offset freq. interf. 2 = 10 MHz IIP2 2nd – order intercept point At maximum gain 17 dBm Offset freq. interf. 1 = 60 MHz Offset freq. interf. 2 = 62 MHz RSSI tolerance Tolerance within gain step ±5 dB RSSI dynamic range 81 dB 565 8393C-MCU Wireless-09/14

Symbol Parameter Condition Min. Typ. Max. Units RSSI resolution 3 dB RSSI sensitivity Defined as RSSI_BASE_VAL -90 dBm Minimum RSSI value P ≤ RSSI_BASE_VAL 0 RF Maximum RSSI value P > RSSI_BASE_VAL + 81 dB 28 RF Note: 1. Offset equals ±120 ppm 35.14.5 Current Consumption Specifications Test Conditions (unless otherwise stated): V = 3.0V, f = 2.45 GHz, T = 25°C, Measurement setup see Figure 32-1 on page DD RF OP 540. (Power Reduction Register PRR0 and PRR1 are not set). Symbol Parameter Condition Min. Typ. Max. Units IBUSY_TX Supply current transmit state PTX = 3.5 dBm 14.5 mA P = 1.5 dBm 10 mA TX P = -2.5 dBm 9 mA TX P = -16.5 dBm 8 mA TX (current consumption is reduced at V = 1.8V for each output power level) DD I Supply current RX_ON state RX_ON state, with register setting 6 mA RX_ON_RPC RPC mode enabled(2) RX_PDT_LEVEL < 8(1) I RX_ON state, with register setting 5 mA RX_ON_P_RPC RX_PDT_LEVEL > 8(1) I Supply current PLL_ON state 0.45 mA RX_ON_RPC RPC mode enabled(2) I Supply current RX_ON state RX_ON state 12.5 mA RX_ON I RPC mode disabled(2) RX_ON state, with register setting 12.0 mA RX_ON_P RX_PDT_LEVEL > 0(1) I Supply current PLL_ON state 5.7 mA PLL_ON RPC mode disabled(2) I Supply current TRX_OFF state TRX_OFF state 0.4 mA TRX_OFF I Supply current SLEEP state SLEEP state 0.02 µA SLEEP Note: 1. Refer to section " RX_SYN – Transceiver Receiver Sensitivity Control Register" on page 131. 2. Refer to section "Reduced Power Consumption Mode (RPC)" on page 104. 35.14.6 16MHz Crystal Oscillator and Crystal Parameter R equirements Symbol Parameter Condition Min. Typ. Max. Units f Crystal frequency For accuracy see "General RF 16 MHz 0 Specifications" on page 564 C Load capacitance 8 14 pF L C Static capacitance 7 pF 0 R Series resistance 100 Ω 1 ATmega256/128/64RFR2 566 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 Symbol Parameter Condition Min. Typ. Max. Units t 16MHz XTAL oscillator off-time Minimum sleep time of the transceiver 1.0 ms XTALOFF 36 Typical Characteristics 36.1 Supply Current vs. Clock Speed with Transceiver in SLEEP 36.1.1 Clock source 16MHz RC Oscillator Figure 36-5. Active Supply Current vs. Frequency (V = 3.0V, PRR0/1 = 0xFF/0x3F) DD 5 4 125°C A] 2855°°CC m -40°C n [ o pti 3 m u s n o C 2 nt e r r u C 1 0 0.0 2.0 4.0 6.0 8.0 10.0 12.0 14.0 16.0 FreqEuVeDnDcy [ V [M] Hz] 567 8393C-MCU Wireless-09/14

Figure 36-6. Active Supply Current vs. V (f =1MHz, PRR0/1 = 0xFF/0x3F) DD CLK 5 4 A] m n [ o pti 3 m u s n o C 2 nt e r r Cu 1 1 8255°°CC 25°C -40°C 0 1.8 2.0 2.2 2.4 2.6 2.8 3.0 3.2 3.4 3.6 EVDD [V] Figure 36-7. Active Supply Current vs. V (f = 16MHz, PRR0/1 = 0x00/0x00) DD CLK 5 125°C 85°C 4 25°C A] -40°C m n [ o pti 3 m u s n o C 2 nt e r r u C 1 0 1.8 2.0 2.2 2.4 2.6 2.8 3.0 3.2 3.4 3.6 EVDD [V] ATmega256/128/64RFR2 568 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 Figure 36-8. Idle Supply Current vs. V (f = 1MHz; PRR0/1 = 0xFF/0x3F) DD CLK 5 4 A] m n [ o pti 3 m u s n o C 2 ent r r u C 1 125°C 85°C 25°C -40°C 0 1.8 2.0 2.2 2.4 2.6 2.8 3.0 3.2 3.4 3.6 EVDD [V] Figure 36-9. Idle Supply Current vs. V (f = 8MHz, PRR0/1 = 0xFF/0x3F) DD CLK 5 4 A] m n [ o pti 3 m u s n o C 2 nt e r r Cu 125°C 1 85°C 25°C -40°C 0 1.8 2.0 2.2 2.4 2.6 2.8 3.0 3.2 3.4 3.6 EVDD [V] 569 8393C-MCU Wireless-09/14

36.1.2 External clock source on pin CLKI Figure 36-10. Active Supply Current vs. Frequency (V = 3.0V, PRR0/1 = 0x00/0x00) DD 5 125°C 85°C 25°C -40°C 4 A] m n [ o pti 3 m u s n o C 2 nt e r r u C 1 0 0.0 2.0 4.0 6.0 8.0 10.0 12.0 14.0 16.0 FreCqLuKen [cMyH z[M] Hz] Figure 36-11. Active Supply Current vs. Frequency (V = 3.0V, PRR0/1 = 0xFF/0x3F) DD 5 125°C 85°C 4 25°C A] -40°C m n [ o pti 3 m u s n o C 2 nt e urr C 1 0 0.0 2.0 4.0 6.0 8.0 10.0 12.0 14.0 16.0 FreqCuLeKn [cMyH [zM]Hz] ATmega256/128/64RFR2 570 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 Figure 36-12. Idle Supply Current vs. Frequency (V = 3.0V, PRR0/1 set and reset) DD 5 4 A] m n [ ptio 3 m nsu 1 8255°°CC nnoo PPRRRR o 25°C no PRR C 2 -40°C no PRR urrent 1 282555°°°CCC PPPRRRRRR ssseeettt C -40°C PRR set 1 0 0.0 2.0 4.0 6.0 8.0 10.0 12.0 14.0 16.0 FrCeLqKu e[MncHyz ] [MHz] 36.2 Current Consumption of Bandgap Source and Digital Voltage Regulator The supply currents of band-gap reference source and digital voltage regulator are part of all supply current measurement. In DEEP_SLEEP mode both units are disabled. Figure 36-13. Combined Supply Current of Bandgap Source and Voltage Regulator 1 0.9 0.8 A] m 0.7 n [ o pti 0.6 m u 0.5 s n o C 0.4 nt e rr 0.3 125°C u 85°C C 25°C 0.2 -40°C 0.1 0 1.8 2.0 2.2 2.4 2.6 2.8 3.0 3.2 3.4 3.6 CLK [MHz] EVDD [V] 36.3 Current Consumption in various Transceiver States The AVR microcontroller is in Active state (clk =16MHz) with no power reduction set CPU by the register PRR0 and PRR1. The clock source of the microcontroller is the internal 16MHz RC Oscillator. 571 8393C-MCU Wireless-09/14

Figure 36-14. TRXOFF state supply current vs V DD 22 20 18 A] 16 m n [ 14 o pti m 12 u s n 10 o C ent 8 urr 6 125°C C 85°C 25°C 4 -40°C 2 0 1.8 2.0 2.2 2.4 2.6 2.8 3.0 3.2 3.4 3.6 EVDD [V] Figure 36-15. RX_ON state supply current vs. V DD 22 20 125°C 18 85°C A] 16 25°C m n [ 14 -40°C o pti m 12 u s n 10 o C nt 8 e urr 6 C 4 2 0 1.8 2.0 2.2 2.4 2.6 2.8 3.0 3.2 3.4 3.6 EVDD [V] ATmega256/128/64RFR2 572 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 Figure 36-16. RX_ON State Supply Current vs. V , RPC Enabled DD 22 20 18 A] m 16 n [ o 14 pti m 12 125°C su 85°C n 10 27°C o -40°C C nt 8 e rr 6 u C 4 2 0 1.8 2.0 2.2 2.4 2.6 2.8 3.0 3.2 3.4 3.6 EVDD [V] Figure 36-17. RX_ON State Supply Current, RPC Enabled, RX_PDT_LEVEL = 15 22 20 18 A] m 16 on [ 14 pti m 12 su 125°C n 10 85°C Co 27°C nt 8 -40°C e rr 6 u C 4 2 0 1.8 2.0 2.2 2.4 2.6 2.8 3.0 3.2 3.4 3.6 EVDD [V] 573 8393C-MCU Wireless-09/14

Figure 36-18. TX Active state supply current vs. V (maximum TX output power) DD 22 125°C 20 85°C 25°C 18 -40°C A] 16 m n [ 14 o pti m 12 u s n 10 o C ent 8 urr 6 C 4 2 0 1.8 2.0 2.2 2.4 2.6 2.8 3.0 3.2 3.4 3.6 EVDD [V] 36.4 RF Measurements For all RF power measurement results the calibration level is the differential RF input of the device. It enables an easy calculation for the different RF front-ends with external power amplifier and/or RF switches (diversity, RX/TX). The combined loss of Balun, strip-line and SMA connecter on the Radio-Controller-Board is <1dB. 36.4.1 Packet Error Rate (PER) Figure 36-19. PER vs. input power for 250kbit mode 10 9 8 7 6 %] R [ 5 E P 4 3 2 1 EVDD=1.8V 0 EVDD=3.0V EVDD=3.6V -102.0 -100.0 -98.0 -96.0 -94.0 -92.0 -90.0 Input Power [dBm] ATmega256/128/64RFR2 574 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 36.4.2 Transmit Power Figure 36-20. TX maximum output power 5 Bm] 4 -40 °C d r [ 25 °C e w o 85 °C P 3 ut p 125 °C ut O m 2 u m xi a M X 1 T 0 1.8 2.0 2.2 2.4 2.6 2.8 3.0 3.2 3.4 3.6 Supply Voltage [V] Figure 36-21. TX output power vs. TX_PWR in register PHY_TX_PWR 10 5 m] B 0 d er [ w Po -5 ut p ut O -10 X T -15 -40 °C 25 °C 85 °C -20 125 °C 0.0 2.0 4.0 6.0 8.0 10.0 12.0 14.0 16.0 TX_PWR register value [#] 575 8393C-MCU Wireless-09/14

36.5 BOD Threshold Figure 36-22. Brown-out Threshold vs. Temperature (Rising Supply Voltage) 3 2.5 BOD_LEVEL=2.4 BOD_LEVEL=2.3 V] BBOODD__LLEEVVEELL==22..12 p [ 2 BOD_LEVEL=2.0 u BOD_LEVEL=1.9 el BOD_LEVEL=1.8 v e ge l 1.5 a olt v h c 1 wit s 0.5 0 -40.0 -20.0 0.0 20.0 40.0 60.0 80.0 100.0 120.0 Temperature [°C] Figure 36-23. Brown-out Threshold vs. Temperature (Falling Supply Voltage) 3 2.5 BOD_LEVEL=2.4 V] BOD_LEVEL=2.3 n [ BBOODD__LLEEVVEELL==22..12 w 2 BOD_LEVEL=2.0 do BOD_LEVEL=1.9 el BOD_LEVEL=1.8 v e e l 1.5 g a olt v h 1 c wit s 0.5 0 -40.0 -20.0 0.0 20.0 40.0 60.0 80.0 100.0 120.0 Temperature [°C] ATmega256/128/64RFR2 576 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 36.6 Pin Driver Strength Figure 36-24. I/O Pin Output Voltage vs. Source Current (V = 3.0V, DPDS0=0) DD 0.45 125°C 85°C 25°C -40 °C 0.4 0.35 0.3 V] H [ 0.25 O V D- 0.2 D V E 0.15 0.1 0.05 0 0.0 1.0 2.0 3.0 4.0 5.0 6.0 7.0 8.0 IOH [mA] Figure 36-25. I/O Pin Output Voltage vs. Source Current (25°C, DPDS0=0) 0.7 0.6 EVDD=1.8 0.5 V] H [ 0.4 O EVDD=2.4 _ V D- 0.3 EVDD=3.0 VD EVDD=3.6 E 0.2 0.1 0 0.0 1.0 2.0 3.0 4.0 5.0 6.0 7.0 8.0 I_OH [mA] 577 8393C-MCU Wireless-09/14

Figure 36-26. I/O Pin Output Voltage vs. Source Current (25°C, V = 3.0V) DD 0.45 DPD=0 DPD=1 DPD=2 DPD=3 0.4 0.35 0.3 V] H [ 0.25 O V D- 0.2 D V E 0.15 0.1 0.05 0 0.0 5.0 10.0 15.0 20.0 25.0 30.0 IOH [mA] Figure 36-27. I/O Pin Output Voltage vs. Sink Current (V =3.0V, DPDS0 = 0) DD 0.45 125°C 85°C 0.4 25°C 0.35 0.3 -40 °C V] 0.25 L [ O V 0.2 0.15 0.1 0.05 0 0.0 1.0 2.0 3.0 4.0 5.0 6.0 7.0 8.0 IOL [mA] ATmega256/128/64RFR2 578 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 Figure 36-28. I/O Pin Output Voltage vs. Sink Current (25°C, DPDS0=1) 0.3 0.25 125 degC 85 degC 0.2 25 degC V] L [ 0.15 -40 degC O _ V 0.1 0.05 0 0.0 1.0 2.0 3.0 4.0 5.0 6.0 7.0 8.0 I_OL [mA] Figure 36-29. I/O Pin Output Voltage vs. Sink Current (25°C, V = 3.0V) DD 0.45 DPD=0 DPD=1 DPD=2 DPD=3 0.4 0.35 0.3 V] 0.25 L [ O V 0.2 0.15 0.1 0.05 0 0.0 5.0 10.0 15.0 20.0 25.0 30.0 IOL [mA] 579 8393C-MCU Wireless-09/14

36.7 Power-Down Current Figure 36-30. Power-Down Current vs. Temperature (Watchdog Disabled) 3.6V 3.0V 1.8V 10 7 5 3 A] µ 2 [ Y L P UP 1 S I 0.7 0.5 0.3 0.2 0.1 -40 -25 -10 5 20 35 50 65 80 95 110 125 Temperature [°C] Figure 36-31. Power-Down Current vs. Supply Voltage (Watchdog Disabled) 125°C 10 7 5 3 85°C A] µ 2 [ Y L P UP 1 S 25°C I 0.7 0.5 -40°C 0.3 0.2 0.1 1,8 2,0 2,2 2,4 2,6 2,8 3,0 3,2 3,4 3,6 V [V] DD ATmega256/128/64RFR2 580 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 Figure 36-32. Power-Down Current vs. Temperature (Watchdog Enabled) 3.6V 3.0V 10 1.8V 7 5 3 A] µ 2 [ Y L P UP 1 S I 0.7 0.5 0.3 0.2 0.1 -40 -25 -10 5 20 35 50 65 80 95 110 125 Temperature [°C] Figure 36-33. Power-Down Current vs. Supply Voltage (Watchdog Enabled) 125°C 10 7 5 85°C 3 A] µ 2 [ 25°C Y L P UP 1 -40°C S I 0.7 0.5 0.3 0.2 0.1 1,8 2,0 2,2 2,4 2,6 2,8 3,0 3,2 3,4 3,6 VDD[V] 36.8 Static ADC Parameter – INL and DNL All static parameter of the ADC have been obtained with f = 2 MHz, SUT = 10, ADCLK THT = 0 and an internal reference voltage of 1.6V. 581 8393C-MCU Wireless-09/14

Figure 36-34. Integral Nonlinearity vs. Output Code (Single-Ended, 3.0V, 25°C) 0.8 0.6 0.4 ] B S L 0.2 L [ N I 0.0 -0.2 -0.4 0 128 256 384 512 640 768 896 1024 Digital Output Code Figure 36-35. Differential Nonlinearity vs. Output Code (Single-Ended, 3.0V, 25°C) 0.3 0.2 0.1 ] B S L 0.0 L [ N D -0.1 -0.2 -0.3 0 128 256 384 512 640 768 896 1024 Digital Output Code ATmega256/128/64RFR2 582 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 Figure 36-36. Integral Nonlinearity vs. Output Code (with PGA, Gain=10, 3.0V, 25°C) 1.0 0.0 -1.0 ] B S L L [ N -2.0 I -3.0 -4.0 -512 -384 -256 -128 0 128 256 384 512 Digital Output Code Figure 36-37. Differential Nonlinearity vs. Output Code (with PGA, Gain=10, 3.0V, 25°C) 0.8 0.6 0.4 ] B S L L [ 0.2 N D 0.0 -0.2 -0.4 -512 -384 -256 -128 0 128 256 384 512 Digital Output Code 583 8393C-MCU Wireless-09/14

Figure 36-38. Integral Nonlinearity vs. Temperature at V = 3.6V DEVDD 16 14 12 B] 10 S L Gain = 200 [ X 8 A M L| N 6 |I 4 Gain = 10 2 Gain = 1 Single Ended 0 -40 -20 0 20 40 60 80 100 120 140 Temperature [°C] Figure 36-39. Integral Nonlinearity vs. Supply Voltage at 25°C 16 14 12 B] 10 Gain = 200 S L [ X 8 A M L| N 6 |I 4 Gain = 10 Gain = 1 2 Single Ended 0 1.8 2.0 2.2 2.4 2.6 2.8 3.0 3.2 3.4 3.6 V [V] DD ATmega256/128/64RFR2 584 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 Figure 36-40. Differential Nonlinearity vs. Temperature at V = 3.6V EVDD 7 Gain = 200 6 5 ] B S L 4 [ X A M L| 3 N D | 2 1 Gain = 10 Gain = 1 Single Ended 0 -40 -20 0 20 40 60 80 100 120 140 Temperature [°C] Figure 36-41. Differential Nonlinearity vs. Supply Voltage V at 25°C EVDD 7 6 Gain = 200 5 ] B S L 4 [ X A M L| 3 N D | 2 1 Gain = 10 Gain = 1 Single Ended 0 1.8 2.0 2.2 2.4 2.6 2.8 3.0 3.2 3.4 3.6 V [V] DD 36.9 Dynamic ADC Parameter – ENOB The dynamic ADC parameters for the single-ended channels have been measured with f = 4 MHz, SUT = 20, THT = 0 and an internal reference voltage of 1.6V. The sine ADCLK 585 8393C-MCU Wireless-09/14

wave of the input signal had a frequency of f = 20.207 kHz and peak-to-peak IN,SIN amplitude of V = 1.58V. IN,PP Figure 36-42. 2048 Point F FT Output for a Single-Ended ADC Channel (3.0V, 25 °C) 20 20.21; 0.00 SINAD = 57.54 dB 0 ENOB = 9.27 bit -20 THD = -63.08 dB ] B d e [ -40 d u plit -60 40.41; -64.27 m 60.62; -74.25 80.83; -71.80 A 101.04; -78.53 -80 -100 -120 0 20 40 60 80 100 120 140 160 Frequency [kHz] Figure 36-43. Effective Number of Bits vs. Supply Voltage for Single-Ended Channels 10.0 125°C 9.5 85°C 25°C -40°C 9.0 8.5 ] B S L B [ 8.0 O N E 7.5 7.0 6.5 6.0 1.8 2.0 2.2 2.4 2.6 2.8 3.0 3.2 3.4 3.6 V [V] DD ATmega256/128/64RFR2 586 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 The dynamic ADC parameters for the differential channels with a gain of 10 have been measured with f = 2 MHz, SUT = 10, THT = 0 and an internal reference voltage of ADCLK 1.6V. The input sine wave had a frequency of f = 20.124 kHz and peak-to-peak IN,SIN amplitude of V = 0.31V. IN,PP Figure 36-44. 2048 Point FFT Output for a Gain=10 ADC Channel (3.0V, 25 °C) 20 SINAD = 43.59 dB 20.12; 0.00 0 ENOB = 6.95 bit THD = -51.61 dB -20 ] B d e [ -40 d 40.25; -53.42 60.37; -56.28 u lit -60 p m A -80 -100 -120 0 10 20 30 40 50 60 70 80 Frequency [kHz] Figure 36-45. Effective Number of Bits vs. Supply Voltage for Gain=10 Channels 10.0 9.5 9.0 8.5 ] B S L B [ 8.0 O N E 7.5 7.0 85°C 125°C 25°C 6.5 -40°C 6.0 1.8 2.0 2.2 2.4 2.6 2.8 3.0 3.2 3.4 3.6 V [V] DD 587 8393C-MCU Wireless-09/14

36.10 ADC Voltage Reference Figure 36-46. 1.6V ADC Voltage Reference vs. Supply Voltage 1.63 1.62 1.61 125°C V] 1.60 2875°°CC [F E R A V 1.59 -40°C 1.58 1.57 1.56 1.8 2.0 2.2 2.4 2.6 2.8 3.0 3.2 3.4 3.6 V [V] DD 36.11 Temperature Sensor The temperature measurement results have been measured with an ADC clock of 500 kHz, SUT = 80, THT = 4 a nd an internal reference voltage of 1.6V. To enhance the accuracy and resolution the data of 128 measurements per temperature step have been decimated. ATmega256/128/64RFR2 588 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 Figure 36-47. Measured Temperature Value vs. Temperature and V EVDD 140 3.6V 3.0V 120 1.8V ] 100 C ° e [ 80 r u t a er 60 p m e 40 T d e r 20 u s a Me 0 -20 -40 -40 -20 0 20 40 60 80 100 120 140 Temperature [°C] Figure 36-48. Error of Measured Temperature Value θ – θ vs. Temperature MEAS IDEAL 4 3 3.0V 2 ] C 1 ° r [ o r 0 r E n a e -1 M -2 -3 -4 -40 -20 0 20 40 60 80 100 120 140 Temperature [°C] 589 8393C-MCU Wireless-09/14

Figure 36-49. Standard Deviation of Measured Temperature vs. Temperature 1.0 0.8 ] C ° n [ 0.6 o ti a evi 0.4 D d 3.0V r a d 0.2 n a t S 0.0 -0.2 -40 -20 0 20 40 60 80 100 120 140 Temperature [°C] 36.12 Internal Oscillator Speed Figure 36-50. 128 kHz RC Oscillator Frequency vs. OSCCAL Register Value 200 125°C 85°C 175 25°C -40°C 150 125 ] z H k 100 [C fR 75 50 25 0 0 32 64 96 128 160 192 224 256 OSCCAL ATmega256/128/64RFR2 590 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 Figure 36-51. 128 kHz RC Oscillator Frequency vs. Supply Voltage 200 175 150 125°C 85°C 125 25°C ] -40°C z H k 100 [C R f 75 50 25 0 1.8 2.0 2.2 2.4 2.6 2.8 3.0 3.2 3.4 3.6 V [V] DD Figure 36-52. 16 MHz RC Oscillator Frequency vs. OSCCAL Register Value 24 125°C 85°C 25°C 20 -40°C 16 ] z H M 12 [C R f 8 4 0 0 32 64 96 128 160 192 224 256 OSCCAL 591 8393C-MCU Wireless-09/14

Figure 36-53. 16 MHz RC Oscillator Frequency vs. Supply Voltage V DEVDD 24 20 125°C 85°C 16 25°C -40°C ] z H M 12 [C R f 8 4 0 1.8 2.0 2.2 2.4 2.6 2.8 3.0 3.2 3.4 3.6 V [V] DD 36.13 Programming Current The programming currents shown in the following figures are averaged over the entire write/erase time. The value is primarily defined by the integrated charge pump. Therefore the currents for Flash, EEPROM, Fuse- and Lock-bit programming operations are similar. ATmega256/128/64RFR2 592 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 Figure 36-54. Programming Current vs. Supply Voltage V DEVDD 7 -40°C 25°C 6 85°C 125°C 5 ] A m 4 [ Y L P P 3 SU I 2 1 0 1.8 2.0 2.2 2.4 2.6 2.8 3.0 3.2 3.4 3.6 V [V] DD 593 8393C-MCU Wireless-09/14

37 Ordering Information ATmega256RFR2 Speed (MHz) Power Supply Ordering Code Pa ckage Packing Operation Range 16 1.8 – 3.6V ATmega256RFR2-ZU PI Tray Industrial (-40°C to 85°C) 16 1.8 – 3.6V ATmega256RFR2-ZUR PI Tape & Reel Industrial (-40°C to 85°C) 16 1.8 – 3.6V ATmega256RFR2-ZF PI Tray Industrial (-40°C to 125°C) 16 1.8 – 3.6V ATmega256RFR2-ZFR PI Tape & Reel Industrial (-40°C to 125°C) Notes: 1. Pb-free packaging, complies to European Directive for Restriction of Hazardous Substances (RoHS directive). Also Halide free and fully Green. 2. Performance figures for 125°C are only valid for devices with ordering code ATmega256RFR2-ZF/-ZFR. Package Type PI 64-lead, 9 x 9 x 0.9 mm Body, Quad Flat No-lead Package (QFN) ATmega256/128/64RFR2 594 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 ATmega128RFR2 Speed (MHz) Power Supply Ordering Code Package Packing Operation Range 16 1.8 – 3.6V ATmega128RFR2-ZU PI Tray Industrial (-40°C to 85°C) 16 1.8 – 3.6V ATmega128RFR2-ZUR PI Tape & Reel Industrial (-40°C to 85°C) 16 1.8 – 3.6V ATmega128RFR2-ZF PI Tray Industrial (-40°C to 125°C) 16 1.8 – 3.6V ATmega128RFR2-ZFR PI Tape & Reel Industrial (-40°C to 125°C) Notes: 1. Pb-free packaging, complies to European Directive for Restriction of Hazardous Substances (RoHS directive). Also Halide free and fully Green. 2. Performance figures for 125°C are only valid for devices with ordering code ATmega128RFR2-ZF/-ZFR. Package Type PI 64-lead, 9 x 9 x 0.9 mm Body, Quad Flat No-lead Package (QFN) 595 8393C-MCU Wireless-09/14

ATmega64RFR2 Speed (MHz) Power Supply Ordering Code Package Packing Operation Range 16 1.8 – 3.6V ATmega64RFR2-ZU PI Tray Industrial (-40°C to 85°C) 16 1.8 – 3.6V ATmega64RFR2-ZUR PI Tape & Reel Industrial (-40°C to 85°C) 16 1.8 – 3.6V ATmega64RFR2-ZF PI Tray Industrial (-40°C to 125°C) 16 1.8 – 3.6V ATmega64RFR2-ZFR PI Tape & Reel Industrial (-40°C to 125°C) Notes: 1. Pb-free packaging, complies to European Directive for Restriction of Hazardous Substances (RoHS directive). Also Halide free and fully Green. 2. Performance figures for 125°C are only valid for devices with ordering code ATmega64RFR2-ZF/-ZFR. Package Type PI 64-lead, 9 x 9 x 0.9 mm Body, Quad Flat No-lead Package (QFN) ATmega256/128/64RFR2 596 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 38 Packaging Information PI d ccc C A d aaa C A A2 A D A3 A1 d bbb C B 0.10 E LASER MARK FOR PIN 1 B IDENTIFICATION IN THIS AREA SEATING C PLANE TOP VIEW DRAWINGS NOT SCALED D2 SIDE VIEW 1.27 MILLIMETER INCH SYMBOL MIN. NOM. MAX. MIN. NOM. MAX. A --- --- 0.90 --- --- 0.035 A1 --- --- 0.05 --- --- 0.001 R A2 --- 0.65 0.70 --- 0.026 0.028 PIN1 ID A3 0.20 REF. 0.008 REF. E2 0.20 R b 0.18 0.25 0.30 0.007 0.010 0.012 0.45 D 9.00 bsc 0.354 bsc D2 5.55 5.65 5.75 0.219 0.222 0.226 E 9.00 bsc 0.354 bsc 1.72 E2 4.65 4.75 4.85 0.183 0.187 0.191 L L 0.35 0.40 0.45 0.014 0.016 0.018 b e e 0.50 bsc 0.020 bsc L j 0.10 m C A B R 0.09 --- --- 0.004 --- --- TOLERANCES OF FORM AND POSITION BOTTOM VIEW aaa 0.10 0.004 bbb 0.10 0.004 ALL DIMENSIONS ARE IN MILLIMETERS. ccc 0.05 0.002 02/12/2008 PACKAGE WARPAGE MAX 0.08 mm. TITLE DRAWING No. REV. Atmel Nantes S.A. La Chantrerie - BP 70602 PI - 64 leads - 9.0 x 9.0 mm - pitch 0.5mm 44306 Nantes Cedex 3 - France Quad Flat No Lead Package QFN PI A 597 8393C-MCU Wireless-09/14

39 Errata 39.1 ATmega256RFR2 revision D • Interrupt restrictions in Deep-sleep Mode • Device does not enter Deep-Sleep if no crystal is connected to XTAL pins 39.2 ATmega256RFR2 revision C • Interrupt restrictions in Deep-sleep Mode • Device does not enter Deep-Sleep if no crystal is connected to XTAL pins 39.3 ATmega256RFR2 revision B • Interrupt restrictions in Deep-sleep Mode • Device does not enter Deep-Sleep if no crystal is connected to XTAL pins • PMU shows erroneous behavior with a 3µs period 39.4 ATmega256RFR2 revision A Not sampled. 39.5 ATmega128RFR2 revision D • Interrupt restrictions in Deep-sleep Mode • Relocation of sleep instruction within boot section not sufficient • Device does not enter Deep-Sleep if no crystal is connected to XTAL pins 39.6 ATmega128RFR2 revision A, B, C Not sampled. 39.7 ATmega64RFR2 revision D • Interrupt restrictions in Deep-sleep Mode • Relocation of sleep instruction within boot section not sufficient • Device does not enter Deep-Sleep if no crystal is connected to XTAL pins 39.8 ATmega64RFR2 revision A, B, C Not sampled 39.9 Detailed errata description 39.9.1 Device does not enter Deep-Sleep if no crystal is connected to XTAL pins If the device is used without the transceiver then there may be no crystal connected to the pins XTAL1 and XTAL2. The transceiver will then not enter its sleep state if the SLPTR bit in the TRXPR register is set and in consequence the device will not enter the deep sleep power-down state. (3672) Problem Fix/Workaround To disable the transceiver set the PRTRX24 bit in the PRR1 register. ATmega256/128/64RFR2 598 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 39.9.2 PMU shows erroneous behavior with a 3µs period The results from the phase measurement unit (PMU) depend on the length of the initial delay between a frequency change and the start of the phase measurement process (software timer). If the timer delay is increased then after adding 3µs, the same results are achieved. For some delay settings the PMU results are correct, for others they are wrong. (3768) Problem Fix/Workaround The software has to guarantee equidistant PMU measurements. The measurement start must be aligned to the internal clocks for instance by tweaking the program code with nop instructions. 39.9.3 Interrupt restrictions in Deep-sleep Mode In Deep-Sleep Mode, there is a restriction regarding allowed memory location for the sleep instruction. Otherwise the interrupts will be disabled and can not wake-up the device. (4567) Problem Fix/Workaround There are two safe constellations where Deep-sleep Mode is guaranteed to allow interrupts waking up the device. • If the IVSEL bit is not set (default value), the PC must be below the lowest possible boot segment, i.e. below word address 0x1F000 (byte address 0x3E000) for the 256K Byte FLASH memory configuration (application section of the memory). • If the IVSEL bit is set, the PC must be above the beginning of the smallest (topmost) possible boot segment, i .e. above word address 0x1FE00 (byte address 0x3FC00) for the 256K Byte FLASH memory configuration. Note that the addresses mentioned are independent of the actual state of the BOOTSZ[1:0] fuse bits in high fuse. The memory locations for wakeup by interrupts from Deep-Sleep have to been told to compiler respective linker as describe below. • Pseudo-code listing inclu ding Compiler directives for actions to take for Deep-Sleep // relocate function to last quarter of FLASH boot section // ADDRESS=0x3FC00 / 256K Byte FLASH void go_sleep_boot(void) __attribute__((section(".high"), noinline)); void go_sleep_boot(void) { asm(“SLEEP”); } // relocate function to the application section // ADDRESS=0x3E000 / 256K Byte FLASH // default bootloader fuse settings void go_sleep_appl(void) __attribute__((section(".text"), noinline)); void go_sleep_appl(void) { asm(“SLEEP”); } // Beware that at least one interrupt source must // be setup and enabled when entering here. void gosleep(void) { /* prepare Deep-sleep Mode */ 599 8393C-MCU Wireless-09/14

PRR1 = (1 << PRTRX24); /* power-off transceiver */ SMCR = (2 << SM0) | (1 << SE); if (MCUCR & (1 << IVSEL)) go_sleep_boot(); else go_sleep_appl(); /* back from sleep here */ SMCR = 0; } Linker options to relocate the interrupt functions to the required memory address the linker need to have following options added (related to 256kByte FLASH memory configuration): …. -Wl,--section-start=. text=0x3E000 -Wl,--section-start=.high=0x3FC00 For other tool chains please contact the tool vendor. If the source code needs to be portable for all memory configurations consider the limitations as described in the chapter "Relocation of sleep instruction within boot section not sufficient" below. 39.9.4 Relocation of sleep instruction within boot section not sufficient Relocation of sleep instruction within the boot section as described in chapter 39.9.3 above for the 256K Byte FLASH memory configuration does not wakeup the devices with a smaller FLASH memory configuration (128K Byte, 64K Byte). (4567) Problem Fix/Workaround Do not use wakeup interrupts in the boot section. It is recommended to place the wakeup interrupts in the application section. If it is required to save current while executing the program from the boot section choose an appropriated mode as described in the chapter "AVR Microcontroller Sleep Modes" on page 186. If the transceiver is not in S LEEP state the use of PowerDown respective PowerSave mode is possible because the device will not enter DeepSleep mode. ATmega256/128/64RFR2 600 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 40 Revision history Please note that the referring page numbers in this section are referring to this document. The referring rev ision in this section are referring to the document revision Rev. 8393C-MCU Wireless-09/14 1. Routing of divided EVDD voltage to the comparator added in the chapter "EVDD Voltage Measurement" on page 463 2. Endurance value corrected in the chapter "In-System Reprogrammable Flash Program Memory" on page 18 3. Errata section added 4. Product names replaced by FLASH memory configuration in chapters "Stack Pointer" on page 13 and "Deep-Sleep Mode" on page 558 5. Comment in pseudo code in chapter "Reading the Signature Row from Software" on page 494 changed to English 6. Additional cross-link to TX chapter added in "External RF-Front End Control" on page 98 7. Assembly code and some details added to chapter "Reading the Signature Row from Software" on page 494 8. "Factory Row" replaced by "Signature Row" in NEMCR – Flash Extended-Mode Control-Register on page 503 9. Relation between SRT and Frame Buffer Protection added in "Dynamic Frame Buffer Protection" on page 99 and "SRT – Smart Receiving Technology" on page 104 10. Relation between SRT and Random Number generator added in "SRT – Smart Receiving Technology" on page 104. 11. Assembly code and some details added to chapter "Reading the Signature Row from Software" on page 494 12. Old identifier TST_FRAME_LENGTH replaced by TST_RX_LENGTH Rev. 8393B-MCU Wireless-02/13 1. Wrong revision reference / device reference removed 2. Added register "TRX_CTRL_0 – Tranceiver Control Register 0" on page 116 3. Enumeration in the register VERSION_NUM corrected 4. Added register "TST_SDM – Transceiver Sigma-Delta Modulator Control and Test Register" on page 155 5. Added register "TST_AGC – Transceiver Automatic Gain Control and Test Register" on page 154 6. New register added to "Register Summary" on page 543 7. Electrical parameter corrected 8. Added register SCTRSTHH/HL/LH/LL, SCRSTRHH/HL/LH/LL and "SCCSR – Symbol Counter Compare Source Register " on page 161 9. Added register "IRQ_STATUS1 – Transceiver Interrupt Status Register 1" on page 127 and "IRQ_STATUS – Transceiver Interrupt Status Register" on page 127 10. Voltage regulator - maximum load current during ramp-up added (coin cell support). 11. Chapter "Random Number Generator" on page 92 – missing modes added to note 12. Chapter "Phase Difference Measurement" on page 106 added Rev. 8393A-MCU Wireless-11/12 1. Initial release 601 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 602 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 Table of Contents Features .................................................................................................. 1 Applications ............... ............................................................................ 1 1 Pin Configurations .............................................................................. 2 2 Disclaimer ............................................................................................ 2 3 Overview .............................................................................................. 3 3.1 Block Diagram ........................................................................................................ 3 3.2 Pin Descriptions......... ............................................................................................. 5 3.3 Unused Pins ........................................................................................................... 7 3.4 Compatibility to ATmega128RFA1 ......................................................................... 7 4 Resources............................................................................................ 7 5 About Code Exampl es ........................................................................ 7 6 Data Retention and Endurance .......................................................... 7 6.1 Data Retention........................................................................................................ 7 6.2 Endurance of the Code Memory (FLASH) ............................................................. 7 6.3 Endurance of the Data Memory (EEPROM) .......................................................... 8 7 AVR CPU Core ..................................................................................... 9 7.1 Introduction ............................................................................................................. 9 7.2 Architectural Overview ........................................................................................... 9 7.3 ALU – Arithmetic Logic Unit ................................................................................. 10 7.4 Status Register .......... ........................................................................................... 11 7.5 General Purpose Register File ............................................................................. 12 7.6 Stack Pointer ........................................................................................................ 13 7.7 Instruction Execution Timing ................................................................................ 15 7.8 Reset and Interrupt Handling ............................................................................... 15 8 AVR Memories ................................................................................... 18 8.1 In-System Reprogrammable Flash Program Memory.......................................... 18 8.2 SRAM Data Memory ............................................................................................ 18 8.3 EEPROM Data Memory ....................................................................................... 20 8.4 EEPROM Register De scription ............................................................................ 26 8.5 I/O Memory ........................................................................................................... 28 8.6 General Purpose I/O Registers ............................................................................ 29 8.7 Other Port Registers ............................................................................................. 30 9 Low-Power 2.4 GHz Transceiver ...................................................... 32 9.1 Features ............................................................................................................... 32 9.2 General Circuit Description .................................................................................. 33 603 8393C-MCU Wireless-09/14

9.3 Transceiver to Microcontroller Interface ............................................................... 34 9.4 Operating Modes .................................................................................................. 38 9.5 Functional Description .......................................................................................... 67 9.6 Module Description ............................................................................................... 80 9.7 Radio Transceiver Usage ..................................................................................... 90 9.8 Radio Transceiver Extended Feature Set ............................................................ 92 9.9 Continuous Transmission Test Mode ................................................................. 107 9.10 Abbreviations .................................................................................................... 108 9.11 Reference Documen ts ...................................................................................... 110 9.12 Register Description ......................................................................................... 111 10 MAC Symbol Counter ................................................................... 157 10.1 Main Features................................................................................................... 157 10.2 Clock source selection and Sleep/Active mode operation ............................... 157 10.3 32 bit Register Access (Atomic Read/Write) .................................................... 158 10.4 Symbol Counter (32 bit, SCCNT) ..................................................................... 158 10.5 Symbol Counter SFD Timestamp Register (32 bit, SCTSR, Read Only) ........ 158 10.6 Symbol Counter Beacon Timestamp Register (32 bit, SCBTSR) .................... 159 10.7 Compare Unit (3x 32 bit, SCOCR1, SCOCR2, SCOCR3) ............................... 159 10.8 Interrupt Control Registers ............................................................................... 159 10.9 Backoff Slot Counter ........................................................................................ 160 10.10 Symbol Counter Usage .................................................................................. 160 10.11 Register Description ....................................................................................... 161 11 System Clock and Clock Options ................................................ 176 11.1 Overview ........................................................................................................... 176 11.2 Clock Systems and their Distribution ............................................................... 176 11.3 Clock Sources .................................................................................................. 177 11.4 Calibrated Internal RC Oscillator ...................................................................... 178 11.5 128 kHz Internal Oscillator ............................................................................... 179 11.6 External Clock .................................................................................................. 179 11.7 Transceiver Crystal Oscillator .......................................................................... 180 11.8 Clock Output Buffer . ......................................................................................... 181 11.9 Timer/Counter Oscillator .................................................................................. 181 11.10 System Clock Prescaler ................................................................................. 181 11.11 Register Description ....................................................................................... 182 12 Power Management and Sleep Modes ........................................ 185 12.1 Deep-Sleep Mode ............................................................................................ 185 ATmega256/128/64RFR2 604 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 12.2 AVR Microcontroller Sleep Modes ................................................................... 186 12.2.6 Extended Standby Mode ............................................................................... 188 12.3 Power Reduction Register ................................................................................ 188 12.4 Minimizing Power Consumption ....................................................................... 189 12.5 Supply Voltage and Leakage Control ............................................................... 191 12.6 Register Description ......................................................................................... 196 13 System Control and Reset ........................................................... 209 13.1 Resetting the AVR ............................................................................................ 209 13.2 Reset Sources ......... ......................................................................................... 209 13.3 Internal Voltage Reference ............................................................................... 212 13.4 Watchdog Timer ............................................................................................... 213 13.5 Register Description ......................................................................................... 216 14 I/O-Ports ................. ........................................................................ 219 14.1 Introduction ....................................................................................................... 219 14.2 Ports as General Digital I/O .............................................................................. 220 14.3 Alternate Port Functions ................................................................................... 224 14.4 Register Description ......................................................................................... 236 15 Interrupts ....................................................................................... 243 15.1 Interrupt Vectors in ATmega256/128/64RFR2 ................................................. 243 15.2 Reset and Interrupt Vector Placement ............................................................. 245 15.3 Moving Interrupts Between Application and Boot Section ............................... 248 15.4 Register Description ......................................................................................... 249 16 External Interrupts ........................................................................ 250 16.1 Pin Change Interrupt Timing ............................................................................ 250 16.2 Register Description ......................................................................................... 251 17 8-bit Timer/Counter0 with PWM ................................................... 258 17.1 Features ........................................................................................................... 258 17.2 Overview ........................................................................................................... 258 17.3 Timer/Counter Clock Sources .......................................................................... 259 17.4 Counter Unit ..................................................................................................... 259 17.5 Output Compare Uni t ....................................................................................... 260 17.6 Compare Match Output Unit ............................................................................. 262 17.7 Modes of Operation .......................................................................................... 264 17.8 Timer/Counter Timing Diagrams ...................................................................... 268 17.9 Register Description ......................................................................................... 270 18 16-bit Timer/Counter (Timer/Counter 1, 3, 4, and 5) ................... 276 605 8393C-MCU Wireless-09/14

18.1 Features ........................................................................................................... 276 18.2 Overview ........................................................................................................... 276 18.3 Accessing 16-bit Registers ............................................................................... 278 18.4 Timer/Counter Clock Sources .......................................................................... 281 18.5 Counter Unit ..................................................................................................... 281 18.6 Input Capture Unit ............................................................................................ 282 18.7 Output Compare Units ...................................................................................... 284 18.8 Compare Match Output Unit ............................................................................. 286 18.9 Modes of Operation . ......................................................................................... 288 18.10 Timer/Counter Timing Diagrams .................................................................... 296 18.11 Register Description ....................................................................................... 298 19 Timer/Counter 0, 1, 3, 4, and 5 Prescaler .................................... 336 19.1 Internal Clock Source ....................................................................................... 336 19.2 Prescaler Reset ................................................................................................ 336 19.3 External Clock Source ...................................................................................... 336 19.4 Register Description ......................................................................................... 337 20 Output Compare Modulator (OCM1C0A)..................................... 339 20.1 Overview ................. . ......................................................................................... 339 20.2 Description ........................................................................................................ 339 20.3 Timing Example ................................................................................................ 340 21 8-bit Timer/Counter2 with PWM and Asynchronous Operation 341 21.1 Features ........................................................................................................... 341 21.2 Overview ........................................................................................................... 341 21.3 Timer/Counter Clock Sources .......................................................................... 342 21.4 Counter Unit ..................................................................................................... 343 21.5 Modes of Operation .......................................................................................... 343 21.6 Output Compare Unit ....................................................................................... 348 21.7 Compare Match Output Unit ............................................................................. 349 21.8 Timer/Counter Timing Diagrams ...................................................................... 351 21.9 Asynchronous Operation of Timer/Counter2 .................................................... 352 21.10 Timer/Counter Pres caler ................................................................................ 355 21.11 Register Description ....................................................................................... 356 22 SPI- Serial Peripheral Interface .................................................... 363 22.1 Features ........................................................................................................... 363 22.2 Functional Description ...................................................................................... 363 __ 22.3 Pin Functionality Slave Select Pin SS .............................................................. 367 ATmega256/128/64RFR2 606 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 22.4 Register Description ......................................................................................... 369 23 USART............................................................................................ 372 23.1 Features ........................................................................................................... 372 23.2 Overview ........................................................................................................... 372 23.3 Clock Generation .............................................................................................. 373 23.4 Frame Formats ................................................................................................. 376 23.5 USART Initialization ......................................................................................... 377 23.6 Data Transmission – The USART Transmitter ................................................. 378 23.7 Data Reception – Th e USART Receiver .......................................................... 381 23.8 Asynchronous Data Reception ......................................................................... 385 23.9 Multi-processor Communication Mode ............................................................. 388 23.10 Register Description ....................................................................................... 389 23.11 Examples of Baud Rate Setting ..................................................................... 398 24 USART in SPI Mode ...................................................................... 401 24.1 Overview ........................................................................................................... 401 24.2 USART MSPIM vs. SPI .................................................................................... 401 24.3 SPI Data Modes and Timing ............................................................................ 402 24.4 Frame Formats ................................................................................................. 403 24.5 Data Transfer.................................................................................................... 404 24.6 USART MSPIM Register Description ............................................................... 406 25 2-wire Serial Interface ................................................................... 410 25.1 Features .................. ......................................................................................... 410 25.2 2-wire Serial Interface Bus Definition ............................................................... 410 25.2.2 Electrical ........................................................................................................ 411 25.3 Data Transfer and Frame Format..................................................................... 411 25.4 Multi-master Bus Systems, Arbitration and Synchronization ........................... 413 25.5 Overview of the TWI Module ............................................................................ 415 25.6 Using the TWI ................................................................................................... 417 25.7 Transmission Modes ........................................................................................ 420 25.8 Multi-master Systems and Arbitration .............................................................. 433 25.9 Register Description ......................................................................................... 434 26 AC – Analog Comparator ............................................................. 440 26.1 Analog Comparator Multiplexed Input .............................................................. 440 26.2 Register Description ......................................................................................... 441 27 ADC – Analog to Digital Converter .............................................. 444 27.1 Features ........................................................................................................... 444 607 8393C-MCU Wireless-09/14

27.2 Operation .......................................................................................................... 445 27.3 ADC Start-Up.................................................................................................... 446 27.4 Starting a Conversion ....................................................................................... 447 27.5 Pre-scaling and Conversion Timing ................................................................. 448 27.6 Changing Channel or Reference Selection ...................................................... 451 27.7 ADC Noise Canceller ....................................................................................... 454 27.8 ADC Conversion Result ................................................................................... 458 27.9 Internal Temperature Measurement ................................................................. 460 27.10 SRAM DRT Voltag e Measurement ................................................................ 462 27.11 EVDD Voltage Measurement ......................................................................... 463 27.12 Register Description ....................................................................................... 464 28 JTAG Interface and On-chip Debug System ............................... 472 28.1 Features ........................................................................................................... 472 28.2 Overview ........................................................................................................... 472 28.3 TAP - Test Access Port .................................................................................... 473 28.4 TAP Controller .................................................................................................. 474 28.5 Using the Boundary-scan Chain....................................................................... 475 28.6 Using the On-chip D ebug System .................................................................... 475 28.7 On-chip Debug Specific JTAG Instructions ...................................................... 476 28.8 Using the JTAG Programming Capabilities ...................................................... 476 28.9 Bibliography ...................................................................................................... 477 28.10 On-chip Debug Related Register in I/O Memory............................................ 477 29 IEEE 1149.1 (JTAG) Boundary-scan ............................................ 478 29.1 Features ........................................................................................................... 478 29.2 System Overview ............................................................................................. 478 29.3 Data Registers .................................................................................................. 478 29.4 Boundary-scan Specific JTAG Instructions ...................................................... 480 29.5 Boundary-scan Chain ....................................................................................... 481 29.6 Boundary-scan Related Register in I/O Memory .............................................. 484 29.7 Boundary-scan Description Language Files .................................................... 485 29.8 ATmega256/128/64R FR2 Boundary-scan Order ............................................. 485 30 Boot Loader Support – Read-While-Write Self-Programming ... 487 30.1 Features ........................................................................................................... 487 30.2 Application and Boot Loader Flash Sections ................................................... 487 30.3 Read-While-Write and No Read-While-Write Flash Sections .......................... 488 30.4 Boot Loader Lock Bits ...................................................................................... 490 ATmega256/128/64RFR2 608 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 30.5 Addressing the Flash During Self-Programming .............................................. 490 30.6 Self-Programming the Flash ............................................................................. 491 30.7 Register Description ......................................................................................... 501 31 Memory Programming .................................................................. 504 31.1 Program And Data Memory Lock Bits .............................................................. 504 31.2 Fuse Bits ........................................................................................................... 505 31.3 Signature Bytes ................................................................................................ 507 31.4 User Signature Data ......................................................................................... 507 31.5 Calibration Byte ....... ......................................................................................... 507 31.6 Page Size ......................................................................................................... 507 31.7 Parallel Programming Parameters, Pin Mapping, and Commands ................. 508 31.8 Parallel Programming ....................................................................................... 510 31.9 Serial Downloading .......................................................................................... 521 31.10 Programming via the JTAG Interface ............................................................. 525 32 Application Circuits ...................................................................... 540 32.1 Basic Application Schematic ............................................................................ 540 32.2 Extended Feature Set Application Schematic .................................................. 541 33 Register Summary ........................................................................ 543 34 Instruction Set Summary.............................................................. 548 34.1 Arithmetic and Logic Instructions ..................................................................... 548 34.2 Branch Instructions ........................................................................................... 549 34.3 Bit and Bit Test Instru ctions .............................................................................. 550 34.4 Data Transfer Instructions ................................................................................ 551 34.5 MCU Control Instructions ................................................................................. 552 35 Electrical Characteristics ............................................................. 553 35.1 Absolute Maximum Ratings .............................................................................. 553 35.2 Recommended Operating Range..................................................................... 553 35.3 Digital Pin Characteristics ................................................................................ 554 35.4 Transceiver Pin Characteristics ........................................................................ 554 35.5 Power Supply Currents (RF transceiver in SLEEP mode) ............................... 555 35.6 Clock Characteristics ........................................................................................ 555 35.7 System and Reset Characteristics ................................................................... 556 35.8 Power Management Electrical Characteristics ................................................. 557 35.9 2-wire Serial Interface Characteristics ............................................................. 559 35.10 SPI Timing Characteristics ............................................................................. 560 35.11 ADC Characteristics ....................................................................................... 561 609 8393C-MCU Wireless-09/14

35.12 Temperature Sensor Characteristics ............................................................. 563 35.13 Analog Comparator Characteristics ............................................................... 563 35.14 Transceiver Electrical Characteristics ............................................................ 563 36 Typical Characteristics ................................................................. 567 36.1 Supply Current vs. Clock Speed with Transceiver in SLEEP .......................... 567 36.2 Current Consumption of Bandgap Source and Digital Voltage Regulator ....... 571 36.3 Current Consumption in various Transceiver States........................................ 571 36.4 RF Measurements ............................................................................................ 574 36.5 BOD Threshold ....... . ......................................................................................... 576 36.6 Pin Driver Strength ........................................................................................... 577 36.7 Power-Down Current ........................................................................................ 580 36.8 Static ADC Parameter – INL and DNL ............................................................. 581 36.9 Dynamic ADC Parameter – ENOB ................................................................... 585 36.10 ADC Voltage Reference ................................................................................. 588 36.11 Temperature Sensor ...................................................................................... 588 36.12 Internal Oscillator Speed ................................................................................ 590 36.13 Programming Current ..................................................................................... 592 37 Ordering Information .................................................................... 594 38 Packaging Information ................................................................. 597 39 Errata ............................................................................................. 598 39.1 ATmega256RFR2 revision D ........................................................................... 598 39.2 ATmega256RFR2 revision C ........................................................................... 598 39.3 ATmega256RFR2 revision B ............................................................................ 598 39.4 ATmega256RFR2 revision A ............................................................................ 598 39.5 ATmega128RFR2 revision D ........................................................................... 598 39.6 ATmega128RFR2 revision A, B, C................................................................... 598 39.7 ATmega64RFR2 revision D ............................................................................. 598 39.8 ATmega64RFR2 revision A, B, C..................................................................... 598 39.9 Detailed errata description ............................................................................... 598 40 Revision history ............................................................................ 601 Table of Contents ...... ......................................................................... 603 ATmega256/128/64RFR2 610 8393C-MCU Wireless-09/14

ATmega256/128/64RFR2 Atmel Corporation Atmel Asia Limited Atmel Munich GmbH Atmel Japan G.K. 1600 Technology Drive Unit 01-5 & 16, 19F Business Campus 16F Shin-Osaki Kangyo Bldg. San Jose, CA 95110 BEA Tower, Millennium City 5 Parkring 4 1-6-4 Osaki, Shinagawa-ku USA 418 Kwun Tong Road D-85748 Garching b. Munich Tokyo 141-0032 Tel: (+1)(408) 441-0311 Kwun Tong, Kowloon GERMANY JAPAN Fax: (+1)(408) 487-2600 HONG KONG Tel: (+49) 89-31970-0 Tel: (+81)(3) 6417-0300 www.atmel.com Tel: (+852) 2245-6100 Fax: (+49) 89-3194621 Fax: (+81)(3) 6417-0370 Fax: (+852) 2722-1369 © 2014 Atmel Corporation. All rights reserved. / Rev.: 8393C-MCU Wireless-09/14 Atmel®, Atmel logo and combinations thereof, Enabling Unlimited Possibilities®, and others are registered trademarks or trademarks of Atmel Corporation or its subsidiaries. Other terms and product names may be trademarks of others. Disclaimer: The information in this document is provided in connection with Atmel products. No license, express or implied, by estoppel or otherwise, to any intellectual property right is granted by this document or in connection with the sale of Atmel products. EXCEPT AS SET FORTH IN THE ATMEL TERMS AND CONDITIONS OF SALES LOCATED ON THE ATMEL WEBSITE, ATMEL ASSUMES NO LIABILITY WHATSOEVER AND DISCLAIMS ANY EXPRESS, IMPLIED OR STATUTORY WARRANTY RELATING TO ITS PRODUCTS INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, CONSEQUENTIAL, PUNITIVE, SPECIAL OR INCIDENTAL DAMAGES (INCLUDING, WITHOUT LIMITATION, DAMAGES FOR LOSS AND PROFITS, BUSINESS INTERRUPTION, OR LOSS OF INFORMATION) ARISING OUT OF THE USE OR INABILITY TO USE THIS DOCUMENT, EVEN IF ATMEL HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. Atmel makes no representations or warranties with respect to the accuracy or completeness of the contents of this document and reserves the right to make changes to specifications and products descriptions at any time without notice. Atmel does not make any commitment to update the information contained herein. Unless specifically provided otherwise, Atmel products are not suitable for, and shall not be used i n6, 11 automotive applications. Atmel products are not intended, authorized, or warranted for use as components in applications in tended to support or sustain life. 8393C-MCU Wireless-09/14

Mouser Electronics Authorized Distributor Click to View Pricing, Inventory, Delivery & Lifecycle Information: M icrochip: ATMEGA256RFR2-ZU ATMEGA256RFR2-ZF ATMEGA128RFR2-ZFR ATMEGA64RFR2-ZFR ATMEGA64RFR2- ZF ATMEGA128RFR2-ZF ATMEGA64RFR2-ZUR ATMEGA64RFR2-ZU ATMEGA256RFR2-ZUR ATMEGA128RFR2-ZUR ATMEGA256RFR2-ZFR ATMEGA128RFR2-ZU