Attiny 441
Attiny 441
Attiny 441
DATASHEET
Features
8495G–AVR–01/2014
1. Pin Configurations
Figure 1-1. Pinout in 14-pin SOIC.
VCC 1 14 GND
(PCINT8/ADC11/XTAL1/CLKI) PB0 2 13 PA0 (PCINT0/ADC0/AREF/MISO)
(PCINT9/ADC10/XTAL2/INT0) PB1 3 12 PA1 (PCINT1/ADC1/AIN00/TOCC0/TXD0/MOSI)
(PCINT11/ADC9/RESET/dW) PB3 4 11 PA2 (PCINT2/ADC2/AIN01/TOCC1/RXD0/SS)
(PCINT10/ADC8/CLKO/TOCC7/ICP2/RXD0) PB2 5 10 PA3 (PCINT3/ADC3/AIN10/TOCC2/T0/XCK0/SCK)
(PCINT7/ADC7/TOCC6/ICP1/TXD0/SS) PA7 6 9 PA4 (PCINT4/ADC4/AIN11/TOCC3/T1/RXD1/SCL/SCK)
(PCINT6/ADC6/ACO1/TOCC5/XCK1/SDA/MOSI) PA6 7 8 PA5 (PCINT5/ADC5/ACO0/TOCC4/T2/TXD1/MISO)
PA6 (PCINT6/ADC6/ACO1/TOCC5/XCK1/SDA/MOSI)
PA5 (PCINT5/ADC5/ACO0/TOCC4/T2/TXD1/MISO)
DNC
DNC
DNC
20
19
18
17
16
NOTE
Bottom pad should be
soldered to ground.
DNC: Do Not Connect
1.1.1 VCC
Supply voltage.
1.1.2 GND
Ground.
ATtiny441/841 [DATASHEET] 2
8495G–AVR–01/2014
1.1.3 RESET
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 and provided the reset pin has not been disabled. The minimum pulse length is given in Table 25-5 on page 240.
Shorter pulses are not guaranteed to generate a reset.
The reset pin can also be used as a (weak) I/O pin.
ATtiny441/841 [DATASHEET] 3
8495G–AVR–01/2014
2. Overview
ATtiny441/841 is a low-power CMOS 8-bit microcontrollers based on the AVR enhanced RISC architecture. By executing
powerful instructions in a single clock cycle, the ATtiny441/841 achieves throughputs approaching 1 MIPS per MHz
allowing the system designer to optimize power consumption versus processing speed.
DEBUG
INTERFACE
ISP TWO-WIRE
ON-CHIP INTERFACE INTERFACE
POWER DEBUGGER
SUPERVISION:
POR
BOD USART USART
RESET EEPROM
PROGRAM DATA
MEMORY MEMORY
TEMPERATURE VOLTAGE
(FLASH) (SRAM) SENSOR REFERENCE
ANALOG MULTIPLEXER
COMPARATOR
PORT A PORT B
PA[7:0] PB[3:0]
ATtiny441/841 [DATASHEET] 4
8495G–AVR–01/2014
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), allowing two independent registers to be accessed in a single instruction,
executed in one clock cycle. The resulting architecture is compact and code efficient while achieving throughputs up to
ten times faster than conventional CISC microcontrollers.
ATtiny441/841 provides the following features:
4K/8K bytes of in-system programmable Flash
256/512 bytes of SRAM data memory
256/512 bytes of EEPROM data memory
12 general purpose I/O lines
32 general purpose working registers
One 8-bit timer/counter with two PWM channels
Two 16-bit timer/counters with two PWM channels
Internal and external interrupts
One 10-bit ADC with 5 internal and 12 external channels
One ultra-low power, programmable watchdog timer with internal oscillator
Two programmable USARTs with start frame detection
Slave Two-Wire Interface (TWI)
Master/slave Serial Peripheral Interface (SPI)
Calibrated 8MHz oscillator
Calibrated 32kHz, ultra low power oscillator
Four software selectable power saving modes.
The device is manufactured using Atmel’s high density non-volatile memory technology. The Flash program memory can
be re-programmed in-system through a serial interface, by a conventional non-volatile memory programmer or by an on-
chip boot code, running on the AVR core.
The ATtiny441/841 AVR is supported by a full suite of program and system development tools including: C compilers,
macro assemblers, program debugger/simulators and evaluation kits.
ATtiny441/841 [DATASHEET] 5
8495G–AVR–01/2014
3. General Information
3.1 Resources
A comprehensive set of drivers, application notes, data sheets and descriptions on development tools are available for
download at http://www.atmel.com/avr.
3.4 Disclaimer
Typical values contained in this datasheet are based on simulations and characterization of other AVR microcontrollers
manufactured on the same process technology.
ATtiny441/841 [DATASHEET] 6
8495G–AVR–01/2014
4. CPU Core
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 calculations, control peripherals, and
handle interrupts.
DATA INTERRUPT
UNIT
INDIRECT ADDRESSING
MEMORY
(SRAM)
STATUS AND
CONTROL
PROGRAM
COUNTER
GENERAL
PURPOSE
REGISTERS
PROGRAM
MEMORY X
Y
Z
(FLASH)
DIRECT ADDRESSING
INSTRUCTION
REGISTER ALU
INSTRUCTION
DECODER
CONTROL
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.
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 the 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. Single register
operations can also be executed in the ALU. After an arithmetic operation, the Status Register is updated to reflect
information about the result of the operation.
ATtiny441/841 [DATASHEET] 7
8495G–AVR–01/2014
Program flow is provided by conditional and unconditional jump and call instructions, capable of directly addressing the
whole address space. Most AVR instructions have a single 16-bit word format but 32-bit wide instructions also exist. The
actual instruction set varies, as some devices only implement a part of the instruction set.
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 AVR 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 ATtiny441/841 has Extended I/O Space from 0x60 - 0xFF in SRAM where only the
ST/STS/STD and LD/LDS/LDD instructions can be used.
Figure 4-2 below shows the structure of the 32 general purpose working registers in the CPU.
ATtiny441/841 [DATASHEET] 8
8495G–AVR–01/2014
Figure 4-2. 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 4-2, 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.
15 0
X-register 7 XH 0 7 XL 0
R27 R26
15 0
Y-register 7 YH 0 7 YL 0
R29 R28
15 0
Z-register 7 ZH 0 7 ZL 0
R31 R30
ATtiny441/841 [DATASHEET] 9
8495G–AVR–01/2014
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).
clkCPU
1st Instruction Fetch
1st Instruction Execute
2nd Instruction Fetch
2nd Instruction Execute
3rd Instruction Fetch
3rd Instruction Execute
4th Instruction Fetch
Figure 4-5 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.
ATtiny441/841 [DATASHEET] 10
8495G–AVR–01/2014
Figure 4-5. Single Cycle ALU Operation
T1 T2 T3 T4
clkCPU
Total Execution Time
ATtiny441/841 [DATASHEET] 11
8495G–AVR–01/2014
Assembly Code Example
C Code Example
char cSREG;
cSREG = SREG; /* store SREG value */
/* disable interrupts during timed sequence */
_CLI();
EECR |= (1<<EEMPE); /* start EEPROM write */
EECR |= (1<<EEPE);
SREG = cSREG; /* restore SREG value (I-bit) */
When using the SEI instruction to enable interrupts, the instruction following SEI will be executed before any pending
interrupts, as shown in the following example.
Assembly Code Example
C Code Example
ATtiny441/841 [DATASHEET] 12
8495G–AVR–01/2014
4.8 Register Description
Bit 7 6 5 4 3 2 1 0
(0x71) CCP[7:0] CCP
Read/Write W W W W W W W R/W
Initial Value 0 0 0 0 0 0 0 0
ATtiny441/841 [DATASHEET] 13
8495G–AVR–01/2014
4.8.3 SREG – Status Register
Bit 7 6 5 4 3 2 1 0
0x3F (0x5F) I T H S V N Z C SREG
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
ATtiny441/841 [DATASHEET] 14
8495G–AVR–01/2014
5. Memories
The AVR architecture makes a distinction between program memory and data memory, locating each memory type in a
separate address space. Executable code is located in non-volatile program memory (Flash), whereas data can be
placed in either volatile (SRAM) or non-volatile memory (EEPROM). See Figure 5-1, below.
DATA MEMORY
PROGRAM MEMORY
EXTENDED
I/O REGISTER FILE
DATA MEMORY
GENERAL PURPOSE
REGISTER FILE
FLASH SRAM EEPROM
Constant tables can be allocated within the entire address space of program memory. See instructions LPM (Load
Program Memory), and SPM (Store Program Memory) in “Instruction Set Summary” on page 351. Flash program
memory can also be programmed from an external device, as described in “External Programming” on page 225.
Timing diagrams for instruction fetch and execution are presented in “Instruction Execution Timing” on page 10.
The Flash memory has a minimum endurance of 10,000 write/erase cycles.
ATtiny441/841 [DATASHEET] 15
8495G–AVR–01/2014
5.2 Data Memory (SRAM) and Register Files
Table 5-2 shows how the data memory and register files of ATtiny441/841 are organized. These memory areas are
volatile, i.e. they do not retain information when power is removed.
Device Memory Area Size Long Address (1) Short Address (2)
Note: 1. Also known as data address. This mode of addressing covers the entire data memory and register area. The
address is contained in a 16-bit area of two-word instructions.
2. Also known as direct I/O address. This mode of addressing covers part of the register area, only. It is used
by instructions where the address is embedded in the instruction word.
The 512/768 memory locations include the general purpose register file, I/O register file, extended I/O register file, and
the internal data memory.
For compatibility with future devices, reserved bits should be written to zero, if accessed. Reserved I/O memory
addresses should never be written.
ATtiny441/841 [DATASHEET] 16
8495G–AVR–01/2014
particularly useful for storing global variables and status flags, since they are accessible to bit-specific instructions such
as SBI, CBI, SBIC, SBIS, SBRC, and SBRS.
All addressing modes can be used on the entire volatile memory, including the general purpose register file, the I/O
register files and the data memory.
Internal SRAM is accessed in two clkCPU cycles, as illustrated in Figure 5-2, below.
clkCPU
Address Compute Address Address valid
Data
Write
WR
Data
Read
RD
ATtiny441/841 [DATASHEET] 17
8495G–AVR–01/2014
5.3 Data Memory (EEPROM)
ATtiny441/841 contains 256/512 bytes of non-volatile data memory. This EEPROM is organized as a separate data
space, in which single bytes can be read and written. All access registers are located in the I/O space.
The EEPROM memory layout is summarized in Table 5-3, below.
The internal 8MHz oscillator is used to time EEPROM operations. The frequency of the oscillator must be within the
requirements described in “OSCCAL0 – Oscillator Calibration Register” on page 33.
When powered by heavily filtered supplies, the supply voltage, VCC, is likely to rise or fall slowly on power-up and power-
down. Slow rise and fall times may put the device in a state where it is running at supply voltages lower than specified. To
avoid problems in situations like this, see “Preventing EEPROM Corruption” on page 19.
The EEPROM has a minimum endurance of 100,000 write/erase cycles.
The programming method is selected using the EEPROM Programming Mode bits (EEPM1 and EEPM0) in EEPROM
Control Register (EECR). See Table 5-4 on page 23. Write and erase times are given in the same table.
Since EEPROM programming takes some time the application must wait for one operation to complete before starting
the next. This can be done by either polling the EEPROM Program Enable bit (EEPE) in EEPROM Control Register
(EECR), or via the EEPROM Ready Interrupt. The EEPROM interrupt is controlled by the EEPROM Ready Interrupt
Enable (EERIE) bit in EECR.
5.3.2 Read
To read an EEPROM memory location follow the procedure below:
Poll the EEPROM Program Enable bit (EEPE) in EEPROM Control Register (EECR) to make sure no other
EEPROM operations are in process. If set, wait to clear.
Write target address to EEPROM Address Registers (EEARH/EEARL).
Start the read operation by setting the EEPROM Read Enable bit (EERE) in the EEPROM Control Register
(EECR). During the read operation, the CPU is halted for four clock cycles before executing the next instruction.
Read data from the EEPROM Data Register (EEDR).
ATtiny441/841 [DATASHEET] 18
8495G–AVR–01/2014
5.3.3 Erase
In order to prevent unintentional EEPROM writes, a specific procedure must be followed to erase memory locations. To
erase an EEPROM memory location follow the procedure below:
1. Poll the EEPROM Program Enable bit (EEPE) in EEPROM Control Register (EECR) to make sure no other
EEPROM operations are in process. If set, wait to clear.
2. Set mode of programming to erase by writing EEPROM Programming Mode bits (EEPM0 and EEPM1) in
EEPROM Control Register (EECR).
3. Write target address to EEPROM Address Registers (EEARH/EEARL).
4. Enable erase by setting EEPROM Master Program Enable (EEMPE) in EEPROM Control Register (EECR). Within
four clock cycles, start the erase operation by setting the EEPROM Program Enable bit (EEPE) in the EEPROM
Control Register (EECR). During the erase operation, the CPU is halted for two clock cycles before executing the
next instruction.
The EEPE bit remains set until the erase operation has completed. While the device is busy programming, it is not
possible to perform any other EEPROM operations.
5.3.4 Write
In order to prevent unintentional EEPROM writes, a specific procedure must be followed to write to memory locations.
Before writing data to EEPROM the target location must be erased. This can be done either in the same operation or as
part of a split operation. Writing to an un-erased EEPROM location will result in corrupted data.
To write an EEPROM memory location follow the procedure below:
1. Poll the EEPROM Program Enable bit (EEPE) in EEPROM Control Register (EECR) to make sure no other
EEPROM operations are in process. If set, wait to clear.
2. Set mode of programming by writing EEPROM Programming Mode bits (EEPM0 and EEPM1) in EEPROM Control
Register (EECR). Alternatively, data can be written in one operation or the write procedure can be split up in erase,
only, and write, only.
3. Write target address to EEPROM Address Registers (EEARH/EEARL).
4. Write target data to EEPROM Data Register (EEDR).
5. Enable write by setting EEPROM Master Program Enable (EEMPE) in EEPROM Control Register (EECR). Within
four clock cycles, start the write operation by setting the EEPROM Program Enable bit (EEPE) in the EEPROM
Control Register (EECR). During the write operation, the CPU is halted for two clock cycles before executing the
next instruction.
The EEPE bit remains set until the write operation has completed. While the device is busy with programming, it is not
possible to do any other EEPROM operations.
ATtiny441/841 [DATASHEET] 19
8495G–AVR–01/2014
EEPROM data corruption is avoided by keeping the device in reset during periods of insufficient power supply voltage.
This is easily done by enabling the internal Brown-Out Detector (BOD). If BOD detection levels are not sufficient for the
design, an external reset circuit for low VCC can be used.
Provided that supply voltage is sufficient, an EEPROM write operation will be completed even when a reset occurs.
EEPROM_write:
; Wait for completion of previous write
sbic EECR, EEPE
rjmp EEPROM_write
; Set Programming mode
ldi r16, (0<<EEPM1)|(0<<EEPM0)
out EECR, r16
; Set up address (r18:r17) in address registers
out EEARH, r18
out EEARL, r17
; Write data (r19) to data register
out EEDR, r19
; Write logical one to EEMPE
sbi EECR, EEMPE
; Start eeprom write by setting EEPE
sbi EECR, EEPE
ret
C Code Example
ATtiny441/841 [DATASHEET] 20
8495G–AVR–01/2014
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.
EEPROM_read:
; Wait for completion of previous write
sbic EECR, EEPE
rjmp EEPROM_read
; Set up address (r18:r17) in address registers
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
Bit 7 6 5 4 3 2 1 0
0x1F (0x3F) – – – – – – – EEAR8 EEARH
Read/Write R R R R R R R R/W
Initial Value 0 0 0 0 0 0 0 X/0
ATtiny441/841 [DATASHEET] 21
8495G–AVR–01/2014
5.4.2 EEARL – EEPROM Address Register Low
Bit 7 6 5 4 3 2 1 0
0x1E (0x3E) EEAR7 EEAR6 EEAR5 EEAR4 EEAR3 EEAR2 EEAR1 EEAR0 EEARL
Read/Write R/W R/W R/W R/W R/W R/W R/W R/W
Initial Value X/0 X X X X X X X
Bit 7 6 5 4 3 2 1 0
0x1D (0x3D) EEDR7 EEDR6 EEDR5 EEDR4 EEDR3 EEDR2 EEDR1 EEDR0 EEDR
Read/Write R/W R/W R/W R/W R/W R/W R/W R/W
Initial Value 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
0x1C (0x3C) – – EEPM1 EEPM0 EERIE EEMPE EEPE EERE EECR
Read/Write R R R/W R/W R/W R/W R/W R/W
Initial Value 0 0 X X 0 0 X 0
ATtiny441/841 [DATASHEET] 22
8495G–AVR–01/2014
Table 5-4. EEPROM Programming Mode Bits and Programming Times
1 1 – Reserved
ATtiny441/841 [DATASHEET] 23
8495G–AVR–01/2014
5.4.5 GPIOR2 – General Purpose I/O Register 2
Bit 7 6 5 4 3 2 1 0
0x15 (0x35) MSB LSB GPIOR2
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
This register may be used freely for storing any kind of data.
Bit 7 6 5 4 3 2 1 0
0x14 (0x34) MSB LSB GPIOR1
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
This register may be used freely for storing any kind of data.
Bit 7 6 5 4 3 2 1 0
0x13 (0x33) MSB LSB GPIOR0
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
This register may be used freely for storing any kind of data.
ATtiny441/841 [DATASHEET] 24
8495G–AVR–01/2014
6. Clock System
Figure 6-1 presents the principal clock systems and their distribution in ATtiny441/841. 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 and power reduction register bits, as described in “Power Management and Sleep Modes”
on page 35. The clock systems is detailed below.
CLOCK
PRESCALER
WATCHDOG
CLOCK
CLOCK
SWITCH
ATtiny441/841 [DATASHEET] 25
8495G–AVR–01/2014
6.1.4 ADC Clock – clkADC
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.
The clock source is selected using CKSEL fuses, as shown in Table 6-1 below.
(1)
CKSEL[3:0] Frequency Device Clocking Option
0010 8MHz Calibrated Internal 8MHz Oscillator (see page 27) (2)
0100 32 – 512kHz Internal Ultra Low Power (ULP) Oscillator (see page 27)
Note: 1. For all fuses “1” means unprogrammed and “0” means programmed.
2. This is the default setting. The device is shipped with this fuse combination.
.
CKSEL fuse bits can be read by firmware (see “Reading Lock, Fuse and Signature Data from Software” on page 222),
but firmware can not write to fuse bits.
When the device wakes up from power-down the selected clock source is used to time the start-up, ensuring stable
oscillator operation before instruction execution starts. When the CPU starts from reset, the internal 32kHz oscillator is
used for generating an additional delay, allowing supply voltage to reach a stable level before normal device operation is
started.
System clock alternatives are discussed in the following sections.
ATtiny441/841 [DATASHEET] 26
8495G–AVR–01/2014
Figure 6-2. External Clock Drive Configuration
EXTERNAL
CLOCK CLKI
SIGNAL
GND
Start-up time for this clock source is determined by the SUT fuse bit, as shown in Table 6-5 on page 30.
To ensure stable operation of the MCU it is required to avoid sudden changes in the external clock frequency . A
variation in frequency of more than 2% from one clock cycle to the next can lead to unpredictable behavior. It is required
to ensure that the MCU is kept in Reset during such changes in the clock frequency.
Stable operation for large step changes in system clock frequency is guaranteed when using the system clock prescaler.
See “System Clock Prescaler” on page 29.
ATtiny441/841 [DATASHEET] 27
8495G–AVR–01/2014
When the ULP oscillator is used as a system clock, the operating frequency can be programmed using ULPOSC2..0
fuses. The available frequencies are shown in Table 6-2. Note that higher frequencies are available for system clock,
only. Even when a higher frequency is selected the watchdog and the reset time-out counter still use 32 kHz.
111 32 kHz
110 64 kHz
Start-up time for this clock source is determined by the SUT fuse bit, as shown in Table 6-5 on page 30.
Pin Capacitance
XTAL1 16 pF
XTAL2 6 pF
Start-up time for this clock source is determined by the SUT fuse bit, as shown in Table 6-5 on page 30.
C2
XTAL2
C1
XTAL1
GND
ATtiny441/841 [DATASHEET] 28
8495G–AVR–01/2014
Capacitors C1 and C2 should always be equal, both for crystals and resonators. The optimal value of the capacitors
depends on the crystal or resonator in use, the amount of stray capacitance, and the electromagnetic noise of the
environment. Some initial guidelines for choosing capacitors for use with crystals are given in Table 6-4, below. For
ceramic resonators, the capacitor values given by the manufacturer should be used.
> 1MHz 12 – 22 pF
The oscillator can operate in different modes, each optimized for a specific frequency range. See Table 6-1 on page 26.
Start-up time for this clock source is determined by the SUT bit, as explained in “Start-Up Time” on page 30.
The default setting gives a 1MHz system clock and ensures all users can make their desired clock source setting using
an in-system or high-voltage programmer.
ATtiny441/841 [DATASHEET] 29
8495G–AVR–01/2014
6.5 Start-Up Time
The CKSEL and SUT bits define the start-up time of the device, as shown in Table 6-5, below.
Table 6-5. CKSEL and SUT Fuse Bits vs. Device Start-up Time
0 External 6 CK 14 CK + 16ms
0000
1 Reserved — —
0001 X Reserved — —
1 Reserved — —
0010 (4)
0 (4) Internal (8 MHz) 6 CK 14 CK + 16ms
0011 X Reserved — —
0101 X Reserved — —
0111 X Reserved — —
ATtiny441/841 [DATASHEET] 30
8495G–AVR–01/2014
3. Device start-up time after reset.
4. The device is shipped with this option selected.
5. These options should be used only if frequency stability at start-up is not important.
6. Recommended use: fast rising power or BOD enabled.
Bit 7 6 5 4 3 2 1 0
(0x72) OSCRDY CSTR CKOUTC SUT CKSEL3 CKSEL2 CKSEL1 CKSEL0 CLKCR
Read/Write R W R/W R/W R/W R/W R/W R/W
Initial Value 0 0 0 See Bit Description
ATtiny441/841 [DATASHEET] 31
8495G–AVR–01/2014
6.6.2 CLKPR – Clock Prescale Register
Bit 7 6 5 4 3 2 1 0
(0x73) – – – – CLKPS3 CLKPS2 CLKPS1 CLKPS0 CLKPR
Read/Write R R R R R/W R/W R/W R/W
Initial Value 0 0 0 0 See Bit Description
0 0 0 0 1 (1)
0 0 0 1 2
0 0 1 0 4
0 0 1 1 8 (2)
0 1 0 0 16
0 1 0 1 32
0 1 1 0 64
0 1 1 1 128
1 0 0 0 256
1 0 0 1
1 0 1 0
1 0 1 1
1 1 0 0 Reserved
1 1 0 1
1 1 1 0
1 1 1 1
Note: 1. This is the initial value when CKDIV8 fuse has been unprogrammed.
2. This is the initial value when CKDIV8 fuse has been programmed. The device is shipped with the CKDIV8
Fuse programmed.
ATtiny441/841 [DATASHEET] 32
8495G–AVR–01/2014
The initial value of clock prescaler bits is determined by the CKDIV8 fuse (see Table 23-5 on page 220). When CKDIV8
is unprogrammed, the system clock prescaler is set to one and, when programmed, to eight. Any value can be written to
the CLKPS bits regardless of the CKDIV8 fuse bit setting.
When CKDIV8 is programmed the initial value of CLKPS bits give a clock division factor of eight at start up. This is useful
when the selected clock source has a higher frequency than allowed under present operating conditions. See “Speed” on
page 238.
To avoid unintentional changes to clock frequency, the following sequence must be followed:
1. Write the required signature to the CCP register. See page 13.
2. Within four instruction cycles, write the desired value to CLKPS bits.
Bit 7 6 5 4 3 2 1 0
(0x74) CAL07 CAL06 CAL05 CAL04 CAL03 CAL02 CAL01 CAL00 OSCCAL0
Read/Write R/W R/W R/W R/W R/W R/W R/W R/W
Initial Value Device Specific Calibration Value
Bit 7 6 5 4 3 2 1 0
(0x75) Oscillator Temperature Calibration Data OSCTCAL0A
Read/Write R/W R/W R/W R/W R/W R/W R/W R/W
Initial Value Device Specific Calibration Value
ATtiny441/841 [DATASHEET] 33
8495G–AVR–01/2014
6.6.5 OSCTCAL0B – Oscillator Temperature Calibration Register B
Bit 7 6 5 4 3 2 1 0
(0x76) Oscillator Temperature Calibration Data OSCTCAL0B
Read/Write R/W R/W R/W R/W R/W R/W R/W R/W
Initial Value Device Specific Calibration Value
Bit 7 6 5 4 3 2 1 0
(0x77) – – – – – – CAL11 CAL10 OSCCAL1
Read/Write R R R R R R R/W R/W
Initial Value 0 0 0 0 0 0 Calibration Value
ATtiny441/841 [DATASHEET] 34
8495G–AVR–01/2014
7. Power Management and Sleep Modes
The high performance and industry leading code efficiency makes the AVR microcontrollers an ideal choice for low
power applications. In addition, sleep modes enable the application to shut down unused modules in the MCU, thereby
saving power. The AVR provides various sleep modes allowing the user to tailor the power consumption to the
application’s requirements.
Table 7-1. Active Clock Domains and Wake-up Sources in Different Sleep Modes
Ready Interrupt
SPM/EEPROM
ADC Interrupt
Watchdog
USART (1)
Other I/O
INT0 and
Interrupt
clkFLASH
clkADC
clkCPU
clkIO
Sleep Mode
Idle X X X X X X X X X X
Standby X X X(3) X X
Power-down X X(3) X X
To enter a sleep mode, the SE bit in MCUCR must be set and a SLEEP instruction must be executed. The SMn bits in
MCUCR select which sleep mode will be activated by the SLEEP instruction. See Table 7-2 on page 38 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. If a
reset occurs during sleep mode, the MCU wakes up and executes from the Reset Vector.
Note that if a level triggered interrupt is used for wake-up the changed level must be held for some time to wake up the
MCU (and for the MCU to enter the interrupt service routine). See “External Interrupts” on page 51 for details.
ATtiny441/841 [DATASHEET] 35
8495G–AVR–01/2014
Idle mode allows the MCU to wake up from external triggered interrupts as well as internal ones, such as Timer Overflow.
If wake-up from the analog comparator interrupt is not required, the analog comparator can be powered down by setting
the ACD bit in ACSRA. See “ACSR1A – Analog Comparator 1 Control and Status Register” on page 129. This will reduce
power consumption in Idle mode.
If the ADC is enabled, a conversion starts automatically when this mode is entered.
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.
The following events can wake up the MCU:
Watchdog reset, external reset, and brown-out reset
External level interrupt on INT0, and pin change interrupt
ADC conversion complete interrupt, and SPM/EEPROM ready interrupt
USART start frame detection, and TWI slave address match
The peripheral should in most cases be disabled before stopping the clock. Clearing the PRR bit wakes up the peripheral
and puts it in the same state as before shutdown.
Peripheral shutdown can be used in Idle mode and Active mode to significantly reduce the overall power consumption. In
all other sleep modes, the clock is already stopped.
ATtiny441/841 [DATASHEET] 36
8495G–AVR–01/2014
7.3 Minimizing Power Consumption
There are several issues to consider when trying to minimize 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
modules may need special consideration when trying to achieve the lowest possible power consumption.
ATtiny441/841 [DATASHEET] 37
8495G–AVR–01/2014
Input Disable Registers. See “DIDR0 – Digital Input Disable Register 0” on page 149 and “DIDR1 – Digital Input Disable
Register 1” on page 150 for details.
Bit 7 6 5 4 3 2 1 0
0x35 (0x55) – – SE SM1 SM0 – ISC01 ISC00 MCUCR
Read/Write R R R/W R/W R/W R R/W R/W
Initial Value 0 0 0 0 0 0 0 0
0 0 Idle
1 0 Power-down
1 1 Standby (1)
Bit 7 6 5 4 3 2 1 0
(0x70) PRTWI PRUSART1 PRUSART0 PRSPI PRTIM2 PRTIM1 PRTIM0 PRADC PRR
Read/Write R/w R R/W R/W R/W R/W R/W R/W
Initial Value 0 0 0 0 0 0 0 0
ATtiny441/841 [DATASHEET] 38
8495G–AVR–01/2014
Bit 6 – PRUSART1: Power Reduction USART1
Writing a logic one to this bit shuts down the USART1 module. When the USART is re-enabled, operation will continue
like before the shutdown.
ATtiny441/841 [DATASHEET] 39
8495G–AVR–01/2014
8. System Control and Reset
BORF
PORF
EXTRF
WDRF
VCC BROWN OUT
RESET CIRCUIT
PULL-UP INTERNAL
RESISTOR POWER-ON S Q
COUNTER RESET RESET
RESET CIRCUIT
SPIKE TIMEOUT
RESET R
FILTER
EXTERNAL
RESET CIRCUIT DELAY
COUNTERS
CK
WATCHDOG
TIMER
RSTDISBL
WATCHDOG CLOCK
OSCILLATOR GENERATOR
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.
ATtiny441/841 [DATASHEET] 40
8495G–AVR–01/2014
Figure 8-2. MCU Start-up, RESET Tied to VCC
V POT
V CC
V RST
RESET
t TOUT
TIME-OUT
INTERNAL
RESET
V POT
V CC
> t TOUT
V RST
RESET
t TOUT
TIME-OUT
INTERNAL
RESET
ATtiny441/841 [DATASHEET] 41
8495G–AVR–01/2014
Figure 8-4. External Reset During Operation
CC
CK
ATtiny441/841 [DATASHEET] 42
8495G–AVR–01/2014
Figure 8-6. Brown-out Reset During Operation
VCC VBOT+
VBOT-
RESET
TIME-OUT tTOUT
INTERNAL
RESET
The BOD circuit will not detect a drop in VCC unless the voltage stays below the trigger level for the detection time, tBOD
(see “System and Reset Characteristics” on page 240).
The BOD circuit has three modes of operation:
Disabled: In this mode of operation VCC is not monitored and, hence, it is recommended only for applications
where the power supply remains stable.
Enabled: In this mode the VCC level is continuously monitored. If VCC drops below VBOT for at least tBOD a brown-
out reset will be generated.
Sampled: In this mode the VCC level is sampled on each negative edge of a 1kHz clock that has been derived
from the 32kHz ULP oscillator. Between each sample the BOD is turned off. Compared to the mode where BOD is
constantly enabled this mode of operation reduces power consumption but fails to detect drops in VCC between
two positive edges of the 1kHz clock. When a brown-out is detected in this mode, the BOD circuit is set to enabled
mode to ensure that the device is kept in reset until VCC has risen above VBOT . The BOD will return to sampled
mode after reset has been released and the fuses have been read in.
The BOD mode of operation is selected using BODACT and BODPD fuse bits. The BODACT fuse bits determine how
the BOD operates in active and idle mode, as shown in Table 8-1.
Table 8-1. Setting BOD Mode of Operation in Active and Idle Modes
0 0 Reserved
0 1 Sampled
1 0 Enabled
1 1 Disabled
The BODPD fuse bits determine the mode of operation in all sleep modes except idle mode, as shown in Table 8-2.
ATtiny441/841 [DATASHEET] 43
8495G–AVR–01/2014
Table 8-2. Setting BOD Mode of Operation in Sleep Modes Other Than Idle
0 0 Reserved
0 1 Sampled
1 0 Enabled
1 1 Disabled
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.
ATtiny441/841 [DATASHEET] 44
8495G–AVR–01/2014
Table 8-3. WDT Configuration as a Function of the Fuse Settings of WDTON
WDTON Safety Level WDT Initial State How to Disable the WDT How to Change Time-out
32 kHz WATCHDOG
ULP OSCILLATOR PRESCALER
OSC/128K
OSC/256K
OSC/32K
OSC/64K
OSC/4K
OSC/8K
OSC/512
OSC/16K
OSC/1K
OSC/2K
WATCHDOG
RESET
WDP0
WDP1
MUX
WDP2
WDP3
WDE
MCU RESET
8.4.1 Timed Sequences for Changing the Configuration of the Watchdog Timer
The sequence for changing configuration differs slightly between the two safety levels. Separate procedures are
described for each level.
Safety Level 1
In this mode, the Watchdog Timer is initially disabled, but can be enabled by writing the WDE bit to one without
any restriction. A timed sequence is needed when disabling an enabled Watchdog Timer. To disable an enabled
Watchdog Timer, the following procedure must be followed:
1. Write the signature for change enable of protected I/O registers to register CCP
2. Within four instruction cycles, in the same operation, write WDE and WDP bits
Safety Level 2
In this mode, the Watchdog Timer is always enabled, and the WDE bit will always read as one. A timed sequence
is needed when changing the Watchdog Time-out period. To change the Watchdog Time-out, the following proce-
dure must be followed:
1. Write the signature for change enable of protected I/O registers to register CCP
2. Within four instruction cycles, write the WDP bit. The value written to WDE is irrelevant
ATtiny441/841 [DATASHEET] 45
8495G–AVR–01/2014
Assembly Code Example
WDT_off:
wdr
; Clear WDRF in RSTFLR
in r16, RSTFLR
andi r16, ~(1<<WDRF)
out RSTFLR, r16
; Write signature for change enable of protected I/O register
ldi r16, 0xD8
out CCP, r16
; Within four instruction cycles, turn off WDT
ldi r16, (0<<WDE)
out WDTCSR, r16
ret
Bit 7 6 5 4 3 2 1 0
0x34 (0x54) – – – – WDRF BORF EXTRF PORF MCUSR
Read/Write R R R R R/W R/W R/W R/W
Initial Value 0 0 0 0 See Bit Description
ATtiny441/841 [DATASHEET] 46
8495G–AVR–01/2014
8.5.2 WDTCSR – Watchdog Timer Control and Status Register
Bit 7 6 5 4 3 2 1 0
0x21 (0x41) WDIF WDIE WDP3 – WDE WDP2 WDP1 WDP0 WDTCSR
Read/Write R/W R/W R/W R/W R/W R/W R/W R/W
Initial Value 0 0 0 0 X 0 0 0
0 0 Stopped None
1 0 Running Reset
ATtiny441/841 [DATASHEET] 47
8495G–AVR–01/2014
Bits 5, 2:0 – WDP[3:0]: Watchdog Timer Prescaler 3 - 0
The WDP[3:0] bits determine the Watchdog Timer prescaling when the Watchdog Timer is enabled. The different
prescaling values and their corresponding Timeout Periods are shown in Table 8-5.
WDP3 WDP2 WDP1 WDP0 Number of WDT Oscillator Cycles Typical Time-out at VCC = 5.0V
0 0 0 0 512 cycles 16 ms
0 0 0 1 1K cycles 32 ms
0 0 1 0 2K cycles 64 ms
0 0 1 1 4K cycles 0.125 s
0 1 0 0 8K cycles 0.25 s
1 0 1 0
1 0 1 1
1 1 0 0
Reserved(1)
1 1 0 1
1 1 1 0
1 1 1 1
Note: 1. If selected, one of the valid settings below 0b1010 will be used.
To avoid unintentional changes of these bits, the following sequence must be followed:
1. Write the required signature to the CCP register. See page 13.
2. Within four instruction cycles, write the desired bit value.
ATtiny441/841 [DATASHEET] 48
8495G–AVR–01/2014
9. Interrupts
For a general explanation of interrupt handling, see “Reset and Interrupt Handling” on page 11.
ATtiny441/841 [DATASHEET] 49
8495G–AVR–01/2014
Vector No. Address Label Interrupt Source
A typical setup for interrupt vector addresses in is shown in the program example below.
ATtiny441/841 [DATASHEET] 50
8495G–AVR–01/2014
In case the program never enables an interrupt source, the Interrupt Vectors will not be used and, consequently, regular
program code can be placed at these locations.
Registers PCMSK0 and PCMSK1 control which pins contribute to the pin change interrupts.
Pin change interrupts on PCINT[11:0] are detected asynchronously, which means that these interrupts can be used for
waking the part also from sleep modes other than Idle mode.
External interrupt INT0 can be triggered by a falling or rising edge, or a low level. When INT0 is enabled and 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 INT0 requires the presence of an I/O clock, as described in
“Clock System” on page 25.
clk
PCINT(0)
pin_lat
pin_sync
pcint_in_(0)
pcint_syn
pcint_setflag
PCIF
ATtiny441/841 [DATASHEET] 51
8495G–AVR–01/2014
9.2.2 Low Level Interrupt
A low level interrupt on INT0 is detected asynchronously. This means that the interrupt source can be used for waking
the part also from sleep modes other than Idle (the I/O clock is halted in all sleep modes except Idle).
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 as described in “Clock
System” on page 25.
If the low level on the interrupt pin is removed before the device has woken up then program execution will not be
diverted to the interrupt service routine but continue from the instruction following the SLEEP command.
Bit 7 6 5 4 3 2 1 0
0x35 (0x55) – – SE SM1 SM0 – ISC01 ISC00 MCUCR
Read/Write R R R/W R/W R/W R R/W R/W
Initial Value 0 0 0 0 0 0 0 0
Note: 1. If low level interrupt is selected, the low level must be held until the completion of the currently executing
instruction to generate an interrupt.
2. The value on the INT0 pin is sampled before detecting edges. If edge or toggle interrupt is selected, pulses
that last longer than one clock period will generate an interrupt. Shorter pulses are not guaranteed to gener-
ate an interrupt.
Bit 7 6 5 4 3 2 1 0
0x3B (0x5B) – INT0 PCIE1 PCIE0 – – – – GIMSK
Read/Write R R/W R/W R/W R R R R
Initial Value 0 0 0 0 0 0 0 0
ATtiny441/841 [DATASHEET] 52
8495G–AVR–01/2014
Bit 6 – INT0: External Interrupt Request 0 Enable
The external interrupt for pin INT0 is enabled when this bit and the I-bit in the Status Register (SREG) are set. The trigger
conditions are set with the ISC0n bits.
Activity on the pin will cause an interrupt request even if INT0 has been configured as an output.
Bit 7 6 5 4 3 2 1 0
0x3A (0x5A) – INTF0 PCIF1 PCIF0 – – – – GIFR
Read/Write R R/W R/W R/W R R R R
Initial Value 0 0 0 0 0 0 0 0
ATtiny441/841 [DATASHEET] 53
8495G–AVR–01/2014
Bits 3:0 – Res: Reserved Bits
These bits are reserved and will always read zero.
Bit 7 6 5 4 3 2 1 0
0x20 (0x40) – – – – PCINT11 PCINT10 PCINT9 PCINT8 PCMSK1
Read/Write R R R R R/W R/W R/W R/W
Initial Value 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
0x12 (0x32) PCINT7 PCINT6 PCINT5 PCINT4 PCINT3 PCINT2 PCINT1 PCINT0 PCMSK0
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
ATtiny441/841 [DATASHEET] 54
8495G–AVR–01/2014
10. I/O Ports
10.1 Overview
All AVR 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. Each output buffer has sink and source capability. The pin driver is strong enough to drive LED displays
directly. All port pins have individually selectable pull-up resistors with a supply-voltage invariant resistance. All I/O pins
have protection diodes to both VCC and Ground as indicated in Figure 10-1 on page 55. See “Electrical Characteristics”
on page 236 for a complete list of parameters.
Rpu
Pxn Logic
Cpin
See Figure
"General Digital I/O" for
Details
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.
The physical I/O Registers and bit locations are listed in “Register Description” on page 71.
Four I/O memory address locations are allocated for each port, one each for the Data Register – PORTx, Data Direction
Register – DDRx, Pull-up Enable Register – PUEx, and the Port Input Pins – PINx. The Port Input Pins I/O location is
read only, while the Data Register, the Data Direction Register, and the Pull-up Enable 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.
Using the I/O port as General Digital I/O is described in “Ports as General Digital I/O” on page 55. Most port pins are
multiplexed with alternative functions for the peripheral features on the device. How each alternative function interferes
with the port pin is described in “Alternative Port Functions” on page 60. Refer to the individual module sections for a full
description of the alternative functions.
Note that enabling the alternative function of some of the port pins does not affect the use of the other pins in the port as
general digital I/O.
ATtiny441/841 [DATASHEET] 55
8495G–AVR–01/2014
Figure 10-2. General Digital I/O(1)
REx
Q D
PUExn
Q CLR
RESET WEx
Q D
DDxn
Q CLR
WDx
RESET
RDx
DATA BUS
1
Pxn Q D
PORTxn 0
Q CLR
RESET
WRx WPx
SLEEP RRx
SYNCHRONIZER
RPx
D Q D Q
PINxn
L Q Q
clk I/O
Note: 1. WEx, WRx, WPx, WDx, REx, RRx, RPx, and RDx are common to all pins within the same port. clkI/O, and SLEEP
are common to all ports.
ATtiny441/841 [DATASHEET] 56
8495G–AVR–01/2014
The pull-up resistor is activated, if the PUExn is written logic one. To switch the pull-up resistor off, PUExn has to be
written logic zero.
Table 10-1 summarizes the control signals for the pin value.
NOT RECOMMENDED.
Output low (sink) and internal pull-up active. Sources
1 0 1 Output Yes
current through internal pull-up resistor and consumes
power constantly
Port pins are tri-stated when a reset condition becomes active, even when no clocks are running.
ATtiny441/841 [DATASHEET] 57
8495G–AVR–01/2014
Figure 10-3. Switching Between Input and Output in Break-Before-Make-Mode
SYSTEM CLK
r16 0x02
r17 0x01
PORTx 0x55
Px0 tri-state
SYSTEM CLK
SYNC LATCH
PINxn
t pd, max
t pd, min
Consider the clock period starting shortly after the first falling edge of the system clock. The latch is closed when the
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 tpd,max and tpd,min, a single signal transition on the pin
will be delayed between ½ and 1½ system clock period depending upon the time of assertion.
ATtiny441/841 [DATASHEET] 58
8495G–AVR–01/2014
When reading back a software assigned pin value, a nop instruction must be inserted as indicated in Figure 10-5. The out
instruction sets the “SYNC LATCH” signal at the positive edge of the clock. In this case, the delay tpd through the
synchronizer is one system clock period.
SYSTEM CLK
r16 0xFF
SYNC LATCH
PINxn
t pd
ATtiny441/841 [DATASHEET] 59
8495G–AVR–01/2014
Assembly Code Example
...
; Define pull-ups and set outputs high
; Define directions for port pins
ldi r16,(1<<PUEB2)
ldi r17,(1<<PB0)
ldi r18,(1<<DDB1)|(1<<DDB0)
out PUEB,r16
out PORTB,r17
out DDRB,r18
; Insert nop for synchronization
nop
; Read port pins
in r16,PINB
...
ATtiny441/841 [DATASHEET] 60
8495G–AVR–01/2014
Figure 10-6. Alternative Port Functions
PUOExn REx
PUOVxn
1
0 Q D
PUExn
Q CLR
DDOExn
RESET WEx
DDOVxn
1
0 Q D
DDxn
Q CLR
WDx
PVOExn RESET
RDx
PVOVxn
DATA BUS
1 1
Pxn
0 Q D 0
PORTxn
PTOExn
Q CLR
DIEOExn
WPx
DIEOVxn RESET
1 WRx
RRx
0 SLEEP
SYNCHRONIZER
RPx
SET
D Q D Q
PINxn
L CLR Q CLR Q
clk I/O
DIxn
AIOxn
Note: WEx, WRx, WPx, WDx, REx, RRx, RPx, and RDx are common to all pins within the same port. clkI/O, and SLEEP are
common to all ports. All other signals are unique for each pin.
ATtiny441/841 [DATASHEET] 61
8495G–AVR–01/2014
The illustration in the figure above serves as a generic description applicable to all port pins in the AVR microcontroller
family. Some overriding signals may not be present in all port pins.
Table 10-2 summarizes the function of the overriding signals. The pin and port indexes from Figure 10-6 on page 61 are
not shown in the succeeding tables. The overriding signals are generated internally in the modules having the alternative
function.
If this signal is set, the pull-up enable is controlled by the PUOV signal. If
PUOE Pull-Up Override Enable
this signal is cleared, the pull-up is enabled when PUExn = 0b1.
If this signal is set, the Output Driver Enable is controlled by the DDOV
DDOE Data Direction Override Enable signal. If this signal is cleared, the Output driver is enabled by the DDxn
Register bit.
If this signal is set and the Output Driver is enabled, the port value is
PVOE Port Value Override Enable 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.
If PVOE is set, the port value is set to PVOV, regardless of the setting of the
PVOV Port Value Override Value
PORTxn Register bit.
PTOE Port Toggle Override Enable If PTOE is set, the PORTxn Register bit is inverted.
If this bit is set, the Digital Input Enable is controlled by the DIEOV signal. If
Digital Input Enable Override
DIEOE this signal is cleared, the Digital Input Enable is determined by MCU state
Enable
(Normal mode, sleep mode).
Digital Input Enable Override If DIEOE is set, the Digital Input is enabled/disabled when DIEOV is
DIEOV
Value set/cleared, regardless of the MCU state (Normal mode, sleep mode).
This is the Digital Input to alternative functions. In the figure, the signal is
connected to the output of the schmitt-trigger but before the synchronizer.
DI Digital Input
Unless the Digital Input is used as a clock source, the module with the
alternative function will use its own synchronizer.
The following subsections shortly describe the alternative functions for each port, and relate the overriding signals to the
alternative function. Refer to the alternative function description for further details.
ATtiny441/841 [DATASHEET] 62
8495G–AVR–01/2014
Table 10-3. Alternative Functions of Port A
SCK Master clock output / slave clock input of SPI (alternative location)
SCK Master clock output / slave clock input of SPI (default location)
ATtiny441/841 [DATASHEET] 63
8495G–AVR–01/2014
Pin Function Description of Alternative Function
Table 10-4, below, summarizes the override signals used by the alternative functions of the port. For an illustration on
how signals are used, see Figure 10-6 on page 61.
ATtiny441/841 [DATASHEET] 64
8495G–AVR–01/2014
Table 10-4. Override Signals of Port A
PUOV 0
DDOV 0
PTOE 0
PUOV 0
PTOE 0
ATtiny441/841 [DATASHEET] 65
8495G–AVR–01/2014
Pin Signal Composition
PUOE 0
PUOV 0
DDOV 0
PVOE TOCC1OE
PTOE 0
PUOE 0
PUOV 0
DDOV 0
PTOE 0
PUOE 0
PUOV 0
PTOE 0
ATtiny441/841 [DATASHEET] 66
8495G–AVR–01/2014
Pin Signal Composition
PUOE TXEN1
PUOV 0
DDOV TXEN1
PTOE 0
PUOE 0
PUOV 0
PTOE 0
ATtiny441/841 [DATASHEET] 67
8495G–AVR–01/2014
Pin Signal Composition
PUOV 0
PTOE 0
ATtiny441/841 [DATASHEET] 68
8495G–AVR–01/2014
Pin Function Description of Alternative Function
dW debugWire input/output
Table 10-6, below, summarizes the override signals used by the alternative functions of the port. For an illustration on
how signals are used, see Figure 10-6 on page 61.
PUOV 0
DDOV 0
PB0 PVOV 0
PTOE 0
PUOE EXT_OSC
PUOV 0
DDOE EXT_OSC
DDOV 0
PVOE EXT_OSC
PB1 PVOV 0
PTOE 0
DI PCINT9 INPUT
ATtiny441/841 [DATASHEET] 69
8495G–AVR–01/2014
Pin Signal Composition
PUOE CKOUT
PUOV 0
DDOV CKOUT
PTOE 0
PUOE RSTDISBL
PUOV 1
DDOE RSTDISBL
DDOV 0
PVOE RSTDISBL
PB3 PVOV 0
PTOE 0
DI PCINT11 INPUT
ATtiny441/841 [DATASHEET] 70
8495G–AVR–01/2014
10.4 Register Description
Bit 7 6 5 4 3 2 1 0
(0x64) – – – – – – BBMB BBMA PORTCR
Read/Write R R R R R R R/W R/W
Initial Value 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
(0x6A) – – – – – – PHDEA1 PHDEA0 PHDE
Read/Write R R R R R R/W R/W R/W
Initial Value 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
(0x62) – – – – PUEB3 PUEB2 PUEB1 PUEB0 PUEB
Read/Write R R R R R/W R/W R/W R/W
Initial Value 0 0 0 0 0 0 0 0
ATtiny441/841 [DATASHEET] 71
8495G–AVR–01/2014
Bits 3:0 – PUEB[3:0]: Pull-Up Enable Bits
When a pull-up enable bit, PUEBn, is set the pull-up resistor on the equivalent port pin, PBn, is enabled.
Bit 7 6 5 4 3 2 1 0
0x18 (0x38) – – – – PORTB3 PORTB2 PORTB1 PORTB0 PORTB
Read/Write R R R R R/W R/W R/W R/W
Initial Value 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
0x17 (0x37) – – – – DDB3 DDB2 DDB1 DDB0 DDRB
Read/Write R R R R R/W R/W R/W R/W
Initial Value 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
0x16 (0x36) – – – – PINB3 PINB2 PINB1 PINB0 PINB
Read/Write R R R R R/W R/W R/W R/W
Initial Value N/A N/A N/A N/A N/A N/A N/A N/A
ATtiny441/841 [DATASHEET] 72
8495G–AVR–01/2014
10.4.7 PUEA – Port A Pull-Up Enable Control Register
Bit 7 6 5 4 3 2 1 0
(0x63) PUEA7 PUEA6 PUEA5 PUEA4 PUEA3 PUEA2 PUEA1 PUEA0 PUEA
Read/Write R/W R/W R/W R/W R/W R/W R/W R/W
Initial Value 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
0x1B (0x3B) PORTA7 PORTA6 PORTA5 PORTA4 PORTA3 PORTA2 PORTA1 PORTA0 PORTA
Read/Write R/W R/W R/W R/W R/W R/W R/W R/W
Initial Value 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
0x1A (0x3A) DDA7 DDA6 DDA5 DDA4 DDA3 DDA2 DDA1 DDA0 DDRA
Read/Write R/W R/W R/W R/W R/W R/W R/W R/W
Initial Value 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
0x19 (0x39) PINA7 PINA6 PINA5 PINA4 PINA3 PINA2 PINA1 PINA0 PINA
Read/Write R/W R/W R/W R/W R/W R/W R/W R/W
Initial Value N/A N/A N/A N/A N/A N/A N/A N/A
ATtiny441/841 [DATASHEET] 73
8495G–AVR–01/2014
11. 8-bit Timer/Counter0 with PWM
11.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 Interrupt Sources (TOV0, OCF0A, and OCF0B)
11.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 11-1.
Edge
Tn
Detector
TOP BOTTOM
( From Prescaler )
Timer/Counter
TCNTn
= =0
OCnA
(Int.Req.)
Waveform
= Generation
OCnA
OCRnA
Fixed
OCnB
TOP
(Int.Req.)
Value
DATA BUS
Waveform
= Generation
OCnB
OCRnB
TCCRnA TCCRnB
ATtiny441/841 [DATASHEET] 74
8495G–AVR–01/2014
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 84.
For actual placement of I/O pins, refer to Figure 1-1 on page 2, and Figure 1-2 on page 2. Also, see “TOCPMSA1 and
TOCPMSA0 – Timer/Counter Output Compare Pin Mux Selection Registers” on page 115, and “TOCPMCOE –
Timer/Counter Output Compare Pin Mux Channel Output Enable” on page 116.
11.2.1 Registers
The Timer/Counter (TCNT0) and Output Compare Registers (OCR0A and OCR0B) are 8-bit registers. Interrupt request
(abbreviated to Int.Req. in Figure 11-1) signals are all visible in the Timer Interrupt Flag Register (TIFR). All interrupts are
individually masked with the Timer Interrupt Mask Register (TIMSK). TIFR and TIMSK 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 (clkT0).
The double buffered Output Compare Registers (OCR0A and OCR0B) is 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 76 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.
11.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 11-1 are also used extensively throughout the document.
Constant Description
MAX The counter reaches its MAXimum when it becomes 0xFF (decimal 255)
The counter reaches the TOP when it becomes equal to the highest value in the count sequence. The
TOP TOP value can be assigned to be the fixed value 0xFF (MAX) or the value stored in the OCR0A Register.
The assignment depends on the mode of operation
ATtiny441/841 [DATASHEET] 75
8495G–AVR–01/2014
Figure 11-2. Counter Unit Block Diagram
TOVn
DATA BUS (Int.Req.)
Clock Select
count Edge
Tn
clear clkTn Detector
TCNTn Control Logic
direction
( From Prescaler )
bottom top
Depending of the mode of operation used, the counter is cleared, incremented, or decremented at each timer clock
(clkT0). clkT0 can be generated from an external or internal clock source, selected by the Clock Select bits (CS0[2:0]).
When no clock source is selected (CS0[2:0] = 0) the timer is stopped. However, the TCNT0 value can be accessed by
the CPU, regardless of whether clkT0 is present or not. A CPU write 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 output OC0A. For more details about advanced counting sequences and waveform generation, see “Modes of
Operation” on page 79.
The Timer/Counter Overflow Flag (TOV0) is set according to the mode of operation selected by the WGM0[1:0] bits.
TOV0 can be used for generating a CPU interrupt.
ATtiny441/841 [DATASHEET] 76
8495G–AVR–01/2014
Figure 11-3. Output Compare Unit, Block Diagram
DATA BUS
OCRnx TCNTn
8-BIT COMPARATOR
OCFnx (Int.Req.)
top
bottom
WAVEFORM GENERATOR OCnx
FOCn
WGMn[2:0] COMnX[1: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, thereby making the output glitch-
free.
The OCR0x Register access may seem complex, but this is not case. When the double buffering is enabled, the CPU
has access to the OCR0x Buffer Register, and if double buffering is disabled the CPU will access the OCR0x directly.
ATtiny441/841 [DATASHEET] 77
8495G–AVR–01/2014
Be aware that the COM0x[1:0] bits are not double buffered together with the compare value. Changing the COM0x[1:0]
bits will take effect immediately.
COMnx1
COMnx0 Waveform
D Q
FOCn Generator
1
OCn
OCnx Pin
0
D Q
DATA BUS
PORT
D Q
DDR
clk I/O
The general I/O port function is overridden by the Output Compare (OC0x) from the Waveform Generator if either of the
COM0x[1:0] bits are set. However, the OC0x 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 OC0x pin (DDR_OC0x) must be set as output
before the OC0x 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 OC0x state before the output is enabled. Note that
some COM0x[1:0] bit settings are reserved for certain modes of operation, see “Register Description” on page 84
ATtiny441/841 [DATASHEET] 78
8495G–AVR–01/2014
A change of the COM0x[1: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 Force Output Compare bits. See “TCCR0B –
Timer/Counter Control Register B” on page 88.
TCNTn
OCnA
(COMnA[1: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 be used for updating the TOP value. However, changing TOP to a
ATtiny441/841 [DATASHEET] 79
8495G–AVR–01/2014
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 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 (COM0A[1:0] = 1). The OC0A value will not be visible on
the port pin unless the data direction for the pin is set to output. When OCR0A is set to zero (0x00) the waveform
generated will have a maximum frequency of fclk_I/O/2. The waveform frequency is defined by the following equation:
f clk_I/O
f OCnx = --------------------------------------------------
2 N 1 + OCRnA
The N variable represents the prescale 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 counts from
MAX to 0x00.
ATtiny441/841 [DATASHEET] 80
8495G–AVR–01/2014
Figure 11-6. Fast PWM Mode, Timing Diagram
TCNTn
OCnx (COMnx[1:0] = 2)
OCnx (COMnx[1:0] = 3)
Period 1 2 3 4 5 6 7
The Timer/Counter Overflow Flag (TOV0) 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 OC0x pins. Setting the COM0x[1:0]
bits to two will produce a non-inverted PWM and an inverted PWM output can be generated by setting the COM0x[1:0] to
three: Setting the COM0A[1:0] bits to one 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 11-3 on page 85). The actual OC0x 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 OC0x Register at the Compare Match between OCR0x and TCNT0, and clearing (or setting) the OC0x Register at
the timer clock cycle the counter is cleared (changes from TOP to BOTTOM).
The PWM frequency for the output can be calculated by the following equation:
f clk_I/O
f OCnxPWM = ----------------------------------
N TOP + 1
The N variable represents the prescale factor (1, 8, 64, 256, or 1024).
The extreme values for the OCR0x Register represents special cases when generating a PWM waveform output in the
fast PWM mode. If OCR0x is set equal to BOTTOM, the output will be a narrow spike for each TOP+1 timer clock cycle.
Setting the OCR0x equal to TOP will result in a constantly high or low output (depending on the polarity of the output set
by the COM0x[1:0] bits.)
A frequency (with 50% duty cycle) waveform output in fast PWM mode can be achieved by setting OC0A to toggle its
logical level on each Compare Match (COM0A[1:0] = 1). The waveform generated will have a maximum frequency of 0 =
fclk_I/O/2 when OCR0A is set to zero. This feature is similar to the OC0A toggle in CTC mode, except the double buffer
feature of the Output Compare unit is enabled in the fast PWM mode.
ATtiny441/841 [DATASHEET] 81
8495G–AVR–01/2014
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.
OCRnx Update
TCNTn
OCnx (COMnx[1:0] = 2)
OCxn (COMnx[1:0] = 3)
Period 1 2 3
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 TCNT0 value will be equal to TOP for one timer clock cycle. The timing diagram
for the phase correct PWM mode is shown on Figure 11-7. The TCNT0 value is in the timing diagram shown 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 TCNT0 slopes represent Compare Matches between OCR0x and TCNT0.
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.
In phase correct PWM mode, the compare unit allows generation of PWM waveforms on the OC0x pins. Setting the
COM0x[1:0] bits to two will produce a non-inverted PWM. An inverted PWM output can be generated by setting the
COM0x[1:0] to three: Setting the COM0A0 bits to one 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 11-4 on page 86). The actual OC0x 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 OC0x Register at the Compare Match between OCR0x and TCNT0 when the counter increments, and
setting (or clearing) the OC0x Register at Compare Match between OCR0x and TCNT0 when the counter decrements.
The PWM frequency for the output when using phase correct PWM can be calculated by the following equation:
f clk_I/O
f OCnxPCPWM = -------------------------------
2 N TOP
The N variable represents the prescale factor (1, 8, 64, 256, or 1024).
The extreme values for the OCR0x Register represent special cases when generating a PWM waveform output in the
phase correct PWM mode. If the OCR0x is set equal to BOTTOM, the output will be continuously low and if set equal to
ATtiny441/841 [DATASHEET] 82
8495G–AVR–01/2014
TOP 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 11-7 on page 82 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.
OCR0x changes its value from TOP, like in Figure 11-7 on page 82. When the OCR0x value is TOP the OCnx pin
value is the same as the result of a down-counting Compare Match. To ensure symmetry around BOTTOM the
OCnx value at TOP must correspond to the result of an up-counting Compare Match.
The timer starts counting from a value higher than the one in OCR0x, and for that reason misses the Compare
Match and hence the OCnx change that would have happened on the way up.
clkI/O
clkTn
(clkI/O /1)
TOVn
Figure 11-9 on page 83 shows the same timing data, but with the prescaler enabled.
clkI/O
clkTn
(clkI/O /8)
TOVn
Figure 11-10 on page 84 shows the setting of OCF0B in all modes and OCF0A in all modes except CTC mode and PWM
mode, where OCR0A is TOP.
ATtiny441/841 [DATASHEET] 83
8495G–AVR–01/2014
Figure 11-10.Timer/Counter Timing Diagram, Setting of OCF0x, with Prescaler (fclk_I/O/8)
clkI/O
clkTn
(clkI/O /8)
OCFnx
Figure 11-11 on page 84 shows the setting of OCF0A and the clearing of TCNT0 in CTC mode and fast PWM mode
where OCR0A is TOP.
Figure 11-11.Timer/Counter Timing Diagram, Clear Timer on Compare Match mode, with Prescaler (fclk_I/O/8)
clkI/O
clkTn
(clkI/O /8)
TCNTn
TOP - 1 TOP BOTTOM BOTTOM + 1
(CTC)
OCRnx TOP
OCFnx
11.9.1 TOCPMSA1 and TOCPMSA0 – Timer/Counter Output Compare Pin Mux Selection Registers
Bit 7 6 5 4 3 2 1 0
(0x68) TOCC7S1 TOCC7S0 TOCC6S1 TOCC6S0 TOCC5S1 TOCC5S0 TOCC4S1 TOCC4S0 TOCPMSA1
(0x67) TOCC3S1 TOCC3S0 TOCC2S1 TOCC2S0 TOCC1S1 TOCC1S0 TOCC0S1 TOCC0S0 TOCPMSA0
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
ATtiny441/841 [DATASHEET] 84
8495G–AVR–01/2014
11.9.2 TCCR0A – Timer/Counter Control Register A
Bit 7 6 5 4 3 2 1 0
0x30 (0x50) COM0A1 COM0A0 COM0B1 COM0B0 – – WGM01 WGM00 TCCR0A
Read/Write R/W R/W R/W R/W R R R/W R/W
Initial Value 0 0 0 0 0 0 0 0
Table 11-3 shows COM0A[1:0] bit functionality when WGM0[2:0] bits are set to fast PWM mode.
Note: A special case occurs when OCR0A equals TOP and COM0A1 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 80 for more details.
Table 11-4 shows COM0A[1:0] bit functionality when WGM0[2:0] bits are set to phase correct PWM mode.
ATtiny441/841 [DATASHEET] 85
8495G–AVR–01/2014
Table 11-4. Compare Output Mode, Phase Correct PWM Mode
Clear OC0A on Compare Match when up-counting. Set OC0A on Compare Match
1 0
when down-counting.
Set OC0A on Compare Match when up-counting. Clear OC0A on Compare Match
1 1
when down-counting.
Note: When OCR0A equals TOP and COM0A1 is set, the Compare Match is ignored, but the set or clear is done at
TOP. See “Phase Correct PWM Mode” on page 81 for more details.
Table 11-6 shows COM0B[1:0] bit functionality when WGM0[2:0] bits are set to fast PWM mode.
0 1 Reserved
Note: A special case occurs when OCR0B equals TOP and COM0B1 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 80 for more details.
ATtiny441/841 [DATASHEET] 86
8495G–AVR–01/2014
Table 11-7 shows the COM0B[1:0] bit functionality when the WGM0[2:0] bits are set to phase correct PWM mode.
0 1 Reserved
Clear OC0B on Compare Match when up-counting. Set OC0B on Compare Match
1 0
when down-counting.
Set OC0B on Compare Match when up-counting. Clear OC0B on Compare Match
1 1
when down-counting.
Note: A special case occurs when OCR0B equals TOP and COM0B1 is set. In this case, the Compare Match is
ignored, but the set or clear is done at TOP. See “Phase Correct PWM Mode” on page 81 for more details.
4 1 0 0 Reserved – – –
6 1 1 0 Reserved – – –
ATtiny441/841 [DATASHEET] 87
8495G–AVR–01/2014
11.9.3 TCCR0B – Timer/Counter Control Register B
Bit 7 6 5 4 3 2 1 0
0x33 (0x53) FOC0A FOC0B – – WGM02 CS02 CS01 CS00 TCCR0B
Read/Write W W R R R/W R/W R/W R/W
Initial Value 0 0 0 0 0 0 0 0
0 0 1 clkI/O/(No prescaling)
ATtiny441/841 [DATASHEET] 88
8495G–AVR–01/2014
CS02 CS01 CS00 Description
If external pin modes are used for the 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.
Bit 7 6 5 4 3 2 1 0
0x32 (0x52) TCNT0[7:0] TCNT0
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 Timer/Counter Register gives direct access, both for read and write operations, to the Timer/Counter 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, introduces a risk of missing a Compare Match between TCNT0 and the
OCR0x Registers.
Bit 7 6 5 4 3 2 1 0
0x36 (0x56) OCR0A[7:0] OCR0A
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 Output Compare Register A 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 OC0A pin.
Bit 7 6 5 4 3 2 1 0
0x3C (0x5C) OCR0B[7:0] OCR0B
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 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.
ATtiny441/841 [DATASHEET] 89
8495G–AVR–01/2014
11.9.7 TIMSK0 – Timer/Counter Interrupt Mask Register
Bit 7 6 5 4 3 2 1 0
0x39 (0x59) – – – – – OCIE0B OCIE0A TOIE0 TIMSK0
Read/Write R R R R R R/W R/W R/W
Initial Value 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
0x38 (0x58) – – – – – OCF0B OCF0A TOV0 TIFR0
Read/Write R R R R R R/W R/W R/W
Initial Value 0 0 0 0 0 0 0 0
ATtiny441/841 [DATASHEET] 90
8495G–AVR–01/2014
I-bit, TOIE0 (Timer/Counter0 Overflow Interrupt Enable), and TOV0 are set, the Timer/Counter0 Overflow interrupt is
executed.
The setting of this flag is dependent of the WGM0[2:0] bit setting. See Table 11-8 on page 87.
ATtiny441/841 [DATASHEET] 91
8495G–AVR–01/2014
12. 16-bit Timer/Counters (Timer/Counter 1 & Timer/Counter 2)
12.1 Features
True 16-bit Design (i.e., Allows 16-bit PWM)
Two independent Output Compare Units
Double Buffered Output Compare Registers
One Input Capture Unit
Input Capture Noise Canceler
Clear Timer on Compare Match (Auto Reload)
Glitch-free, Phase Correct Pulse Width Modulator (PWM)
Variable PWM Period
Frequency Generator
External Event Counter
Four independent interrupt Sources (TOVn, OCFnA, OCFnB, and ICFn)
12.3 Overview
The 16-bit timer/counter unit allows accurate program execution timing (event management), wave generation, and
signal timing measurement.
A simplified block diagram of the 16-bit timer/counter is shown in Figure 12-1. 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 section “Register
Description” on page 111.
ATtiny441/841 [DATASHEET] 92
8495G–AVR–01/2014
Figure 12-1. 16-bit Timer/Counter Block Diagram
Count TOVn
Clear (Int.Req.)
Control Logic
Direction clkTn Clock Select
Edge
Tn
Detector
TOP BOTTOM
( From Prescaler )
Timer/Counter
TCNTn
= =0
OCnA
(Int.Req.)
Waveform
= Generation
OCnA
OCRnA
Fixed OCnB
TOP (Int.Req.)
DATA BUS
Values
Waveform
= Generation
OCnB
Edge Noise
ICRn
Detector Canceler
ICPn
TCCRnA TCCRnB
For actual placement of I/O pins, refer to Figure 1-1 on page 2, and Figure 1-2 on page 2. Also, see “TOCPMSA1 and
TOCPMSA0 – Timer/Counter Output Compare Pin Mux Selection Registers” on page 115, and “TOCPMCOE –
Timer/Counter Output Compare Pin Mux Channel Output Enable” on page 116.
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. For example, TCNT1 for accessing Timer/Counter1 counter value and so
on.
12.3.1 Registers
The Timer Counter (TCNTn), Output Compare Registers (OCRnA/B), 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
section “Accessing 16-bit Registers” on page 108. The Timer/Counter Control Registers (TCCRnA/B) are 8-bit registers
and have no CPU access restrictions. Interrupt requests (abbreviated to Int.Req. in the figure) signals are all visible in the
Timer Interrupt Flag Register (TIFR). All interrupts are individually masked with the Timer Interrupt Mask Register
(TIMSK). TIFR and TIMSK are not shown in the figure.
ATtiny441/841 [DATASHEET] 93
8495G–AVR–01/2014
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 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 (clkTn).
The double buffered Output Compare Registers (OCRnA/B) are compared with the 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). See “Output Compare Units” on page 97. The compare match event will also set the
Compare Match Flag (OCFnA/B) 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 “Analog Comparator 0” on page 124 and “Analog
Comparator 1” on page 128). The Input Capture unit includes a digital filtering unit (Noise Canceler) 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 OCRnA
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 in 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.
12.3.2 Definitions
The following definitions are used extensively throughout the section:
Constant Description
MAX The counter reaches its MAXimum when it becomes 0xFFFF (decimal 65535)
The counter reaches TOP when it becomes equal to the highest value in the count sequence. The TOP
TOP value can be assigned to be the fixed value 0xFFFF (MAX), the value stored in the OCRnA register, or the
value stored in the ICRn register. The assignment depends on the mode of operation
ATtiny441/841 [DATASHEET] 94
8495G–AVR–01/2014
Figure 12-2. Counter Unit Block Diagram
TEMP (8-bit)
Clock Select
Count Edge
Tn
TCNTnH (8-bit) TCNTnL (8-bit) Clear clkTn Detector
Control Logic
Direction
TCNTn (16-bit Counter)
( From Prescaler )
TOP BOTTOM
The 16-bit counter is mapped into two 8-bit I/O memory locations: Counter High (TCNTnH) containing the upper eight
bits of the counter, and Counter Low (TCNTnL) containing 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 when the counter is counting that will give unpredictable results. The special
cases are described in the sections where they are of importance.
Depending on the mode of operation used, the counter is cleared, incremented, or decremented at each timer clock
(clkTn). The clkTn can be generated from an external or internal clock source, selected by the Clock Select bits (CSn[2:0]).
When no clock source is selected (CSn[2:0] = 0) the timer is stopped. However, the TCNTn value can be accessed by
the CPU, independent of whether clkTn is present or not. A CPU write overrides (has priority over) all counter clear or
count operations.
The counting sequence is determined by the setting of the Waveform Generation mode bits (WGMn[3: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 100.
The Timer/Counter Overflow Flag (TOVn) is set according to the mode of operation selected by the WGMn[3:0] bits.
TOVn can be used for generating a CPU interrupt.
ATtiny441/841 [DATASHEET] 95
8495G–AVR–01/2014
Figure 12-3. Input Capture Unit Block Diagram
TEMP (8-bit)
Analog
Comparator Noise Edge
ICFn (Int.Req.)
Canceler Detector
ICPn
When a change of the logic level (an event) occurs on the Input Capture pin (ICPn), alternatively on the Analog
Comparator output (ACOm), and this change confirms to the setting of the edge detector, a capture will be triggered.
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
(ICIEn = 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 cleared by software by writing a logical one to its I/O bit location.
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). When
the CPU reads the ICRnH I/O location it will access the TEMP Register.
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 (WGMn[3: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 108.
ATtiny441/841 [DATASHEET] 96
8495G–AVR–01/2014
An Input Capture can be triggered by software by controlling the port of the ICPn pin.
ATtiny441/841 [DATASHEET] 97
8495G–AVR–01/2014
Figure 12-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)
= (16-bit Comparator )
OCFnx (Int.Req.)
TOP
Waveform Generator OCnx
BOTTOM
WGMn[3:0] COMnx[1: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 case. When the double buffering is enabled, the CPU
has access to the OCRnx Buffer Register, and if double buffering is disabled the CPU will access the OCRnx directly.
The content of the OCRnx (Buffer or Compare) Register is only changed by a write operation (the timer/counter does not
update this register automatically as the TCNTn and ICRn Register). Therefore OCRnx is not read via the high byte
temporary register (TEMP). However, it is a good practice to read the low byte first as when 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. When the high byte I/O location is written by the CPU, the
TEMP Register will be updated by the value written. 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 108.
ATtiny441/841 [DATASHEET] 98
8495G–AVR–01/2014
12.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 timer clock cycle, 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 enabled.
COMnx1
COMnx0 Waveform
D Q
FOCnx Generator
1
OCnx
OCnx Pin
0
D Q
DATA BUS
PORT
D Q
DDR
clk I/O
Figure 12-5 shows a simplified schematic of the logic affected by the COMnx[1: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
ATtiny441/841 [DATASHEET] 99
8495G–AVR–01/2014
are affected by the COMnx[1:0] bits are shown. When referring to the OCnx state, the reference is for the internal OCnx
Register, not the OCnx pin. If a system reset occur, the OCnx Register is reset to “0”.
The general I/O port function is overridden by the Output Compare (OCnx) from the Waveform Generator if either of the
COMnx[1: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. See Table 12-2 on page 112, Table 12-3 on page 112 and Table 12-4
on page 112 for details.
The design of the Output Compare pin logic allows initialization of the OCnx state before the output is enabled. Note that
some COMnx[1:0] bit settings are reserved for certain modes of operation. See “Register Description” on page 111
The COMnx[1:0] bits have no effect on the Input Capture unit.
TCNTn
OCnA
(COMnA[1:0] = 1)
(Toggle)
Period 1 2 3 4
An interrupt can be generated at each time the counter value reaches the TOP value by either using 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 the 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 OCRnA or ICRn is lower than the current value of TCNTn, the counter will miss the
compare match. 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. An alternative will then be to use the
fast PWM mode using OCRnA for defining TOP (WGMn[3:0] = 15) since 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 (COMnA[1: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 nA = fclk_I/O/2 when OCRnA is set to zero (0x0000). The waveform frequency is defined by the
following equation:
f clk_I/O
f 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 timer clock cycle that the counter counts from MAX
to 0x0000.
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 (WGMn[3:0] = 5, 6, or 7), the value in ICRn (WGMn[3:0] = 14), or the value in OCRnA (WGMn[3: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 12-7 on page 102. 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.
TCNTn
OCnx (COMnx[1:0] = 2)
OCnx (COMnx[1: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 for defining the TOP value. If one
of the interrupts are enabled, the interrupt handler routine can be used 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. If the TOP value is lower than any of the Compare Registers, a compare match will never occur
between the TCNTn and the OCRnx. Note that when using fixed TOP values the unused bits are masked to zero when
any of the OCRnx Registers are written.
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 when the counter is running with none or a low
prescaler value, there is a risk that the new ICRn value written is lower than the current value of TCNTn. The result will
then be that the counter will miss the compare match at the TOP value. The counter will then have to count to the MAX
value (0xFFFF) and wrap around starting at 0x0000 before the compare match can occur. The OCRnA Register
however, is double buffered. This feature allows the OCRnA I/O location to be written anytime. When the OCRnA I/O
location is written the value written will be put into the OCRnA Buffer Register. The OCRnA Compare Register will then
The N variable represents the prescaler divider (1, 8, 64, 256, or 1024).
The extreme values for the OCRnx Register represents 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 COMnx[1: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 (COMnA[1:0] = 1). The waveform generated will have a maximum frequency of nA =
fclk_I/O/2 when OCRnA is 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.
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 (WGMn[3:0] = 1, 2, or 3), the value in ICRn (WGMn[3:0] = 10), or the value in OCRnA
(WGMn[3: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 12-8.
The figure shows phase correct 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 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.
TCNTn
OCnx (COMnx[1:0] = 2)
OCnx (COMnx[1: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 TCNTn and the OCRnx. Note that when using 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 12-8 illustrates, changing the TOP actively
while the timer/counter is running in the phase correct mode can result in an unsymmetrical output. The reason for this
can be found in the time of update 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 differ the two slopes of the
period will differ in length. The difference in length gives the unsymmetrical result on 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 generation of PWM waveforms on the OCnx pins. Setting the
COMnx[1:0] bits to two will produce a non-inverted PWM and an inverted PWM output can be generated by setting the
COMnx[1:0] to three (See Table 12-4 on page 112). The actual OCnx value will only be visible on the port pin if the data
direction for the port pin is set as 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 clearing (or
setting) the OCnx Register at compare match between OCRnx and TCNTn when the counter decrements. The PWM
frequency for the output when using phase correct PWM can be calculated by the following equation:
f clk_I/O
f OCnxPCPWM = ----------------------------
2 N TOP
The N variable represents the prescaler divider (1, 8, 64, 256, or 1024).
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 (WGMn[3:0] = 8), or the value in OCRnA (WGMn[3:0] = 9). 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 and frequency correct PWM mode is shown on Figure 12-9.
Figure 12-9. Phase and Frequency Correct PWM Mode, Timing Diagram
OCRnx/TOP Updateand
TOVn Interrupt Flag Set
(Interrupt on Bottom)
TCNTn
OCnx (COMnx[1:0] = 2)
OCnx (COMnx[1:0] = 3)
Period 1 2 3 4
f clk_I/O
f OCnxPFCPWM = ----------------------------
2 N TOP
The N variable represents the prescaler divider (1, 8, 64, 256, or 1024).
The extreme values for the OCRnx Register represents 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.
clkI/O
clkTn
(clkI/O /1)
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)
Figure 12-11 shows the same timing data, but with the prescaler enabled.
clkI/O
clkTn
(clkI/O /8)
OCFnx
Figure 12-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.
clkI/O
clkTn
(clkI/O /1)
OCFnx
Figure 12-13 shows the same timing data, but with the prescaler enabled.
clkI/O
clkTn
(clkI/O /8)
OCFnx
...
; 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 Example
unsigned int i;
...
/* Set TCNTn to 0x01FF */
TCNTn = 0x1FF;
/* Read TCNTn into i */
i = TCNTn;
...
The assembly code example returns the TCNTn value in the r17:r16 register pair.
It is important to notice that 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,
when both the main code and the interrupt code update the temporary register, the main code must disable the interrupts
during the 16-bit access.
The following code examples show how to do an atomic read of the TCNTn Register contents. Reading any of the
OCRnA/B or ICRn Registers can be done by using the same principle.
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
C Code Example
The assembly code example returns the TCNTn value in the r17:r16 register pair.
The following code examples show how to do an atomic write of the TCNTn Register contents. Writing any of the
OCRnA/B or ICRn Registers can be done by using the same principle.
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
The assembly code example requires that the r17:r16 register pair contains the value to be written to TCNTn.
Bit 7 6 5 4 3 2 1 0
0x2F (0x4F) COM1A1 COM1A0 COM1B1 COM1B0 – – WGM11 WGM10 TCCR1A
Read/Write R/W R/W R/W R/W R R R/W R/W
Initial Value 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
(0xCA) COM2A1 COM2A0 COM2B1 COM2B0 – – WGM21 WGM20 TCCR2A
Read/Write R/W R/W R/W R/W R R R/W R/W
Initial Value 0 0 0 0 0 0 0 0
COMnA1 COMnA0
COMnB1 COMnB0 Description
Table 12-3 shows COMnx[1:0] bit functionality when WGMn[3:0] bits are set to fast PWM mode.
COMnA1 COMnA0
COMnB1 COMnB0 Description
Note: A special case occurs when OCRnA/OCRnB equals TOP and COMnA1/COMnB1 is set. In this case the com-
pare match is ignored, but the set or clear is done at BOTTOM. See “Fast PWM Mode” on page 101 for more
details.
Table 12-4 shows COMnx[1:0] functionality when WGMn[3:0] are set to phase or phase and frequency correct PWM.
Table 12-4. Compare Output Mode, Phase Correct and Phase & Frequency Correct PWM
COMnA1 COMnA0
COMnB1 COMnB0 Description
Mode of Update of
Mode WGMn[3:0] Operation TOP OCRnx at TOVn Flag Set at
13 1101 (Reserved) – – –
Bit 7 6 5 4 3 2 1 0
0x2E (0x4E) ICNC1 ICES1 – WGM13 WGM12 CS12 CS11 CS10 TCCR1B
Read/Write R/W 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 6 5 4 3 2 1 0
(0xC9) ICNC2 ICES2 – WGM23 WGM22 CS22 CS21 CS20 TCCR2B
Read/Write R/W R/W R R/W R/W R/W R/W R/W
Initial Value 0 0 0 0 0 0 0 0
If external pin modes are used for the timer/counter, transitions on the Tn pin will clock the counter even if the pin is
configured as an output. This feature allows software control of the counting.
Bit 7 6 5 4 3 2 1 0
0x22 (0x42) FOC1A FOC1B – – – – – – TCCR1C
Read/Write W W R R R R R R
Initial Value 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
(0xC8) FOC2A FOC2B – – – – – – TCCR2C
Read/Write W W R R R R R R
Initial Value 0 0 0 0 0 0 0 0
12.12.4 TOCPMSA1 and TOCPMSA0 – Timer/Counter Output Compare Pin Mux Selection Registers
Bit 7 6 5 4 3 2 1 0
(0x68) TOCC7S1 TOCC7S0 TOCC6S1 TOCC6S0 TOCC5S1 TOCC5S0 TOCC4S1 TOCC4S0 TOCPMSA1
(0x67) TOCC3S1 TOCC3S0 TOCC2S1 TOCC2S0 TOCC1S1 TOCC1S0 TOCC0S1 TOCC0S0 TOCPMSA0
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
Bits 7:0 – TOCCnS1 and TOCCnS0: Timer/Counter Output Compare Channel Select
TOCCnS1 and TOCCnS bits select which timer/counter compare output is routed to the corresponding TOCCn
pin. The three timer/counters provide six possible compare outputs that can be routed to output pins, as shown in the
TOCCnS1:0
TOCCn Output 00 01 1X
12.12.5 TOCPMCOE – Timer/Counter Output Compare Pin Mux Channel Output Enable
Bit 7 6 5 4 3 2 1 0
(0x66) TOCC7OE TOCC6OE TOCC5OE TOCC4OE TOCC3OE TOCC2OE TOCC1OE TOCC0OE TOCPMCOE
Read/Write R/W R/W R/W R/W R/W R/W R/W R/W
Initial Value 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
0x2D (0x4D) TCNT1[15:8] TCNT1H
0x2C (0x4C) TCNT1[7:0] TCNT1L
Read/Write R/W R/W R/W R/W R/W R/W R/W R/W
Initial Value 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
(0xC7) TCNT2[15:8] TCNT2H
(0xC6) TCNT2[7:0] TCNT2L
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 two timer/counter I/O locations (TCNTnH and TCNTnL, combined TCNTn) 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 “Accessing 16-bit Registers” on
page 108.
Bit 7 6 5 4 3 2 1 0
0x2B (0x4B) OCR1A[15:8] OCR1AH
0x2A (0x4A) OCR1A[7:0] OCR1AL
Read/Write R/W R/W R/W R/W R/W R/W R/W R/W
Initial Value 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
(0xC5) OCR2A[15:8] OCR2AH
(0xC4) OCR2A[7:0] OCR2AL
Read/Write R/W R/W R/W R/W R/W R/W R/W R/W
Initial Value 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
0x29 (0x49) OCR1B[15:8] OCR1BH
0x28 (0x48) OCR1B[7:0] OCR1BL
Read/Write R/W R/W R/W R/W R/W R/W R/W R/W
Initial Value 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
(0xC3) OCR2B[15:8] OCR2BH
(0xC2) OCR2B[7:0] OCR2BL
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 Output Compare Registers contain a 16-bit value that is continuously compared with the counter value (TCNTn). A
match can be used to generate an Output Compare interrupt, or to generate a waveform output on the OCnx 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 “Accessing 16-bit Registers” on page 108.
Bit 7 6 5 4 3 2 1 0
0x25 (0x45) ICR1[15:8] ICR1H
0x24 (0x44) ICR1[7:0] ICR1L
Read/Write R/W R/W R/W R/W R/W R/W R/W R/W
Initial Value 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
(0xC1) ICR2[15:8] ICR2H
(0xC0) ICR2[7:0] ICR2L
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 Input Capture is updated with the counter (TCNTn) value each time an event occurs on the ICPn pin (or optionally on
the Analog Comparator output). The Input Capture 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. “Accessing 16-bit Registers” on page 108.
Bit 7 6 5 4 3 2 1 0
0x0F (0x2F) – – ICIE1 – – OCIE1B OCIE1A TOIE1 TIMSK1
Read/Write R R R/W R R R/W R/W R/W
Initial Value 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
0x11 (0x31) – – ICIE2 – – OCIE2B OCIE2A TOIE2 TIMSK2
Read/Write R R R/W R R R/W R/W R/W
Initial Value 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
0x0E (0x2E) – – ICF1 – – OCF1B OCF1A TOV1 TIFR1
Read/Write R R R/W R R R/W R/W R/W
Initial Value 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
0x10 (0x30) – – ICF2 – – OCF2B OCF2A TOV2 TIFR2
Read/Write R R R/W R R R/W R/W R/W
Initial Value 0 0 0 0 0 0 0 0
CK/8
CK/64
CK/256
CK/1024
PSR
Tn SYNC
CSn0
CSn1
CSn2
TIMER/COUNTER
CLOCK SOURCE
clk Tn
The synchronization logic on the input pin (Tn) is shown in Figure 13-2 on page 122.
Tn D Q D Q D Q Tn_sync
(To Clock
Select Logic)
LE
clk I/O
The registers are clocked at the positive edge of the internal system clock (clkI/O). The latch is transparent in the high
period of the internal system clock.
Depending on the Clock Select bits of the timer/counter, the edge detector generates one clkTn pulse for each positive or
negative edge it detects.
The synchronization and edge detector logic introduces a delay of 2.5 to 3.5 system clock cycles from an edge has been
applied to the Tn pin to the counter is updated.
Enabling and disabling of the clock input must be done when Tn has been stable for at least one system clock cycle,
otherwise it is a risk that a false Timer/Counter clock pulse is generated.
To ensure correct sampling, each half period of the external clock applied must be longer than one system clock cycle.
Given a 50/50 duty cycle the external clock must be guaranteed to have less than half the system clock frequency (fExtClk
< fclk_I/O/2). Since the edge detector uses sampling, the Nyquist sampling theorem states that the maximum frequency of
an external clock it can detect is half the sampling frequency. However, due to variation of the system clock frequency
and duty cycle caused by oscillator source tolerances, it is recommended that maximum frequency of an external clock
source is less than fclk_I/O/2.5.
An external clock source can not be prescaled.
Bit 7 6 5 4 3 2 1 0
0x23 (0x43) TSM – – – – – – PSR GTCCR
Read/Write R/W R R R R R R R/W
Initial Value 0 0 0 0 0 0 0 0
AIN00
VCC
BANDGAP ACD0
REFERENCE ACIE0
ANALOG
COMPARATOR 0
IRQ
AIN01
ACNMUX[1:0] ACI0
ACIS01 ACIS00
ADC MUX
ACIC0
OUTPUT
HSEL0
TO T/C CAPTURE
HLEV0 TRIGGER MUX
ACO0
Input options for the analog comparator are listed in Table 14-1, below.
Note: 1. To avoid interference from digital port functions the analog comparator port pins should be configured as
inputs with the internal pull-up switched off.
In order to use the ADC multiplexer, the ADC Power Reduction bit must be disabled . See “PRR – Power Reduction
Register” on page 38 for more details.
Bit 7 6 5 4 3 2 1 0
0x0A (0x2A) ACD0 ACPMUX2 ACO0 ACI0 ACIE0 ACIC0 ACIS01 ACIS00 ACSR0A
Read/Write R/W R/W R R/W R/W R/W R/W R/W
Initial Value 0 0 N/A 0 0 0 0 0
0 1 Reserved
When changing these bits, the analog comparator interrupt must be disabled. Otherwise, an interrupt can occur when the
bits are changed.
Bit 7 6 5 4 3 2 1 0
0x0B (0x2B) HSEL0 HLEV0 – ACOE0 ACNMUX1 ACNMUX0 ACPMUX1 ACPMUX0 ACSR0B
Read/Write R/W R/W R/W R R/W R/W R/W R/W
Initial Value 0 0 0 0 0 0 0 0
0 X Not enabled
0 20 mV
1
1 50 mV
0 0 AIN01 pin
1 0
Reserved
1 1
0 0 0 AIN00 pin
0 0 1 Reserved
0 1 0 Reserved
0 1 1 Reserved
1 0 1 Reserved
1 1 0 Reserved
1 1 1 Reserved
Bit 7 6 5 4 3 2 1 0
(0x60) ADC7D ADC6D ADC5D ADC4D ADC3D ADC2D ADC1D ADC0D DIDR0
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
AIN10
VCC
BANDGAP
REFERENCE ACD1
ACIE1
ANALOG
COMPARATOR 1
IRQ
ACME1
ADEN1 ACI1
ACIS11 ACIS10
AIN11
ACIC1
HSEL1
TO T/C CAPTURE
ADC MUX HLEV1 TRIGGER MUX
OUTPUT ACO1
Input options for the analog comparator are listed in Table 15-1, below.
Note: 1. To avoid interference from digital port functions the analog comparator port pins should be configured as
inputs with the internal pull-up switched off.
In order to use the ADC multiplexer, the ADC Power Reduction bit must be disabled . See “PRR – Power Reduction
Register” on page 38 for more details.
Bit 7 6 5 4 3 2 1 0
0x0C (0x2C) ACD1 ACBG1 ACO1 ACI1 ACIE1 ACIC1 ACIS11 ACIS10 ACSR1A
Read/Write R/W R/W R R/W R/W R/W R/W R/W
Initial Value 1 0 N/A 0 0 0 0 0
0 AIN10
0 1 Reserved
When changing these bits, the analog comparator interrupt must be disabled. Otherwise, an interrupt can occur when the
bits are changed.
Bit 7 6 5 4 3 2 1 0
0x0D (0x2D) HSEL1 HLEV1 – ACOE1 – ACME1 – – ACSR1B
Read/Write R/W R/W R R R R/W R R
Initial Value 0 0 0 0 0 0 0 0
0 X Not enabled
0 20 mV
1
1 50 mV
Bit 5 – Reserved
This bit is reserved and will always read zero.
Bit 3 – Reserved
This bit is reserved and will always read zero.
0 X AIN11
1 1 AIN11
Bit 7 6 5 4 3 2 1 0
(0x60) ADC7D ADC6D ADC5D ADC4D ADC3D ADC2D ADC1D ADC0D DIDR0
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
16.1 Features
10-bit Resolution
1 LSB Integral Non-linearity
± 2 LSB Absolute Accuracy
15µs Conversion Time
15 kSPS at Maximum Resolution
12 Multiplexed Single Ended Input Channels
10 Differential Ended Input Channel
46 Differential Input Pairs
Selectable Gain (1x / 20x / 100x)
Temperature Sensor Input Channel
Optional Left Adjustment for ADC Result Readout
0 - VCC ADC Input Voltage Range
ADC Reference Voltages: 1.1V, 2.2V, and 4.096V
Free Running or Single Conversion Mode
ADC Start Conversion by Auto Triggering on Interrupt Sources
Interrupt on ADC Conversion Complete
Sleep Mode Noise Canceler
16.2 Overview
ATtiny441/841 features a 10-bit, successive approximation Analog-to-Digital Converter (ADC). The ADC is wired to a 16-
channel analog multiplexer, which allows the ADC to measure the voltage at 12 single-ended input pins, from 46
differential input pairs, or from four internal, single-ended voltage channels coming from the internal temperature sensor,
internal voltage reference, analog ground, or supply voltage. Voltage inputs are referred to 0V (GND).
The ADC contains a Sample 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 16-1 on page 133.
Internal reference voltage of nominally 1.1V, 2.2V, and 4V is provided on-chip. Alternatively, VCC can be used as
reference voltage for single ended channels.
INTERRUPT FLAGS
ADMUXB ADMUXA ADCSRB ADCSRA ADCH+ADCL
GSEL
MUX[5:0]
ADLAR
ADTS[2:0]
ADSC
ADATE
ADPS2
ADPS1
ADPS0
ADEN
ADIE
TRIGGER ADC IRQ
SELECT
START
PRESCALER
ADC[9:0]
ADIF
AREF CONVERSION LOGIC
VCC
10-BIT DAC -
INTERNAL
REFERENCE +
SAMPLE & HOLD
COMPARATOR
TEMPERATURE
SENSOR
ADC0
ADC1
ADC MUX OUTPUT
ADC2
INPUT
... MUX
(POS)
ADC8 +
-
ADC9
GAIN AMPLIFIER
ADC10
ADC11
... AGND
INPUT MULTIPLEXER
(NEGATIVE)
ADTS[2:0]
PRESCALER
START CLKADC
ADIF ADATE
SOURCE 1
. CONVERSION
. LOGIC
.
. EDGE
SOURCE n DETECTOR
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.
ADPS0
ADPS1
ADPS2
The ADC module contains a prescaler, as illustrated in Figure 16-3 on page 135, which generates an acceptable ADC
clock frequency from any CPU frequency above 100 kHz. The prescaling is set by the ADPS bits in ADCSRA. The
prescaler starts counting from the moment the ADC is switched on by setting the ADEN bit in ADCSRA. The prescaler
keeps running for as long as the ADEN bit is set, and is continuously reset when ADEN is low.
When initiating a single ended conversion by setting the ADSC bit in ADCSRA, the conversion starts at the following
rising edge of the ADC clock cycle.
Figure 16-4. ADC Timing Diagram, First Conversion (Single Conversion Mode)
Next
First Conversion Conversion
Cycle Number 1 2 13 14 15 16 17 18 19 20 21 22 23 24 25 26 1 2 3
ADC Clock
ADEN
ADSC
ADIF
The actual sample-and-hold takes place 4 ADC clock cycles after the start of a normal conversion and 15 ADC clock
cycles after the start of a first conversion. See Figure 16-5. When a conversion is complete, the result is written to the
ADC Data Registers, and ADIF is set. In Single Conversion mode, ADSC is cleared simultaneously. The software may
then set ADSC again, and a new conversion will be initiated on the first rising ADC clock edge.
Cycle Number 1 2 3 4 5 6 7 8 11 12 13 14 15 1 2 3
ADC Clock
ADSC
ADIF
When Auto Triggering is used, the prescaler is reset when the trigger event occurs, as shown in Figure 16-6 below. This
assures a fixed delay from the trigger event to the start of conversion. In this mode, the sample-and-hold takes place 4.5
ADC clock cycles after the rising edge on the trigger source signal. Two additional CPU clock cycles are used for
synchronization logic.
Cycle Number 1 2 3 4 5 6 7 8 9 13 14 15 1 2
ADC Clock
Trigger
Source
ADATE
ADIF
In Free Running mode, a new conversion will be started immediately after the conversion completes, while ADSC
remains high. See Figure 16-7.
13 14 15 1 2 3 4 5
Cycle Number
ADC Clock
ADSC
ADIF
Normal conversions 4 15
Note: 1. When gain amplifier is active, also includes the first conversion after a change in channel, reference or gain
setting.
Note that the ADC will not automatically be 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.
IIH
ADCn
1..100 kohm
CS/H= 14 pF
IIL
VCC/2
Note: The capacitor in the figure depicts the total capacitance, including the sample/hold capacitor and any stray or parasitic
capacitance inside the device. The value given is worst case.
Where high ADC accuracy is required it is recommended to use ADC Noise Reduction Mode, as described in Section
16.7 on page 139. This is especially the case when system clock frequency is above 1 MHz, or when the ADC is used for
reading the internal temperature sensor, as described in Section 16.12 on page 143. A good system design with properly
placed, external bypass capacitors does reduce the need for using ADC Noise Reduction Mode
Offset: The deviation of the first transition (0x000 to 0x001) compared to the ideal transition (at 0.5 LSB). Ideal
value: 0 LSB.
Output Code
Ideal ADC
Actual ADC
Offset
Error
VREF Input Voltage
Ideal ADC
Actual ADC
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.
Ideal ADC
Actual ADC
1 LSB
DNL
0x00
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. 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.
V IN 1024
ADC = -------------------------
V REF
... where VIN is the voltage on the selected input pin and VREF the selected voltage reference. 0x000 represents analog
ground, and 0x3FF represents the selected voltage reference minus one LSB. The result is presented in one-sided form,
from 0x3FF to 0x000.
If the measured signal is not bipolar by nature (9 bits + sign as the 10th bit), this method of conversion loses one bit of the
converter dynamic range.
The values described in Table 16-2 are typical values. However, due to process variation the temperature sensor output
voltage varies from one chip to another. To be capable of achieving more accurate results the temperature measurement
can be calibrated in the application software. The software calibration can be done using the formula:
T = k * [(ADCH << 8) | ADCL] + TOS
where ADCH and ADCL are the ADC data registers, k is the fixed slope coefficient and TOS is the temperature sensor
offset. Typically, k is very close to 1.0 and in single-point calibration the coefficient may be omitted. Where higher
accuracy is required the slope coefficient should be evaluated based on measurements at two temperatures.
Bit 7 6 5 4 3 2 1 0
0x09 (0x29) – – MUX5 MUX4 MUX3 MUX2 MUX1 MUX0 ADMUXA
Read/Write R R R/W R/W R/W R/W R/W R/W
Initial Value 0 0 0 0 0 0 0 0
Differential-Ended
00 0000 ADC0 — —
00 0001 ADC1 — —
00 0010 ADC2 — —
00 0011 ADC3 — —
00 0100 ADC4 — —
00 0101 ADC5 — —
00 0110 ADC6 — —
00 0111 ADC7 — —
00 1000 ADC8 — —
00 1001 ADC9 — —
00 1010 ADC10 — —
00 1011 ADC11 — —
(1)
00 1100 Temperature sensor — —
00 1110 0V (AGND) — —
10 1110 — — —
10 1111 — — —
If these bits are changed during a conversion, the change will not go into effect until the conversion is complete (ADIF in
ADCSRA is set).
Bit 7 6 5 4 3 2 1 0
0x08 (0x28) REFS2 REFS1 REFS0 – – – GSEL1 GSEL0 ADMUXB
Read/Write R/W R/W R/W R R R R/W R/W
Initial Value 0 0 0 0 0 0 0 0
If these bits are changed during a conversion, the change will not go in effect until this conversion is complete (ADIF in
ADCSR is set).
0 0 1
0 1 20
1 0 100
1 1 Reserved
16.13.3.1ADLAR = 0
Bit 15 14 13 12 11 10 9 8
0x07 (0x27) – – – – – – ADC9 ADC8 ADCH
0x06 (0x26) 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
16.13.3.2ADLAR = 1
Bit 15 14 13 12 11 10 9 8
0x07 (0x27) ADC9 ADC8 ADC7 ADC6 ADC5 ADC4 ADC3 ADC2 ADCH
0x06 (0x26) 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 ADC conversion is complete, the result is found in these two registers.
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 is required, it is sufficient to read ADCH. Otherwise, ADCL must be read first, then
ADCH.
The ADLAR bit in ADCSRB, and the MUX bits in ADMUXA 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.
Bit 7 6 5 4 3 2 1 0
0x05 (0x25) 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
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
Bit 7 6 5 4 3 2 1 0
0x04 (0x24) – – – – ADLAR ADTS2 ADTS1 ADTS0 ADCSRB
Read/Write R R R R R/W R/W R/W R/W
Initial Value 0 0 0 0 0 0 0 0
0 0 1 Analog Comparator 0
1 0 0 Timer/Counter0 Overflow
1 1 0 Timer/Counter1 Overflow
Bit 7 6 5 4 3 2 1 0
(0x60) ADC7D ADC6D ADC5D ADC4D ADC3D ADC2D ADC1D ADC0D DIDR0
Read/Write R/W R/W R/W R/W R/W R/W R/W R/W
Initial Value 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
(0x61) – – – – ADC9D ADC8D ADC10D ADC11D DIDR1
Read/Write R R R R R/W R/W R/W R/W
Initial Value 0 0 0 0 0 0 0 0
17.1 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
17.2 Overview
The Serial Peripheral Interface (SPI) allows high-speed synchronous data transfer between ATtiny441/841 and
peripheral devices, or between several AVR devices. The SPI module is illustrated in Figure 17-1.
CLKIO
DIVIDER
/2/4/8/16/32/64/128
SS
SPI2X
SPI2X
Note: For SPI pin placement, see Figure 1-1 on page 2, and Table 17-1 on page 153.
SHIFT
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 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 periods: Longer than 2 CPU clock cycles.
High periods: Longer than 2 CPU clock cycles.
Note: See “Alternative Port Functions” on page 60 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.
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
in r16, SPSR
sbrs r16, SPIF
rjmp Wait_Transmit
ret
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);
}
The following code examples show how to initialize the SPI as a Slave and how to perform a simple reception.
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
in r16, SPSR
sbrs r16, SPIF
rjmp SPI_SlaveReceive
; Read received data and return
in r16,SPDR
ret
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 reception complete */
while(!(SPSR & (1<<SPIF)))
;
/* Return Data Register */
return SPDR;
}
Thus, when interrupt-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.
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
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
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 shown in Table 17-2, which is a summary of Table 17-3 on page 157 and Table 17-4 on page 158.
Bit 7 6 5 4 3 2 1 0
(0xB2) SPIE SPE DORD MSTR CPOL CPHA SPR1 SPR0 SPCR
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
0 Rising Falling
1 Falling Rising
0 Sample Setup
1 Setup Sample
Table 17-5. Relationship Between SCK and the I/O Clock Frequency
0 0 0 fclk_I/O/4
0 0 1 fclk_I/O/16
0 1 0 fclk_I/O/64
0 1 1 fclk_I/O/128
1 0 0 fclk_I/O/2
1 0 1 fclk_I/O/8
1 1 0 fclk_I/O/32
1 1 1 fclk_I/O/64
Bit 7 6 5 4 3 2 1 0
(0xB1) SPIF WCOL – – – – – SPI2X SPSR
Read/Write R/W R/W R R R R R R/W
Initial Value 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
(0xB0) MSB LSB SPDR
Read/Write R/W R/W R/W R/W R/W R/W R/W R/W
Initial Value X X X X X X X X Undefined
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 6 5 4 3 2 1 0
(0x65) – – – – – – SPIMAP U0MAP REMAP
Read/Write R R R R R R R/W R/W
Initial Value 0 0 0 0 0 0 0 0
18.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
Three Separate Interrupts on TX Complete, TX Data Register Empty and RX Complete
Multi-processor Communication Mode
Double Speed Asynchronous Communication Mode
Start Frame Detection
18.3 Overview
The Universal Synchronous and Asynchronous serial Receiver and Transmitter (USART) is a highly flexible serial
communication device.
A simplified block diagram of the USART Transmitter is shown in Figure 18-1 on page 161. CPU accessible I/O Registers
and I/O pins are shown in bold.
The Power Reducion USART0 bit, PRUSART0, in “PRR – Power Reduction Register” on page 38 must be disabled by
writing a logical zero to it.
The Power Reducion USART1 bit, PRUSART1, in “PRR – Power Reduction Register” on page 38 must be disabled by
writing a logical zero to it.
Clock Generator
UBRR[H:L]
OSC
Transmitter
TX
UDR (Transmit)
CONTROL
PARITY
GENERATOR
DATA BUS
PIN
TRANSMIT SHIFT REGISTER TxD
CONTROL
Receiver
CLOCK RX
RECOVERY CONTROL
DATA PIN
RECEIVE SHIFT REGISTER RxD
RECOVERY CONTROL
PARITY
UDR (Receive)
CHECKER
For USART pin placement, see Figure 1-1 on page 2 and “Alternative Port Functions” on page 60.
The dashed boxes in the block diagram of Figure 18-1 illustrate the three main parts of the USART, as follows (listed
from the top):
Clock generator
Transmitter
Receiver
The clock generation logic consists of synchronization logic (for external clock input in synchronous slave operation), and
the baud rate generator. The transfer clock pin (XCKn) is only used in synchronous transfer mode.
The transmitter consists of a single write buffer, a serial shift register, a parity generator and control logic for handling
different serial frame formats. The write buffer allows a continuous transfer of data without 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 units, 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 the following errors:
Frame Error
Data Overrun Error
Parity Errors.
Prescaling UBRR+1
/2 /4 /2
Down-Counter 0
1
0
OSC txclk
1
DDR_XCK
Sync Edge
xcki Register Detector 0
XCK UMSEL
xcko 1
Pin
DDR_XCK UCPOL 1
rxclk
0
The UMSELn bit selects between asynchronous and synchronous operation. In asynchronous mode, the speed is
controlled by the U2X bit.
In synchronous mode, the direction bit of the XCKn pin (DDR_XCKn) in the Data Direction Register where the XCKn pin
is located (DDRx) controls whether the clock source is internal (master mode), or external (slave mode). The XCKn pin is
active in synchronous mode, only.
f OSC f OSC
Asynchronous Normal mode (U2Xn = 0) BAUD = ----------------------------------------- UBRRn = ----------------------- – 1
16 UBRRn + 1 16BAUD
f OSC f OSC
Asynchronous Double Speed mode (U2Xn = 1) BAUD = -------------------------------------- UBRRn = -------------------- – 1
8 UBRRn + 1 8BAUD
f OSC f OSC
Synchronous Master mode BAUD = -------------------------------------- UBRRn = -------------------- – 1
2 UBRRn + 1 2BAUD
Note: 1. Baud rate is defined as the transfer rate in bits per second (bps)
Some examples of UBRRn values for selected system clock frequencies are shown in Table 18-6 on page 177.
f OSC
f XCKn -----------
4
Note that fosc depends on the stability of the system clock source. It is therefore recommended to add some margin to
avoid possible data loss due to frequency variations.
UCPOL = 1 XCK
RxD / TxD
Sample
UCPOL = 0 XCK
RxD / TxD
Sample
As shown in Figure 18-3, when UCPOLn is set, the data is changed at falling XCKn edge and sampled at rising XCKn
edge. When UCPOLn is cleared, the data is changed at rising XCKn edge and sampled at falling XCKn edge.
A frame begins with the start bit followed by the least significant data bit. Then follows the other data bits, the last one
being the most significant bit. If enabled, the parity bit is inserted after the data bits, before the stop bits. When a
complete frame has been transmitted it can be directly followed by a new frame, or the communication line can be set to
an idle (high) state.
Figure 18-4 illustrates the possible combinations of the frame formats. Bits inside brackets are optional.
(IDLE) St 0 1 2 3 4 [5] [6] [7] [8] [P] Sp1 [Sp2] (St / IDLE)
The frame format used by the USART is set by the UCSZn, UPMn and USBSn bits, as follows:
The USART Character SiZe bits (UCSZn) select the number of data bits in the frame
The USART Parity Mode bits (UPMn) choose the type of parity bit
The selection between one or two stop bits is done by the USART Stop Bit Select bit (USBSn). The receiver
ignores the second stop bit. An FE (Frame Error) will therefore only be detected in the cases where the first stop
bit is zero.
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.
... where:
PEVEN Parity bit using even parity
PODD Parity bit using odd parity
dn Data bit n of the character
If used, the parity bit is located between the last data bit and the first stop bit of a serial frame.
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
C Code Example(1)
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.
USART_Transmit:
; Wait for empty transmit buffer
sbis UCSRnA,UDREn
rjmp USART_Transmit
; Put data (r16) into buffer, sends the data
out UDRn,r16
ret
C Code Example(1)
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.
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
Notes: 1. These transmit functions are written to be general functions. They can be optimized if the contents of the
UCSRB is static. For example, only the TXB8 bit of UCSRB is used after initialization.
2. See “Code Examples” on page 6.
The ninth bit can be used for indicating an address frame when using multi processor communication mode or for other
protocol handling as for example synchronization.
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
C Code Example(1)
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.
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
C Code Example(1)
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.
USART_Flush:
sbis UCSRnA, RXCn
ret
in r16, UDRn
rjmp USART_Flush
C Code Example(1)
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. In Figure 18-5, samples are indicated with numbers inside boxes and sample number 1 denotes
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 center of the received bit. In the figure, the center samples are emphasized by having the sample number inside
boxes. The majority voting process is done as follows: If two or all three samples have high levels, the received bit is
registered to be a logic one. If two, or all three samples have low levels, the received bit is registered to be a logic zero.
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 18-7 shows the sampling of the stop bit and the earliest possible beginning of the start bit of the next frame.
Figure 18-7. Stop Bit Sampling and Next Start Bit Sampling
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 stop bit is subject to the same majority voting as the other bits in the frame. If the stop bit is registered to have a logic
low 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. In normal speed mode, the first low level sample can be at point marked (A) in Figure 18-7. In double speed mode
the first low level must be delayed to (B). Point (C) marks the full length of a stop bit.
The early start bit detection influences the operational range of the receiver.
D + 1 S D + 2 S
R slow = ------------------------------------------ R fast = -----------------------------------
S – 1 + D S + SF D + 1 S + S M
... where:
D Sum of character size and parity size (D = 5 to 10 bit)
S Samples per bit, 16 for normal speed mode, or 8 for double speed mode.
SF First sample number used for majority voting, 8 (normal speed), or 4 (double)
SM Middle sample number for majority voting, 9 (normal speed), or 5 (double speed)
Rslow The ratio of the slowest incoming data rate that can be accepted with respect to
the receiver baud rate
Rfast The ratio of the fastest incoming data rate that can be accepted with respect to
the receiver baud rate
Table 18-2 and Table 18-3 list the maximum receiver baud rate error that can be tolerated. Note that normal speed mode
has higher toleration of baud rate variations.
Table 18-2. Recommended Maximum Receiver Baud Rate Error in Normal Speed Mode
Table 18-3. Recommended Maximum Receiver Baud Rate Error in Double Speed Mode
The recommendations of the maximum receiver baud rate error are made under the assumption that the receiver and
transmitter divide the maximum total error equally.
There are two possible sources for the receivers baud rate error:
The system clock of the receiver will always have some minor instability over the supply voltage range and the
temperature range
The second source for error is more controllable. The baud rate generator can not always do an exact division of
the system frequency to get the baud rate wanted. In this case an UBRR value that gives an acceptable low error
should be used, if possible
The maximum baud rate in asynchronous mode depends on the sleep mode the device is woken up from, as follows:
Idle sleep mode: the same as in active mode.
Other sleep modes: see Table 18-4 and Table 18-5.
Frame Size
Baudrate 5 6 7 8 9 10
Frame Size
Baudrate 5 6 7 8 9 10
It is possible but impractical to use any of the 5- to 8-bit character frame formats, 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 use the same character size setting. If 5- to 8-bit character frames are used, the transmitter must be set to use
two stop bits, since the first stop bit is used for indicating the frame type.
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.
Table 18-6. Examples of UBRR Settings for Commonly Used Oscillator Frequencies
230.4k – – – – – – 0 0.0% – – – –
250k – – – – – – – – – – 0 0.0%
(1)
Max 62.5 kbps 125 kbps 115.2 kbps 230.4 kbps 125 kbps 250 kbps
Table 18-7. Examples of UBRR Settings for Commonly Used Oscillator Frequencies
2400 95 0.0% 191 0.0% 103 0.2% 207 0.2% 191 0.0% 383 0.0%
1M – – – – – – – – – – 0 -7.8%
Max (1) 230.4 kbps 460.8 kbps 250 kbps 0.5 Mbps 460.8 kbps 921.6 kbps
2400 207 0.2% 416 -0.1% 287 0.0% 575 0.0% 383 0.0% 767 0.0%
4800 103 0.2% 207 0.2% 143 0.0% 287 0.0% 191 0.0% 383 0.0%
9600 51 0.2% 103 0.2% 71 0.0% 143 0.0% 95 0.0% 191 0.0%
Max (1) 0.5 Mbps 1 Mbps 691.2 kbps 1.3824 Mbps 921.6 kbps 1.8432 Mbps
Table 18-9. Examples of UBRR Settings for Commonly Used Oscillator Frequencies
2400 416 -0.1% 832 0.0% 479 0.0% 959 0.0% 520 0.0% 1041 0.0%
4800 207 0.2% 416 -0.1% 239 0.0% 479 0.0% 259 0.2% 520 0.0%
9600 103 0.2% 207 0.2% 119 0.0% 239 0.0% 129 0.2% 259 0.2%
14.4k 68 0.6% 138 -0.1% 79 0.0% 159 0.0% 86 -0.2% 173 -0.2%
19.2k 51 0.2% 103 0.2% 59 0.0% 119 0.0% 64 0.2% 129 0.2%
1M 0 0.0% 1 0.0% – – – – – – – –
(1)
Max. 1 Mbps 2 Mbps 1.152 Mbps 2.304 Mbps 1.25 Mbps 2.5 Mbps
Bit 7 6 5 4 3 2 1 0
(0x80) RXB[7:0] UDR0 (Read)
(0x80) TXB[7:0] UDR0 (Write)
Read/Write R/W R/W R/W R/W R/W R/W R/W R/W
Initial Value 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
(0x90) RXB[7:0] UDR1 (Read)
(0x90) TXB[7:0] UDR1 (Write)
Read/Write R/W R/W R/W R/W R/W R/W R/W R/W
Initial Value 0 0 0 0 0 0 0 0
The USART transmit data buffer and USART receive data buffer registers share the same I/O address, referred to as
USART Data Register, or UDRn. Data written to UDRn goes to the Transmit Data Buffer register (TXB). Reading UDR
returns 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 UDREn flag is set. Data written to UDRn when the UDREn flag is not set
will be ignored. When the transmitter is enabled and data is written to the transmit buffer, the transmitter will load the data
into the transmit shift register when it is empty. The data is then serially transmitted on the TxDn 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, Read-Modify-Write instructions (SBI and CBI) should not be used to access
this location. Care should also be taken when using bit test instructions (SBIC and SBIS), since these also change the
state of the FIFO.
Bit 7 6 5 4 3 2 1 0
(0x86) RXC0 TXC0n UDRE0n FE0 DOR0 UPE0 U2X0 MPCM0 UCSR0A
Read/Write R R/W R R R R R/W R/W
Initial Value 0 0 1 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
(0x96) RXC1 TXC1 UDRE1 FE1 DOR1 UPE1 U2X1 MPCM1 UCSR1A
Read/Write R R/W R R R R R/W R/W
Initial Value 0 0 1 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
(0x85) RXCIE0 TXCIE0 UDRIE0 RXEN0 TXEN0 UCSZ02 RXB80 TXB80 UCSR0B
Read/Write R/W R/W R/W R/W R/W R/W R R/W
Initial Value 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
(0x95) RXCIE1 TXCIE1 UDRIE1 RXEN1 TXEN1 UCSZ12 RXB81 TXB81 UCSR1B
Read/Write R/W R/W R/W R/W R/W R/W R R/W
Initial Value 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
(0x84) UMSEL01 UMSEL00 UPM01 UPM00 USBS0 UCSZ01 UCSZ00 UCPOL0 UCSR0C
Read/Write R R/W R/W R/W R/W R/W R/W R/W
Initial Value 0 0 0 0 0 1 1 0
Bit 7 6 5 4 3 2 1 0
(0x94) UMSEL11 UMSEL10 UPM11 UPM10 USBS1 UCSZ11 UCSZ10 UCPOL1 UCSR1C
Read/Write R R/W R/W R/W R/W R/W R/W R/W
Initial Value 0 0 0 0 0 1 1 0
0 0 Asynchronous USART
0 1 Synchronous USART
1 0 Reserved
Note: 1. For full description of the Master SPI Mode (MSPIM) Operation, see “USART in SPI Mode” on page 187.
0 0 Disabled
0 1 Reserved
0 1-bit
1 2-bit
0 0 0 5-bit
0 0 1 6-bit
0 1 0 7-bit
0 1 1 8-bit
1 0 0 Reserved
1 0 1 Reserved
1 1 0 Reserved
1 1 1 9-bit
Bit 7 6 5 4 3 2 1 0
(0x83) RXSIE0 RXS0 SFDE0 – – – – – UCSR0D
Read/Write R/W R/W R/W R R R R R
Initial Value 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
(0x93) RXSIE1 RXS1 SFDE1 – – – – – UCSR1D
Read/Write R/W R/W R/W R R R R R
Initial Value 0 0 0 0 0 0 0 0
1 0 0 Reserved
1 0 1 Start frame detector enabled. RXCn flag wakes up MCU from all sleep modes
1 1 0 Start frame detector enabled. RXSn flag wakes up MCU from all sleep modes
1 1 1 Start frame detector enabled. RXCn and RXSn wake up MCU from all sleep modes
Initial Value 0 0 0 0 0 0 0 0
Read/Write R R R R R/W R/W R/W R/W
Bit 15 14 13 12 11 10 9 8
(0x82) – – – – UBRR0[11:8] UBRR0H
(0x81) UBRR0[7:0] UBRR0L
Bit 7 6 5 4 3 2 1 0
Read/Write R/W R/W R/W R/W R/W R/W R/W R/W
Initial Value 0 0 0 0 0 0 0 0
Initial Value 0 0 0 0 0 0 0 0
Read/Write R R R R R/W R/W R/W R/W
Bit 15 14 13 12 11 10 9 8
(0x92) – – – – UBRR1[11:8] UBRR1H
(0x91) UBRR1[7:0] UBRR1L
Bit 7 6 5 4 3 2 1 0
Read/Write R/W R/W R/W R/W R/W R/W R/W R/W
Initial Value 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
(0x65) – – – – – – SPIMAP U0MAP REMAP
Read/Write R R R R R R R/W R/W
Initial Value 0 0 0 0 0 0 0 0
19.1 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 (fXCKmax = fCK/2)
Flexible Interrupt Generation
19.2 Overview
The Universal Synchronous and Asynchronous serial Receiver and Transmitter (USART) can be set to a master SPI
compliant mode of operation.
Setting both UMSELn[1:0] bits 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 registers
changes when using MSPIM.
f OSC f OSC
Synchronous Master mode BAUD = -------------------------------------- UBRRn = -------------------- – 1
2 UBRRn + 1 2BAUD
Note: 1. The baud rate is defined as the transfer rate in bits per second (bps)
UCPOL=0 UCPOL=1
UCPHA=1
XCK XCK
XCK XCK
A frame starts with the least or most significant data bit. Then follows the next data bits, up to a total of eight, 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 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.
Note: To ensure immediate initialization of the XCKn output the baud-rate register (UBRRn) must be zero 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 registers R17:R16.
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
Note: To keep the input buffer in sync with the number of data bytes transmitted, UDRn 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 flag (UDREn) and the Receive Complete flag (RXCn). 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 and the data
received will be available in the same register (R16) after the function returns.
USART_MSPIM_Transfer:
; Wait for empty transmit buffer
sbis UCSRnA, UDREn
rjmp USART_MSPIM_Transfer
; Put data (r16) into 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)
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 Collision) 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 19-3.
Bit 7 6 5 4 3 2 1 0
(0x86) RXC0 TXC0 UDRE0 – – – – – UCSR0A
Read/Write R/W R/W R/W R R R R R
Initial Value 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
(0x96) RXC1 TXC1 UDRE1 – – – – – UCSR1A
Read/Write R/W R/W R/W R R R R R
Initial Value 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
(0x85) RXCIE0 TXCIE0 UDRIE0 RXEN0 TXEN0 – – – UCSR0B
Read/Write R/W R/W R/W R/W R/W R R R
Initial Value 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
(0x95) RXCIE1 TXCIE1 UDRIE1 RXEN1 TXEN1 – – – UCSR1B
Read/Write R/W R/W R/W R/W R/W R R R
Initial Value 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
(0x84) UMSEL01 UMSEL00 – – – UDORD0 UCPHA0 UCPOL0 UCSR0C
Read/Write R/W R/W R R R R/W R/W R/W
Initial Value 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
(0x94) UMSEL11 UMSEL10 – – – UDORD1 UCPHA1 UCPOL1 UCSR1C
Read/Write R/W R/W R R R R/W R/W R/W
Initial Value 0 0 0 0 0 0 0 0
0 0 Asynchronous USART
0 1 Synchronous USART
1 0 (Reserved)
See “UCSRnC – USART Control and Status Register C” on page 183 for full description of the normal USART operation.
Bits UDORDn, UCPHAn, and UCPOLn may be set in the same write operation where the MSPIM is enabled.
20.1 Features
I2C compatible
SMBus compatible (with reservations)
100kHz and 400kHz support at low system clock frequencies
Slew-Rate Limited Output Drivers
Input Filter provides noise suppression
7-bit, and General Call Address Recognition in Hardware
Address mask register for address masking or dual address match
10-bit addressing supported
Optional Software Address Recognition Provides Unlimited Number of Slave Addresses
Operates in all sleep modes, including Power Down
Slave Arbitration allows support for SMBus Address Resolve Protocol (ARP)
20.2 Overview
The Two Wire Interface (TWI) is a bi-directional, bus communication interface, which uses only two wires. The TWI is I2C
compatible and, with reservations, SMBus compatible (see “Compatibility with SMBus” on page 203).
A device connected to the bus must act as a master or slave.The master initiates a data transaction by addressing a
slave on the bus, and telling whether it wants to transmit or receive data. One bus can have several masters, and an
arbitration process handles priority if two or more masters try to transmit at the same time.
The TWI module in ATtiny441/841 implements slave functionality, only. Lost arbitration, errors, collisions and clock holds
on the bus are detected in hardware and indicated in separate status flags.
Both 7-bit and general address call recognition is implemented in hardware. 10-bit addressing is also supported. A
dedicated address mask register can act as a second address match register or as a mask register for the slave address
to match on a range of addresses. The slave logic continues to operate in all sleep modes, including Power down. This
enables the slave to wake up from sleep on TWI address match. It is possible to disable the address matching and let
this be handled in software instead. This allows the slave to detect and respond to several addresses. Smart Mode can
be enabled to auto trigger operations and reduce software complexity.
The TWI module includes bus state logic that collects information to detect START and STOP conditions, bus collision
and bus errors. The bus state logic continues to operate in all sleep modes including Power down.
A unique address is assigned to all slave devices connected to the bus, and the master will use this to address a slave
and initiate a data transaction. 7-bit or 10-bit addressing can be used.
Several masters can be connected to the same bus, and this is called a multi-master environment. An arbitration
mechanism is provided for resolving bus ownership between masters since only one master device may own the bus at
any given time.
A device can contain both master and slave logic, and can emulate multiple slave devices by responding to more than
one address.
A master indicates the start of transaction by issuing a START condition (S) on the bus. An address packet with a slave
address (ADDRESS) and an indication whether the master wishes to read or write data (R/W), is then sent. After all data
packets (DATA) are transferred, the master issues a STOP condition (P) on the bus to end the transaction. The receiver
must acknowledge (A) or not-acknowledge (A) each byte received.
Figure 20-2 shows a TWI transaction.
Multiple START conditions can be issued during a single transaction. A START condition not directly following a STOP
condition, are named a Repeated START condition (Sr).
Combining bit transfers results in the formation of address and data packets. These packets consist of 8 data bits (one
byte) with the most significant bit transferred first, plus a single bit not-acknowledge (NACK) or acknowledge (ACK)
response. The addressed device signals ACK by pulling the SCL line low, and NACK by leaving the line SCL high during
the ninth clock cycle.
20.3.6 Transaction
A transaction is the complete transfer from a START to a STOP condition, including any Repeated START conditions in
between. The TWI standard defines three fundamental transaction modes: Master Write, Master Read, and combined
transaction.
Figure 20-5 illustrates the Master Write transaction. The master initiates the transaction by issuing a START condition (S)
followed by an address packet with direction bit set to zero (ADDRESS+W).
Given that the slave acknowledges the address, the master can start transmitting data (DATA) and the slave will ACK or
NACK (A/A) each byte. If no data packets are to be transmitted, the master terminates the transaction by issuing a STOP
condition (P) directly after the address packet. There are no limitations to the number of data packets that can be
transferred. If the slave signal a NACK to the data, the master must assume that the slave cannot receive any more data
and terminate the transaction.
Figure 20-6 illustrates the Master Read transaction. The master initiates the transaction by issuing a START condition
followed by an address packet with direction bit set to one (ADRESS+R). The addressed slave must acknowledge the
address for the master to be allowed to continue the transaction.
If the device is in a sleep mode and a START condition is detected the clock is stretched during the wake-up period for
the device.
A slave device can slow down the bus frequency by stretching the clock periodically on a bit level. This allows the slave
to run at a lower system clock frequency. However, the overall performance of the bus will be reduced accordingly. Both
the master and slave device can randomly stretch the clock on a byte level basis before and after the ACK/NACK bit.
This provides time to process incoming or prepare outgoing data, or performing other time critical tasks.
In the case where the slave is stretching the clock the master will be forced into a wait-state until the slave is ready and
vice versa.
20.3.8 Arbitration
A master can only start a bus transaction if it has detected that the bus is idle. As the TWI bus is a multi master bus, it is
possible that two devices initiate a transaction at the same time. This results in multiple masters owning the bus
simultaneously. This is solved using an arbitration scheme where the master loses control of the bus if it is not able to
transmit a high level on the SDA line. The masters who lose arbitration must then wait until the bus becomes idle (i.e.
wait for a STOP condition) before attempting to reacquire bus ownership. Slave devices are not involved in the arbitration
procedure.
Figure 20-9 shows an example where two TWI masters are contending for bus ownership. Both devices are able to issue
a START condition, but DEVICE1 loses arbitration when attempting to transmit a high level (bit 5) while DEVICE2 is
transmitting a low level.
Arbitration between a repeated START condition and a data bit, a STOP condition and a data bit, or a repeated START
condition and STOP condition are not allowed and will require special handling by software.
20.3.9 Synchronization
A clock synchronization algorithm is necessary for solving situations where more than one master is trying to control the
SCL line at the same time. The algorithm is based on the same principles used for clock stretching previously described.
Figure 20-10 shows an example where two masters are competing for the control over the bus clock. The SCL line is the
wired-AND result of the two masters clock outputs.
A high to low transition on the SCL line will force the line low for all masters on the bus and they start timing their low
clock period. The timing length of the low clock period can vary between the masters. When a master (DEVICE1 in this
The number of interrupts generated is kept at a minimum by automatic handling of most conditions. Quick Command can
be enabled to auto trigger operations and reduce software complexity.
Promiscuous Mode can be enabled to allow the slave to respond to all received addresses.
Bit 7 6 5 4 3 2 1 0
(0xA5) TWSHE – TWDIE TWASIE TWEN TWSIE TWPME TWSME TWSCRA
Read/Write R/W R R/W R/W R/W R/W R/W R/W
Initial Value 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
(0xA4) – – – – TWHNM TWAA TWCMD1 TWCMD0 TWSCRB
Read/Write R R R R R/W R/W W W
Initial Value 0 0 0 0 0 0 0 0
00 X No action
01 X Reserved
10 0 Execute Acknowledge Action, then wait for any START (S/Sr) condition
1 No action
Writing the TWCMD bits will automatically release the SCL line and clear the TWCH and slave interrupt flags.
TWAA and TWCMDn bits can be written at the same time. Acknowledge Action will then be executed before the
command is triggered.
Bit 7 6 5 4 3 2 1 0
(0xA3) TWDIF TWASIF TWCH TWRA TWC TWBE TWDIR TWAS TWSSRA
Read/Write R/W R/W R R R/W R/W R/W R/W
Initial Value 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
(0xA2) TWSA[7:0] TWSA
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 slave address register contains the TWI slave address used by the slave address match logic to determine if a
master has addressed the slave. When using 7-bit or 10-bit address recognition mode, the high seven bits of the address
register (TWSA[7:1]) represent the slave address. The least significant bit (TWSA0) is used for general call address
recognition. Setting TWSA0 enables general call address recognition logic.
When using 10-bit addressing the address match logic only support hardware address recognition of the first byte of a
10-bit address. If TWSA[7:1] is set to “0b11110nn”, 'nn' will represent bits 9 and 8 of the slave address. The next byte
received is then bits 7 to 0 in the 10-bit address, but this must be handled by software.
When the address match logic detects that a valid address byte has been received, the TWASIF is set and the TWDIR
flag is updated.
If TWPME in TWSCRA is set, the address match logic responds to all addresses transmitted on the TWI bus. TWSA is
not used in this mode.
Bit 7 6 5 4 3 2 1 0
(0xA1) TWSAM[7:1] TWAE TWSAM
Read/Write R/W R/W R/W R/W R/W R/W R/W R/W
Initial Value 0 0 0 0 0 0 0 0
Bit 7 6 5 4 3 2 1 0
(0xA0) TWSD[7:0] TWSD
Read/Write R/W R/W R/W R/W R/W R/W R/W R/W
Initial Value 0 0 0 0 0 0 0 0
The data register is used when transmitting and received data. During transfer, data is shifted from/to the TWSD register
and to/from the bus. Therefore, the data register cannot be accessed during byte transfers. This is protected in hardware.
The data register can only be accessed when the SCL line is held low by the slave, i.e. when TWCH is set.
When a master reads data from a slave, the data to be sent must be written to the TWSD register. The byte transfer is
started when the master starts to clock the data byte from the slave. It is followed by the slave receiving the acknowledge
bit from the master. The TWDIF and the TWCH bits are then set.
When a master writes data to a slave, the TWDIF and the TWCH flags are set when one byte has been received in the
data register. If Smart Mode is enabled, reading the data register will trigger the bus operation, as set by the TWAA bit in
TWSCRB.
Accessing TWSD will clear the slave interrupt flags and the TWCH bit.
21.1 Features
Complete Program Flow Control
Emulates All On-chip Functions, Both Digital and Analog , except RESET Pin
Real-time Operation
Symbolic Debugging Support (Both at C and Assembler Source Level, or for Other HLLs)
Unlimited Number of Program Break Points (Using Software Break Points)
Non-intrusive Operation
Electrical Characteristics Identical to Real Device
Automatic Configuration System
High-Speed Operation
Programming of Non-volatile Memories
21.2 Overview
The debugWIRE On-chip debug system uses a One-wire, bi-directional interface to control the program flow, execute
AVR instructions in the CPU and to program the different non-volatile memories.
1.8 - 5.5V
VCC
dW dW(RESET)
GND
Bit 7 6 5 4 3 2 1 0
0x27 (0x47) DWDR[7:0] DWDR
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 DWDR Register provides a communication channel from the running program in the MCU to the debugger. This
register is only accessible by the debugWIRE and can therefore not be used as a general purpose register in the normal
operations.
22.1 Features
Self-Programming Enables MCU to Erase, Write and Reprogram Application Memory
Efficient Read-Modify-Write Support
Lock Bits Allow Application Memory to Be Securely Closed for Further Access
22.2 Overview
The device provides a self-programming mechanism for downloading and uploading program code by the MCU itself.
Self-Programming can use any available data interface and associated protocol to read code and write (program) that
code into program memory.
The 4-Page Erase command erases four program memory pages at the same time. If only part of this section needs to
be changed, the rest must be stored before the erase, and then be re-written.
The temporary page buffer can be accessed in a random sequence.
The SPM instruction is disabled by default but it can be enabled by programming the SELFPRGEN fuse (to “0”).
Bit 15 14 13 12 11 10 9 8
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
Since the Flash is organized in pages (see Table 24-1 on page 225), 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 22-1, below.
PCMSB PAGEMSB
PROGRAM
PCPAGE PCWORD
COUNTER
01
PAGE
02
INSTRUCTION WORD
PAGEEND
The 4-Page Erase command addresses several program memory pages simultaneously, as shown in Figure 22-2,
below.
PCMSB PAGEMSB
PROGRAM
PCPAGE PCWORD
COUNTER
PAGE ADDRESS
WITHIN THE FLASH
PROGRAM MEMORY
PAGE
Variable Description
Program Counter page address. Selects program memory page for Page Load & Page Write
PCPAGE commands. Selects a block of program pages for the 4-Page Erase operation.
See Table 24-1 on page 225
The bit in the Z register that is mapped to PCMSB. Because Z[0] is not used, ZPCMSB = PCMSB + 1. Z
ZPCMSB
register bits above ZPCMSB are ignored
Program Counter word address. Selects the word within a page. This is used for filling the temporary
PCWORD buffer and must be zero during page write operations.
See Table 24-1 on page 225
PAGEMSB The most significant bit used to address the word within one page
The bit in the Z register that is mapped to PAGEMSB. Because Z[0] is not used, ZPAGEMSB =
ZPAGEMSB
PAGEMSB + 1
Note that 4-Page Erase and Page Write operations address memory independently. Therefore the software must make
sure the Page Write command addresses a page previously erased by the 4-Page Erase command.
Although the least significant bit of the Z-register (Z0) should be zero for SPM, it should be noted that the LPM instruction
addresses the Flash byte-by-byte and uses Z0 as a byte select bit.
Once a programming operation is initiated, the address is latched and the Z-pointer can be used for other operations.
The data in R1 and R0 is ignored. The page address must be written to PCPAGE in the Z-register. PCPAGE[1:0] are
ignored, as are other bits in the Z-pointer.
If an interrupt occurs during the timed sequence above the four cycle access cannot be guaranteed. In order to ensure
atomic operation interrupts should be disabled before writing to SPMCSR.
The CPU is halted during the 4-Page Erase operation.
The content of PCWORD in the Z-register is used to address the data in the temporary buffer. The temporary buffer will
auto-erase after a Page Write operation, or by writing the CTPB bit in SPMCSR. It is also erased after a system reset.
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.
The CPU is halted during the Page Write operation.
SPM: Flash 4-Page Erase, Flash Page Write, and lock bit write 3.7 ms 4.5 ms
Note: 1. Min and max programming times are per individual operation.
Bit 7 6 5 4 3 2 1 0
0x37 (0x57) – – RSIG CTPB RFLB PGWRT PGERS SPMEN SPMCSR
Read/Write R R R/W R/W R/W R/W R/W R/W
Initial Value 0 0 0 0 0 0 0 0
– 7 – 1 (unprogrammed)
– 6 – 1 (unprogrammed)
– 5 – 1 (unprogrammed)
– 4 – 1 (unprogrammed)
– 3 – 1 (unprogrammed)
– 2 – 1 (unprogrammed)
LB2 1 1 (unprogrammed)
Lock bit Below
LB1 0 1 (unprogrammed)
Lock bits can be left unprogrammed (“1”) or can be programmed (“0”) to obtain the additional features listed in Table 23-
2.
0 1 Reserved
Further reading and programming of Flash and EEPROM is disabled in high-voltage and
0 0 serial programming modes. Fuse bits are locked in both serial and high-voltage
programming modes (2)
When programming the lock bits, the mode of protection can be increased, only. Writing the same, or lower, mode of
protection automatically results in maximum protection.
Lock bits can be erased to “1” with the Chip Erase command, only.
The ATtiny441/841 has no separate boot loader section. The SPM instruction is enabled for the whole Flash if the
SELFPRGEN fuse is programmed (“0”), otherwise it is disabled.
7 ULPOSCSEL2 1 (unprogrammed)
Frequency selection for Internal Ultra Low
6 ULPOSCSEL1 Page 28 1 (unprogrammed)
Power (ULP) Oscillator
5 ULPOSCSEL0 1 (unprogrammed)
2 BODLEVEL2 1 (unprogrammed)
0 BODLEVEL0 1 (unprogrammed)
5 – – – 1 (unprogrammed)
Note: 1. Unprogramming this fuse at low voltages may result in over-clocking. See Section 25.1.3 on page 238 for
device speed versus supply voltage.
2. This setting results in maximum start-up time for the default clock source.
3. This setting selects Calibrated Internal 8MHz Oscillator.
Fuse bits are locked when Lock Bit 1 (LB1) is programmed. Hence, fuse bits must be programmed before lock bits.
Fuse bits are not affected by a Chip Erase.
0x00 Reserved
0x00
0x01 Calibration data for internal 8MHz oscillator (OSCCAL0) (1)
– Reserved
0x01 - 0x02
– Reserved
0x06 Reserved
0x03
0x07 Calibration data for internal 32kHz oscillator (OSCCAL1)(1)
– Reserved
0x04 - 0x06
– Reserved
0x14 Reserved
0x0A
0x15 Wafer number(5)
0x16 Y-coordinate(5)
0x0B
0x17 X-coordinate(5)
– Reserved
0x0C-0x15
– Reserved
– Reserved
0x17-0x3F
– Reserved
Bit 7 6 5 4 3 2 1 0
Rd – – BLB12 BLB11 BLB02 BLB01 LB2 LB1
Bit 7 6 5 4 3 2 1 0
Rd FLB7 FLB6 FLB5 FLB4 FLB3 FLB2 FLB1 FLB0
For a detailed description and mapping of the Fuse Low Byte, see Table 23-5 on page 220.
To read the Fuse High Byte (FHB), replace the address in the Z-pointer with 0x0003 and repeat the procedure above. If
successful, the contents of the destination register are as follows.
Bit 7 6 5 4 3 2 1 0
Rd FHB7 FHB6 FHB5 FHB4 FHB3 FHB2 FHB1 FHB0
For a detailed description and mapping of the Fuse High Byte, see Table 23-4 on page 219.
To read the Fuse Extended Byte (FEB), replace the address in the Z-pointer with 0x0002 and repeat the previous
procedure. If successful, the contents of the destination register are as follows.
Bit 7 6 5 4 3 2 1 0
Rd FEB7 FEB6 FEB5 FEB4 FEB3 FEB2 FEB1 FEB0
For a detailed description and mapping of the Fuse Extended Byte, see Table 23-3 on page 219.
If successful, the contents of the destination register are as described in section “Device Signature Imprint Table” on
page 220.
DSIT_read:
; Uses Z-pointer as table index
ldi ZH, 0
ldi ZL, 1
; Preload SPMCSR bits into R16, then write to SPMCSR
ldi r16, (1<<RSIG)|(1<<SPMEN)
out SPMCSR, r16
; Issue LPM. Table data will be returned into r17
lpm r17, Z
ret
Device Flash Size Page Size PCWORD (1) Pages PCPAGE (1) PCMSB (1)
2K words
ATtiny441 8 words PC[2:0] 256 PC[10:3] 10
(4K bytes)
4K words
ATtiny841 8 words PC[2:0] 512 PC[11:3] 11
(8K bytes)
Device EEPROM Size Page Size PCWORD (1) Pages PCPAGE (1) EEAMSB
Table 24-3. Typical Wait Delays Before Next Flash or EEPROM Location Can Be Written
tWD_FLASH 4.5 ms
tWD_EEPROM 3.6 ms
tWD_ERASE 9.0 ms
+1.8 - 5.5V
MOSI VCC
MISO
SCK
CLKI
RESET
GND
Note: If the device is clocked by the internal oscillator there is no need to connect a clock source to the CLKI pin.
When programming the EEPROM, an auto-erase cycle is built into the self-timed programming operation and there is no
need to first execute the Chip Erase instruction. This applies for serial programming mode, only.
The Chip Erase operation turns the content of every memory location in Flash 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:
Instruction Format
Load Instructions
Load Extended Address byte (1) $4D $00 Extended adr $00
Load Program Memory Page, High byte $48 $00 adr LSB high data byte in
Load Program Memory Page, Low byte $40 $00 adr LSB low data byte in
Read Instructions
Read Program Memory, Low byte $20 adr MSB adr LSB low data byte out
Read EEPROM Memory $A0 0000 00aa (2) aaaa aaaa (2) data byte out
Read Signature Byte $30 $00 0000 000aa (2) data byte out
Read Fuse High bits $58 $08 $00 data byte out
Read Fuse Extended Bits $50 $08 $00 data byte out
Write Program Memory Page $4C adr MSB (4) adr LSB (4) $00
Write EEPROM Memory $C0 0000 00aa (2) aaaa aaaa (2) data byte in
Write Fuse High bits (5) $AC $A8 $00 data byte in
(5)
Write Fuse Extended Bits $AC $A4 $00 data byte in
Page Buffer
Page Offset
Page 0
Page 1
Page 2
Page Number
Page N-1
Program Memory/
EEPROM Memory
The minimum period for the Serial Clock Input (SCI) during High-voltage Serial Programming is 220 ns.
PA4 Prog_enable[0] 0
PA5 Prog_enable[1] 0
PA6 Prog_enable[2] 0
If the rise time of the VCC is unable to fulfill the requirements listed above, the following alternative algorithm can be used:
1. Set Prog_enable pins listed in Table 24-7 on page 230 to “000”, RESET pin and VCC to 0V.
2. Apply 4.5 - 5.5V between VCC and GND.
3. Monitor VCC, and as soon as VCC reaches 0.9 - 1.1V, apply 11.5 - 12.5V to RESET.
4. Keep the Prog_enable pins unchanged for at least 10 µs after the high-voltage has been applied to ensure the
Prog_enable Signature has been latched.
5. Release the Prog_enable[2] pin to avoid drive contention with other pin functions.
6. Wait until VCC actually reaches 4.5 - 5.5V before giving any serial instructions on SDI/SII.
7. Exit Programming mode by power the device down or by bringing RESET pin to 0V.
Note: 1. The EEPROM memory is preserved during Chip Erase if the EESAVE Fuse is programmed.
When writing or reading serial data to the ATtiny441/841, data is clocked on the rising edge of the serial clock, see Figure
25-6 on page 244, Figure 24-3 on page 229 and Table 25-12 on page 245 for details.
01
02
PAGEEND
SCI 0 1 2 3 4 5 6 7 8 9 10
PB0
Instruction Format
SDI 0_ bbbb_bbbb _00 0_eeee_eeee_00 0_0000_0000_00 0_0000_0000_00 Repeat after Instr. 1 - 7until the
entire page buffer is filled or
SII 0_0000_1100_00 0_0010_1100_00 0_0110_1101_00 0_0110_1100_00
until all data within the page is
Load Flash
SDO x_xxxx_xxxx_xx x_xxxx_xxxx_xx x_xxxx_xxxx_xx x_xxxx_xxxx_xx filled.(2)
Page Buffer
SDI 0_dddd_dddd_00 0_0000_0000_00 0_0000_0000_00
SII 0_0011_1100_00 0_0111_1101_00 0_0111_1100_00 Instr 5-7.
SDO x_xxxx_xxxx_xx x_xxxx_xxxx_xx x_xxxx_xxxx_xx
0_eeee_eeee_00
SDI 0_bbbb_bbbb_00 0_aaaa_aaaa_00 0_0000_0000_00 Repeat Instr. 1 - 5 until the
0_0010_1100_00 entire page buffer is filled or
SII 0_0000_1100_00 0_0001_1100_00 0_0110_1101_00
x_xxxx_xxxx_xx until all data within the page is
Load SDO x_xxxx_xxxx_xx x_xxxx_xxxx_xx x_xxxx_xxxx_xx filled.(3)
EEPROM
Page Buffer
SDI 0_0000_0000_00
SII 0_0110_1100_00
SDO x_xxxx_xxxx_xx
SDI 0_bbbb_bbbb_00 0_aaaa_aaaa_00 0_eeee_eeee_00 0_0000_0000_00 Repeat Instr. 1 - 6 for each new
SII 0_0000_1100_00 0_0001_1100_00 0_0010_1100_00 0_0110_1101_00 address. Wait after Instr. 6 until
SDO x_xxxx_xxxx_xx x_xxxx_xxxx_xx x_xxxx_xxxx_xx x_xxxx_xxxx_xx SDO goes high.(4)
Write
EEPROM Byte
SDI 0_0000_0000_00 0_0000_0000_00
SII 0_0110_0100_00 0_0110_1100_00 Instr. 5-6
SDO x_xxxx_xxxx_xx x_xxxx_xxxx_xx
SDI 0_0100_0000_00 0_A987_6543_00 0_0000_0000_00 0_0000_0000_00 Wait after Instr. 4 until SDO
Write Fuse
SII 0_0100_1100_00 0_0010_1100_00 0_0110_0100_00 0_0110_1100_00 goes high. Write A - 3 = “0” to
Low Bits
SDO x_xxxx_xxxx_xx x_xxxx_xxxx_xx x_xxxx_xxxx_xx x_xxxx_xxxx_xx program the Fuse bit.
SDI 0_0100_0000_00 0_IHGF_EDCB_00 0_0000_0000_00 0_0000_0000_00 Wait after Instr. 4 until SDO
Write Fuse
SII 0_0100_1100_00 0_0010_1100_00 0_0111_0100_00 0_0111_1100_00 goes high. Write F - B = “0” to
High Bits
SDO x_xxxx_xxxx_xx x_xxxx_xxxx_xx x_xxxx_xxxx_xx x_xxxx_xxxx_xx program the Fuse bit.
SDI 0_0100_0000_00 0_0000_000J_00 0_0000_0000_00 0_0000_0000_00 Wait after Instr. 4 until SDO
Write Fuse
SII 0_0100_1100_00 0_0010_1100_00 0_0110_0110_00 0_0110_1110_00 goes high. Write J = “0” to
Extended Bits
SDO x_xxxx_xxxx_xx x_xxxx_xxxx_xx x_xxxx_xxxx_xx x_xxxx_xxxx_xx program the Fuse bit.
SDI 0_0010_0000_00 0_0000_0021_00 0_0000_0000_00 0_0000_0000_00 Wait after Instr. 4 until SDO
Write Lock Bits SII 0_0100_1100_00 0_0010_1100_00 0_0110_0100_00 0_0110_1100_00 goes high. Write 2 - 1 = “0” to
SDO x_xxxx_xxxx_xx x_xxxx_xxxx_xx x_xxxx_xxxx_xx x_xxxx_xxxx_xx program the Lock Bit.
Notes: 1. a = address high bits, b = address low bits, d = data in high bits, e = data in low bits, p = data out high bits, q = data
out low bits, x = don’t care, 1 = Lock Bit1, 2 = Lock Bit2, 3 = CKSEL0 Fuse, 4 = CKSEL1 Fuse, 5 = CKSEL2 Fuse, 6
= CKSEL3 Fuse, 7 = SUT0 Fuse, 8 = SUT1 Fuse, 9 = CKOUT Fuse, A = CKDIV8 Fuse, B = BODLEVEL0 Fuse, C =
BODLEVEL1 Fuse, D= BODLEVEL2 Fuse, E = EESAVE Fuse, F = WDTON Fuse, G = SPIEN Fuse, H = DWEN
Fuse, I = RSTDISBL Fuse, J = SELFPRGEN Fuse
2. For page sizes less than 256 words, parts of the address (bbbb_bbbb) will be parts of the page address.
3. For page sizes less than 256 bytes, parts of the address (bbbb_bbbb) will be parts of the page address.
4. The EEPROM is written page-wise. But only the bytes that are loaded into the page are actually written to the
EEPROM. Page-wise EEPROM access is more efficient when multiple bytes are to be written to the same page. Note
that auto-erase of EEPROM is not available in High-voltage Serial Programming, only in SPI Programming.
25.1 ATtiny441
Operating Temperature . . . . . . . . . . . -55C to +125C *Notice: Stresses beyond those listed under “Absolute
Maximum Ratings” may cause permanent damage
to the device. This is a stress rating only and
Storage Temperature . . . . . . . . . . . . . -65C to +150C functional operation of the device at these or other
conditions beyond those indicated in the operational
sections of this specification is not implied. Exposure
Voltage on any Pin except RESET
to absolute maximum rating conditions for extended
with respect to Ground. . . . . . . . . . -0.5V to VCC+0.5V
periods may affect device reliability.
25.1.2 DC Characteristics
25.1.3 Speed
The maximum operating frequency of the device is dependent on supply voltage, VCC. The relationship between supply
voltage and maximum operating frequency is piecewise linear, as shown in Figure 25-1.
16 MHz
10 MHz
4 MHz
2 MHz
Accuracy at given
Calibration Voltage &
Method Target Frequency VCC Temperature Temperature
Factory
8.0 MHz 2.7V – 4.0V 0°C – 85C ±2%
Calibration
User Fixed freq. within: Fixed voltage within: Fixed temp. within:
±1%(1)
Calibration 7.3 – 8.1 MHz 1.7V – 5.5V -40C to +85C
Notes: 1. Accuracy of oscillator frequency at calibration point (fixed temperature and fixed voltage).
25.1.4.2 Accuracy of Calibrated 32kHz Oscillator
It is possible to manually calibrate the internal 32kHz oscillator to be more accurate than default factory calibration. Note
that the oscillator frequency depends on temperature and voltage. Voltage and temperature characteristics can be found
in “ ULP 32kHz Oscillator” on page 293.
Calibration
Method Target Frequency VCC Temperature Accuracy
Factory
32kHz 1.7 – 5.5V -40C to +85C ±30%
Calibration
V IH1
V IL1
VBG Internal bandgap voltage VCC = 3.3V, TA = 25°C 1.056 1.1 1.144 V
VCC=1.7V to 5.5V at
Internal 1.1V reference voltage 1.067 1.1 1.133 V
TA=-40°C to 85°C
VCC=2.3V to 5.5V at
VREF Internal 2.2V reference voltage 2.134 2.2 2.266 V
TA=-40°C to 85°C
VCC=4.2V to 5.5V at
Internal 4.096V reference voltage 3.932 4.096 4.260 V
TA=-40°C to 85°C
0XX Reserved
Note: 1. VBOT may be below nominal minimum operating voltage for some devices. For devices where this is the
case, the device is tested down to VCC = VBOT during the production test. This guarantees that a Brown-out
Reset will occur before VCC drops to a voltage where correct operation of the microcontroller is no longer
guaranteed.
Table 25-9. ADC Characteristics. TA = -40 ... +85C. VCC = 1.7 – 5.5V
Resolution 10 Bits
Integral Non-Linearity
VREF = VCC = 4V,
(INL, accuracy after offset 1 LSB
ADC clock = 200 kHz
and gain calibration)
tLOW tLOW
SCL
SDA
tBUF
MOSI
tOVSH tSHOX tSLSH
SCK
tSHSL
MISO
SAMPLE
Table 25-11. Serial Programming Characteristics, TA = -40 ... +85C, VCC = 1.7 – 5.5V
Note: 1. 2 tCLCL for fck < 12MHz, 3 tCLCL for fck >= 12 MHz
SCI (PB0)
tSHSL
SDO (PA4)
tSHOV
tSHIX SDI (PA6), SII (PB1) Hold after SCI (PB0) High 50 ns
Operating Temperature . . . . . . . . . . . -55C to +125C *Notice: Stresses beyond those listed under “Absolute
Maximum Ratings” may cause permanent damage
to the device. This is a stress rating only and
Storage Temperature . . . . . . . . . . . . . -65C to +150C functional operation of the device at these or other
conditions beyond those indicated in the operational
sections of this specification is not implied. Exposure
Voltage on any Pin except RESET
to absolute maximum rating conditions for extended
with respect to Ground. . . . . . . . . . -0.5V to VCC+0.5V
periods may affect device reliability.
25.2.2 DC Characteristics
16 MHz
10 MHz
4 MHz
2 MHz
Accuracy at given
Calibration Voltage &
Method Target Frequency VCC Temperature Temperature
Factory
8.0 MHz 2.7V – 4.0V 0°C – 85C ±2%
Calibration
User Fixed freq. within: Fixed voltage within: Fixed temp. within:
±1%(1)
Calibration 7.3 – 8.1 MHz 1.7V – 5.5V -40C to +85C
Notes: 1. Accuracy of oscillator frequency at calibration point (fixed temperature and fixed voltage).
25.2.4.2 Accuracy of Calibrated 32kHz Oscillator
It is possible to manually calibrate the internal 32kHz oscillator to be more accurate than default factory calibration. Note
that the oscillator frequency depends on temperature and voltage. Voltage and temperature characteristics can be found
in “ ULP 32kHz Oscillator” on page 293.
Calibration
Method Target Frequency VCC Temperature Accuracy
Factory
32kHz 1.7 – 5.5V -40C to +85C ±30%
Calibration
V IH1
V IL1
VBG Internal bandgap voltage VCC = 3.3V, TA = 25°C 1.056 1.1 1.144 V
VCC=1.7V to 5.5V at
Internal 1.1V reference voltage 1.067 1.1 1.133 V
TA=-40°C to 85°C
VCC=2.3V to 5.5V at
VREF Internal 2.2V reference voltage 2.134 2.2 2.266 V
TA=-40°C to 85°C
VCC=4.2V to 5.5V at
Internal 4.096V reference voltage 3.932 4.096 4.260 V
TA=-40°C to 85°C
0XX Reserved
Note: 1. VBOT may be below nominal minimum operating voltage for some devices. For devices where this is the
case, the device is tested down to VCC = VBOT during the production test. This guarantees that a Brown-out
Reset will occur before VCC drops to a voltage where correct operation of the microcontroller is no longer
guaranteed.
Table 25-21. ADC Characteristics. TA = -40 ... +85C. VCC = 1.7 – 5.5V
Resolution 10 Bits
Integral Non-Linearity
VREF = VCC = 4V,
(INL, accuracy after offset 1 LSB
ADC clock = 200 kHz
and gain calibration)
tLOW tLOW
SCL
SDA
tBUF
MOSI
tOVSH tSHOX tSLSH
SCK
tSHSL
MISO
SAMPLE
Table 25-23. Serial Programming Characteristics, TA = -40 ... +85C, VCC = 1.7 – 5.5V
Note: 1. 2 tCLCL for fck < 12MHz, 3 tCLCL for fck >= 12 MHz
SCI (PB0)
tSHSL
SDO (PA4)
tSHOV
tSHIX SDI (PA6), SII (PB1) Hold after SCI (PB0) High 50 ns
26.1 ATtiny441
Figure 26-1. Active Supply Current vs. Low Frequency (0.1 - 1.0MHz)
1200
1000
5.5
800 5.0
4.5
ICC [uA]
600
3.3
2.7
400
1.8
200 1.7
0
0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0
Frequency [MHz]
12
10
5.5
8
5.0
Icc [mA]
4.5
6
3.3
4 2.7
1.8
2
1.7
0
0 2 4 6 8 10 12 14 16
Frequency [MHz]
4
ICC [mA]
3 105
85
2
25
1 0
-40
0
1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5
VCC [V]
Figure 26-4. Active Supply Current vs. VCC, Internal ULP 32kHz Oscillator
35
30
25
20
ICC [uA]
105
15
85
10 25
0
5
-40
0
1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5
VCC [V]
70
60
50
40
ICC [uA]
105
30
85
20 25
0
10
-40
0
1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5
VCC [V]
Figure 26-6. Active Supply Current vs. VCC, Internal ULP 128kHz Oscillator
120
100
80
ICC [uA]
60 105
85
40
25
20 0
-40
0
1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5
VCC [V]
250
200
150
ICC [uA]
105
100 85
25
50 0
-40
0
1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5
VCC [V]
Figure 26-8. Active Supply Current vs. VCC, Internal ULP 512kHz Oscillator
450
400
350
300
ICC [uA]
250
105
200
85
150
25
100
0
50
-40
0
1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5
VCC [V]
Figure 26-9. Idle Supply Current vs. Low Frequency, (0.1 - 1.0MHz)
160
140
5.5
120 5.0
100 4.5
Icc [uA]
80 3.3
2.7
60
1.8
40
1.7
20
0
0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0
Frequency [MHz]
3.0
2.5
5.5
2.0
5.0
ICC [mA]
1.5 4.5
3.3
1.0
2.7
0.5
1.8
1.7
0.0
0 2 4 6 8 10 12 14 16
Frequency [MHz]
1.4
1.2
1.0
ICC [mA]
0.8
105
0.6
85
0.4 25
0
0.2
-40
0.0
1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5
VCC [V]
Figure 26-12.Idle Supply Current vs. VCC, Internal ULP 32kHz Oscillator
35
30
25
20
ICC [uA]
105
15
85
10 25
0
5
-40
0
1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5
VCC [V]
14
12
10
8
ICC [uA]
105
6
85
4 25
0
2
-40
0
1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5
VCC [V]
Figure 26-14.Idle Supply Current vs. VCC, Internal ULP 128kHz Oscillator
20
18
16
14
12
ICC [uA]
10 105
8 85
6 25
4 0
2 -40
0
1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5
VCC [V]
35
30
25
20
ICC [uA]
105
15
85
10 25
0
5
-40
0
1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5
VCC [V]
Figure 26-16.Idle Supply Current vs. VCC, Internal ULP 512kHz Oscillator
70
60
50
40
ICC [uA]
105
30
85
20 25
0
10
-40
0
1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5
VCC [V]
300
250
200
ICC [uA]
150 105
85
100
25
50 0
-40
0
1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5
VCC [V]
300
250
200
ICC [uA]
150 105
85
100
25
50 0
-40
0
1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5
VCC [V]
2.5
2.0
1.5
ICC [uA]
105
1.0 85
25
0.5 0
-40
0.0
1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5
Vcc [V]
4
ICC [uA]
3 105
85
2
25
1 0
-40
0
1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5
VCC [V]
Figure 26-21.Reset Supply Current vs. VCC, Excluding Current through the Reset Pull-up
0.9
0.8
0.7
0.6
ICC [mA]
0.5
105
0.4
85
0.3
25
0.2
0
0.1
-40
0
1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5
Vcc [V]
3000
2500
2000
Pulsewidth [ns]
1500 105
85
1000
25
500 0
-40
0
1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5
VCC [V]
30
25
20
Icc [uA]
105
15 85
25
10 0
-40
5
1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5
VCC [V]
Figure 26-24.Analog Comparator 0 (AC0) Current Consumption vs. VCC, Frequency = 1MHz
200
180
160
140
120
ICC [uA]
100 105
80 85
60 25
40 0
20 -40
0
1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5
VCC [V]
200
180
160
140
120
ICC [uA]
100 105
80 85
60 25
40 0
20 -40
0
1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5
VCC [V]
0.450
0.400
0.350
0.300
ICC [mA]
0.250
105
0.200
85
0.150
25
0.100
0
0.050
-40
0.000
1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5
VCC [V]
30
25
ICC [uA] 20
15 105
85
10
25
5 0
-40
0
1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5
VCC [V]
18
16
14
12
ICC [uA]
10
105
8
85
6
25
4
0
2
-40
0
1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5
VCC [V]
30
25
ICC [uA] 20
15 105
85
10
25
5 0
-40
0
1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5
VCC [V]
30
25
20
ICC [uA]
15 105
85
10
25
5 0
-40
0
1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5
VCC [V]
30
25
ICC [uA] 20
15 105
85
10
25
5 0
-40
0
1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5
VCC [V]
25
20
15
ICC [uA]
105
10 85
25
5 0
-40
0
1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5
VCC [V]
25
20
15
ICC [uA]
105
10 85
25
5 0
-40
0
1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5
VCC [V]
Figure 26-34.I/O Pin Pull-Up Resistor Current vs. Input Voltage, VCC = 1.8V
60
50
40
IOP [uA]
30 105
85
20
25
10 0
-40
0
0.0 0.2 0.4 0.6 0.8 1.0 1.2 1.4 1.6 1.8 2.0
VOP [V]
80
70
60
50
IOP [uA]
40 105
30 85
25
20
0
10
-40
0
0.0 0.5 1.0 1.5 2.0 2.5 3.0
VOP [V]
Figure 26-36.I/O Pin Pull-Up Resistor Current vs. Input Voltage, VCC = 5.0V
160
140
120
100
IOP [uA]
80 105
60 85
25
40
0
20
-40
0
0.0 0.5 1.0 1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0
VOP [V]
Figure 26-37.Reset Pull-Up Resistor Current vs. Reset Pin Voltage, VCC = 1.8V
40
35
30
25
IRESET [uA]
20 105
15 85
25
10
0
5
-40
0
0.0 0.2 0.4 0.6 0.8 1.0 1.2 1.4 1.6 1.8 2.0
VRESET [V]
Figure 26-38.Reset Pull-Up Resistor Current vs. Reset Pin Voltage, VCC = 2.7V
70
60
50
IRESET [uA]
40
105
30
85
20 25
0
10
-40
0
0.0 0.5 1.0 1.5 2.0 2.5 3.0
VRESET [V]
120
100
IRESET [uA] 80
60 105
85
40
25
20 0
-40
0
0.0 0.5 1.0 1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0
VRESET [V]
Figure 26-40.I/O Pin Input Threshold Voltage vs. VCC , VIH I/O Pin Read as “1”
3.5
3.0
2.5
Threshold [V]
2.0
105
1.5
85
1.0 25
0
0.5
-40
0.0
1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5
VCC [V]
3.0
2.5
1.5 105
85
1.0
25
0.5 0
-40
0.0
1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5
VCC [V]
0.7
0.6
0.5
Hysteresis [V]
0.4
105
0.3
85
0.2 25
0
0.1
-40
0.0
1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5
VCC [V]
Figure 26-43.Reset as I/O Input Threshold Voltage vs. VCC , VIH I/O Pin Read as “1”
3.5
3.0
2.5
Threshold [V]
2.0
105
1.5
85
1.0 25
0
0.5
-40
0.0
1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5
VCC [V]
Figure 26-44.Reset as I/O Input Threshold Voltage vs. VCC , VIL I/O Pin Read as “0”
2.5
2.0
Threshold [V]
1.5
105
1.0 85
25
0.5 0
-40
0.0
1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5
VCC [V]
0.9
0.8
0.7
0.5
105
0.4
85
0.3
25
0.2
0
0.1
-40
0.0
1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5
VCC [V]
Figure 26-46.Reset Input Threshold Voltage vs. VCC , VIH I/O Pin Read as “1”
3.5
3.0
2.5
Threshold [V]
2.0
105
1.5
85
1.0 25
0
0.5
-40
0.0
1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5
VCC [V]
2.5
2.0
Threshold [V]
1.5
105
1.0 85
25
0.5 0
-40
0.0
1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5
VCC [V]
0.7
0.6
0.5
Hysteresis [V]
0.4
105
0.3
85
0.2 25
0
0.1
-40
0.0
1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5
VCC [V]
Figure 26-49.I/O Pin Output Voltage vs. Sink Current, Standard Sink I/O pins, VCC=1.8V
1.0
0.9
0.8
0.7
0.6
VOL [V]
0.5 105
0.4 85
0.3 25
0.2 0
0.1 -40
0.0
0.0 0.5 1.0 1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0
IOL [mA]
Figure 26-50.I/O Pin Output Voltage vs. Sink Current, Standard Sink I/O pins, VCC=3.0V
1.0
0.9
0.8
0.7
0.6
VOL [V]
0.5 105
0.4 85
0.3 25
0.2 0
0.1 -40
0.0
0 1 2 3 4 5 6 7 8 9 10
IOL [mA]
1.0
0.9
0.8
0.7
0.6
VOL [V]
0.5 105
0.4 85
0.3 25
0.2 0
0.1 -40
0.0
0 2 4 6 8 10 12 14 16 18 20
IOL [mA]
Figure 26-52.I/O Pin Output Voltage vs. Sink Current, High Sink I/O pins, VCC=1.8V
0.8
0.7
0.6
0.5
VOL [V]
0.4 105
0.3 85
25
0.2
0
0.1
-40
0.0
0 1 2 3 4 5 6 7 8 9 10
IOL [mA]
0.8
0.7
0.6
0.5
VOL [V]
0.4 105
0.3 85
25
0.2
0
0.1
-40
0.0
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
IOL [mA]
Figure 26-54.I/O Pin Output Voltage vs. Sink Current, High Sink I/O pins, VCC=5.0V
0.8
0.7
0.6
0.5
VOL [V]
0.4 105
0.3 85
25
0.2
0
0.1
-40
0.0
0 2 4 6 8 10 12 14 16 18 20
IOL [mA]
0.8
0.7
0.6
0.5
VOL [V]
0.4 105
0.3 85
25
0.2
0
0.1
-40
0.0
0 1 2 3 4 5 6 7 8 9 10
IOL [mA]
Figure 26-56.I/O Pin Output Voltage vs. Sink Current, Extra High Sink I/O pins, VCC=3.0V
0.8
0.7
0.6
0.5
VOL [V]
0.4 105
0.3 85
25
0.2
0
0.1
-40
0.0
0 2 4 6 8 10 12 14 16 18 20
IOL [mA]
0.8
0.7
0.6
0.5
VOL [V]
0.4 105
0.3 85
25
0.2
0
0.1
-40
0.0
0 2 4 6 8 10 12 14 16 18 20
IOL [mA]
Figure 26-58.Reset as I/O Pin Output Voltage vs. Sink Current, VCC=1.8V
0.8
0.7
0.6
0.5
VOL [V]
0.4 105
0.3 85
25
0.2
0
0.1
-40
0.0
0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8
IOL [mA]
0.8
0.7
0.6
0.5
VOL [V]
0.4 105
0.3 85
25
0.2
0
0.1
-40
0.0
0.0 0.2 0.4 0.6 0.8 1.0 1.2 1.4
IOL [mA]
Figure 26-60.Reset as I/O Pin Output Voltage vs. Sink Current, VCC=5.0V
0.8
0.7
0.6
0.5
VOL [V]
0.4 105
0.3 85
25
0.2
0
0.1
-40
0.0
0.0 0.2 0.4 0.6 0.8 1.0 1.2 1.4 1.6 1.8 2.0
IOL [mA]
2.0
1.8
1.6
1.4
1.2
VOH [V]
1.0 105
0.8 85
0.6 25
0.4 0
0.2 -40
0.0
0.0 0.5 1.0 1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0
IOH [mA]
3.5
3.0
2.5
2.0
VOH [V]
105
1.5
85
1.0 25
0
0.5
-40
0.0
0 1 2 3 4 5 6 7 8 9 10
IOH [mA]
5.1
5.0
4.9
4.8
4.7
VOH [V]
4.6 105
4.5 85
4.4 25
4.3 0
4.2 -40
4.1
0 2 4 6 8 10 12 14 16 18 20
IOH [mA]
Figure 26-64.Reset as I/O Pin Output Voltage vs. Source Current, VCC=1.8V
1.6
1.4
1.2
1.0
VOH [V]
0.8 105
0.6 85
25
0.4
0
0.2
-40
0.0
0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0
IOH [mA]
3.0
2.5
1.5 105
85
1.0
25
0.5 0
-40
0.0
0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0
IOH [mA]
Figure 26-66.Reset as I/O Pin Output Voltage vs. Source Current, VCC=5.0V
4.5
4.0
3.5
3.0
VOH [V]
2.5
105
2.0
85
1.5
25
1.0
0
0.5
-40
0.0
0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0
IOH [mA]
1.90
1.89
1.88
Threshold [V]
1.87
1.86 1
0
1.85
1.84
-45 -35 -25 -15 -5 5 15 25 35 45 55 65 75 85 95 105
Temperature [C]
2.80
2.78
2.76
Threshold [V]
2.74
2.72 1
0
2.70
2.68
-45 -35 -25 -15 -5 5 15 25 35 45 55 65 75 85 95 105
Temperature [C]
4.36
4.34
4.3
4.28
1
4.26
0
4.24
4.22
-45 -35 -25 -15 -5 5 15 25 35 45 55 65 75 85 95 105
Temperature [C]
Figure 26-70.Bandgap Voltage vs. Operating Voltage, Internal Voltage Reference = 1.1V
1.115
1.110
1.105
Vref [V]
105
1.100 85
25
1.095 0
-40
1.090
1.7 1.9 2.1 2.3 2.5 2.7 2.9 3.1 3.3 3.5 3.7 3.9 4.1 4.3 4.5 4.7 4.9 5.1 5.3 5.5
Vcc [V]
2.206
2.204
2.202
2.200
Vref [V]
2.198 105
2.196 85
25
2.194
0
2.192
-40
2.190
2.3 2.5 2.7 2.9 3.1 3.3 3.5 3.7 3.9 4.1 4.3 4.5 4.7 4.9 5.1 5.3 5.5
Vcc [V]
Figure 26-72.Bandgap Voltage vs. Operating Voltage, Internal Voltage Reference = 4.096V
4.095
4.090
4.085
Vref [V]
105
4.080 85
25
4.075 0
-40
4.070
4.2 4.3 4.4 4.5 4.6 4.7 4.8 4.9 5 5.1 5.2 5.3 5.4 5.5
Vcc [V]
Figure 26-73.Analog Comparator Offset vs. Input Pin Voltage, Offset -, VCC = 5.0V
-2
-4
Offset- [mV]
-6
105
-8
85
-10 25
0
-12
-40
-14
1.0 1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5 6.0
Vin [V]
Figure 26-74.Analog Comparator Offset vs. Input Pin Voltage, Offset +, VCC = 5.0V
11
10
9
Offset [mV]
8
105
7
85
6 25
0
5
-40
4
1.0 1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5 6.0
Vin [V]
Figure 26-75. Calibrated Internal 8MHz RC Oscillator, Frequency vs. Operating Voltage
8.5
8.4
8.3
Frequency [MHz]
8.2
8.1 105
8.0 85
25
7.9
0
7.8
-40
7.7
1.7 1.9 2.1 2.3 2.5 2.7 2.9 3.1 3.3 3.5 3.7 3.9 4.1 4.3 4.5 4.7 4.9 5.1 5.3 5.5
VCC [V]
Figure 26-76. Calibrated Internal 8MHz RC Oscillator, Frequency vs. Operating Temperature
8.5
8.4 5.5
8.3 5.0
4.5
Frequency [MHz]
8.2
3.3
8.1
2.7
8.0
1.8
7.9 1.7
7.8
7.7
-45 -35 -25 -15 -5 5 15 25 35 45 55 65 75 85 95 105
Temperature [C]
18
16
14
12
Frequency [MHz]
10
105
8
85
6
25
4
0
2
-40
0
0 15 30 45 60 75 90 105 120 135 150 165 180 195 210 225 240 255
OSCCAL
32
31
30 105
Frequency [KHz]
85
29
25
28 0
-40
27
26
1.7 1.9 2.1 2.3 2.5 2.7 2.9 3.1 3.3 3.5 3.7 3.9 4.1 4.3 4.5 4.7 4.9 5.1 5.3 5.5
VCC [V]
30.5
30.0
29.5
28.5 5.0
28.0
4.5
3.3
27.5
2.7
27.0
1.8
26.5
1.7
26.0
-45 -35 -25 -15 -5 5 15 25 35 45 55 65 75 85 95 105
Temperature [C]
Figure 26-80. ULP 32kHz Calibrated Oscillator Frequency vs. OSCCAL1 Value
50
45
40
Frequency [KHz]
35
105
30
85
25 25
0
20
-40
15
0 1 2 3
OSCCAL
60
58
105
56
Frequency [KHz]
85
54 25
0
52
-40
50
48
1.7 1.9 2.1 2.3 2.5 2.7 2.9 3.1 3.3 3.5 3.7 3.9 4.1 4.3 4.5 4.7 4.9 5.1 5.3 5.5
VCC [V]
58
57
56
55 5.5
Frequency [KHz]
54 5.0
53 4.5
52
3.3
2.7
51
1.8
50
1.7
49
-45 -35 -25 -15 -5 5 15 25 35 45 55 65 75 85 95 105
Temperature [C]
90
80
70
60
Frequency [KHz]
50
105
40
85
30
25
20
0
10
-40
0
0 1 2 3
OSCCAL
115
110
105
105
85
Frequency [KHz]
100 25
0
95
-40
90
85
80
1.7 1.9 2.1 2.3 2.5 2.7 2.9 3.1 3.3 3.5 3.7 3.9 4.1 4.3 4.5 4.7 4.9 5.1 5.3 5.5
VCC [V]
108
106
104
100 5.0
98 4.5
96 3.3
94
2.7
1.8
92
1.7
90
-45 -35 -25 -15 -5 5 15 25 35 45 55 65 75 85 95 105
Temperature [C]
Figure 26-86. ULP 128kHz Calibrated Oscillator Frequency vs. OSCCAL1 Value
160
140
120
Frequency [KHz]
100
80 105
60 85
25
40
0
20
-40
0
0 1 2 3
OSCCAL
210
205
200 105
Frequency [KHz]
195 85
190
25
0
185
-40
180
175
170
1.7 1.9 2.1 2.3 2.5 2.7 2.9 3.1 3.3 3.5 3.7 3.9 4.1 4.3 4.5 4.7 4.9 5.1 5.3 5.5
VCC [V]
210
205
200
5.5
Frequency [KHz]
195 5.0
4.5
190
3.3
185
2.7
180 1.8
1.7
175
-45 -35 -25 -15 -5 5 15 25 35 45 55 65 75 85 95 105
Temperature [C]
300
250
150 105
85
100
25
50 0
-40
0
0 1 2 3
OSCCAL
420
410
400
Frequency [KHz]
105
390 85
25
380
0
370 -40
360
1.7 1.9 2.1 2.3 2.5 2.7 2.9 3.1 3.3 3.5 3.7 3.9 4.1 4.3 4.5 4.7 4.9 5.1 5.3 5.5
VCC [V]
420
410
Temperature [C]
Figure 26-92. ULP 512kHz Calibrated Oscillator Frequency vs. OSCCAL1 Value
600
550
500
Frequency [KHz]
450
400 105
350 85
25
300
0
250
-40
200
0 1 2 3
OSCCAL
1200
1000
5.5
800 5.0
4.5
ICC [uA]
600
3.3
2.7
400
1.8
200 1.7
0
0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0
Frequency [MHz]
12
10
5.5
8
5.0
Icc [mA]
4.5
6
3.3
4 2.7
1.8
2
1.7
0
0 2 4 6 8 10 12 14 16
Frequency [MHz]
4
ICC [mA]
3 105
85
2
25
1 0
-40
0
1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5
VCC [V]
Figure 26-96.Active Supply Current vs. VCC, Internal ULP 32kHz Oscillator
35
30
25
20
ICC [uA]
105
15
85
10 25
0
5
-40
0
1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5
VCC [V]
70
60
50
40
ICC [uA]
105
30
85
20 25
0
10
-40
0
1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5
VCC [V]
Figure 26-98.Active Supply Current vs. VCC, Internal ULP 128kHz Oscillator
120
100
80
ICC [uA]
60 105
85
40
25
20 0
-40
0
1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5
VCC [V]
250
200
150
ICC [uA]
105
100 85
25
50 0
-40
0
1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5
VCC [V]
Figure 26-100.Active Supply Current vs. VCC, Internal ULP 512kHz Oscillator
450
400
350
300
ICC [uA]
250
105
200
85
150
25
100
0
50
-40
0
1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5
VCC [V]
160
140
5.5
120 5.0
100 4.5
Icc [uA]
80 3.3
2.7
60
1.8
40
1.7
20
0
0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0
Frequency [MHz]
3.0
2.5
5.5
2.0
5.0
ICC [mA]
1.5 4.5
3.3
1.0
2.7
0.5
1.8
1.7
0.0
0 2 4 6 8 10 12 14 16
Frequency [MHz]
1.4
1.2
1.0
ICC [mA]
0.8
105
0.6
85
0.4 25
0
0.2
-40
0.0
1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5
VCC [V]
Figure 26-104.Idle Supply Current vs. VCC, Internal ULP 32kHz Oscillator
35
30
25
20
ICC [uA]
105
15
85
10 25
0
5
-40
0
1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5
VCC [V]
14
12
10
8
ICC [uA]
105
6
85
4 25
0
2
-40
0
1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5
VCC [V]
Figure 26-106.Idle Supply Current vs. VCC, Internal ULP 128kHz Oscillator
20
18
16
14
12
ICC [uA]
10 105
8 85
6 25
4 0
2 -40
0
1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5
VCC [V]
35
30
25
20
ICC [uA]
105
15
85
10 25
0
5
-40
0
1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5
VCC [V]
Figure 26-108.Idle Supply Current vs. VCC, Internal ULP 512kHz Oscillator
70
60
50
40
ICC [uA]
105
30
85
20 25
0
10
-40
0
1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5
VCC [V]
300
250
200
ICC [uA]
150 105
85
100
25
50 0
-40
0
1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5
VCC [V]
300
250
200
ICC [uA]
150 105
85
100
25
50 0
-40
0
1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5
VCC [V]
2.5
2.0
1.5
ICC [uA]
105
1.0 85
25
0.5 0
-40
0.0
1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5
Vcc [V]
4
ICC [uA]
3 105
85
2
25
1 0
-40
0
1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5
VCC [V]
Figure 26-113.Reset Supply Current vs. VCC, Excluding Current through the Reset Pull-up
0.9
0.8
0.7
0.6
ICC [mA]
0.5
105
0.4
85
0.3
25
0.2
0
0.1
-40
0
1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5
Vcc [V]
3000
2500
2000
Pulsewidth [ns]
1500 105
85
1000
25
500 0
-40
0
1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5
VCC [V]
30
25
20
Icc [uA]
105
15 85
25
10 0
-40
5
1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5
VCC [V]
Figure 26-116.Analog Comparator 0 (AC0) Current Consumption vs. VCC, Frequency = 1MHz
200
180
160
140
120
ICC [uA]
100 105
80 85
60 25
40 0
20 -40
0
1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5
VCC [V]
200
180
160
140
120
ICC [uA]
100 105
80 85
60 25
40 0
20 -40
0
1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5
VCC [V]
0.450
0.400
0.350
0.300
ICC [mA]
0.250
105
0.200
85
0.150
25
0.100
0
0.050
-40
0.000
1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5
VCC [V]
30
25
ICC [uA] 20
15 105
85
10
25
5 0
-40
0
1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5
VCC [V]
18
16
14
12
ICC [uA]
10
105
8
85
6
25
4
0
2
-40
0
1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5
VCC [V]
30
25
ICC [uA] 20
15 105
85
10
25
5 0
-40
0
1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5
VCC [V]
30
25
20
ICC [uA]
15 105
85
10
25
5 0
-40
0
1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5
VCC [V]
30
25
ICC [uA] 20
15 105
85
10
25
5 0
-40
0
1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5
VCC [V]
25
20
15
ICC [uA]
105
10 85
25
5 0
-40
0
1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5
VCC [V]
25
20
15
ICC [uA]
105
10 85
25
5 0
-40
0
1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5
VCC [V]
Figure 26-126.I/O Pin Pull-Up Resistor Current vs. Input Voltage, VCC = 1.8V
60
50
40
IOP [uA]
30 105
85
20
25
10 0
-40
0
0.0 0.2 0.4 0.6 0.8 1.0 1.2 1.4 1.6 1.8 2.0
VOP [V]
80
70
60
50
IOP [uA]
40 105
30 85
25
20
0
10
-40
0
0.0 0.5 1.0 1.5 2.0 2.5 3.0
VOP [V]
Figure 26-128.I/O Pin Pull-Up Resistor Current vs. Input Voltage, VCC = 5.0V
160
140
120
100
IOP [uA]
80 105
60 85
25
40
0
20
-40
0
0.0 0.5 1.0 1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0
VOP [V]
Figure 26-129.Reset Pull-Up Resistor Current vs. Reset Pin Voltage, VCC = 1.8V
40
35
30
25
IRESET [uA]
20 105
15 85
25
10
0
5
-40
0
0.0 0.2 0.4 0.6 0.8 1.0 1.2 1.4 1.6 1.8 2.0
VRESET [V]
Figure 26-130.Reset Pull-Up Resistor Current vs. Reset Pin Voltage, VCC = 2.7V
70
60
50
IRESET [uA]
40
105
30
85
20 25
0
10
-40
0
0.0 0.5 1.0 1.5 2.0 2.5 3.0
VRESET [V]
120
100
IRESET [uA] 80
60 105
85
40
25
20 0
-40
0
0.0 0.5 1.0 1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0
VRESET [V]
Figure 26-132.I/O Pin Input Threshold Voltage vs. VCC , VIH I/O Pin Read as “1”
3.5
3.0
2.5
Threshold [V]
2.0
105
1.5
85
1.0 25
0
0.5
-40
0.0
1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5
VCC [V]
3.0
2.5
1.5 105
85
1.0
25
0.5 0
-40
0.0
1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5
VCC [V]
0.7
0.6
0.5
Hysteresis [V]
0.4
105
0.3
85
0.2 25
0
0.1
-40
0.0
1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5
VCC [V]
Figure 26-135.Reset as I/O Input Threshold Voltage vs. VCC , VIH I/O Pin Read as “1”
3.5
3.0
2.5
Threshold [V]
2.0
105
1.5
85
1.0 25
0
0.5
-40
0.0
1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5
VCC [V]
Figure 26-136.Reset as I/O Input Threshold Voltage vs. VCC , VIL I/O Pin Read as “0”
2.5
2.0
Threshold [V]
1.5
105
1.0 85
25
0.5 0
-40
0.0
1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5
VCC [V]
0.9
0.8
0.7
0.5
105
0.4
85
0.3
25
0.2
0
0.1
-40
0.0
1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5
VCC [V]
Figure 26-138.Reset Input Threshold Voltage vs. VCC , VIH I/O Pin Read as “1”
3.5
3.0
2.5
Threshold [V]
2.0
105
1.5
85
1.0 25
0
0.5
-40
0.0
1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5
VCC [V]
2.5
2.0
Threshold [V]
1.5
105
1.0 85
25
0.5 0
-40
0.0
1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5
VCC [V]
0.7
0.6
0.5
Hysteresis [V]
0.4
105
0.3
85
0.2 25
0
0.1
-40
0.0
1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5
VCC [V]
Figure 26-141.I/O Pin Output Voltage vs. Sink Current, Standard Sink I/O pins, VCC=1.8V
1.0
0.9
0.8
0.7
0.6
VOL [V]
0.5 105
0.4 85
0.3 25
0.2 0
0.1 -40
0.0
0.0 0.5 1.0 1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0
IOL [mA]
Figure 26-142.I/O Pin Output Voltage vs. Sink Current, Standard Sink I/O pins, VCC=3.0V
1.0
0.9
0.8
0.7
0.6
VOL [V]
0.5 105
0.4 85
0.3 25
0.2 0
0.1 -40
0.0
0 1 2 3 4 5 6 7 8 9 10
IOL [mA]
1.0
0.9
0.8
0.7
0.6
VOL [V]
0.5 105
0.4 85
0.3 25
0.2 0
0.1 -40
0.0
0 2 4 6 8 10 12 14 16 18 20
IOL [mA]
Figure 26-144.I/O Pin Output Voltage vs. Sink Current, High Sink I/O pins, VCC=1.8V
0.8
0.7
0.6
0.5
VOL [V]
0.4 105
0.3 85
25
0.2
0
0.1
-40
0.0
0 1 2 3 4 5 6 7 8 9 10
IOL [mA]
0.8
0.7
0.6
0.5
VOL [V]
0.4 105
0.3 85
25
0.2
0
0.1
-40
0.0
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
IOL [mA]
Figure 26-146.I/O Pin Output Voltage vs. Sink Current, High Sink I/O pins, VCC=5.0V
0.8
0.7
0.6
0.5
VOL [V]
0.4 105
0.3 85
25
0.2
0
0.1
-40
0.0
0 2 4 6 8 10 12 14 16 18 20
IOL [mA]
0.8
0.7
0.6
0.5
VOL [V]
0.4 105
0.3 85
25
0.2
0
0.1
-40
0.0
0 1 2 3 4 5 6 7 8 9 10
IOL [mA]
Figure 26-148.I/O Pin Output Voltage vs. Sink Current, Extra High Sink I/O pins, VCC=3.0V
0.8
0.7
0.6
0.5
VOL [V]
0.4 105
0.3 85
25
0.2
0
0.1
-40
0.0
0 2 4 6 8 10 12 14 16 18 20
IOL [mA]
0.8
0.7
0.6
0.5
VOL [V]
0.4 105
0.3 85
25
0.2
0
0.1
-40
0.0
0 2 4 6 8 10 12 14 16 18 20
IOL [mA]
Figure 26-150.Reset as I/O Pin Output Voltage vs. Sink Current, VCC=1.8V
0.8
0.7
0.6
0.5
VOL [V]
0.4 105
0.3 85
25
0.2
0
0.1
-40
0.0
0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8
IOL [mA]
0.8
0.7
0.6
0.5
VOL [V]
0.4 105
0.3 85
25
0.2
0
0.1
-40
0.0
0.0 0.2 0.4 0.6 0.8 1.0 1.2 1.4
IOL [mA]
Figure 26-152.Reset as I/O Pin Output Voltage vs. Sink Current, VCC=5.0V
0.8
0.7
0.6
0.5
VOL [V]
0.4 105
0.3 85
25
0.2
0
0.1
-40
0.0
0.0 0.2 0.4 0.6 0.8 1.0 1.2 1.4 1.6 1.8 2.0
IOL [mA]
2.0
1.8
1.6
1.4
1.2
VOH [V]
1.0 105
0.8 85
0.6 25
0.4 0
0.2 -40
0.0
0.0 0.5 1.0 1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0
IOH [mA]
3.5
3.0
2.5
2.0
VOH [V]
105
1.5
85
1.0 25
0
0.5
-40
0.0
0 1 2 3 4 5 6 7 8 9 10
IOH [mA]
5.1
5.0
4.9
4.8
4.7
VOH [V]
4.6 105
4.5 85
4.4 25
4.3 0
4.2 -40
4.1
0 2 4 6 8 10 12 14 16 18 20
IOH [mA]
Figure 26-156.Reset as I/O Pin Output Voltage vs. Source Current, VCC=1.8V
1.6
1.4
1.2
1.0
VOH [V]
0.8 105
0.6 85
25
0.4
0
0.2
-40
0.0
0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0
IOH [mA]
3.0
2.5
1.5 105
85
1.0
25
0.5 0
-40
0.0
0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0
IOH [mA]
Figure 26-158.Reset as I/O Pin Output Voltage vs. Source Current, VCC=5.0V
4.5
4.0
3.5
3.0
VOH [V]
2.5
105
2.0
85
1.5
25
1.0
0
0.5
-40
0.0
0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0
IOH [mA]
1.90
1.89
1.88
Threshold [V]
1.87
1.86 1
0
1.85
1.84
-45 -35 -25 -15 -5 5 15 25 35 45 55 65 75 85 95 105
Temperature [C]
2.80
2.78
2.76
Threshold [V]
2.74
2.72 1
0
2.70
2.68
-45 -35 -25 -15 -5 5 15 25 35 45 55 65 75 85 95 105
Temperature [C]
4.36
4.34
4.3
4.28
1
4.26
0
4.24
4.22
-45 -35 -25 -15 -5 5 15 25 35 45 55 65 75 85 95 105
Temperature [C]
Figure 26-162.Bandgap Voltage vs. Operating Voltage, Internal Voltage Reference = 1.1V
1.115
1.110
1.105
Vref [V]
105
1.100 85
25
1.095 0
-40
1.090
1.7 1.9 2.1 2.3 2.5 2.7 2.9 3.1 3.3 3.5 3.7 3.9 4.1 4.3 4.5 4.7 4.9 5.1 5.3 5.5
Vcc [V]
2.206
2.204
2.202
2.200
Vref [V]
2.198 105
2.196 85
25
2.194
0
2.192
-40
2.190
2.3 2.5 2.7 2.9 3.1 3.3 3.5 3.7 3.9 4.1 4.3 4.5 4.7 4.9 5.1 5.3 5.5
Vcc [V]
Figure 26-164.Bandgap Voltage vs. Operating Voltage, Internal Voltage Reference = 4.096V
4.095
4.090
4.085
Vref [V]
105
4.080 85
25
4.075 0
-40
4.070
4.2 4.3 4.4 4.5 4.6 4.7 4.8 4.9 5 5.1 5.2 5.3 5.4 5.5
Vcc [V]
Figure 26-165.Analog Comparator Offset vs. Input Pin Voltage, Offset -, VCC = 5.0V
-2
-4
Offset- [mV]
-6
105
-8
85
-10 25
0
-12
-40
-14
1.0 1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5 6.0
Vin [V]
Figure 26-166.Analog Comparator Offset vs. Input Pin Voltage, Offset +, VCC = 5.0V
11
10
9
Offset [mV]
8
105
7
85
6 25
0
5
-40
4
1.0 1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5 6.0
Vin [V]
Figure 26-167. Calibrated Internal 8MHz RC Oscillator, Frequency vs. Operating Voltage
8.5
8.4
8.3
Frequency [MHz]
8.2
8.1 105
8.0 85
25
7.9
0
7.8
-40
7.7
1.7 1.9 2.1 2.3 2.5 2.7 2.9 3.1 3.3 3.5 3.7 3.9 4.1 4.3 4.5 4.7 4.9 5.1 5.3 5.5
VCC [V]
Figure 26-168. Calibrated Internal 8MHz RC Oscillator, Frequency vs. Operating Temperature
8.5
8.4 5.5
8.3 5.0
4.5
Frequency [MHz]
8.2
3.3
8.1
2.7
8.0
1.8
7.9 1.7
7.8
7.7
-45 -35 -25 -15 -5 5 15 25 35 45 55 65 75 85 95 105
Temperature [C]
18
16
14
12
Frequency [MHz]
10
105
8
85
6
25
4
0
2
-40
0
0 15 30 45 60 75 90 105 120 135 150 165 180 195 210 225 240 255
OSCCAL
32
31
30 105
Frequency [KHz]
85
29
25
28 0
-40
27
26
1.7 1.9 2.1 2.3 2.5 2.7 2.9 3.1 3.3 3.5 3.7 3.9 4.1 4.3 4.5 4.7 4.9 5.1 5.3 5.5
VCC [V]
30.5
30.0
29.5
28.5 5.0
28.0
4.5
3.3
27.5
2.7
27.0
1.8
26.5
1.7
26.0
-45 -35 -25 -15 -5 5 15 25 35 45 55 65 75 85 95 105
Temperature [C]
Figure 26-172. ULP 32kHz Calibrated Oscillator Frequency vs. OSCCAL1 Value
50
45
40
Frequency [KHz]
35
105
30
85
25 25
0
20
-40
15
0 1 2 3
OSCCAL
60
58
105
56
Frequency [KHz]
85
54 25
0
52
-40
50
48
1.7 1.9 2.1 2.3 2.5 2.7 2.9 3.1 3.3 3.5 3.7 3.9 4.1 4.3 4.5 4.7 4.9 5.1 5.3 5.5
VCC [V]
58
57
56
55 5.5
Frequency [KHz]
54 5.0
53 4.5
52
3.3
2.7
51
1.8
50
1.7
49
-45 -35 -25 -15 -5 5 15 25 35 45 55 65 75 85 95 105
Temperature [C]
90
80
70
60
Frequency [KHz]
50
105
40
85
30
25
20
0
10
-40
0
0 1 2 3
OSCCAL
115
110
105
105
85
Frequency [KHz]
100 25
0
95
-40
90
85
80
1.7 1.9 2.1 2.3 2.5 2.7 2.9 3.1 3.3 3.5 3.7 3.9 4.1 4.3 4.5 4.7 4.9 5.1 5.3 5.5
VCC [V]
108
106
104
100 5.0
98 4.5
96 3.3
94
2.7
1.8
92
1.7
90
-45 -35 -25 -15 -5 5 15 25 35 45 55 65 75 85 95 105
Temperature [C]
Figure 26-178. ULP 128kHz Calibrated Oscillator Frequency vs. OSCCAL1 Value
160
140
120
Frequency [KHz]
100
80 105
60 85
25
40
0
20
-40
0
0 1 2 3
OSCCAL
210
205
200 105
Frequency [KHz]
195 85
190
25
0
185
-40
180
175
170
1.7 1.9 2.1 2.3 2.5 2.7 2.9 3.1 3.3 3.5 3.7 3.9 4.1 4.3 4.5 4.7 4.9 5.1 5.3 5.5
VCC [V]
210
205
200
5.5
Frequency [KHz]
195 5.0
4.5
190
3.3
185
2.7
180 1.8
1.7
175
-45 -35 -25 -15 -5 5 15 25 35 45 55 65 75 85 95 105
Temperature [C]
300
250
150 105
85
100
25
50 0
-40
0
0 1 2 3
OSCCAL
420
410
400
Frequency [KHz]
105
390 85
25
380
0
370 -40
360
1.7 1.9 2.1 2.3 2.5 2.7 2.9 3.1 3.3 3.5 3.7 3.9 4.1 4.3 4.5 4.7 4.9 5.1 5.3 5.5
VCC [V]
420
410
Temperature [C]
Figure 26-184. ULP 512kHz Calibrated Oscillator Frequency vs. OSCCAL1 Value
600
550
500
Frequency [KHz]
450
400 105
350 85
25
300
0
250
-40
200
0 1 2 3
OSCCAL
Note: 1. For compatibility with future devices, reserved bits should be written to zero if accessed. Reserved I/O memory
addresses should never be written.
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, unlike most other AVRs, the CBI and
SBI instructions will only operation the specified bit, and can therefore be used on registers containing such Status
Flags. The CBI and SBI instructions work with registers 0x00 to 0x1F only.
ATtiny441-SSU
14S1
ATtiny441-SSUR
Industrial ATtiny441-MU
16 MHz 1.7 – 5.5V 20M1
(-40C to +85C)(2) ATtiny441-MUR
ATtiny441-MMH
20M2
ATtiny441-MMHR
Notes: 1. All packages are Pb-free, halide-free and fully green and they comply with the European directive for
Restriction of Hazardous Substances (RoHS).
2. These devices can also be supplied in wafer form. Please contact your local Atmel sales office for detailed
ordering information and minimum quantities.
Package Type
14S1 14-lead, 0.150" Wide Body, Plastic Gull Wing Small Outline Package (SOIC)
20M1 20-pad, 4 x 4 x 0.8 mm Body, Quad Flat No-Lead / Micro Lead Frame Package (QFN/MLF)
20M2 20-pad, 3 x 3 x 0.85 mm Body, Very Thin Quad Flat No Lead Package (VQFN)
ATtiny841-SSU
14S1
ATtiny841-SSUR
Industrial ATtiny841-MU
16 MHz 1.7 – 5.5V 20M1
(-40C to +85C)(2) ATtiny841-MUR
ATtiny841-MMH
20M2
ATtiny841-MMHR
Notes: 1. All packages are Pb-free, halide-free and fully green and they comply with the European directive for
Restriction of Hazardous Substances (RoHS).
2. These devices can also be supplied in wafer form. Please contact your local Atmel sales office for detailed
ordering information and minimum quantities.
Package Type
14S1 14-lead, 0.150" Wide Body, Plastic Gull Wing Small Outline Package (SOIC)
20M1 20-pad, 4 x 4 x 0.8 mm Body, Quad Flat No-Lead / Micro Lead Frame Package (QFN/MLF)
20M2 20-pad, 3 x 3 x 0.85 mm Body, Very Thin Quad Flat No Lead Package (VQFN)
30.1 14S1
E H
L
Top View End View
COMMON DIMENSIONS
(Unit of Measure = mm/inches)
e b
SYMBOL MIN NOM MAX NOTE
A1 A 1.35/0.0532 – 1.75/0.0688
A A1 0.1/.0040 – 0.25/0.0098
b 0.33/0.0130 – 0.5/0.0200 5
D D 8.55/0.3367 – 8.74/0.3444 2
E 3.8/0.1497 – 3.99/0.1574 3
Side View H 5.8/0.2284 – 6.19/0.2440
L 0.41/0.0160 – 1.27/0.0500 4
e 1.27/0.050 BSC
Notes: 1. This drawing is for general information only; refer to JEDEC Drawing MS-012, Variation AB for additional information.
2. Dimension D does not include mold Flash, protrusions or gate burrs. Mold Flash, protrusion and gate burrs shall not
exceed 0.15 mm (0.006") per side.
3. Dimension E does not include inter-lead Flash or protrusion. Inter-lead flash and protrusions shall not exceed 0.25 mm
(0.010") per side.
4. L is the length of the terminal for soldering to a substrate.
5. The lead width B, as measured 0.36 mm (0.014") or greater above the seating plane, shall not exceed a maximum value
of 0.61 mm (0.024") per side.
2/5/02
TITLE DRAWING NO. REV.
2325 Orchard Parkway 14S1, 14-lead, 0.150" Wide Body, Plastic Gull
R San Jose, CA 95131 Wing Small Outline Package (SOIC) 14S1 A
1
Pin 1 ID
2
3 E SIDE VIEW
TOP VIEW
A2
D2
A1
1 0.08 C
Pin #1 2
Notch COMMON DIMENSIONS
(0.20 R) 3 E2 (Unit of Measure = mm)
10/27/04
TITLE DRAWING NO. REV.
2325 Orchard Parkway 20M1, 20-pad, 4 x 4 x 0.8 mm Body, Lead Pitch 0.50 mm,
R
San Jose, CA 95131 2.6 mm Exposed Pad, Micro Lead Frame Package (MLF) 20M1 B
D C
y
Pin 1 ID
E
SIDE VIEW
TOP VIEW
A1
A
D2
16 17 18 19 20
COMMON DIMENSIONS
(Unit of Measure = mm)
C0.18 (8X)
15 1 SYMBOL MIN NOM MAX NOTE
A 0.75 0.80 0.85
Pin #1 Chamfer
14 (C 0.3) 2 A1 0.00 0.02 0.05
e
b 0.17 0.22 0.27
E2 13 3
C 0.152
12 4 D 2.90 3.00 3.10
D2 1.40 1.55 1.70
11 5
E 2.90 3.00 3.10
10/24/08
TITLE GPC DRAWING NO. REV.
Package Drawing Contact: 20M2, 20-pad, 3 x 3 x 0.85 mm Body, Lead Pitch 0.45 mm,
[email protected] 1.55 x 1.55 mm Exposed Pad, Thermally Enhanced ZFC 20M2 B
Plastic Very Thin Quad Flat No Lead Package (VQFN)
31.1 ATtiny441
31.1.1 Rev. D
No known erratas.
31.1.2 Rev. C
Not sampled
31.1.3 Rev. B
Not sampled.
31.1.4 Rev. A
Not sampled
31.2 ATtiny841
31.2.1 Rev. C
No known erratas.
31.2.2 Rev. B
Issue: Non-volatile Memories Should Not Be Written at High Temperatures And Low Voltages
Reliability issues have been detected when Flash, EEPROM or Fuse Bytes are programmed at volt-
ages below 3V AND temperatures above 55°C.
Workaround: Do not write to Flash, EEPROM or Fuse bytes when supply voltage is below 3V AND device tem-
perature is above 55°C.
31.2.3 Rev. A
Issue: Non-volatile Memories Should Not Be Written at High Temperatures And Low Voltages
Reliability issues have been detected when Flash, EEPROM or Fuse Bytes are programmed at volt-
ages below 3V AND temperatures above 55C.
Workaround: Do not write to Flash, EEPROM or Fuse bytes when supply voltage is below 3V AND device tem-
perature is above 55C.
Updated Figure 1-1 on page 2, Figure 1-2 on page 2, and REMAP register on pages 159,
8495B 12/2012
186 and 347. Added ATtiny241.
8495C 03/2013 Updated “Ordering Information” : All -SU and SUR updated to -SSU and -SSUR.
Features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1. Pin Configurations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
1.1 Pin Description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
2. Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
3. General Information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
3.1 Resources. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
3.2 Code Examples. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
3.3 Data Retention . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
3.4 Disclaimer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
4. CPU Core . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
4.1 Architectural Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
4.2 ALU – Arithmetic Logic Unit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
4.3 Status Register . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
4.4 General Purpose Register File . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
4.5 Stack Pointer. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
4.6 Instruction Execution Timing. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
4.7 Reset and Interrupt Handling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
4.8 Register Description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
5. Memories . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
5.1 Program Memory (Flash) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
5.2 Data Memory (SRAM) and Register Files. . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
5.3 Data Memory (EEPROM) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
5.4 Register Description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
6. Clock System . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
6.1 Clock Subsystems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
6.2 Clock Sources. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
6.3 System Clock Prescaler . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
6.4 Clock Output Buffer. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
6.5 Start-Up Time . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
6.6 Register Description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
9. Interrupts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
ATtiny441/841 [DATASHEET] 1
8495G–AVR–01/2014
9.1 Interrupt Vectors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
9.2 External Interrupts. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
9.3 Register Description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
ATtiny441/841 [DATASHEET] 2
8495G–AVR–01/2014
16.6 Changing Channel, Gain, and Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . 138
16.7 ADC Noise Canceler . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139
16.8 Analog Input Circuitry . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139
16.9 Noise Canceling Techniques . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 140
16.10 ADC Accuracy Definitions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 140
16.11 ADC Conversion Result . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 142
16.12 Temperature Measurement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 143
16.13 Register Description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 143
ATtiny441/841 [DATASHEET] 3
8495G–AVR–01/2014
21.5 Limitations of debugWIRE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 211
21.6 Register Description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 211
ATtiny441/841 [DATASHEET] 4
8495G–AVR–01/2014
ATtiny441/841 [DATASHEET] 5
8495G–AVR–01/2014
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 Roa D-85748 Garching b. Munich Tokyo 141-0032
Tel: (+1) (408) 441-0311 Kwun Tong, Kowloon GERMANY JAPAN
Fax: (+1) (408) 487-2600 HONG KONG Tel: (+49) 89-31970-0 Tel: (+81) (3) 6417-0300
www.atmel.com Tel: (+852) 2245-6100 Fax: (+49) 89-3194621 Fax: (+81) (3) 6417-0370
Fax: (+852) 2722-1369
Atmel®, Atmel logo and combinations thereof, Enabling Unlimited Possibilities®,AVR®, and others are registered trademarks or trademarks of Atmel Corporation or
its subsidiaries. Other terms and product names may be trademarks of others.
Disclaimer: The information in this document is provided in connection with Atmel products. No license, express or implied, by estoppel or otherwise, to any intellectual property right is granted by this
document or in connection with the sale of Atmel products. EXCEPT AS SET FORTH IN THE ATMEL TERMS AND CONDITIONS OF SALES LOCATED ON THE ATMEL WEBSITE, ATMEL ASSUMES
NO LIABILITY WHATSOEVER AND DISCLAIMS ANY EXPRESS, IMPLIED OR STATUTORY WARRANTY RELATING TO ITS PRODUCTS INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
CONSEQUENTIAL, PUNITIVE, SPECIAL OR INCIDENTAL DAMAGES (INCLUDING, WITHOUT LIMITATION, DAMAGES FOR LOSS AND PROFITS, BUSINESS INTERRUPTION, OR LOSS OF
INFORMATION) ARISING OUT OF THE USE OR INABILITY TO USE THIS DOCUMENT, EVEN IF ATMEL HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. Atmel makes no
representations or warranties with respect to the accuracy or completeness of the contents of this document and reserves the right to make changes to specifications and products descriptions at any time
without notice. Atmel does not make any commitment to update the information contained herein. Unless specifically provided otherwise, Atmel products are not suitable for, and shall not be used in,
automotive applications. Atmel products are not intended, authorized, or warranted for use as components in applications intended to support or sustain life.