• USB Hub with One Attached and Four External Ports
• USB Keyboard Function with Four Programmable Endpoints
• 16 KB Program Memory, 512-Byte Data SRAM
• 32 x 8 General-purpose Working Registers
• 42 Programmable I/O Port Pins
• Support for 20 x 8 Keyboard Matrix
• Keyboard Scan Inputs with Pull-up Resistor
• Four LED Driver Outputs
• One 8-bit Timer/Counter with Separate Pre-scaler
• One 16-bit Timer/Counter with Separate Pre-scaler and Dual 8-, 9- or 10-bit PWM
• External and Internal Interrupt Sources
• Programmable Watchdog Timer
• 6-MHz Oscillator with On-chip PLL
• 5V Operation with On-chip 3.3V Power Supply
• 64-lead LQFP Package
8-bit RISC Microcontroller with 83 ns Instruction Cycle Time
Multimedia
USB Keyboard
Controller with
Embedded Hub
1.Description
The Atmel AT43USB325 is an 8-bit microcontroller based on the AVR RISC architecture. By executing powerful instructions in a single clock cycle, the AT43USB325
achieves throughputs approaching 12 MIPS. The AVR core combines a rich instruction set with 32 general-purpose working registers. All 32 registers are directly
connected to the ALU allowing two independent registers to be accessed in one single
instruction executed in one clock cycle. The resulting architecture is more code efficient while achieving throughputs up to ten times faster than conventional CISC
microcontrollers.
The AT43USB325 features an on-chip 16-Kbyte program memory and
512 bytes of data memory. It is supported by a standard set of peripherals such as
timer/counter modules, watchdog timer and internal and external interrupt sources.
The major peripheral included in the AT43USB325 is the USB Hub with an embedded
function and GPIO ports designed for use in a keyboard controller. The embedded
function has 4 endpoints that makes the AT43USB325 extremely suitable for keyboards supporting the consumer page as described in the “USB Usage Tables”.
The AT43USB325 comes in two versions. The program memory of the
AT43USB325E is an SRAM that is automatically written from an external serial
EEPROM during power on. The AT43USB325M has a masked ROM program memory. The two versions are pin, function and binary compatible.
XTAL1InputOscillator Input – Input to the inverting oscillator amplifier.
XTAL2OutputOscillator Output – Output of the inverting oscillator amplifier.
LFTInput
DPOBi-directional
DMOBi-directionalUpstream Minus USB I/O
DP[2:5]Bi-directional
DM[2:5]Bi-directional
PA[0:7]Bi-directional
Power Supply/Ground5V Power Supply
External Capacitors for Internal Voltage Regulator – A high quality 2.2µF capacitor must
be connected to CEXT1 and 0.33 µF to CEXT2 for proper operation of the chip.
Power Supply/Ground Ground
PLL Filter – For proper operation of the PLL, this pin should be connected through a 0.01 µF
capacitor in parallel with a 100Ω resistor in series with a 0.1 µF capacitor to ground (VSS).
Both capacitors must be high quality ceramic.
Upstream Plus USB I/O – This pin should be connected to CEXT1 through an external
1.5 kΩ pull-up resistor. DP0 and DM0 form the differential signal pin pairs connected to the
Host Controller or an upstream Hub.
Port Plus USB I/O – Each of these pins should be connected to VSS through an external
15 kΩ resistor. DP[2:5] and DM[2:5] are the differential signal pin pairs to connect
downstream USB devices.
Port Minus USB I/O – Each of these pins should be connected to VSS through an external
15 kΩ resistor.
Port A[0:7] – Bi-directional 8-bit I/O port with controlled slew rate. These pins are used as
eight of the keyboard matrix column output strobes. PA[0:7] = COL[0:7].
Port B[0:7] – Bi-directional 8-bit I/O port controlled slew rate. These pins are used
as the eight of the keyboard matrix column output strobes: PB[0:7] = COL[8:15].
PB[0:7]Bi-directional
PB0 has a dual function: the input to timer/counter0.
Port PinAlternate Function
PB0T0, Timer/Counter0 external input
PC[0:7]Bi-directional
PD[0,1,3:7]Bi-directional
PE[0:3]Bi-directional
PE[4:7]Bi-directional
4
AT43USB325
Port C[0:7] – Bi-directional 8-bit I/O port with internal pull-ups. These pins are used as
Port D[0,1,3:7] – Bi-directional I/O ports. Port D[1,4:7] have dual functions as shown below:
Port PinAlternate Function
PD1T1, Timer/Counter1 External Input
PD3INT1, External Interrupt Input 1
PD4INTA, External Interrupt Input A
PD5INTB, External Interrupt Input B
PD6INTC, External Interrupt Input C
PD7INTD, External Interrupt Input D
Port E[0:3] – Bi-directional I/O port with controlled slew rate which can be used as four
additional keyboard column output strobes, COL[16:19].
PE[4:7] – Bi-directional I/O port. PE[4:7] have built-in series limiting resistors and can be
used to drive LEDs directly
3355C–USB–4/05
1.3Signal Description (Continued)
NameTypeFunction
Port F[1:3] – Bi-directional I/O port. In the AT43USB325E, these port pins have dual
functions as the interface pins to the serial EEPROM as shown below:
Alternate Function 1
PF[1:3]Bi-directional
NC/SSNOutput
TESTInputTest Pin – This pin should be tied to ground.
RESETNInputReset – Active low
Note:Signal names ending with an N are active low.
Port Pin
PF1SCK, SPI Master Clock OutOC1A, Timer/Counter1 Output Compare A
PF2SI, SPI Slave Data InputOC1B, Timer/Counter1 Output Compare B
PF3SO, SPI Slave Data OutICP, Timer/Counter1 Input Capture
No Connect/Slave Select – In the AT43USB325M this pin is not used. In the AT43USB325E
this pin is the SPI slave select input used for enabling the serial memory during program
memory downloading.
(AT43USB325E only)Alternate Function 2
AT43USB325
3355C–USB–4/05
5
Figure 1-3.AT43USB325 Enhanced RISC Architecture with USB Keyboard Controller and Hub
8 x 16
Program
Memory
Instruction
Register
Instruction
Decoder
Control
Lines
Program
Counter
Status and
Control
32 x 8
General-purpose
Registers
ALU
512 x 8
SRAM
11 GPIO
Lines
Interrupt
Unit
8-bit
Timer/Counter
16-bit
Timer/Counter
Watchdog
Timer
20 Strobe
Outputs
8 Strobe Inputs
USB
Hub and
Function
4 LED Drives
6
AT43USB325
3355C–USB–4/05
2.Architectural Overview
The AT43USB325 is a USB microcontroller with special peripherals for use as a programmable
keyboard controller.
The peripherals and features of the AT43USB325 microcontroller are similar to those of the
AT90S8515, with the exception of the following modifications:
• A downloadable SRAM or masked ROM for program memory
• No EEPROM
• No external data memory accesses
• No analog comparator, SPI, UART
• Idle mode not supported
• Additional GPIO port pins: PE, PF
• Four new external interrupt input pins: INTA, INTB, INTC, INTD
• USB Hub with attached function
The embedded USB hardware of the AT43USB325 is a compound device, consisting of a 5 port
hub with a permanently attached function on one port. The hub and attached function are two
independent USB devices, each having its own device addresses and control endpoints. The
hub has its dedicated interrupt endpoint, while the USB function has three additional programmable endpoints with 8-byte FIFOs.
AT43USB325
The microcontroller always runs from a 12 MHz clock that is generated by the USB hardware.
While the nominal and average period of this clock is 83.3 ns, it may have single cycles that
deviate by ±20.8 ns during a phase adjustment by the SIE's clock/data separator of the USB
hardware.
The microcontroller shares most of the control and status registers of the megaAVR
troller Family. The registers for managing the USB operations are mapped into its SRAM space.
The I/O section on page 17 summarizes the available I/O registers. The “AVR Register Set” on
page 40 covers the AVR registers. Please refer to the Atmel AVR manual for more information.
The fast-access register file contains 32 x 8-bit general-purpose working registers with a single
clock cycle access time. This means that during one single clock cycle, one Arithmetic Logic Unit
(ALU) operation is executed. 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 three address pointers is
also used as the address pointer for look-up tables in program memory. These added function
registers are the 16-bit X-, Y- and Z-registers.
The ALU supports arithmetic and logic operations between registers or between a constant and
a register. Single register operations are also executed in the ALU. Figure 1-3 on page 6 shows
the AT43USB325 AVR Enhanced RISC microcontroller architecture.
In addition to the register operation, the conventional memory addressing modes can be used
on the register file as well. This is enabled by the fact that the register file is assigned the 32 lowest Data Space addresses ($00 - $1 F), allowing them to be accessed as though they were
ordinary memory locations.
™
Microcon-
3355C–USB–4/05
7
The I/O memory space contains 64 addresses for CPU peripheral functions as Control Registers, Timer/Counters, 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, $20 - $5F.
The AVR uses a Harvard architecture concept – with separate memories and buses for program
and data. The program memory is 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 a downloadable SRAM or a mask programmed ROM.
With the relative jump and call instructions, the whole 24K address space is directly accessed.
Most AVR instructions have a single 16-bit word format. Every program memory address contains a 16- or 32-bit instruction.
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 Stack Pointer (SP) in the reset routine (before subroutines or interrupts are executed). The 10-bit SP is read/write accessible in the I/O space.
The 512-byte data SRAM can be easily 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 at the beginning of the program memory. The interrupts have priority in accordance
with their interrupt vector position. The lower the interrupt vector address, the higher the priority.
8
AT43USB325
3355C–USB–4/05
3.General-purpose Register File
Table 3-1.AVR CPU General-purpose Working Register
RegisterAddressComment
R0$00
R1$01
R2$02
..
R13$0D
R14$0E
R15$0F
R16$10
R17$11
..
R26$1AX-register low byte
R27$1BX-register high byte
R28$1CY-register low byte
R29$1DY-register high byte
AT43USB325
R30$1EZ-register low byte
R31$1FZ-register high byte
All register operating instructions in the instruction set have direct and single cycle access to all
registers. The only exception is the five constant arithmetic and logic instructions SBCI, SUBI,
CPI, ANDI, and ORI between a constant and a register, and the LDI instruction for load immediate constant data. These instructions apply to the second half of the registers in the register file
– R16..R31. The general SBC, SUB, CP, AND, and OR and all other operations between two
registers or on a single register apply to the entire register file.
As shown in Table 3-1, 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-registers can be set to index any register in the file.
3355C–USB–4/05
9
3.1X-, Y- and Z- Registers
Registers R26..R31 contain some added functions to their general-purpose usage. These registers are address pointers for indirect addressing of the Data Space. The three indirect address
registers X, Y, and Z are defined as:
X-register15XHXL0
Y-register15YHYL0
Z-register15ZHZL0
In the different addressing modes these address registers have functions as fixed displacement,
automatic increment and decrement (see the descriptions for the different instructions).
7070
R27 ($1B)R26 ($1A)
7070
R29 ($1D)R28 ($1C)
7070
R30 ($1F)R31 ($1E)
3.2Arithmetic Logic Unit (ALU)
The high-performance AVR ALU operates in direct connection with all 32 general-purpose working registers. Within a single clock cycle, ALU operations between registers in the register file
are executed. The ALU operations are divided into three main categories – arithmetic, logical
and bit-functions.
3.3Program Memory
The AT43USB325E contains 16K bytes on-chip downloadable memory for program storage
while the AT43USB325M has a masked programmable ROM. Since all instructions are 16- or
32-bit words, the program memory is organized as 8K x 16. The AT43USB325 Program Counter
(PC) is 13 bits wide, thus addressing the 8,192 program memory addresses.
Constant tables can be allocated within the entire program memory address space (see the LPM
- Load Program Memory instruction description).
The program memory of the AT43USB325E is automatically written with data stored in an external serial EEPROM during the chip's power on reset sequence. The power on reset is the only
way the on-chip program memory of the AT43USB325E will be written or modified.
The two versions of the AT43USB325 are binary compatible. A firmware written for the
AT43USB325E will work unaltered on the AT43USB325M. The only functional difference
10
AT43USB325
3355C–USB–4/05
AT43USB325
between the two versions is with respect to the serial EEPROM interface pins, GPIO PF[0:3].
The differences are:
Port F PinsAT43USB325EAT43USB325M
Slave Select Pin – Its output will be asserted (low) during
PF0
downloading of firmware and will stay de-asserted (high) after
download is completed.
NC (No connect)
PF1, PF2, PF3
Functions as serial EEPROM interface signals during
downloading and as GPIO pins after download is completed.
3.4SPI Serial EEPROM Interface (AT43USB325E Only)
The AT43USB325E is designed to interface directly with a synchronous serial peripheral interface (SPI) SEEPROM such as the Atmel AT25HP256/512. All instructions, addresses and data
are transferred with the MSB first and start with a high-to-low SSN transition.
Note:The SPI port of the AT43USB325E at PF[0:3] is dedicated for program memory downloading only.
It cannot be accessed by the firmware program.
Figure 3-1.AT43USB325E Read Sequence
SSN
AT43USB325EAT25HP256
3.4.1Read Sequence
1. The AT43USB325E asserts its SSN output pin and outputs a 3 MHz clock at SCK. It
continues to activate SCK until the completion of the read process.
2. The AT43USB325E transmits the READ opcode (= 0000011) through its MOSI, followed by the 16-bit byte address to be read, x0000. Please note that the
AT43USB325E will send a 16-byte address only. SEEPROM with SPI that requires a
24-bit address cannot be used with the AT43USB325E.
3. The SEEPROM then shifts out the data through its MISO pin.
4. The AT43USB325E de-asserts SCK and SSN after 16K bytes data read is complete.
MOSI
MISO
SCK
GPIO
3355C–USB–4/05
Figure 3-2.READ Timing
SSN
SCK
MOSI
MISO
1 2 3 4 5 6 7 8 9 101120212223242526272829300
INSTRUCTION
HIGH IMPEDANCE
BYTE ADDRESS
...
0123131415
DATA OUT
20134567
MSB
11
3.5SRAM Data Memory
Table 3-3 summarizes how the AT43USB325 SRAM Memory is organized. The lower 608 Data
Memory locations address the Register file, the I/O Memory and the internal data SRAM. The
first 96 locations address the Register File + I/O Memory, and the next 512 locations address the
internal data SRAM. The five different addressing modes for the data memory cover: Direct,
Indirect with Displacement, Indirect, Indirect with Pre-decrement and Indirect with Post-increment. In the register file, registers R26 to R31 feature the indirect addressing pointer registers.
Direct addressing reaches the entire data space.
The Indirect with Displacement mode features 63 address locations that reach from the base
address given by the Y- or Z-register.
When using register indirect addressing modes with automatic pre-decrement and post-increment, the address registers X, Y, and Z are decremented and incremented.
The 32 general-purpose working registers, 64 I/O registers and the 512 bytes of internal data
SRAM in the AT43USB325 are all accessible through these addressing modes.
To manage the USB hardware, a special set of registers is assigned. These registers are
mapped to SRAM space between addresses $1F00 and 1FFF. Table 3-3 and Table 3-4 give an
overview of these registers.
All AT43USB325 I/O and peripherals, except for the USB hardware registers, are placed in the
I/O space. The I/O locations are accessed by the IN and OUT instructions transferring data
between the 32 general-purpose working registers and the I/O space. I/O registers within the
address range $00 – $1F are directly bit-accessible using the SBI and CBI instructions. In these
registers, the value of single bits can be checked by using the SBIS and SBIC instructions. Refer
to the instruction set documentations of the AVR for more details. When using the I/O specific
commands, IN and OUT, the I/O address $00 – $3F must be used. When addressing I/O registers as SRAM, $20 must be added to this address. All I/O register addresses throughout this
document are shown with the SRAM address in parentheses.
3.7USB Hub
3.7.1USB Function
18
AT43USB325
For compatibility with future devices, reserved bits should be written to zero if accessed.
Reserved I/O memory addresses should never be written.
A block diagram of the USB hardware of the AT43USB325 is shown in Figure 3-3. The USB hub
of the AT43USB325 has 5 downstream ports. The embedded function is permanently attached
to Port 1. Ports 2, 3, 4 and 5 are available as external ports. The actual number of ports used is
strictly defined by the firmware of the AT43USB325 and can vary from 0 to 4. Because the exact
configuration is defined by firmware, these ports may even function as permanently attached
ports as long as the Hub Descriptor identifies them as such.
The embedded USB function has its own device address and has a default endpoint plus 3 other
programmable endpoints with their own 8-byte FIFOs. Endpoints 1 and 2 can be programmed
as interrupt IN or OUT or bulk IN or OUT endpoints.
3355C–USB–4/05
Figure 3-3.USB Hardware
Port 0
XCVR
Hub Repeater
Serial Interface Engine
AT43USB325
Port 2
XCVR
Port 3
XCVR
Port 4
XCVR
Port 5
XCVR
Hub
Interface
Unit
Port 1
Function
Interface
Unit
Data
Address
Control
AVR Microcontroller
3355C–USB–4/05
19
4.Functional Description
4.1On-chip Power Supply
The AT43USB325 contains two on-chip power supplies that generate 3.3V with a capacity of 30
mA each from the 5V power input. The on-chip power supplies are intended to supply the
AT43USB325 internal circuit and the 1.5K pull-up resistor only and should not be used for other
purposes. External 2.2 µF filter capacitors are required at the power supply outputs, CEXT1 and
CEXT2. The internal power supplies can be disabled as described in the next paragraph.
The user should be careful when the GPIO pins are required to supply high-load currents. If the
application requires that the GPIO supply currents beyond the capability of the on-chip power
supply, the AT43USB325 should be supplied by an external 3.3V power supply. In this case, the
5V V
through the CEXT1 and CEXT2 pins.
4.2I/O Pin Characteristics
The I/O pins of the AT43USB325 should not be directly connected to voltages less than VSS or
more than the voltage at the CEXT pins. If it is necessary to violate this rule, insert a series resistor between the I/O pin and the source of the external signal source that limits the current into
the I/O pin to less than 2 mA. Under no circumstance should the external voltage exceed 5.5V.
To do so will put the chip under excessive stress.
power supply pin should be left unconnected and the 3.3V power supplied to the chip
CC
4.3Oscillator and PLL
All clock signals required to operate the AT43USB325 are derived from an on-chip oscillator. To
reduce EMI and power dissipation, the oscillator is designed to operate with a 6 MHz crystal. An
on-chip PLL generates the high frequency for the clock/data separator of the Serial Interface
Engine. In the suspended state, the oscillator circuitry is turned off.
The oscillator of the AT43USB325 is a special, low-drive type, designed to work with most crystals without any external components. The crystal must be of the parallel resonance type
requiring a load capacitance of about 10 pF. If the crystal requires a higher value capacitance,
external capacitors can be added to the two terminals of the crystal and ground to meet the
required value. To assure quick start-up, a crystal with a high Q, or low ESR, should be used. To
meet the USB hub frequency accuracy and stability requirements for hubs, the crystal should
have an accuracy and stability of better than 100 PPM. The use of a ceramic resonator in place
of the crystal is not recommended because a resonator would not have the necessary frequency
accuracy and stability.
The clock can also be externally sourced. In this case, connect the clock source to the XTAL1
pin, while leaving XTAL2 pin floating. The switching level at the OSC1 pin can be as low as
0.47V and a CMOS device is required to drive this pin to maintain good noise margins at the low
switching level.
For proper operation of the PLL, an external RC filter consisting of a series RC network of 100Ω
and 0.1 µF in parallel with a 0.01 µF capacitor must be connected from the LFT pin to V
only high-quality ceramic capacitors.
SS
. Use
20
AT43USB325
3355C–USB–4/05
Figure 4-1.Oscillator and PLL
AT43USB325
U1
4.4Reset and Interrupt Handling
The AT43USB325 provides 12 different interrupt sources with 4 separate reset vectors, each
with a separate program vector in the program memory space. Nine of the interrupt sources
share 2 interrupt reset vectors. These nine are the USB related interrupts. All interrupts are
assigned individual enable bits which must be set (one) together with the I-bit in the status register in order to enable the interrupt.
The lowest addresses in the program memory space are automatically defined as the Reset and
Interrupt vectors. The complete list of vectors is shown in Table 4-1. The list also determines the
priority levels of the different interrupts. The lower the address, the higher is the priority level.
RESET has the highest priority, and next is INT0 – the USB Suspend and Resume Interrupt, etc.
The most typical and general program setup for the Reset and Interrupt Vector Addresses are:
AddressLabelsCodeComments
$000jmp RESET; Reset Handler
$002jmp EXT_INT0; IRQ0 Handler
$00Ejmp TIM0_OVF; Timer0
Overflow
Handler
$018jmp USB_HW; USB Handler
;
$00dMAIN:ldi r16, high (RAMEND); Main Program
start
$00eout SPH, r16
$00fldi r16, low (RAMEND)
$010out SPL, r16
$011<instr> xxx
............
USB related interrupt events are routed to reset vectors 13 and 2 through a separate set of interrupt, interrupt enable and interrupt mask registers that are mapped to the data SRAM space.
These interrupts must be enabled though their control register bits. In the event an interrupt is
generated, the source of the interrupt is identified by reading the interrupt registers. The USB
frame and transaction related interrupt events, such as Start of Frame interrupt, are grouped in
one set of registers: USB Interrupt Flag Register, USB Interrupt Enable Register and USB Interrupt Mask Register. The USB Bus reset and suspend/resume are grouped in another set of
registers: Suspend/Resume Register, Suspend/Resume Interrupt Enable Register and Suspend/Resume Interrupt Mask Register.
Some applications may include firmware routines lasting for long periods that can not be interrupted. At the same time, other less critical events may need attention after the critical routine is
completed. The AT43USB325 solves this problem by having interrupt mask registers in addition
to the interrupt enable registers of the USB related interrupts. The difference between the mask
and enable registers is:
• The enable register enables the interrupt so it is captured into the interrupt register. If it is not
enabled, and an interrupt occurs, the interrupt will be lost.
• The mask register merely masks the interrupt from interrupting the CPU. Upon unmasking,
the pending interrupt is triggered.
22
AT43USB325
3355C–USB–4/05
Figure 4-2.AT43USB325 Interrupt Structure
USB Interrupt
Flag Register
SOF
EOF2
FEP3
FEP2
USB Interrupt
Enable Register
USB Interrupt
Mask Register
USB
AT43USB325
Microcontroller
Interrupt
Logic
13
FEP1
FEP0
HEP0
FRMWUP
GLB SUSP
BUS RESET
4.5Reset Sources
RSM
INTA
INTB
INTC
INTD
Suspend/Resume
Register
Suspend/Resume
Interrupt Enable
Register
Suspend/Resume
Interrupt Mask
The AT43USB325 has four sources of reset:
Register
TIMER0 OVF
TIMER OVF
COMPB
COMPA
INT1
INT0
RESET
8
7
6
5
3
2
1
3355C–USB–4/05
• Power-on Reset – The MCU is reset when the supply voltage is below the power-on reset
threshold.
• External Reset – The MCU is reset when a low level is present on the RESET pin for more
than 50 ns.
• Watchdog Reset – The MCU is reset when the watchdog timer period expires and the
watchdog is enabled.
• USB Reset – The AT43USB325 has a feature to separate the USB and microcontroller
resets. This feature is enabled by setting the BUS INT EN, bit 3 of the SPRSIE register. A
USB bus reset is defined as a SE0 (single ended zero) of at least 4 slow speed USB clock
cycles received by Port0. The internal reset pulse to the USB hardware and microcontroller
lasts for 24 oscillator periods.
– Resets not separated: A USB bus reset will also reset the microcontroller.
23
Figure 4-3.Reset Logic
– Separated reset: A USB bus reset will only reset the USB hardware, while an
interrupt to the microcontroller will be generated if the BUS INT MSK bit, bit 3 of
SPRSMSK register, is also set.
When the USB hardware is reset, the compound device is de-configured and has to be re-enumerated by the host. When the microcontroller is reset, all I/O registers are then set to their initial
values, and the program starts execution from address $000. The instruction placed in address
$000 must be a JMP instruction to the reset handling routine. If the program never enables an
interrupt source, the interrupt vectors are not used, and regular program code can be placed at
these locations. The circuit diagram in Figure 4-3 shows the reset logic.
USB Reset
VCC
RSTN
1-MHz Clock
4.6Power-on Reset
A Power-on Reset (POR) circuit ensures that the device is reset from power-on. An internal
timer clocked from the Watchdog timer oscillator prevents the MCU from starting until after a certain period after V
time.
POR Ckt
Reset Ckt
Watchdog Timer
Divider
OR
Cntr Reset
FSTRT
14-bit Cntr
has reached the power-on threshold voltage, regardless of the VCC rise
CC
ON
S
R
24
If the build-in start-up delay is sufficient, RESET can be connected to V
external pull-up resistor. By holding the pin low for a period after V
Power-on Reset period can be extended.
AT43USB325
directly or via an
CC
has been applied, the
CC
3355C–USB–4/05
4.7External Reset
AT43USB325
An external reset is generated by a low-level on the RESET pin. Reset pulses longer than
200 ns will generate a reset. Shorter pulses are not guaranteed to generate a reset. When the
applied signal reaches the Reset Threshold Voltage - V
starts the MCU after the Time-out period t
has expired.
TOUT
Figure 4-4.External Reset During Operation
VCC
on its positive edge, the delay timer
RST
TIME-OUT
INTERNAL
4.8Watchdog Timer Reset
When the watchdog times out, it will generate a short reset pulse of 1 XTAL cycle duration. On
the falling edge of this pulse, the delay timer starts counting the Time-out period t
Figure 4-5.Watchdog Reset During Operation
VCC
RESET
WDT
TIME-OUT
RESET
TIME-OUT
RESET
RESET
V
RST
1 XTAL Cycle
t
TOUT
t
TOUT
TOUT
.
3355C–USB–4/05
INTERNAL
RESET
25
4.9Non-USB Related Interrupt Handling
The AT43USB325 has two non-USB 8-bit Interrupt Mask control registers; GIMSK (General
Interrupt Mask Register) and TIMSK (Timer/Counter Interrupt Mask Register).
When an interrupt occurs, the Global Interrupt Enable I-bit is cleared (zero) and all interrupts are
disabled. The user software can set (one) the I-bit to enable nested interrupts. The I-bit is set
(one) when a Return from Interrupt instruction, RETI, is executed.
For Interrupts triggered by events that can remain static (e.g. the Output Compare register1
matching the value of Timer/Counter1) the interrupt flag is set when the event occurs. If the
interrupt flag is cleared and the interrupt condition persists, the flag will not be set until the event
occurs the next time.
When the Program Counter is vectored to the actual interrupt vector in order to execute the
interrupt handling routine, hard-ware clears the corresponding flag that generated the interrupt.
Some of the interrupt flags can also be cleared by writing a logic one to the flag bit position(s) to
be cleared.
If an interrupt condition occurs when the corresponding interrupt enable bit is cleared (zero), the
interrupt flag will be set and remembered until the interrupt is enabled, or the flag is cleared by
software.
If one or more interrupt conditions occur when the global interrupt enable bit is cleared (zero),
the corresponding interrupt flag(s) will be set and remembered until the global interrupt enable
bit is set (one), and will be executed by order of priority.
Note that external level interrupt does not have a flag, and will only be remembered for as long
as the interrupt condition is active.
4.9.1General Interrupt Mask Register – GIMSK
Bit765 4 3 210
$3B ($5B)INT1INT0––––––GIMSK
Read/WriteR/WR/WRRRRRR
Initial Value00000000
• Bit 7 – INT1: External Interrupt Request 1 Enable
When the INT1 bit is set (one) and the I-bit in the Status Register (SREG) is set (one), the external pin interrupt is enabled. The Interrupt Sense Control1 bits 1/0 (ISC11 and ISC10) in the MCU
general Control Register (MCUCR) defines whether the external interrupt is activated on rising
or falling edge of the INT1 pin or level sensed. Activity on the pin will cause an interrupt request
even if INT1 is configured as an output. The corresponding interrupt of External Interrupt
Request 1 is executed from program memory address $004. See also “External Interrupts” on
When the INT0 bit is set (one) and the I-bit in the Status Register (SREG) is set (one), the external pin interrupt is enabled. The Interrupt Sense Control0 bits 1/0 (ISC01 and ISC00) in the MCU
general Control Register (MCUCR) defines whether the external interrupt is activated on rising
or falling edge of the INT0 pin or level sensed. Activity on the pin will cause an interrupt request
even if INT0 is configured as an output. The corresponding interrupt of Interrupt Request 0 is
executed from program memory address $002. See also “External Interrupts” on page 29.
26
AT43USB325
3355C–USB–4/05
AT43USB325
• Bits 5..0 – Res: Reserved Bits
These bits are reserved bits in the AT43USB325 and always read as zero.
4.9.2General Interrupt Flag Register – GIFR
Bit 76543210
$3A ($5A)INTF1INT F0––––––GIFR
Read/WriteR/WR/WRRRRRR
Initial Value00000000
• Bit 7 – INTF1: External Interrupt Flag1
When an event on the INT1 pin triggers an interrupt request, INTF1 becomes set (one). If the Ibit in SREG and the INT1 bit in GIMSK are set (one), the MCU will jump to the interrupt vector at
address $004. The flag is cleared when the interrupt routine is executed. Alternatively, the flag
can be cleared by writing a logical one to it.
• Bit 6 – INTF0: Interrupt Flag0 (Suspend/Resume Interrupt Flag)
When an event on the INT0 (that is, a USB event-related interrupt) triggers an interrupt request,
INTF0 becomes set (one). If the I-bit in SREG and the INT0 bit in GIMSK are set (one), the MCU
will jump to the interrupt vector at address $002. The flag is cleared when the interrupt routine is
executed. Alternatively, the flag can be cleared by writing a logical one to it.
• Bits 5..0 – Res: Reserved Bits
These bits are reserved bits in the AT43USB325 and always read as zero.
• Bit 7 – TOIE1: Timer/Counter1 Overflow Interrupt Enable
When the TOIE1 bit is set (one) and the I-bit in the Status Register is set (one), the
Timer/Counter1 Overflow interrupt is enabled. The corresponding interrupt (at vector $006) is
executed if an overflow in Timer/Counter1 occurs, i.e., when the TOV1 bit is set in the
Timer/Counter Interrupt Flag Register (TIFR).
• Bit 6 – OCE1A: Timer/Counter1 Output CompareA Match Interrupt Enable
When the OCIE1A bit is set (one) and the I-bit in the Status Register is set (one), the
Timer/Counter1 CompareA Match interrupt is enabled. The corresponding interrupt (at vector
$004) is executed if a CompareA match in Timer/Counter1 occurs, i.e., when the OCF1A bit is
set in the TIFR.
• Bit 5 – OCIE1B: Timer/Counter1 Output CompareB Match Interrupt Enable
When the OCIE1B bit is set (one) and the I-bit in the Status Register is set (one), the
Timer/Counter1 CompareB Match interrupt is enabled. The corresponding interrupt (at vector
3355C–USB–4/05
27
$005) is executed if a CompareB match in Timer/Counter1 occurs, i.e., when the OCF1B bit is
set in the TIFR.
• Bit 4 – Res: Reserved Bit
This bit is a reserved bit in the AT43USB325 and always reads zero.
• Bit 3 – TICIE1: Timer/Counter1 Input Capture Interrupt Enable
When the TICIE1 bit is set (one) and the I-bit in the Status Register is set (one), the
Timer/Counter1 Input Capture Event Interrupt is enabled. The corresponding interrupt (at vector
$003) is executed if a capture-triggering event occurs on pin 31, ICP, i.e., when the ICF1 bit is
set in the TIFR.
• Bit 2 – Res: Reserved Bit
This bit is a reserved bit in the AT43USB325 and always reads zero.
• Bit 1 – TOIE0: Timer/Counter0 Overflow Interrupt Enable
When the TOIE0 bit is set (one) and the I-bit in the Status Register is set (one), the
Timer/Counter0 Overflow interrupt is enabled. The corresponding interrupt (at vector $007) is
executed if an overflow in Timer/Counter0 occurs, i.e., when the TOV0 bit is set in the TIFR.
• Bit 0 – Res: Reserved Bit
This bit is a reserved bit in the AT43USB325 and always reads zero.
4.9.4Timer/Counter Interrupt Flag Register – TIFR
Bit765 4 3 210
$38 ($58)TOV1OCF1AOCIFB–ICF1–TOV0–TIFR
Read/WriteR/WR/WR/WRR/WRR/WR
Initial Value00000000
• Bit 7 – TOV1: Timer/Counter1 Overflow Flag
The TOV1 is set (one) when an overflow occurs in Timer/Counter1. TOV1 is cleared by the hardware when executing the corresponding interrupt handling vector. Alternatively, TOV1 is cleared
by writing a logic one to the flag. When the I-bit in SREG, and TOIE1 (Timer/Counter1 Overflow
Interrupt Enable), and TOV1 are set (one), the Timer/Counter1 Overflow Interrupt is executed. In
PWM mode, this bit is set when Timer/Counter1 changes counting direction at $0000.
• Bit 6 – OCF1A: Output Compare Flag 1A
The OCF1A bit is set (one) when compare match occurs between the Timer/Counter1 and the
data in OCR1A - Output Compare Register 1A. OCF1A is cleared by the hardware when executing the corresponding interrupt handling vector. Alternatively, OCF1A is cleared by writing a
logic one to the flag. When the I-bit in SREG, and OCIE1A (Timer/Counter1 Compare match
InterruptA Enable), and the OCF1A are set (one), the Timer/Counter1 Compare A match Interrupt is executed.
• Bit 5 – OCF1B: Output Compare Flag 1B
The OCF1B bit is set (one) when compare match occurs between the Timer/Counter1 and the
data in OCR1B - Output Compare Register 1B. OCF1B is cleared by the hardware when execut-
28
AT43USB325
3355C–USB–4/05
AT43USB325
ing the corresponding interrupt handling vector. Alternatively, OCF1B is cleared by writing a
logic one to the flag. When the I-bit in SREG, and OCIE1B (Timer/Counter1 Compare match
InterruptB Enable), and the OCF1B are set (one), the Timer/Counter1 Compare B match Interrupt is executed.
• Bit 4 – Res: Reserved Bit
This bit is a reserved bit in the AT43USB325 and always reads zero.
• Bit 3 – ICF1: - Input Capture Flag 1
The ICF1 bit is set (one) to flag an input capture event, indicating that the Timer/Counter1 value
has been transferred to the input capture register - ICR1. ICF1 is cleared by the hardware when
executing the corresponding interrupt handling vector. Alternatively, ICF1 is cleared by writing a
logic one to the flag. When the SREG I-bit, and TICIE1 (Timer/Counter1 Input Capture Interrupt
Enable), and ICF1 are set (one), the Timer/Counter1 Capture Interrupt is executed.
• Bit 2 – Res: Reserved Bit
This bit is a reserved bit in the AT43USB325 and always reads zero.
• Bit 1 – TOV: Timer/Counter0 Overflow Flag
The bit TOV0 is set (one) when an overflow occurs in Timer/Counter0. TOV0 is cleared by the
hardware when executing the corresponding interrupt handling vector. Alternatively, TOV0 is
cleared by writing a logic one to the flag. When the SREG I- bit, and TOIE0 (Timer/Counter0
Overflow Interrupt Enable), and TOV0 are set (one), the Timer/Counter0 Overflow interrupt is
executed.
• Bit 0 – Res: Reserved Bit
This bit is a reserved bit in the AT43USB325 and always reads zero.
4.10External Interrupts
The external interrupts are triggered by the INT1 and INTA/B/C/D pins. Observe that, if enabled,
the INT1 interrupt will trigger even if the INT1 pin is configured as an output. This feature provides a way of generating a software interrupt. A falling or rising edge or a low level can trigger
the external interrupts. This is set up as indicated in the specification for the MCU Control Register – MCUCR and the Interrupt Sense Control Register – ISCR. When INT1 is enabled and is
configured as level triggered, the interrupt will trigger as long as the pin is held low. INT1 is set
up as described in the specification for the MCU Control Register – MCUCR.
4.11Interrupt Response Time
The interrupt execution response for all the enabled AVR interrupts is 4 clock cycles minimum. 4
clock cycles after the interrupt flag has been set, the program vector address for the actual interrupt handling routine is executed. During this 4 clock cycle period, the Program Counter (2
bytes) is pushed onto the Stack, and the Stack Pointer is decremented by 2. The vector is normally a jump to the interrupt routine, and this jump takes 3 clock cycles. If an interrupt occurs
during execution of a multi-cycle instruction, this instruction is completed before the interrupt is
served.
A return from an interrupt handling routine (same as for a subroutine call routine) takes 4 clock
cycles. During these 4 clock cycles, the Program Counter (2 bytes) is popped back from the
Stack, the Stack Pointer is incremented by 2, and the I flag in SREG is set. When the AVR exits
3355C–USB–4/05
29
from an interrupt, it will always return to the main program and execute one more instruction
before any pending interrupt is served.
4.11.1MCU Control Register – MCUCR
Bit76543210
$35 ($55)––SESMISC11ISC10––MCUCR
Read/WriteRRR/WR/WR/WR/WRR
Initial Value00000000
• Bit 7, 6 – Res: Reserved Bits
• Bit 5 – SE: Sleep Enable
The SE bit must be set (1) to make the MCU enter the sleep mode when the SLEEP instruction
is executed. To avoid the MCU entering the sleep mode, unless it is the programmer's purpose,
it is recommended to set the Sleep Enable SE bit just before the execution of the SLEEP
instruction.
• Bit 4 – SM: Sleep Mode
This bit selects between the two available sleep modes. When SM is cleared (zero), Idle Mode is
selected as Sleep Mode. When SM is set (1), Power Down mode is selected as sleep mode. The
AT43USB325 does not support the Idle Mode and SM should always be set to one when entering the Sleep Mode.
• Bit 3, 2 – ISC11, ISC10: Interrupt Sense Control 1 Bit 1 and Bit 0
The External Interrupt 1 is activated by the external pin INT1 if the SREG I-flag and the corresponding interrupt mask in the GIMSK is set. The level and edges on the external INT1 pin that
activate the interrupt are defined in the following table:
Table 4-2.INT1 Sense Control
ISC11ISC10Description
00The low level of INT1 generates an interrupt request.
01Reserved.
10The falling edge of INT1 generates an interrupt request.
11The rising edge of INT1 generates an interrupt request.
30
AT43USB325
3355C–USB–4/05
4.12USB Interrupt Sources
The USB interrupts are described below.
Table 4-3.USB Interrupt Sources
InterruptDescription
SOF Received
EOF2
Function EP0 Interrupt
Function EP1 Interrupt
Function EP2 Interrupt
AT43USB325
Whenever USB hardware decodes a valid Start of Frame. The
frame number is stored in the two Frame Number Registers.
Activated whenever the hub's frame timer reaches its EOF2 time
point.
See “Control Transfers at Control End-point EP0” on page 64 for
details.
For an OUT endpoint it indicates that Function Endpoint 1 has
received a valid OUT packet and that the data is in the FIFO. For
an IN endpoint it means that the endpoint has received an IN
token, sent out the data in the FIFO and received an ACK from the
Host. The FIFO is now ready to be written by new data from the
microcontroller.
For an OUT endpoint it indicates that Function Endpoint 2 has
received a valid OUT packet and that the data is in the FIFO. For
an IN endpoint it means that the endpoint has received an IN
token, sent out the data in the FIFO and received an ACK from the
Host. The FIFO is now ready to be written by new data from the
microcontroller.
For an OUT end-point it indicates that Function End-point 3 has
received a valid OUT packet and that the data is in the FIFO. For
Function EP3 Interrupt
Hub EP0 Interrupt
FRWUP
GLB SUSP
RSM
BUS RESET
an IN end-point it means that the end-point has received an IN
token, sent out the data in the FIFO and received an ACK from the
Host. The FIFO is now ready to be written by new data from the
microcontroller.
See “Control Transfers at Control End-point EP0” on page 64 for
details.
USB hardware has received a embedded function remote wakeup
request.
USB hardware has received global suspend signaling and is
preparing to put the hub in the suspend mode. The
microcontroller's firmware should place the embedded function in
the suspend state.
USB hardware received resume signaling and is propagating the
resume signaling. The microcontroller's firmware should take the
embedded function out of the suspended state.
USB hardware received a USB bus reset. This applies only in
cases where a separation between USB bus reset and
microcontroller reset is required. Be very careful when using this
feature.
All interrupts have individual enable, status, and mask bits through the interrupt enable register
and interrupt mask register. The Suspend and Resume interrupts are cleared by writing a 0 to
the particular interrupt bit. All other interrupts are cleared when the microcontroller sets a bit in
an interrupt acknowledge register.
3355C–USB–4/05
31
4.13USB Endpoint Interrupt Sources
An assertion or activation of one or more bits in the endpoint's Control and Status Register triggers the endpoint interrupts. These triggers are different for control and non-control endpoints as
described in the table below. Please refer to the Control and Status Register for more
information.
This bit is asserted after the USB hardware receives a valid SOF packet.
• Bit 6 – EOF2 INT: EOF2 Interrupt
This bit is asserted 10 clocks before the expected start of a frame.
• Bit 5 – Res: Reserved Bit
This bit is reserved and always reads as zero.
• Bit 4 – FEP3 INT: Function End-point 3 Interrupt
• Bit 3 – HEP0 INT: Hub Endpoint 0 Interrupt
• Bit 2 – FEP2 INT: Function Endpoint 2 Interrupt
• Bit 1 – FEP1 INT: Function Endpoint 1 Interrupt
• Bit 0 – FEP0 INT: Function Endpoint 0 Interrupt
The hub and function interrupt bits will be set by the hardware whenever the following bits in the
corresponding endpoint's Control and Status Register are modified by the USB hardware:
1. RX OUT Packet is set (control and OUT endpoints)
2. TX Packet Ready is cleared AND TX Complete is set (control and IN endpoints)
When the SOF IE bit is set (1), the Start of Frame Interrupt is enabled.
• Bit 6 – EOF2 IE: Enable EOF2 Interrupt
When the EOF2 IE bit is set (1), the EOF2 Interrupt is enabled.
• Bit 5 – Res: Reserved bit
This bit is reserved and always read as zero.
• Bit 4 – FEP3 IE: Enable Function End-point 3 Interrupt
When the FE3 IE bit is set (1), the Function End-point 3 Interrupt is enabled.
• Bit 3 – HEP0 IE: Enable Endpoint 0 Interrupt
When the HEP0 IE bit is set (1), the Hub Endpoint 0 Interrupt is enabled.
AT43USB325
• Bit 2 – FEP2 IE: Enable Endpoint 2 Interrupt
When the FE2 IE bit is set (1), the Function Endpoint 2 Interrupt is enabled.
• Bit 1 – FEP1 IE: Enable Endpoint 1 Interrupt
When the FE1 IE bit is set (1), the Function Endpoint 1 Interrupt is enabled.
• Bit 0 – FEP0 IE: Enable Endpoint 0 Interrupt
When the FE0 IE bit is set (1), the Function Endpoint 0 Interrupt is enabled.
3355C–USB–4/05
35
4.13.5Suspend/Resume Register – SPRSR
Bit76543210
$1FFAINTDINTCINTBINTABUS INTFRWUPRSMGLB SUSPSPRSR
Read/WriteRRRRR/WRRR
Initial Value00000000
• Bit 7 – INTD: External Interrupt D
The INTD bit is set when an external interrupt at the INTD pin is detected.
• Bit 6 – INTC: External Interrupt C
The INTC bit is set when an external interrupt at the INTC pin is detected.
• Bit 5 – INTB: External Interrupt B
The INTB bit is set when an external interrupt at the INTB pin is detected.
• Bit 4 – INTA: External Interrupt A
The INTA bit is set when an external interrupt at the INTA pin is detected.
Note:INTA/B/C/D cannot be used to wake up the AT43USB325 from the suspend state.
• Bit 3 – BUS INT: USB Bus Interrupt
When the USB reset separation feature is enabled (= SPRSIE and SPRSMSK bits 3 are set
to 1) the BUS INT bit is set when USB bus reset is detected by the USB hardware.
• Bit 2 – FRWUP: Function Remote Wakeup
The USB hardware sets this bit to signal that a key depression is detected indicating remote
wakeup. An interrupt is generated if the FRWUP IE bit of the SPRSIE register is set.
• Bit 1 – RSM: Resume
The USB hardware sets this bit when a USB resume signaling is detected at any of its port
except Port 1. An interrupt is generated if the RSM IE bit of the SPRSIE register is set.
• Bit 0 – GLB SUSP: Global Suspend
The USB hardware sets this bit when a USB global suspend signaling is detected. An interrupt is
generated if the GLBSUSP IE bit of the SPRSIE register is set.
Setting the INTD EN bit will initiate an interrupt whenever the INTD bit of SPRSR is set.
• · Bit 6 – INTC EN: External Interrupt C Enable
Setting the INTC EN bit will initiate an interrupt whenever the INTC bit of SPRSR is set.
• · Bit 5 – INTB EN: External Interrupt B Enable
Setting the INTD EN bit will initiate an interrupt whenever the INTB bit of SPRSR is set.
• · Bit 4 – INTA EN: External Interrupt A Enable
Setting the INTD EN bit will initiate an interrupt whenever the INTA bit of SPRSR is set.
• · Bit 3 – BUS INT EN: USB Reset Interrupt Enable
When the BUS INT EN bit is set, the USB and µC resets are separated. A USB bus reset (SE0
for longer than 3 ms) will reset the USB hardware only and not the µC. However, an interrupt to
the µC will be generated and bit 3 of SPRSR is set.
IE
RSM
IE
GLB
SUSP IE
SPRSIE
• · Bit 2 – FRWUP IE: Function Remote Wakeup Interrupt Enable
Setting the FRWUP IE bit will initiate an interrupt whenever the FRWUP bit of SPRSR is set.
• · Bit 1 – RSM IE: Resume Interrupt Enable
Setting the RSM IE bit will initiate an interrupt whenever the RSM bit of SPRSR is set.
• · Bit 0 – GLB SUSP IE: Global Suspend Interrupt Enable
Setting the GLB SUSP IE bit will initiate an interrupt whenever the GLB SUSP bit of SPRSR is
set.
The bits of the Suspend/Resume Mask Register are used to make an interrupt caused by an
event in the Suspend/Resume Register visible to the µC. The Suspend/Resume Interrupt
Enable Register bits enables the interrupt while the Suspend/Resume Interrupt Mask Register
allows the µC to control when it wants visibility to an interrupt. 1 = enable mask, 0 = disable
mask.
• Bit 7 – INTD MSK: External Interrupt D Mask
• Bit 6 – INTC MSK: External Interrupt C Mask
• Bit 5 – INTB MSK: External Interrupt B Mask
• Bit 4 – INTA MSK: External Interrupt A Mask
• Bit 3 – BUS INT MSK: USB Reset Interrupt Mask
BUS INT
MSK
FRWUP
MSK
RSM
MSK
GLB SUSP
MSK
SPRSMSK
• Bit 2 – FRWUP MSK: Function Remote Wakeup Interrupt Mask
• Bit 1 – RSM MSK: Resume Interrupt Mask
• Bit 0 – GLB SUSP MSK: Global Suspend Interrupt Enable
38
AT43USB325
3355C–USB–4/05
AT43USB325
4.13.8INTA/B/C/D Interrupt Sense Control Register – ISCR
Bit76543210
$1FF1ISC71ISC70ISC61ISC60ISC51ISC50ISC41ISC40ISCR
Read/WriteR/WR/WR/WR/WR/WR/WR/WR/W
Initial Value00000000
• Bit 7,6 – ISC71, ISC70: External Interrupt D Sense Control Bits
ISC71 and ISC70 controls the level and sense of the input at the INTD pin as defined below:
ISC71 ISC70 Description
00Low level of INTD
01Reserved
10Falling edge of INTD
11Rising edge of INTD
• Bit 5,4 – ISC61, ISC60: External Interrupt C Sense Control Bits
ISC71 and ISC70 controls the level and sense of the input at the INTC pin as defined below:
ISC61 ISC60 Description
00Low level of INTC
01Reserved
10Falling edge of INTC
11Rising edge of INTC
• Bit 3,2 – ISC51, ISC40: External Interrupt B Sense Control Bits
ISC51 and ISC50 controls the level and sense of the input at the INTB pin as defined below:
ISC51 ISC50 Description
00Low level of INTB
01Reserved
10Falling edge of INTB
11Rising edge of INTB
• Bit 1,0 – ISC41, ISC40: External Interrupt A Sense Control Bits
ISC41 and ISC40 controls the level and sense of the input at the INTA pin as defined below:
ISC41 ISC40 Description
00Low level of INTA
01Reserved
10Falling edge of INTA
3355C–USB–4/05
11Rising edge of INTA
39
5.AVR Register Set
5.1Status Register and Stack Pointer
5.1.1Status Register – SREG
Bit76543210
$3F ($5F)ITHSVNZCSREG
Read/WriteR/WR/WR/WR/WR/WR/WR/WR/W
Initial Value00000000
•Bit 7 – I: Global Interrupt Enable
The global interrupt enable bit must be set (one) for the interrupts to be enabled. The individual
interrupt enable control is then performed in separate control registers. If the global interrupt
enable bit is cleared (zero), none of the interrupts are enabled independent of the individual
interrupt enable settings. The I-bit is cleared by the hardware after an interrupt has occurred,
and is set by the RETI instruction to enable subsequent interrupts.
•Bit 6 – T: Bit Copy Storage
The bit copy instructions BLD (Bit LoaD) and BST (Bit STore) use the T bit as source and destination for the operated bit. A bit from a register in the register file can be copied into T by the
BST instruction, and a bit in T can be copied into a bit in a register in the register file by the BLD
instruction.
•Bit 5 – H: Half Carry Flag
The half carry flag H indicates a half carry in some arithmetic operations. See the Instruction Set
Description for detailed information.
•Bit 4 – S: Sign Bit, S = N⊕V
The S-bit is always an exclusive or between the negative flag N and the two's complement overflow flag V. See the Instruction Set Description for detailed information.
•Bit 3 – V: Two's Complement Overflow Flag
The two's complement overflow flag V supports two's complement arithmetics. See the Instruction Set Description for detailed information.
•Bit 2 – N: Negative Flag
The negative flag N indicates a negative result after the different arithmetic and logic operations.
See the Instruction Set Description for detailed information.
•Bit 1 – Z: Zero Flag
The zero flag Z indicates a zero result after the different arithmetic and logic operations. See the
Instruction Set Description for detailed information.
•Bit 0 – C: Carry Flag
The carry flag C indicates a carry in an arithmetic or logic operation. See the Instruction Set
Description for detailed information.
Note that the status register is not automatically stored when entering an interrupt routine and
restored when returning from an interrupt routine. This must be handled by software.
40
AT43USB325
3355C–USB–4/05
AT43USB325
5.1.2Stack Pointer Register – SP
Bit 1514131211109 8
$3E ($5E)ITHSVNZCSPH
$3D ($5D)SP7SP6SP5SP4SP3SP2SP1SP0SPL
Read/WriteR/WR/WR/WR/WR/WR/WR/WR/W
Initial Value00000000
The Stack Pointer points to the data SRAM stack area where the Subroutine and Interrupt
Stacks are located. This Stack space in the data SRAM must be defined by the program before
any subroutine calls are executed or interrupts are enabled. The stack pointer must be set to
point above $60. The Stack Pointer is decremented by one when data is pushed onto the Stack
with the PUSH instruction, and it is decremented by two when an address is pushed onto the
Stack with subroutine calls and interrupts. The Stack Pointer is incremented by one when data is
popped from the Stack with the POP instruction and it is incremented by two when an address is
popped from the Stack with return from subroutine RET or return from interrupt RETI.
5.2Sleep Modes
To enter the sleep modes, the SE bit in MCUCR must be set (one) and a SLEEP instruction
must be executed. If an enabled interrupt occurs while the MCU is in a sleep mode, the MCU
awakes, executes the interrupt routine, and resumes execution from the instruction following
SLEEP. The contents of the register file, SRAM and I/O memory are unaltered. If a reset occurs
during sleep mode, the MCU wakes up and executes from the Reset vector.
76 5 4 3210
R/WR/WR/WR/WR/WR/WR/WR/W
00 0 0 0000
5.2.1Power Down Mode
When the SM bit is set (one), the SLEEP instruction forces the MCU into the Power Down Mode.
In this mode, the external oscillator is stopped, while the external interrupts continue operating.
Only an external reset, an external level interrupt on INT0 or INT1, can wake up the MCU.
Note that when a level triggered interrupt is used for wake-up from power down, the low level
must be held for a time longer than the reset delay time-out period t
will fail to wake up.
. Otherwise, the MCU
TOUT
3355C–USB–4/05
41
6.Timer/Counters
The AT43USB325 provides two general-purpose Timer/Counters - one 8-bit T/C and one 16-bit
T/C. The Timer/Counters have individual prescaling selection from the same 10-bit prescaling
timer. Both Timer/Counters can either be used as a timer with an internal clock time base or as a
counter with an external pin connection which triggers the counting.
6.1Timer/Counter Prescaler
The four different prescaled selections are: CK/8, CK/64, CK/256 and CK/1024 where CK is the
oscillator clock. For the two Timer/Counters, added selections as CK, external source and stop,
can be selected as clock sources.
Figure 6-1.Timer/Counter Prescaler
CK
T0
T1
CS10
CS11
CS12
10-bit T/C Prescaler
CK/8
0
CS00
CS01
CS02
CK/64
CK/256
CK/1024
0
42
Timer/Counter1 Clock Source
AT43USB325
TCK1
Timer/Counter0 Clock Source
TCK0
3355C–USB–4/05
6.28-bit Timer/Counter0
The 8-bit Timer/Counter0 can select clock source from CK, prescaled CK or an external pin. In
addition it can be stopped as described in the specification for the Timer/Counter0 Control Register (TCCR0). The overflow status flag is found in the Timer/Counter Interrupt Flag Register
(TIFR). Control signals are found in the Timer/Counter0 Control Register (TCCR0). The interrupt
enable/disable settings for Timer/Counter0 are found in the Timer/Counter Interrupt Mask Register - TIMSK.
When Timer/Counter0 is externally clocked, the external signal is synchronized with the oscillator frequency of the CPU. To assure proper sampling of the external clock, the minimum time
between two external clock transitions must be at least one internal CPU clock period. The
external clock signal is sampled on the rising edge of the internal CPU clock.
The 8-bit Timer/Counter0 features both a high resolution and a high accuracy usage with the
lower prescaling opportunities. Similarly, the high prescaling opportunities make the
Timer/Counter0 useful for lower speed functions or exact timing functions with infrequent
actions.
Figure 6-2.Timer/Counter0 Block Diagram
AT43USB325
T/C0
Overflow IRQ
8-bit Data Bus
TOIE1
OICIE1A
OICIE1B
TICIE1
TOIE0
Timer Int. Mask Register
(TIMSK)
70
Timer/Counter0
(TCNT0)
Timer Int. Flag Register
TOV1
OCF1A
T/C Clock Source
(TIFR)
OCF1B
TOV0
ICF1
T/C0 Control Register
(TCCR0)
CS02
CS01
TOV0
Control
Logic
CS00
CK
T0
3355C–USB–4/05
43
6.2.1Timer/Counter0 Control Register – TCCR0
Bit7654321 0
$33 ($53)–––––CS02CS01CS00TCCR0
Read/WriteRRRRRR/WR/WR/W
Initial Value00000000
• Bits 7..3 – Res: Reserved Bits
These bits are reserved bits in the AT43USB325 and always read as zero.
• Bits 2, 1, 0 – CS02, CS01, CS00: Clock Select0, bit 2, 1 and 0
The Clock Select0 bits 2, 1 and 0 define the prescaling source of Timer/Counter0.
Table 6-1.Clock 0 Prescale Select
CS02CS01CS00Description
000Stop, the Timer/Counter0 is stopped
001CK
010CK/8
011CK/64
100CK/256
101CK/1024
110External Pin T0, falling edge
111External Pin T0, rising edge
The Stop condition provides a Timer Enable/Disable function. The CK down divided modes are
scaled directly from the CK oscillator clock. If the external pin modes are used for
Timer/Counter0, transitions on PB0/(T0) will clock the counter even if the pin is configured as an
output. This feature can give the user SW control of the counting.
6.2.2Timer/Counter0 – TCNT0
Bit 76543210
$32 ($52)MSB––––––LSBTCNT0
Read/WriteR/WR/WR/WR/WR/WR/WR/WR/W
Initial Value00000000
The Timer/Counter0 is realized as an up-counter with read and write access. If the
Timer/Counter0 is written and a clock source is present, the Timer/Counter0 continues counting
in the clock cycle following the write operation.
44
AT43USB325
3355C–USB–4/05
6.316-bit Timer/Counter1
Figure 6-3.Timer/Counter1 Block Diagram
AT43USB325
T/C1
OVERFLOW IRQ
TOIE1
OCIE1A
OCIE1B
TICIE1
8-BIT DATA BUS
TIMER INT. MASK
REGISTER (TIMSK)
15
T/C1 INPUT CAPTURE REGISTER (ICR1)
TOIE0
8
T/C1 COMPARE
MATCHA IRQ
TOV1
OCF1A
OCF1B
TIMER INT. FLAG
REGISTER (TIFR)
TOV1
OCF1A
OCF1B
7
T/C1 COMPARE
MATCHB IRQ
ICF1
TOV0
ICF1
CAPTURE
TRIGGER
T/C1 CONTROL
REGISTER A (TCCR1A)
COM1A1
COM1A0
COM1B1
0
T/C1INPUT
CAPTURE IRQ
COM1B0
PWM11
T/C1 CONTROL
REGISTER B (TCCR1B)
ICES1
ICNC1
PWM10
CONTROL
LOGIC
CS12
CTC1
CS11
CS10
CK
T1
7
15
TIMER/COUNTER1 (TCNT1)
15
16-BIT COMPARATOR
15
TIMER/COUNTER1 OUTPUT COMPARE REGISTER A
8
7
8
7
8
0
0
15
16-BIT COMPARATOR
0
TIMER/COUNTER1 OUTPUT COMPARE REGISTER B
78
7
815
0
0
3355C–USB–4/05
45
6.416-bit Timer/Counter1 Operation
The 16-bit Timer/Counter1 can select clock source from CK, prescaled CK or an external pin. In
addition, it can be stopped as described in the specification for the Timer/Counter1 Control Registers (TCCR1A and TCCR1B). The different status flags (overflow, compare match and capture
event) are found in the Timer/Counter Interrupt Flag Register (TIFR). Control signals are found
in the Timer/Counter1 Control Registers (TCCR1A and TCCR1B). The interrupt enable/disable
settings for Timer/Counter1 are found in the Timer/Counter Interrupt Mask Register (TIMSK).
When Timer/Counter1 is externally clocked, the external signal is synchronized with the oscillator frequency of the CPU. To assure proper sampling of the external clock, the minimum time
between two external clock transitions must be at least one internal CPU clock period. The
external clock signal is sampled on the rising edge of the internal CPU clock.
The 16-bit Timer/Counter1 features both a high resolution and a high accuracy usage with the
lower prescaling opportunities. Similarly, the high prescaling opportunities makes the
Timer/Counter1 useful for lower speed functions or exact timing functions with infrequent
actions.
The Timer/Counter1 supports two Output Compare functions using the Output Compare Register 1 A and B (OCR1A and OCR1B) as the data sources to be compared to the Timer/Counter1
contents. The Output Compare functions include optional clearing of the counter on compareA
match, and actions on the Output Compare pins on both compare matches.
Timer/Counter1 can also be used as a 8-, 9- or 10-bit Pulse With Modulator. In this mode the
counter and the OCR1A/OCR1B registers serve as a dual glitch-free stand-alone PWM with
centered pulses.
The Input Capture function of Timer/Counter1 provides a capture of the Timer/Counter1 contents to the Input Capture Register - ICR1, triggered by an external event on the Input Capture
Pin (ICP/PF3). The actual capture event settings are defined by the Timer/Counter1 Control
Register (TCCR1B). The AT43USB325 has no analog comparator and the mux control signal,
ACO, is permanently set so that the ICP input is routed to the noise canceler.
If the noise canceler function is enabled, the actual trigger condition for the capture event is
monitored over 4 samples, and all 4 must be equal to activate the capture flag.
Figure 6-4.ICP Pin Schematic Diagram
0
ICP
1
ACIC: COMPARATOR IC ENABLE
ACC0: COMPARATOR OUTPUT
The COM1A1 and COM1A0 control bits determine any output pin action following a compare
match in Timer/Counter1. Any output pin actions affect pin OC1A (Output CompareA) pin 1. This
is an alternative function to an I/O port and the corresponding direction control bit must be set
(one) to control the output pin. The control configuration is shown in Table 6-2.
The COM1B1 and COM1B0 control bits determine any output pin action following a compare
match in Timer/Counter1. Any output pin actions affect pin OC1B (Output CompareB). The following control configuration is given:
Table 6-2.Compare 1 Mode Select
COM1X1COM1X0Description
00Timer/Counter1 disconnected from output pin OC1X.
01Toggle the OC1X output line.
10Clear the OC1X output line (to zero).
11Set the OC1X output line (to one).
(2)
(1)
(1)
(1)
(1)
Note:1. X = A or B
2. In PWM mode, these bits have a different function. Refer to Table 6-6 for a detailed
description.
• Bits 3..2 – Res: Reserved Bits
These bits are reserved bits in the AT43USB325 and always read zero.
When the ICNC1 bit is cleared (zero), the input capture trigger noise canceler function is disabled. The input capture is triggered at the first rising/falling edge sampled on the ICP (input
capture pin) as specified. When the ICNC1 bit is set (one), four successive samples are measured on the ICP and all samples must be high/low according to the input capture trigger
specification in the ICES1 bit. The actual sampling frequency is the 12 MHz system clock
frequency.
•Bit 6 – ICES1: Input Capture1 Edge Select
While the ICES1 bit is cleared (zero), the Timer/Counter1 contents are transferred to the Input
Capture Register (ICR1) on the falling edge of the ICP. While the ICES1 bit is set (one), the
Timer/Counter1 contents are transferred to the ICR1 on the rising edge of the ICP.
• Bits 5, 4 – Res: Reserved Bits
These bits are reserved bits in the AT43USB325 and always read zero.
•Bit 3 – CTC1: Clear Timer/Counter1 on Compare Match
When the CTC1 control bit is set (one), the Timer/Counter1 is reset to $0000 in the clock cycle
after a compareA match. If the CTC1 control bit is cleared, Timer/Counter1 continues counting
and is unaffected by a compare match. Since the compare match is detected in the CPU clock
cycle following the match, this function will behave differently when a prescaling higher than 1 is
used for the timer. When a prescaling of 1 is used, and the compareA register is set to C, the
timer will count as follows if CTC1 is set:
... | C-2 | C-1 | C | 0 | 1 | ...
When the prescaler is set to divide by 8, the timer will count like this:
• Bits 2, 1, 0 – CS12, CS11, CS10: Clock Select1, Bit 2, 1 and 0
The Clock Select1 bits 2, 1 and 0 define the prescaling source of Timer/Counter1.
Table 6-4.Clock 1 Prescale Select
CS12CS11CS10Description
000Stop, the Timer/Counter1 is stopped.
001CK
010CK/8
011CK/64
100CK/256
48
AT43USB325
3355C–USB–4/05
AT43USB325
Table 6-4.Clock 1 Prescale Select (Continued)
CS12CS11CS10Description
101CK/1024
110External Pin T1, falling edge
111External Pin T1, rising edge
The Stop condition provides a Timer Enable/Disable function. The CK down divided modes are
scaled directly from the 12 MHz system clock. If the external pin modes are used for
Timer/Counter1, transitions on PB1/(T1) will clock the counter even if the pin is configured as an
output. This feature can give the user SW control of the counting.
6.4.3Timer/Counter1 – TCNT1H and TCNT1L
Bit15141312111098
$2D ($4D)MSB–––––––TCNT1H
$2C ($4C)–––––––LSBTCNT1L
76 5 4 3210
Read/WriteR/WR/WR/WR/WR/WR/WR/WR/W
R/WR/WR/WR/WR/WR/WR/WR/W
Initial Value00000000
00 0 0 0000
This 16-bit register contains the prescaled value of the 16-bit Timer/Counter1. 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 register (TEMP). This temporary register is also used when accessing OCR1A, OCR1B and ICR1. If the main program and also
interrupt routines perform access to registers using TEMP, interrupts must be disabled during
access from the main program and from interrupt routines if interrupts are allowed from within
interrupt routines.
• TCNT1 Timer/Counter1 Write:
When the CPU writes to the high byte TCNT1H, the written data is placed in the TEMP register.
Next, when the CPU writes the low byte TCNT1L, this byte of data is combined with the byte
data in the TEMP register, and all 16 bits are written to the TCNT1 Timer/Counter1 register
simultaneously. Consequently, the high byte TCNT1H must be accessed first for a full 16-bit register write operation.
3355C–USB–4/05
• TCNT1 Timer/Counter1 Read:
When the CPU reads the low byte TCNT1L, the data of the low byte TCNT1L is sent to the CPU
and the data of the high byte TCNT1H is placed in the TEMP register. When the CPU reads the
data in the high byte TCNT1H, the CPU receives the data in the TEMP register. Consequently,
the low byte TCNT1L must be accessed first for a full 16-bit register read operation.
The Timer/Counter1 is realized as an up or up/down (in PWM mode) counter with read and write
access. If Timer/Counter1 is written to and a clock source is selected, the Timer/Counter1 continues counting in the timer clock cycle after it is preset with the written value.
49
6.4.4Timer/Counter1 Output Compare Register – OCR1AH and OCR1AL
Bit 1514131211109 8
$2B ($4B)MSB–––––––OCR1AH
$2A ($4A)–––––––LSBOCR1AL
76 5 4 3210
Read/WriteR/WR/WR/WR/WR/WR/WR/WR/W
R/WR/WR/WR/WR/WR/WR/WR/W
Initial Value00000000
00 0 0 0000
6.4.5Timer/Counter1 Output Compare Register – OCR1BH and OCR1BL
Bit 1514131211109 8
$29 ($49)MSB–––––––OCR1BH
$28 ($48)–––––––LSBOCR1BL
76543210
Read/WriteR/WR/WR/WR/WR/WR/WR/WR/W
R/WR/WR/WR/WR/WR/WR/WR/W
Initial Value00000000
00000000
The output compare registers are 16-bit read/write registers.
The Timer/Counter1 Output Compare Registers contain the data to be continuously compared
with Timer/Counter1. Actions on compare matches are specified in the Timer/Counter1 Control
and Status register.A compare match does only occur if Timer/Counter1 counts to the OCR
value. A software write that sets TCNT1 and OCR1A or OCR1B to the same value does not generate a compare match.
A compare match will set the compare interrupt flag in the CPU clock cycle following the compare event.
Since the Output Compare Registers OCR1A and OCR1B are 16-bit registers, a temporary register TEMP is used when OCR1A/B are written to ensure that both bytes are updated
simultaneously. When the CPU writes the high byte, OCR1AH or OCR1BH, the data is temporarily stored in the TEMP register. When the CPU writes the low byte, OCR1AL or OCR1BL, the
TEMP register is simultaneously written to OCR1AH or OCR1BH. Consequently, the high byte
OCR1AH or OCR1BH must be written first for a full 16-bit register write operation.
50
The TEMP register is also used when accessing TCNT1, and ICR1. If the main program and
also interrupt routines perform access to registers using TEMP, interrupts must be disabled during access from the main program and from interrupt routines if interrupts are allowed from
within interrupt routines.
AT43USB325
3355C–USB–4/05
AT43USB325
6.4.6Timer/Counter1 Input Capture Register – ICR1H and ICR1L
Bit 1514131211109 8
$25 ($45)MSB–––––––ICR1H
$24 ($44)–––––––LSBICR1L
76 5 4 3210
Read/WriteRRRRRRRR
RRRRRRRR
Initial Value00000000
00 0 0 0000
The input capture register is a 16-bit read-only register.
When the rising or falling edge (according to the input capture edge setting - ICES1) of the signal at the input capture pin (ICP) is detected, the current value of the Timer/Counter1 is
transferred to the Input Capture Register (ICR1). At the same time, the Input Capture Flag
(ICF1) is set (one).
Since the ICR1 is a 16-bit register, a temporary register TEMP is used when ICR1 is read to
ensure that both bytes are read simultaneously. When the CPU reads the low byte ICR1L, the
data is sent to the CPU and the data of the high byte ICR1H is placed in the TEMP register.
When the CPU reads the data in the high byte ICR1H, the CPU receives the data in the TEMP
register. Consequently, the low byte ICR1L must be accessed first for a full 16-bit register read
operation.
The TEMP register is also used when accessing TCNT1, OCR1A and OCR1B. If the main program and also interrupt routines perform access to registers using TEMP, interrupts must be
disabled during access from the main program and from interrupt routines, if interrupts are
allowed from within interrupt routines.
6.4.7Timer/Counter1 In PWM Mode
When the PWM mode is selected, Timer/Counter1, the Output Compare Register1A (OCR1A)
and the Output Compare Register1B (OCR1B) form a dual 8-, 9- or 10-bit, free-running, glitchfree and phase correct PWM with outputs on the PD5 (OC1A) and OC1B pins. Timer/Counter1
acts as an up/down counter, counting up from $0000 to TOP (see Table 6-5), where it turns and
counts down again to zero before the cycle is repeated. When the counter value matches the
contents of the 10 least significant bits of OCR1A or OCR1B, the PD5(OC1A)/OC1B pins are set
or cleared according to the settings of the COM1A1/COM1A0 or COM1B1/COM1B0 bits in the
Timer/Counter1 Control Register TCCR1A. Refer to Table 6-6 for details.
Table 6-5.Timer TOP Values and PWM Frequency
PWM ResolutionTimer TOP valueFrequency
8-bit$00FF (255)f
9-bit$01FF (511)f
10-bit$03FF(1023)f
TCK1
TCK1
TCK1
/510
/1022
/2046
3355C–USB–4/05
51
Table 6-6.Compare1 Mode Select in PWM Mode
COM1X1COM1X0Effect on OCX1
00Not connected
01Not connected
10
11
Note:X = A or B
Note that in the PWM mode, the 10 least significant OCR1A/OCR1B bits, when written, are
transferred to a temporary location. They are latched when Timer/Counter1 reaches the value
TOP. This prevents the occurrence of odd-length PWM pulses (glitches) in the event of an
unsynchronized OCR1A/OCR1B write. See Figure 6-5 for an example.
Figure 6-5.Effects on Unsynchronized OCR1 Latching
Cleared on compare match, up-counting. Set on compare match,
down-counting (non-inverted PWM).
Cleared on compare match, down-counting. Set on compare match,
up-counting (inverted PWM).
Compare Value Changes
Counter Value
Compare Value
SynchronizedOCR1X Latch
UnsynchronizedOCR1X Latch
Note:X = A or B
PWM Output OC1X
Compare Value Changes
Counter Value
Compare Value
PWM Output OC1X
Glitch
During the time between the write and the latch operation, a read from OCR1A or OCR1B will
read the contents of the temporary location. This means that the most recently written value
always will read out of OCR1A/B
When the OCR1 contains $0000 or TOP, the output OC1A/OC1B is updated to low or high on
the next compare match, according to the settings of COM1A1/COM1A0 or COM1B1/COM1B0.
This is shown in Table 6-7.
Note: If the compare register contains the TOP value and the prescaler is not in use
(CS12..CS10 = 001), the PWM output will not produce any pulse at all, because up-counting and
down-counting values are reached simultaneously. When the prescaler is in use (CS12..CS10 =
001 or 000), the PWM output goes active when the counter reaches the TOP value, but the
52
AT43USB325
3355C–USB–4/05
down-counting compare match is not interpreted to be reached before the next time the counter
reaches the TOP value, making a one-period PWM pulse.
Table 6-7.PWM Outputs OCR1X = $0000 or Top
Note:X = A or B
In PWM mode, the Timer Overflow Flag1, TOV1, is set when the counter advances from $0000.
Timer Overflow Interrupt1 operates exactly as in normal Timer/Counter mode, i.e. it is executed
when TOV1 is set provided that Timer Overflow Interrupt1 and global interrupts are enabled.
This also applies to the Timer Output Compare1 flags and interrupts.
6.5Watchdog Timer
The Watchdog Timer is clocked from a 1 MHz clock derived from the 6 MHz on chip oscillator.
By controlling the Watchdog Timer prescaler, the Watchdog reset interval can be adjusted, see
Table 6-8 for a detailed description. The WDR (Watchdog Reset) instruction resets the Watch-
dog Timer. Eight different clock cycle periods can be selected to determine the reset period. If
the reset period expires without another Watchdog reset, the AT43USB325 resets and executes
from the reset vector.
AT43USB325
COM1X1COM1X0OCR1XOutput OC1X
10$0000L
10TOPH
11$0000H
11TOPL
To prevent unintentional disabling of the watchdog, a special turn-off sequence must be followed
when the watchdog is disabled. Refer to the description of the Watchdog Timer Control Register
for details.
Figure 6-6.Watchdog Timer
1 MHz Clock
Watchdog
Reset
OSC/8K
WDP0
WDP1
WDP2
WDE
Watchdog Prescaler
OSC/16K
OSC/32K
OSC/64K
OSC/128K
OSC/256K
OSC/512K
OSC/1024K
3355C–USB–4/05
MCU Reset
53
6.5.1Watch Dog Timer Control Register – WDTCR
Bit76543210
$21 ($41)–––WDTOEWDEWDP2WDP1WDP0WDTCR
Read/WriteRRRR/WR/WR/WR/WR/W
Initial Value00000000
• Bits 7..5 – Res: Reserved Bits
These bits are reserved bits in the AT43USB325 and will always read as zero.
•Bit 4 – WDTOE: Watch Dog Turn-Off Enable
This bit must be set (one) when the WDE bit is cleared. Otherwise, the watchdog will not be disabled. Once set, the hardware will clear this bit to zero after four clock cycles. Refer to the
description of the WDE bit for a watchdog disable procedure.
•Bit 3 – WDE: Watch Dog Enable
When the WDE is set (one) the Watchdog Timer is enabled, and if the WDE is cleared (zero) the
Watchdog Timer function is disabled. WDE can only be cleared if the WDTOE bit is set (one). To
disable an enabled watchdog timer, the following procedure must be followed:
1. In the same operation, write a logical one to WDTOE and WDE. A logical one must be
written to WDE even though it is set to one before the disable operation starts.
2. Within the next four clock cycles, write a logical 0 to WDE. This disables the watchdog.
• Bits 2..0 – WDP2, WDP1, WDP0: Watch Dog Timer Prescaler 2, 1 and 0
The WDP2, WDP1 and WDP0 bits determine the Watchdog Timer prescaling when the Watchdog Timer is enabled. The different prescaling values and their corresponding Time-out Periods
are shown in Table 6-8.
Table 6-8.Watchdog Timer Prescale Select
WDP2WDP1WDP0Number of WDT Oscillator cyclesTime-out
0008K cycles8.2 ms
00116K cycles16.4 ms
01032K cycles33.8 ms
01164K cycles65.6 ms
100128K cycles0.131 s
101256K cycles0.262 s
110512K cycles0.524 s
1111,024K cycles1.048 s
Note:The WDR (Watchdog Reset) instruction should always be executed before the Watchdog Timer is
enabled. This ensures that the reset period will be in accordance with the Watchdog Timer prescale settings. If the Watchdog Timer is enabled without reset, the watchdog timer may not start to
count from zero. To avoid unintentional MCU reset, the Watchdog Timer should be disabled or
reset before changing the Watchdog Timer Prescale Select.
54
AT43USB325
3355C–USB–4/05
7.I/O Ports
AT43USB325
All GPIO 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 for changing
drive value if configured as output or enabling/disabling of pull-up resistors if configured as input.
The keyboard matrix strobe output pins, PA[0:7], PB[0:7] and PE[0:3] have controlled slope drivers. With a load of 100 pF, the output fall time ranges between 75 ns and 300 ns. The keyboard
matrix strobe input pins, PC[0:7] have When the FE3 IMSK bit is set (1), the Function End-point
3 Interrupt is masked.
PE[4:7] have 5V tolerant outputs and each has a built-in series resistor of 330Ω nominal value.
These output pins are designed for driving an LED connected to the 5V supply.
The dedicated functions are summarized in Table 7-1.
Table 7-1.GPIO Function Assignments
FunctionGPIO
Scan out[0:7]PA[0:7]
Scan out[8:15]PB[0:7]
Scan out[16:19]PE[0:3]
Scan in[0:7]PC[0:7]
LED driversPE[4:7]
EEPROM InterfacePF[1:3]
In the AT43USB325E Port F[0:3] are used as the SPI signals for the external serial EEPROM.
Once the data from the SEEPROM are loaded to the SRAM, Port F[1:3] become available as
GPIO pins. Only cycling the power to the chip off and on again will temporarily assign these pins
as EEPOM signals.
3355C–USB–4/05
55
7.1Port A
Port A is an 8-bit bi-directional I/O port with open drain outputs and controlled slew rate. It is
designed for use as the column driver in a keyboard controller. The Port A output buffers can
sink or source 4 mA.
Three I/O memory address locations are allocated for the Port A, one each for the Data Register
PORTA, $1B($3B), Data Direction Register (DDRA), $1A($3A) and the Port A Input Pins (PINA)
$19($39). The Port A Input Pins address is read only, while the Data Register and the Data
Direction Register are read/write.
The Port A Input Pins address (PINA) is not a register, and this address enables access to the
physical value on each Port A pin. When reading PORTA the Port A Data Latch is read, and
when reading PINA, the logical values present on the pins are read.
AT43USB325
3355C–USB–4/05
7.2Port B
AT43USB325
Port B is an 8-bit bi-directional I/O port with open drain outputs and controlled slew rate. It is
designed for use as the column driver in a keyboard controller. The Port B output buffers can
sink or source 4 mA.
Three I/O memory address locations are allocated for the Port B, one each for the Data Register
- PORTB, $18($38), Data Direction Register (DDRB), $17($37) and the Port B Input Pins
(PINB), $16($36). The Port B Input Pins address is read only, while the Data Register and the
Data Direction Register are read/write.
The Port B Input Pins address (PINB) is not a register, and this address enables access to the
physical value on each Port B pin. When reading PORTB, the Port B Data Latch is read, and
when reading PINB, the logical values present on the pins are read.
57
7.3Port C
Port C is an 8-bit bi-directional I/O port with an internal pull-up resistor at each pin. Port C is
designed for use as the row inputs of a keyboard controller. Its output buffers can sink 4 mA.
Three I/O memory address locations are allocated for the Port C, one each for the Data Register
- PORTC, $15($35), Data Direction Register - DDRC, $14($34) and the Port C Input Pins –
PINC, $13($33). The Port C Input Pin’s address is read only, while the Data Register and the
Data Direction Register are read/write.
The Port C Input Pins address (PINC) is not a register, and this address enables access to the
physical value on each Port C pin. When reading PORTC, the Port C Data Latch is read, and
when reading PINC, the logical values present on the pins are read.
AT43USB325
3355C–USB–4/05
7.4Port D
AT43USB325
Port D is a 7-bit bi-directional I/O port.
Three I/O memory address locations are allocated for the Port D, one each for the Data Register
- PORTD, $12($32), Data Direction Register - DDRD, $11($31) and the Port D Input Pins PIND, $10($30). The Port D Input Pins address is read only, while the Data Register and the
Data Direction Register are read/write. Some Port D pins have alternate functions as shown in
the following table:
Table 7-2.Port D Pins Alternate Functions
Port PinAlternate Function
PD1T1 (Timer/Counter1 External Counter Input)
PD3INT1 (External Interrupt 1 Input)
PD4INTA (External Interrupt A Input)
PD5INTB (External Interrupt B Input)
PD6INTC (External Interrupt C Input)
PD7INTD (External Interrupt D Input)
When the pins are used for the alternate function the DDRD and PORTD register has to be set
according to the alternate function description.
The Port D Input Pins address (PIND) is not a register, and this address enables access to the
physical value on each Port D pin. When reading PORTD, the Port D Data Latch is read, and
when reading PIND, the logical values present on the pins are read.
59
7.4.4Port D as General Digital I/O
PDn, General I/O Pin: The DDDn bit in the DDRD register selects the direction of this pin. If
DDDn is set (one), PDn is con-figured as an output pin. If DDDn is cleared (zero), PDn is configured as an input pin. The value of PORTDn has no meaning in this mode. The Port D pins are
tri-stated when a reset condition becomes active.
Table 7-3.DDDn Bits on Port D Pins
DDDnPORTDnI/OComment
00InputTri-state (Hi-Z)
01InputTri-state (Hi-Z)
10OutputPush-pull Zero Output
11OutputPush-pull One Output
Note:n: 7,6,5,4,3,1,0, pin number
7.4.5Alternate Functions of Port D
INT1, External Interrupt Source 1: The PD3 pin can serve as an external interrupt source to
the MCU. See the interrupt description for further details, and how to enable the source.
7.5Port E
Port E[0:3] each is a bi-directional I/O port with open drain outputs and controlled slew rate and
is designed for use as the column drivers in a keyboard controller. The Port E[0:3] output buffers
can sink 4 mA. Port E[4:7] are bi-directional I/O with outputs capable of driving LEDs directly.
Each pin of Port E[4:7] has a series resistor to limit the LEDs current.
Three I/O memory address locations are allocated for the Port E, one each for the Data Register
- PORTE, $03($23), Data Direction Register - DDRE, $02($22) and the Port E Input Pins - PINE,
$01($21). The Port E Input Pins address is read only, while the Data Register and the Data
Direction Register are read/write.
The Port E Input Pins address, PINE, is not a register, and this address enables access to the
physical value on each Port E pin. When reading PORTE the Port E Data Latch is read, and
when reading PINE, the logical values present on the pins are read.
7.5.4Port E as General Digital I/O
PEn, General I/O Pin: The DDEn bit in the DDRE register selects the direction of this pin. If
DDEn is set (one), PEn is con-figured as an output pin. If DDEn is cleared (zero), PEn is configured as an input pin. The value of PORTEn has no meaning in this mode. The Port E pins are tristated when a reset condition becomes active.
Table 7-4.DDEn Bits on Port E Pins
DDEnPORTEnI/OComment
00InputTri-state (Hi-Z)
01InputTri-state (Hi-Z)
7.6Port F
10OutputPush-pull Zero Output
11OutputPush-pull One Output
Note:n: 7,6…0, pin number
Port F[1:3] is a 3-bit bi-directional I/O that becomes available after the program memory is written at the end of POR. Three I/O memory address locations are allocated for the Port F, one
each for the Data Register - PORTF, $06($26), Data Direction Register - DDRF, $05($25) and
the Port F Input Pins - PIND, $04($24). The Port F Input Pins address is read only, while the
Data Register and the Data Direction Register are read/write. Some Port F pins have alternate
functions as shown in the following table:
Table 7-5.Port F Pins Alternate Functions
Port PinAlternate Function 1Alternate Function 2
PF1SCK (SPI Bus Serial Clock)
PF2MOSI (SPI Bus Master Output/Slave Input)
PF3MISO (SPI Bus Master Input/Slave Output)ICP (Timer/Counter1 Input Capture)
OC1A (Timer/Counter1 Output CompareA
Match Output)
OC1B (Timer/Counter1 Output CompareB
Match Output)
After power up, PF[1:3] are used to load the program memory. This process is automatic. After
completion of program memory downloading, the SSN pin is de-asserted (=logic 1) and the pins
functions as GPIOs. When the pins are used for the alternate function, after downloading is
completed, the DDRF and PORTF register has to be set according to the alternate function
description.
3355C–USB–4/05
61
7.6.1Port F Data Register – PORTF
Bit76543210
$06($26)----PORTF3PORTF2PORTF1-PORTF
Read/WriteR/WR/WR/WR/WR/WR/WR/WR/W
Initial Value00000000
7.6.2Port F Data Direction Register – DDRF
7.6.3Port F Input Pin Address – PINF
Bit76543210
$05($25)----DDF3DDF2DDF1-DDRF
Read/WriteR/WR/WR/WR/WR/WR/WR/WR/W
Initial Value00000000
Bit76543210
$04($24)----PINF3PINF2PINF1-PINF
Read/WriteRRRRRRRR
Initial ValueN/AN/AN/AN/AN/AN/AN/AN/A
The Port F Input Pins address - PINF - is not a register, and this address enables access to the
physical value on each Port F pin. When reading PORTF, the Port F Data Latch is read, and
when reading PINF, the logical values present on the pins are read.
7.6.4Port F as General Digital I/O
PFn, General I/O Pin: After firmware downloading, the DDFn bit in the DDRF register selects
the direction of this pin. If DDFn is set (one), PFn is con-figured as an output pin. If DDFn is
cleared (zero), PFn is configured as an input pin. The value of PORTFn has no meaning in this
mode. The Port F pins are tri-stated when a reset condition becomes active.
62
Table 7-6.DDFn Bits on Port F Pins
DDFnPORTFnI/OComment
00InputTri-state (Hi-Z)
01InputTri-state (Hi-Z)
10OutputPush-pull Zero Output
11OutputPush-pull One Output
Note:n: 3,2,1, pin number
AT43USB325
3355C–USB–4/05
8.Programming the USB Module
The USB hardware consists of two devices, hub and function, each with their own device
address and endpoints. Its operation is controlled through a set of memory mapped registers.
The exact configuration of the USB device is defined by the software and it can be programmed
to operate as a compound device, or as a hub only or as a function only. The hub has the
required control and interrupt endpoints. The number of external downstream ports is programmable from 0 to 2. The DP and DM pins of the unused port(s) must be connected to ground. The
USB function has one control endpoint and 2 programmable endpoints. All the endpoints have
their own 8-byte FIFOs. If the hub is disabled, one extra endpoint becomes available to the
function.
8.1USB Function
The USB function hardware is designed to operate in the single packet mode and to manage the
USB protocol layer. It consists of a Serial Interface Engine (SIE), endpoint FIFOs and a Function
Interface Unit (FIU). The SIE performs the following tasks: USB signaling detection/generation,
data serialization/de-serialization, data encoding/decoding, bit stuffing and un-stuffing,
clock/data separation, and CRC generation/checking. It also decodes and manages all packet
data types and packet fields.
The endpoint FIFO buffers the data to be sent out or data received. The FIU manages the flow of
data between the SIE, FIFO and the internal microcontroller bus. It controls the FIFO and monitors the status of the transactions and interfaces to the CPU. It initiates interrupts and acts upon
commands sent by the firmware.
AT43USB325
The USB function hardware of the AT43USB325 makes the physical interface and the protocol
layer transparent to the user. To start the process, the firmware must first enable the endpoints
and which place them in receive mode by default. The device address by default is address 0.
The USB function hardware then waits for a setup token from the host. When a valid setup token
is received, it automatically stores the data packet in endpoint 0 FIFO and responds with an
ACK. It then notifies the microcontroller through an interrupt. The microcontroller reads the FIFO
and parses the request.
Transactions for the non-control endpoints are even simpler. Once the endpoint is enabled, it
waits for an IN or an OUT token depending whether it is programmed as an IN or OUT endpoint.
For example, if it is an IN endpoint, the microcontroller simply loads the data into the endpoint's
FIFO and sets a bit in the control and status register. The USB hardware will assemble the data
in a USB packet and waits for an IN token. When it receives one, it automatically responds by
transmitting the data packet and completes the transaction by waiting for the host's ACK. When
one is received, the USB hardware will signal the microcontroller that the transaction has been
completed successfully. Retries and data toggles are performed automatically by the USB hardware. When the IN endpoint is not ready to send data, in the case where the microcontroller has
not filled the FIFO, it will automatically respond with a NAK.
Similarly, an OUT endpoint will wait for an OUT token. When one is received, it will store the
data in the FIFO, completes the transaction and interrupt the microcontroller, which then reads
the FIFO and enables the endpoint for the next packet. If the FIFO is not cleared, the USB hardware will responds with a NAK.
3355C–USB–4/05
A detailed description of how USB transactions are handled is described in the following sections. First for a control endpoint and then for non-control endpoints.
63
8.1.1Control Transfers at Control End-point EP0
The description given below is for the function control end-point, but applies to the hub control
end-point as well if the proper registers are used.
The following illustration describes the three possible types of control transfers – Control Write,
Control Read and No-data control:
SetupDataStatus
StageStageStage
Control
Write
Control
Read
No-data
Control
SETUP(0)OUT(1)OUT(0)OUT(0/1)
DATA0DATA1DATA0DATA0/1DATA1(0)
SETUP(0)
DATA0DATA1DATA0DATA0/1DATA1(0)
SetupStatus
StageStage
SETUP(0)IN(1)
DATA0DATA1(0)
The following state diagram shows how the various state transitions are triggered. Additional
decision making may take place within the response states to determine the next expected
state. Unmarked arcs represent transitions that trigger immediately following completion of the
response state processing. Stable states, those requiring an interrupt to exit having no
unmarked arcs as exit paths, are shown in bold.
…
IN(1)OUT(1)IN(0)IN(0/1)
…
DATAn
DATA1(0)
Legend:
Data packet with PID’s
data toggle bit equal to n
Zero length DATA1 packet
IN(1)IN(1)
64
AT43USB325
3355C–USB–4/05
ANY STABLE STATE
(
RX_SETUP_INT
Setup
Response
AT43USB325
)
TX_COMPLETE_INT
Control
Read Data
Response
RX_OUT_INT
No-data
Status
Response
RX_OUT_INT
TX_COMPLETE_INT
Control
Write Data
Response
Control
Write Status
Response
RX_OUT_INT
TX_COMPLETE_INT
TX_COMPLETE_INT
Control
Read Status
Response
Idle
The following information describes how the AT43USB325’s USB hardware and firmware operates during a control transfer between the host and the hub’s or function’s control end-point.
Legend:DATA1/DATA0 = Data packet with DATA1 or DATA2 PID
8.1.2Idle State
3355C–USB–4/05
DATA1(0) = Zero length DATA1 packet
This is the default state from power-up.
65
8.1.3Setup Response State
The Function Interface Unit (FIU) receives a SETUP token with 8 bytes of data from the Host.
The FIU stores the data in the FIFO, sends an ACK back to the host and asserts an RX_SETUP
interrupt.
1. SETUP token, DATA from Host
2. ACK to Host
3. Store data in FIFO
4. Set RX SETUP → INT
HardwareFirmware
5. Read UISR
6. Read CSR0
7. Read Byte Count
8. Read FIFO
9. Parse command data
10. Write to H/FCAR0:
11. If Control Read: set DIR, clear RX
SETUP, fill FIFO, set TX Packet
Ready in CAR0
12. If Control Write: clear DIR in CAR0
13. If no Data Stage: set Data End,
clear DIR, set Force STALL in
CAR0
14. Set UIAR[EP0 INTACK] to clear
the interrupt source
66
AT43USB325
3355C–USB–4/05
8.1.4No-data Status Response State
The Function Interface Unit receives an IN token from the Host. The FIU responds with a zero
length DATA1 packet until receiving an ACK from the host, then asserts a TX_COMPLETE
interrupt.
1. IN token from Host
2. Send DATA1(0)
3. ACK from Host
4. Set TX COMPLETE → INT
AT43USB325
HardwareFirmware
5. Read UISR
6. Read CSR0
7. If SET ADDRESS, program the
new Address, set ADD_EN bit
8. Clear TX_COMPLETE, clear Data
End, set Force STALL in CAR0
9. Set UIAR[EP0 INTACK]
8.1.5Control Read Data Response State
The Function Interface Unit receives an IN token from the Host. The FIU responds with NAKs
until TX_PACKET_READY is set. The FIU then sends the data in the FIFO upstream, retrying
until it successfully receives an ACK from the host. Finally, the FIU clears the
TX_PACKET_READY bit and asserts a TX_COMPLETE interrupt.
HardwareFirmware
1. IN token from Host
2. a. If TX Packet Ready = 1, send
DATA0/DATA1
b. If TX Packet Ready = 0, send
NAK
3. ACK from Host
4. Clear TX Packet Ready
Set TX Complete → INT
5. Read UISR
6. Read CSR0
7. Clear TX COMPLETE in CAR0:
a. If more data: fill FIFO, set TX
Packet Ready, set DIR in CAR0
b. If no more data: set Force
STALL, set DATA END in CAR0
8. Set UIAR[EP0 INTACK] to clear
interrupt source
Repeat steps 1 through 8
3355C–USB–4/05
67
8.1.6Control Read Status Response State
The Function Interface Unit receives an OUT token from the Host with a zero length DATA1
packet. The FIU responds with a NAK until TX_COMPLETE is cleared. The FIU will then ACK
the retried OUT token from the Host and assert an RX_OUT interrupt.
HardwareFirmware
1. OUT token from Host
2. DATA1(0) from Host
3. TX Complete = 0 ?
a. If yes, ACK to Host
Set RX OUT → INT
b. If no, NAK to Host
4. Read UISR
5. Read CSR0
6. Clear RX OUT, set Data End, set
Force Stall in H/FCAR0.
Note: A SETUP token will clear
Data End, therefore, it is not
cleared by FW in case Host retries.
7. Set UIAR[EP0 INTACK] to clear
interrupt source
8.1.7Control Write Data Response State
The Function Interface Unit receives an OUT token from the Host with a DATA packet. The FIU
places the incoming data into the FIFO, issues an ACK to the host, and asserts an RX_OUT
interrupt.
HardwareFirmware
1. OUT token from Host
2. Put DATA0/DATA1 into FIFO
3. ACK to Host
4. Set RX OUT → INT
5. Read UISR
6. Read CSR0
7. Read FIFO
8. Clear RX OUT
If last data packet, set Force
STALL, set DATA END.
9. Set UIAR[EP0 INTACK] to clear
the interrupt source
Repeat steps 1 through 9 until last DATA PACKET:
68
AT43USB325
3355C–USB–4/05
8.1.8Control Write Status Response State
The Function Interface Unit receives an IN token from the Host. The FIU responds with a zero
length DATA1 packet, retrying until it receives an ACK back from the Host. The FIU then asserts
a TX_COMPLETE interrupt.
HardwareFirmware
1. IN token from Host
2. Send DATA1(0)
3. ACK from Host
4. Set TX Complete → INT
8.1.9Interrupt/Bulk IN Transfers at Function End-point
The firmware must first condition the end-point through the End-point Control Register, FENDP1/2/3_CNTR:
AT43USB325
5. Read UISR
6. Read CSR0
7. Clear TX COMPLETE, clear Data
End, set Force STALL in CAR0
8. Set UIAR[EP0 INTACK] to clear
the interrupt source
Set end-point direction: set EPDIR
Set interrupt or bulk: EPTYPE = 11 or 10
Enable end-point: set EPEN
The Function Interface Unit receives an IN token from the Host. The FIU responds with NAKs
until TX_PACKET_READY is set. The FIU then sends the data in the FIFO upstream, retrying
until it successfully receives an ACK from the host. Finally, the FIU clears the
TX_PACKET_READY bit and asserts a TX_COMPLETE interrupt.
1. Read UISR
2. Read FCSR1/2/3
3. Clear TX_COMPLETE
If more data: fill FIFO, set TX Packet Ready
Wait for TX_COMPLETE interrupt
If no more data: set DATA END in FCAR1/2/3
4. Set UIAR[FEP1/2/3 INTACK] to clear the interrupt source
3355C–USB–4/05
69
8.1.10Interrupt/Bulk OUT Transfers at Function End-point EP1, 2 and 3
The firmware must first condition the end-point through the End-point Control Register, FENDP1/2/3_CNTR:
Set end-point direction: clear EPDIR
Set interrupt or bulk: EPTYPE = 11 or 10
Enable end-point: set EPEN
The Function Interface Unit receives an OUT token from the Host with a DATA packet. The FIU
places the incoming data into the FIFO, issues an ACK to the host, and asserts an RX_OUT
interrupt.
1. Read UISR
2. Read FCSR1/2/3
3. Read FIFO
4. Clear RX_OUT
If more data:
Wait for RX_OUT interrupt
If no more data: set DATA END
Set UIAR[FEP1/2/3 INTACK] to clear the interrupt source
70
AT43USB325
3355C–USB–4/05
8.2USB Registers
The following sections describe the registers of the AT43USB325’s USB hub and function units.
Reading a bit for which the microcontroller does not have read access will yield a zero value
result. Writing to a bit for which the microcontroller does not have write access has no effect.
8.2.1Hub Address Register – HADDR
The USB hub contains an address register that contains the hub address assigned by the host.
This Hub Address Register must be programmed by the microcontroller once it has received a
SET_ADDRESS request from the host. The USB hardware uses the new address only after the
status phase of the transaction is completed when the microcontroller has enabled the new
address by setting bit 0 of the Global State Register. After power-up or reset, this register will
contain the value of 0x00.
AT43USB325
8.2.1.1Hub Address Register – HADDR
Bit76543210
$1FEFSAENHADD6HADD5HADD4HADD3HADD2HADD1HADD0HADDR
Read/WriteR/WR/WR/WR/WR/WR/WR/WR/W
Initial Value00000000
• Bit 7 – SAEN: Single Address Enable
The Single Address Enable bit allows the microcontroller to configure the AT43USB325 into a
single address or a composite device. Once this capability is enabled, the hub endpoint 0
(HEP0) is converted from a control endpoint to a programmable function endpoint FEP3; all the
endpoints would then operate on the single address.
• Bit 6..0 – HADD6...0: Hub Address[6:0]
8.2.2Function Address Register – FADDR
The USB function contains an address register that contains the function address assigned by
the host. This Function Address Register must be programmed by the microcontroller once it
has received a SET_ADDRESS request from the host and completed the status phase of the
transaction. After power up or reset, this register will contain the value of 0x00.
8.2.2.1Function Address Register – FADDR
3355C–USB–4/05
Bit76543210
$1FEEFENFADD6FADD5FADD4FADD3FADD2FADD1FADD0FADDR
Read/WriteR/WR/WR/WR/WR/WR/WR/WR/W
Initial Value00000000
• Bit 7 – FEN: Function Enable
The Function Enable bit (FEN) allows the firmware to enable or disable the function endpoints.
The firmware will set this bit after receipt of a reset through the hub, SetPortFeature[PORT_RESET]. Once this bit is set, the USB hardware passes to and from the host.
When the Single Address bit is set, the condition of FEN is ignored.
• Bit 6..0 – FADD6...0: Function Address[6:0]
71
8.3Endpoint Registers
8.3.1Hub Endpoint 0 Control Register – HENDP0_CR
8.3.2Function Endpoint 0 Control Register – FENDP0_CR
Bit 765432 1 0
$1FE7EPEN–––DTGLEEPDIREPTYPE1EPTYPE0HENDP0_CR
$24 ($44)EPEN–––DTGLEEPDIREPTYPE1EPTYPE0FENDP0_CR
Read/WriteR/WRRRR/WR/WR/WR/W
Initial Value00000000
• Bit 7 – EPEN: Endpoint Enable
0 = Disable endpoint
1 = Enable endpoint
• Bit 6..4 – Reserved
These bits are reserved in the AT43USB325 and will read as zero.
• Bit 3 – DTGLE: Data Toggle
Identifies DATA0 or DATA1 packets. This bit will automatically toggle and requires clearing by
the firmware only in certain special circumstances.
• Bit 2 – EPDIR: Endpoint Direction
0 = Out
1 = In
• Bit 1, 0 – EPTYPE: Endpoint Type
These bits must be programmed as 0, 0.
72
AT43USB325
3355C–USB–4/05
AT43USB325
8.3.3Function Endpoint 1-3 Control Register – FENDP1-3_CR
Bit76543210
$1FE4EPEN–––DTGLEEPDIREPTYPE1EPTYPE0FENDP1_CR
$1FE3EPEN–––DTGLEEPDIREPTYPE1EPTYPE0FENDP2_CR
$1FE2EPEN–––DTGLEEPDIREPTYPE1EPTYPE0FENDP3_CR
Read/WriteR/WRRRR/WR/WR/WR/W
Initial Value00000000
• Bit 7 – EPEN: Endpoint Enable
0 = Disable endpoint
1 = Enable endpoint
• Bit 6..4 – Reserved
These bits are reserved in the AT43USB325 and will read as zero.
• Bit 3 – DTGLE: Data Toggle
Identifies DATA0 or DATA1 packets. This bit will automatically toggle and requires clearing by
the firmware only in certain special circumstances.
• Bit 2 – EPDIR: Endpoint Direction
0 = Out
1 = In
• Bit 1, 0 – EPTYPE: Endpoint Type
These bits program the type of endpoint.
Bit1Bit0Type
01Isochronous
10Bulk
11Interrupt
3355C–USB–4/05
73
8.3.4Hub Endpoint 0 Data Register – HDR0
8.3.5Function Endpoint 0..3 Data Register – FDR0..3
Bit76543210
$1FD7DATA7DATA6DATA5DATA4DATA3DATA2DATA1DATA0HDR0
$1FD5DATA7DATA6DATA5DATA4DATA3DATA2DATA1DATA0FDR0
$1FD4DATA7DATA6DATA5DATA4DATA3DATA2DATA1DATA0FDR1
$1FD3DATA7DATA6DATA5DATA4DATA3DATA2DATA1DATA0FDR2
$1FD2DATA7DATA6DATA5DATA4DATA3DATA2DATA1DATA0FDR3
Read/WriteR/WR/WR/WR/WR/WR/WR/WR/W
Initial Value00000000
This register is used to read data from or to write data to the Hub Endpoint 0 FIFO.
• Bit 7..0 – FDAT7..0: FIFO Data
Hub endpoint 1 has a single byte data register instead of a FIFO. This data register contains the
hub and port status change bitmap. This data register is automatically updated by the USB hardware and is not accessible by the firmware. The bits in this register when read by the host will
be:
Bit76543210
$––P5 CSP4 CSP3 SCP2 SCP1 SCH SCHDR1
Read/WriteR/WR/WR/WR/WR/WR/WR/WR/W
Initial Value00000000
• Bit 7,6 – Reserved
These bits are reserved in the AT43USB325 and will read as zero.
The contents of these registers stores the number of bytes to be sent or that was received by
USB Hub and Function endpoints. This count includes the 16-bit CRC. To get the actual byte
count of the data, subtract the count in the register by 2. The maximum byte count supported by
the AT43USB325 is 8 bytes. Hub endpoint 1 has no byte count register.
Function EP0 $1FCD––BYTCT5BYTCT4BYTCT3BYTCT2BYTCT1BYTCT0FBYTE_CNT0
Function EP1 $1FCC––BYTCT5BYTCT4BYTCT3BYTCT2BYTCT1BYTCT0FBYTE_CNT1
Function EP2 $1FCB––BYTCT5BYTCT4BYTCT3BYTCT2BYTCT1BYTCT0FBYTE_CNT2
Function EP3 $1FCA––BYTCT5BYTCT4BYTCT3BYTCT2BYTCT1BYTCT0FBYTE_CNT3
Read/WriteRRRR/WR/WR/WR/WR/W
Initial Value00000000
• Bit 7..6 – Reserved
These bits are reserved in the AT43USB325 and will read as zero.
AT43USB325
• Bit 5..0 – BYTCT5..0: Byte Count – Length of Endpoint Data Packet
3355C–USB–4/05
75
8.3.8Hub Endpoint 0 Service Routine Register – HCSR0
8.3.9Function Endpoint 0 Service Routine Register – FCSR0
Bit76543210
Function EP0 $1FDF––––STALL SENTRX SETUPRX OUT PACKETTX COMPLETEHCSR0
Function EP0 $1FDD––––STALL SENTRX SETUP RX OUT PACKETTX COMPLETEFCSR0
Read/WriteRRRRRRRR
Initial Value00000000
• Bit 7..4 – Reserved
These bits are reserved in the AT43USB325 and will read as zero.
• Bit 3 – STALL SENT
The USB hardware sets this bit after a STALL has been sent to the host. The firmware uses this
bit when responding to a Get Status[Endpoint] request. It is a read only bit and that is cleared
indirectly by writing a one to the STALL_SENT_ACK bit of the Control and Acknowledge
Register.
• Bit 2 – RX SETUP: Setup Packet Received
This bit is used by control endpoints only to signal to the microcontroller that the USB hardware
has received a valid SETUP packet and that the data portion of the packet is stored in the FIFO.
The hardware will clear all other bits in this register while setting RX SETUP. If interrupt is
enabled, the microcontroller will be interrupted when RX SETUP is set. After the completion of
reading the data from the FIFO, firmware should clear this bit by writing a one to the
RX_SETUP_ACK bit of the Control and Acknowledge Register.
• Bit 1 – RX OUT PACKET
The USB hardware sets this bit after it has stored the data of an OUT transaction in the FIFO.
While this bit is set, the hardware will NAK all OUT tokens. The USB hardware will not overwrite
the data in the FIFO except for an early set-up. RX OUT Packet is used for the following
operations:
1. Control write transactions by a control endpoint.
2. OUT transaction with DATA1 PID to complete the status phase of a control endpoint.
Setting this bit causes an interrupt to the microcontroller if the interrupt is enabled. FW clears
this bit after the FIFO contents have been read by writing a one to the RX_OUT_PACKET_ACK
bit of the Control and Acknowledge Register.
• Bit 0 – TX COMPL: Transmit Completed
This bit is used by a control endpoint hardware to signal to the microcontroller that it has successfully completed certain transactions. TX Complete is set at the completion of a:
1. Control read data stage.
2. Status stage without data stage.
3. Status stage after a control write transaction.
This bit is read only and is cleared indirectly by writing a one to the TX_COMPLETE_ACK bit of
the Control and Acknowledge Register.
76
AT43USB325
3355C–USB–4/05
8.3.10Hub Endpoint 0 Control and Acknowledge Register – HCAR0
AT43USB325
8.3.11Function Endpoint 0 Control and Acknowledge Register – FCAR0
Bit76543210
Hub EP0
$1FA7
Function
EP0
$1FDD
Read/WriteR/WR/WR/WR/WR/WR/WR/WR/W
Initial Value00000000
DIR
DIR
DATA
END
DATA
END
FORCE
STALL
FORCE
STALL
TX
PACKET
READY
TX
PACKET
READY
STALL_
SENT_
ACK
STALL_
SENT_
ACK
•Bit 7 – DIR: Control transfer direction
It is set by the microcontroller firmware to indicate the direction of a control transfer to the USB
hardware. The FW writes to this bit location after it receives an RX SETUP interrupt. The hardware uses this bit to determine the status phase of a control transfer.
0 = control write or no data stage
1 = control read
•Bit 6 – DATA END
When set to 1 by firmware, this bit indicate that the microcontroller has either placed the last
data packet in FIFO, or that the microcontroller has processed the last data packet it expects
from the Host. This bit is used by control endpoints only together with bit 4 (TX Packet Ready) to
signal the USB hardware to go to the STATUS phase after the packet currently residing in the
FIFO is transmitted. After the hardware completes the STATUS phase it will interrupt the microcontroller without clearing this bit.
RX_
SETUP_
ACK
RX_
SETUP_
ACK
RX_OUT_
PACKET_
ACK
RX_OUT_
PACKET_
ACK
TX_
COMPLETE_
ACK
TX_
COMPLETE_
ACK
HCA
R0
FCAR
0
•Bit 5 – FORCE STALL
This bit is set by the microcontroller to indicate a stalled endpoint. The hardware will send a
STALL handshake as a response to the next IN or OUT token, or whenever there is a control
transfer without a Data Stage.
The microcontroller sets this bit if it wants to force a STALL. A STALL is sent if any of the following condition is encountered:
1. An unsupported request is received.
2. The host continues to ask for data after the data is exhausted.
3. The control transfer has no data stage.
•Bit 4 – TX PACKET READY: Transmit Packet Ready
When set by the firmware, this bit indicates that the microcontroller has loaded the FIFO with a
packet of data. This bit is cleared by the hardware after the USB Host acknowledges the packet.
For ISO endpoints, this bit is cleared unconditionally after the data is sent.
This bit is used for the following operations:
1. Control read transactions by a control endpoint.
2. IN transactions with DATA1 PID to complete the status phase for a control endpoint,
when this bit is zero but Data End set high (bit 4).
3. By a BULK IN or ISO IN or INT IN endpoint.
3355C–USB–4/05
77
The microcontroller should write into the FIFO only if this bit is cleared. After it has completed
writing the data, it should set this bit. This data can be of zero length.
Hardware clears this bit after it receives an ACK. If the interrupt is enabled and if the TX Complete bit is set, clearing the TX Packet Ready bit by the hardware causes an interrupt to the
microcontroller.
•Bit 3 – STALL_SENT_ACK: Acknowledge Stall Sent Interrupt
Firmware sets this bit to clear STALL SENT, CSR bit 3. The 1 written in the CSRACK3 bit is not
actually stored and thus does not have to be cleared.
Firmware sets this bit to clear TX COMPLETE, CSR bit0. The 1 written in the CSRACK0 bit is
not actually stored and thus does not have to be cleared.
78
AT43USB325
3355C–USB–4/05
AT43USB325
8.3.12Function Endpoint 1,2,3 Service Routine Register – FCSR1,2,3
Bit76543210
Function EP1 $1FDC––––STALL SENT–RX OUT PACKETTX COMPLETEFCSR1
Function EP2 $1FDB––––STALL SENT–RX OUT PACKETTX COMPLETEFCSR2
Function EP3 $1FDA––––STALL SENT–RX OUT PACKETTX COMPLETEFCSR3
Read/Write RRRRRRRR
Initial Value 00000000
• Bit 7..4 – Reserved
These bits are reserved in the AT43USB325 and will read as zero.
• Bit 3 – STALL SENT
The USB hardware sets this bit after a STALL has been sent to the host. The firmware uses this
bit when responding to a Get Status[Endpoint] request. It is a read only bit and that is cleared
indirectly by writing a one to the STALL_SENT_ACK bit of the Control and Acknowledge
Register.
• Bit 2 – Reserved
This bit is reserved in the AT43USB325 and will read as zero.
• Bit 1 – RX OUT PACKET
The USB hardware sets this bit after it has stored the data of an OUT transaction in the FIFO.
While this bit is set, the hardware will NAK all OUT tokens. The USB hardware will not overwrite
the data in the FIFO except for an early set-up. RX OUT Packet is used by a BULK OUT or ISO
OUT or INT OUT endpoint.
Setting this bit causes an interrupt to the microcontroller if the interrupt is enabled. FW clears
this bit after the FIFO contents have been read by writing a one to the RX_SETUP_ACK bit of
the Control and Acknowledge Register.
• Bit 0 – TX COMPLETE: Transmit Completed
This bit is used by the endpoint hardware to signal to the microcontroller that the IN transaction
was completed successfully. This bit is read only and is cleared indirectly by writing a one to the
TX_COMPLETE_ACK bit of the Control and Acknowledge Register.
3355C–USB–4/05
79
8.3.13Function Endpoint 1,2,3 Control and Acknowledge Register – FCAR1,2,3
Bit76543210
Function
EP1 $1FA4
Function
EP2 $1FA3
Function
EP3 $1FA2
Read/WriteRR/WR/WR/WR/WRR/WR/W
Initial Value00000000
DATA
END
DATA
END
DATA
END
FORCE
STALL
FORCE
STALL
FORCE
STALL
–
–
–
TX PACKET
RDY
TX PACKET
RDY
TX PACKET
RDY
STALL_SENT
-ACK
STALL_SENT
-ACK
STALL_SENT
-ACK
–
–
–
• Bit 7 – Reserved
This bit is reserved in the AT43USB325 and will read as zero.
• Bit 6 – DATA END
When set to 1 by firmware, this bit indicate that the microcontroller has either placed the last
data packet in FIFO, or that the microcontroller has processed the last data packet it expects
from the Host.
• Bit 5 – FORCE STALL
This bit is set by the microcontroller to indicate a stalled endpoint. The hardware will send a
STALL handshake as a response to the next IN or OUT token. The microcontroller sets this bit if
it wants to force a STALL. A STALL is send if the host continues to ask for data after the data is
exhausted.
RX_OUT_PACKET
_ACK
RX_OUT_PACKET
_ACK
RX_OUT_PACKET
_ACK
TX_COMPLETE
_ACK
TX_COMPLETE
_ACK
TX_COMPLETE
_ACK
FCAR1
FCAR2
FCAR3
• Bit 4 – TX PACKET RDY: Transmit Packet Ready
When set by the firmware, this bit indicates that the microcontroller has loaded the FIFO with a
packet of data. This bit is cleared by the hardware after the USB Host acknowledges the packet.
For ISO endpoints, this bit is cleared unconditionally after the data is sent.
The microcontroller should write into the FIFO only if this bit is cleared. After it has completed
writing the data, it should set this bit. This data can be of zero length.
The hardware clears this bit after it receives an ACK. If the interrupt is enabled and if the TX
Complete bit is set, clearing the TX Packet Ready bit by the hardware causes an interrupt to the
microcontroller.
• Bit 3 – STALL_SENT_ACK: Acknowledge Stall Sent Interrupt
Firmware sets this bit to clear STALL SENT, CSR bit 3. The 1 written in the CSRACK3 bit is not
actually stored and thus does not have to be cleared.
• Bit 2 – Reserved
This bit is reserved in the AT43USB325 and will read as zero.
• Bit 1 – RX_OUT_PACKET_ACK: Acknowledge RX OUT PACKET Interrupt
Firmware sets this bit to clear RX OUT PACKET, CSR bit1. The 1 written in the CSRACK1 bit is
not actually stored and thus does not have to be cleared.
• Bit 0 – TX_COMPLETE_ACK: Acknowledge TX COMPLETE Interrupt
Firmware sets this bit to clear TX COMPLETE, CSR bit0. The 1 written in the CSRACK0 bit is
not actually stored and thus does not have to be cleared.
80
AT43USB325
3355C–USB–4/05
8.4USB Hub
AT43USB325
The hub in a USB system provides for the electrical interface between USB devices and the
host. The major functions that the hub must supports are:
• Connectivity
• Power management
• Device connect and disconnect
• Bus fault detection and recovery
• Full speed and low speed device support
A hub consists of two major components: a hub repeater and a hub controller. The hub repeater
is responsible for:
• Providing upstream connectivity between the selected device and the Host
• Managing connectivity setup and tear-down
• Handling bus fault detection and recovery
• Detecting connect/disconnect on each port
The Hub Controller is responsible for:
• Hub enumeration
• Providing configuration information to the host
• Providing status of each port to the host
• Controlling each port per host command
The first two tasks of the hub are similar to that of a USB function and are described in detail in
the following section. The descriptions will cover the features of the AT43USB325's hub and how
to program it to make a USB-compliant hub.
Control transactions for the hub control endpoint proceed exactly the same way as those
described for the embedded function. The operation of the hub's endpoint 1 is fully implemented
in the hardware and does not need any firmware support. Any status changes within the hub will
automatically update hub endpoint 1, which will be sent to the host at the next IN token that is
addressed to it. If no change has occurred, the interrupt endpoint will respond with a NAK.
3355C–USB–4/05
81
8.4.1Hub General Registers
8.4.1.1Global State Register – GLB_STATE
Bit76543210
$1FFB–KB INT EN–SUSP FLGRESUME FLGRMWUPECONFGHADD ENGLB_STATE
Read/WriteRRRRRR/WR/WR/W
Initial Value00000000
•Bit 7 – Reserved Bit
This bit is reserved in the AT43USB325 and will read as zero.
•Bit 6 – KB INT EN: Keyboard Interrupt Enable
The firmware must set this bit to a 1 before entering suspend to allow remote wakeup when any
key depression is detected in the suspended state.
•Bit 5 – Reserved Bit
This bit is reserved in the AT43USB325 and will read as zero.
•Bit 4 – SUSP FLG: Suspend Flag
This bit is set to 1 while the USB hardware is in the suspended state. This bit is a firmware read
only bit. It is set and cleared by the USB hardware.
•Bit 3 – RESUME FLGL Resume Flag
When the USB hardware receives a resume signal from the upstream device it sets this bit. This
bit will stay set until the USB hardware completes the downstream resume signaling. This bit is a
firmware read only bit. It is set and cleared by the USB hardware.
•Bit 2 – RMWUPE: Remote Wakeup Enable
This bit is set if the host enables the hub's remote wakeup feature.
•Bit 1 – CONFG: Configured
This bit is set by firmware after a valid SET_CONFIGURATION request is received. It is cleared
by a reset or by a SET_CONFIGURATION with a value of 0.
•Bit 0 – HADD EN: Hub Address Enabled
This bit is set by firmware after the status phase of a SET_ADDRESS request transaction so the
hub will use the new address starting at the next transaction.
82
AT43USB325
3355C–USB–4/05
8.4.2Hub Status Register
In the AT43USB325 overcurrent detection and port power switch control output processing is
done in firmware. The hardware is designed so that various types of hubs are possible just
through firmware modifications.
1. Hub local power status, bits 0 and 2, are optional features and apply to hubs that report
2. Hub overcurrent status, bits 1 and 3, apply to self powered hubs with bus powered SIE
The firmware uses bits 1 and 3 to generate bit 0 of the Hub and Port Status Change Bitmap
which is transmitted through the Hub Endpoint1 Data Register. Bit 0 of this register is a 1 whenever bit 1 or 3 of HSTATR is a 1.
AT43USB325
on a global basis. If this feature is not used, both these bits should be programmed to 0.
To use this feature, the firmware needs to know the status of the local power supply,
which requires an input pin and extra internal or external circuitry.
only, or hubs that are programmable as self/bus powered. The firmware should clear
these two bits to 0.
8.4.2.1Hub Status Register – HSTR
Bit76543210
$1FC7––––OVLSCLPSCOVILPSHSTR
Read/WriteRRRRR/WR/WR/WR/W
Initial Value00000000
• Bit 7..4 – Reserved
These bits are reserved in the AT43USB325 and will read as zero.
• Bit 3 – OVLSC: Overcurrent Status Change
0 = No change has occurred on Overcurrent Indicator
1 = Overcurrent Indicator has changed
• Bit 2 – LPSC: Hub Local Power Status Change
0 = No change has occurred on Local Power Status
1 = Local Power Status has changed
• Bit 1 – OVI: Overcurrent Indicator
0 = All power operations normal
1 = An overcurrent exist on a hub wide basis
3355C–USB–4/05
• Bit 0 – LPS: Hub Local Power Status
0 = Local power supply is good
1 = Local power supply is lost (inactive)
83
8.4.2.2Hub Port Control Register – HPCON
Bit76543210
$1FC5–HPCON2HPCON1HPCON0–HPADD2HPADD1HPADD0HPCON
Read/WriteRR/WR/WR/WRR/WR/WR/W
Initial Value00000000
•Bit 7 – Reserved
This bits is reserved in the AT43USB325 and will read as zero.
• Bit 6..4 – HPCON2..0: Hub Port Control Command
These bits are written by firmware to control the port states upon receipt of a Host request.
Bit6Bit5Bit4Action
000Disable port
001Enable port
010Reset and enable port
011Suspend port
100Resume port
Disable Port = ClearPortFeature(PORT_ENABLE)
Action: USB hardware places addressed port in disabled state. Port 1 is placed in disabled
state by firmware.
Enable Port = SetPort Feature(PORT_ENABLE)
Action: USB hardware places addressed port in enabled state. Firmware is responsible for plac-
ing Port 1 in enabled state.
Reset and Enable Port = SetPort Feature(PORT_RESET)
Action: USB hardware drives reset signaling through addressed port. USB hardware and firm-
ware resets their embedded function registers to the default state.
Suspend Port = SetPortFeature(PORT_SUSPEND)
Action: USB hardware places port in idle state and stops propagating traffic through the
addressed port. Firmware places Port 1 in suspend state by disabling its endpoints and placing
the peripheral function in its low power state.
Resume Port = ClearPortFeature(PORT_SUSPEND)
Action: USB hardware sends resume signaling to addressed port and then enables port. Firm-
ware takes the embedded function out of the suspend state and enables Port 1's endpoints.
•Bit 3 – Reserved
This bits is reserved in the AT43USB325 and will read as zero.
84
• Bit 2..0 – HPCON2..0: Hub Port Address
AT43USB325
3355C–USB–4/05
These bits define which port is being addressed for the command defined by bits [2:0].
Bit2Bit1Bit0Port addresses
101Port5
100Port4
011Port3
010Port2
8.4.3Selective Suspend and Resume
The host can selectively suspend and resume a port through the Set Port Feature
(PORT_SUSPEND) and Clear Port Feature (PORT_SUSPEND).
A port enters the suspend state after the microcontroller interprets the suspend request and sets
the appropriate bits of the Hub Port Control Register, HPCON. From this point on he hub
repeater hardware is responsible for proper actions in placing Ports 2:5 in the suspend mode.
For Port 1, the embedded function port, the hardware will stop responding to any normal bus
traffic, but the microcontroller firmware must place all external circuitry associated with the function in the low-power state.
AT43USB325
A port exits from the suspend state when the hub receives a Clear Port Feature
(PORT_SUSPEND) or Set Port Feature (PORT_RESET). If the Clear Port Feature
(PORT_SUSPEND) is directed towards Ports 2:5, the USB hardware drives a “K” downstream
for at least 20 ms followed by a low speed EOP. It then places the port in the enabled state. A
Clear Port Feature (PORT_SUSPEND) to Port 1 (the embedded function) causes the firmware
to wait 20 ms, take the embedded function out of the suspended state and then enable the port.
The ports can also exit from the suspended state through a remote wakeup if this feature is
enabled. For Ports 2:5, this means detection of a connect/disconnect or an upstream directed J
to K signaling. Remote wakeup for the embedded function is initiated through a key depression
which triggers a KB INT.
3355C–USB–4/05
85
8.4.4Hub Port Status Register
The bits in this register are used by the microcontroller firmware when reporting a port's status
through the Port Status Field, wPortStatus. Bits 3 (POCI) and 5 (PPSTAT) are used by the USB
hardware and are the only two bits that the firmware should set or clear. All other bits should not
be modified by the firmware.
This bit is reserved in the AT43USB325 and will read as zero.
• Bit 6 – LSP: Low-speed Device Attached
0 = Full-speed device attached to this port
1 = Slow-speed device attached to this port
Set to 0 for Port 1 (full-speed only). Set and cleared by the hardware upon detection of device at
EOF2.
• Bit 5 – PPSTAT: Port Power Status
0 = Port is powered OFF
86
1 = Port is powered ON
Set to 1 for Port 1. Set and cleared based on present status of port power.
• Bit 4 – PRSTAT: Port Reset Status
0 = Reset signaling not asserted
1 = Reset signaling asserted
Set and cleared by the hardware as a result of initiating a port reset by Port Control Register.
• Bit 3 – POCI: Port Overcurrent Indicator
0 = Power normal
1 = Overcurrent exist on port
Set to 0 for Port 1. Set and cleared by firmware upon detection of an overcurrent or removal of
an overcurrent.
AT43USB325
3355C–USB–4/05
AT43USB325
• Bit 2 – PSSTAT: Port Suspend Status
0 = Port not suspended
1 = Port suspended
Set and cleared by the hardware as controlled through Port Control Register.
• Bit 1 – PESTAT: Port Enable Status
0 = Port is disabled
1 = Port is enabled
Set and cleared by the hardware as controlled through Port Control register.
• Bit 0 – PCSTAT: Port Connect Status
0 = No device on this port
1 = Device present on this port
Set to 1 for Port 1. Set and cleared by the hardware after sampling of connect status at EOF2.
8.4.4.2Overcurrent Detect Register – UOVCER
Bit76543210
$1FF2–– – – –OVC2––UOVCER
Read/WriteRRRRRR/WRR
Initial Value00000000
• Bit 7..3 – Reserved
These bits are reserved in the AT43USB325 and will read as zero.
•Bit 2 – OVC 2
Setting this bit enables the hub to detect an overcurrent on a port while the hub is in the suspend
state. The overcurrent condition is signalled by a 1 to 0 transition at PD0.
• Bit 1, 0 – Reserved
These bits are reserved in the AT43USB325 and will read as zero.
3355C–USB–4/05
87
8.4.4.3Hub Port State Register – HPSTAT2...5
Bit76543210
Port2 $1FA9––––––DPSTATEDMSTATEPSTATE2
Port3 $1FAA––––––DPSTATEDMSTATEPSTATE3
Port4 $1FAB––––––DPSTATEDMSTATEPSTATE4
Port5 $1FAC––––––DPSTATEDMSTATEPSTATE5
Read/WriteRRRRRRRR
Initial Value00000000
These registers contain the state of the ports’ DP and DM pins, which will be sent to the host
upon receipt of a GetBusState request.
• Bit 7..2 – Reserved
These bits are reserved in the AT43USB325 and will read as zero.
•Bit 1 – DPSTATE: DPlus State
Value of DP at last EOF. Set and cleared by hardware at EOF2.
Set to 1 for Port 1.
•Bit 0 – DMSTATE: DMinus State
Value of DM at last EOF. Set and cleared by hardware at EOF2.
Set to 0 for Port 1.
8.4.4.4Hub Port Status Change Register – PSCR1..5
Bit76543210
Port1 $1FB0–––RSTSCPOCICPSSCPESCPCSCPSCR1
Port2 $1FB1–––RSTSCPOCICPSSCPESCPCSCPSCR2
Port3 $1FB2–––RSTSCPOCICPSSCPESCPCSCPSCR3
Port4 $1FB3–––RSTSCPOCICPSSCPESCPCSCPSCR4
Port5 $1FB4–––RSTSCPOCICPSSCPESCPCSCPSCR5
Read/WriteRRRRRRRR
Initial Value00000000
The microcontroller firmware uses the bits in this register to monitor when a port status change
has occurred, which then gets reported to the host through the Port Change Field wPortChange.
Except for bit 3, the Port Overcurrent Indicator Change, the bits in this register are set by the
USB hardware. Otherwise, the firmware should only clear these bits.
• Bit 7..5 – Reserved
These bits are reserved in the AT43USB325 and will read as zero.
88
• Bit 4 – RSTSC: Port Reset Status Change
0 = No change
AT43USB325
3355C–USB–4/05
AT43USB325
1 = Reset complete
This bit is set by the USB hardware after it completes RESET signaling which is initiated when
the Reset and Enable Port command is detected at the Port Control Register, HPCON. The firmware sends this command when it decodes a SetPortFeature(PORT_RESET) request from the
host.
At EOF2 after the hardware completes the port reset, the hardware sets the Port Enable Status
bit and clears the Port Reset Status bit of the Hub Port Status Register, HPSTAT. Cleared by
firmware, ClearPortFeature(PORT_RESET).
• Bit 3 – POCIC: Port Overcurrent Indicator Change
0 = No change has occurred on Overcurrent Indicator
1 = Overcurrent Indicator has changed
This bit is relevant to hubs with individual overcurrent reporting only. The firmware sets this bit
as a result of detecting overcurrent at the ports OVC# pin. The firmware clears bit through ClearPortFeature(PORT_OVER_CURRENT). For Port 1, this bit is always cleared.
• Bit 2 – PSSC: Port Suspend Status Change
0 = No change
1 = Resume completed
Port 2, 3 set by hardware upon completion of firmware initiated resume process. Port 1 set by
firmware 20 ms after the next EOF2 after completion of resume process. RESUME signaling is
initiated through global resume, selective resume and remote wakeup. Cleared by firmware via
host request ClearPortFeature(PORT_SUSPEND).
• Bit 1 – PESC: Port Enable/Disable Status Change
0 = No change has occurred on Port Enable/Disable Status
1 = Port Enable/Disable status has changed
Set by hardware due to babble, physical disconnect or overcurrent except for Port 1 in which
case it is set by hardware at EOF2 due to hardware events. Cleared by firmware via Host
request ClearPortFeature(PORT_ENABLE).
• Bit 0 – PCSC: Port Connect Status Change
0 = No change has occurred on Current Connect Status
1 = Current Connect Status has changed
This bit is set by hardware at EOF2 after it detects a connect or disconnect at a port, except for
Port 1. Hardware sets this bit for Port 5 after a hub reset. Cleared by firmware via Host request
ClearPortFeature(PORT_CONNECTION).
3355C–USB–4/05
89
8.4.5Hub and Port Power Management
Overcurrent protection and power switching are required for the external downstream ports only.
In the AT43USB325, these tasks are completely programmable. This means that any type of
hub is achievable with the AT43USB325: self-powered or bus-powered hubs, per port or global
overcurrent protection, individual or ganged port power switching.
The use of the MCU's GPIO pins are required to interface to the external power supply monitoring and switching. The on-chip hardware of the AT43USB325 contains the circuitry to handle all
the possible combinations of port power management tasks. The firmware defines the exact
configuration.
8.4.6Overcurrent Sensing
The AT43USB325 is capable of detecting overcurrent during active operation only, or during any
condition even when the hub is in the suspended state. When overcurrent in the active state only
is desired, any GPIO pin of the AT43USB325 can be used to sense and the overcurrent condition. Control of the condition must be performed by the firmware. If overcurrent detection under
any condition is desired, then specific GPIO pins must be used to sense the overcurrent and the
proper bit(s) of UOVCER set. In Global Overcurrent Protection mode, overcurrent sensing must
be routed to GPIO PD0. In Individual Port Overcurrent Protection mode Port2 and Port 3 overcurrent sensing must be assigned to GPIO PD0 and PD1. In the following description, it is
assumed that overcurrent protection is required under any condition.
1. Global Overcurrent Protection – In this mode, the Port Overcurrent Indicator and Port
Overcurrent Indicator Change should be set to 0's. For the AT43USB325 an external
solid state switch, such as the Micrel MIC2025-2, is required to switch power to the
external USB ports. The FLG output of the switch should be connected to PD0. When
an overcurrent occurs, FLG is asserted and the firmware should set the Hub Overcurrent Indicator and Hub Overcurrent Indicator Change and switch off power to all
external downstream ports. The hub status change is reported on the next IN token
through the hub's interrupt endpoint, Endpoint1.
2. Individual Port Overcurrent Protection – The Hub Overcurrent Indicator and Hub
Overcurrent Indicator Change bits should be set to 0's. One MIC2026-2 is required for
the two USB ports. The FLG output of the MIC2026-2 associated with Port2 should be
connected to GPIO PD0 and the other FLG output to PD1. An overcurrent is indicated
by assertion of FLG. The firmware sets the corresponding port's Overcurrent Indicator
and the Overcurrent Indicator Change bits and switches off power to the port. At the
next IN token from the Host, the AT43USB325 reports the port status change through
the hub's Endpoint1.
8.4.7Port Power Switching
1. Gang Power Switching – One of the microcontroller GPIO pins, PWRN, must be pro-
2. Individual Power Switching – Two microcontroller GPIO pins, PWR2N and PWR3N,
grammed as an output to control the external switch such as the MIC2025-2. Switch
ON is requested by the USB Host through the SetPortFeature(PORT_POWER)
request. Switch OFF is executed upon receipt of a ClearPortFeature(PORT_POWER)
or upon detecting an overcurrent condition. The firmware clears the Power Control Bit.
Only if all of the Power Control Bits of ports 2 and 3 are cleared should the firmware deassert the PWRN pin.
must be assigned for each USB port to control the external switch such as the
MIC2026-2. Each of the Power Control Bits controls one PWRxN.
cally into one or more gangs, but reported individually.
3355C–USB–4/05
Figure 8-1 shows a simplified diagram of a power management circuit of an AT43USB325 based
hub design with global overcurrent protection and ganged power switching.
The AT43USB325 enters suspend only when requested by the USB host through bus inactivity
for at least 3 ms. The USB hardware would detect this request, sets the GLB_SUSP bit of
SPRSR, Suspend/Resume Register, and interrupts the microcontroller if the interrupt is enabled.
The microcontroller should shut down any peripheral activity and enter the Power Down mode
by setting the SE and SM bits of MCUCR and then executes the SLEEP instruction. The USB
hardware shuts off the oscillator and PLL.
8.5.1Global Resume
Global resume is signaled by a J to K state change on Port0. The USB hardware enables the
oscillator/PLL, propagates the RESUME signaling, and sets the RSM bit of the SPRSR, which
generates an interrupt. The microcontroller starts executing where it left off and services the
interrupt. As part of the ISR, the firmware clears the GLB_SUSP bit.
8.5.2Remote Wakeup
While the AT43USB325 is in global suspend, resume signaling is also possible through remote
wakeup if the remote wakeup feature is enabled. Remote wakeup is defined as a port connect,
port disconnect or resume signaling received at a downstream port or, in case of the embedded
function, through an external interrupt.
A remote wakeup initiated at a downstream port is similar in many respects to a global resume.
The USB hardware enables the oscillator/PLL, propagates the RESUME signaling, and sets the
RSM bit of the SPRSR which generates an interrupt. The microcontroller starts executing where
it left off and services the interrupt. As part of the ISR, the firmware clears the GLB_SUSP bit.
A remote wakeup from the embedded function is initiated through INT0 or the external interrupt,
INT1, which enables the oscillator/PLL and the USB hardware. The USB hardware drives
RESUME signaling and sets the FRMWUP and RSM bits of SPRSR which generates an interrupt to the microcontroller. The microcontroller starts executing where it left off and services the
interrupt. As part of the ISR, the firmware clears the GLB SUSP bit.
At completion of RESUME signaling, the USB hardware sets the Port Suspend Status Change
bits of the Hub Port Status Change Registers.
8.5.3Selective Suspend and Resume
See section on Hub Port Control Register, HPCON.
92
AT43USB325
3355C–USB–4/05
8.5.4Suspend and Resume Process
8.5.4.1Global Suspend
The Host stops sending packets, the hardware detects this as global suspend signaling and
stops all downstream signaling. Finally, the hardware asserts the GLB_SUSP interrupt.
1. Host stops sending packets
2. Global suspend signaling
detected
3. Stop downstream signaling
4. Set GBL SUS bit → interrupt
10. SLEEP bit detected
AT43USB325
HardwareFirmware
5. Shut down any peripheral activity
6. Set Sleep Enable and Sleep Mode
bits of MCUCR
7. Set GPIO to low power state if
required
8. Set UOVCER bit 2
9. Execute SLEEP instruction
8.5.4.2Global Resume
The Host resumes signaling, the hardware detects this as global resume and propagates this
signaling to all downstream ports. Finally, the hardware enables the oscillator and asserts the
RSM interrupt.
11. Shut off oscillator
HardwareFirmware
1. Host resumes signaling
2. Resume signaling detected
3. Propagate signaling downstream
4. Enable oscillator
5. Set RSM bit → interrupt
6. Reset RSM and GBL SUSP bits
7. Restore GPIO states if required
8. Clear UOVCER bit 2
9. Enable peripheral activity
3355C–USB–4/05
93
8.5.4.3Remote Wake-up, Downstream Ports
The hardware detects a connect/disconnect/port resume and propagates resume signaling
upstream. Finally, the hardware enables the oscillator and asserts the RSM interrupt.
HardwareFirmware
1. Connect/disconnect/port resume
detected
2. Propagate resume signaling
3. Enable Oscillator
4. Set RSM bit → interrupt
8.5.4.4Remote Wake-up, Embedded Function
The hardware detects an INT0/INT1 and propagates resume signaling upstream. Finally, the
hardware enables the oscillator and asserts the RSM and FRWUP interrupts.
HardwareFirmware
1. External event activates INT0/INT1
2. Propagate resume signaling
5. Reset RSM and GBL SUSP bits
6. Restore GPIO states if required
7. Clear UOVCER bit 2
8. Enable peripheral activity
3. Enable Oscillator
4. Set RSM and FRMWUP bits →
interrupt
8.5.4.5Selective Suspend, Downstream Ports
HardwareFirmware
3. Suspend or resume port per
command
5. Clear GLB SUSP, RSM, FRMWUP
bits
6. Restore GPIO states if required
7. Clear UOVCER bit 2
8. Enable peripheral activity
1. Set or Clear Port Feature
PORT_SUSPEND decoded
2. Write HPCON[2:0] and HPADD[2:0]
bits
94
AT43USB325
3355C–USB–4/05
8.5.4.6Selective Suspend, Embedded Function
HardwareFirmware
8.5.4.7Selective Resume, Embedded Function
HardwareFirmware
AT43USB325
1. Set Port Feature PORT_SUSPEND
decoded
2. Disable Port 1’s endpoints
3. Set GPIO to low power state if
required
1. Clear Port Feature PORT_SUSPEND
decoded
2. Clear Port 1 suspend status bit
3. Restore GPIO states if required
4. Wait 23 ms, then set enable status bit
and suspend change bit
5. Enable Port 1 endpoints
6. Send updated port status at next
IN to endpoint1
3355C–USB–4/05
95
9.Electrical Specification
9.1Absolute Maximum Ratings
Stresses beyond those listed below may cause permanent damage to the device. This is a
stress rating only and functional operation of the device at these or any other conditions beyond
those indicated in the operational sections of this specification is not implied. Exposure to absolute maximum rating conditions for extended periods may affect device reliability.