|
If you can't view the Datasheet, Please click here to try to view without PDF Reader . |
|
Datasheet File OCR Text: |
1 features ? avr ? 8-bit risc microcontroller with 83 ns instruction cycle time usb hub with one attached and four external ports usb function with two programmable endpoints external program memory, 512-byte data sram 32 x 8 general purpose working registers 32 programmable i/o port pins programmable serial uart master/slave spi serial interface one 8-bit timer/counter with separate pre-scaler one 16-bit timer/counter with separate pre-scaler and two pwms external and internal interrupt sources programmable watchdog timer 6 mhz oscillator with on-chip pll 5v operation with on-chip 3.3v power supply 100-lead lqfp package description the atmel at43usb320a is an 8-bit microcontroller based on the avr risc architec- ture. by executing powerful instructions in a single clock cycle, the at43usb320a achieves throughputs approaching 12 mips. the avr core combines a rich instruc- tion 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 effi- cient while achieving throughputs up to ten times faster than conventional cisc microcontrollers. the at43usb320a features an on-chip 512-byte of data memory. it is supported by a standard set of peripherals such as timer/counter modules, watchdog timer and inter- nal and external interrupt sources. the major peripheral included in the at43usb320a is the usb hub with an embedded function for use in peripherals such as monitor with remote control as shown in figure 1. note: there are two versions of the at43usb320a. they are indicated by the internal part numbers 55618d and 55618e. the only difference between the two versions is in the polarity of the suspend pin. the 55618d suspend pin is active low, while the 55618e suspend pin is active high. full-speed usb microcontroller with an embedded hub at43usb320a rev. 1443e?usb?4/04
2 at43usb320a 1443e?usb?4/04 hub/monitor/ir chip application figure 1. application example pin configurations remote ir unit ir xcvr ir xcvr hub/monitor/ir chip upstream port downstream ports i c /uart monitor c to usb host to usb devices 2 100-lead lqfp x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 75 74 73 72 71 70 69 68 67 66 65 64 63 62 61 60 59 58 57 56 55 54 53 52 51 100 99 98 97 96 95 94 93 92 91 90 89 88 87 86 85 84 83 82 81 80 79 78 77 76 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 3 at43usb320a 1443e?usb?4/04 pin assignment type: i = input o = output b = bi-directional v = power supply, ground pin number signal type 1pd2b 2pd3b 3pd4b 4pd5b 5pd6b 6pd7b 76/12n i 8lfto 9xtal1 i 10 xtal2 o 11 vss v 12 testn i 13 a0 b 14 a1 b 15 a2 b 16 a3 b 17 a4 b 18 a5 b 19 a6 b 20 a7 b 21 vss v 22 a8 b 23 a9 b 24 a10 b 25 nc ? 26 nc ? 27 a11 b 28 a12 b 29 a13 b 30 a14 b 31 a15 b 32 vcc v 33 vss v 34 cext1 o 35 suspend o 36 d0 i 37 d1 i 38 d2 i 39 d3 i 40 d4 i 41 d5 i 42 d6 i 43 d7 i 44 vss v 45 d8 i 46 d9 i 47 d10 i 48 d11 i 49 nc ? 50 nc ? 51 d12 i 52 d13 i 53 d14 i 54 d15 i 55 vss v 56 icp v 57 dp0 b 58 dm0 b 59 dp1 b 60 dm1 b 61 vcc v 62 vss v pin number signal type 4 at43usb320a 1443e?usb?4/04 63 cext2 o 64 dp2 b 65 dm2 b 66 dp3 b 67 dm3 b 68 dp4 b 69 dm4 b 70 pa0 b 71 pa1 b 72 pa2 b 73 pa3 b 74 pa4 b 75 vss v 76 nc ? 77 pa5 b 78 pa6 b 79 pa7 b 80 pb0 b 81 pb1 b pin number signal type 82 pb2 b 83 pb3 b 84 vss v 85 pb4 b 86 pb5 b 87 pb6 b 88 pb7 b 89 pc0 b 90 pc1 b 91 pc2 b 92 pc3 b 93 pc4 b 94 pc5 b 95 pc6 b 96 pc7 b 97 pd0 b 98 pd1 b 99 vss v 100 nc ? pin number signal type 5 at43usb320a 1443e?usb?4/04 signal description name type function v cc power supply/ground 5v power supply v ss power supply/ground ground cext1, 2 power supply/ground external capacitors for power supplies ? high quality 0.33 f capacitors must be connected to cext1 and 2 for proper operation of the chip. xtal1 input oscillator input ? input to the inverting oscillator amplifier. xtal2 output oscillator output ? output of the inverting oscillator amplifier. lft input 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.22 f capacitor to ground (vss). both capacitors must be high quality ceramic. dpo bi-directional upstream plus usb i/o ? this pin should be connected to cext1 through an external 1.5 k ? . dmo bi-directional upstream minus usb i/o dp[1:4] bi-directional downstream plus usb i/o ? each of these pins should be connected to vss through an external 15 k ? resistor. dp[1:4] and dm[1:4] are the differential signal pin pairs to connect downstream usb devices. dm[1:4] bi-directional downstream minus usb i/o ? each of these pins should be connected to vss through an external 15 k ? resistor. pa[0:7] bi-directional port a[0:7] ? bi-directional 8-bit i/o port with 4 ma drive strength. pb[0:7] bi-directional port b[0:7] ? bi-directional 8-bit i/o port with 4 ma drive. pb[0,1,4:7] have dual functions as shown below: port pin alternate function pb0 t0, timer/counter0 external input pb1 t1, timer/counter1 external input pb4 ssn, spi slave port select or scl, i2c serial bus clock pb5 mosi, spi slave port select input pb6 miso, spi master data in, slave data out pb7 sck, spi master clock out, slave clock in pc[0:7] bi-directional port c[0:7] ? bi-directional 8-bit i/o port with 4 ma drive strength. pd[0:7] bi-directional port d[0:7] ? bi-directional i/o ports with 4 ma drive strength. pd[0:3,5] have dual functions as shown below: port pin alternate function pd0 rxd, serial input port pd1 txd, serial input port pd2 int0, external interrupt 0 pd3 int1, external interrupt 1 pd5 oc1a timer/counter1 output compare a testn input test pin ? this pin should be tied to ground. suspend output suspend ? this pin is asserted when the at43usb320a enters the suspend status. in the 55618d, it is active low and in the 55618e and later versions, it is active high. 6 at43usb320a 1443e?usb?4/04 figure 2. the at43usb320a enhanced risc architecture interrupt unit 8-bit timer/counter 16-bit timer/counter watchdog timer spi unit serial uart status and control program counter external program memory instruction register instruction decoder control lines 32 x 8 general-purpose registers alu 512 x 8 sram 32 gpio lines usb hub and function 7 at43usb320a 1443e?usb?4/04 architectural overview the peripherals and features of the at43usb320a microcontroller are similar to those of the at90s8515, with the exception of the following modifications: external program memory no eeprom no external data memory accesses no analog comparation idle mode not supported usb hub with attached function no internal pull-ups in the general-purpose i/o pin pa, pb, pc, pd the embedded usb hardware of the at43usb320a 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 2 additional program- mable endpoints with separate 8-byte fifos. 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 ? micro- controller family. the registers for managing the usb operations are mapped into its sram space. the i/o section on page 16 summarizes the available i/o registers. the ?avr register set? on page 36 covers the avr registers. please refer to the atmel avr manual for more information. the fast-access register file concept 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 arith- metic 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 func- tion 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 2 on page 6 shows the at43usb320a 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. the i/o memory space contains 64 addresses for cpu peripheral functions as control regis- ters, 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 pro- gram 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 con- tains a 16- or 32-bit instruction. 8 at43usb320a 1443e?usb?4/04 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 pro- grams 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 flexi- ble 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 accor- dance with their interrupt vector position. the lower the interrupt vector address, the higher the priority. the general- purpose register file 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 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 imple- mented 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. table 1 . avr cpu general purpose working register register address comment r0 $00 r1 $01 r2 $02 .. r13 $0d r14 $0e r15 $0f r16 $10 r17 $11 .. r26 $1a x-register low byte r27 $1b x-register high byte r28 $1c y-register low byte r29 $1d y-register high byte r30 $1e z-register low byte r31 $1f z-register high byte 9 at43usb320a 1443e?usb?4/04 x-, y- and z- registers registers r26..r31 contain some added functi ons to their general-purpose usage. these reg- isters are address pointers for indirect addressing of the data space. the three indirect address registers x, y, and z are defined as: in the different addressing modes these address registers have functions as fixed displace- ment, automatic increment and decrement (see the descriptions for the different instructions). alu ? arithmetic logic unit 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, log- ical and bit-functions. program memory the at43usb320a operates from an external program memory. since all instructions are 16- or 32-bit words, the program memory is organized as x16. the at43usb320a program counter (pc) is 16 bits wide, thus addressing the 64k program memory addresses. constant tables can be allocated within the entire program memory address space (see the lpm - load program memory instruction description). x-register 15 xh xl 0 7070 r27 ($1b) r26 ($1a) y-register 15 yh yl 0 7070 r29 ($1d) r28 ($1c) z-register 15 zh zl 0 7070 r30 ($1f) r31 ($1e) 10 at43usb320a 1443e?usb?4/04 sram data memory table 3 summarizes how the at43usb320a 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-incre- ment, the address registers x, y, and z are decremented and incremented. the 32 general purpose working registers, 64 i/o registers and the 1024 bytes of internal data sram in the at43usb320a 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 and table 4 give an overview of these registers. 11 at43usb320a 1443e?usb?4/04 table 2 . sram organization register file data address space r0 $0000 r1 $0001 r30 $001e r31 $001f i/o registers $00 $0020 $01 $0021 $3e $005e $3f $005f internal sram $0060 $0061 $025e $045f usb registers $1f00 $1ffe $1fff 12 at43usb320a 1443e?usb?4/04 table 3 . usb hub and function registers address name function $1ffd frm_num_h frame number high register $1ffc frm_num_l frame number low register $1ffb glb_state global state register $1ffa sprsr suspend/resume register $1ff9 sprsie suspend/resume interrupt enable register $1ff7 uisr usb interrupt status register $1ff5 uiar usb interrupt acknowledge register $1ff3 uier usb interrupt enable register $1ff2 uovcer overcurrent detect register $1fef haddr hub address register $1fee faddr function address register $1fe7 hendp0_cntr hub endpoint 0 control register $1fe5 fendp0_cntr function endpoint 0 control register $1fe4 fendp1_cntr function endpoint 1 control register $1fe3 fendp2_cntr function endpoint 2 control register $1fdf hcsr0 hub controller endpoint 0 service routine register $1fdd fcsr0 function controller endpoint 0 service routine register $1fdc fcsr1 function controller endpoint 1 service routine register $1fdb fcsr2 function controller endpoint 2 service routine register $1fd7 hdr0 hub endpoint 0 fifo data register $1fd5 fdr0 function endpoint 0 fifo data register $1fd4 fdr1 function endpoint 1 fifo data register $1fd3 fdr2 function endpoint 2 fifo data register $1fcf hbyte_cnt0 hub endpoint 0 byte count register $1fcd fbyte_cnt0 function endpoint 0 byte count register $1fcc fbyte_cnt1 function endpoint 1 byte count register $1fcb fbyte_cnt2 function endpoint 2 byte count register $1fc7 hstr hub status register $1fc5 hpcon hub port control register $1fbc hpstat5 hub port 5 status register $1fbb hpstat4 hub port 4 status register $1fba hpstat3 hub port 3 status register $1fb9 hpstat2 hub port 2 status register $1fb8 hpstat1 hub port 1 status register $1fb4 hpscr5 hub port 5 status change register 13 at43usb320a 1443e?usb?4/04 $1fb3 hpscr4 hub port 4 status change register $1fb2 hpscr3 hub port 3 status change register $1fb1 hpscr2 hub port 2 status change register $1fb0 hpscr1 hub port 1 status change register $1fac pstate5 hub port 5 bus state register $1fab pstate4 hub port 4 bus state register $1faa pstate3 hub port 3 bus state register $1fa9 pstate2 hub port 2 bus state register $1fa8 pstate1 hub port 1 bus state register $1fa7 hcar0 hub endpoint 0 control and acknowledge register $1fa5 fcar0 function endpoint 0 control and acknowledge register $1fa4 fcar1 function endpoint 1 control and acknowledge register $1fa3 fcar2 function endpoint 2 control and acknowledge register table 3 . usb hub and function registers (continued) address name function 14 at43usb320a 1443e?usb?4/04 table 4 . usb hub and function registers name address bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 glb_state $1ffb ? susp flg resume flg rmwupe confg hadd en sprsr $1ffa ? ? ? ? ? frwup rsm glb susp sprsie $1ff9 ? ? ? ? ? frwup ie rsm ie glb susp ie uisr $1ff7 sof int eof2 int ? fep3 in t hep0 int fep2 int fep1 int fep0 int uiar $1ff5 sof intack eof2 intack ? fep3 intack hep0 intack fep2 intack fep1 intack fep0 intack uier $1ff3 sof ie eof2 ie ? fep3 ie hep0 ie fep2 ie fep1 ie fep0 ie haddr $1fef saen hadd6 hadd5 hadd4 hadd3 hadd2 hadd1 hadd0 faddr $1fee fen fadd6 fadd5 fadd4 fadd3 fadd2 fadd1 fadd0 hendp0_cntr $1fe7 epen ? ? ? dtgle epdir eptype1 eptype0 fendp0_cntr $1fe5 epen ? ? ? dtgle epdir eptype1 eptype0 fendp1_cntr $1fe4 epen ? ? ? dtgle epdir eptype1 eptype0 fendp2_cntr $1fe3 epen ? ? ? dtgle epdir eptype1 eptype0 hcsr0 $1fdf ? ? ? ? stall sent rx setup rx out packet tx cemplete fcsr0 $1fdd ? ? ? ? stall sent rx setup rx out packet tx complete fcsr1 $1fdc ? ? ? ? stall sent rx setup rx out packet tx complete fcsr2 $1fdb ? ? ? ? stall sent rx setup rx out packet tx complete hdr0 $1fd7 data7 data6 data5 data4 data3 data2 data1 data0 fdr0 $1fd5 data7 data6 data5 data4 data3 data2 data1 data0 fdr1 $1fd4 data7 data6 data5 data4 data3 data2 data1 data0 fdr2 $1fd3 data7 data6 data5 data4 data3 data2 data1 data0 hbyte_cnt0 $1fcf ? ? ? bytct4 bytct3 bytct2 bytct1 bytct0 fbyte_cnt0 $1fcd ? ? ? bytct4 bytct3 bytct2 bytct1 bytct0 fbyte_cnt1 $1fcc ? ? ? bytct4 bytct3 bytct2 bytct1 bytct0 fbyte_cnt2 $1fcb ? ? ? bytct4 bytct3 bytct2 bytct1 bytct0 hstr $1fc7 ? ? ? ? ovlsc lpsc ovi lps hpcon $1fc5 ? hpcon2 hpcon1 hpcon0 ? hpadd2 hpadd1 hpadd0 hpstat5 $1fbc ? lsp ppstat prstat poci psstat pestat pcstat hpstat4 $1fbb ? lsp ppstat prstat poci psstat pestat pcstat hpstat3 $1fba ? lsp ppstat prstat poci psstat pestat pcstat hpstat2 $1fb9 ? lsp ppstat prstat poci psstat pestat pcstat hpstat1 $1fb8 ? lsp ppstat prstat poci psstat pestat pcstat hpscr5 $1fb4 ? ? ? rstsc pocic pssc pesc pcsc hpscr4 $1fb3 ? ? ? rstsc pocic pssc pesc pcsc hpscr3 $1fb2 ? ? ? rstsc pocic pssc pesc pcsc hpscr2 $1fb1 ? ? ? rstsc pocic pssc pesc pcsc hpscr1 $1fb0 ? ? ? rstsc pocic pssc pesc pcsc pstate5 $1fac ? ? ? ? ? ? dpstate dmstate pstate4 $1fab ? ? ? ? ? ? dpstate dmstate pstate3 $1faa ? ? ? ? ? ? dpstate dmstate pstate2 $1fa9 ? ? ? ? ? ? dpstate dmstate pstate1 $1fa8 ? ? ? ? ? ? dpstate dmstate hcar0 $1fa7 ctl dir data end force stall tx packet ready stall_sent-ack rx_setup_ack rx_out_packet_ack tx_complete-ack 15 at43usb320a 1443e?usb?4/04 fcar0 $1fa5 ctl dir data end force stall tx packet ready stall_sent-ack rx_setup_ack rx_out_packet_ack tx_complete-ack fcar1 $1fa4 ctl dir data end force stall tx packet ready stall_sent-ack rx_setup_ack rx_out_packet_ack tx_complete-ack fcar2 $1fa3 ctl dir data end force stall tx packet ready stall_sent-ack rx_setup_ack rx_out_packet_ack tx_complete-ack table 4 . usb hub and function registers (continued) name address bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 16 at43usb320a 1443e?usb?4/04 i/o memory the i/o space definition of the at43usb320a is shown in the following table: table 5 . i/o memory space i/o (sram) address name function $3f ($5f) sreg status register $3e ($5e) sph stack pointer high $3d ($5d) spl stack pointer low $3b ($5b) gimsk general interrupt mask register $3a ($5a) gifr general interrupt flag register $39 ($59) timsk timer/counter interrupt mask register $38 ($58) tifr timer/counter interrupt mask register $35 ($55) mcucr mcu general control register $33 ($53) tccr0 timer/counter0 control register $32 ($52) tcnt0 timer/counter0 (8 bit) $2f ($4f) tccr1a timer/counter1 control register a $2e ($4e) ttcr1b timer/counter0 control register b $2d ($52) tcnt1h timer/counter1 high byte $2c ($52) tcnt1l timer/counter0 low byte $2b ($4b) ocr1ah timer/counter1 output compare register a high byte $2a ($4a) ocr1al timer/counter1 output compare register a low byte $29 ($49) ocr1bh timer/counter1 output compare register b high byte $28 ($48) ocr1bl timer/counter1 output compare register b low byte $25 ($45) icr1h t/c 1 input capture register high byte $24 ($44) icr1l t/c 1 input capture register low byte $21 ($41) wdtcr watchdog timer counter register $1b ($4b) porta data register, port a $1a ($3a) ddra data direction register, port a $19 ($39) pina input pins, port a $18 ($38) portb data register, port b $17 ($37) ddrb data direction register, port b $16 ($36) pinb input pins, port b $13($33) portc data register, port c $12 ($32) portd data register, port d $11 ($31) ddrd data direction register, port d $10 ($30) pind input pins, port d $0b (2b) usr uart status register $0a (2a) ucr uart control register $09 (29) ubrr uart baud rate register 17 at43usb320a 1443e?usb?4/04 all at43usb320a 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 instruc- tions. 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 address- ing 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. for compatibility with future devices, reserved bits should be written to zero if accessed. reserved i/o memory addresses should never be written. usb hub a block diagram of the usb hardware of the at43usb320a is shown in figure 3. the usb hub of the at43usb320a has 5 downstream ports. the embedded function is permanently attached to port 5. ports 1 through 4 are available as external ports. the actual number of ports used is strictly defined by the firmware of the at43usb320a and can vary from 0 to 4. because the exact configuration is defined by firmware, ports 1 to 4 may even function as per- manently attached ports as long as the hub descriptor identifies them as such. usb function the embedded usb function has its own device address and has a default endpoint plus 2 other programmable endpoints with 8-byte fifos. endpoints 1 - 3 can be programmed as interrupt in or out or bulk in or out endpoints. 18 at43usb320a 1443e?usb?4/04 figure 3. usb hardware hub repeater serial interface engine avr microcontroller data address control hub interface unit port 5 function interface unit port 0 xcvr port 2 xcvr port 4 xcvr port 3 xcvr port 1 xcvr 19 at43usb320a 1443e?usb?4/04 functional description on-chip power supply the at43usb320a 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 at43usb320a internal circuit and the 1.5k pull-up resistor only and should not be used for other purposes. external 0.33 f filter capacitors are required at the power supply outputs, cext1 and 2. 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 suppl y currents beyond the c apability of the on-chip power supply, the at43usb320a should be suppli ed by an external 3.3v power supply. in this case, the 5v v cc power supply pin should be left unconnected and the 3.3v power supplied to the chip through the cext1 and 2 pins. i/o pin characteristics the i/o pins of the at43usb320a should not be directly connected to voltages less than v ss 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. oscillator and pll all clock signals required to operate the at43usb320a are derived from an on-chip oscillator. to reduce emi and power dissipation, the oscillator is designed to operate with a 6 mhz crys- tal. 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 at43usb320a 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.22 f in parallel with a 0.01 f capacitor must be connected from the lft pin to v ss . use only high-quality ceramic capacitors. 20 at43usb320a 1443e?usb?4/04 figure 4. oscillato r and pll reset and interrupt handling the at43usb320a provides 22 different interrupt sources with 13 separate reset vectors, each with a separate program vector in the program memory space. eleven of the interrupt sources share 2 interrupt reset vectors. these 11 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 6. 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 inter- rupt, etc. at43usb320a xtal1 xtal2 lft y1 6.000 mhz u1 c2 0.01 uf c1 0.22 uf r1 100 table 6 . reset and interrupt vectors vector no. program address source interrupt definition 1 $000 reset external reset, power-on reset and watchdog reset 2 $002 int0 usb suspend and resume 3 $004 int1 external interrupt request 1 4 $006 timer1 capt timer/counter1 capture event 5 $008 timer1 compa timer/counter1 compare match a 6 $00a timer1 compb timer/counter1 compare match b 7 $00c timer1, ovf timer/counter1 overflow 8 $00e timer0, ovf timer/counter0 overflow 9 $010 spi, stc spi serial transfer complete 10 $012 uart rx uart rx complete 11 $014 uart udre uart rx data receiver output 12 $016 uart tx uart tx complete 13 $018 usb hw usb hardware 21 at43usb320a 1443e?usb?4/04 the most typical and general program setup for the reset and interrupt vector addresses are: 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 and usb interrupt enable regis- ter. the usb bus reset and suspend/resume are grouped in another set of registers: suspend/resume register and suspend/resume interrupt enable register. address labels code comments $000 jmp reset ; reset handler $004 jmp ext_int1 ; irq1 handler $00e jmp tim0_ovf ; timer0 overflow handler $018 jmp usb_hw ; usb handler ; $00d main: ldi r16, high (ramend) ; main program start $00e out sph, r16 $00f ldi r16, low (ramend) $010 out spl, r16 $011 22 at43usb320a 1443e?usb?4/04 figure 5. at43usb320a interrupt structure reset sources the at43usb320a has four sources of reset: 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 ? 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. 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 vector s are not used, and regular program code can be placed at these locations. the circuit diagram in figure 6 shows the reset logic. the user can select the start-up time according to typical oscillator start-up. the number of wdt oscilla- tor cycles used for each time-out is shown in table 7. suspend/resume register suspend/resume interrupt enable register usb interrupt status register usb interrupt enable register usb uart udre spi stc timer0 ovf timer1 ovf timer1 compb timer1 compa timer1 capt int1 int0, susp/rsm reset microcontroller interrupt logic 13 12 9 8 7 6 5 4 3 2 1 sof eof2 fep2 fep1 fep0 reserved hep0 frmwup rsm glb susp uart rx 10 11 uart tx eof1 23 at43usb320a 1443e?usb?4/04 figure 6. reset logic power-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 cc has reached the power-on threshold voltage, regardless of the v cc rise time. if the build-in start-up delay is sufficient, reset can be connected to v cc directly or via an external pull-up resistor. by holding the pin low for a period after v cc has been applied, the power-on reset period can be extended. fstrt cntr reset usb reset or por ckt reset ckt watchdog timer divider 14-bit cntr vcc rstn system clock s r on table 7 . number of watchdog oscillator cycles fstrt time-out at v cc = 5v number of wdt cycles programmed 1.1 ms 1k unprogrammed 16.0 ms 16k 24 at43usb320a 1443e?usb?4/04 external reset an external reset is generated by a low-level on the r eset pin. reset pulses l onger 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 rst on its positive edge, the delay timer starts the mcu after the time-out period t tout has expired. figure 7. external reset during operation watchdog 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 tout . figure 8. watchdog reset during operation non-usb related interrupt handling the at43usb320a 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 conditi on 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 inter- rupt. some of the interrupt flags can also be cleared by writing a logic one to the flag bit position(s) to be cleared. t tout v rst vcc reset time-out internal reset t tout vcc reset wdt time-out reset time-out 1 xtal cycle internal reset 25 at43usb320a 1443e?usb?4/04 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 exec uted 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. 26 at43usb320a 1443e?usb?4/04 general interrupt mask register ? gimsk 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 acti- vated 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 exter- nal interrupt request 1 is executed from program memory address $004. see also ?external interrupts? on page 29. bit 6 ? int0: interrupt request 0 (suspend/resume interrupt) enable 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 acti- vated 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 inter- rupt request 0 is executed from program memory address $002. see also ?external interrupts? on page 29. bits 5..0 ? res: reserved bits these bits are reserved bits in the at43usb320a and always read as zero. general interrupt flag register ? gifr bit 7 ? intf1: external interrupt flag1 when an event on the int1 pin triggers an interrupt request, intf1 becomes set (one). if the i-bit in sreg and the int1 bit in gimsk are set (one), the mcu will jump to the interrupt vec- tor 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 at43usb320a and always read as zero. bit 7 6 5 4 3 210 $3b ($5b) int1 int0 ? ? ? ? ? ? gimsk read/write r/w r/w r r r r r r initial value 0 0 0 0 0 0 0 0 bit 7 6 5 4 3 2 1 0 $3a ($5a) intf1 int f0 ? ? ? ? ? ? gifr read/write r/w r/w r r r r r r initial value 0 0 0 0 0 0 0 0 27 at43usb320a 1443e?usb?4/04 timer/counter interrupt mask register ? timsk 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 $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 at43usb320a 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 vec- tor $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 at43usb320a 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 at43usb320a and always reads zero. bit 7 6 5 4 3 2 1 0 $39 ($59) toie1 ocie1a ocie1nb ? ticie1 ? toie0 ? timsk read/write r/w r/w r/w r r/w r r/w r initial value 0 0 0 0 0 0 0 0 28 at43usb320a 1443e?usb?4/04 timer/counter interrupt flag register ? tifr 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 ma tch occurs between the timer/counter1 and the data in ocr1a - output compare register 1a. ocf1a is cleared by the hardware when exe- cuting 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 inter- rupt is executed. bit 5 ? ocf1b: output compare flag 1b the ocf1b bit is set (one) when compare ma tch occurs between the timer/counter1 and the data in ocr1b - output compare register 1b. ocf1b is cleared by the hardware when exe- cuting 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 inter- rupt is executed. bit 4 ? res: reserved bit this bit is a reserved bit in the at43usb320a 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 hard- ware 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 at43usb320a 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 at43usb320a and always reads zero. bit 7 6 543210 $38 ($58) tov1 ocf1a ocifb ? icf1 ? tov0 ? tifr read/write r/w r/w r/w r r/w r r/w r initial value 0 0 0 0 0 0 0 0 29 at43usb320a 1443e?usb?4/04 external interrupts the external interrupts are triggered by the int0 and int1 pins. observe that, if enabled, the int0/int1 interrupt will trigger even if the int0/int1 pins are configured as outputs. this fea- ture provides a way of generating a software interrupt. the external interrupts can be triggered by a falling or rising edge or a low level. this is set up as indicated in the specification for the mcu control register (mcucr) and the interrupt sense control register (iscr). when the external interrupt is enabled and is configured as level triggered, the interrupt will trigger as long as the pin is held low. the external interrupts are set up as described in the specification for the mcu control register (mcucr). interrupt 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 th is 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 nor- mally 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 from an interrupt, it will always return to the main program and execute one more instruc- tion before any pending interrupt is served. 30 at43usb320a 1443e?usb?4/04 mcu control register ? mcucr 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 sl eep instruc- tion 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 at43usb320a 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 corre- sponding 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: bit 1, 0 ? isc01, isc00: interrupt sense control 0 bit 1 and bit 0 the external interrupt 1 is activated by the external pin int1 if the sreg i-flag and the corre- sponding 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: bit 7 6 5 4 3 2 1 0 $35 ($55) ? ? se sm isc11 isc10 isc01 isc00 mcucr read/write r r r/w r/w r/w r/w r/w r/w initial value 0 0 0 0 0 0 0 0 table 8 . int1 sense control isc11 isc10 description 0 0 the low level of int1 generates an interrupt request. 01reserved. 1 0 the falling edge of int1 generates an interrupt request. 1 1 the rising edge of int1 generates an interrupt request. table 9 . int1 sense control isc01 isc00 description 0 0 the low level of int1 generates an interrupt request. 01reserved. 1 0 the falling edge of int1 generates an interrupt request. 1 1 the rising edge of int1 generates an interrupt request. 31 at43usb320a 1443e?usb?4/04 usb interrupt sources the usb interrupts are described below. all interrupts have individual enable, status, and mask bits through the interrupt enable regis- ter 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. table 1 0. usb interrupt sources interrupt description sof received whenever usb hardware decodes a valid start of frame. the frame number is stored in the two frame number registers. eof2 activated whenever the hub's frame timer reaches its eof2 time point. function ep0 interrupt see ?control transfers at control endpoint ep0? on page 70 for details. function ep1 interrupt 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. function ep2 interrupt 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. hub ep0 interrupt see ?control transfers at control endpoint ep0? on page 70 for details. frwup usb hardware has received a embedded function remote wakeup request. glb susp 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. rsm 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. 32 at43usb320a 1443e?usb?4/04 usb 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 end- points as described in the table below. please refer to the control and status register for more information. usb interrupt status register ? uisr bit 7 ? sof int: start of frame interrupt 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, 4 ? res: reserved bits these bits are reserved and always read as zero. 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) 3. rx setup is set (control endpoints only) 4. tx complete is set table 1 1. usb endpoint interrupt sources bit endpoint type rx_out_packet control, out tx_complete control, in stall_sent control, in rx_setup control bit 7 654 3 210 $1ff7 sof int eof2 int ? ? hep0 int fe2 int fe1 int fe0 int uisr read/write r r r r r r r r initial value 0 0 0 0 0 0 0 0 33 at43usb320a 1443e?usb?4/04 usb interrupt acknowledge register ? uiar bit 7 ? sof intack: start of frame interrupt acknowledge the microcontroller firmware writes a 1 to this bit to clear the sof int bit. bit 6 ? eof2 intack: eof2 interrupt acknowledge the microcontroller firmware writes a 1 to this bit to clear the eof2 int bit. bit 5, 4 ? res: reserved bits these bits are reserved and always read as zero. bit 3 ? hep0 intack: hub endpoint 0 interrupt acknowledge the microcontroller firmware writes a 1 to this bit to clear the hep0 int bit. bit 2 ? fep2 intack: function endpoint 2 interrupt acknowledge the microcontroller firmware writes a 1 to this bit to clear the fep2 bit. bit 1 ? fep1 intack: function endpoint 1 interrupt acknowledge the microcontroller firmware writes a 1 to this bit to clear the fep1 bit. bit 0 ? fep0 intack: function endpoint 0 interrupt acknowledge the microcontroller firmware writes a 1 to this bit to clear the fep0 int bit. bit7 654 321 0 $1ff5 sof intack eof2 intack ? ? hep0 intack fep2 imsk fep1 intack fep0 intack uiar read/write w w r w w w w w initial value 0 0 0 0 0 0 0 0 34 at43usb320a 1443e?usb?4/04 usb interrupt enable register ? uier bit 7 ? sof ie: enable start of frame interrupt 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, 4 ? res: reserved bit these bits are reserved and always read as zero. bit 3 ? hep0 ie: enable endpoint 0 interrupt when the hep0 ie bit is set (1), the hub endpoint 0 interrupt is enabled. 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. suspend/resume register ? sprsr bit 7..3 ? res: reserved bits these bits are reserved and are always read as zeros. bit 2 ? frwup: function remote wakeup the usb hardware sets this bit to signal that external interrupt 1 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 gl obal suspend signaling is detected. an interrupt is generated if the glbsusp ie bit of the sprsie register is set. bit7 654 321 0 $1ff3 sof ie eof2 ie ? ? hep0 ie fep2 ie fep1 ie fep0 ie uier read/write r/w r/w r r/w r/w r/w r/w r/w initial value 0 0 0 0 0 0 0 0 bit76543 2 1 0 $1ffa ? ? ? ? ? frwup rsm glb susp sprsr read/write r r r r r/w r r r initial value 0 0 0 0 0 0 0 0 35 at43usb320a 1443e?usb?4/04 suspend/resume interrupt enable register ? sprsie bit 7..3 ? res: reserved bits these bits are reserved and are always read as zeros. bit 3 ? bus int en: usb reset interrupt enable when the bus int en bit is set, the usb and microcontroller resets are separated. a usb bus reset (se0 for longer than 3 ms) will reset the usb hardware only and not the microcon- troller. however, an interrupt to the microcontroller will be generated and bit 3 of sprsr is set. 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. bit 7 6 5 4 3 2 1 0 $1ff9 ? ? ? ? ? frwup rsm glb susp sprsie read/write r r r r r/w r r r initial value 0 0 0 0 0 0 0 0 36 at43usb320a 1443e?usb?4/04 avr register set status register and stack pointer status register ? sreg bit 7 ? i: global interrupt enable the global interrupt enable bit must be set (one) for the interrupts to be enabled. the individ- ual 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 des- tination 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 opera- tions. 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. bit 76543210 $3f ($5f) ithsvnzcsreg read/write r/w r/w r/w r/w r/w r/w r/w r/w initial value 0 0 0 0 0 0 0 0 37 at43usb320a 1443e?usb?4/04 stack pointer register ? sp 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. sleep 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. power 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 and the watchdog (if enabled) continue operating. only an external reset or 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 tout . otherwise, the mcu will fail to wake up. bit 15 14 13 12 11 10 9 8 $3e ($5e) i t h s v n z c sph $3d ($5d) sp7 sp6 sp5 sp4 sp3 sp2 sp1 sp0 spl 76 5 4 3210 read/write r/w r/w r/w r/w r/w r/w r/w r/w r/w r/w r/w r/w r/w r/w r/w r/w initial value 0 0 0 0 0 0 0 0 00 0 0 0000 38 at43usb320a 1443e?usb?4/04 timer/counters the at43usb320a 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 prescal- ing timer. both timer/counters can either be used as a timer with an internal clock timebase or as a counter with an external pin connection which triggers the counting. timer/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 9. timer/counter prescaler 10-bit t/c prescaler cs00 cs01 cs02 cs10 cs11 cs12 0 0 ck t0 t1 ck/8 ck/64 ck/256 ck/1024 timer/counter1 clock source tck1 timer/counter0 clock source tck0 39 at43usb320a 1443e?usb?4/04 8-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 regis- ter (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 oscil- lator 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 10. timer/counter0 block diagram control logic timer/counter0 (tcnt0) timer int. mask register (timsk) timer int. flag register (tifr) t/c0 control register (tccr0) toie1 oicie1a oicie1b ticie1 toie0 tov1 ocf1a ocf1b icf1 tov0 cs02 cs01 cs00 t/c clock source tov0 70 ck t0 t/c0 overflow irq 8-bit data bus 40 at43usb320a 1443e?usb?4/04 timer/counter0 control register ? tccr0 bits 7..3 ? res: reserved bits these bits are reserved bits in the at43usb320a 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. 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 clo ck the counter even if the pin is configured as an output. this feature can give the user sw control of the counting. timer/counter0 ? tcnt0 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 count- ing in the clock cycle following the write operation. bit 7 6 5 4 3 2 1 0 $33 ($53) ? ? ? ? ? cs02 cs01 cs00 tccr0 read/write r r r r r r/w r/w r/w initial value 0 0 0 0 0 0 0 0 table 1 2. clock 0 prescale select cs02 cs01 cs00 description 0 0 0 stop, the timer/counter0 is stopped 001ck 010ck/8 011ck/64 100ck/256 101ck/1024 1 1 0 external pin t0, falling edge 1 1 1 external pin t0, rising edge bit 7 6 5 4 3 2 1 0 $32 ($52) msb ? ? ? ? ? ? lsb tcnt0 read/write r/w r/w r/w r/w r/w r/w r/w r/w initial value 0 0 0 0 0 0 0 0 41 at43usb320a 1443e?usb?4/04 16-bit timer/counter1 figure 11. timer/counter1 block diagram control logic timer int. mask register (timsk) t/c1 control register a (tccr1a) t/c1 control register b (tccr1b) toie1 ocie1a ocie1b ticie1 toie0 com1a1 com1a0 com1b1 icf1 pwm11 cs12 cs11 cs10 ck t1 t/c1 overflow irq 8-bit data bus 7 0 t/c1 input capture register (icr1) 8 15 timer/counter1 (tcnt1) 16-bit comparator timer/counter1 output compare register a 16-bit comparator timer/counter1 output compare register b 7 0 8 15 7 0 8 15 7 0 8 15 0 15 7 0 8 15 7 8 t/c1 compare matcha irq t/c1 compare matchb irq t/c1input capture irq tov1 ocf1a ocf1b icf1 tov0 tov1 timer int. flag register (tifr) ctc1 icnc1 ices1 com1b0 ocf1a ocf1b pwm10 capture trigger 42 at43usb320a 1443e?usb?4/04 16-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 oscil- lator 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 reg- ister 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 con- tents 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). in addition, the analog comparator can be set to trigger the input cap- ture. refer to . 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 12. icp pin schematic diagram icp 0 1 noise canceler edge select icnc1 ices1 icf1 acic aco acic: comparator ic enable acc0: comparator output 43 at43usb320a 1443e?usb?4/04 timer/counter1 control register a ? tccr1a bits 7, 6 ? com1a1, com1a0: compare output mode1a, bits 1 and 0 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 13. bits 5, 4 ? com1b1, com1b0: compare output mode1b, bits 1 and 0 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 fol- lowing control configuration is given: notes: 1. x = a or b 2. in pwm mode, these bits have a different function. refer to table 17 for a detailed description. bits 3..2 ? res: reserved bits these bits are reserved bits in the at43usb320a and always read zero. bits 1..0 ? pwm11, pwm10: pulse width modulator select bits 1 and 0 these bits select pwm operation of timer/counter1 as specified in table 14. bit 7 6 5 4 3 2 1 0 $2f ($4f) com1a1 com1a0 com1b1 com1b0 ? ? pwm11 pwm10 tccr1a read/write r/w r/w r/w r/w r r r/w r/w initial value 0 0 0 0 0 0 0 0 table 1 3. compare 1 mode select (2) com1x1 com1x0 description 0 0 timer/counter1 disconnected from output pin oc1x. (1) 0 1 toggle the oc1x output line. (1) 1 0 clear the oc1x output line (to zero). (1) 1 1 set the oc1x output line (to one). (1) table 1 4. pwm mode select pwm11 pwm10 description 0 0 pwm operation of timer/counter1 is disabled. 0 1 timer/counter1 is an 8-bit pwm. 1 0 timer/counter1 is a 9-bit pwm. 1 1 timer/counter1 is a 10-bit pwm. 44 at43usb320a 1443e?usb?4/04 timer/counter1 control register b ? tccr1b bit 7 ? icnc1: input capture1 noise canceler (4 cks) when the icnc1 bit is cleared (zero), the input capture trigger noise canceler function is dis- abled. the input capture is triggered at the first rising/falling edge sampled on the icp (input capture pin) as s pecified. when the icnc1 bit is set (one), four successive samples are mea- sured 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 time r/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 at43usb320a 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: ... | c-2, c-2, c-2, c-2, c-2, c-2, c-2, c-2 | c-1, c-1, c-1, c-1, c-1, c-1, c-1, c-1 | c, 0, 0, 0, 0, 0, 0, 0 | ... in pwm mode, this bit has no effect. 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. bit 7 6 5 4 3 2 1 0 $2e ($4e) icnc1 ices1 ? ? ctc1 cs12 cs11 cs10 tccr1b read/write r/w r/w r/w r/w r r r/w r/w initial value 0 0 0 0 0 0 0 0 table 1 5. clock 1 prescale select cs12 cs11 cs10 description 0 0 0 stop, the timer/counter1 is stopped. 001ck 010ck/8 011ck/64 1 0 0 ck/256 45 at43usb320a 1443e?usb?4/04 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. 1 0 1 ck/1024 1 1 0 external pin t1, falling edge 1 1 1 external pin t1, rising edge table 15. clock 1 prescale select (continued) cs12 cs11 cs10 description 46 at43usb320a 1443e?usb?4/04 timer/counter1 ? tcnt1h and tcnt1l 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 tem- porary 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 dis- abled 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 regis- ter. 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 regis- ter simultaneously. consequently, the high byte tcnt1h must be accessed first for a full 16- bit register write operation. 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. bit 15 14 13 12 11 10 9 8 $2d ($4d) msb ? ? ? ? ? ? ? tcnt1h $2c ($4c) ? ? ? ? ? ? ? lsb tcnt1l 76 5 4 3210 read/write r/w r/w r/w r/w r/w r/w r/w r/w r/w r/w r/w r/w r/w r/w r/w r/w initial value 0 0 0 0 0 0 0 0 00 0 0 0000 47 at43usb320a 1443e?usb?4/04 timer/counter1 output compare register ? ocr1ah and ocr1al timer/counter1 output compare register ? ocr1bh and ocr1bl the output compare registers ar e 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 con- trol 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 com- pare event. since the output compare registers ocr1a and ocr1b are 16-bit registers, a temporary register temp is used when ocr1a/b are wr itten to ensure that both bytes are updated simultaneously. when the cpu writes the high byte, ocr1ah or ocr1bh, the data is tempo- rarily 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. 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 in terrupt routines if interrupts are allowed from within interrupt routines. bit 15 14 13 12 11 10 9 8 $2b ($4b) msb ? ? ? ? ? ? ? ocr1ah $2a ($4a) ? ? ? ? ? ? ? lsb ocr1al 76 5 4 3210 read/write r/w r/w r/w r/w r/w r/w r/w r/w r/w r/w r/w r/w r/w r/w r/w r/w initial value 0 0 0 0 0 0 0 0 00 0 0 0000 bit 1514131211109 8 $29 ($49) msb???????ocr1bh $28 ($48) ???????lsbocr1bl 76543210 read/write r/w r/w r/w r/w r/w r/w r/w r/w r/w r/w r/w r/w r/w r/w r/w r/w initial value00000000 00000000 48 at43usb320a 1443e?usb?4/04 timer/counter1 input capture register ? icr1h and icr1l 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 sig- nal 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 pro- gram 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. timer/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, glitch- free 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 16), where it turns and counts down again to zero be fore the cycle is repeat ed. 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 17 for details. bit 15 14 13 12 11 10 9 8 $25 ($45) msb ? ? ? ? ? ? ? icr1h $24 ($44) ? ? ? ? ? ? ? lsb icr1l 76 5 4 3210 read/write r r r r r r r r rrrrrrrr initial value 0 0 0 0 0 0 0 0 00 0 0 0000 table 16. timer top values and pwm frequency pwm resolution timer top value frequency 8-bit $00ff (255) f tck1 /510 9-bit $01ff (511) f tck1 /1022 10-bit $03ff(1023) f tck1 /2046 49 at43usb320a 1443e?usb?4/04 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 13 for an example. figure 13. effects on unsynchronized ocr1 latching note: x = a or b 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 18. 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 table 17. compare1 mode select in pwm mode com1x1 com1x0 effect on ocx1 0 0 not connected 0 1 not connected 10 cleared on compare match, up-counting. set on compare match, down-counting (non-inverted pwm). 11 cleared on compare match, down-counting. set on compare match, up-counting (inverted pwm). synchronized ocr1x latch pwm output oc1x counter value compare value pwm output oc1x counter value compare value unsynchronized ocr1x latch glitch compare value changes compare value changes 50 at43usb320a 1443e?usb?4/04 value, but the 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. 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. watchdog timer the watchdog timer is clocked from a 1 mhz clo ck derived from the 6 mhz on chip oscillator. by controlling the watchdog timer prescaler, the watchdog reset interval can be adjusted, see table 19 for a detailed description. the wdr (watchdog reset) instruction resets the watchdog timer. eight different clock cycle periods can be selected to determine the reset period. if the reset period expires without another watchdog reset, the at43usb320a resets and executes from the reset vector. to prevent unintentional disabling of the watchdog, a special turn-off sequence must be fol- lowed when the watchdog is disabled. refer to the description of the watchdog timer control register for details. figure 14. watchdog timer table 18. pwm outputs ocr1x = $0000 or top com1x1 com1x0 ocr1x output oc1x 1 0 $0000 l 10top h 1 1 $0000 h 11top l osc/16k osc/32k osc/64k osc/128k osc/256k osc/512k osc/1024k 1 mhz clock mcu reset wde wdp2 wdp1 wdp0 watchdog reset watchdog prescaler osc/8k 51 at43usb320a 1443e?usb?4/04 watchdog timer control register ? wdtcr bits 7..5 ? res: reserved bits these bits are reserved bits in the at43usb320a and w ill 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 19. 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 dis- abled or reset before changing the watchdog timer prescale select. bit 7 6 5 4 3 2 1 0 $21 ($41) ? ? ? wdtoe wde wdp2 wdp1 wdp0 wdtcr read/write r r r r/w r/w r/w r/w r/w initial value 0 0 0 0 0 0 0 0 table 1 9. watchdog timer prescale select wdp2 wdp1 wdp0 number of wdt oscillator cycles time-out 0 0 0 8k cycles 8.2 ms 0 0 1 16k cycles 16.4 ms 0 1 0 32k cycles 33.8 ms 0 1 1 64k cycles 65.6 ms 1 0 0 128k cycles 0.131 s 1 0 1 256k cycles 0.262 s 1 1 0 512k cycles 0.524 s 1 1 1 1,024k cycles 1.048 s 52 at43usb320a 1443e?usb?4/04 serial peripheral interface (spi) the serial peripheral interface (spi) allows high-speed synchronous data transfer between the at43usb320a and peripheral devices or between several avr devices. the at43usb320a spi features include the following: full-duplex, 3-wire synchronous data transfer master or slave operation lsb first or msb first data transfer four programmable bit rates end of transmission interrupt flag write collision flag protection wakeup from idle mode (slave mode only) figure 15. spi block diagram select spi clock (master) clock logic clock spi control spi status register 88 spi control register s m m s miso pb6 mosi pb5 sck pb7 ss pb4 pin control logic 8-bit shift register read data buffer divider 4 16 64 128 mstr spe msb lsb sysclk spr1 spr0 spif wcol spie spe dord mstr cpol cpha spr1 spr0 8 mstr spe dord s m spi interrupt request internal data bus 53 at43usb320a 1443e?usb?4/04 the interconnection between master and slave cpus with spi is shown in figure 16. the pb7(sck) pin is the clock output in the master mode and is the clock input in the slave mode. writing to the spi data register of the master cpu starts the spi clock generator, and the data written shifts out of the pb5(mosi) pin and into the pb5(mosi) pin of the slave cpu. after shifting one byte, the spi clock generator stops, setting the end of transmission flag (spif). if the spi interrupt enable bit (spie) in the spcr register is set, an interrupt is requested. the slave select input, pb4(ss), is set low to select an individual slave spi device. the two shift registers in the master and the slave can be considered as one distributed 16-bit circular shift register. this is shown in figure 16. when data is shifted from the master to the slave, data is also shifted in the opposite direction, simultaneously. this means that during one shift cycle, data in the master and the slave are interchanged. figure 16. spi master/slave interconnection the system is single buffered in the transmit di rection and double buffered in the receive direc- tion. this means that bytes to be transmitted cannot be written to the spi data register before the entire shift cycle is completed. when receiving data, however, a received byte must be read from the spi data register before the next byte has been completely shifted in. other- wise, the first byte is lost. when the spi is enabled, the data direction of the mosi, miso, sck and ss pins is overrid- den according to the following table: note: see ?port b? on page 64. for a detailed description of how to define the direction of the user defined spi pins. sck sck ss ss v cc miso miso mosi mosi lsb master msb 8-bit shift register spi clock generator lsb slave msb 8-bit shift register table 2 0. spi pin overrides pin direction, master spi direction, slave spi mosi user defined input miso input user defined sck user defined input ssn user defined input 54 at43usb320a 1443e?usb?4/04 ss pin functionality when the spi is configured as a master (mstr in spcr is set), the user can determine the direction of the ss pin. if ss is configured as an output, the pin is a general output pin which does not affect the spi system. if ss is configured as an input, it must be held high to ensure master spi operation. if the ss pin is driven low by peripheral circuitry when the spi is config- ured as master with the ss pin defined as an input, the spi system interprets this as another master selecting the spi as a slave and starting to send data to it. to avoid bus contention, the spi system takes the following actions: 1. the mstr bit in spcr is cleared and the spi system becomes a slave. as a result of the spi becoming a slave, the mosi and sck pins become inputs. 2. the spif flag in spsr is set, and if the spi interrupt is enabled and the i-bit in sreg are set, the interrupt routine will be executed. thus, when interrupt-driven spi transmittal is used in master mode, and there exists a possi- bility that ss is driven low, the interrupt should always check that the mstr bit is still set. once the mstr bit has been cleared by a slave select, it must be set by the user to re-enable spi master mode. when the spi is configured as a slave, the ss pin is always input. when ss is held low, the spi is activated and miso becomes an output if configured so by the user. all other pins are inputs. when ss is driven high, all pins are inputs, and the spi is passive, which means that it will not receive incoming data. note that the spi logic will be reset onc e the ss pin is brought high. if the ss pin is brought high during a transmission, the spi will stop sending and receiv- ing immediately and both data received and data sent must be considered as lost. data modes there are four combinations of sck phase and polarity with respect to serial data, which are determined by control bits cpha and cpol. the spi data transfer formats are shown in fig- ure 17 and figure 18. figure 17. spi transfer format with cpha = 0 and dord = 0 note: * not defined but normally lsb of character just received. * lsb 1 2 3 4 5 6 msb lsb 1 2 3 4 5 6 12345678 msb sck cycle # (for reference) sck (cpol = 0) sck (cpol = 1) mosi (from master) miso (from slave) ss (to slave) 55 at43usb320a 1443e?usb?4/04 figure 18. spi transfer format with cpha = 1 and dord = 0 note: * not defined, but normally lsb of previously transmitted character. 1 2 3 4 5 6 lsb 1 2 3 4 5 6 12345678 msb sck cycle # (for reference) sck (cpol = 0) sck (cpol = 1) mosi (from master) miso (from slave) ss (to slave) lsb msb * 56 at43usb320a 1443e?usb?4/04 spi control register ? spcr bit 7 ? spie: spi interrupt enable this bit causes the spi interrupt to be executed if spif bit in the spsr register is set and the global interrupts are enabled. bit 6 ? spe: spi enable when the spe bit is set (one), the spi is enabled. this bit must be set to enable any spi operations. bit 5 ? dord: data order when the dord bit is set (one), the lsb of the data word is transmitted first. when the dord bit is cleared (zero), the msb of the data word is transmitted first. bit 4 ? mstr: master/slave select this bit selects master spi mode when set (one), and slave spi mode when cleared (zero). if ss is configured as an input and is driven low while mstr is set, mstr will be cleared, and spif in spsr will become set. the user will then have to set mstr to re- enable spi master mode. bit 3 ? cpol: clock polarity when this bit is set (one), sck is high when idle. when cpol is cleared (zero), sck is low when idle. refer to figure 17 and figure 18 for additional information. bit 2 ? cpha: clock phase refer to figure 17 or figure 18 for the functionality of this bit. bits 1,0 ? spr1, spr0: spi clock rate select 1 and 0 these two bits control the sck rate of the device configured as a master. spr1 and spr0 have no effect on the slave. the relationship between sck and the oscillator clock frequency f cl is shown in the following table: bit76543210 $0d ($2d) spie spe dord mstr cpol cpha spr1 spr0 spcr read/write r/w r/w r/w r/w r/w r/w r/w r/w initial value 0 0 0 0 0 0 0 0 table 2 1. relationship between sck and the oscillato r frequency spr1 spr0 sck frequency 00 3 mhz 0 1 750 khz 1 0 187.5 khz 1 1 93.75 khz 57 at43usb320a 1443e?usb?4/04 spi status register ? spsr bit 7 ? spif: spi interrupt flag when a serial transfer is complete, the spif bit is set (one) and an interrupt is generated if spie in spcr is set (one) and global interrupts are enabled. if ss is an input and is driven low when the spi is in master mode, this will also set the spif flag. spif is cleared by the hard- ware when executing the corresponding interrupt handling vector. alternatively, the spif bit is cleared by first reading the spi status register when spif is set (one), then accessing the spi data register (spdr). bit 6 ? wcol: write collision flag the wcol bit is set if the spi data register (spdr) is written during a data transfer. the wcol bit (and the spif bit) are cleared (zero) by first reading the spi status register when wcol is set (one), and then accessing the spi data register. bit 5..0 ? res: reserved bits these bits are reserved bits in the at43usb320a and w ill always read as zero. spi data register ? spdr the spi data register is a read/write register used for data transfer between the register file and the spi shift register. writing to the register initiates data transmission. reading the regis- ter causes the shift register receive buffer to be read. uart the at43usb320a features a full duplex (separate receive and transmit registers) universal asynchronous receiver and transmitter (uart). the main features are: baud rate generator that can generate a large number of baud rates (bps) high baud rates at low xtal frequencies 8-bit data noise filtering overrun detection framing error detection false start bit detection three separate interrupts on tx complete, tx data register empty and rx complete bit 7 6 5 4 3 2 1 0 $0e ($2e) spif wcol ? ? ? ? ? ? spsr read/writerrrrrrrr initial value 0 0 0 0 0 0 0 0 bit 76543210 $0f ($2f) msb??????lsbspdr read/write r/w r/w r/w r/w r/w r/w r/w r/w initial value x x x x x x x x undefined 58 at43usb320a 1443e?usb?4/04 data transmission a block schematic of the uart transmitter is shown in figure 19. data transmission is initiated by writing the data to be transmitted to the uart i/o data register, udr. data is transferred from udr to the transmit shift register when: a new character has been written to udr after the stop bit from the previous character has been shifted out. the shift register is loaded immediately. a new character has been written to udr before the stop bit from the previous character has been shifted out. the shift register is loaded when the stop bit of the character currently being transmitted has been shifted out. if the 10-bit transmitter shift register is empty, data is transferred from udr to the shift regis- ter. at this time the udr e (uart data register empty) bit in the uart status register, usr, is set. when this bit is set (one), the uart is ready to receive the next character. at the same time as the data is transferred from udr to the 10-bit shift register, bit 0 of the shift reg- ister is cleared (start bit) and bit 9 is set (stop bit). on the baud rate clock following the transfer operation to the shift register, the start bit is shifted out on the txd pin. the n follows the data, lsb first. when the stop bit has been shifted out, the shift register is loaded if any new data has been written to the udr during the transmission. during loading, udre is set. if there is no new data in the udr register to send when the stop bit is shifted out, the udre flag will remain set until udr is written again. when no new data has been written and the stop bit has been present on txd for one bit length, the tx complete flag (txc) in usr is set. the txen bit in ucr enables the uart transmitter when set (one). when this bit is cleared (zero), the pd1 pin can be used for general i/o. when txen is set, the uart transmitter will be connected to pd1, which is forced to be an output pin regardless of the setting of the ddd1 bit in ddrd. 59 at43usb320a 1443e?usb?4/04 figure 19. uart transmitter data reception figure 20 shows a block diagram of the uart receiver. the receiver front-end logic samples the signal on the rxd pin at a frequency 16 times the baud rate. while the line is idle, one single sample of logical "0" will be interpreted as the fall- ing edge of a start bit and the start bit detection sequence is initiated. let sample 1 denote the first zero-sample. following the 1-to-0 transition, the receiver samples the rxd pin at samples 8, 9 and 10. if two or more of these three samples are found to be logical "1"s, the start bit is rejected as a noise spike and the receiver starts looking for the next 1-to-0 transition. if, however, a valid start bit is detected, sampling of the data bits following the start bit is per- formed. these bits are also sampled at samples 8, 9 and 10. the logical value found in at least two of the three samples is taken as the bit value. all bits are shifted into the transmitter shift register as they are sampled. sampling of an incoming character is shown in figure 19. when the stop bit enters the receiver, the majority of the three samples must be "1" to accept the stop bit. if two or more samples are logical "0's, the framing error (fe) flag in the uart status register (usr) is set. before readi ng the udr register, the us er should always check the fe bit to detect framing errors. whether or not a valid stop bit is detected at the end of a character reception cycle, the data is transferred to udr and the rxc flag in usr is set. udr is in fact two physically separate reg- 60 at43usb320a 1443e?usb?4/04 isters, one for transmitted data and one for received data. when udr is read, the receive data register is accessed, and when udr is written, the transmit data register is accessed. if, after having received a character, the udr register has not been read since the last receive, the overrun (or) flag in ucr is set. this means that the last data byte shifted into the shift register could not be transferred to udr and has been lost. the or bit is buffered and is updated when the valid data byte in udr is read. thus, the user should always check the or bit after reading the udr register in order to detect any overruns if the baud rate is high or cpu load is high. when the rxen bit in the ucr register is cleared (zero), the receiver is disabled. this means that the pdo pin can be used as a general i/o pin. when rxen is set, the uart receiver will be connected to pdo, which is forced to be an input pin regardless of the setting of the dddo bit in ddrd. when pdo is forced to input by the uart, the portdo bit can st ill be used to control the pull-up resistor on the pin. figure 20. uart receiver figure 21. sampling received data 61 at43usb320a 1443e?usb?4/04 uart control uart i/o data register ? udr the udr register is actually two physically separate registers sharing the same i/o address. when writing to the register, the uart transmit data register is written. when reading from udr, the uart receive data register is read. uart status register ? usr the usr register is a read-only register providing information on the uart status. bits 7 ? rxc: uart receive complete this bit is set (one) when a received character is transferred from the receiver shift register to udr. the bit is set regardless of any detected framing errors. when the rxcie bit in ucr is set, the uart receive complete interrupt will be executed when rxc is set (one). rxc is cleared by reading udr. when interrupt-driven data reception is used, the uart receive complete interrupt routine must read udr in order to clear rxc, otherwise a new interrupt will occur once the interrupt routine terminates. bit 6 ? txc: uart transmit complete this bit is set (one) when the entire character (including the stop bit) in the transmit shift reg- ister has been shifted out an d no new data has been written to udr. this flag is especially useful in half-duplex communications interfaces, where a transmitting application must enter receive mode and free the communications bus immediately after completing the transmission. when the txcie bit in ucr is set, setting of txc causes the uart transmit complete inter- rupt to be executed. txc is cleared by hardware when executing the corresponding interrupt handling vector. alternatively, the txc bit is cleared (zero) by writing a logical "1"to the bit. bit 5 ? udre: uart data register empty this bit is set (one) when a character written to udr is transferred to the transmit shift regis- ter. setting of this bit indicates that the transmitter is ready to receive a new character for transmission. bit 76543210 $0d ($2c) msb??????lsb udr read/write r/w r/w r/w r/w r/w r/w r/w r/w initial value00000000 bit 76543210 $0d ($2b) rxc txc udre fe or ? ? ? usr read/writer/wr/wrrrrrr initial value00000000 62 at43usb320a 1443e?usb?4/04 when the udrie bit in ucr is set, the uart transmit complete interrupt to be executed as long as udre is set. udre is cleared by writing udr. when interrupt-driven data transmittal is used, the uart data register empty interrupt routine must write udr in order to clear udre, otherwise a new interrupt will occur once the interrupt routine terminates. udre is set (one) during reset to indicate that the transmitter is ready. bit 4 ? fe: framing error this bit is set if a framing error condition is detected, i.e., when the stop bit of an incoming character is zero. the fe bit is cleared when the stop bit of received data is one. bit 3 ? or: overrun this bit is set if an overrun condition is detected, i.e., when a character already present in the udr register is not read before the next character has been shifted into the receiver shift reg- ister. the or bit is buffered, which means that it will be set once the valid data still in udre is read. the or bit is cleared (zero) when data is received and transferred to udr. bits 2...0 ? res: reserved bits these bits are reserved bits in the at43usb320a and w ill always read as zero. uart control register ? ucr bit 7 ? rxcie: rx complete interrupt enable when this bit is set (one), a setting of the rxc bit in usr will cause the receive complete interrupt routine to be executed provided that global interrupts are enabled. bit 6 ? txcie: tx complete interrupt enable when this bit is set (one), a setting of the txc bit in usr will cause the transmit complete interrupt routine to be executed provided that global interrupts are enabled. bit 5 ? udrie: uart data register empty interrupt enable when this bit is set (one), a setting of the udr e bit in usr will cause the uart data register empty interrupt routine to be executed provided that global interrupts are enabled. bit 4 ? rxen: receiver enable this bit enables the uart receiver when set (one). when the receiver is disabled, the txc, or and fe status flags cannot become set. if these flags are set, turning off rxen does not cause them to be cleared. bit 3 ? txen: transmitter enable this bit enables the uart transmitter when set (one). when disabling the transmitter while transmitting a character, the transmitter is not disabled before the character in the shift register plus any following c haracter in udr has been completely transmitted. bit 2 ..0 ? res: reserved bits these bits are the reserved bits of the at43usb320a. bit 76543210 $0a ($2a) rxcie txcie udrie rxen txen - - - ucr read/write r/w r/w r/w r/w r/w r r/w initial value00000 10 63 at43usb320a 1443e?usb?4/04 baud rate generator the baud rate generator is a frequency divider that generates baud rates according to the fol- lowing equation: baud = sysclk/16(ubrr + 1) baud = baud rate sysclk = 16 mhz ubrr = contents of the uart baud rate register, ubrr (0 ? 255) for standard crystal frequencies, the most commonly used baud rates can be generated by using the ubrr settings in table 22. ubrr values that yield an actual baud rate differing less than 2% from the target baud rate are boldface in the table. however, using baud rates that have more than 1% error is not recommended. high error ratings give less noise immunity. uart baud rate register ? ubrr the ubrr register is an 8-bit read/write register that specifies the uart baud rate according to the equation on the previous page. i/o-ports all avr ports have true read-modify-write functionality when used as general digital i/o ports. this means that the direction of one port pin can be changed without unintentionally changing the direction of any other pin with the sbi and cbi instructions. the same applies for changing drive value if configured as output or enabling/disabling of pull-up resistors if config- ured as input. port a port a is an 8-bit bi-directional i/o port. 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 regis- ter porta, $1b($3b), data direction register (ddra), $1a($3a) and the port a input pins table 2 2. ubrr settings baud rate ubrr % error 2400 416 0.08 4800 207 0.16 9600 103 0.16 14400 68 0.64 19200 51 0.16 28800 34 0.79 38400 25 0.16 57600 16 2.12 76800 12 0.16 115200 8 3.55 bit 76543210 $09 ($29) msb lsb ubrr read/write r/w r/w r/w r/w r/w r/w r/w r/w initial value00000000 64 at43usb320a 1443e?usb?4/04 (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 pins have no selectable pull-up resistors. port a data register ? porta port a data direction register ? ddra port a input pins address ? pina 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. port a as general digital i/o all 8 pins in port a have equal functionality when used as digital i/o pins. pan, general i/o pin: the ddan bit in the ddra register selects the direction of this pin, if ddan is set (one), pan is configured as an output pin. if ddan is cleared (zero), pan is config- ured as an input pin. if portan is set (one) when the pin is configured as an input pin, the mos pull-up resistor is activated. to switch the pull-up resistor off, the portan has to be cleared (zero) or the pin has to configured as an output pin. the port a pins are tri-stated when a reset condition becomes active, even if the clock is not active. note: n: 7,6...0, pin number. port b port b is an 8-bit bi-directional i/o port. the port b output buffers can sink or source 4 ma. bit 7 6 5 4 3 2 1 0 $1b ($3b) porta7 porta6 porta5 porta4 porta3 porta2 porta1 porta0 porta read/write r/w r/w r/w r/w r/w r/w r/w r/w initial value 0 0 0 0 0 0 0 0 bit 76543 210 $1a ($3a) dda7 dda6 dda5 dda4 dda3 dda2 dda1 dda0 ddra read/write r/w r/w r/w r/w r/w r/w r/w r/w initial value 0 0 0 0 0 0 0 0 bit 76543 210 $19 ($39) pina7 pina6 pina5 pina4 pina3 pina2 pina1 pina0 pina read/write r r r r r r r r initial value n/a n/a n/a n/a n/a n/a n/a n/a table 2 3. ddan effects on port a pins ddan portan i/o comment 0 0 input tri-state (hi-z) 0 1 input tri-state (hi-z) 1 0 output push-pull zero output 1 1 output push-pull one output 65 at43usb320a 1443e?usb?4/04 three i/o memory address locations are allocated for the port b, one each for the data regis- ter - 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 pins have no selectable pull-up resistors. the port b pins with alternate functions are shown in the following table: when the pins are used for the alternate function the ddrb and portb register has to be set according to the alternate function description. table 2 4. port b pins alternate functions port pin alternate functions pb0 t0 (timer/counter 0 external counter input) pb1 t1 (timer/counter 1 external counter input) pb4 ss (spi slave select input) pb5 mosi (spi bus master output/slave input) pb6 miso (spi bus master input/slave output) pb7 sck (spi bus serial clock) 66 at43usb320a 1443e?usb?4/04 port b data register ? portb port b data direction register ? ddrb port b input pins address ? pinb 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. port b as general digital i/o all 8 pins in port b have equal functionality when used as digital i/o pins. pbn, general i/o pin: the ddbn bit in the ddrb register selects the direction of this pin, if ddbn is set (one), pbn is con-figured as an output pin. if ddbn is cleared (zero), pbn is con- figured as an input pin. if portbn is set (one) when the pin is configured as an input pin, the mos pull-up resistor is activated. to switch the pull-up resistor off, the portbn has to be cleared (zero) or the pin has to configured as an output pin. the port b pins are tri-stated when a reset condition becomes active, even if the clock is not active. note: n: 7, 6...0, pin number. bit 7 6 543210 $18 ($38) portb7 portb6 portb5 portb4 portb3 portb2 portb1 portb0 portb read/write r/w r/w r/w r/w r/w r/w r/w r/w initial value 0 0 0 0 0 0 0 0 bit 7 6 5 4 3 2 1 0 $17 ($37) ddb7 ddb6 ddb5 ddb4 ddb3 ddb2 ddb1 ddb0 ddrb read/write r/w r/w r/w r/w r/w r/w r/w r/w initial value 0 0 0 0 0 0 0 0 bit 7 6 5 4 3 2 1 0 $16 ($36) pinb7 pinb6 pinb5 pinb4 pinb3 pinb2 pinb1 pinb0 pinb read/write r r r r r r r r initial value n/a n/a n/a n/a n/a n/a n/a n/a table 2 5. ddbn effects on port b pins ddbn portbn i/o comment 0 0 input tri-state (hi-z) 0 1 input tri-state (hi-z) 1 0 output push-pull zero output 1 1 output push-pull one output 67 at43usb320a 1443e?usb?4/04 port c port c is an 8-bit bi-directional i/o port with push-pull outputs. the port c output buffers can sink 4 ma three i/o memory address locations are allocated for the port c, one each for the data regis- ter ? portc, $15($35), data direction register ? ddrc, $14($34) and the port c input pins ? pinc, $13($33). the port c input pins address is read only, while the data register and the data direction register are read/write. port c data register ? portc port c data direction register ? ddrc port c input pins address ? pinc 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. port c as general digital i/o all 8 pins in port c have equal functionality when used as digital i/o pins. pcn, general i/o pin: the ddcn bit in the ddrc register selects the direction of this pin, if ddcn is set (one), pcn is configured as an output pin. if ddcn is cleared (zero), pcn is con- figured as an input pin. the value of portcn has no meaning in this mode. the port c pins are tri-stated when a reset condition becomes active, even if the clock is not active. note: n: 7?0, pin number bit 76543210 $15 ($35) portc7 portc6 portc5 portc4 portc3 portc2 portc1 portc0 portc read/write r/w r/w r/w r/w r/w r/w r/w r/w initial value00000000 bit 76543210 $14 ($34) ddc7 ddc6 ddc5 ddc4 ddc3 ddc2 ddc1 ddc0 ddrc read/write r/w r/w r/w r/w r/w r/w r/w r/w initial value00000000 bit 76543210 $13 ($33) pinc7 pinc6 pinc5 pinc4 pinc3 pinc2 pinc1 pinc0 pinc read/write r r r r r r r r initial value n/a n/a n/a n/a n/a n/a n/a n/a table 2 6. ddcn effects on port c pins ddcn portcn i/o comment 0 0 input tri-state (hi-z) 0 1 input tri-state (hi-z) 1 0 output push-pull zero output 1 1 output push-pull one output 68 at43usb320a 1443e?usb?4/04 port d port d is an 8-bit bi-directional i/o port. its output buffers can sink or source 2 ma. three i/o memory address locations are allocated for the port d, one each for the data regis- ter - 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. the port pins have no selectable pull-up resistors. some port d pins have alternate functions as shown in table 27. when the pins are used for the alternate function the ddrd and portd register has to be set according to the alternate function description. port d data register ? portd port d data direction register ? ddrd port d input pins address ? pind 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. table 2 7. port d alternate functions port pin alternate function pd0 rxd (uart input line) pd1 txd (uart output line) pd2 int0, external interrupt 0 pd3 int1, external interrupt 1 pd5 oc1a timer/counter1 output compare a bit 7 6 5 4 3 2 1 0 $12 ($32) portd7 portd6 portd5 portd4 portd3 portd2 portd1 portd0 portd read/write r/w r/w r/w r/w r/w r/w r/w r/w initial value 0 0 0 0 0 0 0 0 bit 7 654 3 210 $11 ($31) ddd7 ddd6 ddd5 ddd4 ddd3 ddd2 ddd1 ddd0 ddrd read/write r/w r/w r/w r/w r/w r/w r/w r/w initial value 0 0 0 0 0 0 0 0 bit 7 6 5 4 3 2 1 0 $10 ($30) pind7 pind6 pind5 pind4 pind3 pind2 pind1 pind0 pind read/write r r r r r r r r initial value n/a n/a n/a n/a n/a n/a n/a n/a 69 at43usb320a 1443e?usb?4/04 port d as general digital i/o pdn, general i/o pin: the dddn bit in the ddrd register se lects 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 con- figured as an input pin. if portdn is set (one) when the pin is configured as an input pin, the mos pull-up resistor is activated. to switch the pull-up resistor off, the portdn has to be cleared (zero) or the pin has to configured as an output pin. the port d pins are tri-stated when a reset condition becomes active, even if the clock is not active. note: n: 7, 6...0, pin number. 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 pro- grammed 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 4. 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 fifo. if the hub is disabled, one extra endpoint becomes available to the function. the usb 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 detec- tion/generation, data serialization/de-serialization, data encoding/decoding, bit stuffing and un- stuffing, clock/data separati on, 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. the usb function hardware of the at43usb320a makes the physical interface and the proto- col 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 the 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 micro- controller 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 end- point. 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 auto- matically 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 table 2 8. dddn bits on port d pins dddn portdn i/o comment 0 0 input tri-state (hi-z) 0 1 input tri-state (hi-z) 1 0 output push-pull zero output 1 1 output push-pull one output 70 at43usb320a 1443e?usb?4/04 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. a detailed description of how usb transactions are handled is described in the following sec- tions. first for a control endpoint and then for non-control endpoints. control transfers at control endpoint ep0 the description given below is for the function control endpoint, but applies to the hub control endpoint 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: setup data status stage stage stage control write data0 data1 data0 data0/1 data1(0) control read data0 data1 data0 data0/1 data1(0) setup status stage stage no-data control data0 data1(0) setup(0) setup(0) out(1) out(0) out(0/1) ? in(1) in(1) setup(0) in(1) in(1) out(1) in(0) in(0/1) ? legend: datan data packet with pid?s data toggle bit equal to n data1(0) zero length data1 packet 71 at43usb320a 1443e?usb?4/04 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. idle setup response no-data status response control read status response control write status response rx_setup_int rx_out_int tx_complete_int tx_complete_int tx_complete_int rx_out_int control read data response tx_complete_int control write data response rx_out_int ( any stable state ) 72 at43usb320a 1443e?usb?4/04 the following information describes how the at43usb320a?s usb hardware and firmware operates during a control transfer between the host and the hub?s or function?s control endpoint. idle state this is the default state from power-up. setup 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. legend: data1/data0 = data packet with data1 or data2 pid data1(0) = zero length data1 packet hardware firmware 1. setup token, data from host 2. ack to host 3. store data in fifo 4. set rx setup int 5. read uisr 6. read csr0 7. read byte count 8. read fifo 9. parse command data 10. write to h/fcar0: a. if control read: set dir, clear rx setup, fill fifo, set tx packet ready in car0 b. if control write: clear dir in car0 c. if no data stage: set data end, clear dir, set force stall in car0 11. set uiar[ep0 intack] to clear the interrupt source 73 at43usb320a 1443e?usb?4/04 no-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. control 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. hardware firmware 1. in token from host 2. send data1(0) 3. ack from host 4. set tx complete int 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] hardware firmware 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 74 at43usb320a 1443e?usb?4/04 control 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. control 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. hardware firmware 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 hardware firmware 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: 75 at43usb320a 1443e?usb?4/04 control 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. hardware firmware 1. in token from host 2. send data1(0) 3. ack from host 4. set tx complete int 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 76 at43usb320a 1443e?usb?4/04 interrupt/bulk in transfers at function endpoint the firmware must first condition the endpoint through the endpoint control register, fendp1/2_cntr: set endpoint direction: set epdir set interrupt or bulk: eptype = 11 or 10 enable endpoint: 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. 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 4. set uiar[fep1/2 intack] to clear the interrupt source interrupt/bulk out transfers at function endpoint ep1 and 2 the firmware must first condition the endpoint through the endpoint control register, fendp1/2_cntr: set endpoint direction: clear epdir set interrupt or bulk: eptype = 11 or 10 enable endpoint: 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. read fifo 4. clear rx_out if more data: wait for rx_out interrupt if no more data: set data end 5. set uiar[fep1/2 intack] to clear the interrupt source 77 at43usb320a 1443e?usb?4/04 usb registers the following sections describe the registers of the at43usb320a?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. hub 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 re quest 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. hub address register ? haddr bit 7 ? saen: single address enable the single address enable bit allows the microcontroller to configure the at43usb320a 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] bit76543210 $1fef saen hadd6 hadd5 hadd4 hadd3 hadd2 hadd1 hadd0 haddr read/write r/w r/w r/w r/w r/w r/w r/w r/w initial value 0 0 0 0 0 0 0 0 78 at43usb320a 1443e?usb?4/04 function 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. function address register ? faddr 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 rece ipt of a reset through the hub, setportfea- ture[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] endpoint registers hub endpoint 0 control register ? hendp0_cr function endpoint 0 control register ? fendp0_cr bit 7 ? epen: endpoint enable 0 = disable endpoint 1 = enable endpoint bit 6..4 ? reserved these bits are reserved in the at43usb320a 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. bit76543210 $1fee fen fadd6 fadd5 fadd4 fadd3 fadd2 fadd1 fadd0 faddr read/write r/w r/w r/w r/w r/w r/w r/w r/w initial value 0 0 0 0 0 0 0 0 bit 765432 1 0 $1fe7 epen ? ? ? dtgle epdir eptype1 eptype0 hendp0_cr $24 ($44) epen ? ? ? dtgle epdir eptype1 eptype0 fendp0_cr read/write r/w r r r r/w r/w r/w r/w initial value 0 0 0 0 0 0 0 0 79 at43usb320a 1443e?usb?4/04 function endpoint 1, 2 control register ? fendp1,2_cr bit 7 ? epen: endpoint enable 0 = disable endpoint 1 = enable endpoint bit 6..4 ? reserved these bits are reserved in the at43usb320a 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 programs the type of endpoint. bit 7654 3 2 1 0 $1fe4 epen ? ? ? dtgle epdir eptype1 eptype0 fendp1_cr $1fe3 epen ? ? ? dtgle epdir eptype1 eptype0 fendp2_cr read/write r/w r r r r/w r/w r/w r/w initial value 0 0 0 0 0 0 0 0 bit1 bit0 type 0 1 isochronous 10bulk 1 1 interrupt 80 at43usb320a 1443e?usb?4/04 hub endpoint 0 data register ? hdr0 function endpoint 0..2 data register ? fdr0..2 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: bit 7, 6 ? reserved these bits are reserved in the at43usb320a and will read as zero. bit 5 ? p5 sc: port 5 status change bit 4 ? p4 sc: port 4status change bit 3 ? p3 sc: port 3 status change bit 2 ? p2 sc: port 2 status change bit 1 ? p1 sc: port 1 status change bit 0 ? h sc: hub status change bit76543210 $1fd7 data7 data6 data5 data4 data3 data2 data1 data0 hdr0 $1fd5 data7 data6 data5 data4 data3 data2 data1 data0 fdr0 $1fd4 data7 data6 data5 data4 data3 data2 data1 data0 fdr1 $1fd3 data7 data6 data5 data4 data3 data2 data1 data0 fdr2 read/write r/w r/w r/w r/w r/w r/w r/w r/w initial value 0 0 0 0 0 0 0 0 bit 7 6 5 4 3 2 1 0 $ ? ? p5 sc p4 sc p3 sc p2 sc p1 sc h sc hdr1 read/write r/w r/w r/w r/w r/w r/w r/w r/w initial value 0 0 0 0 0 0 0 0 81 at43usb320a 1443e?usb?4/04 hub endpoint 0 byte count register ? hbyte_cnt0 function endpoint 0..2 byte count register ? fbyte_cnt0..2 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. hub endpoint 1 has no byte count register. bit 7..5 ? reserved these bits are reserved in the at43usb320a and will read as zero. bit 4..0 ? bytct4..0: byte count ? length of endpoint data packet bit 76543 210 hub ep0 $1fcf ? ? ? bytct4 bytct3 bytct2 bytct1 bytct0 hbyte_cnt0 function ep0 $1fcd ? ? ? bytct4 bytct3 bytct2 bytct1 bytct0 fbyte_cnt0 function ep1 $1fcc ? ? ? bytct4 bytct3 bytct2 bytct1 bytct0 fbyte_cnt1 function ep2 $1fcb ? ? ? bytct4 bytct3 bytct2 bytct1 bytct0 fbyte_cnt2 read/write r r r r/w r/w r/w r/w r/w initial value00000 000 82 at43usb320a 1443e?usb?4/04 hub endpoint 0 service routine register ? hcsr0 function endpoint 0 service routine register ? fcsr0 bit 7..4 ? reserved these bits are reserved in the at43usb320a 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 acknowl- edge register. bit 2 ? rx setup: setup packet received this bit is used by control endpoints only to signal to the microcontroller that the usb hard- ware 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 inter- rupt 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 over- write 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 suc- cessfully 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. bit 7654 3 2 1 0 function ep0 $1fdf ? ? ? ? stall sent rx setup rx out packet tx complete hcsr0 function ep0 $1fdd ? ? ? ? stall sent rx setup rx out packet tx complete fcsr0 read/write r r r r r r r r initial value 0 0 0 0 0 0 0 0 83 at43usb320a 1443e?usb?4/04 hub endpoint 0 control and acknowledge register ? hcar0 function endpoint 0 control and acknowledge register ? fcar0 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 hard- ware 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. 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 fol- lowing 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. 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. bit 7 6 5 4 3 2 1 0 hub ep0 $1fa7 dir data end force stall tx packet ready stall_ sent_ ack rx_ setup_ ack rx_out_ packet_ ack tx_ complete_ ack hcar0 function ep0 $1fdd dir data end force stall tx packet ready stall_ sent_ ack rx_ setup_ ack rx_out_ packet_ ack tx_ complete_ ack fcar0 read/write r/w r/w r/w r/w r/w r/w r/w r/w initial value 0 0 0 0 0 0 0 0 84 at43usb320a 1443e?usb?4/04 hardware clears this bit after it receives an ack. if the interrupt is enabled and if the tx com- plete 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 ? rx_setup_ack: acknowledge rx setup interrupt firmware sets this bit to clear rx setup, csr bit2. the 1 written in the csrack2 bit is not actually stored and thus does not have to be cleared. 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. function endpoint 1, 2 service routine register ? fcsr1, 2 bit 7..4 ? reserved these bits are reserved in the at43usb320a 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 acknowl- edge register. bit 2 ? reserved this bit is reserved in the at43usb320a 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 over- write 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 transac- tion 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. bit 765432 1 0 function ep1 $1fdc ? ? ? ? stall sent ? rx out packet tx complete fcsr1 function ep2 $1fdb ? ? ? ? stall sent ? rx out packet tx complete fcsr2 read/write r r r r r r r r initial value 0 0 0 0 0 0 0 0 85 at43usb320a 1443e?usb?4/04 function endpoint 1, 2 control and acknowledge register ? fcar1, 2 bit 7 ? reserved this bit is reserved in the at43usb320a 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. 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 at43usb320a 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. bit 7 6 5 4 3 2 1 0 function ep1 $1fa4 ? data end force stall tx packet rdy stall_sent- ack ? rx_out_packet _ack tx_complete _ack fcar1 function ep2 $1fa3 ? data end force stall tx packet rdy stall_sent- ack ? rx_out_packet _ack tx_complete -ack fcar2 read/write r r/w r/w r/w r/w r r/w r/w initial value 0 0 0 0 0 0 0 0 86 at43usb320a 1443e?usb?4/04 usb hub 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 at43usb320a'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 imple- mented 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. 87 at43usb320a 1443e?usb?4/04 hub general registers global state register ? glb_state bit 7...5 ? reserved bits these bits are reserved in the at43usb320a and will read as zeros. 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. bit 7 6 5 4 3 2 1 0 $1ffb ? ? ? susp flg resume flg rmwupe confg hadd en glb_state read/write r r r r r r/w r/w r/w initial value 0 0 0 0 0 0 0 0 88 at43usb320a 1443e?usb?4/04 hub status register in the at43usb320a 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 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. 2. hub overcurrent status, bits 1 and 3, apply to self powered hubs with bus powered sie only, or hubs that are programmable as self/bus powered. the firmware should clear these two bits to 0. 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. hub status register ? hstr bit 7..4 ? reserved these bits are reserved in the at43usb320a 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 bit 0 ? lps: hub local power status 0 = local power supply is good 1 = local power supply is lost (inactive) bit76543210 $1fc7 ? ? ? ? ovlsc lpsc ovi lps hstr read/write r r r r r/w r/w r/w r/w initial value 0 0 0 0 0 0 0 0 89 at43usb320a 1443e?usb?4/04 hub port control register ? hpcon bit 7 ? reserved this bits is reserved in the at43usb320a 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. 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 placing 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 firmware 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 plac- ing 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. firmware takes the embedded function out of the suspend state and enables port 1's endpoints. bit 3 ? reserved this bits is reserved in the at43usb320a and will read as zero. bit 2..0 ? hpcon2..0: hub port address bit76543210 $1fc5 ? hpcon2 hpcon1 hpcon0 ? hpadd2 hpadd1 hpadd0 hpcon read/write r r/w r/w r/w r r/w r/w r/w initial value 0 0 0 0 0 0 0 0 bit6 bit5 bit4 action 0 0 0 disable port 0 0 1 enable port 0 1 0 reset and enable port 0 1 1 suspend port 1 0 0 resume port 90 at43usb320a 1443e?usb?4/04 these bits define which port is being addressed for the command defined by bits [2:0]. bit2 bit1 bit0 port addresses 101port 5 100port 4 011port 3 010port 2 001port 1 91 at43usb320a 1443e?usb?4/04 selective 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 [1:4] in the suspend mode. for port 5, 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. 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 [1:4], the usb hardware drives a "k" down- stream 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 [1:4], this means detection of a connect/disconnect or an upstream directed j to k signaling. remote wakeup for the embedded function is initiated through an external interrupt at int0. 92 at43usb320a 1443e?usb?4/04 hub 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. hub port status register ? hpstat1:5 bit 7 ? reserved this bit is reserved in the at43usb320a 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 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. 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 bit 7 6 5 4 3 2 1 0 port1 $1fb8 ? lsp ppstat prstat poci psstat pestat pcstat hpstat1 port2 $1fb9 ? lsp ppstat prstat poci psstat pestat pcstat hpstat2 port3 $1fba ? lsp ppstat prstat poci psstat pestat pcstat hpstat3 port4 $1fbb ? lsp ppstat prstat poci psstat pestat pcstat hpstat4 port5 $1fbc ? lsp ppstat prstat poci psstat pestat pcstat hpstat5 read/write r r r/w r r/w r r r initial value 0 0 0 0 0 0 0 0 93 at43usb320a 1443e?usb?4/04 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. hub port state register ? hpstat1:5 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 at43usb320a 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. bit 765432 1 0 port1 $1fa8 ? ? ? ? ? ? dpstate dmstate pstate1 port2 $1fa9 ? ? ? ? ? ? dpstate dmstate pstate2 port3 $1faa ? ? ? ? ? ? dpstate dmstate pstate3 port4 $1fab ? ? ? ? ? ? dpstate dmstate pstate4 port5 $1fac ? ? ? ? ? ? dpstate dmstate pstate5 read/write r r r r r r r r initial value 0 0 0 0 0 0 0 0 94 at43usb320a 1443e?usb?4/04 hub port status change register ? pscr1..3 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 at43usb320a and will read as zero. bit 4 ? rstsc: port reset status change 0 = no change 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 sta- tus 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 1:4 is set by hardware upon completion of firmware initiated resume process. port 5 is set by firmware 20 ms after the next eof2 after completion of resume process. resume signal- ing is initiated through global resume, selective resume and remote wakeup. cleared by firmware via host request clearportfeature(port_suspend). bit76543210 port1 $1fb0 ? ? ? rstsc pocic pssc pesc pcsc pscr1 port2 $1fb1 ? ? ? rstsc pocic pssc pesc pcsc pscr2 port3 $1fb2 ? ? ? rstsc pocic pssc pesc pcsc pscr3 port4 $1fb3 ? ? ? rstsc pocic pssc pesc pcsc pscr4 port5 $1fb4 ? ? ? rstsc pocic pssc pesc pcsc pscr5 read/write r r r r r r r r initial value 0 0 0 0 0 0 0 0 95 at43usb320a 1443e?usb?4/04 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 5 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 5. hardware sets this bit for port 5 after a hub reset. cleared by firmware via host request clearportfeature(port_connection). hub and port power management for the utmost flexibility, the usb hardware of the at43usb320a is designed to accommo- date hubs of various capacitance. management of the downstream port power is also defined by the firmware: per port or global overcurrent sensing, individual or gang power switching. while the interface to the external power supply monitoring and switching is achieved through the microcontroller?s gpio pins, the usb hardware of the at43usb320a contains the cir- cuitry to handle all the possible combinations port power managem ent tasks. overcurrent sensing 1. global overcurrent protection ? in this mode, the port overcurrent indicator and port overcurrent indicator change should be set to 0's. for the at43usb320a an external solid state switch, such as the micrel mic2545-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 the hub. 2. individual port over-current protection ? the hub overcurrent indicator and hub overcurrent indicator change bits should be set to 0's. one mic2026-2 is required for each two usb ports. each of the flg# outputs of the mic2026-2 should be connected to an unused microcontroller port. 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 at43usb320a reports the status change. port power switching 1. gang power switching ? one of the microcontroller i/o port pins must be pro- grammed as an output to control the external switch, pwrn. 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 1 through 4 are cleared should the firmware de-assert the pwrn pin. 2. individual power switching ? one microcontroller i/o port pin must be assigned for each usb port to control the external switch, pwrxn, where x = 1, 2, 3, 4. each of the power control bits controls one pwrxn. 3. multiple ganged overcurrent protection ? overcurrent sensing is grouped physi- cally into one or more gangs, but reported individually. figure 22 shows a simplified diagram of a power management circuit of an at43usb320a based hub design with global overcurrent protection and ganged power switching. 96 at43usb320a 1443e?usb?4/04 figure 22. port power management suspend and resume the at43usb320a enters suspend only when requested by the usb host through bus inac- tivity 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 sl eep instruc- tion. the usb hardware shuts off the oscillator and pll. global resume global resume is signaled by a j to k state change on port0. the usb hardware enables the oscillator/pll, pr opagates 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. remote wakeup while the at43usb320a 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 inter- rupt, int1, which enables the o scillator/pll and the u sb hardware. the usb hardware drives resume signaling and sets the frmwup and rsm bits of sprsr which generates an inter- ctl flg in out switch at43usb320a gnd vcc pwrn ovcn port2_power port2_gnd port3_power port3_gnd bus_power gnd port1_power port1_gnd port4_power port4_gnd 97 at43usb320a 1443e?usb?4/04 rupt 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. selective suspend and resume see ?hub port control register ? hpcon? on page 89. suspend and resume process global 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. global 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. hardware firmware 1.host stops sending packets 2. global suspend signaling detected 3. stop downstream signaling 4. set gbl sus bit interrupt 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 10. sleep bit detected 11. shut off oscillator hardware firmware 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 98 at43usb320a 1443e?usb?4/04 remote 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. remote wake-up, embedded function the hardware detects an int0/int1 and propagates resume signaling upstream. finally, the hardware enables the oscillator and assert s the rsm and frwup interrupts. selective suspend, downstream ports hardware firmware 1. connect/disconnect/port resume detected 2. propagate resume signaling 3. enable oscillator 4. set rsm bit interrupt 5. reset rsm and gbl susp bits 6. restore gpio states if required 7. clear uovcer bit 2 8. enable peripheral activity hardware firmware 1.external event activates int0/int1 2. propagate resume signaling 3. enable oscillator 4. set rsm and frmwup bits interrupt 5. clear glb susp, rsm, frmwup bits 6. restore gpio states if required 7. clear uovcer bit 2 8. enable peripheral activity hardware firmware 1. set or clear port feature port_suspend decoded 2. write hpcon[2:0] and hpadd[2:0] bits 3. suspend or resume port per command 99 at43usb320a 1443e?usb?4/04 selective suspend, embedded function selective resume, embedded function hardware firmware 1. set port feature port_suspend decoded 2. disable port 5?s endpoints 3. set gpio to low power state if required hardware firmware 1. clear port feature port_suspend decoded 2. clear port 5 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 5 endpoints 6. send updated port status at next in to endpoint1 100 at43usb320a 1443e?usb?4/04 electrical specification absolute 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. expo- sure to absolute maximum rating conditions for extended periods may affect device reliability. dc characteristics the values shown in this table are valid for ta = 0 c to 85 c, vcc = 4.4 to 5.25v, unless oth- erwise noted. table 2 9. absolute maximum ratings symbol parameter condition min max unit v cc5 5v power supply 5.5 v vi dc input voltage -0.3v vcext+0.3 4.6 max v vo dc output voltage -0.3 vcext+0.3 4.6 max v to operating temperature -40 +125 c ts storage temperature -65 +150 c table 3 0. power supply symbol parameter condition min max unit v cc 5v power supply 4.4 5.25 v i cc 5v supply current 40 ma i ccs suspended device current 250 ua 101 at43usb320a 1443e?usb?4/04 table 3 1. usb signals: dpx, dmx symbol parameter condition min max unit v ih input level high (driven) 2.0 v v ihz input level high (floating) 2.7 v v il input level low 0.8 v v di differential input sensitivity dpx and dmx 0.2 v v cm differential common mode range 0.8 2.5 v v ol1 static output low rl of 1.5 k ? to 3.6v 0.3 v v oh1 static output high rl of 15 k ? to gnd 2.8 3.6 v v crs output signal crossover 1.3 2.0 v v in input capacitance 20 pf table 3 2. pa, pb, pc, pd symbol parameter condition min max unit v ol2 output low level iol = 4 ma 0.5 v v oh2 output high level ioh = 4 ma vcext - 0.4 v v il2 input low level -0.3 0.3 vcext v v ih2 input high level 0.7 vcext vcext + 0.3 v c input/output capacitance 1 mhz 10 pf 102 at43usb320a 1443e?usb?4/04 note: xtal2 must not be used to drive other circuitry. ac characteristics note: 1. with external 27 ? series resistor. figure 23. full-speed load table 3 3. oscillator signals: xtal1, xtal2 symbol parameter condition min max unit v lh osc1 switching level 0.47 1.20 v v hl osc1 switching level 0.67 1.44 v cx1 input capacitance, xtal1 16 pf cx2 output capacitance, xtal2 16 pf c12 osc1/2 capacitance 8 pf t su start-up time 6 mhz, fundamental 2 ms dl drive level 150 w table 3 4. usb driver characteristics, full speed operation symbol parameter condition min max unit tr rise time c l = 50 pf 4 20 ns tf fall time c l = 50 pf 4 20 ns trfm tr/tf matching 90 110 % zdrv driver output resistance (1) steady state drive 28 44 ? table 3 5. usb driver characteristics, low-speed operation symbol parameter condition min max unit tr rise time cl = 200 - 600 pf 75 300 ns tf fall time cl = 200 - 600 pf 75 300 ns trfm tr/tf matching 80 125 % txd+ txd- r s r s c l c l c l = 50 pf 103 at43usb320a 1443e?usb?4/04 figure 24. low-speed downstream port load note: 1. with 6.000 mhz, 100 ppm crystal. txd+ txd- r s r s c l c l c l = 200 pf to 600 pf 3.6v 1.5 k ohm table 3 6. usb source timings, full-speed operation symbol parameter condition min max unit tdrate full speed data rate (1) average bit rate 11.97 12.03 mb/s tframe frame interval (1) 0.9995 1.0005 ms trfi consecutive frame interval jitter (1) no clock adjustment 42 ns trfiadj consecutive frame interval jitter (1) with clock adjustment 126 ns tdj1 tdj2 source diff driver jitter to n ex t tr a n s i t i o n for paired transitions -2 -1 2 1 ns tfdeop source jitter for differential transition to seo transitions -2 5 ns tdeop differential to eop transition skew -2 5 ns tjr1 tjr2 recvr data jitter tolerance to n ex t tr a n s i t i o n for paired transitions -18.5 -9 18.5 9 ns tfeopt source seo interval of eop 160 175 ns tfeopr receiver seo interval of eop 82 ns tfst width of seo interval during differential transition 14 ns 104 at43usb320a 1443e?usb?4/04 figure 25. differential data jitter figure 26. differential-to-eop transition skew and eop width figure 27. receiver jitter tolerance crossover points paired transitions n*t period + t xjr2 consecutive transitions n*t period + t xjr1 t period differential data lines crossover point extended differential data lines t period diff. data-to- se0 skew n*t period + t deop source eop width: t feopt t leopt receiver eop width: t feopr t leopr t period differential data lines consecutive transitions n*t period + t jr1 consecutive transitions n*t period + t jr1 t jr t jr1 t jr2 105 at43usb320a 1443e?usb?4/04 table 3 7. hub timings, full-speed operation symbol parameter condition min max unit thdd2 hub differential data delay without cable 44 ns thdj1 thdj2 hub diff driver jitter to next transition for paired transitions -3 -1 3 1 ns tfsop data bit width distortion after sop -5 5 ns tfeopd hub eop delay relative to thdd 015ns tfhesk hub eop output width skew -15 15 ns table 3 8. hub timings, low-speed operation symbol parameter condition min max unit tlhdd hub differential data delay 300 ns tlhdj1 tlhdj2 tluhj1 tluhj2 downstr hub diff driver jitter to next transition, downst for paired transitions, downst to next transition, upstr for paired transitions, upstr -45 -15 -45 -45 45 15 45 45 ns tsop data bit width distortion after sop -60 60 ns tleopd hub eop delay relative to thdd 0 200 ns tlhesk hub eop output width skew -300 300 ns 106 at43usb320a 1443e?usb?4/04 table 3 9. hub event timings symbol parameter condition min max unit tdcnn time to detect a downstream port connect event 2.5 2000 s tddis time to detect a disconnect event on downstream port awake hub suspended hub 2.5 2.5 2000 12000 s tursm time from detecting downstream resume to rebroadcast 100 s tdrst duration of driving reset to a downstream device only for a setportfeature (port_reset) request 10 20 s tdspdev time to evaluate device speed after reset 2.5 1000 s turlk time to detect a long k from upstream 2.5 5.5 s turlseo time to detect a long seo from upstream 2.5 5.5 s turpseo duration of repeating seo upstream 23 fs bits tudeop duration of sending seo upstream after eof1 2fs bits 107 at43usb320a 1443e?usb?4/04 figure 28. hub differential delay, differential jitter and sop distortion figure 29. hub eop delay and eop skew differential data lines hub delay downstream t hdd1 crossover point downstream port crossover point hub delay upstream t hdd2 upstream port crossover point upstream end of cable v ss v ss v ss v ss 50% point of initial swing a. downstream hub delay with cable b. upstream hub delay without cable crossover point hub delay upstream t hdd1, t hdd2 crossover point downstream port upstream port or end of cable v ss v ss c. upstream hub delay with or without cable c. upstream eop delay with or without cable v ss a. upstream eop delay with cable b. downstream eop delay without cable t eop t eop+ crossover point extended crossover point extended crossover point extended crossover point extended downstream port upstream port t eop- t eop+ v ss 50% point of initial swing downstream port upstream end of cable v ss t eop- t eop+ v ss downstream port upstream port or end of cable v ss v ss 108 at43usb320a 1443e?usb?4/04 figure 30. external program memory read timing diagram table 4 0. external program memory read timing symbol parameter condition min max unit t acc address to output delay 55 ns t cen cen to output delay 55 ns t df cen to output float 0 ns t oh output hold from cen or address, whichever occurred first 0 ns address t oh t acc output valid address valid t df t ce ce output highz 109 at43usb320a 1443e?usb?4/04 ordering information ordering code package operation range at43usb320a -ac 100 lqfp commercial (0 c to 70 c) 110 at43usb320a 1443e?usb?4/04 packaging information 100aa ? lqfp 2325 orchard parkway san jose, ca 95131 title drawing no. r rev. 100aa, 100-lead, 14 x 14 mm body size, 1.4 mm body thickness, 0.5 mm lead pitch, low profile quad flat pack (lqfp) c 100aa 04/29/2002 pin 1 identifier 0?~7? pin 1 l c a1 a2 a d1 d e e1 e b a ? ? 1.60 a1 0.05 ? 0.15 a2 1.35 1.40 1.45 d 15.75 16.00 16.25 d1 13.90 14.00 14.10 note 2 e 15.75 16.00 16.25 e1 13.90 14.00 14.10 note 2 b 0.17 ? 0.27 c 0.09 ? 0.20 l 0.45 ? 0.75 e 0.50 typ notes: 1. this package conforms to jedec reference ms-026, variation aed. 2. dimensions d1 and e1 do not include mold protrusion. allowable protrusion is 0.25 mm per side. dimensions d1 and e1 are maximum plastic body size dimensions including mold mismatch. 3. lead coplanarity is 0.08 mm maximum. common dimensions (unit of measure = mm) symbol min nom max note 111 at43usb320a 1443e?usb?4/04 errata sheet errata (all date codes): missed watchdog timer reset problem there is a synchronization problem between the watchdog clock and the avr clock. even though the clock inputs to both the watchdog timer and the avr core are generated through the same crystal, the two clock sources are not going through the same pll. the avr is clocked at 12 mhz and the watchdog timer is clocked at 1mhz. the wdr (watchdog reset) instruction is a one-clock-cycle instruction. as such, when a watchdog timer reset occurs due to a wdr, the watchdog timer may miss the reset. this happens frequently if the avr is clocked much faster than the watchdog timer. fix/workaround a workaround is to invoke the wdr repetitively to ensure that the wa tchdog timer will be able to receive the reset signal. if the avr runs at 12 mhz, the wdr command must be invoked fourteen times back to back. the following is the sample code for resetting and arming the watchdog timer, assuming the avr is running at 12 mhz: asm ( "ldi r16,15\n wdr\n wdr\n wdr\n wdr\n wdr\n wdr\n wdr\n wdr\n wdr\n wdr\n wdr\n wdr\n wdr\n out 0x21,r16 " ); to disarm and disable the watchdog, do the following: asm ( "ldi r16,0x18\nldi r17,0x10\n\n out 0x21,r16\n out 0x21,r17 " ); please note that if the avr runs at 24 mhz, the wdr should be invoked twenty-six times. 112 at43usb320a 1443e?usb?4/04 change log doc. rev. comments 1443e data correction: timeout period data in table 19 on page 51. information change: uart does not support a 9-bit data mode. changes were made to ?data reception? on page 59, to figure 19 on page 59 and figure 20 on page 60. the ?uart control register ? ucr? on page 62. additions: added an ?errata sheet? on page 111 and a ?change log? on page 112. table of contents i table of contents features ................................................................................................. 1 description ............................................................................................ 1 hub/monitor/ir chip application......................................................... 2 pin configurations................................................................................ 2 pin assignment ................................................................................... 3 signal description ................................................................................................ 5 architectural overview......................................................................... 7 the general-purpose register file ..................................................... 8 x-, y- and z- registers......................................................................................... 9 alu ? arithmetic logic unit ................................................................................. 9 program memory.................................................................................................. 9 sram data memory .......................................................................................... 10 i/o memory......................................................................................................... 16 usb hub ............................................................................................................ 17 functional description ....................................................................... 19 on-chip power supply........................................................................................ 19 i/o pin characteristics........................................................................................ 19 oscillator and pll .............................................................................................. 19 reset and interrupt handling ............................................................................. 20 reset sources.................................................................................................... 22 power-on reset.................................................................................................. 23 external reset.................................................................................................... 24 watchdog timer reset....................................................................................... 24 non-usb related interrupt handling ................................................................. 24 external interrupts .............................................................................................. 29 interrupt response time.................................................................................... 29 usb interrupt sources ....................................................................................... 31 usb endpoint interrupt sources ........................................................................ 32 avr register set ................................................................................ 36 status register and stack pointer ..................................................................... 36 sleep modes ...................................................................................................... 37 timer/counters ................................................................................... 38 timer/counter prescaler .................................................................................... 38 ii 1443e?usb?4/04 8-bit timer/counter0........................................................................................... 39 16-bit timer/counter1......................................................................................... 41 16-bit timer/counter1 operation ........................................................................ 42 watchdog timer ................................................................................................. 50 serial peripheral interface (spi) ......................................................................... 52 uart.................................................................................................... 57 data transmission.............................................................................. 58 data reception.................................................................................... 59 uart control ...................................................................................... 61 baud rate generator.......................................................................... 63 i/o-ports............................................................................................... 63 port a.................................................................................................................. 63 port b.................................................................................................................. 64 port c.................................................................................................................. 67 port d.................................................................................................................. 68 programming the usb module.......................................................... 69 the usb function .............................................................................................. 69 usb registers .................................................................................................... 77 endpoint registers ............................................................................................. 78 usb hub............................................................................................................. 86 suspend and resume ........................................................................................ 96 electrical specification .................................................................... 100 absolute maximum ratings .............................................................................. 100 dc characteristics............................................................................................ 100 ordering information........................................................................ 109 packaging information ..................................................................... 110 100aa ? lqfp.................................................................................................. 110 errata sheet....................................................................................... 111 problem ............................................................................................................ 111 fix/workaround ................................................................................................ 111 change log ....................................................................................... 112 table of contents .................................................................................. i printed on recycled paper. 1443e?usb?4/04 /xm disclaimer: atmel corporation makes no warranty for the use of its products, other than those expressly contained in the company?s standar d warranty which is detailed in atmel?s terms and conditions located on the company?s web site. the company assumes no responsibi lity for any errors which may appear in this document, reserves the right to change devices or specifications detailed herein at any time wi thout notice, and does not make any commitment to update the information contained herein. no licenses to patents or other intellectual property of atmel are granted by the company in connection with the sale of atmel products, expressly or by implication. atmel?s products are not aut horized for use as critical components in life support devices or systems. atmel corporation atmel operations 2325 orchard parkway san jose, ca 95131, usa tel: 1(408) 441-0311 fax: 1(408) 487-2600 regional headquarters europe atmel sarl route des arsenaux 41 case postale 80 ch-1705 fribourg switzerland tel: (41) 26-426-5555 fax: (41) 26-426-5500 asia room 1219 chinachem golden plaza 77 mody road tsimshatsui east kowloon hong kong tel: (852) 2721-9778 fax: (852) 2722-1369 japan 9f, tonetsu shinkawa bldg. 1-24-8 shinkawa chuo-ku, tokyo 104-0033 japan tel: (81) 3-3523-3551 fax: (81) 3-3523-7581 memory 2325 orchard parkway san jose, ca 95131, usa tel: 1(408) 441-0311 fax: 1(408) 436-4314 microcontrollers 2325 orchard parkway san jose, ca 95131, usa tel: 1(408) 441-0311 fax: 1(408) 436-4314 la chantrerie bp 70602 44306 nantes cedex 3, france tel: (33) 2-40-18-18-18 fax: (33) 2-40-18-19-60 asic/assp/smart cards zone industrielle 13106 rousset cedex, france tel: (33) 4-42-53-60-00 fax: (33) 4-42-53-60-01 1150 east cheyenne mtn. blvd. colorado springs, co 80906, usa tel: 1(719) 576-3300 fax: 1(719) 540-1759 scottish enterprise technology park maxwell building east kilbride g75 0qr, scotland tel: (44) 1355-803-000 fax: (44) 1355-242-743 rf/automotive theresienstrasse 2 postfach 3535 74025 heilbronn, germany tel: (49) 71-31-67-0 fax: (49) 71-31-67-2340 1150 east cheyenne mtn. blvd. colorado springs, co 80906, usa tel: 1(719) 576-3300 fax: 1(719) 540-1759 biometrics/imaging/hi-rel mpu/ high speed converters/rf datacom avenue de rochepleine bp 123 38521 saint-egreve cedex, france tel: (33) 4-76-58-30-00 fax: (33) 4-76-58-34-80 literature requests www.atmel.com/literature ? atmel corporation 2004 . all rights reserved. atmel ? and combinations thereof, and avr ? are the registered trademarks, and megaavr ? is the trademark of atmel corporation or its subsidiaries. other terms and product names may be the trademarks of others. |
Price & Availability of AT43USB320A-AC |
|
|
All Rights Reserved © IC-ON-LINE 2003 - 2022 |
[Add Bookmark] [Contact Us] [Link exchange] [Privacy policy] |
Mirror Sites : [www.datasheet.hk]
[www.maxim4u.com] [www.ic-on-line.cn]
[www.ic-on-line.com] [www.ic-on-line.net]
[www.alldatasheet.com.cn]
[www.gdcy.com]
[www.gdcy.net] |